List of usage examples for android.widget ImageView postDelayed
public boolean postDelayed(Runnable action, long delayMillis)
Causes the Runnable to be added to the message queue, to be run after the specified amount of time elapses.
From source file:Main.java
public static void startVDAnimation(ImageView imageView, @DrawableRes int inactiveResId, @DrawableRes int activeResId, int duration) { int drawableResId = imageView.isSelected() ? activeResId : inactiveResId; Drawable drawable = ContextCompat.getDrawable(imageView.getContext(), drawableResId); imageView.setImageDrawable(drawable); if (drawable instanceof Animatable) { Animatable animatable = (Animatable) drawable; if (animatable.isRunning()) { animatable.stop();/*from w ww . j a v a2s . co m*/ } animatable.start(); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { imageView.setSelected(!imageView.isSelected()); } else { imageView.postDelayed(() -> { imageView.setSelected(!imageView.isSelected()); int nextDrawableResId = imageView.isSelected() ? activeResId : inactiveResId; Drawable nextDrawable = ContextCompat.getDrawable(imageView.getContext(), nextDrawableResId); imageView.setImageDrawable(nextDrawable); }, duration); } } }
From source file:net.yoching.android.MainActivity.java
public void flipCoins(View view) { final List<Integer> outcomes = new ArrayList<Integer>(3); for (int i = 0; i < 3; i++) { int j = Math.random() > .5 ? 1 : 2; outcomes.add(new Integer(j)); animatedCoins[i].setHeadsOrTails(j); }// w w w . jav a2 s .c om int heads = Collections.frequency(outcomes, new Integer(1)); Bitmap lineRender = null; if (heads >= 2) { lineRender = strongLine; outcomeBuffer.append("1"); } else { lineRender = splitLine; outcomeBuffer.append("2"); } Log.d(TAG, "wrexagram outcome buffer : " + outcomeBuffer.toString()); if (!imageViewStack.isEmpty()) { List<Long> list = new ArrayList<Long>(); for (int i = 2; i < 6; i++) { list.add(new Long(i * 100)); // list contains: [2,3,4,5] } Collections.shuffle(list); handler.postDelayed(animatedCoins[0], list.get(0)); handler.postDelayed(animatedCoins[1], list.get(1)); handler.postDelayed(animatedCoins[2], list.get(2)); final ImageView wrexaLine = imageViewStack.pop(); wrexaLine.setImageBitmap(lineRender); wrexaLine.setVisibility(View.INVISIBLE); wrexaLine.postDelayed(new Runnable() { @Override public void run() { wrexaLine.setVisibility(View.VISIBLE); } }, 2300); } Intent intent = new Intent(MainActivity.this, ViewWrexagramActivity.class); TossListener tossListener = new TossListener(intent, outcomeBuffer); handler.postDelayed(tossListener, 2000); }
From source file:com.example.image.ImageWorker.java
/** * Called when the processing is complete and the final bitmap should be set on the ImageView. * * @param imageView//from w ww .j a v a 2 s. c om * @param bitmap */ private void setImageBitmap(final ImageView imageView, final Bitmap bitmap) { if (mFadeInBitmap) { // Transition drawable with a transparent drwabale and the final bitmap final TransitionDrawable td = new TransitionDrawable(new Drawable[] { mLoadingBitmap != null ? getLoadingDrawable() : new ColorDrawable(android.R.color.transparent), new BitmapDrawable(mResources, bitmap) }); // Set background to loading bitmap //imageView.setBackgroundDrawable(getLoadingDrawable()); imageView.setImageDrawable(td); td.startTransition(FADE_IN_TIME); imageView.postDelayed(new Runnable() { @Override public void run() { imageView.setImageBitmap(bitmap); } }, FADE_IN_TIME); } else { imageView.setImageBitmap(bitmap); } }