Home | History | Annotate | Download | only in util
      1 /*
      2  * Copyright (C) 2016 The Android Open Source Project
      3  *
      4  * Licensed under the Apache License, Version 2.0 (the "License");
      5  * you may not use this file except in compliance with the License.
      6  * You may obtain a copy of the License at
      7  *
      8  *      http://www.apache.org/licenses/LICENSE-2.0
      9  *
     10  * Unless required by applicable law or agreed to in writing, software
     11  * distributed under the License is distributed on an "AS IS" BASIS,
     12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13  * See the License for the specific language governing permissions and
     14  * limitations under the License.
     15  */
     16 
     17 package com.android.setupwizardlib.util;
     18 
     19 import android.view.View;
     20 
     21 import com.android.setupwizardlib.view.NavigationBar;
     22 
     23 /**
     24  * Add this helper to require the scroll view to be scrolled to the bottom, making sure that the
     25  * user sees all content on the screen. This will change the navigation bar to show the more button
     26  * instead of the next button when there is more content to be seen. When the more button is
     27  * clicked, the scroll view will be scrolled one page down.
     28  */
     29 public abstract class AbstractRequireScrollHelper implements View.OnClickListener {
     30 
     31     private final NavigationBar mNavigationBar;
     32 
     33     private boolean mScrollNeeded;
     34     // Whether the user have seen the more button yet.
     35     private boolean mScrollNotified = false;
     36 
     37     protected AbstractRequireScrollHelper(NavigationBar navigationBar) {
     38         mNavigationBar = navigationBar;
     39     }
     40 
     41     protected void requireScroll() {
     42         mNavigationBar.getMoreButton().setOnClickListener(this);
     43     }
     44 
     45     protected void notifyScrolledToBottom() {
     46         if (mScrollNeeded) {
     47             mNavigationBar.post(new Runnable() {
     48                 @Override
     49                 public void run() {
     50                     mNavigationBar.getNextButton().setVisibility(View.VISIBLE);
     51                     mNavigationBar.getMoreButton().setVisibility(View.GONE);
     52                 }
     53             });
     54             mScrollNeeded = false;
     55             mScrollNotified = true;
     56         }
     57     }
     58 
     59     protected void notifyRequiresScroll() {
     60         if (!mScrollNeeded && !mScrollNotified) {
     61             mNavigationBar.post(new Runnable() {
     62                 @Override
     63                 public void run() {
     64                     mNavigationBar.getNextButton().setVisibility(View.GONE);
     65                     mNavigationBar.getMoreButton().setVisibility(View.VISIBLE);
     66                 }
     67             });
     68             mScrollNeeded = true;
     69         }
     70     }
     71 
     72     @Override
     73     public void onClick(View view) {
     74         pageScrollDown();
     75     }
     76 
     77     protected abstract void pageScrollDown();
     78 }
     79