use of net.osmand.plus.OsmandApplication in project Osmand by osmandapp.
the class AddQuickActionDialog method onCreateDialog.
@NonNull
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
OsmandApplication application = (OsmandApplication) getActivity().getApplication();
boolean light = application.getSettings().isLightContent() && !application.getDaynightHelper().isNightMode();
return new Dialog(new ContextThemeWrapper(getActivity(), light ? R.style.Dialog90Light : R.style.Dialog90Dark), getTheme());
}
use of net.osmand.plus.OsmandApplication in project Osmand by osmandapp.
the class EditPoiDialogFragment method showEditInstance.
public static void showEditInstance(final Amenity amenity, final AppCompatActivity activity) {
final OsmandSettings settings = ((OsmandApplication) activity.getApplication()).getSettings();
final OpenstreetmapUtil openstreetmapUtilToLoad;
OsmEditingPlugin plugin = OsmandPlugin.getPlugin(OsmEditingPlugin.class);
if (// settings.OFFLINE_EDITION.get() ||
!settings.isInternetConnectionAvailable(true)) {
openstreetmapUtilToLoad = plugin.getPoiModificationLocalUtil();
} else {
openstreetmapUtilToLoad = plugin.getPoiModificationRemoteUtil();
}
new AsyncTask<Void, Void, Node>() {
@Override
protected Node doInBackground(Void... params) {
return openstreetmapUtilToLoad.loadNode(amenity);
}
protected void onPostExecute(Node n) {
if (n != null) {
EditPoiDialogFragment fragment = EditPoiDialogFragment.createInstance(n, false);
fragment.show(activity.getSupportFragmentManager(), TAG);
} else {
Toast.makeText(activity, activity.getString(R.string.poi_error_poi_not_found), Toast.LENGTH_LONG).show();
}
}
}.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}
use of net.osmand.plus.OsmandApplication in project Osmand by osmandapp.
the class QuickActionsWidget method createPageView.
private View createPageView(ViewGroup container, int position) {
OsmandApplication application = ((OsmandApplication) getContext().getApplicationContext());
boolean light = application.getSettings().isLightContent() && !application.getDaynightHelper().isNightMode();
LayoutInflater li = getLayoutInflater(light ? R.style.OsmandLightTheme : R.style.OsmandDarkTheme);
View page = li.inflate(R.layout.quick_action_widget_page, container, false);
GridLayout gridLayout = (GridLayout) page.findViewById(R.id.grid);
final boolean land = !AndroidUiHelper.isOrientationPortrait((Activity) getContext());
final int maxItems = actions.size() == 1 ? 1 : ELEMENT_PER_PAGE;
for (int i = 0; i < maxItems; i++) {
View view = li.inflate(R.layout.quick_action_widget_item, gridLayout, false);
if (i + (position * ELEMENT_PER_PAGE) < actions.size()) {
final QuickAction action = QuickActionFactory.produceAction(actions.get(i + (position * ELEMENT_PER_PAGE)));
((ImageView) view.findViewById(imageView)).setImageResource(action.getIconRes(getContext()));
((TextView) view.findViewById(R.id.title)).setText(action.getActionText(application));
if (action.isActionWithSlash(application)) {
((ImageView) view.findViewById(R.id.imageSlash)).setImageResource(light ? R.drawable.ic_action_icon_hide_white : R.drawable.ic_action_icon_hide_dark);
}
view.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View view) {
if (selectionListener != null)
selectionListener.onActionSelected(action);
}
});
if (action.isActionEditable()) {
view.setOnLongClickListener(new OnLongClickListener() {
@Override
public boolean onLongClick(View v) {
CreateEditActionDialog dialog = CreateEditActionDialog.newInstance(action.id);
dialog.show(((AppCompatActivity) getContext()).getSupportFragmentManager(), AddQuickActionDialog.TAG);
return true;
}
});
}
if (!action.isActionEnable(application)) {
view.setEnabled(false);
view.setAlpha(0.5f);
}
}
if (land) {
view.findViewById(R.id.dividerBot).setVisibility(GONE);
view.findViewById(R.id.dividerRight).setVisibility(VISIBLE);
} else {
view.findViewById(R.id.dividerBot).setVisibility(i < ELEMENT_PER_PAGE / 2 ? VISIBLE : GONE);
view.findViewById(R.id.dividerRight).setVisibility(((i + 1) % 3) == 0 ? GONE : VISIBLE);
}
gridLayout.addView(view);
}
return gridLayout;
}
use of net.osmand.plus.OsmandApplication in project Osmand by osmandapp.
the class MapStyleAction method getOnAddBtnClickListener.
@Override
protected View.OnClickListener getOnAddBtnClickListener(final MapActivity activity, final Adapter adapter) {
return new View.OnClickListener() {
@Override
public void onClick(View view) {
AlertDialog.Builder bld = new AlertDialog.Builder(activity);
bld.setTitle(R.string.renderers);
final OsmandApplication app = activity.getMyApplication();
final List<String> visibleNamesList = new ArrayList<>();
final ArrayList<String> items = new ArrayList<>(app.getRendererRegistry().getRendererNames());
final boolean nauticalPluginDisabled = OsmandPlugin.getEnabledPlugin(NauticalMapsPlugin.class) == null;
Iterator<String> iterator = items.iterator();
while (iterator.hasNext()) {
String item = iterator.next();
if (nauticalPluginDisabled && item.equals(RendererRegistry.NAUTICAL_RENDER)) {
iterator.remove();
} else {
String translation = RendererRegistry.getTranslatedRendererName(activity, item);
visibleNamesList.add(translation != null ? translation : item.replace('_', ' ').replace('-', ' '));
}
}
final ArrayAdapter<String> arrayAdapter = new ArrayAdapter<>(activity, R.layout.dialog_text_item);
arrayAdapter.addAll(visibleNamesList);
bld.setAdapter(arrayAdapter, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
String renderer = items.get(i);
RenderingRulesStorage loaded = app.getRendererRegistry().getRenderer(renderer);
if (loaded != null) {
adapter.addItem(renderer, activity);
}
dialogInterface.dismiss();
}
});
bld.setNegativeButton(R.string.shared_string_dismiss, null);
bld.show();
}
};
}
use of net.osmand.plus.OsmandApplication in project Osmand by osmandapp.
the class MapMarkersListAdapter method reloadData.
public void reloadData() {
items.clear();
OsmandApplication app = mapActivity.getMyApplication();
myLoc = app.getLocationProvider().getLastStaleKnownLocation();
showLocationItem = myLoc != null;
inRoundTrip = app.getSettings().ROUTE_MAP_MARKERS_ROUND_TRIP.get();
if (showLocationItem) {
lookupLocationAddress(app);
items.add(myLoc);
}
items.addAll(mapActivity.getMyApplication().getMapMarkersHelper().getMapMarkers());
calculateStartAndFinishPos();
showRoundTripItem = inRoundTrip && !inDragAndDrop && startPos != -1;
if (showRoundTripItem) {
items.add(finishPos, items.get(startPos));
}
}
Aggregations