diff --git a/webrtc/examples/androidapp/AndroidManifest.xml b/webrtc/examples/androidapp/AndroidManifest.xml index a8c09619c9..dfe8975b31 100644 --- a/webrtc/examples/androidapp/AndroidManifest.xml +++ b/webrtc/examples/androidapp/AndroidManifest.xml @@ -22,7 +22,9 @@ android:allowBackup="false"> + android:label="@string/app_name" + android:theme="@style/Theme.AppCompat" + android:windowSoftInputMode="adjustPan"> diff --git a/webrtc/examples/androidapp/res/drawable-hdpi/ic_add_white_24dp.png b/webrtc/examples/androidapp/res/drawable-hdpi/ic_add_white_24dp.png new file mode 100644 index 0000000000..694179bd46 Binary files /dev/null and b/webrtc/examples/androidapp/res/drawable-hdpi/ic_add_white_24dp.png differ diff --git a/webrtc/examples/androidapp/res/drawable-mdpi/ic_add_white_24dp.png b/webrtc/examples/androidapp/res/drawable-mdpi/ic_add_white_24dp.png new file mode 100644 index 0000000000..3856041d70 Binary files /dev/null and b/webrtc/examples/androidapp/res/drawable-mdpi/ic_add_white_24dp.png differ diff --git a/webrtc/examples/androidapp/res/drawable-xhdpi/ic_add_white_24dp.png b/webrtc/examples/androidapp/res/drawable-xhdpi/ic_add_white_24dp.png new file mode 100644 index 0000000000..67bb598e52 Binary files /dev/null and b/webrtc/examples/androidapp/res/drawable-xhdpi/ic_add_white_24dp.png differ diff --git a/webrtc/examples/androidapp/res/drawable-xxhdpi/ic_add_white_24dp.png b/webrtc/examples/androidapp/res/drawable-xxhdpi/ic_add_white_24dp.png new file mode 100644 index 0000000000..0fdced8fce Binary files /dev/null and b/webrtc/examples/androidapp/res/drawable-xxhdpi/ic_add_white_24dp.png differ diff --git a/webrtc/examples/androidapp/res/drawable-xxxhdpi/ic_add_white_24dp.png b/webrtc/examples/androidapp/res/drawable-xxxhdpi/ic_add_white_24dp.png new file mode 100644 index 0000000000..d64c22e9ed Binary files /dev/null and b/webrtc/examples/androidapp/res/drawable-xxxhdpi/ic_add_white_24dp.png differ diff --git a/webrtc/examples/androidapp/res/layout/activity_connect.xml b/webrtc/examples/androidapp/res/layout/activity_connect.xml index 5b80771588..acc20dc6a1 100644 --- a/webrtc/examples/androidapp/res/layout/activity_connect.xml +++ b/webrtc/examples/androidapp/res/layout/activity_connect.xml @@ -1,72 +1,82 @@ + xmlns:android="http://schemas.android.com/apk/res/android" + xmlns:app="http://schemas.android.com/apk/res-auto" + android:layout_margin="16dp" + android:layout_width="match_parent" + android:layout_height="match_parent" + android:orientation="vertical" + android:weightSum="1" + android:layout_centerHorizontal="true"> - - - - - - - - + + + + + android:imeOptions="actionDone" + android:inputType="text"/> + + + + - + + + + + + + + \ No newline at end of file diff --git a/webrtc/examples/androidapp/res/layout/dialog_add_favorite.xml b/webrtc/examples/androidapp/res/layout/dialog_add_favorite.xml new file mode 100644 index 0000000000..28b533aa0c --- /dev/null +++ b/webrtc/examples/androidapp/res/layout/dialog_add_favorite.xml @@ -0,0 +1,14 @@ + + + + + \ No newline at end of file diff --git a/webrtc/examples/androidapp/res/menu/connect_menu.xml b/webrtc/examples/androidapp/res/menu/connect_menu.xml index d9f94867b9..8beddddd45 100644 --- a/webrtc/examples/androidapp/res/menu/connect_menu.xml +++ b/webrtc/examples/androidapp/res/menu/connect_menu.xml @@ -1,8 +1,14 @@ - + + diff --git a/webrtc/examples/androidapp/res/values/arrays.xml b/webrtc/examples/androidapp/res/values/arrays.xml index ba8c8918ce..dd06c46ed1 100644 --- a/webrtc/examples/androidapp/res/values/arrays.xml +++ b/webrtc/examples/androidapp/res/values/arrays.xml @@ -36,4 +36,8 @@ ISAC + + Remove favorite + + diff --git a/webrtc/examples/androidapp/res/values/strings.xml b/webrtc/examples/androidapp/res/values/strings.xml index df891c77fe..24244238e0 100644 --- a/webrtc/examples/androidapp/res/values/strings.xml +++ b/webrtc/examples/androidapp/res/values/strings.xml @@ -3,12 +3,13 @@ AppRTC AppRTC Settings Disconnect Call - Room names: Please enter a room name. Room names are shared with everyone, so think of something unique and send it to a friend. - Connect + Favorites + No favorites + Add favorite Invalid URL The URL or room name you entered resulted in an invalid URL: %1$s @@ -16,14 +17,15 @@ Connecting to: %1$s FATAL ERROR: Missing URL to connect to. OK + Add + Cancel Switch front/back camera Toggle debug view Toggle microphone on/off Settings - Add new room to the list - Remove room from the list + Loopback connection Connect to the room - Loopback connection + Add favorite room_preference diff --git a/webrtc/examples/androidapp/src/org/appspot/apprtc/ConnectActivity.java b/webrtc/examples/androidapp/src/org/appspot/apprtc/ConnectActivity.java index e55dba0cba..b0bceccff4 100644 --- a/webrtc/examples/androidapp/src/org/appspot/apprtc/ConnectActivity.java +++ b/webrtc/examples/androidapp/src/org/appspot/apprtc/ConnectActivity.java @@ -10,16 +10,19 @@ package org.appspot.apprtc; -import android.app.Activity; -import android.app.AlertDialog; import android.content.DialogInterface; import android.content.Intent; import android.content.SharedPreferences; import android.net.Uri; import android.os.Bundle; import android.preference.PreferenceManager; +import android.support.design.widget.FloatingActionButton; +import android.support.v7.app.AlertDialog; +import android.support.v7.app.AppCompatActivity; import android.util.Log; +import android.view.ContextMenu; import android.view.KeyEvent; +import android.view.LayoutInflater; import android.view.Menu; import android.view.MenuItem; import android.view.View; @@ -42,15 +45,14 @@ import java.util.Random; /** * Handles the initial setup where the user selects which room to join. */ -public class ConnectActivity extends Activity { +public class ConnectActivity extends AppCompatActivity { private static final String TAG = "ConnectActivity"; private static final int CONNECTION_REQUEST = 1; + private static final int REMOVE_FAVORITE_INDEX = 0; private static boolean commandLineRun = false; - private ImageButton addRoomButton; - private ImageButton removeRoomButton; private ImageButton connectButton; - private ImageButton connectLoopbackButton; + private FloatingActionButton addFavoriteButton; private EditText roomEditText; private ListView roomListView; private SharedPreferences sharedPref; @@ -114,7 +116,7 @@ public class ConnectActivity extends Activity { public boolean onEditorAction( TextView textView, int i, KeyEvent keyEvent) { if (i == EditorInfo.IME_ACTION_DONE) { - addRoomButton.performClick(); + addFavoriteButton.performClick(); return true; } return false; @@ -123,32 +125,27 @@ public class ConnectActivity extends Activity { roomEditText.requestFocus(); roomListView = (ListView) findViewById(R.id.room_listview); - roomListView.setChoiceMode(ListView.CHOICE_MODE_SINGLE); - - addRoomButton = (ImageButton) findViewById(R.id.add_room_button); - addRoomButton.setOnClickListener(addRoomListener); - removeRoomButton = (ImageButton) findViewById(R.id.remove_room_button); - removeRoomButton.setOnClickListener(removeRoomListener); + roomListView.setEmptyView(findViewById(android.R.id.empty)); + roomListView.setOnItemClickListener(roomListClickListener); + registerForContextMenu(roomListView); connectButton = (ImageButton) findViewById(R.id.connect_button); connectButton.setOnClickListener(connectListener); - connectLoopbackButton = - (ImageButton) findViewById(R.id.connect_loopback_button); - connectLoopbackButton.setOnClickListener(connectListener); // 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()) && !commandLineRun) { - commandLineRun = true; boolean loopback = intent.getBooleanExtra( CallActivity.EXTRA_LOOPBACK, false); int runTimeMs = intent.getIntExtra( CallActivity.EXTRA_RUNTIME, 0); String room = sharedPref.getString(keyprefRoom, ""); - roomEditText.setText(room); - connectToRoom(loopback, runTimeMs); + connectToRoom(room, true, loopback, runTimeMs); return; } + + addFavoriteButton = (FloatingActionButton) findViewById(R.id.add_favorite_button); + addFavoriteButton.setOnClickListener(addFavoriteListener); } @Override @@ -157,6 +154,33 @@ public class ConnectActivity extends Activity { return true; } + @Override + public void onCreateContextMenu(ContextMenu menu, View v, ContextMenu.ContextMenuInfo menuInfo) { + if (v.getId() == R.id.room_listview) { + AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) menuInfo; + menu.setHeaderTitle(roomList.get(info.position)); + String[] menuItems = getResources().getStringArray(R.array.roomListContextMenu); + for (int i = 0; i < menuItems.length; i++) { + menu.add(Menu.NONE, i, i, menuItems[i]); + } + } else { + super.onCreateContextMenu(menu, v, menuInfo); + } + } + + @Override + public boolean onContextItemSelected(MenuItem item) { + if (item.getItemId() == REMOVE_FAVORITE_INDEX) { + AdapterView.AdapterContextMenuInfo info = + (AdapterView.AdapterContextMenuInfo) item.getMenuInfo(); + roomList.remove(info.position); + adapter.notifyDataSetChanged(); + return true; + } + + return super.onContextItemSelected(item); + } + @Override public boolean onOptionsItemSelected(MenuItem item) { // Handle presses on the action bar items. @@ -164,6 +188,9 @@ public class ConnectActivity extends Activity { Intent intent = new Intent(this, SettingsActivity.class); startActivity(intent); return true; + } else if (item.getItemId() == R.id.action_loopback) { + connectToRoom(null, false, true, 0); + return true; } else { return super.onOptionsItemSelected(item); } @@ -217,28 +244,13 @@ public class ConnectActivity extends Activity { } } - private final OnClickListener connectListener = new OnClickListener() { - @Override - public void onClick(View view) { - boolean loopback = false; - if (view.getId() == R.id.connect_loopback_button) { - loopback = true; - } - commandLineRun = false; - connectToRoom(loopback, 0); - } - }; + private void connectToRoom( + String roomId, boolean commandLineRun, boolean loopback, int runTimeMs) { + this.commandLineRun = commandLineRun; - private void connectToRoom(boolean loopback, int runTimeMs) { - // Get room name (random for loopback). - String roomId; + // roomId is random for loopback. if (loopback) { roomId = Integer.toString((new Random()).nextInt(100000000)); - } else { - roomId = getSelectedItem(); - if (roomId == null) { - roomId = roomEditText.getText().toString(); - } } String roomUrl = sharedPref.getString( @@ -390,41 +402,46 @@ public class ConnectActivity extends Activity { return false; } - private final OnClickListener addRoomListener = new OnClickListener() { + private final AdapterView.OnItemClickListener + roomListClickListener = new AdapterView.OnItemClickListener() { @Override - public void onClick(View view) { - String newRoom = roomEditText.getText().toString(); - if (newRoom.length() > 0 && !roomList.contains(newRoom)) { - adapter.add(newRoom); - adapter.notifyDataSetChanged(); - } + public void onItemClick(AdapterView adapterView, View view, int i, long l) { + String roomId = ((TextView) view).getText().toString(); + connectToRoom(roomId, false, false, 0); } }; - private final OnClickListener removeRoomListener = new OnClickListener() { + private final OnClickListener addFavoriteListener = new OnClickListener() { @Override public void onClick(View view) { - String selectedRoom = getSelectedItem(); - if (selectedRoom != null) { - adapter.remove(selectedRoom); - adapter.notifyDataSetChanged(); - } + AlertDialog.Builder builder = new AlertDialog.Builder(ConnectActivity.this); + + final View dialogView = LayoutInflater.from(ConnectActivity.this) + .inflate(R.layout.dialog_add_favorite, null); + final EditText favoriteEditText = (EditText) dialogView.findViewById(R.id.favorite_edittext); + favoriteEditText.append(roomEditText.getText()); + + builder.setTitle(R.string.add_favorite_title) + .setPositiveButton(R.string.add, new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialogInterface, int i) { + String newRoom = favoriteEditText.getText().toString(); + if (newRoom.length() > 0 && !roomList.contains(newRoom)) { + adapter.add(newRoom); + adapter.notifyDataSetChanged(); + } + } + }) + .setView(dialogView) + .setNegativeButton(R.string.cancel, null); + builder.show(); } }; - private String getSelectedItem() { - int position = AdapterView.INVALID_POSITION; - if (roomListView.getCheckedItemCount() > 0 && adapter.getCount() > 0) { - position = roomListView.getCheckedItemPosition(); - if (position >= adapter.getCount()) { - position = AdapterView.INVALID_POSITION; - } + private final OnClickListener connectListener = new OnClickListener() { + @Override + public void onClick(View view) { + connectToRoom(roomEditText.getText().toString(), false, false, 0); } - if (position != AdapterView.INVALID_POSITION) { - return adapter.getItem(position); - } else { - return null; - } - } - + }; } diff --git a/webrtc/webrtc_examples.gyp b/webrtc/webrtc_examples.gyp index 4420d8dd64..9ef10cebf6 100755 --- a/webrtc/webrtc_examples.gyp +++ b/webrtc/webrtc_examples.gyp @@ -408,6 +408,7 @@ 'type': 'none', 'dependencies': [ 'api/api.gyp:libjingle_peerconnection_java', + '<(DEPTH)/third_party/android_tools/android_tools.gyp:android_support_design_javalib' ], 'variables': { 'apk_name': 'AppRTCDemo', @@ -418,9 +419,11 @@ 'R_package_relpath': 'org/appspot/apprtc', 'input_jars_paths': [ 'examples/androidapp/third_party/autobanh/autobanh.jar', + '<(DEPTH)/third_party/android_tools/sdk/extras/android/support/v4/android-support-v4.jar', ], 'library_dexed_jars_paths': [ 'examples/androidapp/third_party/autobanh/autobanh.jar', + '<(DEPTH)/third_party/android_tools/sdk/extras/android/support/v4/android-support-v4.jar', ], 'native_lib_target': 'libjingle_peerconnection_so', 'add_to_dependents_classpaths':1,