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, ...@@ -108,6 +108,12 @@ public class Chromoting extends AppCompatActivity implements ConnectionListener,
private ActionBarDrawerToggle mDrawerToggle; 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; private AccountSwitcher mAccountSwitcher;
/** The currently-connected Client, if any. */ /** The currently-connected Client, if any. */
...@@ -167,6 +173,44 @@ public class Chromoting extends AppCompatActivity implements ConnectionListener, ...@@ -167,6 +173,44 @@ public class Chromoting extends AppCompatActivity implements ConnectionListener,
mProgressView.setVisibility(View.GONE); 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 * Called when the activity is first created. Loads the native library and requests an
* authentication token from the system. * authentication token from the system.
...@@ -200,7 +244,13 @@ public class Chromoting extends AppCompatActivity implements ConnectionListener, ...@@ -200,7 +244,13 @@ public class Chromoting extends AppCompatActivity implements ConnectionListener,
mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout); mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
mDrawerToggle = new ActionBarDrawerToggle(this, mDrawerLayout, toolbar, 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); mDrawerLayout.addDrawerListener(mDrawerToggle);
// Disable the hamburger icon animation. This is more complex than it ought to be. // 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, ...@@ -440,7 +490,7 @@ public class Chromoting extends AppCompatActivity implements ConnectionListener,
/** Called when the user touches hyperlinked text. */ /** Called when the user touches hyperlinked text. */
@Override @Override
public void onClick(View view) { public void onClick(View view) {
HelpSingleton.getInstance().launchHelp(this, HelpContext.HOST_SETUP); launchHelp(HelpContext.HOST_SETUP);
} }
private void onDeleteHostClicked(int hostIndex) { private void onDeleteHostClicked(int hostIndex) {
......
...@@ -17,7 +17,6 @@ import android.widget.TextView; ...@@ -17,7 +17,6 @@ import android.widget.TextView;
import org.chromium.base.ApiCompatibilityUtils; import org.chromium.base.ApiCompatibilityUtils;
import org.chromium.chromoting.help.HelpContext; import org.chromium.chromoting.help.HelpContext;
import org.chromium.chromoting.help.HelpSingleton;
/** /**
* Describes the appearance and behavior of the navigation menu. This also implements * Describes the appearance and behavior of the navigation menu. This also implements
...@@ -40,33 +39,30 @@ public class NavigationMenuAdapter extends ArrayAdapter<NavigationMenuAdapter.Na ...@@ -40,33 +39,30 @@ public class NavigationMenuAdapter extends ArrayAdapter<NavigationMenuAdapter.Na
} }
} }
public static ListView createNavigationMenu(final Activity activity) { public static ListView createNavigationMenu(final Chromoting chromoting) {
ListView navigationMenu = (ListView) activity.getLayoutInflater() ListView navigationMenu =
.inflate(R.layout.navigation_list, null); (ListView) chromoting.getLayoutInflater().inflate(R.layout.navigation_list, null);
NavigationMenuItem feedbackItem = new NavigationMenuItem( NavigationMenuItem feedbackItem = new NavigationMenuItem(
activity.getResources().getString(R.string.actionbar_send_feedback), chromoting.getResources().getString(R.string.actionbar_send_feedback),
getIcon(activity, R.drawable.ic_announcement), getIcon(chromoting, R.drawable.ic_announcement), new Runnable() {
new Runnable() {
@Override @Override
public void run() { public void run() {
HelpSingleton.getInstance().launchFeedback(activity); chromoting.launchFeedback();
} }
}); });
NavigationMenuItem helpItem = new NavigationMenuItem( NavigationMenuItem helpItem = new NavigationMenuItem(
activity.getResources().getString(R.string.actionbar_help), chromoting.getResources().getString(R.string.actionbar_help),
getIcon(activity, R.drawable.ic_help), getIcon(chromoting, R.drawable.ic_help), new Runnable() {
new Runnable() {
@Override @Override
public void run() { public void run() {
HelpSingleton.getInstance().launchHelp(activity, chromoting.launchHelp(HelpContext.HOST_LIST);
HelpContext.HOST_LIST);
} }
}); });
NavigationMenuItem[] navigationMenuItems = { feedbackItem, helpItem }; NavigationMenuItem[] navigationMenuItems = { feedbackItem, helpItem };
NavigationMenuAdapter adapter = new NavigationMenuAdapter(activity, navigationMenuItems); NavigationMenuAdapter adapter = new NavigationMenuAdapter(chromoting, navigationMenuItems);
navigationMenu.setAdapter(adapter); navigationMenu.setAdapter(adapter);
navigationMenu.setOnItemClickListener(adapter); navigationMenu.setOnItemClickListener(adapter);
return navigationMenu; 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