List of usage examples for android.widget ImageView setImageBitmap
@android.view.RemotableViewMethod public void setImageBitmap(Bitmap bm)
From source file:org.lol.reddit.activities.CaptchaActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { PrefsUtility.applyTheme(this); getSupportActionBar().setTitle(R.string.post_captcha_title); super.onCreate(savedInstanceState); final LoadingView loadingView = new LoadingView(this, R.string.download_waiting, true, true); setContentView(loadingView);/*from w ww . j av a 2 s . c o m*/ final RedditAccount selectedAccount = RedditAccountManager.getInstance(this) .getAccount(getIntent().getStringExtra("username")); final CacheManager cm = CacheManager.getInstance(this); RedditAPI.newCaptcha(cm, new APIResponseHandler.NewCaptchaResponseHandler(this) { @Override protected void onSuccess(final String captchaId) { final URI captchaUrl = Constants.Reddit.getUri("/captcha/" + captchaId); cm.makeRequest(new CacheRequest(captchaUrl, RedditAccountManager.getAnon(), null, Constants.Priority.CAPTCHA, 0, CacheRequest.DownloadType.FORCE, Constants.FileType.CAPTCHA, false, false, true, CaptchaActivity.this) { @Override protected void onCallbackException(Throwable t) { BugReportActivity.handleGlobalError(CaptchaActivity.this, t); } @Override protected void onDownloadNecessary() { } @Override protected void onDownloadStarted() { loadingView.setIndeterminate(R.string.download_downloading); } @Override protected void onFailure(RequestFailureType type, Throwable t, StatusLine status, String readableMessage) { final RRError error = General.getGeneralErrorForFailure(CaptchaActivity.this, type, t, status, url.toString()); General.showResultDialog(CaptchaActivity.this, error); finish(); } @Override protected void onProgress(long bytesRead, long totalBytes) { loadingView.setProgress(R.string.download_downloading, (float) ((double) bytesRead / (double) totalBytes)); } @Override protected void onSuccess(final CacheManager.ReadableCacheFile cacheFile, long timestamp, UUID session, boolean fromCache, String mimetype) { final Bitmap image; try { image = BitmapFactory.decodeStream(cacheFile.getInputStream()); } catch (IOException e) { BugReportActivity.handleGlobalError(CaptchaActivity.this, e); return; } General.UI_THREAD_HANDLER.post(new Runnable() { public void run() { final LinearLayout ll = new LinearLayout(CaptchaActivity.this); ll.setOrientation(LinearLayout.VERTICAL); final ImageView captchaImg = new ImageView(CaptchaActivity.this); ll.addView(captchaImg); final LinearLayout.LayoutParams layoutParams = (LinearLayout.LayoutParams) captchaImg .getLayoutParams(); layoutParams.setMargins(20, 20, 20, 20); layoutParams.height = General.dpToPixels(context, 100); captchaImg.setScaleType(ImageView.ScaleType.FIT_CENTER); final EditText captchaText = new EditText(CaptchaActivity.this); ll.addView(captchaText); ((LinearLayout.LayoutParams) captchaText.getLayoutParams()).setMargins(20, 0, 20, 20); captchaText.setInputType(android.text.InputType.TYPE_CLASS_TEXT | android.text.InputType.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD | InputType.TYPE_TEXT_FLAG_CAP_CHARACTERS); captchaImg.setImageBitmap(image); final Button submitButton = new Button(CaptchaActivity.this); submitButton.setText(R.string.post_captcha_submit_button); ll.addView(submitButton); ((LinearLayout.LayoutParams) submitButton.getLayoutParams()).setMargins(20, 0, 20, 20); ((LinearLayout.LayoutParams) submitButton .getLayoutParams()).gravity = Gravity.RIGHT; ((LinearLayout.LayoutParams) submitButton .getLayoutParams()).width = LinearLayout.LayoutParams.WRAP_CONTENT; submitButton.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { final Intent result = new Intent(); result.putExtra("captchaId", captchaId); result.putExtra("captchaText", captchaText.getText().toString()); setResult(RESULT_OK, result); finish(); } }); final ScrollView sv = new ScrollView(CaptchaActivity.this); sv.addView(ll); setContentView(sv); } }); } }); } @Override protected void onCallbackException(Throwable t) { BugReportActivity.handleGlobalError(CaptchaActivity.this, t); } @Override protected void onFailure(RequestFailureType type, Throwable t, StatusLine status, String readableMessage) { final RRError error = General.getGeneralErrorForFailure(CaptchaActivity.this, type, t, status, null); General.showResultDialog(CaptchaActivity.this, error); finish(); } @Override protected void onFailure(APIFailureType type) { final RRError error = General.getGeneralErrorForFailure(CaptchaActivity.this, type); General.showResultDialog(CaptchaActivity.this, error); finish(); } }, selectedAccount, this); }
From source file:com.ryan.ryanreader.activities.CaptchaActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { PrefsUtility.applyTheme(this); getSupportActionBar().setTitle(R.string.post_captcha_title); super.onCreate(savedInstanceState); final LoadingView loadingView = new LoadingView(this, R.string.download_waiting, true, true); setContentView(loadingView);/*from w w w .j a va2 s .c om*/ final RedditAccount selectedAccount = RedditAccountManager.getInstance(this) .getAccount(getIntent().getStringExtra("username")); final CacheManager cm = CacheManager.getInstance(this); RedditAPI.newCaptcha(cm, new APIResponseHandler.NewCaptchaResponseHandler(this) { @Override protected void onSuccess(final String captchaId) { final URI captchaUrl = Constants.Reddit.getUri("/captcha/" + captchaId); cm.makeRequest(new CacheRequest(captchaUrl, RedditAccountManager.getAnon(), null, Constants.Priority.CAPTCHA, 0, CacheRequest.DownloadType.FORCE, Constants.FileType.CAPTCHA, false, false, true, CaptchaActivity.this) { @Override protected void onCallbackException(Throwable t) { BugReportActivity.handleGlobalError(CaptchaActivity.this, t); } @Override protected void onDownloadNecessary() { } @Override protected void onDownloadStarted() { loadingView.setIndeterminate(R.string.download_downloading); } @Override protected void onFailure(RequestFailureType type, Throwable t, StatusLine status, String readableMessage) { final RRError error = General.getGeneralErrorForFailure(CaptchaActivity.this, type, t, status); General.showResultDialog(CaptchaActivity.this, error); finish(); } @Override protected void onProgress(long bytesRead, long totalBytes) { loadingView.setProgress(R.string.download_downloading, (float) ((double) bytesRead / (double) totalBytes)); } @Override protected void onSuccess(final CacheManager.ReadableCacheFile cacheFile, long timestamp, UUID session, boolean fromCache, String mimetype) { final Bitmap image; try { image = BitmapFactory.decodeStream(cacheFile.getInputStream()); } catch (IOException e) { BugReportActivity.handleGlobalError(CaptchaActivity.this, e); return; } new Handler(Looper.getMainLooper()).post(new Runnable() { public void run() { final LinearLayout ll = new LinearLayout(CaptchaActivity.this); ll.setOrientation(LinearLayout.VERTICAL); final ImageView captchaImg = new ImageView(CaptchaActivity.this); ll.addView(captchaImg); final LinearLayout.LayoutParams layoutParams = (LinearLayout.LayoutParams) captchaImg .getLayoutParams(); layoutParams.setMargins(20, 20, 20, 20); layoutParams.height = General.dpToPixels(context, 100); captchaImg.setScaleType(ImageView.ScaleType.FIT_CENTER); final EditText captchaText = new EditText(CaptchaActivity.this); ll.addView(captchaText); ((LinearLayout.LayoutParams) captchaText.getLayoutParams()).setMargins(20, 0, 20, 20); captchaText.setInputType(android.text.InputType.TYPE_CLASS_TEXT | android.text.InputType.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD | InputType.TYPE_TEXT_FLAG_CAP_CHARACTERS); captchaImg.setImageBitmap(image); final Button submitButton = new Button(CaptchaActivity.this); submitButton.setText(R.string.post_captcha_submit_button); ll.addView(submitButton); ((LinearLayout.LayoutParams) submitButton.getLayoutParams()).setMargins(20, 0, 20, 20); ((LinearLayout.LayoutParams) submitButton .getLayoutParams()).gravity = Gravity.RIGHT; ((LinearLayout.LayoutParams) submitButton .getLayoutParams()).width = LinearLayout.LayoutParams.WRAP_CONTENT; submitButton.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { final Intent result = new Intent(); result.putExtra("captchaId", captchaId); result.putExtra("captchaText", captchaText.getText().toString()); setResult(RESULT_OK, result); finish(); } }); final ScrollView sv = new ScrollView(CaptchaActivity.this); sv.addView(ll); setContentView(sv); } }); } }); } @Override protected void onCallbackException(Throwable t) { BugReportActivity.handleGlobalError(CaptchaActivity.this, t); } @Override protected void onFailure(RequestFailureType type, Throwable t, StatusLine status, String readableMessage) { final RRError error = General.getGeneralErrorForFailure(CaptchaActivity.this, type, t, status); General.showResultDialog(CaptchaActivity.this, error); finish(); } @Override protected void onFailure(APIFailureType type) { final RRError error = General.getGeneralErrorForFailure(CaptchaActivity.this, type); General.showResultDialog(CaptchaActivity.this, error); finish(); } }, selectedAccount, this); }
From source file:org.quantumbadger.redreader.activities.CaptchaActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { PrefsUtility.applyTheme(this); getSupportActionBar().setTitle(R.string.post_captcha_title); super.onCreate(savedInstanceState); final LoadingView loadingView = new LoadingView(this, R.string.download_waiting, true, true); setContentView(loadingView);// w w w. j av a2s .co m final RedditAccount selectedAccount = RedditAccountManager.getInstance(this) .getAccount(getIntent().getStringExtra("username")); final CacheManager cm = CacheManager.getInstance(this); RedditAPI.newCaptcha(cm, new APIResponseHandler.NewCaptchaResponseHandler(this) { @Override protected void onSuccess(final String captchaId) { final URI captchaUrl = Constants.Reddit.getUri("/captcha/" + captchaId); cm.makeRequest(new CacheRequest(captchaUrl, RedditAccountManager.getAnon(), null, Constants.Priority.CAPTCHA, 0, CacheRequest.DownloadType.FORCE, Constants.FileType.CAPTCHA, false, false, true, CaptchaActivity.this) { @Override protected void onCallbackException(Throwable t) { BugReportActivity.handleGlobalError(CaptchaActivity.this, t); } @Override protected void onDownloadNecessary() { } @Override protected void onDownloadStarted() { loadingView.setIndeterminate(R.string.download_downloading); } @Override protected void onFailure(RequestFailureType type, Throwable t, StatusLine status, String readableMessage) { final RRError error = General.getGeneralErrorForFailure(CaptchaActivity.this, type, t, status, url.toString()); General.showResultDialog(CaptchaActivity.this, error); finish(); } @Override protected void onProgress(long bytesRead, long totalBytes) { loadingView.setProgress(R.string.download_downloading, (float) ((double) bytesRead / (double) totalBytes)); } @Override protected void onSuccess(final CacheManager.ReadableCacheFile cacheFile, long timestamp, UUID session, boolean fromCache, String mimetype) { final Bitmap image; try { image = BitmapFactory.decodeStream(cacheFile.getInputStream()); } catch (IOException e) { BugReportActivity.handleGlobalError(CaptchaActivity.this, e); return; } new Handler(Looper.getMainLooper()).post(new Runnable() { public void run() { final LinearLayout ll = new LinearLayout(CaptchaActivity.this); ll.setOrientation(LinearLayout.VERTICAL); final ImageView captchaImg = new ImageView(CaptchaActivity.this); ll.addView(captchaImg); final LinearLayout.LayoutParams layoutParams = (LinearLayout.LayoutParams) captchaImg .getLayoutParams(); layoutParams.setMargins(20, 20, 20, 20); layoutParams.height = General.dpToPixels(context, 100); captchaImg.setScaleType(ImageView.ScaleType.FIT_CENTER); final EditText captchaText = new EditText(CaptchaActivity.this); ll.addView(captchaText); ((LinearLayout.LayoutParams) captchaText.getLayoutParams()).setMargins(20, 0, 20, 20); captchaText.setInputType(android.text.InputType.TYPE_CLASS_TEXT | android.text.InputType.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD | InputType.TYPE_TEXT_FLAG_CAP_CHARACTERS); captchaImg.setImageBitmap(image); final Button submitButton = new Button(CaptchaActivity.this); submitButton.setText(R.string.post_captcha_submit_button); ll.addView(submitButton); ((LinearLayout.LayoutParams) submitButton.getLayoutParams()).setMargins(20, 0, 20, 20); ((LinearLayout.LayoutParams) submitButton .getLayoutParams()).gravity = Gravity.RIGHT; ((LinearLayout.LayoutParams) submitButton .getLayoutParams()).width = LinearLayout.LayoutParams.WRAP_CONTENT; submitButton.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { final Intent result = new Intent(); result.putExtra("captchaId", captchaId); result.putExtra("captchaText", captchaText.getText().toString()); setResult(RESULT_OK, result); finish(); } }); final ScrollView sv = new ScrollView(CaptchaActivity.this); sv.addView(ll); setContentView(sv); } }); } }); } @Override protected void onCallbackException(Throwable t) { BugReportActivity.handleGlobalError(CaptchaActivity.this, t); } @Override protected void onFailure(RequestFailureType type, Throwable t, StatusLine status, String readableMessage) { final RRError error = General.getGeneralErrorForFailure(CaptchaActivity.this, type, t, status, null); General.showResultDialog(CaptchaActivity.this, error); finish(); } @Override protected void onFailure(APIFailureType type) { final RRError error = General.getGeneralErrorForFailure(CaptchaActivity.this, type); General.showResultDialog(CaptchaActivity.this, error); finish(); } }, selectedAccount, this); }
From source file:mobisocial.musubi.objects.PictureObj.java
/** * Pass in one of raw or fd as the source of the image. * Not thread safe, only call on the ui thread. *//*from w ww. ja va 2s . c o m*/ protected static void bindImageToView(Context context, ImageView imageView, byte[] raw, FileDescriptor fd) { // recycle old images (vs. caching in ImageCache) if (imageView.getDrawable() != null) { BitmapDrawable d = (BitmapDrawable) imageView.getDrawable(); if (d != null && d.getBitmap() != null) { d.getBitmap().recycle(); } } BitmapFactory.Options options = new BitmapFactory.Options(); options.inJustDecodeBounds = true; if (fd != null) { BitmapFactory.decodeFileDescriptor(fd, null, options); } else { BitmapFactory.decodeByteArray(raw, 0, raw.length, options); } Resources res = context.getResources(); float scaleFactor; if (res.getBoolean(R.bool.is_tablet)) { scaleFactor = 3.0f; } else { scaleFactor = 2.0f; } DisplayMetrics dm = context.getResources().getDisplayMetrics(); int pixels = dm.widthPixels; if (dm.heightPixels < pixels) { pixels = dm.heightPixels; } int width = (int) (pixels / scaleFactor); int height = (int) ((float) width / options.outWidth * options.outHeight); int max_height = (int) (AppStateObj.MAX_HEIGHT * dm.density); if (height > max_height) { width = width * max_height / height; height = max_height; } options.inJustDecodeBounds = false; options.inTempStorage = getTempData(); options.inSampleSize = 1; //TODO: lame, can just compute while (options.outWidth / (options.inSampleSize + 1) >= width && options.outHeight / (options.inSampleSize + 1) >= height) { options.inSampleSize++; } options.inPurgeable = true; options.inInputShareable = true; Bitmap bm; if (fd != null) { bm = BitmapFactory.decodeFileDescriptor(fd, null, options); } else { bm = BitmapFactory.decodeByteArray(raw, 0, raw.length, options); } imageView.getLayoutParams().width = width + 13; imageView.getLayoutParams().height = height + 14; imageView.setImageBitmap(bm); }
From source file:com.nd.pad.GreenBrowser.util.ImageDownloader.java
/** * Same as download but the image is always downloaded and the cache is not * used. Kept private at the moment as its interest is not clear. *//* w w w .j a v a 2s.co m*/ private void forceDownload(String url, ImageView imageView, int loadingDrawable_ID, int failDrawable_ID, boolean isSaveLocal, ImageDownLoaderAction action) { if (url == null) { imageView.setImageResource(failDrawable_ID); return; } if (cancelPotentialDownload(url, imageView)) { /*modeCORRECT*/ switch (mode) { case NO_ASYNC_TASK: Bitmap bitmap = downloadBitmap(url); addBitmapToCache(url, bitmap); imageView.setImageBitmap(bitmap); break; case NO_DOWNLOADED_DRAWABLE: imageView.setMinimumHeight(156); BitmapDownloaderTask task = new BitmapDownloaderTask(imageView, failDrawable_ID, isSaveLocal, action); task.execute(url); break; case CORRECT: task = new BitmapDownloaderTask(imageView, failDrawable_ID, isSaveLocal, action); DownloadedDrawable downloadedDrawable = new DownloadedDrawable(task, loadingDrawable_ID); imageView.setImageDrawable(downloadedDrawable); imageView.setMinimumHeight(156); try { task.execute(url); } catch (RejectedExecutionException localRejectedExecutionException) { } break; } } }
From source file:com.nd.pad.GreenBrowser.util.ImageDownloader.java
/** * // w ww .ja v a 2 s . c o m * dD{ * @param url * @param imageView imageview * @param loadingDrawable_ID * @param failDrawable_ID * @param isSaveLocal * @param action * MyGoPlusV3 * <pre> * * 2013-6-13 ? * </pre> */ public void download(String url, ImageView imageView, int loadingDrawable_ID, int failDrawable_ID, boolean isSaveLocal, ImageDownLoaderAction action) { Bitmap bitmap = getBitmapFromCache(url); /* */ if (bitmap == null && isSaveLocal) { bitmap = getBitmapFromLocal(url, Constants.FILE_CACHE); } /* */ if (bitmap == null) { forceDownload(url, imageView, loadingDrawable_ID, failDrawable_ID, isSaveLocal, action); } else { cancelPotentialDownload(url, imageView); imageView.setImageBitmap(bitmap); if (action != null) { action.downFinish(); } } }
From source file:com.google.android.imageloader.ImageLoader.java
/** * Binds a URL to an {@link ImageView} within an {@link android.widget.AdapterView}. * * @param adapter the adapter for the {@link android.widget.AdapterView}. * @param view the {@link ImageView}./*w w w. j a va 2s .c o m*/ * @param url the image URL. * @return a {@link BindResult}. * @throws NullPointerException if any of the arguments are {@code null}. */ public BindResult bind(BaseAdapter adapter, ImageView view, String url) { if (adapter == null) { throw new NullPointerException("Adapter is null"); } if (view == null) { throw new NullPointerException("ImageView is null"); } if (url == null) { throw new NullPointerException("URL is null"); } Bitmap bitmap = getBitmap(url); ImageError error = getError(url); if (bitmap != null) { view.setImageBitmap(bitmap); return BindResult.OK; } else { // Clear the ImageView by default. // The caller can set their own placeholder // based on the return value. view.setImageDrawable(null); if (error != null) { return BindResult.ERROR; } else { ImageRequest request = new ImageRequest(adapter, url); // For adapters, post the latest requests // at the front of the queue in case the user // has already scrolled past most of the images // that are currently in the queue. insertRequestAtFrontOfQueue(request); return BindResult.LOADING; } } }
From source file:com.google.android.imageloader.ImageLoader.java
/** * Binds a URL to an {@link ImageView} within an {@link android.widget.ExpandableListView}. * * @param adapter the adapter for the {@link android.widget.ExpandableListView}. * @param view the {@link ImageView}./* w w w . j ava 2 s . c o m*/ * @param url the image URL. * @return a {@link BindResult}. * @throws NullPointerException if any of the arguments are {@code null}. */ public BindResult bind(BaseExpandableListAdapter adapter, ImageView view, String url) { if (adapter == null) { throw new NullPointerException("Adapter is null"); } if (view == null) { throw new NullPointerException("ImageView is null"); } if (url == null) { throw new NullPointerException("URL is null"); } Bitmap bitmap = getBitmap(url); ImageError error = getError(url); if (bitmap != null) { view.setImageBitmap(bitmap); return BindResult.OK; } else { // Clear the ImageView by default. // The caller can set their own placeholder // based on the return value. view.setImageDrawable(null); if (error != null) { return BindResult.ERROR; } else { ImageRequest request = new ImageRequest(adapter, url); // For adapters, post the latest requests // at the front of the queue in case the user // has already scrolled past most of the images // that are currently in the queue. insertRequestAtFrontOfQueue(request); return BindResult.LOADING; } } }
From source file:com.hichinaschool.flashcards.anki.multimediacard.activity.MultimediaCardEditorActivity.java
private void createNewViewer(LinearLayout linearLayout, final IField field, final int index) { final MultimediaCardEditorActivity context = this; switch (field.getType()) { case TEXT:/*from ww w.j a v a 2 s .co m*/ // Create a text field and an edit button, opening editing for // the // text field TextView textView = new TextView(this); textView.setText(field.getText()); linearLayout.addView(textView, LinearLayout.LayoutParams.MATCH_PARENT); break; case IMAGE: ImageView imgView = new ImageView(this); // // BitmapFactory.Options options = new BitmapFactory.Options(); // options.inSampleSize = 2; // Bitmap bm = BitmapFactory.decodeFile(myJpgPath, options); // jpgView.setImageBitmap(bm); LinearLayout.LayoutParams p = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT); File f = new File(field.getImagePath()); Bitmap b = BitmapUtil.decodeFile(f, getMaxImageSize()); int currentapiVersion = android.os.Build.VERSION.SDK_INT; if (currentapiVersion >= android.os.Build.VERSION_CODES.ECLAIR) { b = ExifUtil.rotateFromCamera(f, b); } imgView.setImageBitmap(b); imgView.setScaleType(ImageView.ScaleType.CENTER_INSIDE); imgView.setAdjustViewBounds(true); DisplayMetrics metrics = new DisplayMetrics(); getWindowManager().getDefaultDisplay().getMetrics(metrics); int height = metrics.heightPixels; int width = metrics.widthPixels; imgView.setMaxHeight((int) Math.round(height * 0.6)); imgView.setMaxWidth((int) Math.round(width * 0.7)); linearLayout.addView(imgView, p); break; case AUDIO: AudioView audioView = AudioView.createPlayerInstance(this, R.drawable.av_play, R.drawable.av_pause, R.drawable.av_stop, field.getAudioPath()); linearLayout.addView(audioView); break; default: Log.e("multimedia editor", "Unsupported field type found"); break; } Button editButtonText = new Button(this); editButtonText.setText(gtxt(R.string.multimedia_editor_activity_edit_button)); linearLayout.addView(editButtonText, LinearLayout.LayoutParams.MATCH_PARENT); editButtonText.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Intent i = new Intent(context, EditFieldActivity.class); putExtrasAndStartEditActivity(field, index, i); } }); }
From source file:com.gokuai.yunkuandroidsdk.imageutils.ImageWorker.java
/** * Called when the processing is complete and the final drawable should be * set on the ImageView.//from w w w.j av a2s. co 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), isRoundDrawable ? new BitmapDrawable(mResources, Util.makeRoundDrawable(drawable, GKApplication.getInstance(), false)) : drawable }); // Set background to loading bitmap imageView.setBackgroundDrawable(isRoundDrawable ? new BitmapDrawable(mResources, Util.makeRoundDrawable(drawable, GKApplication.getInstance(), false)) : new BitmapDrawable(mResources, mLoadingBitmap)); imageView.setImageDrawable(td); td.startTransition(FADE_IN_TIME); } else { if (isRoundDrawable) { imageView.setImageBitmap(Util.makeRoundDrawable(drawable, GKApplication.getInstance(), false)); } else { imageView.setImageDrawable(drawable); } } }