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

The following examples show how to use android.widget.ImageView#setImageBitmap() . 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: ImageLoader.java    From TitanjumNote with Apache License 2.0 6 votes vote down vote up
/**
 * The default implementation of ImageListener which handles basic functionality
 * of showing a default image until the network response is received, at which point
 * it will switch to either the actual image or the error image.
 * @param view The imageView that the listener is associated with.
 * @param defaultImageResId Default image resource ID to use, or 0 if it doesn't exist.
 * @param errorImageResId Error image resource ID to use, or 0 if it doesn't exist.
 */
public static ImageListener getImageListener(final ImageView view,
        final int defaultImageResId, final int errorImageResId) {
    return new ImageListener() {
        @Override
        public void onErrorResponse(VolleyError error) {
            if (errorImageResId != 0) {
                view.setImageResource(errorImageResId);
            }
        }

        @Override
        public void onResponse(ImageContainer response, boolean isImmediate) {
            if (response.getBitmap() != null) {
                view.setImageBitmap(response.getBitmap());
            } else if (defaultImageResId != 0) {
                view.setImageResource(defaultImageResId);
            }
        }
    };
}
 
Example 2
Source File: Test4ImageActivity.java    From AndroidGodEye with Apache License 2.0 6 votes vote down vote up
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    LinearLayout contentView = new LinearLayout(this);
    ImageView imageView0 = new ImageView(this);
    imageView0.setImageBitmap(ShadowBitmapFactory.create("AndroidGodEye-Bitmap", null, new Point(200, 100)));
    ImageView imageView1 = new ImageView(this);
    imageView1.setImageBitmap(ShadowBitmapFactory.create("AndroidGodEye-Bitmap", null, new Point(200, 100)));
    ImageView imageView2 = new ImageView(this);
    imageView2.setImageBitmap(ShadowBitmapFactory.create("AndroidGodEye-Bitmap", null, new Point(200, 100)));
    imageView3 = new ImageView(this);
    imageView3.setImageBitmap(ShadowBitmapFactory.create("AndroidGodEye-Bitmap", null, new Point(200, 100)));
    contentView.addView(imageView0);
    contentView.addView(imageView1);
    contentView.addView(imageView2);
    contentView.addView(imageView3);
    setContentView(contentView);
    imageView0.measure(50, 50);
    imageView0.layout(0, 0, 50, 50);
    imageView1.measure(500, 500);
    imageView1.layout(0, 0, 500, 500);
    imageView2.measure(210, 95);
    imageView2.layout(0, 0, 210, 95);
    imageView3.measure(50, 50);
    imageView3.layout(0, 0, 50, 50);
}
 
Example 3
Source File: RecipeListAdapter.java    From AndroidWearable-Samples with Apache License 2.0 6 votes vote down vote up
@Override
public View getView(int position, View convertView, ViewGroup parent) {
    View view = convertView;
    if (view == null) {
        LayoutInflater inf = LayoutInflater.from(mContext);
        view = inf.inflate(R.layout.list_item, null);
    }
    Item item = (Item) getItem(position);
    TextView titleView = (TextView) view.findViewById(R.id.textTitle);
    TextView summaryView = (TextView) view.findViewById(R.id.textSummary);
    ImageView iv = (ImageView) view.findViewById(R.id.imageView);

    titleView.setText(item.title);
    summaryView.setText(item.summary);
    if (item.image != null) {
        iv.setImageBitmap(item.image);
    } else {
        iv.setImageDrawable(mContext.getResources().getDrawable(R.drawable.ic_noimage));
    }
    return view;
}
 
Example 4
Source File: PrivateActivity.java    From SimplicityBrowser with MIT License 6 votes vote down vote up
private void createFileName() {
    LayoutInflater inflater = getLayoutInflater();
    Bitmap resizedBitmap = Bitmap.createBitmap(favoriteIcon);
    @SuppressLint("InflateParams") View alertLayout = inflater.inflate(R.layout.layout_shortcut, null);
    shortcutNameEditText = alertLayout.findViewById(R.id.shortcut_name_edittext);
    AlertDialog alertDialog = createExitDialog();
    alertDialog.setTitle(R.string.add_home);
    alertDialog.setView(alertLayout);
    alertDialog.show();
    shortcutNameEditText.setHint(webViewTitle);
    ImageView imageShortcut = alertDialog.findViewById(R.id.fav_imageView);
    if (imageShortcut != null) {
        imageShortcut.setImageBitmap(StaticUtils.getCircleBitmap(resizedBitmap));
    }else{
        Log.d("Null", "");
    }
    alertDialog.getButton(DialogInterface.BUTTON_POSITIVE).setTextColor(ContextCompat.getColor(this, R.color.md_blue_600));
    alertDialog.getButton(DialogInterface.BUTTON_NEGATIVE).setTextColor(Color.LTGRAY);
}
 
