forked from organicmaps/organicmaps
Save routing state when rotating device.
This commit is contained in:
parent
ffcc7babb6
commit
b9c2d4285e
7 changed files with 62 additions and 26 deletions
|
@ -1220,6 +1220,12 @@ extern "C"
|
|||
return frm()->IsRoutingActive();
|
||||
}
|
||||
|
||||
JNIEXPORT jboolean JNICALL
|
||||
Java_com_mapswithme_maps_Framework_nativeIsRouteBuilt(JNIEnv * env, jclass thiz)
|
||||
{
|
||||
return frm()->IsRouteBuilt();
|
||||
}
|
||||
|
||||
JNIEXPORT void JNICALL
|
||||
Java_com_mapswithme_maps_Framework_nativeCloseRouting(JNIEnv * env, jclass thiz)
|
||||
{
|
||||
|
|
|
@ -105,6 +105,8 @@ public class Framework
|
|||
//@{
|
||||
public native static boolean nativeIsRoutingActive();
|
||||
|
||||
public native static boolean nativeIsRouteBuilt();
|
||||
|
||||
public native static void nativeCloseRouting();
|
||||
|
||||
public native static void nativeBuildRoute(double lat, double lon);
|
||||
|
|
|
@ -14,6 +14,7 @@ import android.os.Bundle;
|
|||
import android.os.Environment;
|
||||
import android.os.Handler;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.v4.app.Fragment;
|
||||
import android.support.v4.app.FragmentManager;
|
||||
import android.support.v4.app.FragmentTransaction;
|
||||
|
@ -103,6 +104,7 @@ public class MWMActivity extends BaseMwmFragmentActivity
|
|||
private static final String STATE_ROUTE_FOLLOWED = "RouteFollowed";
|
||||
private static final String STATE_PP_OPENED = "PpOpened";
|
||||
private static final String STATE_MAP_OBJECT = "MapObject";
|
||||
private static final String STATE_MENU_OPENED = "MenuOpened";
|
||||
// Map tasks that we run AFTER rendering initialized
|
||||
private final Stack<MapTask> mTasks = new Stack<>();
|
||||
private BroadcastReceiver mExternalStorageReceiver;
|
||||
|
@ -547,7 +549,7 @@ public class MWMActivity extends BaseMwmFragmentActivity
|
|||
}
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState)
|
||||
public void onCreate(@Nullable Bundle savedInstanceState)
|
||||
{
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
|
@ -575,14 +577,44 @@ public class MWMActivity extends BaseMwmFragmentActivity
|
|||
{
|
||||
String value = intent.getStringExtra(EXTRA_SCREENSHOTS_TASK);
|
||||
if (value.equals(SCREENSHOTS_TASK_LOCATE))
|
||||
{
|
||||
switchNextLocationState();
|
||||
}
|
||||
}
|
||||
|
||||
mLocationPredictor = new LocationPredictor(new Handler(), this);
|
||||
mLikesManager = new LikesManager(this);
|
||||
mMemLogging = new MemLogging(this);
|
||||
restoreRoutingState(savedInstanceState);
|
||||
}
|
||||
|
||||
private void restoreRoutingState(@Nullable Bundle savedInstanceState)
|
||||
{
|
||||
if (Framework.nativeIsRoutingActive())
|
||||
{
|
||||
if (savedInstanceState != null && savedInstanceState.getBoolean(STATE_ROUTE_FOLLOWED))
|
||||
{
|
||||
updateRoutingDistance();
|
||||
mRlTurnByTurnBox.setVisibility(View.VISIBLE);
|
||||
mRlRoutingBox.setVisibility(View.GONE);
|
||||
}
|
||||
else if (Framework.nativeIsRouteBuilt())
|
||||
{
|
||||
updateRoutingDistance();
|
||||
mRlRoutingBox.setVisibility(View.VISIBLE);
|
||||
mRlTurnByTurnBox.setVisibility(View.GONE);
|
||||
}
|
||||
else if (savedInstanceState != null)
|
||||
{
|
||||
final MapObject object = savedInstanceState.getParcelable(STATE_MAP_OBJECT);
|
||||
if (object != null)
|
||||
{
|
||||
mPlacePage.setState(State.PREVIEW);
|
||||
mPlacePage.setMapObject(object);
|
||||
}
|
||||
mIvStartRouting.setVisibility(View.GONE);
|
||||
mTvStartRouting.setVisibility(View.GONE);
|
||||
mPbRoutingProgress.setVisibility(View.VISIBLE);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void initViews()
|
||||
|
@ -719,13 +751,14 @@ public class MWMActivity extends BaseMwmFragmentActivity
|
|||
@Override
|
||||
protected void onSaveInstanceState(Bundle outState)
|
||||
{
|
||||
if (mRlTurnByTurnBox.getVisibility() == View.VISIBLE)
|
||||
outState.putBoolean(STATE_ROUTE_FOLLOWED, true);
|
||||
else if (mPlacePage.getState() != State.HIDDEN)
|
||||
|
||||
if (mPlacePage.getState() != State.HIDDEN)
|
||||
{
|
||||
outState.putBoolean(STATE_PP_OPENED, true);
|
||||
outState.putParcelable(STATE_MAP_OBJECT, mPlacePage.getMapObject());
|
||||
}
|
||||
else if (mVerticalToolbar.getVisibility() == View.VISIBLE)
|
||||
outState.putBoolean(STATE_MENU_OPENED, true);
|
||||
|
||||
super.onSaveInstanceState(outState);
|
||||
}
|
||||
|
@ -733,19 +766,13 @@ public class MWMActivity extends BaseMwmFragmentActivity
|
|||
@Override
|
||||
protected void onRestoreInstanceState(@NonNull Bundle savedInstanceState)
|
||||
{
|
||||
if (savedInstanceState.getBoolean(STATE_ROUTE_FOLLOWED))
|
||||
{
|
||||
if (Framework.nativeIsRoutingActive())
|
||||
{
|
||||
mRlTurnByTurnBox.setVisibility(View.VISIBLE);
|
||||
mRlRoutingBox.setVisibility(View.GONE);
|
||||
}
|
||||
}
|
||||
else if (savedInstanceState.getBoolean(STATE_PP_OPENED))
|
||||
if (savedInstanceState.getBoolean(STATE_PP_OPENED))
|
||||
{
|
||||
mPlacePage.setState(State.PREVIEW);
|
||||
mPlacePage.setMapObject((MapObject) savedInstanceState.getParcelable(STATE_MAP_OBJECT));
|
||||
}
|
||||
else if (savedInstanceState.getBoolean(STATE_MENU_OPENED))
|
||||
setVerticalToolbarVisible(true);
|
||||
|
||||
super.onRestoreInstanceState(savedInstanceState);
|
||||
}
|
||||
|
@ -999,10 +1026,8 @@ public class MWMActivity extends BaseMwmFragmentActivity
|
|||
|
||||
SearchController.getInstance().onResume();
|
||||
mPlacePage.onResume();
|
||||
tryResumeRouting();
|
||||
mLocationPredictor.resume();
|
||||
mLikesManager.showLikeDialogs();
|
||||
|
||||
mMemLogging.startLogging();
|
||||
}
|
||||
|
||||
|
@ -1019,15 +1044,6 @@ public class MWMActivity extends BaseMwmFragmentActivity
|
|||
mLikesManager.cancelLikeDialogs();
|
||||
}
|
||||
|
||||
private void tryResumeRouting()
|
||||
{
|
||||
if (Framework.nativeIsRoutingActive())
|
||||
{
|
||||
updateRoutingDistance();
|
||||
mRlRoutingBox.setVisibility(View.VISIBLE);
|
||||
}
|
||||
}
|
||||
|
||||
private void updateExternalStorageState()
|
||||
{
|
||||
boolean available = false, writable = false;
|
||||
|
|
|
@ -2033,6 +2033,11 @@ bool Framework::IsRoutingActive() const
|
|||
return m_routingSession.IsActive();
|
||||
}
|
||||
|
||||
bool Framework::IsRouteBuilt() const
|
||||
{
|
||||
return m_routingSession.IsBuilt();
|
||||
}
|
||||
|
||||
void Framework::BuildRoute(m2::PointD const & destination)
|
||||
{
|
||||
shared_ptr<State> const & state = GetLocationState();
|
||||
|
|
|
@ -499,6 +499,7 @@ public:
|
|||
/// @name Routing mode
|
||||
//@{
|
||||
bool IsRoutingActive() const;
|
||||
bool IsRouteBuilt() const;
|
||||
void BuildRoute(m2::PointD const & destination);
|
||||
typedef function<void (routing::IRouter::ResultCode, vector<storage::TIndex> const &)> TRouteBuildingCallback;
|
||||
void SetRouteBuildingListener(TRouteBuildingCallback const & callback);
|
||||
|
|
|
@ -66,6 +66,11 @@ bool RoutingSession::IsNavigable() const
|
|||
return (m_state == RouteNotStarted || m_state == OnRoute);
|
||||
}
|
||||
|
||||
bool RoutingSession::IsBuilt() const
|
||||
{
|
||||
return (IsNavigable() || m_state == RouteNeedRebuild || m_state == RouteFinished);
|
||||
}
|
||||
|
||||
void RoutingSession::Reset()
|
||||
{
|
||||
m_state = RoutingNotActive;
|
||||
|
|
|
@ -55,6 +55,7 @@ public:
|
|||
|
||||
bool IsActive() const;
|
||||
bool IsNavigable() const;
|
||||
bool IsBuilt() const;
|
||||
void Reset();
|
||||
|
||||
State OnLocationPositionChanged(m2::PointD const & position, location::GpsInfo const & info);
|
||||
|
|
Loading…
Add table
Reference in a new issue