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.klinker.android.twitter.utils.NotificationUtils.java

private static NotificationCompat.InboxStyle getMentionsInboxStyle(int numberNew, int accountNumber,
        Context context, String title) {
    NotificationCompat.InboxStyle style = new NotificationCompat.InboxStyle();

    Cursor cursor = MentionsDataSource.getInstance(context).getCursor(accountNumber);
    if (!cursor.moveToLast()) {
        return style;
    }/*from  ww w .  ja v  a 2  s  . c  o  m*/

    AppSettings settings = AppSettings.getInstance(context);

    if (numberNew > 5) {
        if (numberNew - 5 == 1) {
            style.setSummaryText("+" + (numberNew - 5) + " " + context.getString(R.string.new_mention));
        } else {
            style.setSummaryText("+" + (numberNew - 5) + " " + context.getString(R.string.new_mentions));
        }

        for (int i = 0; i < 5; i++) {
            String handle = cursor.getString(cursor.getColumnIndex(MentionsSQLiteHelper.COLUMN_SCREEN_NAME));
            String text = cursor.getString(cursor.getColumnIndex(MentionsSQLiteHelper.COLUMN_TEXT));
            String longText = "<b>@" + handle + "</b>: " + text;

            style.addLine(Html.fromHtml(
                    settings.addonTheme ? longText.replaceAll("FF8800", settings.accentColor) : longText));

            cursor.moveToPrevious();
        }
    } else {

        for (int i = 0; i < numberNew; i++) {
            String handle = cursor.getString(cursor.getColumnIndex(MentionsSQLiteHelper.COLUMN_SCREEN_NAME));
            String text = cursor.getString(cursor.getColumnIndex(MentionsSQLiteHelper.COLUMN_TEXT));
            String longText = "<b>@" + handle + "</b>: " + text;

            style.addLine(Html.fromHtml(
                    settings.addonTheme ? longText.replaceAll("FF8800", settings.accentColor) : longText));

            cursor.moveToPrevious();
        }
    }

    style.setBigContentTitle(title);

    return style;
}

From source file:com.android.argb.edhlc.Utils.java

public static void createAboutDialog(final View view) {
    @SuppressLint("InflateParams")
    View aboutDialog = LayoutInflater.from(view.getContext()).inflate(R.layout.dialog_about, null);

    TextView version = (TextView) aboutDialog.findViewById(R.id.version);
    TextView aChart = (TextView) aboutDialog.findViewById(R.id.thirdPartyAChartEngine);
    TextView crop = (TextView) aboutDialog.findViewById(R.id.thirdPartyCrop);
    TextView picker = (TextView) aboutDialog.findViewById(R.id.thirdColorPicker);
    TextView apache = (TextView) aboutDialog.findViewById(R.id.apache);

    try {/*from www.  ja  v  a  2  s.c o m*/
        PackageInfo pInfo = pInfo = view.getContext().getPackageManager()
                .getPackageInfo(view.getContext().getPackageName(), 0);
        version.setText(pInfo.versionName);
    } catch (PackageManager.NameNotFoundException e) {
        version.setText("");
    }

    aChart.setText(Html.fromHtml("<u>AChartEngine</u>"));
    aChart.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Uri uriUrl = Uri.parse("http://www.achartengine.org/index.html");
            Intent launchBrowser = new Intent(Intent.ACTION_VIEW, uriUrl);
            view.getContext().startActivity(launchBrowser);
        }
    });

    crop.setText(Html.fromHtml("<u>Android CropImage</u>"));
    crop.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Uri uriUrl = Uri.parse("https://github.com/lvillani/android-cropimage");
            Intent launchBrowser = new Intent(Intent.ACTION_VIEW, uriUrl);
            view.getContext().startActivity(launchBrowser);
        }
    });

    picker.setText(Html.fromHtml("<u>Android Stock Color Picker Library</u>"));
    picker.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Uri uriUrl = Uri.parse("https://github.com/woalk/android-colorpicker");
            Intent launchBrowser = new Intent(Intent.ACTION_VIEW, uriUrl);
            view.getContext().startActivity(launchBrowser);
        }
    });

    apache.setText(Html.fromHtml(
            "Licensed under Apache License v2.0.<br>You can obtain a copy of the license <u>here</u>."));
    apache.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Uri uriUrl = Uri.parse("http://www.apache.org/licenses/LICENSE-2.0");
            Intent launchBrowser = new Intent(Intent.ACTION_VIEW, uriUrl);
            view.getContext().startActivity(launchBrowser);
        }
    });

    AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(view.getContext());
    alertDialogBuilder.setView(aboutDialog);
    alertDialogBuilder.setTitle("");
    alertDialogBuilder.setPositiveButton("OK", new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            dialog.dismiss();
        }
    });
    alertDialogBuilder.setNeutralButton("MORE", new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            dialog.dismiss();

            AlertDialog.Builder alertDialogBuilder2 = new AlertDialog.Builder(view.getContext());
            alertDialogBuilder2
                    .setView(LayoutInflater.from(view.getContext()).inflate(R.layout.dialog_about2, null));
            alertDialogBuilder2.setTitle("");
            alertDialogBuilder2.setPositiveButton("OK", new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    dialog.dismiss();
                }
            });
            alertDialogBuilder2.setNegativeButton("BACK", new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    createAboutDialog(view);
                }
            });
            final AlertDialog alertDialog2 = alertDialogBuilder2.create();
            alertDialog2.show();
        }
    });
    final AlertDialog alertDialog = alertDialogBuilder.create();
    alertDialog.show();
}

