Example usage for android.widget TextView setTag

List of usage examples for android.widget TextView setTag

Introduction

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

Prototype

public void setTag(final Object tag) 

Source Link

Document

Sets the tag associated with this view.

Usage

From source file:com.prasanna.android.stacknetwork.utils.MarkdownFormatter.java

private static void addImgLinkText(final Context context, ArrayList<View> views, final String url,
        LinearLayout.LayoutParams params) {
    final TextView textView = new TextView(context);
    textView.setTextColor(Color.BLUE);
    textView.setLayoutParams(params);/*from  w  ww  . j  a va  2 s .c  o  m*/
    textView.setText("View image");
    textView.setTextSize(getTextSize(context));
    textView.setPadding(3, 3, 3, 3);
    textView.setTag(url);
    textView.setClickable(true);
    setupOnLinkClick(context, url, textView);
    views.add(textView);
}

From source file:Main.java

/**
 * Make a textview to a collapsible textview with the indicator on the right of the textview
 * //from  w w w  .j  a  v  a 2s.  co  m
 * @param tv , {@link TextView} to be converted
 * @param upDrawableResId , drawable resource id to be used as up indicator
 * @param downDrawableResId , drawable resource id to be used as down indicator
 * @param lineTreshold , no of line to be displayed for the collapsed state
 */
public static void makeCollapsible(final TextView tv, int upDrawableResId, int downDrawableResId,
        final int lineTreshold) {

    final Drawable[] drawables = tv.getCompoundDrawables();
    final Drawable up = tv.getContext().getResources().getDrawable(upDrawableResId);
    final Drawable down = tv.getContext().getResources().getDrawable(downDrawableResId);
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
        tv.setCompoundDrawablesWithIntrinsicBounds(drawables[0], drawables[1], down, drawables[3]);
        tv.setEllipsize(TruncateAt.END);
        tv.setMaxLines(lineTreshold);
        tv.setTag(true);
        tv.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                if (v instanceof TextView) {
                    TextView tv = (TextView) v;
                    boolean snippet = (Boolean) tv.getTag();
                    if (snippet) {
                        // show everything
                        snippet = false;
                        tv.setMaxLines(Integer.MAX_VALUE);
                        tv.setEllipsize(null);
                        tv.setCompoundDrawablesWithIntrinsicBounds(drawables[0], drawables[1], up,
                                drawables[3]);
                    } else {
                        // show snippet
                        snippet = true;
                        tv.setMaxLines(lineTreshold);
                        tv.setEllipsize(TruncateAt.END);
                        tv.setCompoundDrawablesWithIntrinsicBounds(drawables[0], drawables[1], down,
                                drawables[3]);
                    }
                    tv.setTag(snippet);
                }

            }
        });
    } else {
        tv.addTextChangedListener(new TextWatcher() {

            @Override
            public void afterTextChanged(Editable arg0) {

                ViewTreeObserver vto = tv.getViewTreeObserver();
                vto.addOnGlobalLayoutListener(new OnGlobalLayoutListener() {

                    @SuppressWarnings("deprecation")
                    @SuppressLint("NewApi")
                    @Override
                    public void onGlobalLayout() {

                        tv.setEllipsize(TruncateAt.END);
                        int line = tv.getLineCount();
                        tv.setMaxLines(lineTreshold);
                        if (line <= lineTreshold) {
                            tv.setOnClickListener(new View.OnClickListener() {

                                @Override
                                public void onClick(View arg0) {
                                    // empty listener
                                    // Log.d("line count", "count: "+
                                    // tv.getLineCount());
                                }
                            });
                            if (tv.getLayout() != null) {
                                if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN) {
                                    tv.getViewTreeObserver().removeGlobalOnLayoutListener(this);
                                } else {
                                    tv.getViewTreeObserver().removeOnGlobalLayoutListener(this);
                                }
                            }
                            return;
                        }

                        tv.setCompoundDrawablesWithIntrinsicBounds(drawables[0], drawables[1], down,
                                drawables[3]);
                        tv.setTag(true);
                        tv.setOnClickListener(new View.OnClickListener() {

                            @Override
                            public void onClick(View v) {
                                if (v instanceof TextView) {
                                    TextView tv = (TextView) v;
                                    boolean snippet = (Boolean) tv.getTag();
                                    if (snippet) {
                                        snippet = false;
                                        // show everything
                                        tv.setMaxLines(Integer.MAX_VALUE);
                                        tv.setEllipsize(null);
                                        tv.setCompoundDrawablesWithIntrinsicBounds(drawables[0], drawables[1],
                                                up, drawables[3]);
                                    } else {
                                        snippet = true;
                                        // show snippet
                                        tv.setMaxLines(lineTreshold);
                                        tv.setEllipsize(TruncateAt.END);
                                        tv.setCompoundDrawablesWithIntrinsicBounds(drawables[0], drawables[1],
                                                down, drawables[3]);
                                    }
                                    tv.setTag(snippet);
                                }

                            }
                        });

                        if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN) {
                            tv.getViewTreeObserver().removeGlobalOnLayoutListener(this);
                        } else {
                            tv.getViewTreeObserver().removeOnGlobalLayoutListener(this);
                        }
                    }

                });
            }

            @Override
            public void beforeTextChanged(CharSequence arg0, int arg1, int arg2, int arg3) {
            }

            @Override
            public void onTextChanged(CharSequence arg0, int arg1, int arg2, int arg3) {
            }

        });
    }

}

