forked from organicmaps/organicmaps
[android] Extracted search module.
This commit is contained in:
parent
fe18df87eb
commit
bf190d9b74
5 changed files with 231 additions and 187 deletions
|
@ -16,13 +16,14 @@
|
|||
android:background="?searchLayoutBackground"
|
||||
android:orientation="horizontal"
|
||||
android:padding="@dimen/margin_quarter"
|
||||
android:visibility="gone"
|
||||
android:visibility="invisible"
|
||||
tools:visibility="visible">
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/search_fuel"
|
||||
style="@style/MwmWidget.SearchNavigationButton"
|
||||
android:layout_marginLeft="60dp"
|
||||
android:layout_marginStart="60dp"
|
||||
android:src="@drawable/ic_routing_fuel_on"/>
|
||||
|
||||
<ImageView
|
||||
|
|
|
@ -18,7 +18,7 @@
|
|||
android:layout_marginLeft="-70dp"
|
||||
android:layout_marginStart="-70dp"
|
||||
android:background="?searchLayoutBackground"
|
||||
android:visibility="gone"
|
||||
android:visibility="invisible"
|
||||
tools:visibility="visible">
|
||||
|
||||
<ImageView
|
||||
|
|
|
@ -745,7 +745,7 @@ public class MwmActivity extends BaseMwmFragmentActivity
|
|||
}
|
||||
});
|
||||
mOnmapDownloader.onResume();
|
||||
mNavigationController.getNavMenu().onResume(null);
|
||||
mNavigationController.onResume();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -1249,6 +1249,7 @@ public class MwmActivity extends BaseMwmFragmentActivity
|
|||
if (RoutingController.get().isNavigating())
|
||||
{
|
||||
mNavigationController.show(true);
|
||||
mSearchController.hide();
|
||||
mMainMenu.setState(MainMenu.State.NAVIGATION, false);
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -1,19 +1,12 @@
|
|||
package com.mapswithme.maps.routing;
|
||||
|
||||
import android.animation.Animator;
|
||||
import android.animation.AnimatorInflater;
|
||||
import android.app.Activity;
|
||||
import android.content.Intent;
|
||||
import android.location.Location;
|
||||
import android.os.Build;
|
||||
import android.support.annotation.DrawableRes;
|
||||
import android.support.annotation.IdRes;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.text.TextUtils;
|
||||
import android.util.Pair;
|
||||
import android.view.View;
|
||||
import android.view.ViewTreeObserver;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.TextView;
|
||||
|
||||
|
@ -26,19 +19,17 @@ import com.mapswithme.maps.MwmActivity;
|
|||
import com.mapswithme.maps.R;
|
||||
import com.mapswithme.maps.bookmarks.data.DistanceAndAzimut;
|
||||
import com.mapswithme.maps.location.LocationHelper;
|
||||
import com.mapswithme.maps.search.SearchEngine;
|
||||
import com.mapswithme.maps.settings.SettingsActivity;
|
||||
import com.mapswithme.maps.sound.TtsPlayer;
|
||||
import com.mapswithme.maps.widget.FlatProgressView;
|
||||
import com.mapswithme.maps.widget.menu.NavMenu;
|
||||
import com.mapswithme.util.Graphics;
|
||||
import com.mapswithme.util.StringUtils;
|
||||
import com.mapswithme.util.UiUtils;
|
||||
import com.mapswithme.util.Utils;
|
||||
import com.mapswithme.util.statistics.AlohaHelper;
|
||||
import com.mapswithme.util.statistics.Statistics;
|
||||
|
||||
public class NavigationController implements View.OnClickListener
|
||||
public class NavigationController
|
||||
{
|
||||
private final View mFrame;
|
||||
private final View mBottomFrame;
|
||||
|
@ -66,54 +57,7 @@ public class NavigationController implements View.OnClickListener
|
|||
private final TextView mDistanceUnits;
|
||||
private final FlatProgressView mRouteProgress;
|
||||
|
||||
private final View mSearchLayout;
|
||||
private final ImageView mSearchButton;
|
||||
private SearchOption mCurrentSearch;
|
||||
private boolean mIsSearchExpanded;
|
||||
|
||||
private enum SearchOption
|
||||
{
|
||||
FUEL(R.id.search_fuel, R.drawable.ic_routing_fuel_off, R.drawable.ic_routing_fuel_on, "fuel"),
|
||||
PARKING(R.id.search_parking, R.drawable.ic_routing_parking_off, R.drawable.ic_routing_parking_on, "parking"),
|
||||
FOOD(R.id.search_food, R.drawable.ic_routing_food_off, R.drawable.ic_routing_food_on, "food"),
|
||||
SHOP(R.id.search_shop, R.drawable.ic_routing_shop_off, R.drawable.ic_routing_shop_on, "shop"),
|
||||
ATM(R.id.search_atm, R.drawable.ic_routing_atm_off, R.drawable.ic_routing_atm_on, "atm");
|
||||
|
||||
private int resId;
|
||||
private int drawableOff;
|
||||
private int drawableOn;
|
||||
private String searchQuery;
|
||||
|
||||
SearchOption(@IdRes int resId, @DrawableRes int drawableOff, @DrawableRes int drawableOn, String searchQuery)
|
||||
{
|
||||
this.resId = resId;
|
||||
this.drawableOff = drawableOff;
|
||||
this.drawableOn = drawableOn;
|
||||
this.searchQuery = searchQuery;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
public static SearchOption FromResId(@IdRes int resId)
|
||||
{
|
||||
for (SearchOption searchOption : SearchOption.values())
|
||||
{
|
||||
if (searchOption.resId == resId)
|
||||
return searchOption;
|
||||
}
|
||||
throw new IllegalArgumentException("No navigation search for id " + resId);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static SearchOption FromSearchQuery(@NonNull String query)
|
||||
{
|
||||
for (SearchOption searchOption : SearchOption.values())
|
||||
{
|
||||
if (searchOption.searchQuery.equals(query))
|
||||
return searchOption;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
private final SearchWheel mSearchWheel;
|
||||
|
||||
private boolean mShowTimeLeft = true;
|
||||
|
||||
|
@ -162,25 +106,13 @@ public class NavigationController implements View.OnClickListener
|
|||
mDistanceUnits = (TextView) mBottomFrame.findViewById(R.id.distance_dimen);
|
||||
mRouteProgress = (FlatProgressView) mBottomFrame.findViewById(R.id.navigation_progress);
|
||||
|
||||
// Search
|
||||
mSearchButton = (ImageView) mFrame.findViewById(R.id.btn_search);
|
||||
mSearchButton.setOnClickListener(this);
|
||||
mSearchLayout = mFrame.findViewById(R.id.search_frame);
|
||||
if (UiUtils.isLandscape(mFrame.getContext()))
|
||||
{
|
||||
UiUtils.waitLayout(mSearchLayout, new ViewTreeObserver.OnGlobalLayoutListener()
|
||||
{
|
||||
@Override
|
||||
public void onGlobalLayout()
|
||||
{
|
||||
mSearchLayout.setPivotX(0);
|
||||
mSearchLayout.setPivotX(mSearchLayout.getMeasuredHeight() / 2);
|
||||
}
|
||||
});
|
||||
}
|
||||
for (SearchOption searchOption : SearchOption.values())
|
||||
mFrame.findViewById(searchOption.resId).setOnClickListener(this);
|
||||
refreshSearchVisibility();
|
||||
mSearchWheel = new SearchWheel(mFrame);
|
||||
}
|
||||
|
||||
public void onResume()
|
||||
{
|
||||
mNavMenu.onResume(null);
|
||||
mSearchWheel.onResume();
|
||||
}
|
||||
|
||||
private NavMenu createNavMenu()
|
||||
|
@ -198,9 +130,7 @@ public class NavigationController implements View.OnClickListener
|
|||
Statistics.INSTANCE.trackEvent(Statistics.EventName.ROUTING_CLOSE);
|
||||
AlohaHelper.logClick(AlohaHelper.ROUTING_CLOSE);
|
||||
parent.refreshFade();
|
||||
SearchEngine.cancelSearch();
|
||||
mIsSearchExpanded = false;
|
||||
mCurrentSearch = null;
|
||||
mSearchWheel.reset();
|
||||
break;
|
||||
case SETTINGS:
|
||||
parent.closeMenu(Statistics.EventName.ROUTING_SETTINGS, AlohaHelper.MENU_SETTINGS, new Runnable()
|
||||
|
@ -351,108 +281,4 @@ public class NavigationController implements View.OnClickListener
|
|||
{
|
||||
return mNavMenu;
|
||||
}
|
||||
|
||||
private void toggleSearch()
|
||||
{
|
||||
final int animRes;
|
||||
if (mIsSearchExpanded)
|
||||
{
|
||||
animRes = R.animator.show_zoom_out_alpha;
|
||||
mIsSearchExpanded = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
animRes = R.animator.show_zoom_in_alpha;
|
||||
mIsSearchExpanded = true;
|
||||
UiUtils.show(mSearchLayout);
|
||||
}
|
||||
final Animator animator = AnimatorInflater.loadAnimator(mSearchLayout.getContext(), animRes);
|
||||
animator.setTarget(mSearchLayout);
|
||||
animator.start();
|
||||
animator.addListener(new UiUtils.SimpleAnimatorListener()
|
||||
{
|
||||
@Override
|
||||
public void onAnimationEnd(Animator animation)
|
||||
{
|
||||
refreshSearchVisibility();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void refreshSearchVisibility()
|
||||
{
|
||||
for (SearchOption searchOption : SearchOption.values())
|
||||
UiUtils.showIf(mIsSearchExpanded, mSearchLayout.findViewById(searchOption.resId));
|
||||
|
||||
UiUtils.showIf(mIsSearchExpanded, mSearchLayout);
|
||||
}
|
||||
|
||||
private void refreshWithSearchQuery(@NonNull String query)
|
||||
{
|
||||
if (query.isEmpty())
|
||||
return;
|
||||
|
||||
refreshSearchButtonImage(SearchOption.FromSearchQuery(query));
|
||||
}
|
||||
|
||||
private void refreshSearchButtonImage(@Nullable SearchOption searchOption)
|
||||
{
|
||||
if (searchOption == null)
|
||||
{
|
||||
mSearchButton.setImageDrawable(Graphics.tint(mSearchButton.getContext(),
|
||||
R.drawable.ic_menu_search));
|
||||
}
|
||||
else
|
||||
{
|
||||
mSearchButton.setImageDrawable(Graphics.tint(mSearchButton.getContext(),
|
||||
searchOption.drawableOff,
|
||||
R.attr.colorAccent));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClick(View v)
|
||||
{
|
||||
switch (v.getId())
|
||||
{
|
||||
case R.id.btn_search:
|
||||
if (mCurrentSearch != null)
|
||||
{
|
||||
mCurrentSearch = null;
|
||||
mSearchButton.setImageDrawable(Graphics.tint(mSearchButton.getContext(), R.drawable.ic_menu_search));
|
||||
SearchEngine.cancelSearch();
|
||||
mIsSearchExpanded = false;
|
||||
refreshSearchVisibility();
|
||||
return;
|
||||
}
|
||||
|
||||
if (mIsSearchExpanded)
|
||||
{
|
||||
showSearchInParent();
|
||||
return;
|
||||
}
|
||||
|
||||
toggleSearch();
|
||||
break;
|
||||
default:
|
||||
startSearch(SearchOption.FromResId(v.getId()));
|
||||
}
|
||||
}
|
||||
|
||||
private void showSearchInParent()
|
||||
{
|
||||
final MwmActivity parent = (MwmActivity) mFrame.getContext();
|
||||
parent.showSearch();
|
||||
mIsSearchExpanded = false;
|
||||
refreshSearchVisibility();
|
||||
}
|
||||
|
||||
private void startSearch(SearchOption searchOption)
|
||||
{
|
||||
mCurrentSearch = searchOption;
|
||||
SearchEngine.searchInteractive(searchOption.searchQuery, System.nanoTime(), false /* isMapAndTable */);
|
||||
refreshSearchButtonImage(searchOption);
|
||||
|
||||
toggleSearch();
|
||||
}
|
||||
}
|
||||
|
|
216
android/src/com/mapswithme/maps/routing/SearchWheel.java
Normal file
216
android/src/com/mapswithme/maps/routing/SearchWheel.java
Normal file
|
@ -0,0 +1,216 @@
|
|||
package com.mapswithme.maps.routing;
|
||||
|
||||
import android.animation.Animator;
|
||||
import android.animation.AnimatorInflater;
|
||||
import android.support.annotation.DrawableRes;
|
||||
import android.support.annotation.IdRes;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.text.TextUtils;
|
||||
import android.view.View;
|
||||
import android.view.ViewTreeObserver;
|
||||
import android.widget.ImageView;
|
||||
|
||||
import com.mapswithme.maps.MwmActivity;
|
||||
import com.mapswithme.maps.R;
|
||||
import com.mapswithme.maps.search.SearchEngine;
|
||||
import com.mapswithme.util.Graphics;
|
||||
import com.mapswithme.util.UiUtils;
|
||||
|
||||
class SearchWheel implements View.OnClickListener
|
||||
{
|
||||
private static String TAG = "TEST";
|
||||
private final View mFrame;
|
||||
|
||||
private final View mSearchLayout;
|
||||
private final ImageView mSearchButton;
|
||||
|
||||
private boolean mIsExpanded;
|
||||
private SearchOption mCurrentOption;
|
||||
|
||||
private enum SearchOption
|
||||
{
|
||||
FUEL(R.id.search_fuel, R.drawable.ic_routing_fuel_off, R.drawable.ic_routing_fuel_on, "fuel"),
|
||||
PARKING(R.id.search_parking, R.drawable.ic_routing_parking_off, R.drawable.ic_routing_parking_on, "parking"),
|
||||
FOOD(R.id.search_food, R.drawable.ic_routing_food_off, R.drawable.ic_routing_food_on, "food"),
|
||||
SHOP(R.id.search_shop, R.drawable.ic_routing_shop_off, R.drawable.ic_routing_shop_on, "shop"),
|
||||
ATM(R.id.search_atm, R.drawable.ic_routing_atm_off, R.drawable.ic_routing_atm_on, "atm");
|
||||
|
||||
private int resId;
|
||||
private int drawableOff;
|
||||
private int drawableOn;
|
||||
private String searchQuery;
|
||||
|
||||
SearchOption(@IdRes int resId, @DrawableRes int drawableOff, @DrawableRes int drawableOn, String searchQuery)
|
||||
{
|
||||
this.resId = resId;
|
||||
this.drawableOff = drawableOff;
|
||||
this.drawableOn = drawableOn;
|
||||
this.searchQuery = searchQuery;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
public static SearchOption FromResId(@IdRes int resId)
|
||||
{
|
||||
for (SearchOption searchOption : SearchOption.values())
|
||||
{
|
||||
if (searchOption.resId == resId)
|
||||
return searchOption;
|
||||
}
|
||||
throw new IllegalArgumentException("No navigation search for id " + resId);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static SearchOption FromSearchQuery(@NonNull String query)
|
||||
{
|
||||
final String normalizedQuery = query.trim().toLowerCase();
|
||||
for (SearchOption searchOption : SearchOption.values())
|
||||
{
|
||||
if (searchOption.searchQuery.equals(normalizedQuery))
|
||||
return searchOption;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
SearchWheel(View frame)
|
||||
{
|
||||
mFrame = frame;
|
||||
|
||||
// Search
|
||||
mSearchButton = (ImageView) mFrame.findViewById(R.id.btn_search);
|
||||
mSearchButton.setOnClickListener(this);
|
||||
mSearchLayout = mFrame.findViewById(R.id.search_frame);
|
||||
if (UiUtils.isLandscape(mFrame.getContext()))
|
||||
{
|
||||
UiUtils.waitLayout(mSearchLayout, new ViewTreeObserver.OnGlobalLayoutListener()
|
||||
{
|
||||
@Override
|
||||
public void onGlobalLayout()
|
||||
{
|
||||
mSearchLayout.setPivotX(0);
|
||||
mSearchLayout.setPivotY(mSearchLayout.getMeasuredHeight() / 2);
|
||||
}
|
||||
});
|
||||
}
|
||||
for (SearchOption searchOption : SearchOption.values())
|
||||
mFrame.findViewById(searchOption.resId).setOnClickListener(this);
|
||||
refreshSearchVisibility();
|
||||
}
|
||||
|
||||
public void reset()
|
||||
{
|
||||
mIsExpanded = false;
|
||||
mCurrentOption = null;
|
||||
SearchEngine.cancelSearch();
|
||||
}
|
||||
|
||||
public void onResume()
|
||||
{
|
||||
final String query = SearchEngine.getQuery();
|
||||
if (TextUtils.isEmpty(query))
|
||||
{
|
||||
resetSearchButtonImage();
|
||||
return;
|
||||
}
|
||||
|
||||
mCurrentOption = SearchOption.FromSearchQuery(query);
|
||||
refreshSearchButtonImage();
|
||||
}
|
||||
|
||||
private void toggleSearchLayout()
|
||||
{
|
||||
final int animRes;
|
||||
if (mIsExpanded)
|
||||
{
|
||||
animRes = R.animator.show_zoom_out_alpha;
|
||||
mIsExpanded = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
animRes = R.animator.show_zoom_in_alpha;
|
||||
mIsExpanded = true;
|
||||
UiUtils.show(mSearchLayout);
|
||||
}
|
||||
final Animator animator = AnimatorInflater.loadAnimator(mSearchLayout.getContext(), animRes);
|
||||
animator.setTarget(mSearchLayout);
|
||||
animator.start();
|
||||
animator.addListener(new UiUtils.SimpleAnimatorListener()
|
||||
{
|
||||
@Override
|
||||
public void onAnimationEnd(Animator animation)
|
||||
{
|
||||
refreshSearchVisibility();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void refreshSearchVisibility()
|
||||
{
|
||||
for (SearchOption searchOption : SearchOption.values())
|
||||
UiUtils.visibleIf(mIsExpanded, mSearchLayout.findViewById(searchOption.resId));
|
||||
|
||||
UiUtils.visibleIf(mIsExpanded, mSearchLayout);
|
||||
}
|
||||
|
||||
private void resetSearchButtonImage()
|
||||
{
|
||||
mSearchButton.setImageDrawable(Graphics.tint(mSearchButton.getContext(),
|
||||
R.drawable.ic_routing_search_on));
|
||||
}
|
||||
|
||||
private void refreshSearchButtonImage()
|
||||
{
|
||||
mSearchButton.setImageDrawable(Graphics.tint(mSearchButton.getContext(),
|
||||
mCurrentOption == null ?
|
||||
R.drawable.ic_routing_search_off :
|
||||
mCurrentOption.drawableOff,
|
||||
R.attr.colorAccent));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClick(View v)
|
||||
{
|
||||
switch (v.getId())
|
||||
{
|
||||
case R.id.btn_search:
|
||||
if (mCurrentOption != null || !TextUtils.isEmpty(SearchEngine.getQuery()))
|
||||
{
|
||||
SearchEngine.cancelSearch();
|
||||
mCurrentOption = null;
|
||||
mIsExpanded = false;
|
||||
resetSearchButtonImage();
|
||||
refreshSearchVisibility();
|
||||
return;
|
||||
}
|
||||
|
||||
if (mIsExpanded)
|
||||
{
|
||||
showSearchInParent();
|
||||
return;
|
||||
}
|
||||
|
||||
toggleSearchLayout();
|
||||
break;
|
||||
default:
|
||||
startSearch(SearchOption.FromResId(v.getId()));
|
||||
}
|
||||
}
|
||||
|
||||
private void showSearchInParent()
|
||||
{
|
||||
final MwmActivity parent = (MwmActivity) mFrame.getContext();
|
||||
parent.showSearch();
|
||||
mIsExpanded = false;
|
||||
refreshSearchVisibility();
|
||||
}
|
||||
|
||||
private void startSearch(SearchOption searchOption)
|
||||
{
|
||||
mCurrentOption = searchOption;
|
||||
SearchEngine.searchInteractive(searchOption.searchQuery, System.nanoTime(), false /* isMapAndTable */);
|
||||
refreshSearchButtonImage();
|
||||
|
||||
toggleSearchLayout();
|
||||
}
|
||||
}
|
Loading…
Add table
Reference in a new issue