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.benefit.buy.library.viewpagerindicator.IconPageIndicator.java

@Override
public void notifyDataSetChanged() {
    mIconsLayout.removeAllViews();/* ww  w  .j a  v  a  2s .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();
}

From source file:com.jana.android.ui.view.IconPageIndicator.java

public void notifyDataSetChanged() {
    mIconsLayout.removeAllViews();/*from  w  w  w.  j  a v 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));
        view.setPadding(5, 0, 5, 0);
        mIconsLayout.addView(view);
    }
    if (mSelectedIndex > count) {
        mSelectedIndex = count - 1;
    }
    setCurrentItem(mSelectedIndex);
    requestLayout();
}

From source file:com.vrem.wifianalyzer.wifi.AccessPointsDetail.java

public void setView(@NonNull Resources resources, @NonNull View view, @NonNull WiFiDetail wiFiDetail,
        boolean child, boolean frequencyRange) {
    ((TextView) view.findViewById(R.id.ssid)).setText(wiFiDetail.getTitle());

    TextView textIPAddress = (TextView) view.findViewById(R.id.ipAddress);
    TextView textLinkSpeed = (TextView) view.findViewById(R.id.linkSpeed);
    String ipAddress = wiFiDetail.getWiFiAdditional().getIPAddress();
    if (StringUtils.isBlank(ipAddress)) {
        textIPAddress.setVisibility(View.GONE);
        textLinkSpeed.setVisibility(View.GONE);
    } else {//from  w w  w . ja  v a2  s  . co m
        textIPAddress.setVisibility(View.VISIBLE);
        textIPAddress.setText(ipAddress);

        int linkSpeed = wiFiDetail.getWiFiAdditional().getLinkSpeed();
        if (linkSpeed == WiFiConnection.LINK_SPEED_INVALID) {
            textLinkSpeed.setVisibility(View.GONE);
        } else {
            textLinkSpeed.setVisibility(View.VISIBLE);
            textLinkSpeed.setText(String.format("%d%s", linkSpeed, WifiInfo.LINK_SPEED_UNITS));
        }
    }

    ImageView configuredImage = (ImageView) view.findViewById(R.id.configuredImage);
    if (wiFiDetail.getWiFiAdditional().isConfiguredNetwork()) {
        configuredImage.setVisibility(View.VISIBLE);
        configuredImage.setColorFilter(resources.getColor(R.color.connected));
    } else {
        configuredImage.setVisibility(View.GONE);
    }

    WiFiSignal wiFiSignal = wiFiDetail.getWiFiSignal();
    Strength strength = wiFiSignal.getStrength();
    ImageView imageView = (ImageView) view.findViewById(R.id.levelImage);
    imageView.setImageResource(strength.imageResource());
    imageView.setColorFilter(resources.getColor(strength.colorResource()));

    Security security = wiFiDetail.getSecurity();
    ImageView securityImage = (ImageView) view.findViewById(R.id.securityImage);
    securityImage.setImageResource(security.imageResource());
    securityImage.setColorFilter(resources.getColor(R.color.icons_color));

    TextView textLevel = (TextView) view.findViewById(R.id.level);
    textLevel.setText(String.format("%ddBm", wiFiSignal.getLevel()));
    textLevel.setTextColor(resources.getColor(strength.colorResource()));

    ((TextView) view.findViewById(R.id.channel))
            .setText(String.format("%d", wiFiSignal.getWiFiChannel().getChannel()));
    ((TextView) view.findViewById(R.id.frequency))
            .setText(String.format("%d%s", wiFiSignal.getFrequency(), WifiInfo.FREQUENCY_UNITS));
    ((TextView) view.findViewById(R.id.distance)).setText(String.format("%.1fm", wiFiSignal.getDistance()));
    ((TextView) view.findViewById(R.id.capabilities)).setText(wiFiDetail.getCapabilities());

    TextView textVendor = ((TextView) view.findViewById(R.id.vendor));
    String vendor = wiFiDetail.getWiFiAdditional().getVendorName();
    if (StringUtils.isBlank(vendor)) {
        textVendor.setVisibility(View.GONE);
    } else {
        textVendor.setVisibility(View.VISIBLE);
        textVendor.setText(vendor);
    }

    if (child) {
        view.findViewById(R.id.tab).setVisibility(View.VISIBLE);
    } else {
        view.findViewById(R.id.tab).setVisibility(View.GONE);
    }

    if (frequencyRange) {
        view.findViewById(R.id.channel_frequency_range_row).setVisibility(View.VISIBLE);
        ((TextView) view.findViewById(R.id.channel_frequency_range)).setText(String.format("%d - %d %s",
                wiFiSignal.getFrequencyStart(), wiFiSignal.getFrequencyEnd(), WifiInfo.FREQUENCY_UNITS));
    } else {
        view.findViewById(R.id.channel_frequency_range_row).setVisibility(View.GONE);
    }
}

From source file:kr.co.generic.wifianalyzer.wifi.AccessPointDetail.java

private void setViewCompact(@NonNull Context context, @NonNull View view, @NonNull WiFiDetail wiFiDetail,
        boolean isChild) {
    ((TextView) view.findViewById(kr.co.generic.wifianalyzer.R.id.ssid)).setText(wiFiDetail.getTitle());

    WiFiSignal wiFiSignal = wiFiDetail.getWiFiSignal();
    Strength strength = wiFiSignal.getStrength();

    Security security = wiFiDetail.getSecurity();
    ImageView securityImage = (ImageView) view.findViewById(kr.co.generic.wifianalyzer.R.id.securityImage);
    securityImage.setImageResource(security.imageResource());
    securityImage/*from w w  w .j  a v  a2 s .c  om*/
            .setColorFilter(ContextCompat.getColor(context, kr.co.generic.wifianalyzer.R.color.icons_color));

    TextView textLevel = (TextView) view.findViewById(kr.co.generic.wifianalyzer.R.id.level);
    textLevel.setText(String.format(Locale.ENGLISH, "%ddBm", wiFiSignal.getLevel()));
    textLevel.setTextColor(ContextCompat.getColor(context, strength.colorResource()));

    ((TextView) view.findViewById(kr.co.generic.wifianalyzer.R.id.channel))
            .setText(wiFiSignal.getChannelDisplay());
    ((TextView) view.findViewById(kr.co.generic.wifianalyzer.R.id.primaryFrequency)).setText(String
            .format(Locale.ENGLISH, "%d%s", wiFiSignal.getPrimaryFrequency(), WiFiSignal.FREQUENCY_UNITS));
    ((TextView) view.findViewById(kr.co.generic.wifianalyzer.R.id.distance))
            .setText(String.format(Locale.ENGLISH, "%5.1fm", wiFiSignal.getDistance()));

    if (isChild) {
        view.findViewById(kr.co.generic.wifianalyzer.R.id.tab).setVisibility(View.VISIBLE);
    } else {
        view.findViewById(kr.co.generic.wifianalyzer.R.id.tab).setVisibility(View.GONE);
    }
}

