Java Code Examples for android.widget.ImageView#setImageDrawable()

The following examples show how to use android.widget.ImageView#setImageDrawable() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SimpleImageBanner.java    From FlycoBanner_Master with MIT License 6 votes vote down vote up
@Override
public View onCreateItemView(int position) {
    View inflate = View.inflate(mContext, R.layout.adapter_simple_image, null);
    ImageView iv = ViewFindUtils.find(inflate, R.id.iv);

    final BannerItem item = mDatas.get(position);
    int itemWidth = mDisplayMetrics.widthPixels;
    int itemHeight = (int) (itemWidth * 360 * 1.0f / 640);
    iv.setScaleType(ImageView.ScaleType.CENTER_CROP);
    iv.setLayoutParams(new LinearLayout.LayoutParams(itemWidth, itemHeight));

    String imgUrl = item.imgUrl;

    if (!TextUtils.isEmpty(imgUrl)) {
        Glide.with(mContext)
                .load(imgUrl)
                .override(itemWidth, itemHeight)
                .centerCrop()
                .placeholder(colorDrawable)
                .into(iv);
    } else {
        iv.setImageDrawable(colorDrawable);
    }

    return inflate;
}
 
Example 2
Source File: Corner.java    From Roundr with Apache License 2.0 6 votes vote down vote up
@Override
public void createAndAttachView(int corner, FrameLayout frame) {
	// Set the image based on window corner
	LayoutInflater inflater = (LayoutInflater) getSystemService(LAYOUT_INFLATER_SERVICE);
	ImageView v = (ImageView) inflater.inflate(R.layout.corner, frame, true).findViewById(R.id.iv);
	// Top left by default
	v.setImageDrawable(getResources().getDrawable(R.drawable.topleft));
	switch (corner) {
	case 1:
		v.setImageDrawable(getResources().getDrawable(R.drawable.topright));
		break;
	case 2:
		v.setImageDrawable(getResources().getDrawable(R.drawable.bottomleft));
		break;
	case 3:
		v.setImageDrawable(getResources().getDrawable(R.drawable.bottomright));
		break;
	}
}
 
Example 3
Source File: ColorsDialogFragment.java    From TLint with Apache License 2.0 6 votes vote down vote up
@Override
public View getView(int position, View convertView, ViewGroup parent) {
    if (convertView == null) {
        convertView = View.inflate(getActivity(), R.layout.item_md_colors, null);
    }

    if (!colorMap.containsKey(String.valueOf(position))) {
        colorMap.put(String.valueOf(position),
                new ColorDrawable(getResources().getColor(ThemeUtil.themeColorArr[position][0])));
    }

    ImageView imgColor = (ImageView) convertView.findViewById(R.id.ivColor);
    ColorDrawable colorDrawable = colorMap.get(String.valueOf(position));
    imgColor.setImageDrawable(colorDrawable);

    View imgSelected = convertView.findViewById(R.id.ivSelected);
    imgSelected.setVisibility(
            SettingPrefUtil.getThemeIndex(getActivity()) == position ? View.VISIBLE : View.GONE);

    return convertView;
}
 
Example 4
Source File: IconPackManager.java    From emerald with GNU General Public License v3.0 6 votes vote down vote up
public static void setIcon(Context c, ImageView img, BaseData a) {
	File iconFile;
	iconFile = MyCache.getCustomIconFile(c, a);
	if (!iconFile.exists()) {
		if (a instanceof AppData) {
			iconFile = MyCache.getIconFile(c, a);
		} else {
			iconFile = MyCache.getShortcutIconFile(c, ((ShortcutData)a).getUri());
		}
	}
	if (iconFile.exists()){
		try {
			img.setImageDrawable(Drawable.createFromStream(
				new FileInputStream(iconFile), null));
		} catch (Exception e) {
			img.setImageResource(android.R.drawable.sym_def_app_icon);
		} finally {
			return;
		}
	} else {
		img.setImageResource(android.R.drawable.sym_def_app_icon);
	}
}
 
