drawer is working

This commit is contained in:
GaidamakUA 2015-08-24 12:22:05 +03:00
parent 2a856156cc
commit 46d8531c21
7 changed files with 130 additions and 100 deletions

View file

@ -1,62 +1,53 @@
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="@dimen/dashboard_map_toolbar"
app:contentInsetStart="4dp"
android:background="@color/actionbar_light_color"
app:contentInsetLeft="4dp"
android:background="@color/actionbar_light_color" >
app:contentInsetStart="4dp">
<ImageView
android:id="@+id/toolbar_back"
android:layout_width="@dimen/list_item_height"
android:layout_height="@dimen/list_item_height"
android:layout_gravity="left"
android:scaleType="center"
android:background="@drawable/dashboard_button_light"
android:src="@drawable/abc_ic_ab_back_mtrl_am_alpha" />
android:scaleType="center"
android:src="@drawable/abc_ic_ab_back_mtrl_am_alpha"
tools:visibility="visible"/>
<ImageView
android:id="@+id/toolbar_list"
android:layout_width="@dimen/list_item_height"
android:layout_height="@dimen/list_item_height"
android:layout_gravity="left"
android:background="@drawable/dashboard_button_light"
android:scaleType="center"
android:src="@drawable/ic_navigation_drawer"/>
<ImageView
android:id="@+id/toolbar_settings"
android:layout_width="@dimen/list_item_height"
android:layout_height="@dimen/list_item_height"
android:layout_gravity="left"
android:background="@drawable/dashboard_button_light"
android:scaleType="center"
android:src="@drawable/ic_action_settings"/>
<TextView
android:id="@+id/toolbar_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="left"
android:textSize="@dimen/abc_text_size_headline_material"
android:scaleType="center"
android:text="Toolbar"
android:textColor="@color/abc_primary_text_material_dark"
android:scaleType="center"
android:text="Toolbar" />
<ImageView
android:id="@+id/toolbar_list"
android:layout_width="@dimen/list_item_height"
android:layout_height="@dimen/list_item_height"
android:layout_gravity="right"
android:background="@drawable/dashboard_button_light"
android:scaleType="center"
android:src="@drawable/ic_navigation_drawer" />
<ImageView
android:id="@+id/toolbar_settings"
android:layout_width="@dimen/list_item_height"
android:layout_height="@dimen/list_item_height"
android:layout_gravity="right"
android:background="@drawable/dashboard_button_light"
android:scaleType="center"
android:src="@drawable/ic_action_settings" />
<ImageView
android:id="@+id/toolbar_configure_screen"
android:layout_width="@dimen/list_item_height"
android:layout_height="@dimen/list_item_height"
android:layout_gravity="right"
android:background="@drawable/dashboard_button_light"
android:scaleType="center"
android:src="@drawable/ic_configure_screen_dark" />
android:textSize="@dimen/abc_text_size_headline_material"
tools:visibility="gone"/>
<ImageView
android:id="@+id/toolbar_ok"
@ -65,7 +56,7 @@
android:layout_gravity="right"
android:background="@drawable/dashboard_button_light"
android:scaleType="center"
android:src="@drawable/ic_action_done" />
android:src="@drawable/ic_action_done"/>
<ImageView
android:id="@+id/toolbar_sort"
@ -74,7 +65,7 @@
android:layout_gravity="right"
android:background="@drawable/dashboard_button_light"
android:scaleType="center"
android:src="@drawable/ic_sort_waypoint_dark" />
android:src="@drawable/ic_sort_waypoint_dark"/>
<ImageView
@ -84,8 +75,8 @@
android:layout_gravity="right"
android:background="@drawable/dashboard_button_light"
android:scaleType="center"
android:visibility="gone"
android:src="@drawable/ic_flat_list_dark" />
android:src="@drawable/ic_flat_list_dark"
android:visibility="gone"/>
<ImageView
android:id="@+id/toolbar_edit"
@ -94,8 +85,8 @@
android:layout_gravity="right"
android:background="@drawable/dashboard_button_light"
android:scaleType="center"
android:visibility="gone"
android:src="@drawable/ic_action_edit_dark" />
android:src="@drawable/ic_action_edit_dark"
android:visibility="gone"/>
</android.support.v7.widget.Toolbar>

View file

@ -1,11 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout
android:id="@+id/drawer_layout"
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<FrameLayout
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent">

View file

@ -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);

View file

@ -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());
@ -135,7 +143,7 @@ public class MapActivity extends AccessibleActivity {
final Builder noti = new NotificationCompat.Builder(
this).setContentTitle(Version.getAppName(app))
.setContentText(getString(R.string.go_back_to_osmand))
.setSmallIcon(smallIcon )
.setSmallIcon(smallIcon)
// .setLargeIcon(Helpers.getBitmap(R.drawable.mirakel, getBaseContext()))
.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);
}
}
@ -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);
@ -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,7 +810,11 @@ public class MapActivity extends AccessibleActivity {
}
return null;
}
protected void onPostExecute(Void result) {};
protected void onPostExecute(Void result) {
}
;
}.execute((Void) null);
}
@ -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);
}
}

View file

@ -544,6 +544,15 @@ public class MapActivityActions implements DialogProvider {
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

View file

@ -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);

View file

@ -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);