Example 5
Source File: DownloadImageTask.java    From StreamHub-Android-SDK with MIT License 5 votes vote down vote up
public static void getRoundedShape(ImageView scaleBitmapImageview) {
	Drawable scaleDrawable = scaleBitmapImageview.getDrawable();
	BitmapDrawable bitmapDrawable = ((BitmapDrawable) scaleDrawable);
	Bitmap bitmap = bitmapDrawable.getBitmap();
	Bitmap targetBitmap = null;
	try {
		int targetWidth = 100;
		int targetHeight = 100;
		targetBitmap = Bitmap.createBitmap(targetWidth, targetHeight,
				Bitmap.Config.ARGB_8888);

		Canvas canvas = new Canvas(targetBitmap);
		Path path = new Path();
		path.addCircle(
				((float) targetWidth - 1) / 2,
				((float) targetHeight - 1) / 2,
				(Math.min(((float) targetWidth), ((float) targetHeight)) / 2),
				Path.Direction.CCW);

		canvas.clipPath(path);
		Bitmap sourceBitmap = bitmap;
		canvas.drawBitmap(
				sourceBitmap,
				new Rect(0, 0, sourceBitmap.getWidth(), sourceBitmap
						.getHeight()), new Rect(0, 0, targetWidth,
						targetHeight), null);
	} catch (Exception e) {
		// e.printStackTrace();
	}
	scaleBitmapImageview.setImageBitmap(targetBitmap);
	// return targetBitmap;
}
 
Example 6
Source File: BaseActivity.java    From CoolViewPager with Apache License 2.0 5 votes vote down vote up
public View createImageView(int imgResId){
    ImageView imageView = new ImageView(this);
    imageView.setLayoutParams(new CoolViewPager.LayoutParams());
    imageView.setScaleType(ImageView.ScaleType.FIT_XY);
    if(imgs.get(""+imgResId) != null){
        imageView.setImageBitmap(imgs.get(""+imgResId));
    }else{
        BitmapFactory.Options options = new BitmapFactory.Options();
        options.inSampleSize = 2;
        Bitmap bitmap = BitmapFactory.decodeResource(getResources(),imgResId,options);
        imgs.put(""+imgResId,bitmap);
        imageView.setImageBitmap(bitmap);
    }
    return imageView;
}
 
Example 7
Source File: NotificationBoardCallback.java    From Android-Notification with Apache License 2.0 5 votes vote down vote up
/**
 * Called when a row view is being updated.
 *
 * @param board
 * @param rowView
 * @param entry
 */
public void onRowViewUpdate(NotificationBoard board, RowView rowView, NotificationEntry entry) {
    if (DBG) Log.v(TAG, "onRowViewUpdate - " + entry.ID);

    ImageView iconView = (ImageView) rowView.findViewById(R.id.icon);
    TextView titleView = (TextView) rowView.findViewById(R.id.title);
    TextView textView = (TextView) rowView.findViewById(R.id.text);
    TextView whenView = (TextView) rowView.findViewById(R.id.when);
    ProgressBar bar = (ProgressBar) rowView.findViewById(R.id.progress);

    if (entry.iconDrawable != null) {
        iconView.setImageDrawable(entry.iconDrawable);
    } else if (entry.smallIconRes != 0) {
        iconView.setImageResource(entry.smallIconRes);
    } else if (entry.largeIconBitmap != null) {
        iconView.setImageBitmap(entry.largeIconBitmap);
    }

    titleView.setText(entry.title);
    textView.setText(entry.text);

    if (entry.showWhen) {
        whenView.setText(entry.whenFormatted);
    }

    if (entry.progressMax != 0 || entry.progressIndeterminate) {
        bar.setVisibility(View.VISIBLE);
        bar.setIndeterminate(entry.progressIndeterminate);
        if (!entry.progressIndeterminate) {
            bar.setMax(entry.progressMax);
            bar.setProgress(entry.progress);
        }
    } else {
        bar.setVisibility(View.GONE);
    }

}
 
