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.money.manager.ex.search.SearchFragment.java

@Subscribe
public void onEvent(AmountEnteredEvent event) {
    View rootView = getView();/*from  ww w.  ja va2  s.co  m*/
    if (rootView == null)
        return;

    int id = Integer.parseInt(event.requestId);
    View view = rootView.findViewById(id);
    if (view != null && view instanceof TextView) {
        TextView textView = (TextView) view;

        // update the value in tag?
        String value = event.amount.toString();
        textView.setTag(value);

        // display amount
        FormatUtilities format = new FormatUtilities(getActivity());
        String displayAmount = format.formatWithLocale(event.amount);
        textView.setText(displayAmount);
    }
}

From source file:com.android.inputmethod.latin.suggestions.SuggestionStripLayoutHelper.java

private int setupWordViewsAndReturnStartIndexOfMoreSuggestions(final SuggestedWords suggestedWords,
        final int maxSuggestionInStrip) {
    // Clear all suggestions first
    for (int positionInStrip = 0; positionInStrip < maxSuggestionInStrip; ++positionInStrip) {
        final TextView wordView = mWordViews.get(positionInStrip);
        wordView.setText(null);/*  ww  w  . ja v a 2s .c  om*/
        wordView.setTag(null);
        // Make this inactive for touches in {@link #layoutWord(int,int)}.
        if (SuggestionStripView.DBG) {
            mDebugInfoViews.get(positionInStrip).setText(null);
        }
    }
    int count = 0;
    int indexInSuggestedWords;
    for (indexInSuggestedWords = 0; indexInSuggestedWords < suggestedWords.size()
            && count < maxSuggestionInStrip; indexInSuggestedWords++) {
        final int positionInStrip = getPositionInSuggestionStrip(indexInSuggestedWords, suggestedWords);
        if (positionInStrip < 0) {
            continue;
        }
        final TextView wordView = mWordViews.get(positionInStrip);
        // {@link TextView#getTag()} is used to get the index in suggestedWords at
        // {@link SuggestionStripView#onClick(View)}.
        wordView.setTag(indexInSuggestedWords);
        wordView.setText(getStyledSuggestedWord(suggestedWords, indexInSuggestedWords));
        wordView.setTextColor(getSuggestionTextColor(suggestedWords, indexInSuggestedWords));
        if (SuggestionStripView.DBG) {
            mDebugInfoViews.get(positionInStrip).setText(suggestedWords.getDebugString(indexInSuggestedWords));
        }
        count++;
    }
    return indexInSuggestedWords;
}

From source file:com.gh4a.activities.IssueEditActivity.java

private void showLabelDialog() {
    if (mAllLabels == null) {
        mProgressDialog = showProgressDialog(getString(R.string.loading_msg), true);
        getSupportLoaderManager().initLoader(0, null, mLabelCallback);
    } else {//from  ww  w .  ja va 2 s  .co m
        LayoutInflater inflater = getLayoutInflater();
        final List<Label> selectedLabels = mEditIssue.getLabels() != null
                ? new ArrayList<>(mEditIssue.getLabels())
                : new ArrayList<Label>();
        View labelContainerView = inflater.inflate(R.layout.generic_linear_container, null);
        ViewGroup container = (ViewGroup) labelContainerView.findViewById(R.id.container);

        View.OnClickListener clickListener = new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Label label = (Label) view.getTag();
                if (selectedLabels.contains(label)) {
                    selectedLabels.remove(label);
                    setLabelSelection((TextView) view, false);
                } else {
                    selectedLabels.add(label);
                    setLabelSelection((TextView) view, true);
                }
            }
        };

        for (final Label label : mAllLabels) {
            final View rowView = inflater.inflate(R.layout.row_issue_create_label, container, false);
            View viewColor = rowView.findViewById(R.id.view_color);
            viewColor.setBackgroundColor(ApiHelpers.colorForLabel(label));

            final TextView tvLabel = (TextView) rowView.findViewById(R.id.tv_title);
            tvLabel.setText(label.getName());
            tvLabel.setOnClickListener(clickListener);
            tvLabel.setTag(label);

            setLabelSelection(tvLabel, selectedLabels.contains(label));
            container.addView(rowView);
        }

        new AlertDialog.Builder(this).setCancelable(true).setTitle(R.string.issue_labels)
                .setView(labelContainerView).setNegativeButton(R.string.cancel, null)
                .setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        mEditIssue.setLabels(selectedLabels);
                        updateLabels();
                    }
                }).show();
    }
}

