From 2a4229fe1106bf3ebc1eb18385f91836848c4204 Mon Sep 17 00:00:00 2001 From: Vladimir Jovanovic Date: Thu, 26 Jan 2017 15:34:04 +0100 Subject: [PATCH] Position saved onSaveState in FragmentCurve Readme fix --- README.md | 6 ++---- .../lemniscate/sample/FragmentCurve.java | 18 +++++++++++++++--- 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 9c5ad66..308b681 100644 --- a/README.md +++ b/README.md @@ -1,10 +1,8 @@ ![Lemniscate header](http://i.imgur.com/i9t5vUm.png) -[![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://github.com/vlad1m1r990/Lemniscate/blob/master/LICENSE) -[![](https://jitpack.io/v/vlad1m1r990/Lemniscate.svg)](https://jitpack.io/#vlad1m1r990/Lemniscate) -[![API](https://img.shields.io/badge/API-11%2B-green.svg?style=flat)](https://android-arsenal.com/api?level-11) -[![Android Arsenal](https://img.shields.io/badge/Android%20Arsenal-Lemniscate-green.svg?style=flat)](https://android-arsenal.com/details/1/5142) +[![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://github.com/vlad1m1r990/Lemniscate/blob/master/LICENSE) [![](https://jitpack.io/v/vlad1m1r990/Lemniscate.svg)](https://jitpack.io/#vlad1m1r990/Lemniscate) [![API](https://img.shields.io/badge/API-11%2B-green.svg?style=flat)](https://android-arsenal.com/api?level-11) [![Android Arsenal](https://img.shields.io/badge/Android%20Arsenal-Lemniscate-green.svg?style=flat)](https://android-arsenal.com/details/1/5142) +----- Lemniscate is a library that will help you to make your progress view nice and sleek. diff --git a/sample/src/main/java/com/vlad1m1r/lemniscate/sample/FragmentCurve.java b/sample/src/main/java/com/vlad1m1r/lemniscate/sample/FragmentCurve.java index 4329f9b..2e5f330 100644 --- a/sample/src/main/java/com/vlad1m1r/lemniscate/sample/FragmentCurve.java +++ b/sample/src/main/java/com/vlad1m1r/lemniscate/sample/FragmentCurve.java @@ -25,6 +25,7 @@ public class FragmentCurve extends Fragment { + private static final String KEY_POSITION = "position"; public interface OnViewCreated { void onViewShown(int position, BaseCurveProgressView baseCurveProgressView); @@ -36,7 +37,7 @@ public interface OnViewCreated { private BaseCurveProgressView mBaseCurveProgressView; private TextView mCurveName; - private LinearLayout mLayoutViewholder; + private LinearLayout mLayoutViewHolder; private int mPosition; @@ -50,6 +51,10 @@ public static FragmentCurve getInstance(int position) { @Override public void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); + + if(savedInstanceState != null && savedInstanceState.containsKey(KEY_POSITION)) + mPosition = savedInstanceState.getInt(KEY_POSITION); + if(mBaseCurveProgressView == null) { mBaseCurveProgressView = getViewForPosition(mPosition); mBaseCurveProgressView.setLayoutParams(new LinearLayout.LayoutParams( @@ -64,12 +69,12 @@ public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, ViewGroup root = (ViewGroup) inflater.inflate(R.layout.fragment_curve, container, false); mCurveName = (TextView) root.findViewById(R.id.textCurveName); - mLayoutViewholder = (LinearLayout) root.findViewById(R.id.layoutViewHolder); + mLayoutViewHolder = (LinearLayout) root.findViewById(R.id.layoutViewHolder); if(mBaseCurveProgressView.getParent() != null) { ((ViewGroup) mBaseCurveProgressView.getParent()).removeView(mBaseCurveProgressView); } - mLayoutViewholder.addView(mBaseCurveProgressView); + mLayoutViewHolder.addView(mBaseCurveProgressView); mCurveName.setText(mBaseCurveProgressView.getClass().getSimpleName()); @@ -121,4 +126,11 @@ public int getPosition() { public void setPosition(int position) { this.mPosition = position; } + + + @Override + public void onSaveInstanceState(Bundle outState) { + outState.putInt(KEY_POSITION, mPosition); + super.onSaveInstanceState(outState); + } }