コード例 #1
0
  public void testStartTransition() {
    MockCallBack cb = new MockCallBack();
    mTransitionDrawable.setCallback(cb);

    // start when there is no transition
    cb.reset();
    mTransitionDrawable.startTransition(2000);
    assertTrue(cb.hasCalledInvalidateDrawable());
    assertTransition(COLOR0, COLOR1, 2000);

    // start when there is a transition in progress
    makeTransitionInProgress(2000, 1000);
    cb.reset();
    mTransitionDrawable.startTransition(2000);
    assertTrue(cb.hasCalledInvalidateDrawable());
    assertTransition(COLOR0, COLOR1, 2000);

    // start when there is a reverse transition in progress
    makeReverseTransitionInProgress(2000, 1000);
    cb.reset();
    mTransitionDrawable.startTransition(2000);
    assertTrue(cb.hasCalledInvalidateDrawable());
    assertTransition(COLOR0, COLOR1, 2000);

    // should not accept negative duration
    mTransitionDrawable.startTransition(-1);
  }
コード例 #2
0
ファイル: Transicion.java プロジェクト: cosmin14/PMM
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_transicion);

    ImageView imagen1 = (ImageView) findViewById(R.id.img1);

    TransitionDrawable mi_transicion =
        (TransitionDrawable) getResources().getDrawable(R.drawable.transicion);

    imagen1.setImageDrawable(mi_transicion);
    mi_transicion.startTransition(1000);

    btn = (Button) findViewById(R.id.btnAnimacion);
    btn.setOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View v) {

            /*Intent miIntent= new Intent(Transicion.this, Animacion.class);
            Bundle miBundle=new Bundle();
            miIntent.putExtras(miBundle);
            startActivity(miIntent);*/
            Intent miIntent = new Intent(Transicion.this, Animacion.class);
            Bundle miBundle = new Bundle();
            miIntent.putExtras(miBundle);
            startActivityForResult(miIntent, COD_RESPUESTA);
          }
        });
  }
コード例 #3
0
  public void setBitmap(Bitmap bitmap) {
    // Make sure uri and original are consistently both null or both
    // non-null.
    if (bitmap == null) {
      mThumb = null;
      mThumbs = null;
      setImageDrawable(null);
      setVisibility(GONE);
      return;
    }

    LayoutParams param = getLayoutParams();
    final int miniThumbWidth = param.width - getPaddingLeft() - getPaddingRight();
    final int miniThumbHeight = param.height - getPaddingTop() - getPaddingBottom();
    mThumb = ThumbnailUtils.extractThumbnail(bitmap, miniThumbWidth, miniThumbHeight);
    if (mThumbs == null || !mEnableAnimation) {
      mThumbs = new Drawable[2];
      mThumbs[1] = new BitmapDrawable(getContext().getResources(), mThumb);
      setImageDrawable(mThumbs[1]);
    } else {
      mThumbs[0] = mThumbs[1];
      mThumbs[1] = new BitmapDrawable(getContext().getResources(), mThumb);
      mThumbTransition = new TransitionDrawable(mThumbs);
      setImageDrawable(mThumbTransition);
      mThumbTransition.startTransition(500);
    }
    setVisibility(VISIBLE);
  }
コード例 #4
0
  /**
   * Called when the processing is complete and the final bitmap should be set on the ImageView.
   *
   * @param imageView
   * @param bitmap
   */
  private void setImageBitmap(ImageView imageView, Bitmap bitmap) {
    callback.invoke("success", 200);
    if (mFadeInBitmap) {
      // Transition drawable with a transparent drwabale and the final
      // bitmap
      final TransitionDrawable td =
          new TransitionDrawable(
              new Drawable[] {
                new ColorDrawable(android.R.color.transparent),
                new BitmapDrawable(mContext.getResources(), bitmap)
              });
      // Set background to loading bitmap
      // imageView.setBackgroundDrawable(new BitmapDrawable(mContext
      // .getResources(), mLoadingBitmap));

      imageView.setImageDrawable(td);
      // if (bitmap.getHeight() > imageView.getHeight()) {
      // imageView.setLayoutParams(new LinearLayout.LayoutParams(bitmap
      // .getWidth(), bitmap.getHeight()));
      // } else {
      // imageView.setLayoutParams(new LinearLayout.LayoutParams(bitmap
      // .getWidth(), imageView.getHeight()));
      //
      // }
      td.startTransition(FADE_IN_TIME);
    } else {
      // if (bitmap.getHeight() > imageView.getHeight()) {
      // imageView.setLayoutParams(new
      // RelativeLayout.LayoutParams(imageView
      // .getWidth(), WallPicActivity.itemheight));
      // }
      imageView.setImageBitmap(bitmap);
    }
  }
