Example usage for android.widget TextView setMovementMethod

List of usage examples for android.widget TextView setMovementMethod

Introduction

In this page you can find the example usage for android.widget TextView setMovementMethod.

Prototype

public final void setMovementMethod(MovementMethod movement) 

Source Link

Document

Sets the android.text.method.MovementMethod for handling arrow key movement for this TextView.

Usage

From source file:org.wikipedia.edit.EditSectionActivity.java

private void updateEditLicenseText() {
    TextView editLicenseText = findViewById(R.id.edit_section_license_text);
    editLicenseText.setText(StringUtil.fromHtml(String.format(
            getString(AccountUtil.isLoggedIn() ? R.string.edit_save_action_license_logged_in
                    : R.string.edit_save_action_license_anon),
            getString(R.string.terms_of_use_url), getString(R.string.cc_by_sa_3_url))));

    editLicenseText.setMovementMethod(new LinkMovementMethodExt(new LinkMovementMethodExt.UrlHandler() {
        @Override//ww  w  . ja v  a  2 s .  co m
        public void onUrlClick(@NonNull String url, @Nullable String notUsed) {
            if (url.equals("https://#login")) {
                funnel.logLoginAttempt();
                Intent loginIntent = LoginActivity.newIntent(EditSectionActivity.this, LoginFunnel.SOURCE_EDIT,
                        funnel.getSessionToken());
                startActivityForResult(loginIntent, Constants.ACTIVITY_REQUEST_LOGIN);
            } else {
                handleExternalLink(EditSectionActivity.this, Uri.parse(url));
            }
        }
    }));
}

From source file:com.grokkingandroid.sampleapp.samples.SampleBaseFragment.java

@SuppressLint("NewApi")
protected void showLinks(ViewGroup container) {
    String[] linkTexts = getLinkTexts();
    String[] linkTargets = getLinkTargets();
    StringBuilder link = null;//w w  w .j  a v a  2  s . c  o m
    for (int i = 0; i < linkTexts.length; i++) {
        // TODO: Use an inflater
        TextView tv = new TextView(getActivity());
        LinearLayout.LayoutParams params = null;
        params = new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
        if (i != linkTexts.length - 1) {
            int marginBottom = getResources().getDimensionPixelSize(R.dimen.linkSpacing);
            params.setMargins(0, 0, 0, marginBottom);
        }
        tv.setLayoutParams(params);
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
            tv.setTextIsSelectable(true);
        }
        tv.setTextAppearance(getActivity(), android.R.style.TextAppearance_Medium);
        link = new StringBuilder(100);
        link.append("<a href=\"");
        link.append(linkTargets[i]);
        link.append("\">");
        link.append(linkTexts[i]);
        link.append("</a>");
        Spanned spannedLink = Html.fromHtml(link.toString());
        tv.setText(spannedLink);
        tv.setMovementMethod(LinkMovementMethod.getInstance());
        container.addView(tv);
    }
}

From source file:com.inter.trade.ui.fragment.smsreceivepayment.SmsSuccessFragment.java

private void initView(View view) {
    if (requsetData != null) {
        TextView tv_content = (TextView) view.findViewById(R.id.tv_content);
        String s1 = "????";
        String s2 = requsetData.getValue("fumobile");
        String s3 = "??";
        String s4 = "" + requsetData.getValue("money");
        String s5 = ",??1";
        String content = s1 + s2 + s3 + s4 + s5;
        int len = 0;
        /**// www. j  a v a 2 s .  com
         * ?TEXTVIEW??
         */
        SpannableString ss = new SpannableString(content);
        ss.setSpan(new ForegroundColorSpan(getResources().getColor(R.color.agent_apply_yellow)),
                len = s1.length() + s2.length() + s3.length(), len + s4.length(),
                Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
        tv_content.setText(ss);
        tv_content.setMovementMethod(LinkMovementMethod.getInstance());

        //         String content = "????"
        //               +requsetData.getValue("fumobile")
        //               +"??"
        //               +requsetData.getValue("money")
        //               +",??1";
        //         tv_content.setText(content);

        TextView tv_shou_bank = (TextView) view.findViewById(R.id.tv_shou_bank);
        String shou_bank = "" + requsetData.getValue("shoucardbank");
        tv_shou_bank.setText(shou_bank);

        TextView tv_shou_card = (TextView) view.findViewById(R.id.tv_shou_card);
        String shou_card = "?" + requsetData.getValue("shoucardno");
        tv_shou_card.setText(shou_card);
    }

    Button see_history = (Button) view.findViewById(R.id.see_history);
    see_history.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub
            getActivity().setResult(Constants.ACTIVITY_FINISH);
            getActivity().finish();
        }
    });

    Button btnAgain = (Button) view.findViewById(R.id.btn_again);
    btnAgain.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            /**
             * ??
             */
            SmsReceivePaymentMainFragment.isComeBackFromPaySuccess = true;
            Intent intent = new Intent(getActivity(), IndexActivity.class);
            intent.putExtra(FragmentFactory.INDEX_KEY, FuncMap.SMSRECEIPT_INDEX_FUNC);
            intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
            startActivity(intent);
        }
    });

}

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

