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.i2max.i2smartwork.common.conference.ConferenceDetailViewFragment.java

public void setFilesLayout(String title, LinearLayout targetLayout, Object object) {

    final List<LinkedTreeMap<String, String>> filesList = (List<LinkedTreeMap<String, String>>) object;
    if (filesList == null || (filesList != null && filesList.size() <= 0)) {
        targetLayout.setVisibility(View.GONE);
    } else {//  w ww.j ava  2  s  .  c  o  m
        Log.e(TAG, "fileList size =" + filesList.size());
        targetLayout.setVisibility(View.VISIBLE);
        targetLayout.removeAllViews();
        //addTitleView
        LinearLayout.LayoutParams tvParam = new LinearLayout.LayoutParams(
                LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT);
        tvParam.setMargins(0, DisplayUtil.dip2px(getActivity(), 12), 0, DisplayUtil.dip2px(getActivity(), 10));

        TextView tvTitle = new TextView(getActivity());
        tvTitle.setLayoutParams(tvParam);
        if (Build.VERSION.SDK_INT < 23) {
            tvTitle.setTextAppearance(getActivity(), android.R.style.TextAppearance_Material_Medium);
        } else {
            tvTitle.setTextAppearance(android.R.style.TextAppearance_Material_Medium);
        }
        tvTitle.setTextSize(TypedValue.COMPLEX_UNIT_SP, 15);
        tvTitle.setTextColor(getResources().getColor(R.color.text_color_black));
        tvTitle.setText(title);

        targetLayout.addView(tvTitle);

        //addFilesView
        for (int i = 0; i < filesList.size(); i++) {
            final LinkedTreeMap<String, String> fileMap = filesList.get(i);
            LayoutInflater inflater = (LayoutInflater) getActivity()
                    .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            View fileView = inflater.inflate(R.layout.view_item_file, null);

            ImageView ivIcFileExt = (ImageView) fileView.findViewById(R.id.iv_ic_file_ext);
            TextView tvFileNm = (TextView) fileView.findViewById(R.id.tv_file_nm);

            //??  ? 
            ivIcFileExt.setImageResource(R.drawable.ic_file_doc);
            String fileNm = FormatUtil.getStringValidate(fileMap.get("file_nm"));
            tvFileNm.setText(fileNm);
            FileUtil.setFileExtIcon(ivIcFileExt, fileNm);
            final String fileExt = FileUtil.getFileExtsion(fileNm);
            final String downloadURL = I2UrlHelper.File
                    .getDownloadFile(FormatUtil.getStringValidate(fileMap.get("file_id")));

            fileView.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {

                    try {
                        Intent intent = null;
                        if ("Y".equals(FormatUtil.getStringValidate(fileMap.get("conv_yn")))) {
                            //i2viewer ? ( conv_yn='Y')
                            intent = IntentUtil.getI2ViewerIntent(
                                    FormatUtil.getStringValidate(fileMap.get("file_id")),
                                    FormatUtil.getStringValidate(fileMap.get("file_nm")));
                            getActivity().startActivity(intent);
                        } else if ("mp4".equalsIgnoreCase(fileExt) || "fla".equalsIgnoreCase(fileExt)
                                || "wmv".equalsIgnoreCase(fileExt) || "avi".equalsIgnoreCase(fileExt)) { //video
                            intent = IntentUtil.getVideoPlayIntent(downloadURL);
                        } else {
                            //? ??
                            intent = new Intent(Intent.ACTION_VIEW, Uri.parse(downloadURL));
                            Bundle bundle = new Bundle();
                            bundle.putString("Authorization", I2UrlHelper.getTokenAuthorization());
                            intent.putExtra(Browser.EXTRA_HEADERS, bundle);
                            Log.d(TAG, "intent:" + intent.toString());
                        }
                        getActivity().startActivity(intent);
                    } catch (ActivityNotFoundException e) {
                        Toast.makeText(getActivity(),
                                "I2Viewer? ?  .\n  ? ?.",
                                Toast.LENGTH_LONG).show();
                        //TODO ? ? ?   URL
                    }
                }
            });

            targetLayout.addView(fileView);
        }

    }
}

From source file:com.cicada.yuanxiaobao.common.BaseAdapterHelper.java

/**
 * Will set the image of an ImageView from a resource id.
 * //from  w w  w .ja  va2  s.  c  o  m
 * @param viewId
 *            The view id.
 * @param imageResId
 *            The image resource id.
 * @return The BaseAdapterHelper for chaining.
 */
