Search in sources :

Example 81 with OsmandApplication

use of net.osmand.plus.OsmandApplication in project Osmand by osmandapp.

the class SelectCategoryDialogFragment method getIcon.

private static Drawable getIcon(final Activity activity, int resId, int color) {
    OsmandApplication app = (OsmandApplication) activity.getApplication();
    Drawable d = app.getResources().getDrawable(resId).mutate();
    d.clearColorFilter();
    d.setColorFilter(color, PorterDuff.Mode.SRC_IN);
    return d;
}
Also used : OsmandApplication(net.osmand.plus.OsmandApplication) Drawable(android.graphics.drawable.Drawable)

Example 82 with OsmandApplication

use of net.osmand.plus.OsmandApplication in project Osmand by osmandapp.

the class FavouritesAdapter method onBindViewHolder.

@Override
public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
    if (holder instanceof FavouritesViewHolder) {
        OsmandApplication app = (OsmandApplication) ((Activity) context).getApplication();
        IconsCache iconsCache = app.getIconsCache();
        FavouritesViewHolder favouritesViewHolder = (FavouritesViewHolder) holder;
        FavouritePoint favouritePoint = getItem(position);
        favouritesViewHolder.title.setText(favouritePoint.getName());
        if (favouritePoint.getCategory().equals("")) {
            favouritesViewHolder.description.setText(R.string.shared_string_favorites);
        } else {
            favouritesViewHolder.description.setText(favouritePoint.getCategory());
        }
        Location myloc = app.getLocationProvider().getLastKnownLocation();
        favouritesViewHolder.favouriteImage.setImageDrawable(FavoriteImageDrawable.getOrCreate(context, favouritePoint.getColor(), false));
        if (myloc == null) {
            return;
        }
        float dist = (float) MapUtils.getDistance(favouritePoint.getLatitude(), favouritePoint.getLongitude(), myloc.getLatitude(), myloc.getLongitude());
        favouritesViewHolder.distance.setText(OsmAndFormatter.getFormattedDistance(dist, app));
        favouritesViewHolder.arrowImage.setImageDrawable(iconsCache.getIcon(R.drawable.ic_direction_arrow));
        DashLocationFragment.updateLocationView(useCenter, location, heading, favouritesViewHolder.arrowImage, favouritesViewHolder.distance, favouritePoint.getLatitude(), favouritePoint.getLongitude(), screenOrientation, app, context);
    }
}
Also used : OsmandApplication(net.osmand.plus.OsmandApplication) FavouritePoint(net.osmand.data.FavouritePoint) IconsCache(net.osmand.plus.IconsCache) Location(net.osmand.Location)

Example 83 with OsmandApplication

use of net.osmand.plus.OsmandApplication in project Osmand by osmandapp.

the class PointDescription method getLocationNamePlain.

public static String getLocationNamePlain(Context ctx, double lat, double lon) {
    OsmandSettings st = ((OsmandApplication) ctx.getApplicationContext()).getSettings();
    int f = st.COORDINATES_FORMAT.get();
    if (f == PointDescription.UTM_FORMAT) {
        UTMPoint pnt = new UTMPoint(new LatLonPoint(lat, lon));
        return pnt.zone_number + "" + pnt.zone_letter + " " + ((long) pnt.easting) + " " + ((long) pnt.northing);
    } else if (f == PointDescription.OLC_FORMAT) {
        try {
            return getLocationOlcName(lat, lon);
        } catch (RuntimeException e) {
            e.printStackTrace();
            return "0, 0";
        }
    } else {
        try {
            return LocationConvert.convert(lat, f) + ", " + LocationConvert.convert(lon, f);
        } catch (RuntimeException e) {
            e.printStackTrace();
            return "0, 0";
        }
    }
}
Also used : OsmandApplication(net.osmand.plus.OsmandApplication) LatLonPoint(com.jwetherell.openmap.common.LatLonPoint) UTMPoint(com.jwetherell.openmap.common.UTMPoint) OsmandSettings(net.osmand.plus.OsmandSettings) LatLonPoint(com.jwetherell.openmap.common.LatLonPoint) UTMPoint(com.jwetherell.openmap.common.UTMPoint)

Example 84 with OsmandApplication

use of net.osmand.plus.OsmandApplication in project Osmand by osmandapp.

the class PointDescription method getLocationName.

public static String getLocationName(Context ctx, double lat, double lon, boolean sh) {
    OsmandSettings st = ((OsmandApplication) ctx.getApplicationContext()).getSettings();
    int f = st.COORDINATES_FORMAT.get();
    if (f == PointDescription.UTM_FORMAT) {
        UTMPoint pnt = new UTMPoint(new LatLonPoint(lat, lon));
        return pnt.zone_number + "" + pnt.zone_letter + " " + ((long) pnt.easting) + " " + ((long) pnt.northing);
    } else if (f == PointDescription.OLC_FORMAT) {
        try {
            return getLocationOlcName(lat, lon);
        } catch (RuntimeException e) {
            e.printStackTrace();
            return "0, 0";
        }
    } else {
        try {
            return ctx.getString(sh ? R.string.short_location_on_map : R.string.location_on_map, LocationConvert.convert(lat, f), LocationConvert.convert(lon, f));
        } catch (RuntimeException e) {
            e.printStackTrace();
            return ctx.getString(sh ? R.string.short_location_on_map : R.string.location_on_map, 0, 0);
        }
    }
}
Also used : OsmandApplication(net.osmand.plus.OsmandApplication) LatLonPoint(com.jwetherell.openmap.common.LatLonPoint) UTMPoint(com.jwetherell.openmap.common.UTMPoint) OsmandSettings(net.osmand.plus.OsmandSettings) LatLonPoint(com.jwetherell.openmap.common.LatLonPoint) UTMPoint(com.jwetherell.openmap.common.UTMPoint)

