List of usage examples for android.widget ImageView setImageDrawable
public void setImageDrawable(@Nullable Drawable drawable)
From source file:com.example.android.supportv4.graphics.RoundedBitmapDrawableActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_rounded_bitmap); // Create a bitmap and set it circular. Bitmap bitmap = BitmapFactory.decodeResource(getResources(), IMAGE_RES); mRoundedBitmapDrawable = RoundedBitmapDrawableFactory.create(getResources(), bitmap); // Get references to the inflated views. ToggleButton toggle = (ToggleButton) findViewById(R.id.toggle_round); ImageView image = (ImageView) findViewById(R.id.image); // Set up initial view state and on checked change listener. image.setImageDrawable(mRoundedBitmapDrawable); toggle.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override//w w w. j a v a2 s .co m public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { mRoundedBitmapDrawable.setCircular(isChecked); } }); }
From source file:com.scott.crash.DrawableManager.java
public void fetchDrawableOnThread(final String urlString, final ImageView imageView) { if (drawableMap.containsKey(urlString)) { imageView.setImageDrawable(drawableMap.get(urlString)); }/*from w w w. jav a2s .c o m*/ final Handler handler = new Handler() { @Override public void handleMessage(Message message) { imageView.setImageDrawable((Drawable) message.obj); } }; Thread thread = new Thread() { @Override public void run() { //TODO : set imageView to a "pending" image Drawable drawable = fetchDrawable(urlString); Message message = handler.obtainMessage(1, drawable); handler.sendMessage(message); } }; thread.start(); }
From source file:com.swavdev.tc.DrawableManager.java
public void fetchDrawableOnThread(final String urlString, final ImageView imageView) { if (drawableMap.containsKey(urlString)) { imageView.setImageDrawable(drawableMap.get(urlString)); }//from ww w . j ava 2 s.c o m final Handler handler = new Handler() { @Override public void handleMessage(Message message) { imageView.setImageDrawable((Drawable) message.obj); } }; executorService.submit(new Thread() { @Override public void run() { Drawable drawable = fetchDrawable(urlString); Message message = handler.obtainMessage(1, drawable); handler.sendMessage(message); } }); }
From source file:com.example.hotelapp.DrawableManager.java
@SuppressLint("HandlerLeak") public void fetchDrawableOnThread(final String urlString, final ImageView imageView) { if (drawableMap.containsKey(urlString)) { imageView.setImageDrawable(drawableMap.get(urlString)); }//from w ww. j a va2 s. c o m final Handler handler = new Handler() { @Override public void handleMessage(Message message) { imageView.setImageDrawable((Drawable) message.obj); } }; Thread thread = new Thread() { @Override public void run() { //TODO : set imageView to a "pending" image Drawable drawable = fetchDrawable(urlString); Message message = handler.obtainMessage(1, drawable); handler.sendMessage(message); } }; thread.start(); }
From source file:Main.java
/** * @see "http://blog.peterkuterna.net/2011/09/simple-crossfade-on-imageview.html" * with modifications by Thomas Suarez.//from w w w . j a v a 2 s.co m */ public static void setImageDrawableWithFade(final Activity context, final ImageView imageView, final String drawableName, final int durationMillis) { int resId = getDrawableId(context, drawableName); // get new drawable resource Drawable drawable; if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.LOLLIPOP) { drawable = context.getResources().getDrawable(resId, context.getTheme()); } else { drawable = context.getResources().getDrawable(resId); // this is deprecated starting in Android 5.0 Lollipop } final Drawable currentDrawable = imageView.getDrawable(); final Drawable newDrawable = drawable; Runnable r = new Runnable() { @Override public void run() { if (currentDrawable != null) { Drawable[] arrayDrawable = new Drawable[2]; arrayDrawable[0] = currentDrawable; arrayDrawable[1] = newDrawable; TransitionDrawable transitionDrawable = new TransitionDrawable(arrayDrawable); transitionDrawable.setCrossFadeEnabled(true); imageView.setImageDrawable(transitionDrawable); transitionDrawable.startTransition(durationMillis); } else { imageView.setImageDrawable(newDrawable); } } }; context.runOnUiThread(r); }
From source file:am.project.x.business.drawables.loadingdrawable.LoadingDrawableActivity.java
private void setDoubleCircleDrawable() { final ImageView loading = findViewById(R.id.ld_iv_01); final DoubleCircleDrawable drawable = new DoubleCircleDrawable(density); loading.setImageDrawable(drawable); drawable.start();/*w ww.j a v a 2 s.c o m*/ }
From source file:com.github.bcfurtado.copaapp.util.DrawableManager.java
/** * Carrega a imagem a partir de uma url em uma thread separada da thread da interface. * @param urlString indica a url da imagem * @param imageView indica a imagemView a qual imagem vai ser associada ao ser carregada. *///from ww w . jav a 2s.com public void fetchDrawableOnThread(final String urlString, final ImageView imageView) { if (drawableMap.containsKey(urlString)) { imageView.setImageDrawable(drawableMap.get(urlString)); } final Handler handler = new Handler() { @Override public void handleMessage(Message message) { imageView.setImageDrawable((Drawable) message.obj); } }; Thread thread = new Thread() { @Override public void run() { //TODO : set imageView to a "pending" image Drawable drawable = fetchDrawable(urlString); Message message = handler.obtainMessage(1, drawable); handler.sendMessage(message); } }; thread.start(); }
From source file:com.arlib.floatingsearchview.suggestions.SearchSuggestionsAdapter.java
private void resetImageView(ImageView imageView) { imageView.setImageDrawable(null); imageView.setAlpha(1.0f); }
From source file:com.oonusave.coupon.DrawableManager.java
public void fetchDrawableOnThread(final String urlString, final ImageView imageView) { if (drawableMap.containsKey(urlString)) { imageView.setImageDrawable(drawableMap.get(urlString)); return;//from w w w . j a v a 2s . c o m } if (urlString != null && "".equalsIgnoreCase(urlString)) { return; } final Handler handler = new Handler() { @Override public void handleMessage(Message message) { imageView.setImageDrawable((Drawable) message.obj); } }; Thread thread = new Thread() { @Override public void run() { //TODO : set imageView to a "pending" image Drawable drawable = fetchDrawable(urlString); drawableMap.put(urlString, drawable); Message message = handler.obtainMessage(1, drawable); handler.sendMessage(message); } }; thread.start(); }
From source file:com.keepassdroid.icons.DrawableFactory.java
public void assignDrawableTo(ImageView iv, Resources res, PwIcon icon) { Drawable draw = getIconDrawable(res, icon); iv.setImageDrawable(draw); }