Example 5
Source File: WebDialog.java    From kognitivo with Apache License 2.0 6 votes vote down vote up
private void createCrossImage() {
    crossImageView = new ImageView(getContext());
    // Dismiss the dialog when user click on the 'x'
    crossImageView.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            cancel();
        }
    });
    Drawable crossDrawable = getContext().getResources().getDrawable(R.drawable.com_facebook_close);
    crossImageView.setImageDrawable(crossDrawable);
    /* 'x' should not be visible while webview is loading
     * make it visible only after webview has fully loaded
     */
    crossImageView.setVisibility(View.INVISIBLE);
}
 
Example 6
Source File: StateView.java    From StateViews with MIT License 6 votes vote down vote up
private void setIcon(View view, Drawable icon, Integer color, int iconSize) {
    ImageView mImageView = view.findViewById(R.id.state_icon);

    if (color != null) {
        mImageView.setColorFilter(color, android.graphics.PorterDuff.Mode.SRC_IN);
    } else {
        TypedValue typedValue = new TypedValue();
        getContext().getTheme().resolveAttribute(R.attr.colorAccent, typedValue, true);
        mImageView.setColorFilter(typedValue.data, android.graphics.PorterDuff.Mode.SRC_IN);
    }

    if (iconSize > 0) {
        LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(iconSize, iconSize);
        mImageView.setLayoutParams(params);
    }

    if (icon != null) {
        mImageView.setImageDrawable(icon);
        mImageView.setVisibility(View.VISIBLE);
    } else {
        mImageView.setVisibility(View.GONE);
    }
}
 
Example 7
Source File: DialogActivity.java    From codeexamples-android with Eclipse Public License 1.0 5 votes vote down vote up
public void onClick(View v) {
    LinearLayout layout = (LinearLayout)findViewById(R.id.inner_content);
    ImageView iv = new ImageView(DialogActivity.this);
    iv.setImageDrawable(getResources().getDrawable(R.drawable.icon48x48_1));
    iv.setPadding(4, 4, 4, 4);
    layout.addView(iv);
}
 
Example 8
Source File: TweetProgressListAdapter.java    From YiBo with Apache License 2.0 5 votes vote down vote up
@Override
public View getView(int position, View convertView, ViewGroup parent) {
	if (convertView == null) {
		convertView = inflater.inflate(R.layout.list_item_dialog_tweet_progress, null);
	}
	final LocalAccount account = (LocalAccount)getItem(position);
	
	ImageView ivProfileImage = (ImageView) convertView.findViewById(R.id.ivProfileImage);
       ivProfileImage.setImageDrawable(GlobalResource.getDefaultMinHeader(context));
       
	String profileImageUrl = account.getUser().getProfileImageUrl();
	if (StringUtil.isNotEmpty(profileImageUrl)) {
		new ImageLoad4HeadTask(ivProfileImage, profileImageUrl, true).execute();
	}
	
	TextView screenName = (TextView) convertView.findViewById(R.id.tvScreenName);
	TextView spName = (TextView) convertView.findViewById(R.id.tvSPName);
	ImageView ivTweetState = (ImageView) convertView.findViewById(R.id.ivTweetState);
	
	State state = mapState.get(account);
	if (state == null) {
		state = State.Waiting;
		mapState.put(account, state);
	}
	ivTweetState.setImageLevel(state.getState());
       if (state == State.Loading) {
       	ivTweetState.startAnimation(rotateAnimation);
       } else {
       	ivTweetState.clearAnimation();
       }
       
	screenName.setText(account.getUser().getScreenName());
	String snNameText = account.getServiceProvider().getSpName();
	spName.setText(snNameText);
	
	return convertView;
}
 
Example 9
Source File: DisplayImageActivity.java    From SnapchatClone with MIT License 5 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_display_image);

    Bundle b = getIntent().getExtras();
    uid = b.getString("uid");
    chatOrStory = b.getString("chatOrStory");
    username = b.getString("username");
    profileImageUrl = b.getString("profileImageUrl");

    mImage = findViewById(R.id.imageViewDisplayedImage);

    ImageView profile = findViewById(R.id.userProfile);
    TextView user = findViewById(R.id.usernameDisplay);
    info = findViewById(R.id.userInfo);
    progressBar = findViewById(R.id.progressBar);

    if (profileImageUrl.equals("default")) {
        profile.setImageDrawable(ContextCompat.getDrawable(getApplicationContext(), R.drawable.profile));
    } else {
        Glide.with(getApplication()).load(profileImageUrl).into(profile);
    }

    user.setText(username);

    if (chatOrStory.equals("chat")) {
        listenForChat();
    }

    if (chatOrStory.equals("story")) {
        listenForStory();
    }
}
 
