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(int key, final Object tag) 

Source Link

Document

Sets a tag associated with this view and a key.

Usage

From source file:ru.orangesoftware.financisto.activity.ActivityLayout.java

public TextView addFilterNodeMinus(LinearLayout layout, int id, int minusId, int labelId, int defaultValueResId,
        String defaultValue) {/*from www  .  j  av  a2 s  . c  o  m*/
    Builder b = inflater.new ListBuilder(layout, R.layout.select_entry_minus).withButtonId(minusId, listener)
            .withId(id, listener).withLabel(labelId);
    if (defaultValue != null) {
        b.withData(defaultValue);
    } else {
        b.withData(defaultValueResId);
    }
    View v = b.create();
    ImageView clearBtn = hideButton(v, minusId);
    TextView text = v.findViewById(R.id.data);
    text.setTag(R.id.bMinus, clearBtn); // needed for dynamic toggling in any activity with filters
    return text;
}

From source file:ru.orangesoftware.financisto.activity.ActivityLayout.java

public Pair<TextView, AutoCompleteTextView> addListNodeWithButtonsAndFilter(LinearLayout layout,
        int nodeLayoutId, int id, int actBtnId, int clearBtnId, int labelId, int defaultValueResId,
        int filterToggleId) {
    ListBuilder b = inflater.new ListBuilder(layout, nodeLayoutId);
    final View v = b.withButtonId(actBtnId, listener).withClearButtonId(clearBtnId, listener)
            .withAutoCompleteFilter(listener, filterToggleId).withId(id, listener).withLabel(labelId)
            .withData(defaultValueResId).create();

    if (actBtnId > 0) {
        showButton(v, actBtnId);//from  w ww .j  av  a 2s.c o m
    }

    AutoCompleteTextView filterTxt = v.findViewById(R.id.autocomplete_filter);
    ToggleButton toggleBtn = v.findViewById(filterToggleId);
    filterTxt.setTag(toggleBtn);

    TextView textView = v.findViewById(R.id.data);
    textView.setTag(R.id.bMinus, v.findViewById(clearBtnId));
    textView.setTag(v);
    return Pair.create(textView, filterTxt);
}

From source file:ru.orangesoftware.financisto.activity.ActivityLayout.java

public Pair<TextView, AutoCompleteTextView> addListNodeCategory(LinearLayout layout, int filterToggleId) {
    ListBuilder b = inflater.new ListBuilder(layout, R.layout.select_entry_category);
    View v = b.withButtonId(R.id.category_add, listener).withClearButtonId(R.id.category_clear, listener)
            .withAutoCompleteFilter(listener, filterToggleId).withId(R.id.category, listener)
            .withLabel(R.string.category).withData(R.string.select_category).create();

    ImageView transferImageView = v.findViewById(R.id.split);
    transferImageView.setId(R.id.category_split);
    transferImageView.setOnClickListener(listener);

    ToggleButton toggleBtn = v.findViewById(filterToggleId);
    AutoCompleteTextView filterTxt = v.findViewById(R.id.autocomplete_filter);
    filterTxt.setTag(toggleBtn);/*from   www.  j  av a  2 s.  co  m*/
    TextView entityNameTxt = v.findViewById(R.id.data);
    entityNameTxt.setTag(R.id.bMinus, v.findViewById(R.id.category_clear));
    return Pair.create(entityNameTxt, filterTxt);
}

From source file:com.google.android.gcm.demo.ui.GroupsFragment.java

