Update UI

This commit is contained in:
Victor Shcherb 2015-03-08 14:32:21 +01:00
parent 6422a8aa56
commit 1142ad4130
8 changed files with 179 additions and 73 deletions

View file

@ -622,6 +622,8 @@ public class OsmandSettings {
return p;
}
public final CommonPreference<Boolean> USE_DASHBOARD_INSTEAD_OF_DRAWER = new BooleanPreference("use_dashboard_instead_of_drawer", true).makeGlobal().cache();
// this value string is synchronized with settings_pref.xml preference name
public final CommonPreference<Boolean> USE_INTERNET_TO_DOWNLOAD_TILES = new BooleanPreference("use_internet_to_download_tiles", true).makeGlobal().cache();

View file

@ -115,7 +115,7 @@ public class MapActivity extends AccessibleActivity {
private WakeLockHelper wakeLockHelper;
private boolean intentLocation = false;
private DashboardOnMap dashboardOnMap;
private DashboardOnMap dashboardOnMap = new DashboardOnMap(this);
private AppInitializeListener initListener;
private Notification getNotification() {
@ -143,7 +143,6 @@ public class MapActivity extends AccessibleActivity {
mapActions = new MapActivityActions(this);
mapLayers = new MapActivityLayers(this);
dashboardOnMap = new DashboardOnMap(this);
dashboardOnMap.createDashboardView();
if (app.isApplicationInitializing()) {
dashboardOnMap.setDashboardVisibility(true);
@ -484,17 +483,23 @@ public class MapActivity extends AccessibleActivity {
loc.setLatitude(mapView.getLatitude());
loc.setLongitude(mapView.getLongitude());
getMapActions().enterRoutePlanningMode(null, null, status == OsmandSettings.NAVIGATE_CURRENT_GPX);
}
if (mapLabelToShow != null && latLonToShow != null) {
mapLayers.getContextMenuLayer().setSelectedObject(toShow);
mapLayers.getContextMenuLayer().setLocation(latLonToShow,
mapLabelToShow.getFullPlainName(this, latLonToShow.getLatitude(), latLonToShow.getLongitude()));
}
if (latLonToShow != null && !latLonToShow.equals(cur)) {
mapView.getAnimatedDraggingThread().startMoving(latLonToShow.getLatitude(), latLonToShow.getLongitude(),
settings.getMapZoomToShow(), true);
if(dashboardOnMap.isVisible()) {
dashboardOnMap.setDashboardVisibility(false);
}
}
if (latLonToShow != null) {
if(dashboardOnMap.isVisible()) {
dashboardOnMap.setDashboardVisibility(false);
}
if (mapLabelToShow != null) {
mapLayers.getContextMenuLayer().setSelectedObject(toShow);
mapLayers.getContextMenuLayer().setLocation(latLonToShow,
mapLabelToShow.getFullPlainName(this, latLonToShow.getLatitude(), latLonToShow.getLongitude()));
}
if (!latLonToShow.equals(cur)) {
mapView.getAnimatedDraggingThread().startMoving(latLonToShow.getLatitude(),
latLonToShow.getLongitude(), settings.getMapZoomToShow(), true);
}
// remember if map should come back to isMapLinkedToLocation=true
mapViewTrackingUtilities.setMapLinkedToLocation(false);
}

View file

@ -701,9 +701,7 @@ public class MapActivityActions implements DialogProvider {
.listen(new OnContextMenuClick() {
@Override
public boolean onContextMenuClick(ArrayAdapter<?> adapter, int itemId, int pos, boolean isChecked) {
// Intent newIntent = new Intent(mapActivity, mapActivity.getMyApplication().getAppCustomization().getMainMenuActivity());
// newIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
// mapActivity.startActivity(newIntent);
getMyApplication().getSettings().USE_DASHBOARD_INSTEAD_OF_DRAWER.set(true);
mapActivity.getDashboard().setDashboardVisibility(true);
return true;
}
@ -754,7 +752,7 @@ public class MapActivityActions implements DialogProvider {
@Override
public boolean onContextMenuClick(ArrayAdapter<?> adapter, int itemId, int pos, boolean isChecked) {
enterRoutePlanningMode(null, null, false);
return true;
return true;
}
}).reg();
} else if(routingHelper.isRouteCalculated()) {
@ -934,7 +932,7 @@ public class MapActivityActions implements DialogProvider {
return optionsMenuHelper;
}
private void prepareConfigureScreen() {
public void prepareConfigureScreen() {
currentDrawer = DrawerType.CONFIGURE_SCREEN;
ContextMenuAdapter cm = mapActivity.getMapLayers().getMapInfoLayer().getViewConfigureMenuAdapter();
prepareOptionsMenu(cm);
@ -1017,7 +1015,7 @@ public class MapActivityActions implements DialogProvider {
private void whereAmIDialog() {
public void whereAmIDialog() {
final List<String> items = new ArrayList<String>();
items.add(getString(R.string.show_location));
items.add(getString(R.string.show_details));

View file

@ -1,18 +1,39 @@
package net.osmand.plus.dashboard;
import android.app.Activity;
import android.support.v4.app.Fragment;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.activities.MapActivity;
/**
* Created by Denis on 24.11.2014.
*/
public class DashBaseFragment extends Fragment {
private DashboardOnMap dashboard;
public OsmandApplication getMyApplication(){
if (getActivity() == null){
return null;
}
return (OsmandApplication) getActivity().getApplication();
}
@Override
public void onAttach(Activity activity) {
super.onAttach(activity);
if(activity instanceof MapActivity) {
dashboard = ((MapActivity) activity).getDashboard();
dashboard.onAttach(this);
}
}
@Override
public void onDetach() {
super.onDetach();
if(dashboard != null) {
dashboard.onDetach(this);
}
}
}

View file

@ -105,6 +105,7 @@ public class DashPluginsFragment extends DashBaseFragment {
private void updatePluginState(View pluginView, OsmandPlugin plugin) {
CompoundButton enableDisableButton = (CompoundButton) pluginView.findViewById(R.id.plugin_enable_disable);
Button getButton = (Button) pluginView.findViewById(R.id.get_plugin);
enableDisableButton.setOnCheckedChangeListener(null);
if (plugin.needsInstallation()) {
getButton.setVisibility(View.VISIBLE);
enableDisableButton.setVisibility(View.GONE);
@ -113,6 +114,7 @@ public class DashPluginsFragment extends DashBaseFragment {
enableDisableButton.setVisibility(View.VISIBLE);
enableDisableButton.setChecked(plugin.isActive());
}
setListener(plugin, enableDisableButton, pluginView);
ImageButton logoView = (ImageButton) pluginView.findViewById(R.id.plugin_logo);
if (plugin.isActive()) {
@ -141,6 +143,11 @@ public class DashPluginsFragment extends DashBaseFragment {
enableDisableButton.setOnCheckedChangeListener(null);
updatePluginState(view, plugin);
final View pluginView = view;
setListener(plugin, enableDisableButton, pluginView);
container.addView(view);
}
private void setListener(final OsmandPlugin plugin, CompoundButton enableDisableButton, final View pluginView) {
enableDisableButton.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
@ -152,6 +159,5 @@ public class DashPluginsFragment extends DashBaseFragment {
}
}
});
container.addView(view);
}
}

View file

@ -1,12 +1,22 @@
package net.osmand.plus.dashboard;
import java.lang.ref.WeakReference;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.R;
import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.audionotes.DashAudioVideoNotesFragment;
import net.osmand.plus.helpers.ScreenOrientationHelper;
import net.osmand.plus.monitoring.DashTrackFragment;
import net.osmand.plus.routing.RoutingHelper;
import net.osmand.plus.views.controls.FloatingActionButton;
import android.content.Intent;
import android.os.Build;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
import android.support.v4.view.MenuItemCompat;
@ -30,23 +40,26 @@ public class DashboardOnMap {
private static final int LIST_ID = 1;
private static final int WAYPOINTS_ID = 2;
private static final int DIRECTIONS_ID = 2;
private static final int CONFIGURE_SCREEN_ID = 3;
private static final int SETTINGS_ID = 4;
private MapActivity ma;
private MapActivity mapActivity;
FloatingActionButton fabButton;
boolean floatingButtonVisible = true;
private FrameLayout dashboardView;
private boolean visible = false;
private boolean landscape;
private List<WeakReference<DashBaseFragment>> fragList = new LinkedList<WeakReference<DashBaseFragment>>();
public DashboardOnMap(MapActivity ma) {
this.ma = ma;
this.mapActivity = ma;
}
public void createDashboardView() {
dashboardView = (FrameLayout) ma.getLayoutInflater().inflate(R.layout.dashboard_over_map, null, false);
landscape = !ScreenOrientationHelper.isOrientationPortrait(mapActivity);
dashboardView = (FrameLayout) mapActivity.getLayoutInflater().inflate(R.layout.dashboard_over_map, null, false);
dashboardView.setLayoutParams(new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
ViewGroup.LayoutParams.MATCH_PARENT));
View.OnClickListener listener = new View.OnClickListener() {
@ -57,23 +70,29 @@ public class DashboardOnMap {
};
dashboardView.findViewById(R.id.content).setOnClickListener(listener);
dashboardView.setOnClickListener(listener);
((FrameLayout) ma.findViewById(R.id.ParentLayout)).addView(dashboardView);
((FrameLayout) mapActivity.findViewById(R.id.ParentLayout)).addView(dashboardView);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
fabButton = new FloatingActionButton.Builder(ma)
.withDrawable(ma.getResources().getDrawable(R.drawable.ic_action_map))
.withButtonColor(ma.getResources().getColor(R.color.color_myloc_distance)).withGravity(Gravity.TOP | Gravity.RIGHT)
.withMargins(0, 160, 16, 0).create();
fabButton = new FloatingActionButton.Builder(mapActivity)
.withDrawable(mapActivity.getResources().getDrawable(R.drawable.ic_action_map))
.withButtonColor(mapActivity.getResources().getColor(R.color.color_myloc_distance))
.withGravity(landscape ? Gravity.BOTTOM | Gravity.RIGHT : Gravity.TOP | Gravity.RIGHT)
.withMargins(0, landscape ? 0 : 160, 16, landscape ? 16 : 0).create();
fabButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if (getMyApplication().accessibilityEnabled()) {
mapActivity.getMapActions().whereAmIDialog();
} else {
mapActivity.getMapViewTrackingUtilities().backToLocationImpl();
}
setDashboardVisibility(false);
}
});
fabButton.hideFloatingActionButton();
}
if (ScreenOrientationHelper.isOrientationPortrait(ma)) {
if (ScreenOrientationHelper.isOrientationPortrait(mapActivity)) {
((NotifyingScrollView) dashboardView.findViewById(R.id.main_scroll))
.setOnScrollChangedListener(onScrollChangedListener);
}
@ -81,35 +100,40 @@ public class DashboardOnMap {
}
protected OsmandApplication getMyApplication() {
return mapActivity.getMyApplication();
}
public void setDashboardVisibility(boolean visible) {
this.visible = visible;
if (visible) {
addDashboardFragments();
addOrUpdateDashboardFragments();
setupActionBar();
dashboardView.setVisibility(View.VISIBLE);
fabButton.showFloatingActionButton();
open(dashboardView.findViewById(R.id.animateContent));
ma.getMapActions().disableDrawer();
ma.findViewById(R.id.MapInfoControls).setVisibility(View.GONE);
ma.findViewById(R.id.MapButtons).setVisibility(View.GONE);
mapActivity.getMapActions().disableDrawer();
mapActivity.findViewById(R.id.MapInfoControls).setVisibility(View.GONE);
mapActivity.findViewById(R.id.MapButtons).setVisibility(View.GONE);
} else {
ma.getMapActions().enableDrawer();
mapActivity.getMapActions().enableDrawer();
hide(dashboardView.findViewById(R.id.animateContent));
ma.findViewById(R.id.MapInfoControls).setVisibility(View.VISIBLE);
ma.findViewById(R.id.MapButtons).setVisibility(View.VISIBLE);
mapActivity.findViewById(R.id.MapInfoControls).setVisibility(View.VISIBLE);
mapActivity.findViewById(R.id.MapButtons).setVisibility(View.VISIBLE);
fabButton.hideFloatingActionButton();
}
}
private void setupActionBar() {
final Toolbar tb = (Toolbar) ma.findViewById(R.id.bottomControls);
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_flat_list_dark, MenuItemCompat.SHOW_AS_ACTION_ALWAYS);
createMenuItem(menu, WAYPOINTS_ID, R.string.waypoints,
R.drawable.ic_action_flage_dark, MenuItemCompat.SHOW_AS_ACTION_ALWAYS);
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.settings_activity,
@ -134,13 +158,35 @@ public class DashboardOnMap {
protected boolean onOptionsItemSelected(MenuItem item) {
return false;
setDashboardVisibility(false);
if(item.getItemId() == LIST_ID) {
getMyApplication().getSettings().USE_DASHBOARD_INSTEAD_OF_DRAWER.set(false);
mapActivity.getMapActions().toggleDrawer();
} else if(item.getItemId() == DIRECTIONS_ID) {
RoutingHelper routingHelper = mapActivity.getRoutingHelper();
if(!routingHelper.isFollowingMode() && !routingHelper.isRoutePlanningMode()) {
mapActivity.getMapActions().enterRoutePlanningMode(null, null, false);
} else {
mapActivity.getMapViewTrackingUtilities().switchToRoutePlanningMode();
mapActivity.refreshMap();
}
} 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;
}
// To animate view slide out from right to left
private void open(View view){
TranslateAnimation animate = new TranslateAnimation(-ma.findViewById(R.id.ParentLayout).getWidth(),0,0,0);
TranslateAnimation animate = new TranslateAnimation(-mapActivity.findViewById(R.id.ParentLayout).getWidth(),0,0,0);
animate.setDuration(500);
animate.setFillAfter(true);
view.startAnimation(animate);
@ -148,7 +194,7 @@ public class DashboardOnMap {
}
private void hide(View view) {
TranslateAnimation animate = new TranslateAnimation(0, -ma.findViewById(R.id.ParentLayout).getWidth(), 0, 0);
TranslateAnimation animate = new TranslateAnimation(0, -mapActivity.findViewById(R.id.ParentLayout).getWidth(), 0, 0);
animate.setDuration(500);
animate.setFillAfter(true);
animate.setAnimationListener(new AnimationListener() {
@ -173,38 +219,43 @@ public class DashboardOnMap {
}
private void addDashboardFragments() {
FragmentManager manager = ma.getSupportFragmentManager();
private void addOrUpdateDashboardFragments() {
FragmentManager manager = mapActivity.getSupportFragmentManager();
FragmentTransaction fragmentTransaction = manager.beginTransaction();
if (manager.findFragmentByTag(DashErrorFragment.TAG) == null &&
ma.getMyApplication().getAppInitializer().checkPreviousRunsForExceptions(ma)) {
DashErrorFragment errorFragment = new DashErrorFragment();
fragmentTransaction.add(R.id.content, errorFragment, DashErrorFragment.TAG);
}
if (manager.findFragmentByTag(DashSearchFragment.TAG) == null) {
fragmentTransaction.add(R.id.content, new DashSearchFragment(), DashSearchFragment.TAG);
}
if (manager.findFragmentByTag(DashRecentsFragment.TAG) == null) {
fragmentTransaction.add(R.id.content, new DashRecentsFragment(), DashRecentsFragment.TAG);
}
if (manager.findFragmentByTag(DashFavoritesFragment.TAG) == null) {
fragmentTransaction.add(R.id.content, new DashFavoritesFragment(), DashFavoritesFragment.TAG);
}
if (manager.findFragmentByTag(DashAudioVideoNotesFragment.TAG) == null) {
fragmentTransaction.add(R.id.content, new DashAudioVideoNotesFragment(), DashAudioVideoNotesFragment.TAG);
}
if (manager.findFragmentByTag(DashTrackFragment.TAG) == null) {
fragmentTransaction.add(R.id.content, new DashTrackFragment(), DashTrackFragment.TAG);
}
// fragmentTransaction.add(R.id.content, new DashUpdatesFragment(), DashUpdatesFragment.TAG);
if (manager.findFragmentByTag(DashPluginsFragment.TAG) == null) {
fragmentTransaction.add(R.id.content, new DashPluginsFragment(), DashPluginsFragment.TAG);
}
showFragment(manager, fragmentTransaction, DashErrorFragment.TAG, DashErrorFragment.class,
mapActivity.getMyApplication().getAppInitializer().checkPreviousRunsForExceptions(mapActivity));
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, DashUpdatesFragment.TAG, DashUpdatesFragment.class);
showFragment(manager, fragmentTransaction, DashPluginsFragment.TAG, DashPluginsFragment.class);
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);
}
} catch (Exception e) {
getMyApplication().showToastMessage("Error showing dashboard");
e.printStackTrace();
}
}
private NotifyingScrollView.OnScrollChangedListener onScrollChangedListener = new NotifyingScrollView.OnScrollChangedListener() {
public void onScrollChanged(ScrollView who, int l, int t, int oldl, int oldt) {
@ -213,11 +264,26 @@ public class DashboardOnMap {
FrameLayout.LayoutParams lp = (FrameLayout.LayoutParams) fabButton.getLayoutParams();
lp.topMargin = (int) Math.max(30 * scale, 160 * scale - sy);
((FrameLayout) fabButton.getParent()).updateViewLayout(fabButton, lp);
// TODO
}
};
public boolean isVisible() {
return visible;
}
public void onDetach(DashBaseFragment dashBaseFragment) {
Iterator<WeakReference<DashBaseFragment>> it = fragList.iterator();
while(it.hasNext()) {
WeakReference<DashBaseFragment> wr = it.next();
if(wr.get() == dashBaseFragment) {
it.remove();
}
}
}
public void onAttach(DashBaseFragment dashBaseFragment) {
fragList.add(new WeakReference<DashBaseFragment>(dashBaseFragment));
}
}

View file

@ -39,9 +39,13 @@ public class MapMenuControls extends MapControls {
// double lat = activity.getMapView().getLatitude();
// double lon = activity.getMapView().getLongitude();
// MainMenuActivity.backToMainMenuDialog(activity, new LatLon(lat, lon));
mapActivity.getMapActions().onDrawerBack();
mapActivity.getMapActions().toggleDrawer();
notifyClicked();
if(mapActivity.getMyApplication().getSettings().USE_DASHBOARD_INSTEAD_OF_DRAWER.get()) {
mapActivity.getDashboard().setDashboardVisibility(true);
} else {
mapActivity.getMapActions().onDrawerBack();
mapActivity.getMapActions().toggleDrawer();
}
}
});
}

View file

@ -26,8 +26,12 @@ public class SmallMapMenuControls extends MapControls {
@Override
public void onClick(View v) {
notifyClicked();
mapActivity.getMapActions().onDrawerBack();
mapActivity.getMapActions().toggleDrawer();
if(mapActivity.getMyApplication().getSettings().USE_DASHBOARD_INSTEAD_OF_DRAWER.get()) {
mapActivity.getDashboard().setDashboardVisibility(true);
} else {
mapActivity.getMapActions().onDrawerBack();
mapActivity.getMapActions().toggleDrawer();
}
}
});
}