コード例 #5
0
ファイル: ImageLoader.java プロジェクト: matmaden/BankRate
    public void run() {
      if (imageViewReused(photoToLoad)) return;
      if (bitmap != null) {
        if (FADE_IN_BITMAP) {
          final TransitionDrawable td =
              new TransitionDrawable(
                  new Drawable[] {
                    new ColorDrawable(android.R.color.transparent),
                    new BitmapDrawable(mResources, bitmap)
                  });
          photoToLoad.imageView.setImageDrawable(td);
          td.startTransition(FADE_IN_TIME);
        } else {
          photoToLoad.imageView.setImageBitmap(bitmap);
        } // end if
      } else {
        try {
          photoToLoad.imageView.setImageResource(R.drawable.icon_book_big);
        } catch (Exception e) {
          e.printStackTrace();
        }

        //                photoToLoad.imageView.setImageResource(R.drawable.no_image);
      } // end if
    }
コード例 #6
0
 /**
  * 改变ActionBar color
  *
  * @param newColor 颜色值
  */
 private void setActionBarcolor(int newColor) {
   // 改变ActionBar颜色如果ActionBar是可用的
   if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
     Drawable colorDrawable = new ColorDrawable(newColor);
     Drawable bottomDrawable = getResources().getDrawable(R.drawable.abc_ab_share_pack_mtrl_alpha);
     LayerDrawable ld = new LayerDrawable(new Drawable[] {colorDrawable, bottomDrawable});
     if (oldBackground == null) {
       if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN_MR1) {
         ld.setCallback(drawableCallback);
       } else {
         getActionBar().setBackgroundDrawable(ld);
       }
     } else {
       TransitionDrawable td = new TransitionDrawable(new Drawable[] {oldBackground, ld});
       // 解决了破碎ActionBarContainer可拉的处理
       // pre-API 17 builds
       // https://github.com/android/platform_frameworks_base/commit/a7cc06d82e45918c37429a59b14545c6a57db4e4
       if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN_MR1) {
         td.setCallback(drawableCallback);
       } else {
         getActionBar().setBackgroundDrawable(td);
       }
       td.startTransition(200);
     }
   }
 }
コード例 #7
0
 public void animateCircularClip(int x, int y, boolean in, AnimatorListener listener) {
   if (mAnimator != null) {
     mAnimator.cancel();
   }
   final int w = mDetail.getWidth() - x;
   final int h = mDetail.getHeight() - y;
   int innerR = 0;
   if (x < 0 || w < 0 || y < 0 || h < 0) {
     innerR = Math.abs(x);
     innerR = Math.min(innerR, Math.abs(y));
     innerR = Math.min(innerR, Math.abs(w));
     innerR = Math.min(innerR, Math.abs(h));
   }
   int r = (int) Math.ceil(Math.sqrt(x * x + y * y));
   r = (int) Math.max(r, Math.ceil(Math.sqrt(w * w + y * y)));
   r = (int) Math.max(r, Math.ceil(Math.sqrt(w * w + h * h)));
   r = (int) Math.max(r, Math.ceil(Math.sqrt(x * x + h * h)));
   if (in) {
     mAnimator = ViewAnimationUtils.createCircularReveal(mDetail, x, y, innerR, r);
   } else {
     mAnimator = ViewAnimationUtils.createCircularReveal(mDetail, x, y, r, innerR);
   }
   mAnimator.setDuration((long) (mAnimator.getDuration() * 1.5));
   if (listener != null) {
     mAnimator.addListener(listener);
   }
   if (in) {
     mBackground.startTransition((int) (mAnimator.getDuration() * 0.6));
     mAnimator.addListener(mVisibleOnStart);
   } else {
     mDetail.postDelayed(mReverseBackground, (long) (mAnimator.getDuration() * 0.65));
     mAnimator.addListener(mGoneOnEnd);
   }
   mAnimator.start();
 }
