Move VibratorCompatWrapper to VibratorUtils.

bug: 6129704

Change-Id: Ib63f1ed2d610e27e14957cf8805ef884cae6adf6
diff --git a/java/src/com/android/inputmethod/compat/VibratorCompatWrapper.java b/java/src/com/android/inputmethod/compat/VibratorCompatWrapper.java
deleted file mode 100644
index 2fb8b87..0000000
--- a/java/src/com/android/inputmethod/compat/VibratorCompatWrapper.java
+++ /dev/null
@@ -1,51 +0,0 @@
-/*
- * Copyright (C) 2011 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.inputmethod.compat;
-
-import android.content.Context;
-import android.os.Vibrator;
-
-import java.lang.reflect.Method;
-
-public class VibratorCompatWrapper {
-    private static final Method METHOD_hasVibrator = CompatUtils.getMethod(Vibrator.class,
-            "hasVibrator");
-
-    private static final VibratorCompatWrapper sInstance = new VibratorCompatWrapper();
-    private Vibrator mVibrator;
-
-    private VibratorCompatWrapper() {
-    }
-
-    public static VibratorCompatWrapper getInstance(Context context) {
-        if (sInstance.mVibrator == null) {
-            sInstance.mVibrator =
-                    (Vibrator) context.getSystemService(Context.VIBRATOR_SERVICE);
-        }
-        return sInstance;
-    }
-
-    public boolean hasVibrator() {
-        if (mVibrator == null)
-            return false;
-        return (Boolean) CompatUtils.invoke(mVibrator, true, METHOD_hasVibrator);
-    }
-
-    public void vibrate(long milliseconds) {
-        mVibrator.vibrate(milliseconds);
-    }
-}
diff --git a/java/src/com/android/inputmethod/latin/AudioAndHapticFeedbackManager.java b/java/src/com/android/inputmethod/latin/AudioAndHapticFeedbackManager.java
index 9c5ccc7..55664d4 100644
--- a/java/src/com/android/inputmethod/latin/AudioAndHapticFeedbackManager.java
+++ b/java/src/com/android/inputmethod/latin/AudioAndHapticFeedbackManager.java
@@ -21,8 +21,8 @@
 import android.view.HapticFeedbackConstants;
 import android.view.View;
 
-import com.android.inputmethod.compat.VibratorCompatWrapper;
 import com.android.inputmethod.keyboard.Keyboard;
+import com.android.inputmethod.latin.VibratorUtils;
 
 /**
  * This class gathers audio feedback and haptic feedback functions.
@@ -33,13 +33,13 @@
 public class AudioAndHapticFeedbackManager {
     final private SettingsValues mSettingsValues;
     final private AudioManager mAudioManager;
-    final private VibratorCompatWrapper mVibrator;
+    final private VibratorUtils mVibratorUtils;
     private boolean mSoundOn;
 
     public AudioAndHapticFeedbackManager(final LatinIME latinIme,
             final SettingsValues settingsValues) {
         mSettingsValues = settingsValues;
-        mVibrator = VibratorCompatWrapper.getInstance(latinIme);
+        mVibratorUtils = VibratorUtils.getInstance(latinIme);
         mAudioManager = (AudioManager) latinIme.getSystemService(Context.AUDIO_SERVICE);
         mSoundOn = reevaluateIfSoundIsOn();
     }
@@ -93,8 +93,8 @@
                         HapticFeedbackConstants.KEYBOARD_TAP,
                         HapticFeedbackConstants.FLAG_IGNORE_GLOBAL_SETTING);
             }
-        } else if (mVibrator != null) {
-            mVibrator.vibrate(mSettingsValues.mKeypressVibrationDuration);
+        } else if (mVibratorUtils != null) {
+            mVibratorUtils.vibrate(mSettingsValues.mKeypressVibrationDuration);
         }
     }
 
diff --git a/java/src/com/android/inputmethod/latin/Settings.java b/java/src/com/android/inputmethod/latin/Settings.java
index 650dcdc..fd61292 100644
--- a/java/src/com/android/inputmethod/latin/Settings.java
+++ b/java/src/com/android/inputmethod/latin/Settings.java
@@ -44,7 +44,7 @@
 
 import com.android.inputmethod.compat.CompatUtils;
 import com.android.inputmethod.compat.InputMethodServiceCompatWrapper;
-import com.android.inputmethod.compat.VibratorCompatWrapper;
+import com.android.inputmethod.latin.VibratorUtils;
 import com.android.inputmethod.latin.define.ProductionFlag;
 import com.android.inputmethodcommon.InputMethodSettingsActivity;
 
@@ -179,7 +179,7 @@
             generalSettings.removePreference(mVoicePreference);
         }
 
-        if (!VibratorCompatWrapper.getInstance(context).hasVibrator()) {
+        if (!VibratorUtils.getInstance(context).hasVibrator()) {
             generalSettings.removePreference(findPreference(PREF_VIBRATE_ON));
         }
 
@@ -358,7 +358,7 @@
     private void refreshEnablingsOfKeypressSoundAndVibrationSettings(
             SharedPreferences sp, Resources res) {
         if (mKeypressVibrationDurationSettingsPref != null) {
-            final boolean hasVibrator = VibratorCompatWrapper.getInstance(this).hasVibrator();
+            final boolean hasVibrator = VibratorUtils.getInstance(this).hasVibrator();
             final boolean vibrateOn = hasVibrator && sp.getBoolean(Settings.PREF_VIBRATE_ON,
                     res.getBoolean(R.bool.config_default_vibration_enabled));
             mKeypressVibrationDurationSettingsPref.setEnabled(vibrateOn);
@@ -421,7 +421,7 @@
             @Override
             public void onStopTrackingTouch(SeekBar arg0) {
                 final int tempMs = arg0.getProgress();
-                VibratorCompatWrapper.getInstance(context).vibrate(tempMs);
+                VibratorUtils.getInstance(context).vibrate(tempMs);
             }
         });
         sb.setProgress(currentMs);
diff --git a/java/src/com/android/inputmethod/latin/SettingsValues.java b/java/src/com/android/inputmethod/latin/SettingsValues.java
index c1335fd..0ad685b 100644
--- a/java/src/com/android/inputmethod/latin/SettingsValues.java
+++ b/java/src/com/android/inputmethod/latin/SettingsValues.java
@@ -23,8 +23,8 @@
 import android.view.inputmethod.EditorInfo;
 
 import com.android.inputmethod.compat.InputTypeCompatUtils;
-import com.android.inputmethod.compat.VibratorCompatWrapper;
 import com.android.inputmethod.keyboard.internal.KeySpecParser;
+import com.android.inputmethod.latin.VibratorUtils;
 
 import java.util.ArrayList;
 import java.util.Arrays;
@@ -187,7 +187,7 @@
 
     private static boolean isVibrateOn(final Context context, final SharedPreferences prefs,
             final Resources res) {
-        final boolean hasVibrator = VibratorCompatWrapper.getInstance(context).hasVibrator();
+        final boolean hasVibrator = VibratorUtils.getInstance(context).hasVibrator();
         return hasVibrator && prefs.getBoolean(Settings.PREF_VIBRATE_ON,
                 res.getBoolean(R.bool.config_default_vibration_enabled));
     }
diff --git a/java/src/com/android/inputmethod/latin/VibratorUtils.java b/java/src/com/android/inputmethod/latin/VibratorUtils.java
new file mode 100644
index 0000000..33ffdd9
--- /dev/null
+++ b/java/src/com/android/inputmethod/latin/VibratorUtils.java
@@ -0,0 +1,50 @@
+/*
+ * Copyright (C) 2012 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.inputmethod.latin;
+
+import android.content.Context;
+import android.os.Vibrator;
+
+public class VibratorUtils {
+    private static final VibratorUtils sInstance = new VibratorUtils();
+    private Vibrator mVibrator;
+
+    private VibratorUtils() {
+        // This utility class is not publicly instantiable.
+    }
+
+    public static VibratorUtils getInstance(Context context) {
+        if (sInstance.mVibrator == null) {
+            sInstance.mVibrator = (Vibrator) context.getSystemService(Context.VIBRATOR_SERVICE);
+        }
+        return sInstance;
+    }
+
+    public boolean hasVibrator() {
+        if (mVibrator == null) {
+            return false;
+        }
+        return mVibrator.hasVibrator();
+    }
+
+    public void vibrate(long milliseconds) {
+        if (mVibrator == null) {
+            return;
+        }
+        mVibrator.vibrate(milliseconds);
+    }
+}