Example 8
Source File: NavigationSnapshotReadyCallback.java    From graphhopper-navigation-android with MIT License 5 votes vote down vote up
@NonNull
private ImageView updateScreenshotViewWithSnapshot(Bitmap snapshot) {
  ImageView screenshotView = navigationView.findViewById(R.id.screenshotView);
  screenshotView.setVisibility(View.VISIBLE);
  screenshotView.setImageBitmap(snapshot);
  return screenshotView;
}
 
Example 9
Source File: CardThumbnailView.java    From example with Apache License 2.0 5 votes vote down vote up
@Override
protected void onPostExecute(Bitmap bitmap) {
    if (isCancelled()) {
        bitmap = null;
    }

    if (imageViewReference != null && bitmap != null) {
        final ImageView imageView = imageViewReference.get();
        final BitmapWorkerTask bitmapWorkerTask =
                getBitmapWorkerTask(imageView);
        if (this == bitmapWorkerTask && imageView != null) {
            if (!mCardThumbnail.applyBitmap(imageView,bitmap))
                imageView.setImageBitmap(bitmap);
            sendBroadcast();
            mLoadingErrorResource=false;
        }
    }else{
        sendBroadcast(false);
        if (mCardThumbnail!=null && mCardThumbnail.getErrorResourceId()!=0){
            if (!mLoadingErrorResource){
                //To avoid a loop
                loadBitmap(mCardThumbnail.getErrorResourceId(), mImageView);
            }
            mLoadingErrorResource=true;
        }
    }
}
 
Example 10
Source File: MonsterListFragment.java    From MonsterHunter4UDatabase with MIT License 5 votes vote down vote up
@Override
public void bindView(View view, Context context, Cursor cursor) {
	// Get the monster for the current row
	Monster monster = mMonsterCursor.getMonster();
       AssetManager manager = context.getAssets();

	// Set up the text view
	TextView monsterNameTextView = (TextView) view.findViewById(R.id.item_label);
	ImageView monsterImage = (ImageView) view.findViewById(R.id.item_image);

          RelativeLayout itemLayout = (RelativeLayout) view.findViewById(R.id.listitem);
	
	String cellText = monster.getName();
	String cellImage = "icons_monster/" + monster.getFileLocation();
	
	monsterNameTextView.setText(cellText);
	
       // Read a Bitmap from Assets
       try {
           InputStream open = manager.open(cellImage);
           Bitmap bitmap = BitmapFactory.decodeStream(open);
           // Assign the bitmap to an ImageView in this layout
           monsterImage.setImageBitmap(bitmap);
       } catch (IOException e) {
           e.printStackTrace();
       }

          itemLayout.setTag(monster.getId());
          itemLayout.setOnClickListener(new MonsterClickListener(context, monster.getId()));
}
 
Example 11
Source File: DragFloatViewHelper.java    From MultiItem with Apache License 2.0 5 votes vote down vote up
/**
 * @param coverView 被覆盖的view,用于生产浮层View
 * @return 需要跟随手势浮动的 View
 */
protected View createFloatView(View coverView) {
    ImageView floatView = new ImageView(coverView.getContext());
    coverView.destroyDrawingCache();
    coverView.setDrawingCacheEnabled(true);
    Bitmap bitmap = coverView.getDrawingCache();
    if (bitmap != null && !bitmap.isRecycled()) {
        floatView.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT));
        floatView.setImageBitmap(bitmap);
    }
    return floatView;
}
 
Example 12
Source File: AddFriendQRActivity.java    From NaviBee with GNU General Public License v3.0 5 votes vote down vote up
private void generateQRCode() {
    try {
        qrCode = new BarcodeEncoder().encodeBitmap(ADD_FRIEND_URL + uid,
                BarcodeFormat.QR_CODE, 768, 768);

        AlertDialog.Builder builder = new AlertDialog.Builder(this);
        ImageView image = new ImageView(this);
        image.setImageBitmap(qrCode);
        builder.setView(image);
        dialog = builder.create();
    } catch (Exception ignored) {
    }
}
 