コード例 #8
0
 public void toggleLightControl(boolean on) {
   if (on) {
     // Update UI
     switch (mCurrentMode) {
       case R.id.mode_lightbulb:
       case R.id.mode_viewfinder:
         mDrawable.startTransition(200);
         break;
       case R.id.mode_lightswitch:
         mLightswitch.setChecked(true);
         break;
     }
   } else {
     // Update UI
     switch (mCurrentMode) {
       case R.id.mode_lightbulb:
       case R.id.mode_viewfinder:
         mDrawable.reverseTransition(300);
         break;
       case R.id.mode_lightswitch:
         mLightswitch.setChecked(false);
         break;
     }
   }
 }
コード例 #9
0
ファイル: PlayerView.java プロジェクト: lyase/KeepScore
  private void fadeOutBadge(final Runnable onAnimationComplete) {
    synchronized (lock) {
      if (!animationRunning // animation is already running, so shouldn't
          // start a new one
          && lastIncremented.get() != 0 // counter was reset, in which
          // case it would be
          // unintuitive for the badge
          // to fade
          && badgeTextView.getVisibility() == View.VISIBLE) {
        // animation isn't already showing, and the badge is visible
        animationRunning = true;

        badgeLinearLayout.setVisibility(View.VISIBLE);
        // show an animation for the badge with the textview and the
        // background linearlayout fading out
        Animation fadeOutAnimation = AnimationUtils.loadAnimation(context, android.R.anim.fade_out);
        fadeOutAnimation.setDuration(ANIMATION_TIME);
        fadeOutAnimation.setAnimationListener(
            new AnimationListener() {

              @Override
              public void onAnimationStart(Animation animation) {}

              @Override
              public void onAnimationRepeat(Animation animation) {}

              @Override
              public void onAnimationEnd(Animation animation) {
                synchronized (lock) {
                  badgeTextView.setVisibility(View.INVISIBLE);

                  // necessary to update again to set the history text
                  // view correctly
                  onAnimationComplete.run();
                  animationRunning = false;
                }
              }
            });
        badgeTextView.setAnimation(fadeOutAnimation);
        fadeOutAnimation.start();
        TransitionDrawable transitionDrawable =
            (TransitionDrawable) badgeLinearLayout.getBackground();
        transitionDrawable.setCrossFadeEnabled(true);
        transitionDrawable.startTransition(ANIMATION_TIME);
      } else {
        // just don't show it - the animation might already be showing,
        // or maybe the badge is
        // already invisible
        badgeLinearLayout.setVisibility(View.INVISIBLE);
        badgeTextView.setVisibility(View.INVISIBLE);

        // this ensures that the history text view gets updated
        // properly, even if the user
        // exits the activity while the animation is in progress (e.g.
        // by going to the Settings)
        onAnimationComplete.run();
      }
    }
  }
コード例 #10
0
ファイル: TimeTrail.java プロジェクト: Swas99/ThreeCards
  private void TimerOnFinish() {
    // Sync threads !!
    CurrentGame.AcquireLOCK();

    isAnimating = true;
    SecondsLeft_TimeTrial = 0;
    CurrentGame.SetGameInfoText();

    CurrentGame.Btn_Power.setEnabled(false);
    SetEnableControls(false, CurrentGame.GameBoard);

    ImageView[] availableCards = new ImageView[CurrentGame.RowSize * CurrentGame.ColumnSize];
    int length = GetAvailableCards(availableCards);
    if (length == 1) {
      TransitionDrawable cross_fade =
          CreateTransitionDrawable(
              R.drawable.lock, R.drawable.card_destroyed, CurrentGame.mContext);
      ImageView card = availableCards[0];
      card.getParent().requestChildFocus(card, card);
      card.setOnClickListener(null);
      card.setImageDrawable(cross_fade);
      cross_fade.startTransition(800);
      new CountDownTimer(800, 800) {
        @Override
        public void onTick(long milliSecondsToFinish) {}

        @Override
        public void onFinish() {
          // Sync threads !!
          CurrentGame.AcquireLOCK();

          CurrentGame.GameTimer.cancel();
          CurrentGame.postGameLogic();
          SetEnableControls(true, CurrentGame.GameBoard);
          CurrentGame.Btn_Power.setEnabled(true);

          // Sync threads !!
          CurrentGame.ReleaseLOCK();
          isAnimating = false;
        }
      }.start();

    } else if (length == 2) {
      ShuffleCards(availableCards, length);
    } else if (length > 2) {
      if (CurrentGame.EffectiveClickCount % 2 == 0
          && Math.random() <= .75) // Replace card 75% time for first card
      {
        ImageView[] selected_cards = SelectCardsRandomly(availableCards, length, POW_REPLACE);
        ReplaceCards(selected_cards, selected_cards.length);
      } else {
        ImageView[] selected_cards = SelectCardsRandomly(availableCards, length, POW_SHUFFLE);
        ShuffleCards(selected_cards, selected_cards.length);
      }
    }

    // Sync threads !!
    CurrentGame.ReleaseLOCK();
  }
