Example usage for android.text.method LinkMovementMethod getInstance

List of usage examples for android.text.method LinkMovementMethod getInstance

Introduction

In this page you can find the example usage for android.text.method LinkMovementMethod getInstance.

Prototype

public static MovementMethod getInstance() 

Source Link

Usage

From source file:com.gelakinetic.mtgfam.fragments.CardViewFragment.java

/**
 * This will fill the UI elements with information from the database
 * It also saves information for AsyncTasks to use later and manages the transform/flip button
 *
 * @param id the ID of the the card to be displayed
 * @return true if the UI was filled in, false otherwise
 *//*from   w ww  .  j a  v a2 s .  c  om*/
public void setInfoFromID(final long id) {

    /* If the views are null, don't attempt to fill them in */
    if (mSetTextView == null) {
        return;
    }

    ImageGetter imgGetter = ImageGetterHelper.GlyphGetter(getActivity());

    SQLiteDatabase database = DatabaseManager.getInstance(getActivity(), false).openDatabase(false);
    Cursor cCardById;
    try {
        cCardById = CardDbAdapter.fetchCards(new long[] { id }, null, database);
    } catch (FamiliarDbException e) {
        handleFamiliarDbException(true);
        DatabaseManager.getInstance(getActivity(), false).closeDatabase(false);
        return;
    }

    /* http://magiccards.info/scans/en/mt/55.jpg */
    mCardName = cCardById.getString(cCardById.getColumnIndex(CardDbAdapter.KEY_NAME));
    mCardCMC = cCardById.getInt(cCardById.getColumnIndex(CardDbAdapter.KEY_CMC));
    mSetCode = cCardById.getString(cCardById.getColumnIndex(CardDbAdapter.KEY_SET));

    /* Start building a description */
    addToDescription(getString(R.string.search_name), mCardName);
    try {
        mSetName = CardDbAdapter.getSetNameFromCode(mSetCode, database);
        addToDescription(getString(R.string.search_set), mSetName);
    } catch (FamiliarDbException e) {
        /* no set for you */
    }

    try {
        mMagicCardsInfoSetCode = CardDbAdapter
                .getCodeMtgi(cCardById.getString(cCardById.getColumnIndex(CardDbAdapter.KEY_SET)), database);
    } catch (FamiliarDbException e) {
        handleFamiliarDbException(true);
        DatabaseManager.getInstance(getActivity(), false).closeDatabase(false);
        return;
    }
    mCardNumber = cCardById.getString(cCardById.getColumnIndex(CardDbAdapter.KEY_NUMBER));

    switch ((char) cCardById.getInt(cCardById.getColumnIndex(CardDbAdapter.KEY_RARITY))) {
    case 'C':
    case 'c':
        mSetTextView
                .setTextColor(ContextCompat.getColor(getContext(), getResourceIdFromAttr(R.attr.color_common)));
        addToDescription(getString(R.string.search_rarity), getString(R.string.search_Common));
        break;
    case 'U':
    case 'u':
        mSetTextView.setTextColor(
                ContextCompat.getColor(getContext(), getResourceIdFromAttr(R.attr.color_uncommon)));
        addToDescription(getString(R.string.search_rarity), getString(R.string.search_Uncommon));
        break;
    case 'R':
    case 'r':
        mSetTextView
                .setTextColor(ContextCompat.getColor(getContext(), getResourceIdFromAttr(R.attr.color_rare)));
        addToDescription(getString(R.string.search_rarity), getString(R.string.search_Rare));
        break;
    case 'M':
    case 'm':
        mSetTextView
                .setTextColor(ContextCompat.getColor(getContext(), getResourceIdFromAttr(R.attr.color_mythic)));
        addToDescription(getString(R.string.search_rarity), getString(R.string.search_Mythic));
        break;
    case 'T':
    case 't':
        mSetTextView.setTextColor(
                ContextCompat.getColor(getContext(), getResourceIdFromAttr(R.attr.color_timeshifted)));
        addToDescription(getString(R.string.search_rarity), getString(R.string.search_Timeshifted));
        break;
    }

    String sCost = cCardById.getString(cCardById.getColumnIndex(CardDbAdapter.KEY_MANACOST));
    addToDescription(getString(R.string.search_mana_cost), sCost);
    CharSequence csCost = ImageGetterHelper.formatStringWithGlyphs(sCost, imgGetter);
    mCostTextView.setText(csCost);

    String sAbility = cCardById.getString(cCardById.getColumnIndex(CardDbAdapter.KEY_ABILITY));
    addToDescription(getString(R.string.search_text), sAbility);
    CharSequence csAbility = ImageGetterHelper.formatStringWithGlyphs(sAbility, imgGetter);
    mAbilityTextView.setText(csAbility);
    mAbilityTextView.setMovementMethod(LinkMovementMethod.getInstance());

    String sFlavor = cCardById.getString(cCardById.getColumnIndex(CardDbAdapter.KEY_FLAVOR));
    addToDescription(getString(R.string.search_flavor_text), sFlavor);
    CharSequence csFlavor = ImageGetterHelper.formatStringWithGlyphs(sFlavor, imgGetter);
    mFlavorTextView.setText(csFlavor);

    mNameTextView.setText(cCardById.getString(cCardById.getColumnIndex(CardDbAdapter.KEY_NAME)));
    mCardType = CardDbAdapter.getTypeLine(cCardById);
    mTypeTextView.setText(mCardType);
    mSetTextView.setText(cCardById.getString(cCardById.getColumnIndex(CardDbAdapter.KEY_SET)));
    mArtistTextView.setText(cCardById.getString(cCardById.getColumnIndex(CardDbAdapter.KEY_ARTIST)));
    String numberAndRarity = cCardById.getString(cCardById.getColumnIndex(CardDbAdapter.KEY_NUMBER)) + " ("
            + (char) cCardById.getInt(cCardById.getColumnIndex(CardDbAdapter.KEY_RARITY)) + ")";
    mNumberTextView.setText(numberAndRarity);

    addToDescription(getString(R.string.search_type), CardDbAdapter.getTypeLine(cCardById));
    addToDescription(getString(R.string.search_artist),
            cCardById.getString(cCardById.getColumnIndex(CardDbAdapter.KEY_ARTIST)));
    addToDescription(getString(R.string.search_collectors_number),
            cCardById.getString(cCardById.getColumnIndex(CardDbAdapter.KEY_NUMBER)));

    int loyalty = cCardById.getInt(cCardById.getColumnIndex(CardDbAdapter.KEY_LOYALTY));
    float p = cCardById.getFloat(cCardById.getColumnIndex(CardDbAdapter.KEY_POWER));
    float t = cCardById.getFloat(cCardById.getColumnIndex(CardDbAdapter.KEY_TOUGHNESS));
    if (loyalty != CardDbAdapter.NO_ONE_CARES) {
        if (loyalty == CardDbAdapter.X) {
            mPowTouTextView.setText("X");
        } else {
            mPowTouTextView.setText(Integer.valueOf(loyalty).toString());
        }
    } else if (p != CardDbAdapter.NO_ONE_CARES && t != CardDbAdapter.NO_ONE_CARES) {

        String powTouStr = "";

        if (p == CardDbAdapter.STAR)
            powTouStr += "*";
        else if (p == CardDbAdapter.ONE_PLUS_STAR)
            powTouStr += "1+*";
        else if (p == CardDbAdapter.TWO_PLUS_STAR)
            powTouStr += "2+*";
        else if (p == CardDbAdapter.SEVEN_MINUS_STAR)
            powTouStr += "7-*";
        else if (p == CardDbAdapter.STAR_SQUARED)
            powTouStr += "*^2";
        else if (p == CardDbAdapter.X)
            powTouStr += "X";
        else {
            if (p == (int) p) {
                powTouStr += (int) p;
            } else {
                powTouStr += p;
            }
        }

        powTouStr += "/";

        if (t == CardDbAdapter.STAR)
            powTouStr += "*";
        else if (t == CardDbAdapter.ONE_PLUS_STAR)
            powTouStr += "1+*";
        else if (t == CardDbAdapter.TWO_PLUS_STAR)
            powTouStr += "2+*";
        else if (t == CardDbAdapter.SEVEN_MINUS_STAR)
            powTouStr += "7-*";
        else if (t == CardDbAdapter.STAR_SQUARED)
            powTouStr += "*^2";
        else if (t == CardDbAdapter.X)
            powTouStr += "X";
        else {
            if (t == (int) t) {
                powTouStr += (int) t;
            } else {
                powTouStr += t;
            }
        }

        addToDescription(getString(R.string.search_power), powTouStr);

        mPowTouTextView.setText(powTouStr);
    } else {
        mPowTouTextView.setText("");
    }

    boolean isMultiCard = false;
    switch (CardDbAdapter.isMultiCard(mCardNumber,
            cCardById.getString(cCardById.getColumnIndex(CardDbAdapter.KEY_SET)))) {
    case NOPE:
        isMultiCard = false;
        mTransformButton.setVisibility(View.GONE);
        mTransformButtonDivider.setVisibility(View.GONE);
        break;
    case TRANSFORM:
        isMultiCard = true;
        mTransformButton.setVisibility(View.VISIBLE);
        mTransformButtonDivider.setVisibility(View.VISIBLE);
        mTransformButton.setText(R.string.card_view_transform);
        break;
    case FUSE:
        isMultiCard = true;
        mTransformButton.setVisibility(View.VISIBLE);
        mTransformButtonDivider.setVisibility(View.VISIBLE);
        mTransformButton.setText(R.string.card_view_fuse);
        break;
    case SPLIT:
        isMultiCard = true;
        mTransformButton.setVisibility(View.VISIBLE);
        mTransformButtonDivider.setVisibility(View.VISIBLE);
        mTransformButton.setText(R.string.card_view_other_half);
        break;
    }

    if (isMultiCard) {
        if (mCardNumber.contains("a")) {
            mTransformCardNumber = mCardNumber.replace("a", "b");
        } else if (mCardNumber.contains("b")) {
            mTransformCardNumber = mCardNumber.replace("b", "a");
        }
        try {
            mTransformId = CardDbAdapter.getIdFromSetAndNumber(mSetCode, mTransformCardNumber, database);
        } catch (FamiliarDbException e) {
            handleFamiliarDbException(true);
            DatabaseManager.getInstance(getActivity(), false).closeDatabase(false);
            return;
        }
        if (mTransformId == -1) {
            mTransformButton.setVisibility(View.GONE);
            mTransformButtonDivider.setVisibility(View.GONE);
        } else {
            mTransformButton.setOnClickListener(new View.OnClickListener() {
                public void onClick(View v) {
                    releaseImageResources(true);
                    mCardNumber = mTransformCardNumber;
                    setInfoFromID(mTransformId);
                }
            });
        }
    }

    mMultiverseId = cCardById.getInt(cCardById.getColumnIndex(CardDbAdapter.KEY_MULTIVERSEID));

    /* Do we load the image immediately to the main page, or do it in a dialog later? */
    if (mActivity.mPreferenceAdapter.getPicFirst()) {
        mImageScrollView.setVisibility(View.VISIBLE);
        mTextScrollView.setVisibility(View.GONE);

        mActivity.setLoading();
        if (mAsyncTask != null) {
            mAsyncTask.cancel(true);
        }
        mAsyncTask = new FetchPictureTask();
        ((FetchPictureTask) mAsyncTask).execute(MAIN_PAGE);
    } else {
        mImageScrollView.setVisibility(View.GONE);
        mTextScrollView.setVisibility(View.VISIBLE);
    }

    /* Figure out how large the color indicator should be. Medium text is 18sp, with a border its 22sp */
    int dimension = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, 22,
            getResources().getDisplayMetrics());

    mColorIndicatorLayout.removeAllViews();
    ColorIndicatorView civ = new ColorIndicatorView(this.getActivity(), dimension, dimension / 15,
            cCardById.getString(cCardById.getColumnIndex(CardDbAdapter.KEY_COLOR)), sCost);
    if (civ.shouldInidcatorBeShown()) {
        mColorIndicatorLayout.setVisibility(View.VISIBLE);
        mColorIndicatorLayout.addView(civ);
    } else {
        mColorIndicatorLayout.setVisibility(View.GONE);
    }

    String allLanguageKeys[][] = {
            { Language.Chinese_Traditional, CardDbAdapter.KEY_NAME_CHINESE_TRADITIONAL,
                    CardDbAdapter.KEY_MULTIVERSEID_CHINESE_TRADITIONAL },
            { Language.Chinese_Simplified, CardDbAdapter.KEY_NAME_CHINESE_SIMPLIFIED,
                    CardDbAdapter.KEY_MULTIVERSEID_CHINESE_SIMPLIFIED },
            { Language.French, CardDbAdapter.KEY_NAME_FRENCH, CardDbAdapter.KEY_MULTIVERSEID_FRENCH },
            { Language.German, CardDbAdapter.KEY_NAME_GERMAN, CardDbAdapter.KEY_MULTIVERSEID_GERMAN },
            { Language.Italian, CardDbAdapter.KEY_NAME_ITALIAN, CardDbAdapter.KEY_MULTIVERSEID_ITALIAN },
            { Language.Japanese, CardDbAdapter.KEY_NAME_JAPANESE, CardDbAdapter.KEY_MULTIVERSEID_JAPANESE },
            { Language.Portuguese_Brazil, CardDbAdapter.KEY_NAME_PORTUGUESE_BRAZIL,
                    CardDbAdapter.KEY_MULTIVERSEID_PORTUGUESE_BRAZIL },
            { Language.Russian, CardDbAdapter.KEY_NAME_RUSSIAN, CardDbAdapter.KEY_MULTIVERSEID_RUSSIAN },
            { Language.Spanish, CardDbAdapter.KEY_NAME_SPANISH, CardDbAdapter.KEY_MULTIVERSEID_SPANISH },
            { Language.Korean, CardDbAdapter.KEY_NAME_KOREAN, CardDbAdapter.KEY_MULTIVERSEID_KOREAN } };

    // Clear the translations first
    mTranslatedNames.clear();

    // Add English
    Card.ForeignPrinting englishPrinting = new Card.ForeignPrinting();
    englishPrinting.mLanguageCode = Language.English;
    englishPrinting.mName = mCardName;
    englishPrinting.mMultiverseId = mMultiverseId;
    mTranslatedNames.add(englishPrinting);

    // Add all the others
    for (String lang[] : allLanguageKeys) {
        Card.ForeignPrinting fp = new Card.ForeignPrinting();
        fp.mLanguageCode = lang[0];
        fp.mName = cCardById.getString(cCardById.getColumnIndex(lang[1]));
        fp.mMultiverseId = cCardById.getInt(cCardById.getColumnIndex(lang[2]));
        if (fp.mName != null && !fp.mName.isEmpty()) {
            mTranslatedNames.add(fp);
        }
    }

    cCardById.close();

    /* Find the other sets this card is in ahead of time, so that it can be remove from the menu if there is only
       one set */
    Cursor cCardByName;
    try {
        cCardByName = CardDbAdapter.fetchCardByName(mCardName,
                new String[] { CardDbAdapter.DATABASE_TABLE_CARDS + "." + CardDbAdapter.KEY_SET,
                        CardDbAdapter.DATABASE_TABLE_CARDS + "." + CardDbAdapter.KEY_ID,
                        CardDbAdapter.DATABASE_TABLE_CARDS + "." + CardDbAdapter.KEY_NUMBER },
                false, database);
    } catch (FamiliarDbException e) {
        handleFamiliarDbException(true);
        DatabaseManager.getInstance(getActivity(), false).closeDatabase(false);
        return;
    }
    mPrintings = new LinkedHashSet<>();
    mCardIds = new LinkedHashSet<>();
    while (!cCardByName.isAfterLast()) {
        try {
            String number = cCardByName.getString(cCardByName.getColumnIndex(CardDbAdapter.KEY_NUMBER));
            if (!(number == null || number.length() == 0)) {
                number = " (" + number + ")";
            } else {
                number = "";
            }
            if (mPrintings.add(CardDbAdapter.getSetNameFromCode(
                    cCardByName.getString(cCardByName.getColumnIndex(CardDbAdapter.KEY_SET)), database)
                    + number)) {
                mCardIds.add(cCardByName.getLong(cCardByName.getColumnIndex(CardDbAdapter.KEY_ID)));
            }
        } catch (FamiliarDbException e) {
            handleFamiliarDbException(true);
            DatabaseManager.getInstance(getActivity(), false).closeDatabase(false);
            return;
        }
        cCardByName.moveToNext();
    }
    cCardByName.close();
    /* If it exists in only one set, remove the button from the menu */
    if (mPrintings.size() == 1) {
        mActivity.supportInvalidateOptionsMenu();
    }
    DatabaseManager.getInstance(getActivity(), false).closeDatabase(false);

    if (mShouldReportView) {
        reportAppIndexViewIfAble();
    }
}

