Search in sources :

Example 6 with HistoryEntry

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());
}
Also used : FragmentActivity(android.support.v4.app.FragmentActivity) LatLon(net.osmand.data.LatLon) OsmandApplication(net.osmand.plus.OsmandApplication) HistoryEntry(net.osmand.plus.helpers.SearchHistoryHelper.HistoryEntry) Intent(android.content.Intent)

Example 7 with HistoryEntry

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;
            }
        }
    }
}
Also used : FragmentActivity(android.support.v4.app.FragmentActivity) LatLon(net.osmand.data.LatLon) HistoryEntry(net.osmand.plus.helpers.SearchHistoryHelper.HistoryEntry) ImageView(android.widget.ImageView) View(android.view.View) AdapterView(android.widget.AdapterView) TextView(android.widget.TextView) ListView(android.widget.ListView)

Example 8 with HistoryEntry

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;
}
Also used : Amenity(net.osmand.data.Amenity) WptPt(net.osmand.plus.GPXUtilities.WptPt) FavouritePoint(net.osmand.data.FavouritePoint) FavoriteGroup(net.osmand.plus.FavouritesDbHelper.FavoriteGroup) Drawable(android.graphics.drawable.Drawable) FavoriteImageDrawable(net.osmand.plus.base.FavoriteImageDrawable) HistoryEntry(net.osmand.plus.helpers.SearchHistoryHelper.HistoryEntry) CustomSearchPoiFilter(net.osmand.search.core.CustomSearchPoiFilter) AbstractPoiType(net.osmand.osm.AbstractPoiType) FavouritePoint(net.osmand.data.FavouritePoint)

Example 9 with HistoryEntry

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;
}
Also used : LatLon(net.osmand.data.LatLon) PointDescription(net.osmand.data.PointDescription) HistoryEntry(net.osmand.plus.helpers.SearchHistoryHelper.HistoryEntry) FavouritePoint(net.osmand.data.FavouritePoint)

Example 10 with HistoryEntry

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;
}
Also used : HistoryEntry(net.osmand.plus.helpers.SearchHistoryHelper.HistoryEntry)

Aggregations

HistoryEntry (net.osmand.plus.helpers.SearchHistoryHelper.HistoryEntry)11 LatLon (net.osmand.data.LatLon)7 FavouritePoint (net.osmand.data.FavouritePoint)5 View (android.view.View)3 ImageView (android.widget.ImageView)3 TextView (android.widget.TextView)3 ArrayList (java.util.ArrayList)3 Amenity (net.osmand.data.Amenity)3 PointDescription (net.osmand.data.PointDescription)3 AbstractPoiType (net.osmand.osm.AbstractPoiType)3 Intent (android.content.Intent)2 FragmentActivity (android.support.v4.app.FragmentActivity)2 AdapterView (android.widget.AdapterView)2 ListView (android.widget.ListView)2 File (java.io.File)2 List (java.util.List)2 City (net.osmand.data.City)2 Street (net.osmand.data.Street)2 GPXFile (net.osmand.plus.GPXUtilities.GPXFile)2 WptPt (net.osmand.plus.GPXUtilities.WptPt)2