103 lines
4 KiB
Java
103 lines
4 KiB
Java
/*
|
|
* Copyright (C) 2017 Schürmann & Breitmoser GbR
|
|
*
|
|
* This program is free software: you can redistribute it and/or modify
|
|
* it under the terms of the GNU General Public License as published by
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
* (at your option) any later version.
|
|
*
|
|
* This program is distributed in the hope that it will be useful,
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
* GNU General Public License for more details.
|
|
*
|
|
* You should have received a copy of the GNU General Public License
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
*/
|
|
|
|
package org.sufficientlysecure.keychain.ui.util;
|
|
|
|
import android.animation.Keyframe;
|
|
import android.animation.ObjectAnimator;
|
|
import android.animation.PropertyValuesHolder;
|
|
import android.annotation.TargetApi;
|
|
import android.os.Build.VERSION_CODES;
|
|
import android.view.View;
|
|
|
|
@TargetApi(VERSION_CODES.ICE_CREAM_SANDWICH)
|
|
/** Simple animation helper for subtle attention seeker stuff.
|
|
*
|
|
* Code borrowed from Cyril Mottier: https://plus.google.com/+CyrilMottier/posts/FABaJhRMCuy
|
|
*/
|
|
public class SubtleAttentionSeeker {
|
|
|
|
public static ObjectAnimator tada(View view) {
|
|
return tada(view, 1f);
|
|
}
|
|
|
|
public static ObjectAnimator tada(View view, float shakeFactor) {
|
|
return tada(view, shakeFactor, 1400);
|
|
}
|
|
|
|
public static ObjectAnimator tada(View view, float shakeFactor, int duration) {
|
|
|
|
PropertyValuesHolder pvhScaleX = PropertyValuesHolder.ofKeyframe(View.SCALE_X,
|
|
Keyframe.ofFloat(0f, 1f),
|
|
Keyframe.ofFloat(.1f, .9f),
|
|
Keyframe.ofFloat(.2f, .9f),
|
|
Keyframe.ofFloat(.3f, 1.1f),
|
|
Keyframe.ofFloat(.4f, 1.1f),
|
|
Keyframe.ofFloat(.5f, 1.1f),
|
|
Keyframe.ofFloat(.6f, 1.1f),
|
|
Keyframe.ofFloat(.7f, 1.1f),
|
|
Keyframe.ofFloat(.8f, 1.1f),
|
|
Keyframe.ofFloat(.9f, 1.1f),
|
|
Keyframe.ofFloat(1f, 1f)
|
|
);
|
|
|
|
PropertyValuesHolder pvhScaleY = PropertyValuesHolder.ofKeyframe(View.SCALE_Y,
|
|
Keyframe.ofFloat(0f, 1f),
|
|
Keyframe.ofFloat(.1f, .9f),
|
|
Keyframe.ofFloat(.2f, .9f),
|
|
Keyframe.ofFloat(.3f, 1.1f),
|
|
Keyframe.ofFloat(.4f, 1.1f),
|
|
Keyframe.ofFloat(.5f, 1.1f),
|
|
Keyframe.ofFloat(.6f, 1.1f),
|
|
Keyframe.ofFloat(.7f, 1.1f),
|
|
Keyframe.ofFloat(.8f, 1.1f),
|
|
Keyframe.ofFloat(.9f, 1.1f),
|
|
Keyframe.ofFloat(1f, 1f)
|
|
);
|
|
|
|
PropertyValuesHolder pvhRotate = PropertyValuesHolder.ofKeyframe(View.ROTATION,
|
|
Keyframe.ofFloat(0f, 0f),
|
|
Keyframe.ofFloat(.1f, -3f * shakeFactor),
|
|
Keyframe.ofFloat(.2f, -3f * shakeFactor),
|
|
Keyframe.ofFloat(.3f, 3f * shakeFactor),
|
|
Keyframe.ofFloat(.4f, -3f * shakeFactor),
|
|
Keyframe.ofFloat(.5f, 3f * shakeFactor),
|
|
Keyframe.ofFloat(.6f, -3f * shakeFactor),
|
|
Keyframe.ofFloat(.7f, 3f * shakeFactor),
|
|
Keyframe.ofFloat(.8f, -3f * shakeFactor),
|
|
Keyframe.ofFloat(.9f, 3f * shakeFactor),
|
|
Keyframe.ofFloat(1f, 0)
|
|
);
|
|
|
|
return ObjectAnimator.ofPropertyValuesHolder(view, pvhScaleX, pvhScaleY, pvhRotate).
|
|
setDuration(duration);
|
|
}
|
|
|
|
@TargetApi(VERSION_CODES.LOLLIPOP)
|
|
public static ObjectAnimator tintBackground(View view, int duration) {
|
|
return ObjectAnimator.ofArgb(view, "backgroundColor",
|
|
0x00FF0000, 0x33FF0000, 0x00FF0000).setDuration(duration);
|
|
}
|
|
|
|
@TargetApi(VERSION_CODES.LOLLIPOP)
|
|
public static ObjectAnimator tintText(View view, int duration) {
|
|
return ObjectAnimator.ofArgb(view, "backgroundColor",
|
|
0x00FF7F00, 0x33FF7F00, 0x00FF7F00).setDuration(duration);
|
|
}
|
|
|
|
}
|