From source file:Main.java

public static void setTime(Activity activity, TextView view, long millis) {
    int flags = DateUtils.FORMAT_SHOW_TIME;
    flags |= DateUtils.FORMAT_CAP_NOON_MIDNIGHT;
    if (DateFormat.is24HourFormat(activity)) {
        flags |= DateUtils.FORMAT_24HOUR;
    }/*w  w w  . j av a 2  s  .  c om*/

    // Unfortunately, DateUtils doesn't support a timezone other than the
    // default timezone provided by the system, so we have this ugly hack
    // here to trick it into formatting our time correctly. In order to
    // prevent all sorts of craziness, we synchronize on the TimeZone class
    // to prevent other threads from reading an incorrect timezone from
    // calls to TimeZone#getDefault()
    // TODO fix this if/when DateUtils allows for passing in a timezone
    String timeString;
    synchronized (TimeZone.class) {
        timeString = DateUtils.formatDateTime(activity, millis, flags);
        TimeZone.setDefault(null);
    }

    view.setTag(millis);
    view.setText(timeString);
}

From source file:com.secbro.qark.exportedcomponent.exportedreceiver.IntentSenderFragment.java

private void createKeyValuePairLayout(String key, LinearLayout paramsLayout) {
    LinearLayout linearLayout = new LinearLayout(getActivity());
    linearLayout.setOrientation(LinearLayout.HORIZONTAL);

    LinearLayout.LayoutParams llp = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
            ViewGroup.LayoutParams.WRAP_CONTENT);
    llp.setMargins(50, 10, 50, 10); // llp.setMargins(left, top, right, bottom);
    TextView keyTextView = new TextView(getActivity());
    keyTextView.setTag("key" + key);
    keyTextView.setText(key);//w  ww  .  ja  v  a  2  s  .c om
    keyTextView.setLayoutParams(llp);

    LinearLayout.LayoutParams llp1 = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.WRAP_CONTENT);
    llp.setMargins(50, 10, 50, 10); // llp.setMargins(left, top, right, bottom);
    EditText valueEditText = new EditText(getActivity());
    valueEditText.setTag("value" + key);
    valueEditText.setLayoutParams(llp1);

    linearLayout.addView(keyTextView);
    linearLayout.addView(valueEditText);
    paramsLayout.addView(linearLayout);
}

From source file:de.azapps.mirakel.adapter.TagAdapter.java

@Override
public void bindView(final View v, final Context ctx, final Cursor c) {
    final Tag tag = new Tag(c);
    final TextView t = (TextView) v.findViewById(R.id.tag_list_name);
    t.setText(tag.getName());/*from www .  j av a  2 s  . c  o m*/
    t.setOnClickListener(this.onClick);
    t.setTag(tag);
}