/**
 * Fills in the views with all the {@link Product} details.
 *//*www. j  a v a 2  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:gr.scify.newsum.ui.ViewActivity.java

protected void initGestures() {
    GestureOverlayView gestureOverlayView = new GestureOverlayView(this);
    View inflate = getLayoutInflater().inflate(R.layout.view, null);
    gestureOverlayView.addView(inflate);
    gestureOverlayView.addOnGesturePerformedListener(this);
    gestureOverlayView.setGestureColor(Color.TRANSPARENT);
    gestureOverlayView.setUncertainGestureColor(Color.TRANSPARENT);
    gestureLib = GestureLibraries.fromRawResource(this, R.raw.gestures);
    if (!gestureLib.load()) {
        finish();/*from  w  ww  .  java  2 s . c om*/
    }
    setContentView(gestureOverlayView);
    getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.custom_title);

    ImageView title_image = (ImageView) findViewById(R.id.title_image);
    title_image.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            Intent browse = new Intent(Intent.ACTION_VIEW, Uri.parse(getResources().getString(R.string.scify)));
            startActivity(browse);
        }

    });

    // Allow links to be followed into browser
    final TextView tx = (TextView) findViewById(R.id.textView1);
    tx.setMovementMethod(LinkMovementMethod.getInstance());
}

From source file:br.com.carlosrafaelgn.fplay.ActivityBrowserRadio.java