From source file:com.gelakinetic.selfr.CameraActivity.java

/**
 * Build a dialog, currently only the about dialog
 *
 * @param id An ID corresponding to the dialog to be shown
 * @return A Dialog to be displayed by the system
 *//*from  w w w  . j av  a 2 s.  c  om*/
@Override
protected Dialog onCreateDialog(int id) {
    switch (id) {
    case DIALOG_ABOUT: {
        /* Make a new builder */
        AlertDialog.Builder builder = new AlertDialog.Builder(CameraActivity.this);

        /* Inflate the dialog view */
        View dialogView = View.inflate(CameraActivity.this, R.layout.about_dialog, null);

        /* Set the title */
        String title;
        try {
            title = getString(R.string.app_name) + " "
                    + getPackageManager().getPackageInfo(getPackageName(), 0).versionName;
        } catch (PackageManager.NameNotFoundException e) {
            title = getString(R.string.app_name);
        }
        builder.setTitle(title);

        /* Set the text, with links enabled */
        TextView dialogText = (TextView) dialogView.findViewById(R.id.about_dialog_text);
        String aboutText = getString(R.string.about_message);

        /* Add the build date if possible */
        String buildDate = getBuildDate();
        if (buildDate != null) {
            aboutText += buildDate + "<br>";
        }

        dialogText.setText(formatHtmlString(aboutText));
        dialogText.setMovementMethod(LinkMovementMethod.getInstance());
        builder.setView(dialogView);

        /* Show the dialog */
        return builder.create();
    }
    default: {
        return super.onCreateDialog(id);
    }
    }
}