@Override
public void refresh() {
    float density = getActivity().getResources().getDisplayMetrics().density;
    SimpleArrayMap<String, Sender> senders = mSenders.getSenders();
    LinearLayout sendersList = new LinearLayout(getActivity());
    sendersList.setOrientation(LinearLayout.VERTICAL);
    for (int i = 0; i < senders.size(); i++) {
        Sender sender = senders.valueAt(i);
        if (sender.groups.size() > 0) {
            LinearLayout senderRow = (LinearLayout) getActivity().getLayoutInflater()
                    .inflate(R.layout.widget_icon_text_button_row, sendersList, false);
            ImageView senderIcon = (ImageView) senderRow.findViewById(R.id.widget_itbr_icon);
            TextView senderText = (TextView) senderRow.findViewById(R.id.widget_itbr_text);
            senderRow.findViewById(R.id.widget_itbr_button).setVisibility(View.GONE);
            senderIcon.setImageResource(R.drawable.cloud_googblue);
            senderIcon.setPadding(0, 0, (int) (8 * density), 0);
            senderText.setText(getString(R.string.groups_sender_id, sender.senderId));
            sendersList.addView(senderRow);
            for (DeviceGroup deviceGroup : sender.groups.values()) {
                LinearLayout row = (LinearLayout) getActivity().getLayoutInflater()
                        .inflate(R.layout.widget_icon_text_button_row, sendersList, false);
                ImageView icon = (ImageView) row.findViewById(R.id.widget_itbr_icon);
                TextView label = (TextView) row.findViewById(R.id.widget_itbr_text);
                Button button = (Button) row.findViewById(R.id.widget_itbr_button);
                icon.setImageResource(R.drawable.group_grey600);
                label.setText(deviceGroup.notificationKeyName);
                label.setBackgroundResource(selectableBackgroundResource);
                label.setTag(R.id.tag_action, ACTION_OPEN_GROUP);
                label.setTag(R.id.tag_senderid, sender.senderId);
                label.setTag(R.id.tag_group, deviceGroup.notificationKeyName);
                label.setOnClickListener(this);

                button.setText(R.string.groups_delete);
                button.setTag(R.id.tag_action, ACTION_DELETE_GROUP);
                button.setTag(R.id.tag_senderid, sender.senderId);
                button.setTag(R.id.tag_group, deviceGroup.notificationKeyName);
                button.setOnClickListener(this);
                row.setPadding((int) (16 * density), 0, 0, 0);
                sendersList.addView(row);
            }// w  w w . j av  a  2s.  co  m
        }
    }
    if (sendersList.getChildCount() == 0) {
        TextView noTokens = new TextView(getActivity());
        noTokens.setText(getString(R.string.groups_no_groups_available));
        noTokens.setTypeface(null, Typeface.ITALIC);
        sendersList.addView(noTokens);
    }
    FrameLayout topicsView = (FrameLayout) getActivity().findViewById(R.id.groups_list_wrapper);
    topicsView.removeAllViews();
    topicsView.addView(sendersList);
}

From source file:edu.stanford.mobisocial.dungbeetle.model.DbObject.java

/**
 * @param v the view to bind//from  w w w. j  a v  a2s  .  com
 * @param context standard activity context
 * @param c the cursor source for the object in the db object table.
 * Must include _id in the projection.
 * 
 * @param allowInteractions controls whether the bound view is
 * allowed to intercept touch events and do its own processing.
 */