@Override
public void onClick(View view) {
    if (view == btnGoBack) {
        if (isAtFavorites) {
            isAtFavorites = false;/*w  w w.  j a va 2s. c  o m*/
            doSearch();
        } else {
            finish(0, view, true);
        }
    } else if (view == btnFavorite) {
        isAtFavorites = true;
        radioStationList.cancel();
        radioStationList.fetchFavorites(getApplication());
        updateButtons();
    } else if (view == btnSearch) {
        final Context ctx = getHostActivity();
        final LinearLayout l = (LinearLayout) UI.createDialogView(ctx, null);

        LinearLayout.LayoutParams p = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,
                LinearLayout.LayoutParams.WRAP_CONTENT);
        chkGenre = new RadioButton(ctx);
        chkGenre.setText(R.string.genre);
        chkGenre.setChecked(Player.lastRadioSearchWasByGenre);
        chkGenre.setOnClickListener(this);
        chkGenre.setTextSize(TypedValue.COMPLEX_UNIT_PX, UI._DLGsp);
        chkGenre.setLayoutParams(p);

        p = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,
                LinearLayout.LayoutParams.WRAP_CONTENT);
        p.topMargin = UI._DLGsppad;
        btnGenre = new Spinner(ctx);
        btnGenre.setContentDescription(ctx.getText(R.string.genre));
        btnGenre.setLayoutParams(p);

        p = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,
                LinearLayout.LayoutParams.WRAP_CONTENT);
        p.topMargin = UI._DLGsppad << 1;
        chkTerm = new RadioButton(ctx);
        chkTerm.setText(R.string.search_term);
        chkTerm.setChecked(!Player.lastRadioSearchWasByGenre);
        chkTerm.setOnClickListener(this);
        chkTerm.setTextSize(TypedValue.COMPLEX_UNIT_PX, UI._DLGsp);
        chkTerm.setLayoutParams(p);

        p = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,
                LinearLayout.LayoutParams.WRAP_CONTENT);
        p.topMargin = UI._DLGsppad;
        txtTerm = new EditText(ctx);
        txtTerm.setContentDescription(ctx.getText(R.string.search_term));
        txtTerm.setText(Player.radioSearchTerm == null ? "" : Player.radioSearchTerm);
        txtTerm.setOnClickListener(this);
        txtTerm.setTextSize(TypedValue.COMPLEX_UNIT_PX, UI._DLGsp);
        txtTerm.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_FLAG_CAP_SENTENCES);
        txtTerm.setSingleLine();
        txtTerm.setLayoutParams(p);

        p = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,
                LinearLayout.LayoutParams.WRAP_CONTENT);
        p.topMargin = UI._DLGsppad;
        p.bottomMargin = UI._DLGsppad;
        final TextView lbl = new TextView(ctx);
        lbl.setAutoLinkMask(0);
        lbl.setLinksClickable(true);
        //http://developer.android.com/design/style/color.html
        lbl.setLinkTextColor(new BgColorStateList(UI.isAndroidThemeLight() ? 0xff0099cc : 0xff33b5e5));
        lbl.setTextSize(TypedValue.COMPLEX_UNIT_PX, UI._14sp);
        lbl.setGravity(Gravity.CENTER_HORIZONTAL);
        lbl.setText(SafeURLSpan.parseSafeHtml(getText(R.string.by_dir_xiph_org)));
        lbl.setMovementMethod(LinkMovementMethod.getInstance());
        lbl.setLayoutParams(p);

        l.addView(chkGenre);
        l.addView(btnGenre);
        l.addView(chkTerm);
        l.addView(txtTerm);
        l.addView(lbl);

        btnGenre.setAdapter(this);
        btnGenre.setSelection(getValidGenre(Player.radioLastGenre));
        defaultTextColors = txtTerm.getTextColors();

        UI.prepareDialogAndShow((new AlertDialog.Builder(ctx)).setTitle(getText(R.string.search)).setView(l)
                .setPositiveButton(R.string.search, this).setNegativeButton(R.string.cancel, this)
                .setOnCancelListener(this).create());
    } else if (view == btnGoBackToPlayer) {
        finish(-1, view, false);
    } else if (view == btnAdd) {
        addPlaySelectedItem(false);
    } else if (view == btnPlay) {
        addPlaySelectedItem(true);
    } else if (view == chkGenre || view == btnGenre) {
        chkGenre.setChecked(true);
        chkTerm.setChecked(false);
    } else if (view == chkTerm || view == txtTerm) {
        chkGenre.setChecked(false);
        chkTerm.setChecked(true);
    } else if (view == list) {
        if (!isAtFavorites && !loading && (radioStationList == null || radioStationList.getCount() == 0))
            onClick(btnFavorite);
    }
}

