Skip to content

Commit

Permalink
v1.0.8 - fixed toast not disappearing when dismissed quickly. providi…
Browse files Browse the repository at this point in the history
…ng no text shrinks the toast to only the loader.
  • Loading branch information
code-mc committed Jul 3, 2015
1 parent 3adcd22 commit 428d2b9
Show file tree
Hide file tree
Showing 8 changed files with 38 additions and 6 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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'
}
```

Expand All @@ -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
Expand Down
4 changes: 3 additions & 1 deletion app/app.iml
Original file line number Diff line number Diff line change
Expand Up @@ -81,12 +81,14 @@
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/rs" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/symbols" />
<excludeFolder url="file://$MODULE_DIR$/build/outputs" />
<excludeFolder url="file://$MODULE_DIR$/build/reports" />
<excludeFolder url="file://$MODULE_DIR$/build/test-results" />
<excludeFolder url="file://$MODULE_DIR$/build/tmp" />
</content>
<orderEntry type="jdk" jdkName="Android API 22 Platform" jdkType="Android SDK" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" exported="" name="library-2.4.0" level="project" />
<orderEntry type="library" exported="" name="load-toast-1.0.6" level="project" />
<orderEntry type="library" exported="" name="load-toast-1.0.8" level="project" />
</component>
</module>

2 changes: 1 addition & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,5 @@ android {

dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile project(':loadtoast')
compile 'net.steamcrafted:load-toast:1.0.8'
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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));
Expand Down
2 changes: 1 addition & 1 deletion loadtoast/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
6 changes: 6 additions & 0 deletions loadtoast/loadtoast.iml
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/java" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/jni" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/rs" isTestSource="true" />
<excludeFolder url="file://$MODULE_DIR$/build/docs" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/assets" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/bundles" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/classes" />
Expand All @@ -81,7 +82,12 @@
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/res" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/rs" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/symbols" />
<excludeFolder url="file://$MODULE_DIR$/build/libs" />
<excludeFolder url="file://$MODULE_DIR$/build/outputs" />
<excludeFolder url="file://$MODULE_DIR$/build/poms" />
<excludeFolder url="file://$MODULE_DIR$/build/release" />
<excludeFolder url="file://$MODULE_DIR$/build/reports" />
<excludeFolder url="file://$MODULE_DIR$/build/test-results" />
<excludeFolder url="file://$MODULE_DIR$/build/tmp" />
</content>
<orderEntry type="jdk" jdkName="Android API 22 Platform" jdkType="Android SDK" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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){
Expand All @@ -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);

Expand Down Expand Up @@ -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();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 428d2b9

Please sign in to comment.