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.gammalabs.wifianalyzer.wifi.AccessPointDetail.java

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

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

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

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

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

    if (isChild) {
        view.findViewById(R.id.tab).setVisibility(View.VISIBLE);
    } else {/*w ww  . jav  a2s .  c o  m*/
        view.findViewById(R.id.tab).setVisibility(View.GONE);
    }
}

From source file:com.accia77.mockey.ui.PapiroActivity.java

@Override
public void onResume() {
    super.onResume();

    setTitle(MyApplication.getInstance().getMainActivityTitle());

    massimaSceltaTextView = (TextView) findViewById(R.id.massimaSceltaTextView);
    String stringaTextView = currentEntry.getUserEditedEntry();

    if (mDoShowAndPlayQuote) {
        // Custom toast con il testo della frase
        LayoutInflater inflater = getLayoutInflater();
        View layout = inflater.inflate(R.layout.papiro_toast, (ViewGroup) findViewById(R.id.toast_layout_root));

        ImageView image = (ImageView) layout.findViewById(R.id.papiro_toast_image);
        image.setImageResource(R.drawable.ic_small_monkey_head);
        TextView text = (TextView) layout.findViewById(R.id.papiro_toast_text);
        text.setText(stringaTextView);// w w  w  .  j  a  v a  2 s. c o  m

        Toast toast = new Toast(this);
        toast.setGravity(Gravity.CENTER_VERTICAL, 0, 0);
        toast.setDuration(Toast.LENGTH_SHORT);
        toast.setView(layout);
        toast.show();

        // Playback of the quote
        if (currentEntry.getEntryType() == MySQLiteHelper.ENTRY_TYPE_PURE_TEXT) {
            MyApplication.getInstance().playSelection(currentEntry);
        } else if (currentEntry.getEntryType() == MySQLiteHelper.ENTRY_TYPE_AUDIO) {
            // No playback if the sd card is not mounted
            if (MyApplication.getInstance().isSdCardMounted(false)) {
                MyApplication.getInstance().playSelection(currentEntry);
            }
        }

        mDoShowAndPlayQuote = false;
    }

    if (MyApplication.getInstance().isDefaultPapiroLoaded()) {
        massimaSceltaTextView.setText(stringaTextView);
        massimaSceltaTextView.setVisibility(View.VISIBLE);
    } else
        massimaSceltaTextView.setVisibility(View.INVISIBLE);

}

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

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

    Drink drink = drinks.get(url);//from www. j  av a  2  s .  c om

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

    TextView drinkInfo = (TextView) v.findViewById(R.id.drink_confirmation_info);
    drinkInfo.setText(drink.getInfo());

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

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

    ImageButton enjoyButton = (ImageButton) v.findViewById(R.id.enjoy_button);
    enjoyButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            Bundle params = new Bundle();
            params.putString("object", drinks.get(url).getURL());
            ((SocialCafeApplication) getActivity().getApplication()).asyncRunner.request("me/og.likes", params,
                    "POST", new EnjoyedDrinkPostListener(), ENJOY_STATE);

        }
    });

    ImageButton menuButton = (ImageButton) v.findViewById(R.id.return_to_menu_button);
    menuButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Intent intent = new Intent(getActivity(), MenuActivity.class);
            intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
            startActivity(intent);
        }
    });
    return v;
}

From source file:com.frostwire.android.gui.adapters.PeerListAdapter.java

private void populateIcon(ImageView icon, Peer peer) {
    if (peer.isLocalHost()) {
        icon.setImageResource(R.drawable.my_files_device);
    } else {/*from ww  w . j ava 2 s.c o m*/
        switch (peer.getDeviceMajorType()) {
        case Constants.DEVICE_MAJOR_TYPE_PHONE:
            icon.setImageResource(R.drawable.device_type_type_phone);
            break;
        case Constants.DEVICE_MAJOR_TYPE_TABLET:
            icon.setImageResource(R.drawable.device_type_icon_tablet);
            break;
        case Constants.DEVICE_MAJOR_TYPE_DESKTOP:
            icon.setImageResource(R.drawable.device_type_icon_desktop);
            break;
        default:
            icon.setImageResource(R.drawable.device_type_type_generic);
        }
    }
}

From source file:com.gudong.appkit.ui.fragment.ColorChooseDialog.java

private View getColorItemView(final Context context, int position, boolean isSelect) {
    int color = mColors[position];
    int widthImageCheckView = Utils.convertDensityPix(context, 24);
    int widthColorView = Utils.convertDensityPix(context, 56);
    int widthMargin = Utils.convertDensityPix(context, 4);

    ImageView imageView = new ImageView(context);
    imageView.setImageResource(R.drawable.ic_check);

    FrameLayout.LayoutParams ivParams = new FrameLayout.LayoutParams(widthImageCheckView, widthImageCheckView);
    ivParams.gravity = Gravity.CENTER;/*from   w  ww .ja  va 2  s. com*/
    imageView.setLayoutParams(ivParams);
    imageView.setVisibility(isSelect ? View.VISIBLE : View.INVISIBLE);

    FrameLayout frameLayout = new FrameLayout(context);
    GridLayout.LayoutParams params = new GridLayout.LayoutParams(
            new FrameLayout.LayoutParams(widthColorView, widthColorView));
    params.setGravity(Gravity.CENTER);
    params.setMargins(widthMargin, widthMargin, widthMargin, widthMargin);
    frameLayout.setLayoutParams(params);

    setBackgroundSelector(frameLayout, color);

    frameLayout.addView(imageView);
    frameLayout.setOnClickListener(this);
    frameLayout.setTag(position);
    return frameLayout;
}