From source file:eu.faircode.adblocker.ActivityMain.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    Log.i(TAG, "Create version=" + Util.getSelfVersionName(this) + "/" + Util.getSelfVersionCode(this));
    Util.logExtras(getIntent());//ww w. j  a  va  2 s . c o  m

    if (Build.VERSION.SDK_INT < MIN_SDK) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.android);
        return;
    }

    Util.setTheme(this);
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    swEnabled = (SwitchCompat) findViewById(R.id.swEnabled);
    running = true;

    final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
    boolean enabled = prefs.getBoolean("enabled", false);
    boolean initialized = prefs.getBoolean("initialized", false);

    // Upgrade
    Receiver.upgrade(initialized, this);

    if (!getIntent().hasExtra(EXTRA_APPROVE)) {
        if (enabled)
            ServiceSinkhole.start("UI", this);
        else
            ServiceSinkhole.stop("UI", this);
    }

    // Action bar
    final View actionView = getLayoutInflater().inflate(R.layout.actionmain, null, false);
    ivIcon = (ImageView) actionView.findViewById(R.id.ivIcon);
    ivQueue = (ImageView) actionView.findViewById(R.id.ivQueue);

    ivMetered = (ImageView) actionView.findViewById(R.id.ivMetered);

    // Icon
    ivIcon.setOnLongClickListener(new View.OnLongClickListener() {
        @Override
        public boolean onLongClick(View view) {
            menu_about();
            return true;
        }
    });

    // Title
    getSupportActionBar().setTitle(null);

    // Netguard is busy
    ivQueue.setOnLongClickListener(new View.OnLongClickListener() {
        @Override
        public boolean onLongClick(View view) {
            int location[] = new int[2];
            actionView.getLocationOnScreen(location);
            Toast toast = Toast.makeText(ActivityMain.this, R.string.msg_queue, Toast.LENGTH_LONG);
            toast.setGravity(Gravity.TOP | Gravity.START, location[0] + ivQueue.getLeft(),
                    Math.round(location[1] + ivQueue.getBottom() - toast.getView().getPaddingTop()));
            toast.show();
            return true;
        }
    });

    // On/off switch
    swEnabled.setChecked(enabled);
    swEnabled.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            Log.i(TAG, "Switch=" + isChecked);
            prefs.edit().putBoolean("enabled", isChecked).apply();

            if (isChecked) {
                try {
                    final Intent prepare = VpnService.prepare(ActivityMain.this);
                    if (prepare == null) {
                        Log.i(TAG, "Prepare done");
                        onActivityResult(REQUEST_VPN, RESULT_OK, null);
                    } else {
                        // Show dialog
                        LayoutInflater inflater = LayoutInflater.from(ActivityMain.this);
                        View view = inflater.inflate(R.layout.vpn, null, false);
                        dialogVpn = new AlertDialog.Builder(ActivityMain.this).setView(view)
                                .setCancelable(false)
                                .setPositiveButton(android.R.string.yes, new DialogInterface.OnClickListener() {
                                    @Override
                                    public void onClick(DialogInterface dialog, int which) {
                                        if (running) {
                                            Log.i(TAG, "Start intent=" + prepare);
                                            try {
                                                startActivityForResult(prepare, REQUEST_VPN);
                                            } catch (Throwable ex) {
                                                Log.e(TAG, ex.toString() + "\n" + Log.getStackTraceString(ex));
                                                Util.sendCrashReport(ex, ActivityMain.this);
                                                onActivityResult(REQUEST_VPN, RESULT_CANCELED, null);
                                                prefs.edit().putBoolean("enabled", false).apply();
                                            }
                                        }
                                    }
                                }).setOnDismissListener(new DialogInterface.OnDismissListener() {
                                    @Override
                                    public void onDismiss(DialogInterface dialogInterface) {
                                        dialogVpn = null;
                                    }
                                }).create();
                        dialogVpn.show();
                    }
                } catch (Throwable ex) {
                    // Prepare failed
                    Log.e(TAG, ex.toString() + "\n" + Log.getStackTraceString(ex));
                    Util.sendCrashReport(ex, ActivityMain.this);
                    prefs.edit().putBoolean("enabled", false).apply();
                }

            } else
                ServiceSinkhole.stop("switch off", ActivityMain.this);
        }
    });
    if (enabled)
        checkDoze();

    // Network is metered
    ivMetered.setOnLongClickListener(new View.OnLongClickListener() {
        @Override
        public boolean onLongClick(View view) {
            int location[] = new int[2];
            actionView.getLocationOnScreen(location);
            Toast toast = Toast.makeText(ActivityMain.this, R.string.msg_metered, Toast.LENGTH_LONG);
            toast.setGravity(Gravity.TOP | Gravity.START, location[0] + ivMetered.getLeft(),
                    Math.round(location[1] + ivMetered.getBottom() - toast.getView().getPaddingTop()));
            toast.show();
            return true;
        }
    });

    getSupportActionBar().setDisplayShowCustomEnabled(true);
    getSupportActionBar().setCustomView(actionView);

    // Disabled warning
    TextView tvDisabled = (TextView) findViewById(R.id.tvDisabled);
    tvDisabled.setVisibility(enabled ? View.GONE : View.VISIBLE);

    // Application list
    //        RecyclerView rvApplication = (RecyclerView) findViewById(R.id.rvApplication);
    //        rvApplication.setHasFixedSize(true);
    //        rvApplication.setLayoutManager(new LinearLayoutManager(this));
    //        adapter = new AdapterRule(this);
    //        rvApplication.setAdapter(adapter);

    // Swipe to refresh
    TypedValue tv = new TypedValue();
    getTheme().resolveAttribute(R.attr.colorPrimary, tv, true);
    //        swipeRefresh = (SwipeRefreshLayout) findViewById(R.id.swipeRefresh);
    //        swipeRefresh.setColorSchemeColors(Color.WHITE, Color.WHITE, Color.WHITE);
    //        swipeRefresh.setProgressBackgroundColorSchemeColor(tv.data);
    //        swipeRefresh.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
    //            @Override
    //            public void onRefresh() {
    //                Rule.clearCache(ActivityMain.this);
    //                ServiceSinkhole.reload("pull", ActivityMain.this);
    //                updateApplicationList(null);
    //            }
    //        });

    // Listen for preference changes
    prefs.registerOnSharedPreferenceChangeListener(this);

    // Listen for rule set changes
    IntentFilter ifr = new IntentFilter(ACTION_RULES_CHANGED);
    LocalBroadcastManager.getInstance(this).registerReceiver(onRulesChanged, ifr);

    // Listen for queue changes
    IntentFilter ifq = new IntentFilter(ACTION_QUEUE_CHANGED);
    LocalBroadcastManager.getInstance(this).registerReceiver(onQueueChanged, ifq);

    // Listen for added/removed applications
    IntentFilter intentFilter = new IntentFilter();
    intentFilter.addAction(Intent.ACTION_PACKAGE_ADDED);
    intentFilter.addAction(Intent.ACTION_PACKAGE_REMOVED);
    intentFilter.addDataScheme("package");
    registerReceiver(packageChangedReceiver, intentFilter);

    // First use
    if (!initialized) {
        // Create view
        LayoutInflater inflater = LayoutInflater.from(this);
        View view = inflater.inflate(R.layout.first, null, false);
        TextView tvFirst = (TextView) view.findViewById(R.id.tvFirst);
        tvFirst.setMovementMethod(LinkMovementMethod.getInstance());

        // Show dialog
        dialogFirst = new AlertDialog.Builder(this).setView(view).setCancelable(false)
                .setPositiveButton(android.R.string.yes, new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        if (running)
                            prefs.edit().putBoolean("initialized", true).apply();
                    }
                }).setNegativeButton(android.R.string.no, new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        if (running)
                            finish();
                    }
                }).setOnDismissListener(new DialogInterface.OnDismissListener() {
                    @Override
                    public void onDismiss(DialogInterface dialogInterface) {
                        dialogFirst = null;
                    }
                }).create();
        dialogFirst.show();
    }

    // Fill application list
    updateApplicationList(getIntent().getStringExtra(EXTRA_SEARCH));

    // Update IAB SKUs
    try {
        iab = new IAB(new IAB.Delegate() {
            @Override
            public void onReady(IAB iab) {
                try {
                    iab.updatePurchases();

                    if (!IAB.isPurchased(ActivityPro.SKU_LOG, ActivityMain.this))
                        prefs.edit().putBoolean("log", false).apply();
                    if (!IAB.isPurchased(ActivityPro.SKU_THEME, ActivityMain.this)) {
                        if (!"teal".equals(prefs.getString("theme", "teal")))
                            prefs.edit().putString("theme", "teal").apply();
                    }
                    if (!IAB.isPurchased(ActivityPro.SKU_SPEED, ActivityMain.this))
                        prefs.edit().putBoolean("show_stats", false).apply();
                } catch (Throwable ex) {
                    Log.e(TAG, ex.toString() + "\n" + Log.getStackTraceString(ex));
                } finally {
                    iab.unbind();
                }
            }
        }, this);
        iab.bind();
    } catch (Throwable ex) {
        Log.e(TAG, ex.toString() + "\n" + Log.getStackTraceString(ex));
    }

    checkExtras(getIntent());
}

