List of usage examples for android.widget ImageView setBackground
public void setBackground(Drawable background)
From source file:com.tafayor.selfcamerashot.taflib.helpers.GraphicsHelper.java
public static void tintView(ImageView view, int color) { Drawable bg = view.getBackground();//from w ww. j ava2s. c om if (bg != null) { bg = DrawableCompat.wrap(bg); DrawableCompat.setTint(bg, color); view.setBackground(bg); } Drawable img = view.getDrawable(); if (img != null) { img = DrawableCompat.wrap(img); DrawableCompat.setTint(img, color); view.setImageDrawable(img); } }
From source file:com.android.packageinstaller.permission.ui.PermissionAppsFragment.java
private static void bindUi(Fragment fragment, PermissionApps permissionApps) { final Drawable icon = permissionApps.getIcon(); final CharSequence label = permissionApps.getLabel(); final ActionBar ab = fragment.getActivity().getActionBar(); if (ab != null) { ab.setTitle(fragment.getString(R.string.permission_title, label)); }/*from w ww.j a v a 2 s.co m*/ final ViewGroup rootView = (ViewGroup) fragment.getView(); final ImageView iconView = (ImageView) rootView.findViewById(R.id.lb_icon); if (iconView != null) { // Set the icon as the background instead of the image because ImageView // doesn't properly scale vector drawables beyond their intrinsic size iconView.setBackground(icon); } final TextView titleView = (TextView) rootView.findViewById(R.id.lb_title); if (titleView != null) { titleView.setText(label); } final TextView breadcrumbView = (TextView) rootView.findViewById(R.id.lb_breadcrumb); if (breadcrumbView != null) { breadcrumbView.setText(R.string.app_permissions); } }
From source file:es.voghdev.prjdagger2.ui.renderer.UserRenderer.java
private void transformImageWithPorterDuff(ImageView imageView) { Drawable background = ContextCompat.getDrawable(mContext, R.drawable.rounded_edges); background.setColorFilter(ContextCompat.getColor(mContext, R.color.light_gray), PorterDuff.Mode.SRC_OVER); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { imageView.setBackground(background); // setBackground requires minSdkVersion >= 16!! } else {//from ww w .j a va 2 s . c o m imageView.setBackgroundDrawable(background); // setBackground requires minSdkVersion >= 16!! } }
From source file:com.example.android.navigationdrawer.QRCode.java
public void onQR(View v) { switch (v.getId()) { case R.id.button1: String qrInputText = MidiFile.readString; //Find screen size WindowManager manager = (WindowManager) getSystemService(WINDOW_SERVICE); Display display = manager.getDefaultDisplay(); Point point = new Point(); display.getSize(point);/*from ww w .ja v a 2 s. co m*/ int width = point.x; int height = point.y; int smallerDimension = width < height ? width : height; smallerDimension = smallerDimension * 3 / 4; //Encode with a QR Code image QRCodeEncoder qrCodeEncoder = new QRCodeEncoder(qrInputText, null, Contents.Type.TEXT, BarcodeFormat.QR_CODE.toString(), smallerDimension); try { Bitmap bitmap = qrCodeEncoder.encodeAsBitmap(); ImageView myImage = (ImageView) findViewById(R.id.imageView1); myImage.setImageBitmap(bitmap); // Get screen size Display display1 = this.getWindowManager().getDefaultDisplay(); Point size = new Point(); display1.getSize(size); int screenWidth = size.x; int screenHeight = size.y; // Get target image size Bitmap bitmap1 = qrCodeEncoder.encodeAsBitmap(); int bitmapHeight = bitmap1.getHeight(); int bitmapWidth = bitmap1.getWidth(); // Scale the image down to fit perfectly into the screen // The value (250 in this case) must be adjusted for phone/tables displays while (bitmapHeight > (screenHeight - 250) || bitmapWidth > (screenWidth - 250)) { bitmapHeight = bitmapHeight / 2; bitmapWidth = bitmapWidth / 2; } // Create resized bitmap image BitmapDrawable resizedBitmap = new BitmapDrawable(this.getResources(), Bitmap.createScaledBitmap(bitmap, bitmapWidth, bitmapHeight, false)); // Create dialog Dialog dialog = new Dialog(this); dialog.requestWindowFeature(Window.FEATURE_NO_TITLE); dialog.setContentView(R.layout.thumbnail); ImageView image = (ImageView) dialog.findViewById(R.id.imageview); // !!! Do here setBackground() instead of setImageDrawable() !!! // image.setBackground(resizedBitmap); // Without this line there is a very small border around the image (1px) // In my opinion it looks much better without it, so the choice is up to you. dialog.getWindow().setBackgroundDrawable(null); dialog.show(); } catch (WriterException e) { e.printStackTrace(); } break; } }
From source file:gr.unfold.android.tsibato.images.ImageWorker.java
@TargetApi(16) @SuppressWarnings("deprecation") 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 }); // Set background to loading bitmap if (Utils.hasJellyBean()) { imageView.setBackground(new BitmapDrawable(mResources, mLoadingBitmap)); } else {// ww w.jav a2 s .c om imageView.setBackgroundDrawable(new BitmapDrawable(mResources, mLoadingBitmap)); } imageView.setImageDrawable(td); td.startTransition(FADE_IN_TIME); } else { imageView.setImageDrawable(drawable); } }
From source file:com.mallapp.utils.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./*from ww w . java 2 s. c om*/ */ 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(android.R.color.transparent), new BitmapDrawable(mResources, bitmap) }); imageView.setBackground(imageView.getDrawable()); imageView.setImageDrawable(td); td.startTransition(FADE_IN_TIME); } else { bitmap = getCroppedBitmap(bitmap); imageView.setImageBitmap(bitmap); } }
From source file:org.glucosio.android.activity.MainActivity.java
public void checkIfEmptyLayout() { LinearLayout emptyLayout = (LinearLayout) findViewById(R.id.activity_main_empty_layout); ViewPager pager = (ViewPager) findViewById(R.id.activity_main_pager); if (presenter.isdbEmpty()) { pager.setVisibility(View.GONE); tabLayout.setVisibility(View.GONE); emptyLayout.setVisibility(View.VISIBLE); bottomSheetAddDialogView = getLayoutInflater().inflate(R.layout.fragment_add_bottom_dialog_disabled, null);/*from ww w .jav a 2s. c o m*/ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { if (getResources().getConfiguration().orientation == 1) { // If Portrait choose vertical curved line ImageView arrow = (ImageView) findViewById(R.id.activity_main_arrow); arrow.setBackground(getResources().getDrawable(R.drawable.curved_line_vertical)); } else { // Else choose horizontal one ImageView arrow = (ImageView) findViewById(R.id.activity_main_arrow); arrow.setBackground((getResources().getDrawable(R.drawable.curved_line_horizontal))); } } } else { pager.setVisibility(View.VISIBLE); emptyLayout.setVisibility(View.GONE); bottomSheetAddDialogView = getLayoutInflater().inflate(R.layout.fragment_add_bottom_dialog, null); } }
From source file:com.cnblogs.app.bitmap.ImageWorker.java
/** * Called when the processing is complete and the final drawable should be * set on the ImageView.//ww w . j a v a2 s . c o m * * @param imageView * @param drawable */ 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 }); // Set background to loading bitmap imageView.setBackground(new BitmapDrawable(mResources, mLoadingBitmap)); imageView.setImageDrawable(td); td.startTransition(FADE_IN_TIME); } else { imageView.setImageDrawable(drawable); } }
From source file:com.tack.android.image.ImageWorker.java
/** * Called when the processing is complete and the final bitmap should be set on the ImageView. * * @param imageView//ww w .j a v a 2s.co m * @param bitmap */ @TargetApi(Build.VERSION_CODES.JELLY_BEAN) @SuppressWarnings("deprecation") private void setImageBitmap(ImageView imageView, Bitmap bitmap) { if (mFadeInBitmap) { // Transition drawable with a transparent drawable 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 (ConfigUtil.hasV16()) { imageView.setBackground(new BitmapDrawable(mResources, mLoadingBitmap)); } else { imageView.setBackgroundDrawable(new BitmapDrawable(mResources, mLoadingBitmap)); } imageView.setImageDrawable(td); td.startTransition(FADE_IN_TIME); } else { imageView.setImageBitmap(bitmap); } }
From source file:com.itsherpa.andg.imageloader.ContactImageLoader.java
/** * Called when the processing is complete and the final bitmap should be set * on the ImageView./*from www . java 2s.c om*/ * * @param imageView * The ImageView to set the bitmap to. * @param bitmap * The new bitmap to set. */ @TargetApi(Build.VERSION_CODES.JELLY_BEAN) @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(android.R.color.transparent), new BitmapDrawable(mResources, bitmap) }); if (Build.VERSION.SDK_INT >= 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); } }