forked from organicmaps/organicmaps
[android] Review fixes.
This commit is contained in:
parent
5a234b8cb5
commit
dc7d46fc11
15 changed files with 58 additions and 80 deletions
|
@ -950,6 +950,13 @@ public class MwmActivity extends BaseMwmFragmentActivity
|
|||
});
|
||||
}
|
||||
|
||||
if (mIsFragmentContainer)
|
||||
{
|
||||
RoutingPlanFragment fragment = (RoutingPlanFragment) getFragment(RoutingPlanFragment.class);
|
||||
if (fragment != null)
|
||||
fragment.restoreRoutingPanelState(savedInstanceState);
|
||||
}
|
||||
|
||||
if (!mIsFragmentContainer && RoutingController.get().isPlanning())
|
||||
mRoutingPlanInplaceController.restoreState(savedInstanceState);
|
||||
|
||||
|
|
|
@ -177,18 +177,19 @@ public class SplashActivity extends AppCompatActivity
|
|||
if (grantResults.length == 0)
|
||||
return;
|
||||
|
||||
boolean isWriteGranted = false;
|
||||
for (int i = 0; i < permissions.length; i++)
|
||||
{
|
||||
int result = grantResults[i];
|
||||
String permission = permissions[i];
|
||||
if (permission.equals(WRITE_EXTERNAL_STORAGE) && result == PERMISSION_GRANTED)
|
||||
isWriteGranted = true;
|
||||
{
|
||||
mPermissionsGranted = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (isWriteGranted)
|
||||
if (mPermissionsGranted)
|
||||
{
|
||||
mPermissionsGranted = true;
|
||||
init();
|
||||
resumeDialogs();
|
||||
}
|
||||
|
@ -215,7 +216,6 @@ public class SplashActivity extends AppCompatActivity
|
|||
{
|
||||
MwmApplication.get().initNativePlatform();
|
||||
MwmApplication.get().initNativeCore();
|
||||
LocationHelper.INSTANCE.init();
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
|
|
|
@ -5,7 +5,6 @@ import android.content.Context;
|
|||
import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
import android.location.Location;
|
||||
import android.location.LocationManager;
|
||||
import android.text.TextUtils;
|
||||
|
||||
import java.util.concurrent.CountDownLatch;
|
||||
|
@ -15,6 +14,7 @@ import com.mapswithme.maps.R;
|
|||
import com.mapswithme.maps.downloader.CountryItem;
|
||||
import com.mapswithme.maps.downloader.MapManager;
|
||||
import com.mapswithme.maps.editor.Editor;
|
||||
import com.mapswithme.maps.location.LocationHelper;
|
||||
import com.mapswithme.util.LocationUtils;
|
||||
import com.mapswithme.util.concurrency.UiThread;
|
||||
|
||||
|
@ -124,23 +124,13 @@ public class WorkerService extends IntentService
|
|||
@android.support.annotation.UiThread
|
||||
private static boolean processLocation()
|
||||
{
|
||||
final LocationManager manager = (LocationManager) MwmApplication.get().getSystemService(Context.LOCATION_SERVICE);
|
||||
Location l = null;
|
||||
try
|
||||
{
|
||||
l = manager.getLastKnownLocation(LocationManager.PASSIVE_PROVIDER);
|
||||
}
|
||||
catch (SecurityException e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
if (l == null || LocationUtils.isExpired(l, l.getTime(), LocationUtils.LOCATION_EXPIRATION_TIME_MILLIS_LONG))
|
||||
return false;
|
||||
|
||||
MwmApplication.get().initNativePlatform();
|
||||
MwmApplication.get().initNativeCore();
|
||||
|
||||
Location l = LocationHelper.INSTANCE.getLastKnownLocation();
|
||||
if (l == null)
|
||||
return false;
|
||||
|
||||
String country = MapManager.nativeFindCountry(l.getLatitude(), l.getLongitude());
|
||||
if (TextUtils.isEmpty(country))
|
||||
return false;
|
||||
|
|
|
@ -2,6 +2,7 @@ package com.mapswithme.maps.base;
|
|||
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.text.TextUtils;
|
||||
|
||||
import com.mapswithme.util.Config;
|
||||
import com.mapswithme.util.UiUtils;
|
||||
|
@ -10,14 +11,14 @@ import com.mapswithme.util.concurrency.UiThread;
|
|||
import com.mapswithme.util.statistics.Statistics;
|
||||
import com.my.tracker.MyTracker;
|
||||
|
||||
public class BaseActivityDelegate
|
||||
class BaseActivityDelegate
|
||||
{
|
||||
@NonNull
|
||||
private final BaseActivity mActivity;
|
||||
@Nullable
|
||||
private String mThemeName;
|
||||
|
||||
public BaseActivityDelegate(@NonNull BaseActivity activity)
|
||||
BaseActivityDelegate(@NonNull BaseActivity activity)
|
||||
{
|
||||
mActivity = activity;
|
||||
}
|
||||
|
@ -25,27 +26,27 @@ public class BaseActivityDelegate
|
|||
public void onCreate()
|
||||
{
|
||||
mThemeName = Config.getCurrentUiTheme();
|
||||
if (mThemeName != null)
|
||||
if (!TextUtils.isEmpty(mThemeName))
|
||||
mActivity.get().setTheme(mActivity.getThemeResourceId(mThemeName));
|
||||
}
|
||||
|
||||
public void onDestroy()
|
||||
void onDestroy()
|
||||
{
|
||||
ViewServer.get(mActivity.get()).removeWindow(mActivity.get());
|
||||
}
|
||||
|
||||
public void onPostCreate()
|
||||
void onPostCreate()
|
||||
{
|
||||
ViewServer.get(mActivity.get()).addWindow(mActivity.get());
|
||||
}
|
||||
|
||||
public void onStart()
|
||||
void onStart()
|
||||
{
|
||||
Statistics.INSTANCE.startActivity(mActivity.get());
|
||||
MyTracker.onStartActivity(mActivity.get());
|
||||
}
|
||||
|
||||
public void onStop()
|
||||
void onStop()
|
||||
{
|
||||
Statistics.INSTANCE.stopActivity(mActivity.get());
|
||||
MyTracker.onStopActivity(mActivity.get());
|
||||
|
@ -63,9 +64,9 @@ public class BaseActivityDelegate
|
|||
org.alohalytics.Statistics.logEvent("$onPause", mActivity.getClass().getSimpleName());
|
||||
}
|
||||
|
||||
public void onPostResume()
|
||||
void onPostResume()
|
||||
{
|
||||
if (mThemeName != null && mThemeName.equals(Config.getCurrentUiTheme()))
|
||||
if (!TextUtils.isEmpty(mThemeName) && mThemeName.equals(Config.getCurrentUiTheme()))
|
||||
return;
|
||||
|
||||
// Workaround described in https://code.google.com/p/android/issues/detail?id=93731
|
||||
|
|
|
@ -5,6 +5,7 @@ import android.support.v4.app.Fragment;
|
|||
import android.support.v7.app.AppCompatActivity;
|
||||
|
||||
import com.mapswithme.maps.MwmApplication;
|
||||
import com.mapswithme.util.Utils;
|
||||
|
||||
public class BaseMwmFragment extends Fragment
|
||||
{
|
||||
|
@ -13,13 +14,7 @@ public class BaseMwmFragment extends Fragment
|
|||
public void onAttach(Context context)
|
||||
{
|
||||
super.onAttach(context);
|
||||
if (context instanceof AppCompatActivity && !MwmApplication.get().isPlatformInitialized())
|
||||
{
|
||||
((AppCompatActivity)context).getSupportFragmentManager()
|
||||
.beginTransaction()
|
||||
.detach(this)
|
||||
.commit();
|
||||
}
|
||||
Utils.detachFragmentIfInitializing(context, this);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -27,8 +27,6 @@ public class BaseMwmFragmentActivity extends AppCompatActivity
|
|||
{
|
||||
private final BaseActivityDelegate mBaseDelegate = new BaseActivityDelegate(this);
|
||||
|
||||
@Nullable
|
||||
private Bundle mSavedState;
|
||||
private boolean mInitializationComplete = false;
|
||||
|
||||
@Override
|
||||
|
@ -54,7 +52,6 @@ public class BaseMwmFragmentActivity extends AppCompatActivity
|
|||
@Override
|
||||
protected void onCreate(@Nullable Bundle savedInstanceState)
|
||||
{
|
||||
mSavedState = savedInstanceState;
|
||||
if (!MwmApplication.get().isPlatformInitialized()
|
||||
|| !Utils.checkPermissions(this, SplashActivity.PERMISSIONS))
|
||||
{
|
||||
|
@ -261,10 +258,4 @@ public class BaseMwmFragmentActivity extends AppCompatActivity
|
|||
SplashActivity.start(this, type);
|
||||
finish();
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public Bundle getSavedInstanceState()
|
||||
{
|
||||
return mSavedState;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -22,13 +22,7 @@ public abstract class BaseMwmListFragment extends ListFragment
|
|||
public void onAttach(Context context)
|
||||
{
|
||||
super.onAttach(context);
|
||||
if (context instanceof AppCompatActivity && !MwmApplication.get().isPlatformInitialized())
|
||||
{
|
||||
((AppCompatActivity)context).getSupportFragmentManager()
|
||||
.beginTransaction()
|
||||
.detach(this)
|
||||
.commit();
|
||||
}
|
||||
Utils.detachFragmentIfInitializing(context, this);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -45,13 +45,7 @@ public abstract class BaseMwmRecyclerFragment extends Fragment
|
|||
public void onAttach(Context context)
|
||||
{
|
||||
super.onAttach(context);
|
||||
if (context instanceof AppCompatActivity && !MwmApplication.get().isPlatformInitialized())
|
||||
{
|
||||
((AppCompatActivity)context).getSupportFragmentManager()
|
||||
.beginTransaction()
|
||||
.detach(this)
|
||||
.commit();
|
||||
}
|
||||
Utils.detachFragmentIfInitializing(context, this);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -46,7 +46,7 @@ public class BookmarkCategoriesFragment extends BaseMwmRecyclerFragment
|
|||
protected BookmarkCategoriesAdapter getAdapter()
|
||||
{
|
||||
RecyclerView.Adapter adapter = super.getAdapter();
|
||||
return adapter != null ? (BookmarkCategoriesAdapter)adapter : null;
|
||||
return adapter != null ? (BookmarkCategoriesAdapter) adapter : null;
|
||||
}
|
||||
|
||||
@CallSuper
|
||||
|
|
|
@ -253,7 +253,6 @@ public class OnmapDownloader implements MwmActivity.LeftAnimationTrackListener
|
|||
{
|
||||
MapManager.nativeUnsubscribe(mStorageSubscriptionSlot);
|
||||
mStorageSubscriptionSlot = 0;
|
||||
|
||||
MapManager.nativeUnsubscribeOnCountryChanged();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -115,8 +115,6 @@ public class EditorFragment extends BaseMwmFragment implements View.OnClickListe
|
|||
|
||||
private EditorHostFragment mParent;
|
||||
|
||||
private boolean mIsViewCreated = false;
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState)
|
||||
|
@ -128,8 +126,6 @@ public class EditorFragment extends BaseMwmFragment implements View.OnClickListe
|
|||
@Override
|
||||
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState)
|
||||
{
|
||||
mIsViewCreated = true;
|
||||
|
||||
mParent = (EditorHostFragment) getParentFragment();
|
||||
|
||||
initViews(view);
|
||||
|
@ -210,8 +206,7 @@ public class EditorFragment extends BaseMwmFragment implements View.OnClickListe
|
|||
public void onSaveInstanceState(Bundle outState)
|
||||
{
|
||||
super.onSaveInstanceState(outState);
|
||||
if (mIsViewCreated)
|
||||
setEdits();
|
||||
setEdits();
|
||||
}
|
||||
|
||||
boolean setEdits()
|
||||
|
|
|
@ -9,6 +9,8 @@ import android.support.annotation.Nullable;
|
|||
|
||||
import com.mapswithme.maps.MwmApplication;
|
||||
import com.mapswithme.util.LocationUtils;
|
||||
import com.mapswithme.util.log.Logger;
|
||||
import com.mapswithme.util.log.LoggerFactory;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
@ -19,6 +21,8 @@ class AndroidNativeProvider extends BaseLocationProvider
|
|||
private final static String TAG = AndroidNativeProvider.class.getSimpleName();
|
||||
private final static String[] TRUSTED_PROVIDERS = { LocationManager.NETWORK_PROVIDER,
|
||||
LocationManager.GPS_PROVIDER };
|
||||
private final static Logger LOGGER = LoggerFactory.INSTANCE.getLogger(LoggerFactory.Type.LOCATION);
|
||||
|
||||
@NonNull
|
||||
private final LocationManager mLocationManager;
|
||||
@NonNull
|
||||
|
@ -51,15 +55,18 @@ class AndroidNativeProvider extends BaseLocationProvider
|
|||
long interval = LocationHelper.INSTANCE.getInterval();
|
||||
LOGGER.d(TAG, "Request Android native provider '" + provider
|
||||
+ "' to get locations at this interval = " + interval + " ms");
|
||||
mListeners.add(listener);
|
||||
try
|
||||
{
|
||||
mLocationManager.requestLocationUpdates(provider, interval, 0, listener);
|
||||
}
|
||||
catch (SecurityException e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
LOGGER.e(TAG, "Dynamic permission ACCESS_COARSE_LOCATION/ACCESS_FINE_LOCATION is not granted",
|
||||
e);
|
||||
setActive(false);
|
||||
return;
|
||||
}
|
||||
mListeners.add(listener);
|
||||
}
|
||||
|
||||
LocationHelper.INSTANCE.startSensors();
|
||||
|
@ -131,7 +138,8 @@ class AndroidNativeProvider extends BaseLocationProvider
|
|||
}
|
||||
catch (SecurityException e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
LOGGER.e(TAG, "Dynamic permission ACCESS_COARSE_LOCATION/ACCESS_FINE_LOCATION is not granted",
|
||||
e);
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
|
|
@ -158,12 +158,6 @@ public enum LocationHelper
|
|||
}
|
||||
};
|
||||
|
||||
|
||||
public void init()
|
||||
{
|
||||
mLogger.d(LocationHelper.class.getSimpleName(), "ctor()");
|
||||
}
|
||||
|
||||
@UiThread
|
||||
public void initialize()
|
||||
{
|
||||
|
|
|
@ -28,10 +28,6 @@ public class RoutingPlanFragment extends BaseMwmFragment
|
|||
mPlanController = new RoutingPlanController(res, getActivity());
|
||||
updatePoints();
|
||||
|
||||
Bundle activityState = getMwmActivity().getSavedInstanceState();
|
||||
if (activityState != null)
|
||||
restoreRoutingPanelState(activityState);
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
|
|
|
@ -15,8 +15,10 @@ import android.support.annotation.NonNull;
|
|||
import android.support.annotation.Nullable;
|
||||
import android.support.annotation.StringRes;
|
||||
import android.support.v4.app.ActivityCompat;
|
||||
import android.support.v4.app.Fragment;
|
||||
import android.support.v4.app.NavUtils;
|
||||
import android.support.v7.app.AlertDialog;
|
||||
import android.support.v7.app.AppCompatActivity;
|
||||
import android.text.SpannableStringBuilder;
|
||||
import android.text.Spanned;
|
||||
import android.text.TextUtils;
|
||||
|
@ -438,4 +440,16 @@ public class Utils
|
|||
|
||||
return true;
|
||||
}
|
||||
|
||||
public static void detachFragmentIfInitializing(@NonNull Context context,
|
||||
@NonNull Fragment fragment)
|
||||
{
|
||||
if (context instanceof AppCompatActivity && !MwmApplication.get().isPlatformInitialized())
|
||||
{
|
||||
((AppCompatActivity)context).getSupportFragmentManager()
|
||||
.beginTransaction()
|
||||
.detach(fragment)
|
||||
.commit();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue