Search in sources :

Example 41 with OsmandApplication

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

the class EditFavoriteGroupDialogFragment method createMenuItems.

@Override
public void createMenuItems(Bundle savedInstanceState) {
    final OsmandApplication app = getMyApplication();
    FavouritesDbHelper helper = app.getFavorites();
    Bundle args = getArguments();
    if (args != null) {
        String groupName = args.getString(GROUP_NAME_KEY);
        if (groupName != null) {
            group = helper.getGroup(groupName);
        }
    }
    if (group == null) {
        return;
    }
    items.add(new TitleItem(Algorithms.isEmpty(group.name) ? app.getString(R.string.shared_string_favorites) : group.name));
    BaseBottomSheetItem editNameItem = new SimpleBottomSheetItem.Builder().setIcon(getContentIcon(R.drawable.ic_action_edit_dark)).setTitle(getString(R.string.edit_name)).setLayoutId(R.layout.bottom_sheet_item_simple).setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            AlertDialog.Builder b = new AlertDialog.Builder(getContext());
            b.setTitle(R.string.favorite_group_name);
            final EditText nameEditText = new EditText(getContext());
            nameEditText.setText(group.name);
            b.setView(nameEditText);
            b.setNegativeButton(R.string.shared_string_cancel, null);
            b.setPositiveButton(R.string.shared_string_save, new DialogInterface.OnClickListener() {

                @Override
                public void onClick(DialogInterface dialog, int which) {
                    String name = nameEditText.getText().toString();
                    boolean nameChanged = !Algorithms.objectEquals(group.name, name);
                    if (nameChanged) {
                        app.getFavorites().editFavouriteGroup(group, name, group.color, group.visible);
                        updateParentFragment();
                    }
                    dismiss();
                }
            });
            b.show();
        }
    }).create();
    items.add(editNameItem);
    final int themeRes = nightMode ? R.style.OsmandDarkTheme : R.style.OsmandLightTheme;
    final View changeColorView = View.inflate(new ContextThemeWrapper(getContext(), themeRes), R.layout.change_fav_color, null);
    ((ImageView) changeColorView.findViewById(R.id.change_color_icon)).setImageDrawable(getContentIcon(R.drawable.ic_action_appearance));
    updateColorView((ImageView) changeColorView.findViewById(R.id.colorImage));
    BaseBottomSheetItem changeColorItem = new BaseBottomSheetItem.Builder().setCustomView(changeColorView).setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            final ListPopupWindow popup = new ListPopupWindow(getActivity());
            popup.setAnchorView(changeColorView);
            popup.setContentWidth(AndroidUtils.dpToPx(app, 200f));
            popup.setModal(true);
            popup.setDropDownGravity(Gravity.END | Gravity.TOP);
            if (AndroidUiHelper.isOrientationPortrait(getActivity())) {
                popup.setVerticalOffset(AndroidUtils.dpToPx(app, 48f));
            } else {
                popup.setVerticalOffset(AndroidUtils.dpToPx(app, -48f));
            }
            popup.setHorizontalOffset(AndroidUtils.dpToPx(app, -6f));
            final FavoriteColorAdapter colorAdapter = new FavoriteColorAdapter(getActivity());
            popup.setAdapter(colorAdapter);
            popup.setOnItemClickListener(new AdapterView.OnItemClickListener() {

                @Override
                public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                    Integer color = colorAdapter.getItem(position);
                    if (color != null) {
                        if (color != group.color) {
                            app.getFavorites().editFavouriteGroup(group, group.name, color, group.visible);
                            updateParentFragment();
                        }
                    }
                    popup.dismiss();
                    dismiss();
                }
            });
            popup.show();
        }
    }).create();
    items.add(changeColorItem);
    BaseBottomSheetItem showOnMapItem = new BottomSheetItemWithCompoundButton.Builder().setChecked(group.visible).setIcon(getContentIcon(R.drawable.ic_map)).setTitle(getString(R.string.shared_string_show_on_map)).setLayoutId(R.layout.bottom_sheet_item_with_switch).setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            boolean visible = !group.visible;
            app.getFavorites().editFavouriteGroup(group, group.name, group.color, visible);
            updateParentFragment();
            dismiss();
        }
    }).create();
    items.add(showOnMapItem);
    if (group.points.size() > 0) {
        items.add(new DividerHalfItem(getContext()));
        final MapMarkersHelper markersHelper = app.getMapMarkersHelper();
        final MapMarkersGroup markersGr = markersHelper.getOrCreateGroup(this.group);
        final boolean synced = markersHelper.isGroupSynced(markersGr.getId());
        BaseBottomSheetItem markersGroupItem = new SimpleBottomSheetItem.Builder().setIcon(getContentIcon(synced ? R.drawable.ic_action_delete_dark : R.drawable.ic_action_flag_dark)).setTitle(getString(synced ? R.string.remove_from_map_markers : R.string.shared_string_add_to_map_markers)).setLayoutId(R.layout.bottom_sheet_item_simple).setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View view) {
                if (synced) {
                    markersHelper.removeMarkersGroup(markersGr);
                } else {
                    markersHelper.addOrEnableGroup(markersGr);
                }
                dismiss();
                MapActivity.launchMapActivityMoveToTop(getActivity());
            }
        }).create();
        items.add(markersGroupItem);
        BaseBottomSheetItem shareItem = new SimpleBottomSheetItem.Builder().setIcon(getContentIcon(R.drawable.ic_action_gshare_dark)).setTitle(getString(R.string.shared_string_share)).setLayoutId(R.layout.bottom_sheet_item_simple).setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View view) {
                FavoritesTreeFragment fragment = getFavoritesTreeFragment();
                if (fragment != null) {
                    fragment.shareFavorites(EditFavoriteGroupDialogFragment.this.group);
                }
                dismiss();
            }
        }).create();
        items.add(shareItem);
    }
}
Also used : BaseBottomSheetItem(net.osmand.plus.base.bottomsheetmenu.BaseBottomSheetItem) AlertDialog(android.support.v7.app.AlertDialog) SimpleBottomSheetItem(net.osmand.plus.base.bottomsheetmenu.SimpleBottomSheetItem) OsmandApplication(net.osmand.plus.OsmandApplication) DialogInterface(android.content.DialogInterface) TitleItem(net.osmand.plus.base.bottomsheetmenu.simpleitems.TitleItem) ListPopupWindow(android.support.v7.widget.ListPopupWindow) DividerHalfItem(net.osmand.plus.base.bottomsheetmenu.simpleitems.DividerHalfItem) MapMarkersGroup(net.osmand.plus.MapMarkersHelper.MapMarkersGroup) ImageView(android.widget.ImageView) EditText(android.widget.EditText) Bundle(android.os.Bundle) FavouritesDbHelper(net.osmand.plus.FavouritesDbHelper) ImageView(android.widget.ImageView) View(android.view.View) AdapterView(android.widget.AdapterView) TextView(android.widget.TextView) ContextThemeWrapper(android.view.ContextThemeWrapper) MapMarkersHelper(net.osmand.plus.MapMarkersHelper) AdapterView(android.widget.AdapterView)

