Java Code Examples for android.graphics.drawable.TransitionDrawable#reverseTransition()

The following examples show how to use android.graphics.drawable.TransitionDrawable#reverseTransition() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ActivityMain.java    From Clip-Stack with MIT License 6 votes vote down vote up
private void onStarredMenuClicked() {
    isStarred = !isStarred;
    mFabRotation(isStarred, TRANSLATION_SLOW);
    setStarredIcon();
    lastStorageUpdate = null;
    setView();
    final TransitionDrawable mFabBackground = (TransitionDrawable) mFAB.getBackground();
    if (isStarred) {
        mFabBackground.startTransition((int) mFAB.animate().getDuration());
    } else {
        mFabBackground.reverseTransition((int) mFAB.animate().getDuration());
    }
    new Handler().postDelayed(new Runnable() {
        @Override
        public void run() {
            mFAB.setImageResource(isStarred ?
                            R.drawable.ic_action_star_white
                            :
                            R.drawable.ic_action_add
            );
        }
    }, TRANSLATION_SLOW / 3 * 2);
}
 
Example 2
Source File: ToolbarPhone.java    From delion with Apache License 2.0 5 votes vote down vote up
@Override
public void onUrlFocusChange(final boolean hasFocus) {
    super.onUrlFocusChange(hasFocus);

    triggerUrlFocusAnimation(hasFocus);

    TransitionDrawable shadowDrawable = (TransitionDrawable) mToolbarShadow.getDrawable();
    if (hasFocus) {
        dismissTabSwitcherCallout();
        shadowDrawable.startTransition(URL_FOCUS_CHANGE_ANIMATION_DURATION_MS);
    } else {
        shadowDrawable.reverseTransition(URL_FOCUS_CHANGE_ANIMATION_DURATION_MS);
    }
}
 
Example 3
Source File: ToolbarPhone.java    From delion with Apache License 2.0 5 votes vote down vote up
@Override
protected void handleFindToolbarStateChange(boolean showing) {
    setVisibility(showing ? View.GONE : View.VISIBLE);
    TransitionDrawable shadowDrawable = (TransitionDrawable) mToolbarShadow.getDrawable();
    if (showing) {
        shadowDrawable.startTransition(URL_FOCUS_CHANGE_ANIMATION_DURATION_MS);
    } else {
        shadowDrawable.reverseTransition(URL_FOCUS_CHANGE_ANIMATION_DURATION_MS);
    }
}
 
Example 4
Source File: ToolbarPhone.java    From AndroidChromium with Apache License 2.0 5 votes vote down vote up
@Override
public void onUrlFocusChange(final boolean hasFocus) {
    super.onUrlFocusChange(hasFocus);

    triggerUrlFocusAnimation(hasFocus);

    TransitionDrawable shadowDrawable = (TransitionDrawable) mToolbarShadow.getDrawable();
    if (hasFocus) {
        dismissTabSwitcherCallout();
        shadowDrawable.startTransition(URL_FOCUS_CHANGE_ANIMATION_DURATION_MS);
    } else {
        shadowDrawable.reverseTransition(URL_FOCUS_CHANGE_ANIMATION_DURATION_MS);
    }
}
 
Example 5
Source File: ToolbarPhone.java    From AndroidChromium with Apache License 2.0 5 votes vote down vote up
@Override
protected void handleFindToolbarStateChange(boolean showing) {
    setVisibility(showing ? View.GONE : View.VISIBLE);
    TransitionDrawable shadowDrawable = (TransitionDrawable) mToolbarShadow.getDrawable();
    if (showing) {
        shadowDrawable.startTransition(URL_FOCUS_CHANGE_ANIMATION_DURATION_MS);
    } else {
        shadowDrawable.reverseTransition(URL_FOCUS_CHANGE_ANIMATION_DURATION_MS);
    }
}
 
Example 6
Source File: ToolbarPhone.java    From 365browser with Apache License 2.0 5 votes vote down vote up
@Override
public void onUrlFocusChange(final boolean hasFocus) {
    super.onUrlFocusChange(hasFocus);

    triggerUrlFocusAnimation(hasFocus);

    TransitionDrawable shadowDrawable = (TransitionDrawable) mToolbarShadow.getDrawable();
    if (hasFocus) {
        dismissTabSwitcherCallout();
        shadowDrawable.startTransition(URL_FOCUS_CHANGE_ANIMATION_DURATION_MS);
    } else {
        shadowDrawable.reverseTransition(URL_FOCUS_CHANGE_ANIMATION_DURATION_MS);
    }
}
 
Example 7
Source File: ToolbarPhone.java    From 365browser with Apache License 2.0 5 votes vote down vote up
@Override
protected void handleFindToolbarStateChange(boolean showing) {
    setVisibility(showing ? View.GONE : View.VISIBLE);
    TransitionDrawable shadowDrawable = (TransitionDrawable) mToolbarShadow.getDrawable();
    if (showing) {
        shadowDrawable.startTransition(URL_FOCUS_CHANGE_ANIMATION_DURATION_MS);
    } else {
        shadowDrawable.reverseTransition(URL_FOCUS_CHANGE_ANIMATION_DURATION_MS);
    }
}
 
Example 8
Source File: DefaultChatHeadManager.java    From springy-heads with Apache License 2.0 5 votes vote down vote up
@Override
public void hideOverlayView(boolean animated) {
    if (overlayVisible) {
        TransitionDrawable drawable = (TransitionDrawable) overlayView.getBackground();
        int duration = OVERLAY_TRANSITION_DURATION;
        if (!animated) duration = 0;
        drawable.reverseTransition(duration);
        overlayView.setClickable(false);
        overlayVisible = false;
    }
}
 
Example 9
Source File: SegmentedGroup.java    From SSForms with GNU General Public License v3.0 4 votes vote down vote up
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);
            }
        }
    });
}