From source file:com.ubergeek42.WeechatAndroid.adapters.ChatLinesAdapter.java

@Override
public View getView(int position, View convertView, ViewGroup parent) {
    View retview; // The view to return
    TextView textview;

    boolean mustDrawReadMarker = getItemId(position) == buffer.readMarkerLine;

    // we only want to reuse TextViews, not the special lastLineRead view,
    // so force view recreation
    if (mustDrawReadMarker || convertView instanceof RelativeLayout)
        convertView = null;/*  w  ww  . jav a  2  s  .  c  o m*/

    if (convertView == null) {
        if (mustDrawReadMarker) {
            retview = inflater.inflate(R.layout.chatview_line_read_marker, null);
            textview = (TextView) retview.findViewById(R.id.chatline_message);
            //noinspection deprecation
            retview.findViewById(R.id.separator).setBackgroundDrawable(
                    new ColorDrawable(0xFF000000 | ColorScheme.get().chat_read_marker[0]));
        } else {
            textview = (TextView) inflater.inflate(R.layout.chatview_line, null);
            retview = textview;
        }
        textview.setTextColor(0xFF000000 | ColorScheme.get().defaul[0]);
        textview.setMovementMethod(LinkMovementMethod.getInstance());
    } else { // convertview is only ever not null for the simple case
        textview = (TextView) convertView;
        retview = textview;
    }

    textview.setTextSize(P.textSize);
    Line line = (Line) getItem(position);
    textview.setText(line.spannable);
    textview.setTag(line);
    if (typeface != null)
        textview.setTypeface(typeface);

    return retview;
}

