List of usage examples for android.widget ImageView setImageBitmap
@android.view.RemotableViewMethod public void setImageBitmap(Bitmap bm)
From source file:br.com.brolam.cloudvision.ui.helpers.ImagesHelper.java
/** * Realizar a solicitao do download ou recuperar a imagem do arquivo temporrio e exibir * em um ImageView para uma imagem de background Note Vision * @param noteVisionKey informar uma chave vlida. * @param noteVision informar um Note Vision vlido. * @param imageView informar um ImageView vlido. */// www .j a v a 2 s . c o m public void loadNoteVisionBackground(String noteVisionKey, HashMap noteVision, ImageView imageView) { //Endereo da imagem no Firebase Storage. String pathNoteVisionBackground = NoteVision.getBackgroundPath(this.cloudVisionProvider.getUserId(), noteVisionKey); imageView.setImageBitmap(null); NoteVision.BackgroundOrigin backgroundOrigin = NoteVision.getBackground(noteVision); if (backgroundOrigin == NoteVision.BackgroundOrigin.LOCAL) { /** * Se o upload da imagem de background ainda no foi realizado, ser exibida * a imagem do arquivo temporrio. */ imageView.setImageURI(getImageUriFile(noteVisionKey)); //Relizar uma requisio de upload se ainda no existir uma requisio ativia. requestNoteVisionBackgroundPutFile(noteVisionKey); } else if (backgroundOrigin == NoteVision.BackgroundOrigin.REMOTE) { Glide.with(this.activity).using(new FirebaseImageLoader()) .load(this.firebaseStorage.getReference(pathNoteVisionBackground)) .diskCacheStrategy(DiskCacheStrategy.RESULT) //Quando uma imagem atualizado, uma nova assinatura deve ser criada //para o Glide tambm atualizar a imagem em cache. .signature(new StringSignature(NoteVision.getBackgroundSignature(noteVision))).into(imageView); } }
From source file:com.amaze.carbonfilemanager.ui.icons.IconHolder.java
/** * Method that returns a drawable reference of a FileSystemObject. * * @param iconView View to load the drawable into * @param fso The FileSystemObject reference * @param defaultIcon Drawable to be used in case no specific one could be found * @return Drawable The drawable reference *///from w w w. j ava 2 s. c o m public void loadDrawable(final ImageView iconView, final String fso, Drawable defaultIcon) { if (!mUseThumbs) { return; } // Is cached? final String filePath = fso; if (this.mAppIcons.containsKey(filePath)) { iconView.setImageBitmap(this.mAppIcons.get(filePath)); return; } new Thread(new Runnable() { @Override public void run() { mHandler.removeMessages(MSG_DESTROY); if (mWorkerThread == null || mWorkerHandler == null) { mWorkerThread = new HandlerThread("IconHolderLoader"); mWorkerThread.start(); mWorkerHandler = new WorkerHandler(mWorkerThread.getLooper()); } mRequests.put(iconView, fso); Message msg = mWorkerHandler.obtainMessage(MSG_LOAD, fso); msg.sendToTarget(); } }).start(); }
From source file:com.appirio.android.samples.util.ImageDownloader.java
/** * Same as {@link #download(String, ImageView)}, with the possibility to provide an additional * cookie that will be used when the image will be retrieved. * * @param url The URL of the image to download. * @param imageView The ImageView to bind the downloaded image to. * @param cookie A cookie String that will be used by the http connection. *//* w ww.ja v a 2s .c o m*/ public void download(String url, ImageView imageView, String cookie) { resetPurgeTimer(); Bitmap bitmap = getBitmapFromCache(url); if (bitmap == null) { forceDownload(url, imageView, cookie); } else { cancelPotentialDownload(url, imageView); imageView.setImageBitmap(bitmap); } }
From source file:com.nttec.everychan.http.recaptcha.Recaptcha2fallback.java
@Override public void handle(final Activity activity, final CancellableTask task, final Callback callback) { try {//w ww . j a v a 2 s .co m final HttpClient httpClient = ((HttpChanModule) MainApplication.getInstance().getChanModule(chanName)) .getHttpClient(); final String usingURL = scheme + RECAPTCHA_FALLBACK_URL + publicKey + (sToken != null && sToken.length() > 0 ? ("&stoken=" + sToken) : ""); String refererURL = baseUrl != null && baseUrl.length() > 0 ? baseUrl : usingURL; Header[] customHeaders = new Header[] { new BasicHeader(HttpHeaders.REFERER, refererURL) }; String htmlChallenge; if (lastChallenge != null && lastChallenge.getLeft().equals(usingURL)) { htmlChallenge = lastChallenge.getRight(); } else { htmlChallenge = HttpStreamer.getInstance().getStringFromUrl(usingURL, HttpRequestModel.builder().setGET().setCustomHeaders(customHeaders).build(), httpClient, null, task, false); } lastChallenge = null; Matcher challengeMatcher = Pattern.compile("name=\"c\" value=\"([\\w-]+)").matcher(htmlChallenge); if (challengeMatcher.find()) { final String challenge = challengeMatcher.group(1); HttpResponseModel responseModel = HttpStreamer.getInstance().getFromUrl( scheme + RECAPTCHA_IMAGE_URL + challenge + "&k=" + publicKey, HttpRequestModel.builder().setGET().setCustomHeaders(customHeaders).build(), httpClient, null, task); try { InputStream imageStream = responseModel.stream; final Bitmap challengeBitmap = BitmapFactory.decodeStream(imageStream); final String message; Matcher messageMatcher = Pattern.compile("imageselect-message(?:.*?)>(.*?)</div>") .matcher(htmlChallenge); if (messageMatcher.find()) message = RegexUtils.removeHtmlTags(messageMatcher.group(1)); else message = null; final Bitmap candidateBitmap; Matcher candidateMatcher = Pattern .compile("fbc-imageselect-candidates(?:.*?)src=\"data:image/(?:.*?);base64,([^\"]*)\"") .matcher(htmlChallenge); if (candidateMatcher.find()) { Bitmap bmp = null; try { byte[] imgData = Base64.decode(candidateMatcher.group(1), Base64.DEFAULT); bmp = BitmapFactory.decodeByteArray(imgData, 0, imgData.length); } catch (Exception e) { } candidateBitmap = bmp; } else candidateBitmap = null; activity.runOnUiThread(new Runnable() { final int maxX = 3; final int maxY = 3; final boolean[] isSelected = new boolean[maxX * maxY]; @SuppressLint("InlinedApi") @Override public void run() { LinearLayout rootLayout = new LinearLayout(activity); rootLayout.setOrientation(LinearLayout.VERTICAL); if (candidateBitmap != null) { ImageView candidateView = new ImageView(activity); candidateView.setImageBitmap(candidateBitmap); int picSize = (int) (activity.getResources().getDisplayMetrics().density * 50 + 0.5f); candidateView.setLayoutParams(new LinearLayout.LayoutParams(picSize, picSize)); candidateView.setScaleType(ImageView.ScaleType.FIT_XY); rootLayout.addView(candidateView); } if (message != null) { TextView textView = new TextView(activity); textView.setText(message); CompatibilityUtils.setTextAppearance(textView, android.R.style.TextAppearance); textView.setLayoutParams( new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT)); rootLayout.addView(textView); } FrameLayout frame = new FrameLayout(activity); frame.setLayoutParams( new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT)); final ImageView imageView = new ImageView(activity); imageView.setLayoutParams(new FrameLayout.LayoutParams( FrameLayout.LayoutParams.MATCH_PARENT, FrameLayout.LayoutParams.MATCH_PARENT)); imageView.setScaleType(ImageView.ScaleType.FIT_XY); imageView.setImageBitmap(challengeBitmap); frame.addView(imageView); final LinearLayout selector = new LinearLayout(activity); selector.setLayoutParams(new FrameLayout.LayoutParams( FrameLayout.LayoutParams.MATCH_PARENT, FrameLayout.LayoutParams.MATCH_PARENT)); AppearanceUtils.callWhenLoaded(imageView, new Runnable() { @Override public void run() { selector.setLayoutParams(new FrameLayout.LayoutParams(imageView.getWidth(), imageView.getHeight())); } }); selector.setOrientation(LinearLayout.VERTICAL); selector.setWeightSum(maxY); for (int y = 0; y < maxY; ++y) { LinearLayout subSelector = new LinearLayout(activity); subSelector.setLayoutParams(new LinearLayout.LayoutParams( LinearLayout.LayoutParams.MATCH_PARENT, 0, 1f)); subSelector.setOrientation(LinearLayout.HORIZONTAL); subSelector.setWeightSum(maxX); for (int x = 0; x < maxX; ++x) { FrameLayout switcher = new FrameLayout(activity); switcher.setLayoutParams(new LinearLayout.LayoutParams(0, LinearLayout.LayoutParams.MATCH_PARENT, 1f)); switcher.setTag(new int[] { x, y }); switcher.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { int[] coord = (int[]) v.getTag(); int index = coord[1] * maxX + coord[0]; isSelected[index] = !isSelected[index]; v.setBackgroundColor(isSelected[index] ? Color.argb(128, 0, 255, 0) : Color.TRANSPARENT); } }); subSelector.addView(switcher); } selector.addView(subSelector); } frame.addView(selector); rootLayout.addView(frame); Button checkButton = new Button(activity); checkButton.setLayoutParams( new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT)); checkButton.setText(android.R.string.ok); rootLayout.addView(checkButton); ScrollView dlgView = new ScrollView(activity); dlgView.addView(rootLayout); final Dialog dialog = new Dialog(activity); dialog.setTitle("Recaptcha"); dialog.setContentView(dlgView); dialog.setCanceledOnTouchOutside(false); dialog.setOnCancelListener(new DialogInterface.OnCancelListener() { @Override public void onCancel(DialogInterface dialog) { if (!task.isCancelled()) { callback.onError("Cancelled"); } } }); dialog.getWindow().setLayout(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT); dialog.show(); checkButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { dialog.dismiss(); if (task.isCancelled()) return; Async.runAsync(new Runnable() { @Override public void run() { try { List<NameValuePair> pairs = new ArrayList<NameValuePair>(); pairs.add(new BasicNameValuePair("c", challenge)); for (int i = 0; i < isSelected.length; ++i) if (isSelected[i]) pairs.add(new BasicNameValuePair("response", Integer.toString(i))); HttpRequestModel request = HttpRequestModel.builder() .setPOST(new UrlEncodedFormEntity(pairs, "UTF-8")) .setCustomHeaders(new Header[] { new BasicHeader(HttpHeaders.REFERER, usingURL) }) .build(); String response = HttpStreamer.getInstance().getStringFromUrl( usingURL, request, httpClient, null, task, false); String hash = ""; Matcher matcher = Pattern.compile( "fbc-verification-token(?:.*?)<textarea[^>]*>([^<]*)<", Pattern.DOTALL).matcher(response); if (matcher.find()) hash = matcher.group(1); if (hash.length() > 0) { Recaptcha2solved.push(publicKey, hash); activity.runOnUiThread(new Runnable() { @Override public void run() { callback.onSuccess(); } }); } else { lastChallenge = Pair.of(usingURL, response); throw new RecaptchaException( "incorrect answer (hash is empty)"); } } catch (final Exception e) { Logger.e(TAG, e); if (task.isCancelled()) return; handle(activity, task, callback); } } }); } }); } }); } finally { responseModel.release(); } } else throw new Exception("can't parse recaptcha challenge answer"); } catch (final Exception e) { Logger.e(TAG, e); if (!task.isCancelled()) { activity.runOnUiThread(new Runnable() { @Override public void run() { callback.onError(e.getMessage() != null ? e.getMessage() : e.toString()); } }); } } }
From source file:com.momo.util.ImageDownloader.java
/** * Same as {@link #download(String, ImageView)}, with the possibility to provide an additional * cookie that will be used when the image will be retrieved. * * @param url The URL of the image to download. * @param imageView The ImageView to bind the downloaded image to. * @param cookie A cookie String that will be used by the http connection. *//* w w w. j a va 2 s .c om*/ public void download(String url, ImageView imageView, String cookie) { //resetPurgeTimer(); Bitmap bitmap = getBitmapFromCache(url); if (bitmap == null) { forceDownload(url, imageView, cookie); } else { cancelPotentialDownload(url, imageView); imageView.setImageBitmap(bitmap); } }
From source file:ca.ualberta.app.activity.CreateQuestionActivity.java
public void viewQuestionImage(View view) { LayoutInflater inflater = LayoutInflater.from(view.getContext()); View imgEntryView = inflater.inflate(R.layout.dialog_photo, null); final AlertDialog dialog = new AlertDialog.Builder(view.getContext()).create(); ImageView img = (ImageView) imgEntryView.findViewById(R.id.large_image); img.setImageBitmap(image); dialog.setView(imgEntryView);// w w w. j ava2 s .c o m dialog.show(); imgEntryView.setOnClickListener(new OnClickListener() { public void onClick(View paramView) { dialog.cancel(); } }); }
From source file:com.example.foodstagram.FacebookImageLoader.java
public void load(String filename, ImageView imageView, BaseListItem listItem) { Bitmap bitmap = getBitmapFromCache(filename); if (bitmap == null) { forceLoad(filename, imageView);// w ww .j ava2s. c o m } else { imageView.setImageBitmap(bitmap); } // custom added code //listItem.notifyDataChanged(); }
From source file:com.micabytes.app.BaseFragment.java
@NonNull protected ImageView setImageView(int resId, Bitmap img) throws UIObjectNotFoundException { View root = getView();//from ww w .jav a2 s . c o m if (root == null) throw new UIObjectNotFoundException(COULD_NOT_FIND_THE_ROOT_VIEW); if (img == null) throw new IllegalArgumentException("setting image view " + resId + " with no or null bitmap"); ImageView v = (ImageView) root.findViewById(resId); if (v == null) throw new UIObjectNotFoundException(COULD_NOT_FIND_RES_ID + resId + IN_FIND_VIEW_BY_ID); v.setImageBitmap(img); return v; }
From source file:com.cloverstudio.spika.utils.BitmapManager.java
public void loadBitmap(final String url, final ImageView imageView, ProgressBar pbLoading) { imageViews.put(imageView, url);//from w w w.j a v a 2 s . co m Bitmap bitmap = getBitmapFromCache(url); // check in UI thread, so no concurrency issues if (bitmap != null) { if (smallImg) { imageView.setScaleType(ImageView.ScaleType.CENTER); } else { imageView.setScaleType(ImageView.ScaleType.CENTER_INSIDE); } imageView.setImageBitmap(bitmap); if (pbLoading != null) pbLoading.setVisibility(View.GONE); } else { imageView.setImageBitmap(null); imageView.setBackgroundResource(R.color.loading_background); queueJob(url, imageView, pbLoading); } }
From source file:com.cicada.yuanxiaobao.common.BaseAdapterHelper.java
/** * Add an action to set the image of an image view. Can be called multiple * times.//from w w w . j ava 2 s. c o m */ public BaseAdapterHelper setImageBitmap(int viewId, Bitmap bitmap) { ImageView view = retrieveView(viewId); view.setImageBitmap(bitmap); return this; }