[Quick search] added quick search topbar

This commit is contained in:
Alexey Kulish 2016-07-24 18:56:13 +03:00
parent b7378c0c61
commit ea203771d3
8 changed files with 292 additions and 15 deletions

View file

@ -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">
<LinearLayout
android:layout_width="match_parent"
@ -347,6 +348,60 @@
</LinearLayout>
</FrameLayout>
<FrameLayout
android:id="@+id/search_topbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:visibility="gone"
tools:visibility="visible">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<LinearLayout
android:id="@+id/search_topbar_layout"
android:layout_width="match_parent"
android:layout_height="@dimen/dashboard_map_toolbar"
android:gravity="center_vertical"
android:orientation="horizontal">
<ImageView
android:id="@+id/search_icon"
android:layout_width="54dp"
android:layout_height="wrap_content"
android:src="@drawable/ic_action_search_dark"/>
<TextView
android:id="@+id/search_title"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="@null"
android:clickable="true"
android:gravity="center_vertical"
android:textColor="?android:textColorPrimary"
android:lines="1"
android:ellipsize="end"
android:singleLine="true"
android:text="Search"
android:textSize="@dimen/abc_text_size_medium_material"/>
<ImageButton
android:id="@+id/search_close_button"
style="@style/Widget.AppCompat.ActionButton"
android:layout_width="48dp"
android:layout_height="48dp"
android:contentDescription="@string/shared_string_close"
android:src="@drawable/ic_action_remove_dark"/>
</LinearLayout>
</LinearLayout>
</FrameLayout>
<!-- CENTER -->
<FrameLayout

View file

@ -146,6 +146,66 @@
</LinearLayout>
</FrameLayout>
<FrameLayout
android:id="@+id/search_topbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:visibility="gone"
tools:visibility="visible">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<LinearLayout
android:id="@+id/search_topbar_layout"
android:layout_width="match_parent"
android:layout_height="@dimen/dashboard_map_toolbar"
android:gravity="center_vertical"
android:orientation="horizontal">
<ImageView
android:id="@+id/search_icon"
android:layout_width="54dp"
android:layout_height="wrap_content"
android:src="@drawable/ic_action_search_dark"/>
<TextView
android:id="@+id/search_title"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="@null"
android:clickable="true"
android:gravity="center_vertical"
android:textColor="?android:textColorPrimary"
android:lines="1"
android:ellipsize="end"
android:singleLine="true"
android:text="Search"
android:textSize="@dimen/abc_text_size_medium_material"/>
<ImageButton
android:id="@+id/search_close_button"
style="@style/Widget.AppCompat.ActionButton"
android:layout_width="48dp"
android:layout_height="48dp"
android:contentDescription="@string/shared_string_close"
android:src="@drawable/ic_action_remove_dark"/>
</LinearLayout>
<FrameLayout
android:id="@+id/search_topbar_shadow"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:foreground="@drawable/bg_contextmenu_shadow"
android:foregroundGravity="top|fill_horizontal"/>
</LinearLayout>
</FrameLayout>
<FrameLayout
android:id="@+id/map_markers_top_bar"
@ -153,7 +213,8 @@
android:layout_height="wrap_content"
android:clickable="true"
android:minHeight="@dimen/map_address_height"
android:visibility="gone">
android:visibility="gone"
tools:visibility="visible">
<LinearLayout
android:layout_width="match_parent"

View file