From source file:com.vrem.wifianalyzer.wifi.accesspoint.AccessPointDetail.java

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

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

    Security security = wiFiDetail.getSecurity();
    ImageView securityImage = (ImageView) view.findViewById(R.id.securityImage);
    securityImage.setImageResource(security.getImageResource());
    securityImage.setColorFilter(ContextCompat.getColor(context, R.color.icons_color));

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

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

    if (isChild) {
        view.findViewById(R.id.tab).setVisibility(View.VISIBLE);
    } else {//from ww  w  . j  a  v  a  2  s .  c  o  m
        view.findViewById(R.id.tab).setVisibility(View.GONE);
    }
}

From source file:com.airflo.FlightDetailFragment.java

/**
 * Method to build and add the View. It will consider preferences for
 * certain items, textsizes, and handle empty fields.
 *//*from ww w .j ava 2 s  . c  o m*/
public void addViews() {
    table.setColumnShrinkable(1, true);

    sharedPrefs = PreferenceManager.getDefaultSharedPreferences(OnlyContext.getContext());
    float detSize = Float.valueOf(sharedPrefs.getString("detailtextsize", "20"));
    boolean hideEmpty = sharedPrefs.getBoolean("detailListPrefEmpty", true);
    for (Identi identi : FlightData.identis.getIdentis()) {
        String prefKey = "detailListPref" + identi.getKey();
        if (sharedPrefs.getBoolean(prefKey, true)) {
            if (hideEmpty) {
                if (mItem.getFromKey(identi.getKey()) == null)
                    continue;
                if (mItem.getFromKey(identi.getKey()).equals(""))
                    continue;
            }
            if (identi.getKey().equals("tag")) {
                if (mItem.getFromKey(identi.getKey()).length() > 0) {
                    LinearLayout lnn = (LinearLayout) rootView.findViewById(R.id.LinearAdditionLayout);
                    String[] tags = mItem.getFromKey(identi.getKey()).split(";");
                    for (String tag : tags) {
                        if (tag.equals("off-field"))
                            tag = "off_field";
                        int resID = getResources().getIdentifier(tag, "drawable", "com.airflo");
                        ImageView img = new ImageView(getActivity());
                        img.setImageResource(resID);
                        img.setPadding(8, 14, 8, 0);
                        lnn.addView(img);
                    }
                }

            } else {
                TableRow row = new TableRow(getActivity());

                header = new TextView(getActivity());
                header.setSingleLine();
                header.setTextSize(detSize);
                header.setText(identi.getStringRep());
                header.setPadding(6, 4, 10, 4);
                row.addView(header);

                cell = new TextView(getActivity());
                cell.setSingleLine(false);
                cell.setTextSize(detSize);
                cell.setText(mItem.getFromKey(identi.getKey()));
                cell.setPadding(6, 4, 6, 4);
                row.addView(cell);

                table.addView(row);
            }

        }
    }
}

From source file:com.aokp.romcontrol.github.tasks.GetCommitsInProjectTask.java

protected void onPreExecute() {
    // show commit after we load next set
    mCategory.setTitle(mContext.getString(R.string.loading_commits));
    mCategory.setOrderingAsAdded(true);//from  www .  j a va2  s  .  c o m
    if (mProgressDialog == null) {
        mProgressDialog = new ProgressDialog(mAlertDialog.getContext());
        ImageView imageView = new ImageView(mContext);
        imageView.setImageResource(R.drawable.octacat);
        mProgressDialog.show();
        mProgressDialog.setContentView(R.layout.github_octacat);
    }
}

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

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

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

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

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

    //SET CHANNEL
    ((TextView) view.findViewById(R.id.channel)).setText(wiFiSignal.getChannelDisplay());

    ((TextView) view.findViewById(R.id.primaryFrequency)).setText(String.format(Locale.ENGLISH, "%d%s",
            wiFiSignal.getPrimaryFrequency(), WiFiSignal.FREQUENCY_UNITS));

    ((TextView) view.findViewById(R.id.distance))
            .setText(String.format(Locale.ENGLISH, "%5.1fm", wiFiSignal.getDistance()));

    if (isChild) {
        view.findViewById(R.id.tab).setVisibility(View.VISIBLE);
    } else {//from   ww  w .j  a  v a  2 s .  c om
        view.findViewById(R.id.tab).setVisibility(View.GONE);
    }
}

From source file:cat.picas.spadessamples.adapter.PersonCursorAdapter.java

@Override
public void bindView(View view, Context context, Cursor cursor) {
    Person person = PersonDao.MAPPER.createFromCursor(cursor, mCursorInfo);
    ContactPoint contactPoint = ContactPointDao.MAPPER.createFromCursor(cursor, mCursorInfo);

    TextView nameView = (TextView) view.findViewById(R.id.name);
    TextView contactPointView = (TextView) view.findViewById(R.id.contact_point);
    ImageView hasSpouseView = (ImageView) view.findViewById(R.id.has_spouse);

    nameView.setText(person.getName());//from ww w  . j  av a 2s  . co m
    contactPointView.setText(getContactPoint(contactPoint));
    hasSpouseView.setImageResource((!person.spouse.isNull()) ? android.R.drawable.checkbox_on_background
            : android.R.drawable.checkbox_off_background);
}