|
|
@@ -1,6 +1,8 @@
|
|
|
package com.miekir.common.utils;
|
|
|
|
|
|
import android.content.Context;
|
|
|
+import android.util.TypedValue;
|
|
|
+import android.view.Gravity;
|
|
|
import android.widget.Toast;
|
|
|
|
|
|
/**
|
|
|
@@ -16,6 +18,9 @@ public class ToastTool {
|
|
|
|
|
|
private static long mLastShortToastMillis;
|
|
|
private static long mLastLongToastMillis;
|
|
|
+
|
|
|
+ private static int mVerticalMargin = 0;
|
|
|
+
|
|
|
/**
|
|
|
* @param text 要弹出的语句
|
|
|
*/
|
|
|
@@ -25,9 +30,13 @@ public class ToastTool {
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
+ initMargin(context);
|
|
|
+
|
|
|
if (System.currentTimeMillis() - mLastShortToastMillis > PERIOD_SHORT) {
|
|
|
mLastShortToastMillis = System.currentTimeMillis();
|
|
|
- Toast.makeText(context, text, Toast.LENGTH_SHORT).show();
|
|
|
+ Toast toast = Toast.makeText(context, text, Toast.LENGTH_SHORT);
|
|
|
+ toast.setGravity(Gravity.BOTTOM|Gravity.CENTER_HORIZONTAL, 0, mVerticalMargin);
|
|
|
+ toast.show();
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -40,9 +49,24 @@ public class ToastTool {
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
+ initMargin(context);
|
|
|
+
|
|
|
if (System.currentTimeMillis() - mLastLongToastMillis > PERIOD_LONG) {
|
|
|
mLastLongToastMillis = System.currentTimeMillis();
|
|
|
- Toast.makeText(context, text, Toast.LENGTH_LONG).show();
|
|
|
+ Toast toast = Toast.makeText(context, text, Toast.LENGTH_LONG);
|
|
|
+ toast.setGravity(Gravity.BOTTOM|Gravity.CENTER_HORIZONTAL, 0, mVerticalMargin);
|
|
|
+ toast.show();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private static void initMargin(Context context) {
|
|
|
+ if (context == null) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ if (mVerticalMargin == 0) {
|
|
|
+ mVerticalMargin = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP,
|
|
|
+ 72,
|
|
|
+ context.getResources().getDisplayMetrics());
|
|
|
}
|
|
|
}
|
|
|
}
|