Example usage for android.widget ImageView setImageResource

List of usage examples for android.widget ImageView setImageResource

Introduction

In this page you can find the example usage for android.widget ImageView setImageResource.

Prototype

@android.view.RemotableViewMethod(asyncImpl = "setImageResourceAsync")
public void setImageResource(@DrawableRes int resId) 

Source Link

Document

Sets a drawable as the content of this ImageView.

Usage

From source file:com.csipsimple.ui.filters.AccountFiltersListAdapter.java

@Override
public void bindView(View view, Context context, Cursor cursor) {
    Filter filter = new Filter();
    filter.createFromDb(cursor);/*from   ww  w  .  ja  v a 2s  .  c o  m*/
    String filterDesc = filter.getRepresentation(context);

    TextView tv = (TextView) view.findViewById(R.id.line1);
    ImageView icon = (ImageView) view.findViewById(R.id.action_icon);

    tv.setText(filterDesc);
    icon.setContentDescription(filterDesc);
    switch (filter.action) {
    case Filter.ACTION_CAN_CALL:
        icon.setImageResource(R.drawable.ic_menu_goto);
        break;
    case Filter.ACTION_CANT_CALL:
        icon.setImageResource(R.drawable.ic_menu_blocked_user);
        break;
    case Filter.ACTION_REPLACE:
        icon.setImageResource(android.R.drawable.ic_menu_edit);
        break;
    case Filter.ACTION_DIRECTLY_CALL:
        icon.setImageResource(R.drawable.ic_menu_answer_call);
        break;
    case Filter.ACTION_AUTO_ANSWER:
        icon.setImageResource(R.drawable.ic_menu_auto_answer);
        break;
    default:
        break;
    }
}

From source file:com.android.jhansi.designchallenge.NavigationDrawerActivity.java

private void showCustomToast(int resId) {
    LayoutInflater inflater = getLayoutInflater();
    View layout = inflater.inflate(R.layout.custom_toast, (ViewGroup) findViewById(R.id.custom_toast_layout));

    ImageView image = (ImageView) layout.findViewById(R.id.image);
    image.setImageResource(resId);

    Toast toast = new Toast(getApplicationContext());
    toast.setGravity(Gravity.TOP, 0, -1);
    toast.setDuration(Toast.LENGTH_SHORT);
    toast.setView(layout);//from ww  w.j ava 2 s  . c  o  m
    toast.show();
}

From source file:com.machine.custom.viewpagerindicator.IconPageIndicator.java

public void notifyDataSetChanged() {
    mIconsLayout.removeAllViews();/*from   w w  w .j ava2  s.co m*/
    IconPagerAdapter iconAdapter = (IconPagerAdapter) mViewPager.getAdapter();
    int count = iconAdapter.getCount();
    if (iconStylesId == 0) {
        iconStylesId = R.attr.focusCricleStyle;
    }
    for (int i = 0; i < count; i++) {
        ImageView view = new ImageView(getContext(), null, iconStylesId);
        view.setImageResource(iconAdapter.getIconResId(i));
        mIconsLayout.addView(view);
    }
    if (mSelectedIndex > count) {
        mSelectedIndex = count - 1;
    }
    setCurrentItem(mSelectedIndex);
    requestLayout();
    //        isTransmit = true;
}

From source file:com.manning.androidhacks.hack008.MainActivity.java

private ImageView createNewView() {
    ImageView ret = new ImageView(this);
    ret.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));
    ret.setScaleType(ScaleType.FIT_XY);//from w  w w . ja va2  s .co  m
    ret.setImageResource(PHOTOS[mIndex]);
    mIndex = (mIndex + 1 < PHOTOS.length) ? mIndex + 1 : 0;

    return ret;
}

From source file:com.filemanager.free.adapters.DrawerAdapter.java

@Override
public View getView(final int position, View convertView, ViewGroup parent) {
    if (values.get(position).isSection()) {
        ImageView view = new ImageView(context);
        if (m.theme1 == 0)
            view.setImageResource(R.color.divider);
        else/*from   w ww. j av a 2  s.  co m*/
            view.setImageResource(R.color.divider_dark);
        view.setClickable(false);
        view.setFocusable(false);
        if (m.theme1 == 0)
            view.setBackgroundColor(Color.WHITE);
        else
            view.setBackgroundResource(R.color.background_material_dark);
        view.setLayoutParams(new AbsListView.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, m.dpToPx(17)));
        view.setPadding(0, m.dpToPx(8), 0, m.dpToPx(8));
        return view;
    } else {
        View view = inflater.inflate(R.layout.drawerrow, parent, false);
        final TextView txtTitle = (TextView) view.findViewById(R.id.firstline);
        final ImageView imageView = (ImageView) view.findViewById(R.id.icon);
        if (m.theme1 == 0) {
            view.setBackgroundResource(R.drawable.safr_ripple_white);
        } else {
            view.setBackgroundResource(R.drawable.safr_ripple_black);
        }
        view.setOnClickListener(new View.OnClickListener() {

            public void onClick(View p1) {
                m.selectItem(position);
            }
            // TODO: Implement this method

        });
        view.setOnLongClickListener(new View.OnLongClickListener() {
            @Override
            public boolean onLongClick(View v) {
                if (!getItem(position).isSection())
                    // not to remove the first bookmark (storage) and permanent bookmarks
                    if (position > m.storage_count && position < values.size() - 7) {
                        EntryItem item = (EntryItem) getItem(position);
                        String path = (item).getPath();
                        if (DataUtils.containsBooks(new String[] { item.getTitle(), path }) != -1) {
                            m.renameBookmark((item).getTitle(), path);
                        } else if (path.startsWith("smb:/")) {
                            m.showSMBDialog(item.getTitle(), path, true);
                        }
                    } else if (position < m.storage_count) {
                        String path = ((EntryItem) getItem(position)).getPath();
                        if (!path.equals("/"))
                            new Futils().showProps(RootHelper.generateBaseFile(new File(path), true), m,
                                    m.theme1);
                    }

                // return true to denote no further processing
                return true;
            }
        });

        txtTitle.setText(((EntryItem) (values.get(position))).getTitle());
        imageView.setImageDrawable(getDrawable(position));
        imageView.clearColorFilter();
        if (myChecked.get(position)) {
            if (m.theme1 == 0)
                view.setBackgroundColor(Color.parseColor("#ffeeeeee"));
            else
                view.setBackgroundColor(Color.parseColor("#ff424242"));
            imageView.setColorFilter(fabskin);
            txtTitle.setTextColor(Color.parseColor(m.fabskin));
        } else {
            if (m.theme1 == 0) {
                imageView.setColorFilter(Color.parseColor("#666666"));
                txtTitle.setTextColor(ContextCompat.getColor(getContext(), android.R.color.black));
            } else {
                imageView.setColorFilter(Color.WHITE);
                txtTitle.setTextColor(ContextCompat.getColor(getContext(), android.R.color.white));
            }
        }

        return view;
    }
}