From source file:com.gh4a.fragment.RepositoryFragment.java

private void fillData() {
    TextView tvRepoName = (TextView) mContentView.findViewById(R.id.tv_repo_name);
    SpannableStringBuilder repoName = new SpannableStringBuilder();
    repoName.append(mRepository.getOwner().getLogin());
    repoName.append("/");
    repoName.append(mRepository.getName());
    repoName.setSpan(new IntentSpan(tvRepoName.getContext()) {
        @Override//  w w w .  ja  va2  s.  com
        protected Intent getIntent() {
            return IntentUtils.getUserActivityIntent(getActivity(), mRepository.getOwner());
        }
    }, 0, mRepository.getOwner().getLogin().length(), 0);
    tvRepoName.setText(repoName);
    tvRepoName.setMovementMethod(UiUtils.CHECKING_LINK_METHOD);

    TextView tvParentRepo = (TextView) mContentView.findViewById(R.id.tv_parent);
    if (mRepository.isFork() && mRepository.getParent() != null) {
        Repository parent = mRepository.getParent();
        tvParentRepo.setVisibility(View.VISIBLE);
        tvParentRepo.setText(
                getString(R.string.forked_from, parent.getOwner().getLogin() + "/" + parent.getName()));
        tvParentRepo.setOnClickListener(this);
        tvParentRepo.setTag(parent);
    } else {
        tvParentRepo.setVisibility(View.GONE);
    }

    fillTextView(R.id.tv_desc, 0, mRepository.getDescription());
    fillTextView(R.id.tv_language, R.string.repo_language, mRepository.getLanguage());
    fillTextView(R.id.tv_url, 0, !StringUtils.isBlank(mRepository.getHomepage()) ? mRepository.getHomepage()
            : mRepository.getHtmlUrl());

    mContentView.findViewById(R.id.cell_stargazers).setOnClickListener(this);
    mContentView.findViewById(R.id.cell_forks).setOnClickListener(this);
    mContentView.findViewById(R.id.cell_pull_requests).setOnClickListener(this);
    mContentView.findViewById(R.id.tv_contributors_label).setOnClickListener(this);
    mContentView.findViewById(R.id.other_info).setOnClickListener(this);
    mContentView.findViewById(R.id.tv_releases_label).setOnClickListener(this);

    Permissions permissions = mRepository.getPermissions();
    updateClickableLabel(R.id.tv_collaborators_label, permissions != null && permissions.hasPushAccess());
    updateClickableLabel(R.id.tv_downloads_label, mRepository.isHasDownloads());
    updateClickableLabel(R.id.tv_wiki_label, mRepository.isHasWiki());

    TextView tvStargazersCount = (TextView) mContentView.findViewById(R.id.tv_stargazers_count);
    tvStargazersCount.setText(String.valueOf(mRepository.getWatchers()));

    TextView tvForksCount = (TextView) mContentView.findViewById(R.id.tv_forks_count);
    tvForksCount.setText(String.valueOf(mRepository.getForks()));

    LinearLayout llIssues = (LinearLayout) mContentView.findViewById(R.id.cell_issues);

    if (mRepository.isHasIssues()) {
        llIssues.setVisibility(View.VISIBLE);
        llIssues.setOnClickListener(this);
        // value will be filled when PR count arrives
    } else {
        llIssues.setVisibility(View.GONE);
    }

    mContentView.findViewById(R.id.tv_private)
            .setVisibility(mRepository.isPrivate() ? View.VISIBLE : View.GONE);

}

From source file:com.nadmm.airports.FragmentBase.java

protected void makeClickToCall(TextView tv) {
    PackageManager pm = mActivity.getPackageManager();
    boolean hasTelephony = pm.hasSystemFeature(PackageManager.FEATURE_TELEPHONY);
    if (hasTelephony && tv.getText().length() > 0) {
        UiUtils.setTextViewDrawable(tv, R.drawable.ic_phone);
        tv.setTag(Intent.ACTION_DIAL);
        tv.setOnClickListener(mOnPhoneClickListener);
    } else {/*from  w  w  w.ja v  a 2 s  .  c  o m*/
        UiUtils.removeTextViewDrawable(tv);
        tv.setOnClickListener(null);
    }
}

From source file:com.dgsd.android.ShiftTracker.Fragment.EditShiftFragment.java

