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.sutromedia.android.core.PhotoActivity.java

public void onEndSlideShow() {
    if (mInSlideShow) {
        mInSlideShow = false;//  w  w w  . jav  a  2s.co m
        mHandler.removeCallbacks(mSlideShowRunnable);
        mShowSlideShowControls = true;

        ImageView image = (ImageView) findViewById(R.image.play_slideshow);
        image.setImageResource(R.drawable.play_slideshow);
        hideControlsSoon();
        mSwitcher.refresh();
    }
}

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

private void populateFilePart(View view, FileSearchResult sr) {
    ImageView fileTypeIcon = findView(view, R.id.view_bittorrent_search_result_list_item_filetype_icon);
    fileTypeIcon.setImageResource(getFileTypeIconId());

    TextView adIndicator = findView(view, R.id.view_bittorrent_search_result_list_item_ad_indicator);
    adIndicator.setVisibility(View.GONE);

    TextView title = findView(view, R.id.view_bittorrent_search_result_list_item_title);
    title.setText(sr.getDisplayName());//  ww w  . j  a va2 s.  c  o m

    TextView fileSize = findView(view, R.id.view_bittorrent_search_result_list_item_file_size);
    if (sr.getSize() > 0) {
        fileSize.setText(UIUtils.getBytesInHuman(sr.getSize()));
    } else {
        fileSize.setText("...");
    }

    TextView extra = findView(view, R.id.view_bittorrent_search_result_list_item_text_extra);
    extra.setText(FilenameUtils.getExtension(sr.getFilename()));

    TextView seeds = findView(view, R.id.view_bittorrent_search_result_list_item_text_seeds);
    seeds.setText("");

    String license = sr.getLicense().equals(Licenses.UNKNOWN) ? "" : " - " + sr.getLicense();

    TextView sourceLink = findView(view, R.id.view_bittorrent_search_result_list_item_text_source);
    sourceLink.setText(sr.getSource() + license); // TODO: ask for design
    sourceLink.setTag(sr.getDetailsUrl());
    sourceLink.setPaintFlags(sourceLink.getPaintFlags() | Paint.UNDERLINE_TEXT_FLAG);
    sourceLink.setOnClickListener(linkListener);
}

From source file:com.layer.messenger.makemoji.MakeMojiAtlasComposer.java

private void addAttachmentMenuItem(AttachmentSender sender) {
    LayoutInflater inflater = LayoutInflater.from(getContext());
    LinearLayout menuLayout = (LinearLayout) mAttachmentMenu.getContentView();

    View menuItem = inflater.inflate(com.layer.atlas.R.layout.atlas_message_composer_attachment_menu_item,
            menuLayout, false);/*w  ww. j  a  v  a2  s  .c  om*/
    ((TextView) menuItem.findViewById(com.layer.atlas.R.id.title)).setText(sender.getTitle());
    menuItem.setTag(sender);
    menuItem.setOnClickListener(new OnClickListener() {
        public void onClick(View v) {
            mAttachmentMenu.dismiss();
            ((AttachmentSender) v.getTag()).requestSend();
        }
    });
    if (sender.getIcon() != null) {
        ImageView iconView = ((ImageView) menuItem.findViewById(com.layer.atlas.R.id.icon));
        iconView.setImageResource(sender.getIcon());
        iconView.setVisibility(VISIBLE);
        Drawable d = DrawableCompat.wrap(iconView.getDrawable());
        DrawableCompat.setTint(d, getResources().getColor(com.layer.atlas.R.color.atlas_icon_enabled));
    }
    menuLayout.addView(menuItem);
}

From source file:com.i2max.i2smartwork.common.work.WorkDetailViewFragment.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.size() <= 0) {
        targetLayout.setVisibility(View.GONE);
    } else {// w ww .  j av a 2s . co 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) {
                    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);

                }
            });

            targetLayout.addView(fileView);
        }

    }
}

From source file:com.landenlabs.all_UiDemo.frag.ImageScalesFrag.java

private void setImage(ImageView imageView, int imageRes) {
    if (false && imageRes == R.drawable.scr_home) {
        // ScaleDrawable does nothing.
        setScaledVector(imageView, imageRes);
    } else {/*www.  java 2  s  . co m*/
        imageView.setImageResource(imageRes);
    }
}

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

