Example usage for android.text Html fromHtml

List of usage examples for android.text Html fromHtml

Introduction

In this page you can find the example usage for android.text Html fromHtml.

Prototype

@Deprecated
public static Spanned fromHtml(String source) 

Source Link

Document

Returns displayable styled text from the provided HTML string with the legacy flags #FROM_HTML_MODE_LEGACY .

Usage

From source file:com.liato.bankdroid.banking.banks.ResursBank.java

@Override
public void updateTransactions(Account account, Urllib urlopen) throws LoginException, BankException {
    super.updateTransactions(account, urlopen);
    // Only update transactions for the main account
    if (!account.getId().startsWith("b_"))
        return;//from ww w.  j  a va2  s .c o  m

    try {
        response = urlopen.open("https://secure.resurs.se/internetbank/kontoutdrag.jsp");
        Matcher matcher = reTransactions.matcher(response);
        ArrayList<Transaction> transactions = new ArrayList<Transaction>();
        while (matcher.find()) {
            /*
             * Capture groups:
             * GROUP                    EXAMPLE DATA
             * 1: Date                  2010-04-17
             * 2: Transaction           ONOFF L+NNA
             * 3: Currency              always null?
             * 4: Amount                -95,00 kr 
             * 
             */
            transactions.add(new Transaction(matcher.group(1),
                    Html.fromHtml(matcher.group(2)).toString().trim(), Helpers.parseBalance(matcher.group(4))));
        }
        account.setTransactions(transactions);
    } catch (ClientProtocolException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}

From source file:com.liato.bankdroid.banking.banks.DinersClub.java

@Override
public void update() throws BankException, LoginException, BankChoiceException {
    super.update();
    if (username == null || password == null || username.length() == 0 || password.length() == 0) {
        throw new LoginException(res.getText(R.string.invalid_username_password).toString());
    }//  w w w  . j av a 2s .c o  m
    urlopen = login();
    if (!"https://secure.dinersclub.se/dcs/eSaldo/Default.aspx".equalsIgnoreCase(urlopen.getCurrentURI())) {
        try {
            response = urlopen.open("https://secure.dinersclub.se/dcs/eSaldo/Default.aspx");
        } catch (ClientProtocolException e) {
            throw new BankException(e.getMessage());
        } catch (IOException e) {
            throw new BankException(e.getMessage());
        }
    }

    Matcher matcher = reBalance.matcher(response);
    if (matcher.find()) {
        /*
         * Capture groups:
         * GROUP                EXAMPLE DATA
         * 1: Name              Privatkort
         * 2: Card number       1234 789456 741
         * 3: Balance           3.331,79 kr
         * 
         */
        accounts.add(new Account(Html.fromHtml(matcher.group(1)).toString().trim(),
                Helpers.parseBalance(matcher.group(3)), "1"));
        balance = balance.add(Helpers.parseBalance(matcher.group(3)));
    }
    if (accounts.isEmpty()) {
        throw new BankException(res.getText(R.string.no_accounts_found).toString());
    }

    /* Detect invoice dates - needed to find the transactions */
    matcher = reInvoices.matcher(response);
    if (matcher.find()) {
        invoiceUrl = matcher.group(1);
    } else {
        invoiceUrl = null;
    }

    super.updateComplete();
}

From source file:com.adrup.saldo.bank.lf.LfBankManager.java

@Override
public Map<AccountHashKey, RemoteAccount> getAccounts(Map<AccountHashKey, RemoteAccount> accounts)
        throws BankException {
    Log.d(TAG, "getAccounts()");
    HttpClient httpClient = new SaldoHttpClient(mContext);

    try {/* www .j  a v  a 2s  .c om*/
        // get login page
        Log.d(TAG, "getting login page");
        HttpContext httpContext = new BasicHttpContext();
        String res = HttpHelper.get(httpClient, LOGIN_URL, httpContext);
        HttpUriRequest currentReq = (HttpUriRequest) httpContext.getAttribute(ExecutionContext.HTTP_REQUEST);
        HttpHost currentHost = (HttpHost) httpContext.getAttribute(ExecutionContext.HTTP_TARGET_HOST);
        String action = currentHost.toURI() + currentReq.getURI();
        Log.e(TAG, "action=" + action);

        Matcher matcher = Pattern.compile(VIEWSTATE_REGEX).matcher(res);
        if (!matcher.find()) {
            Log.e(TAG, "No viewstate match.");
            Log.d(TAG, res);
            throw new LfBankException("No viewState match.");
        }
        String viewState = matcher.group(1);
        Log.d(TAG, "viewState= " + viewState);

        matcher = Pattern.compile(EVENTVALIDATION_REGEX).matcher(res);
        if (!matcher.find()) {
            Log.e(TAG, "No eventvalidation match.");
            Log.d(TAG, res);
            throw new LfBankException("No eventValidation match.");
        }
        String eventValidation = matcher.group(1);
        Log.d(TAG, "eventValidation= " + eventValidation);

        // do login post
        List<NameValuePair> parameters = new ArrayList<NameValuePair>(3);

        parameters.add(new BasicNameValuePair("__LASTFOCUS", ""));
        parameters.add(new BasicNameValuePair("__EVENTTARGET", ""));
        parameters.add(new BasicNameValuePair("__EVENTARGUMENT", ""));
        parameters.add(new BasicNameValuePair(VIEWSTATE_PARAM, viewState));
        parameters.add(new BasicNameValuePair("selMechanism", "PIN-kod"));
        parameters.add(new BasicNameValuePair(USER_PARAM, mBankLogin.getUsername()));
        parameters.add(new BasicNameValuePair(PASS_PARAM, mBankLogin.getPassword()));
        parameters.add(new BasicNameValuePair("btnLogIn.x", "39"));
        parameters.add(new BasicNameValuePair("btnLogIn.y", "11"));
        parameters.add(new BasicNameValuePair(EVENTVALIDATION_PARAM, eventValidation));

        Log.d(TAG, "logging in...");
        res = HttpHelper.post(httpClient, action, parameters);

        if (res.contains("Felaktig inloggning")) {
            Log.d(TAG, "auth fail");
            throw new AuthenticationException("auth fail");
        }

        Log.d(TAG, "getting accountsUrl");

        // token
        matcher = Pattern.compile(TOKEN_REGEX).matcher(res);
        if (!matcher.find()) {
            Log.e(TAG, "No token match.");
            Log.d(TAG, res);
            throw new LfBankException("No token match.");
        }
        String token = matcher.group(1);
        Log.d(TAG, "token= " + token);

        // accountsUrl
        matcher = Pattern.compile(ACCOUNTS_URL_REGEX).matcher(res);

        if (!matcher.find()) {
            Log.e(TAG, "No accountsUrl match.");
            Log.d(TAG, res);
            throw new LfBankException("No accountsUrl match.");
        }
        String accountsUrl = Html.fromHtml(matcher.group(1)).toString();

        accountsUrl += "&_token=" + token;
        Log.d(TAG, "tokenized accountsUrl= " + accountsUrl);

        // get accounts page
        Log.d(TAG, "fetching accounts");
        res = HttpHelper.get(httpClient, accountsUrl);

        matcher = Pattern.compile(ACCOUNTS_REGEX).matcher(res);

        int remoteId = 1;
        int count = 0;
        while (matcher.find()) {
            count++;
            int groupCount = matcher.groupCount();
            for (int i = 1; i <= groupCount; i++) {
                Log.d(TAG, i + ":" + matcher.group(i));
            }
            if (groupCount < 2) {
                throw new BankException("Pattern match issue: groupCount < 2");
            }

            int ordinal = remoteId;
            String name = Html.fromHtml(matcher.group(1)).toString();
            long balance = Long.parseLong(matcher.group(2).replaceAll("\\,|\\.| ", "")) / 100;
            accounts.put(new AccountHashKey(String.valueOf(remoteId), mBankLogin.getId()),
                    new Account(String.valueOf(remoteId), mBankLogin.getId(), ordinal, name, balance));
            remoteId++;
        }
        if (count == 0) {
            Log.d(TAG, "no accounts added");
            Log.d(TAG, res);
        }
    } catch (IOException e) {
        Log.e(TAG, e.getMessage(), e);
        throw new LfBankException(e.getMessage(), e);

    } catch (HttpException e) {
        Log.e(TAG, e.getMessage(), e);
        throw new LfBankException(e.getMessage(), e);
    } finally {
        httpClient.getConnectionManager().shutdown();
    }

    return accounts;
}

From source file:com.lepin.activity.CarpoolWithCalendarActivity.java

protected void setData() {
    carpoolCalendar = carpoolProgramPassenger.getCarpoolCalendar();
    money = carpoolCalendar.length * carpoolProgramPassenger.getCarpoolProgram().getCharge();
    if (isDriver) {
        user = carpoolProgramPassenger.getPassenger();
    } else {/*w  ww.j a  va 2s.  c  o  m*/
        user = mPincheInfo.getUser();
    }
    mNameText.setText(user.getUsername(this));
    telString = user.getTel();
    // ???
    if (user != null && user.isUserStateVerify()) {
        mVImageView.setVisibility(View.VISIBLE);
    }
    if (isDriver) {
        if (carpoolCalendar.length > 0) {

            mShowMoneyTextView.setText(Html
                    .fromHtml("" + "<font color=\"#ff00ff\">" + carpoolCalendar.length + "</font>"
                            + "," + "<font color=\"#ff00ff\">" + money + "</font>" + ""));
        } else {
            mShowMoneyTextView.setText(getString(R.string.passenger_pay_all));
        }

        mShowMoneyTextView.setVisibility(View.VISIBLE);
    } else {
        if (carpoolCalendar.length > 0) {
            mPayMoneyTextView.setText(Html.fromHtml(getString(R.string.money_num) + "<font color=\"#ff00ff\">"
                    + money + "</font>" + getString(R.string.unit_yuan)));
            mPayButton.setOnClickListener(this);
        } else {
            mPayMoneyTextView.setText(getString(R.string.no_need_to_pay));
            mPayButton.setVisibility(View.GONE);
        }
        mDrivingYears.setText(getString(R.string.driving_years, user.getDriveAge()));
        mDrivingYears.setVisibility(View.VISIBLE);
        if (mPincheInfo.getCar() != null) {// 
            Car car = mPincheInfo.getCar();
            mCarLicenseText.setText(
                    (car.getLicence() == null || car.getLicence().equals("")) ? getString(R.string.unknow)
                            : car.getLicence());
            mCarBrandText.setText(car.getCarType().getCarTypeName());
        }
        mPayLayout.setVisibility(View.VISIBLE);
    }

    mStarText.setText(mPincheInfo.getStart_name());
    mEndText.setText(mPincheInfo.getEnd_name());
    mPeopleNum.setText(String.valueOf(mPincheInfo.getNum()));
    mCostText.setText(String.valueOf(mPincheInfo.getCharge()));
    this.mStartDateText.setText(mPincheInfo.getCycle().getTxt() + "  " + getString(R.string.moring) + ":"
            + mPincheInfo.getDepartureTime());// ???
    if (!TextUtils.isEmpty(mPincheInfo.getBackTime())) {
        this.mBackDateText.setText(mPincheInfo.getCycle().getTxt() + "  " + getString(R.string.night) + ":"
                + mPincheInfo.getBackTime());// ?
    }
    if (!TextUtils.isEmpty(mPincheInfo.getNote())) {
        this.mNoteText.setText(mPincheInfo.getNote());
    }

    // 
    mCalendarView.setCalendarDate(carpoolCalendar);
    if (mCalendarLayout.getVisibility() != View.VISIBLE) {
        mCalendarLayout.setVisibility(View.VISIBLE);
        ((View) findViewById(R.id.my_order_detail_calendar_divider)).setVisibility(View.GONE);
    }
    ((View) findViewById(R.id.my_order_root_view)).setVisibility(View.VISIBLE);

}

From source file:com.liato.bankdroid.banking.banks.CSN.java

@Override
public void update() throws BankException, LoginException, BankChoiceException {
    super.update();
    if (username == null || password == null || username.length() == 0 || password.length() == 0) {
        throw new LoginException(res.getText(R.string.invalid_username_password).toString());
    }/*from   w  w  w  .  j  av a2 s  .  com*/
    urlopen = login();
    try {
        response = urlopen.open(
                "https://www.csn.se/aterbetalning/hurStorArMinSkuld/aktuellStudieskuld.do?javascript=off");
        Matcher matcher;
        matcher = reBalance.matcher(response);
        int i = 0;
        while (matcher.find()) {
            /*
             * Capture groups:
             * GROUP                EXAMPLE DATA
             * 1: ID                0
             * 2: Name              Ln efter 30 juni 2001 (annuitetsln)
             * 3: Amount            123,456
             *  
             */
            BigDecimal amount = Helpers.parseBalance(matcher.group(3).replace(",", "")).negate();
            Account account = new Account(Html.fromHtml(matcher.group(2)).toString().trim(), amount,
                    matcher.group(1).trim(), Account.LOANS);
            if (i > 0) {
                account.setAliasfor("0");
            }
            accounts.add(account);
            balance = balance.add(amount);
            i++;
        }

        if (accounts.isEmpty()) {
            throw new BankException(res.getText(R.string.no_accounts_found).toString());
        }
    } catch (ClientProtocolException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } finally {
        super.updateComplete();
    }
}

From source file:com.amazon.cordova.plugin.ADMMessageHandler.java

/**
 * Creates a notification when app is not running or is not in foreground. It puts the message info into the Intent
 * extra//from  w  w  w.ja v  a 2  s . co m
 * 
 * @param context
 * @param extras
 */
public void createNotification(Context context, Bundle extras) {
    NotificationManager notificationManager = (NotificationManager) getSystemService(
            Context.NOTIFICATION_SERVICE);
    String appName = getAppName(this);

    // reuse the intent so that we can combine multiple messages into extra
    if (notificationIntent == null) {
        notificationIntent = new Intent(this, ADMHandlerActivity.class);
    }
    notificationIntent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_CLEAR_TOP);
    notificationIntent.putExtra("pushBundle", extras);

    PendingIntent contentIntent = PendingIntent.getActivity(this, 0, notificationIntent,
            PendingIntent.FLAG_UPDATE_CURRENT);

    final Builder notificationBuilder = new Notification.Builder(context);
    notificationBuilder.setSmallIcon(context.getApplicationInfo().icon).setWhen(System.currentTimeMillis())
            .setContentIntent(contentIntent);

    if (this.shouldShowMessageInNotification()) {
        String message = extras.getString(PushPlugin.MESSAGE);
        notificationBuilder.setContentText(Html.fromHtml(message).toString());
    } else {
        notificationBuilder.setContentText(this.defaultMessageTextInNotification());
    }

    String title = appName;
    notificationBuilder.setContentTitle(title).setTicker(title);
    notificationBuilder.setAutoCancel(true);
    // Because the ID remains unchanged, the existing notification is updated.
    notificationManager.notify((String) appName, NOTIFICATION_ID, notificationBuilder.getNotification());
}

From source file:it.gulch.linuxday.android.fragments.EventDetailsFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.fragment_event_details, container, false);

    holder = new ViewHolder();
    holder.inflater = inflater;/*from   w w  w. jav  a 2s . c  o m*/

    ((TextView) view.findViewById(R.id.title)).setText(event.getTitle());
    TextView textView = (TextView) view.findViewById(R.id.subtitle);
    String text = event.getSubtitle();
    if (TextUtils.isEmpty(text)) {
        textView.setVisibility(View.GONE);
    } else {
        textView.setText(text);
    }

    MovementMethod linkMovementMethod = LinkMovementMethod.getInstance();

    // Set the persons summary text first; replace it with the clickable text when the loader completes
    holder.personsTextView = (TextView) view.findViewById(R.id.persons);
    String personsSummary = "";
    if (CollectionUtils.isEmpty(event.getPeople())) {
        holder.personsTextView.setVisibility(View.GONE);
    } else {
        personsSummary = StringUtils.join(event.getPeople(), ", ");
        holder.personsTextView.setText(personsSummary);
        holder.personsTextView.setMovementMethod(linkMovementMethod);
        holder.personsTextView.setVisibility(View.VISIBLE);
    }

    ((TextView) view.findViewById(R.id.track)).setText(event.getTrack().getTitle());
    Date startTime = event.getStartDate();
    Date endTime = event.getEndDate();
    text = String.format("%1$s, %2$s  %3$s", event.getTrack().getDay().getName(),
            (startTime != null) ? TIME_DATE_FORMAT.format(startTime) : "?",
            (endTime != null) ? TIME_DATE_FORMAT.format(endTime) : "?");
    ((TextView) view.findViewById(R.id.time)).setText(text);
    final String roomName = event.getTrack().getRoom().getName();
    TextView roomTextView = (TextView) view.findViewById(R.id.room);
    Spannable roomText = new SpannableString(String.format("%1$s", roomName));
    //      final int roomImageResId = getResources()
    //            .getIdentifier(StringUtils.roomNameToResourceName(roomName), "drawable",
    //                        getActivity().getPackageName());
    //      // If the room image exists, make the room text clickable to display it
    //      if(roomImageResId != 0) {
    //         roomText.setSpan(new UnderlineSpan(), 0, roomText.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
    //         roomTextView.setOnClickListener(new View.OnClickListener()
    //         {
    //
    //            @Override
    //            public void onClick(View view)
    //            {
    //               RoomImageDialogFragment.newInstance(roomName, roomImageResId).show(getFragmentManager());
    //            }
    //         });
    //         roomTextView.setFocusable(true);
    //      }
    roomTextView.setText(roomText);

    textView = (TextView) view.findViewById(R.id.abstract_text);
    text = event.getEventAbstract();
    if (TextUtils.isEmpty(text)) {
        textView.setVisibility(View.GONE);
    } else {
        String strippedText = StringUtils.stripEnd(Html.fromHtml(text).toString(), " \n");
        textView.setText(strippedText);
        textView.setMovementMethod(linkMovementMethod);
    }
    textView = (TextView) view.findViewById(R.id.description);
    text = event.getDescription();
    if (TextUtils.isEmpty(text)) {
        textView.setVisibility(View.GONE);
    } else {
        String strippedText = StringUtils.stripEnd(Html.fromHtml(text).toString(), " \n");
        textView.setText(strippedText);
        textView.setMovementMethod(linkMovementMethod);
    }

    holder.linksContainer = (ViewGroup) view.findViewById(R.id.links_container);
    return view;
}

