1 /* 2 * Copyright (C) 2023 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.server.autofill.ui; 18 19 import android.content.Context; 20 import android.util.AttributeSet; 21 import android.view.Gravity; 22 import android.view.View; 23 import android.widget.LinearLayout; 24 25 import com.android.internal.R; 26 import com.android.internal.widget.ButtonBarLayout; 27 28 /** An extension of {@link ButtonBarLayout} for use in Autofill bottom sheets. */ 29 public class BottomSheetButtonBarLayout extends ButtonBarLayout { 30 BottomSheetButtonBarLayout(Context context, AttributeSet attrs)31 public BottomSheetButtonBarLayout(Context context, AttributeSet attrs) { 32 super(context, attrs); 33 } 34 35 @Override onMeasure(int widthMeasureSpec, int heightMeasureSpec)36 protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { 37 super.onMeasure(widthMeasureSpec, heightMeasureSpec); 38 39 final View spacer = findViewById(R.id.autofill_button_bar_spacer); 40 if (spacer == null) { 41 return; 42 } 43 if (isStacked()) { 44 spacer.getLayoutParams().width = 0; 45 spacer.getLayoutParams().height = 46 getResources().getDimensionPixelSize(R.dimen.autofill_button_bar_spacer_height); 47 setGravity(Gravity.CENTER_VERTICAL | Gravity.END); 48 } else { 49 spacer.getLayoutParams().width = 50 getResources().getDimensionPixelSize(R.dimen.autofill_button_bar_spacer_width); 51 spacer.getLayoutParams().height = 0; 52 setGravity(Gravity.CENTER_VERTICAL); 53 } 54 } 55 isStacked()56 private boolean isStacked() { 57 return getOrientation() == LinearLayout.VERTICAL; 58 } 59 } 60