Adding setting screen to AppRTCDemo.
- Move server URL from connection screen to the setting screen. - Add setting for local video resolution. - Auto save last entered room number. - Use full screen mode in video renderer and fix texture offsets recalculation when rendering type is dynamically changed. BUG=3935,3953 R=kjellander@webrtc.org, pbos@webrtc.org, pthatcher@webrtc.org Review URL: https://webrtc-codereview.appspot.com/30769004 git-svn-id: http://webrtc.googlecode.com/svn/trunk@7534 4adac7df-926f-26a2-2b94-8c16560cd09d
This commit is contained in:
@@ -110,9 +110,9 @@ public class AppRTCDemoActivity extends Activity
|
||||
|
||||
VideoRendererGui.setView(videoView);
|
||||
remoteRender = VideoRendererGui.create(0, 0, 100, 100,
|
||||
VideoRendererGui.ScalingType.SCALE_ASPECT_FIT);
|
||||
VideoRendererGui.ScalingType.SCALE_ASPECT_FILL);
|
||||
localRender = VideoRendererGui.create(0, 0, 100, 100,
|
||||
VideoRendererGui.ScalingType.SCALE_ASPECT_FIT);
|
||||
VideoRendererGui.ScalingType.SCALE_ASPECT_FILL);
|
||||
|
||||
videoView.setOnClickListener(
|
||||
new View.OnClickListener() {
|
||||
|
@@ -31,9 +31,15 @@ import android.app.Activity;
|
||||
import android.app.AlertDialog;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
import android.content.pm.ActivityInfo;
|
||||
import android.net.Uri;
|
||||
import android.os.Bundle;
|
||||
import android.preference.PreferenceManager;
|
||||
import android.util.Log;
|
||||
import android.view.KeyEvent;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.view.View.OnClickListener;
|
||||
import android.view.inputmethod.EditorInfo;
|
||||
@@ -51,16 +57,25 @@ import org.webrtc.MediaCodecVideoEncoder;
|
||||
public class ConnectActivity extends Activity {
|
||||
|
||||
private static final String TAG = "ConnectActivity";
|
||||
public static final String CONNECT_URL_EXTRA = "connect_url";
|
||||
private Button connectButton;
|
||||
private EditText urlEditText;
|
||||
private EditText roomEditText;
|
||||
private CheckBox loopbackCheckBox;
|
||||
private SharedPreferences sharedPref;
|
||||
private String keyprefUrl;
|
||||
private String keyprefResolution;
|
||||
private String keyprefRoom;
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
// Get setting keys.
|
||||
PreferenceManager.setDefaultValues(this, R.xml.preferences, false);
|
||||
sharedPref = PreferenceManager.getDefaultSharedPreferences(this);
|
||||
keyprefUrl = getString(R.string.pref_url_key);
|
||||
keyprefResolution = getString(R.string.pref_resolution_key);
|
||||
keyprefRoom = getString(R.string.pref_room_key);
|
||||
|
||||
// If an implicit VIEW intent is launching the app, go directly to that URL.
|
||||
final Intent intent = getIntent();
|
||||
if ("android.intent.action.VIEW".equals(intent.getAction())) {
|
||||
@@ -70,8 +85,6 @@ public class ConnectActivity extends Activity {
|
||||
|
||||
setContentView(R.layout.activity_connect);
|
||||
|
||||
urlEditText = (EditText) findViewById(R.id.url_edittext);
|
||||
|
||||
loopbackCheckBox = (CheckBox) findViewById(R.id.check_loopback);
|
||||
loopbackCheckBox.setChecked(false);
|
||||
|
||||
@@ -94,15 +107,33 @@ public class ConnectActivity extends Activity {
|
||||
connectButton.setOnClickListener(new OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
String url = urlEditText.getText().toString();
|
||||
String url = sharedPref.getString(keyprefUrl,
|
||||
getString(R.string.pref_url_default));
|
||||
if (loopbackCheckBox.isChecked()) {
|
||||
url += "/?debug=loopback";
|
||||
} else {
|
||||
url += "/?r=" + roomEditText.getText();
|
||||
}
|
||||
|
||||
if (MediaCodecVideoEncoder.isPlatformSupported()) {
|
||||
url += "&hd=true";
|
||||
// Add video resolution constraints.
|
||||
String resolution = sharedPref.getString(keyprefResolution,
|
||||
getString(R.string.pref_resolution_default));
|
||||
String[] dimensions = resolution.split("[ x]+");
|
||||
if (dimensions.length == 2) {
|
||||
try {
|
||||
int maxWidth = Integer.parseInt(dimensions[0]);
|
||||
int maxHeight = Integer.parseInt(dimensions[1]);
|
||||
if (maxWidth > 0 && maxHeight > 0) {
|
||||
url += "&video=minHeight=" + maxHeight + ",maxHeight=" +
|
||||
maxHeight + ",minWidth=" + maxWidth + ",maxWidth=" + maxWidth;
|
||||
}
|
||||
} catch (NumberFormatException e) {
|
||||
Log.e(TAG, "Wrong video resolution setting: " + resolution);
|
||||
}
|
||||
} else {
|
||||
if (MediaCodecVideoEncoder.isPlatformSupported()) {
|
||||
url += "&hd=true";
|
||||
}
|
||||
}
|
||||
// TODO(kjellander): Add support for custom parameters to the URL.
|
||||
connectToRoom(url);
|
||||
@@ -110,6 +141,40 @@ public class ConnectActivity extends Activity {
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCreateOptionsMenu(Menu menu) {
|
||||
getMenuInflater().inflate(R.menu.connect_menu, menu);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(MenuItem item) {
|
||||
// Handle presses on the action bar items.
|
||||
if (item.getItemId() == R.id.action_settings) {
|
||||
Intent intent = new Intent(this, SettingsActivity.class);
|
||||
startActivity(intent);
|
||||
return true;
|
||||
} else {
|
||||
return super.onOptionsItemSelected(item);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPause() {
|
||||
super.onPause();
|
||||
String room = roomEditText.getText().toString();
|
||||
SharedPreferences.Editor editor = sharedPref.edit();
|
||||
editor.putString(keyprefRoom, room);
|
||||
editor.commit();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResume() {
|
||||
super.onResume();
|
||||
String room = sharedPref.getString(keyprefRoom, "");
|
||||
roomEditText.setText(room);
|
||||
}
|
||||
|
||||
private void connectToRoom(String roomUrl) {
|
||||
if (validateUrl(roomUrl)) {
|
||||
Uri url = Uri.parse(roomUrl);
|
||||
|
@@ -0,0 +1,88 @@
|
||||
/*
|
||||
* libjingle
|
||||
* Copyright 2014, Google Inc.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
* 3. The name of the author may not be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
|
||||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
|
||||
* EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
||||
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
package org.appspot.apprtc;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.SharedPreferences;
|
||||
import android.content.SharedPreferences.OnSharedPreferenceChangeListener;
|
||||
import android.os.Bundle;
|
||||
import android.preference.Preference;
|
||||
|
||||
public class SettingsActivity extends Activity
|
||||
implements OnSharedPreferenceChangeListener{
|
||||
private SettingsFragment settingsFragment;
|
||||
private String keyprefUrl;
|
||||
private String keyprefResolution;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
keyprefUrl = getString(R.string.pref_url_key);
|
||||
keyprefResolution = getString(R.string.pref_resolution_key);
|
||||
|
||||
// Display the fragment as the main content.
|
||||
settingsFragment = new SettingsFragment();
|
||||
getFragmentManager().beginTransaction()
|
||||
.replace(android.R.id.content, settingsFragment)
|
||||
.commit();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onResume() {
|
||||
super.onResume();
|
||||
// Set summary to be the user-description for the selected value
|
||||
SharedPreferences sharedPreferences =
|
||||
settingsFragment.getPreferenceScreen().getSharedPreferences();
|
||||
sharedPreferences.registerOnSharedPreferenceChangeListener(this);
|
||||
updateSummary(sharedPreferences, keyprefUrl);
|
||||
updateSummary(sharedPreferences, keyprefResolution);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPause() {
|
||||
super.onPause();
|
||||
SharedPreferences sharedPreferences =
|
||||
settingsFragment.getPreferenceScreen().getSharedPreferences();
|
||||
sharedPreferences.unregisterOnSharedPreferenceChangeListener(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences,
|
||||
String key) {
|
||||
if (key.equals(keyprefUrl) || key.equals(keyprefResolution)) {
|
||||
updateSummary(sharedPreferences, key);
|
||||
}
|
||||
}
|
||||
|
||||
private void updateSummary(SharedPreferences sharedPreferences, String key) {
|
||||
Preference updatedPref = settingsFragment.findPreference(key);
|
||||
// Set summary to be the user-description for the selected value
|
||||
updatedPref.setSummary(sharedPreferences.getString(key, ""));
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,41 @@
|
||||
/*
|
||||
* libjingle
|
||||
* Copyright 2014, Google Inc.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
* 3. The name of the author may not be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
|
||||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
|
||||
* EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
||||
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
package org.appspot.apprtc;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.preference.PreferenceFragment;
|
||||
|
||||
public class SettingsFragment extends PreferenceFragment {
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
// Load the preferences from an XML resource
|
||||
addPreferencesFromResource(R.xml.preferences);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user