@Override
public void onTimeSelected(long millis) {
    if (getActivity() == null)
        return;//from  w  w w  . ja  v a2 s  .  co m

    TextView tv = null;
    if (mLastTimeSelected == LastTimeSelected.START)
        tv = mStartTime;
    else if (mLastTimeSelected == LastTimeSelected.END)
        tv = mEndTime;
    else
        return; //O no! This should never happen!

    tv.setTag(millis);

    int flags = DateUtils.FORMAT_SHOW_TIME;
    if (DateFormat.is24HourFormat(getActivity()))
        flags |= DateUtils.FORMAT_24HOUR;
    else
        flags |= DateUtils.FORMAT_12HOUR;

    tv.setError(null);
    tv.setText(DateUtils.formatDateRange(getActivity(), millis, millis, flags));
}

From source file:com.huyn.demogroup.relativetop.PagerSlidingTabStrip.java

private void addIconAndTextTab(int position, int resId, String title) {
    LinearLayout tab = new LinearLayout(getContext());
    tab.setGravity(Gravity.CENTER);/*w w w .jav  a2  s. co  m*/

    TextView text = new TextView(getContext());
    text.setText(title);
    text.setTextColor(Color.WHITE);
    text.setGravity(Gravity.CENTER);
    text.setSingleLine();

    ImageView img = new ImageView(getContext());
    img.setImageBitmap(iProvider.getBitmap(resId));

    tab.addView(img);
    tab.addView(text);
    text.setPadding(10, 0, 0, 0);
    text.setTag("TEXT");

    addTab(position, tab);
}

From source file:oyagev.projects.android.ArduCopter.BluetoothChat.java

private void addControl(String name, String type, int commandValue) {

    Log.d(TAG, "Adding cmd: " + commandValue);

    LinearLayout row = new LinearLayout(this);
    row.setOrientation(LinearLayout.HORIZONTAL);
    row.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,
            LinearLayout.LayoutParams.WRAP_CONTENT));

    View view = new TextView(this);

    //hidden view for command value
    TextView cmdView = new TextView(this);
    cmdView.setLayoutParams(new LinearLayout.LayoutParams(0, 0));
    cmdView.setVisibility(View.INVISIBLE);
    cmdView.setText(String.valueOf(commandValue));
    cmdView.setTag("cmd");

    //Setup the control
    if (type.equals("Button")) {
        view = new Button(this);

        ((Button) view).setText(name);
        ((Button) view).setOnClickListener(new OnClickListener() {

            @Override//www . j a  v a2  s . c  o m
            public void onClick(View v) {
                TextView cmd = (TextView) ((LinearLayout) v.getParent()).findViewWithTag("cmd");

                dispatchUserEvent((int) Integer.valueOf(cmd.getText().toString()), new byte[] { 1 });

            }
        });
    } else if (type.equals("Edit")) {
        view = new EditText(this);

        ((EditText) view).setText(name);
    } else if (type.equals("Label")) {
        view = new TextView(this);

        ((TextView) view).setText(name);
    } else if (type.equals("Scrollbar")) {
        view = new LinearLayout(this);

        TextView text = new TextView(this);
        text.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT,
                LinearLayout.LayoutParams.WRAP_CONTENT));
        text.setText(name);
        text.setTag("seek_text");
        SeekBar bar = new SeekBar(this);
        bar.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,
                LinearLayout.LayoutParams.WRAP_CONTENT));

        ((LinearLayout) view).setOrientation(LinearLayout.VERTICAL);

        ((LinearLayout) view).addView(text);
        ((LinearLayout) view).addView(bar);

        bar.setOnSeekBarChangeListener(new OnSeekBarChangeListener() {

            @Override
            public void onStopTrackingTouch(SeekBar seekBar) {
                // TODO Auto-generated method stub

            }

            @Override
            public void onStartTrackingTouch(SeekBar seekBar) {
                // TODO Auto-generated method stub

            }

            @Override
            public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {

                TextView cmd = (TextView) ((LinearLayout) ((LinearLayout) seekBar.getParent()).getParent())
                        .findViewWithTag("cmd");

                ByteBuffer buffer = ByteBuffer.allocate(2);
                buffer.putShort((short) progress);

                dispatchUserEvent((int) Integer.valueOf(cmd.getText().toString()), buffer.array());

            }
        });
    } else if (type.equals("Input String")) {
        view = new LinearLayout(this);

        TextView text = new TextView(this);
        text.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT,
                LinearLayout.LayoutParams.WRAP_CONTENT));
        text.setText(name);
        text.setTag("inp_text");
        TextView inp = new TextView(this);
        inp.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,
                LinearLayout.LayoutParams.WRAP_CONTENT));

        //((LinearLayout)view).setOrientation(LinearLayout.VERTICAL);

        ((LinearLayout) view).addView(text);
        ((LinearLayout) view).addView(inp);

        ycomm.registerCallback((byte) commandValue, new CallbackView(getApplicationContext(), inp) {
            @Override
            public void run(byte type, byte command, byte[] data, byte data_langth) {
                // TODO Auto-generated method stub
                String str = new String(data);
                ((TextView) this.view).setText(str);
            }
        });
    } else {
        return;
    }
    view.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,
            LinearLayout.LayoutParams.WRAP_CONTENT));

    row.addView(cmdView);
    row.addView(view);
    ((LinearLayout) findViewById(R.id.controls_layout)).addView(row);

}

