Search in sources :

Example 81 with TransitionDrawable

use of android.graphics.drawable.TransitionDrawable in project Klyph by jonathangerbaud.

the class AbsHListView method keyPressed.

/**
 * Sets the selector state to "pressed" and posts a CheckForKeyLongPress to see if this is a long press.
 */
protected 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) ListView(android.widget.ListView)

Example 82 with TransitionDrawable

use of android.graphics.drawable.TransitionDrawable in project Wallpaper-Manager by Bencodes.

the class TwoWayAbsListView 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 != null && !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)

Example 83 with TransitionDrawable

use of android.graphics.drawable.TransitionDrawable in project android-segmented-control by Kaopiz.

the class SegmentedGroup method updateBackground.

private void updateBackground(View view) {
    int checked = mLayoutSelector.getSelected();
    int unchecked = mLayoutSelector.getUnselected();
    // Set text color
    ColorStateList colorStateList = new ColorStateList(new int[][] { { -android.R.attr.state_checked }, { android.R.attr.state_checked } }, new int[] { mTintColor, mCheckedTextColor });
    ((Button) view).setTextColor(colorStateList);
    // Redraw with tint color
    Drawable checkedDrawable = resources.getDrawable(checked).mutate();
    Drawable uncheckedDrawable = resources.getDrawable(unchecked).mutate();
    ((GradientDrawable) checkedDrawable).setColor(mTintColor);
    ((GradientDrawable) checkedDrawable).setStroke(mMarginDp, mTintColor);
    ((GradientDrawable) uncheckedDrawable).setStroke(mMarginDp, mTintColor);
    ((GradientDrawable) uncheckedDrawable).setColor(mUnCheckedTintColor);
    // Set proper radius
    ((GradientDrawable) checkedDrawable).setCornerRadii(mLayoutSelector.getChildRadii(view));
    ((GradientDrawable) uncheckedDrawable).setCornerRadii(mLayoutSelector.getChildRadii(view));
    GradientDrawable maskDrawable = (GradientDrawable) resources.getDrawable(unchecked).mutate();
    maskDrawable.setStroke(mMarginDp, mTintColor);
    maskDrawable.setColor(mUnCheckedTintColor);
    maskDrawable.setCornerRadii(mLayoutSelector.getChildRadii(view));
    int maskColor = Color.argb(50, Color.red(mTintColor), Color.green(mTintColor), Color.blue(mTintColor));
    maskDrawable.setColor(maskColor);
    LayerDrawable pressedDrawable = new LayerDrawable(new Drawable[] { uncheckedDrawable, maskDrawable });
    Drawable[] drawables = { uncheckedDrawable, checkedDrawable };
    TransitionDrawable transitionDrawable = new TransitionDrawable(drawables);
    if (((RadioButton) view).isChecked()) {
        transitionDrawable.reverseTransition(0);
    }
    StateListDrawable stateListDrawable = new StateListDrawable();
    stateListDrawable.addState(new int[] { -android.R.attr.state_checked, android.R.attr.state_pressed }, pressedDrawable);
    stateListDrawable.addState(StateSet.WILD_CARD, transitionDrawable);
    mDrawableMap.put(view.getId(), transitionDrawable);
    // Set button background
    if (Build.VERSION.SDK_INT >= 16) {
        view.setBackground(stateListDrawable);
    } else {
        view.setBackgroundDrawable(stateListDrawable);
    }
    super.setOnCheckedChangeListener(new OnCheckedChangeListener() {

        @Override
        public void onCheckedChanged(RadioGroup group, int checkedId) {
            TransitionDrawable current = mDrawableMap.get(checkedId);
            current.reverseTransition(200);
            if (mLastCheckId != 0) {
                TransitionDrawable last = mDrawableMap.get(mLastCheckId);
                if (last != null)
                    last.reverseTransition(200);
            }
            mLastCheckId = checkedId;
            if (mCheckedChangeListener != null) {
                mCheckedChangeListener.onCheckedChanged(group, checkedId);
            }
        }
    });
}
Also used : TransitionDrawable(android.graphics.drawable.TransitionDrawable) RadioGroup(android.widget.RadioGroup) LayerDrawable(android.graphics.drawable.LayerDrawable) Drawable(android.graphics.drawable.Drawable) TransitionDrawable(android.graphics.drawable.TransitionDrawable) StateListDrawable(android.graphics.drawable.StateListDrawable) GradientDrawable(android.graphics.drawable.GradientDrawable) ColorStateList(android.content.res.ColorStateList) RadioButton(android.widget.RadioButton) StateListDrawable(android.graphics.drawable.StateListDrawable) GradientDrawable(android.graphics.drawable.GradientDrawable) RadioButton(android.widget.RadioButton) Button(android.widget.Button) LayerDrawable(android.graphics.drawable.LayerDrawable)

Example 84 with TransitionDrawable

use of android.graphics.drawable.TransitionDrawable in project Shuttle by timusus.

the class BitmapPalette method crossfadeTargetBackground.

private void crossfadeTargetBackground(PaletteTarget target, Pair<View, Integer> t, int newColor) {
    final Drawable oldColor = t.first.getBackground();
    final Drawable[] drawables = new Drawable[2];
    drawables[0] = oldColor != null ? oldColor : new ColorDrawable(t.first.getSolidColor());
    drawables[1] = new ColorDrawable(newColor);
    TransitionDrawable transitionDrawable = new TransitionDrawable(drawables);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
        t.first.setBackground(transitionDrawable);
    } else {
        // noinspection deprecation
        t.first.setBackgroundDrawable(transitionDrawable);
    }
    transitionDrawable.startTransition(target.targetCrossfadeSpeed);
}
Also used : TransitionDrawable(android.graphics.drawable.TransitionDrawable) ColorDrawable(android.graphics.drawable.ColorDrawable) ColorDrawable(android.graphics.drawable.ColorDrawable) Drawable(android.graphics.drawable.Drawable) TransitionDrawable(android.graphics.drawable.TransitionDrawable)

Example 85 with TransitionDrawable

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

the class BitmapLoader method bitmapHasBeenSet.

/**
 * 当前加载的图片已经绑定在ImageView上了
 *
 * @param imageView
 * @param url
 * @return
 */
public boolean bitmapHasBeenSet(ImageView imageView, String url) {
    if (imageView != null) {
        Drawable drawable = imageView.getDrawable();
        if (drawable != null) {
            if (drawable instanceof TransitionDrawable) {
                TransitionDrawable transitionDrawable = (TransitionDrawable) drawable;
                drawable = transitionDrawable.getDrawable(1);
            }
            if (drawable instanceof MyDrawable) {
                MyDrawable myDrawable = (MyDrawable) drawable;
                if (myDrawable.getMyBitmap() != null && url.equals(myDrawable.getMyBitmap().getUrl())) {
                    return true;
                }
            }
        }
    }
    return false;
}
Also used : TransitionDrawable(android.graphics.drawable.TransitionDrawable) 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) 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