diff --git a/android/src/com/mapswithme/maps/MwmActivity.java b/android/src/com/mapswithme/maps/MwmActivity.java index 56462a70a2a..044e67bbbfc 100644 --- a/android/src/com/mapswithme/maps/MwmActivity.java +++ b/android/src/com/mapswithme/maps/MwmActivity.java @@ -2365,7 +2365,8 @@ public boolean isSubwayEnabled() @Override public void onCommonBuildError(int lastResultCode, @NonNull String[] lastMissingMaps) { - RoutingErrorDialogFragment fragment = RoutingErrorDialogFragment.create(lastResultCode, lastMissingMaps); + RoutingErrorDialogFragment fragment = RoutingErrorDialogFragment.create(getApplicationContext(), + lastResultCode, lastMissingMaps); fragment.show(getSupportFragmentManager(), RoutingErrorDialogFragment.class.getSimpleName()); } @@ -2852,7 +2853,7 @@ public void onClick(View v) Statistics.INSTANCE.trackEvent(Statistics.EventName.TOOLBAR_MY_POSITION); AlohaHelper.logClick(AlohaHelper.TOOLBAR_MY_POSITION); - if (!PermissionsUtils.isLocationGranted()) + if (!PermissionsUtils.isLocationGranted(getApplicationContext())) { if (PermissionsUtils.isLocationExplanationNeeded(MwmActivity.this)) PermissionsUtils.requestLocationPermission(MwmActivity.this, REQ_CODE_LOCATION_PERMISSION); diff --git a/android/src/com/mapswithme/maps/PanelAnimator.java b/android/src/com/mapswithme/maps/PanelAnimator.java index 04d747d5928..8286b6ece07 100644 --- a/android/src/com/mapswithme/maps/PanelAnimator.java +++ b/android/src/com/mapswithme/maps/PanelAnimator.java @@ -3,6 +3,8 @@ import android.animation.Animator; import android.animation.ValueAnimator; import android.os.Bundle; + +import androidx.annotation.IntegerRes; import androidx.annotation.NonNull; import androidx.annotation.Nullable; import androidx.fragment.app.Fragment; @@ -14,17 +16,19 @@ class PanelAnimator { - private static final int DURATION = MwmApplication.get().getResources().getInteger(R.integer.anim_panel); private static final int WIDTH = UiUtils.dimen(R.dimen.panel_width); private final MwmActivity mActivity; private final Listeners mAnimationTrackListeners = new Listeners<>(); private final View mPanel; + @IntegerRes + private final int mDuration; PanelAnimator(MwmActivity activity) { mActivity = activity; mPanel = mActivity.findViewById(R.id.fragment_container); + mDuration = mActivity.getResources().getInteger(R.integer.anim_panel); } void registerListener(@NonNull MwmActivity.LeftAnimationTrackListener animationTrackListener) @@ -99,7 +103,7 @@ public void onAnimationEnd(Animator animation) } }); - animator.setDuration(DURATION); + animator.setDuration(mDuration); animator.setInterpolator(new AccelerateInterpolator()); animator.start(); } @@ -144,7 +148,7 @@ public void onAnimationEnd(Animator animation) } }); - animator.setDuration(DURATION); + animator.setDuration(mDuration); animator.setInterpolator(new AccelerateInterpolator()); animator.start(); } diff --git a/android/src/com/mapswithme/maps/ads/RateStoreDialogFragment.java b/android/src/com/mapswithme/maps/ads/RateStoreDialogFragment.java index b67f13afa40..f1357ac87f0 100644 --- a/android/src/com/mapswithme/maps/ads/RateStoreDialogFragment.java +++ b/android/src/com/mapswithme/maps/ads/RateStoreDialogFragment.java @@ -115,7 +115,9 @@ public void onClick(View v) long installTime = 0; try { - info = MwmApplication.get().getPackageManager().getPackageInfo(BuildConfig.APPLICATION_ID, 0); + info = MwmApplication.from(requireContext()) + .getPackageManager() + .getPackageInfo(BuildConfig.APPLICATION_ID, 0); installTime = info.firstInstallTime; } catch (PackageManager.NameNotFoundException e) { diff --git a/android/src/com/mapswithme/maps/background/NotificationService.java b/android/src/com/mapswithme/maps/background/NotificationService.java index e685b4cfb43..1896c7ca421 100644 --- a/android/src/com/mapswithme/maps/background/NotificationService.java +++ b/android/src/com/mapswithme/maps/background/NotificationService.java @@ -111,7 +111,7 @@ private void tryToShowNotification() } // Do not show push when user is in the navigation mode. - if (MwmApplication.get().arePlatformAndCoreInitialized() + if (MwmApplication.from(getApplicationContext()).arePlatformAndCoreInitialized() && RoutingController.get().isNavigating()) { LOGGER.d(TAG, "Notification is rejected. The user is in navigation mode."); diff --git a/android/src/com/mapswithme/maps/routing/ResultCodesHelper.java b/android/src/com/mapswithme/maps/routing/ResultCodesHelper.java index f6355b50217..8c0f522404c 100644 --- a/android/src/com/mapswithme/maps/routing/ResultCodesHelper.java +++ b/android/src/com/mapswithme/maps/routing/ResultCodesHelper.java @@ -1,5 +1,6 @@ package com.mapswithme.maps.routing; +import android.content.Context; import android.content.res.Resources; import android.util.Pair; @@ -34,9 +35,10 @@ class ResultCodesHelper static final int HAS_WARNINGS = 16; @NonNull - static ResourcesHolder getDialogTitleSubtitle(int errorCode, int missingCount) + static ResourcesHolder getDialogTitleSubtitle(@NonNull Context context, + int errorCode, int missingCount) { - Resources resources = MwmApplication.get().getResources(); + Resources resources = MwmApplication.from(context).getResources(); int titleRes = 0; List messages = new ArrayList<>(); @StringRes diff --git a/android/src/com/mapswithme/maps/routing/RoutingController.java b/android/src/com/mapswithme/maps/routing/RoutingController.java index 1c8ba21d160..154e29a3ec1 100644 --- a/android/src/com/mapswithme/maps/routing/RoutingController.java +++ b/android/src/com/mapswithme/maps/routing/RoutingController.java @@ -14,6 +14,7 @@ import androidx.annotation.Nullable; import androidx.appcompat.app.AlertDialog; import androidx.core.util.Pair; +import androidx.fragment.app.Fragment; import androidx.fragment.app.FragmentActivity; import com.mapswithme.maps.Framework; import com.mapswithme.maps.MwmApplication; @@ -380,13 +381,14 @@ private void showDisclaimer(final MapObject startPoint, final MapObject endPoint if (mContainer == null) return; + FragmentActivity activity = mContainer.getActivity(); StringBuilder builder = new StringBuilder(); for (int resId : new int[] { R.string.dialog_routing_disclaimer_priority, R.string.dialog_routing_disclaimer_precision, R.string.dialog_routing_disclaimer_recommendations, R.string.dialog_routing_disclaimer_borders, R.string.dialog_routing_disclaimer_beware }) - builder.append(MwmApplication.get().getString(resId)).append("\n\n"); + builder.append(MwmApplication.from(activity.getApplicationContext()).getString(resId)).append("\n\n"); - new AlertDialog.Builder(mContainer.getActivity()) + new AlertDialog.Builder(activity) .setTitle(R.string.dialog_routing_disclaimer_title) .setMessage(builder.toString()) .setCancelable(false) diff --git a/android/src/com/mapswithme/maps/routing/RoutingErrorDialogFragment.java b/android/src/com/mapswithme/maps/routing/RoutingErrorDialogFragment.java index 7f2153f7363..6a9cf1497c1 100644 --- a/android/src/com/mapswithme/maps/routing/RoutingErrorDialogFragment.java +++ b/android/src/com/mapswithme/maps/routing/RoutingErrorDialogFragment.java @@ -1,7 +1,10 @@ package com.mapswithme.maps.routing; +import android.content.Context; import android.content.DialogInterface; import android.os.Bundle; + +import androidx.annotation.NonNull; import androidx.annotation.Nullable; import androidx.fragment.app.Fragment; import androidx.appcompat.app.AlertDialog; @@ -30,7 +33,7 @@ void beforeDialogCreated(AlertDialog.Builder builder) super.beforeDialogCreated(builder); ResultCodesHelper.ResourcesHolder resHolder = - ResultCodesHelper.getDialogTitleSubtitle(mResultCode, mMissingMaps.size()); + ResultCodesHelper.getDialogTitleSubtitle(requireContext(), mResultCode, mMissingMaps.size()); Pair titleMessage = resHolder.getTitleMessage(); builder.setTitle(titleMessage.first); @@ -94,7 +97,8 @@ private void startDownload() @Override public void run() { - RoutingMapsDownloadFragment downloader = RoutingMapsDownloadFragment.create(mMapsArray); + RoutingMapsDownloadFragment downloader = RoutingMapsDownloadFragment + .create(getAppContextOrThrow(), mMapsArray); downloader.show(getActivity().getSupportFragmentManager(), downloader.getClass().getSimpleName()); mCancelled = false; @@ -137,12 +141,14 @@ void parseArguments() mResultCode = getArguments().getInt(EXTRA_RESULT_CODE); } - public static RoutingErrorDialogFragment create(int resultCode, @Nullable String[] missingMaps) + public static RoutingErrorDialogFragment create(@NonNull Context context, + int resultCode, @Nullable String[] missingMaps) { Bundle args = new Bundle(); args.putInt(EXTRA_RESULT_CODE, resultCode); args.putStringArray(EXTRA_MISSING_MAPS, missingMaps); - RoutingErrorDialogFragment res = (RoutingErrorDialogFragment)Fragment.instantiate(MwmApplication.get(), RoutingErrorDialogFragment.class.getName()); + RoutingErrorDialogFragment res = (RoutingErrorDialogFragment) Fragment + .instantiate(context, RoutingErrorDialogFragment.class.getName()); res.setArguments(args); return res; } diff --git a/android/src/com/mapswithme/maps/routing/RoutingMapsDownloadFragment.java b/android/src/com/mapswithme/maps/routing/RoutingMapsDownloadFragment.java index 372f2c6d5ff..c6d866793aa 100644 --- a/android/src/com/mapswithme/maps/routing/RoutingMapsDownloadFragment.java +++ b/android/src/com/mapswithme/maps/routing/RoutingMapsDownloadFragment.java @@ -1,7 +1,10 @@ package com.mapswithme.maps.routing; +import android.content.Context; import android.content.DialogInterface; import android.os.Bundle; + +import androidx.annotation.NonNull; import androidx.fragment.app.Fragment; import androidx.appcompat.app.AlertDialog; import android.view.View; @@ -171,11 +174,12 @@ public void onStop() } } - public static RoutingMapsDownloadFragment create(String[] missingMaps) + public static RoutingMapsDownloadFragment create(@NonNull Context context, String[] missingMaps) { Bundle args = new Bundle(); args.putStringArray(EXTRA_MISSING_MAPS, missingMaps); - RoutingMapsDownloadFragment res = (RoutingMapsDownloadFragment) Fragment.instantiate(MwmApplication.get(), RoutingMapsDownloadFragment.class.getName()); + RoutingMapsDownloadFragment res = (RoutingMapsDownloadFragment) Fragment + .instantiate(context, RoutingMapsDownloadFragment.class.getName()); res.setArguments(args); return res; } diff --git a/android/src/com/mapswithme/maps/routing/RoutingPlanController.java b/android/src/com/mapswithme/maps/routing/RoutingPlanController.java index 3505f6e8fa8..1f247cdaf30 100644 --- a/android/src/com/mapswithme/maps/routing/RoutingPlanController.java +++ b/android/src/com/mapswithme/maps/routing/RoutingPlanController.java @@ -28,7 +28,6 @@ public class RoutingPlanController extends ToolbarController { - static final int ANIM_TOGGLE = MwmApplication.get().getResources().getInteger(R.integer.anim_default); private static final String BUNDLE_HAS_DRIVING_OPTIONS_VIEW = "has_driving_options_view"; private final View mFrame; @@ -50,6 +49,7 @@ public class RoutingPlanController extends ToolbarController private final RoutingBottomMenuController mRoutingBottomMenuController; int mFrameHeight; + final int mAnimToggle; @NonNull private final View mDrivingOptionsBtnContainer; @@ -110,6 +110,8 @@ public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) btn.setOnClickListener(v -> DrivingOptionsActivity.start(requireActivity())); mDriverOptionsLayoutListener = new SelfTerminatedDrivingOptionsLayoutListener(); + mAnimToggle = MwmApplication.from(activity.getApplicationContext()) + .getResources().getInteger(R.integer.anim_default); } @NonNull diff --git a/android/src/com/mapswithme/maps/routing/RoutingPlanInplaceController.java b/android/src/com/mapswithme/maps/routing/RoutingPlanInplaceController.java index 687ea9c9ce7..09541d6ff3c 100644 --- a/android/src/com/mapswithme/maps/routing/RoutingPlanInplaceController.java +++ b/android/src/com/mapswithme/maps/routing/RoutingPlanInplaceController.java @@ -94,7 +94,7 @@ public void onAnimationEnd(Animator animation) completion.run(); } }); - animator.setDuration(ANIM_TOGGLE); + animator.setDuration(mAnimToggle); animator.start(); return animator; } diff --git a/android/src/com/mapswithme/maps/widget/RotateDrawable.java b/android/src/com/mapswithme/maps/widget/RotateDrawable.java index b447fb7f755..73562de06f0 100644 --- a/android/src/com/mapswithme/maps/widget/RotateDrawable.java +++ b/android/src/com/mapswithme/maps/widget/RotateDrawable.java @@ -15,11 +15,6 @@ public class RotateDrawable extends Drawable private final Drawable mBaseDrawable; private float mAngle; - public RotateDrawable(@DrawableRes int resId) - { - this(ContextCompat.getDrawable(MwmApplication.get(), resId)); - } - public RotateDrawable(Drawable drawable) { super(); diff --git a/android/src/com/mapswithme/maps/widget/placepage/PlacePageButtons.java b/android/src/com/mapswithme/maps/widget/placepage/PlacePageButtons.java index 72735d15d88..eb8835f1ce6 100644 --- a/android/src/com/mapswithme/maps/widget/placepage/PlacePageButtons.java +++ b/android/src/com/mapswithme/maps/widget/placepage/PlacePageButtons.java @@ -3,6 +3,8 @@ import androidx.annotation.DrawableRes; import androidx.annotation.NonNull; import androidx.annotation.StringRes; + +import android.content.Context; import android.view.LayoutInflater; import android.view.MenuItem; import android.view.View; @@ -89,7 +91,7 @@ public int getDisabledStateResId() } @DrawableRes - public int getEnabledStateResId() + public int getEnabledStateResId(@NonNull Context context) { return mEnabledStateResId; } @@ -108,7 +110,7 @@ public int getDisabledStateResId() } @Override - public int getEnabledStateResId() + public int getEnabledStateResId(@NonNull Context context) { throw new UnsupportedOperationException("Not supported here"); } @@ -292,9 +294,10 @@ public int getBackgroundResource() new ImageResources.Stub() { @Override - public int getEnabledStateResId() + public int getEnabledStateResId(@NonNull Context context) { - return ThemeUtils.getResource(MwmApplication.get(), android.R.attr.homeAsUpIndicator); + return ThemeUtils.getResource(MwmApplication.from(context), + android.R.attr.homeAsUpIndicator); } }, ButtonType.BACK), @@ -491,7 +494,7 @@ private void showPopup(final List buttons) for (int i = mMaxButtons; i < buttons.size(); i++) { PlacePageButton bsItem = buttons.get(i); - int iconRes = bsItem.getIcon().getEnabledStateResId(); + int iconRes = bsItem.getIcon().getEnabledStateResId(mPlacePage.getContext()); bs.sheet(i, iconRes, bsItem.getTitle()); } @@ -511,14 +514,15 @@ public boolean onMenuItemClick(MenuItem item) private View createButton(@NonNull final List items, @NonNull final PlacePageButton current) { - LayoutInflater inflater = LayoutInflater.from(mPlacePage.getContext()); + Context context = mPlacePage.getContext(); + LayoutInflater inflater = LayoutInflater.from(context); View parent = inflater.inflate(R.layout.place_page_button, mFrame, false); ImageView icon = (ImageView) parent.findViewById(R.id.icon); TextView title = (TextView) parent.findViewById(R.id.title); title.setText(current.getTitle()); - icon.setImageResource(current.getIcon().getEnabledStateResId()); + icon.setImageResource(current.getIcon().getEnabledStateResId(context)); mItemListener.onPrepareVisibleView(current, parent, icon, title); parent.setOnClickListener(new ShowPopupClickListener(current, items)); return parent;