Search in sources :

Example 1 with OsmandSettings

use of net.osmand.plus.settings.backend.OsmandSettings in project Osmand by osmandapp.

the class OsmAndDialogs method showVoiceProviderDialog.

public static void showVoiceProviderDialog(final MapActivity activity, final ApplicationMode applicationMode, final boolean applyAllModes) {
    OsmandApplication app = activity.getMyApplication();
    final OsmandSettings settings = app.getSettings();
    boolean nightMode = app.getDaynightHelper().isNightModeForMapControls();
    final RoutingOptionsHelper routingOptionsHelper = app.getRoutingOptionsHelper();
    final AlertDialog.Builder builder = new AlertDialog.Builder(UiUtilities.getThemedContext(activity, nightMode));
    final String[] firstSelectedVoiceProvider = new String[1];
    View view = UiUtilities.getInflater(activity, nightMode).inflate(R.layout.select_voice_first, null);
    ((ImageView) view.findViewById(R.id.icon)).setImageDrawable(app.getUIUtilities().getIcon(R.drawable.ic_action_volume_up, settings.isLightContent()));
    view.findViewById(R.id.spinner).setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(final View v) {
            routingOptionsHelper.selectVoiceGuidance(activity, new CallbackWithObject<String>() {

                @Override
                public boolean processResult(String result) {
                    boolean acceptableValue = !RoutePreferencesMenu.MORE_VALUE.equals(firstSelectedVoiceProvider[0]);
                    if (acceptableValue) {
                        ((TextView) v.findViewById(R.id.selectText)).setText(routingOptionsHelper.getVoiceProviderName(v.getContext(), result));
                        firstSelectedVoiceProvider[0] = result;
                    }
                    return acceptableValue;
                }
            }, applicationMode);
        }
    });
    ((ImageView) view.findViewById(R.id.dropDownIcon)).setImageDrawable(app.getUIUtilities().getIcon(R.drawable.ic_action_arrow_drop_down, settings.isLightContent()));
    builder.setCancelable(true);
    builder.setNegativeButton(R.string.shared_string_cancel, null);
    builder.setPositiveButton(R.string.shared_string_apply, new DialogInterface.OnClickListener() {

        @Override
        public void onClick(DialogInterface dialog, int which) {
            if (!Algorithms.isEmpty(firstSelectedVoiceProvider[0])) {
                routingOptionsHelper.applyVoiceProvider(activity, firstSelectedVoiceProvider[0], applyAllModes);
                if (OsmandSettings.VOICE_PROVIDER_NOT_USE.equals(firstSelectedVoiceProvider[0])) {
                    settings.VOICE_MUTE.setModeValue(applicationMode, true);
                } else {
                    settings.VOICE_MUTE.setModeValue(applicationMode, false);
                }
            }
        }
    });
    builder.setNeutralButton(R.string.shared_string_do_not_use, new DialogInterface.OnClickListener() {

        @Override
        public void onClick(DialogInterface dialogInterface, int i) {
            if (applyAllModes) {
                for (ApplicationMode mode : ApplicationMode.allPossibleValues()) {
                    // if (!settings.VOICE_PROVIDER.isSetForMode(mode)) {
                    settings.VOICE_PROVIDER.setModeValue(mode, OsmandSettings.VOICE_PROVIDER_NOT_USE);
                    settings.VOICE_MUTE.setModeValue(mode, true);
                // }
                }
            }
            settings.VOICE_PROVIDER.setModeValue(applicationMode, OsmandSettings.VOICE_PROVIDER_NOT_USE);
            settings.VOICE_MUTE.setModeValue(applicationMode, true);
        }
    });
    builder.setView(view);
    builder.show();
}
Also used : AlertDialog(androidx.appcompat.app.AlertDialog) OsmandApplication(net.osmand.plus.OsmandApplication) DialogInterface(android.content.DialogInterface) ApplicationMode(net.osmand.plus.settings.backend.ApplicationMode) ImageView(android.widget.ImageView) TextView(android.widget.TextView) View(android.view.View) OsmandSettings(net.osmand.plus.settings.backend.OsmandSettings) RoutingOptionsHelper(net.osmand.plus.routepreparationmenu.RoutingOptionsHelper) CallbackWithObject(net.osmand.CallbackWithObject) TextView(android.widget.TextView) ImageView(android.widget.ImageView)

Example 2 with OsmandSettings

use of net.osmand.plus.settings.backend.OsmandSettings in project Osmand by osmandapp.

