Search in sources :

Example 36 with TransitionDrawable

use of android.graphics.drawable.TransitionDrawable in project KeepScore by nolanlawson.

the class PlayerView method fadeOutBadge.

private void fadeOutBadge(final Runnable onAnimationComplete) {
    synchronized (lock) {
        if (// animation is already running, so shouldn't
        !animationRunning.get() && // start a new one
        lastIncremented.get() != // counter was reset, in which
        0 && // to fade
        badgeTextView.getVisibility() == View.VISIBLE) {
            // animation isn't already showing, and the badge is visible
            animationRunning.set(true);
            animationWasCanceled.set(false);
            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) {
                        log.d("onAnimationEnd, setting visiblity to invisible");
                        if (!animationWasCanceled.get()) {
                            badgeTextView.setVisibility(View.INVISIBLE);
                        }
                        // necessary to update again to set the history text
                        // view correctly
                        onAnimationComplete.run();
                        animationRunning.set(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();
        }
    }
}
Also used : TransitionDrawable(android.graphics.drawable.TransitionDrawable) Animation(android.view.animation.Animation) AnimationListener(android.view.animation.Animation.AnimationListener)

Example 37 with TransitionDrawable

use of android.graphics.drawable.TransitionDrawable in project KeepScore by nolanlawson.

the class PlayerView method makeBadgeVisible.

private void makeBadgeVisible() {
    synchronized (lock) {
        // show the badge, canceling the "fade out" animation if necessary
        TransitionDrawable transitionDrawable = (TransitionDrawable) badgeLinearLayout.getBackground();
        transitionDrawable.resetTransition();
        log.d("reset transition");
        if (badgeTextView.getAnimation() != null) {
            log.d("cleared animation");
            badgeTextView.clearAnimation();
            animationWasCanceled.set(true);
        }
        badgeTextView.setVisibility(View.VISIBLE);
        badgeLinearLayout.setVisibility(View.VISIBLE);
    }
}
Also used : TransitionDrawable(android.graphics.drawable.TransitionDrawable)

Example 38 with TransitionDrawable

use of android.graphics.drawable.TransitionDrawable in project android_frameworks_base by ParanoidAndroid.

the class AbsListView method keyPressed.

/**
     * Sets the selector state to "pressed" and posts a CheckForKeyLongPress to see if
     * this is a long press.
     */
void keyPressed() {
    if (!isEnabled() || !isClickable()) {
        return;
    }
    Drawable selector = mSelector;
    Rect selectorRect = mSelectorRect;
    if (selector != null && (isFocused() || touchModeDrawsInPressedState()) && !selectorRect.isEmpty()) {
        final View v = getChildAt(mSelectedPosition - mFirstPosition);
        if (v != null) {
            if (v.hasFocusable())
                return;
            v.setPressed(true);
        }
        setPressed(true);
        final boolean longClickable = isLongClickable();
        Drawable d = selector.getCurrent();
        if (d != null && d instanceof TransitionDrawable) {
            if (longClickable) {
                ((TransitionDrawable) d).startTransition(ViewConfiguration.getLongPressTimeout());
            } else {
                ((TransitionDrawable) d).resetTransition();
            }
        }
        if (longClickable && !mDataChanged) {
            if (mPendingCheckForKeyLongPress == null) {
                mPendingCheckForKeyLongPress = new CheckForKeyLongPress();
            }
            mPendingCheckForKeyLongPress.rememberWindowAttachCount();
            postDelayed(mPendingCheckForKeyLongPress, ViewConfiguration.getLongPressTimeout());
        }
    }
}
Also used : Rect(android.graphics.Rect) TransitionDrawable(android.graphics.drawable.TransitionDrawable) Drawable(android.graphics.drawable.Drawable) TransitionDrawable(android.graphics.drawable.TransitionDrawable) View(android.view.View)

Example 39 with TransitionDrawable

use of android.graphics.drawable.TransitionDrawable in project mobile-android by photo.

the class ImageWorker method setImageBitmap.

/**
     * 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) {
    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
        int sdk = android.os.Build.VERSION.SDK_INT;
        if (sdk < android.os.Build.VERSION_CODES.JELLY_BEAN) {
            setBackgroundDrawable(imageView);
        } else {
            setBackground(imageView);
        }
        imageView.setImageDrawable(td);
        td.startTransition(FADE_IN_TIME);
    } else {
        imageView.setImageBitmap(bitmap);
    }
}
Also used : TransitionDrawable(android.graphics.drawable.TransitionDrawable) ColorDrawable(android.graphics.drawable.ColorDrawable) BitmapDrawable(android.graphics.drawable.BitmapDrawable)

Example 40 with TransitionDrawable

use of android.graphics.drawable.TransitionDrawable in project platform_frameworks_base by android.

the class AbsListView method onTouchUp.

private void onTouchUp(MotionEvent ev) {
    switch(mTouchMode) {
        case TOUCH_MODE_DOWN:
        case TOUCH_MODE_TAP:
        case TOUCH_MODE_DONE_WAITING:
            final int motionPosition = mMotionPosition;
            final View child = getChildAt(motionPosition - mFirstPosition);
            if (child != null) {
                if (mTouchMode != TOUCH_MODE_DOWN) {
                    child.setPressed(false);
                }
                final float x = ev.getX();
                final boolean inList = x > mListPadding.left && x < getWidth() - mListPadding.right;
                if (inList && !child.hasFocusable()) {
                    if (mPerformClick == null) {
                        mPerformClick = new PerformClick();
                    }
                    final AbsListView.PerformClick performClick = mPerformClick;
                    performClick.mClickMotionPosition = motionPosition;
                    performClick.rememberWindowAttachCount();
                    mResurrectToPosition = motionPosition;
                    if (mTouchMode == TOUCH_MODE_DOWN || mTouchMode == TOUCH_MODE_TAP) {
                        removeCallbacks(mTouchMode == TOUCH_MODE_DOWN ? mPendingCheckForTap : mPendingCheckForLongPress);
                        mLayoutMode = LAYOUT_NORMAL;
                        if (!mDataChanged && mAdapter.isEnabled(motionPosition)) {
                            mTouchMode = TOUCH_MODE_TAP;
                            setSelectedPositionInt(mMotionPosition);
                            layoutChildren();
                            child.setPressed(true);
                            positionSelector(mMotionPosition, child);
                            setPressed(true);
                            if (mSelector != null) {
                                Drawable d = mSelector.getCurrent();
                                if (d != null && d instanceof TransitionDrawable) {
                                    ((TransitionDrawable) d).resetTransition();
                                }
                                mSelector.setHotspot(x, ev.getY());
                            }
                            if (mTouchModeReset != null) {
                                removeCallbacks(mTouchModeReset);
                            }
                            mTouchModeReset = new Runnable() {

                                @Override
                                public void run() {
                                    mTouchModeReset = null;
                                    mTouchMode = TOUCH_MODE_REST;
                                    child.setPressed(false);
                                    setPressed(false);
                                    if (!mDataChanged && !mIsDetaching && isAttachedToWindow()) {
                                        performClick.run();
                                    }
                                }
                            };
                            postDelayed(mTouchModeReset, ViewConfiguration.getPressedStateDuration());
                        } else {
                            mTouchMode = TOUCH_MODE_REST;
                            updateSelectorState();
                        }
                        return;
                    } else if (!mDataChanged && mAdapter.isEnabled(motionPosition)) {
                        performClick.run();
                    }
                }
            }
            mTouchMode = TOUCH_MODE_REST;
            updateSelectorState();
            break;
        case TOUCH_MODE_SCROLL:
            final int childCount = getChildCount();
            if (childCount > 0) {
                final int firstChildTop = getChildAt(0).getTop();
                final int lastChildBottom = getChildAt(childCount - 1).getBottom();
                final int contentTop = mListPadding.top;
                final int contentBottom = getHeight() - mListPadding.bottom;
                if (mFirstPosition == 0 && firstChildTop >= contentTop && mFirstPosition + childCount < mItemCount && lastChildBottom <= getHeight() - contentBottom) {
                    mTouchMode = TOUCH_MODE_REST;
                    reportScrollStateChange(OnScrollListener.SCROLL_STATE_IDLE);
                } else {
                    final VelocityTracker velocityTracker = mVelocityTracker;
                    velocityTracker.computeCurrentVelocity(1000, mMaximumVelocity);
                    final int initialVelocity = (int) (velocityTracker.getYVelocity(mActivePointerId) * mVelocityScale);
                    // Fling if we have enough velocity and we aren't at a boundary.
                    // Since we can potentially overfling more than we can overscroll, don't
                    // allow the weird behavior where you can scroll to a boundary then
                    // fling further.
                    boolean flingVelocity = Math.abs(initialVelocity) > mMinimumVelocity;
                    if (flingVelocity && !((mFirstPosition == 0 && firstChildTop == contentTop - mOverscrollDistance) || (mFirstPosition + childCount == mItemCount && lastChildBottom == contentBottom + mOverscrollDistance))) {
                        if (!dispatchNestedPreFling(0, -initialVelocity)) {
                            if (mFlingRunnable == null) {
                                mFlingRunnable = new FlingRunnable();
                            }
                            reportScrollStateChange(OnScrollListener.SCROLL_STATE_FLING);
                            mFlingRunnable.start(-initialVelocity);
                            dispatchNestedFling(0, -initialVelocity, true);
                        } else {
                            mTouchMode = TOUCH_MODE_REST;
                            reportScrollStateChange(OnScrollListener.SCROLL_STATE_IDLE);
                        }
                    } else {
                        mTouchMode = TOUCH_MODE_REST;
                        reportScrollStateChange(OnScrollListener.SCROLL_STATE_IDLE);
                        if (mFlingRunnable != null) {
                            mFlingRunnable.endFling();
                        }
                        if (mPositionScroller != null) {
                            mPositionScroller.stop();
                        }
                        if (flingVelocity && !dispatchNestedPreFling(0, -initialVelocity)) {
                            dispatchNestedFling(0, -initialVelocity, false);
                        }
                    }
                }
            } else {
                mTouchMode = TOUCH_MODE_REST;
                reportScrollStateChange(OnScrollListener.SCROLL_STATE_IDLE);
            }
            break;
        case TOUCH_MODE_OVERSCROLL:
            if (mFlingRunnable == null) {
                mFlingRunnable = new FlingRunnable();
            }
            final VelocityTracker velocityTracker = mVelocityTracker;
            velocityTracker.computeCurrentVelocity(1000, mMaximumVelocity);
            final int initialVelocity = (int) velocityTracker.getYVelocity(mActivePointerId);
            reportScrollStateChange(OnScrollListener.SCROLL_STATE_FLING);
            if (Math.abs(initialVelocity) > mMinimumVelocity) {
                mFlingRunnable.startOverfling(-initialVelocity);
            } else {
                mFlingRunnable.startSpringback();
            }
            break;
    }
    setPressed(false);
    if (mEdgeGlowTop != null) {
        mEdgeGlowTop.onRelease();
        mEdgeGlowBottom.onRelease();
    }
    // Need to redraw since we probably aren't drawing the selector anymore
    invalidate();
    removeCallbacks(mPendingCheckForLongPress);
    recycleVelocityTracker();
    mActivePointerId = INVALID_POINTER;
    if (PROFILE_SCROLLING) {
        if (mScrollProfilingStarted) {
            Debug.stopMethodTracing();
            mScrollProfilingStarted = false;
        }
    }
    if (mScrollStrictSpan != null) {
        mScrollStrictSpan.finish();
        mScrollStrictSpan = null;
    }
}
Also used : TransitionDrawable(android.graphics.drawable.TransitionDrawable) VelocityTracker(android.view.VelocityTracker) Drawable(android.graphics.drawable.Drawable) TransitionDrawable(android.graphics.drawable.TransitionDrawable) View(android.view.View)

Aggregations

TransitionDrawable (android.graphics.drawable.TransitionDrawable)61 Drawable (android.graphics.drawable.Drawable)45 View (android.view.View)23 ColorDrawable (android.graphics.drawable.ColorDrawable)22 BitmapDrawable (android.graphics.drawable.BitmapDrawable)21 VelocityTracker (android.view.VelocityTracker)10 Rect (android.graphics.Rect)9 Handler (android.os.Handler)8 LayerDrawable (android.graphics.drawable.LayerDrawable)5 RippleDrawable (android.graphics.drawable.RippleDrawable)3 Animation (android.view.animation.Animation)3 ImageView (android.widget.ImageView)3 SuppressLint (android.annotation.SuppressLint)2 Intent (android.content.Intent)2 ColorStateList (android.content.res.ColorStateList)2 ContentObserver (android.database.ContentObserver)2 Bitmap (android.graphics.Bitmap)2 Canvas (android.graphics.Canvas)2 GradientDrawable (android.graphics.drawable.GradientDrawable)2 StateListDrawable (android.graphics.drawable.StateListDrawable)2