Merge "Added VibratorCompatWrapper"

main
satok 2011-03-24 21:49:00 -07:00 committed by Android (Google) Code Review
commit 01829b8847
3 changed files with 52 additions and 7 deletions

View File

@ -0,0 +1,47 @@
/*
* 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", int.class);
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);
}
}

View File

@ -20,6 +20,7 @@ import com.android.inputmethod.compat.CompatUtils;
import com.android.inputmethod.compat.InputMethodManagerCompatWrapper;
import com.android.inputmethod.compat.InputMethodServiceCompatWrapper;
import com.android.inputmethod.deprecated.VoiceProxy;
import com.android.inputmethod.compat.VibratorCompatWrapper;
import com.android.inputmethod.keyboard.Keyboard;
import com.android.inputmethod.keyboard.KeyboardActionListener;
import com.android.inputmethod.keyboard.KeyboardSwitcher;
@ -45,7 +46,6 @@ import android.os.Handler;
import android.os.IBinder;
import android.os.Message;
import android.os.SystemClock;
import android.os.Vibrator;
import android.preference.PreferenceActivity;
import android.preference.PreferenceManager;
import android.text.InputType;
@ -2117,9 +2117,8 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
private void loadSettings(EditorInfo attribute) {
// Get the settings preferences
final SharedPreferences prefs = mPrefs;
Vibrator vibrator = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE);
mVibrateOn = vibrator != null && vibrator.hasVibrator()
&& prefs.getBoolean(Settings.PREF_VIBRATE_ON, false);
final boolean hasVibrator = VibratorCompatWrapper.getInstance(this).hasVibrator();
mVibrateOn = hasVibrator && prefs.getBoolean(Settings.PREF_VIBRATE_ON, false);
mSoundOn = prefs.getBoolean(Settings.PREF_SOUND_ON,
mResources.getBoolean(R.bool.config_default_sound_enabled));

View File

@ -19,6 +19,7 @@ package com.android.inputmethod.latin;
import com.android.inputmethod.compat.CompatUtils;
import com.android.inputmethod.compat.InputMethodManagerCompatWrapper;
import com.android.inputmethod.deprecated.VoiceProxy;
import com.android.inputmethod.compat.VibratorCompatWrapper;
import android.app.AlertDialog;
import android.app.Dialog;
@ -26,7 +27,6 @@ import android.app.backup.BackupManager;
import android.content.DialogInterface;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.os.Vibrator;
import android.preference.CheckBoxPreference;
import android.preference.ListPreference;
import android.preference.Preference;
@ -134,8 +134,7 @@ public class Settings extends PreferenceActivity
generalSettings.removePreference(mVoicePreference);
}
Vibrator vibrator = (Vibrator) getSystemService(VIBRATOR_SERVICE);
if (vibrator == null || !vibrator.hasVibrator()) {
if (!VibratorCompatWrapper.getInstance(this).hasVibrator()) {
generalSettings.removePreference(findPreference(PREF_VIBRATE_ON));
}