From source file:com.liato.bankdroid.banking.banks.MobilbankenBase.java

@Override
public void updateTransactions(Account account, Urllib urlopen) throws LoginException, BankException {
    super.updateTransactions(account, urlopen);

    Matcher matcher;/*w  w  w . ja  v  a  2s  .  com*/
    try {
        response = urlopen.open(String.format("https://mobil-banken.se/%s/accountmovement.html?account_no=%s",
                targetId, account.getId()));
        matcher = reTransactions.matcher(response);
        ArrayList<Transaction> transactions = new ArrayList<Transaction>();
        while (matcher.find()) {
            /*
             * Capture groups:
             * GROUP                    EXAMPLE DATA
             * 1: Transaction           Kortkp QPARKSTOCKHOLM,  STOCKHOLM
             * 2: Amount                -40,00
             * 3: Date                  2010.12.23 
             * 
             */
            transactions.add(new Transaction(matcher.group(3).trim().replace(".", "-"),
                    Html.fromHtml(matcher.group(1)).toString().trim(), Helpers.parseBalance(matcher.group(2))));
        }
        account.setTransactions(transactions);
    } catch (ClientProtocolException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}

From source file:com.liato.bankdroid.banking.banks.AmericanExpress.java

@Override
public void update() throws BankException, LoginException, BankChoiceException {
    super.update();
    if (username == null || password == null || username.length() == 0 || password.length() == 0) {
        throw new LoginException(res.getText(R.string.invalid_username_password).toString());
    }/*w  ww  .  ja v  a2  s.  c  o  m*/

    urlopen = login();
    Matcher matcher = reAccounts.matcher(response);

    while (matcher.find()) {
        /*
         * Capture groups:
         * GROUP                    EXAMPLE DATA
         * 1: Account number        XXX-11111
         * 2: ID                    0
         * 3: Name                  SAS EuroBonus American Express&reg; Card
         * 4: Amount                1.111,11 kr
         * 
         */
        accounts.add(new Account(Html.fromHtml(matcher.group(3)).toString().trim(),
                Helpers.parseBalance(matcher.group(4)).negate(), matcher.group(2).trim()));
        balance = balance.add(Helpers.parseBalance(matcher.group(4)).negate());
    }

    if (accounts.isEmpty()) {
        throw new BankException(res.getText(R.string.no_accounts_found).toString());
    }
    super.updateComplete();
}

From source file:com.mendhak.gpslogger.common.network.CertificateValidationWorkflow.java

private static void onWorkflowFinished(final Context context, Exception e, boolean isValid) {

    Dialogs.hideProgress();/* ww w.  j  a v  a2 s .com*/

    if (!isValid) {
        final CertificateValidationException cve = Networks.extractCertificateValidationException(e);

        if (cve != null) {
            LOG.debug("Untrusted certificate found, " + cve.getCertificate().toString());
            try {
                final StringBuilder sb = new StringBuilder();
                sb.append(cve.getMessage());
                sb.append("<br /><br /><strong>").append("Subject: ").append("</strong>")
                        .append(cve.getCertificate().getSubjectDN().getName());
                sb.append("<br /><br /><strong>").append("Issuer: ").append("</strong>")
                        .append(cve.getCertificate().getIssuerDN().getName());
                sb.append("<br /><br /><strong>").append("Fingerprint: ").append("</strong>")
                        .append(DigestUtils.shaHex(cve.getCertificate().getEncoded()));
                sb.append("<br /><br /><strong>").append("Issued on: ").append("</strong>")
                        .append(cve.getCertificate().getNotBefore());
                sb.append("<br /><br /><strong>").append("Expires on: ").append("</strong>")
                        .append(cve.getCertificate().getNotAfter());

                new MaterialDialog.Builder(context).title(R.string.ssl_certificate_add_to_keystore)
                        .content(Html.fromHtml(sb.toString())).positiveText(R.string.ok)
                        .negativeText(R.string.cancel).onPositive(new MaterialDialog.SingleButtonCallback() {
                            @Override
                            public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) {
                                try {
                                    Networks.addCertToKnownServersStore(cve.getCertificate(),
                                            context.getApplicationContext());
                                    Dialogs.alert("", context.getString(R.string.restart_required), context);
                                } catch (Exception e) {
                                    LOG.error("Could not add to the keystore", e);
                                }

                                dialog.dismiss();
                            }
                        }).show();

            } catch (Exception e1) {
                LOG.error("Could not get fingerprint of certificate", e1);
            }

        } else {
            LOG.error("Error while attempting to fetch server certificate", e);
            Dialogs.error(context.getString(R.string.error),
                    "Error while attempting to fetch server certificate", e != null ? e.getMessage() : "", e,
                    context);
        }
    } else {
        Dialogs.alert(context.getString(R.string.success), context.getString(R.string.ssl_certificate_is_valid),
                context);
    }
}