Example 42 with OsmandApplication

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

the class FavoritesListFragment method onAttach.

@Override
public void onAttach(Activity activity) {
    super.onAttach(activity);
    Intent intent = activity.getIntent();
    settings = getApplication().getSettings();
    OsmandApplication app = getApplication();
    favouritesAdapter = new FavouritesAdapter(activity, app.getFavorites().getFavouritePoints(), false);
    setListAdapter(favouritesAdapter);
    setHasOptionsMenu(true);
    if (intent != null) {
        selectFavoriteMode = intent.hasExtra(SELECT_FAVORITE_POINT_INTENT_KEY);
        if (intent.hasExtra(SearchActivity.SEARCH_LAT) && intent.hasExtra(SearchActivity.SEARCH_LON)) {
            double lat = intent.getDoubleExtra(SearchActivity.SEARCH_LAT, 0);
            double lon = intent.getDoubleExtra(SearchActivity.SEARCH_LON, 0);
            if (lat != 0 || lon != 0) {
                favouritesAdapter.location = new LatLon(lat, lon);
            }
        }
    }
}
Also used : LatLon(net.osmand.data.LatLon) OsmandApplication(net.osmand.plus.OsmandApplication) Intent(android.content.Intent)

Example 43 with OsmandApplication

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

the class FavoritesListFragment method locationUpdate.