public static void bindView(View v, final Context context, Cursor cursor, boolean allowInteractions) {
    TextView nameText = (TextView) v.findViewById(R.id.name_text);
    ViewGroup frame = (ViewGroup) v.findViewById(R.id.object_content);
    frame.removeAllViews();

    // make sure we have all the columns we need
    Long objId = cursor.getLong(cursor.getColumnIndexOrThrow(DbObj.COL_ID));
    String[] projection = null;
    String selection = DbObj.COL_ID + " = ?";
    String[] selectionArgs = new String[] { Long.toString(objId) };
    String sortOrder = null;
    Cursor c = context.getContentResolver().query(DbObj.OBJ_URI, projection, selection, selectionArgs,
            sortOrder);
    if (!c.moveToFirst()) {
        Log.w(TAG, "could not find obj " + objId);
        c.close();
        return;
    }
    DbObj obj = App.instance().getMusubi().objForCursor(c);
    if (obj == null) {
        nameText.setText("Failed to access database.");
        Log.e("DbObject", "cursor was null for bindView of DbObject");
        return;
    }
    DbUser sender = obj.getSender();
    Long timestamp = c.getLong(c.getColumnIndexOrThrow(DbObj.COL_TIMESTAMP));
    Long hash = obj.getHash();
    short deleted = c.getShort(c.getColumnIndexOrThrow(DELETED));
    String feedName = obj.getFeedName();
    String type = obj.getType();
    Date date = new Date(timestamp);
    c.close();
    c = null;

    if (sender == null) {
        nameText.setText("Message from unknown contact.");
        return;
    }
    nameText.setText(sender.getName());

    final ImageView icon = (ImageView) v.findViewById(R.id.icon);
    if (sViewProfileAction == null) {
        sViewProfileAction = new OnClickViewProfile((Activity) context);
    }
    icon.setTag(sender.getLocalId());
    if (allowInteractions) {
        icon.setOnClickListener(sViewProfileAction);
        v.setTag(objId);
    }
    icon.setImageBitmap(sender.getPicture());

    if (deleted == 1) {
        v.setBackgroundColor(sDeletedColor);
    } else {
        v.setBackgroundColor(Color.TRANSPARENT);
    }

    TextView timeText = (TextView) v.findViewById(R.id.time_text);
    timeText.setText(RelativeDate.getRelativeDate(date));

    frame.setTag(objId); // TODO: error prone! This is database id
    frame.setTag(R.id.object_entry, cursor.getPosition()); // this is cursor id
    FeedRenderer renderer = DbObjects.getFeedRenderer(type);
    if (renderer != null) {
        renderer.render(context, frame, obj, allowInteractions);
    }

    if (!allowInteractions) {
        v.findViewById(R.id.obj_attachments_icon).setVisibility(View.GONE);
        v.findViewById(R.id.obj_attachments).setVisibility(View.GONE);
    } else {
        if (!MusubiBaseActivity.isDeveloperModeEnabled(context)) {
            v.findViewById(R.id.obj_attachments_icon).setVisibility(View.GONE);
            v.findViewById(R.id.obj_attachments).setVisibility(View.GONE);
        } else {
            ImageView attachmentCountButton = (ImageView) v.findViewById(R.id.obj_attachments_icon);
            TextView attachmentCountText = (TextView) v.findViewById(R.id.obj_attachments);
            attachmentCountButton.setVisibility(View.VISIBLE);

            if (hash == 0) {
                attachmentCountButton.setVisibility(View.GONE);
            } else {
                //int color = DbObject.colorFor(hash);
                boolean selfPost = false;
                DBHelper helper = new DBHelper(context);
                try {
                    Cursor attachments = obj.getSubfeed().query("type=?", new String[] { LikeObj.TYPE });
                    try {
                        attachmentCountText.setText("+" + attachments.getCount());

                        if (attachments.moveToFirst()) {
                            while (!attachments.isAfterLast()) {
                                if (attachments.getInt(attachments.getColumnIndex(CONTACT_ID)) == -666) {
                                    selfPost = true;
                                    break;
                                }
                                attachments.moveToNext();

                            }
                        }
                    } finally {
                        attachments.close();
                    }
                } finally {
                    helper.close();
                }
                if (selfPost) {
                    attachmentCountButton.setImageResource(R.drawable.ic_menu_love_red);
                } else {
                    attachmentCountButton.setImageResource(R.drawable.ic_menu_love);
                }
                attachmentCountText.setTag(R.id.object_entry, hash);
                attachmentCountText.setTag(R.id.feed_label, Feed.uriForName(feedName));
                attachmentCountText.setOnClickListener(LikeListener.getInstance(context));
            }
        }
    }
}

From source file:org.goodev.discourse.utils.ImageLoader.java