From source file:com.limewoodmedia.nsdroid.activities.Nation.java

private void doSetup() {
    setTitle(data.name);/*from   w  w w  . ja v  a 2s  .c o  m*/

    // Set banner
    if (data.banners != null && data.banners.length > 0) {
        String bannerURL = data.getBannerURL(data.banners[0]);
        imageLoader.displayImage(bannerURL, banner, options);
    } else {
        banner.setImageResource(R.drawable.default_white);
    }
    if (data.flagURL != null) {
        imageLoader.displayImage(data.flagURL, flag, options);
    }
    pretitle.setText(getString(R.string.pretitle, data.type));
    name.setText(data.name);
    motto.setText(Html.fromHtml(data.motto));
    region.setText(Html.fromHtml("<a href=\"com.limewoodMedia.nsdroid.region://" + data.region.replace(' ', '_')
            + "\">" + data.region + "</a>"));
    switch (data.worldAssemblyStatus) {
    case NON_MEMBER:
        waStatus.setVisibility(View.GONE);
        break;
    case WA_MEMBER:
        waStatus.setText(getResources().getString(R.string.wa_member));
        if (waStatus.getVisibility() != View.VISIBLE) {
            waStatus.setVisibility(View.VISIBLE);
        }
        break;
    case WA_DELEGATE:
        waStatus.setText(getResources().getString(R.string.wa_delegate));
        if (waStatus.getVisibility() != View.VISIBLE) {
            waStatus.setVisibility(View.VISIBLE);
        }
        break;
    }
    influence.setText(getResources().getString(R.string.influence) + ": " + data.influence);
    endoByYou = false;
    Log.d(TAG, "Id: " + NationInfo.getInstance(this).getId());
    for (String e : data.endorsements) {
        Log.d(TAG, "Endo: " + e);
        if (NationInfo.getInstance(this).getId().equals(e)) {
            Log.d(TAG, "Endorsed!");
            endoByYou = true;
            break;
        }
    }
    if (!myNation && data.worldAssemblyStatus != WAStatus.NON_MEMBER
            && TagParser.nameToId(data.region).equals(NationInfo.getInstance(this).getRegionId())
            && NationInfo.getInstance(this).getWAStatus() != WAStatus.NON_MEMBER) {
        endorsed.setText(endoByYou ? R.string.nation_endorsed : R.string.nation_not_endorsed);
        endorsed.setVisibility(View.VISIBLE);
    } else {
        endorsed.setVisibility(View.GONE);
    }
    category.setText(data.category);
    civilRights.setText(data.freedoms.civilRights);
    economicStrength.setText(data.freedoms.economy);
    politicalFreedoms.setText(data.freedoms.politicalFreedoms);

    // Set gradients
    Color[] colors = getGradientFor(data.freedoms.civilRightsValue);
    Log.d(TAG, "Civil rights: " + colors[0] + "; " + colors[1]);
    civilRights.setGradient(colors[0], colors[1]);

    colors = getGradientFor(data.freedoms.economyValue);
    economicStrength.setGradient(colors[0], colors[1]);

    colors = getGradientFor(data.freedoms.politicalFreedomsValue);
    politicalFreedoms.setGradient(colors[0], colors[1]);

    // Census ranks
    censusTitle.setText(wData.census);
    worldRank.setText(Utils.getOrdinal(data.worldCensus));
    worldRank.setTotal(wData.numNations);
    colors = getGradientForCensus(data.worldCensus, wData.numNations);
    worldRank.setGradient(colors[0], colors[1]);
    regionRank.setText(Utils.getOrdinal(data.regionalCensus));
    regionRank.setTotal(rData.numNations);
    colors = getGradientForCensus(data.regionalCensus, rData.numNations);
    regionRank.setGradient(colors[0], colors[1]);

    description.setText(Html.fromHtml(data.getDescription().replace("\n", "<br/>")));

    // Endorsements
    if (data.endorsements.length > 0) {
        String endos = "";
        for (String n : data.endorsements) {
            if (endos.length() > 0) {
                endos += ", ";
            }
            endos += "<a href=\"com.limewoodMedia.nsdroid.nation://" + n + "\">" + TagParser.idToName(n)
                    + "</a>";
        }
        endorsements.setText(Html.fromHtml(endos));
        endorsements.setMovementMethod(LinkMovementMethod.getInstance());
    } else {
        endorsements.setVisibility(View.GONE);
        findViewById(R.id.nation_endorsements_title).setVisibility(View.GONE);
    }

    runOnUiThread(new Runnable() {
        @Override
        public void run() {
            supportInvalidateOptionsMenu();
        }
    });
    layout.setVisibility(View.VISIBLE);
}