From source file:com.klinker.android.twitter.utils.NotificationUtils.java

private static NotificationCompat.InboxStyle getDMInboxStyle(int numberNew, int accountNumber, Context context,
        String title) {/*  w ww.ja  v a2s  . co  m*/
    NotificationCompat.InboxStyle style = new NotificationCompat.InboxStyle();

    Cursor cursor = DMDataSource.getInstance(context).getCursor(accountNumber);
    if (!cursor.moveToLast()) {
        return style;
    }

    AppSettings settings = AppSettings.getInstance(context);

    if (numberNew > 5) {
        if (numberNew - 5 == 1) {
            style.setSummaryText("+" + (numberNew - 5) + " " + context.getString(R.string.new_direct_message));
        } else {
            style.setSummaryText("+" + (numberNew - 5) + " " + context.getString(R.string.new_direct_messages));
        }

        for (int i = 0; i < 5; i++) {
            String handle = cursor.getString(cursor.getColumnIndex(DMSQLiteHelper.COLUMN_SCREEN_NAME));
            String text = cursor.getString(cursor.getColumnIndex(DMSQLiteHelper.COLUMN_TEXT));
            String longText = "<b>@" + handle + "</b>: " + text;

            style.addLine(Html.fromHtml(
                    settings.addonTheme ? longText.replaceAll("FF8800", settings.accentColor) : longText));

            cursor.moveToPrevious();
        }
    } else {

        for (int i = 0; i < numberNew; i++) {
            String handle = cursor.getString(cursor.getColumnIndex(DMSQLiteHelper.COLUMN_SCREEN_NAME));
            String text = cursor.getString(cursor.getColumnIndex(DMSQLiteHelper.COLUMN_TEXT));
            String longText = "<b>@" + handle + "</b>: " + text;

            style.addLine(Html.fromHtml(
                    settings.addonTheme ? longText.replaceAll("FF8800", settings.accentColor) : longText));

            cursor.moveToPrevious();
        }
    }

    style.setBigContentTitle(title);

    return style;
}

From source file:cgeo.geocaching.cgBase.java