Example 85 with OsmandApplication

use of net.osmand.plus.OsmandApplication in project Osmand by osmandapp.

the class DashTrackFragment method setupGpxFiles.

private void setupGpxFiles() {
    View mainView = getView();
    final File dir = getMyApplication().getAppPath(IndexConstants.GPX_INDEX_DIR);
    final OsmandApplication app = getMyApplication();
    if (app == null) {
        return;
    }
    final List<String> list = new ArrayList<String>();
    for (SelectedGpxFile sg : app.getSelectedGpxHelper().getSelectedGPXFiles()) {
        if (!sg.isShowCurrentTrack()) {
            GPXFile gpxFile = sg.getGpxFile();
            if (gpxFile != null) {
                list.add(gpxFile.path);
            }
        }
    }
    int totalCount = 3 + list.size() / 2;
    if (app.getSettings().SAVE_GLOBAL_TRACK_TO_GPX.get()) {
        totalCount--;
    }
    if (list.size() < totalCount) {
        final List<GPXInfo> res = GpxUiHelper.getSortedGPXFilesInfoByDate(dir, true);
        for (GPXInfo r : res) {
            String name = r.getFileName();
            if (!list.contains(name)) {
                list.add(name);
                if (list.size() >= totalCount) {
                    break;
                }
            }
        }
    }
    if (list.size() == 0 && OsmandPlugin.getEnabledPlugin(OsmandMonitoringPlugin.class) == null) {
        (mainView.findViewById(R.id.main_fav)).setVisibility(View.GONE);
        return;
    } else {
        (mainView.findViewById(R.id.main_fav)).setVisibility(View.VISIBLE);
        DashboardOnMap.handleNumberOfRows(list, getMyApplication().getSettings(), ROW_NUMBER_TAG);
    }
    LinearLayout tracks = (LinearLayout) mainView.findViewById(R.id.items);
    tracks.removeAllViews();
    LayoutInflater inflater = getActivity().getLayoutInflater();
    if (OsmandPlugin.getEnabledPlugin(OsmandMonitoringPlugin.class) != null) {
        View view = inflater.inflate(R.layout.dash_gpx_track_item, null, false);
        createCurrentTrackView(view, app);
        ((TextView) view.findViewById(R.id.name)).setText(R.string.shared_string_currently_recording_track);
        updateCurrentTrack(view, getActivity(), app);
        view.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                AvailableGPXFragment.openTrack(getActivity(), null);
            }
        });
        view.findViewById(R.id.divider_dash).setVisibility(View.VISIBLE);
        tracks.addView(view);
        startHandler(view);
    }
    for (String filename : list) {
        final File f = new File(filename);
        AvailableGPXFragment.GpxInfo info = new AvailableGPXFragment.GpxInfo();
        info.subfolder = "";
        info.file = f;
        View v = inflater.inflate(R.layout.dash_gpx_track_item, null, false);
        AvailableGPXFragment.updateGpxInfoView(v, info, app, true);
        v.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                AvailableGPXFragment.openTrack(getActivity(), f);
            }
        });
        ImageButton showOnMap = ((ImageButton) v.findViewById(R.id.show_on_map));
        showOnMap.setVisibility(View.VISIBLE);
        showOnMap.setContentDescription(getString(R.string.shared_string_show_on_map));
        updateShowOnMap(app, f, v, showOnMap);
        tracks.addView(v);
    }
}
Also used : OsmandApplication(net.osmand.plus.OsmandApplication) GPXInfo(net.osmand.plus.helpers.GpxUiHelper.GPXInfo) ArrayList(java.util.ArrayList) ImageView(android.widget.ImageView) View(android.view.View) TextView(android.widget.TextView) ImageButton(android.widget.ImageButton) SelectedGpxFile(net.osmand.plus.GpxSelectionHelper.SelectedGpxFile) LayoutInflater(android.view.LayoutInflater) TextView(android.widget.TextView) GPXFile(net.osmand.plus.GPXUtilities.GPXFile) SelectedGpxFile(net.osmand.plus.GpxSelectionHelper.SelectedGpxFile) GPXFile(net.osmand.plus.GPXUtilities.GPXFile) File(java.io.File) LinearLayout(android.widget.LinearLayout) AvailableGPXFragment(net.osmand.plus.myplaces.AvailableGPXFragment)

Aggregations

OsmandApplication (net.osmand.plus.OsmandApplication)181 View (android.view.View)46 TextView (android.widget.TextView)39 ArrayList (java.util.ArrayList)33 AlertDialog (android.support.v7.app.AlertDialog)32 ImageView (android.widget.ImageView)31 DialogInterface (android.content.DialogInterface)27 OsmandSettings (net.osmand.plus.OsmandSettings)27 LatLon (net.osmand.data.LatLon)25 Intent (android.content.Intent)21 AdapterView (android.widget.AdapterView)19 File (java.io.File)17 OsmandMapTileView (net.osmand.plus.views.OsmandMapTileView)15 Location (net.osmand.Location)13 EditText (android.widget.EditText)12 ContextMenuAdapter (net.osmand.plus.ContextMenuAdapter)12 ArrayAdapter (android.widget.ArrayAdapter)11 ListView (android.widget.ListView)11 ContextMenuItem (net.osmand.plus.ContextMenuItem)11 SelectedGpxFile (net.osmand.plus.GpxSelectionHelper.SelectedGpxFile)11