use of net.osmand.plus.helpers.SearchHistoryHelper.HistoryEntry in project Osmand by osmandapp.
the class SearchHistoryFragment method onResume.
@Override
public void onResume() {
super.onResume();
// Hardy: onResume() code is needed so that search origin is properly reflected in tab contents when origin has been changed on one tab, then tab is changed to another one.
location = null;
FragmentActivity activity = getActivity();
Intent intent = activity.getIntent();
if (intent != null) {
double lat = intent.getDoubleExtra(SEARCH_LAT, 0);
double lon = intent.getDoubleExtra(SEARCH_LON, 0);
if (lat != 0 || lon != 0) {
historyAdapter.location = new LatLon(lat, lon);
}
}
if (location == null && activity instanceof SearchActivity) {
location = ((SearchActivity) activity).getSearchPoint();
}
if (location == null) {
location = ((OsmandApplication) activity.getApplication()).getSettings().getLastKnownMapLocation();
}
historyAdapter.clear();
for (HistoryEntry entry : helper.getHistoryEntries()) {
historyAdapter.add(entry);
}
locationUpdate(location);
clearButton.setVisibility(historyAdapter.isEmpty() ? View.GONE : View.VISIBLE);
screenOrientation = DashLocationFragment.getScreenOrientation(getActivity());
}
use of net.osmand.plus.helpers.SearchHistoryHelper.HistoryEntry in project Osmand by osmandapp.
the class SearchHistoryFragment method updateCompassValue.
@Override
public void updateCompassValue(float value) {
// 99 in next line used to one-time initalize arrows (with reference vs. fixed-north direction) on non-compass
// devices
FragmentActivity activity = getActivity();
float lastHeading = heading != null ? heading : 99;
heading = value;
if (heading != null && Math.abs(MapUtils.degreesDiff(lastHeading, heading)) > 5) {
if (activity instanceof SearchActivity) {
((SearchActivity) activity).getAccessibilityAssistant().lockEvents();
historyAdapter.notifyDataSetChanged();
((SearchActivity) activity).getAccessibilityAssistant().unlockEvents();
} else {
historyAdapter.notifyDataSetChanged();
}
} else {
heading = lastHeading;
}
if (activity instanceof SearchActivity) {
final View selected = ((SearchActivity) activity).getAccessibilityAssistant().getFocusedView();
if (selected != null) {
try {
int position = getListView().getPositionForView(selected);
if ((position != AdapterView.INVALID_POSITION) && (position >= getListView().getHeaderViewsCount())) {
HistoryEntry historyEntry = historyAdapter.getItem(position - getListView().getHeaderViewsCount());
LatLon location = new LatLon(historyEntry.getLat(), historyEntry.getLon());
((SearchActivity) activity).getNavigationInfo().updateTargetDirection(location, heading.floatValue());
}
} catch (Exception e) {
return;
}
}
}
}
use of net.osmand.plus.helpers.SearchHistoryHelper.HistoryEntry in project Osmand by osmandapp.
the class QuickSearchListItem method getIcon.
public static Drawable getIcon(OsmandApplication app, SearchResult searchResult) {
if (searchResult == null || searchResult.objectType == null) {
return null;
}
int iconId = -1;
switch(searchResult.objectType) {
case CITY:
return getIcon(app, R.drawable.ic_action_building_number);
case VILLAGE:
return getIcon(app, R.drawable.ic_action_home_dark);
case POSTCODE:
case STREET:
return getIcon(app, R.drawable.ic_action_street_name);
case HOUSE:
return getIcon(app, R.drawable.ic_action_building);
case STREET_INTERSECTION:
return getIcon(app, R.drawable.ic_action_intersection);
case POI_TYPE:
if (searchResult.object instanceof AbstractPoiType) {
String iconName = getPoiTypeIconName((AbstractPoiType) searchResult.object);
if (!Algorithms.isEmpty(iconName)) {
iconId = RenderingIcons.getBigIconResourceId(iconName);
}
} else if (searchResult.object instanceof CustomSearchPoiFilter) {
Object res = ((CustomSearchPoiFilter) searchResult.object).getIconResource();
if (res instanceof String && RenderingIcons.containsBigIcon(res.toString())) {
iconId = RenderingIcons.getBigIconResourceId(res.toString());
} else {
iconId = R.drawable.mx_user_defined;
}
}
if (iconId > 0) {
return getIcon(app, iconId);
} else {
return getIcon(app, R.drawable.ic_action_search_dark);
}
case POI:
Amenity amenity = (Amenity) searchResult.object;
String id = getAmenityIconName(app, amenity);
Drawable icon = null;
if (id != null) {
iconId = RenderingIcons.getBigIconResourceId(id);
if (iconId > 0) {
icon = getIcon(app, iconId);
}
}
if (icon == null) {
return getIcon(app, R.drawable.ic_action_search_dark);
} else {
return icon;
}
case LOCATION:
return getIcon(app, R.drawable.ic_action_world_globe);
case FAVORITE:
FavouritePoint fav = (FavouritePoint) searchResult.object;
return FavoriteImageDrawable.getOrCreate(app, fav.getColor(), false);
case FAVORITE_GROUP:
FavoriteGroup group = (FavoriteGroup) searchResult.object;
int color = group.color == 0 || group.color == Color.BLACK ? app.getResources().getColor(R.color.color_favorite) : group.color;
return app.getIconsCache().getPaintedIcon(R.drawable.ic_action_fav_dark, color | 0xff000000);
case REGION:
return getIcon(app, R.drawable.ic_world_globe_dark);
case RECENT_OBJ:
HistoryEntry entry = (HistoryEntry) searchResult.object;
if (entry.getName() != null && !Algorithms.isEmpty(entry.getName().getIconName())) {
String iconName = entry.getName().getIconName();
if (RenderingIcons.containsBigIcon(iconName)) {
iconId = RenderingIcons.getBigIconResourceId(iconName);
} else {
iconId = app.getResources().getIdentifier(iconName, "drawable", app.getPackageName());
}
}
if (iconId <= 0) {
iconId = SearchHistoryFragment.getItemIcon(entry.getName());
}
try {
return getIcon(app, iconId);
} catch (Exception e) {
return getIcon(app, SearchHistoryFragment.getItemIcon(entry.getName()));
}
case WPT:
WptPt wpt = (WptPt) searchResult.object;
return FavoriteImageDrawable.getOrCreate(app, wpt.getColor(), false);
case UNKNOWN_NAME_FILTER:
break;
}
return null;
}
use of net.osmand.plus.helpers.SearchHistoryHelper.HistoryEntry in project Osmand by osmandapp.
the class QuickSearchListItem method getName.
public static String getName(OsmandApplication app, SearchResult searchResult) {
switch(searchResult.objectType) {
case STREET:
if (searchResult.localeName.endsWith(")")) {
int i = searchResult.localeName.indexOf('(');
if (i > 0) {
return searchResult.localeName.substring(0, i).trim();
}
}
break;
case STREET_INTERSECTION:
if (!Algorithms.isEmpty(searchResult.localeRelatedObjectName)) {
return searchResult.localeName + " - " + searchResult.localeRelatedObjectName;
}
break;
case RECENT_OBJ:
HistoryEntry historyEntry = (HistoryEntry) searchResult.object;
PointDescription pd = historyEntry.getName();
return pd.getSimpleName(app, false);
case LOCATION:
LatLon latLon = searchResult.location;
return PointDescription.getLocationNamePlain(app, latLon.getLatitude(), latLon.getLongitude());
}
return searchResult.localeName;
}
use of net.osmand.plus.helpers.SearchHistoryHelper.HistoryEntry in project Osmand by osmandapp.
the class QuickSearchListItem method getTypeIcon.
public static Drawable getTypeIcon(OsmandApplication app, SearchResult searchResult) {
switch(searchResult.objectType) {
case FAVORITE:
case FAVORITE_GROUP:
return app.getIconsCache().getThemedIcon(R.drawable.ic_small_group);
case RECENT_OBJ:
HistoryEntry historyEntry = (HistoryEntry) searchResult.object;
String typeName = historyEntry.getName().getTypeName();
if (typeName != null && !typeName.isEmpty()) {
return app.getIconsCache().getThemedIcon(R.drawable.ic_small_group);
} else {
return null;
}
}
return null;
}
Aggregations