@Override
public void locationUpdate(LatLon l) {
    if (getActivity() instanceof SearchActivity) {
        if (((SearchActivity) getActivity()).isSearchAroundCurrentLocation() && l != null) {
            if (!compassRegistered) {
                OsmandApplication app = getMyApplication();
                app.getLocationProvider().removeCompassListener(app.getLocationProvider().getNavigationInfo());
                app.getLocationProvider().addCompassListener(this);
                compassRegistered = true;
            }
            favouritesAdapter.searchAroundLocation = true;
        } else {
            favouritesAdapter.searchAroundLocation = false;
        }
    }
    if (favouritesAdapter != null) {
        favouritesAdapter.updateLocation(l);
    }
}
Also used : OsmandApplication(net.osmand.plus.OsmandApplication) SearchActivity(net.osmand.plus.activities.search.SearchActivity)

Example 44 with OsmandApplication

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

the class MapInfoWidgetsFactory method createGPSInfoControl.

public TextInfoWidget createGPSInfoControl(final MapActivity map) {
    final OsmandApplication app = map.getMyApplication();
    final OsmAndLocationProvider loc = app.getLocationProvider();
    final TextInfoWidget gpsInfoControl = new TextInfoWidget(map) {

        private int u = -1;

        private int f = -1;

        @Override
        public boolean updateInfo(DrawSettings d) {
            GPSInfo gpsInfo = loc.getGPSInfo();
            if (gpsInfo.usedSatellites != u || gpsInfo.foundSatellites != f) {
                u = gpsInfo.usedSatellites;
                f = gpsInfo.foundSatellites;
                setText(gpsInfo.usedSatellites + "/" + gpsInfo.foundSatellites, "");
                return true;
            }
            return false;
        }
    };
    gpsInfoControl.setIcons(R.drawable.widget_gps_info_day, R.drawable.widget_gps_info_night);
    gpsInfoControl.setText(null, null);
    gpsInfoControl.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View view) {
            new StartGPSStatus(map).run();
        }
    });
    return gpsInfoControl;
}
Also used : OsmAndLocationProvider(net.osmand.plus.OsmAndLocationProvider) OsmandApplication(net.osmand.plus.OsmandApplication) OnClickListener(android.view.View.OnClickListener) GPSInfo(net.osmand.plus.OsmAndLocationProvider.GPSInfo) StartGPSStatus(net.osmand.plus.activities.actions.StartGPSStatus) OsmandMapTileView(net.osmand.plus.views.OsmandMapTileView) ImageView(android.widget.ImageView) View(android.view.View) TextView(android.widget.TextView) DrawSettings(net.osmand.plus.views.OsmandMapLayer.DrawSettings)

Example 45 with OsmandApplication

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

the class MapMarkersLayer method collectObjectsFromPoint.

@Override
public void collectObjectsFromPoint(PointF point, RotatedTileBox tileBox, List<Object> o, boolean unknownLocation) {
    if (tileBox.getZoom() < 3) {
        return;
    }
    amenities.clear();
    OsmandApplication app = map.getMyApplication();
    int r = getDefaultRadiusPoi(tileBox);
    boolean selectMarkerOnSingleTap = app.getSettings().SELECT_MARKER_ON_SINGLE_TAP.get();
    for (MapMarker marker : app.getMapMarkersHelper().getMapMarkers()) {
        if ((!unknownLocation && selectMarkerOnSingleTap) || !isSynced(marker)) {
            LatLon latLon = marker.point;
            if (latLon != null) {
                int x = (int) tileBox.getPixXFromLatLon(latLon.getLatitude(), latLon.getLongitude());
                int y = (int) tileBox.getPixYFromLatLon(latLon.getLatitude(), latLon.getLongitude());
                if (calculateBelongs((int) point.x, (int) point.y, x, y, r)) {
                    if (!unknownLocation && selectMarkerOnSingleTap) {
                        o.add(marker);
                    } else {
                        if (isMarkerOnFavorite(marker) || isMarkerOnWaypoint(marker)) {
                            continue;
                        }
                        Amenity mapObj = getMapObjectByMarker(marker);
                        if (mapObj != null) {
                            amenities.add(mapObj);
                            o.add(mapObj);
                        } else {
                            o.add(marker);
                        }
                    }
                }
            }
        }
    }
}
Also used : LatLon(net.osmand.data.LatLon) Amenity(net.osmand.data.Amenity) OsmandApplication(net.osmand.plus.OsmandApplication) MapMarker(net.osmand.plus.MapMarkersHelper.MapMarker) TargetPoint(net.osmand.plus.TargetPointsHelper.TargetPoint) QuadPoint(net.osmand.data.QuadPoint) Paint(android.graphics.Paint)

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