Search in sources :

Example 46 with TransitionDrawable

use of android.graphics.drawable.TransitionDrawable in project EhViewer by seven332.

the class LoadImageView method onGetValue.

@Override
public boolean onGetValue(@NonNull ImageBitmap value, int source) {
    Drawable drawable;
    try {
        drawable = new ImageDrawable(value);
    } catch (RecycledException e) {
        // The image might be recycled because it is removed from memory cache.
        Log.d(TAG, "The image is recycled", e);
        return false;
    }
    clearDrawable();
    if (Integer.MIN_VALUE != mOffsetX) {
        drawable = new PreciselyClipDrawable(drawable, mOffsetX, mOffsetY, mClipWidth, mClipHeight);
    }
    onPreSetImageDrawable(drawable, true);
    if ((source == Conaco.SOURCE_DISK || source == Conaco.SOURCE_NETWORK) && isShown()) {
        Drawable[] layers = new Drawable[2];
        layers[0] = new ColorDrawable(Color.TRANSPARENT);
        layers[1] = drawable;
        TransitionDrawable transitionDrawable = new TransitionDrawable(layers);
        setImageDrawable(transitionDrawable);
        transitionDrawable.startTransition(300);
    } else {
        setImageDrawable(drawable);
    }
    return true;
}
Also used : ImageDrawable(com.hippo.image.ImageDrawable) PreciselyClipDrawable(com.hippo.drawable.PreciselyClipDrawable) TransitionDrawable(android.graphics.drawable.TransitionDrawable) RecycledException(com.hippo.image.RecycledException) ColorDrawable(android.graphics.drawable.ColorDrawable) PreciselyClipDrawable(com.hippo.drawable.PreciselyClipDrawable) ColorDrawable(android.graphics.drawable.ColorDrawable) Drawable(android.graphics.drawable.Drawable) ImageDrawable(com.hippo.image.ImageDrawable) TransitionDrawable(android.graphics.drawable.TransitionDrawable)

Example 47 with TransitionDrawable

use of android.graphics.drawable.TransitionDrawable in project AisenWeiBo by wangdan.

the class VideoHintImageView method setImageDrawable.

@Override
public void setImageDrawable(Drawable drawable) {
    super.setImageDrawable(drawable);
    MyDrawable myDrawable = null;
    if (drawable instanceof MyDrawable) {
        myDrawable = (MyDrawable) drawable;
    } else if (drawable instanceof TransitionDrawable) {
        myDrawable = (MyDrawable) ((TransitionDrawable) drawable).getDrawable(1);
    }
    if (myDrawable != null) {
        MyBitmap myBitmap = myDrawable.getMyBitmap();
        if (myBitmap instanceof VideoBitmap) {
            setOnClickListener(this);
            videoBean = ((VideoBitmap) myBitmap).getVideoBean();
            if (getWidth() > 0) {
                int width = myBitmap.getBitmap().getWidth();
                int height = myBitmap.getBitmap().getHeight();
                float scale = getWidth() * 1.0f / width;
                height = (int) (height * scale);
                if (height > getWidth() * 4 / 5) {
                    height = getWidth() * 4 / 5;
                }
                LinearLayout.LayoutParams params = (LinearLayout.LayoutParams) getLayoutParams();
                if (params != null) {
                    params.height = height;
                } else {
                    params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, height);
                }
                setLayoutParams(params);
            }
            Logger.d(VideoHintImageView.class.getSimpleName(), videoBean);
        }
    }
}
Also used : MyBitmap(org.aisen.android.component.bitmaploader.core.MyBitmap) TransitionDrawable(android.graphics.drawable.TransitionDrawable) MyDrawable(org.aisen.android.component.bitmaploader.view.MyDrawable) Paint(android.graphics.Paint) LinearLayout(android.widget.LinearLayout)

Example 48 with TransitionDrawable

use of android.graphics.drawable.TransitionDrawable in project AisenWeiBo by wangdan.

the class PLAAbsListView method onTouchEvent.

