Home | History | Annotate | Download | only in views
      1 /*
      2  * Copyright (C) 2014 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.systemui.recents.views;
     18 
     19 import android.animation.ObjectAnimator;
     20 import android.content.Context;
     21 import android.util.AttributeSet;
     22 import android.widget.FrameLayout;
     23 import com.android.systemui.recents.RecentsConfiguration;
     24 
     25 
     26 /** The task footer view */
     27 public class TaskViewFooter extends FrameLayout {
     28 
     29     interface TaskFooterViewCallbacks {
     30         public void onTaskFooterHeightChanged(int height, int maxHeight);
     31     }
     32 
     33     RecentsConfiguration mConfig;
     34 
     35     TaskFooterViewCallbacks mCb;
     36     int mFooterHeight;
     37     int mMaxFooterHeight;
     38     ObjectAnimator mFooterAnimator;
     39 
     40     public TaskViewFooter(Context context) {
     41         this(context, null);
     42     }
     43 
     44     public TaskViewFooter(Context context, AttributeSet attrs) {
     45         this(context, attrs, 0);
     46     }
     47 
     48     public TaskViewFooter(Context context, AttributeSet attrs, int defStyleAttr) {
     49         this(context, attrs, defStyleAttr, 0);
     50     }
     51 
     52     public TaskViewFooter(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
     53         super(context, attrs, defStyleAttr, defStyleRes);
     54         mConfig = RecentsConfiguration.getInstance();
     55         mMaxFooterHeight = mConfig.taskViewLockToAppButtonHeight;
     56         setFooterHeight(getFooterHeight());
     57     }
     58 
     59     /** Sets the callbacks for when the footer height changes. */
     60     void setCallbacks(TaskFooterViewCallbacks cb) {
     61         mCb = cb;
     62         mCb.onTaskFooterHeightChanged(mFooterHeight, mMaxFooterHeight);
     63     }
     64 
     65     /** Sets the footer height. */
     66     public void setFooterHeight(int footerHeight) {
     67         if (footerHeight != mFooterHeight) {
     68             mFooterHeight = footerHeight;
     69             mCb.onTaskFooterHeightChanged(footerHeight, mMaxFooterHeight);
     70         }
     71     }
     72 
     73     /** Gets the footer height. */
     74     public int getFooterHeight() {
     75         return mFooterHeight;
     76     }
     77 
     78     /** Animates the footer into and out of view. */
     79     void animateFooterVisibility(final boolean visible, int duration) {
     80         // Return early if there is no footer
     81         if (mMaxFooterHeight <= 0) return;
     82 
     83         // Cancel the previous animation
     84         if (mFooterAnimator != null) {
     85             mFooterAnimator.removeAllListeners();
     86             mFooterAnimator.cancel();
     87         }
     88         int finalHeight = visible ? mMaxFooterHeight : 0;
     89         if (duration > 0) {
     90             mFooterAnimator = ObjectAnimator.ofInt(this, "footerHeight", finalHeight);
     91             mFooterAnimator.setDuration(duration);
     92             mFooterAnimator.setInterpolator(mConfig.fastOutSlowInInterpolator);
     93             mFooterAnimator.start();
     94         } else {
     95             setFooterHeight(finalHeight);
     96         }
     97     }
     98 }
     99