From 428d2b99ebe67155558a49814bf28ae5b1ab78c3 Mon Sep 17 00:00:00 2001 From: code-mc Date: Sat, 4 Jul 2015 01:06:45 +0200 Subject: [PATCH] v1.0.8 - fixed toast not disappearing when dismissed quickly. providing no text shrinks the toast to only the loader. --- README.md | 4 +++- app/app.iml | 4 +++- app/build.gradle | 2 +- .../net/steamcrafted/loadtoastlib/MainActivity.java | 7 ++++++- loadtoast/build.gradle | 2 +- loadtoast/loadtoast.iml | 6 ++++++ .../java/net/steamcrafted/loadtoast/LoadToast.java | 11 ++++++++++- .../net/steamcrafted/loadtoast/LoadToastView.java | 8 ++++++++ 8 files changed, 38 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 0b24d6d..9b9606f 100644 --- a/README.md +++ b/README.md @@ -13,7 +13,7 @@ The default toasts are ugly and don't really provide much more than a short mess #### Gradle ```groovy dependencies { - compile 'net.steamcrafted:load-toast:1.0.7' + compile 'net.steamcrafted:load-toast:1.0.8' } ``` @@ -31,6 +31,8 @@ Change the displayed text: lt.setText("Sending Reply..."); ``` +If you don't have a message to display, the toast will shrink to only show the circular loader. + Then proceed to show the toast: ```java diff --git a/app/app.iml b/app/app.iml index a1937b2..b79496f 100644 --- a/app/app.iml +++ b/app/app.iml @@ -81,12 +81,14 @@ + + - + diff --git a/app/build.gradle b/app/build.gradle index f338fed..58668cf 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -31,5 +31,5 @@ android { dependencies { compile fileTree(dir: 'libs', include: ['*.jar']) - compile project(':loadtoast') + compile 'net.steamcrafted:load-toast:1.0.8' } diff --git a/app/src/main/java/net/steamcrafted/loadtoastlib/MainActivity.java b/app/src/main/java/net/steamcrafted/loadtoastlib/MainActivity.java index f19340c..6ba173c 100644 --- a/app/src/main/java/net/steamcrafted/loadtoastlib/MainActivity.java +++ b/app/src/main/java/net/steamcrafted/loadtoastlib/MainActivity.java @@ -4,6 +4,7 @@ import android.content.Intent; import android.graphics.Color; import android.os.Bundle; +import android.os.Handler; import android.view.View; import android.view.ViewGroup; @@ -14,14 +15,18 @@ public class MainActivity extends Activity { // Example activity + int delay = 0; + @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); - final String text = "abcdefghijklmnopq"; + final String text = ""; final LoadToast lt = new LoadToast(this).setText(text).setTranslationY(100).show(); + //lt.success(); final ViewGroup root = (ViewGroup) findViewById(android.R.id.content); + View v = new View(this); v.setBackgroundColor(Color.RED); root.addView(v, new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, 400)); diff --git a/loadtoast/build.gradle b/loadtoast/build.gradle index 7e015c8..bbe110b 100644 --- a/loadtoast/build.gradle +++ b/loadtoast/build.gradle @@ -3,7 +3,7 @@ apply plugin: 'com.android.library' ext { PUBLISH_GROUP_ID = 'net.steamcrafted' PUBLISH_ARTIFACT_ID = 'load-toast' - PUBLISH_VERSION = '1.0.7' + PUBLISH_VERSION = '1.0.8' } android { diff --git a/loadtoast/loadtoast.iml b/loadtoast/loadtoast.iml index c9c2d82..d207d12 100644 --- a/loadtoast/loadtoast.iml +++ b/loadtoast/loadtoast.iml @@ -62,6 +62,7 @@ + @@ -81,7 +82,12 @@ + + + + + diff --git a/loadtoast/src/main/java/net/steamcrafted/loadtoast/LoadToast.java b/loadtoast/src/main/java/net/steamcrafted/loadtoast/LoadToast.java index 96676b2..c7c9abe 100644 --- a/loadtoast/src/main/java/net/steamcrafted/loadtoast/LoadToast.java +++ b/loadtoast/src/main/java/net/steamcrafted/loadtoast/LoadToast.java @@ -22,6 +22,7 @@ public class LoadToast { private ViewGroup mParentView; private int mTranslationY = 0; private boolean mShowCalled = false; + private boolean mToastCanceled = false; private boolean mInflated = false; public LoadToast(Context context){ @@ -35,7 +36,7 @@ public void run() { ViewHelper.setTranslationX(mView, (mParentView.getWidth() - mView.getWidth()) / 2); ViewHelper.setTranslationY(mView, -mView.getHeight() + mTranslationY); mInflated = true; - if(mShowCalled) show(); + if(!mToastCanceled && mShowCalled) show(); } },1); @@ -90,11 +91,19 @@ public LoadToast show(){ } public void success(){ + if(!mInflated){ + mToastCanceled = true; + return; + } mView.success(); slideUp(); } public void error(){ + if(!mInflated){ + mToastCanceled = true; + return; + } mView.error(); slideUp(); } diff --git a/loadtoast/src/main/java/net/steamcrafted/loadtoast/LoadToastView.java b/loadtoast/src/main/java/net/steamcrafted/loadtoast/LoadToastView.java index ecec7ac..064b388 100644 --- a/loadtoast/src/main/java/net/steamcrafted/loadtoast/LoadToastView.java +++ b/loadtoast/src/main/java/net/steamcrafted/loadtoast/LoadToastView.java @@ -211,6 +211,9 @@ protected void onDraw(Canvas c){ super.onDraw(c); float ws = Math.max(1f - WIDTH_SCALE, 0f); + // If there is nothing to display, just draw a circle + if(mText.length() == 0) ws = 0; + float translateLoad = (1f-ws)*(IMAGE_WIDTH+MAX_TEXT_WIDTH); float leftMargin = translateLoad/2; float textOpactity = Math.max(0, ws * 10f - 9f); @@ -255,6 +258,11 @@ protected void onDraw(Canvas c){ //Log.d("spin", "rot " + progrot + " len " + proglength); toastPath.reset(); + + if(mText.length() == 0){ + ws = Math.max(1f - WIDTH_SCALE, 0f); + } + toastPath.arcTo(spinnerRect, 180 * progrot, Math.min((200 / .75f) * proglength + 1 + 560*(1f-ws),359.9999f)); loaderPaint.setAlpha((int)(255 * ws)); c.drawPath(toastPath, loaderPaint);