List of usage examples for android.widget ImageView setImageBitmap
@android.view.RemotableViewMethod public void setImageBitmap(Bitmap bm)
From source file:com.rightscale.app.dashboard.ShowServerMonitoring.java
public void consumeImage(Bitmap bitmap, String tag) { ImageView view = (ImageView) findViewById(R.id.show_server_monitoring_graph); if (bitmap != null) { view.setScaleType(ImageView.ScaleType.FIT_CENTER); view.setImageBitmap(bitmap); } else {//from w w w . java 2 s.c o m view.setScaleType(ImageView.ScaleType.CENTER); view.setImageDrawable( getBaseContext().getResources().getDrawable(android.R.drawable.ic_menu_close_clear_cancel)); } }
From source file:com.andrewshu.android.reddit.threads.BitmapManager.java
public void fetchBitmapOnThread(final String urlString, final ImageView imageView, final ProgressBar indeterminateProgressBar, final Activity act) { SoftReference<Bitmap> ref = mCache.get(urlString); if (ref != null && ref.get() != null) { imageView.setImageBitmap(ref.get()); return;/*w ww . ja v a 2 s. c om*/ } final Runnable progressBarShow = new Runnable() { public void run() { if (indeterminateProgressBar != null) { imageView.setVisibility(View.GONE); indeterminateProgressBar.setVisibility(View.VISIBLE); } } }; final Runnable progressBarHide = new Runnable() { public void run() { if (indeterminateProgressBar != null) { indeterminateProgressBar.setVisibility(View.GONE); imageView.setVisibility(View.VISIBLE); } } }; final Handler handler = new Handler() { @Override public void handleMessage(Message message) { if (indeterminateProgressBar != null && act != null) act.runOnUiThread(progressBarHide); imageView.setImageBitmap((Bitmap) message.obj); } }; Thread thread = new Thread() { @Override public void run() { if (indeterminateProgressBar != null && act != null) act.runOnUiThread(progressBarShow); Bitmap bitmap = fetchBitmap(urlString); Message message = handler.obtainMessage(1, bitmap); handler.sendMessage(message); } }; thread.start(); }
From source file:MainActivity.java
public void sendRequest(View view) { final ImageView imageView = (ImageView) findViewById(R.id.imageView); RequestQueue queue = Volley.newRequestQueue(this); String url = "http://www.android.com/static/img/logos-2x/android-wordmark-8EC047.png"; ImageRequest imageRequest = new ImageRequest(url, new Response.Listener<Bitmap>() { @Override// ww w . ja va 2 s. co m public void onResponse(Bitmap bitmap) { imageView.setImageBitmap(bitmap); } }, 0, 0, ImageView.ScaleType.CENTER, null, new Response.ErrorListener() { @Override public void onErrorResponse(VolleyError error) { error.printStackTrace(); } }); queue.add(imageRequest); }
From source file:com.example.georg.theupub.ProfileActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_profile); Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); setSupportActionBar(toolbar);//from w w w . j a v a 2 s . co m if (!getPoints()) { Context context = getApplicationContext(); CharSequence text = "Can't get points. Can't reach database!"; int duration = Toast.LENGTH_LONG; Toast toast = Toast.makeText(context, text, duration); toast.show(); } DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout); ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close); drawer.setDrawerListener(toggle); toggle.syncState(); NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view); navigationView.setNavigationItemSelectedListener(this); QRCodeWriter writer = new QRCodeWriter(); try { // BitMatrix matrix = writer.encode( // "Giorgos Demosthenous 953157", BarcodeFormat.QR_CODE, 400, 400); BitMatrix matrix = writer.encode(sample_user, BarcodeFormat.QR_CODE, 400, 400); Bitmap qrcode_bmp = toBitmap(matrix); ImageView iv = (ImageView) findViewById(R.id.grImage_id); iv.setImageResource(R.drawable.qr); iv.setImageBitmap(qrcode_bmp); } catch (WriterException e) { e.printStackTrace(); } // Shows the points of the user pointText = (TextView) findViewById(R.id.Points); pointText.setText(userPoints + " Points"); }
From source file:com.lge.friendsCamera.CustomListAdapter.java
public View getView(final int position, View view, ViewGroup parent) { mCurrentPosition = position; //Set current position LayoutInflater inflater = mContext.getLayoutInflater(); View rowView = view;/*from w w w. j a va 2 s . c o m*/ ViewHolder holder; if (view == null) { rowView = inflater.inflate(R.layout.customlistadapter_layout, null, true); holder = new ViewHolder(); holder.imageView = (ImageView) rowView.findViewById(R.id.icon); holder.textViewName = (TextView) rowView.findViewById(R.id.itemname); holder.textViewSize = (TextView) rowView.findViewById(R.id.itemsize); rowView.setTag(holder); } else { holder = (ViewHolder) rowView.getTag(); } //Set background color of current row setRowBackground(position, rowView, parent); final ImageView rowImageView = holder.imageView; rowImageView.setImageBitmap(mDummyBitmap); if (position < mItemInfo.size()) { //Get item information of current position HashMap<String, String> info = mItemInfo.get(position); holder.textViewName.setText(info.get(OSCParameterNameMapper.FileInfo.NAME)); String sizeString = convertBytesToMB(info.get(OSCParameterNameMapper.FileInfo.SIZE)); holder.textViewSize.setText(sizeString); } if (position < mBitmapId.size()) { //Get thumbnail bitmap data of current position HttpAsyncTask.OnCancelCallback cancelCallback = new HttpAsyncTask.OnCancelCallback() { //Return http request need to be canceled or not //if position of this call back is out of bound, then cancel the request // bound => (current position - 10, current position + 10) @Override public boolean cancelBackground(Object object) { int tmpPosition = position; // the position of requested item if (object != null) tmpPosition = (int) object; Log.d(TAG, "$$mCurrentPos = " + mCurrentPosition + " temp = " + tmpPosition); return !(((mCurrentPosition - mDummyCnt) < tmpPosition) && (tmpPosition < (mCurrentPosition + mDummyCnt))); } }; HttpAsyncTask.OnHttpListener thumbnailListener = new HttpAsyncTask.OnHttpListener() { //Set bitmap image as thumbnail of row view at the position @Override public void onResponse(OSCReturnType type, final Object response) { Log.v(TAG, "type = " + type); if (type == OSCReturnType.SUCCESS || response != null) { if (((mCurrentPosition - mDummyCnt) < position) && (position < (mCurrentPosition + mDummyCnt))) { rowImageView.setImageBitmap((Bitmap) response); } } } }; //Request thumbnail image getThumbnailImage(position, thumbnailListener, cancelCallback); } return rowView; }
From source file:edu.berkeley.boinc.adapter.NoticesListAdapter.java
@Override public View getView(int position, View convertView, ViewGroup parent) { final Notice listItem = entries.get(position); LayoutInflater vi = (LayoutInflater) activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE); View v = vi.inflate(R.layout.notices_layout_listitem, null); ImageView ivIcon = (ImageView) v.findViewById(R.id.projectIcon); Bitmap icon = getIcon(position);/*from ww w .ja v a2s . co m*/ // if available set icon, if not boinc logo if (icon == null) { ivIcon.setImageDrawable(getContext().getResources().getDrawable(R.drawable.boinc)); } else { ivIcon.setImageBitmap(icon); } TextView tvProjectName = (TextView) v.findViewById(R.id.projectName); tvProjectName.setText(listItem.project_name); TextView tvNoticeTitle = (TextView) v.findViewById(R.id.noticeTitle); tvNoticeTitle.setText(listItem.title); TextView tvNoticeContent = (TextView) v.findViewById(R.id.noticeContent); tvNoticeContent.setText(Html.fromHtml(listItem.description)); TextView tvNoticeTime = (TextView) v.findViewById(R.id.noticeTime); tvNoticeTime.setText(DateUtils.formatDate(new java.util.Date((long) listItem.create_time * 1000))); v.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { if (Logging.DEBUG) Log.d(Logging.TAG, "noticeClick: " + listItem.link); if (listItem.link != null && !listItem.link.isEmpty()) { Intent i = new Intent(Intent.ACTION_VIEW, Uri.parse(listItem.link)); activity.startActivity(i); } } }); return v; }
From source file:com.binroot.fatpita.BitmapManager2.java
public void fetchBitmapOnThread(final String urlString, final ImageView imageView, final ProgressBar indeterminateProgressBar, final Activity act, final int sample) { SoftReference<Bitmap> ref = mCache.get(urlString); if (ref != null && ref.get() != null) { imageView.setImageBitmap(ref.get()); return;/*from ww w . ja va 2 s. c o m*/ } final Runnable progressBarShow = new Runnable() { public void run() { if (indeterminateProgressBar != null) { imageView.setVisibility(View.GONE); indeterminateProgressBar.setVisibility(View.VISIBLE); } } }; final Runnable progressBarHide = new Runnable() { public void run() { if (indeterminateProgressBar != null) { indeterminateProgressBar.setVisibility(View.GONE); imageView.setVisibility(View.VISIBLE); } } }; final Handler handler = new Handler() { @Override public void handleMessage(Message message) { if (indeterminateProgressBar != null && act != null) act.runOnUiThread(progressBarHide); imageView.setImageBitmap((Bitmap) message.obj); } }; Thread thread = new Thread() { @Override public void run() { if (indeterminateProgressBar != null && act != null) act.runOnUiThread(progressBarShow); Bitmap bitmap = fetchBitmap(urlString, sample); Message message = handler.obtainMessage(1, bitmap); handler.sendMessage(message); } }; thread.start(); }
From source file:edu.stanford.mobisocial.dungbeetle.feed.objects.PictureObj.java
public void render(Context context, ViewGroup frame, Obj obj, boolean allowInteractions) { JSONObject content = obj.getJson();//from w w w .j a v a 2s. c o m byte[] raw = obj.getRaw(); if (raw == null) { Pair<JSONObject, byte[]> p = splitRaw(content); content = p.first; raw = p.second; } ImageView imageView = new ImageView(context); imageView.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT)); imageView.setImageBitmap(BitmapFactory.decodeByteArray(raw, 0, raw.length)); // App.instance().objectImages.lazyLoadImage(raw.hashCode(), raw, imageView); frame.addView(imageView); }
From source file:ca.cmput301f13t03.adventure_datetime.view.FragmentView.java
public void setUpView() { if (_fragment == null) return;// w ww.j ava 2 s . c om /** Layout items **/ _filmLayout = (LinearLayout) _rootView.findViewById(R.id.filmstrip); _filmstrip = (HorizontalScrollView) _rootView.findViewById(R.id.filmstrip_wrapper); _choices = (Button) _rootView.findViewById(R.id.choices); _content = (TextView) _rootView.findViewById(R.id.content); if (_fragment.getStoryMedia() == null) _fragment.setStoryMedia(new ArrayList<Image>()); /* Run on UI Thread for server stuff */ getActivity().runOnUiThread(new Runnable() { @Override public void run() { /** Programmatically set filmstrip height **/ if (_fragment.getStoryMedia().size() > 0) _filmstrip.getLayoutParams().height = FILM_STRIP_SIZE; else _filmstrip.getLayoutParams().height = 0; _content.setText(_fragment.getStoryText()); _filmLayout.removeAllViews(); // 1) Create new ImageView and add to the LinearLayout // 2) Set appropriate Layout Params to ImageView // 3) Give onClickListener for going to fullscreen LinearLayout.LayoutParams lp; //for (int i = 0; i < _fragment.getStoryMedia().size(); i++) { for (int i = 0; i < _fragment.getStoryMedia().size(); i++) { ImageView li = new ImageView(getActivity()); li.setScaleType(ScaleType.CENTER_INSIDE); li.setImageBitmap(_fragment.getStoryMedia().get(i).decodeBitmap()); _filmLayout.addView(li); lp = (LinearLayout.LayoutParams) li.getLayoutParams(); lp.setMargins(10, 10, 10, 10); lp.width = FILM_STRIP_SIZE; lp.height = FILM_STRIP_SIZE; lp.gravity = Gravity.CENTER_VERTICAL; li.setLayoutParams(lp); li.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { Intent intent = new Intent(getActivity(), FullScreen_Image.class); intent.putExtra(FullScreen_Image.TAG_AUTHOR, false); startActivity(intent); } }); } if (_fragment.getChoices().size() > 0) { /** Choices **/ final List<String> choices = new ArrayList<String>(); for (Choice choice : _fragment.getChoices()) choices.add(choice.getText()); choices.add("I'm feeling lucky."); _choices.setText("Actions"); _choices.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { new AlertDialog.Builder(v.getContext()).setTitle("Actions").setCancelable(true) .setItems(choices.toArray(new String[choices.size()]), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { /** You feeling lucky, punk? **/ if (which == _fragment.getChoices().size()) which = (int) (Math.random() * _fragment.getChoices().size()); Choice choice = _fragment.getChoices().get(which); Toast.makeText(FragmentView.this.getActivity(), choice.getText(), Toast.LENGTH_LONG).show(); Locator.getUserController().MakeChoice(choice); } }) .create().show(); } }); } else { /** End of story **/ Locator.getUserController().deleteBookmark(); _choices.setText("The End"); _choices.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { new AlertDialog.Builder(v.getContext()).setTitle("La Fin").setCancelable(true) .setPositiveButton("Play Again", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { Locator.getUserController().StartStory(_fragment.getStoryID()); } }) .setNegativeButton("Change Adventures", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { if (!_isEditing) getActivity().onBackPressed(); } }).create().show(); } }); } } }); }
From source file:Main.java
public static void setFBImage(final String fbid, final Context context, final ImageView v) { new AsyncTask<String, Void, Bitmap>() { @Override// w w w . ja va 2s. co m protected Bitmap doInBackground(String... strings) { File img = new File(context.getFilesDir() + "/profile.jpg"); Bitmap bmp = null; if (img.exists()) { try { bmp = BitmapFactory.decodeFile(img.getAbsolutePath()); } catch (Exception E) { E.printStackTrace(); } } else { try { URL img_url = new URL("https://graph.facebook.com/" + String.valueOf(fbid) + "/picture?type=large&redirect=true&width=400&height=400"); bmp = BitmapFactory.decodeStream(img_url.openConnection().getInputStream()); FileOutputStream fOut = new FileOutputStream(img); bmp.compress(Bitmap.CompressFormat.JPEG, 90, fOut); fOut.flush(); fOut.close(); } catch (Exception E) { E.printStackTrace(); } } return bmp; } @Override protected void onPostExecute(Bitmap img) { if (img != null) { v.setImageBitmap(img); } } }.execute(); }