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.mastercard.masterpasswallet.adapters.CardPagerAdapter.java

@Override
public Object instantiateItem(ViewGroup container, int position) {
    final Card card = mCards.get(position);

    View view = LayoutInflater.from(mContext).inflate(R.layout.partial_payment_card, null);
    ImageView cardImage = (ImageView) view.findViewById(R.id.img_card);
    cardImage.setImageResource(card.getCardImageFull());
    TextView cardPan = (TextView) view.findViewById(R.id.txt_card_pan);
    cardPan.setText(mContext.getString(R.string.masked_pan, " " + card.getPANEnding()));

    TextView cardName = (TextView) view.findViewById(R.id.txt_card_name);
    cardName.setText(card.getCardName());
    cardName.setVisibility(View.VISIBLE);

    // Show/hide overlay to indicate if card is suspended or not
    View inactiveOverlay = view.findViewById(R.id.img_overlay);
    if (card.IsActive()) {
        inactiveOverlay.setVisibility(View.GONE);
    } else {// ww w . j a v a 2s . c o m
        inactiveOverlay.setVisibility(View.VISIBLE);
    }

    // Set actions
    if (mListener != null) {
        // Configure card info action
        ImageView imgInfo = (ImageView) view.findViewById(R.id.img_info);
        imgInfo.setVisibility(View.VISIBLE);
        imgInfo.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                mListener.showCardInfo(card);
            }
        });

        // Configure making card default
        ImageView imgDefaultCard = (ImageView) view.findViewById(R.id.img_default_card);
        imgDefaultCard.setVisibility(View.VISIBLE);
        if (card.isDefault(PaymentContext.CONTACTLESS)) {
            imgDefaultCard.setImageResource(R.drawable.ic_favourite_selected);
        } else {
            imgDefaultCard.setImageResource(R.drawable.ic_favourite_deselected);
        }
        imgDefaultCard.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                mListener.makeDefaultcard(card);
            }
        });

    }

    // Configure card balance
    View layBalance = view.findViewById(R.id.lay_balance);
    layBalance.setVisibility(View.VISIBLE);

    TextView txtBalanceType = (TextView) view.findViewById(R.id.tvBalanceType);
    TextView txtBalance = (TextView) view.findViewById(R.id.tvBalance);
    if (card.isCreditCard()) {
        txtBalanceType.setText("Current Balance:");
    } else {
        txtBalanceType.setText("Available Balance:");
    }
    DecimalFormat decimalFormat = new DecimalFormat("$##,##0.00");
    String amount = decimalFormat.format(card.getCardBalance() / 100f);
    txtBalance.setText(amount);

    // Add the layout to the container
    container.addView(view);
    return view;
}

From source file:com.jsvr.sprinkles.tutorial.ScreenSlidePageFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    // Inflate the layout containing a title and body text.
    ViewGroup rootView = (ViewGroup) inflater.inflate(R.layout.fragment_screen_slide_page, container, false);

    //        // Set the title view to show the page number.
    //        ((TextView) rootView.findViewById(android.R.id.text1)).setText(
    //                getString(R.string.title_template_step, mPageNumber + 1));

    if (mDrawable.equals("end")) {
        Button b = (Button) rootView.findViewById(R.id.button_stop_tutorial);
        b.setVisibility(View.VISIBLE);
        TextView t = (TextView) rootView.findViewById(R.id.privacy_warning);
        t.setVisibility(View.VISIBLE);
        return rootView;
    }/*  ww  w . j  a  v a 2s . c  o m*/
    ImageView image = ((ImageView) rootView.findViewById(R.id.tutorial_image));
    int id = getResources().getIdentifier(mDrawable, "drawable", ScreenSlideActivity.PACKAGE_NAME);
    image.setImageResource(id);

    return rootView;
}

From source file:cn.qbcbyb.library.view.PagerTabStrip.java

private void addIconTab(final int position) {

    ImageView tab = new ImageView(getContext());
    tab.setImageResource(indicatorDrawable);
    tab.setScaleType(ImageView.ScaleType.CENTER);

    addTab(position, tab);/*from  ww w .ja v  a2 s  .  co m*/

}

