|
/** |
|
* Copyright 2015 Karl Lindmark <[email protected]> |
|
* |
|
* 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. |
|
*/ |
|
|
|
public class AnimatedFloatingActionButton extends FloatingActionButton { |
|
private static final float MIN_SCALE = 0.0f; |
|
private static final float MAX_SCALE = 1.0f; |
|
private static final float ROTATION_OFFSET = 90; |
|
private static final long START_DELAY = 400L; |
|
private static final long ANIMATION_DURATION = 300L; |
|
|
|
public AnimatedFloatingActionButton(Context context) { |
|
super(context); |
|
} |
|
|
|
public AnimatedFloatingActionButton(Context context, AttributeSet attrs) { |
|
super(context, attrs); |
|
} |
|
|
|
public AnimatedFloatingActionButton(Context context, AttributeSet attrs, int defStyleAttr) { |
|
super(context, attrs, defStyleAttr); |
|
} |
|
|
|
public void showWithAnimation() { |
|
// Make sure the relevant values are "reset" |
|
setRotation(-ROTATION_OFFSET); |
|
setScaleX(MIN_SCALE); |
|
setScaleY(MIN_SCALE); |
|
|
|
animate().scaleX(MAX_SCALE) |
|
.scaleY(MAX_SCALE) |
|
.rotationBy(ROTATION_OFFSET) |
|
.setStartDelay(START_DELAY) |
|
.setDuration(ANIMATION_DURATION) |
|
.start(); |
|
} |
|
|
|
public void hideWithAnimation() { |
|
animate().scaleX(MIN_SCALE) |
|
.scaleY(MIN_SCALE) |
|
.rotationBy(-ROTATION_OFFSET) |
|
.setDuration(ANIMATION_DURATION) |
|
.start(); |
|
} |
|
} |