From source file:pl.poznan.put.cs.ify.app.market.MarketInfoDetailsFrag.java

private void initGui(View v, MarketInfo marketInfo) {
    TextView rate = (TextView) v.findViewById(R.id.tv_rate);
    TextView desc = (TextView) v.findViewById(R.id.tv_desc);
    TextView date = (TextView) v.findViewById(R.id.tv_date);
    TextView name = (TextView) v.findViewById(R.id.tv_name);
    ListView commentsList = (ListView) v.findViewById(R.id.lv_comments);
    TextView commentsLabel = (TextView) v.findViewById(R.id.tv_comments);
    View commentsSep = v.findViewById(R.id.comments_sep);

    if (marketInfo.getComments() == null || marketInfo.getComments().isEmpty()) {
        commentsList.setVisibility(View.GONE);
        commentsLabel.setVisibility(View.GONE);
        commentsSep.setVisibility(View.GONE);
    } else {/*from   ww  w .  ja v a2s . com*/
        CommentsAdapter commentsAdapter = new CommentsAdapter(marketInfo.getComments(),
                (LayoutInflater) getActivity().getSystemService(Context.LAYOUT_INFLATER_SERVICE));
        commentsList.setAdapter(commentsAdapter);
    }

    try {
        rate.setText("Rate: " + rateFormat.format(marketInfo.getRate()));
    } catch (RuntimeException ex) {
        rate.setText("Not yet rated");
    }

    desc.setMovementMethod(new ScrollingMovementMethod());
    desc.setText(marketInfo.getDescription());
    date.setText(dateFormat.format(new Date(marketInfo.getTimestamp())));
    name.setText(marketInfo.getName());

    Button download = (Button) v.findViewById(R.id.btn_download);
    download.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            showLoadingButton();
            downloadJar(getMarketInfo());
        }
    });
}

From source file:com.grarak.kerneladiutor.views.recyclerview.downloads.DownloadKernelView.java