@Override
protected void onCreate(Bundle savedState) {
    super.onCreate(savedState);
    setContentView(R.layout.activity_main);
    mLogger = new Logger(this);
    mLogsUI = (TextView) findViewById(R.id.logs);
    mLoggerCallback = new BroadcastReceiver() {
        @Override//from   w w  w  .  jav a 2s .com
        public void onReceive(Context context, Intent intent) {
            switch (intent.getAction()) {
            case LoggingService.ACTION_CLEAR_LOGS:
                mLogsUI.setText("");
                break;
            case LoggingService.ACTION_LOG:
                StringBuilder stringBuilder = new StringBuilder();
                String newLog = intent.getStringExtra(LoggingService.EXTRA_LOG_MESSAGE);
                String oldLogs = Html.toHtml(new SpannableString(mLogsUI.getText()));
                appendFormattedLogLine(newLog, stringBuilder);
                stringBuilder.append(oldLogs);
                mLogsUI.setText(Html.fromHtml(stringBuilder.toString()));
                List<Fragment> fragments = getSupportFragmentManager().getFragments();
                for (Fragment fragment : fragments) {
                    if (fragment instanceof RefreshableFragment && fragment.isVisible()) {
                        ((RefreshableFragment) fragment).refresh();
                    }
                }
                break;
            }
        }
    };

    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
    mDrawerView = (FrameLayout) findViewById(R.id.navigation_drawer);
    mDrawerMenu = (ListView) findViewById(R.id.navigation_drawer_menu);
    mDrawerScrim = findViewById(R.id.navigation_drawer_scrim);

    setSupportActionBar(toolbar);
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);

    TypedArray colorPrimaryDark = getTheme().obtainStyledAttributes(new int[] { R.attr.colorPrimaryDark });
    mDrawerLayout.setStatusBarBackgroundColor(colorPrimaryDark.getColor(0, 0xFF000000));
    mDrawerLayout.setDrawerShadow(R.drawable.drawer_shadow, GravityCompat.START);
    colorPrimaryDark.recycle();

    ImageView drawerHeader = new ImageView(this);
    drawerHeader.setImageResource(R.drawable.drawer_gcm_logo);
    mDrawerMenu.addHeaderView(drawerHeader);

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
        // Set the drawer width accordingly with the guidelines: window_width - toolbar_height.
        toolbar.addOnLayoutChangeListener(new View.OnLayoutChangeListener() {
            @Override
            public void onLayoutChange(View view, int left, int top, int right, int bottom, int oldLeft,
                    int oldTop, int oldRight, int oldBottom) {
                if (left == 0 && top == 0 && right == 0 && bottom == 0) {
                    return;
                }
                DisplayMetrics metrics = new DisplayMetrics();
                getWindowManager().getDefaultDisplay().getMetrics(metrics);
                float logicalDensity = metrics.density;
                int maxWidth = (int) Math.ceil(320 * logicalDensity);
                DrawerLayout.LayoutParams params = (DrawerLayout.LayoutParams) mDrawerView.getLayoutParams();
                int newWidth = view.getWidth() - view.getHeight();
                params.width = (newWidth > maxWidth ? maxWidth : newWidth);
                mDrawerView.setLayoutParams(params);
            }
        });
    }

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT_WATCH) {
        mDrawerView.setOnApplyWindowInsetsListener(new View.OnApplyWindowInsetsListener() {
            @TargetApi(Build.VERSION_CODES.KITKAT_WATCH)
            @Override
            public WindowInsets onApplyWindowInsets(View v, WindowInsets insets) {
                // Set scrim height to match status bar height.
                mDrawerScrim.setLayoutParams(new FrameLayout.LayoutParams(FrameLayout.LayoutParams.MATCH_PARENT,
                        insets.getSystemWindowInsetTop()));
                return insets;
            }
        });
    }

    int activeItemIndicator = (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB)
            ? android.R.layout.simple_list_item_activated_1
            : android.R.layout.simple_list_item_checked;

    mMainMenu = new MainMenu(this);
    mDrawerMenu.setOnItemClickListener(this);
    mDrawerMenu.setAdapter(new ArrayAdapter<>(getSupportActionBar().getThemedContext(), activeItemIndicator,
            android.R.id.text1, mMainMenu.getEntries()));

    mDrawerToggle = new ActionBarDrawerToggle(this, mDrawerLayout, R.string.drawer_open,
            R.string.drawer_close) {
        @Override
        public void onDrawerOpened(View drawerView) {
            // The user learned how to open the drawer. Do not open it for him anymore.
            getAppPreferences().edit().putBoolean(PREF_OPEN_DRAWER_AT_STARTUP, false).apply();
            super.onDrawerOpened(drawerView);
        }
    };

    boolean activityResumed = (savedState != null);
    boolean openDrawer = getAppPreferences().getBoolean(PREF_OPEN_DRAWER_AT_STARTUP, true);
    int lastScreenId = getAppPreferences().getInt(PREF_LAST_SCREEN_ID, 0);
    selectItem(lastScreenId);
    if (!activityResumed && openDrawer) {
        mDrawerLayout.openDrawer(mDrawerView);
    }
    mDrawerLayout.setDrawerListener(mDrawerToggle);

    /*
     * Here we check if the Activity was created by the user clicking on one of our GCM
     * notifications:
     * 1. Check if the action of the intent used to launch the Activity.
     * 2. Print out any additional data sent with the notification. This is included as extras
     *  on the intent.
     */
    Intent launchIntent = getIntent();
    if ("gcm_test_app_notification_click_action".equals(launchIntent.getAction())) {
        Bundle data = launchIntent.getExtras();
        data.isEmpty(); // Force the bundle to unparcel so that toString() works
        String format = getResources().getString(R.string.notification_intent_received);
        mLogger.log(Log.INFO, String.format(format, data));
    }
}