From source file:com.freegeek.android.materialbanner.view.indicator.IconPageIndicator.java

public void notifyDataSetChanged() {
    mIconsLayout.removeAllViews();/* w  ww  . j  av a 2 s  . c  o m*/
    IconPagerAdapter iconAdapter = (IconPagerAdapter) mViewPager.getAdapter();
    int count = iconAdapter.getCount();
    for (int i = 0; i < count; i++) {
        ImageView view = new ImageView(getContext(), null, R.attr.vpiIconPageIndicatorStyle);
        view.setImageResource(iconAdapter.getIconResId(i));
        mIconsLayout.addView(view);
    }
    if (mSelectedIndex > count) {
        mSelectedIndex = count - 1;
    }
    setCurrentItem(mSelectedIndex);
    requestLayout();
    invalidate();
}

From source file:com.example.pagergallerysample.PagerGalleryAdapter.java

@Override
public Object instantiateItem(ViewGroup container, int position) {

    View root = mInflater.inflate(R.layout.item, null);
    ImageView img = (ImageView) root.findViewById(R.id.item_img);
    Resources res = mContext.get().getResources();
    int resId = res.getIdentifier("item" + (position + 1), "drawable", mContext.get().getPackageName());
    img.setImageResource(resId);
    TextView txt = (TextView) root.findViewById(R.id.item_label);
    txt.setText("item " + (position + 1));
    RelativeLayout.LayoutParams lp = new RelativeLayout.LayoutParams(100,
            RelativeLayout.LayoutParams.MATCH_PARENT);
    root.setLayoutParams(lp);//from  w w  w  .  j  av a  2  s  .  c o m
    container.addView(root);
    return root;
}

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

public void render(Context context, ViewGroup frame, Obj obj, boolean allowInteractions) {
    JSONObject content = obj.getJson();//ww  w  . j a  v  a 2s .  c  om
    byte[] raw = obj.getRaw();

    if (raw == null) {
        Pair<JSONObject, byte[]> p = splitRaw(content);
        content = p.first;
        raw = p.second;
    }

    LinearLayout inner = new LinearLayout(context);
    inner.setLayoutParams(CommonLayouts.FULL_WIDTH);
    inner.setOrientation(LinearLayout.HORIZONTAL);
    frame.addView(inner);

    ImageView imageView = new ImageView(context);
    imageView.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT,
            LinearLayout.LayoutParams.WRAP_CONTENT));
    BitmapFactory bf = new BitmapFactory();
    imageView.setImageBitmap(bf.decodeByteArray(raw, 0, raw.length));
    inner.addView(imageView);

    ImageView iconView = new ImageView(context);
    iconView.setImageResource(R.drawable.play);
    iconView.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT,
            LinearLayout.LayoutParams.WRAP_CONTENT));
    inner.addView(iconView);
}

From source file:com.hybris.mobile.lib.ui.view.Alert.java

/**
 * Set the icon on the alert// w  w  w.  ja  v a2  s.c o m
 *
 * @param context       application-specific resources
 * @param configuration describes all device configuration information
 * @param mainView      ViewGroup resources
 * @param textView      alert message to be viewed message to be displayedView
 */
