diff options
| author | Menny Even Danan <menny@evendanan.net> | 2016-02-27 04:17:44 +0000 |
|---|---|---|
| committer | Menny Even Danan <menny@evendanan.net> | 2016-02-27 04:27:38 +0000 |
| commit | bab429a5f7085fd659fb4f63b99bad8aec92386d (patch) | |
| tree | 669d3eeb52203b60f7722b7b22247b9015f30de7 /src | |
| parent | 82fb5e75fec76a50ad51bd6a896b5113dd03b2bb (diff) | |
| download | AnySoftKeyboard-bab429a5f7085fd659fb4f63b99bad8aec92386d.tar.gz AnySoftKeyboard-bab429a5f7085fd659fb4f63b99bad8aec92386d.tar.bz2 | |
adding permissions step for tablets. #574
Diffstat (limited to 'src')
| -rw-r--r-- | src/main/java/com/anysoftkeyboard/ui/settings/setup/SetUpKeyboardWizardFragment.java | 32 | ||||
| -rw-r--r-- | src/main/res/layout-w600dp/keyboard_setup_wizard_layout.xml | 60 |
2 files changed, 62 insertions, 30 deletions
diff --git a/src/main/java/com/anysoftkeyboard/ui/settings/setup/SetUpKeyboardWizardFragment.java b/src/main/java/com/anysoftkeyboard/ui/settings/setup/SetUpKeyboardWizardFragment.java index c421888fa..0082208ce 100644 --- a/src/main/java/com/anysoftkeyboard/ui/settings/setup/SetUpKeyboardWizardFragment.java +++ b/src/main/java/com/anysoftkeyboard/ui/settings/setup/SetUpKeyboardWizardFragment.java @@ -11,11 +11,12 @@ import android.support.v4.app.Fragment; import android.support.v4.app.FragmentActivity; import android.support.v4.app.FragmentManager; import android.support.v4.app.FragmentPagerAdapter; -import android.support.v4.view.PagerAdapter; +import android.support.v4.app.FragmentTransaction; import android.support.v4.view.ViewPager; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; +import android.widget.LinearLayout; import android.widget.RelativeLayout; import com.menny.android.anysoftkeyboard.R; @@ -31,6 +32,7 @@ import java.lang.ref.WeakReference; * -) under Marshmallow, we'll also show Permissions */ public class SetUpKeyboardWizardFragment extends Fragment { + private static class WizardHandler extends Handler { private final WeakReference<SetUpKeyboardWizardFragment> mWeakFragment; @@ -138,22 +140,31 @@ public class SetUpKeyboardWizardFragment extends Fragment { @Override public void onViewCreated(View view, Bundle savedInstanceState) { super.onViewCreated(view, savedInstanceState); + WizardPagesAdapter wizardPagesAdapter = new WizardPagesAdapter(getChildFragmentManager()); mFullIndicator = view.findViewById(R.id.selected_page_indicator); mWizardPager = (ViewPager) view.findViewById(R.id.wizard_pages_pager); if (mWizardPager == null/*meaning, this is a tablet - showing all fragments*/) { + ((LinearLayout) view.findViewById(R.id.steps_container)).setWeightSum(wizardPagesAdapter.getCount()); if (savedInstanceState == null) { //I to prevent leaks and duplicate ID errors, I must use the getChildFragmentManager //to add the inner fragments into the UI. //See: https://github.com/AnySoftKeyboard/AnySoftKeyboard/issues/285 FragmentManager fragmentManager = getChildFragmentManager(); - fragmentManager.beginTransaction() - .replace(R.id.wizard_step_one, new WizardPageEnableKeyboardFragment()) - .replace(R.id.wizard_step_two, new WizardPageSwitchToKeyboardFragment()) - .replace(R.id.wizard_step_three, new WizardPageDoneAndMoreSettingsFragment()) - .commit(); + FragmentTransaction transaction = fragmentManager.beginTransaction(); + transaction.replace(R.id.wizard_step_one, wizardPagesAdapter.getItem(0)); + transaction.replace(R.id.wizard_step_two, wizardPagesAdapter.getItem(1)); + if (wizardPagesAdapter.getCount() == 4) { + view.findViewById(R.id.wizard_step_permissions_card).setVisibility(View.VISIBLE); + transaction.replace(R.id.wizard_step_permissions, wizardPagesAdapter.getItem(2)); + transaction.replace(R.id.wizard_step_three, wizardPagesAdapter.getItem(3)); + } else { + view.findViewById(R.id.wizard_step_permissions_card).setVisibility(View.GONE); + transaction.replace(R.id.wizard_step_three, wizardPagesAdapter.getItem(2)); + } + transaction.commit(); } } else { - mWizardPager.setAdapter(new WizardPagesAdapter(getChildFragmentManager())); + mWizardPager.setAdapter(wizardPagesAdapter); mWizardPager.addOnPageChangeListener(onPageChangedListener); } } @@ -182,6 +193,7 @@ public class SetUpKeyboardWizardFragment extends Fragment { FragmentManager fragmentManager = getChildFragmentManager(); refreshFragmentUi(fragmentManager, R.id.wizard_step_one); refreshFragmentUi(fragmentManager, R.id.wizard_step_two); + refreshFragmentUi(fragmentManager, R.id.wizard_step_permissions); refreshFragmentUi(fragmentManager, R.id.wizard_step_three); } else { mWizardPager.getAdapter().notifyDataSetChanged(); @@ -191,19 +203,19 @@ public class SetUpKeyboardWizardFragment extends Fragment { private void refreshFragmentUi(FragmentManager fragmentManager, int layoutId) { Fragment step = fragmentManager.findFragmentById(layoutId); - if (step != null && step instanceof WizardPageBaseFragment) { + if (step instanceof WizardPageBaseFragment) { ((WizardPageBaseFragment) step).refreshFragmentUi(); } } private void scrollToPageRequiresSetup() { if (mWizardPager == null/*meaning, this is a tablet - showing all fragments*/ || - mWizardPager.getAdapter() == null) return; + mWizardPager.getAdapter() == null) return; FragmentPagerAdapter adapter = (FragmentPagerAdapter) mWizardPager.getAdapter(); int fragmentIndex = 0; - for (; fragmentIndex<adapter.getCount();fragmentIndex++) { + for (; fragmentIndex < adapter.getCount(); fragmentIndex++) { WizardPageBaseFragment wizardPageBaseFragment = (WizardPageBaseFragment) adapter.getItem(fragmentIndex); if (!wizardPageBaseFragment.isStepCompleted()) break; } diff --git a/src/main/res/layout-w600dp/keyboard_setup_wizard_layout.xml b/src/main/res/layout-w600dp/keyboard_setup_wizard_layout.xml index c11405075..4e3901d4a 100644 --- a/src/main/res/layout-w600dp/keyboard_setup_wizard_layout.xml +++ b/src/main/res/layout-w600dp/keyboard_setup_wizard_layout.xml @@ -3,15 +3,16 @@ <!-- I'm ignoring InconsistentLayout because we have different elements for tablet and phone --> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" - xmlns:tools="http://schemas.android.com/tools" - tools:ignore="InconsistentLayout" - android:orientation="horizontal" - android:layout_width="match_parent" - android:layout_height="match_parent" - android:weightSum="3" - android:layout_gravity="center" - android:paddingTop="24dp" - android:baselineAligned="false"> + xmlns:tools="http://schemas.android.com/tools" + android:id="@+id/steps_container" + tools:ignore="InconsistentLayout" + android:orientation="horizontal" + android:layout_width="match_parent" + android:layout_height="match_parent" + android:weightSum="3" + android:layout_gravity="center" + android:paddingTop="24dp" + android:baselineAligned="false"> <LinearLayout style="@style/Ask.Card" @@ -27,17 +28,12 @@ android:layout_height="wrap_content" android:gravity="center_horizontal" android:layout_marginBottom="8dp" - android:text="@string/setup_wizard_step_one" /> + android:text="@string/setup_wizard_step_one"/> - <!-- - replaced - android:name="com.anysoftkeyboard.ui.settings.setup.WizardPageEnableKeyboardFragment" - tools:layout="@layout/keyboard_setup_wizard_page_enable_layout" - --> <FrameLayout android:id="@+id/wizard_step_one" android:layout_width="match_parent" - android:layout_height="wrap_content" /> + android:layout_height="wrap_content"/> </LinearLayout> @@ -55,7 +51,7 @@ android:layout_height="wrap_content" android:gravity="center_horizontal" android:layout_marginBottom="8dp" - android:text="@string/setup_wizard_step_two" /> + android:text="@string/setup_wizard_step_two"/> <!-- replaces android:name="com.anysoftkeyboard.ui.settings.setup.WizardPageSwitchToKeyboardFragment" @@ -64,7 +60,31 @@ <FrameLayout android:id="@+id/wizard_step_two" android:layout_width="match_parent" - android:layout_height="wrap_content" /> + android:layout_height="wrap_content"/> + + </LinearLayout> + + <LinearLayout + style="@style/Ask.Card" + android:id="@+id/wizard_step_permissions_card" + android:layout_width="0px" + android:layout_weight="1" + android:layout_margin="12dp" + android:layout_height="wrap_content" + android:orientation="vertical"> + + <TextView + style="@style/Ask.Text.SubTitle" + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:gravity="center_horizontal" + android:layout_marginBottom="8dp" + android:text="@string/setup_wizard_step_permissions_title"/> + + <FrameLayout + android:id="@+id/wizard_step_permissions" + android:layout_width="match_parent" + android:layout_height="wrap_content"/> </LinearLayout> @@ -82,7 +102,7 @@ android:layout_height="wrap_content" android:gravity="center_horizontal" android:layout_marginBottom="8dp" - android:text="@string/setup_wizard_step_three" /> + android:text="@string/setup_wizard_step_three"/> <!-- replaces android:name="com.anysoftkeyboard.ui.settings.setup.WizardPageDoneAndMoreSettingsFragment" @@ -91,7 +111,7 @@ <FrameLayout android:id="@+id/wizard_step_three" android:layout_width="match_parent" - android:layout_height="wrap_content" /> + android:layout_height="wrap_content"/> </LinearLayout> |
