From c97524bfe7e5770835a7e71ed43d12a2e33b02f2 Mon Sep 17 00:00:00 2001 From: Denis Date: Mon, 20 Oct 2014 11:50:50 +0300 Subject: [PATCH] Added back button and menu iteraction for drawer --- .../osmand/plus/activities/MapActivity.java | 9 ++++++- .../plus/activities/MapActivityActions.java | 26 ++++++++++++++++--- 2 files changed, 31 insertions(+), 4 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/activities/MapActivity.java b/OsmAnd/src/net/osmand/plus/activities/MapActivity.java index 6b03f75220..022555b70e 100644 --- a/OsmAnd/src/net/osmand/plus/activities/MapActivity.java +++ b/OsmAnd/src/net/osmand/plus/activities/MapActivity.java @@ -272,6 +272,13 @@ public class MapActivity extends AccessibleActivity { setIntent(intent); } + @Override + public void onBackPressed() { + if (!mapActions.onBackPressed()){ + super.onBackPressed(); + } + } + @Override protected void onResume() { super.onResume(); @@ -465,7 +472,7 @@ public class MapActivity extends AccessibleActivity { } return true; } else if (keyCode == KeyEvent.KEYCODE_MENU && event.getRepeatCount() == 0) { - mapActions.createOptionsMenuAsDrawer(true); + mapActions.onMenuPressed(); return true; } else if (keyCode == KeyEvent.KEYCODE_SEARCH && event.getRepeatCount() == 0) { Intent newIntent = new Intent(MapActivity.this, getMyApplication().getAppCustomization().getSearchActivity()); diff --git a/OsmAnd/src/net/osmand/plus/activities/MapActivityActions.java b/OsmAnd/src/net/osmand/plus/activities/MapActivityActions.java index 0d43e7fbd0..bb5acdbcee 100644 --- a/OsmAnd/src/net/osmand/plus/activities/MapActivityActions.java +++ b/OsmAnd/src/net/osmand/plus/activities/MapActivityActions.java @@ -92,6 +92,9 @@ public class MapActivityActions implements DialogProvider { private final MapActivity mapActivity; private OsmandSettings settings; private RoutingHelper routingHelper; + + DrawerLayout mDrawerLayout; + ListView mDrawerList; public MapActivityActions(MapActivity mapActivity){ @@ -723,11 +726,28 @@ public class MapActivityActions implements DialogProvider { break; } } - + + public boolean onBackPressed(){ + if (mDrawerLayout.isDrawerOpen(mDrawerList)){ + mDrawerLayout.closeDrawer(mDrawerList); + return true; + } + return false; + } + + public void onMenuPressed(){ + if (mDrawerLayout.isDrawerOpen(mDrawerList)){ + mDrawerLayout.closeDrawer(mDrawerList); + } else { + createOptionsMenuAsDrawer(true); + } + + } + public void createOptionsMenuAsDrawer(boolean show){ final ContextMenuAdapter cm = createOptionsMenu(); - final DrawerLayout mDrawerLayout = (DrawerLayout) mapActivity.findViewById(R.id.drawer_layout); - final ListView mDrawerList = (ListView) mapActivity.findViewById(R.id.left_drawer); + mDrawerLayout = (DrawerLayout) mapActivity.findViewById(R.id.drawer_layout); + mDrawerList = (ListView) mapActivity.findViewById(R.id.left_drawer); mDrawerLayout.setDrawerShadow(R.drawable.drawer_shadow, GravityCompat.START); ListAdapter listAdapter; if(Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB){