use of net.osmand.plus.settings.backend.OsmandSettings in project Osmand by osmandapp.
the class RoutingOptionsHelper method showLocalRoutingParameterGroupDialog.
public void showLocalRoutingParameterGroupDialog(final LocalRoutingParameterGroup group, final MapActivity mapActivity, final OnClickListener listener) {
OsmandSettings settings = app.getSettings();
final ContextMenuAdapter adapter = new ContextMenuAdapter(app);
int i = 0;
int selectedIndex = -1;
for (LocalRoutingParameter p : group.getRoutingParameters()) {
adapter.addItem(ContextMenuItem.createBuilder(p.getText(mapActivity)).setSelected(false).createItem());
if (p.isSelected(settings)) {
selectedIndex = i;
}
i++;
}
if (selectedIndex == -1) {
selectedIndex = 0;
}
final boolean nightMode = isNightMode(app);
Context themedContext = UiUtilities.getThemedContext(mapActivity, nightMode);
ApplicationMode selectedAppMode = app.getRoutingHelper().getAppMode();
final int selectedModeColor = selectedAppMode.getProfileColor(nightMode);
AlertDialog.Builder builder = new AlertDialog.Builder(themedContext);
final int layout = R.layout.list_menu_item_native_singlechoice;
final ArrayAdapter<String> listAdapter = new ArrayAdapter<String>(themedContext, layout, R.id.text1, adapter.getItemNames()) {
@NonNull
@Override
public View getView(final int position, View convertView, @NonNull ViewGroup parent) {
// User super class to create the View
View v = convertView;
if (v == null) {
v = UiUtilities.getInflater(mapActivity, nightMode).inflate(layout, parent, false);
}
final ContextMenuItem item = adapter.getItem(position);
AppCompatCheckedTextView tv = (AppCompatCheckedTextView) v.findViewById(R.id.text1);
tv.setText(item.getTitle());
tv.setTextSize(TypedValue.COMPLEX_UNIT_SP, 16f);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
UiUtilities.setupCompoundButtonDrawable(app, nightMode, selectedModeColor, tv.getCheckMarkDrawable());
}
return v;
}
};
final int[] selectedPosition = { selectedIndex };
builder.setSingleChoiceItems(listAdapter, selectedIndex, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int position) {
selectedPosition[0] = position;
}
});
builder.setTitle(group.getText(mapActivity)).setPositiveButton(R.string.shared_string_ok, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
OsmandSettings settings = app.getSettings();
int position = selectedPosition[0];
if (position >= 0 && position < group.getRoutingParameters().size()) {
for (int i = 0; i < group.getRoutingParameters().size(); i++) {
LocalRoutingParameter rp = group.getRoutingParameters().get(i);
rp.setSelected(settings, i == position);
}
mapActivity.getRoutingHelper().onSettingsChanged(true);
if (listener != null) {
listener.onClick();
}
}
}
}).setNegativeButton(R.string.shared_string_cancel, null);
builder.create().show();
}
use of net.osmand.plus.settings.backend.OsmandSettings in project Osmand by osmandapp.
the class TrackDrawInfo method resetParams.
public void resetParams(@NonNull OsmandApplication app, @NonNull GPXFile gpxFile) {
if (currentRecording) {
OsmandSettings settings = app.getSettings();
settings.CURRENT_TRACK_COLOR.resetToDefault();
settings.CURRENT_TRACK_WIDTH.resetToDefault();
settings.CURRENT_TRACK_COLORING_TYPE.resetToDefault();
settings.CURRENT_TRACK_ROUTE_INFO_ATTRIBUTE.resetToDefault();
settings.CURRENT_TRACK_SHOW_ARROWS.resetToDefault();
settings.CURRENT_TRACK_SHOW_START_FINISH.resetToDefault();
initCurrentTrackParams(app);
} else {
color = gpxFile.getColor(0);
width = gpxFile.getWidth(null);
showArrows = gpxFile.isShowArrows();
showStartFinish = gpxFile.isShowStartFinish();
splitInterval = gpxFile.getSplitInterval();
splitType = GpxSplitType.getSplitTypeByName(gpxFile.getSplitType()).getType();
coloringType = ColoringType.getNonNullTrackColoringTypeByName(gpxFile.getColoringType());
routeInfoAttribute = ColoringType.getRouteInfoAttribute(gpxFile.getColoringType());
}
}
use of net.osmand.plus.settings.backend.OsmandSettings in project Osmand by osmandapp.
the class RouteInfoWidgetsFactory method createNextInfoControl.
public NextTurnWidget createNextInfoControl(final Activity activity, final OsmandApplication app, boolean horisontalMini) {
final OsmandSettings settings = app.getSettings();
final RoutingHelper routingHelper = app.getRoutingHelper();
final NextTurnWidget nextTurnInfo = new NextTurnWidget(activity, app, horisontalMini) {
final NextDirectionInfo calc1 = new NextDirectionInfo();
@Override
public boolean updateInfo(DrawSettings drawSettings) {
boolean followingMode = routingHelper.isFollowingMode() || app.getLocationProvider().getLocationSimulation().isRouteAnimating();
TurnType turnType = null;
boolean deviatedFromRoute = false;
int turnImminent = 0;
int nextTurnDistance = 0;
if (routingHelper.isRouteCalculated() && followingMode) {
deviatedFromRoute = routingHelper.isDeviatedFromRoute();
if (deviatedFromRoute) {
turnImminent = 0;
turnType = TurnType.valueOf(TurnType.OFFR, settings.DRIVING_REGION.get().leftHandDriving);
setDeviatePath((int) routingHelper.getRouteDeviation());
} else {
NextDirectionInfo r = routingHelper.getNextRouteDirectionInfo(calc1, true);
if (r != null && r.distanceTo > 0 && r.directionInfo != null) {
turnType = r.directionInfo.getTurnType();
nextTurnDistance = r.distanceTo;
turnImminent = r.imminent;
}
}
}
setTurnType(turnType);
setTurnImminent(turnImminent, deviatedFromRoute);
setTurnDistance(nextTurnDistance);
return true;
}
};
nextTurnInfo.setOnClickListener(new View.OnClickListener() {
// int i = 0;
// boolean leftSide = false;
@Override
public void onClick(View v) {
// TurnPathHelper.calcTurnPath(nextTurnInfo.pathForTurn, nextTurnInfo.turnType,nextTurnInfo.pathTransform);
if (routingHelper.isRouteCalculated() && !routingHelper.isDeviatedFromRoute()) {
routingHelper.getVoiceRouter().announceCurrentDirection(null);
}
}
});
// initial state
return nextTurnInfo;
}
use of net.osmand.plus.settings.backend.OsmandSettings in project Osmand by osmandapp.
the class InAppPurchaseHelperImpl method getSkuDetailsResponseListener.
// Listener that's called when we finish querying the items and subscriptions we own
private SkuDetailsResponseListener getSkuDetailsResponseListener(boolean userRequested) {
return new SkuDetailsResponseListener() {
@NonNull
private List<String> getAllOwnedSubscriptionSkus() {
List<String> result = new ArrayList<>();
BillingManager billingManager = getBillingManager();
if (billingManager != null) {
for (Purchase p : billingManager.getPurchases()) {
if (getInAppPurchases().getInAppSubscriptionBySku(p.getSku()) != null) {
result.add(p.getSku());
}
}
}
for (Entry<String, SubscriptionStateHolder> entry : subscriptionStateMap.entrySet()) {
SubscriptionState state = entry.getValue().state;
if (state == SubscriptionState.PAUSED || state == SubscriptionState.ON_HOLD) {
String sku = entry.getKey();
if (!result.contains(sku)) {
result.add(sku);
}
}
}
return result;
}
@Override
public void onSkuDetailsResponse(@NonNull BillingResult billingResult, List<SkuDetails> skuDetailsList) {
logDebug("Query sku details finished.");
// Have we been disposed of in the meantime? If so, quit.
if (getBillingManager() == null) {
stop(true);
return;
}
// Is it a failure?
if (billingResult.getResponseCode() != BillingClient.BillingResponseCode.OK) {
logError("Failed to query inventory: " + billingResult.getResponseCode());
notifyError(InAppPurchaseTaskType.REQUEST_INVENTORY, billingResult.getDebugMessage());
stop(true);
return;
}
logDebug("Query sku details was successful.");
/*
* Check for items we own. Notice that for each purchase, we check
* the developer payload to see if it's correct! See
* verifyDeveloperPayload().
*/
List<String> allOwnedSubscriptionSkus = getAllOwnedSubscriptionSkus();
for (InAppSubscription s : getSubscriptions().getAllSubscriptions()) {
if (hasDetails(s.getSku())) {
Purchase purchase = getPurchase(s.getSku());
SkuDetails liveUpdatesDetails = getSkuDetails(s.getSku());
if (liveUpdatesDetails != null) {
fetchInAppPurchase(s, liveUpdatesDetails, purchase);
}
allOwnedSubscriptionSkus.remove(s.getSku());
}
}
for (String sku : allOwnedSubscriptionSkus) {
Purchase purchase = getPurchase(sku);
SkuDetails liveUpdatesDetails = getSkuDetails(sku);
if (liveUpdatesDetails != null) {
InAppSubscription s = getSubscriptions().upgradeSubscription(sku);
if (s == null) {
s = new InAppPurchaseLiveUpdatesOldSubscription(liveUpdatesDetails);
}
fetchInAppPurchase(s, liveUpdatesDetails, purchase);
}
}
InAppPurchase fullVersion = getFullVersion();
if (hasDetails(fullVersion.getSku())) {
Purchase purchase = getPurchase(fullVersion.getSku());
SkuDetails fullPriceDetails = getSkuDetails(fullVersion.getSku());
if (fullPriceDetails != null) {
fetchInAppPurchase(fullVersion, fullPriceDetails, purchase);
}
}
InAppPurchase depthContours = getDepthContours();
if (hasDetails(depthContours.getSku())) {
Purchase purchase = getPurchase(depthContours.getSku());
SkuDetails depthContoursDetails = getSkuDetails(depthContours.getSku());
if (depthContoursDetails != null) {
fetchInAppPurchase(depthContours, depthContoursDetails, purchase);
}
}
InAppPurchase contourLines = getContourLines();
if (hasDetails(contourLines.getSku())) {
Purchase purchase = getPurchase(contourLines.getSku());
SkuDetails contourLinesDetails = getSkuDetails(contourLines.getSku());
if (contourLinesDetails != null) {
fetchInAppPurchase(contourLines, contourLinesDetails, purchase);
}
}
Purchase fullVersionPurchase = getPurchase(fullVersion.getSku());
boolean fullVersionPurchased = fullVersionPurchase != null;
if (fullVersionPurchased) {
ctx.getSettings().FULL_VERSION_PURCHASED.set(true);
}
Purchase depthContoursPurchase = getPurchase(depthContours.getSku());
boolean depthContoursPurchased = depthContoursPurchase != null;
if (depthContoursPurchased) {
ctx.getSettings().DEPTH_CONTOURS_PURCHASED.set(true);
}
// Do we have the live updates?
boolean subscribedToLiveUpdates = false;
boolean subscribedToOsmAndPro = false;
boolean subscribedToMaps = false;
List<Purchase> subscriptionPurchases = new ArrayList<>();
for (InAppSubscription s : getSubscriptions().getAllSubscriptions()) {
Purchase purchase = getPurchase(s.getSku());
if (purchase != null || s.getState().isActive()) {
if (purchase != null) {
subscriptionPurchases.add(purchase);
}
if (!subscribedToLiveUpdates && purchases.isLiveUpdatesSubscription(s)) {
subscribedToLiveUpdates = true;
}
if (!subscribedToOsmAndPro && purchases.isOsmAndProSubscription(s)) {
subscribedToOsmAndPro = true;
}
if (!subscribedToMaps && purchases.isMapsSubscription(s)) {
subscribedToMaps = true;
}
}
}
if (!subscribedToLiveUpdates && ctx.getSettings().LIVE_UPDATES_PURCHASED.get()) {
ctx.getSettings().LIVE_UPDATES_PURCHASED.set(false);
} else if (subscribedToLiveUpdates) {
ctx.getSettings().LIVE_UPDATES_PURCHASED.set(true);
}
if (!subscribedToOsmAndPro && ctx.getSettings().OSMAND_PRO_PURCHASED.get()) {
ctx.getSettings().OSMAND_PRO_PURCHASED.set(false);
} else if (subscribedToOsmAndPro) {
ctx.getSettings().OSMAND_PRO_PURCHASED.set(true);
}
if (!subscribedToMaps && ctx.getSettings().OSMAND_MAPS_PURCHASED.get()) {
ctx.getSettings().OSMAND_MAPS_PURCHASED.set(false);
} else if (subscribedToMaps) {
ctx.getSettings().OSMAND_MAPS_PURCHASED.set(true);
}
if (!subscribedToLiveUpdates && !subscribedToOsmAndPro && !subscribedToMaps) {
onSubscriptionExpired();
}
lastValidationCheckTime = System.currentTimeMillis();
logDebug("User " + (subscribedToLiveUpdates ? "HAS" : "DOES NOT HAVE") + " live updates purchased.");
logDebug("User " + (subscribedToOsmAndPro ? "HAS" : "DOES NOT HAVE") + " OsmAnd Pro purchased.");
logDebug("User " + (subscribedToMaps ? "HAS" : "DOES NOT HAVE") + " Maps purchased.");
OsmandSettings settings = ctx.getSettings();
settings.INAPPS_READ.set(true);
List<Purchase> tokensToSend = new ArrayList<>();
if (subscriptionPurchases.size() > 0) {
List<String> tokensSent = Arrays.asList(settings.BILLING_PURCHASE_TOKENS_SENT.get().split(";"));
for (Purchase purchase : subscriptionPurchases) {
if (needRestoreUserInfo()) {
restoreUserInfo(purchase);
}
if (!tokensSent.contains(purchase.getSku())) {
tokensToSend.add(purchase);
}
}
}
List<PurchaseInfo> purchaseInfoList = new ArrayList<>();
for (Purchase purchase : tokensToSend) {
purchaseInfoList.add(getPurchaseInfo(purchase));
}
onSkuDetailsResponseDone(purchaseInfoList, userRequested);
}
private void onSubscriptionExpired() {
if (!isDepthContoursPurchased(ctx)) {
ctx.getSettings().getCustomRenderBooleanProperty("depthContours").set(false);
}
}
};
}
use of net.osmand.plus.settings.backend.OsmandSettings in project Osmand by osmandapp.
the class NavigationScreen method updateCompass.
private void updateCompass() {
OsmandSettings settings = getApp().getSettings();
boolean nightMode = getCarContext().isDarkMode();
if (settings.ROTATE_MAP.get() == OsmandSettings.ROTATE_MAP_NONE) {
compassResId = !nightMode ? R.drawable.ic_compass_niu_white : R.drawable.ic_compass_niu;
} else if (settings.ROTATE_MAP.get() == OsmandSettings.ROTATE_MAP_BEARING) {
compassResId = !nightMode ? R.drawable.ic_compass_bearing_white : R.drawable.ic_compass_bearing;
} else {
compassResId = !nightMode ? R.drawable.ic_compass_white : R.drawable.ic_compass;
}
}
Aggregations