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

Unified Diff: remoting/android/java/src/org/chromium/chromoting/Chromoting.java

Issue 1968283002: Implementing Host List Context Menu and Delete Feature (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: UI Only & Reviewer's Feedback Created 4 years, 7 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 side-by-side diff with in-line comments
Download patch
Index: remoting/android/java/src/org/chromium/chromoting/Chromoting.java
diff --git a/remoting/android/java/src/org/chromium/chromoting/Chromoting.java b/remoting/android/java/src/org/chromium/chromoting/Chromoting.java
index 1e41d10888cdcdcdbe59cf432578005b3a5ee8b0..bbecd4e39e44828874911088c280ff50b92fa3bb 100644
--- a/remoting/android/java/src/org/chromium/chromoting/Chromoting.java
+++ b/remoting/android/java/src/org/chromium/chromoting/Chromoting.java
@@ -20,6 +20,7 @@ import android.support.v7.app.ActionBarDrawerToggle;
import android.support.v7.app.AlertDialog;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
+import android.view.ContextMenu;
import android.view.Gravity;
import android.view.Menu;
import android.view.MenuItem;
@@ -184,6 +185,7 @@ public class Chromoting extends AppCompatActivity implements ConnectionListener,
// Get ahold of our view widgets.
mHostListView = (ListView) findViewById(R.id.hostList_chooser);
+ registerForContextMenu(mHostListView);
mEmptyView = findViewById(R.id.hostList_empty);
mHostListView.setOnItemClickListener(
new AdapterView.OnItemClickListener() {
@@ -395,6 +397,49 @@ public class Chromoting extends AppCompatActivity implements ConnectionListener,
mDrawerToggle.onConfigurationChanged(newConfig);
}
+ private static int getHostIndexForMenu(ContextMenu.ContextMenuInfo menuInfo) {
+ return ((AdapterView.AdapterContextMenuInfo) menuInfo).position;
+ }
+
+ @Override
+ public void onCreateContextMenu(ContextMenu menu, View v,
+ ContextMenu.ContextMenuInfo menuInfo) {
+ super.onCreateContextMenu(menu, v, menuInfo);
+ if (v.getId() == R.id.hostList_chooser) {
+ getMenuInflater().inflate(R.menu.options_actionbar, menu);
+ HostInfo info = mHosts[getHostIndexForMenu(menuInfo)];
+ menu.setHeaderTitle(info.name);
+ }
+ }
+
+ @Override
+ public boolean onContextItemSelected(MenuItem item) {
+ int itemId = item.getItemId();
+ int hostIndex = getHostIndexForMenu(item.getMenuInfo());
+ if (itemId == R.id.actionbar_connect) {
+ onHostClicked(hostIndex);
+ } else if (itemId == R.id.actionbar_delete) {
+ HostInfo hostInfo = mHosts[hostIndex];
Lambros 2016/05/13 21:17:11 I would suggest factoring out this block into a se
Yuwei 2016/05/13 23:43:54 Done.
+ final String hostId = hostInfo.id;
+ AlertDialog.Builder builder = new AlertDialog.Builder(this);
Lambros 2016/05/13 21:17:11 Maybe remove |builder| temporary and do: new Aler
Yuwei 2016/05/13 23:43:54 Done.
+ String message = getString(R.string.confirm_host_delete_android, hostInfo.name);
+ builder.setMessage(message)
+ .setPositiveButton(android.R.string.yes,
+ new DialogInterface.OnClickListener() {
+ @Override
+ public void onClick(DialogInterface dialog, int which) {
+ deleteHost(hostId);
+ dialog.dismiss();
+ }
+ })
+ .setNegativeButton(android.R.string.no, null)
+ .create().show();
+ } else {
+ return false;
+ }
+ return true;
+ }
+
/** Called to initialize the action bar. */
@Override
public boolean onCreateOptionsMenu(Menu menu) {

Powered by Google App Engine
This is Rietveld 408576698