List of usage examples for android.widget ImageView setBackground
public void setBackground(Drawable background)
From source file:com.faayda.imageloader.ImageLoader.java
/** * Called when the processing is complete and the final bitmap should be set on the ImageView. * * @param imageView The ImageView to set the bitmap to. * @param bitmap The new bitmap to set./* www. jav a 2 s .c o m*/ */ @SuppressLint("NewApi") @SuppressWarnings("deprecation") private void setImageBitmap(ImageView imageView, Bitmap bitmap) { if (mFadeInBitmap) { // Transition drawable to fade from loading bitmap to final bitmap final TransitionDrawable td = new TransitionDrawable( new Drawable[] { new ColorDrawable(mResources.getColor(R.color.transparent)), new BitmapDrawable(mResources, bitmap) }); if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.JELLY_BEAN) { imageView.setBackground(imageView.getDrawable()); } else { imageView.setBackgroundDrawable(imageView.getDrawable()); } imageView.setImageDrawable(td); td.startTransition(FADE_IN_TIME); } else { imageView.setImageBitmap(bitmap); } }
From source file:com.snsplus.soqlive.Fragment.Found_Fragment.java
@Override public void isFnasOnClick(String vjUserId, int isFans, int position, ImageView view) { // boolean isLogin = false; // ? if (!MimiApplication.getInstance().isLoginServer) { mainHandler.post(new Runnable() { @Override/*from w w w . jav a 2 s . com*/ public void run() { errorFollowThread thread = new errorFollowThread(); new Thread(thread).start(); } }); return; } if (isFans == 0) { view.setBackground(mContext.getResources().getDrawable(R.drawable.concernno)); mFoundAdapter.listData.get(position).isFans = 1; } if (isFans == 1) { view.setBackground(mContext.getResources().getDrawable(R.drawable.concernyes)); mFoundAdapter.listData.get(position).isFans = 0; } mFoundAdapter.notifyItemChanged(position); String clientUserId = mAppData.getUserInfo().userId; AttentionAnchorUtils attentionAnchorUtils = new AttentionAnchorUtils(mContext, null); attentionAnchorUtils.saveLocalUserInforPref(vjUserId, isFans); attentionAnchorUtils.toLikeAnchor(clientUserId, vjUserId, isFans, position); // toggleLikeUserApi(vjUserId, isFans); }
From source file:com.bitants.wally.views.swipeclearlayout.SwipeClearLayout.java
private View generateCircle(Context context, AttributeSet attrs, DisplayMetrics metrics) { ImageView view = new ImageView(context, attrs); GradientDrawable circle = (GradientDrawable) getResources().getDrawable(R.drawable.circle); circle.setColor(CIRCLE_DEFAULT_COLOR); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { view.setBackground(circle); } else {//w w w .j a v a 2 s. c o m view.setBackgroundDrawable(circle); } int size = (int) (metrics.density * CIRCLE_SIZE); RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(size, size); view.setLayoutParams(params); view.setImageResource(R.drawable.clip_random); view.setScaleType(ImageView.ScaleType.CENTER_INSIDE); view.setRotation(90.0f); return view; }
From source file:image_cache.ImageWorker.java
/** * Called when the processing is complete and the final bitmap should be set * on the ImageView.// w w w . j a va 2 s . c o m * * @param imageView * @param bitmap */ @SuppressWarnings("deprecation") @TargetApi(Build.VERSION_CODES.JELLY_BEAN) private void setImageBitmap(ImageView imageView, Bitmap bitmap) { if (mFadeInBitmap) { // Transition drawable with a transparent drwabale and the final // bitmap final TransitionDrawable td = new TransitionDrawable(new Drawable[] { new ColorDrawable(android.R.color.transparent), new BitmapDrawable(mResources, bitmap) }); // Set background to loading bitmap if (Utils.hasJellyBean()) imageView.setBackground(new BitmapDrawable(mResources, mLoadingBitmap)); else imageView.setBackgroundDrawable(new BitmapDrawable(mResources, mLoadingBitmap)); imageView.setBackgroundColor(0); imageView.setImageDrawable(td); td.startTransition(FADE_IN_TIME); } else { imageView.setBackgroundColor(0); imageView.setImageBitmap(bitmap); } }
From source file:org.zywx.wbpalmstar.plugin.uexscrawl.PhotoScrawlActivity.java
private View getColorImageView(int color) { final ImageView imageView = new ImageView(this); int width = EUExUtil.dipToPixels(32); LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(width, width); int margin = EUExUtil.dipToPixels(4); lp.leftMargin = margin;// w w w.java 2 s .c o m lp.rightMargin = margin; imageView.setLayoutParams(lp); imageView.setTag(color); GradientDrawable colorDrawable = new GradientDrawable(); colorDrawable.setColor(color); colorDrawable.setCornerRadius(8); if (Build.VERSION.SDK_INT < 16) { imageView.setBackgroundDrawable(colorDrawable); } else { imageView.setBackground(colorDrawable); } imageView.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { mCurrnetColor = (int) imageView.getTag(); mScrawlImageView.setPaintColor(mCurrnetColor); mPreviewView.setColor(mCurrnetColor); } }); return imageView; }
From source file:uk.ac.horizon.artcodes.scanner.ScannerActivity.java
private void createSettingsUI(List<DetectorSetting> settings) { settingIcons.removeAllViews();//from w ww. ja va 2 s . com if (settings != null && !settings.isEmpty()) { final int padding = getResources().getDimensionPixelSize(R.dimen.setting_padding); List<DetectorSetting> settingList = settings; if (getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE) { settingList = Lists.reverse(settings); } for (final DetectorSetting setting : settingList) { final ImageView button = new ImageView(this); button.setContentDescription(getString(setting.getText())); final int[] attrs = new int[] { android.R.attr.selectableItemBackground }; final TypedArray ta = obtainStyledAttributes(attrs); final Drawable drawableFromTheme = ta.getDrawable(0); ta.recycle(); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { button.setImageResource(setting.getIcon()); button.setImageTintList(ColorStateList.valueOf(Color.WHITE)); button.setBackground(drawableFromTheme); } else { button.setImageDrawable(getTintedDrawable(setting.getIcon(), Color.WHITE)); //noinspection deprecation button.setBackgroundDrawable(drawableFromTheme); } button.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { setting.nextValue(); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { button.setImageResource(setting.getIcon()); } else { button.setImageDrawable(getTintedDrawable(setting.getIcon(), Color.WHITE)); } button.setContentDescription(getString(setting.getText())); textAnimator.setText(setting.getText()); } }); final LinearLayout.LayoutParams params = new LinearLayout.LayoutParams( LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT, 1); params.weight = 1; button.setLayoutParams(params); settingIcons.addView(button); button.setPadding(padding, padding, padding, padding); } } menuAnimator.setViewVisible(settingIcons.getChildCount() > 0); }
From source file:com.seekon.yougouhui.activity.shop.RegisterShopActivity.java
@TargetApi(Build.VERSION_CODES.JELLY_BEAN) private String addShopIconToView(final ImageView imageView, final ImageButton delButton, Intent data) { String iconPath = null;/*from ww w . ja v a 2 s. c o m*/ Uri selectedImage = data.getData(); String[] filePathColumn = { MediaStore.Images.Media.DATA }; Cursor cursor = null; try { cursor = getContentResolver().query(selectedImage, filePathColumn, null, null, null); cursor.moveToFirst(); int columnIndex = cursor.getColumnIndex(filePathColumn[0]); iconPath = cursor.getString(columnIndex); } finally { cursor.close(); } imageView.setBackgroundResource(0); imageView.setBackground( new BitmapDrawable(FileHelper.decodeFile(iconPath, true, SHOP_ICON_WIDTH, SHOP_ICON_WIDTH))); delButton.setVisibility(View.VISIBLE); delButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { imageView.setBackgroundResource(R.drawable.add_camera); delButton.setVisibility(View.GONE); int viewId = v.getId(); if (viewId == R.id.shop_busi_license_del) { busiLicense = null; } else if (viewId == R.id.shop_image_del) { shopImage = null; } } }); return iconPath; }
From source file:com.htc.dotdesign.ToolBoxService.java
private void setSelectedColor(ImageView button) { Drawable select = getResources().getDrawable(R.drawable.dot_design_select); select.setColorFilter(getResources().getColor(R.color.overlay_color), Mode.SRC_IN); ImageView selectedIcon = (ImageView) mPalette.findViewById(R.id.selected); selectedIcon.setBackground(select); Resources res = getResources(); int id = button.getId(); int buttonLeft = button.getLeft(); int buttonTop = button.getTop(); int m1 = res.getDimensionPixelSize(R.dimen.margin_l); int m2 = res.getDimensionPixelSize(R.dimen.margin_m); int colorSize = res.getDimensionPixelSize(R.dimen.hv01); if (id == R.id.btn_color_11 || id == R.id.btn_color_12 || id == R.id.btn_color_13 || id == R.id.btn_color_14) { buttonTop = m2;/*from w ww . ja va 2 s . c o m*/ } else if (id == R.id.btn_color_21 || id == R.id.btn_color_22 || id == R.id.btn_color_23 || id == R.id.btn_color_24) { buttonTop = m2 + colorSize + m1; } else { buttonTop = m2 + 2 * colorSize + 2 * m1; } if (id == R.id.btn_color_11 || id == R.id.btn_color_21 || id == R.id.btn_color_31) { buttonLeft = m2; } else if (id == R.id.btn_color_12 || id == R.id.btn_color_22 || id == R.id.btn_color_32) { buttonLeft = 3 * m2 + colorSize; } else if (id == R.id.btn_color_13 || id == R.id.btn_color_23 || id == R.id.btn_color_33) { buttonLeft = 5 * m2 + 2 * colorSize; } else { buttonLeft = 7 * m2 + 3 * colorSize; } int widthDiff = res.getDimensionPixelSize(R.dimen.select_color_width) - colorSize; int heightDiff = res.getDimensionPixelSize(R.dimen.select_color_height) - colorSize; int marginLeft = buttonLeft - (widthDiff / 2); int marginTop = buttonTop - (heightDiff / 2); RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) selectedIcon.getLayoutParams(); params.setMargins(marginLeft, marginTop, 0, 0); selectedIcon.setLayoutParams(params); selectedIcon.setVisibility(View.VISIBLE); }
From source file:com.bitmaphandler.ImageWorker.java
/** * Called when the processing is complete and the final drawable should be * set on the ImageView.// www . j a v a2 s . co m * * @param imageView * @param drawable */ @SuppressWarnings("deprecation") @TargetApi(Build.VERSION_CODES.JELLY_BEAN) private void setImageDrawable(ImageView imageView, Drawable drawable) { if (mFadeInBitmap) { // Transition drawable with a transparent drawable and the final drawable final TransitionDrawable td = new TransitionDrawable( new Drawable[] { new ColorDrawable(android.R.color.transparent), drawable }); if (useLoadingImage && mLoadingBitmap != null) { // Set background to loading bitmap if (imageView instanceof CircleImageView) { if (!Utils.hasJellyBean()) { imageView.setBackgroundDrawable(new BitmapDrawable(mResources, CircleImageView.getCroppedBitmap(mLoadingBitmap, mLoadingBitmap.getWidth()))); } else { imageView.setBackground(new BitmapDrawable(mResources, CircleImageView.getCroppedBitmap(mLoadingBitmap, mLoadingBitmap.getWidth()))); } } else if (imageView instanceof RoundedBitmapDisplayer) { if (!Utils.hasJellyBean()) { imageView.setBackgroundDrawable( new BitmapDrawable(mResources, RoundedBitmapDisplayer.roundCorners(mLoadingBitmap, imageView, ((RoundedBitmapDisplayer) imageView).getRoundPixle()))); } else { imageView.setBackground(new BitmapDrawable(mResources, RoundedBitmapDisplayer.roundCorners( mLoadingBitmap, imageView, ((RoundedBitmapDisplayer) imageView).getRoundPixle()))); } } else { if (!Utils.hasJellyBean()) { imageView.setBackgroundDrawable(new BitmapDrawable(mResources, mLoadingBitmap)); } else { imageView.setBackground(new BitmapDrawable(mResources, mLoadingBitmap)); } } } imageView.setImageDrawable(td); td.startTransition(FADE_IN_TIME); } else { imageView.setImageDrawable(drawable); } }
From source file:com.baseproject.image.ImageWorker.java
/** * Called when the processing is complete and the final bitmap should be set * on the ImageView.//from www . j a v a 2 s. c om * * @param imageView * @param bitmap */ @SuppressWarnings("deprecation") @SuppressLint("NewApi") private void setImageBitmap(ImageView imageView, Bitmap bitmap) { if (mFadeInBitmap) { if (imageView.getTag() instanceof String && "no_animation".equals(String.valueOf(imageView.getTag()))) { imageView.setImageBitmap(bitmap); } else { // Transition drawable with a transparent drwabale and the final // bitmap TransitionDrawable td = new TransitionDrawable( new Drawable[] { new ColorDrawable(android.R.color.transparent), new BitmapDrawable(mContext.getResources(), bitmap) }); final WeakReference<TransitionDrawable> tdReference = new WeakReference<TransitionDrawable>(td); td = null; // Set background to loading bitmap final BitmapDrawable bd = new BitmapDrawable(mContext.getResources(), mLoadingBitmap); if (Build.VERSION.SDK_INT >= 16) { imageView.setBackground(bd); } else { imageView.setBackgroundDrawable(bd); } if (null != tdReference.get()) { imageView.setImageDrawable(tdReference.get()); tdReference.get().startTransition(FADE_IN_TIME); } } } else { imageView.setImageBitmap(bitmap); } }