@Override protected void onFinishInflate() { super.onFinishInflate(); // Get the drawable mOriginalTextColor = getTextColors(); // Get the hover color Resources r = getResources(); mHoverColor = r.getColor(R.color.delete_target_hover_tint); mHoverPaint.setColorFilter(new PorterDuffColorFilter(mHoverColor, PorterDuff.Mode.SRC_ATOP)); mUninstallDrawable = (TransitionDrawable) r.getDrawable(R.drawable.uninstall_target_selector); mRemoveDrawable = (TransitionDrawable) r.getDrawable(R.drawable.remove_target_selector); mRemoveDrawable.setCrossFadeEnabled(true); mUninstallDrawable.setCrossFadeEnabled(true); // The current drawable is set to either the remove drawable or the uninstall drawable // and is initially set to the remove drawable, as set in the layout xml. mCurrentDrawable = (TransitionDrawable) getCompoundDrawables()[0]; // Remove the text in the Phone UI in landscape int orientation = getResources().getConfiguration().orientation; if (orientation == Configuration.ORIENTATION_LANDSCAPE) { if (!LauncherApplication.isScreenLarge()) { setText(""); } } }
// This boolean takes effect when the drawable is drawn and the effect can not be tested. public void testAccessCrossFadeEnabled() { assertFalse(mTransitionDrawable.isCrossFadeEnabled()); mTransitionDrawable.setCrossFadeEnabled(true); assertTrue(mTransitionDrawable.isCrossFadeEnabled()); mTransitionDrawable.setCrossFadeEnabled(false); assertFalse(mTransitionDrawable.isCrossFadeEnabled()); }
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(); } } }
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); }
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; }
@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(); }
/** * 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); } }
@Override protected void onFinishInflate() { super.onFinishInflate(); mOriginalTextColor = getTextColors(); // Get the hover color Resources r = getResources(); mHoverColor = r.getColor(R.color.info_target_hover_tint); mHoverPaint.setColorFilter(new PorterDuffColorFilter(mHoverColor, PorterDuff.Mode.SRC_ATOP)); mDrawable = (TransitionDrawable) getCompoundDrawables()[0]; mDrawable.setCrossFadeEnabled(true); // Remove the text in the Phone UI in landscape int orientation = getResources().getConfiguration().orientation; if (orientation == Configuration.ORIENTATION_LANDSCAPE) { if (!LauncherApplication.isScreenLarge()) { setText(""); } } }
@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); }
@SuppressWarnings("deprecation") @Override protected void onFinishInflate() { super.onFinishInflate(); mOriginalTextColor = getTextColors(); // Get the hover color Resources r = getResources(); mHoverColor = r.getColor(R.color.info_target_hover_tint); mDrawable = (TransitionDrawable) getCurrentDrawable(); if (null != mDrawable) { mDrawable.setCrossFadeEnabled(true); } // Remove the text in the Phone UI in landscape int orientation = getResources().getConfiguration().orientation; if (orientation == Configuration.ORIENTATION_LANDSCAPE) { if (!LauncherAppState.getInstance().isScreenLarge()) { setText(""); } } }
/** {@inheritDoc} */ @Override protected TransitionDrawable doInBackground(final String... params) { // Define the key mKey = params[0]; // The result Bitmap bitmap = null; // First, check the disk cache for the image if (mKey != null && mImageCache != null && !isCancelled() && getAttachedImageView() != null) { bitmap = mImageCache.getCachedBitmap(mKey); } // Define the album id now mAlbumId = Long.valueOf(params[3]); // Second, if we're fetching artwork, check the device for the image if (bitmap == null && mImageType.equals(ImageType.ALBUM) && mAlbumId >= 0 && mKey != null && !isCancelled() && getAttachedImageView() != null && mImageCache != null) { bitmap = mImageCache.getCachedArtwork(mContext, mKey, mAlbumId); } // Third, by now we need to download the image if (bitmap == null && ApolloUtils.isOnline(mContext) && !isCancelled() && getAttachedImageView() != null) { // Now define what the artist name, album name, and url are. mArtistName = params[1]; mAlbumName = params[2]; mUrl = processImageUrl(mArtistName, mAlbumName, mImageType); if (mUrl != null) { bitmap = processBitmap(mUrl); } } // Fourth, add the new image to the cache if (bitmap != null && mKey != null && mImageCache != null) { addBitmapToCache(mKey, bitmap); } // Add the second layer to the transiation drawable if (bitmap != null) { final BitmapDrawable layerTwo = new BitmapDrawable(mResources, bitmap); layerTwo.setFilterBitmap(false); layerTwo.setDither(false); mArrayDrawable[1] = layerTwo; // Finally, return the image final TransitionDrawable result = new TransitionDrawable(mArrayDrawable); result.setCrossFadeEnabled(true); result.startTransition(FADE_IN_TIME); return result; } return null; }