diff --git a/app/src/main/java/com/sdsmdg/demoexample/MainActivity.java b/app/src/main/java/com/sdsmdg/demoexample/MainActivity.java index 9ede572..de940cb 100644 --- a/app/src/main/java/com/sdsmdg/demoexample/MainActivity.java +++ b/app/src/main/java/com/sdsmdg/demoexample/MainActivity.java @@ -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; @@ -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")); } } diff --git a/tastytoast/src/main/java/com/sdsmdg/tastytoast/ConfusingToastView.java b/tastytoast/src/main/java/com/sdsmdg/tastytoast/ConfusingToastView.java index aebfa05..b368ca1 100644 --- a/tastytoast/src/main/java/com/sdsmdg/tastytoast/ConfusingToastView.java +++ b/tastytoast/src/main/java/com/sdsmdg/tastytoast/ConfusingToastView.java @@ -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; @@ -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() { diff --git a/tastytoast/src/main/java/com/sdsmdg/tastytoast/DefaultToastView.java b/tastytoast/src/main/java/com/sdsmdg/tastytoast/DefaultToastView.java index 35dff56..42e26d2 100644 --- a/tastytoast/src/main/java/com/sdsmdg/tastytoast/DefaultToastView.java +++ b/tastytoast/src/main/java/com/sdsmdg/tastytoast/DefaultToastView.java @@ -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; @@ -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); diff --git a/tastytoast/src/main/java/com/sdsmdg/tastytoast/ErrorToastView.java b/tastytoast/src/main/java/com/sdsmdg/tastytoast/ErrorToastView.java index 6a8f260..90becd9 100644 --- a/tastytoast/src/main/java/com/sdsmdg/tastytoast/ErrorToastView.java +++ b/tastytoast/src/main/java/com/sdsmdg/tastytoast/ErrorToastView.java @@ -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; @@ -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)); } diff --git a/tastytoast/src/main/java/com/sdsmdg/tastytoast/InfoToastView.java b/tastytoast/src/main/java/com/sdsmdg/tastytoast/InfoToastView.java index 99a3c34..96298ad 100644 --- a/tastytoast/src/main/java/com/sdsmdg/tastytoast/InfoToastView.java +++ b/tastytoast/src/main/java/com/sdsmdg/tastytoast/InfoToastView.java @@ -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; @@ -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)); } diff --git a/tastytoast/src/main/java/com/sdsmdg/tastytoast/SuccessToastView.java b/tastytoast/src/main/java/com/sdsmdg/tastytoast/SuccessToastView.java index 2f887e1..3c0d286 100644 --- a/tastytoast/src/main/java/com/sdsmdg/tastytoast/SuccessToastView.java +++ b/tastytoast/src/main/java/com/sdsmdg/tastytoast/SuccessToastView.java @@ -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; @@ -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)); } diff --git a/tastytoast/src/main/java/com/sdsmdg/tastytoast/TastyToast.java b/tastytoast/src/main/java/com/sdsmdg/tastytoast/TastyToast.java index bdb7400..5c97eca 100644 --- a/tastytoast/src/main/java/com/sdsmdg/tastytoast/TastyToast.java +++ b/tastytoast/src/main/java/com/sdsmdg/tastytoast/TastyToast.java @@ -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; @@ -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); @@ -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); @@ -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); } @@ -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; } diff --git a/tastytoast/src/main/java/com/sdsmdg/tastytoast/WarningToastView.java b/tastytoast/src/main/java/com/sdsmdg/tastytoast/WarningToastView.java index 6fa38eb..1836ab9 100644 --- a/tastytoast/src/main/java/com/sdsmdg/tastytoast/WarningToastView.java +++ b/tastytoast/src/main/java/com/sdsmdg/tastytoast/WarningToastView.java @@ -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; @@ -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); }