@Override
public void onCreateView(View view) {
    super.onCreateView(view);

    if (mDownloadDrawable == null) {
        mDownloadDrawable = ContextCompat.getDrawable(view.getContext(), R.drawable.ic_download);
        DrawableCompat.setTint(mDownloadDrawable, Color.WHITE);
    }/*w  ww  .  j a v  a 2  s.c  o  m*/
    if (mCancelDrawable == null) {
        mCancelDrawable = ContextCompat.getDrawable(view.getContext(), R.drawable.ic_cancel);
        DrawableCompat.setTint(mCancelDrawable, Color.WHITE);
    }

    final TextView title = (TextView) view.findViewById(R.id.title);
    TextView summary = (TextView) view.findViewById(R.id.summary);
    TextView changelog = (TextView) view.findViewById(R.id.changelog);
    mDownloadSection = view.findViewById(R.id.downloadSection);
    mProgressParent = view.findViewById(R.id.progressParent);
    mProgressText = (TextView) view.findViewById(R.id.progressText);
    mProgressBar = (ProgressBar) view.findViewById(R.id.progressbar);
    mFabButton = (FloatingActionButton) view.findViewById(R.id.fab_button);
    mCheckMD5 = view.findViewById(R.id.checkmd5);
    mMismatchMD5 = view.findViewById(R.id.md5_mismatch);
    mInstallButton = view.findViewById(R.id.install);

    final CharSequence titleText = Utils.htmlFrom(mDownload.getName());
    title.setText(titleText);
    title.setMovementMethod(LinkMovementMethod.getInstance());

    String description = mDownload.getDescription();
    if (description != null) {
        summary.setText(Utils.htmlFrom(description));
        summary.setMovementMethod(LinkMovementMethod.getInstance());
    } else {
        summary.setVisibility(View.GONE);
    }

    List<String> changelogs = mDownload.getChangelogs();
    if (changelogs.size() > 0) {
        StringBuilder stringBuilder = new StringBuilder();
        for (String change : changelogs) {
            if (stringBuilder.length() == 0) {
                stringBuilder.append("\u2022").append(" ").append(change);
            } else {
                stringBuilder.append("<br>").append("\u2022").append(" ").append(change);
            }
        }
        changelog.setText(Utils.htmlFrom(stringBuilder.toString()));
        changelog.setMovementMethod(LinkMovementMethod.getInstance());
    } else {
        changelog.setVisibility(View.GONE);
    }

    mMismatchMD5.setVisibility(View.GONE);
    mInstallButton.setVisibility(View.GONE);
    if (mCheckMD5Task == null) {
        mDownloadSection.setVisibility(View.VISIBLE);
        mCheckMD5.setVisibility(View.GONE);
    }
    mProgressParent.setVisibility(mDownloadTask == null ? View.INVISIBLE : View.VISIBLE);
    mFabButton.setImageDrawable(mDownloadTask == null ? mDownloadDrawable : mCancelDrawable);
    mFabButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(final View view) {
            if (mDownloadTask == null) {
                mFabButton.setImageDrawable(mCancelDrawable);
                mProgressParent.setVisibility(View.VISIBLE);
                mMismatchMD5.setVisibility(View.GONE);
                mInstallButton.setVisibility(View.GONE);
                mProgressBar.setProgress(0);
                mProgressText.setText("");

                mProgressBar.setIndeterminate(true);
                mDownloadTask = new DownloadTask(mActvity, new DownloadTask.OnDownloadListener() {

                    private int mPercentage;

                    @Override
                    public void onUpdate(int currentSize, int totalSize) {
                        int percentage = Math.round(currentSize * 100f / totalSize);
                        if (mPercentage != percentage) {
                            mPercentage = percentage;
                            mProgressBar.setIndeterminate(false);
                            double current = Utils.roundTo2Decimals(currentSize / 1024D / 1024D);
                            double total = Utils.roundTo2Decimals(totalSize / 1024D / 1024D);
                            mProgressBar.setProgress(mPercentage);
                            mProgressText.setText(view.getContext().getString(R.string.downloading_counting,
                                    String.valueOf(current), String.valueOf(total))
                                    + view.getContext().getString(R.string.mb));
                        }
                    }

                    @Override
                    public void onSuccess(String path) {
                        mFabButton.setImageDrawable(mDownloadDrawable);
                        mProgressParent.setVisibility(View.INVISIBLE);
                        mDownloadTask = null;
                        checkMD5(mDownload.getMD5sum(), path, mDownload.getInstallMethod());
                    }

                    @Override
                    public void onCancel() {
                        mFabButton.setImageDrawable(mDownloadDrawable);
                        mProgressParent.setVisibility(View.INVISIBLE);
                        mMismatchMD5.setVisibility(View.GONE);
                        mDownloadTask = null;
                    }

                    @Override
                    public void onFailure(String error) {
                        Utils.toast(view.getContext().getString(R.string.download_error, titleText),
                                view.getContext());
                        mFabButton.setImageDrawable(mDownloadDrawable);
                        mProgressParent.setVisibility(View.INVISIBLE);
                        mDownloadTask = null;
                    }
                }, Utils.getInternalDataStorage() + "/downloads/" + titleText.toString() + ".zip");
                mDownloadTask.execute(mDownload.getUrl());
            } else {
                mFabButton.setImageDrawable(mDownloadDrawable);
                mProgressParent.setVisibility(View.INVISIBLE);
                mDownloadTask.cancel();
                mDownloadTask = null;
            }
        }
    });
}