コード例 #11
0
 private void makeReverseTransitionInProgress(int duration, int delay) {
   mTransitionDrawable.resetTransition();
   mTransitionDrawable.startTransition(2000);
   assertTransition(COLOR0, COLOR1, 2000);
   mTransitionDrawable.reverseTransition(duration);
   assertTransitionStart(COLOR1);
   assertTransitionInProgress(COLOR1, COLOR0, delay);
 }
コード例 #12
0
ファイル: ChatWindow.java プロジェクト: nickvon/yaxim
 void populateFrom(
     String date, boolean from_me, String from, String message, int delivery_status) {
   //			Log.i(TAG, "populateFrom(" + from_me + ", " + from + ", " + message + ")");
   getDateView().setText(date);
   TypedValue tv = new TypedValue();
   if (from_me) {
     getTheme().resolveAttribute(R.attr.ChatMsgHeaderMeColor, tv, true);
     getDateView().setTextColor(tv.data);
     getFromView().setText(getString(R.string.chat_from_me));
     getFromView().setTextColor(tv.data);
   } else {
     getTheme().resolveAttribute(R.attr.ChatMsgHeaderYouColor, tv, true);
     getDateView().setTextColor(tv.data);
     getFromView().setText(from + ":");
     getFromView().setTextColor(tv.data);
   }
   switch (delivery_status) {
     case ChatConstants.DS_NEW:
       ColorDrawable layers[] = new ColorDrawable[2];
       getTheme().resolveAttribute(R.attr.ChatNewMessageColor, tv, true);
       layers[0] = new ColorDrawable(tv.data);
       if (from_me) {
         // message stored for later transmission
         getTheme().resolveAttribute(R.attr.ChatStoredMessageColor, tv, true);
         layers[1] = new ColorDrawable(tv.data);
       } else {
         layers[1] = new ColorDrawable(0x00000000);
       }
       TransitionDrawable backgroundColorAnimation = new TransitionDrawable(layers);
       int l = mRowView.getPaddingLeft();
       int t = mRowView.getPaddingTop();
       int r = mRowView.getPaddingRight();
       int b = mRowView.getPaddingBottom();
       mRowView.setBackgroundDrawable(backgroundColorAnimation);
       mRowView.setPadding(l, t, r, b);
       backgroundColorAnimation.setCrossFadeEnabled(true);
       backgroundColorAnimation.startTransition(DELAY_NEWMSG);
       getIconView().setImageResource(R.drawable.ic_chat_msg_status_queued);
       break;
     case ChatConstants.DS_SENT_OR_READ:
       getIconView().setImageResource(R.drawable.ic_chat_msg_status_unread);
       mRowView.setBackgroundColor(0x00000000); // default is transparent
       break;
     case ChatConstants.DS_ACKED:
       getIconView().setImageResource(R.drawable.ic_chat_msg_status_ok);
       mRowView.setBackgroundColor(0x00000000); // default is transparent
       break;
     case ChatConstants.DS_FAILED:
       getIconView().setImageResource(R.drawable.ic_chat_msg_status_failed);
       mRowView.setBackgroundColor(0x30ff0000); // default is transparent
       break;
   }
   getMessageView().setText(message);
   getMessageView().setTextSize(TypedValue.COMPLEX_UNIT_SP, chatWindow.mChatFontSize);
 }
コード例 #13
0
ファイル: CardFragment.java プロジェクト: yakot93/DostavkaMIX
  public void selectOnButton(Button button) {
    TransitionDrawable drawable = (TransitionDrawable) button.getBackground();
    drawable.startTransition(100);

    ObjectAnimator colorAnim = ObjectAnimator.ofInt(button, "textColor", Color.WHITE, Color.BLACK);
    colorAnim.setDuration(100);
    colorAnim.setEvaluator(new ArgbEvaluator());
    colorAnim.start();

    selectDishCount = button;
  }
