Example usage for android.view ViewGroup setTag

List of usage examples for android.view ViewGroup setTag

Introduction

In this page you can find the example usage for android.view ViewGroup setTag.

Prototype

public void setTag(final Object tag) 

Source Link

Document

Sets the tag associated with this view.

Usage

From source file:com.roamprocess1.roaming4world.ui.favorites.FavAdapter.java

@Override
public void bindView(View view, final Context context, Cursor cursor) {
    ContentValues cv = new ContentValues();
    DatabaseUtils.cursorRowToContentValues(cursor, cv);

    int type = ContactsWrapper.TYPE_CONTACT;
    if (cv.containsKey(ContactsWrapper.FIELD_TYPE)) {
        type = cv.getAsInteger(ContactsWrapper.FIELD_TYPE);
    }/*w w  w .ja v  a 2  s .c  o m*/

    showViewForType(view, type);

    if (type == ContactsWrapper.TYPE_GROUP) {
        // Get views
        TextView tv = (TextView) view.findViewById(R.id.header_text);
        ImageView icon = (ImageView) view.findViewById(R.id.header_icon);
        //   PresenceStatusSpinner presSpinner = (PresenceStatusSpinner) view.findViewById(R.id.header_presence_spinner);

        // Get datas
        SipProfile acc = new SipProfile(cursor);

        final Long profileId = cv.getAsLong(BaseColumns._ID);
        final String groupName = acc.android_group;
        final String displayName = acc.display_name;
        final String wizard = acc.wizard;
        final boolean publishedEnabled = (acc.publish_enabled == 1);
        final String domain = acc.getDefaultDomain();

        // Bind datas to view
        //tv.setText(displayName);  //Commented by Esstel Softwares
        tv.setText("Starred Android Contacts");

        icon.setImageResource(WizardUtils.getWizardIconRes(wizard));
        //  presSpinner.setProfileId(profileId);

        // Extra menu view if not already set
        ViewGroup menuViewWrapper = (ViewGroup) view.findViewById(R.id.header_cfg_spinner);

        MenuCallback newMcb = new MenuCallback(context, profileId, groupName, domain, publishedEnabled);
        MenuBuilder menuBuilder;
        if (menuViewWrapper.getTag() == null) {

            final LayoutParams layoutParams = new LayoutParams(LayoutParams.WRAP_CONTENT,
                    LayoutParams.MATCH_PARENT);

            ActionMenuPresenter mActionMenuPresenter = new ActionMenuPresenter(mContext);
            mActionMenuPresenter.setReserveOverflow(true);
            menuBuilder = new MenuBuilder(context);
            menuBuilder.setCallback(newMcb);
            MenuInflater inflater = new MenuInflater(context);
            inflater.inflate(R.menu.fav_menu_new, menuBuilder);
            menuBuilder.addMenuPresenter(mActionMenuPresenter);
            ActionMenuView menuView = (ActionMenuView) mActionMenuPresenter.getMenuView(menuViewWrapper);
            UtilityWrapper.getInstance().setBackgroundDrawable(menuView, null);
            menuViewWrapper.addView(menuView, layoutParams);
            menuViewWrapper.setTag(menuBuilder);
        } else {
            menuBuilder = (MenuBuilder) menuViewWrapper.getTag();
            menuBuilder.setCallback(newMcb);
        }
        //  menuBuilder.findItem(R.id.share_presence).setTitle(publishedEnabled ? R.string.deactivate_presence_sharing : R.string.activate_presence_sharing);
        // menuBuilder.findItem(R.id.set_sip_data).setVisible(!TextUtils.isEmpty(groupName));

    } else if (type == ContactsWrapper.TYPE_CONTACT) {
        ContactInfo ci = ContactsWrapper.getInstance().getContactInfo(context, cursor);
        ci.userData = cursor.getPosition();
        // Get views
        TextView tv = (TextView) view.findViewById(R.id.contact_name);
        QuickContactBadge badge = (QuickContactBadge) view.findViewById(R.id.quick_contact_photo);
        TextView statusText = (TextView) view.findViewById(R.id.status_text);
        ImageView statusImage = (ImageView) view.findViewById(R.id.status_icon);

        // Bind
        if (ci.contactId != null) {
            tv.setText(ci.displayName);
            badge.assignContactUri(ci.callerInfo.contactContentUri);
            ContactsAsyncHelper.updateImageViewWithContactPhotoAsync(context, badge.getImageView(),
                    ci.callerInfo, R.drawable.ic_contact_picture_holo_dark);

            statusText.setVisibility(ci.hasPresence ? View.VISIBLE : View.GONE);
            statusText.setText(ci.status);
            statusImage.setVisibility(ci.hasPresence ? View.VISIBLE : View.GONE);
            statusImage.setImageResource(ContactsWrapper.getInstance().getPresenceIconResourceId(ci.presence));
        }
        View v;
        v = view.findViewById(R.id.contact_view);
        v.setTag(ci);
        v.setOnClickListener(mPrimaryActionListener);
        v = view.findViewById(R.id.secondary_action_icon);
        v.setTag(ci);
        v.setOnClickListener(mSecondaryActionListener);
    } else if (type == ContactsWrapper.TYPE_CONFIGURE) {
        // We only bind if it's the correct type
        // View v = view.findViewById(R.id.configure_view);
        //v.setOnClickListener(this);
        //ConfigureObj cfg = new ConfigureObj();
        // cfg.profileId = cv.getAsLong(BaseColumns._ID);
        // v.setTag(cfg);
    }
}

From source file:com.todoroo.astrid.adapter.TaskAdapter.java

/** Creates a new view for use in the list view */
@Override//from  w  w  w  .  j  a v  a  2  s . c om
public View newView(Context context, Cursor cursor, ViewGroup parent) {
    ViewGroup view = (ViewGroup) inflater.inflate(R.layout.task_adapter_row_simple, parent, false);

    // create view holder
    ViewHolder viewHolder = new ViewHolder();
    viewHolder.task = new Task();
    viewHolder.rowBody = (ViewGroup) view.findViewById(R.id.rowBody);
    viewHolder.nameView = (TextView) view.findViewById(R.id.title);
    viewHolder.completeBox = (CheckableImageView) view.findViewById(R.id.completeBox);
    viewHolder.dueDate = (TextView) view.findViewById(R.id.due_date);
    viewHolder.tagBlock = (TextView) view.findViewById(R.id.tag_block);
    viewHolder.taskActionContainer = view.findViewById(R.id.taskActionContainer);
    viewHolder.taskActionIcon = (ImageView) view.findViewById(R.id.taskActionIcon);

    boolean showFullTaskTitle = preferences.getBoolean(R.string.p_fullTaskTitle, false);
    if (showFullTaskTitle) {
        viewHolder.nameView.setMaxLines(Integer.MAX_VALUE);
        viewHolder.nameView.setSingleLine(false);
        viewHolder.nameView.setEllipsize(null);
    }

    view.setTag(viewHolder);
    for (int i = 0; i < view.getChildCount(); i++) {
        view.getChildAt(i).setTag(viewHolder);
    }

    // add UI component listeners
    addListeners(view);

    return view;
}

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

/**
 * @param v the view to bind/*from   ww  w  .j ava2  s.co m*/
 * @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));
            }
        }
    }
}