the class SearchPOIActivity method onCreateOptionsMenu.

@Override
public boolean onCreateOptionsMenu(Menu omenu) {
    Menu menu = getClearToolbar(true).getMenu();
    searchPOILevel = menu.add(0, SEARCH_MORE, 0, R.string.search_POI_level_btn);
    searchPOILevel.setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS);
    searchPOILevel.setOnMenuItemClickListener(new OnMenuItemClickListener() {

        @Override
        public boolean onMenuItemClick(MenuItem item) {
            return search();
        }
    });
    showFilterItem = menu.add(0, FILTER, 0, R.string.search_poi_filter);
    showFilterItem.setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS);
    showFilterItem = showFilterItem.setIcon(getMyApplication().getUIUtilities().getIcon(R.drawable.ic_action_filter_dark));
    showFilterItem.setOnMenuItemClickListener(new OnMenuItemClickListener() {

        @Override
        public boolean onMenuItemClick(MenuItem item) {
            if (searchFilterLayout.getVisibility() == View.GONE) {
                searchFilterLayout.setVisibility(View.VISIBLE);
                searchFilter.requestFocus();
                InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
                imm.showSoftInput(searchFilter, InputMethodManager.SHOW_IMPLICIT);
            } else {
                if (filter != null) {
                    searchFilter.setText(filter.getSavedFilterByName() == null ? "" : filter.getSavedFilterByName());
                }
                searchFilterLayout.setVisibility(View.GONE);
            }
            return true;
        }
    });
    showOnMapItem = menu.add(0, SHOW_ON_MAP, 0, R.string.shared_string_show_on_map);
    showOnMapItem.setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS);
    showOnMapItem = showOnMapItem.setIcon(getMyApplication().getUIUtilities().getIcon(R.drawable.ic_show_on_map));
    showOnMapItem.setOnMenuItemClickListener(new OnMenuItemClickListener() {

        @Override
        public boolean onMenuItemClick(MenuItem item) {
            OsmandSettings settings = app.getSettings();
            filter.setFilterByName(searchFilter.getText().toString().trim());
            app.getPoiFilters().addSelectedPoiFilter(filter);
            if (location != null) {
                settings.setMapLocationToShow(location.getLatitude(), location.getLongitude(), 15);
            }
            MapActivity.launchMapActivityMoveToTop(SearchPOIActivity.this);
            return true;
        }
    });
    showOnMapItem.setEnabled(!isNameSearch() || amenityAdapter.getCount() > 0);
    if (filter != null && !isNameSearch()) {
        createMenuItem(omenu, SAVE_FILTER, R.string.edit_filter_save_as_menu_item, R.drawable.ic_action_favorite, MenuItem.SHOW_AS_ACTION_IF_ROOM);
        if (!filter.isStandardFilter()) {
            createMenuItem(omenu, DELETE_FILTER, R.string.shared_string_delete, R.drawable.ic_action_delete_dark, MenuItem.SHOW_AS_ACTION_IF_ROOM);
        }
    }
    updateButtonState(false);
    return true;
}
Also used : OnMenuItemClickListener(android.view.MenuItem.OnMenuItemClickListener) MenuItem(android.view.MenuItem) InputMethodManager(android.view.inputmethod.InputMethodManager) Menu(android.view.Menu) PopupMenu(androidx.appcompat.widget.PopupMenu) OsmandSettings(net.osmand.plus.settings.backend.OsmandSettings)

Example 3 with OsmandSettings

use of net.osmand.plus.settings.backend.OsmandSettings in project Osmand by osmandapp.

the class OsmandInAppPurchaseActivity method initInAppPurchaseHelper.