From source file:org.jraf.android.hellomundo.app.pickwebcam.WebcamAdapter.java

@Override
public void bindView(View view, Context context, Cursor cursor) {
    WebcamCursor c = (WebcamCursor) cursor;
    long id = c.getId();

    TextView txtName = (TextView) ViewHolder.get(view, R.id.txtName);
    String name = c.getName();/* w  ww.  j  a v  a  2  s  .  c om*/
    txtName.setText(name);

    WebcamType type = c.getType();
    boolean isUserWebcam = type != null && type == WebcamType.USER;

    // Extend
    View conExtended = ViewHolder.get(view, R.id.conExtended);
    conExtended.setTag(id);
    View btnExtend = ViewHolder.get(view, R.id.btnExtend);
    btnExtend.setTag(conExtended);

    if (cursor.getPosition() == cursor.getCount() - 1) {
        btnExtend.setTag(R.id.lastItem, true);
    } else {
        btnExtend.setTag(R.id.lastItem, false);
    }
    btnExtend.setOnClickListener(mExtendOnClickListener);
    LayoutParams layoutParams = conExtended.getLayoutParams();
    if (mExtendedIds.contains(id)) {
        layoutParams.height = mExtendedHeight;
    } else {
        layoutParams.height = 0;
    }

    // Thumbnail
    ImageView imgThumbnail = ViewHolder.get(view, R.id.imgThumbnail);
    if (isUserWebcam) {
        imgThumbnail.setImageResource(R.drawable.ic_thumbnail_user_defined);
    } else {
        imgThumbnail.setImageResource(0);
        Picasso picasso = Picasso.with(context);
        //            picasso.setDebugging(true);
        picasso.load(c.getThumbUrl())
                .resizeDimen(R.dimen.pickWebcam_item_imgThumbnail_widthHeight,
                        R.dimen.pickWebcam_item_imgThumbnail_widthHeight)
                .centerCrop().placeholder(R.drawable.ic_thumbnail_bg).into(imgThumbnail);
    }

    // Location & time
    TextView txtLocationAndTime = ViewHolder.get(view, R.id.txtLocationAndTime);
    if (isUserWebcam) {
        txtLocationAndTime.setText(R.string.common_userDefined);
    } else {
        String location = c.getLocation();
        String publicId = c.getPublicId();
        boolean specialCam = Constants.SPECIAL_CAMS.contains(publicId);
        if (!specialCam) {
            location += " - " + getLocalTime(context, c.getTimezone());
        }
        txtLocationAndTime.setText(location);
    }

    // Source url
    TextView txtSourceUrl = ViewHolder.get(view, R.id.txtSourceUrl);
    String sourceUrl;
    if (isUserWebcam) {
        sourceUrl = c.getUrl();
        sourceUrl = sourceUrl.substring("http://".length());
        int slashIdx = sourceUrl.indexOf('/');
        if (slashIdx != -1) {
            sourceUrl = sourceUrl.substring(0, slashIdx);
        }
    } else {
        sourceUrl = c.getSourceUrl();
    }
    txtSourceUrl.setText(context.getString(R.string.pickWebcam_source, sourceUrl));
    txtSourceUrl.setTag(sourceUrl);
    txtSourceUrl.setOnClickListener(mSourceOnClickListener);

    // Exclude from random
    Boolean excludeRandom = c.getExcludeRandom();
    boolean excludedFromRandom = excludeRandom != null && excludeRandom;
    View btnExcludeFromRandom = ViewHolder.get(view, R.id.btnExcludeFromRandom);
    btnExcludeFromRandom.setSelected(excludedFromRandom);
    btnExcludeFromRandom.setTag(id);
    btnExcludeFromRandom.setOnClickListener(mExcludeFromRandomOnClickListener);
    ImageView imgExcludedFromRandom = ViewHolder.get(view, R.id.imgExcludedFromRandom);
    if (excludedFromRandom) {
        imgExcludedFromRandom.setVisibility(View.VISIBLE);
    } else {
        imgExcludedFromRandom.setVisibility(View.GONE);
    }

    // Show on map / delete
    View btnShowOnMap = ViewHolder.get(view, R.id.btnShowOnMap);
    ImageView imgShowOnMap = ViewHolder.get(view, R.id.imgShowOnMap);
    TextView txtShowOnMap = ViewHolder.get(view, R.id.txtShowOnMap);
    if (isUserWebcam) {
        imgShowOnMap.setImageResource(R.drawable.ic_ext_delete);
        txtShowOnMap.setText(R.string.pickWebcam_delete);
        btnShowOnMap.setTag(id);
        btnShowOnMap.setOnClickListener(mDeleteOnClickListener);
    } else {
        imgShowOnMap.setImageResource(R.drawable.ic_ext_show_on_map);
        txtShowOnMap.setText(R.string.pickWebcam_showOnMap);
        String coordinates = c.getCoordinates();
        if (coordinates == null) {
            btnShowOnMap.setEnabled(false);
        } else {
            btnShowOnMap.setEnabled(true);
            btnShowOnMap.setTag(R.id.coordinates, coordinates);
            btnShowOnMap.setTag(R.id.name, name);
            btnShowOnMap.setOnClickListener(mShowOnMapOnClickListener);
        }
    }

    View btnPreview = ViewHolder.get(view, R.id.btnPreview);
    btnPreview.setTag(id);
    btnPreview.setOnClickListener(mPreviewOnClickListener);

    // Current webcam
    View conMainItem = ViewHolder.get(view, R.id.conMainItem);
    conMainItem.setSelected(id == mCurrentWebcamId);
}

