aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--res/values/strings.xml12
-rw-r--r--res/values/styles.xml1
-rw-r--r--res/xml/preferences.xml15
-rw-r--r--src/org/connectbot/ConsoleActivity.java12
-rw-r--r--src/org/connectbot/service/TerminalBridge.java6
-rw-r--r--src/org/connectbot/service/TerminalManager.java47
-rw-r--r--src/org/connectbot/util/PreferenceConstants.java2
-rw-r--r--src/org/connectbot/util/VolumePreference.java58
8 files changed, 132 insertions, 21 deletions
diff --git a/res/values/strings.xml b/res/values/strings.xml
index 666bf3c..1998650 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -169,14 +169,20 @@
<!-- Summary for the haptic feedback (bumpy arrow) preference -->
<string name="pref_bumpyarrows_summary">Vibrate when sending arrow keys from trackball; useful for laggy connections</string>
+ <!-- Category title for the Terminal Bell preferences -->
+ <string name="pref_bell_category">Terminal bell</string>
+
<!-- Checkbox preference title for the audible terminal bell feature -->
- <string name="pref_bell_title">Audible terminal bell</string>
+ <string name="pref_bell_title">Audible bell</string>
+
+ <!-- Title for the slider preference to set the volume -->
+ <string name="pref_bell_volume_title">Bell volume</string>
<!-- Checkbox preference title for the vibrate on terminal bell feature -->
- <string name="pref_bell_vibrate_title">Vibrate on terminal bell</string>
+ <string name="pref_bell_vibrate_title">Vibrate on bell</string>
<!-- Checkbox preference title for the receive notifications on terminal bell feature -->
- <string name="pref_bell_notification_title">Terminal bell notifications</string>
+ <string name="pref_bell_notification_title">Background notifications</string>
<!-- Brief summary of the feature that is enabled when the checkbox preference for the receive notifications on terminal bell feature is checked -->
<string name="pref_bell_notification_summary">Send notification when a terminal running in the background sounds a bell.</string>
diff --git a/res/values/styles.xml b/res/values/styles.xml
index 459ee80..4ea59b8 100644
--- a/res/values/styles.xml
+++ b/res/values/styles.xml
@@ -1,3 +1,4 @@
+<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="NoTitle" parent="android:Theme">
<item name="android:windowNoTitle">true</item>
diff --git a/res/xml/preferences.xml b/res/xml/preferences.xml
index 42f6b24..ef2ad49 100644
--- a/res/xml/preferences.xml
+++ b/res/xml/preferences.xml
@@ -36,7 +36,7 @@
<PreferenceCategory
android:title="@string/pref_emulation_category">
-
+
<ListPreference
android:key="emulation"
android:title="@string/pref_emulation_title"
@@ -45,7 +45,7 @@
android:entryValues="@array/list_emulation_modes"
android:defaultValue="screen"
/>
-
+
<EditTextPreference
android:key="scrollback"
android:title="@string/pref_scrollback_title"
@@ -53,7 +53,7 @@
android:defaultValue="140"
android:singleLine="true"
/>
-
+
</PreferenceCategory>
<PreferenceCategory
@@ -113,6 +113,10 @@
android:summary="@string/pref_bumpyarrows_summary"
android:defaultValue="true"
/>
+ </PreferenceCategory>
+
+ <PreferenceCategory
+ android:title="@string/pref_bell_category">
<CheckBoxPreference
android:key="bell"
@@ -120,6 +124,11 @@
android:defaultValue="true"
/>
+ <org.connectbot.util.VolumePreference
+ android:key="bellVolume"
+ android:title="@string/pref_bell_volume_title"
+ />
+
<CheckBoxPreference
android:key="bellVibrate"
android:title="@string/pref_bell_vibrate_title"
diff --git a/src/org/connectbot/ConsoleActivity.java b/src/org/connectbot/ConsoleActivity.java
index b9d13d2..a6c2199 100644
--- a/src/org/connectbot/ConsoleActivity.java
+++ b/src/org/connectbot/ConsoleActivity.java
@@ -36,7 +36,6 @@ import android.content.ServiceConnection;
import android.content.SharedPreferences;
import android.content.pm.ActivityInfo;
import android.content.res.Configuration;
-import android.content.res.Resources;
import android.media.AudioManager;
import android.net.Uri;
import android.os.Bundle;
@@ -305,7 +304,7 @@ public class ConsoleActivity extends Activity {
}
String rotateDefault;
- if (Resources.getSystem().getConfiguration().keyboard == Configuration.KEYBOARD_NOKEYS)
+ if (getResources().getConfiguration().keyboard == Configuration.KEYBOARD_NOKEYS)
rotateDefault = PreferenceConstants.ROTATION_PORTRAIT;
else
rotateDefault = PreferenceConstants.ROTATION_LANDSCAPE;
@@ -671,6 +670,8 @@ public class ConsoleActivity extends Activity {
public boolean onPrepareOptionsMenu(Menu menu) {
super.onPrepareOptionsMenu(menu);
+ setVolumeControlStream(AudioManager.STREAM_NOTIFICATION);
+
final View view = findCurrentView(R.id.console_flip);
boolean activeTerminal = (view instanceof TerminalView);
boolean authenticated = false;
@@ -696,6 +697,13 @@ public class ConsoleActivity extends Activity {
}
@Override
+ public void onOptionsMenuClosed(Menu menu) {
+ super.onOptionsMenuClosed(menu);
+
+ setVolumeControlStream(AudioManager.STREAM_MUSIC);
+ }
+
+ @Override
public void onStart() {
super.onStart();
diff --git a/src/org/connectbot/service/TerminalBridge.java b/src/org/connectbot/service/TerminalBridge.java
index ab8a396..fcb833c 100644
--- a/src/org/connectbot/service/TerminalBridge.java
+++ b/src/org/connectbot/service/TerminalBridge.java
@@ -762,8 +762,6 @@ public class TerminalBridge implements VDUDisplay, OnKeyListener, InteractiveCal
keymode = manager.getKeyMode();
}
- private boolean bumpyArrows = false;
-
/**
* Handle onKey() events coming down from a {@link TerminalView} above us.
* We might collect these for our internal buffer when working with hostkeys
@@ -1110,8 +1108,7 @@ public class TerminalBridge implements VDUDisplay, OnKeyListener, InteractiveCal
}
public synchronized void tryKeyVibrate() {
- if (bumpyArrows)
- manager.vibrate();
+ manager.vibrate();
}
/**
@@ -1173,7 +1170,6 @@ public class TerminalBridge implements VDUDisplay, OnKeyListener, InteractiveCal
int width = parent.getWidth();
int height = parent.getHeight();
- bumpyArrows = manager.prefs.getBoolean(PreferenceConstants.BUMPY_ARROWS, true);
clipboard = (ClipboardManager) parent.getContext().getSystemService(Context.CLIPBOARD_SERVICE);
if (!forcedSize) {
diff --git a/src/org/connectbot/service/TerminalManager.java b/src/org/connectbot/service/TerminalManager.java
index bd3c413..4c120db 100644
--- a/src/org/connectbot/service/TerminalManager.java
+++ b/src/org/connectbot/service/TerminalManager.java
@@ -43,6 +43,7 @@ import android.app.Service;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
+import android.content.SharedPreferences.OnSharedPreferenceChangeListener;
import android.content.res.AssetFileDescriptor;
import android.content.res.Resources;
import android.media.AudioManager;
@@ -67,7 +68,7 @@ import android.util.Log;
*
* @author jsharkey
*/
-public class TerminalManager extends Service implements BridgeDisconnectedListener {
+public class TerminalManager extends Service implements BridgeDisconnectedListener, OnSharedPreferenceChangeListener {
public final static String TAG = TerminalManager.class.toString();
@@ -93,12 +94,12 @@ public class TerminalManager extends Service implements BridgeDisconnectedListen
private WifiManager.WifiLock wifilock;
private MediaPlayer mediaPlayer;
- private static final float BEEP_VOLUME = 0.15f;
private Timer idleTimer;
private final long IDLE_TIMEOUT = 300000; // 5 minutes
private Vibrator vibrator;
+ private volatile boolean wantVibration;
public static final long VIBRATE_DURATION = 30;
private NotificationManager notificationManager;
@@ -108,6 +109,7 @@ public class TerminalManager extends Service implements BridgeDisconnectedListen
public void onCreate() {
Log.i(TAG, "Starting background service");
prefs = PreferenceManager.getDefaultSharedPreferences(this);
+ prefs.registerOnSharedPreferenceChangeListener(this);
res = getResources();
@@ -136,6 +138,7 @@ public class TerminalManager extends Service implements BridgeDisconnectedListen
wifilock = manager.createWifiLock(TAG);
vibrator = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE);
+ wantVibration = prefs.getBoolean(PreferenceConstants.BELL_VIBRATE, true);
enableMediaPlayer();
@@ -384,6 +387,9 @@ public class TerminalManager extends Service implements BridgeDisconnectedListen
private void enableMediaPlayer() {
mediaPlayer = new MediaPlayer();
+ float volume = prefs.getFloat(PreferenceConstants.BELL_VOLUME,
+ PreferenceConstants.DEFAULT_BELL_VOLUME);
+
mediaPlayer.setAudioStreamType(AudioManager.STREAM_NOTIFICATION);
mediaPlayer.setOnCompletionListener(new BeepListener());
@@ -392,7 +398,7 @@ public class TerminalManager extends Service implements BridgeDisconnectedListen
mediaPlayer.setDataSource(file.getFileDescriptor(), file
.getStartOffset(), file.getLength());
file.close();
- mediaPlayer.setVolume(BEEP_VOLUME, BEEP_VOLUME);
+ mediaPlayer.setVolume(volume, volume);
mediaPlayer.prepare();
} catch (IOException e) {
Log.e(TAG, "Error setting up bell media player", e);
@@ -407,11 +413,10 @@ public class TerminalManager extends Service implements BridgeDisconnectedListen
}
public void playBeep() {
- if (prefs.getBoolean(PreferenceConstants.BELL, true))
- if (mediaPlayer != null)
- mediaPlayer.start();
+ if (mediaPlayer != null)
+ mediaPlayer.start();
- if (prefs.getBoolean(PreferenceConstants.BELL_VIBRATE, true))
+ if (wantVibration)
vibrate();
}
@@ -448,8 +453,34 @@ public class TerminalManager extends Service implements BridgeDisconnectedListen
PendingIntent contentIntent = PendingIntent.getActivity(this, 0,
notificationIntent, 0);
- notification.setLatestEventInfo(context, res.getString(R.string.app_name), contentText, contentIntent);
+ notification.setLatestEventInfo(context, res.getString(R.string.app_name),
+ contentText, contentIntent);
notificationManager.notify(NOTIFICATION_ID, notification);
}
+
+ /* (non-Javadoc)
+ * @see android.content.SharedPreferences.OnSharedPreferenceChangeListener#onSharedPreferenceChanged(android.content.SharedPreferences, java.lang.String)
+ */
+ public void onSharedPreferenceChanged(SharedPreferences sharedPreferences,
+ String key) {
+ if (PreferenceConstants.BELL.equals(key)) {
+ boolean wantAudible = sharedPreferences.getBoolean(
+ PreferenceConstants.BELL, true);
+ if (wantAudible && mediaPlayer == null)
+ enableMediaPlayer();
+ else if (!wantAudible && mediaPlayer != null)
+ disableMediaPlayer();
+ } else if (PreferenceConstants.BELL_VOLUME.equals(key)) {
+ if (mediaPlayer != null) {
+ float volume = sharedPreferences.getFloat(
+ PreferenceConstants.BELL_VOLUME,
+ PreferenceConstants.DEFAULT_BELL_VOLUME);
+ mediaPlayer.setVolume(volume, volume);
+ }
+ } else if (PreferenceConstants.BUMPY_ARROWS.equals(key)) {
+ wantVibration = sharedPreferences.getBoolean(
+ PreferenceConstants.BUMPY_ARROWS, true);
+ }
+ }
}
diff --git a/src/org/connectbot/util/PreferenceConstants.java b/src/org/connectbot/util/PreferenceConstants.java
index 2ba8d6f..beec052 100644
--- a/src/org/connectbot/util/PreferenceConstants.java
+++ b/src/org/connectbot/util/PreferenceConstants.java
@@ -66,6 +66,8 @@ public class PreferenceConstants {
public static final String SORT_BY_COLOR = "sortByColor";
public static final String BELL = "bell";
+ public static final String BELL_VOLUME = "bellVolume";
public static final String BELL_VIBRATE = "bellVibrate";
public static final String BELL_NOTIFICATION = "bellNotification";
+ public static final float DEFAULT_BELL_VOLUME = 0.25f;
}
diff --git a/src/org/connectbot/util/VolumePreference.java b/src/org/connectbot/util/VolumePreference.java
new file mode 100644
index 0000000..22471ad
--- /dev/null
+++ b/src/org/connectbot/util/VolumePreference.java
@@ -0,0 +1,58 @@
+/**
+ *
+ */
+package org.connectbot.util;
+
+import android.content.Context;
+import android.preference.DialogPreference;
+import android.util.AttributeSet;
+import android.view.View;
+import android.widget.SeekBar;
+import android.widget.SeekBar.OnSeekBarChangeListener;
+
+/**
+ * @author kenny
+ *
+ */
+public class VolumePreference extends DialogPreference implements OnSeekBarChangeListener {
+ /**
+ * @param context
+ * @param attrs
+ */
+ public VolumePreference(Context context, AttributeSet attrs) {
+ super(context, attrs);
+
+ setupLayout(context, attrs);
+ }
+
+ public VolumePreference(Context context, AttributeSet attrs, int defStyle) {
+ super(context, attrs, defStyle);
+
+ setupLayout(context, attrs);
+ }
+
+ private void setupLayout(Context context, AttributeSet attrs) {
+ setPersistent(true);
+ }
+
+ @Override
+ protected View onCreateDialogView() {
+ SeekBar sb = new SeekBar(getContext());
+
+ sb.setMax(100);
+ sb.setProgress((int)(getPersistedFloat(
+ PreferenceConstants.DEFAULT_BELL_VOLUME) * 100));
+ sb.setPadding(10, 10, 10, 10);
+ sb.setOnSeekBarChangeListener(this);
+
+ return sb;
+ }
+
+ public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
+ persistFloat(progress / 100f);
+ }
+
+ public void onStartTrackingTouch(SeekBar seekBar) { }
+
+ public void onStopTrackingTouch(SeekBar seekBar) { }
+}