private void initInAppPurchaseHelper() {
    deinitInAppPurchaseHelper();
    OsmandApplication app = getMyApplication();
    OsmandSettings settings = app.getSettings();
    if (purchaseHelper == null) {
        InAppPurchaseHelper purchaseHelper = app.getInAppPurchaseHelper();
        if (settings.isInternetConnectionAvailable() && isInAppPurchaseAllowed() && Version.isInAppPurchaseSupported()) {
            this.purchaseHelper = purchaseHelper;
        }
    }
    if (purchaseHelper != null) {
        final WeakReference<OsmandInAppPurchaseActivity> activityRef = new WeakReference<>(this);
        purchaseHelper.isInAppPurchaseSupported(this, new InAppPurchaseInitCallback() {

            @Override
            public void onSuccess() {
                OsmandInAppPurchaseActivity activity = activityRef.get();
                if (!activityDestroyed && AndroidUtils.isActivityNotDestroyed(activity)) {
                    purchaseHelper.setUiActivity(activity);
                    if (purchaseHelper.needRequestInventory()) {
                        purchaseHelper.requestInventory(false);
                    }
                }
            }

            @Override
            public void onFail() {
            }
        });
    } else if (isInAppPurchaseAllowed() && settings.isInternetConnectionAvailable()) {
        InAppPurchaseHelper purchaseHelper = app.getInAppPurchaseHelper();
        if (purchaseHelper != null && purchaseHelper.needRequestPromo()) {
            purchaseHelper.checkPromoAsync(null);
        }
    }
}
Also used : OsmandApplication(net.osmand.plus.OsmandApplication) WeakReference(java.lang.ref.WeakReference) InAppPurchaseHelper(net.osmand.plus.inapp.InAppPurchaseHelper) OsmandSettings(net.osmand.plus.settings.backend.OsmandSettings) InAppPurchaseInitCallback(net.osmand.plus.inapp.InAppPurchaseHelper.InAppPurchaseInitCallback)

Example 4 with OsmandSettings

use of net.osmand.plus.settings.backend.OsmandSettings in project Osmand by osmandapp.

the class TripHelper method buildTrip.