From source file:com.shopify.buy.ui.ProductDetailsFragmentView.java

/**
 * Fills in the views with all the {@link Product} details.
 *///from   w  w w  .j av a2 s  .c o m
private void updateProductDetails() {
    Resources res = getResources();

    findViewById(R.id.product_details_container).setBackgroundColor(theme.getBackgroundColor(res));

    // Product title
    TextView textViewTitle = (TextView) findViewById(R.id.product_title);
    textViewTitle.setText(product.getTitle());
    textViewTitle.setTextColor(theme.getProductTitleColor(res));

    // Product price
    TextView textViewPrice = (TextView) findViewById(R.id.product_price);
    String priceWithCurrency = currencyFormat.format(Double.parseDouble(variant.getPrice()));
    textViewPrice.setText(priceWithCurrency);
    textViewPrice.setTextColor(theme.getAccentColor());

    // Product "compare at" price (appears below the actual price with a strikethrough style)
    TextView textViewCompareAtPrice = (TextView) findViewById(R.id.product_compare_at_price);
    if (!variant.isAvailable()) {
        textViewCompareAtPrice.setVisibility(View.VISIBLE);
        textViewCompareAtPrice.setText(getResources().getString(R.string.sold_out));
        textViewCompareAtPrice.setTextColor(getResources().getColor(R.color.error_background));
        textViewCompareAtPrice.setPaintFlags(0);
    } else if (!TextUtils.isEmpty(variant.getCompareAtPrice())) {
        textViewCompareAtPrice.setVisibility(View.VISIBLE);
        String compareAtPriceWithCurrency = currencyFormat
                .format(Double.parseDouble(variant.getCompareAtPrice()));
        textViewCompareAtPrice.setText(compareAtPriceWithCurrency);
        textViewCompareAtPrice.setTextColor(theme.getCompareAtPriceColor(res));
        textViewCompareAtPrice
                .setPaintFlags(textViewCompareAtPrice.getPaintFlags() | Paint.STRIKE_THRU_TEXT_FLAG);
    } else {
        textViewCompareAtPrice.setVisibility(View.GONE);
    }

    // Set the correct values on the ProductDetailsVariantOptionViews
    List<OptionValue> optionValues = variant.getOptionValues();
    for (OptionValue optionValue : optionValues) {
        ProductDetailsVariantOptionView optionView = visibleOptionViews
                .get(Long.valueOf(optionValue.getOptionId()));
        if (optionView != null) {
            optionView.setOptionValue(optionValue);
        }
    }

    // Product description
    TextView textViewDescription = (TextView) findViewById(R.id.product_description);
    textViewDescription.setText(Html.fromHtml(product.getBodyHtml()), TextView.BufferType.SPANNABLE);
    textViewDescription.setTextColor(theme.getProductDescriptionColor(res));

    // Make the links clickable in the description
    // http://stackoverflow.com/questions/2734270/how-do-i-make-links-in-a-textview-clickable
    textViewDescription.setMovementMethod(LinkMovementMethod.getInstance());
}