Example 13
Source File: ImageLoader.java    From socialauth-android with MIT License 5 votes vote down vote up
public void DisplayImage(String url, ImageView imageView) {
	imageViews.put(imageView, url);
	Bitmap bitmap = memoryCache.get(url);
	if (bitmap != null) {
		imageView.setImageBitmap(bitmap);
	} else {
		queuePhoto(url, imageView);
		imageView.setImageDrawable(new ColorDrawable(Color.WHITE));
	}
}
 
Example 14
Source File: PlatformPageAdapter.java    From Social with Apache License 2.0 4 votes vote down vote up
private void refreshPanel(LinearLayout[] llCells, Object[] logos) {
	int cellBack = R.getBitmapRes(page.getContext(), "ssdk_oks_classic_platform_cell_back");
	int disableBack = R.getBitmapRes(page.getContext(), "ssdk_oks_classic_platfrom_cell_back_nor");
	for (int i = 0; i < logos.length; i++) {
		ImageView ivLogo = R.forceCast(llCells[i].getChildAt(0));
		TextView tvName = R.forceCast(llCells[i].getChildAt(1));
		if (logos[i] == null) {
			ivLogo.setVisibility(View.INVISIBLE);
			tvName.setVisibility(View.INVISIBLE);
			llCells[i].setBackgroundResource(disableBack);
			llCells[i].setOnClickListener(null);
		} else {
			ivLogo.setVisibility(View.VISIBLE);
			tvName.setVisibility(View.VISIBLE);
			llCells[i].setBackgroundResource(cellBack);
			llCells[i].setOnClickListener(this);
			llCells[i].setTag(logos[i]);

			if (logos[i] instanceof CustomerLogo) {
				CustomerLogo logo = R.forceCast(logos[i]);
				if (logo.logo != null) {
					ivLogo.setImageBitmap(logo.logo);
				} else {
					ivLogo.setImageBitmap(null);
				}
				if (logo.label != null) {
					tvName.setText(logo.label);
				} else {
					tvName.setText("");
				}
			} else {
				Platform plat = R.forceCast(logos[i]);
				String name = plat.getName().toLowerCase();
				int resId = R.getBitmapRes(ivLogo.getContext(),"ssdk_oks_classic_" + name);
				if (resId > 0) {
					ivLogo.setImageResource(resId);
				} else {
					ivLogo.setImageBitmap(null);
				}
				resId = R.getStringRes(tvName.getContext(), "ssdk_" + name);
				if (resId > 0) {
					tvName.setText(resId);
				} else {
					tvName.setText("");
				}
			}
		}
	}
}
 
Example 15
Source File: EaseChatRowImage.java    From Study_Android_Demo with Apache License 2.0 4 votes vote down vote up
/**
 * load image into image view
 * 
 * @param thumbernailPath
 * @param iv
 * @param position
 * @return the image exists or not
 */
private boolean showImageView(final String thumbernailPath, final ImageView iv, final String localFullSizePath,final EMMessage message) {
    // first check if the thumbnail image already loaded into cache
    Bitmap bitmap = EaseImageCache.getInstance().get(thumbernailPath);
    if (bitmap != null) {
        // thumbnail image is already loaded, reuse the drawable
        iv.setImageBitmap(bitmap);
        return true;
    } else {
        new AsyncTask<Object, Void, Bitmap>() {

            @Override
            protected Bitmap doInBackground(Object... args) {
                File file = new File(thumbernailPath);
                if (file.exists()) {
                    return EaseImageUtils.decodeScaleImage(thumbernailPath, 160, 160);
                } else if (new File(imgBody.thumbnailLocalPath()).exists()) {
                    return EaseImageUtils.decodeScaleImage(imgBody.thumbnailLocalPath(), 160, 160);
                }
                else {
                    if (message.direct() == EMMessage.Direct.SEND) {
                        if (localFullSizePath != null && new File(localFullSizePath).exists()) {
                            return EaseImageUtils.decodeScaleImage(localFullSizePath, 160, 160);
                        } else {
                            return null;
                        }
                    } else {
                        return null;
                    }
                }
            }

            protected void onPostExecute(Bitmap image) {
                if (image != null) {
                    iv.setImageBitmap(image);
                    EaseImageCache.getInstance().put(thumbernailPath, image);
                } else {
                    if (message.status() == EMMessage.Status.FAIL) {
                        if (EaseCommonUtils.isNetWorkConnected(activity)) {
                            new Thread(new Runnable() {

                                @Override
                                public void run() {
                                    EMClient.getInstance().chatManager().downloadThumbnail(message);
                                }
                            }).start();
                        }
                    }

                }
            }
        }.execute();

        return true;
    }
}
 
