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

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

Issue 2389153003: [remoting android] Close navigation drawer before opening Help/Feedback. (Closed)
Patch Set: Created 4 years, 2 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
« no previous file with comments | « no previous file | remoting/android/java/src/org/chromium/chromoting/NavigationMenuAdapter.java » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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;
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
101 private OAuthTokenConsumer mHostConnectingConsumer; 101 private OAuthTokenConsumer mHostConnectingConsumer;
102 102
103 private OAuthTokenConsumer mHostListRetrievingConsumer; 103 private OAuthTokenConsumer mHostListRetrievingConsumer;
104 104
105 private OAuthTokenConsumer mHostDeletingConsumer; 105 private OAuthTokenConsumer mHostDeletingConsumer;
106 106
107 private DrawerLayout mDrawerLayout; 107 private DrawerLayout mDrawerLayout;
108 108
109 private ActionBarDrawerToggle mDrawerToggle; 109 private ActionBarDrawerToggle mDrawerToggle;
110 110
111 /**
112 * Task to be run after the navigation drawer is closed. Can be null. This i s used to run
113 * Help/Feedback tasks which require a screenshot with the drawer closed.
114 */
115 private Runnable mPendingDrawerCloseTask;
116
111 private AccountSwitcher mAccountSwitcher; 117 private AccountSwitcher mAccountSwitcher;
112 118
113 /** The currently-connected Client, if any. */ 119 /** The currently-connected Client, if any. */
114 private Client mClient; 120 private Client mClient;
115 121
116 /** Shows a warning explaining that a Google account is required, then close s the activity. */ 122 /** Shows a warning explaining that a Google account is required, then close s the activity. */
117 private void showNoAccountsDialog() { 123 private void showNoAccountsDialog() {
118 AlertDialog.Builder builder = new AlertDialog.Builder(this); 124 AlertDialog.Builder builder = new AlertDialog.Builder(this);
119 builder.setMessage(R.string.noaccounts_message); 125 builder.setMessage(R.string.noaccounts_message);
120 builder.setPositiveButton(R.string.noaccounts_add_account, 126 builder.setPositiveButton(R.string.noaccounts_add_account,
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
160 * Shows the appropriate view for the host list and hides the loading indica tor. Shows either 166 * Shows the appropriate view for the host list and hides the loading indica tor. Shows either
161 * the host list chooser or the host list empty view, depending on whether m Hosts contains any 167 * the host list chooser or the host list empty view, depending on whether m Hosts contains any
162 * hosts. 168 * hosts.
163 */ 169 */
164 private void updateHostListView() { 170 private void updateHostListView() {
165 mHostListView.setVisibility(mHosts.length == 0 ? View.GONE : View.VISIBL E); 171 mHostListView.setVisibility(mHosts.length == 0 ? View.GONE : View.VISIBL E);
166 mEmptyView.setVisibility(mHosts.length == 0 ? View.VISIBLE : View.GONE); 172 mEmptyView.setVisibility(mHosts.length == 0 ? View.VISIBLE : View.GONE);
167 mProgressView.setVisibility(View.GONE); 173 mProgressView.setVisibility(View.GONE);
168 } 174 }
169 175
176 private void runPendingDrawerCloseTask() {
177 // Avoid potential recursion problems by null-ing the task first.
178 Runnable task = mPendingDrawerCloseTask;
Yuwei 2016/10/04 23:41:14 Optionally you can have a queue of pending tasks r
Lambros 2016/10/05 00:03:15 Acknowledged. No need for a queue just yet.
179 mPendingDrawerCloseTask = null;
180 if (task != null) {
181 task.run();
182 }
183 }
184
185 private void closeDrawerThenRun(Runnable task) {
Yuwei 2016/10/04 23:41:14 Instead of having extra launch* methods here, coul
Lambros 2016/10/05 00:03:15 If I'm not mistaken, this would mean doubly-nested
Yuwei 2016/10/05 00:27:02 Yep. Callback hell :) Though it can be simplified
186 mPendingDrawerCloseTask = task;
187 if (mDrawerLayout.isDrawerOpen(Gravity.START)) {
188 mDrawerLayout.closeDrawer(Gravity.START);
189 } else {
190 runPendingDrawerCloseTask();
191 }
192 }
193
194 /** Closes any navigation drawer, then shows the Help screen. */
195 public void launchHelp(final HelpContext helpContext) {
196 closeDrawerThenRun(new Runnable() {
197 @Override
198 public void run() {
199 HelpSingleton.getInstance().launchHelp(Chromoting.this, helpCont ext);
200 }
201 });
202 }
203
204 /** Closes any navigation drawer, then shows the Feedback screen. */
205 public void launchFeedback() {
206 closeDrawerThenRun(new Runnable() {
207 @Override
208 public void run() {
209 HelpSingleton.getInstance().launchFeedback(Chromoting.this);
210 }
211 });
212 }
213
170 /** 214 /**
171 * Called when the activity is first created. Loads the native library and r equests an 215 * Called when the activity is first created. Loads the native library and r equests an
172 * authentication token from the system. 216 * authentication token from the system.
173 */ 217 */
174 @Override 218 @Override
175 public void onCreate(Bundle savedInstanceState) { 219 public void onCreate(Bundle savedInstanceState) {
176 super.onCreate(savedInstanceState); 220 super.onCreate(savedInstanceState);
177 setContentView(R.layout.main); 221 setContentView(R.layout.main);
178 222
179 Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); 223 Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
(...skipping 13 matching lines...) Expand all
193 onHostClicked(position); 237 onHostClicked(position);
194 } 238 }
195 }); 239 });
196 240
197 mProgressView = findViewById(R.id.hostList_progress); 241 mProgressView = findViewById(R.id.hostList_progress);
198 242
199 findViewById(R.id.host_setup_link_android).setOnClickListener(this); 243 findViewById(R.id.host_setup_link_android).setOnClickListener(this);
200 244
201 mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout); 245 mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
202 mDrawerToggle = new ActionBarDrawerToggle(this, mDrawerLayout, toolbar, 246 mDrawerToggle = new ActionBarDrawerToggle(this, mDrawerLayout, toolbar,
203 R.string.open_navigation_drawer, R.string.close_navigation_drawe r); 247 R.string.open_navigation_drawer, R.string.close_navigation_drawe r) {
248 @Override
249 public void onDrawerClosed(View drawerView) {
250 super.onDrawerClosed(drawerView);
251 runPendingDrawerCloseTask();
252 }
253 };
204 mDrawerLayout.addDrawerListener(mDrawerToggle); 254 mDrawerLayout.addDrawerListener(mDrawerToggle);
205 255
206 // Disable the hamburger icon animation. This is more complex than it ou ght to be. 256 // Disable the hamburger icon animation. This is more complex than it ou ght to be.
207 // The animation can be customized by tweaking some style parameters - s ee 257 // The animation can be customized by tweaking some style parameters - s ee
208 // http://developer.android.com/reference/android/support/v7/appcompat/R .styleable.html#DrawerArrowToggle . 258 // http://developer.android.com/reference/android/support/v7/appcompat/R .styleable.html#DrawerArrowToggle .
209 // But these can't disable the animation completely. 259 // But these can't disable the animation completely.
210 // The icon can only be changed by disabling the drawer indicator, which has side-effects 260 // The icon can only be changed by disabling the drawer indicator, which has side-effects
211 // that must be worked around. It disables the built-in click listener, so this has to be 261 // that must be worked around. It disables the built-in click listener, so this has to be
212 // implemented and added. This also requires that the toolbar be passed to the 262 // implemented and added. This also requires that the toolbar be passed to the
213 // ActionBarDrawerToggle ctor above (otherwise the listener is ignored a nd warnings are 263 // ActionBarDrawerToggle ctor above (otherwise the listener is ignored a nd warnings are
(...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after
433 if (id == R.id.actionbar_directoryrefresh) { 483 if (id == R.id.actionbar_directoryrefresh) {
434 refreshHostList(); 484 refreshHostList();
435 return true; 485 return true;
436 } 486 }
437 return super.onOptionsItemSelected(item); 487 return super.onOptionsItemSelected(item);
438 } 488 }
439 489
440 /** Called when the user touches hyperlinked text. */ 490 /** Called when the user touches hyperlinked text. */
441 @Override 491 @Override
442 public void onClick(View view) { 492 public void onClick(View view) {
443 HelpSingleton.getInstance().launchHelp(this, HelpContext.HOST_SETUP); 493 launchHelp(HelpContext.HOST_SETUP);
444 } 494 }
445 495
446 private void onDeleteHostClicked(int hostIndex) { 496 private void onDeleteHostClicked(int hostIndex) {
447 HostInfo hostInfo = mHosts[hostIndex]; 497 HostInfo hostInfo = mHosts[hostIndex];
448 final String hostId = hostInfo.id; 498 final String hostId = hostInfo.id;
449 String message = getString(R.string.confirm_host_delete_android, hostInf o.name); 499 String message = getString(R.string.confirm_host_delete_android, hostInf o.name);
450 new AlertDialog.Builder(this) 500 new AlertDialog.Builder(this)
451 .setMessage(message) 501 .setMessage(message)
452 .setPositiveButton(android.R.string.yes, 502 .setPositiveButton(android.R.string.yes,
453 new DialogInterface.OnClickListener() { 503 new DialogInterface.OnClickListener() {
(...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after
675 // Unreachable, but required by Google Java style and findbugs. 725 // Unreachable, but required by Google Java style and findbugs.
676 assert false : "Unreached"; 726 assert false : "Unreached";
677 } 727 }
678 728
679 if (dismissProgress && mProgressIndicator != null) { 729 if (dismissProgress && mProgressIndicator != null) {
680 mProgressIndicator.dismiss(); 730 mProgressIndicator.dismiss();
681 mProgressIndicator = null; 731 mProgressIndicator = null;
682 } 732 }
683 } 733 }
684 } 734 }
OLDNEW
« no previous file with comments | « no previous file | remoting/android/java/src/org/chromium/chromoting/NavigationMenuAdapter.java » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698