From source file:com.mobicage.rogerthat.plugins.history.HistoryListAdapter.java

@Override
public View getView(int position, View convertView, ViewGroup parent) {
    T.UI();/*from  w  ww.java 2  s .  c o m*/

    final View view;

    if (convertView == null) {
        view = mLayoutInflater.inflate(R.layout.activity_list_row, parent, false);
    } else {
        view = convertView;
    }

    final Cursor cursor = getCursor();
    if (!cursor.moveToPosition(position)) {
        throw new IllegalStateException("couldn't move cursor to position " + position);
    }
    final HistoryItem item = mStore.getCurrentHistoryItem(cursor);

    final StringTuple historyText = createHistoryText(item);

    final TextView tv1 = (TextView) view.findViewById(R.id.activity_list_row_text1);
    tv1.setText(historyText.s1);
    tv1.setTextColor(ContextCompat.getColorStateList(mContext, android.R.color.primary_text_light));

    final TextView tv2 = (TextView) view.findViewById(R.id.activity_list_row_text2);
    if (historyText.s2 == null)
        tv2.setVisibility(View.GONE);
    else {
        tv2.setText(historyText.s2);
        tv2.setVisibility(View.VISIBLE);
        tv2.setTextColor(ContextCompat.getColorStateList(mContext, android.R.color.secondary_text_light));
    }

    final TextView tv3 = (TextView) view.findViewById(R.id.activity_list_row_text3);
    if (historyText.s3 == null)
        tv3.setVisibility(View.GONE);
    else {
        tv3.setText(historyText.s3);
        tv3.setVisibility(View.VISIBLE);
        tv3.setTextColor(ContextCompat.getColorStateList(mContext, android.R.color.secondary_text_light));
    }

    updateDividerLine(view, item);

    final int image = getImage(item);
    final ImageView iv = (ImageView) view.findViewById(R.id.activity_list_row_icon);
    if (image != -1) {
        iv.setImageResource(image);
    } else {
        iv.setImageResource(0);
    }

    final TextView timestampTextView = (TextView) view.findViewById(R.id.timestamp);
    timestampTextView.setText(TimeUtils.getHumanTime(mContext, item.timestampMillis, false));

    view.setTag(item);
    return view;
}

From source file:com.github.mobile.gauges.ui.ItemListFragment.java

private void showRefreshAnimation(MenuItem item) {
    hideRefreshAnimation();//from w ww.j  a  v a2 s  . c o m

    refreshItem = item;

    ImageView refreshActionView = (ImageView) getActivity().getLayoutInflater().inflate(layout.action_view,
            null);
    refreshActionView.setImageResource(drawable.ic_action_refresh);
    refreshItem.setActionView(refreshActionView);
    Animation animation = AnimationUtils.loadAnimation(getActivity(), anim.refresh);
    animation.setRepeatMode(RESTART);
    animation.setRepeatCount(INFINITE);
    refreshActionView.startAnimation(animation);
}

From source file:com.google.dotorg.crisisresponse.translationcards.RecordingActivity.java

private void setAudioSaveButtonEnabled() {
    TextView text = (TextView) findViewById(R.id.recording_audio_save_text);
    text.setTextColor(getResources().getColor(R.color.primaryTextColor));
    ImageView image = (ImageView) findViewById(R.id.recording_audio_save_image);
    image.setImageResource(R.drawable.forward_arrow);
}

From source file:org.exoplatform.utils.image.SocialImageLoader.java

public void displayImage(String url, ImageView imageView, boolean isLink) {
    url = SocialActivityUtil.convertToThumbnail(url);
    imageViews.put(imageView, url);//w ww  . j a v a2 s . co m
    Bitmap bitmap = memoryCache.get(url);
    if (bitmap != null)
        imageView.setImageBitmap(bitmap);
    else {
        queuePhoto(url, imageView, isLink);
        imageView.setImageResource(DOWNLOAD_PROGRESS_IMAGE);
    }
}