コード例 #14
0
ファイル: MainActivity.java プロジェクト: orgimeno/pmm
 /** Called when the activity is first created. */
 @Override
 public void onCreate(Bundle savedInstanceState) {
   super.onCreate(savedInstanceState);
   ImageView imagen = new ImageView(this);
   // ImageView imagen = (ImageView) findViewById(R.id.transicionId);
   setContentView(imagen);
   TransitionDrawable mi_transicion =
       (TransitionDrawable) getResources().getDrawable(R.drawable.transicion);
   imagen.setImageDrawable(mi_transicion);
   mi_transicion.startTransition(7000);
 }
コード例 #15
0
 /**
  * Called when the processing is complete and the final drawable should be set on the ImageView.
  *
  * @param imageView
  * @param drawable
  */
 private void setImageDrawable(ImageView imageView, Drawable drawable) {
   if (mFadeInBitmap) {
     final TransitionDrawable td =
         new TransitionDrawable(
             new Drawable[] {new ColorDrawable(android.R.color.transparent), drawable});
     // imageView.setBackgroundDrawable(new BitmapDrawable(mResources, mLoadingBitmap));
     imageView.setImageDrawable(td);
     td.startTransition(FADE_IN_TIME);
   } else {
     imageView.setImageDrawable(drawable);
   }
 }
コード例 #16
0
ファイル: ImageLoader.java プロジェクト: Nairou/Subsonic
  private void setImage(View view, Drawable drawable, boolean crossfade) {
    if (view instanceof TextView) {
      // Cross-fading is not implemented for TextView since it's not in use.  It would be easy to
      // add it, though.
      TextView textView = (TextView) view;
      textView.setCompoundDrawablesWithIntrinsicBounds(drawable, null, null, null);
    } else if (view instanceof ImageView) {
      ImageView imageView = (ImageView) view;
      if (crossfade) {
        Drawable existingDrawable = imageView.getDrawable();
        if (existingDrawable == null) {
          Bitmap emptyImage;
          if (drawable.getIntrinsicWidth() > 0 && drawable.getIntrinsicHeight() > 0) {
            emptyImage =
                Bitmap.createBitmap(
                    drawable.getIntrinsicWidth(),
                    drawable.getIntrinsicHeight(),
                    Bitmap.Config.ARGB_8888);
          } else {
            emptyImage =
                Bitmap.createBitmap(imageSizeDefault, imageSizeDefault, Bitmap.Config.ARGB_8888);
          }
          existingDrawable = new BitmapDrawable(context.getResources(), emptyImage);
        } else {
          // Try to get rid of old transitions
          try {
            TransitionDrawable tmp = (TransitionDrawable) existingDrawable;
            int layers = tmp.getNumberOfLayers();
            existingDrawable = tmp.getDrawable(layers - 1);
          } catch (Exception e) {
            // Do nothing, just means that the drawable is a flat image
          }
        }
        if (!(((BitmapDrawable) existingDrawable)
            .getBitmap()
            .isRecycled())) { // We will flow through to the non-transition if the old image is
                              // recycled... Yay 4.3
          Drawable[] layers = new Drawable[] {existingDrawable, drawable};

          TransitionDrawable transitionDrawable = new TransitionDrawable(layers);
          imageView.setImageDrawable(transitionDrawable);
          transitionDrawable.startTransition(250);
          return;
        }
      }
      imageView.setImageDrawable(drawable);
      return;
    }
  }
コード例 #17
0
  @Override
  public void onStart() {
    super.onStart();

    if (hasServerChanged) {
      updateServerState();
    }

    if (isLoggedIn()) logo.startTransition(0);
    else logo.resetTransition();

    tabManager.showTab();

    running = true;
  }
コード例 #18
0
    private TransitionDrawable createIconTransition(Drawable d, ImageView iView) {
      Resources res = getContext().getResources();

      TransitionDrawable out =
          new TransitionDrawable(
              new Drawable[] {
                this.getContext().getResources().getDrawable(R.drawable.event_blank_image),
                d.getCurrent()
              });
      out.setCrossFadeEnabled(true);
      iView.setImageDrawable(out);
      out.startTransition(500);

      return out;
    }
コード例 #19
0
  @Override
  public void onNewCurrentServer(Server server) {
    this.server = server;

    if (isLoggedIn()) {
      logo.startTransition(500);
    } else {
      logo.reverseTransition(500);
    }

    if (running) {
      tabManager.setServer(server);
    } else {
      this.hasServerChanged = true;
    }
  }
