Example usage for android.view View setTag

List of usage examples for android.view View setTag

Introduction

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

Prototype

public void setTag(final Object tag) 

Source Link

Document

Sets the tag associated with this view.

Usage

From source file:com.orangelabs.rcs.ri.messaging.chat.ChatCursorAdapter.java

@Override
public View newView(Context context, Cursor cursor, ViewGroup parent) {
    View view;
    String mimetype = cursor.getString(cursor.getColumnIndexOrThrow(HistoryLog.MIME_TYPE));

    switch (mimetype) {
    case ChatLog.Message.MimeType.GEOLOC_MESSAGE:
    case ChatLog.Message.MimeType.TEXT_MESSAGE:
        view = mInflater.inflate(R.layout.chat_view_item, parent, false);
        view.setTag(new ViewHolderChatMessage(view, cursor));
        break;/*from  ww  w .  ja  va 2 s  . c  om*/

    case ChatLog.Message.MimeType.GROUPCHAT_EVENT:
        view = mInflater.inflate(R.layout.groupchat_event_view_item, parent, false);
        view.setTag(new ViewHolder(view, cursor));
        break;

    default:
        view = mInflater.inflate(R.layout.filetransfer_view_item, parent, false);
        view.setTag(new ViewHolderFileTransfer(view, cursor));
        break;
    }
    return view;
}

From source file:net.idlesoft.android.apps.github.adapters.CommitListAdapter.java

public View getView(final int index, View convertView, final ViewGroup parent) {
    ViewHolder holder;//from w ww. jav  a2  s. c  o m
    if (convertView == null) {
        convertView = mInflater.inflate(R.layout.commit_list_item, null);
        holder = new ViewHolder();
        holder.commit_date = (TextView) convertView.findViewById(R.id.tv_commit_list_item_commit_date);
        holder.commit_shortdesc = (TextView) convertView.findViewById(R.id.tv_commit_list_item_shortdesc);
        holder.gravatar = (ImageView) convertView.findViewById(R.id.iv_commit_list_item_gravatar);
        convertView.setTag(holder);
    } else {
        holder = (ViewHolder) convertView.getTag();
    }
    try {
        String end;
        final SimpleDateFormat dateFormat = new SimpleDateFormat(Hubroid.GITHUB_TIME_FORMAT);
        final Date commit_time = dateFormat.parse(mJson.getJSONObject(index).getString("committed_date"));
        final Date current_time = dateFormat.parse(dateFormat.format(new Date()));
        final long ms = current_time.getTime() - commit_time.getTime();
        final long sec = ms / 1000;
        final long min = sec / 60;
        final long hour = min / 60;
        final long day = hour / 24;
        if (day > 0) {
            if (day == 1) {
                end = " day ago";
            } else {
                end = " days ago";
            }
            holder.commit_date.setText(day + end);
        } else if (hour > 0) {
            if (hour == 1) {
                end = " hour ago";
            } else {
                end = " hours ago";
            }
            holder.commit_date.setText(hour + end);
        } else if (min > 0) {
            if (min == 1) {
                end = " minute ago";
            } else {
                end = " minutes ago";
            }
            holder.commit_date.setText(min + end);
        } else {
            if (sec == 1) {
                end = " second ago";
            } else {
                end = " seconds ago";
            }
            holder.commit_date.setText(sec + end);
        }
        holder.gravatar.setBackgroundDrawable(mContext.getResources().getDrawable(R.drawable.gravatar_border));
        holder.gravatar.setImageBitmap(
                mGravatars.get(mJson.getJSONObject(index).getJSONObject("author").getString("login")));
        holder.commit_shortdesc.setText(mJson.getJSONObject(index).getString("message").split("\n")[0]);
    } catch (final JSONException e) {
        e.printStackTrace();
    } catch (final ParseException e) {
        e.printStackTrace();
    }
    return convertView;
}

From source file:com.aware.ui.Plugins_Manager.java

