Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

successive animation bug solved #34

Open
wants to merge 1 commit into
base: lib
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
3 changes: 2 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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'

Expand Down
4 changes: 2 additions & 2 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion tastytoast/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ apply plugin: 'com.android.library'

android {
compileSdkVersion 25
buildToolsVersion "25.0.2"
buildToolsVersion '27.0.3'

defaultConfig {
minSdkVersion 11
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
59 changes: 7 additions & 52 deletions tastytoast/src/main/java/com/sdsmdg/tastytoast/TastyToast.java
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand All @@ -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);
Expand All @@ -42,101 +30,68 @@ 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: {
View layout = LayoutInflater.from(context).inflate(R.layout.warning_toast_layout, null, false);

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: {
View layout = LayoutInflater.from(context).inflate(R.layout.error_toast_layout, null, false);

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: {
View layout = LayoutInflater.from(context).inflate(R.layout.info_toast_layout, null, false);

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: {
View layout = LayoutInflater.from(context).inflate(R.layout.default_toast_layout, null, false);

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: {
View layout = LayoutInflater.from(context).inflate(R.layout.confusing_toast_layout, null, false);

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;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand Down Expand Up @@ -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() {
Expand All @@ -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);
Expand Down