public cgCacheWrap parseSearch(cgSearchThread thread, String url, String page, boolean showCaptcha) {
    if (StringUtils.isBlank(page)) {
        Log.e(cgSettings.tag, "cgeoBase.parseSearch: No page given");
        return null;
    }/*from   w w  w . j av  a  2  s  .c  o m*/

    final cgCacheWrap caches = new cgCacheWrap();
    final List<String> cids = new ArrayList<String>();
    final List<String> guids = new ArrayList<String>();
    String recaptchaChallenge = null;
    String recaptchaText = null;

    caches.url = url;

    final Pattern patternCacheType = Pattern.compile(
            "<td class=\"Merge\">[^<]*<a href=\"[^\"]*/seek/cache_details\\.aspx\\?guid=[^\"]+\"[^>]+>[^<]*<img src=\"[^\"]*/images/wpttypes/[^.]+\\.gif\" alt=\"([^\"]+)\" title=\"[^\"]+\"[^>]*>[^<]*</a>",
            Pattern.CASE_INSENSITIVE | Pattern.MULTILINE);
    final Pattern patternGuidAndDisabled = Pattern.compile(
            "<img src=\"[^\"]*/images/wpttypes/[^>]*>[^<]*</a></td><td class=\"Merge\">[^<]*<a href=\"[^\"]*/seek/cache_details\\.aspx\\?guid=([a-z0-9\\-]+)\" class=\"lnk([^\"]*)\">([^<]*<span>)?([^<]*)(</span>[^<]*)?</a>[^<]+<br />([^<]*)<span[^>]+>([^<]*)</span>([^<]*<img[^>]+>)?[^<]*<br />[^<]*</td>",
            Pattern.CASE_INSENSITIVE | Pattern.MULTILINE);
    final Pattern patternTbs = Pattern.compile(
            "<a id=\"ctl00_ContentBody_dlResults_ctl[0-9]+_uxTravelBugList\" class=\"tblist\" data-tbcount=\"([0-9]+)\" data-id=\"[^\"]*\"[^>]*>(.*)</a>",
            Pattern.CASE_INSENSITIVE);
    final Pattern patternTbsInside = Pattern.compile(
            "(<img src=\"[^\"]+\" alt=\"([^\"]+)\" title=\"[^\"]*\" />[^<]*)",
            Pattern.CASE_INSENSITIVE | Pattern.MULTILINE);
    final Pattern patternDirection = Pattern.compile(
            "<img id=\"ctl00_ContentBody_dlResults_ctl[0-9]+_uxDistanceAndHeading\" title=\"[^\"]*\" src=\"[^\"]*/seek/CacheDir\\.ashx\\?k=([^\"]+)\"[^>]*>",
            Pattern.CASE_INSENSITIVE);
    final Pattern patternCode = Pattern.compile("\\|\\W*(GC[a-z0-9]+)[^\\|]*\\|",
            Pattern.CASE_INSENSITIVE | Pattern.MULTILINE);
    final Pattern patternId = Pattern.compile("name=\"CID\"[^v]*value=\"([0-9]+)\"", Pattern.CASE_INSENSITIVE);
    final Pattern patternFavourite = Pattern.compile(
            "<span id=\"ctl00_ContentBody_dlResults_ctl[0-9]+_uxFavoritesValue\" title=\"[^\"]*\" class=\"favorite-rank\">([0-9]+)</span>",
            Pattern.CASE_INSENSITIVE);
    final Pattern patternTotalCnt = Pattern.compile(
            "<td class=\"PageBuilderWidget\"><span>Total Records[^<]*<b>(\\d+)<\\/b>",
            Pattern.CASE_INSENSITIVE);
    final Pattern patternRecaptcha = Pattern.compile(
            "<script[^>]*src=\"[^\"]*/recaptcha/api/challenge\\?k=([^\"]+)\"[^>]*>", Pattern.CASE_INSENSITIVE);
    final Pattern patternRecaptchaChallenge = Pattern.compile("challenge : '([^']+)'",
            Pattern.CASE_INSENSITIVE);

    caches.viewstates = getViewstates(page);

    // recaptcha
    if (showCaptcha) {
        try {
            String recaptchaJsParam = null;
            final Matcher matcherRecaptcha = patternRecaptcha.matcher(page);
            while (matcherRecaptcha.find()) {
                if (matcherRecaptcha.groupCount() > 0) {
                    recaptchaJsParam = matcherRecaptcha.group(1);
                }
            }

            if (recaptchaJsParam != null) {
                final String recaptchaJs = request(false, "www.google.com", "/recaptcha/api/challenge", "GET",
                        "k=" + urlencode_rfc3986(recaptchaJsParam.trim()), 0, true).getData();

                if (StringUtils.isNotBlank(recaptchaJs)) {
                    final Matcher matcherRecaptchaChallenge = patternRecaptchaChallenge.matcher(recaptchaJs);
                    while (matcherRecaptchaChallenge.find()) {
                        if (matcherRecaptchaChallenge.groupCount() > 0) {
                            recaptchaChallenge = matcherRecaptchaChallenge.group(1).trim();
                        }
                    }
                }
            }
        } catch (Exception e) {
            // failed to parse recaptcha challenge
            Log.w(cgSettings.tag, "cgeoBase.parseSearch: Failed to parse recaptcha challenge");
        }

        if (thread != null && StringUtils.isNotBlank(recaptchaChallenge)) {
            thread.setChallenge(recaptchaChallenge);
            thread.notifyNeed();
        }
    }

    if (!page.contains("SearchResultsTable")) {
        // there are no results. aborting here avoids a wrong error log in the next parsing step
        return caches;
    }

    int startPos = page.indexOf("<div id=\"ctl00_ContentBody_ResultsPanel\"");
    if (startPos == -1) {
        Log.e(cgSettings.tag, "cgeoBase.parseSearch: ID \"ctl00_ContentBody_dlResults\" not found on page");
        return null;
    }

    page = page.substring(startPos); // cut on <table

    startPos = page.indexOf(">");
    int endPos = page.indexOf("ctl00_ContentBody_UnitTxt");
    if (startPos == -1 || endPos == -1) {
        Log.e(cgSettings.tag, "cgeoBase.parseSearch: ID \"ctl00_ContentBody_UnitTxt\" not found on page");
        return null;
    }

    page = page.substring(startPos + 1, endPos - startPos + 1); // cut between <table> and </table>

    final String[] rows = page.split("<tr class=");
    final int rows_count = rows.length;

    for (int z = 1; z < rows_count; z++) {
        cgCache cache = new cgCache();
        String row = rows[z];

        // check for cache type presence
        if (!row.contains("images/wpttypes")) {
            continue;
        }

        try {
            final Matcher matcherGuidAndDisabled = patternGuidAndDisabled.matcher(row);

            while (matcherGuidAndDisabled.find()) {
                if (matcherGuidAndDisabled.groupCount() > 0) {
                    guids.add(matcherGuidAndDisabled.group(1));

                    cache.guid = matcherGuidAndDisabled.group(1);
                    if (matcherGuidAndDisabled.group(4) != null) {
                        cache.name = Html.fromHtml(matcherGuidAndDisabled.group(4).trim()).toString();
                    }
                    if (matcherGuidAndDisabled.group(6) != null) {
                        cache.location = Html.fromHtml(matcherGuidAndDisabled.group(6).trim()).toString();
                    }

                    final String attr = matcherGuidAndDisabled.group(2);
                    if (attr != null) {
                        if (attr.contains("Strike")) {
                            cache.disabled = true;
                        } else {
                            cache.disabled = false;
                        }

                        if (attr.contains("OldWarning")) {
                            cache.archived = true;
                        } else {
                            cache.archived = false;
                        }
                    }
                }
            }
        } catch (Exception e) {
            // failed to parse GUID and/or Disabled
            Log.w(cgSettings.tag, "cgeoBase.parseSearch: Failed to parse GUID and/or Disabled data");
        }

        if (settings.excludeDisabled == 1 && (cache.disabled || cache.archived)) {
            // skip disabled and archived caches
            cache = null;
            continue;
        }

        String inventoryPre = null;

        // GC* code
        try {
            final Matcher matcherCode = patternCode.matcher(row);
            while (matcherCode.find()) {
                if (matcherCode.groupCount() > 0) {
                    cache.geocode = matcherCode.group(1).toUpperCase();
                }
            }
        } catch (Exception e) {
            // failed to parse code
            Log.w(cgSettings.tag, "cgeoBase.parseSearch: Failed to parse cache code");
        }

        // cache type
        try {
            final Matcher matcherCacheType = patternCacheType.matcher(row);
            while (matcherCacheType.find()) {
                if (matcherCacheType.groupCount() > 0) {
                    cache.type = cacheTypes.get(matcherCacheType.group(1).toLowerCase());
                }
            }
        } catch (Exception e) {
            // failed to parse type
            Log.w(cgSettings.tag, "cgeoBase.parseSearch: Failed to parse cache type");
        }

        // cache direction - image
        if (settings.getLoadDirImg()) {
            try {
                final Matcher matcherDirection = patternDirection.matcher(row);
                while (matcherDirection.find()) {
                    if (matcherDirection.groupCount() > 0) {
                        cache.directionImg = matcherDirection.group(1);
                    }
                }
            } catch (Exception e) {
                // failed to parse direction image
                Log.w(cgSettings.tag, "cgeoBase.parseSearch: Failed to parse cache direction image");
            }
        }

        // cache inventory
        try {
            final Matcher matcherTbs = patternTbs.matcher(row);
            while (matcherTbs.find()) {
                if (matcherTbs.groupCount() > 0) {
                    cache.inventoryItems = Integer.parseInt(matcherTbs.group(1));
                    inventoryPre = matcherTbs.group(2);
                }
            }
        } catch (Exception e) {
            // failed to parse inventory
            Log.w(cgSettings.tag, "cgeoBase.parseSearch: Failed to parse cache inventory (1)");
        }

        if (StringUtils.isNotBlank(inventoryPre)) {
            try {
                final Matcher matcherTbsInside = patternTbsInside.matcher(inventoryPre);
                while (matcherTbsInside.find()) {
                    if (matcherTbsInside.groupCount() == 2 && matcherTbsInside.group(2) != null) {
                        final String inventoryItem = matcherTbsInside.group(2).toLowerCase();
                        if (inventoryItem.equals("premium member only cache")) {
                            continue;
                        } else {
                            if (cache.inventoryItems <= 0) {
                                cache.inventoryItems = 1;
                            }
                        }
                    }
                }
            } catch (Exception e) {
                // failed to parse cache inventory info
                Log.w(cgSettings.tag, "cgeoBase.parseSearch: Failed to parse cache inventory info");
            }
        }

        // premium cache
        cache.members = row.contains("/images/small_profile.gif");

        // found it
        cache.found = row.contains("/images/icons/icon_smile");

        // own it
        cache.own = row.contains("/images/silk/star.png");

        // id
        try {
            final Matcher matcherId = patternId.matcher(row);
            while (matcherId.find()) {
                if (matcherId.groupCount() > 0) {
                    cache.cacheId = matcherId.group(1);
                    cids.add(cache.cacheId);
                }
            }
        } catch (Exception e) {
            // failed to parse cache id
            Log.w(cgSettings.tag, "cgeoBase.parseSearch: Failed to parse cache id");
        }

        // favourite count
        try {
            final Matcher matcherFavourite = patternFavourite.matcher(row);
            while (matcherFavourite.find()) {
                if (matcherFavourite.groupCount() > 0) {
                    cache.favouriteCnt = Integer.parseInt(matcherFavourite.group(1));
                }
            }
        } catch (Exception e) {
            // failed to parse favourite count
            Log.w(cgSettings.tag, "cgeoBase.parseSearch: Failed to parse favourite count");
        }

        if (cache.nameSp == null) {
            cache.nameSp = (new Spannable.Factory()).newSpannable(cache.name);
            if (cache.disabled || cache.archived) { // strike
                cache.nameSp.setSpan(new StrikethroughSpan(), 0, cache.nameSp.toString().length(),
                        Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
            }
        }

        caches.cacheList.add(cache);
    }

    // total caches found
    try {
        final Matcher matcherTotalCnt = patternTotalCnt.matcher(page);
        while (matcherTotalCnt.find()) {
            if (matcherTotalCnt.groupCount() > 0) {
                if (matcherTotalCnt.group(1) != null) {
                    caches.totalCnt = Integer.valueOf(matcherTotalCnt.group(1));
                }
            }
        }
    } catch (Exception e) {
        // failed to parse cache count
        Log.w(cgSettings.tag, "cgeoBase.parseSearch: Failed to parse cache count");
    }

    if (thread != null && recaptchaChallenge != null) {
        if (thread.getText() == null) {
            thread.waitForUser();
        }

        recaptchaText = thread.getText();
    }

    if (cids.size() > 0 && (recaptchaChallenge == null
            || (recaptchaChallenge != null && StringUtils.isNotBlank(recaptchaText)))) {
        Log.i(cgSettings.tag, "Trying to get .loc for " + cids.size() + " caches");

        try {
            // get coordinates for parsed caches
            final String host = "www.geocaching.com";
            final String path = "/seek/nearest.aspx";
            final StringBuilder params = new StringBuilder();
            params.append("__EVENTTARGET=&__EVENTARGUMENT=");
            if (ArrayUtils.isNotEmpty(caches.viewstates)) {
                params.append("&__VIEWSTATE=");
                params.append(urlencode_rfc3986(caches.viewstates[0]));
                if (caches.viewstates.length > 1) {
                    for (int i = 1; i < caches.viewstates.length; i++) {
                        params.append("&__VIEWSTATE" + i + "=");
                        params.append(urlencode_rfc3986(caches.viewstates[i]));
                    }
                    params.append("&__VIEWSTATEFIELDCOUNT=" + caches.viewstates.length);
                }
            }
            for (String cid : cids) {
                params.append("&CID=");
                params.append(urlencode_rfc3986(cid));
            }

            if (recaptchaChallenge != null && StringUtils.isNotBlank(recaptchaText)) {
                params.append("&recaptcha_challenge_field=");
                params.append(urlencode_rfc3986(recaptchaChallenge));
                params.append("&recaptcha_response_field=");
                params.append(urlencode_rfc3986(recaptchaText));
            }
            params.append("&ctl00%24ContentBody%24uxDownloadLoc=Download+Waypoints");

            final String coordinates = request(false, host, path, "POST", params.toString(), 0, true).getData();

            if (StringUtils.isNotBlank(coordinates)) {
                if (coordinates.contains(
                        "You have not agreed to the license agreement. The license agreement is required before you can start downloading GPX or LOC files from Geocaching.com")) {
                    Log.i(cgSettings.tag,
                            "User has not agreed to the license agreement. Can\'t download .loc file.");

                    caches.error = errorRetrieve.get(-7);

                    return caches;
                }
            }

            LocParser.parseLoc(caches, coordinates);
        } catch (Exception e) {
            Log.e(cgSettings.tag, "cgBase.parseSearch.CIDs: " + e.toString());
        }
    }

    // get direction images
    if (settings.getLoadDirImg()) {
        for (cgCache oneCache : caches.cacheList) {
            if (oneCache.coords == null && oneCache.directionImg != null) {
                cgDirectionImg.getDrawable(oneCache.geocode, oneCache.directionImg);
            }
        }
    }

    // get ratings
    if (guids.size() > 0) {
        Log.i(cgSettings.tag, "Trying to get ratings for " + cids.size() + " caches");

        try {
            final Map<String, cgRating> ratings = getRating(guids, null);

            if (CollectionUtils.isNotEmpty(ratings)) {
                // save found cache coordinates
                for (cgCache oneCache : caches.cacheList) {
                    if (ratings.containsKey(oneCache.guid)) {
                        cgRating thisRating = ratings.get(oneCache.guid);

                        oneCache.rating = thisRating.rating;
                        oneCache.votes = thisRating.votes;
                        oneCache.myVote = thisRating.myVote;
                    }
                }
            }
        } catch (Exception e) {
            Log.e(cgSettings.tag, "cgBase.parseSearch.GCvote: " + e.toString());
        }
    }

    return caches;
}

From source file:com.android.messaging.datamodel.MessageNotificationState.java

private static CharSequence convertHtmlAndStripUrls(final String s) {
    final Spanned text = Html.fromHtml(s);
    if (text instanceof Spannable) {
        stripUrls((Spannable) text);/* w  w w . ja v a  2  s.c o  m*/
    }
    return text;
}

From source file:com.vuze.android.remote.SessionInfo.java

private void openTorrent_perms(Activity activity, Uri uri) {
    try {/*from   www  . j a va  2  s . c o m*/
        InputStream stream = null;
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
            String realPath = PaulBurkeFileUtils.getPath(activity, uri);
            if (realPath != null) {
                String meh = realPath.startsWith("/") ? "file://" + realPath : realPath;
                stream = activity.getContentResolver().openInputStream(Uri.parse(meh));
            }
        }
        if (stream == null) {
            ContentResolver contentResolver = activity.getContentResolver();
            stream = contentResolver.openInputStream(uri);
        }
        openTorrent(activity, uri.toString(), stream);
    } catch (SecurityException e) {
        if (AndroidUtils.DEBUG) {
            e.printStackTrace();
        }
        VuzeEasyTracker.getInstance(activity).logError(e);
        String s = "Security Exception trying to access <b>" + uri + "</b>";
        Toast.makeText(activity, Html.fromHtml(s), Toast.LENGTH_LONG).show();
    } catch (FileNotFoundException e) {
        if (AndroidUtils.DEBUG) {
            e.printStackTrace();
        }
        VuzeEasyTracker.getInstance(activity).logError(e);
        String s = "<b>" + uri + "</b> not found";
        if (e.getCause() != null) {
            s += ". " + e.getCause().getMessage();
        }
        Toast.makeText(activity, Html.fromHtml(s), Toast.LENGTH_LONG).show();
    }
}