@ -22,6 +22,7 @@ import android.os.Handler;
import android.os.Message;
import android.support.annotation.NonNull;
import android.support.v4.app.ActivityCompat;
import android.support.v4.app.Fragment;
import android.support.v4.widget.DrawerLayout;
import android.support.v7.app.AlertDialog;
import android.util.DisplayMetrics;
@ -88,6 +89,7 @@ import net.osmand.plus.resources.ResourceManager;
import net.osmand.plus.routing.RoutingHelper;
import net.osmand.plus.routing.RoutingHelper.IRouteInformationListener;
import net.osmand.plus.routing.RoutingHelper.RouteCalculationProgressCallback;
import net.osmand.plus.search.QuickSearchDialogFragment;
import net.osmand.plus.views.AnimateDraggingMapThread;
import net.osmand.plus.views.MapControlsLayer;
import net.osmand.plus.views.OsmAndMapLayersView;
@ -166,6 +168,7 @@ public class MapActivity extends OsmandActionBarActivity implements DownloadEven
private boolean permissionGranted;
private boolean mIsDestroyed = false;
private boolean quickSearchActive = false;
@Override
public void onCreate(Bundle savedInstanceState) {
@ -1354,4 +1357,35 @@ public class MapActivity extends OsmandActionBarActivity implements DownloadEven
DestinationReachedMenu.show(this);
}
}
public void showQuickSearch() {
QuickSearchDialogFragment fragment = getQuickSearchDialogFragment();
if (fragment != null) {
fragment.show();
refreshMap();
} else {
QuickSearchDialogFragment.showInstance(this, "");
}
}
public void closeQuickSearch() {
QuickSearchDialogFragment fragment = getQuickSearchDialogFragment();
if (fragment != null) {
fragment.closeSearch();
refreshMap();
}
}
public QuickSearchDialogFragment getQuickSearchDialogFragment() {
Fragment fragment = getSupportFragmentManager().findFragmentByTag(QuickSearchDialogFragment.TAG);
return fragment!= null && !fragment.isDetached() && !fragment.isRemoving() ? (QuickSearchDialogFragment) fragment : null;
}
public boolean isQuickSearchDialogActive() {
return quickSearchActive && getQuickSearchDialogFragment() != null;
}
public void setQuickSearchActive(boolean quickSearchActive) {
this.quickSearchActive = quickSearchActive;
}
}

View file

@ -164,7 +164,7 @@ public class QuickSearchDialogFragment extends DialogFragment implements OsmAndC
settings.setMapLocationToShow(location.getLatitude(), location.getLongitude(), 15);
}
MapActivity.launchMapActivityMoveToTop(getActivity());
dismiss();
hide();
}
}
});
@ -272,6 +272,24 @@ public class QuickSearchDialogFragment extends DialogFragment implements OsmAndC
return view;
}
public String getText() {
return searchEditText.getText().toString();
}
public void show() {
getDialog().show();
}
public void hide() {
getDialog().hide();
}
public void closeSearch() {
MapActivity mapActivity = getMapActivity();
mapActivity.getMyApplication().getPoiFilters().clearSelectedPoiFilters();
dismiss();
}
public void addMainSearchFragment() {
FragmentManager childFragMan = getChildFragmentManager();
FragmentTransaction childFragTrans = childFragMan.beginTransaction();
@ -393,12 +411,14 @@ public class QuickSearchDialogFragment extends DialogFragment implements OsmAndC
app.getLocationProvider().addLocationListener(this);
location = app.getLocationProvider().getLastKnownLocation();
updateLocation(location);
getMapActivity().setQuickSearchActive(true);
}
@Override
public void onPause() {
super.onPause();
OsmandApplication app = getMyApplication();
getMapActivity().setQuickSearchActive(false);
getChildFragmentManager().popBackStack();
app.getLocationProvider().removeLocationListener(this);
app.getLocationProvider().removeCompassListener(this);
@ -519,7 +539,6 @@ public class QuickSearchDialogFragment extends DialogFragment implements OsmAndC
}, 0, new AtomicInteger(0), -1));
List<QuickSearchListItem> rows = new ArrayList<>();
if (history.size() > 0) {
searchUICore.sortSearchResults(sp, history);
OsmandApplication app = getMyApplication();
for (SearchResult sr : history) {
rows.add(new QuickSearchListItem(app, sr));

View file

@ -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()) {

View file

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

View file

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

View file

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