Skip to content

Commit 428d2b9

Browse files
committed
v1.0.8 - fixed toast not disappearing when dismissed quickly. providing no text shrinks the toast to only the loader.
1 parent 3adcd22 commit 428d2b9

8 files changed

Lines changed: 38 additions & 6 deletions

File tree

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ The default toasts are ugly and don't really provide much more than a short mess
1313
#### Gradle
1414
```groovy
1515
dependencies {
16-
compile 'net.steamcrafted:load-toast:1.0.7'
16+
compile 'net.steamcrafted:load-toast:1.0.8'
1717
}
1818
```
1919

@@ -31,6 +31,8 @@ Change the displayed text:
3131
lt.setText("Sending Reply...");
3232
```
3333

34+
If you don't have a message to display, the toast will shrink to only show the circular loader.
35+
3436
Then proceed to show the toast:
3537

3638
```java

app/app.iml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,12 +81,14 @@
8181
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/rs" />
8282
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/symbols" />
8383
<excludeFolder url="file://$MODULE_DIR$/build/outputs" />
84+
<excludeFolder url="file://$MODULE_DIR$/build/reports" />
85+
<excludeFolder url="file://$MODULE_DIR$/build/test-results" />
8486
<excludeFolder url="file://$MODULE_DIR$/build/tmp" />
8587
</content>
8688
<orderEntry type="jdk" jdkName="Android API 22 Platform" jdkType="Android SDK" />
8789
<orderEntry type="sourceFolder" forTests="false" />
8890
<orderEntry type="library" exported="" name="library-2.4.0" level="project" />
89-
<orderEntry type="library" exported="" name="load-toast-1.0.6" level="project" />
91+
<orderEntry type="library" exported="" name="load-toast-1.0.8" level="project" />
9092
</component>
9193
</module>
9294

app/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,5 +31,5 @@ android {
3131

3232
dependencies {
3333
compile fileTree(dir: 'libs', include: ['*.jar'])
34-
compile project(':loadtoast')
34+
compile 'net.steamcrafted:load-toast:1.0.8'
3535
}

app/src/main/java/net/steamcrafted/loadtoastlib/MainActivity.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import android.content.Intent;
55
import android.graphics.Color;
66
import android.os.Bundle;
7+
import android.os.Handler;
78
import android.view.View;
89
import android.view.ViewGroup;
910

@@ -14,14 +15,18 @@ public class MainActivity extends Activity {
1415

1516
// Example activity
1617

18+
int delay = 0;
19+
1720
@Override
1821
public void onCreate(Bundle savedInstanceState) {
1922
super.onCreate(savedInstanceState);
2023
setContentView(R.layout.activity_main);
2124

22-
final String text = "abcdefghijklmnopq";
25+
final String text = "";
2326
final LoadToast lt = new LoadToast(this).setText(text).setTranslationY(100).show();
27+
//lt.success();
2428
final ViewGroup root = (ViewGroup) findViewById(android.R.id.content);
29+
2530
View v = new View(this);
2631
v.setBackgroundColor(Color.RED);
2732
root.addView(v, new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, 400));

loadtoast/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ apply plugin: 'com.android.library'
33
ext {
44
PUBLISH_GROUP_ID = 'net.steamcrafted'
55
PUBLISH_ARTIFACT_ID = 'load-toast'
6-
PUBLISH_VERSION = '1.0.7'
6+
PUBLISH_VERSION = '1.0.8'
77
}
88

99
android {

loadtoast/loadtoast.iml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@
6262
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/java" isTestSource="true" />
6363
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/jni" isTestSource="true" />
6464
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/rs" isTestSource="true" />
65+
<excludeFolder url="file://$MODULE_DIR$/build/docs" />
6566
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/assets" />
6667
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/bundles" />
6768
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/classes" />
@@ -81,7 +82,12 @@
8182
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/res" />
8283
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/rs" />
8384
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/symbols" />
85+
<excludeFolder url="file://$MODULE_DIR$/build/libs" />
8486
<excludeFolder url="file://$MODULE_DIR$/build/outputs" />
87+
<excludeFolder url="file://$MODULE_DIR$/build/poms" />
88+
<excludeFolder url="file://$MODULE_DIR$/build/release" />
89+
<excludeFolder url="file://$MODULE_DIR$/build/reports" />
90+
<excludeFolder url="file://$MODULE_DIR$/build/test-results" />
8591
<excludeFolder url="file://$MODULE_DIR$/build/tmp" />
8692
</content>
8793
<orderEntry type="jdk" jdkName="Android API 22 Platform" jdkType="Android SDK" />

loadtoast/src/main/java/net/steamcrafted/loadtoast/LoadToast.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ public class LoadToast {
2222
private ViewGroup mParentView;
2323
private int mTranslationY = 0;
2424
private boolean mShowCalled = false;
25+
private boolean mToastCanceled = false;
2526
private boolean mInflated = false;
2627

2728
public LoadToast(Context context){
@@ -35,7 +36,7 @@ public void run() {
3536
ViewHelper.setTranslationX(mView, (mParentView.getWidth() - mView.getWidth()) / 2);
3637
ViewHelper.setTranslationY(mView, -mView.getHeight() + mTranslationY);
3738
mInflated = true;
38-
if(mShowCalled) show();
39+
if(!mToastCanceled && mShowCalled) show();
3940
}
4041
},1);
4142

@@ -90,11 +91,19 @@ public LoadToast show(){
9091
}
9192

9293
public void success(){
94+
if(!mInflated){
95+
mToastCanceled = true;
96+
return;
97+
}
9398
mView.success();
9499
slideUp();
95100
}
96101

97102
public void error(){
103+
if(!mInflated){
104+
mToastCanceled = true;
105+
return;
106+
}
98107
mView.error();
99108
slideUp();
100109
}

loadtoast/src/main/java/net/steamcrafted/loadtoast/LoadToastView.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,9 @@ protected void onDraw(Canvas c){
211211
super.onDraw(c);
212212

213213
float ws = Math.max(1f - WIDTH_SCALE, 0f);
214+
// If there is nothing to display, just draw a circle
215+
if(mText.length() == 0) ws = 0;
216+
214217
float translateLoad = (1f-ws)*(IMAGE_WIDTH+MAX_TEXT_WIDTH);
215218
float leftMargin = translateLoad/2;
216219
float textOpactity = Math.max(0, ws * 10f - 9f);
@@ -255,6 +258,11 @@ protected void onDraw(Canvas c){
255258
//Log.d("spin", "rot " + progrot + " len " + proglength);
256259

257260
toastPath.reset();
261+
262+
if(mText.length() == 0){
263+
ws = Math.max(1f - WIDTH_SCALE, 0f);
264+
}
265+
258266
toastPath.arcTo(spinnerRect, 180 * progrot, Math.min((200 / .75f) * proglength + 1 + 560*(1f-ws),359.9999f));
259267
loaderPaint.setAlpha((int)(255 * ws));
260268
c.drawPath(toastPath, loaderPaint);

0 commit comments

Comments
 (0)