private void drawUI() {
    //Clear previous states
    store_grid.removeAllViews();//from w ww.ja  va 2  s .  com

    //Build UI
    Cursor installed_plugins = getContentResolver().query(Aware_Plugins.CONTENT_URI, null, null, null,
            Aware_Plugins.PLUGIN_NAME + " ASC");
    if (installed_plugins != null && installed_plugins.moveToFirst()) {
        do {
            final String package_name = installed_plugins
                    .getString(installed_plugins.getColumnIndex(Aware_Plugins.PLUGIN_PACKAGE_NAME));
            final String name = installed_plugins
                    .getString(installed_plugins.getColumnIndex(Aware_Plugins.PLUGIN_NAME));
            final String description = installed_plugins
                    .getString(installed_plugins.getColumnIndex(Aware_Plugins.PLUGIN_DESCRIPTION));
            final String developer = installed_plugins
                    .getString(installed_plugins.getColumnIndex(Aware_Plugins.PLUGIN_AUTHOR));
            final String version = installed_plugins
                    .getString(installed_plugins.getColumnIndex(Aware_Plugins.PLUGIN_VERSION));
            final int status = installed_plugins
                    .getInt(installed_plugins.getColumnIndex(Aware_Plugins.PLUGIN_STATUS));

            final View pkg_view = inflater.inflate(R.layout.plugins_store_pkg_list_item, null, false);
            pkg_view.setTag(package_name); //each view has the package name as a tag for easier references

            try {
                ImageView pkg_icon = (ImageView) pkg_view.findViewById(R.id.pkg_icon);
                if (status != PLUGIN_NOT_INSTALLED) {
                    ApplicationInfo appInfo = getPackageManager().getApplicationInfo(package_name,
                            PackageManager.GET_META_DATA);
                    pkg_icon.setImageDrawable(appInfo.loadIcon(getPackageManager()));
                } else {
                    byte[] img = installed_plugins
                            .getBlob(installed_plugins.getColumnIndex(Aware_Plugins.PLUGIN_ICON));
                    if (img != null)
                        pkg_icon.setImageBitmap(BitmapFactory.decodeByteArray(img, 0, img.length));
                }

                TextView pkg_title = (TextView) pkg_view.findViewById(R.id.pkg_title);
                pkg_title.setText(installed_plugins
                        .getString(installed_plugins.getColumnIndex(Aware_Plugins.PLUGIN_NAME)));

                ImageView pkg_state = (ImageView) pkg_view.findViewById(R.id.pkg_state);

                switch (status) {
                case PLUGIN_DISABLED:
                    pkg_state.setVisibility(View.INVISIBLE);
                    pkg_view.setOnClickListener(new View.OnClickListener() {
                        @Override
                        public void onClick(View v) {
                            AlertDialog.Builder builder = getPluginInfoDialog(name, version, description,
                                    developer);
                            if (isClassAvailable(package_name, "Settings")) {
                                builder.setNegativeButton("Settings", new DialogInterface.OnClickListener() {
                                    @Override
                                    public void onClick(DialogInterface dialog, int which) {
                                        dialog.dismiss();
                                        Intent open_settings = new Intent();
                                        open_settings.setClassName(package_name, package_name + ".Settings");
                                        startActivity(open_settings);
                                    }
                                });
                            }
                            builder.setPositiveButton("Activate", new DialogInterface.OnClickListener() {
                                @Override
                                public void onClick(DialogInterface dialog, int which) {
                                    dialog.dismiss();
                                    Aware.startPlugin(getApplicationContext(), package_name);
                                    drawUI();
                                }
                            });
                            builder.create().show();
                        }
                    });
                    break;
                case PLUGIN_ACTIVE:
                    pkg_state.setImageResource(R.drawable.ic_pkg_active);
                    pkg_view.setOnClickListener(new View.OnClickListener() {
                        @Override
                        public void onClick(View v) {
                            AlertDialog.Builder builder = getPluginInfoDialog(name, version, description,
                                    developer);
                            if (isClassAvailable(package_name, "Settings")) {
                                builder.setNegativeButton("Settings", new DialogInterface.OnClickListener() {
                                    @Override
                                    public void onClick(DialogInterface dialog, int which) {
                                        dialog.dismiss();
                                        Intent open_settings = new Intent();
                                        open_settings.setClassName(package_name, package_name + ".Settings");
                                        startActivity(open_settings);
                                    }
                                });
                            }
                            builder.setPositiveButton("Deactivate", new DialogInterface.OnClickListener() {
                                @Override
                                public void onClick(DialogInterface dialog, int which) {
                                    dialog.dismiss();
                                    Aware.stopPlugin(getApplicationContext(), package_name);
                                    drawUI();
                                }
                            });
                            builder.create().show();
                        }
                    });
                    break;
                case PLUGIN_UPDATED:
                    pkg_state.setImageResource(R.drawable.ic_pkg_updated);
                    pkg_view.setOnClickListener(new View.OnClickListener() {
                        @Override
                        public void onClick(View v) {
                            AlertDialog.Builder builder = getPluginInfoDialog(name, version, description,
                                    developer);
                            if (isClassAvailable(package_name, "Settings")) {
                                builder.setNegativeButton("Settings", new DialogInterface.OnClickListener() {
                                    @Override
                                    public void onClick(DialogInterface dialog, int which) {
                                        dialog.dismiss();
                                        Intent open_settings = new Intent();
                                        open_settings.setClassName(package_name, package_name + ".Settings");
                                        startActivity(open_settings);
                                    }
                                });
                            }
                            builder.setNeutralButton("Deactivate", new DialogInterface.OnClickListener() {
                                @Override
                                public void onClick(DialogInterface dialog, int which) {
                                    dialog.dismiss();
                                    Aware.stopPlugin(getApplicationContext(), package_name);
                                    drawUI();
                                }
                            });
                            builder.setPositiveButton("Update", new DialogInterface.OnClickListener() {
                                @Override
                                public void onClick(DialogInterface dialog, int which) {
                                    dialog.dismiss();
                                    Aware.downloadPlugin(getApplicationContext(), package_name, true);
                                }
                            });
                            builder.create().show();
                        }
                    });
                    break;
                case PLUGIN_NOT_INSTALLED:
                    pkg_state.setImageResource(R.drawable.ic_pkg_download);
                    pkg_view.setOnClickListener(new View.OnClickListener() {
                        @Override
                        public void onClick(View v) {
                            AlertDialog.Builder builder = getPluginInfoDialog(name, version, description,
                                    developer);
                            builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
                                @Override
                                public void onClick(DialogInterface dialog, int which) {
                                    dialog.dismiss();
                                }
                            });
                            builder.setPositiveButton("Install", new DialogInterface.OnClickListener() {
                                @Override
                                public void onClick(DialogInterface dialog, int which) {
                                    dialog.dismiss();
                                    Aware.downloadPlugin(getApplicationContext(), package_name, false);
                                }
                            });
                            builder.create().show();
                        }
                    });
                    break;
                }
                store_grid.addView(pkg_view);
            } catch (NameNotFoundException e) {
                e.printStackTrace();
            }
        } while (installed_plugins.moveToNext());
    }
    if (installed_plugins != null && !installed_plugins.isClosed())
        installed_plugins.close();
}

