use of android.view.animation.AccelerateDecelerateInterpolator in project SwitchButton by kyleduo.
the class SwitchButton method init.
private void init(AttributeSet attrs) {
mTouchSlop = ViewConfiguration.get(getContext()).getScaledTouchSlop();
mClickTimeout = ViewConfiguration.getPressedStateDuration() + ViewConfiguration.getTapTimeout();
mPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
mRectPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
mRectPaint.setStyle(Paint.Style.STROKE);
mRectPaint.setStrokeWidth(getResources().getDisplayMetrics().density);
mTextPaint = getPaint();
mThumbRectF = new RectF();
mBackRectF = new RectF();
mSafeRectF = new RectF();
mThumbSizeF = new PointF();
mThumbMargin = new RectF();
mTextOnRectF = new RectF();
mTextOffRectF = new RectF();
mProcessAnimator = ObjectAnimator.ofFloat(this, "process", 0, 0).setDuration(DEFAULT_ANIMATION_DURATION);
mProcessAnimator.setInterpolator(new AccelerateDecelerateInterpolator());
mPresentThumbRectF = new RectF();
Resources res = getResources();
float density = res.getDisplayMetrics().density;
Drawable thumbDrawable = null;
ColorStateList thumbColor = null;
float margin = density * DEFAULT_THUMB_MARGIN_DP;
float marginLeft = 0;
float marginRight = 0;
float marginTop = 0;
float marginBottom = 0;
float thumbWidth = density * DEFAULT_THUMB_SIZE_DP;
float thumbHeight = density * DEFAULT_THUMB_SIZE_DP;
float thumbRadius = density * DEFAULT_THUMB_SIZE_DP / 2;
float backRadius = thumbRadius;
Drawable backDrawable = null;
ColorStateList backColor = null;
float backMeasureRatio = DEFAULT_BACK_MEASURE_RATIO;
int animationDuration = DEFAULT_ANIMATION_DURATION;
boolean fadeBack = true;
int tintColor = 0;
String textOn = null;
String textOff = null;
float textMarginH = density * DEFAULT_TEXT_MARGIN_DP;
boolean autoAdjustTextPosition = true;
TypedArray ta = attrs == null ? null : getContext().obtainStyledAttributes(attrs, R.styleable.SwitchButton);
if (ta != null) {
thumbDrawable = ta.getDrawable(R.styleable.SwitchButton_kswThumbDrawable);
thumbColor = ta.getColorStateList(R.styleable.SwitchButton_kswThumbColor);
margin = ta.getDimension(R.styleable.SwitchButton_kswThumbMargin, margin);
marginLeft = ta.getDimension(R.styleable.SwitchButton_kswThumbMarginLeft, margin);
marginRight = ta.getDimension(R.styleable.SwitchButton_kswThumbMarginRight, margin);
marginTop = ta.getDimension(R.styleable.SwitchButton_kswThumbMarginTop, margin);
marginBottom = ta.getDimension(R.styleable.SwitchButton_kswThumbMarginBottom, margin);
thumbWidth = ta.getDimension(R.styleable.SwitchButton_kswThumbWidth, thumbWidth);
thumbHeight = ta.getDimension(R.styleable.SwitchButton_kswThumbHeight, thumbHeight);
thumbRadius = ta.getDimension(R.styleable.SwitchButton_kswThumbRadius, Math.min(thumbWidth, thumbHeight) / 2.f);
backRadius = ta.getDimension(R.styleable.SwitchButton_kswBackRadius, thumbRadius + density * 2f);
backDrawable = ta.getDrawable(R.styleable.SwitchButton_kswBackDrawable);
backColor = ta.getColorStateList(R.styleable.SwitchButton_kswBackColor);
backMeasureRatio = ta.getFloat(R.styleable.SwitchButton_kswBackMeasureRatio, backMeasureRatio);
animationDuration = ta.getInteger(R.styleable.SwitchButton_kswAnimationDuration, animationDuration);
fadeBack = ta.getBoolean(R.styleable.SwitchButton_kswFadeBack, true);
tintColor = ta.getColor(R.styleable.SwitchButton_kswTintColor, tintColor);
textOn = ta.getString(R.styleable.SwitchButton_kswTextOn);
textOff = ta.getString(R.styleable.SwitchButton_kswTextOff);
textMarginH = Math.max(textMarginH, backRadius / 2);
textMarginH = ta.getDimension(R.styleable.SwitchButton_kswTextMarginH, textMarginH);
autoAdjustTextPosition = ta.getBoolean(R.styleable.SwitchButton_kswAutoAdjustTextPosition, autoAdjustTextPosition);
ta.recycle();
}
// click
ta = attrs == null ? null : getContext().obtainStyledAttributes(attrs, new int[] { android.R.attr.focusable, android.R.attr.clickable });
if (ta != null) {
boolean focusable = ta.getBoolean(0, true);
//noinspection ResourceType
boolean clickable = ta.getBoolean(1, focusable);
setFocusable(focusable);
setClickable(clickable);
ta.recycle();
}
// text
mTextOn = textOn;
mTextOff = textOff;
mTextMarginH = textMarginH;
mAutoAdjustTextPosition = autoAdjustTextPosition;
// thumb drawable and color
mThumbDrawable = thumbDrawable;
mThumbColor = thumbColor;
mIsThumbUseDrawable = mThumbDrawable != null;
mTintColor = tintColor;
if (mTintColor == 0) {
TypedValue typedValue = new TypedValue();
boolean found = getContext().getTheme().resolveAttribute(R.attr.colorAccent, typedValue, true);
if (found) {
mTintColor = typedValue.data;
} else {
mTintColor = DEFAULT_TINT_COLOR;
}
}
if (!mIsThumbUseDrawable && mThumbColor == null) {
mThumbColor = ColorUtils.generateThumbColorWithTintColor(mTintColor);
mCurrThumbColor = mThumbColor.getDefaultColor();
}
if (mIsThumbUseDrawable) {
thumbWidth = Math.max(thumbWidth, mThumbDrawable.getMinimumWidth());
thumbHeight = Math.max(thumbHeight, mThumbDrawable.getMinimumHeight());
}
mThumbSizeF.set(thumbWidth, thumbHeight);
// back drawable and color
mBackDrawable = backDrawable;
mBackColor = backColor;
mIsBackUseDrawable = mBackDrawable != null;
if (!mIsBackUseDrawable && mBackColor == null) {
mBackColor = ColorUtils.generateBackColorWithTintColor(mTintColor);
mCurrBackColor = mBackColor.getDefaultColor();
mNextBackColor = mBackColor.getColorForState(CHECKED_PRESSED_STATE, mCurrBackColor);
}
// margin
mThumbMargin.set(marginLeft, marginTop, marginRight, marginBottom);
// size & measure params must larger than 1
mBackMeasureRatio = mThumbMargin.width() >= 0 ? Math.max(backMeasureRatio, 1) : backMeasureRatio;
mThumbRadius = thumbRadius;
mBackRadius = backRadius;
mAnimationDuration = animationDuration;
mFadeBack = fadeBack;
mProcessAnimator.setDuration(mAnimationDuration);
// sync checked status
if (isChecked()) {
setProcess(1);
}
}
use of android.view.animation.AccelerateDecelerateInterpolator in project c-geo by just-radovan.
the class cgCacheListAdapter method moveLeft.
private void moveLeft(cgCacheView holder, cgCache cache, boolean force) {
if (cache == null) {
return;
}
try {
holder.checkbox.setChecked(cache.statusChecked);
// slide cache info
Animation hideCheckbox = new TranslateAnimation((int) (SWIPE_DISTANCE * pixelDensity), 0, 0, 0);
hideCheckbox.setRepeatCount(0);
if (force == true) {
hideCheckbox.setDuration(0);
} else {
hideCheckbox.setDuration(400);
}
hideCheckbox.setFillEnabled(true);
hideCheckbox.setFillAfter(true);
hideCheckbox.setInterpolator(new AccelerateDecelerateInterpolator());
// brighten cache info
Animation brightenInfo = new AlphaAnimation(SWIPE_OPACITY, 1.0f);
brightenInfo.setRepeatCount(0);
if (force == true) {
brightenInfo.setDuration(0);
} else {
brightenInfo.setDuration(400);
}
brightenInfo.setFillEnabled(true);
brightenInfo.setFillAfter(true);
brightenInfo.setInterpolator(new AccelerateDecelerateInterpolator());
// animation set (container)
AnimationSet selectAnimation = new AnimationSet(true);
selectAnimation.setFillEnabled(true);
selectAnimation.setFillAfter(true);
selectAnimation.addAnimation(hideCheckbox);
selectAnimation.addAnimation(brightenInfo);
holder.oneInfo.startAnimation(selectAnimation);
cache.statusCheckedView = false;
} catch (Exception e) {
// nothing
}
}
use of android.view.animation.AccelerateDecelerateInterpolator in project c-geo by just-radovan.
the class cgCacheListAdapter method moveRight.
private void moveRight(cgCacheView holder, cgCache cache, boolean force) {
if (cache == null) {
return;
}
try {
holder.checkbox.setChecked(cache.statusChecked);
// slide cache info
Animation showCheckbox = new TranslateAnimation(0, (int) (SWIPE_DISTANCE * pixelDensity), 0, 0);
showCheckbox.setRepeatCount(0);
if (force == true) {
showCheckbox.setDuration(0);
} else {
showCheckbox.setDuration(400);
}
showCheckbox.setFillEnabled(true);
showCheckbox.setFillAfter(true);
showCheckbox.setInterpolator(new AccelerateDecelerateInterpolator());
// dim cache info
Animation dimInfo = new AlphaAnimation(1.0f, SWIPE_OPACITY);
dimInfo.setRepeatCount(0);
if (force == true) {
dimInfo.setDuration(0);
} else {
dimInfo.setDuration(400);
}
dimInfo.setFillEnabled(true);
dimInfo.setFillAfter(true);
dimInfo.setInterpolator(new AccelerateDecelerateInterpolator());
// animation set (container)
AnimationSet selectAnimation = new AnimationSet(true);
selectAnimation.setFillEnabled(true);
selectAnimation.setFillAfter(true);
selectAnimation.addAnimation(showCheckbox);
selectAnimation.addAnimation(dimInfo);
holder.oneInfo.startAnimation(selectAnimation);
cache.statusCheckedView = true;
} catch (Exception e) {
// nothing
}
}
use of android.view.animation.AccelerateDecelerateInterpolator in project VirtualApp by asLody.
the class RippleButton method onTouchEvent.
@Override
public boolean onTouchEvent(final MotionEvent event) {
Log.d("TouchEvent", String.valueOf(event.getActionMasked()));
Log.d("mIsAnimating", String.valueOf(mIsAnimating));
Log.d("mAnimationIsCancel", String.valueOf(mAnimationIsCancel));
boolean superResult = super.onTouchEvent(event);
if (event.getActionMasked() == MotionEvent.ACTION_DOWN && this.isEnabled() && mHover) {
mRect = new Rect(getLeft(), getTop(), getRight(), getBottom());
mAnimationIsCancel = false;
mDownX = event.getX();
mDownY = event.getY();
mRadiusAnimator = ObjectAnimator.ofFloat(this, "radius", 0, dp(50)).setDuration(400);
mRadiusAnimator.setInterpolator(new AccelerateDecelerateInterpolator());
mRadiusAnimator.addListener(new Animator.AnimatorListener() {
@Override
public void onAnimationStart(Animator animator) {
mIsAnimating = true;
}
@Override
public void onAnimationEnd(Animator animator) {
setRadius(0);
ViewHelper.setAlpha(RippleButton.this, 1);
mIsAnimating = false;
}
@Override
public void onAnimationCancel(Animator animator) {
}
@Override
public void onAnimationRepeat(Animator animator) {
}
});
mRadiusAnimator.start();
if (!superResult) {
return true;
}
} else if (event.getActionMasked() == MotionEvent.ACTION_MOVE && this.isEnabled() && mHover) {
mDownX = event.getX();
mDownY = event.getY();
// Cancel the ripple animation when moved outside
if (mAnimationIsCancel = !mRect.contains(getLeft() + (int) event.getX(), getTop() + (int) event.getY())) {
setRadius(0);
} else {
setRadius(dp(50));
}
if (!superResult) {
return true;
}
} else if (event.getActionMasked() == MotionEvent.ACTION_UP && !mAnimationIsCancel && this.isEnabled()) {
mDownX = event.getX();
mDownY = event.getY();
final float tempRadius = (float) Math.sqrt(mDownX * mDownX + mDownY * mDownY);
float targetRadius = Math.max(tempRadius, mMaxRadius);
if (mIsAnimating) {
mRadiusAnimator.cancel();
}
mRadiusAnimator = ObjectAnimator.ofFloat(this, "radius", dp(50), targetRadius);
mRadiusAnimator.setDuration(500);
mRadiusAnimator.setInterpolator(new AccelerateDecelerateInterpolator());
mRadiusAnimator.addListener(new Animator.AnimatorListener() {
@Override
public void onAnimationStart(Animator animator) {
mIsAnimating = true;
}
@Override
public void onAnimationEnd(Animator animator) {
setRadius(0);
ViewHelper.setAlpha(RippleButton.this, 1);
mIsAnimating = false;
}
@Override
public void onAnimationCancel(Animator animator) {
}
@Override
public void onAnimationRepeat(Animator animator) {
}
});
mRadiusAnimator.start();
if (!superResult) {
return true;
}
}
return superResult;
}
use of android.view.animation.AccelerateDecelerateInterpolator in project NotBoringActionBar by flavienlaurent.
the class NoBoringActionBarActivity method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mSmoothInterpolator = new AccelerateDecelerateInterpolator();
mHeaderHeight = getResources().getDimensionPixelSize(R.dimen.header_height);
mMinHeaderTranslation = -mHeaderHeight + getActionBarHeight();
setContentView(R.layout.activity_noboringactionbar);
mListView = (ListView) findViewById(R.id.listview);
mHeader = findViewById(R.id.header);
mHeaderPicture = (KenBurnsView) findViewById(R.id.header_picture);
mHeaderPicture.setResourceIds(R.drawable.picture0, R.drawable.picture1);
mHeaderLogo = (ImageView) findViewById(R.id.header_logo);
mActionBarTitleColor = getResources().getColor(R.color.actionbar_title_color);
mSpannableString = new SpannableString(getString(R.string.noboringactionbar_title));
mAlphaForegroundColorSpan = new AlphaForegroundColorSpan(mActionBarTitleColor);
setupActionBar();
setupListView();
}
Aggregations