public BaseAdapterHelper setImageResource(int viewId, int imageResId) {
    ImageView view = retrieveView(viewId);
    view.setImageResource(imageResId);
    return this;
}

From source file:com.klinker.android.twitter.activities.drawer_activities.discover.trends.SearchedTrendsActivity.java

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    MenuInflater inflater = getMenuInflater();
    inflater.inflate(R.menu.search_activity, menu);

    // Get the SearchView and set the searchable configuration
    SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE);
    searchView = (SearchView) menu.findItem(R.id.menu_search).getActionView();
    // Assumes current activity is the searchable activity
    searchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName()));
    searchView.setIconifiedByDefault(true); // Do not iconify the widget; expand it by default

    int searchImgId = getResources().getIdentifier("android:id/search_button", null, null);
    ImageView view = (ImageView) searchView.findViewById(searchImgId);
    view.setImageResource(settings.theme == AppSettings.THEME_LIGHT ? R.drawable.ic_action_search_light
            : R.drawable.ic_action_search_dark);

    return true;//w  w  w  .  j  a  v  a  2s .co m
}

From source file:com.idevity.card.read.ShowCard.java

/**
 * Method onCreateView.//from   w w w. ja v a2  s. co m
 * 
 * @param inflater
 *            LayoutInflater
 * @param container
 *            ViewGroup
 * @param savedInstanceState
 *            Bundle
 * @return View
 */
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

    Globals g = Globals.getInstance();
    View cardLayout = inflater.inflate(R.layout.activity_show_card, container, false);

    Date now = Calendar.getInstance().getTime();

    byte[] _data = g.getCard();
    CardData80073 carddata = new CardData80073(_data);

    PIVCardHolderUniqueID chuid = null;
    PIVDataTempl chuidInDataTempl = carddata.getPIVCardHolderUniqueID();
    if (chuidInDataTempl != null) {
        byte[] chuidData = chuidInDataTempl.getData();
        if (chuidData == null) {
            chuidData = chuidInDataTempl.getEncoded();
        }
        chuid = new PIVCardHolderUniqueID(chuidData);
    }
    FASCN fascn = null;
    try {
        fascn = chuid.getFASCN();
    } catch (Throwable e) {
        Log.e(TAG, "Error: " + e.getMessage());
    }

    String ac = new String();
    String sc = new String();
    String cn = new String();
    String pi = new String();
    String oc = new String();
    String oi = new String();
    String poa = new String();
    String expiryDate = new String();
    String guid = new String();
    String agencyname = new String();
    String orgname = new String();
    Date expires = now;

    if (fascn != null) {
        ac = fascn.getAgencyCode();
        sc = fascn.getSystemCode();
        cn = fascn.getCredentialNumber();
        pi = fascn.getPersonIdentifier();
        oc = fascn.getOrganizationalCategory();
        oi = fascn.getOrganizationalIdentifier();
        poa = fascn.getAssociationCategory();
        expiryDate = chuid.getExpirationDate().toString();
        expires = chuid.getExpirationDate();
        guid = chuid.getGUID().toString();
        // agencyname
        // orgname
    }

    ImageView sigthumbs = (ImageView) cardLayout.findViewById(R.id.validityIndicator1);
    TextView sigtext = (TextView) cardLayout.findViewById(R.id.validityLabel);
    TextView vtText = (TextView) cardLayout.findViewById(R.id.expirydateLabel);

    if (expires.after(now)) {
        sigthumbs.setImageResource(R.drawable.cert_good);
    } else {
        sigthumbs.setImageResource(R.drawable.cert_bad);
        sigtext.setTextColor(getResources().getColor(R.color.idredmain));
        vtText.setTextColor(getResources().getColor(R.color.idredmain));
    }

    // set agency code default
    TextView editAgencyCode = (TextView) cardLayout.findViewById(R.id.agencyCode);
    editAgencyCode.setText(ac);
    // set system code default
    TextView editSystemCode = (TextView) cardLayout.findViewById(R.id.systemCode);
    editSystemCode.setText(sc);
    // set credential number default
    TextView editCredNumber = (TextView) cardLayout.findViewById(R.id.credNumber);
    editCredNumber.setText(cn);
    // set pi number default
    TextView editPersonId = (TextView) cardLayout.findViewById(R.id.personId);
    editPersonId.setText(pi);
    // set org category
    String organizationalCategory = oc;
    if (organizationalCategory.equalsIgnoreCase("1")) {
        oc = "Federal";
    } else if (organizationalCategory.equalsIgnoreCase("2")) {
        oc = "State";
    } else if (organizationalCategory.equalsIgnoreCase("3")) {
        oc = "Commercial";
    } else if (organizationalCategory.equalsIgnoreCase("4")) {
        oc = "International";
    } else {
        // Default is "Federal"
        oc = "Federal";
    }
    TextView editOrgCat = (TextView) cardLayout.findViewById(R.id.orgCategory);
    editOrgCat.setText(oc);
    // set poa code
    String associationCategory = poa;
    if (associationCategory.equalsIgnoreCase("1")) {
        poa = "Employee";
    } else if (associationCategory.equalsIgnoreCase("2")) {
        poa = "Civil";
    } else if (associationCategory.equalsIgnoreCase("3")) {
        poa = "Executive";
    } else if (associationCategory.equalsIgnoreCase("4")) {
        poa = "Uniformed";
    } else if (associationCategory.equalsIgnoreCase("5")) {
        poa = "Contractor";
    } else if (associationCategory.equalsIgnoreCase("6")) {
        poa = "Affiliate";
    } else if (associationCategory.equalsIgnoreCase("7")) {
        poa = "Beneficiary";
    } else {
        // Default is "Employee"
        poa = "None Specified";
    }
    TextView editPoaCode = (TextView) cardLayout.findViewById(R.id.poaCode);
    editPoaCode.setText(poa);
    // set ord id
    TextView editOrgid = (TextView) cardLayout.findViewById(R.id.orgId);
    editOrgid.setText(oi);
    // set expiry date
    TextView editExpiry = (TextView) cardLayout.findViewById(R.id.expiryDate);
    editExpiry.setText(expiryDate);
    // set guid
    TextView editGuid = (TextView) cardLayout.findViewById(R.id.globadId);
    editGuid.setText(guid);

    Resources res = getResources();
    InputStream is = res.openRawResource(R.raw.sp80087);
    Properties codes = new Properties();
    try {
        codes.loadFromXML(is);
    } catch (InvalidPropertiesFormatException e) {
        Log.e(TAG, "Error: " + e.getMessage());
    } catch (IOException e) {
        Log.e(TAG, "Error: " + e.getMessage());
    }

    if (codes.getProperty(ac) == null) {
        agencyname = "Unknown Agency";
    } else {
        agencyname = codes.getProperty(ac);
    }
    /*
     * set issuing agency from XML data
     */
    TextView editAgencyname = (TextView) cardLayout.findViewById(R.id.issuingAgency);
    editAgencyname.setText(agencyname);

    if (codes.getProperty(oi) == null) {
        orgname = "Unknown Organization";
    } else {
        orgname = codes.getProperty(oi);
    }
    /*
     * set organization name from XML data
     */
    TextView editOrgname = (TextView) cardLayout.findViewById(R.id.issuingOrg);
    editOrgname.setText(orgname);

    return cardLayout;
}

