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:hochschuledarmstadt.photostream_tools.adapter.BasePhotoPagerAdapter.java

@Override
public Object instantiateItem(ViewGroup container, int position) {
    this.container = container;
    Photo photo = photos.get(position);/*from www.java 2s .  com*/
    LayoutInflater inflater = LayoutInflater.from(container.getContext());
    ViewGroup layout = (ViewGroup) inflater.inflate(layoutResId, container, false);
    layout.setTag(Integer.valueOf(position));
    layout.setId(photo.getId());
    onBindView(layout, position, photo);
    container.addView(layout);
    return layout;
}

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

@Override
public View getView(final int pos, ViewPager pager) {
    Context context = pager.getContext();
    LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    ViewGroup layout = (ViewGroup) inflater.inflate(R.layout.view_product_image, pager, false);
    layout.setTag(pos);

    final View imageLoadingIndicator = layout.findViewById(R.id.image_loading_indicator);
    final ImageView imageView = (ImageView) layout.findViewById(R.id.image);

    if (bitmaps == null) {
        bitmaps = new Bitmap[images.size()];
        Arrays.fill(bitmaps, null);
    }//ww w . jav  a 2s  . co  m

    final boolean needBitmap = bitmaps[pos] == null;
    if (!needBitmap) {
        imageLoadingIndicator.setVisibility(View.INVISIBLE);
        imageView.setImageBitmap(bitmaps[pos]);

    } else {
        // We don't ask Picasso to show a placeholder because we want to scale the placeholder differently than
        // the product image. The placeholder should be displayed using CENTER_INSIDE, while the image should be
        // loaded using Picasso's fit() request method (to reduce memory usage during decoding) and then cropped
        // or fitted into the target view.
        String imageUrl = stripQueryFromUrl(images.get(pos).getSrc());
        ImageUtility.loadRemoteImageIntoViewWithoutSize(Picasso.with(context), imageUrl, imageView, maxWidth,
                maxHeight, false, new Callback() {
                    @Override
                    public void onSuccess() {
                        bitmaps[pos] = ((BitmapDrawable) imageView.getDrawable()).getBitmap();
                        imageLoadingIndicator.setVisibility(View.INVISIBLE);
                        addBackgroundColor(pos);
                    }

                    @Override
                    public void onError() {
                        imageLoadingIndicator.setVisibility(View.VISIBLE);
                    }
                });
    }

    return layout;
}

From source file:com.jgkj.bxxc.fragment.IndexFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    if (container.getTag() == null) {
        view = inflater.inflate(R.layout.index_fragment2, container, false);
        init();//  w  w  w .j a va  2 s.  c om
        getImage();
        getheadlines();
        container.setTag(view);
    } else {
        view = (View) container.getTag();
    }
    return view;
}

From source file:com.rubengees.introduction.IntroductionFragment.java

@NonNull
private View initViews(@NonNull LayoutInflater inflater, @NonNull ViewGroup container) {
    ViewGroup root = (ViewGroup) inflater.inflate(R.layout.introduction_fragment, container, false);
    ViewGroup contentContainer = (ViewGroup) root.findViewById(R.id.introduction_fragment_content_container);

    if (slide.getCustomViewBuilder() == null) {
        contentContainer.addView(initDefaultViews(inflater, container));
    } else {// w w w.j  av  a 2s . com
        contentContainer.addView(initCustomViews(inflater, container));
    }

    root.setBackgroundColor(slide.getColor());
    root.setTag(slide.getPosition());

    return root;
}

From source file:de.egore911.drilog.adapter.ShowDataAdapter.java

