Skip to content

Commit

Permalink
added a color parameter in tasty toast
Browse files Browse the repository at this point in the history
  • Loading branch information
pkarira committed Apr 4, 2017
1 parent 5c728d2 commit 67b3c3b
Show file tree
Hide file tree
Showing 8 changed files with 42 additions and 22 deletions.
14 changes: 8 additions & 6 deletions app/src/main/java/com/sdsmdg/demoexample/MainActivity.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.sdsmdg.demoexample;

import android.graphics.Color;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
Expand All @@ -21,31 +22,32 @@ protected void onCreate(Bundle savedInstanceState) {

public void showSuccessToast(View view) {
TastyToast.makeText(getApplicationContext(), "Download Successful !", TastyToast.LENGTH_LONG,
TastyToast.SUCCESS);
TastyToast.SUCCESS, Color.parseColor("#FE9D4D"));
}

public void showWarningToast(View view) {
TastyToast.makeText(getApplicationContext(), "Are you sure ?", TastyToast.LENGTH_LONG,
TastyToast.WARNING);
TastyToast.WARNING, Color.parseColor("#FE9D4D"));
}

public void showErrorToast(View view) {
TastyToast.makeText(getApplicationContext(), "Downloading failed ! Try again later ", TastyToast.LENGTH_LONG,
TastyToast.ERROR);
TastyToast.ERROR, Color.parseColor("#FE9D4D"));
}

public void showInfoToast(View view) {
TastyToast.makeText(getApplicationContext(), "Searching for username : 'Rahul' ", TastyToast.LENGTH_LONG,
TastyToast.INFO);
TastyToast.INFO, Color.parseColor("#FE9D4D"));
}

public void showDefaultToast(View view) {
TastyToast.makeText(getApplicationContext(), "This is Default Toast", TastyToast.LENGTH_LONG,
TastyToast.DEFAULT);
TastyToast.DEFAULT, Color.parseColor("#FE9D4D"));
}


