Move VibratorCompatWrapper to VibratorUtils.
bug: 6129704 Change-Id: Ib63f1ed2d610e27e14957cf8805ef884cae6adf6main
parent
3224878351
commit
376eb52450
|
@ -21,8 +21,8 @@ import android.media.AudioManager;
|
|||
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 @@ import com.android.inputmethod.keyboard.Keyboard;
|
|||
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 @@ public class AudioAndHapticFeedbackManager {
|
|||
HapticFeedbackConstants.KEYBOARD_TAP,
|
||||
HapticFeedbackConstants.FLAG_IGNORE_GLOBAL_SETTING);
|
||||
}
|
||||
} else if (mVibrator != null) {
|
||||
mVibrator.vibrate(mSettingsValues.mKeypressVibrationDuration);
|
||||
} else if (mVibratorUtils != null) {
|
||||
mVibratorUtils.vibrate(mSettingsValues.mKeypressVibrationDuration);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -44,7 +44,7 @@ import android.widget.TextView;
|
|||
|
||||
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 @@ public class Settings extends InputMethodSettingsActivity
|
|||
generalSettings.removePreference(mVoicePreference);
|
||||
}
|
||||
|
||||
if (!VibratorCompatWrapper.getInstance(context).hasVibrator()) {
|
||||
if (!VibratorUtils.getInstance(context).hasVibrator()) {
|
||||
generalSettings.removePreference(findPreference(PREF_VIBRATE_ON));
|
||||
}
|
||||
|
||||
|
@ -358,7 +358,7 @@ public class Settings extends InputMethodSettingsActivity
|
|||
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 @@ public class Settings extends InputMethodSettingsActivity
|
|||
@Override
|
||||
public void onStopTrackingTouch(SeekBar arg0) {
|
||||
final int tempMs = arg0.getProgress();
|
||||
VibratorCompatWrapper.getInstance(context).vibrate(tempMs);
|
||||
VibratorUtils.getInstance(context).vibrate(tempMs);
|
||||
}
|
||||
});
|
||||
sb.setProgress(currentMs);
|
||||
|
|
|
@ -23,8 +23,8 @@ import android.util.Log;
|
|||
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 @@ public class SettingsValues {
|
|||
|
||||
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));
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (C) 2011 The Android Open Source Project
|
||||
* 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.
|
||||
|
@ -14,38 +14,37 @@
|
|||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.android.inputmethod.compat;
|
||||
package com.android.inputmethod.latin;
|
||||
|
||||
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();
|
||||
public class VibratorUtils {
|
||||
private static final VibratorUtils sInstance = new VibratorUtils();
|
||||
private Vibrator mVibrator;
|
||||
|
||||
private VibratorCompatWrapper() {
|
||||
private VibratorUtils() {
|
||||
// This utility class is not publicly instantiable.
|
||||
}
|
||||
|
||||
public static VibratorCompatWrapper getInstance(Context context) {
|
||||
public static VibratorUtils getInstance(Context context) {
|
||||
if (sInstance.mVibrator == null) {
|
||||
sInstance.mVibrator =
|
||||
(Vibrator) context.getSystemService(Context.VIBRATOR_SERVICE);
|
||||
sInstance.mVibrator = (Vibrator) context.getSystemService(Context.VIBRATOR_SERVICE);
|
||||
}
|
||||
return sInstance;
|
||||
}
|
||||
|
||||
public boolean hasVibrator() {
|
||||
if (mVibrator == null)
|
||||
if (mVibrator == null) {
|
||||
return false;
|
||||
return (Boolean) CompatUtils.invoke(mVibrator, true, METHOD_hasVibrator);
|
||||
}
|
||||
return mVibrator.hasVibrator();
|
||||
}
|
||||
|
||||
public void vibrate(long milliseconds) {
|
||||
if (mVibrator == null) {
|
||||
return;
|
||||
}
|
||||
mVibrator.vibrate(milliseconds);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue