From c20ed08b5b165392f30ac25b8df14744ac0059e1 Mon Sep 17 00:00:00 2001 From: amitjangid80 Date: Mon, 21 May 2018 11:57:57 +0530 Subject: [PATCH] Added bounce animation. Updated README.md --- README.md | 157 ++++++++++++++++-- app/src/main/java/com/amit/anim/AnimUtil.java | 31 +++- .../com/amit/anim/MyBounceInterpolator.java | 20 +++ app/src/main/res/anim/bounce.xml | 11 ++ 4 files changed, 205 insertions(+), 14 deletions(-) create mode 100644 app/src/main/java/com/amit/anim/MyBounceInterpolator.java create mode 100644 app/src/main/res/anim/bounce.xml diff --git a/README.md b/README.md index bbf1f51..b3ac7d0 100644 --- a/README.md +++ b/README.md @@ -8,7 +8,7 @@ >**Add it in your root build.gradle at the end of repositories:** -```markdown +``` allprojects{ repositories { ... @@ -19,16 +19,16 @@ allprojects{ #### Step 2. Add the dependency -```markdown +``` dependencies { ... - implementation 'com.github.amitjangid80:multiutillib:v1.2.6' + implementation 'com.github.amitjangid80:multiutillib:v1.2.7' } ``` #### Using maven: -```markdown +``` jitpack.io @@ -39,11 +39,11 @@ dependencies { #### Step 2. Add the dependency -```markdown +``` com.github.amitjangid80 multiutillib - v1.2.6 + v1.2.7 ``` @@ -75,7 +75,7 @@ public class ProjectApplication extends Application ### SharedPreferenceData -```markdown +```java // use it in the activity or class you want to. SharedPreferenceData sharedPreferenceData = new SharedPreferenceData(context); @@ -613,7 +613,7 @@ UiUtils.setMaxLength(textInputEditText, maxLength); **Usage** -```aidl +```java /** * is Sd Card Mounted * this method will check if sd card is mounted or not @@ -710,6 +710,143 @@ Utils.getSha512Hash(byte[] dataToHash); **Usage** -```aidl +```java + +// for making an activity slide from right to left +AnimUtil.slideActivityFromRightToLeft(context); + +// for making an activity slide from left to right +AnimUtil.slideActivityFromLeftToRight(context); + +// for making an activity slide from right to left +AnimUtil.slideActivityFromRightToLeft(context); + +// for making an activity fade in fade out +AnimUtil.activityFadeInFadeOut(context); + +// for making an activity from left with stay +AnimUtil.slideActivityFromLeftWithStay(context); + +// for making an activity from right with stay +AnimUtil.slideActivityFromRightWithStay(context); + +// for making an activity bottom with stay +AnimUtil.slideActivityFromBottomWithStay(context); + +// for making an activity from top with stay +AnimUtil.slideActivityFromUpWithStay(context); + +// for making an activity from bottom to up +AnimUtil.slideActivityFromBottomToUp(context); + +// for making an activity from up to bottom +AnimUtil.slideActivityFromUpToBottom(context); + +// for making an activity from up to bottom +AnimUtil.slideActivityFromUpToBottom(context); + +// this method will make an view group to explode or rise +AnimUtil.explodeTransition(Context context, ViewGroup viewGroup, int duration); + +// this method will make and view to slide from right +AnimUtil.slideAnimFromRight(@NonNull Context context, View view, int duration); + +// this method will make and view to slide from left +AnimUtil.slideAnimFromLeft(@NonNull Context context, View view, int duration); + +// Use your own animation in this method the way you want. +AnimUtil.slideAnim(@NonNull Context context, View view, int duration, @AnimRes int animResId); + +// Use this method to make a button or a view bounce +AnimUtil.bounceAnim(Context context, View view); +``` + +###Social Buttons + +>**Use Social buttons like you use normal button.** + +**Usage** + +```xml + + + + + + + + + + + + + + + + + + + +``` + +###Shine Button + +>**Type of like button with some color explosion.** + +**Usage** + +```xml + +``` -``` \ No newline at end of file diff --git a/app/src/main/java/com/amit/anim/AnimUtil.java b/app/src/main/java/com/amit/anim/AnimUtil.java index 9657909..009ed5f 100644 --- a/app/src/main/java/com/amit/anim/AnimUtil.java +++ b/app/src/main/java/com/amit/anim/AnimUtil.java @@ -161,7 +161,7 @@ public static void slideActivityFromUpWithStay(@NonNull Context context) * * @param context - context of the activity **/ - public static void slideFromBottomToUpAnim(@NonNull Context context) + public static void slideActivityFromBottomToUp(@NonNull Context context) { try { @@ -169,7 +169,7 @@ public static void slideFromBottomToUpAnim(@NonNull Context context) } catch (Exception e) { - Log.e(TAG, "slideFromBottomToUpAnim: exception while animating."); + Log.e(TAG, "slideActivityFromBottomToUp: exception while animating."); e.printStackTrace(); } } @@ -180,7 +180,7 @@ public static void slideFromBottomToUpAnim(@NonNull Context context) * * @param context - context of the activity **/ - public static void slideFromUpToBottomAnim(@NonNull Context context) + public static void slideActivityFromUpToBottom(@NonNull Context context) { try { @@ -188,7 +188,7 @@ public static void slideFromUpToBottomAnim(@NonNull Context context) } catch (Exception e) { - Log.e(TAG, "slideFromUpToBottomAnim: exception while animating."); + Log.e(TAG, "slideActivityFromUpToBottom: exception while animating."); e.printStackTrace(); } } @@ -311,4 +311,27 @@ public static void slideAnim(@NonNull Context context, e.printStackTrace(); } } + + /** + * Bounce anim method + * this method will make a view bounce + * + * @param context - context of the application + * @param view - view to animate + **/ + public static void bounceAnim(Context context, View view) + { + try + { + final Animation animation = AnimationUtils.loadAnimation(context, R.anim.bounce); + MyBounceInterpolator interpolator = new MyBounceInterpolator(0.2, 20); + animation.setInterpolator(interpolator); + view.startAnimation(animation); + } + catch (Exception e) + { + Log.e(TAG, "bounceAnim: exception while making bounce animation."); + e.printStackTrace(); + } + } } diff --git a/app/src/main/java/com/amit/anim/MyBounceInterpolator.java b/app/src/main/java/com/amit/anim/MyBounceInterpolator.java new file mode 100644 index 0000000..12eb602 --- /dev/null +++ b/app/src/main/java/com/amit/anim/MyBounceInterpolator.java @@ -0,0 +1,20 @@ +package com.amit.anim; + +import android.view.animation.Interpolator; + +class MyBounceInterpolator implements Interpolator +{ + private double mAmplitude = 1; + private double mFrequency = 10; + + MyBounceInterpolator(double amplitude, double frequency) + { + this.mAmplitude = amplitude; + this.mFrequency = frequency; + } + + public float getInterpolation(float time) + { + return (float) (-1 * Math.pow(Math.E, -time / mAmplitude) * Math.cos(mFrequency * time) + 1); + } +} diff --git a/app/src/main/res/anim/bounce.xml b/app/src/main/res/anim/bounce.xml new file mode 100644 index 0000000..2ad00cb --- /dev/null +++ b/app/src/main/res/anim/bounce.xml @@ -0,0 +1,11 @@ + + + +