From source file:com.bookkos.bircle.CaptureActivity.java

private void customToast(String toast_text, int icon, boolean bool) {
    getLayoutInflater();//from w w  w . j av a2s  .c  o m
    LayoutInflater inflater = getLayoutInflater();

    int resource = 0;

    if (bool == true) {
        resource = R.layout.success_toast;
    } else {
        resource = R.layout.failure_toast;
    }

    View layout = inflater.inflate(resource, null);
    ImageView image = (ImageView) layout.findViewById(R.id.image);
    image.setImageResource(icon);

    TextView text = (TextView) layout.findViewById(R.id.text);
    text.setText(Html.fromHtml(toast_text));

    final Toast toast = new Toast(this);

    layout.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            toast.cancel();
        }
    });

    toast.setView(layout);
    toast.setGravity(Gravity.CENTER, 0, 0);
    if (modeFlag == true) {
        toast.setDuration(Toast.LENGTH_SHORT);
    } else {
        toast.setDuration(Toast.LENGTH_LONG);
    }
    toast.show();

    //      Toast.makeText(context, toast_text, Toast.LENGTH_SHORT).show();
}

From source file:com.hichinaschool.flashcards.anki.StudyOptionsFragment.java

private void updateValuesFromDeck(boolean reset) {
    String fullName;//from  ww w  . j a  va  2  s. c  o  m
    if (!AnkiDroidApp.colIsOpen()) {
        return;
    }
    JSONObject deck = AnkiDroidApp.getCol().getDecks().current();
    try {
        fullName = deck.getString("name");
        String[] name = fullName.split("::");
        StringBuilder nameBuilder = new StringBuilder();
        if (name.length > 0) {
            nameBuilder.append(name[0]);
        }
        if (name.length > 1) {
            nameBuilder.append("\n").append(name[1]);
        }
        if (name.length > 3) {
            nameBuilder.append("...");
        }
        if (name.length > 2) {
            nameBuilder.append("\n").append(name[name.length - 1]);
        }
        mTextDeckName.setText(nameBuilder.toString());

        // open cram deck option if deck is opened for the first time
        if (mCramInitialConfig != null) {
            openCramDeckOptions(mCramInitialConfig);
            return;
        }
    } catch (JSONException e) {
        throw new RuntimeException(e);
    }

    if (!mFragmented) {
        getActivity().setTitle(fullName);
    }

    String desc;
    try {
        if (deck.getInt("dyn") == 0) {
            desc = AnkiDroidApp.getCol().getDecks().getActualDescription();
            mTextDeckDescription.setMaxLines(3);
        } else {
            desc = getResources().getString(R.string.dyn_deck_desc);
            mTextDeckDescription.setMaxLines(5);
        }
    } catch (JSONException e) {
        throw new RuntimeException(e);
    }
    if (desc.length() > 0) {
        mTextDeckDescription.setText(Html.fromHtml(desc));
        mTextDeckDescription.setVisibility(View.VISIBLE);
    } else {
        mTextDeckDescription.setVisibility(View.GONE);
    }

    DeckTask.launchDeckTask(DeckTask.TASK_TYPE_UPDATE_VALUES_FROM_DECK, mUpdateValuesFromDeckListener,
            new DeckTask.TaskData(AnkiDroidApp.getCol(), new Object[] { reset, mSmallChart != null }));
}

