diff --git a/app/build.gradle b/app/build.gradle index 9d0e7a8..11f746f 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -2,7 +2,7 @@ apply plugin: 'com.android.application' android { compileSdkVersion 25 - buildToolsVersion "25.0.2" + buildToolsVersion '27.0.3' defaultConfig { applicationId "com.sdsmdg.demoexample" diff --git a/build.gradle b/build.gradle index 23295be..ff5abe0 100644 --- a/build.gradle +++ b/build.gradle @@ -3,9 +3,10 @@ buildscript { repositories { jcenter() + google() } dependencies { - classpath 'com.android.tools.build:gradle:2.3.0' + classpath 'com.android.tools.build:gradle:3.1.3' classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.0' classpath 'com.github.dcendents:android-maven-gradle-plugin:1.4.1' diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 52a8df0..5b48cad 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ -#Wed Mar 29 23:08:30 IST 2017 +#Sun Jun 24 13:41:26 IST 2018 distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-3.3-all.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-4.4-all.zip diff --git a/tastytoast/build.gradle b/tastytoast/build.gradle index 873bc74..f2f5222 100644 --- a/tastytoast/build.gradle +++ b/tastytoast/build.gradle @@ -2,7 +2,7 @@ apply plugin: 'com.android.library' android { compileSdkVersion 25 - buildToolsVersion "25.0.2" + buildToolsVersion '27.0.3' defaultConfig { minSdkVersion 11 diff --git a/tastytoast/src/main/java/com/sdsmdg/tastytoast/ConfusingToastView.java b/tastytoast/src/main/java/com/sdsmdg/tastytoast/ConfusingToastView.java index aebfa05..9c5ed8d 100644 --- a/tastytoast/src/main/java/com/sdsmdg/tastytoast/ConfusingToastView.java +++ b/tastytoast/src/main/java/com/sdsmdg/tastytoast/ConfusingToastView.java @@ -38,12 +38,13 @@ public ConfusingToastView(Context context, AttributeSet attrs, int defStyleAttr) } @Override - protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { - super.onMeasure(widthMeasureSpec, heightMeasureSpec); + protected void onSizeChanged(int w, int h, int oldw, int oldh) { + super.onSizeChanged(w, h, oldw, oldh); mWidth = getMeasuredWidth(); mHeight = getMeasuredHeight(); initPaint(); initPath(); + startAnim(); } private void initPaint() { @@ -111,8 +112,6 @@ private ValueAnimator startViewAnim(float startF, final float endF, long time) { valueAnimator = ValueAnimator.ofFloat(startF, endF); valueAnimator.setDuration(time); valueAnimator.setInterpolator(new LinearInterpolator()); - valueAnimator.setRepeatCount(ValueAnimator.INFINITE); - valueAnimator.setRepeatMode(ValueAnimator.RESTART); valueAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { @Override public void onAnimationUpdate(ValueAnimator valueAnimator) { diff --git a/tastytoast/src/main/java/com/sdsmdg/tastytoast/DefaultToastView.java b/tastytoast/src/main/java/com/sdsmdg/tastytoast/DefaultToastView.java index 35dff56..526f95c 100644 --- a/tastytoast/src/main/java/com/sdsmdg/tastytoast/DefaultToastView.java +++ b/tastytoast/src/main/java/com/sdsmdg/tastytoast/DefaultToastView.java @@ -35,11 +35,12 @@ public DefaultToastView(Context context, AttributeSet attrs, int defStyleAttr) { } @Override - protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { - super.onMeasure(widthMeasureSpec, heightMeasureSpec); - initPaint(); + protected void onSizeChanged(int w, int h, int oldw, int oldh) { + super.onSizeChanged(w, h, oldw, oldh); mWidth = getMeasuredWidth(); mPadding = dip2px(5); + initPaint(); + startAnim(); } private void initPaint() { @@ -96,8 +97,6 @@ private ValueAnimator startViewAnim(float startF, final float endF, long time) { valueAnimator = ValueAnimator.ofFloat(startF, endF); valueAnimator.setDuration(time); valueAnimator.setInterpolator(new LinearInterpolator()); - valueAnimator.setRepeatCount(ValueAnimator.INFINITE); - valueAnimator.setRepeatMode(ValueAnimator.RESTART); valueAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { @Override public void onAnimationUpdate(ValueAnimator valueAnimator) { diff --git a/tastytoast/src/main/java/com/sdsmdg/tastytoast/ErrorToastView.java b/tastytoast/src/main/java/com/sdsmdg/tastytoast/ErrorToastView.java index 6a8f260..0026a48 100644 --- a/tastytoast/src/main/java/com/sdsmdg/tastytoast/ErrorToastView.java +++ b/tastytoast/src/main/java/com/sdsmdg/tastytoast/ErrorToastView.java @@ -42,13 +42,14 @@ public ErrorToastView(Context context, AttributeSet attrs, int defStyleAttr) { } @Override - protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { - super.onMeasure(widthMeasureSpec, heightMeasureSpec); - initPaint(); - initRect(); + protected void onSizeChanged(int w, int h, int oldw, int oldh) { + super.onSizeChanged(w, h, oldw, oldh); mWidth = getMeasuredWidth(); mPadding = dip2px(10); mEyeWidth = dip2px(3); + initPaint(); + initRect(); + startAnim(); } private void initPaint() { diff --git a/tastytoast/src/main/java/com/sdsmdg/tastytoast/InfoToastView.java b/tastytoast/src/main/java/com/sdsmdg/tastytoast/InfoToastView.java index 99a3c34..34995aa 100644 --- a/tastytoast/src/main/java/com/sdsmdg/tastytoast/InfoToastView.java +++ b/tastytoast/src/main/java/com/sdsmdg/tastytoast/InfoToastView.java @@ -42,14 +42,15 @@ public InfoToastView(Context context, AttributeSet attrs, int defStyleAttr) { } @Override - protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { - super.onMeasure(widthMeasureSpec, heightMeasureSpec); - initPaint(); - initRect(); + protected void onSizeChanged(int w, int h, int oldw, int oldh) { + super.onSizeChanged(w, h, oldw, oldh); mWidth = getMeasuredWidth(); mPadding = dip2px(10); mEyeWidth = dip2px(3); endPoint = mPadding; + initPaint(); + initRect(); + startAnim(); } private void initPaint() { diff --git a/tastytoast/src/main/java/com/sdsmdg/tastytoast/SuccessToastView.java b/tastytoast/src/main/java/com/sdsmdg/tastytoast/SuccessToastView.java index 2f887e1..b9bebdb 100644 --- a/tastytoast/src/main/java/com/sdsmdg/tastytoast/SuccessToastView.java +++ b/tastytoast/src/main/java/com/sdsmdg/tastytoast/SuccessToastView.java @@ -39,13 +39,15 @@ public SuccessToastView(Context context, AttributeSet attrs, int defStyleAttr) { } @Override - protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { - super.onMeasure(widthMeasureSpec, heightMeasureSpec); - initPaint(); - initRect(); + protected void onSizeChanged(int w, int h, int oldw, int oldh) { + super.onSizeChanged(w, h, oldw, oldh); + mWidth = getMeasuredWidth(); mPadding = dip2px(10); mEyeWidth = dip2px(3); + initPaint(); + initRect(); + startAnim(); } private void initPaint() { diff --git a/tastytoast/src/main/java/com/sdsmdg/tastytoast/TastyToast.java b/tastytoast/src/main/java/com/sdsmdg/tastytoast/TastyToast.java index bdb7400..4800274 100644 --- a/tastytoast/src/main/java/com/sdsmdg/tastytoast/TastyToast.java +++ b/tastytoast/src/main/java/com/sdsmdg/tastytoast/TastyToast.java @@ -7,11 +7,6 @@ import android.widget.TextView; import android.widget.Toast; -import com.facebook.rebound.SimpleSpringListener; -import com.facebook.rebound.Spring; -import com.facebook.rebound.SpringConfig; -import com.facebook.rebound.SpringSystem; - /** * Created by rahul on 28/7/16. */ @@ -27,13 +22,6 @@ public class TastyToast { public static final int DEFAULT = 5; public static final int CONFUSING = 6; - static SuccessToastView successToastView; - static WarningToastView warningToastView; - static ErrorToastView errorToastView; - static InfoToastView infoToastView; - static DefaultToastView defaultToastView; - static ConfusingToastView confusingToastView; - public static Toast makeText(Context context, String msg, int length, int type) { Toast toast = new Toast(context); @@ -42,13 +30,13 @@ public static Toast makeText(Context context, String msg, int length, int type) switch (type) { case 1: { View layout = LayoutInflater.from(context).inflate(R.layout.success_toast_layout, null, false); + TextView text = (TextView) layout.findViewById(R.id.toastMessage); text.setText(msg); - successToastView = (SuccessToastView) layout.findViewById(R.id.successView); - successToastView.startAnim(); text.setBackgroundResource(R.drawable.success_toast); text.setTextColor(Color.parseColor("#FFFFFF")); toast.setView(layout); + layout.findViewById(R.id.successView); break; } case 2: { @@ -56,39 +44,10 @@ public static Toast makeText(Context context, String msg, int length, int type) TextView text = (TextView) layout.findViewById(R.id.toastMessage); text.setText(msg); - - warningToastView = (WarningToastView) layout.findViewById(R.id.warningView); - SpringSystem springSystem = SpringSystem.create(); - final Spring spring = springSystem.createSpring(); - spring.setCurrentValue(1.8); - SpringConfig config = new SpringConfig(40, 5); - spring.setSpringConfig(config); - spring.addListener(new SimpleSpringListener() { - - @Override - public void onSpringUpdate(Spring spring) { - float value = (float) spring.getCurrentValue(); - float scale = (float) (0.9f - (value * 0.5f)); - - warningToastView.setScaleX(scale); - warningToastView.setScaleY(scale); - } - }); - Thread t = new Thread(new Runnable() { - @Override - public void run() { - try { - Thread.sleep(500); - } catch (InterruptedException e) { - } - spring.setEndValue(0.4f); - } - }); - - t.start(); text.setBackgroundResource(R.drawable.warning_toast); text.setTextColor(Color.parseColor("#FFFFFF")); toast.setView(layout); + layout.findViewById(R.id.warningView); break; } case 3: { @@ -96,11 +55,10 @@ public void run() { TextView text = (TextView) layout.findViewById(R.id.toastMessage); text.setText(msg); - errorToastView = (ErrorToastView) layout.findViewById(R.id.errorView); - errorToastView.startAnim(); text.setBackgroundResource(R.drawable.error_toast); text.setTextColor(Color.parseColor("#FFFFFF")); toast.setView(layout); + layout.findViewById(R.id.errorView); break; } case 4: { @@ -108,11 +66,10 @@ public void run() { TextView text = (TextView) layout.findViewById(R.id.toastMessage); text.setText(msg); - infoToastView = (InfoToastView) layout.findViewById(R.id.infoView); - infoToastView.startAnim(); text.setBackgroundResource(R.drawable.info_toast); text.setTextColor(Color.parseColor("#FFFFFF")); toast.setView(layout); + layout.findViewById(R.id.infoView); break; } case 5: { @@ -120,11 +77,10 @@ public void run() { TextView text = (TextView) layout.findViewById(R.id.toastMessage); text.setText(msg); - defaultToastView = (DefaultToastView) layout.findViewById(R.id.defaultView); - defaultToastView.startAnim(); text.setBackgroundResource(R.drawable.default_toast); text.setTextColor(Color.parseColor("#FFFFFF")); toast.setView(layout); + layout.findViewById(R.id.defaultView); break; } case 6: { @@ -132,11 +88,10 @@ public void run() { TextView text = (TextView) layout.findViewById(R.id.toastMessage); text.setText(msg); - confusingToastView = (ConfusingToastView) layout.findViewById(R.id.confusingView); - confusingToastView.startAnim(); text.setBackgroundResource(R.drawable.confusing_toast); text.setTextColor(Color.parseColor("#FFFFFF")); toast.setView(layout); + layout.findViewById(R.id.confusingView); break; } } diff --git a/tastytoast/src/main/java/com/sdsmdg/tastytoast/WarningToastView.java b/tastytoast/src/main/java/com/sdsmdg/tastytoast/WarningToastView.java index 6fa38eb..511062d 100644 --- a/tastytoast/src/main/java/com/sdsmdg/tastytoast/WarningToastView.java +++ b/tastytoast/src/main/java/com/sdsmdg/tastytoast/WarningToastView.java @@ -9,6 +9,11 @@ import android.util.DisplayMetrics; import android.view.View; +import com.facebook.rebound.SimpleSpringListener; +import com.facebook.rebound.Spring; +import com.facebook.rebound.SpringConfig; +import com.facebook.rebound.SpringSystem; + /** * Created by rahul on 25/7/16. */ @@ -39,15 +44,17 @@ public WarningToastView(Context context, AttributeSet attrs, int defStyleAttr) { } @Override - protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { - super.onMeasure(widthMeasureSpec, heightMeasureSpec); - initPaint(); - initRect(); + protected void onSizeChanged(int w, int h, int oldw, int oldh) { + super.onSizeChanged(w, h, oldw, oldh); + mHeight = getMeasuredHeight(); mWidth = getMeasuredWidth(); mPadding = convertDpToPixel(2); mPaddingBottom = mPadding * 2; mStrokeWidth = convertDpToPixel(2); + initPaint(); + initRect(); + startAnim(); } private void initPaint() { @@ -66,6 +73,37 @@ private void initRect() { mHeight / 3, mPadding + convertDpToPixel(18), convertDpToPixel(3) + mPadding + mHeight / 2); } + private void startAnim(){ + SpringSystem springSystem = SpringSystem.create(); + final Spring spring = springSystem.createSpring(); + spring.setCurrentValue(1.8); + SpringConfig config = new SpringConfig(40, 5); + spring.setSpringConfig(config); + spring.addListener(new SimpleSpringListener() { + + @Override + public void onSpringUpdate(Spring spring) { + float value = (float) spring.getCurrentValue(); + float scale = (float) (0.9f - (value * 0.5f)); + + setScaleX(scale); + setScaleY(scale); + } + }); + Thread t = new Thread(new Runnable() { + @Override + public void run() { + try { + Thread.sleep(500); + } catch (InterruptedException e) { + } + spring.setEndValue(0.4f); + } + }); + + t.start(); + + } @Override protected void onDraw(Canvas canvas) { super.onDraw(canvas);