From 78ba036df76d84b04a77d3c9a46f1720871cafeb Mon Sep 17 00:00:00 2001 From: Catfriend1 Date: Sun, 27 Jan 2019 19:22:39 +0100 Subject: [PATCH] Save welcome wizard button state on screen rotation (fixes #281) (#283) * Save welcome wizard button state (fixes #281) * FirstStartActivity xml: Disallow focus for non-button elements * Fix ViewPager taking focus on mouse click glitch on TV * Provide key navigation if ViewPager accidentially took focus (fixes #281) --- .../activities/FirstStartActivity.java | 25 +++++++++++++++++++ .../main/res/layout/activity_first_start.xml | 9 ++++--- 2 files changed, 31 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/com/nutomic/syncthingandroid/activities/FirstStartActivity.java b/app/src/main/java/com/nutomic/syncthingandroid/activities/FirstStartActivity.java index 4ac3baec..b001fc6c 100644 --- a/app/src/main/java/com/nutomic/syncthingandroid/activities/FirstStartActivity.java +++ b/app/src/main/java/com/nutomic/syncthingandroid/activities/FirstStartActivity.java @@ -198,6 +198,30 @@ public class FirstStartActivity extends AppCompatActivity { onBtnNextClick(); } }); + + if (mRunningOnTV) { + mNextButton.setFocusableInTouchMode(true); + } + if (savedInstanceState != null) { + mBackButton.setVisibility(savedInstanceState.getBoolean("mBackButton") ? View.VISIBLE : View.GONE); + mNextButton.setVisibility(savedInstanceState.getBoolean("mNextButton") ? View.VISIBLE : View.GONE); + } + if (mNextButton.getVisibility() == View.VISIBLE) { + mNextButton.requestFocus(); + } else if (mBackButton.getVisibility() == View.VISIBLE) { + mBackButton.requestFocus(); + } + } + + /** + * Saves current tab index and fragment states. + */ + @Override + protected void onSaveInstanceState(Bundle outState) { + super.onSaveInstanceState(outState); + + outState.putBoolean("mBackButton", mBackButton.getVisibility() == View.VISIBLE); + outState.putBoolean("mNextButton", mNextButton.getVisibility() == View.VISIBLE); } public void onBtnBackClick() { @@ -207,6 +231,7 @@ public class FirstStartActivity extends AppCompatActivity { mViewPager.setCurrentItem(current); if (current == 0) { mBackButton.setVisibility(View.GONE); + mNextButton.requestFocus(); } } } diff --git a/app/src/main/res/layout/activity_first_start.xml b/app/src/main/res/layout/activity_first_start.xml index 7a078cf1..17146c54 100644 --- a/app/src/main/res/layout/activity_first_start.xml +++ b/app/src/main/res/layout/activity_first_start.xml @@ -10,10 +10,13 @@ + android:layout_height="match_parent" + android:nextFocusLeft="@+id/btn_back" + android:nextFocusRight="@+id/btn_next" /> -