Example 16
Source File: EditPage.java    From BigApp_Discuz_Android with Apache License 2.0 4 votes vote down vote up
/** display platform list */
public void afterPlatformListGot() {
	int size = platformList == null ? 0 : platformList.length;
	views = new View[size];

	final int dp_24 = dipToPx(getContext(), 24);
	LayoutParams lpItem = new LayoutParams(dp_24, dp_24);
	final int dp_9 = dipToPx(getContext(), 9);
	lpItem.setMargins(0, 0, dp_9, 0);
	FrameLayout.LayoutParams lpMask = new FrameLayout.LayoutParams(
			LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
	lpMask.gravity = Gravity.LEFT | Gravity.TOP;
	int selection = 0;
	for (int i = 0; i < size; i++) {
		FrameLayout fl = new FrameLayout(getContext());
		fl.setLayoutParams(lpItem);
		if (i >= size - 1) {
			fl.setLayoutParams(new LayoutParams(dp_24, dp_24));
		}
		llPlat.addView(fl);
		fl.setOnClickListener(this);

		ImageView iv = new ImageView(getContext());
		iv.setScaleType(ScaleType.CENTER_INSIDE);
		iv.setImageBitmap(getPlatLogo(platformList[i]));
		iv.setLayoutParams(new FrameLayout.LayoutParams(
				LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
		fl.addView(iv);

		views[i] = new View(getContext());
		views[i].setBackgroundColor(0xcfffffff);
		views[i].setOnClickListener(this);
		String platformName = platformList[i].getName();
		for(Platform plat : platforms) {
			if(platformName.equals(plat.getName())) {
				views[i].setVisibility(View.INVISIBLE);
				selection = i;
			}
		}
		views[i].setLayoutParams(lpMask);
		fl.addView(views[i]);
	}

	final int postSel = selection;
	UIHandler.sendEmptyMessageDelayed(0, 333, new Callback() {
		public boolean handleMessage(Message msg) {
			HorizontalScrollView hsv = (HorizontalScrollView)llPlat.getParent();
			hsv.scrollTo(postSel * (dp_24 + dp_9), 0);
			return false;
		}
	});
}
 
Example 17
Source File: EaseEmojiconIndicatorView.java    From nono-android with GNU General Public License v3.0 4 votes vote down vote up
public void selectTo(int startPosition, int targetPostion){
    ImageView startView = dotViews.get(startPosition);
    ImageView targetView = dotViews.get(targetPostion);
    startView.setImageBitmap(unselectedBitmap);
    targetView.setImageBitmap(selectedBitmap);
}
 
Example 18
Source File: ViewHolderHelper.java    From RecyclerViewHelper with MIT License 4 votes vote down vote up
public ViewHolderHelper setImageBitmap(int viewId, Bitmap bitmap) {
    ImageView view = getView(viewId);
    view.setImageBitmap(bitmap);
    return this;
}
 
Example 19
Source File: ViewHolderImpl.java    From commonadapter with MIT License 4 votes vote down vote up
public void setImageBitmap(int viewId, Bitmap bitmap) {
    ImageView target = findViewById(viewId);
    target.setImageBitmap(bitmap);
}
 
Example 20
Source File: BaseViewHolder.java    From demo4Fish with MIT License 4 votes vote down vote up
/**
 * Add an action to set the image of an image view. Can be called multiple times.
 */
public BaseViewHolder setImageBitmap(int viewId, Bitmap bitmap) {
    ImageView view = getView(viewId);
    view.setImageBitmap(bitmap);
    return this;
}