From source file:com.pdftron.pdf.utils.IconPickerGridViewAdapter.java

@Override
public View getView(int position, View convertView, ViewGroup parent) {
    ViewHolder holder;/*from w  w  w  .ja v a 2 s.  co m*/
    if (convertView == null) {
        // if it's not recycled, initialize some attributes
        convertView = LayoutInflater.from(mContext).inflate(R.layout.tools_gridview_icon_picker, null);

        RelativeLayout layout = (RelativeLayout) convertView.findViewById(R.id.cell_layout);
        ImageView imageView = (ImageView) convertView.findViewById(R.id.icon_image_view);

        holder = new ViewHolder();
        holder.mIconLayout = layout;
        holder.mIconImage = imageView;
        convertView.setTag(holder);
    } else {
        holder = (ViewHolder) convertView.getTag();
    }

    final String iconOutline = Tool.ANNOTATION_NOTE_ICON_FILE_PREFIX + mSource.get(position).toLowerCase()
            + Tool.ANNOTATION_NOTE_ICON_FILE_POSTFIX_OUTLINE;
    final String iconFill = Tool.ANNOTATION_NOTE_ICON_FILE_PREFIX + mSource.get(position).toLowerCase()
            + Tool.ANNOTATION_NOTE_ICON_FILE_POSTFIX_FILL;

    int iconOutlineID = mContext.getResources().getIdentifier(iconOutline, "drawable",
            mContext.getPackageName());
    int iconFillID = mContext.getResources().getIdentifier(iconFill, "drawable", mContext.getPackageName());

    // set selected icon
    if (!mSelected.equals("")) {
        if (mSelected.equals(getItem(position))) {
            Drawable[] layers = new Drawable[2];
            layers[0] = ContextCompat.getDrawable(mContext, iconFillID);
            layers[0].setColorFilter(mIconColor, PorterDuff.Mode.SRC_ATOP);
            layers[1] = ContextCompat.getDrawable(mContext, iconOutlineID);
            LayerDrawable layerDrawable = new LayerDrawable(layers);
            holder.mIconImage.setImageDrawable(layerDrawable);
        } else {
            holder.mIconImage.setImageDrawable(mContext.getResources().getDrawable(iconOutlineID));
        }
    }
    return convertView;
}

