try new drawer style (slide from left currently doesn't work)

This commit is contained in:
Victor Shcherb 2015-03-17 02:00:16 +01:00
parent 120c61eb05
commit 6d0f79ff70
12 changed files with 479 additions and 265 deletions

View file

@ -19,7 +19,6 @@
android:orientation="horizontal" >
<net.osmand.plus.dashboard.NotifyingScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/main_scroll"
android:layout_width="360dp"
android:layout_height="match_parent"
@ -36,15 +35,26 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" />
<net.osmand.plus.activities.search.toolbar.SplitToolbar
android:id="@+id/bottomControls"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="?attr/bottomToolBarColor" />
</LinearLayout>
</net.osmand.plus.dashboard.NotifyingScrollView>
<FrameLayout
android:id="@+id/dash_list_view_layout"
android:layout_width="360dp"
android:layout_height="match_parent"
android:layout_gravity="start"
android:visibility="gone" >
<ListView
android:id="@+id/dash_list_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="?attr/card_bg"
android:fadeScrollbars="true" >
</ListView>
</FrameLayout>
<include
android:id="@+id/map_part_dashboard"
android:layout_width="match_parent"

View file

@ -0,0 +1,23 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/main_fav"
android:background="?attr/card_bg"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<LinearLayout android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="@dimen/dashHeaderHeight">
<TextView android:id="@+id/fav_text"
android:text="@string/shared_string_my_places"
style="?attr/dashboardSubHeaderStyle"/>
<Button android:id="@+id/show_all"
android:text="@string/shared_string_show_all"
style="?attr/dashboardGeneralButtonStyle"/>
</LinearLayout>
<LinearLayout android:id="@+id/items"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"/>
</LinearLayout>

View file

@ -12,37 +12,58 @@
layout="@layout/application_loading"
android:visibility="gone" />
<net.osmand.plus.dashboard.NotifyingScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/main_scroll"
<LinearLayout
android:id="@+id/animateContent"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fadeScrollbars="true" >
android:layout_height="wrap_content"
android:orientation="vertical" >
<LinearLayout
android:id="@+id/animateContent"
<net.osmand.plus.dashboard.NotifyingScrollView
android:id="@+id/main_scroll"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
android:layout_height="match_parent"
android:fadeScrollbars="true" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<include
android:id="@+id/map_part_dashboard"
android:layout_width="match_parent"
android:layout_height="@dimen/dashboard_map_top_padding"
layout="@layout/map_view_on_dashboard" />
<LinearLayout
android:id="@+id/content"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" />
</LinearLayout>
</net.osmand.plus.dashboard.NotifyingScrollView>
<FrameLayout
android:id="@+id/dash_list_view_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:visibility="gone" >
<ListView
android:id="@+id/dash_list_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="@dimen/dashboard_map_top_padding"
android:background="?attr/card_bg"
android:fadeScrollbars="true" >
</ListView>
<include
android:id="@+id/map_part_dashboard"
android:layout_width="match_parent"
android:layout_height="@dimen/dashboard_map_top_padding"
layout="@layout/map_view_on_dashboard" />
<LinearLayout
android:id="@+id/content"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" />
<net.osmand.plus.activities.search.toolbar.SplitToolbar
android:id="@+id/bottomControls"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="?attr/bottomToolBarColor" />
</LinearLayout>
</net.osmand.plus.dashboard.NotifyingScrollView>
</FrameLayout>
</LinearLayout>
</FrameLayout>

View file

@ -276,6 +276,7 @@ public class AppInitializer implements IProgress {
if (!osmandSettings.FOLLOW_THE_ROUTE.get()) {
osmandSettings.APPLICATION_MODE.set(osmandSettings.DEFAULT_APPLICATION_MODE.get());
}
osmandSettings.USE_DASHBOARD_INSTEAD_OF_DRAWER.set(true);
startTime = System.currentTimeMillis();
try {
app.bRouterServiceConnection = startupInit(BRouterServiceConnection.connect(app), BRouterServiceConnection.class);

View file

@ -313,10 +313,8 @@ public class MapActivity extends AccessibleActivity {
@Override
public void onBackPressed() {
if(dashboardOnMap.clearBackAction()) {
dashboardOnMap.setDashboardVisibility(true);
} else if (dashboardOnMap.isVisible()) {
dashboardOnMap.setDashboardVisibility(false);
if(dashboardOnMap.onBackPressed()) {
return;
} else if (!mapActions.onBackPressed()) {
super.onBackPressed();
}
@ -558,6 +556,7 @@ public class MapActivity extends AccessibleActivity {
return true;
} else if (keyCode == KeyEvent.KEYCODE_MENU && event.getRepeatCount() == 0) {
mapActions.onMenuPressed();
dashboardOnMap.onMenuPressed();
return true;
} else if (keyCode == KeyEvent.KEYCODE_SEARCH && event.getRepeatCount() == 0) {
Intent newIntent = new Intent(MapActivity.this, getMyApplication().getAppCustomization()

View file

@ -59,6 +59,7 @@ import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.view.WindowManager;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.CompoundButton;
@ -89,6 +90,7 @@ public class MapActivityActions implements DialogProvider {
private RoutingHelper routingHelper;
private boolean refreshDrawer = false;
private static boolean USE_OLD_DRAWER_TODELETE = false;
DrawerLayout mDrawerLayout;
ListView mDrawerList;
private WaypointDialogHelper waypointDialogHelper;
@ -575,58 +577,64 @@ public class MapActivityActions implements DialogProvider {
}
public boolean onBackPressed(){
if (mDrawerLayout.isDrawerOpen(mDrawerList)){
mDrawerLayout.closeDrawer(mDrawerList);
return true;
if (USE_OLD_DRAWER_TODELETE) {
if (mDrawerLayout.isDrawerOpen(mDrawerList)) {
mDrawerLayout.closeDrawer(mDrawerList);
return true;
}
}
return false;
}
public void onMenuPressed(){
if (mDrawerLayout.isDrawerOpen(mDrawerList)){
mDrawerLayout.closeDrawer(mDrawerList);
} else {
prepareStartOptionsMenu();
toggleDrawer();
if (USE_OLD_DRAWER_TODELETE) {
if (mDrawerLayout.isDrawerOpen(mDrawerList)) {
mDrawerLayout.closeDrawer(mDrawerList);
} else {
prepareStartOptionsMenu();
toggleDrawer();
}
}
}
public void prepareStartOptionsMenu(){
if (mDrawerLayout == null) {
mDrawerLayout = (DrawerLayout) mapActivity.findViewById(R.id.drawer_layout);
mDrawerList = (ListView) mapActivity.findViewById(R.id.left_drawer);
mDrawerLayout.setDrawerShadow(R.drawable.drawer_shadow, GravityCompat.START);
mDrawerLayout.setDrawerListener(new DrawerLayout.DrawerListener() {
@Override
public void onDrawerSlide(View view, float v) {
}
if (USE_OLD_DRAWER_TODELETE) {
if (mDrawerLayout == null) {
mDrawerLayout = (DrawerLayout) mapActivity.findViewById(R.id.drawer_layout);
mDrawerList = (ListView) mapActivity.findViewById(R.id.left_drawer);
mDrawerLayout.setDrawerShadow(R.drawable.drawer_shadow, GravityCompat.START);
mDrawerLayout.setDrawerListener(new DrawerLayout.DrawerListener() {
@Override
public void onDrawerSlide(View view, float v) {
}
@Override
public void onDrawerOpened(View view) {
// need to refresh drawer if it
// was opened with slide, not button
if (mDrawerList != null && refreshDrawer) {
if (currentDrawer == DrawerType.WAYPOINTS) {
showWaypointsInDrawer(false);
} else if (currentDrawer == DrawerType.MAIN_MENU) {
final ContextMenuAdapter cm = createMainOptionsMenu();
prepareOptionsMenu(cm);
} else {
mDrawerList.invalidateViews();
@Override
public void onDrawerOpened(View view) {
// need to refresh drawer if it
// was opened with slide, not button
if (mDrawerList != null && refreshDrawer) {
if (currentDrawer == DrawerType.WAYPOINTS) {
showWaypointsInDrawer(false);
} else if (currentDrawer == DrawerType.MAIN_MENU) {
final ContextMenuAdapter cm = createMainOptionsMenu();
prepareOptionsMenu(cm);
} else {
mDrawerList.invalidateViews();
}
}
}
}
@Override
public void onDrawerClosed(View view) {
refreshDrawer = true;
}
@Override
public void onDrawerClosed(View view) {
refreshDrawer = true;
}
@Override
public void onDrawerStateChanged(int i) {
@Override
public void onDrawerStateChanged(int i) {
}
});
}
});
}
}
refreshDrawer();
}
@ -652,8 +660,19 @@ public class MapActivityActions implements DialogProvider {
refreshDrawer = false;
final ArrayAdapter<?> listAdapter =
cm.createListAdapter(mapActivity, getMyApplication().getSettings().isLightContent());
mDrawerList.setAdapter(listAdapter);
mDrawerList.setOnItemClickListener(new AdapterView.OnItemClickListener() {
OnItemClickListener listener = getOptionsMenuOnClickListener(cm, listAdapter);
if(USE_OLD_DRAWER_TODELETE) {
mDrawerList.setAdapter(listAdapter);
mDrawerList.setOnItemClickListener(getOptionsMenuOnClickListener(cm, listAdapter));
}
mapActivity.getDashboard().setListAdapter(listAdapter, listener);
}
private OnItemClickListener getOptionsMenuOnClickListener(final ContextMenuAdapter cm,
final ArrayAdapter<?> listAdapter) {
return new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int which, long id) {
@ -661,7 +680,7 @@ public class MapActivityActions implements DialogProvider {
if(click instanceof OnRowItemClick) {
boolean cl = ((OnRowItemClick) click).onRowItemClick(listAdapter, view, cm.getElementId(which), which);
if(cl) {
mDrawerLayout.closeDrawer(mDrawerList);
closeDrawer();
}
} else if (click != null) {
CompoundButton btn = (CompoundButton) view.findViewById(R.id.check_item);
@ -669,23 +688,35 @@ public class MapActivityActions implements DialogProvider {
btn.setChecked(!btn.isChecked());
} else {
if (click.onContextMenuClick(listAdapter, cm.getElementId(which), which, false)) {
mDrawerLayout.closeDrawer(mDrawerList);
closeDrawer();
}
}
} else {
mDrawerLayout.closeDrawer(mDrawerList);
closeDrawer();
}
}
});
};
}
public void closeDrawer() {
if (USE_OLD_DRAWER_TODELETE) {
if (mDrawerLayout.isDrawerOpen(mDrawerList)) {
mDrawerLayout.closeDrawer(mDrawerList);
}
}
mapActivity.getDashboard().setDashboardVisibility(false);
}
public void toggleDrawer() {
// toggle drawer
if (!mDrawerLayout.isDrawerOpen(mDrawerList)) {
mDrawerLayout.openDrawer(mDrawerList);
} else {
mDrawerLayout.closeDrawer(mDrawerList);
if (USE_OLD_DRAWER_TODELETE) {
if (!mDrawerLayout.isDrawerOpen(mDrawerList)) {
mDrawerLayout.openDrawer(mDrawerList);
} else {
mDrawerLayout.closeDrawer(mDrawerList);
}
}
mapActivity.getDashboard().setDashboardVisibility(!mapActivity.getDashboard().isVisible());
}
public void prepareConfigureMap() {
@ -703,31 +734,36 @@ public class MapActivityActions implements DialogProvider {
final OsmandApplication app = mapActivity.getMyApplication();
ContextMenuAdapter optionsMenuHelper = new ContextMenuAdapter(app);
currentDrawer = DrawerType.MAIN_MENU;
optionsMenuHelper.item(R.string.home_button).icons(R.drawable.ic_dashboard_dark, R.drawable.ic_dashboard_light )
.listen(new OnContextMenuClick() {
@Override
public boolean onContextMenuClick(ArrayAdapter<?> adapter, int itemId, int pos, boolean isChecked) {
getMyApplication().getSettings().USE_DASHBOARD_INSTEAD_OF_DRAWER.set(true);
mapActivity.getDashboard().setDashboardVisibility(true);
return true;
}
}).reg();
// 1. Where am I
optionsMenuHelper.item(R.string.where_am_i).
icons(R.drawable.ic_action_gloc_dark, R.drawable.ic_action_gloc_light)
.listen(new OnContextMenuClick() {
@Override
public boolean onContextMenuClick(ArrayAdapter<?> adapter, int itemId, int pos, boolean isChecked) {
if (getMyApplication().accessibilityEnabled()) {
whereAmIDialog();
} else {
mapActivity.getMapViewTrackingUtilities().backToLocationImpl();
if (USE_OLD_DRAWER_TODELETE) {
optionsMenuHelper.item(R.string.home_button)
.icons(R.drawable.ic_dashboard_dark, R.drawable.ic_dashboard_light)
.listen(new OnContextMenuClick() {
@Override
public boolean onContextMenuClick(ArrayAdapter<?> adapter, int itemId, int pos,
boolean isChecked) {
// getMyApplication().getSettings().USE_DASHBOARD_INSTEAD_OF_DRAWER.set(true);
mapActivity.getDashboard().setDashboardVisibility(true);
return true;
}
return true;
}
}).reg();
}).reg();
// 1. Where am I
optionsMenuHelper.item(R.string.where_am_i)
.icons(R.drawable.ic_action_gloc_dark, R.drawable.ic_action_gloc_light)
.listen(new OnContextMenuClick() {
@Override
public boolean onContextMenuClick(ArrayAdapter<?> adapter, int itemId, int pos,
boolean isChecked) {
if (getMyApplication().accessibilityEnabled()) {
whereAmIDialog();
} else {
mapActivity.getMapViewTrackingUtilities().backToLocationImpl();
}
return true;
}
}).reg();
}
// 2-4. Navigation related (directions, mute, cancel navigation)
boolean muteVisible = routingHelper.getFinalLocation() != null && routingHelper.isFollowingMode();
@ -948,10 +984,14 @@ public class MapActivityActions implements DialogProvider {
currentDrawer = DrawerType.WAYPOINTS;
final int[] running = new int[] { -1 };
ArrayAdapter<Object> listAdapter = waypointDialogHelper.getWaypointsDrawerAdapter(mapActivity, running, flat);
mDrawerList.setAdapter(listAdapter);
OnItemClickListener listener = waypointDialogHelper.getDrawerItemClickListener(mapActivity, running,
listAdapter, null);
if(USE_OLD_DRAWER_TODELETE) {
mDrawerList.setAdapter(listAdapter);
mDrawerList.setOnItemClickListener(listener);
}
refreshDrawer = false;
mDrawerList.setOnItemClickListener(waypointDialogHelper.getDrawerItemClickListener(mapActivity, running,
listAdapter, null));
mapActivity.getDashboard().setListAdapter(listAdapter, listener);
}
public void showWaypointsDialog(boolean flat) {
@ -963,17 +1003,21 @@ public class MapActivityActions implements DialogProvider {
}
public void disableDrawer(){
if(mDrawerLayout == null) {
prepareStartOptionsMenu();
if (USE_OLD_DRAWER_TODELETE) {
if (mDrawerLayout == null) {
prepareStartOptionsMenu();
}
mDrawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_CLOSED);
}
mDrawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_CLOSED);
}
public void enableDrawer(){
if(mDrawerLayout == null) {
prepareStartOptionsMenu();
public void enableDrawer() {
if (USE_OLD_DRAWER_TODELETE) {
if (mDrawerLayout == null) {
prepareStartOptionsMenu();
}
mDrawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_UNLOCKED);
}
mDrawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_UNLOCKED);
}
public void openIntermediatePointsDialog(){

View file

@ -91,10 +91,6 @@ public class MapViewTrackingUtilities implements OsmAndLocationListener, IMapLoc
this.dashboard = dashboard;
}
public DashboardOnMap getDashboard() {
return dashboard;
}
@Override
public void updateLocation(Location location) {
showViewAngle = false;

View file

@ -1,14 +1,12 @@
package net.osmand.plus.dashboard;
import android.app.Activity;
import android.content.Intent;
import android.location.Location;
import android.support.v4.app.Fragment;
import net.osmand.plus.OsmAndAppCustomization;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.myplaces.FavoritesActivity;
import android.app.Activity;
import android.content.Intent;
import android.location.Location;
import android.support.v4.app.Fragment;
/**
* Created by Denis on 24.11.2014.

View file

@ -0,0 +1,64 @@
package net.osmand.plus.dashboard;
import net.osmand.plus.R;
import net.osmand.plus.helpers.FontCache;
import android.graphics.Typeface;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.TextView;
/**
* Created by Denis on 24.11.2014.
*/
public class DashListFragment extends DashBaseFragment {
public static final String TAG = "DASH_LIST_FRAGMENT";
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
View view = getActivity().getLayoutInflater().inflate(R.layout.dash_list_fragment, container, false);
Typeface typeface = FontCache.getRobotoMedium(getActivity());
((TextView) view.findViewById(R.id.fav_text)).setTypeface(typeface);
((TextView) view.findViewById(R.id.fav_text)).setText("Here will be text");
((Button) view.findViewById(R.id.show_all)).setTypeface(typeface);
((Button) view.findViewById(R.id.show_all)).setVisibility(View.GONE);
return view;
}
@Override
public void onOpenDash() {
setupList();
}
public void setupList() {
View mainView = getView();
mainView.findViewById(R.id.main_fav).setVisibility(View.VISIBLE);
LinearLayout lv = (LinearLayout) mainView.findViewById(R.id.items);
lv.removeAllViews();
ArrayAdapter<?> la = dashboard.getListAdapter();
final OnItemClickListener onClick = dashboard.getListAdapterOnClickListener();
for(int i = 0; i < la.getCount(); i++) {
final int position = i;
View v = la.getView(position, null, lv);
if (onClick != null) {
v.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
onClick.onItemClick(null, v, position, position);
}
});
}
lv.addView(v);
}
}
}

View file

@ -1,31 +1,16 @@
package net.osmand.plus.dashboard;
import android.content.Context;
import android.content.Intent;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
import android.support.v4.view.MenuItemCompat;
import android.support.v7.widget.Toolbar;
import android.util.DisplayMetrics;
import android.view.Gravity;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.view.animation.Animation;
import android.view.animation.Animation.AnimationListener;
import android.view.animation.TranslateAnimation;
import android.widget.Button;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.ScrollView;
import gnu.trove.map.hash.TIntObjectHashMap;
import com.software.shell.fab.ActionButton;
import java.lang.ref.WeakReference;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import net.osmand.data.LatLon;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.OsmandPlugin;
import net.osmand.plus.OsmandSettings.CommonPreference;
import net.osmand.plus.R;
import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.audionotes.DashAudioVideoNotesFragment;
@ -39,11 +24,31 @@ import net.osmand.plus.parkingpoint.DashParkingFragment;
import net.osmand.plus.routing.RoutingHelper;
import net.osmand.plus.views.DownloadedRegionsLayer;
import net.osmand.plus.views.OsmandMapTileView;
import android.content.Context;
import android.content.Intent;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
import android.util.DisplayMetrics;
import android.view.Gravity;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewGroup.LayoutParams;
import android.view.ViewGroup.MarginLayoutParams;
import android.view.animation.Animation;
import android.view.animation.Animation.AnimationListener;
import android.view.animation.TranslateAnimation;
import android.widget.AbsListView;
import android.widget.AbsListView.OnScrollListener;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.ScrollView;
import java.lang.ref.WeakReference;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import com.software.shell.fab.ActionButton;
/**
* Created by Denis
@ -52,13 +57,12 @@ import java.util.List;
public class DashboardOnMap {
public static boolean staticVisible = false;
private static final int LIST_ID = 1;
private static final int DIRECTIONS_ID = 2;
private static final int CONFIGURE_SCREEN_ID = 3;
private static final int SETTINGS_ID = 4;
private MapActivity mapActivity;
private ActionButton actionButton;
private FrameLayout dashboardView;
private ArrayAdapter<?> listAdapter;
private OnItemClickListener listAdapterOnClickListener;
private boolean visible = false;
private boolean landscape;
@ -71,7 +75,10 @@ public class DashboardOnMap {
private boolean inLocationUpdate = false;
private boolean saveBackAction;
private ImageView switchButton;
private NotifyingScrollView scrollView;
private View listViewLayout;
private ListView listView;
public DashboardOnMap(MapActivity ma) {
this.mapActivity = ma;
@ -91,20 +98,11 @@ public class DashboardOnMap {
setDashboardVisibility(false);
}
};
scrollView = ((NotifyingScrollView) dashboardView.findViewById(R.id.main_scroll));
listViewLayout = dashboardView.findViewById(R.id.dash_list_view_layout);
listView = (ListView) dashboardView.findViewById(R.id.dash_list_view);
dashboardView.findViewById(R.id.animateContent).setOnClickListener(listener);
dashboardView.setOnClickListener(listener);
switchButton = (ImageView) dashboardView.findViewById(R.id.map_menu_button);
switchButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
setDashboardVisibility(false);
mapActivity.getMyApplication().getSettings().USE_DASHBOARD_INSTEAD_OF_DRAWER.set(false);
mapActivity.getMapActions().toggleDrawer();
}
});
actionButton = new ActionButton(mapActivity);
FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
@ -129,12 +127,50 @@ public class DashboardOnMap {
});
dashboardView.addView(actionButton);
if (ScreenOrientationHelper.isOrientationPortrait(mapActivity)) {
((NotifyingScrollView) dashboardView.findViewById(R.id.main_scroll))
.setOnScrollChangedListener(onScrollChangedListener);
scrollView.setOnScrollChangedListener(onScrollChangedListener);
listView.setOnScrollListener(new OnScrollListener() {
private TIntObjectHashMap<Integer> listViewItemHeights = new TIntObjectHashMap<Integer>();
@Override
public void onScrollStateChanged(AbsListView view, int scrollState) {
}
@Override
public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
// if(listView.getChildCount() == 0) {
// return;
// }
// View c = listView.getChildAt(0);
// int sy = -c.getTop();
// listViewItemHeights.put(listView.getFirstVisiblePosition(), c.getHeight());
// for (int i = 0; i < listView.getFirstVisiblePosition(); ++i) {
// if (listViewItemHeights.get(i) != null) // (this is a sanity check)
// sy += listViewItemHeights.get(i); //add all heights of the views that are gone
// }
// double scale = view.getContext().getResources().getDisplayMetrics().density;
// MarginLayoutParams lp = (MarginLayoutParams) actionButton.getLayoutParams();
// lp.topMargin = (int) Math.max(30 * scale, 160 * scale - sy);
// ((FrameLayout) actionButton.getParent()).updateViewLayout(actionButton, lp);
// MarginLayoutParams llp = (MarginLayoutParams) listView.getLayoutParams();
// llp.topMargin = (int) Math.max(5 * scale, 160 * scale - sy);
// listView.setLayoutParams(llp);
// listView.getParent().requestLayout();
}
});
}
}
private void switchBtnAction() {
setDashboardVisibility(false);
CommonPreference<Boolean> st = mapActivity.getMyApplication().getSettings().USE_DASHBOARD_INSTEAD_OF_DRAWER;
st.set(!st.get());
setDashboardVisibility(true);
// mapActivity.getMapActions().toggleDrawer();
}
public static int convertPixelsToDp(float dp, Context context){
DisplayMetrics displayMetrics = context.getResources().getDisplayMetrics();
@ -164,8 +200,32 @@ public class DashboardOnMap {
protected OsmandApplication getMyApplication() {
return mapActivity.getMyApplication();
}
public ArrayAdapter<?> getListAdapter() {
return listAdapter;
}
public OnItemClickListener getListAdapterOnClickListener() {
return listAdapterOnClickListener;
}
public void setListAdapter(ArrayAdapter<?> listAdapter, OnItemClickListener optionsMenuOnClickListener) {
if(!isVisible()) {
mapActivity.getMyApplication().getSettings().USE_DASHBOARD_INSTEAD_OF_DRAWER.set(false);
}
this.listAdapter = listAdapter;
this.listAdapterOnClickListener = optionsMenuOnClickListener;
if(this.listView != null) {
listView.setAdapter(listAdapter);
listView.setOnItemClickListener(optionsMenuOnClickListener);
}
setDashboardVisibility(true);
}
public void setDashboardVisibility(boolean visible) {
if(visible == this.visible) {
return;
}
this.visible = visible;
DashboardOnMap.staticVisible = visible;
if (visible) {
@ -174,15 +234,39 @@ public class DashboardOnMap {
mapLinkedToLocation = mapActivity.getMapViewTrackingUtilities().isMapLinkedToLocation();
myLocation = mapActivity.getMyApplication().getLocationProvider().getLastKnownLocation();
mapActivity.getMapViewTrackingUtilities().setDashboard(this);
addOrUpdateDashboardFragments();
setupActionBar();
updateDownloadBtn();
dashboardView.setVisibility(View.VISIBLE);
actionButton.show();
updateDownloadBtn();
if(mapActivity.getMyApplication().getSettings().USE_DASHBOARD_INSTEAD_OF_DRAWER.get()) {
addOrUpdateDashboardFragments();
scrollView.setVisibility(View.VISIBLE);
listViewLayout.setVisibility(View.GONE);
switchButton = (ImageView) scrollView.findViewById(R.id.map_menu_button);
if(switchButton == null) {
switchButton = (ImageView) dashboardView.findViewById(R.id.map_menu_button);
}
switchButton.setImageDrawable(mapActivity.getMyApplication().getIconsCache().getIcon(R.drawable.ic_navigation_drawer,
R.color.icon_color_light));
} else {
scrollView.setVisibility(View.GONE);
switchButton = (ImageView) listViewLayout.findViewById(R.id.map_menu_button);
if(switchButton == null) {
switchButton = (ImageView) dashboardView.findViewById(R.id.map_menu_button);
}
listViewLayout.setVisibility(View.VISIBLE);
switchButton.setImageDrawable(mapActivity.getMyApplication().getIconsCache().getIcon(R.drawable.ic_dashboard_dark,
R.color.icon_color_light));
}
switchButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
switchBtnAction();
}
});
//fabButton.showFloatingActionButton();
open(dashboardView.findViewById(R.id.animateContent));
switchButton.setImageDrawable(mapActivity.getMyApplication().getIconsCache().getIcon(R.drawable.ic_navigation_drawer,
R.color.icon_color_light));
mapActivity.getMapActions().disableDrawer();
mapActivity.findViewById(R.id.MapHudButtonsOverlay).setVisibility(View.INVISIBLE);
@ -241,59 +325,11 @@ public class DashboardOnMap {
}
private void setupActionBar() {
final Toolbar tb = (Toolbar) mapActivity.findViewById(R.id.bottomControls);
tb.setTitle(null);
tb.getMenu().clear();
Menu menu = tb.getMenu();
createMenuItem(menu, LIST_ID, R.string.drawer,
R.drawable.ic_dashboard_dark, MenuItemCompat.SHOW_AS_ACTION_ALWAYS);
createMenuItem(menu, DIRECTIONS_ID, R.string.get_directions,
R.drawable.ic_action_gdirections_dark, MenuItemCompat.SHOW_AS_ACTION_ALWAYS);
createMenuItem(menu, CONFIGURE_SCREEN_ID, R.string.layer_map_appearance,
R.drawable.ic_configure_screen_dark, MenuItemCompat.SHOW_AS_ACTION_ALWAYS);
createMenuItem(menu, SETTINGS_ID, R.string.shared_string_settings,
R.drawable.ic_action_settings_enabled_dark, MenuItemCompat.SHOW_AS_ACTION_ALWAYS);
}
public MenuItem createMenuItem(Menu m, int id, int titleRes, int icon, int menuItemType) {
int r = icon;
MenuItem menuItem = m.add(0, id, 0, titleRes);
if (r != 0) {
menuItem.setIcon(r);
}
menuItem.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem item) {
return onOptionsItemSelected(item);
}
});
MenuItemCompat.setShowAsAction(menuItem, menuItemType);
return menuItem;
}
protected boolean onOptionsItemSelected(MenuItem item) {
setDashboardVisibility(false);
if(item.getItemId() == LIST_ID) {
// temporarily disable drawer
// getMyApplication().getSettings().USE_DASHBOARD_INSTEAD_OF_DRAWER.set(false);
mapActivity.getMapActions().toggleDrawer();
} else if(item.getItemId() == DIRECTIONS_ID) {
navigationAction();
} else if(item.getItemId() == CONFIGURE_SCREEN_ID) {
mapActivity.getMapActions().prepareConfigureScreen();
mapActivity.getMapActions().toggleDrawer();
return false;
} else if(item.getItemId() == SETTINGS_ID) {
final Intent settings = new Intent(mapActivity, getMyApplication().getAppCustomization().getSettingsActivity());
mapActivity.startActivity(settings);
} else {
return false;
}
return true;
}
public void navigationAction() {
RoutingHelper routingHelper = mapActivity.getRoutingHelper();
@ -343,51 +379,50 @@ public class DashboardOnMap {
private void addOrUpdateDashboardFragments() {
Iterator<WeakReference<DashBaseFragment>> it = fragList.iterator();
while(it.hasNext()) {
WeakReference<DashBaseFragment> df = it.next();
if(df.get() != null) {
if(df.get().getView() != null) {
df.get().onOpenDash();
}
} else {
it.remove();
}
}
// boolean showCards = mapActivity.getMyApplication().getSettings().USE_DASHBOARD_INSTEAD_OF_DRAWER.get();
boolean showCards = true;
FragmentManager manager = mapActivity.getSupportFragmentManager();
FragmentTransaction fragmentTransaction = manager.beginTransaction();
showFragment(manager, fragmentTransaction, DashErrorFragment.TAG, DashErrorFragment.class,
mapActivity.getMyApplication().getAppInitializer().checkPreviousRunsForExceptions(mapActivity));
showFragment(manager, fragmentTransaction, DashParkingFragment.TAG, DashParkingFragment.class);
showFragment(manager, fragmentTransaction, DashWaypointsFragment.TAG, DashWaypointsFragment.class);
showFragment(manager, fragmentTransaction, DashSearchFragment.TAG, DashSearchFragment.class);
showFragment(manager, fragmentTransaction, DashRecentsFragment.TAG, DashRecentsFragment.class);
showFragment(manager, fragmentTransaction, DashFavoritesFragment.TAG, DashFavoritesFragment.class);
showFragment(manager, fragmentTransaction, DashAudioVideoNotesFragment.TAG, DashAudioVideoNotesFragment.class);
showFragment(manager, fragmentTransaction, DashTrackFragment.TAG, DashTrackFragment.class);
showFragment(manager, fragmentTransaction, DashOsmoFragment.TAG, DashOsmoFragment.class);
//showFragment(manager, fragmentTransaction, DashOsmEditsFragment.TAG, DashOsmEditsFragment.class);
// showFragment(manager, fragmentTransaction, DashUpdatesFragment.TAG, DashUpdatesFragment.class);
showFragment(manager, fragmentTransaction, DashPluginsFragment.TAG, DashPluginsFragment.class);
showFragment(manager, fragmentTransaction, DashErrorFragment.TAG, DashErrorFragment.class,
mapActivity.getMyApplication().getAppInitializer().checkPreviousRunsForExceptions(mapActivity) && showCards);
showFragment(manager, fragmentTransaction, DashParkingFragment.TAG, DashParkingFragment.class, showCards);
showFragment(manager, fragmentTransaction, DashWaypointsFragment.TAG, DashWaypointsFragment.class, showCards);
showFragment(manager, fragmentTransaction, DashSearchFragment.TAG, DashSearchFragment.class, showCards);
showFragment(manager, fragmentTransaction, DashRecentsFragment.TAG, DashRecentsFragment.class, showCards);
showFragment(manager, fragmentTransaction, DashFavoritesFragment.TAG, DashFavoritesFragment.class, showCards);
showFragment(manager, fragmentTransaction, DashAudioVideoNotesFragment.TAG, DashAudioVideoNotesFragment.class, showCards);
showFragment(manager, fragmentTransaction, DashTrackFragment.TAG, DashTrackFragment.class, showCards);
showFragment(manager, fragmentTransaction, DashOsmoFragment.TAG, DashOsmoFragment.class, showCards);
//showFragment(manager, fragmentTransaction, DashOsmEditsFragment.TAG, DashOsmEditsFragment.class, showCards);
// showFragment(manager, fragmentTransaction, DashUpdatesFragment.TAG, DashUpdatesFragment.class, showCards);
showFragment(manager, fragmentTransaction, DashPluginsFragment.TAG, DashPluginsFragment.class, showCards);
showFragment(manager, fragmentTransaction, DashSimulateFragment.TAG, DashSimulateFragment.class,
OsmandPlugin.getEnabledPlugin(OsmandDevelopmentPlugin.class) != null);
OsmandPlugin.getEnabledPlugin(OsmandDevelopmentPlugin.class) != null && showCards);
fragmentTransaction.commit();
}
private <T extends Fragment> void showFragment(FragmentManager manager, FragmentTransaction fragmentTransaction,
String tag, Class<T> cl) {
showFragment(manager, fragmentTransaction, tag, cl, true);
}
private <T extends Fragment> void showFragment(FragmentManager manager, FragmentTransaction fragmentTransaction,
String tag, Class<T> cl, boolean cond) {
try {
if (manager.findFragmentByTag(tag) == null && cond) {
T ni = cl.newInstance();
fragmentTransaction.add(R.id.content, ni, tag);
Fragment frag = manager.findFragmentByTag(tag);
if (manager.findFragmentByTag(tag) == null ) {
if(cond) {
T ni = cl.newInstance();
fragmentTransaction.add(R.id.content, ni, tag);
}
} else {
if(!cond) {
fragmentTransaction.remove(manager.findFragmentByTag(tag));
} else if(frag instanceof DashBaseFragment){
((DashBaseFragment) frag).onOpenDash();
}
}
} catch (Exception e) {
getMyApplication().showToastMessage("Error showing dashboard");
@ -456,6 +491,10 @@ public class DashboardOnMap {
public void onAttach(DashBaseFragment dashBaseFragment) {
fragList.add(new WeakReference<DashBaseFragment>(dashBaseFragment));
}
public void requestLayout() {
dashboardView.requestLayout();
}
public void saveBackAction() {
@ -470,5 +509,24 @@ public class DashboardOnMap {
return false;
}
public void onMenuPressed() {
if (!isVisible()) {
setDashboardVisibility(true);
} else {
setDashboardVisibility(false);
}
}
public boolean onBackPressed() {
if (isVisible()) {
setDashboardVisibility(false);
return true;
}
return false;
}
}

View file

@ -243,7 +243,7 @@ public class WaypointDialogHelper {
dlg.dismiss();
} else if(a instanceof MapActivity){
((MapActivity) a).getMapActions().onDrawerBack();
((MapActivity) a).getMapActions().toggleDrawer();
((MapActivity) a).getMapActions().closeDrawer();
}
}
});
@ -261,7 +261,7 @@ public class WaypointDialogHelper {
dlg.dismiss();
} else if(a instanceof MapActivity){
((MapActivity) a).getMapActions().onDrawerBack();
((MapActivity) a).getMapActions().toggleDrawer();
((MapActivity) a).getMapActions().closeDrawer();
}
}
});

View file

@ -175,7 +175,7 @@ public class MapControlsLayer extends OsmandMapLayer {
public void onClick(View v) {
notifyClicked();
mapActivity.getMapActions().prepareConfigureMap();
mapActivity.getMapActions().toggleDrawer();
mapActivity.getDashboard().setDashboardVisibility(true);
}
});
@ -285,12 +285,12 @@ public class MapControlsLayer extends OsmandMapLayer {
// double lon = activity.getMapView().getLongitude();
// MainMenuActivity.backToMainMenuDialog(activity, new LatLon(lat, lon));
notifyClicked();
if (mapActivity.getMyApplication().getSettings().USE_DASHBOARD_INSTEAD_OF_DRAWER.get()) {
// if (mapActivity.getMyApplication().getSettings().USE_DASHBOARD_INSTEAD_OF_DRAWER.get()) {
mapActivity.getDashboard().setDashboardVisibility(true);
} else {
mapActivity.getMapActions().onDrawerBack();
mapActivity.getMapActions().toggleDrawer();
}
// } else {
// mapActivity.getMapActions().onDrawerBack();
// mapActivity.getMapActions().toggleDrawer();
// }
}
});
mapAppModeShadow = mapActivity.findViewById(R.id.map_app_mode_shadow);
@ -621,7 +621,7 @@ public class MapControlsLayer extends OsmandMapLayer {
boolean nightMode = false;
boolean f = true;
boolean compass;
public MapHudButton setRoundTransparent() {
setBg(R.drawable.btn_circle_trans);
return this;