From source file:com.lloydtorres.stately.helpers.SparkleHelper.java

/**
 * Stylify text view to primary colour and no underline
 * @param c App context//from w  ww.j av a  2 s . c o  m
 * @param t TextView
 */
public static void styleLinkifiedTextView(Context c, TextView t) {
    // Get individual spans and replace them with clickable ones.
    Spannable s = new SpannableString(t.getText());
    URLSpan[] spans = s.getSpans(0, s.length(), URLSpan.class);
    for (URLSpan span : spans) {
        int start = s.getSpanStart(span);
        int end = s.getSpanEnd(span);
        s.removeSpan(span);
        span = new URLSpanNoUnderline(c, span.getURL());
        s.setSpan(span, start, end, 0);
    }

    t.setText(s);
    // Need to set this to allow for clickable TextView links.
    if (!(t instanceof HtmlTextView)) {
        t.setMovementMethod(LinkMovementMethod.getInstance());
    }
}

From source file:org.uguess.android.sysinfo.NetStateManager.java

static void showIpInfo(final IpInfo info, final Activity context) {
    if (info != null && !TextUtils.isEmpty(info.latitude) && !TextUtils.isEmpty(info.longitude)) {

        OnClickListener listener = new OnClickListener() {

            public void onClick(DialogInterface dialog, int which) {
                Intent it = new Intent(Intent.ACTION_VIEW);

                it.setData(Uri.parse("geo:0,0?q=" //$NON-NLS-1$
                        + info.latitude + "," //$NON-NLS-1$
                        + info.longitude + "&z=8")); //$NON-NLS-1$

                it = Intent.createChooser(it, null);

                context.startActivity(it);
            }//from  w  ww.ja  v  a 2  s .  c om
        };

        TextView txt = new TextView(context);
        txt.setPadding(15, 0, 15, 0);
        txt.setTextAppearance(context, android.R.style.TextAppearance_Medium);

        txt.setText(Html.fromHtml(context.getString(
                R.string.location_info, info.ip, info.host == null ? "" //$NON-NLS-1$
                        : ("<a href=\"http://" //$NON-NLS-1$
                                + info.host + "\">" //$NON-NLS-1$
                                + info.host + "</a><br>"), //$NON-NLS-1$
                info.country == null ? "" : info.country, //$NON-NLS-1$
                info.region == null ? "" : info.region, //$NON-NLS-1$
                info.city == null ? "" : info.city))); //$NON-NLS-1$
        txt.setMovementMethod(LinkMovementMethod.getInstance());

        new AlertDialog.Builder(context).setTitle(R.string.ip_location)
                .setPositiveButton(R.string.view_map, listener).setNegativeButton(R.string.close, null)
                .setView(txt).create().show();
    } else {
        Util.shortToast(context, R.string.no_ip_info);
    }
}