From source file:com.hybris.mobile.app.commerce.adapter.ProductListAdapterBase.java

@Override
public View newView(Context arg0, Cursor arg1, ViewGroup arg2) {
    View view = mInflater.inflate(R.layout.item_product_listview, arg2, false);
    view.setTag(new ProductViewHolder(view));
    return view;/*from w w  w  .j  a  v a 2  s.c o m*/
}

From source file:cm.aptoide.com.actionbarsherlock.widget.SuggestionsAdapter.java

/**
 * Tags the view with cached child view look-ups.
 *///from   w w w. j  ava2s  .  c  om
@Override
public View newView(Context context, Cursor cursor, ViewGroup parent) {
    View v = super.newView(context, cursor, parent);
    v.setTag(new ChildViewCache(v));
    return v;
}

From source file:com.dnielfe.manager.adapters.BrowserListAdapter.java

@Override
public View getView(int position, View convertView, ViewGroup parent) {
    final ViewHolder mViewHolder;
    int num_items = 0;
    final File file = new File(getItem(position));
    DateFormat df = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT, Locale.getDefault());

    if (convertView == null) {
        LayoutInflater inflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        convertView = inflater.inflate(R.layout.item_browserlist, parent, false);
        mViewHolder = new ViewHolder(convertView);
        convertView.setTag(mViewHolder);
    } else {//from   w  ww  .  j a  v  a 2  s. c o  m
        mViewHolder = (ViewHolder) convertView.getTag();
    }

    if (Settings.mListAppearance > 0) {
        mViewHolder.dateview.setVisibility(TextView.VISIBLE);
    } else {
        mViewHolder.dateview.setVisibility(TextView.GONE);
    }

    if (Settings.showthumbnail)
        setIcon(file, mViewHolder.icon);
    else
        loadFromRes(file, mViewHolder.icon);

    if (file.isFile()) {
        // Shows the size of File
        mViewHolder.bottomView.setText(FileUtils.byteCountToDisplaySize(file.length()));
    } else {
        String[] list = file.list();

        if (list != null)
            num_items = list.length;

        // show the number of files in Folder
        mViewHolder.bottomView.setText(num_items + mResources.getString(R.string.files));
    }

    mViewHolder.topView.setText(file.getName());
    mViewHolder.dateview.setText(df.format(file.lastModified()));

    return convertView;
}

