package com.enqualcomm.support.utils;\r
\r
import android.content.Context;\r
+import android.os.Handler;\r
+import android.os.HandlerThread;\r
import android.os.Vibrator;\r
\r
import static android.content.Context.VIBRATOR_SERVICE;\r
\r
public class VibrateUtil {\r
\r
- private static Context mContext = null;\r
+ private final Handler handler;\r
\r
- public static VibrateUtil getInstance(Context context) {\r
+ private VibrateUtil(Context context) {\r
if (mContext == null) {\r
mContext = context;\r
}\r
if (vibrator == null) {\r
vibrator = (Vibrator) mContext.getSystemService(VIBRATOR_SERVICE);\r
}\r
+ HandlerThread handlerThread = new HandlerThread("ic:vibrate");\r
+ handlerThread.start();\r
+ handler = new Handler(handlerThread.getLooper());\r
+ }\r
+\r
+ private static Context mContext = null;\r
+\r
+ public static VibrateUtil getInstance(Context context) {\r
if (vibrateUtil == null) {\r
- vibrateUtil = new VibrateUtil();\r
+ synchronized (VibrateUtil.class) {\r
+ if (vibrateUtil == null) {\r
+ vibrateUtil = new VibrateUtil(context);\r
+ }\r
+ }\r
}\r
return vibrateUtil;\r
}\r
private static VibrateUtil vibrateUtil = null;\r
\r
private static long patter_item = 1000;\r
- private long[] patter = {patter_item, 1000, patter_item, 1000}; //1秒开,1秒关,2秒开,50ms关\r
private long[] patterOnce = {patter_item, 1000}; //1秒开,1秒关,2秒开,50ms关\r
\r
/**\r
patter_item = l;\r
}\r
\r
+ boolean isVibrate = false;\r
+\r
public void vibrateOn(boolean on) {\r
+ if (isVibrate) {\r
+ return;\r
+ }\r
if (vibrator != null) {\r
if (on) {\r
- vibrator.cancel();\r
- vibrator.vibrate(1000);//不循环}\r
+ isVibrate = true;\r
+ //一秒钟后置成false\r
+ handler.postDelayed(() -> {\r
+ isVibrate = false;\r
+ ICLogger.d("vibrate finish...");\r
+ }, 1300);\r
+ vibrator.vibrate(1000);//不循环\r
} else {\r
vibrator.cancel();\r
}\r