Skip to content

Commit 987671c

Browse files
committed
Add setting to disable vibration when haptic feedback is disabled system-wide
1 parent 79cd7c4 commit 987671c

File tree

4 files changed

+66
-6
lines changed

4 files changed

+66
-6
lines changed

res/values/strings.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,11 @@
139139
<!-- Detailed description of the local shell preference -->
140140
<string name="pref_shell_detail">&quot;Command to run in Local mode. Default is \&quot;/system/bin/sh -\&quot; (no quotes).&quot;</string>
141141

142+
<!-- Name for the obey haptic feedback setting preference -->
143+
<string name="pref_obeyHaptic_title">"Override vibrate"</string>
144+
<!-- Detailed description of the haptic feedback setting preference -->
145+
<string name="pref_obeyHaptic_summary">"Don't vibrate if haptic feedback is disabled in system settings"</string>
146+
142147
<!-- The category title for terminal emulation preferences. -->
143148
<string name="pref_emulation_category">"Terminal emulation"</string>
144149

res/xml/preferences.xml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,13 @@
5151
android:dialogMessage="@string/pref_shell_detail"
5252
/>
5353

54+
<CheckBoxPreference
55+
android:key="obeyHaptic"
56+
android:defaultValue="false"
57+
android:summary="@string/pref_obeyHaptic_summary"
58+
android:title="@string/pref_obeyHaptic_title"
59+
/>
60+
5461
<PreferenceCategory
5562
android:title="@string/pref_emulation_category">
5663

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

162169
</PreferenceCategory>
163170

171+
164172
</PreferenceScreen>

src/org/connectbot/service/TerminalManager.java

Lines changed: 51 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
import android.content.res.AssetFileDescriptor;
4848
import android.content.res.Configuration;
4949
import android.content.res.Resources;
50+
import android.database.ContentObserver;
5051
import android.media.AudioManager;
5152
import android.media.MediaPlayer;
5253
import android.media.MediaPlayer.OnCompletionListener;
@@ -57,6 +58,7 @@
5758
import android.os.Message;
5859
import android.os.Vibrator;
5960
import android.preference.PreferenceManager;
61+
import android.provider.Settings;
6062
import android.util.Log;
6163

6264
import com.nullwire.trace.ExceptionHandler;
@@ -118,10 +120,36 @@ public class TerminalManager extends Service implements BridgeDisconnectedListen
118120

119121
public boolean hardKeyboardHidden;
120122

123+
private SettingsObserver settingsObserver;
124+
125+
public class SettingsObserver extends ContentObserver {
126+
public SettingsObserver(Handler handler) {
127+
super(handler);
128+
}
129+
130+
public void observe() {
131+
getContentResolver().registerContentObserver(
132+
Settings.System.getUriFor(Settings.System.HAPTIC_FEEDBACK_ENABLED),
133+
false, this);
134+
}
135+
136+
public void stop() {
137+
getContentResolver().unregisterContentObserver(this);
138+
}
139+
140+
@Override
141+
public void onChange(boolean selfChange) {
142+
onSharedPreferenceChanged(prefs, Settings.System.HAPTIC_FEEDBACK_ENABLED);
143+
}
144+
}
145+
121146
@Override
122147
public void onCreate() {
123148
Log.i(TAG, "Starting background service");
124149

150+
settingsObserver = new SettingsObserver(new Handler());
151+
settingsObserver.observe();
152+
125153
ExceptionHandler.register(this);
126154

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

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

156-
wantBellVibration = prefs.getBoolean(PreferenceConstants.BELL_VIBRATE, true);
183+
boolean allowVibration = !prefs.getBoolean(PreferenceConstants.OBEY_HAPTIC, false)
184+
|| (Settings.System.getInt(getContentResolver(),
185+
Settings.System.HAPTIC_FEEDBACK_ENABLED, 1) == 1);
186+
187+
wantKeyVibration = allowVibration && prefs.getBoolean(
188+
PreferenceConstants.BUMPY_ARROWS, true);
189+
wantBellVibration = allowVibration && prefs.getBoolean(
190+
PreferenceConstants.BELL_VIBRATE, true);
191+
157192
enableMediaPlayer();
158193

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

176211
disconnectAll(true);
177212

213+
if(settingsObserver != null) {
214+
settingsObserver.stop();
215+
settingsObserver = null;
216+
}
217+
178218
if(hostdb != null) {
179219
hostdb.close();
180220
hostdb = null;
@@ -622,11 +662,16 @@ else if (!wantAudible && mediaPlayer != null)
622662
PreferenceConstants.DEFAULT_BELL_VOLUME);
623663
mediaPlayer.setVolume(volume, volume);
624664
}
625-
} else if (PreferenceConstants.BELL_VIBRATE.equals(key)) {
626-
wantBellVibration = sharedPreferences.getBoolean(
665+
} else if (PreferenceConstants.BELL_VIBRATE.equals(key)
666+
|| PreferenceConstants.BUMPY_ARROWS.equals(key)
667+
|| PreferenceConstants.OBEY_HAPTIC.equals(key)
668+
|| Settings.System.HAPTIC_FEEDBACK_ENABLED.equals(key)) {
669+
boolean allowVibration = !prefs.getBoolean(PreferenceConstants.OBEY_HAPTIC, false)
670+
|| (Settings.System.getInt(getContentResolver(),
671+
Settings.System.HAPTIC_FEEDBACK_ENABLED, 1) == 1);
672+
wantBellVibration = allowVibration && sharedPreferences.getBoolean(
627673
PreferenceConstants.BELL_VIBRATE, true);
628-
} else if (PreferenceConstants.BUMPY_ARROWS.equals(key)) {
629-
wantKeyVibration = sharedPreferences.getBoolean(
674+
wantKeyVibration = allowVibration && sharedPreferences.getBoolean(
630675
PreferenceConstants.BUMPY_ARROWS, true);
631676
} else if (PreferenceConstants.WIFI_LOCK.equals(key)) {
632677
final boolean lockingWifi = prefs.getBoolean(PreferenceConstants.WIFI_LOCK, true);

src/org/connectbot/util/PreferenceConstants.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ public class PreferenceConstants {
4242
public static final String SHELL = "shell";
4343
public static final String SHELL_DEFAULT = "/system/bin/sh -";
4444

45+
public static final String OBEY_HAPTIC = "obeyHaptic";
46+
4547
public static final String EMULATION = "emulation";
4648

4749
public static final String ROTATION = "rotation";

0 commit comments

Comments
 (0)