From source file:com.battlelancer.seriesguide.adapters.BaseShowsAdapter.java

@Override
public View newView(Context context, Cursor cursor, ViewGroup parent) {
    View v = mLayoutInflater.inflate(LAYOUT, parent, false);

    ViewHolder viewHolder = new ViewHolder();
    viewHolder.name = (TextView) v.findViewById(R.id.seriesname);
    viewHolder.timeAndNetwork = (TextView) v.findViewById(R.id.textViewShowsTimeAndNetwork);
    viewHolder.episode = (TextView) v.findViewById(R.id.TextViewShowListNextEpisode);
    viewHolder.episodeTime = (TextView) v.findViewById(R.id.episodetime);
    viewHolder.poster = (ImageView) v.findViewById(R.id.showposter);
    viewHolder.favorited = (ImageView) v.findViewById(R.id.favoritedLabel);
    viewHolder.contextMenu = (ImageView) v.findViewById(R.id.imageViewShowsContextMenu);

    v.setTag(viewHolder);

    return v;/*from www .java  2  s. c  om*/
}

From source file:com.battlelancer.seriesguide.adapters.ActivitySlowAdapter.java

@Override
public View newView(Context context, Cursor cursor, ViewGroup parent) {
    View v = mLayoutInflater.inflate(LAYOUT, parent, false);

    ViewHolder viewHolder = new ViewHolder();
    viewHolder.episode = (TextView) v.findViewById(R.id.textViewUpcomingEpisode);
    viewHolder.show = (TextView) v.findViewById(R.id.textViewUpcomingShow);
    viewHolder.watchedBox = (WatchedBox) v.findViewById(R.id.watchedBoxUpcoming);
    viewHolder.meta = (TextView) v.findViewById(R.id.textViewUpcomingMeta);
    viewHolder.poster = (ImageView) v.findViewById(R.id.poster);

    v.setTag(viewHolder);

    return v;//from   ww w.  jav  a 2  s. co m
}

From source file:com.aniruddhc.acemusic.player.Drawers.NavigationDrawerLibrariesAdapter.java

/**
 * This method returns the view for the selected view.
 *///from  w w  w  .j av a 2s .  c o m
@Override
public View getView(int position, View convertView, ViewGroup parent) {
    Cursor c = (Cursor) getItem(position);

    if (convertView == null) {
        convertView = LayoutInflater.from(mContext).inflate(R.layout.sliding_menu_list_layout, parent, false);
        holder = new LibrariesListViewHolder();

        holder.tagColor = (ImageView) convertView.findViewById(R.id.sliding_menu_libraries_icon);
        holder.title = (TextView) convertView.findViewById(R.id.sliding_menu_list_item);

        holder.title.setTextColor(0xFFFFFFFF);
        holder.title.setTypeface(TypefaceHelper.getTypeface(mContext, "Roboto-Regular"));
        convertView.setTag(holder);
    } else {
        holder = (LibrariesListViewHolder) convertView.getTag();
    }

    //Retrieve the library's parameters.
    String libraryName = c.getString(c.getColumnIndex(DBAccessHelper.LIBRARY_NAME));
    String libraryColorCode = c.getString(c.getColumnIndex(DBAccessHelper.LIBRARY_TAG));

    //Construct the library color tag drawable from the given color code string.
    int colorCodeDrawableID = 0;
    try {
        colorCodeDrawableID = mContext.getResources().getIdentifier(libraryColorCode, "drawable",
                mContext.getPackageName());
    } catch (Exception e) {
        e.printStackTrace();
    }

    //Set the tag for this child view. The key is required to be an application-defined key.
    convertView.setTag(R.string.library_name, libraryName);
    convertView.setTag(R.string.library_color_code, libraryColorCode);

    holder.title.setText(libraryName);
    holder.tagColor.setImageResource(colorCodeDrawableID);

    return convertView;
}