purchaseInfoList = new ArrayList<>();
+ for (InAppPurchaseData purchase : tokensToSend) {
+ purchaseInfoList.add(getPurchaseInfo(purchase));
+ }
+ onSkuDetailsResponseDone(purchaseInfoList);
+ }
+ };
+ }
+
+ private IapClient getIapClient() {
+ return Iap.getIapClient((Activity) uiActivity);
+ }
+
+ // Call when a purchase is finished
+ private void onPurchaseFinished(InAppPurchaseData purchase) {
+ logDebug("Purchase finished: " + purchase.getProductId());
+ onPurchaseDone(getPurchaseInfo(purchase));
+ }
+
+ @Override
+ protected boolean isBillingManagerExists() {
+ return false;
+ }
+
+ @Override
+ protected void destroyBillingManager() {
+ // non implemented
+ }
+
+ @Override
+ public boolean onActivityResult(@NonNull Activity activity, int requestCode, int resultCode, Intent data) {
+ if (requestCode == Constants.REQ_CODE_BUY_SUB) {
+ boolean succeed = false;
+ if (resultCode == Activity.RESULT_OK) {
+ PurchaseResultInfo result = SubscriptionUtils.getPurchaseResult(activity, data);
+ if (result != null) {
+ switch (result.getReturnCode()) {
+ case OrderStatusCode.ORDER_STATE_CANCEL:
+ logDebug("Purchase cancelled");
+ break;
+ case OrderStatusCode.ORDER_STATE_FAILED:
+ inventoryRequestPending = true;
+ logDebug("Purchase failed");
+ break;
+ case OrderStatusCode.ORDER_PRODUCT_OWNED:
+ inventoryRequestPending = true;
+ logDebug("Product already owned");
+ break;
+ case OrderStatusCode.ORDER_STATE_SUCCESS:
+ inventoryRequestPending = true;
+ InAppPurchaseData purchaseData = SubscriptionUtils.getInAppPurchaseData(null,
+ result.getInAppPurchaseData(), result.getInAppDataSignature());
+ if (purchaseData != null) {
+ onPurchaseFinished(purchaseData);
+ succeed = true;
+ } else {
+ logDebug("Purchase failed");
+ }
+ break;
+ default:
+ break;
+ }
+ } else {
+ logDebug("Purchase failed");
+ }
+ } else {
+ logDebug("Purchase cancelled");
+ }
+ if (!succeed) {
+ stop(true);
+ }
+ return true;
+ } else if (requestCode == Constants.REQ_CODE_BUY_INAPP) {
+ boolean succeed = false;
+ if (data == null) {
+ logDebug("data is null");
+ } else {
+ PurchaseResultInfo buyResultInfo = Iap.getIapClient(activity).parsePurchaseResultInfoFromIntent(data);
+ switch (buyResultInfo.getReturnCode()) {
+ case OrderStatusCode.ORDER_STATE_CANCEL:
+ logDebug("Order has been canceled");
+ break;
+ case OrderStatusCode.ORDER_STATE_FAILED:
+ inventoryRequestPending = true;
+ logDebug("Order has been failed");
+ break;
+ case OrderStatusCode.ORDER_PRODUCT_OWNED:
+ inventoryRequestPending = true;
+ logDebug("Product already owned");
+ break;
+ case OrderStatusCode.ORDER_STATE_SUCCESS:
+ InAppPurchaseData purchaseData = InAppUtils.getInAppPurchaseData(null,
+ buyResultInfo.getInAppPurchaseData(), buyResultInfo.getInAppDataSignature());
+ if (purchaseData != null) {
+ onPurchaseFinished(purchaseData);
+ succeed = true;
+ } else {
+ logDebug("Purchase failed");
+ }
+ break;
+ default:
+ break;
+ }
+ }
+ if (!succeed) {
+ stop(true);
+ }
+ return true;
+ }
+ return false;
+ }
+}
diff --git a/OsmAnd/src-huawei/net/osmand/plus/inapp/InAppPurchasesImpl.java b/OsmAnd/src-huawei/net/osmand/plus/inapp/InAppPurchasesImpl.java
new file mode 100644
index 0000000000..4ed0021b6f
--- /dev/null
+++ b/OsmAnd/src-huawei/net/osmand/plus/inapp/InAppPurchasesImpl.java
@@ -0,0 +1,196 @@
+package net.osmand.plus.inapp;
+
+import android.content.Context;
+
+import androidx.annotation.NonNull;
+import androidx.annotation.Nullable;
+
+import com.huawei.hms.iap.entity.ProductInfo;
+
+import net.osmand.plus.OsmandApplication;
+import net.osmand.plus.R;
+
+public class InAppPurchasesImpl extends InAppPurchases {
+
+ private static final InAppPurchase FULL_VERSION = new InAppPurchaseFullVersion();
+ private static final InAppPurchaseDepthContoursFree DEPTH_CONTOURS_FREE = new InAppPurchaseDepthContoursFree();
+ private static final InAppPurchaseContourLinesFree CONTOUR_LINES_FREE = new InAppPurchaseContourLinesFree();
+
+
+ private static final InAppSubscription[] LIVE_UPDATES_FREE = new InAppSubscription[]{
+ new InAppPurchaseLiveUpdatesMonthlyFree(),
+ new InAppPurchaseLiveUpdates3MonthsFree(),
+ new InAppPurchaseLiveUpdatesAnnualFree()
+ };
+
+ public InAppPurchasesImpl(OsmandApplication ctx) {
+ super(ctx);
+ fullVersion = FULL_VERSION;
+ depthContours = DEPTH_CONTOURS_FREE;
+ contourLines = CONTOUR_LINES_FREE;
+ inAppPurchases = new InAppPurchase[] { fullVersion, depthContours, contourLines };
+
+ liveUpdates = new LiveUpdatesInAppPurchasesFree();
+ for (InAppSubscription s : liveUpdates.getAllSubscriptions()) {
+ if (s instanceof InAppPurchaseLiveUpdatesMonthly) {
+ if (s.isDiscounted()) {
+ discountedMonthlyLiveUpdates = s;
+ } else {
+ monthlyLiveUpdates = s;
+ }
+ }
+ }
+ }
+
+ @Override
+ public boolean isFullVersion(String sku) {
+ return FULL_VERSION.getSku().equals(sku);
+ }
+
+ @Override
+ public boolean isDepthContours(String sku) {
+ return DEPTH_CONTOURS_FREE.getSku().equals(sku);
+ }
+
+ @Override
+ public boolean isContourLines(String sku) {
+ return CONTOUR_LINES_FREE.getSku().equals(sku);
+ }
+
+ @Override
+ public boolean isLiveUpdates(String sku) {
+ for (InAppPurchase p : LIVE_UPDATES_FREE) {
+ if (p.getSku().equals(sku)) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ private static class InAppPurchaseFullVersion extends InAppPurchase {
+
+ private static final String SKU_FULL_VERSION_PRICE = "net.osmand.huawei.full";
+
+ InAppPurchaseFullVersion() {
+ super(SKU_FULL_VERSION_PRICE);
+ }
+
+ @Override
+ public String getDefaultPrice(Context ctx) {
+ return ctx.getString(R.string.full_version_price);
+ }
+ }
+
+ private static class InAppPurchaseDepthContoursFree extends InAppPurchaseDepthContours {
+
+ private static final String SKU_DEPTH_CONTOURS_FREE = "net.osmand.huawei.seadepth";
+
+ InAppPurchaseDepthContoursFree() {
+ super(SKU_DEPTH_CONTOURS_FREE);
+ }
+ }
+
+ private static class InAppPurchaseContourLinesFree extends InAppPurchaseContourLines {
+
+ private static final String SKU_CONTOUR_LINES_FREE = "net.osmand.huawei.contourlines";
+
+ InAppPurchaseContourLinesFree() {
+ super(SKU_CONTOUR_LINES_FREE);
+ }
+ }
+
+ private static class InAppPurchaseLiveUpdatesMonthlyFree extends InAppPurchaseLiveUpdatesMonthly {
+
+ private static final String SKU_LIVE_UPDATES_MONTHLY_HW_FREE = "net.osmand.huawei.monthly";
+
+ InAppPurchaseLiveUpdatesMonthlyFree() {
+ super(SKU_LIVE_UPDATES_MONTHLY_HW_FREE, 1);
+ }
+
+ private InAppPurchaseLiveUpdatesMonthlyFree(@NonNull String sku) {
+ super(sku);
+ }
+
+ @Nullable
+ @Override
+ protected InAppSubscription newInstance(@NonNull String sku) {
+ return sku.startsWith(getSkuNoVersion()) ? new InAppPurchaseLiveUpdatesMonthlyFree(sku) : null;
+ }
+ }
+
+ private static class InAppPurchaseLiveUpdates3MonthsFree extends InAppPurchaseLiveUpdates3Months {
+
+ private static final String SKU_LIVE_UPDATES_3_MONTHS_HW_FREE = "net.osmand.huawei.3months";
+
+ InAppPurchaseLiveUpdates3MonthsFree() {
+ super(SKU_LIVE_UPDATES_3_MONTHS_HW_FREE, 1);
+ }
+
+ private InAppPurchaseLiveUpdates3MonthsFree(@NonNull String sku) {
+ super(sku);
+ }
+
+ @Nullable
+ @Override
+ protected InAppSubscription newInstance(@NonNull String sku) {
+ return sku.startsWith(getSkuNoVersion()) ? new InAppPurchaseLiveUpdates3MonthsFree(sku) : null;
+ }
+ }
+
+ private static class InAppPurchaseLiveUpdatesAnnualFree extends InAppPurchaseLiveUpdatesAnnual {
+
+ private static final String SKU_LIVE_UPDATES_ANNUAL_HW_FREE = "net.osmand.huawei.annual";
+
+ InAppPurchaseLiveUpdatesAnnualFree() {
+ super(SKU_LIVE_UPDATES_ANNUAL_HW_FREE, 1);
+ }
+
+ private InAppPurchaseLiveUpdatesAnnualFree(@NonNull String sku) {
+ super(sku);
+ }
+
+ @Nullable
+ @Override
+ protected InAppSubscription newInstance(@NonNull String sku) {
+ return sku.startsWith(getSkuNoVersion()) ? new InAppPurchaseLiveUpdatesAnnualFree(sku) : null;
+ }
+ }
+
+ public static class InAppPurchaseLiveUpdatesOldSubscription extends InAppSubscription {
+
+ private ProductInfo info;
+
+ InAppPurchaseLiveUpdatesOldSubscription(@NonNull ProductInfo info) {
+ super(info.getProductId(), true);
+ this.info = info;
+ }
+
+ @Override
+ public String getDefaultPrice(Context ctx) {
+ return "";
+ }
+
+ @Override
+ public CharSequence getTitle(Context ctx) {
+ return info.getProductName();
+ }
+
+ @Override
+ public CharSequence getDescription(@NonNull Context ctx) {
+ return info.getProductDesc();
+ }
+
+ @Nullable
+ @Override
+ protected InAppSubscription newInstance(@NonNull String sku) {
+ return null;
+ }
+ }
+
+ private static class LiveUpdatesInAppPurchasesFree extends InAppSubscriptionList {
+
+ public LiveUpdatesInAppPurchasesFree() {
+ super(LIVE_UPDATES_FREE);
+ }
+ }
+}
diff --git a/OsmAnd/src-huawei/net/osmand/plus/inapp/InAppUtils.java b/OsmAnd/src-huawei/net/osmand/plus/inapp/InAppUtils.java
new file mode 100644
index 0000000000..445727de96
--- /dev/null
+++ b/OsmAnd/src-huawei/net/osmand/plus/inapp/InAppUtils.java
@@ -0,0 +1,49 @@
+package net.osmand.plus.inapp;
+
+import android.util.Log;
+
+import androidx.annotation.NonNull;
+import androidx.annotation.Nullable;
+
+import com.huawei.hms.iap.entity.InAppPurchaseData;
+import com.huawei.hms.iap.entity.OwnedPurchasesResult;
+
+import org.json.JSONException;
+
+public class InAppUtils {
+ private static final String TAG = "InAppUtils";
+
+ @Nullable
+ public static InAppPurchaseData getPurchaseData(OwnedPurchasesResult result, String productId) {
+ if (result == null || result.getInAppPurchaseDataList() == null) {
+ Log.i(TAG, "result is null");
+ return null;
+ }
+ int index = result.getItemList().indexOf(productId);
+ if (index != -1) {
+ String data = result.getInAppPurchaseDataList().get(index);
+ String signature = result.getInAppSignature().get(index);
+ return getInAppPurchaseData(productId, data, signature);
+ }
+ return null;
+ }
+
+ @Nullable
+ public static InAppPurchaseData getInAppPurchaseData(@Nullable String productId, @NonNull String data, @NonNull String signature) {
+ if (CipherUtil.doCheck(data, signature, CipherUtil.getPublicKey())) {
+ try {
+ InAppPurchaseData purchaseData = new InAppPurchaseData(data);
+ if (purchaseData.getPurchaseState() == InAppPurchaseData.PurchaseState.PURCHASED) {
+ if (productId == null || productId.equals(purchaseData.getProductId())) {
+ return purchaseData;
+ }
+ }
+ } catch (JSONException e) {
+ Log.e(TAG, "delivery: " + e.getMessage());
+ }
+ } else {
+ Log.e(TAG, "delivery: verify signature error");
+ }
+ return null;
+ }
+}
\ No newline at end of file
diff --git a/OsmAnd/src-huawei/net/osmand/plus/inapp/SubscriptionUtils.java b/OsmAnd/src-huawei/net/osmand/plus/inapp/SubscriptionUtils.java
new file mode 100755
index 0000000000..3b249cb300
--- /dev/null
+++ b/OsmAnd/src-huawei/net/osmand/plus/inapp/SubscriptionUtils.java
@@ -0,0 +1,138 @@
+/**
+ * Copyright 2020. Huawei Technologies Co., Ltd. All rights reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package net.osmand.plus.inapp;
+
+import android.app.Activity;
+import android.content.Intent;
+import android.util.Log;
+
+import androidx.annotation.NonNull;
+import androidx.annotation.Nullable;
+
+import com.huawei.hms.iap.Iap;
+import com.huawei.hms.iap.entity.InAppPurchaseData;
+import com.huawei.hms.iap.entity.OrderStatusCode;
+import com.huawei.hms.iap.entity.OwnedPurchasesResult;
+import com.huawei.hms.iap.entity.PurchaseResultInfo;
+
+import org.json.JSONException;
+
+import java.util.List;
+
+/**
+ * Util for Subscription function.
+ *
+ * @since 2019/12/9
+ */
+public class SubscriptionUtils {
+ private static final String TAG = "SubscriptionUtils";
+
+ /**
+ * Decide whether to offer subscription service
+ *
+ * @param result the OwnedPurchasesResult from IapClient.obtainOwnedPurchases
+ * @param productId subscription product id
+ * @return decision result
+ */
+ @Nullable
+ public static InAppPurchaseData getPurchaseData(OwnedPurchasesResult result, String productId) {
+ if (null == result) {
+ Log.e(TAG, "OwnedPurchasesResult is null");
+ return null;
+ }
+ List dataList = result.getInAppPurchaseDataList();
+ List signatureList = result.getInAppSignature();
+ for (int i = 0; i < dataList.size(); i++) {
+ String data = dataList.get(i);
+ String signature = signatureList.get(i);
+ InAppPurchaseData purchaseData = getInAppPurchaseData(productId, data, signature);
+ if (purchaseData != null) {
+ return purchaseData;
+ }
+ }
+ return null;
+ }
+
+ @Nullable
+ public static InAppPurchaseData getInAppPurchaseData(@Nullable String productId, @NonNull String data, @NonNull String signature) {
+ try {
+ InAppPurchaseData purchaseData = new InAppPurchaseData(data);
+ if (productId == null || productId.equals(purchaseData.getProductId())) {
+ boolean credible = CipherUtil.doCheck(data, signature, CipherUtil.getPublicKey());
+ if (credible) {
+ return purchaseData.isSubValid() ? purchaseData : null;
+ } else {
+ Log.e(TAG, "check the data signature fail");
+ return null;
+ }
+ }
+ } catch (JSONException e) {
+ Log.e(TAG, "parse InAppPurchaseData JSONException", e);
+ return null;
+ }
+ return null;
+ }
+
+ /**
+ * Parse PurchaseResult data from intent
+ *
+ * @param activity Activity
+ * @param data the intent from onActivityResult
+ * @return PurchaseResultInfo
+ */
+ public static PurchaseResultInfo getPurchaseResult(Activity activity, Intent data) {
+ PurchaseResultInfo purchaseResultInfo = Iap.getIapClient(activity).parsePurchaseResultInfoFromIntent(data);
+ if (null == purchaseResultInfo) {
+ Log.e(TAG, "PurchaseResultInfo is null");
+ } else {
+ int returnCode = purchaseResultInfo.getReturnCode();
+ String errMsg = purchaseResultInfo.getErrMsg();
+ switch (returnCode) {
+ case OrderStatusCode.ORDER_PRODUCT_OWNED:
+ Log.w(TAG, "you have owned this product");
+ break;
+ case OrderStatusCode.ORDER_STATE_SUCCESS:
+ boolean credible = CipherUtil.doCheck(purchaseResultInfo.getInAppPurchaseData(), purchaseResultInfo.getInAppDataSignature(), CipherUtil
+ .getPublicKey());
+ if (credible) {
+ try {
+ InAppPurchaseData inAppPurchaseData = new InAppPurchaseData(purchaseResultInfo.getInAppPurchaseData());
+ if (!inAppPurchaseData.isSubValid()) {
+ return getFailedPurchaseResultInfo();
+ }
+ } catch (JSONException e) {
+ Log.e(TAG, "parse InAppPurchaseData JSONException", e);
+ return getFailedPurchaseResultInfo();
+ }
+ } else {
+ Log.e(TAG, "check the data signature fail");
+ return getFailedPurchaseResultInfo();
+ }
+ default:
+ Log.e(TAG, "returnCode: " + returnCode + " , errMsg: " + errMsg);
+ break;
+ }
+ }
+ return purchaseResultInfo;
+ }
+
+ private static PurchaseResultInfo getFailedPurchaseResultInfo() {
+ PurchaseResultInfo info = new PurchaseResultInfo();
+ info.setReturnCode(OrderStatusCode.ORDER_STATE_FAILED);
+ return info;
+ }
+}
diff --git a/OsmAnd/src/net/osmand/FileUtils.java b/OsmAnd/src/net/osmand/FileUtils.java
index 426c5c10c2..1f9a755be5 100644
--- a/OsmAnd/src/net/osmand/FileUtils.java
+++ b/OsmAnd/src/net/osmand/FileUtils.java
@@ -205,10 +205,7 @@ public class FileUtils {
if (!src.exists()) {
return null;
}
- File tempDir = app.getAppPath(IndexConstants.TEMP_DIR);
- if (!tempDir.exists()) {
- tempDir.mkdirs();
- }
+ File tempDir = getTempDir(app);
File dest = new File(tempDir, src.getName());
try {
Algorithms.fileCopy(src, dest);
@@ -218,6 +215,27 @@ public class FileUtils {
return dest;
}
+ public static File getTempDir(OsmandApplication app) {
+ File tempDir = app.getAppPath(IndexConstants.TEMP_DIR);
+ if (!tempDir.exists()) {
+ tempDir.mkdirs();
+ }
+ return tempDir;
+ }
+
+ public static boolean isWritable(File dirToTest) {
+ boolean isWriteable;
+ try {
+ dirToTest.mkdirs();
+ File writeTestFile = File.createTempFile("osmand_", ".tmp", dirToTest);
+ isWriteable = writeTestFile.exists();
+ writeTestFile.delete();
+ } catch (IOException e) {
+ isWriteable = false;
+ }
+ return isWriteable;
+ }
+
public interface RenameCallback {
void renamedTo(File file);
}
diff --git a/OsmAnd/src/net/osmand/aidl/ConnectedApp.java b/OsmAnd/src/net/osmand/aidl/ConnectedApp.java
index 02f412887e..be25ab931d 100644
--- a/OsmAnd/src/net/osmand/aidl/ConnectedApp.java
+++ b/OsmAnd/src/net/osmand/aidl/ConnectedApp.java
@@ -18,10 +18,10 @@ import net.osmand.AndroidUtils;
import net.osmand.plus.ContextMenuAdapter;
import net.osmand.plus.ContextMenuItem;
import net.osmand.plus.OsmandApplication;
+import net.osmand.plus.settings.backend.CommonPreference;
import net.osmand.plus.R;
import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.settings.backend.ApplicationMode;
-import net.osmand.plus.settings.backend.OsmandSettings.CommonPreference;
import net.osmand.plus.views.OsmandMapLayer;
import net.osmand.plus.views.layers.AidlMapLayer;
import net.osmand.plus.views.layers.MapInfoLayer;
diff --git a/OsmAnd/src/net/osmand/aidl/OsmandAidlApi.java b/OsmAnd/src/net/osmand/aidl/OsmandAidlApi.java
index 07c545a424..6329d5db2e 100644
--- a/OsmAnd/src/net/osmand/aidl/OsmandAidlApi.java
+++ b/OsmAnd/src/net/osmand/aidl/OsmandAidlApi.java
@@ -26,9 +26,11 @@ import com.google.gson.reflect.TypeToken;
import net.osmand.AndroidUtils;
import net.osmand.CallbackWithObject;
+import net.osmand.FileUtils;
import net.osmand.GPXUtilities;
import net.osmand.GPXUtilities.GPXFile;
import net.osmand.GPXUtilities.GPXTrackAnalysis;
+import net.osmand.IProgress;
import net.osmand.IndexConstants;
import net.osmand.Location;
import net.osmand.PlatformUtil;
@@ -80,6 +82,7 @@ import net.osmand.plus.settings.backend.ApplicationMode;
import net.osmand.plus.settings.backend.OsmAndAppCustomization;
import net.osmand.plus.settings.backend.OsmandSettings;
import net.osmand.plus.settings.backend.SettingsHelper;
+import net.osmand.plus.settings.backend.ExportSettingsType;
import net.osmand.plus.views.OsmandMapLayer;
import net.osmand.plus.views.OsmandMapTileView;
import net.osmand.plus.views.layers.AidlMapLayer;
@@ -129,11 +132,13 @@ import static net.osmand.aidlapi.OsmandAidlConstants.COPY_FILE_PART_SIZE_LIMIT_E
import static net.osmand.aidlapi.OsmandAidlConstants.COPY_FILE_UNSUPPORTED_FILE_TYPE_ERROR;
import static net.osmand.aidlapi.OsmandAidlConstants.COPY_FILE_WRITE_LOCK_ERROR;
import static net.osmand.aidlapi.OsmandAidlConstants.OK_RESPONSE;
+import static net.osmand.plus.FavouritesDbHelper.FILE_TO_SAVE;
import static net.osmand.plus.helpers.ExternalApiHelper.PARAM_NT_DIRECTION_LANES;
import static net.osmand.plus.helpers.ExternalApiHelper.PARAM_NT_DIRECTION_NAME;
import static net.osmand.plus.helpers.ExternalApiHelper.PARAM_NT_DIRECTION_TURN;
import static net.osmand.plus.helpers.ExternalApiHelper.PARAM_NT_DISTANCE;
import static net.osmand.plus.helpers.ExternalApiHelper.PARAM_NT_IMMINENT;
+import static net.osmand.plus.settings.backend.SettingsHelper.REPLACE_KEY;
public class OsmandAidlApi {
@@ -204,7 +209,7 @@ public class OsmandAidlApi {
private static final ApplicationMode DEFAULT_PROFILE = ApplicationMode.CAR;
- private static final ApplicationMode[] VALID_PROFILES = new ApplicationMode[] {
+ private static final ApplicationMode[] VALID_PROFILES = new ApplicationMode[]{
ApplicationMode.CAR,
ApplicationMode.BICYCLE,
ApplicationMode.PEDESTRIAN
@@ -284,7 +289,7 @@ public class OsmandAidlApi {
}
private void initOsmandTelegram() {
- String[] packages = new String[] {"net.osmand.telegram", "net.osmand.telegram.debug"};
+ String[] packages = new String[]{"net.osmand.telegram", "net.osmand.telegram.debug"};
Intent intent = new Intent("net.osmand.telegram.InitApp");
for (String pack : packages) {
intent.setComponent(new ComponentName(pack, "net.osmand.telegram.InitAppBroadcastReceiver"));
@@ -1015,7 +1020,7 @@ public class OsmandAidlApi {
}
if (!newName.equals(f.getName()) || !newDescription.equals(f.getDescription()) ||
!newCategory.equals(f.getCategory()) || !newAddress.equals(f.getAddress())) {
- favoritesHelper.editFavouriteName(f, newName, newCategory, newDescription,newAddress);
+ favoritesHelper.editFavouriteName(f, newName, newCategory, newDescription, newAddress);
}
refreshMap();
return true;
@@ -2260,6 +2265,21 @@ public class OsmandAidlApi {
return false;
}
+ public boolean importProfileV2(final Uri profileUri, ArrayList settingsTypeKeys, boolean replace,
+ String latestChanges, int version) {
+ if (profileUri != null) {
+ Bundle bundle = new Bundle();
+ bundle.putStringArrayList(SettingsHelper.SETTINGS_TYPE_LIST_KEY, settingsTypeKeys);
+ bundle.putBoolean(REPLACE_KEY, replace);
+ bundle.putString(SettingsHelper.SETTINGS_LATEST_CHANGES_KEY, latestChanges);
+ bundle.putInt(SettingsHelper.SETTINGS_VERSION_KEY, version);
+
+ MapActivity.launchMapActivityMoveToTop(app, null, profileUri, bundle);
+ return true;
+ }
+ return false;
+ }
+
public void registerLayerContextMenu(ContextMenuAdapter adapter, MapActivity mapActivity) {
for (ConnectedApp connectedApp : getConnectedApps()) {
if (!connectedApp.getLayers().isEmpty()) {
@@ -2323,6 +2343,25 @@ public class OsmandAidlApi {
return true;
}
+ public boolean exportProfile(String appModeKey, List settingsTypesKeys) {
+ ApplicationMode appMode = ApplicationMode.valueOfStringKey(appModeKey, null);
+ if (app != null && appMode != null) {
+ List settingsTypes = new ArrayList<>();
+ for (String key : settingsTypesKeys) {
+ settingsTypes.add(ExportSettingsType.valueOf(key));
+ }
+ List settingsItems = new ArrayList<>();
+ settingsItems.add(new SettingsHelper.ProfileSettingsItem(app, appMode));
+ File exportDir = app.getSettings().getExternalStorageDirectory();
+ String fileName = appMode.toHumanString();
+ SettingsHelper settingsHelper = app.getSettingsHelper();
+ settingsItems.addAll(settingsHelper.getFilteredSettingsItems(settingsHelper.getAdditionalData(), settingsTypes));
+ settingsHelper.exportSettings(exportDir, fileName, null, settingsItems, true);
+ return true;
+ }
+ return false;
+ }
+
private static class FileCopyInfo {
long startTime;
long lastAccessTime;
@@ -2349,13 +2388,35 @@ public class OsmandAidlApi {
}
}
- private int copyFileImpl(String fileName, byte[] filePartData, long startTime, boolean done, String destinationDir) {
- File file = app.getAppPath(IndexConstants.TEMP_DIR + fileName);
- File tempDir = app.getAppPath(IndexConstants.TEMP_DIR);
- if (!tempDir.exists()) {
- tempDir.mkdirs();
+ int copyFileV2(String destinationDir, String fileName, byte[] filePartData, long startTime, boolean done) {
+ if (Algorithms.isEmpty(fileName) || filePartData == null) {
+ return COPY_FILE_PARAMS_ERROR;
}
- File destFile = app.getAppPath(destinationDir + fileName);
+ if (filePartData.length > COPY_FILE_PART_SIZE_LIMIT) {
+ return COPY_FILE_PART_SIZE_LIMIT_ERROR;
+ }
+ int result = copyFileImpl(fileName, filePartData, startTime, done, destinationDir);
+ if (done) {
+ if (fileName.endsWith(IndexConstants.BINARY_MAP_INDEX_EXT) && IndexConstants.MAPS_PATH.equals(destinationDir)) {
+ app.getResourceManager().reloadIndexes(IProgress.EMPTY_PROGRESS, new ArrayList());
+ app.getDownloadThread().updateLoadedFiles();
+ } else if (fileName.endsWith(IndexConstants.GPX_FILE_EXT)) {
+ if (destinationDir.startsWith(IndexConstants.GPX_INDEX_DIR)
+ && !FILE_TO_SAVE.equals(fileName)) {
+ destinationDir = destinationDir.replaceFirst(IndexConstants.GPX_INDEX_DIR, "");
+ showGpx(new File(destinationDir, fileName).getPath());
+ } else if (destinationDir.isEmpty() && FILE_TO_SAVE.equals(fileName)) {
+ app.getFavorites().loadFavorites();
+ }
+ }
+ }
+ return result;
+ }
+
+ private int copyFileImpl(String fileName, byte[] filePartData, long startTime, boolean done, String destinationDir) {
+ File tempDir = FileUtils.getTempDir(app);
+ File file = new File(tempDir, fileName);
+ File destFile = app.getAppPath(new File(destinationDir, fileName).getPath());
long currentTime = System.currentTimeMillis();
try {
FileCopyInfo info = copyFilesCache.get(fileName);
diff --git a/OsmAnd/src/net/osmand/aidl/OsmandAidlService.java b/OsmAnd/src/net/osmand/aidl/OsmandAidlService.java
index f1c9493fc8..99e888973f 100644
--- a/OsmAnd/src/net/osmand/aidl/OsmandAidlService.java
+++ b/OsmAnd/src/net/osmand/aidl/OsmandAidlService.java
@@ -1299,7 +1299,8 @@ public class OsmandAidlService extends Service implements AidlCallbackListener {
public boolean importProfile(ProfileSettingsParams params) {
try {
OsmandAidlApi api = getApi("importProfile");
- return api != null && api.importProfile(params.getProfileSettingsUri(), params.getLatestChanges(), params.getVersion());
+ return api != null && api.importProfile(params.getProfileSettingsUri(), params.getLatestChanges(),
+ params.getVersion());
} catch (Exception e) {
handleException(e);
return false;
diff --git a/OsmAnd/src/net/osmand/aidl/OsmandAidlServiceV2.java b/OsmAnd/src/net/osmand/aidl/OsmandAidlServiceV2.java
index 333fd01895..7c69be1e94 100644
--- a/OsmAnd/src/net/osmand/aidl/OsmandAidlServiceV2.java
+++ b/OsmAnd/src/net/osmand/aidl/OsmandAidlServiceV2.java
@@ -85,6 +85,7 @@ import net.osmand.aidlapi.note.StartVideoRecordingParams;
import net.osmand.aidlapi.note.StopRecordingParams;
import net.osmand.aidlapi.note.TakePhotoNoteParams;
import net.osmand.aidlapi.plugins.PluginParams;
+import net.osmand.aidlapi.profile.ExportProfileParams;
import net.osmand.aidlapi.quickaction.QuickActionInfoParams;
import net.osmand.aidlapi.quickaction.QuickActionParams;
import net.osmand.aidlapi.search.SearchParams;
@@ -1091,7 +1092,8 @@ public class OsmandAidlServiceV2 extends Service implements AidlCallbackListener
if (api == null) {
return CANNOT_ACCESS_API_ERROR;
}
- return api.copyFile(params.getFileName(), params.getFilePartData(), params.getStartTime(), params.isDone());
+ return api.copyFileV2(params.getDestinationDir(), params.getFileName(), params.getFilePartData(),
+ params.getStartTime(), params.isDone());
} catch (Exception e) {
handleException(e);
return UNKNOWN_API_ERROR;
@@ -1258,7 +1260,19 @@ public class OsmandAidlServiceV2 extends Service implements AidlCallbackListener
public boolean importProfile(ProfileSettingsParams params) {
try {
OsmandAidlApi api = getApi("importProfile");
- return api != null && api.importProfile(params.getProfileSettingsUri(), params.getLatestChanges(), params.getVersion());
+ return api != null && api.importProfileV2(params.getProfileSettingsUri(), params.getSettingsTypeKeys(),
+ params.isReplace(), params.getLatestChanges(), params.getVersion());
+ } catch (Exception e) {
+ handleException(e);
+ return false;
+ }
+ }
+
+ @Override
+ public boolean exportProfile(ExportProfileParams params) {
+ try {
+ OsmandAidlApi api = getApi("exportProfile");
+ return api != null && api.exportProfile(params.getProfile(), params.getSettingsTypeKeys());
} catch (Exception e) {
handleException(e);
return false;
diff --git a/OsmAnd/src/net/osmand/core/android/MapRendererContext.java b/OsmAnd/src/net/osmand/core/android/MapRendererContext.java
index 03d88fa11c..d65880877c 100644
--- a/OsmAnd/src/net/osmand/core/android/MapRendererContext.java
+++ b/OsmAnd/src/net/osmand/core/android/MapRendererContext.java
@@ -25,7 +25,7 @@ import net.osmand.core.jni.ResolvedMapStyle;
import net.osmand.core.jni.SwigUtilities;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.settings.backend.OsmandSettings;
-import net.osmand.plus.settings.backend.OsmandSettings.CommonPreference;
+import net.osmand.plus.settings.backend.CommonPreference;
import net.osmand.plus.render.RendererRegistry;
import net.osmand.render.RenderingRuleProperty;
import net.osmand.render.RenderingRuleStorageProperties;
diff --git a/OsmAnd/src/net/osmand/data/FavouritePoint.java b/OsmAnd/src/net/osmand/data/FavouritePoint.java
index e5f4f6c8ea..7205b4a422 100644
--- a/OsmAnd/src/net/osmand/data/FavouritePoint.java
+++ b/OsmAnd/src/net/osmand/data/FavouritePoint.java
@@ -13,8 +13,8 @@ import androidx.annotation.StringRes;
import net.osmand.GPXUtilities.WptPt;
import net.osmand.plus.FavouritesDbHelper;
import net.osmand.plus.OsmandApplication;
-import net.osmand.plus.settings.backend.OsmandSettings.BooleanPreference;
-import net.osmand.plus.settings.backend.OsmandSettings.OsmandPreference;
+import net.osmand.plus.settings.backend.BooleanPreference;
+import net.osmand.plus.settings.backend.OsmandPreference;
import net.osmand.plus.R;
import net.osmand.plus.parkingpoint.ParkingPositionPlugin;
import net.osmand.util.Algorithms;
diff --git a/OsmAnd/src/net/osmand/plus/AppInitializer.java b/OsmAnd/src/net/osmand/plus/AppInitializer.java
index 2837bff6f8..78364460a7 100644
--- a/OsmAnd/src/net/osmand/plus/AppInitializer.java
+++ b/OsmAnd/src/net/osmand/plus/AppInitializer.java
@@ -28,7 +28,7 @@ import net.osmand.map.OsmandRegions.RegionTranslation;
import net.osmand.map.WorldRegion;
import net.osmand.osm.AbstractPoiType;
import net.osmand.osm.MapPoiTypes;
-import net.osmand.plus.activities.DayNightHelper;
+import net.osmand.plus.helpers.DayNightHelper;
import net.osmand.plus.activities.LocalIndexHelper;
import net.osmand.plus.activities.LocalIndexInfo;
import net.osmand.plus.activities.SavingTrackHelper;
@@ -38,7 +38,7 @@ import net.osmand.plus.download.ui.AbstractLoadLocalIndexTask;
import net.osmand.plus.helpers.AvoidSpecificRoads;
import net.osmand.plus.helpers.LockHelper;
import net.osmand.plus.helpers.WaypointHelper;
-import net.osmand.plus.inapp.InAppPurchaseHelper;
+import net.osmand.plus.inapp.InAppPurchaseHelperImpl;
import net.osmand.plus.liveupdates.LiveUpdatesHelper;
import net.osmand.plus.mapmarkers.MapMarkersDbHelper;
import net.osmand.plus.monitoring.LiveMonitoringHelper;
@@ -428,7 +428,7 @@ public class AppInitializer implements IProgress {
}
getLazyRoutingConfig();
app.applyTheme(app);
- app.inAppPurchaseHelper = startupInit(new InAppPurchaseHelper(app), InAppPurchaseHelper.class);
+ app.inAppPurchaseHelper = startupInit(new InAppPurchaseHelperImpl(app), InAppPurchaseHelperImpl.class);
app.poiTypes = startupInit(MapPoiTypes.getDefaultNoInit(), MapPoiTypes.class);
app.transportRoutingHelper = startupInit(new TransportRoutingHelper(app), TransportRoutingHelper.class);
app.routingHelper = startupInit(new RoutingHelper(app), RoutingHelper.class);
diff --git a/OsmAnd/src/net/osmand/plus/AppVersionUpgradeOnInit.java b/OsmAnd/src/net/osmand/plus/AppVersionUpgradeOnInit.java
index c49f0a12a2..9eeec4542b 100644
--- a/OsmAnd/src/net/osmand/plus/AppVersionUpgradeOnInit.java
+++ b/OsmAnd/src/net/osmand/plus/AppVersionUpgradeOnInit.java
@@ -3,7 +3,30 @@ package net.osmand.plus;
import android.annotation.SuppressLint;
import android.content.SharedPreferences;
+import com.google.gson.Gson;
+import com.google.gson.GsonBuilder;
+import com.google.gson.reflect.TypeToken;
+
+import net.osmand.data.FavouritePoint.SpecialPointType;
+import net.osmand.data.LatLon;
+import net.osmand.plus.AppInitializer.AppInitializeListener;
+import net.osmand.plus.AppInitializer.InitEvents;
+import net.osmand.plus.api.SettingsAPI;
+import net.osmand.plus.settings.backend.ApplicationMode;
+import net.osmand.plus.settings.backend.CommonPreference;
+import net.osmand.plus.settings.backend.EnumStringPreference;
+import net.osmand.plus.settings.backend.OsmandPreference;
+import net.osmand.plus.settings.backend.OsmandSettings;
+import net.osmand.util.Algorithms;
+
+import java.lang.reflect.Type;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
class AppVersionUpgradeOnInit {
+
public static final String FIRST_TIME_APP_RUN = "FIRST_TIME_APP_RUN"; //$NON-NLS-1$
public static final String VERSION_INSTALLED_NUMBER = "VERSION_INSTALLED_NUMBER"; //$NON-NLS-1$
public static final String NUMBER_OF_STARTS = "NUMBER_OF_STARTS"; //$NON-NLS-1$
@@ -43,7 +66,7 @@ class AppVersionUpgradeOnInit {
@SuppressLint("ApplySharedPref")
void upgradeVersion(SharedPreferences startPrefs, int lastVersion) {
- if(!startPrefs.contains(NUMBER_OF_STARTS)) {
+ if (!startPrefs.contains(NUMBER_OF_STARTS)) {
startPrefs.edit().putInt(NUMBER_OF_STARTS, 1).commit();
} else {
startPrefs.edit().putInt(NUMBER_OF_STARTS, startPrefs.getInt(NUMBER_OF_STARTS, 0) + 1).commit();
@@ -59,27 +82,28 @@ class AppVersionUpgradeOnInit {
} else {
prevAppVersion = startPrefs.getInt(VERSION_INSTALLED_NUMBER, 0);
if (needsUpgrade(startPrefs, lastVersion)) {
+ OsmandSettings settings = app.getSettings();
if (prevAppVersion < VERSION_2_2) {
- app.getSettings().SHOW_DASHBOARD_ON_START.set(true);
- app.getSettings().SHOW_DASHBOARD_ON_MAP_SCREEN.set(true);
- app.getSettings().SHOW_CARD_TO_CHOOSE_DRAWER.set(true);
+ settings.SHOW_DASHBOARD_ON_START.set(true);
+ settings.SHOW_DASHBOARD_ON_MAP_SCREEN.set(true);
+ settings.SHOW_CARD_TO_CHOOSE_DRAWER.set(true);
startPrefs.edit().putInt(VERSION_INSTALLED_NUMBER, VERSION_2_2).commit();
}
if (prevAppVersion < VERSION_2_3) {
startPrefs.edit().putInt(VERSION_INSTALLED_NUMBER, VERSION_2_3).commit();
}
if (prevAppVersion < VERSION_3_2) {
- app.getSettings().BILLING_PURCHASE_TOKENS_SENT.set("");
+ settings.BILLING_PURCHASE_TOKENS_SENT.set("");
startPrefs.edit().putInt(VERSION_INSTALLED_NUMBER, VERSION_3_2).commit();
}
if (prevAppVersion < VERSION_3_5 || Version.getAppVersion(app).equals("3.5.3")
|| Version.getAppVersion(app).equals("3.5.4")) {
- app.getSettings().migratePreferences();
+ migratePreferences();
app.getAppInitializer().addListener(new AppInitializer.AppInitializeListener() {
@Override
public void onProgress(AppInitializer init, AppInitializer.InitEvents event) {
if (event.equals(AppInitializer.InitEvents.FAVORITES_INITIALIZED)) {
- app.getSettings().migrateHomeWorkParkingToFavorites();
+ migrateHomeWorkParkingToFavorites();
}
}
@@ -90,21 +114,22 @@ class AppVersionUpgradeOnInit {
startPrefs.edit().putInt(VERSION_INSTALLED_NUMBER, VERSION_3_5).commit();
}
if (prevAppVersion < VERSION_3_6) {
- app.getSettings().migratePreferences();
+ migratePreferences();
startPrefs.edit().putInt(VERSION_INSTALLED_NUMBER, VERSION_3_6).commit();
}
if (prevAppVersion < VERSION_3_7) {
- app.getSettings().migrateEnumPreferences();
+ migrateEnumPreferences();
startPrefs.edit().putInt(VERSION_INSTALLED_NUMBER, VERSION_3_7).commit();
}
if (prevAppVersion < VERSION_3_7_01) {
- app.getAppInitializer().addListener(new AppInitializer.AppInitializeListener() {
+ app.getAppInitializer().addListener(new AppInitializeListener() {
@Override
public void onProgress(AppInitializer init, AppInitializer.InitEvents event) {
- if (event.equals(AppInitializer.InitEvents.FAVORITES_INITIALIZED)) {
+ if (event.equals(InitEvents.FAVORITES_INITIALIZED)) {
app.getFavorites().fixBlackBackground();
}
}
+
@Override
public void onFinish(AppInitializer init) {
}
@@ -112,7 +137,7 @@ class AppVersionUpgradeOnInit {
startPrefs.edit().putInt(VERSION_INSTALLED_NUMBER, VERSION_3_7_01).commit();
}
if (prevAppVersion < VERSION_3_8_00) {
- app.getSettings().migrateQuickActionStates();
+ migrateQuickActionStates();
startPrefs.edit().putInt(VERSION_INSTALLED_NUMBER, VERSION_3_8_00).commit();
}
startPrefs.edit().putInt(VERSION_INSTALLED_NUMBER, lastVersion).commit();
@@ -135,20 +160,20 @@ class AppVersionUpgradeOnInit {
}
public void resetFirstTimeRun(SharedPreferences startPrefs) {
- if(startPrefs != null) {
+ if (startPrefs != null) {
startPrefs.edit().remove(FIRST_TIME_APP_RUN).commit();
}
}
public int getNumberOfStarts(SharedPreferences startPrefs) {
- if(startPrefs == null) {
+ if (startPrefs == null) {
return 0;
}
return startPrefs.getInt(NUMBER_OF_STARTS, 1);
}
public long getFirstInstalledDays(SharedPreferences startPrefs) {
- if(startPrefs == null) {
+ if (startPrefs == null) {
return 0;
}
long nd = startPrefs.getLong(FIRST_INSTALLED, 0);
@@ -159,4 +184,165 @@ class AppVersionUpgradeOnInit {
public boolean isFirstTime() {
return firstTime;
}
-}
+
+ public void migratePreferences() {
+ OsmandSettings settings = app.getSettings();
+ migrateEnumPreferences();
+ SharedPreferences globalSharedPreferences = (SharedPreferences) settings.getGlobalPreferences();
+ Map globalPrefsMap = globalSharedPreferences.getAll();
+ for (String key : globalPrefsMap.keySet()) {
+ OsmandPreference> pref = settings.getPreference(key);
+ if (pref instanceof CommonPreference) {
+ CommonPreference> commonPreference = (CommonPreference>) pref;
+ if (!commonPreference.isGlobal()) {
+ for (ApplicationMode mode : ApplicationMode.allPossibleValues()) {
+ if (!commonPreference.isSetForMode(mode) && !commonPreference.hasDefaultValueForMode(mode)) {
+ settings.setPreference(key, globalPrefsMap.get(key), mode);
+ }
+ }
+ }
+ }
+ }
+ SharedPreferences defaultProfilePreferences = (SharedPreferences) settings.getProfilePreferences(ApplicationMode.DEFAULT);
+ Map defaultPrefsMap = defaultProfilePreferences.getAll();
+ for (String key : defaultPrefsMap.keySet()) {
+ OsmandPreference> pref = settings.getPreference(key);
+ if (pref instanceof CommonPreference) {
+ CommonPreference> commonPreference = (CommonPreference>) pref;
+ if (commonPreference.isGlobal() && !commonPreference.isSet()) {
+ settings.setPreference(key, defaultPrefsMap.get(key));
+ }
+ }
+ }
+ for (OsmandPreference> pref : getGeneralPrefs()) {
+ if (pref instanceof CommonPreference) {
+ CommonPreference> commonPref = (CommonPreference>) pref;
+ Object defaultVal = commonPref.getModeValue(ApplicationMode.DEFAULT);
+ for (ApplicationMode mode : ApplicationMode.allPossibleValues()) {
+ if (!commonPref.isSetForMode(mode) && !commonPref.hasDefaultValueForMode(mode)) {
+ settings.setPreference(commonPref.getId(), defaultVal, mode);
+ }
+ }
+ }
+ }
+ String json = settings.getSettingsAPI().getString(settings.getGlobalPreferences(), "custom_app_profiles", "");
+ if (!Algorithms.isEmpty(json)) {
+ Gson gson = new GsonBuilder().excludeFieldsWithoutExposeAnnotation().create();
+ Type t = new TypeToken>() {
+ }.getType();
+ List customProfiles = gson.fromJson(json, t);
+ if (!Algorithms.isEmpty(customProfiles)) {
+ for (ApplicationMode.ApplicationModeBean modeBean : customProfiles) {
+ ApplicationMode.ApplicationModeBuilder builder = ApplicationMode.fromModeBean(app, modeBean);
+ ApplicationMode.saveProfile(builder, app);
+ }
+ }
+ }
+ }
+
+ public void migrateEnumPreferences() {
+ OsmandSettings settings = app.getSettings();
+ for (OsmandPreference> pref : settings.getRegisteredPreferences().values()) {
+ if (pref instanceof EnumStringPreference) {
+ EnumStringPreference> enumPref = (EnumStringPreference>) pref;
+ if (enumPref.isGlobal()) {
+ migrateEnumPref(enumPref, (SharedPreferences) settings.getGlobalPreferences());
+ } else {
+ for (ApplicationMode mode : ApplicationMode.allPossibleValues()) {
+ migrateEnumPref(enumPref, (SharedPreferences) settings.getProfilePreferences(mode));
+ }
+ }
+ }
+ }
+ }
+
+ public void migrateQuickActionStates() {
+ OsmandSettings settings = app.getSettings();
+ String quickActionsJson = settings.getSettingsAPI().getString(settings.getGlobalPreferences(), "quick_action_new", "");
+ if (!Algorithms.isEmpty(quickActionsJson)) {
+ Gson gson = new GsonBuilder().create();
+ Type type = new TypeToken>() {
+ }.getType();
+ HashMap quickActions = gson.fromJson(quickActionsJson, type);
+ if (!Algorithms.isEmpty(quickActions)) {
+ for (ApplicationMode mode : ApplicationMode.allPossibleValues()) {
+ settings.setQuickActions(quickActions, mode);
+ }
+ }
+ }
+ }
+
+ private void migrateEnumPref(EnumStringPreference enumPref, SharedPreferences sharedPreferences) {
+ Object value = sharedPreferences.getAll().get(enumPref.getId());
+ if (value instanceof Integer) {
+ int enumIndex = (int) value;
+ if (enumIndex >= 0 && enumIndex < enumPref.getValues().length) {
+ Enum savedValue = enumPref.getValues()[enumIndex];
+ enumPref.setValue(sharedPreferences, savedValue);
+ }
+ }
+ }
+
+ public void migrateHomeWorkParkingToFavorites() {
+ OsmandSettings settings = app.getSettings();
+ FavouritesDbHelper favorites = app.getFavorites();
+ SettingsAPI settingsAPI = settings.getSettingsAPI();
+ Object globalPreferences = settings.getGlobalPreferences();
+
+ LatLon homePoint = null;
+ float lat = settingsAPI.getFloat(globalPreferences, "home_point_lat", 0);
+ float lon = settingsAPI.getFloat(globalPreferences, "home_point_lon", 0);
+ if (lat != 0 || lon != 0) {
+ homePoint = new LatLon(lat, lon);
+ }
+ LatLon workPoint = null;
+ lat = settingsAPI.getFloat(globalPreferences, "work_point_lat", 0);
+ lon = settingsAPI.getFloat(globalPreferences, "work_point_lon", 0);
+ if (lat != 0 || lon != 0) {
+ workPoint = new LatLon(lat, lon);
+ }
+ if (homePoint != null) {
+ favorites.setSpecialPoint(homePoint, SpecialPointType.HOME, null);
+ }
+ if (workPoint != null) {
+ favorites.setSpecialPoint(workPoint, SpecialPointType.WORK, null);
+ }
+ }
+
+
+ public OsmandPreference>[] getGeneralPrefs() {
+ OsmandSettings settings = app.getSettings();
+ return new OsmandPreference[] {
+ settings.EXTERNAL_INPUT_DEVICE,
+ settings.CENTER_POSITION_ON_MAP,
+ settings.ROTATE_MAP,
+ settings.MAP_SCREEN_ORIENTATION,
+ settings.LIVE_MONITORING_URL,
+ settings.LIVE_MONITORING_MAX_INTERVAL_TO_SEND,
+ settings.LIVE_MONITORING_INTERVAL,
+ settings.LIVE_MONITORING,
+ settings.SHOW_TRIP_REC_NOTIFICATION,
+ settings.AUTO_SPLIT_RECORDING,
+ settings.SAVE_TRACK_MIN_SPEED,
+ settings.SAVE_TRACK_PRECISION,
+ settings.SAVE_TRACK_MIN_DISTANCE,
+ settings.SAVE_TRACK_INTERVAL,
+ settings.TRACK_STORAGE_DIRECTORY,
+ settings.SAVE_HEADING_TO_GPX,
+ settings.DISABLE_RECORDING_ONCE_APP_KILLED,
+ settings.SAVE_TRACK_TO_GPX,
+ settings.SAVE_GLOBAL_TRACK_REMEMBER,
+ settings.SAVE_GLOBAL_TRACK_INTERVAL,
+ settings.MAP_EMPTY_STATE_ALLOWED,
+ settings.DO_NOT_USE_ANIMATIONS,
+ settings.USE_KALMAN_FILTER_FOR_COMPASS,
+ settings.USE_MAGNETIC_FIELD_SENSOR_COMPASS,
+ settings.USE_TRACKBALL_FOR_MOVEMENTS,
+ settings.SPEED_SYSTEM,
+ settings.ANGULAR_UNITS,
+ settings.METRIC_SYSTEM,
+ settings.DRIVING_REGION,
+ settings.DRIVING_REGION_AUTOMATIC
+ };
+ }
+}
\ No newline at end of file
diff --git a/OsmAnd/src/net/osmand/plus/ContextMenuAdapter.java b/OsmAnd/src/net/osmand/plus/ContextMenuAdapter.java
index 7263f119bd..d85d6ddd68 100644
--- a/OsmAnd/src/net/osmand/plus/ContextMenuAdapter.java
+++ b/OsmAnd/src/net/osmand/plus/ContextMenuAdapter.java
@@ -38,9 +38,8 @@ import net.osmand.plus.dialogs.HelpArticleDialogFragment;
import net.osmand.plus.helpers.AndroidUiHelper;
import net.osmand.plus.settings.backend.ApplicationMode;
import net.osmand.plus.settings.backend.OsmAndAppCustomization;
-import net.osmand.plus.settings.backend.OsmandSettings;
-import net.osmand.plus.settings.backend.OsmandSettings.ContextMenuItemsPreference;
-import net.osmand.plus.settings.backend.OsmandSettings.OsmandPreference;
+import net.osmand.plus.settings.backend.ContextMenuItemsPreference;
+import net.osmand.plus.settings.backend.OsmandPreference;
import net.osmand.util.Algorithms;
import org.apache.commons.logging.Log;
@@ -53,6 +52,9 @@ import java.util.LinkedHashSet;
import java.util.List;
import java.util.Set;
+import static net.osmand.aidlapi.OsmAndCustomizationConstants.DRAWER_CONFIGURE_PROFILE_ID;
+import static net.osmand.aidlapi.OsmAndCustomizationConstants.DRAWER_SWITCH_PROFILE_ID;
+
public class ContextMenuAdapter {
private static final Log LOG = PlatformUtil.getLog(ContextMenuAdapter.class);
@@ -134,6 +136,19 @@ public class ContextMenuAdapter {
Collections.sort(items, new Comparator() {
@Override
public int compare(ContextMenuItem item1, ContextMenuItem item2) {
+ if (DRAWER_CONFIGURE_PROFILE_ID.equals(item1.getId())
+ && DRAWER_SWITCH_PROFILE_ID.equals(item2.getId())) {
+ return 1;
+ } else if (DRAWER_SWITCH_PROFILE_ID.equals(item1.getId())
+ && DRAWER_CONFIGURE_PROFILE_ID.equals(item2.getId())) {
+ return -1;
+ } else if (DRAWER_SWITCH_PROFILE_ID.equals(item1.getId())
+ || DRAWER_CONFIGURE_PROFILE_ID.equals(item1.getId())) {
+ return -1;
+ } else if (DRAWER_SWITCH_PROFILE_ID.equals(item2.getId())
+ || DRAWER_CONFIGURE_PROFILE_ID.equals(item2.getId())) {
+ return 1;
+ }
int order1 = item1.getOrder();
int order2 = item2.getOrder();
if (order1 < order2) {
@@ -631,7 +646,7 @@ public class ContextMenuAdapter {
return makeDeleteAction(prefs.toArray(new OsmandPreference[prefs.size()]));
}
- private static void resetSetting(ApplicationMode appMode, OsmandSettings.OsmandPreference preference, boolean profileOnly) {
+ private static void resetSetting(ApplicationMode appMode, OsmandPreference preference, boolean profileOnly) {
if (profileOnly) {
preference.resetModeToDefault(appMode);
} else {
diff --git a/OsmAnd/src/net/osmand/plus/GpxSelectionHelper.java b/OsmAnd/src/net/osmand/plus/GpxSelectionHelper.java
index 7217e8af5f..923bbe646a 100644
--- a/OsmAnd/src/net/osmand/plus/GpxSelectionHelper.java
+++ b/OsmAnd/src/net/osmand/plus/GpxSelectionHelper.java
@@ -29,7 +29,7 @@ import net.osmand.plus.helpers.GpxUiHelper;
import net.osmand.plus.helpers.GpxUiHelper.GPXDataSetAxisType;
import net.osmand.plus.helpers.GpxUiHelper.GPXDataSetType;
import net.osmand.plus.routing.RouteProvider;
-import net.osmand.plus.settings.backend.OsmandSettings.MetricsConstants;
+import net.osmand.plus.helpers.enums.MetricsConstants;
import net.osmand.plus.track.GpxSplitType;
import net.osmand.plus.track.GradientScaleType;
import net.osmand.util.Algorithms;
diff --git a/OsmAnd/src/net/osmand/plus/HuaweiDrmHelper.java b/OsmAnd/src/net/osmand/plus/HuaweiDrmHelper.java
deleted file mode 100644
index 7cc2f2798e..0000000000
--- a/OsmAnd/src/net/osmand/plus/HuaweiDrmHelper.java
+++ /dev/null
@@ -1,66 +0,0 @@
-package net.osmand.plus;
-
-import android.app.Activity;
-import android.util.Log;
-
-import java.lang.ref.WeakReference;
-import java.lang.reflect.InvocationTargetException;
-import java.lang.reflect.Method;
-
-public class HuaweiDrmHelper {
- private static final String TAG = HuaweiDrmHelper.class.getSimpleName();
-
- //Copyright protection id
- private static final String DRM_ID = "101117397";
- //Copyright protection public key
- private static final String DRM_PUBLIC_KEY = "9d6f861e7d46be167809a6a62302749a6753b3c1bd02c9729efb3973e268091d";
-
- public static void check(Activity activity) {
- boolean succeed = false;
- try {
- final WeakReference activityRef = new WeakReference<>(activity);
- Class> drmCheckCallbackClass = Class.forName("com.huawei.android.sdk.drm.DrmCheckCallback");
- Object callback = java.lang.reflect.Proxy.newProxyInstance(
- drmCheckCallbackClass.getClassLoader(),
- new java.lang.Class[]{drmCheckCallbackClass},
- new java.lang.reflect.InvocationHandler() {
-
- @Override
- public Object invoke(Object proxy, java.lang.reflect.Method method, Object[] args) {
- Activity a = activityRef.get();
- if (a != null && !a.isFinishing()) {
- String method_name = method.getName();
- if (method_name.equals("onCheckSuccess")) {
- // skip now
- } else if (method_name.equals("onCheckFailed")) {
- closeApplication(a);
- }
- }
- return null;
- }
- });
-
- Class> drmClass = Class.forName("com.huawei.android.sdk.drm.Drm");
- Class[] partypes = new Class[]{Activity.class, String.class, String.class, String.class, drmCheckCallbackClass};
- Method check = drmClass.getMethod("check", partypes);
- check.invoke(null, activity, activity.getPackageName(), DRM_ID, DRM_PUBLIC_KEY, callback);
- succeed = true;
-
- } catch (ClassNotFoundException e) {
- Log.e(TAG, "check: ", e);
- } catch (NoSuchMethodException e) {
- Log.e(TAG, "check: ", e);
- } catch (IllegalAccessException e) {
- Log.e(TAG, "check: ", e);
- } catch (InvocationTargetException e) {
- Log.e(TAG, "check: ", e);
- }
- if (!succeed) {
- closeApplication(activity);
- }
- }
-
- private static void closeApplication(Activity activity) {
- ((OsmandApplication) activity.getApplication()).closeApplicationAnywayImpl(activity, true);
- }
-}
diff --git a/OsmAnd/src/net/osmand/plus/OsmAndFormatter.java b/OsmAnd/src/net/osmand/plus/OsmAndFormatter.java
index 2ac142d06a..b58b3eba5e 100644
--- a/OsmAnd/src/net/osmand/plus/OsmAndFormatter.java
+++ b/OsmAnd/src/net/osmand/plus/OsmAndFormatter.java
@@ -15,9 +15,9 @@ import net.osmand.osm.PoiCategory;
import net.osmand.osm.PoiType;
import net.osmand.plus.settings.backend.ApplicationMode;
import net.osmand.plus.settings.backend.OsmandSettings;
-import net.osmand.plus.settings.backend.OsmandSettings.AngularConstants;
-import net.osmand.plus.settings.backend.OsmandSettings.MetricsConstants;
-import net.osmand.plus.settings.backend.OsmandSettings.SpeedConstants;
+import net.osmand.plus.helpers.enums.AngularConstants;
+import net.osmand.plus.helpers.enums.MetricsConstants;
+import net.osmand.plus.helpers.enums.SpeedConstants;
import net.osmand.util.Algorithms;
import java.text.DateFormatSymbols;
diff --git a/OsmAnd/src/net/osmand/plus/OsmandApplication.java b/OsmAnd/src/net/osmand/plus/OsmandApplication.java
index 43c3a17f09..1a48650a4d 100644
--- a/OsmAnd/src/net/osmand/plus/OsmandApplication.java
+++ b/OsmAnd/src/net/osmand/plus/OsmandApplication.java
@@ -30,6 +30,7 @@ import androidx.multidex.MultiDex;
import androidx.multidex.MultiDexApplication;
import net.osmand.AndroidUtils;
+import net.osmand.FileUtils;
import net.osmand.IndexConstants;
import net.osmand.PlatformUtil;
import net.osmand.access.AccessibilityPlugin;
@@ -42,7 +43,7 @@ import net.osmand.osm.MapPoiTypes;
import net.osmand.osm.io.NetworkUtils;
import net.osmand.plus.AppInitializer.AppInitializeListener;
import net.osmand.plus.access.AccessibilityMode;
-import net.osmand.plus.activities.DayNightHelper;
+import net.osmand.plus.helpers.DayNightHelper;
import net.osmand.plus.activities.ExitActivity;
import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.activities.SavingTrackHelper;
@@ -56,7 +57,9 @@ import net.osmand.plus.download.DownloadIndexesThread;
import net.osmand.plus.download.DownloadService;
import net.osmand.plus.download.IndexItem;
import net.osmand.plus.helpers.AvoidSpecificRoads;
+import net.osmand.plus.helpers.enums.DrivingRegion;
import net.osmand.plus.helpers.LockHelper;
+import net.osmand.plus.helpers.enums.MetricsConstants;
import net.osmand.plus.helpers.WaypointHelper;
import net.osmand.plus.inapp.InAppPurchaseHelper;
import net.osmand.plus.mapmarkers.MapMarkersDbHelper;
@@ -189,7 +192,7 @@ public class OsmandApplication extends MultiDexApplication {
osmandSettings.initExternalStorageDirectory();
}
externalStorageDirectory = osmandSettings.getExternalStorageDirectory();
- if (!OsmandSettings.isWritable(externalStorageDirectory)) {
+ if (!FileUtils.isWritable(externalStorageDirectory)) {
externalStorageDirectoryReadOnly = true;
externalStorageDirectory = osmandSettings.getInternalAppPath();
}
@@ -983,15 +986,15 @@ public class OsmandApplication extends MultiDexApplication {
}
public void setupDrivingRegion(WorldRegion reg) {
- OsmandSettings.DrivingRegion drg = null;
+ DrivingRegion drg = null;
WorldRegion.RegionParams params = reg.getParams();
// boolean americanSigns = "american".equals(params.getRegionRoadSigns());
boolean leftHand = "yes".equals(params.getRegionLeftHandDriving());
- OsmandSettings.MetricsConstants mc1 = "miles".equals(params.getRegionMetric()) ?
- OsmandSettings.MetricsConstants.MILES_AND_FEET : OsmandSettings.MetricsConstants.KILOMETERS_AND_METERS;
- OsmandSettings.MetricsConstants mc2 = "miles".equals(params.getRegionMetric()) ?
- OsmandSettings.MetricsConstants.MILES_AND_METERS : OsmandSettings.MetricsConstants.KILOMETERS_AND_METERS;
- for (OsmandSettings.DrivingRegion r : OsmandSettings.DrivingRegion.values()) {
+ MetricsConstants mc1 = "miles".equals(params.getRegionMetric()) ?
+ MetricsConstants.MILES_AND_FEET : MetricsConstants.KILOMETERS_AND_METERS;
+ MetricsConstants mc2 = "miles".equals(params.getRegionMetric()) ?
+ MetricsConstants.MILES_AND_METERS : MetricsConstants.KILOMETERS_AND_METERS;
+ for (DrivingRegion r : DrivingRegion.values()) {
if (r.leftHandDriving == leftHand && (r.defMetrics == mc1 || r.defMetrics == mc2)) {
drg = r;
break;
diff --git a/OsmAnd/src/net/osmand/plus/OsmandPlugin.java b/OsmAnd/src/net/osmand/plus/OsmandPlugin.java
index 0d887bc47f..4e9ca3d420 100644
--- a/OsmAnd/src/net/osmand/plus/OsmandPlugin.java
+++ b/OsmAnd/src/net/osmand/plus/OsmandPlugin.java
@@ -47,6 +47,8 @@ import net.osmand.plus.rastermaps.OsmandRasterMapsPlugin;
import net.osmand.plus.search.QuickSearchDialogFragment;
import net.osmand.plus.settings.backend.ApplicationMode;
import net.osmand.plus.settings.backend.OsmandSettings;
+import net.osmand.plus.settings.backend.CommonPreference;
+import net.osmand.plus.settings.backend.OsmandPreference;
import net.osmand.plus.settings.fragments.BaseSettingsFragment;
import net.osmand.plus.skimapsplugin.SkiMapsPlugin;
import net.osmand.plus.srtmplugin.SRTMPlugin;
@@ -80,7 +82,7 @@ public abstract class OsmandPlugin {
protected OsmandApplication app;
- protected List pluginPreferences = new ArrayList<>();
+ protected List pluginPreferences = new ArrayList<>();
private boolean active;
private String installURL = null;
@@ -118,7 +120,7 @@ public abstract class OsmandPlugin {
return null;
}
- public List getPreferences() {
+ public List getPreferences() {
return pluginPreferences;
}
@@ -919,44 +921,44 @@ public abstract class OsmandPlugin {
}
}
- protected OsmandSettings.CommonPreference registerBooleanPreference(OsmandApplication app, String prefId, boolean defValue) {
- OsmandSettings.CommonPreference preference = app.getSettings().registerBooleanPreference(prefId, defValue);
+ protected CommonPreference registerBooleanPreference(OsmandApplication app, String prefId, boolean defValue) {
+ CommonPreference preference = app.getSettings().registerBooleanPreference(prefId, defValue);
pluginPreferences.add(preference);
return preference;
}
- private OsmandSettings.CommonPreference registerBooleanAccessibilityPreference(OsmandApplication app, String prefId, boolean defValue) {
- OsmandSettings.CommonPreference preference = app.getSettings().registerBooleanAccessibilityPreference(prefId, defValue);
+ private CommonPreference registerBooleanAccessibilityPreference(OsmandApplication app, String prefId, boolean defValue) {
+ CommonPreference preference = app.getSettings().registerBooleanAccessibilityPreference(prefId, defValue);
pluginPreferences.add(preference);
return preference;
}
- protected OsmandSettings.CommonPreference registerStringPreference(OsmandApplication app, String prefId, String defValue) {
- OsmandSettings.CommonPreference preference = app.getSettings().registerStringPreference(prefId, defValue);
+ protected CommonPreference registerStringPreference(OsmandApplication app, String prefId, String defValue) {
+ CommonPreference preference = app.getSettings().registerStringPreference(prefId, defValue);
pluginPreferences.add(preference);
return preference;
}
- protected OsmandSettings.CommonPreference registerIntPreference(OsmandApplication app, String prefId, int defValue) {
- OsmandSettings.CommonPreference preference = app.getSettings().registerIntPreference(prefId, defValue);
+ protected CommonPreference registerIntPreference(OsmandApplication app, String prefId, int defValue) {
+ CommonPreference preference = app.getSettings().registerIntPreference(prefId, defValue);
pluginPreferences.add(preference);
return preference;
}
- protected OsmandSettings.CommonPreference registerLongPreference(OsmandApplication app, String prefId, long defValue) {
- OsmandSettings.CommonPreference preference = app.getSettings().registerLongPreference(prefId, defValue);
+ protected CommonPreference registerLongPreference(OsmandApplication app, String prefId, long defValue) {
+ CommonPreference preference = app.getSettings().registerLongPreference(prefId, defValue);
pluginPreferences.add(preference);
return preference;
}
- protected OsmandSettings.CommonPreference registerFloatPreference(OsmandApplication app, String prefId, float defValue) {
- OsmandSettings.CommonPreference preference = app.getSettings().registerFloatPreference(prefId, defValue);
+ protected CommonPreference registerFloatPreference(OsmandApplication app, String prefId, float defValue) {
+ CommonPreference preference = app.getSettings().registerFloatPreference(prefId, defValue);
pluginPreferences.add(preference);
return preference;
}
- protected OsmandSettings.CommonPreference registerEnumIntPreference(OsmandApplication app, String prefId, Enum defaultValue, Enum[] values, Class clz) {
- OsmandSettings.CommonPreference preference = app.getSettings().registerEnumIntPreference(prefId, defaultValue, values, clz);
+ protected CommonPreference registerEnumIntPreference(OsmandApplication app, String prefId, Enum defaultValue, Enum[] values, Class clz) {
+ CommonPreference preference = app.getSettings().registerEnumIntPreference(prefId, defaultValue, values, clz);
pluginPreferences.add(preference);
return preference;
}
diff --git a/OsmAnd/src/net/osmand/plus/Version.java b/OsmAnd/src/net/osmand/plus/Version.java
index 14ed68b100..48dd9b1feb 100644
--- a/OsmAnd/src/net/osmand/plus/Version.java
+++ b/OsmAnd/src/net/osmand/plus/Version.java
@@ -1,13 +1,15 @@
package net.osmand.plus;
-import java.io.UnsupportedEncodingException;
-import java.net.URLEncoder;
import android.content.pm.PackageInfo;
-import android.content.pm.PackageManager;
+import android.content.pm.PackageManager;
import net.osmand.plus.inapp.InAppPurchaseHelper;
+import java.io.File;
+import java.io.UnsupportedEncodingException;
+import java.net.URLEncoder;
+
public class Version {
private final String appVersion;
@@ -121,8 +123,8 @@ public class Version {
public static boolean isFreeVersion(OsmandApplication ctx){
return ctx.getPackageName().equals(FREE_VERSION_NAME) ||
ctx.getPackageName().equals(FREE_DEV_VERSION_NAME) ||
- ctx.getPackageName().equals(FREE_CUSTOM_VERSION_NAME)
- ;
+ ctx.getPackageName().equals(FREE_CUSTOM_VERSION_NAME) ||
+ isHuawei(ctx);
}
public static boolean isPaidVersion(OsmandApplication ctx) {
@@ -149,4 +151,21 @@ public class Version {
return v;
}
-}
+ public static boolean isOpenGlAvailable(OsmandApplication app) {
+ if ("qnx".equals(System.getProperty("os.name"))) {
+ return false;
+ }
+ File nativeLibraryDir = new File(app.getApplicationInfo().nativeLibraryDir);
+ if (nativeLibraryDir.exists() && nativeLibraryDir.canRead()) {
+ File[] files = nativeLibraryDir.listFiles();
+ if (files != null) {
+ for (File file : files) {
+ if ("libOsmAndCoreWithJNI.so".equals(file.getName())) {
+ return true;
+ }
+ }
+ }
+ }
+ return false;
+ }
+}
\ No newline at end of file
diff --git a/OsmAnd/src/net/osmand/plus/activities/FavoritesTreeFragment.java b/OsmAnd/src/net/osmand/plus/activities/FavoritesTreeFragment.java
index 91bf4ffbf9..b1a625d27e 100644
--- a/OsmAnd/src/net/osmand/plus/activities/FavoritesTreeFragment.java
+++ b/OsmAnd/src/net/osmand/plus/activities/FavoritesTreeFragment.java
@@ -43,6 +43,7 @@ import net.osmand.plus.FavouritesDbHelper.FavoriteGroup;
import net.osmand.plus.FavouritesDbHelper.FavoritesListener;
import net.osmand.plus.MapMarkersHelper;
import net.osmand.plus.OsmandApplication;
+import net.osmand.plus.settings.backend.OsmandPreference;
import net.osmand.plus.settings.backend.OsmandSettings;
import net.osmand.plus.R;
import net.osmand.plus.UiUtilities;
@@ -96,7 +97,7 @@ public class FavoritesTreeFragment extends OsmandExpandableListFragment implemen
private Set groupsToDelete = new LinkedHashSet<>();
private ActionMode actionMode;
private Drawable arrowImageDisabled;
- private HashMap> preferenceCache = new HashMap<>();
+ private HashMap> preferenceCache = new HashMap<>();
private View footerView;
private Location lastLocation;
private float lastHeading;
@@ -763,8 +764,8 @@ public class FavoritesTreeFragment extends OsmandExpandableListFragment implemen
}
}
- private OsmandSettings.OsmandPreference getGroupExpandedPreference(String groupName) {
- OsmandSettings.OsmandPreference preference = preferenceCache.get(groupName);
+ private OsmandPreference getGroupExpandedPreference(String groupName) {
+ OsmandPreference preference = preferenceCache.get(groupName);
if (preference == null) {
String groupKey = groupName + GROUP_EXPANDED_POSTFIX;
preference = getSettings().registerBooleanPreference(groupKey, false);
diff --git a/OsmAnd/src/net/osmand/plus/activities/MapActivity.java b/OsmAnd/src/net/osmand/plus/activities/MapActivity.java
index 2e840f8b64..122eb9ad7e 100644
--- a/OsmAnd/src/net/osmand/plus/activities/MapActivity.java
+++ b/OsmAnd/src/net/osmand/plus/activities/MapActivity.java
@@ -67,7 +67,6 @@ import net.osmand.plus.AppInitializer;
import net.osmand.plus.AppInitializer.AppInitializeListener;
import net.osmand.plus.AppInitializer.InitEvents;
import net.osmand.plus.GpxSelectionHelper.GpxDisplayItem;
-import net.osmand.plus.HuaweiDrmHelper;
import net.osmand.plus.MapMarkersHelper.MapMarker;
import net.osmand.plus.MapMarkersHelper.MapMarkerChangedListener;
import net.osmand.plus.OnDismissDialogFragmentListener;
@@ -75,6 +74,9 @@ import net.osmand.plus.OsmAndConstants;
import net.osmand.plus.OsmAndLocationSimulation;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.OsmandPlugin;
+import net.osmand.plus.helpers.DayNightHelper;
+import net.osmand.plus.settings.backend.CommonPreference;
+import net.osmand.plus.settings.backend.OsmandSettings;
import net.osmand.plus.R;
import net.osmand.plus.TargetPointsHelper;
import net.osmand.plus.TargetPointsHelper.TargetPoint;
@@ -131,7 +133,6 @@ import net.osmand.plus.search.QuickSearchDialogFragment.QuickSearchTab;
import net.osmand.plus.search.QuickSearchDialogFragment.QuickSearchType;
import net.osmand.plus.settings.backend.ApplicationMode;
import net.osmand.plus.settings.backend.OsmAndAppCustomization.OsmAndAppCustomizationListener;
-import net.osmand.plus.settings.backend.OsmandSettings;
import net.osmand.plus.settings.fragments.BaseSettingsFragment;
import net.osmand.plus.settings.fragments.BaseSettingsFragment.SettingsScreenType;
import net.osmand.plus.settings.fragments.ConfigureProfileFragment;
@@ -276,9 +277,6 @@ public class MapActivity extends OsmandActionBarActivity implements DownloadEven
super.onCreate(savedInstanceState);
- if (Version.isHuawei(getMyApplication())) {
- HuaweiDrmHelper.check(this);
- }
// Full screen is not used here
// getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.main);
@@ -537,7 +535,7 @@ public class MapActivity extends OsmandActionBarActivity implements DownloadEven
@Override
public void requestPrivateAccessRouting() {
if (!settings.FORCE_PRIVATE_ACCESS_ROUTING_ASKED.getModeValue(getRoutingHelper().getAppMode())) {
- final OsmandSettings.CommonPreference allowPrivate
+ final CommonPreference allowPrivate
= settings.getCustomRoutingBooleanProperty(GeneralRouter.ALLOW_PRIVATE, false);
final List modes = ApplicationMode.values(app);
for (ApplicationMode mode : modes) {
diff --git a/OsmAnd/src/net/osmand/plus/activities/MapActivityActions.java b/OsmAnd/src/net/osmand/plus/activities/MapActivityActions.java
index dbd0f133fa..d9137ee2d6 100644
--- a/OsmAnd/src/net/osmand/plus/activities/MapActivityActions.java
+++ b/OsmAnd/src/net/osmand/plus/activities/MapActivityActions.java
@@ -91,6 +91,7 @@ import java.util.Map;
import static net.osmand.IndexConstants.GPX_FILE_EXT;
import static net.osmand.aidlapi.OsmAndCustomizationConstants.DRAWER_CONFIGURE_MAP_ID;
+import static net.osmand.aidlapi.OsmAndCustomizationConstants.DRAWER_CONFIGURE_PROFILE_ID;
import static net.osmand.aidlapi.OsmAndCustomizationConstants.DRAWER_CONFIGURE_SCREEN_ID;
import static net.osmand.aidlapi.OsmAndCustomizationConstants.DRAWER_DASHBOARD_ID;
import static net.osmand.aidlapi.OsmAndCustomizationConstants.DRAWER_DIRECTIONS_ID;
@@ -104,6 +105,7 @@ import static net.osmand.aidlapi.OsmAndCustomizationConstants.DRAWER_OSMAND_LIVE
import static net.osmand.aidlapi.OsmAndCustomizationConstants.DRAWER_PLUGINS_ID;
import static net.osmand.aidlapi.OsmAndCustomizationConstants.DRAWER_SEARCH_ID;
import static net.osmand.aidlapi.OsmAndCustomizationConstants.DRAWER_SETTINGS_ID;
+import static net.osmand.aidlapi.OsmAndCustomizationConstants.DRAWER_SWITCH_PROFILE_ID;
import static net.osmand.aidlapi.OsmAndCustomizationConstants.DRAWER_TRAVEL_GUIDES_ID;
import static net.osmand.aidlapi.OsmAndCustomizationConstants.MAP_CONTEXT_MENU_ADD_GPX_WAYPOINT;
import static net.osmand.aidlapi.OsmAndCustomizationConstants.MAP_CONTEXT_MENU_ADD_ID;
@@ -145,7 +147,7 @@ public class MapActivityActions implements DialogProvider {
private static final int DIALOG_RELOAD_TITLE = 103;
private static final int DIALOG_SAVE_DIRECTIONS = 106;
-
+
private static final int DRAWER_MODE_NORMAL = 0;
private static final int DRAWER_MODE_SWITCH_PROFILE = 1;
@@ -476,7 +478,7 @@ public class MapActivityActions implements DialogProvider {
mapActivity.showQuickSearch(latitude, longitude);
} else if (standardId == R.string.context_menu_item_directions_from) {
//if (OsmAndLocationProvider.isLocationPermissionAvailable(mapActivity)) {
- enterDirectionsFromPoint(latitude, longitude);
+ enterDirectionsFromPoint(latitude, longitude);
//} else {
// ActivityCompat.requestPermissions(mapActivity,
// new String[]{Manifest.permission.ACCESS_FINE_LOCATION},
@@ -535,17 +537,17 @@ public class MapActivityActions implements DialogProvider {
}
public void enterRoutePlanningModeGivenGpx(GPXFile gpxFile, LatLon from, PointDescription fromName,
- boolean useIntermediatePointsByDefault, boolean showMenu) {
+ boolean useIntermediatePointsByDefault, boolean showMenu) {
enterRoutePlanningModeGivenGpx(gpxFile, from, fromName, useIntermediatePointsByDefault, showMenu, MapRouteInfoMenu.DEFAULT_MENU_STATE);
}
public void enterRoutePlanningModeGivenGpx(GPXFile gpxFile, LatLon from, PointDescription fromName,
- boolean useIntermediatePointsByDefault, boolean showMenu, int menuState) {
+ boolean useIntermediatePointsByDefault, boolean showMenu, int menuState) {
enterRoutePlanningModeGivenGpx(gpxFile, null, from, fromName, useIntermediatePointsByDefault, showMenu, menuState);
}
public void enterRoutePlanningModeGivenGpx(GPXFile gpxFile, ApplicationMode appMode, LatLon from, PointDescription fromName,
- boolean useIntermediatePointsByDefault, boolean showMenu, int menuState) {
+ boolean useIntermediatePointsByDefault, boolean showMenu, int menuState) {
settings.USE_INTERMEDIATE_POINTS_NAVIGATION.set(useIntermediatePointsByDefault);
OsmandApplication app = mapActivity.getMyApplication();
TargetPointsHelper targets = app.getTargetPointsHelper();
@@ -727,7 +729,7 @@ public class MapActivityActions implements DialogProvider {
private ContextMenuAdapter createSwitchProfileOptionsMenu(final OsmandApplication app, ContextMenuAdapter optionsMenuHelper, boolean nightMode) {
drawerMode = DRAWER_MODE_NORMAL;
createProfilesController(app, optionsMenuHelper, nightMode, true);
-
+
List activeModes = ApplicationMode.values(app);
ApplicationMode currentMode = app.getSettings().APPLICATION_MODE.get();
@@ -759,7 +761,7 @@ public class MapActivityActions implements DialogProvider {
})
.createItem());
}
-
+
int activeColorPrimaryResId = nightMode ? R.color.active_color_primary_dark : R.color.active_color_primary_light;
optionsMenuHelper.addItem(new ItemBuilder().setLayout(R.layout.profile_list_item)
.setColor(activeColorPrimaryResId)
@@ -778,7 +780,7 @@ public class MapActivityActions implements DialogProvider {
}
private ContextMenuAdapter createNormalOptionsMenu(final OsmandApplication app, ContextMenuAdapter optionsMenuHelper, boolean nightMode) {
-
+
createProfilesController(app, optionsMenuHelper, nightMode, false);
optionsMenuHelper.addItem(new ItemBuilder().setTitleId(R.string.home, mapActivity)
@@ -899,7 +901,7 @@ public class MapActivityActions implements DialogProvider {
}
}).createItem());
- if (Version.isGooglePlayEnabled(app) || Version.isDeveloperVersion(app)) {
+ if (Version.isGooglePlayEnabled(app) || Version.isHuawei(app) || Version.isDeveloperVersion(app)) {
optionsMenuHelper.addItem(new ItemBuilder().setTitleId(R.string.osm_live, mapActivity)
.setId(DRAWER_OSMAND_LIVE_ID)
.setIcon(R.drawable.ic_action_osm_live)
@@ -1055,6 +1057,7 @@ public class MapActivityActions implements DialogProvider {
int icArrowResId = listExpanded ? R.drawable.ic_action_arrow_drop_up : R.drawable.ic_action_arrow_drop_down;
final int nextMode = listExpanded ? DRAWER_MODE_NORMAL : DRAWER_MODE_SWITCH_PROFILE;
optionsMenuHelper.addItem(new ItemBuilder().setLayout(R.layout.main_menu_drawer_btn_switch_profile)
+ .setId(DRAWER_SWITCH_PROFILE_ID)
.setIcon(currentMode.getIconRes())
.setSecondaryIcon(icArrowResId)
.setColor(currentMode.getIconColorInfo().getColor(nightMode))
@@ -1070,6 +1073,7 @@ public class MapActivityActions implements DialogProvider {
})
.createItem());
optionsMenuHelper.addItem(new ItemBuilder().setLayout(R.layout.main_menu_drawer_btn_configure_profile)
+ .setId(DRAWER_CONFIGURE_PROFILE_ID)
.setColor(currentMode.getIconColorInfo().getColor(nightMode))
.setTitle(getString(R.string.configure_profile))
.setListener(new ItemClickListener() {
@@ -1084,8 +1088,8 @@ public class MapActivityActions implements DialogProvider {
}
private String getProfileDescription(OsmandApplication app, ApplicationMode mode,
- Map profilesObjects, String defaultDescription){
- String description = defaultDescription;
+ Map profilesObjects, String defaultDescription) {
+ String description = defaultDescription;
String routingProfileKey = mode.getRoutingProfile();
if (!Algorithms.isEmpty(routingProfileKey)) {
diff --git a/OsmAnd/src/net/osmand/plus/activities/MapActivityLayers.java b/OsmAnd/src/net/osmand/plus/activities/MapActivityLayers.java
index 64f3ad8b9f..442e2f41a1 100644
--- a/OsmAnd/src/net/osmand/plus/activities/MapActivityLayers.java
+++ b/OsmAnd/src/net/osmand/plus/activities/MapActivityLayers.java
@@ -29,7 +29,7 @@ import net.osmand.plus.DialogListItemAdapter;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.OsmandPlugin;
import net.osmand.plus.settings.backend.OsmandSettings;
-import net.osmand.plus.settings.backend.OsmandSettings.CommonPreference;
+import net.osmand.plus.settings.backend.CommonPreference;
import net.osmand.plus.R;
import net.osmand.plus.SQLiteTileSource;
import net.osmand.plus.activities.MapActivity.ShowQuickSearchMode;
diff --git a/OsmAnd/src/net/osmand/plus/activities/OsmandInAppPurchaseActivity.java b/OsmAnd/src/net/osmand/plus/activities/OsmandInAppPurchaseActivity.java
index cb91f7d167..47f7a17444 100644
--- a/OsmAnd/src/net/osmand/plus/activities/OsmandInAppPurchaseActivity.java
+++ b/OsmAnd/src/net/osmand/plus/activities/OsmandInAppPurchaseActivity.java
@@ -5,7 +5,6 @@ import android.app.Activity;
import android.content.ActivityNotFoundException;
import android.content.Intent;
import android.net.Uri;
-import android.os.Bundle;
import android.widget.Toast;
import androidx.annotation.NonNull;
@@ -14,12 +13,15 @@ import androidx.appcompat.app.AppCompatActivity;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
+import net.osmand.AndroidUtils;
import net.osmand.PlatformUtil;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.OsmandPlugin;
import net.osmand.plus.R;
import net.osmand.plus.Version;
+import net.osmand.plus.download.DownloadActivity;
import net.osmand.plus.inapp.InAppPurchaseHelper;
+import net.osmand.plus.inapp.InAppPurchaseHelper.InAppPurchaseInitCallback;
import net.osmand.plus.inapp.InAppPurchaseHelper.InAppPurchaseListener;
import net.osmand.plus.inapp.InAppPurchaseHelper.InAppPurchaseTaskType;
import net.osmand.plus.liveupdates.OsmLiveRestartBottomSheetDialogFragment;
@@ -27,6 +29,7 @@ import net.osmand.plus.srtmplugin.SRTMPlugin;
import org.apache.commons.logging.Log;
+import java.lang.ref.WeakReference;
import java.util.List;
@SuppressLint("Registered")
@@ -34,14 +37,7 @@ public class OsmandInAppPurchaseActivity extends AppCompatActivity implements In
private static final Log LOG = PlatformUtil.getLog(OsmandInAppPurchaseActivity.class);
private InAppPurchaseHelper purchaseHelper;
-
- @Override
- protected void onCreate(@Nullable Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- if (isInAppPurchaseAllowed() && isInAppPurchaseSupported()) {
- purchaseHelper = getMyApplication().getInAppPurchaseHelper();
- }
- }
+ private boolean activityDestroyed;
@Override
protected void onResume() {
@@ -53,17 +49,39 @@ public class OsmandInAppPurchaseActivity extends AppCompatActivity implements In
protected void onDestroy() {
super.onDestroy();
deinitInAppPurchaseHelper();
+ activityDestroyed = true;
}
private void initInAppPurchaseHelper() {
deinitInAppPurchaseHelper();
-
- if (purchaseHelper != null) {
- purchaseHelper.setUiActivity(this);
- if (purchaseHelper.needRequestInventory()) {
- purchaseHelper.requestInventory();
+ if (purchaseHelper == null) {
+ OsmandApplication app = getMyApplication();
+ InAppPurchaseHelper purchaseHelper = app.getInAppPurchaseHelper();
+ if (app.getSettings().isInternetConnectionAvailable()
+ && isInAppPurchaseAllowed()
+ && isInAppPurchaseSupported(purchaseHelper)) {
+ this.purchaseHelper = purchaseHelper;
}
}
+ if (purchaseHelper != null) {
+ final WeakReference 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();
+ }
+ }
+ }
+
+ @Override
+ public void onFail() {
+ }
+ });
+ }
}
private void deinitInAppPurchaseHelper() {
@@ -80,7 +98,11 @@ public class OsmandInAppPurchaseActivity extends AppCompatActivity implements In
InAppPurchaseHelper purchaseHelper = app.getInAppPurchaseHelper();
if (purchaseHelper != null) {
app.logEvent("in_app_purchase_redirect");
- purchaseHelper.purchaseFullVersion(activity);
+ try {
+ purchaseHelper.purchaseFullVersion(activity);
+ } catch (UnsupportedOperationException e) {
+ LOG.error("purchaseFullVersion is not supported", e);
+ }
}
} else {
app.logEvent("paid_version_redirect");
@@ -101,18 +123,27 @@ public class OsmandInAppPurchaseActivity extends AppCompatActivity implements In
InAppPurchaseHelper purchaseHelper = app.getInAppPurchaseHelper();
if (purchaseHelper != null) {
app.logEvent("depth_contours_purchase_redirect");
- purchaseHelper.purchaseDepthContours(activity);
+ try {
+ purchaseHelper.purchaseDepthContours(activity);
+ } catch (UnsupportedOperationException e) {
+ LOG.error("purchaseDepthContours is not supported", e);
+ }
}
}
}
- public static void purchaseSrtmPlugin(@NonNull final Activity activity) {
- OsmandPlugin plugin = OsmandPlugin.getPlugin(SRTMPlugin.class);
- if(plugin == null || plugin.getInstallURL() == null) {
- Toast.makeText(activity.getApplicationContext(),
- activity.getString(R.string.activate_srtm_plugin), Toast.LENGTH_LONG).show();
- } else {
- activity.startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(plugin.getInstallURL())));
+ public static void purchaseContourLines(@NonNull final Activity activity) {
+ OsmandApplication app = (OsmandApplication) activity.getApplication();
+ if (app != null) {
+ InAppPurchaseHelper purchaseHelper = app.getInAppPurchaseHelper();
+ if (purchaseHelper != null) {
+ app.logEvent("contour_lines_purchase_redirect");
+ try {
+ purchaseHelper.purchaseContourLines(activity);
+ } catch (UnsupportedOperationException e) {
+ LOG.error("purchaseContourLines is not supported", e);
+ }
+ }
}
}
@@ -129,8 +160,9 @@ public class OsmandInAppPurchaseActivity extends AppCompatActivity implements In
return false;
}
- public boolean isInAppPurchaseSupported() {
- return Version.isGooglePlayEnabled(getMyApplication());
+ public boolean isInAppPurchaseSupported(InAppPurchaseHelper purchaseHelper) {
+ OsmandApplication app = getMyApplication();
+ return Version.isGooglePlayEnabled(app) || Version.isHuawei(app);
}
@Override
@@ -178,6 +210,11 @@ public class OsmandInAppPurchaseActivity extends AppCompatActivity implements In
}
onInAppPurchaseItemPurchased(sku);
fireInAppPurchaseItemPurchasedOnFragments(fragmentManager, sku, active);
+ if (purchaseHelper != null && purchaseHelper.getContourLines().getSku().equals(sku)) {
+ if (!(this instanceof MapActivity)) {
+ finish();
+ }
+ }
}
public void fireInAppPurchaseItemPurchasedOnFragments(@NonNull FragmentManager fragmentManager,
@@ -222,6 +259,17 @@ public class OsmandInAppPurchaseActivity extends AppCompatActivity implements In
}
}
+ @Override
+ protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
+ boolean handled = false;
+ if (purchaseHelper != null) {
+ handled = purchaseHelper.onActivityResult(this, requestCode, resultCode, data);
+ }
+ if (!handled) {
+ super.onActivityResult(requestCode, resultCode, data);
+ }
+ }
+
public void onInAppPurchaseError(InAppPurchaseTaskType taskType, String error) {
// not implemented
}
diff --git a/OsmAnd/src/net/osmand/plus/activities/SettingsBaseActivity.java b/OsmAnd/src/net/osmand/plus/activities/SettingsBaseActivity.java
index 2187e801a2..316de777b0 100644
--- a/OsmAnd/src/net/osmand/plus/activities/SettingsBaseActivity.java
+++ b/OsmAnd/src/net/osmand/plus/activities/SettingsBaseActivity.java
@@ -25,13 +25,13 @@ import net.osmand.AndroidUtils;
import net.osmand.PlatformUtil;
import net.osmand.plus.OsmAndFormatter;
import net.osmand.plus.OsmandApplication;
+import net.osmand.plus.settings.backend.OsmandSettings;
+import net.osmand.plus.settings.backend.CommonPreference;
+import net.osmand.plus.settings.backend.OsmandPreference;
import net.osmand.plus.R;
import net.osmand.plus.profiles.AppProfileArrayAdapter;
import net.osmand.plus.profiles.ProfileDataObject;
import net.osmand.plus.settings.backend.ApplicationMode;
-import net.osmand.plus.settings.backend.OsmandSettings;
-import net.osmand.plus.settings.backend.OsmandSettings.CommonPreference;
-import net.osmand.plus.settings.backend.OsmandSettings.OsmandPreference;
import org.apache.commons.logging.Log;
diff --git a/OsmAnd/src/net/osmand/plus/activities/SettingsGeneralActivity.java b/OsmAnd/src/net/osmand/plus/activities/SettingsGeneralActivity.java
index aaf206ca06..225384349c 100644
--- a/OsmAnd/src/net/osmand/plus/activities/SettingsGeneralActivity.java
+++ b/OsmAnd/src/net/osmand/plus/activities/SettingsGeneralActivity.java
@@ -42,9 +42,9 @@ import net.osmand.osm.io.NetworkUtils;
import net.osmand.plus.settings.backend.ApplicationMode;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.settings.backend.OsmandSettings;
-import net.osmand.plus.settings.backend.OsmandSettings.AngularConstants;
-import net.osmand.plus.settings.backend.OsmandSettings.DrivingRegion;
-import net.osmand.plus.settings.backend.OsmandSettings.MetricsConstants;
+import net.osmand.plus.helpers.enums.AngularConstants;
+import net.osmand.plus.helpers.enums.DrivingRegion;
+import net.osmand.plus.helpers.enums.MetricsConstants;
import net.osmand.plus.R;
import net.osmand.plus.Version;
import net.osmand.plus.base.MapViewTrackingUtilities;
diff --git a/OsmAnd/src/net/osmand/plus/activities/SettingsNavigationActivity.java b/OsmAnd/src/net/osmand/plus/activities/SettingsNavigationActivity.java
index 260fd63719..a0a5c74992 100644
--- a/OsmAnd/src/net/osmand/plus/activities/SettingsNavigationActivity.java
+++ b/OsmAnd/src/net/osmand/plus/activities/SettingsNavigationActivity.java
@@ -34,6 +34,12 @@ import net.osmand.plus.ContextMenuAdapter;
import net.osmand.plus.ContextMenuItem;
import net.osmand.plus.OsmAndFormatter;
import net.osmand.plus.OsmandApplication;
+import net.osmand.plus.helpers.enums.MetricsConstants;
+import net.osmand.plus.settings.backend.CommonPreference;
+import net.osmand.plus.settings.backend.OsmandSettings;
+import net.osmand.plus.helpers.enums.AutoZoomMap;
+import net.osmand.plus.settings.backend.OsmandPreference;
+import net.osmand.plus.helpers.enums.SpeedConstants;
import net.osmand.plus.R;
import net.osmand.plus.UiUtilities;
import net.osmand.plus.Version;
@@ -44,10 +50,6 @@ import net.osmand.plus.routepreparationmenu.RoutingOptionsHelper;
import net.osmand.plus.routing.RouteProvider.RouteService;
import net.osmand.plus.routing.RoutingHelper;
import net.osmand.plus.settings.backend.ApplicationMode;
-import net.osmand.plus.settings.backend.OsmandSettings;
-import net.osmand.plus.settings.backend.OsmandSettings.AutoZoomMap;
-import net.osmand.plus.settings.backend.OsmandSettings.OsmandPreference;
-import net.osmand.plus.settings.backend.OsmandSettings.SpeedConstants;
import net.osmand.plus.voice.CommandPlayer;
import net.osmand.router.GeneralRouter;
import net.osmand.router.GeneralRouter.GeneralRouterProfile;
@@ -171,7 +173,7 @@ public class SettingsNavigationActivity extends SettingsBaseActivity {
//array size must be equal!
Float[] speedLimitsKmhPos = new Float[]{0f, 5f, 7f, 10f, 15f, 20f};
Float[] speedLimitsMphPos = new Float[]{0f, 3f, 5f, 7f, 10f, 15f};
- if (settings.METRIC_SYSTEM.get() == OsmandSettings.MetricsConstants.KILOMETERS_AND_METERS) {
+ if (settings.METRIC_SYSTEM.get() == MetricsConstants.KILOMETERS_AND_METERS) {
String[] speedNames = new String[speedLimitsKmh.length];
String[] speedNamesPos = new String[speedLimitsKmhPos.length];
for (int i = 0; i < speedLimitsKmh.length; i++) {
@@ -407,7 +409,7 @@ public class SettingsNavigationActivity extends SettingsBaseActivity {
}
public static boolean isRoutingParameterSelected(OsmandSettings settings, ApplicationMode am, RoutingParameter routingParameter) {
- final OsmandSettings.CommonPreference property =
+ final CommonPreference property =
settings.getCustomRoutingBooleanProperty(routingParameter.getId(), routingParameter.getDefaultBoolean());
if(am != null) {
return property.getModeValue(am);
@@ -417,7 +419,7 @@ public class SettingsNavigationActivity extends SettingsBaseActivity {
}
public static void setRoutingParameterSelected(OsmandSettings settings, ApplicationMode am, String routingParameterId, boolean defaultBoolean, boolean isChecked) {
- final OsmandSettings.CommonPreference property = settings.getCustomRoutingBooleanProperty(routingParameterId, defaultBoolean);
+ final CommonPreference property = settings.getCustomRoutingBooleanProperty(routingParameterId, defaultBoolean);
if (am != null) {
property.setModeValue(am, isChecked);
} else {
diff --git a/OsmAnd/src/net/osmand/plus/audionotes/AudioVideoNotesPlugin.java b/OsmAnd/src/net/osmand/plus/audionotes/AudioVideoNotesPlugin.java
index de3453550f..a68a8bc749 100644
--- a/OsmAnd/src/net/osmand/plus/audionotes/AudioVideoNotesPlugin.java
+++ b/OsmAnd/src/net/osmand/plus/audionotes/AudioVideoNotesPlugin.java
@@ -53,8 +53,8 @@ import net.osmand.plus.ContextMenuAdapter.ItemClickListener;
import net.osmand.plus.ContextMenuItem;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.OsmandPlugin;
-import net.osmand.plus.settings.backend.OsmandSettings.CommonPreference;
-import net.osmand.plus.settings.backend.OsmandSettings.OsmandPreference;
+import net.osmand.plus.settings.backend.CommonPreference;
+import net.osmand.plus.settings.backend.OsmandPreference;
import net.osmand.plus.R;
import net.osmand.plus.UiUtilities;
import net.osmand.plus.activities.MapActivity;
diff --git a/OsmAnd/src/net/osmand/plus/audionotes/NotesFragment.java b/OsmAnd/src/net/osmand/plus/audionotes/NotesFragment.java
index 09acdca8d8..8e911b04fc 100644
--- a/OsmAnd/src/net/osmand/plus/audionotes/NotesFragment.java
+++ b/OsmAnd/src/net/osmand/plus/audionotes/NotesFragment.java
@@ -38,7 +38,6 @@ import net.osmand.PlatformUtil;
import net.osmand.data.PointDescription;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.OsmandPlugin;
-import net.osmand.plus.settings.backend.OsmandSettings.NotesSortByMode;
import net.osmand.plus.R;
import net.osmand.plus.Version;
import net.osmand.plus.activities.ActionBarProgressActivity;
diff --git a/OsmAnd/src/net/osmand/plus/audionotes/NotesSortByMode.java b/OsmAnd/src/net/osmand/plus/audionotes/NotesSortByMode.java
new file mode 100644
index 0000000000..cf791dbf26
--- /dev/null
+++ b/OsmAnd/src/net/osmand/plus/audionotes/NotesSortByMode.java
@@ -0,0 +1,14 @@
+package net.osmand.plus.audionotes;
+
+public enum NotesSortByMode {
+ BY_TYPE,
+ BY_DATE;
+
+ public boolean isByType() {
+ return this == BY_TYPE;
+ }
+
+ public boolean isByDate() {
+ return this == BY_DATE;
+ }
+}
diff --git a/OsmAnd/src/net/osmand/plus/audionotes/SortByMenuBottomSheetDialogFragment.java b/OsmAnd/src/net/osmand/plus/audionotes/SortByMenuBottomSheetDialogFragment.java
index de1208a735..06fa83f6ca 100644
--- a/OsmAnd/src/net/osmand/plus/audionotes/SortByMenuBottomSheetDialogFragment.java
+++ b/OsmAnd/src/net/osmand/plus/audionotes/SortByMenuBottomSheetDialogFragment.java
@@ -3,8 +3,7 @@ package net.osmand.plus.audionotes;
import android.os.Bundle;
import android.view.View;
-import net.osmand.plus.settings.backend.OsmandSettings;
-import net.osmand.plus.settings.backend.OsmandSettings.NotesSortByMode;
+import net.osmand.plus.settings.backend.CommonPreference;
import net.osmand.plus.R;
import net.osmand.plus.base.MenuBottomSheetDialogFragment;
import net.osmand.plus.base.bottomsheetmenu.BaseBottomSheetItem;
@@ -53,7 +52,7 @@ public class SortByMenuBottomSheetDialogFragment extends MenuBottomSheetDialogFr
}
private void selectSortByMode(NotesSortByMode mode) {
- final OsmandSettings.CommonPreference sortByMode = getMyApplication().getSettings().NOTES_SORT_BY_MODE;
+ final CommonPreference sortByMode = getMyApplication().getSettings().NOTES_SORT_BY_MODE;
if (sortByMode.get() != mode) {
sortByMode.set(mode);
if (listener != null) {
diff --git a/OsmAnd/src/net/osmand/plus/base/MenuBottomSheetDialogFragment.java b/OsmAnd/src/net/osmand/plus/base/MenuBottomSheetDialogFragment.java
index 7625e5de20..307cfb3bbe 100644
--- a/OsmAnd/src/net/osmand/plus/base/MenuBottomSheetDialogFragment.java
+++ b/OsmAnd/src/net/osmand/plus/base/MenuBottomSheetDialogFragment.java
@@ -8,11 +8,11 @@ import android.graphics.drawable.Drawable;
import android.graphics.drawable.LayerDrawable;
import android.os.Build;
import android.os.Bundle;
-import android.view.ContextThemeWrapper;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewTreeObserver;
+import android.view.ViewTreeObserver.OnScrollChangedListener;
import android.view.Window;
import android.view.WindowManager;
import android.widget.LinearLayout;
@@ -50,8 +50,11 @@ public abstract class MenuBottomSheetDialogFragment extends BottomSheetDialogFra
protected int themeRes;
protected View dismissButton;
protected View rightButton;
+ protected View thirdButton;
+ private View buttonsShadow;
private LinearLayout itemsContainer;
+ private LinearLayout buttonsContainer;
@StringRes
protected int dismissButtonStringRes = R.string.shared_string_cancel;
@@ -74,45 +77,21 @@ public abstract class MenuBottomSheetDialogFragment extends BottomSheetDialogFra
@Override
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup parent, Bundle savedInstanceState) {
createMenuItems(savedInstanceState);
- Context ctx = requireContext();
- View mainView = View.inflate(new ContextThemeWrapper(ctx, themeRes), R.layout.bottom_sheet_menu_base, null);
+ Activity activity = requireActivity();
+ LayoutInflater themedInflater = UiUtilities.getInflater(activity, nightMode);
+ View mainView = themedInflater.inflate(R.layout.bottom_sheet_menu_base, null);
if (useScrollableItemsContainer()) {
- itemsContainer = (LinearLayout) mainView.findViewById(R.id.scrollable_items_container);
+ itemsContainer = mainView.findViewById(R.id.scrollable_items_container);
} else {
mainView.findViewById(R.id.scroll_view).setVisibility(View.GONE);
- itemsContainer = (LinearLayout) mainView.findViewById(R.id.non_scrollable_items_container);
+ itemsContainer = mainView.findViewById(R.id.non_scrollable_items_container);
itemsContainer.setVisibility(View.VISIBLE);
}
+ buttonsShadow = mainView.findViewById(R.id.buttons_shadow);
inflateMenuItems();
-
- dismissButton = mainView.findViewById(R.id.dismiss_button);
- UiUtilities.setupDialogButton(nightMode, dismissButton, getDismissButtonType(), getDismissButtonTextId());
- dismissButton.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View v) {
- onDismissButtonClickAction();
- dismiss();
- }
- });
- if (hideButtonsContainer()) {
- mainView.findViewById(R.id.buttons_container).setVisibility(View.GONE);
- } else {
- int rightBottomButtonTextId = getRightBottomButtonTextId();
- if (rightBottomButtonTextId != DEFAULT_VALUE) {
- mainView.findViewById(R.id.buttons_divider).setVisibility(View.VISIBLE);
- rightButton = mainView.findViewById(R.id.right_bottom_button);
- UiUtilities.setupDialogButton(nightMode, rightButton, getRightBottomButtonType(), rightBottomButtonTextId);
- rightButton.setVisibility(View.VISIBLE);
- rightButton.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View v) {
- onRightBottomButtonClick();
- }
- });
- }
- }
- updateBottomButtons();
+ setupScrollShadow(mainView);
+ setupBottomButtons((ViewGroup) mainView);
setupHeightAndBackground(mainView);
return mainView;
}
@@ -199,7 +178,7 @@ public abstract class MenuBottomSheetDialogFragment extends BottomSheetDialogFra
if (contentView.getHeight() > contentHeight) {
if (useScrollableItemsContainer() || useExpandableList()) {
contentView.getLayoutParams().height = contentHeight;
- mainView.findViewById(R.id.buttons_shadow).setVisibility(View.VISIBLE);
+ buttonsShadow.setVisibility(View.VISIBLE);
} else {
contentView.getLayoutParams().height = ViewGroup.LayoutParams.WRAP_CONTENT;
}
@@ -222,7 +201,18 @@ public abstract class MenuBottomSheetDialogFragment extends BottomSheetDialogFra
private int getContentHeight(int availableScreenHeight) {
int customHeight = getCustomHeight();
- int maxHeight = availableScreenHeight - getResources().getDimensionPixelSize(R.dimen.dialog_button_ex_height);
+ int buttonsHeight;
+ if (useVerticalButtons()) {
+ int padding = getResources().getDimensionPixelSize(R.dimen.content_padding_small);
+ int buttonHeight = getResources().getDimensionPixelSize(R.dimen.dialog_button_height);
+ buttonsHeight = (buttonHeight + padding) * 2 + getFirstDividerHeight();
+ if (getThirdBottomButtonTextId() != DEFAULT_VALUE) {
+ buttonsHeight += buttonHeight + getSecondDividerHeight();
+ }
+ } else {
+ buttonsHeight = getResources().getDimensionPixelSize(R.dimen.dialog_button_ex_height);
+ }
+ int maxHeight = availableScreenHeight - buttonsHeight;
if (customHeight != DEFAULT_VALUE && customHeight <= maxHeight) {
return customHeight;
}
@@ -280,6 +270,18 @@ public abstract class MenuBottomSheetDialogFragment extends BottomSheetDialogFra
}
+ protected int getThirdBottomButtonTextId() {
+ return DEFAULT_VALUE;
+ }
+
+ protected DialogButtonType getThirdBottomButtonType() {
+ return DialogButtonType.PRIMARY;
+ }
+
+ protected void onThirdBottomButtonClick() {
+
+ }
+
protected boolean isDismissButtonEnabled() {
return true;
}
@@ -288,6 +290,42 @@ public abstract class MenuBottomSheetDialogFragment extends BottomSheetDialogFra
return true;
}
+ protected void setupBottomButtons(ViewGroup view) {
+ Activity activity = requireActivity();
+ LayoutInflater themedInflater = UiUtilities.getInflater(activity, nightMode);
+ if (!hideButtonsContainer()) {
+ if (useVerticalButtons()) {
+ buttonsContainer = (LinearLayout) themedInflater.inflate(R.layout.bottom_buttons_vertical, view);
+ setupThirdButton();
+ } else {
+ buttonsContainer = (LinearLayout) themedInflater.inflate(R.layout.bottom_buttons, view);
+ }
+ setupRightButton();
+ setupDismissButton();
+ updateBottomButtons();
+ }
+ }
+
+ boolean useVerticalButtons() {
+ Activity activity = requireActivity();
+ int rightBottomButtonTextId = getRightBottomButtonTextId();
+ if (getDismissButtonTextId() != DEFAULT_VALUE && rightBottomButtonTextId != DEFAULT_VALUE) {
+ if (getThirdBottomButtonTextId() != DEFAULT_VALUE) {
+ return true;
+ }
+ String rightButtonText = getString(rightBottomButtonTextId);
+ boolean portrait = AndroidUiHelper.isOrientationPortrait(activity);
+ int outerPadding = getResources().getDimensionPixelSize(R.dimen.content_padding);
+ int innerPadding = getResources().getDimensionPixelSize(R.dimen.content_padding_small);
+ int dialogWidth = portrait ? AndroidUtils.getScreenWidth(activity) : getResources().getDimensionPixelSize(R.dimen.landscape_bottom_sheet_dialog_fragment_width);
+ int availableTextWidth = (dialogWidth - (outerPadding * 3 + innerPadding * 4)) / 2;
+
+ int measuredTextWidth = AndroidUtils.getTextWidth(getResources().getDimensionPixelSize(R.dimen.default_desc_text_size), rightButtonText);
+ return measuredTextWidth > availableTextWidth;
+ }
+ return false;
+ }
+
protected void updateBottomButtons() {
if (dismissButton != null) {
boolean enabled = isDismissButtonEnabled();
@@ -301,6 +339,66 @@ public abstract class MenuBottomSheetDialogFragment extends BottomSheetDialogFra
}
}
+ private void setupDismissButton() {
+ dismissButton = buttonsContainer.findViewById(R.id.dismiss_button);
+ int buttonTextId = getDismissButtonTextId();
+ if (buttonTextId != DEFAULT_VALUE) {
+ UiUtilities.setupDialogButton(nightMode, dismissButton, getDismissButtonType(), buttonTextId);
+ dismissButton.setOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(View v) {
+ onDismissButtonClickAction();
+ dismiss();
+ }
+ });
+ }
+ AndroidUiHelper.updateVisibility(dismissButton, buttonTextId != DEFAULT_VALUE);
+ }
+
+ private void setupRightButton() {
+ rightButton = buttonsContainer.findViewById(R.id.right_bottom_button);
+ int buttonTextId = getRightBottomButtonTextId();
+ if (buttonTextId != DEFAULT_VALUE) {
+ UiUtilities.setupDialogButton(nightMode, rightButton, getRightBottomButtonType(), buttonTextId);
+ rightButton.setOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(View v) {
+ onRightBottomButtonClick();
+ }
+ });
+ }
+ View divider = buttonsContainer.findViewById(R.id.buttons_divider);
+ divider.getLayoutParams().height = getFirstDividerHeight();
+ AndroidUiHelper.updateVisibility(rightButton, buttonTextId != DEFAULT_VALUE);
+ AndroidUiHelper.updateVisibility(divider, buttonTextId != DEFAULT_VALUE);
+ }
+
+ protected int getFirstDividerHeight() {
+ return getResources().getDimensionPixelSize(R.dimen.content_padding);
+ }
+
+ private void setupThirdButton() {
+ thirdButton = buttonsContainer.findViewById(R.id.third_button);
+ int buttonTextId = getThirdBottomButtonTextId();
+ if (buttonTextId != DEFAULT_VALUE) {
+ UiUtilities.setupDialogButton(nightMode, thirdButton, getThirdBottomButtonType(), buttonTextId);
+ thirdButton.setOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(View v) {
+ onThirdBottomButtonClick();
+ }
+ });
+ }
+ View divider = buttonsContainer.findViewById(R.id.buttons_divider_top);
+ divider.getLayoutParams().height = getSecondDividerHeight();
+ AndroidUiHelper.updateVisibility(thirdButton, buttonTextId != DEFAULT_VALUE);
+ AndroidUiHelper.updateVisibility(divider, buttonTextId != DEFAULT_VALUE);
+ }
+
+ protected int getSecondDividerHeight() {
+ return getResources().getDimensionPixelSize(R.dimen.content_padding);
+ }
+
@ColorRes
protected int getBgColorId() {
return nightMode ? R.color.list_background_color_dark : R.color.list_background_color_light;
@@ -325,7 +423,7 @@ public abstract class MenuBottomSheetDialogFragment extends BottomSheetDialogFra
private LayerDrawable createBackgroundDrawable(@NonNull Context ctx, @DrawableRes int shadowDrawableResId) {
Drawable shadowDrawable = ContextCompat.getDrawable(ctx, shadowDrawableResId);
- Drawable[] layers = new Drawable[]{shadowDrawable, getColoredBg(ctx)};
+ Drawable[] layers = new Drawable[] {shadowDrawable, getColoredBg(ctx)};
return new LayerDrawable(layers);
}
@@ -335,4 +433,21 @@ public abstract class MenuBottomSheetDialogFragment extends BottomSheetDialogFra
}
return !app.getSettings().isLightContent();
}
-}
+
+ private void setupScrollShadow(View view) {
+ final View scrollView;
+ if (useScrollableItemsContainer()) {
+ scrollView = view.findViewById(R.id.scroll_view);
+ } else {
+ scrollView = itemsContainer;
+ }
+ scrollView.getViewTreeObserver().addOnScrollChangedListener(new OnScrollChangedListener() {
+
+ @Override
+ public void onScrollChanged() {
+ boolean scrollToBottomAvailable = scrollView.canScrollVertically(1);
+ AndroidUiHelper.updateVisibility(buttonsShadow, scrollToBottomAvailable);
+ }
+ });
+ }
+}
\ No newline at end of file
diff --git a/OsmAnd/src/net/osmand/plus/chooseplan/ChoosePlanDialogFragment.java b/OsmAnd/src/net/osmand/plus/chooseplan/ChoosePlanDialogFragment.java
index 1e3b650a8f..9a7215867f 100644
--- a/OsmAnd/src/net/osmand/plus/chooseplan/ChoosePlanDialogFragment.java
+++ b/OsmAnd/src/net/osmand/plus/chooseplan/ChoosePlanDialogFragment.java
@@ -215,6 +215,9 @@ public abstract class ChoosePlanDialogFragment extends BaseOsmAndDialogFragment
if (!TextUtils.isEmpty(getInfoDescription())) {
infoDescription.setText(getInfoDescription());
}
+ TextViewEx planInfoDescription = (TextViewEx) view.findViewById(R.id.plan_info_description);
+ planInfoDescription.setText(Version.isHuawei(app)
+ ? R.string.osm_live_payment_subscription_management_hw : R.string.osm_live_payment_subscription_management);
ViewGroup osmLiveCard = buildOsmLiveCard(ctx, cardsContainer);
if (osmLiveCard != null) {
cardsContainer.addView(osmLiveCard);
@@ -428,7 +431,7 @@ public abstract class ChoosePlanDialogFragment extends BaseOsmAndDialogFragment
buttonCancelView.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
- manageSubscription(ctx, s.getSku());
+ purchaseHelper.manageSubscription(ctx, s.getSku());
}
});
div.setVisibility(View.VISIBLE);
@@ -538,15 +541,6 @@ public abstract class ChoosePlanDialogFragment extends BaseOsmAndDialogFragment
}
}
- private void manageSubscription(@NonNull Context ctx, @Nullable String sku) {
- String url = "https://play.google.com/store/account/subscriptions?package=" + ctx.getPackageName();
- if (!Algorithms.isEmpty(sku)) {
- url += "&sku=" + sku;
- }
- Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
- startActivity(intent);
- }
-
private ViewGroup buildPlanTypeCard(@NonNull Context ctx, ViewGroup container) {
if (getPlanTypeFeatures().length == 0) {
return null;
diff --git a/OsmAnd/src/net/osmand/plus/chooseplan/ChoosePlanHillshadeSrtmDialogFragment.java b/OsmAnd/src/net/osmand/plus/chooseplan/ChoosePlanHillshadeSrtmDialogFragment.java
index b2858b53b8..d3a48a5a15 100644
--- a/OsmAnd/src/net/osmand/plus/chooseplan/ChoosePlanHillshadeSrtmDialogFragment.java
+++ b/OsmAnd/src/net/osmand/plus/chooseplan/ChoosePlanHillshadeSrtmDialogFragment.java
@@ -79,7 +79,7 @@ public class ChoosePlanHillshadeSrtmDialogFragment extends ChoosePlanDialogFragm
public void onClick(View v) {
Activity activity = getActivity();
if (activity != null) {
- OsmandInAppPurchaseActivity.purchaseSrtmPlugin(activity);
+ OsmandInAppPurchaseActivity.purchaseContourLines(activity);
dismiss();
}
}
diff --git a/OsmAnd/src/net/osmand/plus/chooseplan/OsmLiveCancelledDialog.java b/OsmAnd/src/net/osmand/plus/chooseplan/OsmLiveCancelledDialog.java
index 788b605eec..a62ffcd296 100644
--- a/OsmAnd/src/net/osmand/plus/chooseplan/OsmLiveCancelledDialog.java
+++ b/OsmAnd/src/net/osmand/plus/chooseplan/OsmLiveCancelledDialog.java
@@ -23,8 +23,9 @@ import androidx.fragment.app.FragmentManager;
import net.osmand.PlatformUtil;
import net.osmand.plus.OsmandApplication;
+import net.osmand.plus.Version;
import net.osmand.plus.settings.backend.OsmandSettings;
-import net.osmand.plus.settings.backend.OsmandSettings.OsmandPreference;
+import net.osmand.plus.settings.backend.OsmandPreference;
import net.osmand.plus.R;
import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.base.BaseOsmAndDialogFragment;
@@ -110,6 +111,8 @@ public class OsmLiveCancelledDialog extends BaseOsmAndDialogFragment implements
descr.append("\n").append("— ").append(feature.toHumanString(ctx));
}
infoDescr.setText(descr);
+ TextViewEx inappDescr = (TextViewEx) view.findViewById(R.id.inapp_descr);
+ inappDescr.setText(Version.isHuawei(app) ? R.string.osm_live_payment_desc_hw : R.string.osm_live_payment_desc);
osmLiveButton = view.findViewById(R.id.card_button);
diff --git a/OsmAnd/src/net/osmand/plus/dashboard/DashChooseAppDirFragment.java b/OsmAnd/src/net/osmand/plus/dashboard/DashChooseAppDirFragment.java
index 9f37cd1b41..883010ea46 100644
--- a/OsmAnd/src/net/osmand/plus/dashboard/DashChooseAppDirFragment.java
+++ b/OsmAnd/src/net/osmand/plus/dashboard/DashChooseAppDirFragment.java
@@ -30,6 +30,7 @@ import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentActivity;
import net.osmand.AndroidUtils;
+import net.osmand.FileUtils;
import net.osmand.ValueHolder;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.settings.backend.OsmandSettings;
@@ -113,7 +114,7 @@ public class DashChooseAppDirFragment {
boolean copyFiles = !currentAppFile.getAbsolutePath().equals(selectedFile.getAbsolutePath()) && !mapsCopied;
warningReadonly.setVisibility(copyFiles ? View.VISIBLE : View.GONE);
if (copyFiles) {
- if (!OsmandSettings.isWritable(currentAppFile)) {
+ if (!FileUtils.isWritable(currentAppFile)) {
warningReadonly.setText(activity.getString(R.string.android_19_location_disabled,
currentAppFile.getAbsolutePath()));
} else {
@@ -385,7 +386,7 @@ public class DashChooseAppDirFragment {
@Override
public void onClick(View v) {
- boolean wr = OsmandSettings.isWritable(selectedFile);
+ boolean wr = FileUtils.isWritable(selectedFile);
if (wr) {
boolean changed = !currentAppFile.getAbsolutePath().equals(selectedFile.getAbsolutePath());
getMyApplication().setExternalStorageDirectory(type, selectedFile.getAbsolutePath());
diff --git a/OsmAnd/src/net/osmand/plus/dashboard/tools/DashboardSettingsDialogFragment.java b/OsmAnd/src/net/osmand/plus/dashboard/tools/DashboardSettingsDialogFragment.java
index 1689a4e298..725a8fefc6 100644
--- a/OsmAnd/src/net/osmand/plus/dashboard/tools/DashboardSettingsDialogFragment.java
+++ b/OsmAnd/src/net/osmand/plus/dashboard/tools/DashboardSettingsDialogFragment.java
@@ -24,7 +24,7 @@ import net.osmand.PlatformUtil;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.OsmandPlugin;
import net.osmand.plus.settings.backend.OsmandSettings;
-import net.osmand.plus.settings.backend.OsmandSettings.CommonPreference;
+import net.osmand.plus.settings.backend.CommonPreference;
import net.osmand.plus.R;
import net.osmand.plus.UiUtilities;
import net.osmand.plus.activities.MapActivity;
diff --git a/OsmAnd/src/net/osmand/plus/development/DevelopmentSettingsFragment.java b/OsmAnd/src/net/osmand/plus/development/DevelopmentSettingsFragment.java
index 7a3503e004..bad57f326b 100644
--- a/OsmAnd/src/net/osmand/plus/development/DevelopmentSettingsFragment.java
+++ b/OsmAnd/src/net/osmand/plus/development/DevelopmentSettingsFragment.java
@@ -35,12 +35,7 @@ public class DevelopmentSettingsFragment extends BaseSettingsFragment {
setupOpenglRenderPref();
setupSafeModePref();
- setupPTSafeMode();
- setupDisableComplexRoutingPref();
- setupFastRecalculationPref();
- setupOsmLiveForRoutingPref();
- setupOsmLiveForPublicTransportPref();
setupSimulateYourLocationPref();
Preference debuggingAndDevelopment = findPreference("debugging_and_development");
@@ -62,13 +57,17 @@ public class DevelopmentSettingsFragment extends BaseSettingsFragment {
}
private void setupOpenglRenderPref() {
- SwitchPreferenceEx useOpenglRender = (SwitchPreferenceEx) findPreference(settings.USE_OPENGL_RENDER.getId());
- useOpenglRender.setDescription(getString(R.string.use_opengl_render_descr));
- useOpenglRender.setIconSpaceReserved(false);
+ SwitchPreferenceEx useOpenglRender = findPreference(settings.USE_OPENGL_RENDER.getId());
+ if (Version.isOpenGlAvailable(app)) {
+ useOpenglRender.setDescription(getString(R.string.use_opengl_render_descr));
+ useOpenglRender.setIconSpaceReserved(false);
+ } else {
+ useOpenglRender.setVisible(false);
+ }
}
private void setupSafeModePref() {
- SwitchPreferenceEx safeMode = (SwitchPreferenceEx) findPreference(settings.SAFE_MODE.getId());
+ SwitchPreferenceEx safeMode = findPreference(settings.SAFE_MODE.getId());
if (!Version.isBlackberry(app)) {
safeMode.setDescription(getString(R.string.safe_mode_description));
safeMode.setIconSpaceReserved(false);
@@ -82,40 +81,6 @@ public class DevelopmentSettingsFragment extends BaseSettingsFragment {
}
}
- private void setupPTSafeMode() {
- SwitchPreferenceEx ptSafeMode = (SwitchPreferenceEx) findPreference(settings.PT_SAFE_MODE.getId());
- if (!Version.isBlackberry(app)) {
- ptSafeMode.setDescription("Switch to Java (safe) Public Transport routing calculation");
- ptSafeMode.setIconSpaceReserved(false);
- } else {
- ptSafeMode.setVisible(false);
- }
- }
-
- private void setupDisableComplexRoutingPref() {
- SwitchPreferenceEx disableComplexRouting = (SwitchPreferenceEx) findPreference(settings.DISABLE_COMPLEX_ROUTING.getId());
- disableComplexRouting.setDescription(getString(R.string.disable_complex_routing_descr));
- disableComplexRouting.setIconSpaceReserved(false);
- }
-
- private void setupFastRecalculationPref() {
- SwitchPreferenceEx useFastRecalculation = (SwitchPreferenceEx) findPreference(settings.USE_FAST_RECALCULATION.getId());
- useFastRecalculation.setDescription(getString(R.string.use_fast_recalculation_desc));
- useFastRecalculation.setIconSpaceReserved(false);
- }
-
- private void setupOsmLiveForRoutingPref() {
- SwitchPreferenceEx useOsmLiveForRouting = (SwitchPreferenceEx) findPreference(settings.USE_OSM_LIVE_FOR_ROUTING.getId());
- useOsmLiveForRouting.setDescription(getString(R.string.use_osm_live_routing_description));
- useOsmLiveForRouting.setIconSpaceReserved(false);
- }
-
- private void setupOsmLiveForPublicTransportPref() {
- SwitchPreferenceEx useOsmLiveForPublicTransport = (SwitchPreferenceEx) findPreference(settings.USE_OSM_LIVE_FOR_PUBLIC_TRANSPORT.getId());
- useOsmLiveForPublicTransport.setDescription(getString(R.string.use_osm_live_public_transport_description));
- useOsmLiveForPublicTransport.setIconSpaceReserved(false);
- }
-
private void setupSimulateYourLocationPref() {
final Preference simulateYourLocation = findPreference(SIMULATE_YOUR_LOCATION);
simulateYourLocation.setIconSpaceReserved(false);
diff --git a/OsmAnd/src/net/osmand/plus/development/SettingsDevelopmentActivity.java b/OsmAnd/src/net/osmand/plus/development/SettingsDevelopmentActivity.java
index b5ea815bed..c500a28254 100644
--- a/OsmAnd/src/net/osmand/plus/development/SettingsDevelopmentActivity.java
+++ b/OsmAnd/src/net/osmand/plus/development/SettingsDevelopmentActivity.java
@@ -14,11 +14,11 @@ import android.preference.PreferenceScreen;
import net.osmand.plus.OsmAndLocationSimulation;
import net.osmand.plus.OsmandApplication;
-import net.osmand.plus.settings.backend.OsmandSettings;
import net.osmand.plus.R;
import net.osmand.plus.Version;
import net.osmand.plus.activities.SettingsBaseActivity;
import net.osmand.plus.render.NativeOsmandLibrary;
+import net.osmand.plus.settings.backend.OsmandSettings;
import net.osmand.util.SunriseSunset;
import java.text.SimpleDateFormat;
@@ -34,41 +34,27 @@ public class SettingsDevelopmentActivity extends SettingsBaseActivity {
app.applyTheme(this);
super.onCreate(savedInstanceState);
getToolbar().setTitle(R.string.debugging_and_development);
- PreferenceScreen cat = getPreferenceScreen();
+ PreferenceScreen category = getPreferenceScreen();
Preference pref;
- cat.addPreference(createCheckBoxPreference(settings.USE_OPENGL_RENDER,
- R.string.use_opengl_render, R.string.use_opengl_render_descr));
+ if (Version.isOpenGlAvailable(app)) {
+ category.addPreference(createCheckBoxPreference(settings.USE_OPENGL_RENDER,
+ R.string.use_opengl_render, R.string.use_opengl_render_descr));
+ }
if (!Version.isBlackberry(app)) {
CheckBoxPreference nativeCheckbox = createCheckBoxPreference(settings.SAFE_MODE, R.string.safe_mode, R.string.safe_mode_description);
- CheckBoxPreference nativePTCheckbox = createCheckBoxPreference(settings.PT_SAFE_MODE, "Native PT routing development", "Switch to Java (safe) Public Transport routing calculation");
// disable the checkbox if the library cannot be used
if ((NativeOsmandLibrary.isLoaded() && !NativeOsmandLibrary.isSupported()) || settings.NATIVE_RENDERING_FAILED.get()) {
nativeCheckbox.setEnabled(false);
nativeCheckbox.setChecked(true);
}
- cat.addPreference(nativeCheckbox);
- cat.addPreference(nativePTCheckbox);
+ category.addPreference(nativeCheckbox);
}
PreferenceCategory navigation = new PreferenceCategory(this);
navigation.setTitle(R.string.routing_settings);
- cat.addPreference(navigation);
- navigation.addPreference(createCheckBoxPreference(settings.DISABLE_COMPLEX_ROUTING,
- R.string.disable_complex_routing, R.string.disable_complex_routing_descr));
-
- navigation.addPreference(createCheckBoxPreference(settings.USE_FAST_RECALCULATION,
- R.string.use_fast_recalculation, R.string.use_fast_recalculation_desc));
-
- navigation.addPreference(createCheckBoxPreference(settings.USE_OSM_LIVE_FOR_ROUTING,
- R.string.use_osm_live_routing,
- R.string.use_osm_live_routing_description));
-
- navigation.addPreference(createCheckBoxPreference(settings.USE_OSM_LIVE_FOR_PUBLIC_TRANSPORT,
- R.string.use_osm_live_public_transport,
- R.string.use_osm_live_public_transport_description));
-
+ category.addPreference(navigation);
pref = new Preference(this);
final Preference simulate = pref;
final OsmAndLocationSimulation sim = getMyApplication().getLocationProvider().getLocationSimulation();
@@ -95,7 +81,7 @@ public class SettingsDevelopmentActivity extends SettingsBaseActivity {
PreferenceCategory debug = new PreferenceCategory(this);
debug.setTitle(R.string.debugging_and_development);
- cat.addPreference(debug);
+ category.addPreference(debug);
CheckBoxPreference dbg = createCheckBoxPreference(settings.DEBUG_RENDERING_INFO,
R.string.trace_rendering, R.string.trace_rendering_descr);
@@ -125,10 +111,6 @@ public class SettingsDevelopmentActivity extends SettingsBaseActivity {
debug.addPreference(createCheckBoxPreference(settings.SHOULD_SHOW_FREE_VERSION_BANNER,
R.string.show_free_version_banner,
R.string.show_free_version_banner_description));
-
-
-
-
pref = new Preference(this);
pref.setTitle(R.string.test_voice_prompts);
@@ -141,7 +123,7 @@ public class SettingsDevelopmentActivity extends SettingsBaseActivity {
return true;
}
});
- cat.addPreference(pref);
+ category.addPreference(pref);
pref = new Preference(this);
pref.setTitle(R.string.logcat_buffer);
@@ -154,11 +136,11 @@ public class SettingsDevelopmentActivity extends SettingsBaseActivity {
return true;
}
});
- cat.addPreference(pref);
+ category.addPreference(pref);
PreferenceCategory info = new PreferenceCategory(this);
info.setTitle(R.string.info_button);
- cat.addPreference(info);
+ category.addPreference(info);
pref = new Preference(this);
pref.setTitle(R.string.global_app_allocated_memory);
diff --git a/OsmAnd/src/net/osmand/plus/development/TestVoiceActivity.java b/OsmAnd/src/net/osmand/plus/development/TestVoiceActivity.java
index f1cddde833..a9a0ba563e 100644
--- a/OsmAnd/src/net/osmand/plus/development/TestVoiceActivity.java
+++ b/OsmAnd/src/net/osmand/plus/development/TestVoiceActivity.java
@@ -19,7 +19,7 @@ import android.widget.Toast;
import androidx.appcompat.app.AlertDialog;
import net.osmand.plus.OsmandApplication;
-import net.osmand.plus.settings.backend.OsmandSettings;
+import net.osmand.plus.settings.backend.OsmandPreference;
import net.osmand.plus.R;
import net.osmand.plus.activities.OsmandActionBarActivity;
import net.osmand.plus.routing.data.StreetName;
@@ -151,7 +151,7 @@ public class TestVoiceActivity extends OsmandActionBarActivity {
v += "\n \u25CF BT SCO: The current app profile is not set to use 'Phone call audio'.";
}
- //OsmandSettings.OsmandPreference pref = ((OsmandApplication) getApplication()).getSettings().VOICE_PROMPT_DELAY[stream];
+ //OsmandPreference pref = ((OsmandApplication) getApplication()).getSettings().VOICE_PROMPT_DELAY[stream];
//if(pref != null) {
// v += "\n \u25CF Voice prompt delay for selected output: " + pref.get() + "\u00A0ms";
//}
@@ -299,7 +299,7 @@ public class TestVoiceActivity extends OsmandActionBarActivity {
}
if (description.startsWith("\u25BA (11.2)")) {
int ams = ((OsmandApplication) getApplication()).getSettings().AUDIO_MANAGER_STREAM.get();
- OsmandSettings.OsmandPreference pref = ((OsmandApplication) getApplication()).getSettings().VOICE_PROMPT_DELAY[ams];
+ OsmandPreference pref = ((OsmandApplication) getApplication()).getSettings().VOICE_PROMPT_DELAY[ams];
if (pref != null) {
if (pref.get() >= 3000) {
pref.set(0);
diff --git a/OsmAnd/src/net/osmand/plus/dialogs/ConfigureMapMenu.java b/OsmAnd/src/net/osmand/plus/dialogs/ConfigureMapMenu.java
index 83c4e1942d..1c01808be8 100644
--- a/OsmAnd/src/net/osmand/plus/dialogs/ConfigureMapMenu.java
+++ b/OsmAnd/src/net/osmand/plus/dialogs/ConfigureMapMenu.java
@@ -33,6 +33,11 @@ import net.osmand.plus.ContextMenuItem;
import net.osmand.plus.DialogListItemAdapter;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.OsmandPlugin;
+import net.osmand.plus.helpers.enums.DayNightMode;
+import net.osmand.plus.settings.backend.OsmandPreference;
+import net.osmand.plus.settings.backend.OsmandSettings;
+import net.osmand.plus.settings.backend.CommonPreference;
+import net.osmand.plus.settings.backend.ListStringPreference;
import net.osmand.plus.R;
import net.osmand.plus.UiUtilities;
import net.osmand.plus.activities.MapActivity;
@@ -40,9 +45,6 @@ import net.osmand.plus.activities.SettingsActivity;
import net.osmand.plus.inapp.InAppPurchaseHelper;
import net.osmand.plus.poi.PoiUIFilter;
import net.osmand.plus.render.RendererRegistry;
-import net.osmand.plus.settings.backend.OsmandSettings;
-import net.osmand.plus.settings.backend.OsmandSettings.CommonPreference;
-import net.osmand.plus.settings.backend.OsmandSettings.ListStringPreference;
import net.osmand.plus.srtmplugin.SRTMPlugin;
import net.osmand.plus.transport.TransportLinesMenu;
import net.osmand.plus.views.OsmandMapTileView;
@@ -307,7 +309,7 @@ public class ConfigureMapMenu {
DateFormat dateFormat = DateFormat.getTimeInstance(DateFormat.SHORT);
String sunriseTime = dateFormat.format(sunriseSunset.getSunrise());
String sunsetTime = dateFormat.format(sunriseSunset.getSunset());
- OsmandSettings.DayNightMode dayNightMode = activity.getMyApplication().getSettings().DAYNIGHT_MODE.get();
+ DayNightMode dayNightMode = activity.getMyApplication().getSettings().DAYNIGHT_MODE.get();
if (dayNightMode.isDay() || dayNightMode.isNight()) {
if (sunriseSunset.isDaytime()) {
description = String.format(app.getString(R.string.sunset_at), sunsetTime);
@@ -334,9 +336,9 @@ public class ConfigureMapMenu {
final OsmandMapTileView view = activity.getMapView();
AlertDialog.Builder bld = new AlertDialog.Builder(new ContextThemeWrapper(view.getContext(), themeRes));
bld.setTitle(R.string.daynight);
- final String[] items = new String[OsmandSettings.DayNightMode.values().length];
+ final String[] items = new String[DayNightMode.values().length];
for (int i = 0; i < items.length; i++) {
- items[i] = OsmandSettings.DayNightMode.values()[i].toHumanString(app);
+ items[i] = DayNightMode.values()[i].toHumanString(app);
}
int i = view.getSettings().DAYNIGHT_MODE.get().ordinal();
bld.setNegativeButton(R.string.shared_string_dismiss, null);
@@ -345,7 +347,7 @@ public class ConfigureMapMenu {
@Override
public void onClick(View v) {
int which = (int) v.getTag();
- view.getSettings().DAYNIGHT_MODE.set(OsmandSettings.DayNightMode.values()[which]);
+ view.getSettings().DAYNIGHT_MODE.set(DayNightMode.values()[which]);
refreshMapComplete(activity);
activity.getDashboard().refreshContent(true);
// adapter.getItem(pos).setDescription(s, getDayNightDescr(activity));
@@ -376,7 +378,7 @@ public class ConfigureMapMenu {
return false;
}
final OsmandMapTileView view = activity.getMapView();
- final OsmandSettings.OsmandPreference mapDensity = view.getSettings().MAP_DENSITY;
+ final OsmandPreference mapDensity = view.getSettings().MAP_DENSITY;
AlertDialog.Builder bld = new AlertDialog.Builder(new ContextThemeWrapper(view.getContext(), themeRes));
int p = (int) (mapDensity.get() * 100);
final TIntArrayList tlist = new TIntArrayList(new int[]{25, 33, 50, 75, 100, 125, 150, 200, 300, 400});
@@ -669,25 +671,25 @@ public class ConfigureMapMenu {
@ColorInt final int selectedProfileColor) {
final List ps = new ArrayList<>();
- final List> prefs = new ArrayList<>();
+ final List> prefs = new ArrayList<>();
Iterator it = customRules.iterator();
while (it.hasNext()) {
RenderingRuleProperty p = it.next();
if (category.equals(p.getCategory()) && p.isBoolean()) {
ps.add(p);
- final OsmandSettings.CommonPreference pref = activity.getMyApplication().getSettings()
+ final CommonPreference pref = activity.getMyApplication().getSettings()
.getCustomRenderBooleanProperty(p.getAttrName());
prefs.add(pref);
it.remove();
}
}
if (prefs.size() > 0) {
- final List> includedPrefs = new ArrayList<>();
+ final List> includedPrefs = new ArrayList<>();
if (customRulesIncluded != null) {
for (RenderingRuleProperty p : customRulesIncluded) {
if (!p.isBoolean()) {
- final OsmandSettings.CommonPreference pref = activity.getMyApplication().getSettings()
+ final CommonPreference pref = activity.getMyApplication().getSettings()
.getCustomRenderProperty(p.getAttrName());
includedPrefs.add(pref);
}
@@ -729,14 +731,14 @@ public class ConfigureMapMenu {
.setId(id)
.setIcon(icon).setListener(clickListener);
boolean selected = false;
- for (OsmandSettings.CommonPreference p : prefs) {
+ for (CommonPreference p : prefs) {
if (p.get()) {
selected = true;
break;
}
}
if (!selected && includedPrefs.size() > 0) {
- for (OsmandSettings.CommonPreference p : includedPrefs) {
+ for (CommonPreference p : includedPrefs) {
if (!Algorithms.isEmpty(p.get())) {
selected = true;
break;
@@ -773,17 +775,17 @@ public class ConfigureMapMenu {
return null;
}
- protected String getDescription(final List> prefs,
- final List> includedPrefs) {
+ protected String getDescription(final List> prefs,
+ final List> includedPrefs) {
int count = 0;
int enabled = 0;
- for (OsmandSettings.CommonPreference p : prefs) {
+ for (CommonPreference p : prefs) {
count++;
if (p.get()) {
enabled++;
}
}
- for (OsmandSettings.CommonPreference p : includedPrefs) {
+ for (CommonPreference p : includedPrefs) {
count++;
if (!Algorithms.isEmpty(p.get())) {
enabled++;
@@ -856,11 +858,11 @@ public class ConfigureMapMenu {
prefs.get(i).set(tempPrefs[i]);
selected |= tempPrefs[i];
}
- final List> includedPrefs = new ArrayList<>();
+ final List> includedPrefs = new ArrayList<>();
if (customRulesIncluded != null) {
for (RenderingRuleProperty p : customRulesIncluded) {
if (p.getAttrName().equals(HIKING_ROUTES_OSMC_ATTR)) {
- final OsmandSettings.CommonPreference pref = activity.getMyApplication().getSettings()
+ final CommonPreference pref = activity.getMyApplication().getSettings()
.getCustomRenderProperty(p.getAttrName());
includedPrefs.add(pref);
if (hikingRouteOSMCValue == 0) {
@@ -894,7 +896,7 @@ public class ConfigureMapMenu {
if (customRulesIncluded != null) {
for (RenderingRuleProperty p : customRulesIncluded) {
if (!p.isBoolean()) {
- final OsmandSettings.CommonPreference pref = activity.getMyApplication().getSettings()
+ final CommonPreference pref = activity.getMyApplication().getSettings()
.getCustomRenderProperty(p.getAttrName());
View spinnerView = View.inflate(new ContextThemeWrapper(activity, themeRes), R.layout.spinner_rule_layout, null);
@@ -1031,7 +1033,7 @@ public class ConfigureMapMenu {
final String propertyDescr = SettingsActivity.getStringPropertyDescription(view.getContext(),
p.getAttrName(), p.getName());
if (p.isBoolean()) {
- final OsmandSettings.CommonPreference pref = view.getApplication().getSettings()
+ final CommonPreference pref = view.getApplication().getSettings()
.getCustomRenderBooleanProperty(p.getAttrName());
return ContextMenuItem.createBuilder(propertyName)
.setId(id)
@@ -1047,7 +1049,7 @@ public class ConfigureMapMenu {
.setSelected(pref.get())
.createItem();
} else {
- final OsmandSettings.CommonPreference pref = view.getApplication().getSettings()
+ final CommonPreference pref = view.getApplication().getSettings()
.getCustomRenderProperty(p.getAttrName());
final String descr;
if (!Algorithms.isEmpty(pref.get())) {
diff --git a/OsmAnd/src/net/osmand/plus/dialogs/DetailsBottomSheet.java b/OsmAnd/src/net/osmand/plus/dialogs/DetailsBottomSheet.java
index 4e8febb56e..ecb8f04b86 100644
--- a/OsmAnd/src/net/osmand/plus/dialogs/DetailsBottomSheet.java
+++ b/OsmAnd/src/net/osmand/plus/dialogs/DetailsBottomSheet.java
@@ -27,7 +27,7 @@ import net.osmand.plus.base.bottomsheetmenu.BottomSheetItemTwoChoicesButton.OnBo
import net.osmand.plus.base.bottomsheetmenu.BottomSheetItemWithCompoundButton;
import net.osmand.plus.base.bottomsheetmenu.simpleitems.DividerItem;
import net.osmand.plus.helpers.FontCache;
-import net.osmand.plus.settings.backend.OsmandSettings.CommonPreference;
+import net.osmand.plus.settings.backend.CommonPreference;
import net.osmand.plus.settings.bottomsheets.BasePreferenceBottomSheet;
import net.osmand.render.RenderingRuleProperty;
import net.osmand.render.RenderingRuleStorageProperties;
diff --git a/OsmAnd/src/net/osmand/plus/dialogs/RasterMapMenu.java b/OsmAnd/src/net/osmand/plus/dialogs/RasterMapMenu.java
index 534c334aec..8219cc5a23 100644
--- a/OsmAnd/src/net/osmand/plus/dialogs/RasterMapMenu.java
+++ b/OsmAnd/src/net/osmand/plus/dialogs/RasterMapMenu.java
@@ -10,8 +10,9 @@ import net.osmand.plus.ContextMenuAdapter;
import net.osmand.plus.ContextMenuItem;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.OsmandPlugin;
+import net.osmand.plus.settings.backend.CommonPreference;
import net.osmand.plus.settings.backend.OsmandSettings;
-import net.osmand.plus.settings.backend.OsmandSettings.LayerTransparencySeekbarMode;
+import net.osmand.plus.rastermaps.LayerTransparencySeekbarMode;
import net.osmand.plus.R;
import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.activities.MapActivityLayers;
@@ -39,9 +40,9 @@ public class RasterMapMenu {
final OsmandSettings settings = app.getSettings();
final OsmandRasterMapsPlugin plugin = OsmandPlugin.getEnabledPlugin(OsmandRasterMapsPlugin.class);
assert plugin != null;
- final OsmandSettings.CommonPreference mapTransparencyPreference;
- final OsmandSettings.CommonPreference mapTypePreference;
- final OsmandSettings.CommonPreference exMapTypePreference;
+ final CommonPreference mapTransparencyPreference;
+ final CommonPreference mapTypePreference;
+ final CommonPreference exMapTypePreference;
final LayerTransparencySeekbarMode currentMapTypeSeekbarMode =
type == RasterMapType.OVERLAY ? LayerTransparencySeekbarMode.OVERLAY : LayerTransparencySeekbarMode.UNDERLAY;
@StringRes final int mapTypeString;
@@ -62,7 +63,7 @@ public class RasterMapMenu {
throw new RuntimeException("Unexpected raster map type");
}
- final OsmandSettings.CommonPreference hidePolygonsPref =
+ final CommonPreference hidePolygonsPref =
mapActivity.getMyApplication().getSettings().getCustomRenderBooleanProperty("noPolygons");
String mapTypeDescr = mapTypePreference.get();
@@ -181,8 +182,8 @@ public class RasterMapMenu {
@NonNull
public static Boolean isSeekbarVisible(OsmandApplication app, RasterMapType type) {
- final OsmandSettings.LayerTransparencySeekbarMode currentMapTypeSeekbarMode =
- type == RasterMapType.OVERLAY ? OsmandSettings.LayerTransparencySeekbarMode.OVERLAY : OsmandSettings.LayerTransparencySeekbarMode.UNDERLAY;
+ final LayerTransparencySeekbarMode currentMapTypeSeekbarMode =
+ type == RasterMapType.OVERLAY ? LayerTransparencySeekbarMode.OVERLAY : LayerTransparencySeekbarMode.UNDERLAY;
LayerTransparencySeekbarMode seekbarMode = app.getSettings().LAYER_TRANSPARENCY_SEEKBAR_MODE.get();
return seekbarMode == LayerTransparencySeekbarMode.UNDEFINED || seekbarMode == currentMapTypeSeekbarMode;
}
diff --git a/OsmAnd/src/net/osmand/plus/dialogs/SendAnalyticsBottomSheetDialogFragment.java b/OsmAnd/src/net/osmand/plus/dialogs/SendAnalyticsBottomSheetDialogFragment.java
index f84ac5239e..983315c503 100644
--- a/OsmAnd/src/net/osmand/plus/dialogs/SendAnalyticsBottomSheetDialogFragment.java
+++ b/OsmAnd/src/net/osmand/plus/dialogs/SendAnalyticsBottomSheetDialogFragment.java
@@ -19,7 +19,7 @@ import androidx.fragment.app.FragmentManager;
import net.osmand.PlatformUtil;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.settings.backend.OsmandSettings;
-import net.osmand.plus.settings.backend.OsmandSettings.OsmandPreference;
+import net.osmand.plus.settings.backend.OsmandPreference;
import net.osmand.plus.R;
import net.osmand.plus.base.MenuBottomSheetDialogFragment;
import net.osmand.plus.base.bottomsheetmenu.BottomSheetItemWithCompoundButton;
diff --git a/OsmAnd/src/net/osmand/plus/download/DownloadIndexesThread.java b/OsmAnd/src/net/osmand/plus/download/DownloadIndexesThread.java
index 4b0dd632aa..80ce6cfb27 100644
--- a/OsmAnd/src/net/osmand/plus/download/DownloadIndexesThread.java
+++ b/OsmAnd/src/net/osmand/plus/download/DownloadIndexesThread.java
@@ -22,7 +22,7 @@ import net.osmand.map.WorldRegion;
import net.osmand.map.WorldRegion.RegionParams;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.settings.backend.OsmandSettings;
-import net.osmand.plus.settings.backend.OsmandSettings.OsmandPreference;
+import net.osmand.plus.settings.backend.OsmandPreference;
import net.osmand.plus.R;
import net.osmand.plus.Version;
import net.osmand.plus.base.BasicProgressAsyncTask;
diff --git a/OsmAnd/src/net/osmand/plus/download/ui/DataStoragePlaceDialogFragment.java b/OsmAnd/src/net/osmand/plus/download/ui/DataStoragePlaceDialogFragment.java
index dceeac1862..f97784cb36 100644
--- a/OsmAnd/src/net/osmand/plus/download/ui/DataStoragePlaceDialogFragment.java
+++ b/OsmAnd/src/net/osmand/plus/download/ui/DataStoragePlaceDialogFragment.java
@@ -21,6 +21,7 @@ import androidx.annotation.NonNull;
import androidx.fragment.app.FragmentManager;
import net.osmand.AndroidUtils;
+import net.osmand.FileUtils;
import net.osmand.IProgress;
import net.osmand.plus.OnDismissDialogFragmentListener;
import net.osmand.plus.OsmandApplication;
@@ -71,7 +72,7 @@ public class DataStoragePlaceDialogFragment extends BottomSheetDialogFragment {
File internalStorage = getInternalStorageDirectory(activity);
File external1Storage = getExternal1StorageDirectory(activity);
- if (external1Storage != null && external1Storage.exists() && OsmandSettings.isWritable(external1Storage)) {
+ if (external1Storage != null && external1Storage.exists() && FileUtils.isWritable(external1Storage)) {
deviceStorage = external1Storage;
deviceStorageType = OsmandSettings.EXTERNAL_STORAGE_TYPE_EXTERNAL_FILE;
deviceStorageName = getString(R.string.storage_directory_external);
@@ -246,7 +247,7 @@ public class DataStoragePlaceDialogFragment extends BottomSheetDialogFragment {
};
public boolean saveFilesLocation(int type, File selectedFile, Activity context) {
- boolean wr = OsmandSettings.isWritable(selectedFile);
+ boolean wr = FileUtils.isWritable(selectedFile);
if (wr) {
((OsmandApplication) context.getApplication())
.setExternalStorageDirectory(type, selectedFile.getAbsolutePath());
diff --git a/OsmAnd/src/net/osmand/plus/activities/DayNightHelper.java b/OsmAnd/src/net/osmand/plus/helpers/DayNightHelper.java
similarity index 98%
rename from OsmAnd/src/net/osmand/plus/activities/DayNightHelper.java
rename to OsmAnd/src/net/osmand/plus/helpers/DayNightHelper.java
index f9ca2afca4..d3ebe9d6ae 100644
--- a/OsmAnd/src/net/osmand/plus/activities/DayNightHelper.java
+++ b/OsmAnd/src/net/osmand/plus/helpers/DayNightHelper.java
@@ -1,20 +1,6 @@
-package net.osmand.plus.activities;
+package net.osmand.plus.helpers;
-import java.util.Date;
-import java.util.List;
-import java.util.TimeZone;
-
-import net.osmand.Location;
-import net.osmand.PlatformUtil;
-import net.osmand.StateChangedListener;
-import net.osmand.plus.settings.backend.ApplicationMode;
-import net.osmand.plus.OsmandApplication;
-import net.osmand.plus.settings.backend.OsmandSettings.DayNightMode;
-import net.osmand.util.SunriseSunset;
-
-import org.apache.commons.logging.Log;
-
import android.content.Context;
import android.hardware.Sensor;
import android.hardware.SensorEvent;
@@ -22,6 +8,20 @@ import android.hardware.SensorEventListener;
import android.hardware.SensorManager;
import android.location.LocationManager;
+import net.osmand.Location;
+import net.osmand.PlatformUtil;
+import net.osmand.StateChangedListener;
+import net.osmand.plus.OsmandApplication;
+import net.osmand.plus.helpers.enums.DayNightMode;
+import net.osmand.plus.settings.backend.ApplicationMode;
+import net.osmand.util.SunriseSunset;
+
+import org.apache.commons.logging.Log;
+
+import java.util.Date;
+import java.util.List;
+import java.util.TimeZone;
+
/**
* Class to help determine if we want to render day or night map - it uses the
* DayNightMode enumeration for its behavior
diff --git a/OsmAnd/src/net/osmand/plus/helpers/DiscountHelper.java b/OsmAnd/src/net/osmand/plus/helpers/DiscountHelper.java
index 61ae82399f..a4bb6ec74f 100644
--- a/OsmAnd/src/net/osmand/plus/helpers/DiscountHelper.java
+++ b/OsmAnd/src/net/osmand/plus/helpers/DiscountHelper.java
@@ -20,12 +20,14 @@ import androidx.annotation.NonNull;
import androidx.appcompat.content.res.AppCompatResources;
import net.osmand.AndroidNetworkUtils;
+import net.osmand.PlatformUtil;
import net.osmand.osm.AbstractPoiType;
import net.osmand.osm.MapPoiTypes;
import net.osmand.osm.PoiCategory;
import net.osmand.osm.PoiType;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.OsmandPlugin;
+import net.osmand.plus.activities.OsmandInAppPurchaseActivity;
import net.osmand.plus.settings.backend.OsmandSettings;
import net.osmand.plus.R;
import net.osmand.plus.Version;
@@ -56,7 +58,7 @@ import java.util.Map;
public class DiscountHelper {
private static final String TAG = "DiscountHelper";
- //private static final String DISCOUNT_JSON = "discount.json";
+ private static final org.apache.commons.logging.Log LOG = PlatformUtil.getLog(DiscountHelper.class);
private static long mLastCheckTime;
private static ControllerData mData;
@@ -81,7 +83,7 @@ public class DiscountHelper {
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() || Version.isHuawei(app)) {
+ if (settings.DO_NOT_SHOW_STARTUP_MESSAGES.get() || !settings.INAPPS_READ.get()) {
return;
}
if (mBannerVisible) {
@@ -312,7 +314,11 @@ public class DiscountHelper {
if (purchaseHelper != null) {
if (url.contains(purchaseHelper.getFullVersion().getSku())) {
app.logEvent("in_app_purchase_redirect");
- purchaseHelper.purchaseFullVersion(mapActivity);
+ try {
+ purchaseHelper.purchaseFullVersion(mapActivity);
+ } catch (UnsupportedOperationException e) {
+ LOG.error("purchaseFullVersion is not supported", e);
+ }
} else {
for (InAppPurchase p : purchaseHelper.getLiveUpdates().getAllSubscriptions()) {
if (url.contains(p.getSku())) {
diff --git a/OsmAnd/src/net/osmand/plus/helpers/GpxUiHelper.java b/OsmAnd/src/net/osmand/plus/helpers/GpxUiHelper.java
index 989bbaa0f8..47650dc2ec 100644
--- a/OsmAnd/src/net/osmand/plus/helpers/GpxUiHelper.java
+++ b/OsmAnd/src/net/osmand/plus/helpers/GpxUiHelper.java
@@ -80,6 +80,10 @@ import net.osmand.plus.OsmAndConstants;
import net.osmand.plus.OsmAndFormatter;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.OsmandPlugin;
+import net.osmand.plus.helpers.enums.MetricsConstants;
+import net.osmand.plus.helpers.enums.SpeedConstants;
+import net.osmand.plus.settings.backend.CommonPreference;
+import net.osmand.plus.settings.backend.OsmandSettings;
import net.osmand.plus.R;
import net.osmand.plus.UiUtilities;
import net.osmand.plus.Version;
@@ -93,7 +97,6 @@ import net.osmand.plus.dialogs.GpxAppearanceAdapter;
import net.osmand.plus.dialogs.GpxAppearanceAdapter.AppearanceListItem;
import net.osmand.plus.monitoring.OsmandMonitoringPlugin;
import net.osmand.plus.routing.RouteCalculationResult;
-import net.osmand.plus.settings.backend.OsmandSettings;
import net.osmand.render.RenderingRuleProperty;
import net.osmand.render.RenderingRulesStorage;
import net.osmand.router.RouteStatisticsHelper;
@@ -514,9 +517,9 @@ public class GpxUiHelper {
} else {
final View apprTitleView = View.inflate(new ContextThemeWrapper(activity, themeRes), R.layout.select_gpx_appearance_title, null);
- final OsmandSettings.CommonPreference prefWidth
+ final CommonPreference prefWidth
= app.getSettings().getCustomRenderProperty(CURRENT_TRACK_WIDTH_ATTR);
- final OsmandSettings.CommonPreference prefColor
+ final CommonPreference prefColor
= app.getSettings().getCustomRenderProperty(CURRENT_TRACK_COLOR_ATTR);
updateAppearanceTitle(activity, app, trackWidthProp, renderer, apprTitleView, prefWidth.get(), prefColor.get());
@@ -574,7 +577,7 @@ public class GpxUiHelper {
if (SHOW_START_FINISH_ATTR.equals(entry.getKey())) {
app.getSettings().SHOW_START_FINISH_ICONS.set("true".equals(entry.getValue()));
} else {
- final OsmandSettings.CommonPreference pref
+ final CommonPreference pref
= app.getSettings().getCustomRenderProperty(entry.getKey());
pref.set(entry.getValue());
}
@@ -1039,7 +1042,7 @@ public class GpxUiHelper {
private static float setupAxisDistance(OsmandApplication ctx, AxisBase axisBase, float meters) {
OsmandSettings settings = ctx.getSettings();
- OsmandSettings.MetricsConstants mc = settings.METRIC_SYSTEM.get();
+ MetricsConstants mc = settings.METRIC_SYSTEM.get();
float divX;
String format1 = "{0,number,0.#} ";
@@ -1048,10 +1051,10 @@ public class GpxUiHelper {
float granularity = 1f;
int mainUnitStr;
float mainUnitInMeters;
- if (mc == OsmandSettings.MetricsConstants.KILOMETERS_AND_METERS) {
+ if (mc == MetricsConstants.KILOMETERS_AND_METERS) {
mainUnitStr = R.string.km;
mainUnitInMeters = METERS_IN_KILOMETER;
- } else if (mc == OsmandSettings.MetricsConstants.NAUTICAL_MILES) {
+ } else if (mc == MetricsConstants.NAUTICAL_MILES) {
mainUnitStr = R.string.nm;
mainUnitInMeters = METERS_IN_ONE_NAUTICALMILE;
} else {
@@ -1065,10 +1068,10 @@ public class GpxUiHelper {
if (meters >= 100 * mainUnitInMeters ||
meters > 9.99f * mainUnitInMeters ||
meters > 0.999f * mainUnitInMeters ||
- mc == OsmandSettings.MetricsConstants.MILES_AND_FEET && meters > 0.249f * mainUnitInMeters ||
- mc == OsmandSettings.MetricsConstants.MILES_AND_METERS && meters > 0.249f * mainUnitInMeters ||
- mc == OsmandSettings.MetricsConstants.MILES_AND_YARDS && meters > 0.249f * mainUnitInMeters ||
- mc == OsmandSettings.MetricsConstants.NAUTICAL_MILES && meters > 0.99f * mainUnitInMeters) {
+ mc == MetricsConstants.MILES_AND_FEET && meters > 0.249f * mainUnitInMeters ||
+ mc == MetricsConstants.MILES_AND_METERS && meters > 0.249f * mainUnitInMeters ||
+ mc == MetricsConstants.MILES_AND_YARDS && meters > 0.249f * mainUnitInMeters ||
+ mc == MetricsConstants.NAUTICAL_MILES && meters > 0.99f * mainUnitInMeters) {
divX = mainUnitInMeters;
if (fmt == null) {
@@ -1078,13 +1081,13 @@ public class GpxUiHelper {
} else {
fmt = null;
granularity = 1f;
- if (mc == OsmandSettings.MetricsConstants.KILOMETERS_AND_METERS || mc == OsmandSettings.MetricsConstants.MILES_AND_METERS) {
+ if (mc == MetricsConstants.KILOMETERS_AND_METERS || mc == MetricsConstants.MILES_AND_METERS) {
divX = 1f;
mainUnitStr = R.string.m;
- } else if (mc == OsmandSettings.MetricsConstants.MILES_AND_FEET) {
+ } else if (mc == MetricsConstants.MILES_AND_FEET) {
divX = 1f / FEET_IN_ONE_METER;
mainUnitStr = R.string.foot;
- } else if (mc == OsmandSettings.MetricsConstants.MILES_AND_YARDS) {
+ } else if (mc == MetricsConstants.MILES_AND_YARDS) {
divX = 1f / YARDS_IN_ONE_METER;
mainUnitStr = R.string.yard;
} else {
@@ -1306,8 +1309,8 @@ public class GpxUiHelper {
boolean drawFilled,
boolean calcWithoutGaps) {
OsmandSettings settings = ctx.getSettings();
- OsmandSettings.MetricsConstants mc = settings.METRIC_SYSTEM.get();
- boolean useFeet = (mc == OsmandSettings.MetricsConstants.MILES_AND_FEET) || (mc == OsmandSettings.MetricsConstants.MILES_AND_YARDS);
+ MetricsConstants mc = settings.METRIC_SYSTEM.get();
+ boolean useFeet = (mc == MetricsConstants.MILES_AND_FEET) || (mc == MetricsConstants.MILES_AND_YARDS);
boolean light = settings.isLightContent();
final float convEle = useFeet ? 3.28084f : 1.0f;
@@ -1408,19 +1411,19 @@ public class GpxUiHelper {
divX = setupAxisDistance(ctx, xAxis, calcWithoutGaps ? analysis.totalDistanceWithoutGaps : analysis.totalDistance);
}
- OsmandSettings.SpeedConstants sps = settings.SPEED_SYSTEM.get();
+ SpeedConstants sps = settings.SPEED_SYSTEM.get();
float mulSpeed = Float.NaN;
float divSpeed = Float.NaN;
final String mainUnitY = sps.toShortString(ctx);
- if (sps == OsmandSettings.SpeedConstants.KILOMETERS_PER_HOUR) {
+ if (sps == SpeedConstants.KILOMETERS_PER_HOUR) {
mulSpeed = 3.6f;
- } else if (sps == OsmandSettings.SpeedConstants.MILES_PER_HOUR) {
+ } else if (sps == SpeedConstants.MILES_PER_HOUR) {
mulSpeed = 3.6f * METERS_IN_KILOMETER / METERS_IN_ONE_MILE;
- } else if (sps == OsmandSettings.SpeedConstants.NAUTICALMILES_PER_HOUR) {
+ } else if (sps == SpeedConstants.NAUTICALMILES_PER_HOUR) {
mulSpeed = 3.6f * METERS_IN_KILOMETER / METERS_IN_ONE_NAUTICALMILE;
- } else if (sps == OsmandSettings.SpeedConstants.MINUTES_PER_KILOMETER) {
+ } else if (sps == SpeedConstants.MINUTES_PER_KILOMETER) {
divSpeed = METERS_IN_KILOMETER / 60;
- } else if (sps == OsmandSettings.SpeedConstants.MINUTES_PER_MILE) {
+ } else if (sps == SpeedConstants.MINUTES_PER_MILE) {
divSpeed = METERS_IN_ONE_MILE / 60;
} else {
mulSpeed = 1f;
@@ -1571,8 +1574,8 @@ public class GpxUiHelper {
}
OsmandSettings settings = ctx.getSettings();
boolean light = settings.isLightContent();
- OsmandSettings.MetricsConstants mc = settings.METRIC_SYSTEM.get();
- boolean useFeet = (mc == OsmandSettings.MetricsConstants.MILES_AND_FEET) || (mc == OsmandSettings.MetricsConstants.MILES_AND_YARDS);
+ MetricsConstants mc = settings.METRIC_SYSTEM.get();
+ boolean useFeet = (mc == MetricsConstants.MILES_AND_FEET) || (mc == MetricsConstants.MILES_AND_YARDS);
final float convEle = useFeet ? 3.28084f : 1.0f;
final float totalDistance = calcWithoutGaps ? analysis.totalDistanceWithoutGaps : analysis.totalDistance;
diff --git a/OsmAnd/src/net/osmand/plus/helpers/LockHelper.java b/OsmAnd/src/net/osmand/plus/helpers/LockHelper.java
index b0f34058d3..ddbb06f2be 100644
--- a/OsmAnd/src/net/osmand/plus/helpers/LockHelper.java
+++ b/OsmAnd/src/net/osmand/plus/helpers/LockHelper.java
@@ -20,7 +20,8 @@ import net.osmand.plus.OsmandApplication;
import net.osmand.plus.routing.VoiceRouter.VoiceMessageListener;
import net.osmand.plus.settings.backend.OsmAndAppCustomization.OsmAndAppCustomizationListener;
import net.osmand.plus.settings.backend.OsmandSettings;
-import net.osmand.plus.settings.backend.OsmandSettings.CommonPreference;
+import net.osmand.plus.settings.backend.CommonPreference;
+import net.osmand.plus.routing.VoiceRouter.VoiceMessageListener;
import org.apache.commons.logging.Log;
diff --git a/OsmAnd/src/net/osmand/plus/helpers/WaypointHelper.java b/OsmAnd/src/net/osmand/plus/helpers/WaypointHelper.java
index b143653754..7f20de3e60 100644
--- a/OsmAnd/src/net/osmand/plus/helpers/WaypointHelper.java
+++ b/OsmAnd/src/net/osmand/plus/helpers/WaypointHelper.java
@@ -24,6 +24,9 @@ import net.osmand.plus.TargetPointsHelper.TargetPoint;
import net.osmand.plus.UiUtilities;
import net.osmand.plus.activities.IntermediatePointsDialog;
import net.osmand.plus.base.PointImageDrawable;
+import net.osmand.plus.helpers.enums.DrivingRegion;
+import net.osmand.plus.helpers.enums.MetricsConstants;
+import net.osmand.plus.helpers.enums.SpeedConstants;
import net.osmand.plus.poi.PoiUIFilter;
import net.osmand.plus.render.RenderingIcons;
import net.osmand.plus.routing.AlarmInfo;
@@ -31,8 +34,6 @@ import net.osmand.plus.routing.AlarmInfo.AlarmInfoType;
import net.osmand.plus.routing.RouteCalculationResult;
import net.osmand.plus.routing.VoiceRouter;
import net.osmand.plus.settings.backend.ApplicationMode;
-import net.osmand.plus.settings.backend.OsmandSettings;
-import net.osmand.plus.settings.backend.OsmandSettings.MetricsConstants;
import net.osmand.util.MapUtils;
import java.util.ArrayList;
@@ -193,7 +194,7 @@ public class WaypointHelper {
return found;
}
- public AlarmInfo getMostImportantAlarm(OsmandSettings.SpeedConstants sc, boolean showCameras) {
+ public AlarmInfo getMostImportantAlarm(SpeedConstants sc, boolean showCameras) {
Location lastProjection = app.getRoutingHelper().getLastProjection();
float mxspeed = route.getCurrentMaxSpeed();
float delta = app.getSettings().SPEED_LIMIT_EXCEED_KMH.get() / 3.6f;
@@ -291,7 +292,7 @@ public class WaypointHelper {
}
public AlarmInfo calculateMostImportantAlarm(RouteDataObject ro, Location loc, MetricsConstants mc,
- OsmandSettings.SpeedConstants sc, boolean showCameras) {
+ SpeedConstants sc, boolean showCameras) {
float mxspeed = ro.getMaximumSpeed(ro.bearingVsRouteDirection(loc));
float delta = app.getSettings().SPEED_LIMIT_EXCEED_KMH.get() / 3.6f;
AlarmInfo speedAlarm = createSpeedAlarm(sc, mxspeed, loc, delta);
@@ -331,7 +332,7 @@ public class WaypointHelper {
return null;
}
- private static AlarmInfo createSpeedAlarm(OsmandSettings.SpeedConstants sc, float mxspeed, Location loc, float delta) {
+ private static AlarmInfo createSpeedAlarm(SpeedConstants sc, float mxspeed, Location loc, float delta) {
AlarmInfo speedAlarm = null;
if (mxspeed != 0 && loc != null && loc.hasSpeed() && mxspeed != RouteDataObject.NONE_MAX_SPEED) {
if (loc.getSpeed() > mxspeed + delta) {
@@ -790,7 +791,7 @@ public class WaypointHelper {
} else if (type == ALARMS) {
//assign alarm list icons manually for now
String typeString = ((AlarmInfo) point).getType().toString();
- OsmandSettings.DrivingRegion region = app.getSettings().DRIVING_REGION.get();
+ DrivingRegion region = app.getSettings().DRIVING_REGION.get();
if (typeString.equals("SPEED_CAMERA")) {
return AppCompatResources.getDrawable(uiCtx, R.drawable.mx_highway_speed_camera);
} else if (typeString.equals("BORDER_CONTROL")) {
diff --git a/OsmAnd/src/net/osmand/plus/helpers/enums/AngularConstants.java b/OsmAnd/src/net/osmand/plus/helpers/enums/AngularConstants.java
new file mode 100644
index 0000000000..4041380fe1
--- /dev/null
+++ b/OsmAnd/src/net/osmand/plus/helpers/enums/AngularConstants.java
@@ -0,0 +1,27 @@
+package net.osmand.plus.helpers.enums;
+
+import android.content.Context;
+
+import net.osmand.plus.R;
+
+public enum AngularConstants {
+ DEGREES(R.string.shared_string_degrees, "°"),
+ DEGREES360(R.string.shared_string_degrees, "°"),
+ MILLIRADS(R.string.shared_string_milliradians, "mil");
+
+ private final int key;
+ private final String unit;
+
+ AngularConstants(int key, String unit) {
+ this.key = key;
+ this.unit = unit;
+ }
+
+ public String toHumanString(Context ctx) {
+ return ctx.getString(key);
+ }
+
+ public String getUnitSymbol() {
+ return unit;
+ }
+}
\ No newline at end of file
diff --git a/OsmAnd/src/net/osmand/plus/helpers/enums/AutoZoomMap.java b/OsmAnd/src/net/osmand/plus/helpers/enums/AutoZoomMap.java
new file mode 100644
index 0000000000..ad09424924
--- /dev/null
+++ b/OsmAnd/src/net/osmand/plus/helpers/enums/AutoZoomMap.java
@@ -0,0 +1,19 @@
+package net.osmand.plus.helpers.enums;
+
+import net.osmand.plus.R;
+
+public enum AutoZoomMap {
+ FARTHEST(R.string.auto_zoom_farthest, 1f, 15.5f),
+ FAR(R.string.auto_zoom_far, 1.4f, 17f),
+ CLOSE(R.string.auto_zoom_close, 2f, 19f);
+
+ public final float coefficient;
+ public final int name;
+ public final float maxZoom;
+
+ AutoZoomMap(int name, float coefficient, float maxZoom) {
+ this.name = name;
+ this.coefficient = coefficient;
+ this.maxZoom = maxZoom;
+ }
+}
\ No newline at end of file
diff --git a/OsmAnd/src/net/osmand/plus/helpers/enums/DayNightMode.java b/OsmAnd/src/net/osmand/plus/helpers/enums/DayNightMode.java
new file mode 100644
index 0000000000..77f0eb8876
--- /dev/null
+++ b/OsmAnd/src/net/osmand/plus/helpers/enums/DayNightMode.java
@@ -0,0 +1,62 @@
+package net.osmand.plus.helpers.enums;
+
+import android.content.Context;
+import android.hardware.Sensor;
+import android.hardware.SensorManager;
+
+import androidx.annotation.DrawableRes;
+import androidx.annotation.StringRes;
+
+import net.osmand.plus.R;
+
+public enum DayNightMode {
+ AUTO(R.string.daynight_mode_auto, R.drawable.ic_action_map_sunset),
+ DAY(R.string.daynight_mode_day, R.drawable.ic_action_map_day),
+ NIGHT(R.string.daynight_mode_night, R.drawable.ic_action_map_night),
+ SENSOR(R.string.daynight_mode_sensor, R.drawable.ic_action_map_light_sensor);
+
+ private final int key;
+ @DrawableRes
+ private final int drawableRes;
+
+ DayNightMode(@StringRes int key, @DrawableRes int drawableRes) {
+ this.key = key;
+ this.drawableRes = drawableRes;
+ }
+
+ public String toHumanString(Context ctx) {
+ return ctx.getString(key);
+ }
+
+ @DrawableRes
+ public int getIconRes() {
+ return drawableRes;
+ }
+
+ public boolean isSensor() {
+ return this == SENSOR;
+ }
+
+ public boolean isAuto() {
+ return this == AUTO;
+ }
+
+ public boolean isDay() {
+ return this == DAY;
+ }
+
+ public boolean isNight() {
+ return this == NIGHT;
+ }
+
+ public static DayNightMode[] possibleValues(Context context) {
+ SensorManager mSensorManager = (SensorManager) context.getSystemService(Context.SENSOR_SERVICE);
+ Sensor mLight = mSensorManager.getDefaultSensor(Sensor.TYPE_LIGHT);
+ boolean isLightSensorEnabled = mLight != null;
+ if (isLightSensorEnabled) {
+ return DayNightMode.values();
+ } else {
+ return new DayNightMode[]{AUTO, DAY, NIGHT};
+ }
+ }
+}
\ No newline at end of file
diff --git a/OsmAnd/src/net/osmand/plus/helpers/enums/DrivingRegion.java b/OsmAnd/src/net/osmand/plus/helpers/enums/DrivingRegion.java
new file mode 100644
index 0000000000..60902c46b5
--- /dev/null
+++ b/OsmAnd/src/net/osmand/plus/helpers/enums/DrivingRegion.java
@@ -0,0 +1,62 @@
+package net.osmand.plus.helpers.enums;
+
+import android.content.Context;
+
+import net.osmand.plus.R;
+
+import java.util.Locale;
+
+/**
+ * Class represents specific for driving region
+ * Signs, leftHandDriving
+ */
+public enum DrivingRegion {
+
+ EUROPE_ASIA(R.string.driving_region_europe_asia, MetricsConstants.KILOMETERS_AND_METERS, false),
+ US(R.string.driving_region_us, MetricsConstants.MILES_AND_FEET, false),
+ CANADA(R.string.driving_region_canada, MetricsConstants.KILOMETERS_AND_METERS, false),
+ UK_AND_OTHERS(R.string.driving_region_uk, MetricsConstants.MILES_AND_METERS, true),
+ JAPAN(R.string.driving_region_japan, MetricsConstants.KILOMETERS_AND_METERS, true),
+ AUSTRALIA(R.string.driving_region_australia, MetricsConstants.KILOMETERS_AND_METERS, true);
+
+ public final boolean leftHandDriving;
+ public final MetricsConstants defMetrics;
+ public final int name;
+
+ DrivingRegion(int name, MetricsConstants def, boolean leftHandDriving) {
+ this.name = name;
+ defMetrics = def;
+ this.leftHandDriving = leftHandDriving;
+ }
+
+ public boolean isAmericanTypeSigns() {
+ return this == DrivingRegion.AUSTRALIA ||
+ this == DrivingRegion.US ||
+ this == DrivingRegion.CANADA;
+ }
+
+ public String getDescription(Context ctx) {
+ return ctx.getString(leftHandDriving ? R.string.left_side_navigation : R.string.right_side_navigation) +
+ ", " +
+ defMetrics.toHumanString(ctx).toLowerCase();
+ }
+
+ public static DrivingRegion getDrivingRegionByLocale() {
+ Locale df = Locale.getDefault();
+ if (df == null) {
+ return DrivingRegion.EUROPE_ASIA;
+ }
+ if (df.getCountry().equalsIgnoreCase(Locale.US.getCountry())) {
+ return DrivingRegion.US;
+ } else if (df.getCountry().equalsIgnoreCase(Locale.CANADA.getCountry())) {
+ return DrivingRegion.CANADA;
+ } else if (df.getCountry().equalsIgnoreCase(Locale.JAPAN.getCountry())) {
+ return DrivingRegion.JAPAN;
+ } else if (df.getCountry().equalsIgnoreCase("au")) {
+ return DrivingRegion.AUSTRALIA;
+ } else if (df.getCountry().equalsIgnoreCase(Locale.UK.getCountry())) {
+ return DrivingRegion.UK_AND_OTHERS;
+ }
+ return DrivingRegion.EUROPE_ASIA;
+ }
+}
\ No newline at end of file
diff --git a/OsmAnd/src/net/osmand/plus/helpers/enums/MetricsConstants.java b/OsmAnd/src/net/osmand/plus/helpers/enums/MetricsConstants.java
new file mode 100644
index 0000000000..20f3804a6a
--- /dev/null
+++ b/OsmAnd/src/net/osmand/plus/helpers/enums/MetricsConstants.java
@@ -0,0 +1,29 @@
+package net.osmand.plus.helpers.enums;
+
+import android.content.Context;
+
+import net.osmand.plus.R;
+
+public enum MetricsConstants {
+ KILOMETERS_AND_METERS(R.string.si_km_m, "km-m"),
+ MILES_AND_FEET(R.string.si_mi_feet, "mi-f"),
+ MILES_AND_METERS(R.string.si_mi_meters, "mi-m"),
+ MILES_AND_YARDS(R.string.si_mi_yard, "mi-y"),
+ NAUTICAL_MILES(R.string.si_nm, "nm");
+
+ private final int key;
+ private final String ttsString;
+
+ MetricsConstants(int key, String ttsString) {
+ this.key = key;
+ this.ttsString = ttsString;
+ }
+
+ public String toHumanString(Context ctx) {
+ return ctx.getString(key);
+ }
+
+ public String toTTSString() {
+ return ttsString;
+ }
+}
\ No newline at end of file
diff --git a/OsmAnd/src/net/osmand/plus/helpers/enums/SpeedConstants.java b/OsmAnd/src/net/osmand/plus/helpers/enums/SpeedConstants.java
new file mode 100644
index 0000000000..1a4c512b8c
--- /dev/null
+++ b/OsmAnd/src/net/osmand/plus/helpers/enums/SpeedConstants.java
@@ -0,0 +1,32 @@
+package net.osmand.plus.helpers.enums;
+
+import android.content.Context;
+
+import net.osmand.plus.R;
+
+public enum SpeedConstants {
+ KILOMETERS_PER_HOUR(R.string.km_h, R.string.si_kmh, false),
+ MILES_PER_HOUR(R.string.mile_per_hour, R.string.si_mph, true),
+ METERS_PER_SECOND(R.string.m_s, R.string.si_m_s, false),
+ MINUTES_PER_MILE(R.string.min_mile, R.string.si_min_m, true),
+ MINUTES_PER_KILOMETER(R.string.min_km, R.string.si_min_km, false),
+ NAUTICALMILES_PER_HOUR(R.string.nm_h, R.string.si_nm_h, true);
+
+ public final int key;
+ public final int descr;
+ public final boolean imperial;
+
+ SpeedConstants(int key, int descr, boolean imperial) {
+ this.key = key;
+ this.descr = descr;
+ this.imperial = imperial;
+ }
+
+ public String toHumanString(Context ctx) {
+ return ctx.getString(descr);
+ }
+
+ public String toShortString(Context ctx) {
+ return ctx.getString(key);
+ }
+}
\ No newline at end of file
diff --git a/OsmAnd/src/net/osmand/plus/helpers/enums/TracksSortByMode.java b/OsmAnd/src/net/osmand/plus/helpers/enums/TracksSortByMode.java
new file mode 100644
index 0000000000..6b4177c701
--- /dev/null
+++ b/OsmAnd/src/net/osmand/plus/helpers/enums/TracksSortByMode.java
@@ -0,0 +1,38 @@
+package net.osmand.plus.helpers.enums;
+
+import androidx.annotation.DrawableRes;
+import androidx.annotation.StringRes;
+
+import net.osmand.plus.R;
+
+public enum TracksSortByMode {
+ BY_DATE(R.string.sort_last_modified, R.drawable.ic_action_time_start),
+ BY_NAME_ASCENDING(R.string.sort_name_ascending, R.drawable.ic_action_sort_by_name_ascending),
+ BY_NAME_DESCENDING(R.string.sort_name_descending, R.drawable.ic_action_sort_by_name_descending);
+
+ private final int iconId;
+ private final int nameId;
+
+ TracksSortByMode(int nameId, int iconId) {
+ this.nameId = nameId;
+ this.iconId = iconId;
+ }
+
+ public boolean isByName() {
+ return this == BY_NAME_ASCENDING || this == BY_NAME_DESCENDING;
+ }
+
+ public boolean isByDate() {
+ return this == BY_DATE;
+ }
+
+ @StringRes
+ public int getNameId() {
+ return nameId;
+ }
+
+ @DrawableRes
+ public int getIconId() {
+ return iconId;
+ }
+}
diff --git a/OsmAnd/src/net/osmand/plus/inapp/InAppPurchaseHelper.java b/OsmAnd/src/net/osmand/plus/inapp/InAppPurchaseHelper.java
index ac7e2c77fb..543c3a819d 100644
--- a/OsmAnd/src/net/osmand/plus/inapp/InAppPurchaseHelper.java
+++ b/OsmAnd/src/net/osmand/plus/inapp/InAppPurchaseHelper.java
@@ -2,6 +2,8 @@ package net.osmand.plus.inapp;
import android.annotation.SuppressLint;
import android.app.Activity;
+import android.content.Context;
+import android.content.Intent;
import android.os.AsyncTask;
import android.text.TextUtils;
import android.util.Log;
@@ -9,13 +11,6 @@ import android.util.Log;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
-import com.android.billingclient.api.BillingClient.BillingResponseCode;
-import com.android.billingclient.api.BillingClient.SkuType;
-import com.android.billingclient.api.BillingResult;
-import com.android.billingclient.api.Purchase;
-import com.android.billingclient.api.SkuDetails;
-import com.android.billingclient.api.SkuDetailsResponseListener;
-
import net.osmand.AndroidNetworkUtils;
import net.osmand.AndroidNetworkUtils.OnRequestResultListener;
import net.osmand.AndroidNetworkUtils.OnRequestsResultListener;
@@ -23,19 +18,16 @@ import net.osmand.AndroidNetworkUtils.RequestResponse;
import net.osmand.PlatformUtil;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.settings.backend.OsmandSettings;
-import net.osmand.plus.settings.backend.OsmandSettings.OsmandPreference;
+import net.osmand.plus.settings.backend.OsmandPreference;
import net.osmand.plus.R;
import net.osmand.plus.Version;
import net.osmand.plus.inapp.InAppPurchases.InAppPurchase;
import net.osmand.plus.inapp.InAppPurchases.InAppPurchase.PurchaseState;
-import net.osmand.plus.inapp.InAppPurchases.InAppPurchaseLiveUpdatesOldSubscription;
import net.osmand.plus.inapp.InAppPurchases.InAppSubscription;
-import net.osmand.plus.inapp.InAppPurchases.InAppSubscriptionIntroductoryInfo;
import net.osmand.plus.inapp.InAppPurchases.InAppSubscriptionList;
-import net.osmand.plus.inapp.util.BillingManager;
-import net.osmand.plus.inapp.util.BillingManager.BillingUpdatesListener;
import net.osmand.plus.liveupdates.CountrySelectionFragment;
import net.osmand.plus.liveupdates.CountrySelectionFragment.CountryItem;
+import net.osmand.plus.settings.backend.OsmandSettings;
import net.osmand.util.Algorithms;
import org.json.JSONArray;
@@ -43,7 +35,6 @@ import org.json.JSONException;
import org.json.JSONObject;
import java.lang.ref.WeakReference;
-import java.text.ParseException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
@@ -53,54 +44,31 @@ import java.util.List;
import java.util.Map;
import java.util.Set;
-public class InAppPurchaseHelper {
+public abstract class InAppPurchaseHelper {
// Debug tag, for logging
- private static final org.apache.commons.logging.Log LOG = PlatformUtil.getLog(InAppPurchaseHelper.class);
+ protected static final org.apache.commons.logging.Log LOG = PlatformUtil.getLog(InAppPurchaseHelper.class);
private static final String TAG = InAppPurchaseHelper.class.getSimpleName();
private boolean mDebugLog = false;
public static final long SUBSCRIPTION_HOLDING_TIME_MSEC = 1000 * 60 * 60 * 24 * 3; // 3 days
- private InAppPurchases purchases;
- private long lastValidationCheckTime;
- private boolean inventoryRequested;
+ protected InAppPurchases purchases;
+ protected long lastValidationCheckTime;
+ protected boolean inventoryRequested;
private static final long PURCHASE_VALIDATION_PERIOD_MSEC = 1000 * 60 * 60 * 24; // daily
- // (arbitrary) request code for the purchase flow
- private static final int RC_REQUEST = 10001;
- // The helper object
- private BillingManager billingManager;
- private List skuDetailsList;
+ protected boolean isDeveloperVersion;
+ protected String token = "";
+ protected InAppPurchaseTaskType activeTask;
+ protected boolean processingTask = false;
+ protected boolean inventoryRequestPending = false;
- private boolean isDeveloperVersion;
- private String token = "";
- private InAppPurchaseTaskType activeTask;
- private boolean processingTask = false;
- private boolean inventoryRequestPending = false;
-
- private OsmandApplication ctx;
- private InAppPurchaseListener uiActivity = null;
-
- /* base64EncodedPublicKey should be YOUR APPLICATION'S PUBLIC KEY
- * (that you got from the Google Play developer console). This is not your
- * developer public key, it's the *app-specific* public key.
- *
- * Instead of just storing the entire literal string here embedded in the
- * program, construct the key at runtime from pieces or
- * use bit manipulation (for example, XOR with some other string) to hide
- * the actual key. The key itself is not secret information, but we don't
- * want to make it easy for an attacker to replace the public key with one
- * of their own and then fake messages from the server.
- */
- private static final String BASE64_ENCODED_PUBLIC_KEY = "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAgk8cEx" +
- "UO4mfEwWFLkQnX1Tkzehr4SnXLXcm2Osxs5FTJPEgyTckTh0POKVMrxeGLn0KoTY2NTgp1U/inp" +
- "wccWisPhVPEmw9bAVvWsOkzlyg1kv03fJdnAXRBSqDDPV6X8Z3MtkPVqZkupBsxyIllEILKHK06" +
- "OCw49JLTsMR3oTRifGzma79I71X0spw0fM+cIRlkS2tsXN8GPbdkJwHofZKPOXS51pgC1zU8uWX" +
- "I+ftJO46a1XkNh1dO2anUiQ8P/H4yOTqnMsXF7biyYuiwjXPOcy0OMhEHi54Dq6Mr3u5ZALOAkc" +
- "YTjh1H/ZgqIHy5ZluahINuDE76qdLYMXrDMQIDAQAB";
+ protected OsmandApplication ctx;
+ protected InAppPurchaseListener uiActivity = null;
public interface InAppPurchaseListener {
+
void onError(InAppPurchaseTaskType taskType, String error);
void onGetItems();
@@ -112,16 +80,62 @@ public class InAppPurchaseHelper {
void dismissProgress(InAppPurchaseTaskType taskType);
}
+ public interface InAppPurchaseInitCallback {
+
+ void onSuccess();
+
+ void onFail();
+ }
+
public enum InAppPurchaseTaskType {
REQUEST_INVENTORY,
PURCHASE_FULL_VERSION,
PURCHASE_LIVE_UPDATES,
- PURCHASE_DEPTH_CONTOURS
+ PURCHASE_DEPTH_CONTOURS,
+ PURCHASE_CONTOUR_LINES
}
- public interface InAppRunnable {
+ public abstract class InAppCommand {
+
+ InAppCommandResultHandler resultHandler;
+
// return true if done and false if async task started
- boolean run(InAppPurchaseHelper helper);
+ abstract void run(InAppPurchaseHelper helper);
+
+ protected void commandDone() {
+ InAppCommandResultHandler resultHandler = this.resultHandler;
+ if (resultHandler != null) {
+ resultHandler.onCommandDone(this);
+ }
+ }
+ }
+
+ public interface InAppCommandResultHandler {
+ void onCommandDone(@NonNull InAppCommand command);
+ }
+
+ public static class PurchaseInfo {
+ private String sku;
+ private String orderId;
+ private String purchaseToken;
+
+ public PurchaseInfo(String sku, String orderId, String purchaseToken) {
+ this.sku = sku;
+ this.orderId = orderId;
+ this.purchaseToken = purchaseToken;
+ }
+
+ public String getSku() {
+ return sku;
+ }
+
+ public String getOrderId() {
+ return orderId;
+ }
+
+ public String getPurchaseToken() {
+ return purchaseToken;
+ }
}
public String getToken() {
@@ -144,6 +158,10 @@ public class InAppPurchaseHelper {
return Version.isDeveloperBuild(ctx) || ctx.getSettings().DEPTH_CONTOURS_PURCHASED.get();
}
+ public static boolean isContourLinesPurchased(@NonNull OsmandApplication ctx) {
+ return Version.isDeveloperBuild(ctx) || ctx.getSettings().CONTOUR_LINES_PURCHASED.get();
+ }
+
public InAppPurchases getInAppPurchases() {
return purchases;
}
@@ -176,9 +194,10 @@ public class InAppPurchaseHelper {
public InAppPurchaseHelper(OsmandApplication ctx) {
this.ctx = ctx;
isDeveloperVersion = Version.isDeveloperVersion(ctx);
- purchases = new InAppPurchases(ctx);
}
+ public abstract void isInAppPurchaseSupported(@NonNull final Activity activity, @Nullable final InAppPurchaseInitCallback callback);
+
public boolean hasInventory() {
return lastValidationCheckTime != 0;
}
@@ -194,12 +213,8 @@ public class InAppPurchaseHelper {
return false;
}
- private BillingManager getBillingManager() {
- return billingManager;
- }
-
- private void exec(final @NonNull InAppPurchaseTaskType taskType, final @NonNull InAppRunnable runnable) {
- if (isDeveloperVersion || !Version.isGooglePlayEnabled(ctx)) {
+ protected void exec(final @NonNull InAppPurchaseTaskType taskType, final @NonNull InAppCommand command) {
+ if (isDeveloperVersion || (!Version.isGooglePlayEnabled(ctx) && !Version.isHuawei(ctx))) {
notifyDismissProgress(taskType);
stop(true);
return;
@@ -222,117 +237,21 @@ public class InAppPurchaseHelper {
try {
processingTask = true;
activeTask = taskType;
- billingManager = new BillingManager(ctx, BASE64_ENCODED_PUBLIC_KEY, new BillingUpdatesListener() {
-
+ command.resultHandler = new InAppCommandResultHandler() {
@Override
- public void onBillingClientSetupFinished() {
- logDebug("Setup finished.");
-
- BillingManager billingManager = getBillingManager();
- // Have we been disposed of in the meantime? If so, quit.
- if (billingManager == null) {
- stop(true);
- return;
- }
-
- if (!billingManager.isServiceConnected()) {
- // Oh noes, there was a problem.
- //complain("Problem setting up in-app billing: " + result);
- notifyError(taskType, billingManager.getBillingClientResponseMessage());
- stop(true);
- return;
- }
-
- processingTask = !runnable.run(InAppPurchaseHelper.this);
+ public void onCommandDone(@NonNull InAppCommand command) {
+ processingTask = false;
}
-
- @Override
- public void onConsumeFinished(String token, BillingResult billingResult) {
- }
-
- @Override
- public void onPurchasesUpdated(final List purchases) {
-
- BillingManager billingManager = getBillingManager();
- // Have we been disposed of in the meantime? If so, quit.
- if (billingManager == null) {
- stop(true);
- return;
- }
-
- if (activeTask == InAppPurchaseTaskType.REQUEST_INVENTORY) {
- List skuInApps = new ArrayList<>();
- for (InAppPurchase purchase : getInAppPurchases().getAllInAppPurchases(false)) {
- skuInApps.add(purchase.getSku());
- }
- for (Purchase p : purchases) {
- skuInApps.add(p.getSku());
- }
- billingManager.querySkuDetailsAsync(SkuType.INAPP, skuInApps, new SkuDetailsResponseListener() {
- @Override
- public void onSkuDetailsResponse(BillingResult billingResult, final List skuDetailsListInApps) {
- // Is it a failure?
- if (billingResult.getResponseCode() != BillingResponseCode.OK) {
- logError("Failed to query inapps sku details: " + billingResult.getResponseCode());
- notifyError(InAppPurchaseTaskType.REQUEST_INVENTORY, billingResult.getDebugMessage());
- stop(true);
- return;
- }
-
- List skuSubscriptions = new ArrayList<>();
- for (InAppSubscription subscription : getInAppPurchases().getAllInAppSubscriptions()) {
- skuSubscriptions.add(subscription.getSku());
- }
- for (Purchase p : purchases) {
- skuSubscriptions.add(p.getSku());
- }
-
- BillingManager billingManager = getBillingManager();
- // Have we been disposed of in the meantime? If so, quit.
- if (billingManager == null) {
- stop(true);
- return;
- }
-
- billingManager.querySkuDetailsAsync(SkuType.SUBS, skuSubscriptions, new SkuDetailsResponseListener() {
- @Override
- public void onSkuDetailsResponse(BillingResult billingResult, final List skuDetailsListSubscriptions) {
- // Is it a failure?
- if (billingResult.getResponseCode() != BillingResponseCode.OK) {
- logError("Failed to query subscriptipons sku details: " + billingResult.getResponseCode());
- notifyError(InAppPurchaseTaskType.REQUEST_INVENTORY, billingResult.getDebugMessage());
- stop(true);
- return;
- }
-
- List skuDetailsList = new ArrayList<>(skuDetailsListInApps);
- skuDetailsList.addAll(skuDetailsListSubscriptions);
- InAppPurchaseHelper.this.skuDetailsList = skuDetailsList;
-
- mSkuDetailsResponseListener.onSkuDetailsResponse(billingResult, skuDetailsList);
- }
- });
- }
- });
- }
- for (Purchase purchase : purchases) {
- if (!purchase.isAcknowledged()) {
- onPurchaseFinished(purchase);
- }
- }
- }
-
- @Override
- public void onPurchaseCanceled() {
- stop(true);
- }
- });
+ };
+ execImpl(taskType, command);
} catch (Exception e) {
logError("exec Error", e);
stop(true);
}
}
+ protected abstract void execImpl(@NonNull final InAppPurchaseTaskType taskType, @NonNull final InAppCommand command);
+
public boolean needRequestInventory() {
return !inventoryRequested && ((isSubscribedToLiveUpdates(ctx) && Algorithms.isEmpty(ctx.getSettings().BILLING_PURCHASE_TOKENS_SENT.get()))
|| System.currentTimeMillis() - lastValidationCheckTime > PURCHASE_VALIDATION_PERIOD_MSEC);
@@ -343,322 +262,20 @@ public class InAppPurchaseHelper {
new RequestInventoryTask().executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, (Void) null);
}
- public void purchaseFullVersion(final Activity activity) {
- notifyShowProgress(InAppPurchaseTaskType.PURCHASE_FULL_VERSION);
- exec(InAppPurchaseTaskType.PURCHASE_FULL_VERSION, new InAppRunnable() {
- @Override
- public boolean run(InAppPurchaseHelper helper) {
- try {
- SkuDetails skuDetails = getSkuDetails(getFullVersion().getSku());
- if (skuDetails == null) {
- throw new IllegalArgumentException("Cannot find sku details");
- }
- BillingManager billingManager = getBillingManager();
- if (billingManager != null) {
- billingManager.initiatePurchaseFlow(activity, skuDetails);
- } else {
- throw new IllegalStateException("BillingManager disposed");
- }
- return false;
- } catch (Exception e) {
- complain("Cannot launch full version purchase!");
- logError("purchaseFullVersion Error", e);
- stop(true);
- }
- return true;
- }
- });
- }
+ public abstract void purchaseFullVersion(@NonNull final Activity activity) throws UnsupportedOperationException;
- public void purchaseLiveUpdates(Activity activity, String sku, String email, String userName,
+ public void purchaseLiveUpdates(@NonNull Activity activity, String sku, String email, String userName,
String countryDownloadName, boolean hideUserName) {
notifyShowProgress(InAppPurchaseTaskType.PURCHASE_LIVE_UPDATES);
new LiveUpdatesPurchaseTask(activity, sku, email, userName, countryDownloadName, hideUserName)
.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, (Void) null);
}
- public void purchaseDepthContours(final Activity activity) {
- notifyShowProgress(InAppPurchaseTaskType.PURCHASE_DEPTH_CONTOURS);
- exec(InAppPurchaseTaskType.PURCHASE_DEPTH_CONTOURS, new InAppRunnable() {
- @Override
- public boolean run(InAppPurchaseHelper helper) {
- try {
- SkuDetails skuDetails = getSkuDetails(getDepthContours().getSku());
- if (skuDetails == null) {
- throw new IllegalArgumentException("Cannot find sku details");
- }
- BillingManager billingManager = getBillingManager();
- if (billingManager != null) {
- billingManager.initiatePurchaseFlow(activity, skuDetails);
- } else {
- throw new IllegalStateException("BillingManager disposed");
- }
- return false;
- } catch (Exception e) {
- complain("Cannot launch depth contours purchase!");
- logError("purchaseDepthContours Error", e);
- stop(true);
- }
- return true;
- }
- });
- }
+ public abstract void purchaseDepthContours(@NonNull final Activity activity) throws UnsupportedOperationException;
- @Nullable
- private SkuDetails getSkuDetails(@NonNull String sku) {
- List skuDetailsList = this.skuDetailsList;
- if (skuDetailsList != null) {
- for (SkuDetails details : skuDetailsList) {
- if (details.getSku().equals(sku)) {
- return details;
- }
- }
- }
- return null;
- }
+ public abstract void purchaseContourLines(@NonNull final Activity activity) throws UnsupportedOperationException;
- private boolean hasDetails(@NonNull String sku) {
- return getSkuDetails(sku) != null;
- }
-
- @Nullable
- private Purchase getPurchase(@NonNull String sku) {
- BillingManager billingManager = getBillingManager();
- if (billingManager != null) {
- List purchases = billingManager.getPurchases();
- if (purchases != null) {
- for (Purchase p : purchases) {
- if (p.getSku().equals(sku)) {
- return p;
- }
- }
- }
- }
- return null;
- }
-
- // Listener that's called when we finish querying the items and subscriptions we own
- private SkuDetailsResponseListener mSkuDetailsResponseListener = new SkuDetailsResponseListener() {
-
- @NonNull
- private List getAllOwnedSubscriptionSkus() {
- List result = new ArrayList<>();
- BillingManager billingManager = getBillingManager();
- if (billingManager != null) {
- for (Purchase p : billingManager.getPurchases()) {
- if (getInAppPurchases().getInAppSubscriptionBySku(p.getSku()) != null) {
- result.add(p.getSku());
- }
- }
- }
- return result;
- }
-
- @Override
- public void onSkuDetailsResponse(BillingResult billingResult, List 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() != 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 allOwnedSubscriptionSkus = getAllOwnedSubscriptionSkus();
- for (InAppSubscription s : getLiveUpdates().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 = getLiveUpdates().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;
- List liveUpdatesPurchases = new ArrayList<>();
- for (InAppPurchase p : getLiveUpdates().getAllSubscriptions()) {
- Purchase purchase = getPurchase(p.getSku());
- if (purchase != null) {
- liveUpdatesPurchases.add(purchase);
- if (!subscribedToLiveUpdates) {
- subscribedToLiveUpdates = true;
- }
- }
- }
- OsmandPreference subscriptionCancelledTime = ctx.getSettings().LIVE_UPDATES_PURCHASE_CANCELLED_TIME;
- if (!subscribedToLiveUpdates && ctx.getSettings().LIVE_UPDATES_PURCHASED.get()) {
- if (subscriptionCancelledTime.get() == 0) {
- subscriptionCancelledTime.set(System.currentTimeMillis());
- ctx.getSettings().LIVE_UPDATES_PURCHASE_CANCELLED_FIRST_DLG_SHOWN.set(false);
- ctx.getSettings().LIVE_UPDATES_PURCHASE_CANCELLED_SECOND_DLG_SHOWN.set(false);
- } else if (System.currentTimeMillis() - subscriptionCancelledTime.get() > SUBSCRIPTION_HOLDING_TIME_MSEC) {
- ctx.getSettings().LIVE_UPDATES_PURCHASED.set(false);
- if (!isDepthContoursPurchased(ctx)) {
- ctx.getSettings().getCustomRenderBooleanProperty("depthContours").set(false);
- }
- }
- } else if (subscribedToLiveUpdates) {
- subscriptionCancelledTime.set(0L);
- ctx.getSettings().LIVE_UPDATES_PURCHASED.set(true);
- }
-
- lastValidationCheckTime = System.currentTimeMillis();
- logDebug("User " + (subscribedToLiveUpdates ? "HAS" : "DOES NOT HAVE")
- + " live updates purchased.");
-
- OsmandSettings settings = ctx.getSettings();
- settings.INAPPS_READ.set(true);
-
- List tokensToSend = new ArrayList<>();
- if (liveUpdatesPurchases.size() > 0) {
- List tokensSent = Arrays.asList(settings.BILLING_PURCHASE_TOKENS_SENT.get().split(";"));
- for (Purchase purchase : liveUpdatesPurchases) {
- if ((Algorithms.isEmpty(settings.BILLING_USER_ID.get()) || Algorithms.isEmpty(settings.BILLING_USER_TOKEN.get()))
- && !Algorithms.isEmpty(purchase.getDeveloperPayload())) {
- String payload = purchase.getDeveloperPayload();
- if (!Algorithms.isEmpty(payload)) {
- String[] arr = payload.split(" ");
- if (arr.length > 0) {
- settings.BILLING_USER_ID.set(arr[0]);
- }
- if (arr.length > 1) {
- token = arr[1];
- settings.BILLING_USER_TOKEN.set(token);
- }
- }
- }
- if (!tokensSent.contains(purchase.getSku())) {
- tokensToSend.add(purchase);
- }
- }
- }
-
- final OnRequestResultListener listener = new OnRequestResultListener() {
- @Override
- public void onResult(String result) {
- notifyDismissProgress(InAppPurchaseTaskType.REQUEST_INVENTORY);
- notifyGetItems();
- stop(true);
- logDebug("Initial inapp query finished");
- }
- };
-
- if (tokensToSend.size() > 0) {
- sendTokens(tokensToSend, listener);
- } else {
- listener.onResult("OK");
- }
- }
- };
-
- private void fetchInAppPurchase(@NonNull InAppPurchase inAppPurchase, @NonNull SkuDetails skuDetails, @Nullable Purchase purchase) {
- if (purchase != null) {
- inAppPurchase.setPurchaseState(PurchaseState.PURCHASED);
- inAppPurchase.setPurchaseTime(purchase.getPurchaseTime());
- } else {
- inAppPurchase.setPurchaseState(PurchaseState.NOT_PURCHASED);
- }
- inAppPurchase.setPrice(skuDetails.getPrice());
- inAppPurchase.setPriceCurrencyCode(skuDetails.getPriceCurrencyCode());
- if (skuDetails.getPriceAmountMicros() > 0) {
- inAppPurchase.setPriceValue(skuDetails.getPriceAmountMicros() / 1000000d);
- }
- String subscriptionPeriod = skuDetails.getSubscriptionPeriod();
- if (!Algorithms.isEmpty(subscriptionPeriod)) {
- if (inAppPurchase instanceof InAppSubscription) {
- try {
- ((InAppSubscription) inAppPurchase).setSubscriptionPeriodString(subscriptionPeriod);
- } catch (ParseException e) {
- LOG.error(e);
- }
- }
- }
- if (inAppPurchase instanceof InAppSubscription) {
- String introductoryPrice = skuDetails.getIntroductoryPrice();
- String introductoryPricePeriod = skuDetails.getIntroductoryPricePeriod();
- String introductoryPriceCycles = skuDetails.getIntroductoryPriceCycles();
- long introductoryPriceAmountMicros = skuDetails.getIntroductoryPriceAmountMicros();
- if (!Algorithms.isEmpty(introductoryPrice)) {
- InAppSubscription s = (InAppSubscription) inAppPurchase;
- try {
- s.setIntroductoryInfo(new InAppSubscriptionIntroductoryInfo(s, introductoryPrice,
- introductoryPriceAmountMicros, introductoryPricePeriod, introductoryPriceCycles));
- } catch (ParseException e) {
- LOG.error(e);
- }
- }
- }
- }
+ public abstract void manageSubscription(@NonNull Context ctx, @Nullable String sku);
@SuppressLint("StaticFieldLeak")
private class LiveUpdatesPurchaseTask extends AsyncTask {
@@ -746,31 +363,7 @@ public class InAppPurchaseHelper {
if (!Algorithms.isEmpty(userId) && !Algorithms.isEmpty(token)) {
logDebug("Launching purchase flow for live updates subscription for userId=" + userId);
final String payload = userId + " " + token;
- exec(InAppPurchaseTaskType.PURCHASE_LIVE_UPDATES, new InAppRunnable() {
- @Override
- public boolean run(InAppPurchaseHelper helper) {
- try {
- Activity a = activity.get();
- SkuDetails skuDetails = getSkuDetails(sku);
- if (a != null && skuDetails != null) {
- BillingManager billingManager = getBillingManager();
- if (billingManager != null) {
- billingManager.setPayload(payload);
- billingManager.initiatePurchaseFlow(a, skuDetails);
- } else {
- throw new IllegalStateException("BillingManager disposed");
- }
- return false;
- } else {
- stop(true);
- }
- } catch (Exception e) {
- logError("launchPurchaseFlow Error", e);
- stop(true);
- }
- return true;
- }
- });
+ exec(InAppPurchaseTaskType.PURCHASE_LIVE_UPDATES, getPurchaseLiveUpdatesCommand(activity, sku, payload));
} else {
notifyError(InAppPurchaseTaskType.PURCHASE_LIVE_UPDATES, "Empty userId");
stop(true);
@@ -778,6 +371,9 @@ public class InAppPurchaseHelper {
}
}
+ protected abstract InAppCommand getPurchaseLiveUpdatesCommand(final WeakReference activity,
+ final String sku, final String payload) throws UnsupportedOperationException;
+
@SuppressLint("StaticFieldLeak")
private class RequestInventoryTask extends AsyncTask {
@@ -808,38 +404,41 @@ public class InAppPurchaseHelper {
try {
JSONObject obj = new JSONObject(response);
JSONArray names = obj.names();
- for (int i = 0; i < names.length(); i++) {
- String skuType = names.getString(i);
- JSONObject subObj = obj.getJSONObject(skuType);
- String sku = subObj.getString("sku");
- if (!Algorithms.isEmpty(sku)) {
- getLiveUpdates().upgradeSubscription(sku);
+ if (names != null) {
+ for (int i = 0; i < names.length(); i++) {
+ String skuType = names.getString(i);
+ JSONObject subObj = obj.getJSONObject(skuType);
+ String sku = subObj.getString("sku");
+ if (!Algorithms.isEmpty(sku)) {
+ getLiveUpdates().upgradeSubscription(sku);
+ }
}
}
} catch (JSONException e) {
logError("Json parsing error", e);
}
}
- exec(InAppPurchaseTaskType.REQUEST_INVENTORY, new InAppRunnable() {
- @Override
- public boolean run(InAppPurchaseHelper helper) {
- logDebug("Setup successful. Querying inventory.");
- try {
- BillingManager billingManager = getBillingManager();
- if (billingManager != null) {
- billingManager.queryPurchases();
- } else {
- throw new IllegalStateException("BillingManager disposed");
- }
- return false;
- } catch (Exception e) {
- logError("queryInventoryAsync Error", e);
- notifyDismissProgress(InAppPurchaseTaskType.REQUEST_INVENTORY);
- stop(true);
- }
- return true;
- }
- });
+ exec(InAppPurchaseTaskType.REQUEST_INVENTORY, getRequestInventoryCommand());
+ }
+ }
+
+ protected abstract InAppCommand getRequestInventoryCommand() throws UnsupportedOperationException;
+
+ protected void onSkuDetailsResponseDone(List purchaseInfoList) {
+ final AndroidNetworkUtils.OnRequestResultListener listener = new AndroidNetworkUtils.OnRequestResultListener() {
+ @Override
+ public void onResult(String result) {
+ notifyDismissProgress(InAppPurchaseTaskType.REQUEST_INVENTORY);
+ notifyGetItems();
+ stop(true);
+ logDebug("Initial inapp query finished");
+ }
+ };
+
+ if (purchaseInfoList.size() > 0) {
+ sendTokens(purchaseInfoList, listener);
+ } else {
+ listener.onResult("OK");
}
}
@@ -852,25 +451,16 @@ public class InAppPurchaseHelper {
parameters.put("aid", ctx.getUserAndroidId());
}
- // Call when a purchase is finished
- private void onPurchaseFinished(Purchase purchase) {
- logDebug("Purchase finished: " + purchase);
-
- // if we were disposed of in the meantime, quit.
- if (getBillingManager() == null) {
- stop(true);
- return;
- }
-
+ protected void onPurchaseDone(PurchaseInfo info) {
logDebug("Purchase successful.");
- InAppPurchase liveUpdatesPurchase = getLiveUpdates().getSubscriptionBySku(purchase.getSku());
+ InAppPurchase liveUpdatesPurchase = getLiveUpdates().getSubscriptionBySku(info.getSku());
if (liveUpdatesPurchase != null) {
// bought live updates
logDebug("Live updates subscription purchased.");
final String sku = liveUpdatesPurchase.getSku();
liveUpdatesPurchase.setPurchaseState(PurchaseState.PURCHASED);
- sendTokens(Collections.singletonList(purchase), new OnRequestResultListener() {
+ sendTokens(Collections.singletonList(info), new OnRequestResultListener() {
@Override
public void onResult(String result) {
boolean active = ctx.getSettings().LIVE_UPDATES_PURCHASED.get();
@@ -887,7 +477,7 @@ public class InAppPurchaseHelper {
}
});
- } else if (purchase.getSku().equals(getFullVersion().getSku())) {
+ } else if (info.getSku().equals(getFullVersion().getSku())) {
// bought full version
getFullVersion().setPurchaseState(PurchaseState.PURCHASED);
logDebug("Full version purchased.");
@@ -898,7 +488,7 @@ public class InAppPurchaseHelper {
notifyItemPurchased(getFullVersion().getSku(), false);
stop(true);
- } else if (purchase.getSku().equals(getDepthContours().getSku())) {
+ } else if (info.getSku().equals(getDepthContours().getSku())) {
// bought sea depth contours
getDepthContours().setPurchaseState(PurchaseState.PURCHASED);
logDebug("Sea depth contours purchased.");
@@ -910,6 +500,17 @@ public class InAppPurchaseHelper {
notifyItemPurchased(getDepthContours().getSku(), false);
stop(true);
+ } else if (info.getSku().equals(getContourLines().getSku())) {
+ // bought contour lines
+ getContourLines().setPurchaseState(PurchaseState.PURCHASED);
+ logDebug("Contours lines purchased.");
+ showToast(ctx.getString(R.string.contour_lines_thanks));
+ ctx.getSettings().CONTOUR_LINES_PURCHASED.set(true);
+
+ notifyDismissProgress(InAppPurchaseTaskType.PURCHASE_CONTOUR_LINES);
+ notifyItemPurchased(getContourLines().getSku(), false);
+ stop(true);
+
} else {
notifyDismissProgress(activeTask);
stop(true);
@@ -921,17 +522,19 @@ public class InAppPurchaseHelper {
stop(false);
}
- private void stop(boolean taskDone) {
+ protected abstract boolean isBillingManagerExists();
+
+ protected abstract void destroyBillingManager();
+
+ protected void stop(boolean taskDone) {
logDebug("Destroying helper.");
- BillingManager billingManager = getBillingManager();
- if (billingManager != null) {
+ if (isBillingManagerExists()) {
if (taskDone) {
processingTask = false;
}
if (!processingTask) {
activeTask = null;
- billingManager.destroy();
- this.billingManager = null;
+ destroyBillingManager();
}
} else {
processingTask = false;
@@ -943,7 +546,7 @@ public class InAppPurchaseHelper {
}
}
- private void sendTokens(@NonNull final List purchases, final OnRequestResultListener listener) {
+ protected void sendTokens(@NonNull final List purchaseInfoList, final OnRequestResultListener listener) {
final String userId = ctx.getSettings().BILLING_USER_ID.get();
final String token = ctx.getSettings().BILLING_USER_TOKEN.get();
final String email = ctx.getSettings().BILLING_USER_EMAIL.get();
@@ -951,12 +554,12 @@ public class InAppPurchaseHelper {
String url = "https://osmand.net/subscription/purchased";
String userOperation = "Sending purchase info...";
final List requests = new ArrayList<>();
- for (Purchase purchase : purchases) {
+ for (PurchaseInfo info : purchaseInfoList) {
Map parameters = new HashMap<>();
parameters.put("userid", userId);
- parameters.put("sku", purchase.getSku());
- parameters.put("orderId", purchase.getOrderId());
- parameters.put("purchaseToken", purchase.getPurchaseToken());
+ parameters.put("sku", info.getSku());
+ parameters.put("orderId", info.getOrderId());
+ parameters.put("purchaseToken", info.getPurchaseToken());
parameters.put("email", email);
parameters.put("token", token);
addUserInfo(parameters);
@@ -967,9 +570,9 @@ public class InAppPurchaseHelper {
public void onResult(@NonNull List results) {
for (RequestResponse rr : results) {
String sku = rr.getRequest().getParameters().get("sku");
- Purchase purchase = getPurchase(sku);
- if (purchase != null) {
- updateSentTokens(purchase);
+ PurchaseInfo info = getPurchaseInfo(sku);
+ if (info != null) {
+ updateSentTokens(info);
String result = rr.getResponse();
if (result != null) {
try {
@@ -979,13 +582,13 @@ public class InAppPurchaseHelper {
} else {
complain("SendToken Error: "
+ obj.getString("error")
- + " (userId=" + userId + " token=" + token + " response=" + result + " google=" + purchase.toString() + ")");
+ + " (userId=" + userId + " token=" + token + " response=" + result + " google=" + info.toString() + ")");
}
} catch (JSONException e) {
logError("SendToken", e);
complain("SendToken Error: "
+ (e.getMessage() != null ? e.getMessage() : "JSONException")
- + " (userId=" + userId + " token=" + token + " response=" + result + " google=" + purchase.toString() + ")");
+ + " (userId=" + userId + " token=" + token + " response=" + result + " google=" + info.toString() + ")");
}
}
}
@@ -995,10 +598,10 @@ public class InAppPurchaseHelper {
}
}
- private void updateSentTokens(@NonNull Purchase purchase) {
+ private void updateSentTokens(@NonNull PurchaseInfo info) {
String tokensSentStr = ctx.getSettings().BILLING_PURCHASE_TOKENS_SENT.get();
Set tokensSent = new HashSet<>(Arrays.asList(tokensSentStr.split(";")));
- tokensSent.add(purchase.getSku());
+ tokensSent.add(info.getSku());
ctx.getSettings().BILLING_PURCHASE_TOKENS_SENT.set(TextUtils.join(";", tokensSent));
}
@@ -1032,10 +635,10 @@ public class InAppPurchaseHelper {
}
@Nullable
- private Purchase getPurchase(String sku) {
- for (Purchase purchase : purchases) {
- if (purchase.getSku().equals(sku)) {
- return purchase;
+ private PurchaseInfo getPurchaseInfo(String sku) {
+ for (PurchaseInfo info : purchaseInfoList) {
+ if (info.getSku().equals(sku)) {
+ return info;
}
}
return null;
@@ -1049,31 +652,35 @@ public class InAppPurchaseHelper {
}
}
- private void notifyError(InAppPurchaseTaskType taskType, String message) {
+ public boolean onActivityResult(@NonNull Activity activity, int requestCode, int resultCode, Intent data) {
+ return false;
+ }
+
+ protected void notifyError(InAppPurchaseTaskType taskType, String message) {
if (uiActivity != null) {
uiActivity.onError(taskType, message);
}
}
- private void notifyGetItems() {
+ protected void notifyGetItems() {
if (uiActivity != null) {
uiActivity.onGetItems();
}
}
- private void notifyItemPurchased(String sku, boolean active) {
+ protected void notifyItemPurchased(String sku, boolean active) {
if (uiActivity != null) {
uiActivity.onItemPurchased(sku, active);
}
}
- private void notifyShowProgress(InAppPurchaseTaskType taskType) {
+ protected void notifyShowProgress(InAppPurchaseTaskType taskType) {
if (uiActivity != null) {
uiActivity.showProgress(taskType);
}
}
- private void notifyDismissProgress(InAppPurchaseTaskType taskType) {
+ protected void notifyDismissProgress(InAppPurchaseTaskType taskType) {
if (uiActivity != null) {
uiActivity.dismissProgress(taskType);
}
@@ -1090,26 +697,26 @@ public class InAppPurchaseHelper {
}
}
- private void complain(String message) {
+ protected void complain(String message) {
logError("**** InAppPurchaseHelper Error: " + message);
showToast(message);
}
- private void showToast(final String message) {
+ protected void showToast(final String message) {
ctx.showToastMessage(message);
}
- private void logDebug(String msg) {
+ protected void logDebug(String msg) {
if (mDebugLog) {
Log.d(TAG, msg);
}
}
- private void logError(String msg) {
+ protected void logError(String msg) {
Log.e(TAG, msg);
}
- private void logError(String msg, Throwable e) {
+ protected void logError(String msg, Throwable e) {
Log.e(TAG, "Error: " + msg, e);
}
diff --git a/OsmAnd/src/net/osmand/plus/inapp/InAppPurchases.java b/OsmAnd/src/net/osmand/plus/inapp/InAppPurchases.java
index b42b57f045..5004e97165 100644
--- a/OsmAnd/src/net/osmand/plus/inapp/InAppPurchases.java
+++ b/OsmAnd/src/net/osmand/plus/inapp/InAppPurchases.java
@@ -11,14 +11,11 @@ import androidx.annotation.ColorInt;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
-import com.android.billingclient.api.SkuDetails;
-
import net.osmand.AndroidUtils;
import net.osmand.Period;
import net.osmand.Period.PeriodUnit;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.R;
-import net.osmand.plus.Version;
import net.osmand.plus.helpers.FontCache;
import net.osmand.plus.widgets.style.CustomTypefaceSpan;
import net.osmand.util.Algorithms;
@@ -33,64 +30,17 @@ import java.util.Locale;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
-public class InAppPurchases {
+public abstract class InAppPurchases {
- private static final InAppPurchase FULL_VERSION = new InAppPurchaseFullVersion();
- private static final InAppPurchaseDepthContoursFull DEPTH_CONTOURS_FULL = new InAppPurchaseDepthContoursFull();
- private static final InAppPurchaseDepthContoursFree DEPTH_CONTOURS_FREE = new InAppPurchaseDepthContoursFree();
- private static final InAppPurchaseContourLinesFull CONTOUR_LINES_FULL = new InAppPurchaseContourLinesFull();
- private static final InAppPurchaseContourLinesFree CONTOUR_LINES_FREE = new InAppPurchaseContourLinesFree();
+ protected InAppPurchase fullVersion;
+ protected InAppPurchase depthContours;
+ protected InAppPurchase contourLines;
+ protected InAppSubscription monthlyLiveUpdates;
+ protected InAppSubscription discountedMonthlyLiveUpdates;
+ protected InAppSubscriptionList liveUpdates;
+ protected InAppPurchase[] inAppPurchases;
- private static final InAppSubscription[] LIVE_UPDATES_FULL = new InAppSubscription[]{
- new InAppPurchaseLiveUpdatesOldMonthlyFull(),
- new InAppPurchaseLiveUpdatesMonthlyFull(),
- new InAppPurchaseLiveUpdates3MonthsFull(),
- new InAppPurchaseLiveUpdatesAnnualFull()
- };
-
- private static final InAppSubscription[] LIVE_UPDATES_FREE = new InAppSubscription[]{
- new InAppPurchaseLiveUpdatesOldMonthlyFree(),
- new InAppPurchaseLiveUpdatesMonthlyFree(),
- new InAppPurchaseLiveUpdates3MonthsFree(),
- new InAppPurchaseLiveUpdatesAnnualFree()
- };
-
- private InAppPurchase fullVersion;
- private InAppPurchase depthContours;
- private InAppPurchase contourLines;
- private InAppSubscription monthlyLiveUpdates;
- private InAppSubscription discountedMonthlyLiveUpdates;
- private InAppSubscriptionList liveUpdates;
- private InAppPurchase[] inAppPurchases;
-
- InAppPurchases(OsmandApplication ctx) {
- fullVersion = FULL_VERSION;
- if (Version.isFreeVersion(ctx)) {
- liveUpdates = new LiveUpdatesInAppPurchasesFree();
- } else {
- liveUpdates = new LiveUpdatesInAppPurchasesFull();
- }
- for (InAppSubscription s : liveUpdates.getAllSubscriptions()) {
- if (s instanceof InAppPurchaseLiveUpdatesMonthly) {
- if (s.isDiscounted()) {
- discountedMonthlyLiveUpdates = s;
- } else {
- monthlyLiveUpdates = s;
- }
- }
- }
- if (Version.isFreeVersion(ctx)) {
- depthContours = DEPTH_CONTOURS_FREE;
- } else {
- depthContours = DEPTH_CONTOURS_FULL;
- }
- if (Version.isFreeVersion(ctx)) {
- contourLines = CONTOUR_LINES_FREE;
- } else {
- contourLines = CONTOUR_LINES_FULL;
- }
-
- inAppPurchases = new InAppPurchase[] { fullVersion, depthContours, contourLines };
+ protected InAppPurchases(OsmandApplication ctx) {
}
public InAppPurchase getFullVersion() {
@@ -123,7 +73,7 @@ public class InAppPurchases {
public InAppSubscription getPurchasedMonthlyLiveUpdates() {
if (monthlyLiveUpdates.isAnyPurchased()) {
return monthlyLiveUpdates;
- } else if (discountedMonthlyLiveUpdates.isAnyPurchased()) {
+ } else if (discountedMonthlyLiveUpdates != null && discountedMonthlyLiveUpdates.isAnyPurchased()) {
return discountedMonthlyLiveUpdates;
}
return null;
@@ -158,31 +108,13 @@ public class InAppPurchases {
return null;
}
- public boolean isFullVersion(String sku) {
- return FULL_VERSION.getSku().equals(sku);
- }
+ public abstract boolean isFullVersion(String sku);
- public boolean isDepthContours(String sku) {
- return DEPTH_CONTOURS_FULL.getSku().equals(sku) || DEPTH_CONTOURS_FREE.getSku().equals(sku);
- }
+ public abstract boolean isDepthContours(String sku);
- public boolean isContourLines(String sku) {
- return CONTOUR_LINES_FULL.getSku().equals(sku) || CONTOUR_LINES_FREE.getSku().equals(sku);
- }
+ public abstract boolean isContourLines(String sku);
- public boolean isLiveUpdates(String sku) {
- for (InAppPurchase p : LIVE_UPDATES_FULL) {
- if (p.getSku().equals(sku)) {
- return true;
- }
- }
- for (InAppPurchase p : LIVE_UPDATES_FREE) {
- if (p.getSku().equals(sku)) {
- return true;
- }
- }
- return false;
- }
+ public abstract boolean isLiveUpdates(String sku);
public abstract static class InAppSubscriptionList {
@@ -260,20 +192,6 @@ public class InAppPurchases {
}
}
- public static class LiveUpdatesInAppPurchasesFree extends InAppSubscriptionList {
-
- public LiveUpdatesInAppPurchasesFree() {
- super(LIVE_UPDATES_FREE);
- }
- }
-
- public static class LiveUpdatesInAppPurchasesFull extends InAppSubscriptionList {
-
- public LiveUpdatesInAppPurchasesFull() {
- super(LIVE_UPDATES_FULL);
- }
- }
-
public abstract static class InAppPurchase {
public enum PurchaseState {
@@ -295,11 +213,11 @@ public class InAppPurchases {
private NumberFormat currencyFormatter;
- private InAppPurchase(@NonNull String sku) {
+ protected InAppPurchase(@NonNull String sku) {
this.sku = sku;
}
- private InAppPurchase(@NonNull String sku, boolean discounted) {
+ protected InAppPurchase(@NonNull String sku, boolean discounted) {
this(sku);
this.discounted = discounted;
}
@@ -777,23 +695,9 @@ public class InAppPurchases {
}
}
- public static class InAppPurchaseFullVersion extends InAppPurchase {
-
- private static final String SKU_FULL_VERSION_PRICE = "osmand_full_version_price";
-
- InAppPurchaseFullVersion() {
- super(SKU_FULL_VERSION_PRICE);
- }
-
- @Override
- public String getDefaultPrice(Context ctx) {
- return ctx.getString(R.string.full_version_price);
- }
- }
-
public static class InAppPurchaseDepthContours extends InAppPurchase {
- private InAppPurchaseDepthContours(String sku) {
+ protected InAppPurchaseDepthContours(String sku) {
super(sku);
}
@@ -803,27 +707,9 @@ public class InAppPurchases {
}
}
- public static class InAppPurchaseDepthContoursFull extends InAppPurchaseDepthContours {
-
- private static final String SKU_DEPTH_CONTOURS_FULL = "net.osmand.seadepth_plus";
-
- InAppPurchaseDepthContoursFull() {
- super(SKU_DEPTH_CONTOURS_FULL);
- }
- }
-
- public static class InAppPurchaseDepthContoursFree extends InAppPurchaseDepthContours {
-
- private static final String SKU_DEPTH_CONTOURS_FREE = "net.osmand.seadepth";
-
- InAppPurchaseDepthContoursFree() {
- super(SKU_DEPTH_CONTOURS_FREE);
- }
- }
-
public static class InAppPurchaseContourLines extends InAppPurchase {
- private InAppPurchaseContourLines(String sku) {
+ protected InAppPurchaseContourLines(String sku) {
super(sku);
}
@@ -833,25 +719,7 @@ public class InAppPurchases {
}
}
- public static class InAppPurchaseContourLinesFull extends InAppPurchaseContourLines {
-
- private static final String SKU_CONTOUR_LINES_FULL = "net.osmand.contourlines_plus";
-
- InAppPurchaseContourLinesFull() {
- super(SKU_CONTOUR_LINES_FULL);
- }
- }
-
- public static class InAppPurchaseContourLinesFree extends InAppPurchaseContourLines {
-
- private static final String SKU_CONTOUR_LINES_FREE = "net.osmand.contourlines";
-
- InAppPurchaseContourLinesFree() {
- super(SKU_CONTOUR_LINES_FREE);
- }
- }
-
- public static abstract class InAppPurchaseLiveUpdatesMonthly extends InAppSubscription {
+ protected static abstract class InAppPurchaseLiveUpdatesMonthly extends InAppSubscription {
InAppPurchaseLiveUpdatesMonthly(String skuNoVersion, int version) {
super(skuNoVersion, version);
@@ -905,45 +773,7 @@ public class InAppPurchases {
}
}
- public static class InAppPurchaseLiveUpdatesMonthlyFull extends InAppPurchaseLiveUpdatesMonthly {
-
- private static final String SKU_LIVE_UPDATES_MONTHLY_FULL = "osm_live_subscription_monthly_full";
-
- InAppPurchaseLiveUpdatesMonthlyFull() {
- super(SKU_LIVE_UPDATES_MONTHLY_FULL, 1);
- }
-
- private InAppPurchaseLiveUpdatesMonthlyFull(@NonNull String sku) {
- super(sku);
- }
-
- @Nullable
- @Override
- protected InAppSubscription newInstance(@NonNull String sku) {
- return sku.startsWith(getSkuNoVersion()) ? new InAppPurchaseLiveUpdatesMonthlyFull(sku) : null;
- }
- }
-
- public static class InAppPurchaseLiveUpdatesMonthlyFree extends InAppPurchaseLiveUpdatesMonthly {
-
- private static final String SKU_LIVE_UPDATES_MONTHLY_FREE = "osm_live_subscription_monthly_free";
-
- InAppPurchaseLiveUpdatesMonthlyFree() {
- super(SKU_LIVE_UPDATES_MONTHLY_FREE, 1);
- }
-
- private InAppPurchaseLiveUpdatesMonthlyFree(@NonNull String sku) {
- super(sku);
- }
-
- @Nullable
- @Override
- protected InAppSubscription newInstance(@NonNull String sku) {
- return sku.startsWith(getSkuNoVersion()) ? new InAppPurchaseLiveUpdatesMonthlyFree(sku) : null;
- }
- }
-
- public static abstract class InAppPurchaseLiveUpdates3Months extends InAppSubscription {
+ protected static abstract class InAppPurchaseLiveUpdates3Months extends InAppSubscription {
InAppPurchaseLiveUpdates3Months(String skuNoVersion, int version) {
super(skuNoVersion, version);
@@ -986,45 +816,7 @@ public class InAppPurchases {
}
}
- public static class InAppPurchaseLiveUpdates3MonthsFull extends InAppPurchaseLiveUpdates3Months {
-
- private static final String SKU_LIVE_UPDATES_3_MONTHS_FULL = "osm_live_subscription_3_months_full";
-
- InAppPurchaseLiveUpdates3MonthsFull() {
- super(SKU_LIVE_UPDATES_3_MONTHS_FULL, 1);
- }
-
- private InAppPurchaseLiveUpdates3MonthsFull(@NonNull String sku) {
- super(sku);
- }
-
- @Nullable
- @Override
- protected InAppSubscription newInstance(@NonNull String sku) {
- return sku.startsWith(getSkuNoVersion()) ? new InAppPurchaseLiveUpdates3MonthsFull(sku) : null;
- }
- }
-
- public static class InAppPurchaseLiveUpdates3MonthsFree extends InAppPurchaseLiveUpdates3Months {
-
- private static final String SKU_LIVE_UPDATES_3_MONTHS_FREE = "osm_live_subscription_3_months_free";
-
- InAppPurchaseLiveUpdates3MonthsFree() {
- super(SKU_LIVE_UPDATES_3_MONTHS_FREE, 1);
- }
-
- private InAppPurchaseLiveUpdates3MonthsFree(@NonNull String sku) {
- super(sku);
- }
-
- @Nullable
- @Override
- protected InAppSubscription newInstance(@NonNull String sku) {
- return sku.startsWith(getSkuNoVersion()) ? new InAppPurchaseLiveUpdates3MonthsFree(sku) : null;
- }
- }
-
- public static abstract class InAppPurchaseLiveUpdatesAnnual extends InAppSubscription {
+ protected static abstract class InAppPurchaseLiveUpdatesAnnual extends InAppSubscription {
InAppPurchaseLiveUpdatesAnnual(String skuNoVersion, int version) {
super(skuNoVersion, version);
@@ -1067,44 +859,6 @@ public class InAppPurchases {
}
}
- public static class InAppPurchaseLiveUpdatesAnnualFull extends InAppPurchaseLiveUpdatesAnnual {
-
- private static final String SKU_LIVE_UPDATES_ANNUAL_FULL = "osm_live_subscription_annual_full";
-
- InAppPurchaseLiveUpdatesAnnualFull() {
- super(SKU_LIVE_UPDATES_ANNUAL_FULL, 1);
- }
-
- private InAppPurchaseLiveUpdatesAnnualFull(@NonNull String sku) {
- super(sku);
- }
-
- @Nullable
- @Override
- protected InAppSubscription newInstance(@NonNull String sku) {
- return sku.startsWith(getSkuNoVersion()) ? new InAppPurchaseLiveUpdatesAnnualFull(sku) : null;
- }
- }
-
- public static class InAppPurchaseLiveUpdatesAnnualFree extends InAppPurchaseLiveUpdatesAnnual {
-
- private static final String SKU_LIVE_UPDATES_ANNUAL_FREE = "osm_live_subscription_annual_free";
-
- InAppPurchaseLiveUpdatesAnnualFree() {
- super(SKU_LIVE_UPDATES_ANNUAL_FREE, 1);
- }
-
- private InAppPurchaseLiveUpdatesAnnualFree(@NonNull String sku) {
- super(sku);
- }
-
- @Nullable
- @Override
- protected InAppSubscription newInstance(@NonNull String sku) {
- return sku.startsWith(getSkuNoVersion()) ? new InAppPurchaseLiveUpdatesAnnualFree(sku) : null;
- }
- }
-
public static class InAppPurchaseLiveUpdatesOldMonthly extends InAppPurchaseLiveUpdatesMonthly {
InAppPurchaseLiveUpdatesOldMonthly(String sku) {
@@ -1127,54 +881,5 @@ public class InAppPurchases {
return null;
}
}
-
- public static class InAppPurchaseLiveUpdatesOldMonthlyFull extends InAppPurchaseLiveUpdatesOldMonthly {
-
- private static final String SKU_LIVE_UPDATES_OLD_MONTHLY_FULL = "osm_live_subscription_2";
-
- InAppPurchaseLiveUpdatesOldMonthlyFull() {
- super(SKU_LIVE_UPDATES_OLD_MONTHLY_FULL);
- }
- }
-
- public static class InAppPurchaseLiveUpdatesOldMonthlyFree extends InAppPurchaseLiveUpdatesOldMonthly {
-
- private static final String SKU_LIVE_UPDATES_OLD_MONTHLY_FREE = "osm_free_live_subscription_2";
-
- InAppPurchaseLiveUpdatesOldMonthlyFree() {
- super(SKU_LIVE_UPDATES_OLD_MONTHLY_FREE);
- }
- }
-
- public static class InAppPurchaseLiveUpdatesOldSubscription extends InAppSubscription {
-
- private SkuDetails details;
-
- InAppPurchaseLiveUpdatesOldSubscription(@NonNull SkuDetails details) {
- super(details.getSku(), true);
- this.details = details;
- }
-
- @Override
- public String getDefaultPrice(Context ctx) {
- return "";
- }
-
- @Override
- public CharSequence getTitle(Context ctx) {
- return details.getTitle();
- }
-
- @Override
- public CharSequence getDescription(@NonNull Context ctx) {
- return details.getDescription();
- }
-
- @Nullable
- @Override
- protected InAppSubscription newInstance(@NonNull String sku) {
- return null;
- }
- }
}
diff --git a/OsmAnd/src/net/osmand/plus/liveupdates/LiveUpdatesFragment.java b/OsmAnd/src/net/osmand/plus/liveupdates/LiveUpdatesFragment.java
index d9824cce8f..c503162910 100644
--- a/OsmAnd/src/net/osmand/plus/liveupdates/LiveUpdatesFragment.java
+++ b/OsmAnd/src/net/osmand/plus/liveupdates/LiveUpdatesFragment.java
@@ -35,6 +35,8 @@ import androidx.fragment.app.FragmentManager;
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout;
import net.osmand.plus.OsmandApplication;
+import net.osmand.plus.settings.backend.CommonPreference;
+import net.osmand.plus.settings.backend.OsmandSettings;
import net.osmand.plus.R;
import net.osmand.plus.Version;
import net.osmand.plus.activities.LocalIndexHelper;
@@ -49,7 +51,6 @@ import net.osmand.plus.inapp.InAppPurchaseHelper.InAppPurchaseListener;
import net.osmand.plus.inapp.InAppPurchaseHelper.InAppPurchaseTaskType;
import net.osmand.plus.inapp.InAppPurchases.InAppSubscription;
import net.osmand.plus.resources.IncrementalChangesManager;
-import net.osmand.plus.settings.backend.OsmandSettings;
import net.osmand.util.Algorithms;
import java.io.File;
@@ -312,7 +313,7 @@ public class LiveUpdatesFragment extends BaseOsmAndFragment implements InAppPurc
}
public void add(LocalIndexInfo info) {
- OsmandSettings.CommonPreference preference = preferenceLiveUpdatesOn(
+ CommonPreference preference = preferenceLiveUpdatesOn(
info.getFileName(), app.getSettings());
if (preference.get()) {
dataShouldUpdate.add(info);
@@ -324,8 +325,8 @@ public class LiveUpdatesFragment extends BaseOsmAndFragment implements InAppPurc
public void notifyLiveUpdatesChanged() {
Set changedSet = new HashSet<>();
for (LocalIndexInfo localIndexInfo : dataShouldUpdate) {
- OsmandSettings.CommonPreference preference =
- preferenceLiveUpdatesOn(localIndexInfo.getFileName(), app.getSettings());
+ CommonPreference preference =
+ preferenceLiveUpdatesOn(localIndexInfo.getFileName(), getSettings());
if (!preference.get()) {
changedSet.add(localIndexInfo);
}
@@ -334,8 +335,8 @@ public class LiveUpdatesFragment extends BaseOsmAndFragment implements InAppPurc
dataShouldNotUpdate.addAll(changedSet);
changedSet.clear();
for (LocalIndexInfo localIndexInfo : dataShouldNotUpdate) {
- OsmandSettings.CommonPreference preference =
- preferenceLiveUpdatesOn(localIndexInfo.getFileName(), app.getSettings());
+ CommonPreference preference =
+ preferenceLiveUpdatesOn(localIndexInfo.getFileName(), getSettings());
if (preference.get()) {
changedSet.add(localIndexInfo);
}
@@ -473,10 +474,10 @@ public class LiveUpdatesFragment extends BaseOsmAndFragment implements InAppPurc
String fileName = li.getFileName();
PendingIntent alarmIntent = getPendingIntent(ctx, fileName);
if (enable) {
- final OsmandSettings.CommonPreference updateFrequencyPreference =
- preferenceUpdateFrequency(fileName, app.getSettings());
- final OsmandSettings.CommonPreference timeOfDayPreference =
- preferenceTimeOfDayToUpdate(fileName, app.getSettings());
+ final CommonPreference updateFrequencyPreference =
+ preferenceUpdateFrequency(fileName, getSettings());
+ final CommonPreference timeOfDayPreference =
+ preferenceTimeOfDayToUpdate(fileName, getSettings());
UpdateFrequency updateFrequency = UpdateFrequency.values()[updateFrequencyPreference.get()];
TimeOfDay timeOfDayToUpdate = TimeOfDay.values()[timeOfDayPreference.get()];
setAlarmForPendingIntent(alarmIntent, alarmMgr, updateFrequency, timeOfDayToUpdate);
@@ -570,7 +571,7 @@ public class LiveUpdatesFragment extends BaseOsmAndFragment implements InAppPurc
public void bindLocalIndexInfo(@NonNull final String item, boolean isLastChild) {
OsmandApplication context = fragment.getMyActivity().getMyApplication();
- final OsmandSettings.CommonPreference shouldUpdatePreference =
+ final CommonPreference shouldUpdatePreference =
preferenceLiveUpdatesOn(item, fragment.getSettings());
IncrementalChangesManager changesManager = context.getResourceManager().getChangesManager();
@@ -600,7 +601,7 @@ public class LiveUpdatesFragment extends BaseOsmAndFragment implements InAppPurc
Algorithms.getFileNameWithoutExtension(new File(item));
final long timestamp = changesManager.getTimestamp(fileNameWithoutExtension);
final long lastCheck = preferenceLastCheck(item, fragment.getSettings()).get();
- OsmandSettings.CommonPreference liveUpdateOn = preferenceLiveUpdatesOn(item, fragment.getSettings());
+ CommonPreference liveUpdateOn = preferenceLiveUpdatesOn(item, fragment.getSettings());
if(liveUpdateOn.get() && lastCheck != DEFAULT_LAST_CHECK) {
String lastCheckString = formatDateTime(fragment.getActivity(), lastCheck );
descriptionTextView.setText(context.getString(R.string.last_update, lastCheckString));
diff --git a/OsmAnd/src/net/osmand/plus/liveupdates/LiveUpdatesHelper.java b/OsmAnd/src/net/osmand/plus/liveupdates/LiveUpdatesHelper.java
index ec4afd6861..ce9d3d9c5b 100644
--- a/OsmAnd/src/net/osmand/plus/liveupdates/LiveUpdatesHelper.java
+++ b/OsmAnd/src/net/osmand/plus/liveupdates/LiveUpdatesHelper.java
@@ -8,6 +8,7 @@ import android.os.AsyncTask;
import androidx.annotation.NonNull;
+import net.osmand.plus.settings.backend.CommonPreference;
import net.osmand.plus.settings.backend.OsmandSettings;
import net.osmand.plus.R;
import net.osmand.plus.activities.OsmandActionBarActivity;
@@ -32,7 +33,7 @@ public class LiveUpdatesHelper {
public static final int DEFAULT_LAST_CHECK = -1;
- private static OsmandSettings.CommonPreference checkPref(OsmandSettings.CommonPreference p) {
+ private static CommonPreference checkPref(CommonPreference p) {
if (p.isSet()) {
T vl = p.get();
p = p.makeGlobal();
@@ -44,37 +45,37 @@ public class LiveUpdatesHelper {
}
return p;
}
- public static OsmandSettings.CommonPreference preferenceForLocalIndex(
+ public static CommonPreference preferenceForLocalIndex(
String fileName, OsmandSettings settings) {
final String settingId = fileName + LIVE_UPDATES_ON_POSTFIX;
return checkPref(settings.registerBooleanPreference(settingId, false));
}
- public static OsmandSettings.CommonPreference preferenceLiveUpdatesOn(
+ public static CommonPreference preferenceLiveUpdatesOn(
String fileName, OsmandSettings settings) {
final String settingId = fileName + LIVE_UPDATES_ON_POSTFIX;
return checkPref(settings.registerBooleanPreference(settingId, false));
}
- public static OsmandSettings.CommonPreference preferenceDownloadViaWiFi(
+ public static CommonPreference preferenceDownloadViaWiFi(
String fileName, OsmandSettings settings) {
final String settingId = fileName + DOWNLOAD_VIA_WIFI_POSTFIX;
return checkPref(settings.registerBooleanPreference(settingId, false));
}
- public static OsmandSettings.CommonPreference preferenceUpdateFrequency(
+ public static CommonPreference preferenceUpdateFrequency(
String fileName, OsmandSettings settings) {
final String settingId = fileName + UPDATE_TIMES_POSTFIX;
return checkPref(settings.registerIntPreference(settingId, UpdateFrequency.HOURLY.ordinal()));
}
- public static OsmandSettings.CommonPreference preferenceTimeOfDayToUpdate(
+ public static CommonPreference preferenceTimeOfDayToUpdate(
String fileName, OsmandSettings settings) {
final String settingId = fileName + TIME_OF_DAY_TO_UPDATE_POSTFIX;
return checkPref(settings.registerIntPreference(settingId, TimeOfDay.NIGHT.ordinal()));
}
- public static OsmandSettings.CommonPreference preferenceLastCheck(
+ public static CommonPreference preferenceLastCheck(
String fileName, OsmandSettings settings) {
final String settingId = fileName + LAST_UPDATE_ATTEMPT_ON_POSTFIX;
return checkPref(settings.registerLongPreference(settingId, DEFAULT_LAST_CHECK));
diff --git a/OsmAnd/src/net/osmand/plus/liveupdates/LiveUpdatesSettingsDialogFragment.java b/OsmAnd/src/net/osmand/plus/liveupdates/LiveUpdatesSettingsDialogFragment.java
index d3f8f2ed4e..d27e733d7a 100644
--- a/OsmAnd/src/net/osmand/plus/liveupdates/LiveUpdatesSettingsDialogFragment.java
+++ b/OsmAnd/src/net/osmand/plus/liveupdates/LiveUpdatesSettingsDialogFragment.java
@@ -23,6 +23,7 @@ import androidx.fragment.app.DialogFragment;
import net.osmand.AndroidUtils;
import net.osmand.PlatformUtil;
import net.osmand.plus.OsmandApplication;
+import net.osmand.plus.settings.backend.CommonPreference;
import net.osmand.plus.settings.backend.OsmandSettings;
import net.osmand.plus.R;
import net.osmand.plus.download.AbstractDownloadActivity;
@@ -85,7 +86,7 @@ public class LiveUpdatesSettingsDialogFragment extends DialogFragment {
final long lastCheck = preferenceLastCheck(fileName, getSettings()).get();
- OsmandSettings.CommonPreference preference = preferenceLiveUpdatesOn(fileName,
+ CommonPreference