From ea203771d3d6c8813c3e8bdb934bce101c77763b Mon Sep 17 00:00:00 2001 From: Alexey Kulish Date: Sun, 24 Jul 2016 18:56:13 +0300 Subject: [PATCH] [Quick search] added quick search topbar --- OsmAnd/res/layout-land/map_hud_top.xml | 57 +++++++++++++- OsmAnd/res/layout/map_hud_top.xml | 63 ++++++++++++++- .../osmand/plus/activities/MapActivity.java | 34 ++++++++ .../search/QuickSearchDialogFragment.java | 23 +++++- .../osmand/plus/views/MapControlsLayer.java | 10 +-- .../net/osmand/plus/views/MapInfoLayer.java | 40 +++++++++- .../mapwidgets/MapInfoWidgetsFactory.java | 77 ++++++++++++++++++- .../mapwidgets/MapMarkersWidgetsFactory.java | 3 +- 8 files changed, 292 insertions(+), 15 deletions(-) diff --git a/OsmAnd/res/layout-land/map_hud_top.xml b/OsmAnd/res/layout-land/map_hud_top.xml index 5577398521..c5b55c7e0f 100644 --- a/OsmAnd/res/layout-land/map_hud_top.xml +++ b/OsmAnd/res/layout-land/map_hud_top.xml @@ -11,7 +11,8 @@ android:layout_height="wrap_content" android:clickable="true" android:minHeight="@dimen/map_address_height" - android:visibility="gone"> + android:visibility="gone" + tools:visibility="visible"> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + android:visibility="gone" + tools:visibility="visible"> rows = new ArrayList<>(); if (history.size() > 0) { - searchUICore.sortSearchResults(sp, history); OsmandApplication app = getMyApplication(); for (SearchResult sr : history) { rows.add(new QuickSearchListItem(app, sr)); diff --git a/OsmAnd/src/net/osmand/plus/views/MapControlsLayer.java b/OsmAnd/src/net/osmand/plus/views/MapControlsLayer.java index 7a94729743..f30f6f1c1c 100644 --- a/OsmAnd/src/net/osmand/plus/views/MapControlsLayer.java +++ b/OsmAnd/src/net/osmand/plus/views/MapControlsLayer.java @@ -78,7 +78,7 @@ public class MapControlsLayer extends OsmandMapLayer { private MapHudButton backToLocationControl; private MapHudButton menuControl; private MapHudButton compassHud; - private MapHudButton quickSearch; + private MapHudButton quickSearchHud; private float cachedRotate = 0; private ImageView appModeIcon; private TextView zoomText; @@ -215,15 +215,15 @@ public class MapControlsLayer extends OsmandMapLayer { }); View search = mapActivity.findViewById(R.id.map_search_button); - quickSearch = createHudButton(search, R.drawable.map_search_dark) + quickSearchHud = createHudButton(search, R.drawable.map_search_dark) .setIconsId(R.drawable.map_search_dark, R.drawable.map_search_night) .setIconColorId(0) .setBg(R.drawable.btn_inset_circle_trans, R.drawable.btn_inset_circle_night); - controls.add(quickSearch); + controls.add(quickSearchHud); search.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { - QuickSearchDialogFragment.showInstance(mapActivity, ""); + mapActivity.showQuickSearch(); } }); @@ -540,7 +540,7 @@ public class MapControlsLayer extends OsmandMapLayer { mapZoomOut.updateVisibility(!dialogOpened); compassHud.updateVisibility(!dialogOpened); layersHud.updateVisibility(!dialogOpened); - quickSearch.updateVisibility(!dialogOpened); + quickSearchHud.updateVisibility(!dialogOpened); if (!routePlanningMode && !routeFollowingMode) { if (mapView.isZooming()) { diff --git a/OsmAnd/src/net/osmand/plus/views/MapInfoLayer.java b/OsmAnd/src/net/osmand/plus/views/MapInfoLayer.java index 5c8d8611ca..135e5a3392 100644 --- a/OsmAnd/src/net/osmand/plus/views/MapInfoLayer.java +++ b/OsmAnd/src/net/osmand/plus/views/MapInfoLayer.java @@ -17,6 +17,7 @@ import net.osmand.plus.R; import net.osmand.plus.activities.MapActivity; import net.osmand.plus.helpers.AndroidUiHelper; import net.osmand.plus.views.mapwidgets.MapInfoWidgetsFactory; +import net.osmand.plus.views.mapwidgets.MapInfoWidgetsFactory.QuickSearchView; import net.osmand.plus.views.mapwidgets.MapInfoWidgetsFactory.TopTextView; import net.osmand.plus.views.mapwidgets.MapMarkersWidgetsFactory; import net.osmand.plus.views.mapwidgets.MapWidgetRegistry; @@ -51,6 +52,7 @@ public class MapInfoLayer extends OsmandMapLayer { private OsmandSettings settings; private DrawSettings drawSettings; private TopTextView streetNameView; + private QuickSearchView quickSearchView; public MapInfoLayer(MapActivity map, RouteLayer layer){ this.map = map; @@ -104,10 +106,13 @@ public class MapInfoLayer extends OsmandMapLayer { MapMarkersWidgetsFactory mwf = map.getMapLayers().getMapMarkersLayer().getWidgetsFactory(); OsmandApplication app = view.getApplication(); lanesControl = ric.createLanesControl(map, view); - - streetNameView = new MapInfoWidgetsFactory.TopTextView(map.getMyApplication(), map); + + streetNameView = new TopTextView(map.getMyApplication(), map); updateStreetName(false, calculateTextState()); - + + quickSearchView = new QuickSearchView(map); + updateQuickSearch(false, calculateTextStateSearch()); + alarmControl = ric.createAlarmInfoControl(app, map); alarmControl.setVisibility(false); @@ -213,6 +218,7 @@ public class MapInfoLayer extends OsmandMapLayer { updateReg(ts, reg); } updateStreetName(nightMode, ts); + updateQuickSearch(nightMode, calculateTextStateSearch()); lanesControl.updateTextSize(nightMode, ts.textColor, ts.textShadowColor, ts.textBold, ts.textShadowRadius / 2); rulerControl.updateTextSize(nightMode, ts.textColor, ts.textShadowColor, (int) (2 * view.getDensity())); this.expand.setBackgroundResource(ts.expand); @@ -227,6 +233,12 @@ public class MapInfoLayer extends OsmandMapLayer { streetNameView.updateTextColor(nightMode, ts.textColor, ts.textShadowColor, ts.textBold, ts.textShadowRadius); } + private void updateQuickSearch(boolean nightMode, TextState ts) { + quickSearchView.setBackgroundResource(AndroidUiHelper.isOrientationPortrait(map) ? ts.boxTop + : ts.boxFree); + quickSearchView.updateTextColor(nightMode, ts.textColor); + } + private void updateReg(TextState ts, MapWidgetRegInfo reg) { View v = reg.widget.getView().findViewById(R.id.widget_bg); if(v != null) { @@ -273,6 +285,27 @@ public class MapInfoLayer extends OsmandMapLayer { return ts; } + private TextState calculateTextStateSearch() { + boolean nightMode = drawSettings != null && drawSettings.isNightMode(); + TextState ts = new TextState(); + ts.night = nightMode; + ts.textColor = nightMode ? ContextCompat.getColor(view.getContext(), R.color.widgettext_night) : Color.BLACK; + if (nightMode) { + ts.boxTop = R.drawable.btn_flat_night; + ts.rightRes = R.drawable.btn_left_round_night; + ts.leftRes = R.drawable.btn_right_round_night; + ts.expand = R.drawable.btn_inset_circle_night; + ts.boxFree = R.drawable.btn_round_night; + } else { + ts.boxTop = R.drawable.btn_flat; + ts.rightRes = R.drawable.btn_left_round; + ts.leftRes = R.drawable.btn_right_round; + ts.expand = R.drawable.btn_inset_circle; + ts.boxFree = R.drawable.btn_round; + } + return ts; + } + @Override public void onDraw(Canvas canvas, RotatedTileBox tileBox, DrawSettings drawSettings) { this.drawSettings = drawSettings; @@ -280,6 +313,7 @@ public class MapInfoLayer extends OsmandMapLayer { updateColorShadowsOfText(); mapInfoControls.updateInfo(settings.getApplicationMode(), drawSettings, expanded); streetNameView.updateInfo(drawSettings); + quickSearchView.updateInfo(); alarmControl.updateInfo(drawSettings); rulerControl.updateInfo(tileBox, drawSettings); lanesControl.updateInfo(drawSettings); diff --git a/OsmAnd/src/net/osmand/plus/views/mapwidgets/MapInfoWidgetsFactory.java b/OsmAnd/src/net/osmand/plus/views/mapwidgets/MapInfoWidgetsFactory.java index 3e9f9dce36..d59fcb6dc7 100644 --- a/OsmAnd/src/net/osmand/plus/views/mapwidgets/MapInfoWidgetsFactory.java +++ b/OsmAnd/src/net/osmand/plus/views/mapwidgets/MapInfoWidgetsFactory.java @@ -7,6 +7,7 @@ import android.support.v7.app.AlertDialog; import android.util.DisplayMetrics; import android.view.View; import android.view.WindowManager; +import android.widget.ImageButton; import android.widget.ImageView; import android.widget.LinearLayout; import android.widget.TextView; @@ -32,6 +33,7 @@ import net.osmand.plus.helpers.WaypointHelper.LocationPointWrapper; import net.osmand.plus.monitoring.OsmandMonitoringPlugin; import net.osmand.plus.routing.RouteDirectionInfo; import net.osmand.plus.routing.RoutingHelper; +import net.osmand.plus.search.QuickSearchDialogFragment; import net.osmand.plus.views.OsmandMapLayer.DrawSettings; import net.osmand.plus.mapcontextmenu.other.MapRouteInfoMenu; import net.osmand.plus.views.mapwidgets.NextTurnInfoWidget.TurnDrawable; @@ -159,7 +161,76 @@ public class MapInfoWidgetsFactory { }); return gpsInfoControl; } - + + public static class QuickSearchView { + private final MapActivity map; + private View searchTopBar; + private View searchTopBarLayout; + private ImageView searchIcon; + private TextView searchTitle; + private ImageButton searchCloseButton; + + public QuickSearchView(final MapActivity map) { + this.map = map; + searchTopBar = map.findViewById(R.id.search_topbar); + searchTopBarLayout = map.findViewById(R.id.search_topbar_layout); + searchIcon = (ImageView) map.findViewById(R.id.search_icon); + searchTitle = (TextView) map.findViewById(R.id.search_title); + searchTitle.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + map.showQuickSearch(); + } + }); + searchCloseButton = (ImageButton) map.findViewById(R.id.search_close_button); + searchCloseButton.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + map.closeQuickSearch(); + } + }); + updateVisibility(false); + } + + public boolean updateVisibility(boolean visible) { + return updateVisibility(searchTopBar, visible); + } + + public boolean updateVisibility(View v, boolean visible) { + if (visible != (v.getVisibility() == View.VISIBLE)) { + if (visible) { + v.setVisibility(View.VISIBLE); + } else { + v.setVisibility(View.GONE); + } + v.invalidate(); + return true; + } + return false; + } + + public void updateInfo() { + boolean isQuickSearchActive = map.isQuickSearchDialogActive(); + if (isQuickSearchActive) { + QuickSearchDialogFragment fragment = map.getQuickSearchDialogFragment(); + if (fragment != null) { + searchTitle.setText(fragment.getText()); + } + } + updateVisibility(isQuickSearchActive); + } + + public void updateTextColor(boolean nightMode, int textColor) { + OsmandApplication app = map.getMyApplication(); + searchTitle.setTextColor(textColor); + searchIcon.setImageDrawable(app.getIconsCache().getIcon(R.drawable.ic_action_search_dark, !nightMode)); + searchCloseButton.setImageDrawable(app.getIconsCache().getIcon(R.drawable.ic_action_remove_dark, !nightMode)); + } + + public void setBackgroundResource(int boxTop) { + searchTopBarLayout.setBackgroundResource(boxTop); + } + } public static class TopTextView { private final RoutingHelper routingHelper; @@ -264,7 +335,9 @@ public class MapInfoWidgetsFactory { text = ""; } } - if (!showNextTurn && updateWaypoint()) { + if (map.isQuickSearchDialogActive()) { + updateVisibility(false); + } else if (!showNextTurn && updateWaypoint()) { updateVisibility(true); updateVisibility(addressText, false); updateVisibility(addressTextShadow, false); diff --git a/OsmAnd/src/net/osmand/plus/views/mapwidgets/MapMarkersWidgetsFactory.java b/OsmAnd/src/net/osmand/plus/views/mapwidgets/MapMarkersWidgetsFactory.java index e030e82b3e..05c304fa25 100644 --- a/OsmAnd/src/net/osmand/plus/views/mapwidgets/MapMarkersWidgetsFactory.java +++ b/OsmAnd/src/net/osmand/plus/views/mapwidgets/MapMarkersWidgetsFactory.java @@ -202,7 +202,8 @@ public class MapMarkersWidgetsFactory { || map.getMyApplication().getRoutingHelper().isFollowingMode() || map.getMyApplication().getRoutingHelper().isRoutePlanningMode() || map.getMapLayers().getMapControlsLayer().getMapRouteInfoMenu().isVisible() - || addressTopBar.getVisibility() == View.VISIBLE) { + || addressTopBar.getVisibility() == View.VISIBLE + || map.isQuickSearchDialogActive()) { updateVisibility(false); return; }