@Override
public boolean onTouchEvent(MotionEvent ev) {
    if (!isEnabled()) {
        // events, it just doesn't respond to them.
        return isClickable() || isLongClickable();
    }
    final int action = ev.getAction();
    View v;
    int deltaY;
    if (mVelocityTracker == null) {
        mVelocityTracker = VelocityTracker.obtain();
    }
    mVelocityTracker.addMovement(ev);
    switch(action & MotionEvent.ACTION_MASK) {
        case MotionEvent.ACTION_DOWN:
            {
                mActivePointerId = ev.getPointerId(0);
                final int x = (int) ev.getX();
                final int y = (int) ev.getY();
                int motionPosition = pointToPosition(x, y);
                if (!mDataChanged) {
                    if ((mTouchMode != TOUCH_MODE_FLING) && (motionPosition >= 0) && (getAdapter().isEnabled(motionPosition))) {
                        // User clicked on an actual view (and was not stopping a fling). It might be a
                        // click or a scroll. Assume it is a click until proven otherwise
                        mTouchMode = TOUCH_MODE_DOWN;
                        // FIXME Debounce
                        if (mPendingCheckForTap == null) {
                            mPendingCheckForTap = new CheckForTap();
                        }
                        postDelayed(mPendingCheckForTap, ViewConfiguration.getTapTimeout());
                    } else {
                        if (ev.getEdgeFlags() != 0 && motionPosition < 0) {
                            // code in ViewRoot to try to find a nearby view to select
                            return false;
                        }
                        if (mTouchMode == TOUCH_MODE_FLING) {
                            // Stopped a fling. It is a scroll.
                            createScrollingCache();
                            mTouchMode = TOUCH_MODE_SCROLL;
                            mMotionCorrection = 0;
                            motionPosition = findMotionRow(y);
                            reportScrollStateChange(OnScrollListener.SCROLL_STATE_TOUCH_SCROLL);
                        }
                    }
                }
                if (motionPosition >= 0) {
                    // Remember where the motion event started
                    v = getChildAt(motionPosition - mFirstPosition);
                    mMotionViewOriginalTop = v.getTop();
                }
                mMotionX = x;
                mMotionY = y;
                mMotionPosition = motionPosition;
                mLastY = Integer.MIN_VALUE;
                break;
            }
        case MotionEvent.ACTION_MOVE:
            {
                final int pointerIndex = ev.findPointerIndex(mActivePointerId);
                final int y = (int) ev.getY(pointerIndex);
                deltaY = y - mMotionY;
                switch(mTouchMode) {
                    case TOUCH_MODE_DOWN:
                    case TOUCH_MODE_TAP:
                    case TOUCH_MODE_DONE_WAITING:
                        // Check if we have moved far enough that it looks more like a
                        // scroll than a tap
                        startScrollIfNeeded(deltaY);
                        break;
                    case TOUCH_MODE_SCROLL:
                        if (PROFILE_SCROLLING) {
                            if (!mScrollProfilingStarted) {
                                Debug.startMethodTracing("AbsListViewScroll");
                                mScrollProfilingStarted = true;
                            }
                        }
                        if (y != mLastY) {
                            deltaY -= mMotionCorrection;
                            int incrementalDeltaY = mLastY != Integer.MIN_VALUE ? y - mLastY : deltaY;
                            // No need to do all this work if we're not going to move anyway
                            boolean atEdge = false;
                            if (incrementalDeltaY != 0) {
                                atEdge = trackMotionScroll(deltaY, incrementalDeltaY);
                            }
                            // Check to see if we have bumped into the scroll limit
                            if (atEdge && getChildCount() > 0) {
                                // Treat this like we're starting a new scroll from the current
                                // position. This will let the user start scrolling back into
                                // content immediately rather than needing to scroll back to the
                                // point where they hit the limit first.
                                int motionPosition = findMotionRow(y);
                                if (motionPosition >= 0) {
                                    final View motionView = getChildAt(motionPosition - mFirstPosition);
                                    mMotionViewOriginalTop = motionView.getTop();
                                }
                                mMotionY = y;
                                mMotionPosition = motionPosition;
                                invalidate();
                            }
                            mLastY = y;
                        }
                        break;
                }
                break;
            }
        case MotionEvent.ACTION_UP:
            {
                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 && !child.hasFocusable()) {
                            if (mTouchMode != TOUCH_MODE_DOWN) {
                                child.setPressed(false);
                            }
                            if (mPerformClick == null) {
                                mPerformClick = new PerformClick();
                            }
                            final PerformClick performClick = mPerformClick;
                            performClick.mChild = child;
                            performClick.mClickMotionPosition = motionPosition;
                            performClick.rememberWindowAttachCount();
                            mResurrectToPosition = motionPosition;
                            if (mTouchMode == TOUCH_MODE_DOWN || mTouchMode == TOUCH_MODE_TAP) {
                                mLayoutMode = LAYOUT_NORMAL;
                                if (!mDataChanged && mAdapter.isEnabled(motionPosition)) {
                                    mTouchMode = TOUCH_MODE_TAP;
                                    layoutChildren();
                                    child.setPressed(true);
                                    positionSelector(child);
                                    setPressed(true);
                                    if (mSelector != null) {
                                        Drawable d = mSelector.getCurrent();
                                        if (d != null && d instanceof TransitionDrawable) {
                                            ((TransitionDrawable) d).resetTransition();
                                        }
                                    }
                                    postDelayed(new Runnable() {

                                        public void run() {
                                            child.setPressed(false);
                                            setPressed(false);
                                            if (!mDataChanged) {
                                                post(performClick);
                                            }
                                            mTouchMode = TOUCH_MODE_REST;
                                        }
                                    }, ViewConfiguration.getPressedStateDuration());
                                } else {
                                    mTouchMode = TOUCH_MODE_REST;
                                }
                                return true;
                            } else if (!mDataChanged && mAdapter.isEnabled(motionPosition)) {
                                post(performClick);
                            }
                        }
                        mTouchMode = TOUCH_MODE_REST;
                        break;
                    case TOUCH_MODE_SCROLL:
                        final int childCount = getChildCount();
                        if (childCount > 0) {
                            int top = getFillChildTop();
                            int bottom = getFillChildBottom();
                            if (mFirstPosition == 0 && top >= mListPadding.top && mFirstPosition + childCount < mItemCount && bottom <= getHeight() - mListPadding.bottom) {
                                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);
                                if (Math.abs(initialVelocity) > mMinimumVelocity) {
                                    if (mFlingRunnable == null) {
                                        mFlingRunnable = new FlingRunnable();
                                    }
                                    reportScrollStateChange(OnScrollListener.SCROLL_STATE_FLING);
                                    mFlingRunnable.start(-initialVelocity);
                                } else {
                                    mTouchMode = TOUCH_MODE_REST;
                                    reportScrollStateChange(OnScrollListener.SCROLL_STATE_IDLE);
                                }
                            }
                        } else {
                            mTouchMode = TOUCH_MODE_REST;
                            reportScrollStateChange(OnScrollListener.SCROLL_STATE_IDLE);
                        }
                        break;
                }
                setPressed(false);
                // Need to redraw since we probably aren't drawing the selector anymore
                invalidate();
                if (mVelocityTracker != null) {
                    mVelocityTracker.recycle();
                    mVelocityTracker = null;
                }
                mActivePointerId = INVALID_POINTER;
                if (PROFILE_SCROLLING) {
                    if (mScrollProfilingStarted) {
                        Debug.stopMethodTracing();
                        mScrollProfilingStarted = false;
                    }
                }
                break;
            }
        case MotionEvent.ACTION_CANCEL:
            {
                mTouchMode = TOUCH_MODE_REST;
                setPressed(false);
                View motionView = this.getChildAt(mMotionPosition - mFirstPosition);
                if (motionView != null) {
                    motionView.setPressed(false);
                }
                clearScrollingCache();
                if (mVelocityTracker != null) {
                    mVelocityTracker.recycle();
                    mVelocityTracker = null;
                }
                mActivePointerId = INVALID_POINTER;
                break;
            }
        case MotionEvent.ACTION_POINTER_UP:
            {
                onSecondaryPointerUp(ev);
                final int x = mMotionX;
                final int y = mMotionY;
                final int motionPosition = pointToPosition(x, y);
                if (motionPosition >= 0) {
                    // Remember where the motion event started
                    v = getChildAt(motionPosition - mFirstPosition);
                    mMotionViewOriginalTop = v.getTop();
                    mMotionPosition = motionPosition;
                }
                mLastY = y;
                break;
            }
    }
    return true;
}
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)