From source file:com.google.android.gcm.demo.ui.GroupActivity.java

private View createNewMemberRow(String name, String value) {
    LinearLayout row = (LinearLayout) getLayoutInflater().inflate(R.layout.widget_icon_text_button_row, null);
    ImageView icon = (ImageView) row.findViewById(R.id.widget_itbr_icon);
    TextView label = (TextView) row.findViewById(R.id.widget_itbr_text);
    Button button = (Button) row.findViewById(R.id.widget_itbr_button);

    icon.setImageResource(R.drawable.smartphone_grey600);
    label.setText(name + ": " + AbstractFragment.truncateToShortString(value));
    button.setText(R.string.group_undo_add_member);
    button.setTag(R.id.tag_action, ACTION_UNDO_ADD_MEMBER);
    button.setTag(R.id.tag_token, name);
    button.setOnClickListener(this);
    return row;/*from  ww  w .j  a va 2s .  c o  m*/
}

From source file:com.google.android.gcm.demo.ui.GroupActivity.java

private View createRemovedMemberRow(String name, String value) {
    LinearLayout row = (LinearLayout) getLayoutInflater().inflate(R.layout.widget_icon_text_button_row, null);
    ImageView icon = (ImageView) row.findViewById(R.id.widget_itbr_icon);
    TextView label = (TextView) row.findViewById(R.id.widget_itbr_text);
    Button button = (Button) row.findViewById(R.id.widget_itbr_button);

    icon.setImageResource(R.drawable.smartphone_grey600);
    label.setText(name + ": " + AbstractFragment.truncateToShortString(value));
    button.setText(R.string.group_undo_remove_member);
    button.setTag(R.id.tag_action, ACTION_UNDO_REMOVE_MEMBER);
    button.setTag(R.id.tag_token, name);
    button.setOnClickListener(this);
    return row;//from w  w w .j  av  a  2s .co  m
}