@NonNull
public Trip buildTrip(float density) {
    RoutingHelper routingHelper = app.getRoutingHelper();
    OsmandSettings settings = app.getSettings();
    TargetPointsHelper targetPointsHelper = app.getTargetPointsHelper();
    TargetPoint pointToNavigate = targetPointsHelper.getPointToNavigate();
    Trip.Builder tripBuilder = new Trip.Builder();
    if (pointToNavigate != null) {
        Pair<Destination, TravelEstimate> dest = getDestination(pointToNavigate);
        tripBuilder.addDestination(dest.first, dest.second);
        lastDestination = dest.first;
        lastDestinationTravelEstimate = dest.second;
    } else {
        lastDestination = null;
        lastDestinationTravelEstimate = null;
    }
    boolean routeBeingCalculated = routingHelper.isRouteBeingCalculated();
    tripBuilder.setLoading(routeBeingCalculated);
    if (!routeBeingCalculated) {
        Step.Builder stepBuilder = new Step.Builder();
        Maneuver.Builder turnBuilder;
        TurnType turnType = null;
        boolean leftSide = settings.DRIVING_REGION.get().leftHandDriving;
        boolean deviatedFromRoute = routingHelper.isDeviatedFromRoute();
        int turnImminent = 0;
        int nextTurnDistance = 0;
        RouteCalculationResult.NextDirectionInfo nextDirInfo;
        RouteCalculationResult.NextDirectionInfo calc = new RouteCalculationResult.NextDirectionInfo();
        if (deviatedFromRoute) {
            turnType = TurnType.valueOf(TurnType.OFFR, leftSide);
            nextTurnDistance = (int) routingHelper.getRouteDeviation();
        } else {
            nextDirInfo = routingHelper.getNextRouteDirectionInfo(calc, true);
            if (nextDirInfo != null && nextDirInfo.distanceTo > 0 && nextDirInfo.directionInfo != null) {
                turnType = nextDirInfo.directionInfo.getTurnType();
                nextTurnDistance = nextDirInfo.distanceTo;
                turnImminent = nextDirInfo.imminent;
            }
        }
        if (turnType != null) {
            TurnDrawable drawable = new TurnDrawable(app, false);
            int height = (int) (TURN_IMAGE_SIZE_DP * density);
            int width = (int) (TURN_IMAGE_SIZE_DP * density);
            drawable.setBounds(0, 0, width, height);
            drawable.setTurnType(turnType);
            drawable.setTurnImminent(turnImminent, deviatedFromRoute);
            Bitmap turnBitmap = drawableToBitmap(drawable, width, height);
            turnBuilder = new Maneuver.Builder(getManeuverType(turnType));
            if (turnType.isRoundAbout()) {
                turnBuilder.setRoundaboutExitNumber(turnType.getExitOut());
            }
            turnBuilder.setIcon(new CarIcon.Builder(IconCompat.createWithBitmap(turnBitmap)).build());
        } else {
            turnBuilder = new Maneuver.Builder(Maneuver.TYPE_UNKNOWN);
        }
        Maneuver maneuver = turnBuilder.build();
        String cue = turnType != null ? RouteCalculationResult.toString(turnType, app, true) : "";
        stepBuilder.setManeuver(maneuver);
        stepBuilder.setCue(cue);
        nextDirInfo = routingHelper.getNextRouteDirectionInfo(calc, false);
        if (nextDirInfo != null && nextDirInfo.directionInfo != null && nextDirInfo.directionInfo.getTurnType() != null) {
            int[] lanes = nextDirInfo.directionInfo.getTurnType().getLanes();
            int locimminent = nextDirInfo.imminent;
            // Do not show too far
            if ((nextDirInfo.distanceTo > 800 && nextDirInfo.directionInfo.getTurnType().isSkipToSpeak()) || nextDirInfo.distanceTo > 1200) {
                lanes = null;
            }
            // int dist = nextDirInfo.distanceTo;
            if (lanes != null) {
                for (int lane : lanes) {
                    int firstTurnType = TurnType.getPrimaryTurn(lane);
                    int secondTurnType = TurnType.getSecondaryTurn(lane);
                    int thirdTurnType = TurnType.getTertiaryTurn(lane);
                    Lane.Builder laneBuilder = new Lane.Builder();
                    laneBuilder.addDirection(LaneDirection.create(getLaneDirection(TurnType.valueOf(firstTurnType, leftSide)), (lane & 1) == 1));
                    if (secondTurnType > 0) {
                        laneBuilder.addDirection(LaneDirection.create(getLaneDirection(TurnType.valueOf(secondTurnType, leftSide)), false));
                    }
                    if (thirdTurnType > 0) {
                        laneBuilder.addDirection(LaneDirection.create(getLaneDirection(TurnType.valueOf(thirdTurnType, leftSide)), false));
                    }
                    stepBuilder.addLane(laneBuilder.build());
                }
                LanesDrawable lanesDrawable = new LanesDrawable(app, 1f, TURN_LANE_IMAGE_SIZE * density, TURN_LANE_IMAGE_MIN_DELTA * density, TURN_LANE_IMAGE_MARGIN * density, TURN_LANE_IMAGE_SIZE * density);
                lanesDrawable.lanes = lanes;
                lanesDrawable.imminent = locimminent == 0;
                lanesDrawable.isNightMode = app.getDaynightHelper().isNightMode();
                // prefer 500 x 74 dp
                lanesDrawable.updateBounds();
                Bitmap lanesBitmap = drawableToBitmap(lanesDrawable, lanesDrawable.getIntrinsicWidth(), lanesDrawable.getIntrinsicHeight());
                stepBuilder.setLanesImage(new CarIcon.Builder(IconCompat.createWithBitmap(lanesBitmap)).build());
            }
        }
        int leftTurnTimeSec = routingHelper.getLeftTimeNextTurn();
        long turnArrivalTime = System.currentTimeMillis() + leftTurnTimeSec * 1000L;
        Distance stepDistance = getDistance(app, nextTurnDistance);
        DateTimeWithZone stepDateTime = DateTimeWithZone.create(turnArrivalTime, TimeZone.getDefault());
        TravelEstimate.Builder stepTravelEstimateBuilder = new TravelEstimate.Builder(stepDistance, stepDateTime);
        stepTravelEstimateBuilder.setRemainingTimeSeconds(leftTurnTimeSec);
        Step step = stepBuilder.build();
        TravelEstimate stepTravelEstimate = stepTravelEstimateBuilder.build();
        tripBuilder.addStep(step, stepTravelEstimate);
        lastStep = step;
        lastStepTravelEstimate = stepTravelEstimate;
        if (!deviatedFromRoute) {
            nextDirInfo = routingHelper.getNextRouteDirectionInfo(calc, true);
            CurrentStreetName currentName = routingHelper.getCurrentName(nextDirInfo);
            tripBuilder.setCurrentRoad(currentName.text);
            lastCurrentRoad = currentName.text;
        } else {
            lastCurrentRoad = null;
        }
    } else {
        lastStep = null;
        lastStepTravelEstimate = null;
    }
    return tripBuilder.build();
}
Also used : Destination(androidx.car.app.navigation.model.Destination) Step(androidx.car.app.navigation.model.Step) Maneuver(androidx.car.app.navigation.model.Maneuver) TargetPoint(net.osmand.plus.helpers.TargetPointsHelper.TargetPoint) Bitmap(android.graphics.Bitmap) RouteCalculationResult(net.osmand.plus.routing.RouteCalculationResult) DateTimeWithZone(androidx.car.app.model.DateTimeWithZone) TurnDrawable(net.osmand.plus.views.mapwidgets.TurnDrawable) TargetPointsHelper(net.osmand.plus.helpers.TargetPointsHelper) Distance(androidx.car.app.model.Distance) Trip(androidx.car.app.navigation.model.Trip) Lane(androidx.car.app.navigation.model.Lane) CurrentStreetName(net.osmand.plus.routing.CurrentStreetName) RoutingHelper(net.osmand.plus.routing.RoutingHelper) TurnType(net.osmand.router.TurnType) LanesDrawable(net.osmand.plus.views.mapwidgets.LanesDrawable) OsmandSettings(net.osmand.plus.settings.backend.OsmandSettings) TargetPoint(net.osmand.plus.helpers.TargetPointsHelper.TargetPoint) TravelEstimate(androidx.car.app.navigation.model.TravelEstimate) NonNull(androidx.annotation.NonNull)