@Override
public View getView(int position, View convertView, ViewGroup parent) {
    Object o = getItem(position);
    boolean isUser = o instanceof User;

    ViewGroup row;
    if (null == convertView) {
        // Create a new view for the user or comment
        if (isUser) {
            row = (RelativeLayout) layoutInflater.inflate(R.layout.line_name, null);
            UserViewHolder holder = new UserViewHolder();
            holder.nameField = (TextView) row.findViewById(R.id.name);
            holder.avatarField = (ImageView) row.findViewById(R.id.avatar);
            holder.user = (User) o;//w w w .j  av  a2s . c o m
            row.setTag(holder);
        } else {
            row = (RelativeLayout) layoutInflater.inflate(R.layout.line_comment, null);
            CommentViewHolder holder = new CommentViewHolder();
            holder.commentField = (TextView) row.findViewById(R.id.comment);
            holder.dateField = (TextView) row.findViewById(R.id.date);
            holder.comment = (Comment) o;
            row.setTag(holder);
        }
    } else {
        // Recycle a previous view if possible
        row = (ViewGroup) convertView;
        if (isUser) {
            UserViewHolder holder = (UserViewHolder) row.getTag();
            holder.user = (User) o;
        } else {
            CommentViewHolder holder = (CommentViewHolder) row.getTag();
            holder.comment = (Comment) o;
        }
    }

    if (isUser) {
        User user = (User) o;

        setDefaultCellBackground(position, row, false);

        // Render a user
        UserViewHolder holder = (UserViewHolder) row.getTag();
        if (watchList != null && watchList.contains(user.nick)) {
            holder.nameField.setTypeface(null, Typeface.BOLD);
        } else {
            holder.nameField.setTypeface(null, Typeface.NORMAL);
        }
        holder.nameField.setText(user.name);
        Picasso.with(activity).load(user.image).placeholder(R.drawable.ic_launcher).into(holder.avatarField);
    } else {
        Comment comment = (Comment) o;

        setDefaultCellBackground(position, row, anchor == comment);

        // Render a comment
        CommentViewHolder holder = (CommentViewHolder) row.getTag();
        holder.commentField.setText(comment.content);
        holder.dateField.setText(comment.time);
    }

    return row;
}

From source file:com.cw.litenote.note.Note_adapter.java

@SuppressLint("SetJavaScriptEnabled")
@Override/*from ww  w . j  a  v  a2s  . com*/
public Object instantiateItem(ViewGroup container, final int position) {
    System.out.println("Note_adapter / instantiateItem / position = " + position);
    // Inflate the layout containing 
    // 1. picture group: image,video, thumb nail, control buttons
    // 2. text group: title, body, time 
    View pagerView = inflater.inflate(R.layout.note_view_adapter, container, false);
    int style = Note.getStyle();
    pagerView.setBackgroundColor(ColorSet.mBG_ColorArray[style]);

    // Picture group
    ViewGroup pictureGroup = (ViewGroup) pagerView.findViewById(R.id.pictureContent);
    String tagPictureStr = "current" + position + "pictureView";
    pictureGroup.setTag(tagPictureStr);

    // image view
    TouchImageView imageView = ((TouchImageView) pagerView.findViewById(R.id.image_view));
    String tagImageStr = "current" + position + "imageView";
    imageView.setTag(tagImageStr);

    // video view
    VideoViewCustom videoView = ((VideoViewCustom) pagerView.findViewById(R.id.video_view));
    String tagVideoStr = "current" + position + "videoView";
    videoView.setTag(tagVideoStr);

    ProgressBar spinner = (ProgressBar) pagerView.findViewById(R.id.loading);

    // link web view
    CustomWebView linkWebView = ((CustomWebView) pagerView.findViewById(R.id.link_web_view));
    String tagStr = "current" + position + "linkWebView";
    linkWebView.setTag(tagStr);

    // line view
    View line_view = pagerView.findViewById(R.id.line_view);

    // text group
    ViewGroup textGroup = (ViewGroup) pagerView.findViewById(R.id.textGroup);

    // Set tag for text web view
    CustomWebView textWebView = ((CustomWebView) textGroup.findViewById(R.id.textBody));

    // set accessibility
    textGroup.setContentDescription(act.getResources().getString(R.string.note_text));
    textWebView.getRootView().setContentDescription(act.getResources().getString(R.string.note_text));

    tagStr = "current" + position + "textWebView";
    textWebView.setTag(tagStr);

    // set text web view
    setWebView(textWebView, spinner, CustomWebView.TEXT_VIEW);

    String linkUri = db_page.getNoteLinkUri(position, true);
    String strTitle = db_page.getNoteTitle(position, true);
    String strBody = db_page.getNoteBody(position, true);

    // View mode
    // picture only
    if (Note.isPictureMode()) {
        System.out.println("Note_adapter / _instantiateItem / isPictureMode ");
        pictureGroup.setVisibility(View.VISIBLE);
        showPictureView(position, imageView, videoView, linkWebView, spinner);

        line_view.setVisibility(View.GONE);
        textGroup.setVisibility(View.GONE);
    }
    // text only
    else if (Note.isTextMode()) {
        System.out.println("Note_adapter / _instantiateItem / isTextMode ");
        pictureGroup.setVisibility(View.GONE);

        line_view.setVisibility(View.VISIBLE);
        textGroup.setVisibility(View.VISIBLE);

        if (Util.isYouTubeLink(linkUri) || !Util.isEmptyString(strTitle) || !Util.isEmptyString(strBody)
                || linkUri.startsWith("http")) {
            showTextWebView(position, textWebView);
        }
    }
    // picture and text
    else if (Note.isViewAllMode()) {
        System.out.println("Note_adapter / _instantiateItem / isViewAllMode ");

        // picture
        pictureGroup.setVisibility(View.VISIBLE);
        showPictureView(position, imageView, videoView, linkWebView, spinner);

        line_view.setVisibility(View.VISIBLE);
        textGroup.setVisibility(View.VISIBLE);

        // text
        if (!Util.isEmptyString(strTitle) || !Util.isEmptyString(strBody) || Util.isYouTubeLink(linkUri)
                || linkUri.startsWith("http")) {
            showTextWebView(position, textWebView);
        } else {
            textGroup.setVisibility(View.GONE);
        }
    }

    // footer of note view
    TextView footerText = (TextView) pagerView.findViewById(R.id.note_view_footer);
    if (!Note.isPictureMode()) {
        footerText.setVisibility(View.VISIBLE);
        footerText.setText(String.valueOf(position + 1) + "/" + pager.getAdapter().getCount());
        footerText.setTextColor(ColorSet.mText_ColorArray[Note.mStyle]);
        footerText.setBackgroundColor(ColorSet.mBG_ColorArray[Note.mStyle]);
    } else
        footerText.setVisibility(View.GONE);

    container.addView(pagerView, 0);

    return pagerView;
}

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

