1 /* 2 * Copyright 2014 The WebRTC Project Authors. All rights reserved. 3 * 4 * Use of this source code is governed by a BSD-style license 5 * that can be found in the LICENSE file in the root of the source 6 * tree. An additional intellectual property rights grant can be found 7 * in the file PATENTS. All contributing project authors may 8 * be found in the AUTHORS file in the root of the source tree. 9 */ 10 11 package org.appspot.apprtc; 12 13 import android.app.Activity; 14 import android.content.SharedPreferences; 15 import android.content.SharedPreferences.OnSharedPreferenceChangeListener; 16 import android.os.Bundle; 17 import android.preference.Preference; 18 19 /** 20 * Settings activity for AppRTC. 21 */ 22 public class SettingsActivity extends Activity 23 implements OnSharedPreferenceChangeListener{ 24 private SettingsFragment settingsFragment; 25 private String keyprefVideoCall; 26 private String keyprefResolution; 27 private String keyprefFps; 28 private String keyprefCaptureQualitySlider; 29 private String keyprefStartVideoBitrateType; 30 private String keyprefStartVideoBitrateValue; 31 private String keyPrefVideoCodec; 32 private String keyprefHwCodec; 33 private String keyprefCaptureToTexture; 34 35 private String keyprefStartAudioBitrateType; 36 private String keyprefStartAudioBitrateValue; 37 private String keyPrefAudioCodec; 38 private String keyprefNoAudioProcessing; 39 private String keyprefAecDump; 40 private String keyprefOpenSLES; 41 42 private String keyPrefRoomServerUrl; 43 private String keyPrefDisplayHud; 44 private String keyPrefTracing; 45 46 @Override onCreate(Bundle savedInstanceState)47 protected void onCreate(Bundle savedInstanceState) { 48 super.onCreate(savedInstanceState); 49 keyprefVideoCall = getString(R.string.pref_videocall_key); 50 keyprefResolution = getString(R.string.pref_resolution_key); 51 keyprefFps = getString(R.string.pref_fps_key); 52 keyprefCaptureQualitySlider = getString(R.string.pref_capturequalityslider_key); 53 keyprefStartVideoBitrateType = getString(R.string.pref_startvideobitrate_key); 54 keyprefStartVideoBitrateValue = getString(R.string.pref_startvideobitratevalue_key); 55 keyPrefVideoCodec = getString(R.string.pref_videocodec_key); 56 keyprefHwCodec = getString(R.string.pref_hwcodec_key); 57 keyprefCaptureToTexture = getString(R.string.pref_capturetotexture_key); 58 59 keyprefStartAudioBitrateType = getString(R.string.pref_startaudiobitrate_key); 60 keyprefStartAudioBitrateValue = getString(R.string.pref_startaudiobitratevalue_key); 61 keyPrefAudioCodec = getString(R.string.pref_audiocodec_key); 62 keyprefNoAudioProcessing = getString(R.string.pref_noaudioprocessing_key); 63 keyprefAecDump = getString(R.string.pref_aecdump_key); 64 keyprefOpenSLES = getString(R.string.pref_opensles_key); 65 66 keyPrefRoomServerUrl = getString(R.string.pref_room_server_url_key); 67 keyPrefDisplayHud = getString(R.string.pref_displayhud_key); 68 keyPrefTracing = getString(R.string.pref_tracing_key); 69 70 // Display the fragment as the main content. 71 settingsFragment = new SettingsFragment(); 72 getFragmentManager().beginTransaction() 73 .replace(android.R.id.content, settingsFragment) 74 .commit(); 75 } 76 77 @Override onResume()78 protected void onResume() { 79 super.onResume(); 80 // Set summary to be the user-description for the selected value 81 SharedPreferences sharedPreferences = 82 settingsFragment.getPreferenceScreen().getSharedPreferences(); 83 sharedPreferences.registerOnSharedPreferenceChangeListener(this); 84 updateSummaryB(sharedPreferences, keyprefVideoCall); 85 updateSummary(sharedPreferences, keyprefResolution); 86 updateSummary(sharedPreferences, keyprefFps); 87 updateSummaryB(sharedPreferences, keyprefCaptureQualitySlider); 88 updateSummary(sharedPreferences, keyprefStartVideoBitrateType); 89 updateSummaryBitrate(sharedPreferences, keyprefStartVideoBitrateValue); 90 setVideoBitrateEnable(sharedPreferences); 91 updateSummary(sharedPreferences, keyPrefVideoCodec); 92 updateSummaryB(sharedPreferences, keyprefHwCodec); 93 updateSummaryB(sharedPreferences, keyprefCaptureToTexture); 94 95 updateSummary(sharedPreferences, keyprefStartAudioBitrateType); 96 updateSummaryBitrate(sharedPreferences, keyprefStartAudioBitrateValue); 97 setAudioBitrateEnable(sharedPreferences); 98 updateSummary(sharedPreferences, keyPrefAudioCodec); 99 updateSummaryB(sharedPreferences, keyprefNoAudioProcessing); 100 updateSummaryB(sharedPreferences, keyprefAecDump); 101 updateSummaryB(sharedPreferences, keyprefOpenSLES); 102 103 updateSummary(sharedPreferences, keyPrefRoomServerUrl); 104 updateSummaryB(sharedPreferences, keyPrefDisplayHud); 105 updateSummaryB(sharedPreferences, keyPrefTracing); 106 } 107 108 @Override onPause()109 protected void onPause() { 110 super.onPause(); 111 SharedPreferences sharedPreferences = 112 settingsFragment.getPreferenceScreen().getSharedPreferences(); 113 sharedPreferences.unregisterOnSharedPreferenceChangeListener(this); 114 } 115 116 @Override onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key)117 public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, 118 String key) { 119 if (key.equals(keyprefResolution) 120 || key.equals(keyprefFps) 121 || key.equals(keyprefStartVideoBitrateType) 122 || key.equals(keyPrefVideoCodec) 123 || key.equals(keyprefStartAudioBitrateType) 124 || key.equals(keyPrefAudioCodec) 125 || key.equals(keyPrefRoomServerUrl)) { 126 updateSummary(sharedPreferences, key); 127 } else if (key.equals(keyprefStartVideoBitrateValue) 128 || key.equals(keyprefStartAudioBitrateValue)) { 129 updateSummaryBitrate(sharedPreferences, key); 130 } else if (key.equals(keyprefVideoCall) 131 || key.equals(keyPrefTracing) 132 || key.equals(keyprefCaptureQualitySlider) 133 || key.equals(keyprefHwCodec) 134 || key.equals(keyprefCaptureToTexture) 135 || key.equals(keyprefNoAudioProcessing) 136 || key.equals(keyprefAecDump) 137 || key.equals(keyprefOpenSLES) 138 || key.equals(keyPrefDisplayHud)) { 139 updateSummaryB(sharedPreferences, key); 140 } 141 if (key.equals(keyprefStartVideoBitrateType)) { 142 setVideoBitrateEnable(sharedPreferences); 143 } 144 if (key.equals(keyprefStartAudioBitrateType)) { 145 setAudioBitrateEnable(sharedPreferences); 146 } 147 } 148 updateSummary(SharedPreferences sharedPreferences, String key)149 private void updateSummary(SharedPreferences sharedPreferences, String key) { 150 Preference updatedPref = settingsFragment.findPreference(key); 151 // Set summary to be the user-description for the selected value 152 updatedPref.setSummary(sharedPreferences.getString(key, "")); 153 } 154 updateSummaryBitrate( SharedPreferences sharedPreferences, String key)155 private void updateSummaryBitrate( 156 SharedPreferences sharedPreferences, String key) { 157 Preference updatedPref = settingsFragment.findPreference(key); 158 updatedPref.setSummary(sharedPreferences.getString(key, "") + " kbps"); 159 } 160 updateSummaryB(SharedPreferences sharedPreferences, String key)161 private void updateSummaryB(SharedPreferences sharedPreferences, String key) { 162 Preference updatedPref = settingsFragment.findPreference(key); 163 updatedPref.setSummary(sharedPreferences.getBoolean(key, true) 164 ? getString(R.string.pref_value_enabled) 165 : getString(R.string.pref_value_disabled)); 166 } 167 setVideoBitrateEnable(SharedPreferences sharedPreferences)168 private void setVideoBitrateEnable(SharedPreferences sharedPreferences) { 169 Preference bitratePreferenceValue = 170 settingsFragment.findPreference(keyprefStartVideoBitrateValue); 171 String bitrateTypeDefault = getString(R.string.pref_startvideobitrate_default); 172 String bitrateType = sharedPreferences.getString( 173 keyprefStartVideoBitrateType, bitrateTypeDefault); 174 if (bitrateType.equals(bitrateTypeDefault)) { 175 bitratePreferenceValue.setEnabled(false); 176 } else { 177 bitratePreferenceValue.setEnabled(true); 178 } 179 } 180 setAudioBitrateEnable(SharedPreferences sharedPreferences)181 private void setAudioBitrateEnable(SharedPreferences sharedPreferences) { 182 Preference bitratePreferenceValue = 183 settingsFragment.findPreference(keyprefStartAudioBitrateValue); 184 String bitrateTypeDefault = getString(R.string.pref_startaudiobitrate_default); 185 String bitrateType = sharedPreferences.getString( 186 keyprefStartAudioBitrateType, bitrateTypeDefault); 187 if (bitrateType.equals(bitrateTypeDefault)) { 188 bitratePreferenceValue.setEnabled(false); 189 } else { 190 bitratePreferenceValue.setEnabled(true); 191 } 192 } 193 } 194