コード例 #20
0
  @Override
  public void onResume() {

    // to fade the settings button
    ImageButton settingsButton = (ImageButton) getActivity().findViewById(R.id.button_settings);

    switch (mCurrentMode) {
      case R.id.mode_lightswitch:
        mLightswitch = (LightSwitch) getActivity().findViewById(R.id.button_lightswitch);
        mLightswitch.setChecked(false);
        if (mOn) mLightswitch.setChecked(true);
        mLightswitch.setOnCheckedChangeListener(
            new OnCheckedChangeListener() {
              @Override
              public void onCheckedChanged(CompoundButton button, boolean isChecked) {
                mListener.onLightControlClick(isChecked);
              }
            });
        settingsButton.setAlpha(255);
        break;
      case R.id.mode_blackout:
        Button image = (Button) getActivity().findViewById(R.id.button_black);
        Animation fadeOut = AnimationUtils.loadAnimation(getActivity(), R.anim.fade_out);
        image.startAnimation(fadeOut);
        settingsButton.setAlpha(90);
        break;
      case R.id.mode_viewfinder:
      case R.id.mode_lightbulb:
        mBulb = (ImageButton) getActivity().findViewById(R.id.button_bulb);
        mDrawable = (TransitionDrawable) mBulb.getDrawable();
        mDrawable.setCrossFadeEnabled(true);
        if (mOn) mDrawable.startTransition(0);
        settingsButton.setAlpha(255);

        break;
    }

    PreviewSurface surface = (PreviewSurface) getActivity().findViewById(R.id.surface);
    if (mCurrentMode == R.id.mode_viewfinder) {
      surface.setLayoutParams(
          new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
    } else {
      surface.setLayoutParams(new LayoutParams(1, 1));
    }

    super.onResume();
  }
コード例 #21
0
  /**
   * Sets a {@link Bitmap} to an {@link ImageView} using a fade-in animation. If there is a {@link
   * Drawable} already set on the ImageView then use that as the image to fade from. Otherwise fade
   * in from a transparent Drawable.
   */
  @TargetApi(Build.VERSION_CODES.HONEYCOMB_MR1)
  private static void setImageBitmap(
      final ImageView imageView, final Bitmap bitmap, Resources resources, boolean fadeIn) {

    // If we're fading in and on HC MR1+
    if (fadeIn && Utils.hasHoneycombMR1()) {
      // Use ViewPropertyAnimator to run a simple fade in + fade out animation to update the
      // ImageView
      imageView
          .animate()
          .scaleY(0.95f)
          .scaleX(0.95f)
          .alpha(0f)
          .setDuration(imageView.getDrawable() == null ? 0 : HALF_FADE_IN_TIME)
          .setListener(
              new AnimatorListenerAdapter() {
                @Override
                public void onAnimationEnd(Animator animation) {
                  imageView.setImageBitmap(bitmap);
                  imageView
                      .animate()
                      .alpha(1f)
                      .scaleY(1f)
                      .scaleX(1f)
                      .setDuration(HALF_FADE_IN_TIME)
                      .setListener(null);
                }
              });
    } else if (fadeIn) {
      // Otherwise use a TransitionDrawable to fade in
      Drawable initialDrawable;
      if (imageView.getDrawable() != null) {
        initialDrawable = imageView.getDrawable();
      } else {
        initialDrawable = transparentDrawable;
      }
      BitmapDrawable bitmapDrawable = new BitmapDrawable(resources, bitmap);
      // Use TransitionDrawable to fade in
      final TransitionDrawable td =
          new TransitionDrawable(new Drawable[] {initialDrawable, bitmapDrawable});
      imageView.setImageDrawable(td);
      td.startTransition(Utils.ANIMATION_FADE_IN_TIME);
    } else {
      // No fade in, just set bitmap directly
      imageView.setImageBitmap(bitmap);
    }
  }
コード例 #22
0
ファイル: ImageWorker.java プロジェクト: 491138002/bfgame
  /**
   * Called when the processing is complete and the final drawable should be set on the ImageView.
   *
   * @param imageView
   * @param drawable
   */
  private void setImageDrawable(ImageView imageView, Drawable drawable) {
    if (mFadeInBitmap) {
      // Transition drawable with a transparent drawable and the final drawable
      final TransitionDrawable td =
          new TransitionDrawable(
              new Drawable[] {new ColorDrawable(android.R.color.transparent), drawable});
      // Set background to loading bitmap
      //            imageView.setBackgroundDrawable(
      //                    new BitmapDrawable(mResources, mLoadingBitmap));
      imageView.setBackgroundDrawable(mResources.getDrawable(defaultRsId));

      imageView.setImageDrawable(td);
      td.startTransition(FADE_IN_TIME);
    } else {
      imageView.setImageDrawable(drawable);
    }
  }
コード例 #23
0
 /**
  * Start a transition to the new image
  *
  * @param drawable the drawable to set
  */
 public void setFadingImageDrawable(Drawable drawable) {
   Drawable currentDrawable = getDrawable();
   if ((currentDrawable != null) && (currentDrawable instanceof TransitionDrawable)) {
     currentDrawable = ((TransitionDrawable) currentDrawable).getDrawable(1);
   }
   if (currentDrawable != null) {
     Drawable[] arrayDrawable = new Drawable[2];
     arrayDrawable[0] = currentDrawable;
     arrayDrawable[1] = drawable;
     TransitionDrawable transitionDrawable = new TransitionDrawable(arrayDrawable);
     transitionDrawable.setCrossFadeEnabled(true);
     setImageDrawable(transitionDrawable);
     transitionDrawable.startTransition(transitionDurationMillis);
   } else {
     setImageDrawable(drawable);
   }
 }
コード例 #24
0
  /**
   * Called when the processing is complete and the final drawable should be set on the ImageView.
   *
   * @param imageView
   * @param drawable
   */
  private void setImageDrawable(ImageViewWithProcessIndicator imageView, Drawable drawable) {
    if (mFadeInBitmap) {
      imageView.showImage();
      // Transition drawable with a transparent drawable and the final drawable
      final TransitionDrawable td =
          new TransitionDrawable(
              new Drawable[] {new ColorDrawable(android.R.color.transparent), drawable});
      // Set background to loading bitmap
      imageView.setBackgroundDrawable(new BitmapDrawable(mResources, mLoadingBitmap));

      imageView.getImageView().setImageDrawable(td);
      td.startTransition(FADE_IN_TIME);
    } else {
      imageView.getImageView().setImageDrawable(drawable);
    }
    imageView.onAsyncImageSet();
  }
コード例 #25
0
 /** Called when the processing is complete and the final bitmap should be set on the ImageView. */
 private void setImageBitmap(ImageView imageView, Bitmap bitmap) {
   if (mFadeInBitmap) {
     // Use TransitionDrawable to fade in.
     final TransitionDrawable td =
         new TransitionDrawable(
             new Drawable[] {
               new ColorDrawable(android.R.color.transparent),
               new BitmapDrawable(mContext.getResources(), bitmap)
             });
     // noinspection deprecation
     imageView.setBackgroundDrawable(imageView.getDrawable());
     imageView.setImageDrawable(td);
     td.startTransition(FADE_IN_TIME);
   } else {
     imageView.setImageBitmap(bitmap);
   }
 }
コード例 #26
0
  @SuppressLint("NewApi")
  private void changeColor(int newColor) {

    tabs.setIndicatorColor(newColor);

    // change ActionBar color just if an ActionBar is available
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {

      Drawable colorDrawable = new ColorDrawable(newColor);
      Drawable bottomDrawable = getResources().getDrawable(R.drawable.actionbar_bottom);
      LayerDrawable ld = new LayerDrawable(new Drawable[] {colorDrawable, bottomDrawable});

      if (oldBackground == null) {

        if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN_MR1) {
          ld.setCallback(drawableCallback);
        } else {
          getActionBar().setBackgroundDrawable(ld);
        }

      } else {

        TransitionDrawable td = new TransitionDrawable(new Drawable[] {oldBackground, ld});

        // workaround for broken ActionBarContainer drawable handling on
        // pre-API 17 builds
        // https://github.com/android/platform_frameworks_base/commit/a7cc06d82e45918c37429a59b14545c6a57db4e4
        if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN_MR1) {
          td.setCallback(drawableCallback);
        } else {
          getActionBar().setBackgroundDrawable(td);
        }

        td.startTransition(200);
      }

      oldBackground = ld;

      // http://stackoverflow.com/questions/11002691/actionbar-setbackgrounddrawable-nulling-background-from-thread-handler
      getActionBar().setDisplayShowTitleEnabled(false);
      getActionBar().setDisplayShowTitleEnabled(true);
    }

    currentColor = newColor;
  }