Example 10
Source File: WallpapersAdapter.java    From wallpaperboard with Apache License 2.0 5 votes vote down vote up
private void setFavorite(@NonNull ImageView imageView, @ColorInt int color, int position, boolean animate) {
    if (position < 0 || position > mWallpapers.size()) return;

    if (mIsFavoriteMode) {
        imageView.setImageDrawable(DrawableHelper.getTintedDrawable(mContext, R.drawable.ic_toolbar_love, color));
        return;
    }

    boolean isFavorite = mWallpapers.get(position).isFavorite();

    if (animate) {
        AnimationHelper.show(imageView)
                .interpolator(new LinearOutSlowInInterpolator())
                .callback(new AnimationHelper.Callback() {
                    @Override
                    public void onAnimationStart() {
                        imageView.setImageDrawable(DrawableHelper.getTintedDrawable(mContext,
                                isFavorite ? R.drawable.ic_toolbar_love : R.drawable.ic_toolbar_unlove, color));
                    }

                    @Override
                    public void onAnimationEnd() {

                    }
                })
                .start();
        return;
    }

    imageView.setImageDrawable(DrawableHelper.getTintedDrawable(mContext,
            isFavorite ? R.drawable.ic_toolbar_love : R.drawable.ic_toolbar_unlove, color));
}
 
Example 11
Source File: BannerPager.java    From BannerPager with Apache License 2.0 5 votes vote down vote up
private void setIndicatorSelected(int currentItem) {
    if (mCurrentIndicator != null) {
        mCurrentIndicator.setImageDrawable(mPagerOptions.mIndicatorDrawable[0]);
        mCurrentIndicator.setSelected(false);
    }
    final ImageView indicator = (ImageView) mIndicatorLayout.getChildAt(currentItem);
    indicator.setSelected(true);
    indicator.setImageDrawable(mPagerOptions.mIndicatorDrawable[1]);
    mCurrentIndicator = indicator;
}
 
Example 12
Source File: ImageProvider.java    From mobile-manager-tool with MIT License 5 votes vote down vote up
private void setLoadedBitmap(ImageView imageView, Bitmap bitmap, String tag) {
    if (!tag.equals(imageView.getTag()))
        return;

    final TransitionDrawable transition = new TransitionDrawable(new Drawable[]{
            new ColorDrawable(android.R.color.transparent),
            new BitmapDrawable(imageView.getResources(), bitmap)
    });

    imageView.setImageDrawable(transition);
    final int duration = imageView.getResources().getInteger(R.integer.image_fade_in_duration);
    transition.startTransition(duration);
}
 
Example 13
Source File: ImageWorker.java    From graphics-samples with Apache License 2.0 5 votes vote down vote up
/**
 * Load an image specified by the data parameter into an ImageView (override
 * {@link ImageWorker#processBitmap(Object)} to define the processing logic). A memory and
 * disk cache will be used if an {@link ImageCache} has been added using
 * {@link ImageWorker#addImageCache(FragmentManager, ImageCache.ImageCacheParams)}. If the
 * image is found in the memory cache, it is set immediately, otherwise an {@link AsyncTask}
 * will be created to asynchronously load the bitmap.
 *
 * @param data The URL of the image to download.
 * @param imageView The ImageView to bind the downloaded image to.
 * @param listener A listener that will be called back once the image has been loaded.
 */
public void loadImage(Object data, ImageView imageView, OnImageLoadedListener listener) {
    if (data == null) {
        return;
    }

    BitmapDrawable value = null;

    if (mImageCache != null) {
        value = mImageCache.getBitmapFromMemCache(String.valueOf(data));
    }

    if (value != null) {
        // Bitmap found in memory cache
        imageView.setImageDrawable(value);
        if (listener != null) {
            listener.onImageLoaded(true);
        }
    } else if (cancelPotentialWork(data, imageView)) {
        //BEGIN_INCLUDE(execute_background_task)
        final BitmapWorkerTask task = new BitmapWorkerTask(data, imageView, listener);
        final AsyncDrawable asyncDrawable =
                new AsyncDrawable(mResources, mLoadingBitmap, task);
        imageView.setImageDrawable(asyncDrawable);

        // NOTE: This uses a custom version of AsyncTask that has been pulled from the
        // framework and slightly modified. Refer to the docs at the top of the class
        // for more info on what was changed.
        task.executeOnExecutor(AsyncTask.DUAL_THREAD_EXECUTOR);
        //END_INCLUDE(execute_background_task)
    }
}
 
