From 46d8531c21f6e97fbdb08c1d81bee047f7760ebd Mon Sep 17 00:00:00 2001 From: GaidamakUA Date: Mon, 24 Aug 2015 12:22:05 +0300 Subject: [PATCH] drawer is working --- OsmAnd/res/layout/dashboard_toolbar.xml | 75 ++++++------ OsmAnd/res/layout/main.xml | 2 +- .../net/osmand/plus/ContextMenuAdapter.java | 2 +- .../osmand/plus/activities/MapActivity.java | 108 ++++++++++++------ .../plus/activities/MapActivityActions.java | 11 +- .../osmand/plus/dashboard/DashboardOnMap.java | 27 +---- .../osmand/plus/views/MapControlsLayer.java | 5 +- 7 files changed, 130 insertions(+), 100 deletions(-) diff --git a/OsmAnd/res/layout/dashboard_toolbar.xml b/OsmAnd/res/layout/dashboard_toolbar.xml index a983b43a9f..28b85ac22c 100644 --- a/OsmAnd/res/layout/dashboard_toolbar.xml +++ b/OsmAnd/res/layout/dashboard_toolbar.xml @@ -1,63 +1,54 @@ - + app:contentInsetStart="4dp"> - - - + android:src="@drawable/abc_ic_ab_back_mtrl_am_alpha" + tools:visibility="visible"/> + android:src="@drawable/ic_navigation_drawer"/> - - - - - + android:src="@drawable/ic_action_settings"/> + + + - + android:src="@drawable/ic_action_done"/> + - - + android:src="@drawable/ic_sort_waypoint_dark"/> + + + android:src="@drawable/ic_flat_list_dark" + android:visibility="gone"/> + android:src="@drawable/ic_action_edit_dark" + android:visibility="gone"/> \ No newline at end of file diff --git a/OsmAnd/res/layout/main.xml b/OsmAnd/res/layout/main.xml index 1b08bd647e..9908d51e14 100644 --- a/OsmAnd/res/layout/main.xml +++ b/OsmAnd/res/layout/main.xml @@ -1,11 +1,11 @@ diff --git a/OsmAnd/src/net/osmand/plus/ContextMenuAdapter.java b/OsmAnd/src/net/osmand/plus/ContextMenuAdapter.java index 60d11a24f5..96b4c70962 100644 --- a/OsmAnd/src/net/osmand/plus/ContextMenuAdapter.java +++ b/OsmAnd/src/net/osmand/plus/ContextMenuAdapter.java @@ -351,7 +351,7 @@ public class ContextMenuAdapter { if (layoutId == R.layout.simple_list_menu_item) { float density = activity.getResources().getDisplayMetrics().density; int paddingInPixels = (int) (24 * density); - int drawableSizeInPixels = (int) (50 * density); // 32 + int drawableSizeInPixels = (int) (32 * density); // 32 imageId.setBounds(0, 0, drawableSizeInPixels, drawableSizeInPixels); tv.setCompoundDrawables(imageId, null, null, null); tv.setCompoundDrawablePadding(paddingInPixels); diff --git a/OsmAnd/src/net/osmand/plus/activities/MapActivity.java b/OsmAnd/src/net/osmand/plus/activities/MapActivity.java index b5f8b31162..58d64a3d6d 100644 --- a/OsmAnd/src/net/osmand/plus/activities/MapActivity.java +++ b/OsmAnd/src/net/osmand/plus/activities/MapActivity.java @@ -15,14 +15,18 @@ import android.os.Environment; import android.os.Handler; import android.os.Message; import android.support.v4.app.NotificationCompat.Builder; +import android.support.v4.widget.DrawerLayout; import android.support.v7.app.NotificationCompat; +import android.util.Log; +import android.view.Gravity; import android.view.KeyEvent; import android.view.MotionEvent; import android.view.View; import android.view.ViewStub; import android.view.Window; import android.view.WindowManager; -import android.widget.LinearLayout; +import android.widget.AdapterView; +import android.widget.ArrayAdapter; import android.widget.ListView; import android.widget.ProgressBar; import android.widget.TextView; @@ -46,6 +50,7 @@ import net.osmand.plus.AppInitializer.AppInitializeListener; import net.osmand.plus.AppInitializer.InitEvents; import net.osmand.plus.ApplicationMode; import net.osmand.plus.BusyIndicator; +import net.osmand.plus.ContextMenuAdapter; import net.osmand.plus.FirstUsageFragment; import net.osmand.plus.OsmAndConstants; import net.osmand.plus.OsmandApplication; @@ -91,7 +96,9 @@ public class MapActivity extends AccessibleActivity { private static MapViewTrackingUtilities mapViewTrackingUtilities; - /** Called when the activity is first created. */ + /** + * Called when the activity is first created. + */ private OsmandMapTileView mapView; private AtlasMapRendererView atlasMapRendererView; @@ -121,6 +128,7 @@ public class MapActivity extends AccessibleActivity { private DashboardOnMap dashboardOnMap = new DashboardOnMap(this); private AppInitializeListener initListener; private IMapDownloaderCallback downloaderCallback; + private DrawerLayout drawerLayout; private Notification getNotification() { Intent notificationIndent = new Intent(this, getMyApplication().getAppCustomization().getMapActivity()); @@ -133,11 +141,11 @@ public class MapActivity extends AccessibleActivity { // pi); int smallIcon = app.getSettings().getApplicationMode().getSmallIconDark(); final Builder noti = new NotificationCompat.Builder( - this).setContentTitle(Version.getAppName(app)) - .setContentText(getString(R.string.go_back_to_osmand)) - .setSmallIcon(smallIcon ) + this).setContentTitle(Version.getAppName(app)) + .setContentText(getString(R.string.go_back_to_osmand)) + .setSmallIcon(smallIcon) // .setLargeIcon(Helpers.getBitmap(R.drawable.mirakel, getBaseContext())) - .setContentIntent(pi).setOngoing(true); + .setContentIntent(pi).setOngoing(true); return noti.build(); } @@ -210,19 +218,34 @@ public class MapActivity extends AccessibleActivity { OsmandPlugin.onMapActivityCreate(this); gpxImportHelper = new GpxImportHelper(this, getMyApplication(), getMapView()); wakeLockHelper = new WakeLockHelper(getMyApplication()); - if(System.currentTimeMillis() - tm > 50) { + if (System.currentTimeMillis() - tm > 50) { System.err.println("OnCreate for MapActivity took " + (System.currentTimeMillis() - tm) + " ms"); } mapView.refreshMap(true); - if(getMyApplication().getAppInitializer().isFirstTime(this)) { + if (getMyApplication().getAppInitializer().isFirstTime(this)) { getSupportFragmentManager().beginTransaction() .add(R.id.fragmentContainer, new FirstUsageFragment(), FirstUsageFragment.TAG).commit(); } - ListView menuItemsListView = (ListView) findViewById(R.id.menuItems); + final ListView menuItemsListView = (ListView) findViewById(R.id.menuItems); menuItemsListView.setDivider(null); - menuItemsListView.setAdapter(mapActions.createMainOptionsMenu().createSimpleListAdapter(this, true)); + final ContextMenuAdapter contextMenuAdapter = mapActions.createMainOptionsMenu(); + final ArrayAdapter simpleListAdapter = contextMenuAdapter.createSimpleListAdapter(this, true); + menuItemsListView.setAdapter(simpleListAdapter); + menuItemsListView.setOnItemClickListener(new AdapterView.OnItemClickListener() { + @Override + public void onItemClick(AdapterView parent, View view, int position, long id) { + ContextMenuAdapter.OnContextMenuClick click = + contextMenuAdapter.getClickAdapter(position); + if (click.onContextMenuClick(simpleListAdapter, + contextMenuAdapter.getElementId(position), position, false)) { + closeDrawer(); + } + } + }); + + drawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout); } private void checkAppInitialization() { @@ -230,20 +253,21 @@ public class MapActivity extends AccessibleActivity { findViewById(R.id.init_progress).setVisibility(View.VISIBLE); initListener = new AppInitializeListener() { boolean openGlSetup = false; + @Override public void onProgress(AppInitializer init, InitEvents event) { String tn = init.getCurrentInitTaskName(); if (tn != null) { ((TextView) findViewById(R.id.ProgressMessage)).setText(tn); } - if(event == InitEvents.NATIVE_INITIALIZED) { + if (event == InitEvents.NATIVE_INITIALIZED) { setupOpenGLView(false); openGlSetup = true; } - if(event == InitEvents.MAPS_INITIALIZED) { + if (event == InitEvents.MAPS_INITIALIZED) { // TODO investigate if this false cause any issues! mapView.refreshMap(false); - if(dashboardOnMap != null) { + if (dashboardOnMap != null) { dashboardOnMap.updateLocation(true, true, false); } } @@ -251,11 +275,11 @@ public class MapActivity extends AccessibleActivity { @Override public void onFinish(AppInitializer init) { - if(!openGlSetup) { + if (!openGlSetup) { setupOpenGLView(false); } mapView.refreshMap(false); - if(dashboardOnMap != null) { + if (dashboardOnMap != null) { dashboardOnMap.updateLocation(true, true, false); } findViewById(R.id.init_progress).setVisibility(View.GONE); @@ -348,7 +372,7 @@ public class MapActivity extends AccessibleActivity { @Override public void onBackPressed() { - if(dashboardOnMap.onBackPressed()) { + if (dashboardOnMap.onBackPressed()) { return; } super.onBackPressed(); @@ -359,7 +383,7 @@ public class MapActivity extends AccessibleActivity { super.onResume(); long tm = System.currentTimeMillis(); if (app.isApplicationInitializing() || DashboardOnMap.staticVisible) { - if(!dashboardOnMap.isVisible()) { + if (!dashboardOnMap.isVisible()) { dashboardOnMap.setDashboardVisibility(true, DashboardOnMap.staticVisibleType); } } @@ -400,7 +424,7 @@ public class MapActivity extends AccessibleActivity { RoutingHelper routingHelper = app.getRoutingHelper(); if (routingHelper.isFollowingMode() && (!Algorithms.objectEquals(targets.getPointToNavigate().point, routingHelper.getFinalLocation()) || !Algorithms - .objectEquals(targets.getIntermediatePointsLatLon(), routingHelper.getIntermediatePoints()))) { + .objectEquals(targets.getIntermediatePointsLatLon(), routingHelper.getIntermediatePoints()))) { targets.updateRouteAndReferesh(true); } app.getLocationProvider().resumeAllUpdates(); @@ -452,7 +476,7 @@ public class MapActivity extends AccessibleActivity { atlasMapRendererView.handleOnResume(); } getMyApplication().getAppCustomization().resumeActivity(MapActivity.class, this); - if(System.currentTimeMillis() - tm > 50) { + if (System.currentTimeMillis() - tm > 50) { System.err.println("OnCreate for MapActivity took " + (System.currentTimeMillis() - tm) + " ms"); } } @@ -495,12 +519,12 @@ public class MapActivity extends AccessibleActivity { loc.setLatitude(mapView.getLatitude()); loc.setLongitude(mapView.getLongitude()); getMapActions().enterRoutePlanningMode(null, null, status == OsmandSettings.NAVIGATE_CURRENT_GPX); - if(dashboardOnMap.isVisible()) { + if (dashboardOnMap.isVisible()) { dashboardOnMap.hideDashboard(); } } if (latLonToShow != null) { - if(dashboardOnMap.isVisible()) { + if (dashboardOnMap.isVisible()) { dashboardOnMap.hideDashboard(); } if (mapLabelToShow != null) { @@ -567,7 +591,7 @@ public class MapActivity extends AccessibleActivity { AccessibleToast.makeText(this, R.string.edit_tilesource_maxzoom, Toast.LENGTH_SHORT).show(); //$NON-NLS-1$ return; } - if(newZoom < 1) { + if (newZoom < 1) { AccessibleToast.makeText(this, R.string.edit_tilesource_minzoom, Toast.LENGTH_SHORT).show(); //$NON-NLS-1$ return; } @@ -601,7 +625,7 @@ public class MapActivity extends AccessibleActivity { LatLon loc = getMapLocation(); newIntent.putExtra(SearchActivity.SEARCH_LAT, loc.getLatitude()); newIntent.putExtra(SearchActivity.SEARCH_LON, loc.getLongitude()); - if(mapViewTrackingUtilities.isMapLinkedToLocation()) { + if (mapViewTrackingUtilities.isMapLinkedToLocation()) { newIntent.putExtra(SearchActivity.SEARCH_NEARBY, true); } startActivity(newIntent); @@ -644,7 +668,7 @@ public class MapActivity extends AccessibleActivity { return super.onTrackballEvent(event); } - + @Override protected void onStart() { super.onStart(); @@ -695,14 +719,14 @@ public class MapActivity extends AccessibleActivity { } public LatLon getMapLocation() { - if(mapView == null) { + if (mapView == null) { return settings.getLastKnownMapLocation(); } return new LatLon(mapView.getLatitude(), mapView.getLongitude()); } - + public float getMapRotate() { - if(mapView == null) { + if (mapView == null) { return 0; } return mapView.getRotate(); @@ -763,7 +787,7 @@ public class MapActivity extends AccessibleActivity { } public void updateMapSettings() { - if(app.isApplicationInitializing()) { + if (app.isApplicationInitializing()) { return; } // update vector renderer @@ -786,9 +810,13 @@ public class MapActivity extends AccessibleActivity { } return null; } - protected void onPostExecute(Void result) {}; + + protected void onPostExecute(Void result) { + } + + ; }.execute((Void) null); - + } @Override @@ -826,7 +854,7 @@ public class MapActivity extends AccessibleActivity { } public void checkExternalStorage() { - if(Build.VERSION.SDK_INT >= 19) { + if (Build.VERSION.SDK_INT >= 19) { return; } String state = Environment.getExternalStorageState(); @@ -916,7 +944,7 @@ public class MapActivity extends AccessibleActivity { protected void onActivityResult(int requestCode, int resultCode, Intent data) { OsmandPlugin.onMapActivityResult(requestCode, resultCode, data); MapControlsLayer mcl = mapView.getLayerByClass(MapControlsLayer.class); - if(mcl != null) { + if (mcl != null) { mcl.onActivityResult(requestCode, resultCode, data); } } @@ -932,4 +960,20 @@ public class MapActivity extends AccessibleActivity { public DashboardOnMap getDashboard() { return dashboardOnMap; } + + public void openDrawer() { + drawerLayout.openDrawer(Gravity.LEFT); + } + + public void disableDrawer() { + drawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_CLOSED); + } + + public void enableDrawer() { + drawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_UNLOCKED); + } + + public void closeDrawer() { + drawerLayout.closeDrawer(Gravity.LEFT); + } } diff --git a/OsmAnd/src/net/osmand/plus/activities/MapActivityActions.java b/OsmAnd/src/net/osmand/plus/activities/MapActivityActions.java index 02187a0059..69ec54b7fb 100644 --- a/OsmAnd/src/net/osmand/plus/activities/MapActivityActions.java +++ b/OsmAnd/src/net/osmand/plus/activities/MapActivityActions.java @@ -543,7 +543,16 @@ public class MapActivityActions implements DialogProvider { final OsmandMapTileView mapView = mapActivity.getMapView(); final OsmandApplication app = mapActivity.getMyApplication(); ContextMenuAdapter optionsMenuHelper = new ContextMenuAdapter(app); - + + optionsMenuHelper.item(R.string.home).iconColor(R.drawable.map_dashboard) + .listen(new OnContextMenuClick() { + @Override + public boolean onContextMenuClick(ArrayAdapter adapter, int itemId, int pos, boolean isChecked) { + mapActivity.closeDrawer(); + mapActivity.getDashboard().setDashboardVisibility(true, DashboardType.DASHBOARD); + return true; + } + }).reg(); optionsMenuHelper.item(R.string.target_points).iconColor(R.drawable.ic_action_flage_dark) .listen(new OnContextMenuClick() { @Override diff --git a/OsmAnd/src/net/osmand/plus/dashboard/DashboardOnMap.java b/OsmAnd/src/net/osmand/plus/dashboard/DashboardOnMap.java index 704e506dc0..29825b8e15 100644 --- a/OsmAnd/src/net/osmand/plus/dashboard/DashboardOnMap.java +++ b/OsmAnd/src/net/osmand/plus/dashboard/DashboardOnMap.java @@ -1,6 +1,7 @@ package net.osmand.plus.dashboard; import android.annotation.SuppressLint; +import android.app.ActionBar; import android.content.Context; import android.content.Intent; import android.graphics.drawable.Drawable; @@ -239,8 +240,6 @@ public class DashboardOnMap implements ObservableScrollViewCallbacks { flat.setVisibility(View.GONE); ImageView settingsButton = (ImageView) dashboardView.findViewById(R.id.toolbar_settings); settingsButton.setVisibility(View.GONE); - ImageView configureScreen = (ImageView) dashboardView.findViewById(R.id.toolbar_configure_screen); - configureScreen.setVisibility(View.GONE); IconsCache iconsCache = mapActivity.getMyApplication().getIconsCache(); ImageView lst = (ImageView) dashboardView.findViewById(R.id.toolbar_list); lst.setVisibility(View.GONE); @@ -302,15 +301,6 @@ public class DashboardOnMap implements ObservableScrollViewCallbacks { }); } if (visibleType == DashboardType.DASHBOARD || visibleType == DashboardType.LIST_MENU) { - configureScreen.setVisibility(View.VISIBLE); - configureScreen.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - setDashboardVisibility(true, DashboardType.CONFIGURE_SCREEN); - } - }); - - settingsButton.setVisibility(View.VISIBLE); settingsButton.setOnClickListener(new View.OnClickListener() { @@ -321,19 +311,12 @@ public class DashboardOnMap implements ObservableScrollViewCallbacks { } }); lst.setVisibility(View.VISIBLE); - if (visibleType == DashboardType.DASHBOARD) { - lst.setImageDrawable(iconsCache.getIcon(R.drawable.ic_navigation_drawer)); - } else if (visibleType == DashboardType.LIST_MENU) { - lst.setImageDrawable(iconsCache.getIcon(R.drawable.ic_dashboard_dark)); - } lst.setOnClickListener(new View.OnClickListener() { + @Override public void onClick(View v) { - if (visibleType == DashboardType.DASHBOARD) { - setDashboardVisibility(true, DashboardType.LIST_MENU, null, true); - } else { - setDashboardVisibility(true, DashboardType.DASHBOARD, null, true); - } + hideDashboard(false); + mapActivity.openDrawer(); } }); } @@ -441,12 +424,14 @@ public class DashboardOnMap implements ObservableScrollViewCallbacks { this.visibleType = type; DashboardOnMap.staticVisible = visible; DashboardOnMap.staticVisibleType = type; + mapActivity.enableDrawer(); if (visible) { mapViewLocation = mapActivity.getMapLocation(); mapRotation = mapActivity.getMapRotate(); mapLinkedToLocation = mapActivity.getMapViewTrackingUtilities().isMapLinkedToLocation(); myLocation = mapActivity.getMyApplication().getLocationProvider().getLastKnownLocation(); mapActivity.getMapViewTrackingUtilities().setDashboard(this); + mapActivity.disableDrawer(); dashboardView.setVisibility(View.VISIBLE); if (isActionButtonVisible()) { actionButton.setVisibility(View.VISIBLE); diff --git a/OsmAnd/src/net/osmand/plus/views/MapControlsLayer.java b/OsmAnd/src/net/osmand/plus/views/MapControlsLayer.java index ee9ee83caa..c8d7000743 100644 --- a/OsmAnd/src/net/osmand/plus/views/MapControlsLayer.java +++ b/OsmAnd/src/net/osmand/plus/views/MapControlsLayer.java @@ -385,7 +385,7 @@ public class MapControlsLayer extends OsmandMapLayer { View backToMenuButton = mapActivity.findViewById(R.id.map_menu_button); - menuControl = createHudButton((ImageView) backToMenuButton, R.drawable.map_dashboard).setBg( + menuControl = createHudButton((ImageView) backToMenuButton, R.drawable.ic_navigation_drawer).setBg( R.drawable.btn_round, R.drawable.btn_round_night); controls.add(menuControl); backToMenuButton.setOnClickListener(new View.OnClickListener() { @@ -395,7 +395,8 @@ public class MapControlsLayer extends OsmandMapLayer { // double lon = activity.getMapView().getLongitude(); // MainMenuActivity.backToMainMenuDialog(activity, new LatLon(lat, lon)); notifyClicked(); - mapActivity.getDashboard().setDashboardVisibility(true, DashboardType.DASHBOARD); + mapActivity.openDrawer(); +// mapActivity.getDashboard().setDashboardVisibility(true, DashboardType.DASHBOARD); } }); mapAppModeShadow = mapActivity.findViewById(R.id.map_app_mode_shadow);