/* * Copyright 2013 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.example.android.batchstepsensor.cardstream; import android.content.Context; import android.util.AttributeSet; import android.view.MotionEvent; import android.view.animation.BounceInterpolator; import android.view.animation.DecelerateInterpolator; import android.widget.Button; /** * Custom Button with a special 'pressed' effect for touch events. */ public class CardActionButton extends Button { public CardActionButton(Context context) { super(context); } public CardActionButton(Context context, AttributeSet attrs) { super(context, attrs); } public CardActionButton(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); } @Override public boolean onTouchEvent(MotionEvent event) { switch(event.getAction()){ case MotionEvent.ACTION_DOWN: setPressed(true); animate().scaleX(0.98f).scaleY(0.98f).alpha(0.8f).setDuration(100). setInterpolator(new DecelerateInterpolator()); break; case MotionEvent.ACTION_UP: animate().scaleX(1.0f).scaleY(1.f).alpha(1.0f).setDuration(50). setInterpolator(new BounceInterpolator()); break; case MotionEvent.ACTION_CANCEL: animate().scaleX(1.0f).scaleY(1.f).alpha(1.0f).setDuration(50). setInterpolator(new BounceInterpolator()); break; } return super.onTouchEvent(event); } }