Example 49 with TransitionDrawable

use of android.graphics.drawable.TransitionDrawable in project AisenWeiBo by wangdan.

the class FadeInDisplayer method loadCompletedisplay.

@Override
public void loadCompletedisplay(ImageView imageView, BitmapDrawable drawable) {
    // PhotoView不设置
    if (imageView.getClass().getSimpleName().indexOf("PhotoView") != -1)
        return;
    if (imageView.getDrawable() != null) {
        final TransitionDrawable td = new TransitionDrawable(new Drawable[] { imageView.getDrawable(), drawable });
        imageView.setImageDrawable(td);
        td.startTransition(300);
    } else {
        imageView.setImageDrawable(drawable);
    }
}
Also used : TransitionDrawable(android.graphics.drawable.TransitionDrawable)

Example 50 with TransitionDrawable

use of android.graphics.drawable.TransitionDrawable in project AisenWeiBo by wangdan.

the class BitmapLoader method getLoadingDrawable.

public static Drawable getLoadingDrawable(Context context, ImageView imageView) {
    Drawable drawable = imageView.getDrawable();
    if (drawable != null && context != null) {
        if (drawable instanceof TransitionDrawable) {
            TransitionDrawable transitionDrawable = (TransitionDrawable) drawable;
            drawable = transitionDrawable.getDrawable(1);
        }
        if (drawable instanceof MyDrawable) {
            MyDrawable myDrawable = (MyDrawable) drawable;
            ImageConfig config = myDrawable.getConfig();
            if (config != null) {
                if (config.getLoadingRes() > 0)
                    return new BitmapDrawable(context.getResources(), new MyBitmap(context, config.getLoadingRes()).getBitmap());
            }
        }
    }
    return new ColorDrawable(Color.parseColor("#fff2f2f2"));
}
Also used : ImageConfig(org.aisen.android.component.bitmaploader.core.ImageConfig) MyBitmap(org.aisen.android.component.bitmaploader.core.MyBitmap) TransitionDrawable(android.graphics.drawable.TransitionDrawable) ColorDrawable(android.graphics.drawable.ColorDrawable) ColorDrawable(android.graphics.drawable.ColorDrawable) Drawable(android.graphics.drawable.Drawable) MyDrawable(org.aisen.android.component.bitmaploader.view.MyDrawable) BitmapDrawable(android.graphics.drawable.BitmapDrawable) TransitionDrawable(android.graphics.drawable.TransitionDrawable) BitmapDrawable(android.graphics.drawable.BitmapDrawable) MyDrawable(org.aisen.android.component.bitmaploader.view.MyDrawable)

Aggregations

TransitionDrawable (android.graphics.drawable.TransitionDrawable)96 Drawable (android.graphics.drawable.Drawable)61 ColorDrawable (android.graphics.drawable.ColorDrawable)35 BitmapDrawable (android.graphics.drawable.BitmapDrawable)31 View (android.view.View)28 VelocityTracker (android.view.VelocityTracker)11 ImageView (android.widget.ImageView)10 Rect (android.graphics.Rect)9 Handler (android.os.Handler)8 Test (org.junit.Test)6 Bitmap (android.graphics.Bitmap)5 LayerDrawable (android.graphics.drawable.LayerDrawable)5 GradientDrawable (android.graphics.drawable.GradientDrawable)3 RippleDrawable (android.graphics.drawable.RippleDrawable)3 SuppressLint (android.annotation.SuppressLint)2 Intent (android.content.Intent)2 ColorStateList (android.content.res.ColorStateList)2 Resources (android.content.res.Resources)2 ContentObserver (android.database.ContentObserver)2 Canvas (android.graphics.Canvas)2