@SuppressLint("NewApi")
private static void setIcon(Activity context, Configuration configuration, ViewGroup mainView,
        TextView textView) {

    ImageView imageView = (ImageView) mainView.findViewById(R.id.alert_view_icon);

    // Reset the current icon
    if (imageView != null) {
        mainView.removeView(imageView);
    }

    // On the textview as well
    textView.setCompoundDrawablesWithIntrinsicBounds(0, 0, 0, 0);
    textView.setCompoundDrawablePadding(0);

    if (configuration.getIconResId() != -1) {

        imageView = new ImageView(context);
        imageView.setId(R.id.alert_view_icon);

        imageView.setImageResource(configuration.getIconResId());
        RelativeLayout.LayoutParams layoutParams = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT,
                LayoutParams.WRAP_CONTENT);
        imageView.setLayoutParams(layoutParams);

        switch (configuration.getIconPosition()) {
        case LEFT_TEXT:
            textView.setCompoundDrawablesWithIntrinsicBounds(configuration.getIconResId(), 0, 0, 0);
            textView.setCompoundDrawablePadding(10);
            break;

        case RIGHT_TEXT:
            textView.setCompoundDrawablesWithIntrinsicBounds(0, 0, configuration.getIconResId(), 0);
            textView.setCompoundDrawablePadding(10);
            break;

        case LEFT:
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
                layoutParams.addRule(RelativeLayout.ALIGN_PARENT_START);
            }

            layoutParams.addRule(RelativeLayout.ALIGN_PARENT_LEFT);
            layoutParams.setMargins(25, 0, 0, 0);
            mainView.addView(imageView);

            // We redefine the layout params otherwise the image is not well aligned
            textView.setLayoutParams(
                    new RelativeLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));
            break;
        case RIGHT:
        default:
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
                layoutParams.addRule(RelativeLayout.ALIGN_PARENT_END);
            }

            layoutParams.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
            layoutParams.setMargins(0, 0, 25, 0);
            mainView.addView(imageView);

            // We redefine the layout params otherwise the image is not well aligned
            textView.setLayoutParams(
                    new RelativeLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));
            break;
        }
    }
}

From source file:com.cse3310.phms.ui.fragments.SlideMenuListFragment.java

@Override
public void onActivityCreated(Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);

    // see FunDapter library at https://github.com/amigold/FunDapter
    BindDictionary<DrawerItem> dict = new BindDictionary<DrawerItem>();
    // setup the text for the items in the sliding menu
    dict.addStringField(R.id.frag_list_item_tv_title, new StringExtractor<DrawerItem>() {
        @Override//from w w  w . j a  v a2 s .  c o  m
        public String getStringValue(DrawerItem drawerItem, int i) {
            return drawerItem.title;
        }
    });

    // setup the icon for the items in the sliding menu
    dict.addStaticImageField(R.id.list_item_icon, new StaticImageLoader<DrawerItem>() {
        @Override
        public void loadImage(DrawerItem item, ImageView imageView, int position) {
            if (item.imageId == DrawerItem.DEFAULT) {
                imageView.setImageResource(R.drawable.ic_launcher);
            } else {
                imageView.setImageResource(item.imageId);
            }
        }
    });

    FunDapter<DrawerItem> adapter = new FunDapter<DrawerItem>(getActivity(), drawerItems, R.layout.list_item,
            dict);
    setListAdapter(adapter);

    getListView().setItemChecked(0, true); // set home in sliding menu as default on start up
}

From source file:com.example.isse.weatherapp.ui.WeatherDetailActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_weather_detail);
    Toolbar toolbar = (Toolbar) findViewById(R.id.detail_toolbar);
    setSupportActionBar(toolbar);/* www .j  a va2 s. c o m*/

    // Show the Up button in the action bar.
    ActionBar actionBar = getSupportActionBar();
    if (actionBar != null) {
        actionBar.setDisplayHomeAsUpEnabled(true);
    }

    //setImage
    ImageView imgTime = (ImageView) findViewById(R.id.img_time);
    switch (getTimeOfDay()) {
    case MORNING:
        imgTime.setImageResource(R.drawable.bg_morning);
        break;
    case DAY:
        imgTime.setImageResource(R.drawable.bg_day);
        break;
    case EVENING:
        imgTime.setImageResource(R.drawable.bg_eve);
        break;
    case NIGHT:
        imgTime.setImageResource(R.drawable.bg_night);
        break;
    default:
        imgTime.setImageResource(R.drawable.bg_day);
    }

    // savedInstanceState is non-null when there is fragment state
    // saved from previous configurations of this activity
    // (e.g. when rotating the screen from portrait to landscape).
    // In this case, the fragment will automatically be re-added
    // to its container so we don't need to manually add it.
    // For more information, see the Fragments API guide at:
    //
    // http://developer.android.com/guide/components/fragments.html
    //
    if (savedInstanceState == null) {
        // Create the detail fragment and add it to the activity
        // using a fragment transaction.
        Bundle arguments = new Bundle();
        arguments.putString(WeatherDetailFragment.ARG_ITEM_ID,
                getIntent().getStringExtra(WeatherDetailFragment.ARG_ITEM_ID));
        arguments.putParcelable(WeatherDetailFragment.ARG_URI,
                getIntent().getParcelableExtra(WeatherDetailFragment.ARG_URI));

        WeatherDetailFragment fragment = new WeatherDetailFragment();
        fragment.setArguments(arguments);
        getSupportFragmentManager().beginTransaction().add(R.id.weather_detail_container, fragment).commit();
    }
}

