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

Side by Side 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 unified diff | Download patch
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 package org.chromium.chromoting; 5 package org.chromium.chromoting;
6 6
7 import android.annotation.SuppressLint; 7 import android.annotation.SuppressLint;
8 import android.app.ProgressDialog; 8 import android.app.ProgressDialog;
9 import android.content.DialogInterface; 9 import android.content.DialogInterface;
10 import android.content.Intent; 10 import android.content.Intent;
11 import android.content.SharedPreferences; 11 import android.content.SharedPreferences;
12 import android.content.pm.PackageManager; 12 import android.content.pm.PackageManager;
13 import android.content.res.Configuration; 13 import android.content.res.Configuration;
14 import android.graphics.drawable.Drawable; 14 import android.graphics.drawable.Drawable;
15 import android.os.Bundle; 15 import android.os.Bundle;
16 import android.provider.Settings; 16 import android.provider.Settings;
17 import android.support.v4.graphics.drawable.DrawableCompat; 17 import android.support.v4.graphics.drawable.DrawableCompat;
18 import android.support.v4.widget.DrawerLayout; 18 import android.support.v4.widget.DrawerLayout;
19 import android.support.v7.app.ActionBarDrawerToggle; 19 import android.support.v7.app.ActionBarDrawerToggle;
20 import android.support.v7.app.AlertDialog; 20 import android.support.v7.app.AlertDialog;
21 import android.support.v7.app.AppCompatActivity; 21 import android.support.v7.app.AppCompatActivity;
22 import android.support.v7.widget.Toolbar; 22 import android.support.v7.widget.Toolbar;
23 import android.view.ContextMenu;
23 import android.view.Gravity; 24 import android.view.Gravity;
24 import android.view.Menu; 25 import android.view.Menu;
25 import android.view.MenuItem; 26 import android.view.MenuItem;
26 import android.view.View; 27 import android.view.View;
27 import android.widget.AdapterView; 28 import android.widget.AdapterView;
28 import android.widget.ArrayAdapter; 29 import android.widget.ArrayAdapter;
29 import android.widget.LinearLayout; 30 import android.widget.LinearLayout;
30 import android.widget.ListView; 31 import android.widget.ListView;
31 import android.widget.Toast; 32 import android.widget.Toast;
32 33
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after
177 super.onCreate(savedInstanceState); 178 super.onCreate(savedInstanceState);
178 setContentView(R.layout.main); 179 setContentView(R.layout.main);
179 180
180 Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); 181 Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
181 setSupportActionBar(toolbar); 182 setSupportActionBar(toolbar);
182 183
183 mHostListManager = new HostListManager(); 184 mHostListManager = new HostListManager();
184 185
185 // Get ahold of our view widgets. 186 // Get ahold of our view widgets.
186 mHostListView = (ListView) findViewById(R.id.hostList_chooser); 187 mHostListView = (ListView) findViewById(R.id.hostList_chooser);
188 registerForContextMenu(mHostListView);
187 mEmptyView = findViewById(R.id.hostList_empty); 189 mEmptyView = findViewById(R.id.hostList_empty);
188 mHostListView.setOnItemClickListener( 190 mHostListView.setOnItemClickListener(
189 new AdapterView.OnItemClickListener() { 191 new AdapterView.OnItemClickListener() {
190 @Override 192 @Override
191 public void onItemClick(AdapterView<?> parent, View view, in t position, 193 public void onItemClick(AdapterView<?> parent, View view, in t position,
192 long id) { 194 long id) {
193 onHostClicked(position); 195 onHostClicked(position);
194 } 196 }
195 }); 197 });
196 198
(...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after
388 } 390 }
389 391
390 /** Called when the display is rotated (as registered in the manifest). */ 392 /** Called when the display is rotated (as registered in the manifest). */
391 @Override 393 @Override
392 public void onConfigurationChanged(Configuration newConfig) { 394 public void onConfigurationChanged(Configuration newConfig) {
393 super.onConfigurationChanged(newConfig); 395 super.onConfigurationChanged(newConfig);
394 396
395 mDrawerToggle.onConfigurationChanged(newConfig); 397 mDrawerToggle.onConfigurationChanged(newConfig);
396 } 398 }
397 399
400 private static int getHostIndexForMenu(ContextMenu.ContextMenuInfo menuInfo) {
401 return ((AdapterView.AdapterContextMenuInfo) menuInfo).position;
402 }
403
404 @Override
405 public void onCreateContextMenu(ContextMenu menu, View v,
406 ContextMenu.ContextMenuInfo menuInfo) {
407 super.onCreateContextMenu(menu, v, menuInfo);
408 if (v.getId() == R.id.hostList_chooser) {
409 getMenuInflater().inflate(R.menu.options_actionbar, menu);
410 HostInfo info = mHosts[getHostIndexForMenu(menuInfo)];
411 menu.setHeaderTitle(info.name);
412 }
413 }
414
415 @Override
416 public boolean onContextItemSelected(MenuItem item) {
417 int itemId = item.getItemId();
418 int hostIndex = getHostIndexForMenu(item.getMenuInfo());
419 if (itemId == R.id.actionbar_connect) {
420 onHostClicked(hostIndex);
421 } else if (itemId == R.id.actionbar_delete) {
422 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.
423 final String hostId = hostInfo.id;
424 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.
425 String message = getString(R.string.confirm_host_delete_android, hos tInfo.name);
426 builder.setMessage(message)
427 .setPositiveButton(android.R.string.yes,
428 new DialogInterface.OnClickListener() {
429 @Override
430 public void onClick(DialogInterface dialog, int which) {
431 deleteHost(hostId);
432 dialog.dismiss();
433 }
434 })
435 .setNegativeButton(android.R.string.no, null)
436 .create().show();
437 } else {
438 return false;
439 }
440 return true;
441 }
442
398 /** Called to initialize the action bar. */ 443 /** Called to initialize the action bar. */
399 @Override 444 @Override
400 public boolean onCreateOptionsMenu(Menu menu) { 445 public boolean onCreateOptionsMenu(Menu menu) {
401 getMenuInflater().inflate(R.menu.chromoting_actionbar, menu); 446 getMenuInflater().inflate(R.menu.chromoting_actionbar, menu);
402 mRefreshButton = menu.findItem(R.id.actionbar_directoryrefresh); 447 mRefreshButton = menu.findItem(R.id.actionbar_directoryrefresh);
403 448
404 if (mAccount == null) { 449 if (mAccount == null) {
405 // If there is no account, don't allow the user to refresh the listi ng. 450 // If there is no account, don't allow the user to refresh the listi ng.
406 mRefreshButton.setEnabled(false); 451 mRefreshButton.setEnabled(false);
407 } 452 }
(...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after
641 // Unreachable, but required by Google Java style and findbugs. 686 // Unreachable, but required by Google Java style and findbugs.
642 assert false : "Unreached"; 687 assert false : "Unreached";
643 } 688 }
644 689
645 if (dismissProgress && mProgressIndicator != null) { 690 if (dismissProgress && mProgressIndicator != null) {
646 mProgressIndicator.dismiss(); 691 mProgressIndicator.dismiss();
647 mProgressIndicator = null; 692 mProgressIndicator = null;
648 } 693 }
649 } 694 }
650 } 695 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698