Add an option to disable proximity sensor to AppRTC Demo Android.

BUG=webrtc:6152
R=magjed@webrtc.org

Review URL: https://codereview.webrtc.org/2194613003 .

Cr-Commit-Position: refs/heads/master@{#13573}
This commit is contained in:
Sami Kalliomaki
2016-07-29 14:11:11 +02:00
parent 0e4bffbed0
commit 3d9c71ad73
5 changed files with 58 additions and 5 deletions

View File

@ -36,6 +36,18 @@
<item>ISAC</item> <item>ISAC</item>
</string-array> </string-array>
<string-array name="speakerphone">
<item>Auto (proximity sensor)</item>
<item>Enabled</item>
<item>Disabled</item>
</string-array>
<string-array name="speakerphoneValues">
<item>auto</item>
<item>true</item>
<item>false</item>
</string-array>
<string-array name="roomListContextMenu"> <string-array name="roomListContextMenu">
<item>Remove favorite</item> <item>Remove favorite</item>
</string-array> </string-array>

View File

@ -142,6 +142,11 @@
<string name="pref_enable_level_control_title">Enable level control.</string> <string name="pref_enable_level_control_title">Enable level control.</string>
<string name="pref_enable_level_control_default">false</string> <string name="pref_enable_level_control_default">false</string>
<string name="pref_speakerphone_key">speakerphone_preference</string>
<string name="pref_speakerphone_title">Speakerphone.</string>
<string name="pref_speakerphone_dlg">Speakerphone.</string>
<string name="pref_speakerphone_default">auto</string>
<string name="pref_miscsettings_key">misc_settings_key</string> <string name="pref_miscsettings_key">misc_settings_key</string>
<string name="pref_miscsettings_title">Miscellaneous settings.</string> <string name="pref_miscsettings_title">Miscellaneous settings.</string>

View File

@ -140,6 +140,14 @@
android:key="@string/pref_enable_level_control_key" android:key="@string/pref_enable_level_control_key"
android:title="@string/pref_enable_level_control_title" android:title="@string/pref_enable_level_control_title"
android:defaultValue="@string/pref_enable_level_control_default" /> android:defaultValue="@string/pref_enable_level_control_default" />
<ListPreference
android:key="@string/pref_speakerphone_key"
android:title="@string/pref_speakerphone_title"
android:defaultValue="@string/pref_speakerphone_default"
android:dialogTitle="@string/pref_speakerphone_dlg"
android:entries="@array/speakerphone"
android:entryValues="@array/speakerphoneValues" />
</PreferenceCategory> </PreferenceCategory>
<PreferenceCategory <PreferenceCategory

View File

@ -16,8 +16,10 @@ import android.content.BroadcastReceiver;
import android.content.Context; import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.content.IntentFilter; import android.content.IntentFilter;
import android.content.SharedPreferences;
import android.content.pm.PackageManager; import android.content.pm.PackageManager;
import android.media.AudioManager; import android.media.AudioManager;
import android.preference.PreferenceManager;
import android.util.Log; import android.util.Log;
import java.util.Collections; import java.util.Collections;
@ -29,6 +31,9 @@ import java.util.Set;
*/ */
public class AppRTCAudioManager { public class AppRTCAudioManager {
private static final String TAG = "AppRTCAudioManager"; private static final String TAG = "AppRTCAudioManager";
private static final String SPEAKERPHONE_AUTO = "auto";
private static final String SPEAKERPHONE_TRUE = "true";
private static final String SPEAKERPHONE_FALSE = "false";
/** /**
* AudioDevice is the names of possible audio devices that we currently * AudioDevice is the names of possible audio devices that we currently
@ -49,11 +54,10 @@ public class AppRTCAudioManager {
private boolean savedIsSpeakerPhoneOn = false; private boolean savedIsSpeakerPhoneOn = false;
private boolean savedIsMicrophoneMute = false; private boolean savedIsMicrophoneMute = false;
// For now; always use the speaker phone as default device selection when private final AudioDevice defaultAudioDevice;
// there is a choice between SPEAKER_PHONE and EARPIECE.
// TODO(henrika): it is possible that EARPIECE should be preferred in some // Contains speakerphone setting: auto, true or false
// cases. If so, we should set this value at construction instead. private final String useSpeakerphone;
private final AudioDevice defaultAudioDevice = AudioDevice.SPEAKER_PHONE;
// Proximity sensor object. It measures the proximity of an object in cm // Proximity sensor object. It measures the proximity of an object in cm
// relative to the view screen of a device and can therefore be used to // relative to the view screen of a device and can therefore be used to
@ -74,6 +78,10 @@ public class AppRTCAudioManager {
// This method is called when the proximity sensor reports a state change, // This method is called when the proximity sensor reports a state change,
// e.g. from "NEAR to FAR" or from "FAR to NEAR". // e.g. from "NEAR to FAR" or from "FAR to NEAR".
private void onProximitySensorChangedState() { private void onProximitySensorChangedState() {
if (!useSpeakerphone.equals(SPEAKERPHONE_AUTO)) {
return;
}
// The proximity sensor should only be activated when there are exactly two // The proximity sensor should only be activated when there are exactly two
// available audio devices. // available audio devices.
if (audioDevices.size() == 2 if (audioDevices.size() == 2
@ -105,6 +113,16 @@ public class AppRTCAudioManager {
audioManager = ((AudioManager) context.getSystemService( audioManager = ((AudioManager) context.getSystemService(
Context.AUDIO_SERVICE)); Context.AUDIO_SERVICE));
SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context);
useSpeakerphone = sharedPreferences.getString(context.getString(R.string.pref_speakerphone_key),
context.getString(R.string.pref_speakerphone_default));
if (useSpeakerphone.equals(SPEAKERPHONE_FALSE)) {
defaultAudioDevice = AudioDevice.EARPIECE;
} else {
defaultAudioDevice = AudioDevice.SPEAKER_PHONE;
}
// Create and initialize the proximity sensor. // Create and initialize the proximity sensor.
// Tablet devices (e.g. Nexus 7) does not support proximity sensors. // Tablet devices (e.g. Nexus 7) does not support proximity sensors.
// Note that, the sensor will not be active until start() has been called. // Note that, the sensor will not be active until start() has been called.

View File

@ -47,6 +47,7 @@ public class SettingsActivity extends Activity
private String keyprefDisableBuiltInAGC; private String keyprefDisableBuiltInAGC;
private String keyprefDisableBuiltInNS; private String keyprefDisableBuiltInNS;
private String keyprefEnableLevelControl; private String keyprefEnableLevelControl;
private String keyprefSpeakerphone;
private String keyPrefRoomServerUrl; private String keyPrefRoomServerUrl;
private String keyPrefDisplayHud; private String keyPrefDisplayHud;
@ -76,6 +77,7 @@ public class SettingsActivity extends Activity
keyprefDisableBuiltInAGC = getString(R.string.pref_disable_built_in_agc_key); keyprefDisableBuiltInAGC = getString(R.string.pref_disable_built_in_agc_key);
keyprefDisableBuiltInNS = getString(R.string.pref_disable_built_in_ns_key); keyprefDisableBuiltInNS = getString(R.string.pref_disable_built_in_ns_key);
keyprefEnableLevelControl = getString(R.string.pref_enable_level_control_key); keyprefEnableLevelControl = getString(R.string.pref_enable_level_control_key);
keyprefSpeakerphone = getString(R.string.pref_speakerphone_key);
keyPrefRoomServerUrl = getString(R.string.pref_room_server_url_key); keyPrefRoomServerUrl = getString(R.string.pref_room_server_url_key);
keyPrefDisplayHud = getString(R.string.pref_displayhud_key); keyPrefDisplayHud = getString(R.string.pref_displayhud_key);
@ -118,6 +120,7 @@ public class SettingsActivity extends Activity
updateSummaryB(sharedPreferences, keyprefDisableBuiltInAGC); updateSummaryB(sharedPreferences, keyprefDisableBuiltInAGC);
updateSummaryB(sharedPreferences, keyprefDisableBuiltInNS); updateSummaryB(sharedPreferences, keyprefDisableBuiltInNS);
updateSummaryB(sharedPreferences, keyprefEnableLevelControl); updateSummaryB(sharedPreferences, keyprefEnableLevelControl);
updateSummaryList(sharedPreferences, keyprefSpeakerphone);
updateSummary(sharedPreferences, keyPrefRoomServerUrl); updateSummary(sharedPreferences, keyPrefRoomServerUrl);
updateSummaryB(sharedPreferences, keyPrefDisplayHud); updateSummaryB(sharedPreferences, keyPrefDisplayHud);
@ -198,6 +201,8 @@ public class SettingsActivity extends Activity
|| key.equals(keyprefEnableLevelControl) || key.equals(keyprefEnableLevelControl)
|| key.equals(keyPrefDisplayHud)) { || key.equals(keyPrefDisplayHud)) {
updateSummaryB(sharedPreferences, key); updateSummaryB(sharedPreferences, key);
} else if (key.equals(keyprefSpeakerphone)) {
updateSummaryList(sharedPreferences, key);
} }
if (key.equals(keyprefStartVideoBitrateType)) { if (key.equals(keyprefStartVideoBitrateType)) {
setVideoBitrateEnable(sharedPreferences); setVideoBitrateEnable(sharedPreferences);
@ -226,6 +231,11 @@ public class SettingsActivity extends Activity
: getString(R.string.pref_value_disabled)); : getString(R.string.pref_value_disabled));
} }
private void updateSummaryList(SharedPreferences sharedPreferences, String key) {
ListPreference updatedPref = (ListPreference) settingsFragment.findPreference(key);
updatedPref.setSummary(updatedPref.getEntry());
}
private void setVideoBitrateEnable(SharedPreferences sharedPreferences) { private void setVideoBitrateEnable(SharedPreferences sharedPreferences) {
Preference bitratePreferenceValue = Preference bitratePreferenceValue =
settingsFragment.findPreference(keyprefStartVideoBitrateValue); settingsFragment.findPreference(keyprefStartVideoBitrateValue);