1/* 2 * Copyright 2018 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 17package androidx.legacy.widget; 18 19import android.annotation.SuppressLint; 20import android.content.Context; 21import android.graphics.Canvas; 22import android.util.AttributeSet; 23import android.view.View; 24 25import androidx.annotation.NonNull; 26import androidx.annotation.Nullable; 27 28/** 29 * Space is a lightweight {@link View} subclass that may be used to create gaps between components 30 * in general purpose layouts. 31 * 32 * @deprecated Use framework {@link android.widget.Space} class instead. 33 */ 34@Deprecated 35public class Space extends View { 36 37 /** 38 * @deprecated Use framework {@link android.widget.Space} class instead. 39 */ 40 @Deprecated 41 public Space(@NonNull Context context, @Nullable AttributeSet attrs, int defStyle) { 42 super(context, attrs, defStyle); 43 if (getVisibility() == VISIBLE) { 44 setVisibility(INVISIBLE); 45 } 46 } 47 48 /** 49 * @deprecated Use framework {@link android.widget.Space} class instead. 50 */ 51 @Deprecated 52 public Space(@NonNull Context context, @Nullable AttributeSet attrs) { 53 this(context, attrs, 0); 54 } 55 56 /** 57 * @deprecated Use framework {@link android.widget.Space} class instead. 58 */ 59 @Deprecated 60 public Space(@NonNull Context context) { 61 this(context, null); 62 } 63 64 /** 65 * Draw nothing. 66 * 67 * @param canvas an unused parameter. 68 * 69 * @deprecated Use framework {@link android.widget.Space} class instead. 70 */ 71 @Deprecated 72 @Override 73 @SuppressLint("MissingSuperCall") 74 public void draw(Canvas canvas) { 75 } 76 77 /** 78 * Compare to: {@link View#getDefaultSize(int, int)} 79 * If mode is AT_MOST, return the child size instead of the parent size 80 * (unless it is too big). 81 */ 82 private static int getDefaultSize2(int size, int measureSpec) { 83 int result = size; 84 int specMode = MeasureSpec.getMode(measureSpec); 85 int specSize = MeasureSpec.getSize(measureSpec); 86 87 switch (specMode) { 88 case MeasureSpec.UNSPECIFIED: 89 result = size; 90 break; 91 case MeasureSpec.AT_MOST: 92 result = Math.min(size, specSize); 93 break; 94 case MeasureSpec.EXACTLY: 95 result = specSize; 96 break; 97 } 98 return result; 99 } 100 101 /** 102 * @deprecated Use framework {@link android.widget.Space} class instead. 103 */ 104 @Deprecated 105 @Override 106 protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { 107 setMeasuredDimension( 108 getDefaultSize2(getSuggestedMinimumWidth(), widthMeasureSpec), 109 getDefaultSize2(getSuggestedMinimumHeight(), heightMeasureSpec)); 110 } 111}