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);
}
}
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);
}
}
}
}
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);
}
}
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;
}
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);
}
}
}
}
}
}
}
Aggregations