Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(256)

Side by Side Diff: talk/examples/android/src/org/appspot/apprtc/SettingsActivity.java

Issue 1235563006: Move talk/examples/* to webrtc/examples. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: 201508051337 Created 5 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 /*
2 * libjingle
3 * Copyright 2014 Google Inc.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 *
8 * 1. Redistributions of source code must retain the above copyright notice,
9 * this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright notice,
11 * this list of conditions and the following disclaimer in the documentation
12 * and/or other materials provided with the distribution.
13 * 3. The name of the author may not be used to endorse or promote products
14 * derived from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
17 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
18 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
19 * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
20 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
21 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
22 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
23 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
24 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
25 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27
28 package org.appspot.apprtc;
29
30 import android.app.Activity;
31 import android.content.SharedPreferences;
32 import android.content.SharedPreferences.OnSharedPreferenceChangeListener;
33 import android.os.Bundle;
34 import android.preference.Preference;
35
36 /**
37 * Settings activity for AppRTC.
38 */
39 public class SettingsActivity extends Activity
40 implements OnSharedPreferenceChangeListener{
41 private SettingsFragment settingsFragment;
42 private String keyprefVideoCall;
43 private String keyprefResolution;
44 private String keyprefFps;
45 private String keyprefStartVideoBitrateType;
46 private String keyprefStartVideoBitrateValue;
47 private String keyPrefVideoCodec;
48 private String keyprefHwCodec;
49
50 private String keyprefStartAudioBitrateType;
51 private String keyprefStartAudioBitrateValue;
52 private String keyPrefAudioCodec;
53 private String keyprefNoAudioProcessing;
54
55 private String keyprefCpuUsageDetection;
56 private String keyPrefRoomServerUrl;
57 private String keyPrefDisplayHud;
58
59 @Override
60 protected void onCreate(Bundle savedInstanceState) {
61 super.onCreate(savedInstanceState);
62 keyprefVideoCall = getString(R.string.pref_videocall_key);
63 keyprefResolution = getString(R.string.pref_resolution_key);
64 keyprefFps = getString(R.string.pref_fps_key);
65 keyprefStartVideoBitrateType = getString(R.string.pref_startvideobitrate_key );
66 keyprefStartVideoBitrateValue = getString(R.string.pref_startvideobitrateval ue_key);
67 keyPrefVideoCodec = getString(R.string.pref_videocodec_key);
68 keyprefHwCodec = getString(R.string.pref_hwcodec_key);
69
70 keyprefStartAudioBitrateType = getString(R.string.pref_startaudiobitrate_key );
71 keyprefStartAudioBitrateValue = getString(R.string.pref_startaudiobitrateval ue_key);
72 keyPrefAudioCodec = getString(R.string.pref_audiocodec_key);
73 keyprefNoAudioProcessing = getString(R.string.pref_noaudioprocessing_key);
74
75 keyprefCpuUsageDetection = getString(R.string.pref_cpu_usage_detection_key);
76 keyPrefRoomServerUrl = getString(R.string.pref_room_server_url_key);
77 keyPrefDisplayHud = getString(R.string.pref_displayhud_key);
78
79 // Display the fragment as the main content.
80 settingsFragment = new SettingsFragment();
81 getFragmentManager().beginTransaction()
82 .replace(android.R.id.content, settingsFragment)
83 .commit();
84 }
85
86 @Override
87 protected void onResume() {
88 super.onResume();
89 // Set summary to be the user-description for the selected value
90 SharedPreferences sharedPreferences =
91 settingsFragment.getPreferenceScreen().getSharedPreferences();
92 sharedPreferences.registerOnSharedPreferenceChangeListener(this);
93 updateSummaryB(sharedPreferences, keyprefVideoCall);
94 updateSummary(sharedPreferences, keyprefResolution);
95 updateSummary(sharedPreferences, keyprefFps);
96 updateSummary(sharedPreferences, keyprefStartVideoBitrateType);
97 updateSummaryBitrate(sharedPreferences, keyprefStartVideoBitrateValue);
98 setVideoBitrateEnable(sharedPreferences);
99 updateSummary(sharedPreferences, keyPrefVideoCodec);
100 updateSummaryB(sharedPreferences, keyprefHwCodec);
101
102 updateSummary(sharedPreferences, keyprefStartAudioBitrateType);
103 updateSummaryBitrate(sharedPreferences, keyprefStartAudioBitrateValue);
104 setAudioBitrateEnable(sharedPreferences);
105 updateSummary(sharedPreferences, keyPrefAudioCodec);
106 updateSummaryB(sharedPreferences, keyprefNoAudioProcessing);
107
108 updateSummaryB(sharedPreferences, keyprefCpuUsageDetection);
109 updateSummary(sharedPreferences, keyPrefRoomServerUrl);
110 updateSummaryB(sharedPreferences, keyPrefDisplayHud);
111 }
112
113 @Override
114 protected void onPause() {
115 super.onPause();
116 SharedPreferences sharedPreferences =
117 settingsFragment.getPreferenceScreen().getSharedPreferences();
118 sharedPreferences.unregisterOnSharedPreferenceChangeListener(this);
119 }
120
121 @Override
122 public void onSharedPreferenceChanged(SharedPreferences sharedPreferences,
123 String key) {
124 if (key.equals(keyprefResolution)
125 || key.equals(keyprefFps)
126 || key.equals(keyprefStartVideoBitrateType)
127 || key.equals(keyPrefVideoCodec)
128 || key.equals(keyprefStartAudioBitrateType)
129 || key.equals(keyPrefAudioCodec)
130 || key.equals(keyPrefRoomServerUrl)) {
131 updateSummary(sharedPreferences, key);
132 } else if (key.equals(keyprefStartVideoBitrateValue)
133 || key.equals(keyprefStartAudioBitrateValue)) {
134 updateSummaryBitrate(sharedPreferences, key);
135 } else if (key.equals(keyprefVideoCall)
136 || key.equals(keyprefHwCodec)
137 || key.equals(keyprefNoAudioProcessing)
138 || key.equals(keyprefCpuUsageDetection)
139 || key.equals(keyPrefDisplayHud)) {
140 updateSummaryB(sharedPreferences, key);
141 }
142 if (key.equals(keyprefStartVideoBitrateType)) {
143 setVideoBitrateEnable(sharedPreferences);
144 }
145 if (key.equals(keyprefStartAudioBitrateType)) {
146 setAudioBitrateEnable(sharedPreferences);
147 }
148 }
149
150 private void updateSummary(SharedPreferences sharedPreferences, String key) {
151 Preference updatedPref = settingsFragment.findPreference(key);
152 // Set summary to be the user-description for the selected value
153 updatedPref.setSummary(sharedPreferences.getString(key, ""));
154 }
155
156 private void updateSummaryBitrate(
157 SharedPreferences sharedPreferences, String key) {
158 Preference updatedPref = settingsFragment.findPreference(key);
159 updatedPref.setSummary(sharedPreferences.getString(key, "") + " kbps");
160 }
161
162 private void updateSummaryB(SharedPreferences sharedPreferences, String key) {
163 Preference updatedPref = settingsFragment.findPreference(key);
164 updatedPref.setSummary(sharedPreferences.getBoolean(key, true)
165 ? getString(R.string.pref_value_enabled)
166 : getString(R.string.pref_value_disabled));
167 }
168
169 private void setVideoBitrateEnable(SharedPreferences sharedPreferences) {
170 Preference bitratePreferenceValue =
171 settingsFragment.findPreference(keyprefStartVideoBitrateValue);
172 String bitrateTypeDefault = getString(R.string.pref_startvideobitrate_defaul t);
173 String bitrateType = sharedPreferences.getString(
174 keyprefStartVideoBitrateType, bitrateTypeDefault);
175 if (bitrateType.equals(bitrateTypeDefault)) {
176 bitratePreferenceValue.setEnabled(false);
177 } else {
178 bitratePreferenceValue.setEnabled(true);
179 }
180 }
181
182 private void setAudioBitrateEnable(SharedPreferences sharedPreferences) {
183 Preference bitratePreferenceValue =
184 settingsFragment.findPreference(keyprefStartAudioBitrateValue);
185 String bitrateTypeDefault = getString(R.string.pref_startaudiobitrate_defaul t);
186 String bitrateType = sharedPreferences.getString(
187 keyprefStartAudioBitrateType, bitrateTypeDefault);
188 if (bitrateType.equals(bitrateTypeDefault)) {
189 bitratePreferenceValue.setEnabled(false);
190 } else {
191 bitratePreferenceValue.setEnabled(true);
192 }
193 }
194 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698