1 /* 2 * Copyright (C) 2017 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.views; 17 18 import android.content.Context; 19 import android.util.AttributeSet; 20 import android.view.View; 21 import android.widget.RelativeLayout; 22 23 /** 24 * Container to show work footer in all-apps. 25 */ 26 public class WorkFooterContainer extends RelativeLayout { 27 WorkFooterContainer(Context context)28 public WorkFooterContainer(Context context) { 29 super(context); 30 } 31 WorkFooterContainer(Context context, AttributeSet attrs)32 public WorkFooterContainer(Context context, AttributeSet attrs) { 33 super(context, attrs); 34 } 35 WorkFooterContainer(Context context, AttributeSet attrs, int defStyleAttr)36 public WorkFooterContainer(Context context, AttributeSet attrs, int defStyleAttr) { 37 super(context, attrs, defStyleAttr); 38 } 39 40 @Override onLayout(boolean changed, int l, int t, int r, int b)41 protected void onLayout(boolean changed, int l, int t, int r, int b) { 42 super.onLayout(changed, l, t, r, b); 43 updateTranslation(); 44 } 45 46 @Override offsetTopAndBottom(int offset)47 public void offsetTopAndBottom(int offset) { 48 super.offsetTopAndBottom(offset); 49 updateTranslation(); 50 } 51 updateTranslation()52 private void updateTranslation() { 53 if (getParent() instanceof View) { 54 View parent = (View) getParent(); 55 int availableBot = parent.getHeight() - parent.getPaddingBottom(); 56 setTranslationY(Math.max(0, availableBot - getBottom())); 57 } 58 } 59 } 60