From source file:com.kyakujin.android.autoeco.ui.MainActivity.java

/**
 * About// w w w .  j  av a2s  .  com
 */
private void showAboutDialog() {
    PackageManager pm = this.getPackageManager();
    String packageName = this.getPackageName();
    String versionName;
    try {
        PackageInfo info = pm.getPackageInfo(packageName, 0);
        versionName = info.versionName;
    } catch (PackageManager.NameNotFoundException e) {
        versionName = "N/A";
    }

    SpannableStringBuilder aboutBody = new SpannableStringBuilder();

    SpannableString mailAddress = new SpannableString(getString(R.string.mailto));
    mailAddress.setSpan(new ClickableSpan() {
        @Override
        public void onClick(View view) {
            Intent intent = new Intent();
            intent.setAction(Intent.ACTION_SENDTO);
            intent.setData(Uri.parse(getString(R.string.description_mailto)));
            intent.putExtra(Intent.EXTRA_SUBJECT, getString(R.string.description_mail_subject));
            startActivity(intent);
        }
    }, 0, mailAddress.length(), 0);

    aboutBody.append(Html.fromHtml(getString(R.string.about_body, versionName)));
    aboutBody.append("\n");
    aboutBody.append(mailAddress);

    LayoutInflater layoutInflater = (LayoutInflater) this.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    TextView aboutBodyView = (TextView) layoutInflater.inflate(R.layout.fragment_about_dialog, null);
    aboutBodyView.setText(aboutBody);
    aboutBodyView.setMovementMethod(LinkMovementMethod.getInstance());

    AlertDialog dlg = new AlertDialog.Builder(this).setTitle(R.string.alert_title_about).setView(aboutBodyView)
            .setPositiveButton("OK", new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    dialog.dismiss();
                }
            }).create();
    dlg.show();
}