From source file:com.jbirdvegas.mgerrit.cards.PatchSetReviewersCard.java

@Override
public View setViewValue(Cursor cursor, View convertView, ViewGroup parent) {

    if (convertView == null) {
        convertView = mInflater.inflate(R.layout.patchset_labels_card, parent, false);
    }//from   w w w.  ja  v a  2  s . c  om

    // Locate the views if necessary (these views are constant)
    ViewHolder viewHolder = (ViewHolder) convertView.getTag();
    if (convertView.getTag() == null) {
        viewHolder = new ViewHolder(convertView);
        convertView.setTag(viewHolder);
    }

    setIndicies(cursor);

    TextView reviewer = viewHolder.reviewer;
    reviewer.setTag(cursor.getInt(mReviewerId_index));
    viewHolder.reviewer.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            int reviewerId = (int) v.getTag();
            setTrackingUser(reviewerId);
        }
    });

    GravatarHelper.attachGravatarToTextView(reviewer, cursor.getString(mReviewerEmail_index), mRequestQueue);
    reviewer.setText(cursor.getString(mReviewerName_index));

    setColoredApproval(cursor.getInt(mCodeReview_index), viewHolder.codeReview, viewHolder.codeReviewLayout);
    setColoredApproval(cursor.getInt(mVerified_index), viewHolder.verified, viewHolder.verifiedLayout);

    return convertView;
}

From source file:org.telegram.ui.Components.BotKeyboardView.java

public void setButtons(TLRPC.TL_replyKeyboardMarkup buttons) {
    botButtons = buttons;/*from  w w  w  .j a va 2s.  co m*/
    container.removeAllViews();
    buttonViews.clear();

    if (buttons != null && botButtons.rows.size() != 0) {
        isFullSize = !buttons.resize;
        buttonHeight = !isFullSize ? 42
                : (int) Math.max(42,
                        (panelHeight - AndroidUtilities.dp(30)
                                - (botButtons.rows.size() - 1) * AndroidUtilities.dp(10))
                                / botButtons.rows.size() / AndroidUtilities.density);
        for (int a = 0; a < buttons.rows.size(); a++) {
            TLRPC.TL_keyboardButtonRow row = buttons.rows.get(a);

            LinearLayout layout = new LinearLayout(getContext());
            layout.setOrientation(LinearLayout.HORIZONTAL);
            container.addView(layout, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, buttonHeight, 15,
                    a == 0 ? 15 : 10, 15, a == buttons.rows.size() - 1 ? 15 : 0));

            float weight = 1.0f / row.buttons.size();
            for (int b = 0; b < row.buttons.size(); b++) {
                TLRPC.KeyboardButton button = row.buttons.get(b);
                TextView textView = new TextView(getContext());
                textView.setTag(button);
                textView.setTextColor(ContextCompat.getColor(getContext(), R.color.bot_keyboard_text));
                textView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 16);
                textView.setGravity(Gravity.CENTER);
                textView.setBackgroundResource(R.drawable.bot_keyboard_button2);
                textView.setPadding(AndroidUtilities.dp(4), 0, AndroidUtilities.dp(4), 0);
                textView.setText(Emoji.replaceEmoji(button.text, textView.getPaint().getFontMetricsInt(),
                        AndroidUtilities.dp(16), false));
                layout.addView(textView, LayoutHelper.createLinear(0, LayoutHelper.MATCH_PARENT, weight, 0, 0,
                        b != row.buttons.size() - 1 ? 10 : 0, 0));
                textView.setOnClickListener(new OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        delegate.didPressedButton((TLRPC.KeyboardButton) v.getTag());
                    }
                });
                buttonViews.add(textView);
            }
        }
    }
}

From source file:com.secbro.qark.exportedcomponent.exportedactivity.IntentParamsFragment.java