コード例 #27
0
  @Override
  protected void onPostExecute(Bitmap bitmap) {

    // Checks if has been canceled due to imageView recycling
    if (isCancelled()) {
      // bitmap = null;
      return;
    }

    // The bitmap will now be attached to view
    if (imageViewReference != null && bitmap != null) {
      final SquareImageView imageView = imageViewReference.get();

      // Checks if is still the task in charge to load image on that imageView
      if (imageView != null && this == (BitmapWorkerTask) imageView.getAsyncTask()) {

        // If the bitmap was already cached it will be directly attached to view
        if (wasCached) {
          imageView.setImageBitmap(bitmap);
        }

        // Otherwise a fading transaction will be used to shot it
        else {
          // Transition with transparent drawabale and the final bitmap
          final TransitionDrawable td =
              new TransitionDrawable(
                  new Drawable[] {
                    new ColorDrawable(Color.TRANSPARENT),
                    new BitmapDrawable(mActivity.getResources(), bitmap)
                  });
          if (td != null) {
            imageView.setImageDrawable(td);
            td.startTransition(FADE_IN_TIME);
          }
        }
      }
    } else {
      if (this.mOnAttachingFileErrorListener != null) {
        mOnAttachingFileErrorListener.onAttachingFileErrorOccurred(mAttachment);
      }
    }
  }