From source file:de.syss.MifareClassicTool.Activities.MainMenu.java

/**
 * Show the about dialog.//from   w  ww  .j av a 2  s  .co m
 */
private void onShowAboutDialog() {
    CharSequence styledText = Html.fromHtml(getString(R.string.dialog_about_mct, Common.getVersionCode()));
    AlertDialog ad = new AlertDialog.Builder(this).setTitle(R.string.dialog_about_mct_title)
            .setMessage(styledText).setIcon(R.mipmap.ic_launcher)
            .setPositiveButton(R.string.action_ok, new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    // Do nothing.
                }
            }).create();
    ad.show();
    // Make links clickable.
    ((TextView) ad.findViewById(android.R.id.message)).setMovementMethod(LinkMovementMethod.getInstance());
}

From source file:busradar.madison.StopDialog.java

@Override
public void show() {
    new Thread() {
        @Override/*from   www.  j  ava 2s.  com*/
        public void run() {

            for (final RouteURL r : routes) {
                G.activity.runOnUiThread(new Runnable() {
                    public void run() {
                        cur_loading_text
                                .setText(String.format("Loading route %s...", G.route_points[r.route].name));
                    }
                });

                final ArrayList<RouteTime> curtimes = new ArrayList<RouteTime>();
                try {
                    System.err.printf("BusRadar URL %s\n", TRANSITTRACKER_URL + r.url);
                    URL url = new URL(TRANSITTRACKER_URL + r.url);
                    URLConnection url_conn = url.openConnection();
                    if (url_conn instanceof HttpsURLConnection) {
                        ((HttpsURLConnection) url_conn).setHostnameVerifier(new HostnameVerifier() {

                            public boolean verify(String hostname, SSLSession session) {
                                return true;
                            }
                        });
                    }
                    InputStream is = url_conn.getInputStream();
                    Scanner scan = new Scanner(is, "UTF-8");

                    //String outstr_cur = "Route " + r.route + "\n";

                    if (scan.findWithinHorizon(num_vehicles_re, 0) != null) {

                        while (scan.findWithinHorizon(time_re, 0) != null) {
                            RouteTime time = new RouteTime();
                            time.route = r.route;
                            time.time = scan.match().group(1).replace(".", "");
                            time.dir = scan.match().group(2);
                            //time.date = DateFormat.getTimeInstance(DateFormat.SHORT).parse(time.time);

                            SimpleDateFormat f = new SimpleDateFormat("h:mm aa", Locale.US);
                            time.date = f.parse(time.time);
                            r.status = RouteURL.DONE;

                            //outstr_cur += String.format("%s to %s\n", time.time, time.dir);
                            curtimes.add(time);
                        }

                        while (scan.findWithinHorizon(time_re_backup, 0) != null) {
                            RouteTime time = new RouteTime();
                            time.route = r.route;
                            time.time = scan.match().group(1).replace(".", "");
                            //time.dir = scan.match().group(2);
                            //time.date = DateFormat.getTimeInstance(DateFormat.SHORT).parse(time.time);

                            SimpleDateFormat f = new SimpleDateFormat("h:mm aa", Locale.US);
                            time.date = f.parse(time.time);
                            r.status = RouteURL.DONE;

                            //outstr_cur += String.format("%s to %s\n", time.time, time.dir);
                            curtimes.add(time);
                        }

                    }

                    //                  else if (scan.findWithinHorizon(no_busses_re, 0) != null) {
                    //                     r.status = RouteURL.NO_MORE_TODAY; 
                    //                  } 
                    //                  else if (scan.findWithinHorizon(no_timepoints_re, 0) != null) {
                    //                     r.status = RouteURL.NO_TIMEPOINTS;
                    //                  }
                    //                  else {
                    //                     r.status = RouteURL.ERROR;
                    //                     System.out.printf("BusRadar: Could not get stop info for %s\n", r.url);
                    //                     
                    //                     throw new Exception("Error parsing TransitTracker webpage.");
                    //                  }
                    else {
                        r.status = RouteURL.NO_STOPS_UNKONWN;
                    }

                    //r.text = outstr_cur;

                    G.activity.runOnUiThread(new Runnable() {
                        public void run() {
                            times.addAll(curtimes);
                            StopDialog.this.update_times();
                        }
                    });

                }
                //               catch  (final IOException ioe) {
                //                  log_problem(ioe);
                //                  G.activity.runOnUiThread(new Runnable() {
                //                     public void run() {
                //                        final Context ctx = StopDialog.this.getContext();
                //                        
                //                        StopDialog.this.setContentView(new RelativeLayout(ctx) {{
                //                           addView(new TextView(ctx) {{
                //                              setText(Html.fromHtml("Error downloading data. Is the data connection enabled?"+
                //                                                  "<p>Report problems to <a href='mailto:support@busradarapp.com'>support@busradarapp.com</a><p>"+ioe));
                //                              setPadding(5, 5, 5, 5);
                //                              this.setMovementMethod(LinkMovementMethod.getInstance());
                //                           }}, new RelativeLayout.LayoutParams(WRAP_CONTENT, WRAP_CONTENT));
                //                        }});
                //                     }
                //                  });                  
                //                  return;
                //               }
                catch (Exception e) {
                    log_problem(e);

                    String custom_msg = "";
                    final String turl = TRANSITTRACKER_URL + r.url;
                    if ((e instanceof SocketException) || (e instanceof UnknownHostException)) {
                        // data connection doesn't work
                        custom_msg = "Error downloading data. Is the data connection enabled?"
                                + "<p>Report problems to <a href='mailto:support@busradarapp.com'>support@busradarapp.com</a><p>"
                                + TextUtils.htmlEncode(e.toString());
                    } else {

                        String rurl = String.format(
                                "http://www.cityofmadison.com/metro/BusStopDepartures/StopID/%04d.pdf", stopid);
                        custom_msg = "Trouble retrieving real-time arrival estimates from <a href='" + turl
                                + "'>this</a> TransitTracker webpage, which is displayed below. "
                                + "Meanwhile, try PDF timetable <a href='" + rurl + "'>here</a>. "
                                + "Contact us at <a href='mailto:support@busradarapp.com'>support@busradarapp.com</a> to report the problem.<p>"
                                + TextUtils.htmlEncode(e.toString());
                    }

                    final String msg = custom_msg;

                    G.activity.runOnUiThread(new Runnable() {
                        public void run() {
                            final Context ctx = StopDialog.this.getContext();

                            StopDialog.this.setContentView(new RelativeLayout(ctx) {
                                {
                                    addView(new TextView(ctx) {
                                        {
                                            setId(1);
                                            setText(Html.fromHtml(msg));
                                            setPadding(5, 5, 5, 5);
                                            this.setMovementMethod(LinkMovementMethod.getInstance());
                                        }
                                    }, new RelativeLayout.LayoutParams(WRAP_CONTENT, WRAP_CONTENT));

                                    addView(new WebView(ctx) {
                                        {
                                            setWebViewClient(new WebViewClient());
                                            loadUrl(turl);
                                        }
                                    }, new RelativeLayout.LayoutParams(LayoutParams.FILL_PARENT,
                                            LayoutParams.FILL_PARENT) {
                                        {
                                            addRule(RelativeLayout.BELOW, 1);
                                        }
                                    });
                                }
                            });
                        }
                    });
                    return;
                }

            }

            G.activity.runOnUiThread(new Runnable() {
                public void run() {
                    cur_loading_text.setText("");
                }
            });
        }
    }.start();

    super.show();

}

