public class TSnackbar {
public static final int LENGTH_SHORT = -1;
/**
* Show the TSnackbar for a long period of time.
*/
public static final int LENGTH_LONG = 0;
private int residenceTime = 0;
private View view;
private static WeakReference<View> oldView;
private String message;
private int stateBarHeight, actionBarHeight;
private Handler handler = new Handler() {
@Override
public void handleMessage(Message msg) {
switch (msg.what) {
case 1:
animateViewOut();
break;
}
}
};
public static TSnackbar make(View view, String message, int time) {
TSnackbar tSnackbar2 = new TSnackbar();
tSnackbar2.setDuration(time);
tSnackbar2.setMessage(message);
tSnackbar2.setView(view);
return tSnackbar2;
}
public void show() {
animateViewIn();
}
public void setMinHeight(int stateBarHeight, int actionBarHeight) {
ViewGroup.LayoutParams params = view.getLayoutParams();
params.height = stateBarHeight + actionBarHeight;
view.setLayoutParams(params);
this.stateBarHeight = stateBarHeight;
this.actionBarHeight = actionBarHeight;
}
public void setView(View view) {
if (oldView != null && oldView.get() != null) {
View old = oldView.get();
if (old.getParent() != null) {
handler.removeMessages(1);
((ViewGroup) old.getParent()).removeView(old);
}
}
ViewGroup viewGroup = findSuitableParent(view);
if (viewGroup != null) {
this.view = LayoutInflater.from(view.getContext()).inflate(R.layout.item_tsnack_bar, null);