public void showConfusingToast(View view) {
TastyToast.makeText(getApplicationContext(), "I don't Know !", TastyToast.LENGTH_LONG,
TastyToast.CONFUSING);
TastyToast.CONFUSING, Color.parseColor("#FE9D4D"));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ public class ConfusingToastView extends View {
Bitmap eye;
ValueAnimator valueAnimator;
float angle = 0f;
public int mPaintColor;
private Paint mPaint;
private float mWidth = 0f;
private float mHeight = 0f;
Expand Down Expand Up @@ -50,7 +51,7 @@ private void initPaint() {
mPaint = new Paint();
mPaint.setAntiAlias(true);
mPaint.setStyle(Paint.Style.STROKE);
mPaint.setColor(Color.parseColor("#FE9D4D"));
mPaint.setColor(mPaintColor);
}

private void initPath() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ public class DefaultToastView extends View {

ValueAnimator valueAnimator;
float mAnimatedValue = 0f;
public int mPaintColor;
private Paint mPaint, mSpikePaint;
private float mWidth = 0f;
private float mPadding = 0f;
Expand Down Expand Up @@ -46,13 +47,13 @@ private void initPaint() {
mPaint = new Paint();
mPaint.setAntiAlias(true);
mPaint.setStyle(Paint.Style.STROKE);
mPaint.setColor(Color.parseColor("#222222"));
mPaint.setColor(mPaintColor);
mPaint.setStrokeWidth(dip2px(2));

mSpikePaint = new Paint();
mSpikePaint.setAntiAlias(true);
mSpikePaint.setStyle(Paint.Style.STROKE);
mSpikePaint.setColor(Color.parseColor("#222222"));
mSpikePaint.setColor(mPaintColor);
mSpikePaint.setStrokeWidth(dip2px(4));

mSpikeLength = dip2px(4);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ public class ErrorToastView extends View {
RectF rightEyeRectF = new RectF();
ValueAnimator valueAnimator;
float mAnimatedValue = 0f;
public int mPaintColor;
private Paint mPaint;
private float mWidth = 0f;
private float mEyeWidth = 0f;
Expand Down Expand Up @@ -55,7 +56,7 @@ private void initPaint() {
mPaint = new Paint();
mPaint.setAntiAlias(true);
mPaint.setStyle(Paint.Style.STROKE);
mPaint.setColor(Color.parseColor("#d9534f"));
mPaint.setColor(mPaintColor);
mPaint.setStrokeWidth(dip2px(2));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ public class InfoToastView extends View {
ValueAnimator valueAnimator;
float mAnimatedValue = 0f;
private String TAG = "com.sdsmdg.tastytoast";
public int mPaintColor;
private Paint mPaint;
private float mWidth = 0f;
private float mEyeWidth = 0f;
Expand Down Expand Up @@ -56,7 +57,7 @@ private void initPaint() {
mPaint = new Paint();
mPaint.setAntiAlias(true);
mPaint.setStyle(Paint.Style.STROKE);
mPaint.setColor(Color.parseColor("#337ab7"));
mPaint.setColor(mPaintColor);
mPaint.setStrokeWidth(dip2px(2));

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ public class SuccessToastView extends View {
RectF rectF = new RectF();
ValueAnimator valueAnimator;
float mAnimatedValue = 0f;
public int mPaintColor;
private Paint mPaint;
private float mWidth = 0f;
private float mEyeWidth = 0f;
Expand Down Expand Up @@ -52,7 +53,7 @@ private void initPaint() {
mPaint = new Paint();
mPaint.setAntiAlias(true);
mPaint.setStyle(Paint.Style.STROKE);
mPaint.setColor(Color.parseColor("#5cb85c"));
mPaint.setColor(mPaintColor);
mPaint.setStrokeWidth(dip2px(2));
}

Expand Down
30 changes: 21 additions & 9 deletions tastytoast/src/main/java/com/sdsmdg/tastytoast/TastyToast.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import android.content.Context;
import android.graphics.Color;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.GradientDrawable;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.TextView;
Expand Down Expand Up @@ -34,7 +36,7 @@ public class TastyToast {
static DefaultToastView defaultToastView;
static ConfusingToastView confusingToastView;

public static Toast makeText(Context context, String msg, int length, int type) {
public static Toast makeText(Context context, String msg, int length, int type, int color) {

Toast toast = new Toast(context);

Expand All @@ -45,19 +47,21 @@ public static Toast makeText(Context context, String msg, int length, int type)
TextView text = (TextView) layout.findViewById(R.id.toastMessage);
text.setText(msg);
successToastView = (SuccessToastView) layout.findViewById(R.id.successView);
successToastView.mPaintColor = color;
successToastView.startAnim();
text.setBackgroundResource(R.drawable.success_toast);
text.setTextColor(Color.parseColor("#FFFFFF"));
Drawable background = text.getBackground();
((GradientDrawable) background).setColor(color);
toast.setView(layout);
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);
warningToastView.mPaintColor = color;
SpringSystem springSystem = SpringSystem.create();
final Spring spring = springSystem.createSpring();
spring.setCurrentValue(1.8);
Expand All @@ -69,7 +73,6 @@ public static Toast makeText(Context context, String msg, int length, int type)
public void onSpringUpdate(Spring spring) {
float value = (float) spring.getCurrentValue();
float scale = (float) (0.9f - (value * 0.5f));

warningToastView.setScaleX(scale);
warningToastView.setScaleY(scale);
}
Expand All @@ -84,58 +87,67 @@ public void run() {
spring.setEndValue(0.4f);
}
});

t.start();
text.setBackgroundResource(R.drawable.warning_toast);
text.setTextColor(Color.parseColor("#FFFFFF"));
Drawable background = text.getBackground();
((GradientDrawable) background).setColor(color);
toast.setView(layout);
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.mPaintColor = color;
errorToastView.startAnim();
text.setBackgroundResource(R.drawable.error_toast);
text.setTextColor(Color.parseColor("#FFFFFF"));
Drawable background = text.getBackground();
((GradientDrawable) background).setColor(color);
toast.setView(layout);
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.mPaintColor = color;
infoToastView.startAnim();
text.setBackgroundResource(R.drawable.info_toast);
text.setTextColor(Color.parseColor("#FFFFFF"));
Drawable background = text.getBackground();
((GradientDrawable) background).setColor(color);
toast.setView(layout);
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.mPaintColor = color;
defaultToastView.startAnim();
text.setBackgroundResource(R.drawable.default_toast);
text.setTextColor(Color.parseColor("#FFFFFF"));
Drawable background = text.getBackground();
((GradientDrawable) background).setColor(color);
toast.setView(layout);
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.mPaintColor = color;
confusingToastView.startAnim();
text.setBackgroundResource(R.drawable.confusing_toast);
text.setTextColor(Color.parseColor("#FFFFFF"));
Drawable background = text.getBackground();
((GradientDrawable) background).setColor(color);
toast.setView(layout);
break;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ public class WarningToastView extends View {
RectF rectFOne = new RectF();
RectF rectFTwo = new RectF();
RectF rectFThree = new RectF();
public int mPaintColor;
private Paint mPaint;
private float mWidth = 0f;
private float mHeight = 0f;
Expand Down Expand Up @@ -54,7 +55,7 @@ private void initPaint() {
mPaint = new Paint();
mPaint.setAntiAlias(true);
mPaint.setStyle(Paint.Style.STROKE);
mPaint.setColor(Color.parseColor("#f0ad4e"));
mPaint.setColor(mPaintColor);
mPaint.setStrokeWidth(mStrokeWidth);
}

Expand Down

0 comments on commit 67b3c3b

Please sign in to comment.