| OLD | NEW |
| 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 Loading... |
| 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 Loading... |
| 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.host_context_menu, 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.connect) { |
| 420 onHostClicked(hostIndex); |
| 421 } else if (itemId == R.id.delete) { |
| 422 onDeleteHostClicked(hostIndex); |
| 423 } else { |
| 424 return false; |
| 425 } |
| 426 return true; |
| 427 } |
| 428 |
| 398 /** Called to initialize the action bar. */ | 429 /** Called to initialize the action bar. */ |
| 399 @Override | 430 @Override |
| 400 public boolean onCreateOptionsMenu(Menu menu) { | 431 public boolean onCreateOptionsMenu(Menu menu) { |
| 401 getMenuInflater().inflate(R.menu.chromoting_actionbar, menu); | 432 getMenuInflater().inflate(R.menu.chromoting_actionbar, menu); |
| 402 mRefreshButton = menu.findItem(R.id.actionbar_directoryrefresh); | 433 mRefreshButton = menu.findItem(R.id.actionbar_directoryrefresh); |
| 403 | 434 |
| 404 if (mAccount == null) { | 435 if (mAccount == null) { |
| 405 // If there is no account, don't allow the user to refresh the listi
ng. | 436 // If there is no account, don't allow the user to refresh the listi
ng. |
| 406 mRefreshButton.setEnabled(false); | 437 mRefreshButton.setEnabled(false); |
| 407 } | 438 } |
| (...skipping 17 matching lines...) Expand all Loading... |
| 425 } | 456 } |
| 426 return super.onOptionsItemSelected(item); | 457 return super.onOptionsItemSelected(item); |
| 427 } | 458 } |
| 428 | 459 |
| 429 /** Called when the user touches hyperlinked text. */ | 460 /** Called when the user touches hyperlinked text. */ |
| 430 @Override | 461 @Override |
| 431 public void onClick(View view) { | 462 public void onClick(View view) { |
| 432 HelpSingleton.getInstance().launchHelp(this, HelpContext.HOST_SETUP); | 463 HelpSingleton.getInstance().launchHelp(this, HelpContext.HOST_SETUP); |
| 433 } | 464 } |
| 434 | 465 |
| 466 private void onDeleteHostClicked(int hostIndex) { |
| 467 HostInfo hostInfo = mHosts[hostIndex]; |
| 468 final String hostId = hostInfo.id; |
| 469 String message = getString(R.string.confirm_host_delete_android, hostInf
o.name); |
| 470 new AlertDialog.Builder(this) |
| 471 .setMessage(message) |
| 472 .setPositiveButton(android.R.string.yes, |
| 473 new DialogInterface.OnClickListener() { |
| 474 @Override |
| 475 public void onClick(DialogInterface dialog, int whic
h) { |
| 476 deleteHost(hostId); |
| 477 dialog.dismiss(); |
| 478 } |
| 479 }) |
| 480 .setNegativeButton(android.R.string.no, null) |
| 481 .create().show(); |
| 482 } |
| 483 |
| 435 /** Called when the user taps on a host entry. */ | 484 /** Called when the user taps on a host entry. */ |
| 436 private void onHostClicked(int index) { | 485 private void onHostClicked(int index) { |
| 437 HostInfo host = mHosts[index]; | 486 HostInfo host = mHosts[index]; |
| 438 if (host.isOnline) { | 487 if (host.isOnline) { |
| 439 connectToHost(host); | 488 connectToHost(host); |
| 440 } else { | 489 } else { |
| 441 String tooltip = host.getHostOfflineReasonText(this); | 490 String tooltip = host.getHostOfflineReasonText(this); |
| 442 Toast.makeText(this, tooltip, Toast.LENGTH_SHORT).show(); | 491 Toast.makeText(this, tooltip, Toast.LENGTH_SHORT).show(); |
| 443 } | 492 } |
| 444 } | 493 } |
| (...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 641 // Unreachable, but required by Google Java style and findbugs. | 690 // Unreachable, but required by Google Java style and findbugs. |
| 642 assert false : "Unreached"; | 691 assert false : "Unreached"; |
| 643 } | 692 } |
| 644 | 693 |
| 645 if (dismissProgress && mProgressIndicator != null) { | 694 if (dismissProgress && mProgressIndicator != null) { |
| 646 mProgressIndicator.dismiss(); | 695 mProgressIndicator.dismiss(); |
| 647 mProgressIndicator = null; | 696 mProgressIndicator = null; |
| 648 } | 697 } |
| 649 } | 698 } |
| 650 } | 699 } |
| OLD | NEW |