/** Creates a new view for use in the list view */
@Override/*from   w ww  .j  a  va 2  s . com*/
public View newView(Context context, Cursor cursor, ViewGroup parent) {
    ViewGroup view = (ViewGroup) inflater.inflate(resource, parent, false);

    view.setTag(new ModelHolder());

    // populate view content
    bindView(view, context, cursor);

    return view;
}

From source file:com.cryart.sabbathschool.adapter.SSReadingViewAdapter.java

@Override
public Object instantiateItem(ViewGroup collection, int position) {
    LayoutInflater inflater = LayoutInflater.from(mContext);
    ViewGroup layout = (ViewGroup) inflater.inflate(R.layout.ss_reading_view, collection, false);
    collection.addView(layout);//from   w  w w.j a v a 2  s  . c  om

    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this.mContext);
    SSReadingDisplayOptions ssReadingDisplayOptions = new SSReadingDisplayOptions(
            prefs.getString(SSConstants.SS_SETTINGS_THEME_KEY, SSReadingDisplayOptions.SS_THEME_LIGHT),
            prefs.getString(SSConstants.SS_SETTINGS_SIZE_KEY, SSReadingDisplayOptions.SS_SIZE_MEDIUM),
            prefs.getString(SSConstants.SS_SETTINGS_FONT_KEY, SSReadingDisplayOptions.SS_FONT_LATO));

    final SSReadingView ssReadingView = layout.findViewById(R.id.ss_reading_view);
    ssReadingView.setReadingDisplayOptions(ssReadingDisplayOptions);
    ssReadingView.setContextMenuCallback(ssReadingViewModel);
    ssReadingView.setHighlightsCommentsCallback(ssReadingViewModel);
    ssReadingView.setReadHighlights(ssReadHighlights.get(position));
    ssReadingView.setReadComments(ssReadComments.get(position));
    ssReadingView.loadRead(ssReads.get(position));

    final Handler handler = new Handler();
    handler.postDelayed(new Runnable() {
        @Override
        public void run() {
            if (ssReadingView != null) {
                ssReadingView.updateHighlights();
                ssReadingView.updateComments();
            }
        }
    }, 800);

    layout.setTag("ssReadingView_" + position);

    return layout;
}

From source file:com.csipsimple.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);
    }//from w w w  . j  ava 2 s  .  c  om

    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);
        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, 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.fututel.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);
    }/*from w w w  .jav  a2  s  .  co  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);
        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, 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_light);

            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);
    }
}