From source file:de.geeksfactory.opacclient.frontend.AccountFragment.java

private void setHtmlTextOrHide(String value, TextView tv) {
    if (!TextUtils.isEmpty(value)) {
        tv.setText(Html.fromHtml(value));
    } else {/*from   w ww. j  a v  a2  s  .  c  o m*/
        tv.setVisibility(View.GONE);
    }
}

From source file:com.klinker.android.twitter.utils.NotificationUtils.java

public static void newInteractions(User interactor, Context context, SharedPreferences sharedPrefs,
        String type) {/* ww  w .  j  a v a2 s . c  o  m*/
    String title = "";
    String text = "";
    String smallText = "";
    Bitmap icon = null;

    AppSettings settings = AppSettings.getInstance(context);

    Intent resultIntent = new Intent(context, RedirectToDrawer.class);
    PendingIntent resultPendingIntent = PendingIntent.getActivity(context, 0, resultIntent, 0);

    int newFollowers = sharedPrefs.getInt("new_followers", 0);
    int newRetweets = sharedPrefs.getInt("new_retweets", 0);
    int newFavorites = sharedPrefs.getInt("new_favorites", 0);
    int newQuotes = sharedPrefs.getInt("new_quotes", 0);

    // set title
    if (newFavorites + newRetweets + newFollowers > 1) {
        title = context.getResources().getString(R.string.new_interactions);
    } else {
        title = context.getResources().getString(R.string.new_interaction_upper);
    }

    // set text
    String currText = sharedPrefs.getString("old_interaction_text", "");
    if (!currText.equals("")) {
        currText += "<br>";
    }
    if (settings.displayScreenName) {
        text = currText + "<b>" + interactor.getScreenName() + "</b> " + type;
    } else {
        text = currText + "<b>" + interactor.getName() + "</b> " + type;
    }
    sharedPrefs.edit().putString("old_interaction_text", text).commit();

    // set icon
    int types = 0;
    if (newFavorites > 0) {
        types++;
    }
    if (newFollowers > 0) {
        types++;
    }
    if (newRetweets > 0) {
        types++;
    }
    if (newQuotes > 0) {
        types++;
    }

    if (types > 1) {
        icon = BitmapFactory.decodeResource(context.getResources(), R.drawable.ic_stat_icon);
    } else {
        if (newFavorites > 0) {
            icon = BitmapFactory.decodeResource(context.getResources(), R.drawable.ic_heart_dark);
        } else if (newRetweets > 0) {
            icon = BitmapFactory.decodeResource(context.getResources(), R.drawable.ic_action_repeat_dark);
        } else {
            icon = BitmapFactory.decodeResource(context.getResources(), R.drawable.drawer_user_dark);
        }
    }

    // set shorter text
    int total = newFavorites + newFollowers + newRetweets + newQuotes;
    if (total > 1) {
        smallText = total + " " + context.getResources().getString(R.string.new_interactions_lower);
    } else {
        smallText = text;
    }

    Intent markRead = new Intent(context, ReadInteractionsService.class);
    PendingIntent readPending = PendingIntent.getService(context, 0, markRead, 0);

    Intent deleteIntent = new Intent(context, NotificationDeleteReceiverOne.class);

    NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context).setContentTitle(title)
            .setContentText(Html.fromHtml(
                    settings.addonTheme ? smallText.replaceAll("FF8800", settings.accentColor) : smallText))
            .setSmallIcon(R.drawable.ic_stat_icon).setLargeIcon(icon).setContentIntent(resultPendingIntent)
            .setTicker(title).setDeleteIntent(PendingIntent.getBroadcast(context, 0, deleteIntent, 0))
            .setPriority(NotificationCompat.PRIORITY_HIGH).setAutoCancel(true);

    if (context.getResources().getBoolean(R.bool.expNotifications)) {
        mBuilder.setStyle(new NotificationCompat.BigTextStyle().bigText(
                Html.fromHtml(settings.addonTheme ? text.replaceAll("FF8800", settings.accentColor) : text)));
    }

    if (settings.vibrate) {
        mBuilder.setDefaults(Notification.DEFAULT_VIBRATE);
    }

    if (settings.sound) {
        try {
            mBuilder.setSound(Uri.parse(settings.ringtone));
        } catch (Exception e) {
            mBuilder.setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION));
        }
    }

    if (settings.led)
        mBuilder.setLights(0xFFFFFF, 1000, 1000);

    if (settings.notifications) {

        NotificationManagerCompat notificationManager = NotificationManagerCompat.from(context);

        notificationManager.notify(4, mBuilder.build());

        // if we want to wake the screen on a new message
        if (settings.wakeScreen) {
            PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
            final PowerManager.WakeLock wakeLock = pm.newWakeLock((PowerManager.SCREEN_BRIGHT_WAKE_LOCK
                    | PowerManager.FULL_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP), "TAG");
            wakeLock.acquire(5000);
        }

        // Pebble notification
        if (sharedPrefs.getBoolean("pebble_notification", false)) {
            sendAlertToPebble(context, title, text);
        }

        // Light Flow notification
        sendToLightFlow(context, title, text);
    }
}