summaryrefslogtreecommitdiff
path: root/library/main/src
diff options
context:
space:
mode:
authorMaurice Lam <yukl@google.com>2015-05-28 19:36:19 -0700
committerMaurice Lam <yukl@google.com>2015-05-29 15:14:35 -0700
commit2d77e072fed129b34e473c7f77246a2b064fab7d (patch)
tree3fcd5069ce032f599d2ef117923f1ab515332e45 /library/main/src
parentb5c78954c32ef124b5df7ab539d6579cb4506f50 (diff)
downloadsetupwizard-2d77e072fed129b34e473c7f77246a2b064fab7d.tar.gz
[SetupWizardLib] Add support for require scrolling
Add SetupWizardLayout.requireScrollToBottom method that will register a RequireScrollHelper on the layout. When the helper is registered and the content view can scroll, the next button will be hidden and a down-arrow button is shown, which will scroll the page down when clicked. Change-Id: Ib9ddcbeec24169cc00265fe107deb1b5099cba8d
Diffstat (limited to 'library/main/src')
-rw-r--r--library/main/src/com/android/setupwizardlib/SetupWizardLayout.java19
-rw-r--r--library/main/src/com/android/setupwizardlib/util/RequireScrollHelper.java86
-rw-r--r--library/main/src/com/android/setupwizardlib/view/NavigationBar.java6
3 files changed, 111 insertions, 0 deletions
diff --git a/library/main/src/com/android/setupwizardlib/SetupWizardLayout.java b/library/main/src/com/android/setupwizardlib/SetupWizardLayout.java
index a628d9e..60da563 100644
--- a/library/main/src/com/android/setupwizardlib/SetupWizardLayout.java
+++ b/library/main/src/com/android/setupwizardlib/SetupWizardLayout.java
@@ -29,6 +29,7 @@ import android.os.Build.VERSION_CODES;
import android.os.Parcel;
import android.os.Parcelable;
import android.util.AttributeSet;
+import android.util.Log;
import android.util.TypedValue;
import android.view.Gravity;
import android.view.LayoutInflater;
@@ -38,6 +39,8 @@ import android.view.ViewStub;
import android.widget.FrameLayout;
import android.widget.TextView;
+import com.android.setupwizardlib.util.RequireScrollHelper;
+import com.android.setupwizardlib.view.BottomScrollView;
import com.android.setupwizardlib.view.Illustration;
import com.android.setupwizardlib.view.NavigationBar;
@@ -222,6 +225,22 @@ public class SetupWizardLayout extends FrameLayout {
return view instanceof NavigationBar ? (NavigationBar) view : null;
}
+ private BottomScrollView getScrollView() {
+ final View view = findViewById(R.id.suw_bottom_scroll_view);
+ return view instanceof BottomScrollView ? (BottomScrollView) view : null;
+ }
+
+ public void requireScrollToBottom() {
+ final NavigationBar navigationBar = getNavigationBar();
+ final BottomScrollView scrollView = getScrollView();
+ if (navigationBar != null && scrollView != null) {
+ RequireScrollHelper.requireScroll(navigationBar, scrollView);
+ } else {
+ Log.e(TAG, "Both suw_layout_navigation_bar and suw_bottom_scroll_view must exist in"
+ + " the template to require scrolling.");
+ }
+ }
+
public void setHeaderText(int title) {
final TextView titleView = (TextView) findViewById(R.id.suw_layout_title);
if (titleView != null) {
diff --git a/library/main/src/com/android/setupwizardlib/util/RequireScrollHelper.java b/library/main/src/com/android/setupwizardlib/util/RequireScrollHelper.java
new file mode 100644
index 0000000..8d796d7
--- /dev/null
+++ b/library/main/src/com/android/setupwizardlib/util/RequireScrollHelper.java
@@ -0,0 +1,86 @@
+/*
+ * Copyright (C) 2015 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.setupwizardlib.util;
+
+import android.view.View;
+import android.widget.ScrollView;
+
+import com.android.setupwizardlib.view.BottomScrollView;
+import com.android.setupwizardlib.view.NavigationBar;
+
+/**
+ * Add this helper to require the scroll view to be scrolled to the bottom, making sure that the
+ * user sees all content on the screen. This will change the navigation bar to show the more button
+ * instead of the next button when there is more content to be seen. When the more button is
+ * clicked, the scroll view will be scrolled one page down.
+ */
+public class RequireScrollHelper implements BottomScrollView.BottomScrollListener,
+ View.OnClickListener {
+
+ /**
+ * Require scrolling on the scrollView, so that if the scrollView has content hidden beneath the
+ * fold, the next button will be hidden and the more button will be shown instead. The more
+ * button will scroll the scrollView downwards when clicked until the bottom is reached.
+ *
+ * @param navigationBar The navigation bar in which the next button's label will be changed.
+ * @param scrollView The {@link BottomScrollView} to be scrolled.
+ */
+ public static RequireScrollHelper requireScroll(NavigationBar navigationBar,
+ BottomScrollView scrollView) {
+ final RequireScrollHelper helper = new RequireScrollHelper(navigationBar, scrollView);
+ helper.requireScroll();
+ return helper;
+ }
+
+ private final BottomScrollView mScrollView;
+ private final NavigationBar mNavigationBar;
+
+ private boolean mScrollNeeded;
+
+ private RequireScrollHelper(NavigationBar navigationBar, BottomScrollView scrollView) {
+ mNavigationBar = navigationBar;
+ mScrollView = scrollView;
+ }
+
+ private void requireScroll() {
+ mNavigationBar.getMoreButton().setOnClickListener(this);
+ mScrollView.setBottomScrollListener(this);
+ }
+
+ @Override
+ public void onScrolledToBottom() {
+ if (mScrollNeeded) {
+ mNavigationBar.getNextButton().setVisibility(View.VISIBLE);
+ mNavigationBar.getMoreButton().setVisibility(View.GONE);
+ mScrollNeeded = false;
+ }
+ }
+
+ @Override
+ public void onRequiresScroll() {
+ if (!mScrollNeeded) {
+ mNavigationBar.getNextButton().setVisibility(View.GONE);
+ mNavigationBar.getMoreButton().setVisibility(View.VISIBLE);
+ mScrollNeeded = true;
+ }
+ }
+
+ @Override
+ public void onClick(View view) {
+ mScrollView.pageScroll(ScrollView.FOCUS_DOWN);
+ }
+}
diff --git a/library/main/src/com/android/setupwizardlib/view/NavigationBar.java b/library/main/src/com/android/setupwizardlib/view/NavigationBar.java
index bc06976..d2bef6c 100644
--- a/library/main/src/com/android/setupwizardlib/view/NavigationBar.java
+++ b/library/main/src/com/android/setupwizardlib/view/NavigationBar.java
@@ -68,6 +68,7 @@ public class NavigationBar extends LinearLayout implements View.OnClickListener
private Button mNextButton;
private Button mBackButton;
+ private Button mMoreButton;
private NavigationBarListener mListener;
public NavigationBar(Context context) {
@@ -92,6 +93,7 @@ public class NavigationBar extends LinearLayout implements View.OnClickListener
View.inflate(getContext(), R.layout.suw_navbar_view, this);
mNextButton = (Button) findViewById(R.id.suw_navbar_next);
mBackButton = (Button) findViewById(R.id.suw_navbar_back);
+ mMoreButton = (Button) findViewById(R.id.suw_navbar_more);
}
public Button getBackButton() {
@@ -102,6 +104,10 @@ public class NavigationBar extends LinearLayout implements View.OnClickListener
return mNextButton;
}
+ public Button getMoreButton() {
+ return mMoreButton;
+ }
+
public void setNavigationBarListener(NavigationBarListener listener) {
mListener = listener;
if (mListener != null) {