Example 5 with OsmandSettings

use of net.osmand.plus.settings.backend.OsmandSettings in project Osmand by osmandapp.

the class DiscountHelper method checkAndDisplay.

@SuppressLint("HardwareIds")
public static void checkAndDisplay(final MapActivity mapActivity) {
    OsmandApplication app = mapActivity.getMyApplication();
    OsmandSettings settings = app.getSettings();
    if (settings.DO_NOT_SHOW_STARTUP_MESSAGES.get() || !settings.INAPPS_READ.get()) {
        return;
    }
    if (mBannerVisible) {
        showDiscountBanner(mapActivity, mData);
    } else if (mFilterVisible) {
        showPoiFilter(mapActivity, mFilter);
    }
    if (System.currentTimeMillis() - mLastCheckTime < 1000 * 60 * 60 * 24 || !settings.isInternetConnectionAvailable()) {
        return;
    }
    mLastCheckTime = System.currentTimeMillis();
    final Map<String, String> pms = new LinkedHashMap<>();
    pms.put("version", Version.getFullVersion(app));
    pms.put("nd", app.getAppInitializer().getFirstInstalledDays() + "");
    pms.put("ns", app.getAppInitializer().getNumberOfStarts() + "");
    pms.put("lang", app.getLanguage() + "");
    try {
        pms.put("aid", Secure.getString(app.getContentResolver(), Secure.ANDROID_ID));
    } catch (Exception e) {
        e.printStackTrace();
    }
    new AsyncTask<Void, Void, String>() {

        @Override
        protected String doInBackground(Void... params) {
            try {
                return AndroidNetworkUtils.sendRequest(mapActivity.getMyApplication(), URL, pms, "Requesting discount info...", false, false);
            } catch (Exception e) {
                logError("Requesting discount info error: ", e);
                return null;
            }
        }

        @Override
        protected void onPostExecute(String response) {
            if (response != null) {
                processDiscountResponse(response, mapActivity);
            }
        }
    }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}
Also used : OsmandApplication(net.osmand.plus.OsmandApplication) OsmandSettings(net.osmand.plus.settings.backend.OsmandSettings) JSONException(org.json.JSONException) LinkedHashMap(java.util.LinkedHashMap) SuppressLint(android.annotation.SuppressLint)

Aggregations

OsmandSettings (net.osmand.plus.settings.backend.OsmandSettings)154 OsmandApplication (net.osmand.plus.OsmandApplication)52 View (android.view.View)25 ArrayList (java.util.ArrayList)23 LatLon (net.osmand.data.LatLon)17 MapActivity (net.osmand.plus.activities.MapActivity)17 TextView (android.widget.TextView)16 NonNull (androidx.annotation.NonNull)16 AlertDialog (androidx.appcompat.app.AlertDialog)15 ApplicationMode (net.osmand.plus.settings.backend.ApplicationMode)15 ArrayAdapter (android.widget.ArrayAdapter)13 ContextMenuItem (net.osmand.plus.ContextMenuItem)13 TargetPoint (net.osmand.plus.helpers.TargetPointsHelper.TargetPoint)12 OsmandMapTileView (net.osmand.plus.views.OsmandMapTileView)12 Context (android.content.Context)11 ImageView (android.widget.ImageView)11 Intent (android.content.Intent)8 List (java.util.List)8 PointDescription (net.osmand.data.PointDescription)8 DialogInterface (android.content.DialogInterface)7