List of usage examples for android.widget ImageView setImageBitmap
@android.view.RemotableViewMethod public void setImageBitmap(Bitmap bm)
From source file:com.cloudbase.cbhelperdemo.DataScreen.java
@SuppressWarnings("unchecked") @Override//from w w w. ja v a2 s.co m public void handleResponse(CBQueuedRequest req, CBHelperResponse res) { // we are downloading a file if (res.getFunction().equals("download")) { if (res.getDownloadedFile() != null) { try { // resize the downloaded image and display it in an ImageView BitmapFactory.Options options = new BitmapFactory.Options(); options.inJustDecodeBounds = true; BitmapFactory.decodeFile(res.getDownloadedFile().getAbsolutePath(), options); int imageHeight = options.outHeight; int imageWidth = options.outWidth; int reqWidth = 200; int reqHeight = 200; int inSampleSize = 1; if (imageHeight > reqHeight || imageWidth > reqWidth) { if (imageWidth > imageHeight) { inSampleSize = Math.round((float) imageHeight / (float) reqHeight); } else { inSampleSize = Math.round((float) imageWidth / (float) reqWidth); } } options.inSampleSize = inSampleSize; options.inJustDecodeBounds = false; Bitmap myBitmap = BitmapFactory.decodeFile(res.getDownloadedFile().getAbsolutePath(), options); //BitmapFactory.decodeStream(new FileInputStream(res.getDownloadedFile()), options); ImageView imageView = new ImageView(this.getActivity()); imageView.setImageBitmap(myBitmap); imageView.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { ((ViewGroup) v.getParent()).removeView(v); } }); //setting image position LayoutParams par = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT); imageView.setLayoutParams(par); this.getActivity().addContentView(imageView, par); } catch (Exception ex) { Log.e("DEMOAPP", "Error while opening downloaded file", ex); } } } else { if (res.getData() instanceof List) { // if we are not downloading and just running the search then read the array of result and // print the size. Log.d("DEMOAPP", "Is is array"); AlertDialog.Builder builder = new AlertDialog.Builder(this.getActivity()); builder.setTitle("Received response"); builder.setMessage("total items: " + ((List<Object>) res.getData()).size()); builder.setPositiveButton("OK", null); builder.show(); } else { Log.d("DEMOAPP", "Data not array: " + res.getData().getClass().toString()); } } }
From source file:com.micabyte.android.app.BaseFragment.java
@SuppressWarnings("ConstantConditions") protected ImageView setImageView(int resId, Bitmap img) { if (img == null) throw new IllegalArgumentException("setting image view " + resId + "with null bitmap"); final ImageView v = (ImageView) getView().findViewById(resId); v.setImageBitmap(img); return v;//from w ww. ja v a 2s. co m }
From source file:com.acceleratedio.pac_n_zoom.DrawSVG.java
public ArrayList<ImageView> DrawSVG(Context context, ImageView orgnlImageView, RelativeLayout rel_anm_lo) { paint.setColor(Color.WHITE);/*from w ww. j ava2s . co m*/ paint.setStyle(Paint.Style.FILL); LoadSVG.SVGData data = AnimActivity.svg_data; ArrayList<ImageView> imgViews = new ArrayList<ImageView>(); imgViews.add(orgnlImageView); if (data.symbl != null) { ArrayList<String> sprt_ordr = data.svg.ordr; int sym_mbr = 0; Bitmap bitmap; Canvas canvas; // - Loop through the sprites int sprt_nmbr = sprt_ordr.size(); data.svg.initScl = new float[sprt_nmbr]; float[] initScl = data.svg.initScl; for (int sprt_mbr = 1; sprt_mbr < sprt_nmbr; sprt_mbr += 1) { String sprt_id = sprt_ordr.get(sprt_mbr); // e.g., id="g2_0" if (Integer.parseInt(sprt_id.substring(sprt_id.indexOf('_') + 1)) > 0) { // The symbol is already drawn; replicate the view String init_sprt = sprt_id.substring(0, sprt_id.indexOf('_') + 1) + '0'; String svg_ordr = data.svg.svg_ordr; String cnt_str = svg_ordr.substring(0, svg_ordr.indexOf(init_sprt)); ImageView init_vw = imgViews.get(StringUtils.countMatches(cnt_str, ",")); Bitmap initBmp = ((BitmapDrawable) init_vw.getDrawable()).getBitmap(); bitmap = Bitmap.createBitmap(initBmp.getWidth(), initBmp.getHeight(), initBmp.getConfig()); canvas = new Canvas(bitmap); canvas.save(Canvas.MATRIX_SAVE_FLAG); xfrmInit crt_sprt = getInitSpriteAttrib(sprt_id); canvas.scale(crt_sprt.scl, crt_sprt.scl); initScl[sprt_mbr] = crt_sprt.scl; canvas.translate(0, 0); } else { // The symbol needs to be drawn; a new view is used bitmap = getCreatBmp(rel_anm_lo); canvas = new Canvas(bitmap); canvas.save(Canvas.MATRIX_SAVE_FLAG); // - Set the init values xfrmInit crt_sprt = getInitSpriteAttrib(sprt_id); canvas.scale(crt_sprt.scl, crt_sprt.scl); initScl[sprt_mbr] = crt_sprt.scl; canvas.translate(0, 0); // - Draw the bitmap LoadSVG.symbol crt_sym = data.symbl.get(sym_mbr); ArrayList<LoadSVG.path> pths = crt_sym.pths; int pth_nmbr = pths.size(); // Loop through the paths for (int pth_mbr = 0; pth_mbr < pth_nmbr; pth_mbr += 1) { LoadSVG.path crt_pth = pths.get(pth_mbr); final Path path = new Path(); final Paint paint = new Paint(); /* Debug if (pth_mbr + 1 == pth_nmbr) { String log_str = "Paths: pth_mbr = " + String.valueOf(pth_mbr) + "; color = " + crt_pth.clr; Log.d("DrawSVG", log_str); } */ paint.setColor(Color.parseColor(crt_pth.clr)); paint.setAntiAlias(true); paint.setStyle(Paint.Style.FILL_AND_STROKE); ld_pth_pnts(crt_pth.pth, path); path.close(); path.setFillType(Path.FillType.EVEN_ODD); canvas.drawPath(path, paint); } canvas.restore(); sym_mbr += 1; } ImageView iv = new ImageView(context); iv.setImageBitmap(bitmap); RelativeLayout.LayoutParams rlp = new RelativeLayout.LayoutParams( RelativeLayout.LayoutParams.MATCH_PARENT, RelativeLayout.LayoutParams.MATCH_PARENT); iv.draw(canvas); iv.setLayoutParams(rlp); iv.setBackgroundColor(Color.TRANSPARENT); imgViews.add(iv); } // sprites } // if symbol return imgViews; }
From source file:com.eyekabob.EventInfo.java
private void handleImageResponse(Bitmap img) { DisplayMetrics metrics = new DisplayMetrics(); getWindowManager().getDefaultDisplay().getMetrics(metrics); float metWidth = metrics.widthPixels; float imgWidth = img.getWidth(); float ratio = metWidth / imgWidth; // Add a little buffer room int newWidth = (int) Math.floor(img.getWidth() * ratio) - 50; int newHeight = (int) Math.floor(img.getHeight() * ratio) - 50; ImageView iv = (ImageView) findViewById(R.id.infoImageView); Bitmap rescaledImg = Bitmap.createScaledBitmap(img, newWidth, newHeight, false); iv.setImageBitmap(rescaledImg); }
From source file:com.normalexception.app.rx8club.handler.AvatarLoader.java
/** * Once we get the image, we actually want to display it * @param url The url of the image//from w ww . j av a 2 s . co m * @param imageView The view to put the image in */ 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.setImageResource(stub_id); } }
From source file:com.cihon.androidrestart_keven.activity.CarNumActivity.java
/** * @param str h5/* w ww.j av a 2 s . c o m*/ */ @Override public void imgBase64(String str, Bitmap b) { Log.e("Log", "webview--" + (mWebView == null)); Log.e("Log", "webview--" + str); String url = "javascript:" + "getWord('" + str + "')"; mWebView.loadUrl(url); ImageView iv = (ImageView) findViewById(R.id.img); iv.setImageBitmap(b); }
From source file:com.m2dl.mini_projet.mini_projet_android.fragment.PhotoDialogFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View v = inflater.inflate(R.layout.menu_photo_view, container, false); if (getArguments() != null) { mainActivity = ((MainActivity) getActivity()); myBitmap = getArguments().getParcelable(ARG_PHOTO); ImageView bitmapDialog = (ImageView) v.findViewById(R.id.imageView); bitmapDialog.setImageBitmap(myBitmap); coordLat = getArguments().getDouble(ARG_COORD_LAT); coordLong = getArguments().getDouble(ARG_COORD_LONG); imageFilePath = getArguments().getString(ARG_FILE_PATH); }//from ww w. j a v a 2 s . c o m getDialog().setTitle("Uploader votre photo"); etPseudo = (EditText) v.findViewById(R.id.editTextPseudo); etTags = (EditText) v.findViewById(R.id.editTextTags); Button buttonAnnuler = (Button) v.findViewById(R.id.buttonAnnuler); buttonAnnuler.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { getDialog().dismiss(); } }); Button buttonConfirmer = (Button) v.findViewById(R.id.buttonConfirmer); buttonConfirmer.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { Date currentDate = new Date(System.currentTimeMillis()); Boolean authorConfirmed, tagsConfirmed; if (!etPseudo.getText().toString().isEmpty()) { authorConfirmed = true; } else { authorConfirmed = false; etPseudo.setError("Ce champs est obligatoire"); } if (!etTags.getText().toString().isEmpty()) { tagsConfirmed = true; } else { tagsConfirmed = false; etTags.setError("Veuillez rentrer au moins un tag"); } if (tagsConfirmed && authorConfirmed) { final Photo myPhoto = new Photo(etPseudo.getText().toString(), coordLat, coordLong, currentDate); String[] myTags = etTags.getText().toString().split(","); for (String tag : myTags) { Tag myTag = new Tag(tag.replaceAll("\\s", "")); myPhoto.putTag(myTag); } String tag = etTags.getText().toString().replaceAll("\\s", ""); final boolean[] uploaded = { false }; final Image p = factory(myPhoto, tag, myBitmap); final Callback<Image> callback = new Callback<Image>() { @Override public void success(Image photo, Response response) { myPhoto.setUrl(photo.url()); mainActivity.putInPhotoMarkers(myPhoto); uploaded[0] = true; getDialog().dismiss(); } @Override public void failure(RetrofitError error) { System.err.println("Could not post photo"); } }; final SimpleImageTag simpleImageTag = ServiceGenerator.createService(SimpleImageTag.class); AsyncTask<InputStream, Void, String> task = new AsyncTask<InputStream, Void, String>() { @Override protected String doInBackground(InputStream... params) { String id = CloudinaryHelper.upload(params[0]); p.setId(id); simpleImageTag.postImage(p, callback); return id; } }; try { task.execute(new FileInputStream(new File(imageFilePath))); } catch (FileNotFoundException e) { e.printStackTrace(); } final ProgressDialog progDialog = ProgressDialog.show(mainActivity, "Upload de l'image en cours...", "Veuillez patienter", true); new Thread() { public void run() { try { while (!uploaded[0]) ; } catch (Exception e) { Log.e(MainActivity.TAG, e.getMessage()); } progDialog.dismiss(); } }.start(); } } }); return v; }
From source file:com.p2c.thelife.SettingsFragment.java
/** * Callback from ImageSelectSupport/*ww w .j a v a2s .c om*/ */ @Override public void notifyImageSelected(Bitmap bitmap) { m_updatedBitmap = bitmap; // set the image ImageView imageView = (ImageView) getActivity().findViewById(R.id.settings_image); imageView.setImageBitmap(m_updatedBitmap); showUpdatePhotoPrompt(false); }
From source file:com.amanmehara.programming.android.activities.ProgramActivity.java
private void setLanguageDatails() { TextView name = (TextView) findViewById(R.id.language_name); name.setText(languageName);/*from ww w .j av a 2 s. co m*/ ImageView image = (ImageView) findViewById(R.id.language_image); if (Objects.nonNull(logoBlob)) { int imageBlobLength = logoBlob.length; Bitmap logo = BitmapFactory.decodeByteArray(logoBlob, 0, imageBlobLength); image.setImageBitmap(logo); } else { image.setImageResource(R.drawable.ic_circle_logo); } }
From source file:ch.dbrgn.android.simplerepost.activities.RepostActivity.java
/*** Private helper methods ***/ private void updateWatermark(int repostStyle) { // Add watermark to image mWatermarkedBitmap = addWatermark(mFilename, repostStyle); // Show image on view if (mWatermarkedBitmap != null) { ImageView mPreviewImageView = (ImageView) findViewById(R.id.media_preview); mPreviewImageView.setImageBitmap(mWatermarkedBitmap); } else {//from w w w . jav a2 s. com // Something went wrong. Return to previous activity. ToastHelper.showGenericErrorToast(this); finish(); } }