[Quick search] ui fixes. Toolbar for transport in progress.

This commit is contained in:
Alexey Kulish 2016-08-06 10:02:30 +03:00
parent 16f3158ce4
commit e9ce449d43
6 changed files with 121 additions and 35 deletions

View file

@ -439,7 +439,10 @@ public class MapActivity extends OsmandActionBarActivity implements DownloadEven
closeDrawer();
return;
}
if (getQuickSearchDialogFragment() != null) {
showQuickSearch(false, false);
return;
}
if (prevActivityIntent != null && getSupportFragmentManager().getBackStackEntryCount() == 0) {
prevActivityIntent.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
LatLon loc = getMapLocation();
@ -576,6 +579,14 @@ public class MapActivity extends OsmandActionBarActivity implements DownloadEven
routingHelper.addListener(this);
app.getMapMarkersHelper().addListener(this);
QuickSearchDialogFragment searchDialogFragment = getQuickSearchDialogFragment();
if (searchDialogFragment != null) {
if (searchDialogFragment.isSearchHidden()) {
searchDialogFragment.hide();
searchDialogFragment.restoreToolbar();
}
}
getMyApplication().getAppCustomization().resumeActivity(MapActivity.class, this);
if (System.currentTimeMillis() - tm > 50) {
System.err.println("OnCreate for MapActivity took " + (System.currentTimeMillis() - tm) + " ms");

View file

@ -313,6 +313,10 @@ public class MapContextMenu extends MenuTitleController implements StateChangedL
if (init(latLon, pointDescription, object)) {
if (!MapContextMenuFragment.showInstance(this, mapActivity, centerMarker)) {
active = false;
} else {
if (menuController != null) {
menuController.onShow();
}
}
centerMarker = false;
autoHide = false;
@ -345,7 +349,7 @@ public class MapContextMenu extends MenuTitleController implements StateChangedL
if (object instanceof MapMarker) {
mapActivity.getMyApplication().getMapMarkersHelper().removeListener(this);
}
if(menuController != null) {
if (menuController != null) {
menuController.onClose();
}
if (this.object != null) {
@ -361,8 +365,8 @@ public class MapContextMenu extends MenuTitleController implements StateChangedL
mapActivity.getMapView().setMapPosition(mapPosition);
mapPosition = 0;
}
if(getMenuController() != null) {
getMenuController().onHide();
if (menuController != null) {
menuController.onHide();
}
WeakReference<MapContextMenuFragment> fragmentRef = findMenuFragment();
if (fragmentRef != null) {
@ -454,7 +458,7 @@ public class MapContextMenu extends MenuTitleController implements StateChangedL
}
private void acquireMenuController() {
if(menuController != null) {
if (menuController != null) {
menuController.onAcquireNewController(pointDescription, object);
}
menuController = MenuController.getMenuController(mapActivity, pointDescription, object, MenuType.STANDARD);

View file

@ -53,6 +53,7 @@ import net.osmand.plus.osmo.OsMoMenuController;
import net.osmand.plus.parkingpoint.ParkingPositionMenuController;
import net.osmand.plus.resources.ResourceManager;
import net.osmand.plus.views.DownloadedRegionsLayer.DownloadMapObject;
import net.osmand.plus.views.mapwidgets.MapInfoWidgetsFactory.TopToolbarViewController;
import net.osmand.util.Algorithms;
import net.osmand.util.MapUtils;
@ -87,6 +88,8 @@ public abstract class MenuController extends BaseMenuController {
protected TitleButtonController rightDownloadButtonController;
protected TitleProgressController titleProgressController;
protected TopToolbarViewController toolbarController;
protected IndexItem indexItem;
protected boolean downloaded;
private BinaryMapDataObject downloadMapDataObject;
@ -272,6 +275,10 @@ public abstract class MenuController extends BaseMenuController {
return titleProgressController;
}
public TopToolbarViewController getToolbarController() {
return toolbarController;
}
public boolean supportZoomIn() {
return true;
}
@ -442,10 +449,19 @@ public abstract class MenuController extends BaseMenuController {
public abstract void buttonPressed();
}
public void onShow() {
if (toolbarController != null) {
getMapActivity().showTopToolbar(toolbarController);
}
}
public void onHide() {
}
public void onClose() {
if (toolbarController != null) {
getMapActivity().hideTopToolbar(toolbarController);
}
}
public void onAcquireNewController(PointDescription pointDescription, Object object) {

View file

@ -1,14 +1,11 @@
package net.osmand.plus.mapcontextmenu.controllers;
import java.lang.ref.WeakReference;
import java.util.List;
import android.view.View;
import android.view.View.OnClickListener;
import net.osmand.binary.OsmandOdb.TransportRouteStop;
import net.osmand.data.LatLon;
import net.osmand.data.PointDescription;
import net.osmand.data.RotatedTileBox;
import net.osmand.data.TransportStop;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.R;
@ -18,17 +15,23 @@ import net.osmand.plus.mapcontextmenu.MapContextMenuFragment;
import net.osmand.plus.mapcontextmenu.MenuBuilder;
import net.osmand.plus.mapcontextmenu.MenuController;
import net.osmand.plus.mapcontextmenu.controllers.TransportStopController.TransportStopRoute;
import net.osmand.plus.views.OsmandMapTileView;
import net.osmand.plus.views.TransportStopsLayer;
import net.osmand.plus.views.mapwidgets.MapInfoWidgetsFactory.TopToolbarView;
import net.osmand.plus.views.mapwidgets.MapInfoWidgetsFactory.TopToolbarViewController;
import java.lang.ref.WeakReference;
import java.util.List;
public class TransportRouteController extends MenuController {
private TransportStopRoute transportStop;
public TransportRouteController(OsmandApplication app, MapActivity mapActivity, PointDescription pointDescription,
TransportStopRoute transportStop) {
TransportStopRoute transportStop) {
super(new MenuBuilder(app), pointDescription, mapActivity);
this.transportStop = transportStop;
toolbarController = new TransportRouteToolbarController();
toolbarController.setTitle(getNameStr());
}
@Override
@ -46,7 +49,7 @@ public class TransportRouteController extends MenuController {
@Override
public int getLeftIconId() {
return this.transportStop.type == null ?
R.drawable.mx_public_transport :
R.drawable.mx_public_transport :
this.transportStop.type.getTopResourceId();
}
@ -59,18 +62,18 @@ public class TransportRouteController extends MenuController {
public boolean displayDistanceDirection() {
return false;
}
@Override
public boolean fabVisible() {
return false;
}
@Override
public boolean buttonsVisible() {
return false;
}
@Override
public boolean displayStreetNameInTitle() {
return super.displayStreetNameInTitle();
@ -80,20 +83,20 @@ public class TransportRouteController extends MenuController {
public String getTypeStr() {
return getPointDescription().getTypeName();
}
@Override
public void onClose() {
super.onHide();
super.onClose();
TransportStopsLayer stopsLayer = getMapActivity().getMapLayers().getTransportStopsLayer();
stopsLayer.setRoute(null);
}
public void onAcquireNewController(PointDescription pointDescription, Object object) {
if(object instanceof TransportRouteStop) {
if (object instanceof TransportRouteStop) {
TransportStopsLayer stopsLayer = getMapActivity().getMapLayers().getTransportStopsLayer();
stopsLayer.setRoute(null);
}
};
}
@Override
public void addPlainMenuItems(String typeStr, PointDescription pointDescription, final LatLon latLon) {
@ -110,7 +113,7 @@ public class TransportRouteController extends MenuController {
}
int defaultIcon = transportStop.type == null ? R.drawable.mx_route_bus_ref : transportStop.type.getResourceId();
int startPosition = 0;
if(!transportStop.showWholeRoute) {
if (!transportStop.showWholeRoute) {
startPosition = (currentStop == -1 ? 0 : currentStop);
if (currentStop > 0) {
addPlainMenuItem(defaultIcon, getMapActivity().getString(R.string.route_stops_before, currentStop),
@ -132,7 +135,7 @@ public class TransportRouteController extends MenuController {
for (int i = startPosition; i < stops.size(); i++) {
final TransportStop stop = stops.get(i);
final String name = useEnglishNames ? stop.getEnName(true) : stop.getName();
addPlainMenuItem(currentStop == i ? R.drawable.ic_action_marker_dark: defaultIcon,
addPlainMenuItem(currentStop == i ? R.drawable.ic_action_marker_dark : defaultIcon,
name, false, false, new OnClickListener() {
@Override
@ -144,7 +147,7 @@ public class TransportRouteController extends MenuController {
stopsLayer.setRoute(null);
mm.show(stop.getLocation(), pd, stop);
WeakReference<MapContextMenuFragment> rr = mm.findMenuFragment();
if(rr != null && rr.get() != null) {
if (rr != null && rr.get() != null) {
rr.get().centerMarkerLocation();
}
}
@ -152,4 +155,25 @@ public class TransportRouteController extends MenuController {
}
}
public static class TransportRouteToolbarController extends TopToolbarViewController {
public TransportRouteToolbarController() {
super(TopToolbarViewControllerType.CONTEXT_MENU);
}
@Override
public void onBackPressed(TopToolbarView view) {
view.getMap().getContextMenu().close();
}
@Override
public void onTitlePressed(TopToolbarView view) {
}
@Override
public void onClosePressed(TopToolbarView view) {
view.getMap().getContextMenu().close();
}
}
}

View file

@ -84,6 +84,9 @@ public class QuickSearchDialogFragment extends DialogFragment implements OsmAndC
private static final String QUICK_SEARCH_LON_KEY = "quick_search_lon_key";
private static final String QUICK_SEARCH_SEARCHING_KEY = "quick_search_searching_key";
private static final String QUICK_SEARCH_SHOW_CATEGORIES_KEY = "quick_search_show_categories_key";
private static final String QUICK_SEARCH_HIDDEN_KEY = "quick_search_hidden_key";
private static final String QUICK_SEARCH_TOOLBAR_TITLE_KEY = "quick_search_toolbar_title_key";
private Toolbar toolbar;
private LockableViewPager viewPager;
private SearchFragmentPagerAdapter pagerAdapter;
@ -117,7 +120,9 @@ public class QuickSearchDialogFragment extends DialogFragment implements OsmAndC
private boolean useMapCenter;
private boolean paused;
private boolean searching;
private boolean hidden;
private boolean foundPartialLocation;
private String toolbarTitle;
private boolean newSearch;
private boolean interruptedSearch;
@ -150,6 +155,8 @@ public class QuickSearchDialogFragment extends DialogFragment implements OsmAndC
centerLatLon = new LatLon(lat, lon);
}
interruptedSearch = savedInstanceState.getBoolean(QUICK_SEARCH_SEARCHING_KEY, false);
hidden = savedInstanceState.getBoolean(QUICK_SEARCH_HIDDEN_KEY, false);
toolbarTitle = savedInstanceState.getString(QUICK_SEARCH_TOOLBAR_TITLE_KEY);
}
if (searchQuery == null && arguments != null) {
searchQuery = arguments.getString(QUICK_SEARCH_QUERY_KEY);
@ -385,8 +392,23 @@ public class QuickSearchDialogFragment extends DialogFragment implements OsmAndC
}
}
public void restoreToolbar() {
if (toolbarTitle != null) {
showToolbar(toolbarTitle);
} else {
showToolbar();
}
}
public void showToolbar() {
toolbarController.setTitle(getText());
toolbarTitle = getText();
toolbarController.setTitle(toolbarTitle);
getMapActivity().showTopToolbar(toolbarController);
}
public void showToolbar(String title) {
toolbarTitle = title;
toolbarController.setTitle(toolbarTitle);
getMapActivity().showTopToolbar(toolbarController);
}
@ -404,6 +426,10 @@ public class QuickSearchDialogFragment extends DialogFragment implements OsmAndC
}
}
public boolean isSearchHidden() {
return hidden;
}
public void show() {
if (useMapCenter) {
LatLon mapCenter = getMapActivity().getMapView().getCurrentRotatedTileBox().getCenterLatLon();
@ -414,10 +440,12 @@ public class QuickSearchDialogFragment extends DialogFragment implements OsmAndC
}
getDialog().show();
paused = false;
hidden = false;
}
public void hide() {
paused = true;
hidden = true;
hideProgressBar();
updateClearButtonVisibility(true);
getDialog().hide();
@ -511,6 +539,10 @@ public class QuickSearchDialogFragment extends DialogFragment implements OsmAndC
public void onSaveInstanceState(Bundle outState) {
outState.putString(QUICK_SEARCH_QUERY_KEY, searchQuery);
outState.putBoolean(QUICK_SEARCH_SEARCHING_KEY, searching);
outState.putBoolean(QUICK_SEARCH_HIDDEN_KEY, hidden);
if (toolbarTitle != null) {
outState.putString(QUICK_SEARCH_TOOLBAR_TITLE_KEY, toolbarTitle);
}
if (centerLatLon != null) {
outState.putDouble(QUICK_SEARCH_LAT_KEY, centerLatLon.getLatitude());
outState.putDouble(QUICK_SEARCH_LON_KEY, centerLatLon.getLongitude());

View file

@ -94,7 +94,7 @@ public abstract class QuickSearchListFragment extends OsmAndListFragment {
|| sr.objectType == ObjectType.WPT
|| sr.objectType == ObjectType.STREET_INTERSECTION) {
showOnMap(sr, sr.objectType != ObjectType.RECENT_OBJ);
showOnMap(sr);
} else {
dialogFragment.completeQueryWithObject(item.getSearchResult());
}
@ -152,7 +152,7 @@ public abstract class QuickSearchListFragment extends OsmAndListFragment {
dialogFragment.onSearchListFragmentResume(this);
}
private void showOnMap(SearchResult searchResult, boolean showTopbar) {
private void showOnMap(SearchResult searchResult) {
if (searchResult.location != null) {
OsmandApplication app = getMyApplication();
String lang = searchResult.requiredSearchPhrase.getSettings().getLang();
@ -220,21 +220,20 @@ public abstract class QuickSearchListFragment extends OsmAndListFragment {
pointDescription = wpt.getPointDescription(getMyApplication());
break;
}
if (showTopbar) {
dialogFragment.showToolbar();
dialogFragment.hide();
if (pointDescription != null) {
dialogFragment.showToolbar(pointDescription.getName());
} else {
dialogFragment.hideToolbar();
dialogFragment.dismiss();
dialogFragment.showToolbar();
}
dialogFragment.hide();
getMyApplication().getSettings().setMapLocationToShow(
searchResult.location.getLatitude(), searchResult.location.getLongitude(),
searchResult.preferredZoom, pointDescription, true, object);
MapActivity.launchMapActivityMoveToTop(getActivity());
if (showTopbar) {
dialogFragment.reloadHistory();
}
dialogFragment.reloadHistory();
}
}