Home | History | Annotate | Download | only in pageindicators
      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 package com.android.launcher3.pageindicators;
     17 
     18 import android.content.Context;
     19 import android.graphics.drawable.Drawable;
     20 import android.util.AttributeSet;
     21 import android.widget.FrameLayout;
     22 
     23 import com.android.launcher3.dynamicui.ExtractedColors;
     24 
     25 /**
     26  * Base class for a page indicator.
     27  */
     28 public abstract class PageIndicator extends FrameLayout {
     29     private CaretDrawable mCaretDrawable;
     30 
     31     protected int mNumPages = 1;
     32 
     33     public PageIndicator(Context context, AttributeSet attrs, int defStyleAttr) {
     34         super(context, attrs, defStyleAttr);
     35         setWillNotDraw(false);
     36     }
     37 
     38     public void setScroll(int currentScroll, int totalScroll) {}
     39 
     40     public void setActiveMarker(int activePage) {}
     41 
     42     public void addMarker() {
     43         mNumPages++;
     44         onPageCountChanged();
     45     }
     46 
     47     public void removeMarker() {
     48         mNumPages--;
     49         onPageCountChanged();
     50     }
     51 
     52     public void setMarkersCount(int numMarkers) {
     53         mNumPages = numMarkers;
     54         onPageCountChanged();
     55     }
     56 
     57     public CaretDrawable getCaretDrawable() {
     58         return mCaretDrawable;
     59     }
     60 
     61     public void setCaretDrawable(CaretDrawable caretDrawable) {
     62         if (mCaretDrawable != null) {
     63             mCaretDrawable.setCallback(null);
     64         }
     65 
     66         mCaretDrawable = caretDrawable;
     67 
     68         if (mCaretDrawable != null) {
     69             mCaretDrawable.setCallback(this);
     70         }
     71     }
     72 
     73     protected void onPageCountChanged() {}
     74 
     75     public void setShouldAutoHide(boolean shouldAutoHide) {}
     76 
     77     public void updateColor(ExtractedColors extractedColors) {}
     78 
     79     @Override
     80     protected boolean verifyDrawable(Drawable who) {
     81         return super.verifyDrawable(who) || who == getCaretDrawable();
     82     }
     83 }
     84