From source file:com.linkedin.android.eventsapp.ProfileActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_profile);

    Bundle extras = getIntent() != null ? getIntent().getExtras() : new Bundle();
    final Person person = extras.getParcelable("person");
    final Activity currentActivity = this;
    final ActionBar bar = getActionBar();
    View viewActionBar = getLayoutInflater().inflate(R.layout.layout_action_bar, null);

    ImageView backView = (ImageView) viewActionBar.findViewById(R.id.actionbar_left);
    backView.setImageResource(R.drawable.arrow_left);
    backView.setVisibility(View.VISIBLE);
    backView.setClickable(true);//from  ww  w .  j a v  a 2s. c om
    backView.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            currentActivity.finish();
        }
    });

    ActionBar.LayoutParams params = new ActionBar.LayoutParams(ActionBar.LayoutParams.WRAP_CONTENT,
            ActionBar.LayoutParams.MATCH_PARENT);
    bar.setCustomView(viewActionBar, params);
    bar.setDisplayShowCustomEnabled(true);
    bar.setDisplayShowTitleEnabled(false);
    bar.setIcon(new ColorDrawable(Color.TRANSPARENT));
    bar.setBackgroundDrawable(new ColorDrawable(Color.parseColor("#F15153")));

    TextView attendeeNameView = (TextView) findViewById(R.id.attendeeName);
    attendeeNameView.setText(person.getFirstName() + " " + person.getLastName());

    final ImageView attendeeImageView = (ImageView) findViewById(R.id.attendeeImage);
    final TextView attendeeHeadlineView = (TextView) findViewById(R.id.attendeeHeadline);
    final TextView attendeeLocationView = (TextView) findViewById(R.id.attendeeLocation);

    boolean isAccessTokenValid = LISessionManager.getInstance(currentActivity).getSession().isValid();
    if (isAccessTokenValid) {
        String url = Constants.personByIdBaseUrl + person.getLinkedinId() + Constants.personProjection;
        APIHelper.getInstance(currentActivity).getRequest(currentActivity, url, new ApiListener() {
            @Override
            public void onApiSuccess(ApiResponse apiResponse) {
                try {
                    JSONObject s = apiResponse.getResponseDataAsJson();
                    String headline = s.has("headline") ? s.getString("headline") : "";
                    String pictureUrl = s.has("pictureUrl") ? s.getString("pictureUrl") : null;
                    JSONObject location = s.getJSONObject("location");
                    String locationName = location != null && location.has("name") ? location.getString("name")
                            : "";

                    attendeeHeadlineView.setText(headline);
                    attendeeLocationView.setText(locationName);
                    if (pictureUrl != null) {
                        new FetchImageTask(attendeeImageView).execute(pictureUrl);
                    } else {
                        attendeeImageView.setImageResource(R.drawable.ghost_person);
                    }
                } catch (JSONException e) {

                }

            }

            @Override
            public void onApiError(LIApiError apiError) {

            }
        });

        ViewStub viewOnLIStub = (ViewStub) findViewById(R.id.viewOnLIStub);
        View viewOnLI = viewOnLIStub.inflate();
        Button viewOnLIButton = (Button) viewOnLI.findViewById(R.id.viewOnLinkedInButton);
        viewOnLIButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                DeepLinkHelper.getInstance().openOtherProfile(currentActivity, person.getLinkedinId(),
                        new DeepLinkListener() {
                            @Override
                            public void onDeepLinkSuccess() {

                            }

                            @Override
                            public void onDeepLinkError(LIDeepLinkError error) {

                            }
                        });
            }
        });
    } else {
        attendeeImageView.setImageResource(R.drawable.ghost_person);
    }
}