private void createKeyValuePairLayout(String key, LinearLayout topLayout) {
    LinearLayout linearLayout = new LinearLayout(getActivity());
    linearLayout.setOrientation(LinearLayout.HORIZONTAL);

    TextView keyTextView = new TextView(getActivity());
    keyTextView.setTag("key" + key);
    keyTextView.setText(key);// ww w .ja  v  a2  s  .c  o m
    LinearLayout.LayoutParams llp = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
            ViewGroup.LayoutParams.WRAP_CONTENT);
    llp.setMargins(50, 40, 50, 10); // llp.setMargins(left, top, right, bottom);
    keyTextView.setLayoutParams(llp);

    LinearLayout.LayoutParams llp1 = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.WRAP_CONTENT);
    EditText valueEditText = new EditText(getActivity());
    valueEditText.setTag("value" + key);
    valueEditText.setLayoutParams(llp1);

    linearLayout.addView(keyTextView);
    linearLayout.addView(valueEditText);
    topLayout.addView(linearLayout);
}

From source file:com.jbirdvegas.mgerrit.cards.PatchSetCommentsCard.java

public View setViewValue(Cursor cursor, View convertView, ViewGroup parent) {
    if (convertView == null) {
        convertView = mInflater.inflate(R.layout.commit_comment, parent, false);
    }/*from   w  w w .j a  v a2  s .c om*/

    ViewHolder viewHolder = (ViewHolder) convertView.getTag();
    if (viewHolder == null) {
        viewHolder = new ViewHolder(convertView);
        convertView.setTag(viewHolder);
    }

    setIndicies(cursor);

    TextView author = viewHolder.authorTextView;
    Integer authorNumber = cursor.getInt(authorId_index);
    author.setTag(authorNumber);
    author.setText(cursor.getString(authorName_index));
    author.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            setTrackingUser((Integer) v.getTag());
        }
    });

    String timestamp = cursor.getString(timestamp_index);
    if (timestamp != null) {
        viewHolder.timestamp.setText(Tools.prettyPrintDate(mContext, timestamp,
                Prefs.getServerTimeZone(mContext), Prefs.getLocalTimeZone(mContext)));
    }

    // setup styled comments
    // use Linkify to automatically linking http/email/addresses
    Linkify.addLinks(viewHolder.commentMessage, Linkify.ALL);
    // replace replace emoticons with drawables
    viewHolder.commentMessage
            .setText(EmoticonSupportHelper.getSmiledText(mContext, cursor.getString(message_index)));

    // set gravatar icon for commenter
    viewHolder.gravatar.setImageUrl(GravatarHelper.getGravatarUrl(cursor.getString(authorEmail_index)),
            new ImageLoader(mRequestQuery, new BitmapLruCache(mContext)));

    return convertView;
}

From source file:com.google.cloud.solutions.cloudadventure.GameScoresFragment.java

/**
 * Updates the View for showing the player scores.
 *
 * @param player the player whose scores have been updated
 *///from   w w w.  j a v  a 2  s . c  o  m
private void updateScoresTable(Player player) {
    String handle = player.getHandle();
    TableRow row = new TableRow(getActivity());
    row.setTag(handle);
    TextView text = new TextView(getActivity());
    text.setTag(handle + PLAYER_TAG_SUFFIX);
    text.setGravity(Gravity.CENTER);
    text.setText(handle);
    row.addView(text);
    text = new TextView(getActivity());
    text.setTag(handle + GEMS_TAG_SUFFIX);
    text.setGravity(Gravity.CENTER);
    text.setText(Long.toString(player.getGemsCollected()));
    row.addView(text);
    text = new TextView(getActivity());
    text.setTag(handle + MOBS_TAG_SUFFIX);
    text.setGravity(Gravity.CENTER);
    text.setText(Long.toString(player.getMobsKilled()));
    row.addView(text);
    text = new TextView(getActivity());
    text.setTag(handle + DEATHS_TAG_SUFFIX);
    text.setGravity(Gravity.CENTER);
    text.setText(Long.toString(player.getNumDeaths()));
    row.addView(text);
    mScoresTable.addView(row);
}