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

Refactor code #23

Open
wants to merge 2 commits 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
1 change: 1 addition & 0 deletions app/src/main/java/com/sdsmdg/demoexample/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import android.view.WindowManager;

import com.sdsmdg.tastytoast.TastyToast;
import com.sdsmdg.tastytoast.TastyToastManager;


public class MainActivity extends AppCompatActivity {
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
android:layout_centerHorizontal="true"
android:layout_weight="1"
android:onClick="showSuccessToast"
android:text="Download" />
android:text="Success" />

<Button
android:id="@+id/button2"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
* Created by Anas Altair on 8/31/2016.
* Modified by rahul on 16/09/2016
*/
public class ConfusingToastView extends View {
public class ConfusingToastView extends ToastView {

Bitmap eye;
ValueAnimator valueAnimator;
Expand Down Expand Up @@ -88,11 +88,6 @@ protected void onDraw(Canvas canvas) {
canvas.drawLine(mWidth / 4f, mHeight * 3f / 4f, mWidth * 3f / 4f, mHeight * 3f / 4f, mPaint);
}

public float dip2px(float dpValue) {
final float scale = getContext().getResources().getDisplayMetrics().density;
return dpValue * scale;
}

public void startAnim() {
stopAnim();
startViewAnim(0f, 1f, 2000);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
/**
* Created by rahul on 27/7/16.
*/
public class DefaultToastView extends View {
public class DefaultToastView extends ToastView {

ValueAnimator valueAnimator;
float mAnimatedValue = 0f;
Expand Down Expand Up @@ -113,9 +113,4 @@ public void onAnimationUpdate(ValueAnimator valueAnimator) {
}
return valueAnimator;
}

public int dip2px(float dpValue) {
final float scale = getContext().getResources().getDisplayMetrics().density;
return (int) (dpValue * scale);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
/**
* Created by rahul on 22/7/16.
*/
public class ErrorToastView extends View {
public class ErrorToastView extends ToastView {

RectF rectF = new RectF();
RectF leftEyeRectF = new RectF();
Expand Down Expand Up @@ -84,11 +84,6 @@ protected void onDraw(Canvas canvas) {
}
}

public int dip2px(float dpValue) {
final float scale = getContext().getResources().getDisplayMetrics().density;
return (int) (dpValue * scale + 0.5f);
}

public void startAnim() {
stopAnim();
startViewAnim(0f, 1f, 2000);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
/**
* Created by rahul on 27/7/16.
*/
public class InfoToastView extends View {
public class InfoToastView extends ToastView {

RectF rectF = new RectF();
ValueAnimator valueAnimator;
Expand Down Expand Up @@ -86,11 +86,6 @@ protected void onDraw(Canvas canvas) {
}
}

public int dip2px(float dpValue) {
final float scale = getContext().getResources().getDisplayMetrics().density;
return (int) (dpValue * scale + 0.5f);
}

public void startAnim() {
stopAnim();
startViewAnim(0f, 1f, 2000);
Expand Down Expand Up @@ -118,7 +113,6 @@ public void onAnimationUpdate(ValueAnimator valueAnimator) {

mAnimatedValue = (float) valueAnimator.getAnimatedValue();

// Log.i(TAG, "Value : " + mAnimatedValue);
if (mAnimatedValue < 0.90) {
endPoint = ((2 * (mWidth) - (4 * mPadding)) * (mAnimatedValue / 2)) + mPadding;
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
/**
* Created by rahul on 22/7/16.
*/
public class SuccessToastView extends View {
public class SuccessToastView extends ToastView {

RectF rectF = new RectF();
ValueAnimator valueAnimator;
Expand Down Expand Up @@ -75,11 +75,6 @@ protected void onDraw(Canvas canvas) {
}
}

public int dip2px(float dpValue) {
final float scale = getContext().getResources().getDisplayMetrics().density;
return (int) (dpValue * scale + 0.5f);
}

public void startAnim() {
stopAnim();
startViewAnim(0f, 1f, 2000);
Expand Down
43 changes: 21 additions & 22 deletions tastytoast/src/main/java/com/sdsmdg/tastytoast/TastyToast.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@
/**
* Created by rahul on 28/7/16.
*/
public class TastyToast {
public class TastyToast extends Toast {
public ToastView view;

public static final int LENGTH_SHORT = 0;
public static final int LENGTH_LONG = 1;

Expand All @@ -27,25 +29,23 @@ 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;
private static ToastView toastView;

public TastyToast(Context context) {
super(context);
}

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

Toast toast = new Toast(context);


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();
toastView = (SuccessToastView) layout.findViewById(R.id.successView);
toastView.startAnim();
text.setBackgroundResource(R.drawable.success_toast);
text.setTextColor(Color.parseColor("#FFFFFF"));
toast.setView(layout);
Expand All @@ -57,7 +57,7 @@ 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);
toastView = (WarningToastView) layout.findViewById(R.id.warningView);
SpringSystem springSystem = SpringSystem.create();
final Spring spring = springSystem.createSpring();
spring.setCurrentValue(1.8);
Expand All @@ -70,8 +70,8 @@ public void onSpringUpdate(Spring spring) {
float value = (float) spring.getCurrentValue();
float scale = (float) (0.9f - (value * 0.5f));

warningToastView.setScaleX(scale);
warningToastView.setScaleY(scale);
toastView.setScaleX(scale);
toastView.setScaleY(scale);
}
});
Thread t = new Thread(new Runnable() {
Expand All @@ -96,8 +96,8 @@ public void run() {

TextView text = (TextView) layout.findViewById(R.id.toastMessage);
text.setText(msg);
errorToastView = (ErrorToastView) layout.findViewById(R.id.errorView);
errorToastView.startAnim();
toastView = (ErrorToastView) layout.findViewById(R.id.errorView);
toastView.startAnim();
text.setBackgroundResource(R.drawable.error_toast);
text.setTextColor(Color.parseColor("#FFFFFF"));
toast.setView(layout);
Expand All @@ -108,8 +108,8 @@ public void run() {

TextView text = (TextView) layout.findViewById(R.id.toastMessage);
text.setText(msg);
infoToastView = (InfoToastView) layout.findViewById(R.id.infoView);
infoToastView.startAnim();
toastView = (InfoToastView) layout.findViewById(R.id.infoView);
toastView.startAnim();
text.setBackgroundResource(R.drawable.info_toast);
text.setTextColor(Color.parseColor("#FFFFFF"));
toast.setView(layout);
Expand All @@ -120,8 +120,8 @@ public void run() {

TextView text = (TextView) layout.findViewById(R.id.toastMessage);
text.setText(msg);
defaultToastView = (DefaultToastView) layout.findViewById(R.id.defaultView);
defaultToastView.startAnim();
toastView = (DefaultToastView) layout.findViewById(R.id.defaultView);
toastView.startAnim();
text.setBackgroundResource(R.drawable.default_toast);
text.setTextColor(Color.parseColor("#FFFFFF"));
toast.setView(layout);
Expand All @@ -132,8 +132,8 @@ public void run() {

TextView text = (TextView) layout.findViewById(R.id.toastMessage);
text.setText(msg);
confusingToastView = (ConfusingToastView) layout.findViewById(R.id.confusingView);
confusingToastView.startAnim();
toastView = (ConfusingToastView) layout.findViewById(R.id.confusingView);
toastView.startAnim();
text.setBackgroundResource(R.drawable.confusing_toast);
text.setTextColor(Color.parseColor("#FFFFFF"));
toast.setView(layout);
Expand All @@ -144,5 +144,4 @@ public void run() {
toast.show();
return toast;
}

}
31 changes: 31 additions & 0 deletions tastytoast/src/main/java/com/sdsmdg/tastytoast/ToastView.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package com.sdsmdg.tastytoast;

import android.content.Context;
import android.util.AttributeSet;
import android.view.View;

/**
* Created by suyash on 26/2/17.
*/

public abstract class ToastView extends View {
public ToastView(Context context) {
super(context);
}

public ToastView(Context context, AttributeSet attrs) {
super(context, attrs);
}

public ToastView(Context context, AttributeSet attrs, int defStyleAttr){
super(context, attrs, defStyleAttr);
}

public abstract void startAnim();
public abstract void stopAnim();

public int dip2px(float dpValue) {
final float scale = getContext().getResources().getDisplayMetrics().density;
return (int) (dpValue * scale + 0.5f);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
/**
* Created by rahul on 25/7/16.
*/
public class WarningToastView extends View {
public class WarningToastView extends ToastView {

RectF rectFOne = new RectF();
RectF rectFTwo = new RectF();
Expand Down Expand Up @@ -96,4 +96,12 @@ public float convertDpToPixel(float dp) {
float px = dp * ((float) metrics.densityDpi / DisplayMetrics.DENSITY_DEFAULT);
return px;
}

public void startAnim(){

}

public void stopAnim(){

}
}