Search in sources :

Example 21 with ApplicationMode

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);
    }
}
Also used : WptPt(net.osmand.plus.GPXUtilities.WptPt) TextView(android.widget.TextView) ApplicationMode(net.osmand.plus.ApplicationMode) TrkSegment(net.osmand.plus.GPXUtilities.TrkSegment) TargetPoint(net.osmand.plus.TargetPointsHelper.TargetPoint) MapActivity(net.osmand.plus.activities.MapActivity)

Example 22 with ApplicationMode

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;
}
Also used : ObservableScrollView(com.github.ksoichiro.android.observablescrollview.ObservableScrollView) ObservableScrollViewCallbacks(com.github.ksoichiro.android.observablescrollview.ObservableScrollViewCallbacks) ApplicationMode(net.osmand.plus.ApplicationMode) Paint(android.graphics.Paint) ImageView(android.widget.ImageView) ObservableScrollView(com.github.ksoichiro.android.observablescrollview.ObservableScrollView) View(android.view.View) AdapterView(android.widget.AdapterView) TextView(android.widget.TextView) OsmandSettings(net.osmand.plus.OsmandSettings) Paint(android.graphics.Paint) ListPopupWindow(android.support.v7.widget.ListPopupWindow) ScrollState(com.github.ksoichiro.android.observablescrollview.ScrollState) TextView(android.widget.TextView) AdapterView(android.widget.AdapterView) ArrayAdapter(android.widget.ArrayAdapter) CompoundButton(android.widget.CompoundButton) Toolbar(android.support.v7.widget.Toolbar) Nullable(android.support.annotation.Nullable)

Example 23 with ApplicationMode

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();
    }
}
Also used : MapInfoLayer(net.osmand.plus.views.MapInfoLayer) ApplicationMode(net.osmand.plus.ApplicationMode)

Example 24 with ApplicationMode

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;
}
Also used : Intent(android.content.Intent) ApplicationMode(net.osmand.plus.ApplicationMode) PoiFiltersHelper(net.osmand.plus.poi.PoiFiltersHelper) TargetPoint(net.osmand.plus.TargetPointsHelper.TargetPoint) TextView(android.widget.TextView) View(android.view.View) OsmandSettings(net.osmand.plus.OsmandSettings) PoiUIFilter(net.osmand.plus.poi.PoiUIFilter) LatLon(net.osmand.data.LatLon) ImageButton(android.widget.ImageButton) ImageButton(android.widget.ImageButton) Button(android.widget.Button) SearchPOIActivity(net.osmand.plus.activities.search.SearchPOIActivity) TextView(android.widget.TextView) IconsCache(net.osmand.plus.IconsCache) TargetPointsHelper(net.osmand.plus.TargetPointsHelper) Nullable(android.support.annotation.Nullable)

Example 25 with ApplicationMode

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());
    }
}
Also used : RouteDataObject(net.osmand.binary.RouteDataObject) ApplicationMode(net.osmand.plus.ApplicationMode) Location(net.osmand.Location)

Aggregations

ApplicationMode (net.osmand.plus.ApplicationMode)41 View (android.view.View)13 TextView (android.widget.TextView)11 ImageView (android.widget.ImageView)7 OsmandApplication (net.osmand.plus.OsmandApplication)7 OsmandSettings (net.osmand.plus.OsmandSettings)7 AlertDialog (android.support.v7.app.AlertDialog)6 ArrayList (java.util.ArrayList)6 DialogInterface (android.content.DialogInterface)5 AdapterView (android.widget.AdapterView)5 LatLon (net.osmand.data.LatLon)5 Intent (android.content.Intent)4 TargetPointsHelper (net.osmand.plus.TargetPointsHelper)4 TargetPoint (net.osmand.plus.TargetPointsHelper.TargetPoint)4 File (java.io.File)3 OsmandPreference (net.osmand.plus.OsmandSettings.OsmandPreference)3 RoutingHelper (net.osmand.plus.routing.RoutingHelper)3 OsmandMapTileView (net.osmand.plus.views.OsmandMapTileView)3 Uri (android.net.Uri)2 PreferenceCategory (android.preference.PreferenceCategory)2