Skip to content
Permalink
Browse files

Add setting to disable vibration when haptic feedback is disabled sys…

…tem-wide
  • Loading branch information
nylen committed Dec 6, 2010
1 parent 79cd7c4 commit 987671c211ba99f8c52c6a7a3419819cd92cf33a
@@ -139,6 +139,11 @@
<!-- Detailed description of the local shell preference -->
<string name="pref_shell_detail">&quot;Command to run in Local mode. Default is \&quot;/system/bin/sh -\&quot; (no quotes).&quot;</string>

<!-- Name for the obey haptic feedback setting preference -->
<string name="pref_obeyHaptic_title">"Override vibrate"</string>
<!-- Detailed description of the haptic feedback setting preference -->
<string name="pref_obeyHaptic_summary">"Don't vibrate if haptic feedback is disabled in system settings"</string>

<!-- The category title for terminal emulation preferences. -->
<string name="pref_emulation_category">"Terminal emulation"</string>

@@ -51,6 +51,13 @@
android:dialogMessage="@string/pref_shell_detail"
/>

<CheckBoxPreference
android:key="obeyHaptic"
android:defaultValue="false"
android:summary="@string/pref_obeyHaptic_summary"
android:title="@string/pref_obeyHaptic_title"
/>

<PreferenceCategory
android:title="@string/pref_emulation_category">

@@ -161,4 +168,5 @@

</PreferenceCategory>


</PreferenceScreen>
@@ -47,6 +47,7 @@
import android.content.res.AssetFileDescriptor;
import android.content.res.Configuration;
import android.content.res.Resources;
import android.database.ContentObserver;
import android.media.AudioManager;
import android.media.MediaPlayer;
import android.media.MediaPlayer.OnCompletionListener;
@@ -57,6 +58,7 @@
import android.os.Message;
import android.os.Vibrator;
import android.preference.PreferenceManager;
import android.provider.Settings;
import android.util.Log;

import com.nullwire.trace.ExceptionHandler;
@@ -118,10 +120,36 @@

public boolean hardKeyboardHidden;

private SettingsObserver settingsObserver;

public class SettingsObserver extends ContentObserver {
public SettingsObserver(Handler handler) {
super(handler);
}

public void observe() {
getContentResolver().registerContentObserver(
Settings.System.getUriFor(Settings.System.HAPTIC_FEEDBACK_ENABLED),
false, this);
}

public void stop() {
getContentResolver().unregisterContentObserver(this);
}

@Override
public void onChange(boolean selfChange) {
onSharedPreferenceChanged(prefs, Settings.System.HAPTIC_FEEDBACK_ENABLED);
}
}

@Override
public void onCreate() {
Log.i(TAG, "Starting background service");

settingsObserver = new SettingsObserver(new Handler());
settingsObserver.observe();

ExceptionHandler.register(this);

prefs = PreferenceManager.getDefaultSharedPreferences(this);
@@ -151,9 +179,16 @@ public void onCreate() {
}

vibrator = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE);
wantKeyVibration = prefs.getBoolean(PreferenceConstants.BUMPY_ARROWS, true);

wantBellVibration = prefs.getBoolean(PreferenceConstants.BELL_VIBRATE, true);
boolean allowVibration = !prefs.getBoolean(PreferenceConstants.OBEY_HAPTIC, false)
|| (Settings.System.getInt(getContentResolver(),
Settings.System.HAPTIC_FEEDBACK_ENABLED, 1) == 1);

wantKeyVibration = allowVibration && prefs.getBoolean(
PreferenceConstants.BUMPY_ARROWS, true);
wantBellVibration = allowVibration && prefs.getBoolean(
PreferenceConstants.BELL_VIBRATE, true);

enableMediaPlayer();

hardKeyboardHidden = (res.getConfiguration().hardKeyboardHidden ==
@@ -175,6 +210,11 @@ public void onDestroy() {

disconnectAll(true);

if(settingsObserver != null) {
settingsObserver.stop();
settingsObserver = null;
}

if(hostdb != null) {
hostdb.close();
hostdb = null;
@@ -622,11 +662,16 @@ else if (!wantAudible && mediaPlayer != null)
PreferenceConstants.DEFAULT_BELL_VOLUME);
mediaPlayer.setVolume(volume, volume);
}
} else if (PreferenceConstants.BELL_VIBRATE.equals(key)) {
wantBellVibration = sharedPreferences.getBoolean(
} else if (PreferenceConstants.BELL_VIBRATE.equals(key)
|| PreferenceConstants.BUMPY_ARROWS.equals(key)
|| PreferenceConstants.OBEY_HAPTIC.equals(key)
|| Settings.System.HAPTIC_FEEDBACK_ENABLED.equals(key)) {
boolean allowVibration = !prefs.getBoolean(PreferenceConstants.OBEY_HAPTIC, false)
|| (Settings.System.getInt(getContentResolver(),
Settings.System.HAPTIC_FEEDBACK_ENABLED, 1) == 1);
wantBellVibration = allowVibration && sharedPreferences.getBoolean(
PreferenceConstants.BELL_VIBRATE, true);
} else if (PreferenceConstants.BUMPY_ARROWS.equals(key)) {
wantKeyVibration = sharedPreferences.getBoolean(
wantKeyVibration = allowVibration && sharedPreferences.getBoolean(
PreferenceConstants.BUMPY_ARROWS, true);
} else if (PreferenceConstants.WIFI_LOCK.equals(key)) {
final boolean lockingWifi = prefs.getBoolean(PreferenceConstants.WIFI_LOCK, true);
@@ -42,6 +42,8 @@
public static final String SHELL = "shell";
public static final String SHELL_DEFAULT = "/system/bin/sh -";

public static final String OBEY_HAPTIC = "obeyHaptic";

public static final String EMULATION = "emulation";

public static final String ROTATION = "rotation";

0 comments on commit 987671c

Please sign in to comment.
You can’t perform that action at this time.