android.widget.ImageView#setImageDrawable ( )源码实例Demo

下面列出了android.widget.ImageView#setImageDrawable ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: Roundr   文件: Corner.java
@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;
	}
}
 
源代码2 项目: TLint   文件: ColorsDialogFragment.java
@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;
}
 
源代码3 项目: emerald   文件: IconPackManager.java
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);
	}
}
 
源代码4 项目: StateViews   文件: StateView.java
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);
    }
}
 
源代码5 项目: kognitivo   文件: WebDialog.java
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);
}
 
源代码6 项目: FlycoBanner_Master   文件: SimpleImageBanner.java
@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;
}
 
源代码7 项目: AndroidChromium   文件: ToolbarPhone.java
@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));
    }
}
 
/** 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;
}
 
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);
}
 
源代码10 项目: graphics-samples   文件: ImageWorker.java
/**
 * 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)
    }
}
 
源代码11 项目: mobile-manager-tool   文件: ImageProvider.java
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);
}
 
源代码12 项目: codeexamples-android   文件: DialogActivity.java
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);
}
 
源代码13 项目: BannerPager   文件: BannerPager.java
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;
}
 
源代码14 项目: wallpaperboard   文件: WallpapersAdapter.java
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));
}
 
源代码15 项目: SnapchatClone   文件: DisplayImageActivity.java
@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();
    }
}
 
源代码16 项目: YiBo   文件: TweetProgressListAdapter.java
@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;
}
 
源代码17 项目: Gallery   文件: BaseAdapterHelper.java
public BaseAdapterHelper setImageDrawable(int viewId, Drawable drawable) {
    ImageView view = retrieveView(viewId);
    view.setImageDrawable(drawable);
    return this;
}
 
源代码18 项目: NClientV2   文件: ImageDownloadUtility.java
private static void loadLogo(ImageView imageView){
    imageView.setImageDrawable(Global.getLogo(imageView.getResources()));
}
 
源代码19 项目: Upchain-wallet   文件: ViewHolder.java
public ViewHolder setImageDrawable(int viewId, Drawable drawable)
{
	ImageView view = getView(viewId);
	view.setImageDrawable(drawable);
	return this;
}
 
源代码20 项目: FeedListViewDemo   文件: ViewFinder.java
/**
 * 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;
}