148 lines
		
	
	
		
			5.4 KiB
		
	
	
	
		
			Java
		
	
	
	
	
	
			
		
		
	
	
			148 lines
		
	
	
		
			5.4 KiB
		
	
	
	
		
			Java
		
	
	
	
	
	
| package androidx.constraintlayout.widget;
 | |
| 
 | |
| import android.content.Context;
 | |
| import android.content.res.TypedArray;
 | |
| import android.graphics.Canvas;
 | |
| import android.graphics.Paint;
 | |
| import android.graphics.Rect;
 | |
| import android.graphics.Typeface;
 | |
| import android.util.AttributeSet;
 | |
| import android.view.View;
 | |
| import androidx.constraintlayout.core.widgets.ConstraintWidget;
 | |
| import androidx.constraintlayout.widget.ConstraintLayout;
 | |
| 
 | |
| /* loaded from: classes.dex */
 | |
| public class Placeholder extends View {
 | |
|     private View mContent;
 | |
|     private int mContentId;
 | |
|     private int mEmptyVisibility;
 | |
| 
 | |
|     public View getContent() {
 | |
|         return this.mContent;
 | |
|     }
 | |
| 
 | |
|     public int getEmptyVisibility() {
 | |
|         return this.mEmptyVisibility;
 | |
|     }
 | |
| 
 | |
|     public void setEmptyVisibility(int visibility) {
 | |
|         this.mEmptyVisibility = visibility;
 | |
|     }
 | |
| 
 | |
|     public Placeholder(Context context) {
 | |
|         super(context);
 | |
|         this.mContentId = -1;
 | |
|         this.mContent = null;
 | |
|         this.mEmptyVisibility = 4;
 | |
|         init(null);
 | |
|     }
 | |
| 
 | |
|     public Placeholder(Context context, AttributeSet attrs) {
 | |
|         super(context, attrs);
 | |
|         this.mContentId = -1;
 | |
|         this.mContent = null;
 | |
|         this.mEmptyVisibility = 4;
 | |
|         init(attrs);
 | |
|     }
 | |
| 
 | |
|     public Placeholder(Context context, AttributeSet attrs, int defStyleAttr) {
 | |
|         super(context, attrs, defStyleAttr);
 | |
|         this.mContentId = -1;
 | |
|         this.mContent = null;
 | |
|         this.mEmptyVisibility = 4;
 | |
|         init(attrs);
 | |
|     }
 | |
| 
 | |
|     public Placeholder(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
 | |
|         super(context, attrs, defStyleAttr);
 | |
|         this.mContentId = -1;
 | |
|         this.mContent = null;
 | |
|         this.mEmptyVisibility = 4;
 | |
|         init(attrs);
 | |
|     }
 | |
| 
 | |
|     private void init(AttributeSet attrs) {
 | |
|         super.setVisibility(this.mEmptyVisibility);
 | |
|         this.mContentId = -1;
 | |
|         if (attrs != null) {
 | |
|             TypedArray obtainStyledAttributes = getContext().obtainStyledAttributes(attrs, R.styleable.ConstraintLayout_placeholder);
 | |
|             int indexCount = obtainStyledAttributes.getIndexCount();
 | |
|             for (int i = 0; i < indexCount; i++) {
 | |
|                 int index = obtainStyledAttributes.getIndex(i);
 | |
|                 if (index == R.styleable.ConstraintLayout_placeholder_content) {
 | |
|                     this.mContentId = obtainStyledAttributes.getResourceId(index, this.mContentId);
 | |
|                 } else if (index == R.styleable.ConstraintLayout_placeholder_placeholder_emptyVisibility) {
 | |
|                     this.mEmptyVisibility = obtainStyledAttributes.getInt(index, this.mEmptyVisibility);
 | |
|                 }
 | |
|             }
 | |
|             obtainStyledAttributes.recycle();
 | |
|         }
 | |
|     }
 | |
| 
 | |
|     @Override // android.view.View
 | |
|     public void onDraw(Canvas canvas) {
 | |
|         if (isInEditMode()) {
 | |
|             canvas.drawRGB(223, 223, 223);
 | |
|             Paint paint = new Paint();
 | |
|             paint.setARGB(255, 210, 210, 210);
 | |
|             paint.setTextAlign(Paint.Align.CENTER);
 | |
|             paint.setTypeface(Typeface.create(Typeface.DEFAULT, 0));
 | |
|             Rect rect = new Rect();
 | |
|             canvas.getClipBounds(rect);
 | |
|             paint.setTextSize(rect.height());
 | |
|             int height = rect.height();
 | |
|             int width = rect.width();
 | |
|             paint.setTextAlign(Paint.Align.LEFT);
 | |
|             paint.getTextBounds("?", 0, 1, rect);
 | |
|             canvas.drawText("?", ((width / 2.0f) - (rect.width() / 2.0f)) - rect.left, ((height / 2.0f) + (rect.height() / 2.0f)) - rect.bottom, paint);
 | |
|         }
 | |
|     }
 | |
| 
 | |
|     public void updatePreLayout(ConstraintLayout container) {
 | |
|         if (this.mContentId == -1 && !isInEditMode()) {
 | |
|             setVisibility(this.mEmptyVisibility);
 | |
|         }
 | |
|         View findViewById = container.findViewById(this.mContentId);
 | |
|         this.mContent = findViewById;
 | |
|         if (findViewById != null) {
 | |
|             ((ConstraintLayout.LayoutParams) findViewById.getLayoutParams()).isInPlaceholder = true;
 | |
|             this.mContent.setVisibility(0);
 | |
|             setVisibility(0);
 | |
|         }
 | |
|     }
 | |
| 
 | |
|     public void setContentId(int id) {
 | |
|         View findViewById;
 | |
|         if (this.mContentId == id) {
 | |
|             return;
 | |
|         }
 | |
|         View view = this.mContent;
 | |
|         if (view != null) {
 | |
|             view.setVisibility(0);
 | |
|             ((ConstraintLayout.LayoutParams) this.mContent.getLayoutParams()).isInPlaceholder = false;
 | |
|             this.mContent = null;
 | |
|         }
 | |
|         this.mContentId = id;
 | |
|         if (id == -1 || (findViewById = ((View) getParent()).findViewById(id)) == null) {
 | |
|             return;
 | |
|         }
 | |
|         findViewById.setVisibility(8);
 | |
|     }
 | |
| 
 | |
|     public void updatePostMeasure(ConstraintLayout container) {
 | |
|         if (this.mContent == null) {
 | |
|             return;
 | |
|         }
 | |
|         ConstraintLayout.LayoutParams layoutParams = (ConstraintLayout.LayoutParams) getLayoutParams();
 | |
|         ConstraintLayout.LayoutParams layoutParams2 = (ConstraintLayout.LayoutParams) this.mContent.getLayoutParams();
 | |
|         layoutParams2.widget.setVisibility(0);
 | |
|         if (layoutParams.widget.getHorizontalDimensionBehaviour() != ConstraintWidget.DimensionBehaviour.FIXED) {
 | |
|             layoutParams.widget.setWidth(layoutParams2.widget.getWidth());
 | |
|         }
 | |
|         if (layoutParams.widget.getVerticalDimensionBehaviour() != ConstraintWidget.DimensionBehaviour.FIXED) {
 | |
|             layoutParams.widget.setHeight(layoutParams2.widget.getHeight());
 | |
|         }
 | |
|         layoutParams2.widget.setVisibility(8);
 | |
|     }
 | |
| }
 |