From source file:com.koushikdutta.superuser.PolicyFragmentInternal.java

@Override
public void onCreate(Bundle savedInstanceState, View view) {
    super.onCreate(savedInstanceState, view);

    getFragment().setHasOptionsMenu(true);

    setEmpty(R.string.no_apps);/*  w w  w .  j av  a2 s  . co m*/

    load();

    if ("com.koushikdutta.superuser".equals(getContext().getPackageName())) {
        ImageView watermark = (ImageView) view.findViewById(R.id.watermark);
        if (watermark != null)
            watermark.setImageResource(R.drawable.clockwork512);
    }
    if (!isPaged())
        showAllLogs();
}

From source file:com.androsz.electricsleepbeta.alarmclock.AlarmClock.java

private void updateIndicatorAndAlarm(final boolean enabled, final ImageView bar, final Alarm alarm) {
    bar.setImageResource(enabled ? R.drawable.ic_indicator_on : R.drawable.ic_indicator_off);
    Alarms.enableAlarm(this, alarm.id, enabled);
    if (enabled) {
        SetAlarm.popAlarmSetToast(this, alarm.hour, alarm.minutes, alarm.daysOfWeek);
    }/*from ww w.ja va  2s. c  o m*/
}

From source file:com.github.tetravex_android.activity.HowToActivity.java

/**
 * Sets the page indicator dots at the bottom of the screen to indicate which page is displayed
 *
 * @param pageIndex the index of the page currently displayed
 *//*from  ww  w . j  a v  a 2 s .com*/
private void setIndicatorDots(int pageIndex) {
    // set the indicator dot for the correct page
    LinearLayout dotGroup = (LinearLayout) findViewById(R.id.how_to_pager_dots);
    for (int i = 0; i < dotGroup.getChildCount(); i++) {
        ImageView view = (ImageView) dotGroup.getChildAt(i);
        String tagString = (String) view.getTag();
        int tagId = Integer.valueOf(tagString);

        if (tagId == pageIndex) {
            view.setImageResource(R.drawable.pager_dot_on);
        } else {
            view.setImageResource(R.drawable.pager_dot_off);
        }
    }
}

From source file:edu.stanford.mobisocial.dungbeetle.feed.objects.VoiceObj.java

public void render(Context context, ViewGroup frame, Obj obj, boolean allowInteractions) {
    ImageView imageView = new ImageView(context);
    imageView.setImageResource(R.drawable.play);
    imageView.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT,
            LinearLayout.LayoutParams.WRAP_CONTENT));
    frame.addView(imageView);//from w  ww .jav a  2s.  co m
}

From source file:com.example.android.tourguide.CategoryAdaptor.java

@Override
public View getView(int position, View convertView, ViewGroup parent) {
    // Check if an existing view is being reused, otherwise inflate the view
    View listItemView = convertView;
    if (listItemView == null) {
        listItemView = LayoutInflater.from(getContext()).inflate(R.layout.list_item, parent, false);
    }//from   www  . j  ava2  s. c om

    // Get the {@link Category} object located at this position in the list
    Category currentCategory = getItem(position);

    // Find the TextView in the list_item.xml layout with the ID category_view.
    TextView categoryView = (TextView) listItemView.findViewById(R.id.catergory_view);
    // Get the Category from the currentCategry object and set this text on
    // the Category TextView.
    categoryView.setText(currentCategory.getCategory());

    // Set the theme color for the list item
    View textContainer = listItemView.findViewById(R.id.text_container);
    // Find the color that resource ID maps
    int color = ContextCompat.getColor(getContext(), mColorResourceID);
    // Set the background color of the text container view
    textContainer.setBackgroundColor(color);

    // Find the ImageView in the list_item.xml layout with the ID image.
    ImageView imageView = (ImageView) listItemView.findViewById(R.id.image);

    if (currentCategory.hasImage()) {
        // Set the image view to the image resource specified in the current word.
        imageView.setImageResource(currentCategory.getImageResourceId());
        // Find the color that resource ID maps
        imageView.setBackgroundColor(color);

        // Make sure the view is Visible
        imageView.setVisibility(View.VISIBLE);
    } else {
        imageView.setVisibility(View.GONE);
    }

    // Return the whole list item layout so that it can be shown in
    // the ListView.
    return listItemView;
}