forked from organicmaps/organicmaps
[android] Added saving/restoring the Uber panel during screen rotation
This commit is contained in:
parent
c1c839a308
commit
52e5fb0b0f
5 changed files with 111 additions and 22 deletions
|
@ -746,7 +746,7 @@ public class MwmActivity extends BaseMwmFragmentActivity
|
|||
{
|
||||
RoutingPlanFragment fragment = (RoutingPlanFragment) getFragment(RoutingPlanFragment.class);
|
||||
if (fragment != null)
|
||||
fragment.saveAltitudeChartState(outState);
|
||||
fragment.saveRoutingPanelState(outState);
|
||||
}
|
||||
|
||||
if (mNavigationController != null)
|
||||
|
|
|
@ -1,20 +1,45 @@
|
|||
package com.mapswithme.maps.api.uber;
|
||||
|
||||
import android.os.Parcel;
|
||||
import android.os.Parcelable;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
|
||||
import com.google.android.gms.analytics.ecommerce.Product;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
public class UberInfo
|
||||
public class UberInfo implements Parcelable
|
||||
{
|
||||
public static final Parcelable.Creator<UberInfo> CREATOR = new Parcelable.Creator<UberInfo>()
|
||||
{
|
||||
|
||||
@Override
|
||||
public UberInfo createFromParcel(Parcel source)
|
||||
{
|
||||
return new UberInfo(source);
|
||||
}
|
||||
|
||||
@Override
|
||||
public UberInfo[] newArray(int size)
|
||||
{
|
||||
return new UberInfo[0];
|
||||
}
|
||||
};
|
||||
|
||||
@Nullable
|
||||
private final Product[] mProducts;
|
||||
|
||||
public UberInfo(@Nullable Product[] products)
|
||||
private UberInfo(@Nullable Product[] products)
|
||||
{
|
||||
mProducts = products;
|
||||
}
|
||||
|
||||
private UberInfo(@NonNull Parcel parcel)
|
||||
{
|
||||
mProducts = (Product[]) parcel.readParcelableArray(Product.class.getClassLoader());
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public Product[] getProducts()
|
||||
{
|
||||
|
@ -29,8 +54,36 @@ public class UberInfo
|
|||
'}';
|
||||
}
|
||||
|
||||
public static class Product
|
||||
@Override
|
||||
public int describeContents()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToParcel(Parcel dest, int flags)
|
||||
{
|
||||
dest.writeParcelableArray(mProducts, 0);
|
||||
}
|
||||
|
||||
public static class Product implements Parcelable
|
||||
{
|
||||
public static final Parcelable.Creator<Product> CREATOR = new Parcelable.Creator<Product>()
|
||||
{
|
||||
|
||||
@Override
|
||||
public Product createFromParcel(Parcel source)
|
||||
{
|
||||
return new Product(source);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Product[] newArray(int size)
|
||||
{
|
||||
return new Product[size];
|
||||
}
|
||||
};
|
||||
|
||||
@NonNull
|
||||
private final String mProductId;
|
||||
@NonNull
|
||||
|
@ -40,7 +93,7 @@ public class UberInfo
|
|||
@NonNull
|
||||
private final String mPrice;
|
||||
|
||||
public Product(@NonNull String productId, @NonNull String name, @NonNull String time, @NonNull String price)
|
||||
private Product(@NonNull String productId, @NonNull String name, @NonNull String time, @NonNull String price)
|
||||
{
|
||||
mProductId = productId;
|
||||
mName = name;
|
||||
|
@ -48,6 +101,14 @@ public class UberInfo
|
|||
mPrice = price;
|
||||
}
|
||||
|
||||
private Product(@NonNull Parcel parcel)
|
||||
{
|
||||
mProductId = parcel.readString();
|
||||
mName = parcel.readString();
|
||||
mTime = parcel.readString();
|
||||
mPrice = parcel.readString();
|
||||
}
|
||||
|
||||
@NonNull
|
||||
public String getProductId()
|
||||
{
|
||||
|
@ -82,6 +143,21 @@ public class UberInfo
|
|||
", mPrice='" + mPrice + '\'' +
|
||||
'}';
|
||||
}
|
||||
|
||||
@Override
|
||||
public int describeContents()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToParcel(Parcel dest, int flags)
|
||||
{
|
||||
dest.writeString(mProductId);
|
||||
dest.writeString(mName);
|
||||
dest.writeString(mTime);
|
||||
dest.writeString(mPrice);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -21,6 +21,7 @@ import android.widget.TextView;
|
|||
import android.widget.Toast;
|
||||
|
||||
import com.mapswithme.maps.Framework;
|
||||
import com.mapswithme.maps.MwmActivity;
|
||||
import com.mapswithme.maps.MwmApplication;
|
||||
import com.mapswithme.maps.R;
|
||||
import com.mapswithme.maps.api.uber.UberInfo;
|
||||
|
@ -39,7 +40,9 @@ import com.mapswithme.util.statistics.Statistics;
|
|||
public class RoutingPlanController extends ToolbarController
|
||||
{
|
||||
static final int ANIM_TOGGLE = MwmApplication.get().getResources().getInteger(R.integer.anim_slots_toggle);
|
||||
private static final String STATE_ALTITUDE_CHART_SHOWN = "altitude chart shown";
|
||||
private static final String STATE_ALTITUDE_CHART_SHOWN = "altitude_chart_shown";
|
||||
private static final String STATE_TAXI_INFO = "taxi_info";
|
||||
|
||||
|
||||
protected final View mFrame;
|
||||
private final ImageView mToggle;
|
||||
|
@ -56,7 +59,8 @@ public class RoutingPlanController extends ToolbarController
|
|||
private int mFrameHeight;
|
||||
private int mToolbarHeight;
|
||||
private boolean mOpen;
|
||||
private boolean mAltitudeChartShown;
|
||||
@Nullable
|
||||
private UberInfo mUberInfo;
|
||||
|
||||
@Nullable
|
||||
private UberInfo.Product mUberProduct;
|
||||
|
@ -218,7 +222,6 @@ public class RoutingPlanController extends ToolbarController
|
|||
|
||||
UiUtils.hide(mUberFrame);
|
||||
UiUtils.show(mAltitudeChartFrame);
|
||||
mAltitudeChartShown = true;
|
||||
showRoutingDetails();
|
||||
}
|
||||
|
||||
|
@ -252,7 +255,6 @@ public class RoutingPlanController extends ToolbarController
|
|||
return;
|
||||
|
||||
UiUtils.hide(mAltitudeChartFrame);
|
||||
mAltitudeChartShown = false;
|
||||
}
|
||||
|
||||
public void updateBuildProgress(int progress, @Framework.RouterType int router)
|
||||
|
@ -393,7 +395,7 @@ public class RoutingPlanController extends ToolbarController
|
|||
//TOOD: show the panel "There is no taxi here"
|
||||
return;
|
||||
}
|
||||
|
||||
mUberInfo = info;
|
||||
mUberProduct = products[0];
|
||||
final PagerAdapter adapter = new UberAdapter(mActivity, products);
|
||||
DotPager pager = new DotPager.Builder(mActivity, (ViewPager) mUberFrame.findViewById(R.id.pager), adapter)
|
||||
|
@ -412,15 +414,20 @@ public class RoutingPlanController extends ToolbarController
|
|||
UiUtils.show(mUberFrame);
|
||||
}
|
||||
|
||||
void saveAltitudeChartState(@NonNull Bundle outState)
|
||||
void saveRoutingPanelState(@NonNull Bundle outState)
|
||||
{
|
||||
outState.putBoolean(STATE_ALTITUDE_CHART_SHOWN, mAltitudeChartShown);
|
||||
outState.putBoolean(STATE_ALTITUDE_CHART_SHOWN, UiUtils.isVisible(mAltitudeChartFrame));
|
||||
outState.putParcelable(STATE_TAXI_INFO, mUberInfo);
|
||||
}
|
||||
|
||||
void restoreAltitudeChartState(@NonNull Bundle state)
|
||||
void restoreRoutingPanelState(@NonNull Bundle state)
|
||||
{
|
||||
if (state.getBoolean(STATE_ALTITUDE_CHART_SHOWN))
|
||||
showRouteAltitudeChart();
|
||||
|
||||
UberInfo info = state.getParcelable(STATE_TAXI_INFO);
|
||||
if (info != null)
|
||||
showUberInfo(info);
|
||||
}
|
||||
|
||||
public void setStartButton()
|
||||
|
@ -453,7 +460,14 @@ public class RoutingPlanController extends ToolbarController
|
|||
@Override
|
||||
public void onClick(View v)
|
||||
{
|
||||
RoutingController.get().start();
|
||||
((MwmActivity)mActivity).closeMenu(Statistics.EventName.ROUTING_START, AlohaHelper.ROUTING_START, new Runnable()
|
||||
{
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
RoutingController.get().start();
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
|
@ -6,7 +6,6 @@ import android.support.annotation.Nullable;
|
|||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.Button;
|
||||
|
||||
import com.mapswithme.maps.Framework;
|
||||
import com.mapswithme.maps.R;
|
||||
|
@ -29,7 +28,7 @@ public class RoutingPlanFragment extends BaseMwmFragment
|
|||
|
||||
Bundle activityState = getMwmActivity().getSavedInstanceState();
|
||||
if (activityState != null)
|
||||
restoreAltitudeChartState(activityState);
|
||||
restoreRoutingPanelState(activityState);
|
||||
|
||||
return res;
|
||||
}
|
||||
|
@ -66,13 +65,13 @@ public class RoutingPlanFragment extends BaseMwmFragment
|
|||
mPlanController.setStartButton();
|
||||
}
|
||||
|
||||
public void restoreAltitudeChartState(@NonNull Bundle state)
|
||||
public void restoreRoutingPanelState(@NonNull Bundle state)
|
||||
{
|
||||
mPlanController.restoreAltitudeChartState(state);
|
||||
mPlanController.restoreRoutingPanelState(state);
|
||||
}
|
||||
|
||||
public void saveAltitudeChartState(@NonNull Bundle outState)
|
||||
public void saveRoutingPanelState(@NonNull Bundle outState)
|
||||
{
|
||||
mPlanController.saveAltitudeChartState(outState);
|
||||
mPlanController.saveRoutingPanelState(outState);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -55,7 +55,7 @@ public class RoutingPlanInplaceController extends RoutingPlanController
|
|||
public void onSaveState(@NonNull Bundle outState)
|
||||
{
|
||||
outState.putBoolean(STATE_OPEN, isOpen());
|
||||
saveAltitudeChartState(outState);
|
||||
saveRoutingPanelState(outState);
|
||||
}
|
||||
|
||||
public void restoreState(@NonNull Bundle state)
|
||||
|
@ -63,7 +63,7 @@ public class RoutingPlanInplaceController extends RoutingPlanController
|
|||
if (state.containsKey(STATE_OPEN))
|
||||
mSlotsRestoredState = state.getBoolean(STATE_OPEN);
|
||||
|
||||
restoreAltitudeChartState(state);
|
||||
restoreRoutingPanelState(state);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
Loading…
Add table
Reference in a new issue