From source file:org.dalol.orthodoxmezmurmedia.utilities.widgets.AmharicKeyboardView.java

private void populateKeyboardRow(KeyboardRow keyboardRow, int keyHeight) {
    Context context = getContext();
    LinearLayout keyContainer = new LinearLayout(context);
    keyContainer.setOrientation(HORIZONTAL);
    keyContainer.setGravity(Gravity.CENTER);

    List<KeyboardKey> keyList = keyboardRow.getKeyList();
    if (keyList != null) {
        for (int i = 0; i < keyList.size(); i++) {
            KeyboardKey keyboardKey = keyList.get(i);
            if (keyboardKey.getKeyCommand() == KeyboardKey.KEY_EVENT_NORMAL) {
                TextView key = new TextView(context);
                key.setGravity(Gravity.CENTER);
                key.setTypeface(mCharTypeface, Typeface.BOLD);
                key.setText(keyboardKey.getCharCode());
                key.setTextSize(16f);//from   w  w w.j a va2 s  .  c om
                key.setTextColor(
                        ContextCompat.getColorStateList(context, R.color.amharic_key_text_color_selector));
                key.setTag(keyboardKey);
                key.setIncludeFontPadding(false);
                keyContainer.setBaselineAligned(false);
                handleChild(key, keyboardKey.getColumnCount(), keyContainer, keyHeight);
            } else if (keyboardKey.getKeyCommand() == KeyboardKey.KEY_EVENT_BACKSPACE
                    || keyboardKey.getKeyCommand() == KeyboardKey.KEY_EVENT_SPACE
                    || keyboardKey.getKeyCommand() == KeyboardKey.KEY_NEW_LINE
                    || keyboardKey.getKeyCommand() == KeyboardKey.KEY_EVENT_ENTER
                    || keyboardKey.getKeyCommand() == KeyboardKey.KEY_HIDE_KEYBOARD) {
                ImageView child = new ImageView(context);
                child.setImageResource(keyboardKey.getCommandImage());
                int padding = getCustomSize(6);
                child.setPadding(padding, padding, padding, padding);
                child.setTag(keyboardKey);
                handleChild(child, keyboardKey.getColumnCount(), keyContainer, keyHeight);
            }
        }
    }
    addView(keyContainer, new LayoutParams(LayoutParams.MATCH_PARENT, keyHeight));
}