From source file:com.google.android.gcm.demo.ui.GroupActivity.java

private View createCurrentMemberRow(String name, String value) {
    LinearLayout row = (LinearLayout) getLayoutInflater().inflate(R.layout.widget_icon_text_button_row, null);
    ImageView icon = (ImageView) row.findViewById(R.id.widget_itbr_icon);
    TextView label = (TextView) row.findViewById(R.id.widget_itbr_text);
    Button button = (Button) row.findViewById(R.id.widget_itbr_button);

    icon.setImageResource(R.drawable.smartphone_grey600);
    label.setText(name + ": " + AbstractFragment.truncateToShortString(value));
    button.setText(R.string.group_remove_member);
    button.setTag(R.id.tag_action, ACTION_REMOVE_MEMBER);
    button.setTag(R.id.tag_token, name);
    button.setOnClickListener(this);
    return row;/*w w  w. j a v a  2 s . c o m*/
}

From source file:com.metinkale.prayerapp.vakit.fragments.MainFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle bdl) {
    mView = inflater.inflate(R.layout.vakit_fragment, container, false);
    setHasOptionsMenu(true);/*from w w w  .j a va 2 s.c  o m*/
    if (mCity == 0) {
        return mView;
    }

    mCountdown = (TextView) mView.findViewById(R.id.countdown);
    mTitle = (TextView) mView.findViewById(R.id.city);
    mDate = (TextView) mView.findViewById(R.id.date);
    mHicri = (TextView) mView.findViewById(R.id.hicri);

    mKerahat = (TextView) mView.findViewById(R.id.kerahat);

    mTimes = Times.getTimes(mCity);

    if (mTimes == null) {
        return new View(getActivity());
    }
    ImageView source1 = (ImageView) mView.findViewById(R.id.source1);
    ImageView source2 = (ImageView) mView.findViewById(R.id.source2);
    if (mTimes.getSource().resId != 0) {
        source1.setImageResource(mTimes.getSource().resId);
        source2.setImageResource(mTimes.getSource().resId);
    }

    if (Prefs.useArabic()) {
        for (int i = 0; i < idsNames.length; i++) {
            TextView tv = (TextView) mView.findViewById(idsNames[i]);
            tv.setGravity(Gravity.LEFT);
            tv.setText(Vakit.getByIndex(i).getString());
        }
    }

    return mView;
}

From source file:com.zhihuigu.sosoOffice.utils.ImageDownloaderUrl.java

/**
 * Same as download but the image is always downloaded and the cache is not
 * used. Kept private at the moment as its interest is not clear.
 *///from   ww  w  . j ava  2 s  .c  om
private void forceDownload(String url, File file, String sql, ImageView imageView) {
    // State sanity: url is guaranteed to never be null in
    // DownloadedDrawable and cache keys.
    if (url == null) {
        imageView.setImageResource(resid);
        return;
    }
    Log.i("", imageView.toString() + "-----" + url);
    if (cancelPotentialDownload(url, imageView)) {
        BitmapDownloaderTask task = new BitmapDownloaderTask(imageView);
        DownloadedDrawable downloadedDrawable = new DownloadedDrawable(task, context, resid);
        imageView.setImageDrawable(downloadedDrawable);

        task.execute(url, file, sql);
    }
}

From source file:com.odoo.base.addons.mail.widget.MailChatterCompose.java

private void addAttachment(OValues values) {
    View attachmentView = LayoutInflater.from(this).inflate(R.layout.base_attachment_item, horizontalScrollView,
            false);//w w  w. ja  va 2s.c  om
    String fileName = values.getString("name");
    String type = values.getString("file_type");
    ImageView imgPreview = (ImageView) attachmentView.findViewById(R.id.attachmentPreview);
    if (type.contains("image")) {
        OLog.log(values.getString("file_uri"));
        imgPreview.setImageURI(Uri.parse(values.getString("file_uri")));
    } else if (type.contains("audio")) {
        imgPreview.setImageResource(R.drawable.audio);
    } else if (type.contains("video")) {
        imgPreview.setImageResource(R.drawable.video);
    } else {
        imgPreview.setImageResource(R.drawable.file);
    }
    OControls.setText(attachmentView, R.id.attachmentFileName, fileName);
    attachmentView.setTag(values);
    attachmentView.findViewById(R.id.btnRemoveAttachment).setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            horizontalScrollView.removeView((View) v.getParent());
        }
    });
    horizontalScrollView.addView(attachmentView);
}