From source file:app.wenya.sketchbookpro.ui.view.looppager.IconPageIndicator.java

public void notifyDataSetChanged() {
    mIconsLayout.removeAllViews();//from w ww  .j a v  a 2  s.  c  o m
    IconPagerAdapter iconAdapter = (IconPagerAdapter) mViewPager.getAdapter();
    int count = iconAdapter.getPagerCount();
    LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT,
            LinearLayout.LayoutParams.WRAP_CONTENT);
    lp.leftMargin = 10;
    lp.rightMargin = 10;
    for (int i = 0; i < count; i++) {
        ImageView view = new ImageView(getContext(), null, R.attr.vpiIconPageIndicatorStyle);
        view.setImageResource(iconAdapter.getIconResId(i));
        view.setLayoutParams(lp);
        mIconsLayout.addView(view);
    }
    if (mSelectedIndex > count) {
        mSelectedIndex = count - 1;
    }
    setCurrentItem(mSelectedIndex);
    requestLayout();
}

From source file:com.spoiledmilk.ibikecph.favorites.FavoritesAdapter.java

@Override
public View getView(int position, View convertView, ViewGroup parent) {
    LayoutInflater inflater = (LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    final View view = inflater.inflate(getListRowLayout(), parent, false);
    TextView tv = (TextView) view.findViewById(R.id.textFavoriteName);
    String name = getItem(position).getName();
    if (name.length() > 19)
        name = name.substring(0, 19) + "...";
    tv.setText(name);/*from  www .java  2s  .c  o  m*/
    tv.setTypeface(IbikeApplication.getNormalFont());
    tv.setTextColor(getTextColor());
    ImageButton btnEdit = (ImageButton) view.findViewById(R.id.btnEdit);
    final FavoritesData fd = getItem(position);
    tv.setPadding(getPadding(fd), 0, 0, 0);
    btnEdit.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View arg0) {
            fragment.onEditFavorite(fd);
        }

    });

    final ImageView imgIcon = ((ImageView) view.findViewById(R.id.icon));

    if (!isEditMode) {
        imgIcon.setImageResource(getIconResourceId(getItem(position)));
        btnEdit.setVisibility(View.GONE);
    } else {
        imgIcon.setImageResource(R.drawable.fav_reorder);
        btnEdit.setVisibility(View.VISIBLE);
    }

    return view;
}