public ImageContainer getForImageSpan(UrlImageGetter imageGetter, String requestUrl, TextView imageView,
        ImageListener listener) {/*from  w  w  w.  ja v a2  s .  c o  m*/

    if (requestUrl == null) {
        requestUrl = "";
    }
    // Find any old image load request pending on this ImageView (in case this view was
    // recycled)
    Object g = imageView.getTag(R.id.poste_image_getter);
    if (g instanceof UrlImageGetter) {
        UrlImageGetter getter = (UrlImageGetter) g;
        ArrayList<ImageContainer> ics = getter.mImageContainers;
        if (getter == imageGetter) {
            boolean inQueue = false;
            ImageContainer result = null;
            for (ImageContainer imageContainer : ics) {
                // Find image url from prior request
                String recycledImageUrl = imageContainer != null ? imageContainer.getRequestUrl() : null;

                // If the new requestUrl is null or the new requestUrl is different to the previous
                // recycled requestUrl
                if (requestUrl.equals(recycledImageUrl)) {
                    inQueue = true;
                    break;
                }
            }
            if (!inQueue) {
                if (requestUrl.length() > 0) {
                    // Queue new request to fetch image
                    return get(requestUrl, listener);
                }
            }
        } else {
            imageView.setTag(R.id.poste_image_getter, null);
            boolean inQueue = false;
            for (ImageContainer imageContainer : ics) {
                // Find image url from prior request
                String recycledImageUrl = imageContainer != null ? imageContainer.getRequestUrl() : null;

                // If the new requestUrl is null or the new requestUrl is different to the previous
                // recycled requestUrl
                if (!requestUrl.equals(recycledImageUrl)) {
                    if (imageContainer != null) {
                        // Cancel previous image request
                        imageContainer.cancelRequest();
                    }
                } else {
                    inQueue = true;
                }
            }
            if (!inQueue) {
                if (requestUrl.length() > 0) {
                    // Queue new request to fetch image
                    return get(requestUrl, listener);
                }
            }

        }
    } else {
        if (requestUrl.length() > 0) {
            // Queue new request to fetch image
            return get(requestUrl, listener);
        }
    }
    return null;

}

From source file:com.hippo.ehviewer.ui.scene.GalleryDetailScene.java

@SuppressWarnings("deprecation")
private void bindTags(GalleryTagGroup[] tagGroups) {
    Context context = getContext2();
    LayoutInflater inflater = getLayoutInflater2();
    Resources resources = getResources2();
    if (null == context || null == inflater || null == resources || null == mTags || null == mNoTags) {
        return;/*w ww. jav  a 2 s . c o m*/
    }

    mTags.removeViews(1, mTags.getChildCount() - 1);
    if (tagGroups == null || tagGroups.length == 0) {
        mNoTags.setVisibility(View.VISIBLE);
        return;
    } else {
        mNoTags.setVisibility(View.GONE);
    }

    int colorTag = resources.getColor(R.color.colorPrimary);
    int colorName = resources.getColor(R.color.purple_a400);
    for (GalleryTagGroup tg : tagGroups) {
        LinearLayout ll = (LinearLayout) inflater.inflate(R.layout.gallery_tag_group, mTags, false);
        ll.setOrientation(LinearLayout.HORIZONTAL);
        mTags.addView(ll);

        TextView tgName = (TextView) inflater.inflate(R.layout.item_gallery_tag, ll, false);
        ll.addView(tgName);
        tgName.setText(tg.groupName);
        tgName.setBackgroundDrawable(new RoundSideRectDrawable(colorName));

        AutoWrapLayout awl = new AutoWrapLayout(context);
        ll.addView(awl, ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
        for (int j = 0, z = tg.size(); j < z; j++) {
            TextView tag = (TextView) inflater.inflate(R.layout.item_gallery_tag, awl, false);
            awl.addView(tag);
            String tagStr = tg.getTagAt(j);
            tag.setText(tagStr);
            tag.setBackgroundDrawable(new RoundSideRectDrawable(colorTag));
            tag.setTag(R.id.tag, tg.groupName + ":" + tagStr);
            tag.setOnClickListener(this);
            tag.setOnLongClickListener(this);
        }
    }
}