Skip to content

Commit 9e567fa

Browse files
committed
Some updates to SnackBar
* Ability to set indeterminate * Ability to customize dismiss timer
1 parent ee89905 commit 9e567fa

File tree

1 file changed

+22
-2
lines changed

1 file changed

+22
-2
lines changed

MaterialDesign/src/com/gc/materialdesign/widgets/SnackBar.java

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@ public class SnackBar extends Dialog{
2323
View.OnClickListener onClickListener;
2424
Activity activity;
2525
View view;
26+
27+
// Timer
28+
private boolean mIndeterminate = false;
29+
private int mTimer = 4 * 1000;
2630

2731
// With action button
2832
public SnackBar(Activity activity, String text, String buttonText, View.OnClickListener onClickListener) {
@@ -79,7 +83,10 @@ public void show() {
7983
super.show();
8084
view.setVisibility(View.VISIBLE);
8185
view.startAnimation(AnimationUtils.loadAnimation(activity, R.anim.snackbar_show_animation));
82-
dismissTimer.start();
86+
87+
if (!mIndeterminate) {
88+
dismissTimer.start();
89+
}
8390
}
8491

8592
// Dismiss timer
@@ -88,7 +95,7 @@ public void show() {
8895
@Override
8996
public void run() {
9097
try {
91-
Thread.sleep(3500);
98+
Thread.sleep(mTimer);
9299
} catch (InterruptedException e) {
93100
e.printStackTrace();
94101
}
@@ -126,6 +133,19 @@ public void onAnimationEnd(Animation animation) {
126133
view.startAnimation(anim);
127134
}
128135

136+
public void setIndeterminate(boolean indeterminate) {
137+
mIndeterminate = indeterminate;
138+
}
129139

140+
public boolean isIndeterminate() {
141+
return mIndeterminate;
142+
}
130143

144+
public void setDismissTimer(int time) {
145+
mTimer = time;
146+
}
147+
148+
public int getDismissTimer() {
149+
return mTimer;
150+
}
131151
}

0 commit comments

Comments
 (0)