Commit c7c97a5c authored by lambroslambrou's avatar lambroslambrou Committed by Commit bot

[remoting android] Close navigation drawer before opening Help/Feedback.

This causes the Feedback screenshot to be captured after the drawer is
closed.

BUG=651527

Review-Url: https://codereview.chromium.org/2389153003
Cr-Commit-Position: refs/heads/master@{#423024}
parent cc9948e8
......@@ -108,6 +108,12 @@ public class Chromoting extends AppCompatActivity implements ConnectionListener,
private ActionBarDrawerToggle mDrawerToggle;
/**
* Task to be run after the navigation drawer is closed. Can be null. This is used to run
* Help/Feedback tasks which require a screenshot with the drawer closed.
*/
private Runnable mPendingDrawerCloseTask;
private AccountSwitcher mAccountSwitcher;
/** The currently-connected Client, if any. */
......@@ -167,6 +173,44 @@ public class Chromoting extends AppCompatActivity implements ConnectionListener,
mProgressView.setVisibility(View.GONE);
}
private void runPendingDrawerCloseTask() {
// Avoid potential recursion problems by null-ing the task first.
Runnable task = mPendingDrawerCloseTask;
mPendingDrawerCloseTask = null;
if (task != null) {
task.run();
}
}
private void closeDrawerThenRun(Runnable task) {
mPendingDrawerCloseTask = task;
if (mDrawerLayout.isDrawerOpen(Gravity.START)) {
mDrawerLayout.closeDrawer(Gravity.START);
} else {
runPendingDrawerCloseTask();
}
}
/** Closes any navigation drawer, then shows the Help screen. */
public void launchHelp(final HelpContext helpContext) {
closeDrawerThenRun(new Runnable() {
@Override
public void run() {
HelpSingleton.getInstance().launchHelp(Chromoting.this, helpContext);
}
});
}
/** Closes any navigation drawer, then shows the Feedback screen. */
public void launchFeedback() {
closeDrawerThenRun(new Runnable() {
@Override
public void run() {
HelpSingleton.getInstance().launchFeedback(Chromoting.this);
}
});
}
/**
* Called when the activity is first created. Loads the native library and requests an
* authentication token from the system.
......@@ -200,7 +244,13 @@ public class Chromoting extends AppCompatActivity implements ConnectionListener,
mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
mDrawerToggle = new ActionBarDrawerToggle(this, mDrawerLayout, toolbar,
R.string.open_navigation_drawer, R.string.close_navigation_drawer);
R.string.open_navigation_drawer, R.string.close_navigation_drawer) {
@Override
public void onDrawerClosed(View drawerView) {
super.onDrawerClosed(drawerView);
runPendingDrawerCloseTask();
}
};
mDrawerLayout.addDrawerListener(mDrawerToggle);
// Disable the hamburger icon animation. This is more complex than it ought to be.
......@@ -440,7 +490,7 @@ public class Chromoting extends AppCompatActivity implements ConnectionListener,
/** Called when the user touches hyperlinked text. */
@Override
public void onClick(View view) {
HelpSingleton.getInstance().launchHelp(this, HelpContext.HOST_SETUP);
launchHelp(HelpContext.HOST_SETUP);
}
private void onDeleteHostClicked(int hostIndex) {
......
......@@ -17,7 +17,6 @@ import android.widget.TextView;
import org.chromium.base.ApiCompatibilityUtils;
import org.chromium.chromoting.help.HelpContext;
import org.chromium.chromoting.help.HelpSingleton;
/**
* Describes the appearance and behavior of the navigation menu. This also implements
......@@ -40,33 +39,30 @@ public class NavigationMenuAdapter extends ArrayAdapter<NavigationMenuAdapter.Na
}
}
public static ListView createNavigationMenu(final Activity activity) {
ListView navigationMenu = (ListView) activity.getLayoutInflater()
.inflate(R.layout.navigation_list, null);
public static ListView createNavigationMenu(final Chromoting chromoting) {
ListView navigationMenu =
(ListView) chromoting.getLayoutInflater().inflate(R.layout.navigation_list, null);
NavigationMenuItem feedbackItem = new NavigationMenuItem(
activity.getResources().getString(R.string.actionbar_send_feedback),
getIcon(activity, R.drawable.ic_announcement),
new Runnable() {
chromoting.getResources().getString(R.string.actionbar_send_feedback),
getIcon(chromoting, R.drawable.ic_announcement), new Runnable() {
@Override
public void run() {
HelpSingleton.getInstance().launchFeedback(activity);
chromoting.launchFeedback();
}
});
NavigationMenuItem helpItem = new NavigationMenuItem(
activity.getResources().getString(R.string.actionbar_help),
getIcon(activity, R.drawable.ic_help),
new Runnable() {
chromoting.getResources().getString(R.string.actionbar_help),
getIcon(chromoting, R.drawable.ic_help), new Runnable() {
@Override
public void run() {
HelpSingleton.getInstance().launchHelp(activity,
HelpContext.HOST_LIST);
chromoting.launchHelp(HelpContext.HOST_LIST);
}
});
NavigationMenuItem[] navigationMenuItems = { feedbackItem, helpItem };
NavigationMenuAdapter adapter = new NavigationMenuAdapter(activity, navigationMenuItems);
NavigationMenuAdapter adapter = new NavigationMenuAdapter(chromoting, navigationMenuItems);
navigationMenu.setAdapter(adapter);
navigationMenu.setOnItemClickListener(adapter);
return navigationMenu;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment