use of net.osmand.plus.ApplicationMode in project Osmand by osmandapp.
the class PlanRouteFragment method updateText.
private void updateText() {
MapActivity mapActivity = getMapActivity();
if (mapActivity != null) {
TextView distanceTv = (TextView) mainView.findViewById(R.id.markers_distance_text_view);
TextView timeTv = (TextView) mainView.findViewById(R.id.markers_time_text_view);
TextView countTv = (TextView) mainView.findViewById(R.id.markers_count_text_view);
ApplicationMode appMode = planRouteContext.getSnappedMode();
TrkSegment snapTrkSegment = planRouteContext.getSnapTrkSegment();
boolean defaultMode = appMode == ApplicationMode.DEFAULT;
float dist = 0;
for (int i = 1; i < snapTrkSegment.points.size(); i++) {
WptPt pt1 = snapTrkSegment.points.get(i - 1);
WptPt pt2 = snapTrkSegment.points.get(i);
dist += MapUtils.getDistance(pt1.lat, pt1.lon, pt2.lat, pt2.lon);
}
distanceTv.setText(OsmAndFormatter.getFormattedDistance(dist, mapActivity.getMyApplication()) + (defaultMode ? "" : ","));
if (defaultMode) {
timeTv.setText("");
} else {
int seconds = (int) (dist / appMode.getDefaultSpeed());
timeTv.setText("~ " + OsmAndFormatter.getFormattedDuration(seconds, mapActivity.getMyApplication()));
}
countTv.setText(mapActivity.getString(R.string.shared_string_markers) + ": " + selectedCount);
}
}
use of net.osmand.plus.ApplicationMode in project Osmand by osmandapp.
the class DirectionIndicationDialogFragment method onCreateView.
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
final OsmandSettings settings = getSettings();
helpImgHeight = getResources().getDimensionPixelSize(R.dimen.action_bar_image_height);
mainView = inflater.inflate(R.layout.fragment_direction_indication_dialog, container);
Toolbar toolbar = (Toolbar) mainView.findViewById(R.id.toolbar);
toolbar.setNavigationIcon(getIconsCache().getIcon(R.drawable.ic_arrow_back));
toolbar.setNavigationOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
dismiss();
}
});
TextView appModeTv = (TextView) mainView.findViewById(R.id.app_mode_text_view);
ApplicationMode appMode = settings.APPLICATION_MODE.get();
appModeTv.setText(appMode.getStringResource());
appModeTv.setCompoundDrawablesWithIntrinsicBounds(null, null, getIconsCache().getIcon(appMode.getSmallIconDark()), null);
if (AndroidUiHelper.isOrientationPortrait(getActivity())) {
((ObservableScrollView) mainView.findViewById(R.id.scroll_view)).setScrollViewCallbacks(new ObservableScrollViewCallbacks() {
@Override
public void onScrollChanged(int scrollY, boolean firstScroll, boolean dragging) {
if (scrollY >= helpImgHeight) {
if (!shadowVisible) {
mainView.findViewById(R.id.app_bar_shadow).setVisibility(View.VISIBLE);
shadowVisible = true;
}
} else if (shadowVisible) {
mainView.findViewById(R.id.app_bar_shadow).setVisibility(View.GONE);
shadowVisible = false;
}
}
@Override
public void onDownMotionEvent() {
}
@Override
public void onUpOrCancelMotionEvent(ScrollState scrollState) {
}
});
}
updateHelpImage();
final TextView menuTv = (TextView) mainView.findViewById(R.id.active_markers_text_view);
menuTv.setText(settings.DISPLAYED_MARKERS_WIDGETS_COUNT.get() == 1 ? R.string.shared_string_one : R.string.shared_string_two);
menuTv.setCompoundDrawablesWithIntrinsicBounds(null, null, getContentIcon(R.drawable.ic_action_arrow_drop_down), null);
menuTv.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
CharSequence[] titles = getMenuTitles();
Paint paint = new Paint();
paint.setTextSize(getResources().getDimensionPixelSize(R.dimen.default_list_text_size));
float titleTextWidth = Math.max(paint.measureText(titles[0].toString()), paint.measureText(titles[1].toString()));
float itemWidth = titleTextWidth + AndroidUtils.dpToPx(getActivity(), 32);
float minWidth = AndroidUtils.dpToPx(getActivity(), 100);
final ListPopupWindow listPopupWindow = new ListPopupWindow(getActivity());
listPopupWindow.setAnchorView(menuTv);
listPopupWindow.setContentWidth((int) (Math.max(itemWidth, minWidth)));
listPopupWindow.setDropDownGravity(Gravity.END | Gravity.TOP);
listPopupWindow.setHorizontalOffset(AndroidUtils.dpToPx(getActivity(), 8));
listPopupWindow.setVerticalOffset(-menuTv.getHeight());
listPopupWindow.setModal(true);
listPopupWindow.setAdapter(new ArrayAdapter<>(getActivity(), R.layout.popup_list_text_item, titles));
listPopupWindow.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
updateDisplayedMarkersCount(position == 0 ? 1 : 2);
listPopupWindow.dismiss();
}
});
listPopupWindow.show();
}
});
final CompoundButton distanceIndicationToggle = (CompoundButton) mainView.findViewById(R.id.distance_indication_switch);
distanceIndicationToggle.setChecked(settings.MARKERS_DISTANCE_INDICATION_ENABLED.get());
mainView.findViewById(R.id.distance_indication_row).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
updateChecked(settings.MARKERS_DISTANCE_INDICATION_ENABLED, distanceIndicationToggle);
updateSelection(true);
}
});
mainView.findViewById(R.id.top_bar_row).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
settings.MAP_MARKERS_MODE.set(MapMarkersMode.TOOLBAR);
updateSelection(true);
}
});
mainView.findViewById(R.id.widget_row).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
settings.MAP_MARKERS_MODE.set(MapMarkersMode.WIDGETS);
updateSelection(true);
}
});
updateSelection(false);
final CompoundButton showArrowsToggle = (CompoundButton) mainView.findViewById(R.id.show_arrows_switch);
showArrowsToggle.setChecked(settings.SHOW_ARROWS_TO_FIRST_MARKERS.get());
mainView.findViewById(R.id.show_arrows_row).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
updateChecked(settings.SHOW_ARROWS_TO_FIRST_MARKERS, showArrowsToggle);
}
});
final CompoundButton showLinesToggle = (CompoundButton) mainView.findViewById(R.id.show_guide_line_switch);
showLinesToggle.setChecked(settings.SHOW_LINES_TO_FIRST_MARKERS.get());
mainView.findViewById(R.id.show_guide_line_row).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
updateChecked(settings.SHOW_LINES_TO_FIRST_MARKERS, showLinesToggle);
}
});
final CompoundButton oneTapActiveToggle = (CompoundButton) mainView.findViewById(R.id.one_tap_active_switch);
oneTapActiveToggle.setChecked(settings.SELECT_MARKER_ON_SINGLE_TAP.get());
mainView.findViewById(R.id.one_tap_active_row).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
updateChecked(settings.SELECT_MARKER_ON_SINGLE_TAP, oneTapActiveToggle);
}
});
return mainView;
}
use of net.osmand.plus.ApplicationMode in project Osmand by osmandapp.
the class MapillaryPlugin method setWidgetVisible.
private void setWidgetVisible(MapActivity mapActivity, boolean visible) {
if (mapillaryWidgetRegInfo != null) {
final List<ApplicationMode> allModes = ApplicationMode.allPossibleValues();
for (ApplicationMode mode : allModes) {
mapActivity.getMapLayers().getMapWidgetRegistry().setVisibility(mode, mapillaryWidgetRegInfo, visible, false);
}
MapInfoLayer mil = mapActivity.getMapLayers().getMapInfoLayer();
if (mil != null) {
mil.recreateControls();
}
mapActivity.refreshMap();
}
}
use of net.osmand.plus.ApplicationMode in project Osmand by osmandapp.
the class DestinationReachedMenuFragment method onCreateView.
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.dest_reached_menu_fragment, container, false);
view.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
dismissMenu();
}
});
IconsCache iconsCache = getMapActivity().getMyApplication().getIconsCache();
ImageButton closeImageButton = (ImageButton) view.findViewById(R.id.closeImageButton);
closeImageButton.setImageDrawable(iconsCache.getIcon(R.drawable.ic_action_remove_dark, menu.isLight()));
closeImageButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
dismissMenu();
}
});
Button removeDestButton = (Button) view.findViewById(R.id.removeDestButton);
removeDestButton.setCompoundDrawablesWithIntrinsicBounds(iconsCache.getIcon(R.drawable.ic_action_done, menu.isLight()), null, null, null);
AndroidUtils.setTextPrimaryColor(view.getContext(), removeDestButton, !menu.isLight());
removeDestButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
getMapActivity().getMyApplication().getTargetPointsHelper().removeWayPoint(true, -1);
Object contextMenuObj = getMapActivity().getContextMenu().getObject();
if (getMapActivity().getContextMenu().isActive() && contextMenuObj != null && contextMenuObj instanceof TargetPoint) {
TargetPoint targetPoint = (TargetPoint) contextMenuObj;
if (!targetPoint.start && !targetPoint.intermediate) {
getMapActivity().getContextMenu().close();
}
}
OsmandSettings settings = getMapActivity().getMyApplication().getSettings();
settings.APPLICATION_MODE.set(settings.DEFAULT_APPLICATION_MODE.get());
getMapActivity().getMapActions().stopNavigationWithoutConfirm();
dismissMenu();
}
});
Button recalcDestButton = (Button) view.findViewById(R.id.recalcDestButton);
recalcDestButton.setCompoundDrawablesWithIntrinsicBounds(iconsCache.getIcon(R.drawable.ic_action_gdirections_dark, menu.isLight()), null, null, null);
AndroidUtils.setTextPrimaryColor(view.getContext(), recalcDestButton, !menu.isLight());
recalcDestButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
TargetPointsHelper helper = getMapActivity().getMyApplication().getTargetPointsHelper();
TargetPoint target = helper.getPointToNavigate();
dismissMenu();
if (target != null) {
helper.navigateToPoint(new LatLon(target.getLatitude(), target.getLongitude()), true, -1, target.getOriginalPointDescription());
getMapActivity().getMapActions().recalculateRoute(false);
getMapActivity().getMapLayers().getMapControlsLayer().startNavigation();
}
}
});
Button findParkingButton = (Button) view.findViewById(R.id.findParkingButton);
ApplicationMode appMode = getMapActivity().getMyApplication().getRoutingHelper().getAppMode();
if (!appMode.isDerivedRoutingFrom(appMode.CAR)) {
findParkingButton.setVisibility(View.GONE);
}
findParkingButton.setCompoundDrawablesWithIntrinsicBounds(iconsCache.getIcon(R.drawable.ic_action_parking_dark, menu.isLight()), null, null, null);
AndroidUtils.setTextPrimaryColor(view.getContext(), findParkingButton, !menu.isLight());
findParkingButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
PoiFiltersHelper helper = getMapActivity().getMyApplication().getPoiFilters();
// PoiType place = getMapActivity().getMyApplication().getPoiTypes().getPoiTypeByKey("parking");
PoiUIFilter parkingFilter = helper.getFilterById(PoiUIFilter.STD_PREFIX + "parking");
if (parkingFilter != null) {
final Intent newIntent = new Intent(getActivity(), SearchPOIActivity.class);
newIntent.putExtra(SearchPOIActivity.AMENITY_FILTER, parkingFilter.getFilterId());
newIntent.putExtra(SearchActivity.SEARCH_NEARBY, true);
startActivityForResult(newIntent, 0);
}
dismissMenu();
}
});
View mainView = view.findViewById(R.id.main_view);
if (menu.isLandscapeLayout()) {
AndroidUtils.setBackground(view.getContext(), mainView, !menu.isLight(), R.drawable.bg_left_menu_light, R.drawable.bg_left_menu_dark);
} else {
AndroidUtils.setBackground(view.getContext(), mainView, !menu.isLight(), R.drawable.bg_bottom_menu_light, R.drawable.bg_bottom_menu_dark);
}
TextView title = (TextView) view.findViewById(R.id.titleTextView);
AndroidUtils.setTextPrimaryColor(view.getContext(), title, !menu.isLight());
return view;
}
use of net.osmand.plus.ApplicationMode in project Osmand by osmandapp.
the class AvoidSpecificRoads method addImpassableRoad.
public void addImpassableRoad(@Nullable final MapActivity activity, @NonNull final LatLon loc, final boolean showDialog, @Nullable final AvoidSpecificRoadsCallback callback, final boolean skipWritingSettings) {
final Location ll = new Location("");
ll.setLatitude(loc.getLatitude());
ll.setLongitude(loc.getLongitude());
ApplicationMode appMode = app.getRoutingHelper().getAppMode();
app.getLocationProvider().getRouteSegment(ll, appMode, new ResultMatcher<RouteDataObject>() {
@Override
public boolean publish(RouteDataObject object) {
if (object == null) {
if (activity != null) {
Toast.makeText(activity, R.string.error_avoid_specific_road, Toast.LENGTH_LONG).show();
}
if (callback != null) {
callback.onAddImpassableRoad(false, null);
}
} else {
addImpassableRoadInternal(object, ll, showDialog, activity, loc);
if (callback != null) {
callback.onAddImpassableRoad(true, object);
}
}
return true;
}
@Override
public boolean isCancelled() {
return callback != null && callback.isCancelled();
}
});
if (!skipWritingSettings) {
app.getSettings().addImpassableRoad(loc.getLatitude(), loc.getLongitude());
}
}
Aggregations