Search in sources :

Example 16 with TransitionDrawable

use of android.graphics.drawable.TransitionDrawable in project PagerSlidingTabStrip by astuetz.

the class MainActivity method changeColor.

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 });
            // 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;
}
Also used : TransitionDrawable(android.graphics.drawable.TransitionDrawable) ColorDrawable(android.graphics.drawable.ColorDrawable) LayerDrawable(android.graphics.drawable.LayerDrawable) LayerDrawable(android.graphics.drawable.LayerDrawable) ColorDrawable(android.graphics.drawable.ColorDrawable) Drawable(android.graphics.drawable.Drawable) TransitionDrawable(android.graphics.drawable.TransitionDrawable)

Example 17 with TransitionDrawable

use of android.graphics.drawable.TransitionDrawable in project xUtils by wyouflf.

the class BitmapFragment method fadeInDisplay.

private void fadeInDisplay(ImageView imageView, Bitmap bitmap) {
    final TransitionDrawable transitionDrawable = new TransitionDrawable(new Drawable[] { TRANSPARENT_DRAWABLE, new BitmapDrawable(imageView.getResources(), bitmap) });
    imageView.setImageDrawable(transitionDrawable);
    transitionDrawable.startTransition(500);
}
Also used : TransitionDrawable(android.graphics.drawable.TransitionDrawable) BitmapDrawable(android.graphics.drawable.BitmapDrawable)

Example 18 with TransitionDrawable

use of android.graphics.drawable.TransitionDrawable in project afinal by yangfuhai.

the class SimpleDisplayer method fadeInDisplay.

private void fadeInDisplay(View imageView, Bitmap bitmap) {
    final TransitionDrawable td = new TransitionDrawable(new Drawable[] { new ColorDrawable(android.R.color.transparent), new BitmapDrawable(imageView.getResources(), bitmap) });
    if (imageView instanceof ImageView) {
        ((ImageView) imageView).setImageDrawable(td);
    } else {
        imageView.setBackgroundDrawable(td);
    }
    td.startTransition(300);
}
Also used : TransitionDrawable(android.graphics.drawable.TransitionDrawable) ColorDrawable(android.graphics.drawable.ColorDrawable) BitmapDrawable(android.graphics.drawable.BitmapDrawable) ImageView(android.widget.ImageView)

Example 19 with TransitionDrawable

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

the class QuickStatusBarHeader method setNotificationPanelHeaderBackground.

private void setNotificationPanelHeaderBackground(final Drawable dw, final boolean force) {
    if (mBackgroundImage.getDrawable() != null && !force) {
        Drawable[] arrayDrawable = new Drawable[2];
        arrayDrawable[0] = mBackgroundImage.getDrawable();
        arrayDrawable[1] = dw;
        TransitionDrawable transitionDrawable = new TransitionDrawable(arrayDrawable);
        transitionDrawable.setCrossFadeEnabled(true);
        mBackgroundImage.setImageDrawable(transitionDrawable);
        transitionDrawable.startTransition(1000);
    } else {
        mBackgroundImage.setImageDrawable(dw);
    }
    applyHeaderBackgroundShadow();
}
Also used : TransitionDrawable(android.graphics.drawable.TransitionDrawable) ColorDrawable(android.graphics.drawable.ColorDrawable) Drawable(android.graphics.drawable.Drawable) TransitionDrawable(android.graphics.drawable.TransitionDrawable) RippleDrawable(android.graphics.drawable.RippleDrawable)

Example 20 with TransitionDrawable

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

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