Example 14
Source File: EmoticonsToolBarView.java    From ChatKeyboard-master with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public void setEmoticonContents(EmoticonsKeyboardBuilder builder) {
    mEmoticonSetBeanList = builder.builder == null ? null : builder.builder.getEmoticonSetBeanList();
    if (mEmoticonSetBeanList == null) {
        return;
    }

    int i = 0;
    for (EmoticonSetBean bean : mEmoticonSetBeanList) {
        View toolBtnView = inflate(mContext, R.layout.emoticonstoolbar_item, null);
        ImageView iv_icon = (ImageView) toolBtnView.findViewById(R.id.iv_icon);
        LinearLayout.LayoutParams imgParams = new LinearLayout.LayoutParams(Utils.dip2px(mContext, mBtnWidth), LayoutParams.MATCH_PARENT);
        iv_icon.setLayoutParams(imgParams);
        ly_tool.addView(toolBtnView);

        iv_icon.setImageDrawable(EmoticonLoader.getInstance(mContext).getDrawable(bean.getIconUri()));

        mToolBtnList.add(iv_icon);

        final int finalI = i;
        iv_icon.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View view) {
                if (mItemClickListeners != null && !mItemClickListeners.isEmpty()) {
                    for (OnToolBarItemClickListener listener : mItemClickListeners) {
                        listener.onToolBarItemClick(finalI);
                    }
                }
            }
        });
        i++;
    }
    setToolBtnSelect(0);
}
 
Example 15
Source File: AuthenticatorActivity.java    From google-authenticator-android with Apache License 2.0 5 votes vote down vote up
/** Removes the Bitmap created in onCreateFloatView() and tells the system to recycle it. */
@Override
public void onDestroyFloatView(View floatView) {
  ImageView imageView = floatView.findViewById(R.id.user_row_dragged_image);
  if (imageView != null) {
    imageView.setImageDrawable(null);
  }
  floatBitmap.recycle();
  floatBitmap = null;
}
 
Example 16
Source File: ToolbarPhone.java    From AndroidChromium with Apache License 2.0 5 votes vote down vote up
@Override
protected void onAttachedToWindow() {
    super.onAttachedToWindow();
    mToolbarShadow = (ImageView) getRootView().findViewById(R.id.toolbar_shadow);

    // This is a workaround for http://crbug.com/574928. Since Jelly Bean is the lowest version
    // we support now and the next deprecation target, we decided to simply workaround.
    if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.JELLY_BEAN) {
        mToolbarShadow.setImageDrawable(
                ApiCompatibilityUtils.getDrawable(getResources(), R.drawable.toolbar_shadow));
    }
}
 
Example 17
Source File: BaseAdapterHelper.java    From Gallery with Apache License 2.0 4 votes vote down vote up
public BaseAdapterHelper setImageDrawable(int viewId, Drawable drawable) {
    ImageView view = retrieveView(viewId);
    view.setImageDrawable(drawable);
    return this;
}
 
Example 18
Source File: ImageDownloadUtility.java    From NClientV2 with Apache License 2.0 4 votes vote down vote up
private static void loadLogo(ImageView imageView){
    imageView.setImageDrawable(Global.getLogo(imageView.getResources()));
}
 
Example 19
Source File: ViewHolder.java    From Upchain-wallet with GNU Affero General Public License v3.0 4 votes vote down vote up
public ViewHolder setImageDrawable(int viewId, Drawable drawable)
{
	ImageView view = getView(viewId);
	view.setImageDrawable(drawable);
	return this;
}
 
Example 20
Source File: ViewFinder.java    From FeedListViewDemo with MIT License 2 votes vote down vote up
/**
 * Set drawable on child image view
 *
 * @param id
 * @param drawable
 * @return image view
 */
public ImageView setDrawable(final int id, final int drawable) {
    ImageView image = imageView(id);
    image.setImageDrawable(image.getResources().getDrawable(drawable));
    return image;
}