From source file:com.angui.exam.widget.IconPageIndicator.java

public void notifyDataSetChanged() {
    mIconsLayout.removeAllViews();//from w  w w  . j a  va2s . co  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));
        final int j = i;
        view.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                // TODO Auto-generated method stub
                setCurrentItem(j);
            }
        });
        mIconsLayout.addView(view);
    }
    if (mSelectedIndex > count) {
        mSelectedIndex = count - 1;
    }
    setCurrentItem(mSelectedIndex);
    requestLayout();
}

From source file:com.futureinst.viewpagerindicator.IconPageIndicator.java

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

From source file:com.justwayward.reader.view.recyclerview.adapter.BaseViewHolder.java

public BaseViewHolder setImageResource(int viewId, int imgResId) {
    ImageView view = getView(viewId);
    view.setImageResource(imgResId);
    return this;
}

From source file:com.facebook.samples.socialcafe.OrderDrinkFragmentActivity.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup parent, Bundle savedInstanceState) {
    View v = inflater.inflate(R.layout.order_drink, parent, false);
    getActivity().setTitle(R.string.place_order);

    TextView userName = (TextView) v.findViewById(R.id.story_order_message);
    userName.setText(getString(R.string.og_message,
            ((SocialCafeApplication) getActivity().getApplication()).userName, drink.getTitle()));

    ImageView userPic = (ImageView) v.findViewById(R.id.user_order_pic);
    userPic.setImageBitmap(((SocialCafeApplication) getActivity().getApplication()).userPic);

    TextView drinkTitle = (TextView) v.findViewById(R.id.drink_order_title);
    drinkTitle.setText(drink.getTitle());

    TextView drinkInfo = (TextView) v.findViewById(R.id.drink_order_info);
    drinkInfo.setText(drink.getInfo());//from  w w w  .j  a v  a 2  s. c o m

    final TextView userMessage = (TextView) v.findViewById(R.id.user_message);

    ImageView drinkImage = (ImageView) v.findViewById(R.id.drink_order_image);
    drinkImage.setImageResource(drink.getImageID());

    ImageButton orderButton = (ImageButton) v.findViewById(R.id.order_drink_button);
    orderButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            dialog = ProgressDialog.show(getActivity(), "", getString(R.string.please_wait), true, true);
            Bundle params = new Bundle();
            params.putString("beverage", drink.getURL());
            if (userMessage.getText() != null && userMessage.getText().length() > 0) {
                params.putString("message", userMessage.getText().toString());
            }
            ((SocialCafeApplication) getActivity().getApplication()).asyncRunner.request("me/social-cafe:order",
                    params, "POST", new OrderDrinkPostListener(), ORDER_STATE);

        }
    });

    ImageButton tagFriendButton = (ImageButton) v.findViewById(R.id.tag_friends);
    tagFriendButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            new AlertDialog.Builder(getActivity()).setMessage(R.string.tag_friends_not_supported)
                    .setPositiveButton(R.string.ok, null).show();
        }
    });

    ImageButton tagLocationButton = (ImageButton) v.findViewById(R.id.tag_location);
    tagLocationButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            new AlertDialog.Builder(getActivity()).setMessage(R.string.tag_location_not_supported)
                    .setPositiveButton(R.string.ok, null).show();
        }
    });

    ImageButton addPhotoButton = (ImageButton) v.findViewById(R.id.add_photo);
    addPhotoButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            new AlertDialog.Builder(getActivity()).setMessage(R.string.add_photo_not_supported)
                    .setPositiveButton(R.string.ok, null).show();
        }
    });

    return v;
}