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

Added color parameter #25

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
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, null);
}

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

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, null);
}

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


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 = Color.parseColor("#FE9D4D");
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 = Color.parseColor("#BB000000");
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 = Color.parseColor("#d9534f");
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 = Color.parseColor("#337ab7");
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 = Color.parseColor("#5cb85c");
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
58 changes: 42 additions & 16 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, Integer color) {

Toast toast = new Toast(context);

Expand All @@ -45,19 +47,24 @@ 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.startAnim();
text.setBackgroundResource(R.drawable.success_toast);
text.setTextColor(Color.parseColor("#FFFFFF"));
if (color != null) {
successToastView.mPaintColor = color;
Drawable background = text.getBackground();
((GradientDrawable) background).setColor(color);
}
successToastView.startAnim();
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);
text.setBackgroundResource(R.drawable.warning_toast);
text.setTextColor(Color.parseColor("#FFFFFF"));
SpringSystem springSystem = SpringSystem.create();
final Spring spring = springSystem.createSpring();
spring.setCurrentValue(1.8);
Expand All @@ -69,7 +76,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 +90,78 @@ public void run() {
spring.setEndValue(0.4f);
}
});

t.start();
text.setBackgroundResource(R.drawable.warning_toast);
text.setTextColor(Color.parseColor("#FFFFFF"));
if(color!=null)
{
warningToastView.mPaintColor = color;
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.startAnim();
text.setBackgroundResource(R.drawable.error_toast);
text.setTextColor(Color.parseColor("#FFFFFF"));
if (color != null) {
errorToastView.mPaintColor = color;
Drawable background = text.getBackground();
((GradientDrawable) background).setColor(color);
}
errorToastView.startAnim();
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.startAnim();
text.setBackgroundResource(R.drawable.info_toast);
text.setTextColor(Color.parseColor("#FFFFFF"));
if (color != null) {
infoToastView.mPaintColor = color;
Drawable background = text.getBackground();
((GradientDrawable) background).setColor(color);
}
infoToastView.startAnim();
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.startAnim();
text.setBackgroundResource(R.drawable.default_toast);
text.setTextColor(Color.parseColor("#FFFFFF"));
if (color != null) {
defaultToastView.mPaintColor = color;
Drawable background = text.getBackground();
((GradientDrawable) background).setColor(color);
}
defaultToastView.startAnim();
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.startAnim();
text.setBackgroundResource(R.drawable.confusing_toast);
text.setTextColor(Color.parseColor("#FFFFFF"));
if(color!=null)
{
confusingToastView.mPaintColor = color;
Drawable background = text.getBackground();
((GradientDrawable) background).setColor(color);
}
confusingToastView.startAnim();
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 = Color.parseColor("#f0ad4e");
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