From source file:com.heath_bar.tvdb.SeriesOverview.java

/** Update the GUI with the specified rating */
private void setUserRatingTextView(int rating) {

    try {// w ww.  ja va2 s  . c o m
        TextView ratingTextView = (TextView) findViewById(R.id.rating);
        String communityRating = (seriesInfo == null) ? "?" : seriesInfo.getRating();
        String communityRatingText = communityRating + " / 10";

        String ratingTextA = communityRatingText + "  (";
        String ratingTextB = (rating == 0) ? "rate" : String.valueOf(rating);
        String ratingTextC = ")";

        int start = ratingTextA.length();
        int end = ratingTextA.length() + ratingTextB.length();

        SpannableStringBuilder ssb = new SpannableStringBuilder(ratingTextA + ratingTextB + ratingTextC);

        ssb.setSpan(new NonUnderlinedClickableSpan() {
            @Override
            public void onClick(View v) {
                showRatingDialog();
            }
        }, start, end, 0);

        ssb.setSpan(new TextAppearanceSpan(getApplicationContext(), R.style.episode_link), start, end, 0); // Set the style of the text
        ratingTextView.setText(ssb, BufferType.SPANNABLE);
        ratingTextView.setMovementMethod(LinkMovementMethod.getInstance());
    } catch (Exception e) {
        Log.e("SeriesOverview", "Failed to setUserRatingTextView: " + e.getMessage());
    }
}