コード例 #28
0
  /**
   * Called when the processing is complete and the final bitmap should be set on the ImageSwitcher.
   *
   * @param ImageSwitcher
   * @param bitmap
   */
  private void setImageBitmap(ImageSwitcher imageSwitcher, Bitmap bitmap) {
    if (fadeIn) {
      // Transition drawable with a transparent drwabale and the final
      // bitmap
      final TransitionDrawable td =
          new TransitionDrawable(
              new Drawable[] {
                new ColorDrawable(android.R.color.transparent),
                new BitmapDrawable(context.getResources(), bitmap)
              });
      // Set background to loading bitmap
      imageSwitcher.setBackgroundDrawable(
          new BitmapDrawable(context.getResources(), loadingBitmap));

      imageSwitcher.setImageDrawable(td);
      td.startTransition(FADE_IN_TIME);
    } else {
      imageSwitcher.setImageDrawable(new BitmapDrawable(bitmap));
    }
  }
コード例 #29
0
ファイル: AnimalPlayer.java プロジェクト: rperlste/android
          @Override
          protected void onPostExecute(Bitmap result) {
            super.onPostExecute(result);
            BitmapDrawable next = new BitmapDrawable(result);
            next.setGravity(android.view.Gravity.CENTER);
            Drawable previous = imageView.getDrawable();

            if (previous instanceof TransitionDrawable)
              previous = ((TransitionDrawable) previous).getDrawable(1);

            if (previous == null) imageView.setImageDrawable(next);
            else {
              Drawable[] drawables = {previous, next};
              TransitionDrawable transition = new TransitionDrawable(drawables);
              imageView.setImageDrawable(transition);
              transition.startTransition(1000);
            }

            handler.postDelayed(updateSlideshow, DURATION);
          }
コード例 #30
0
  @Override
  public void onReceive(Bitmap bitmap) {
    ImageView imageView = imageViewReference.get();
    if (imageView == null) {
      // ImageView has already been garbage collected and is not visible any more.
      return;
    }

    if (!displayLoadingImage) {
      // Show image at once if there was no loading time
      imageView.setImageBitmap(bitmap);
      return;
    }

    Drawable currentDrawable = imageView.getDrawable();
    if (currentDrawable == null) {
      // No previous or loading image is displayed => set new bitmap without transition
      imageView.setImageBitmap(bitmap);
      return;
    }

    // If current drawable is a TransitionDrawable,
    // transition from its final drawable
    if (currentDrawable instanceof TransitionDrawable) {
      currentDrawable = ((TransitionDrawable) currentDrawable).getDrawable(1);
    }

    // Show new bitmap with crossfading transition
    Drawable newDrawable = new BitmapDrawable(imageView.getResources(), bitmap);
    TransitionDrawable transitionDrawable =
        new TransitionDrawable(new Drawable[] {currentDrawable, newDrawable});
    transitionDrawable.setCrossFadeEnabled(true);
    imageView.setImageDrawable(transitionDrawable);

    int animationDuration =
        imageView.getResources().getInteger(android.R.integer.config_shortAnimTime);
    transitionDrawable.startTransition(animationDuration);
  }