1 package com.google.android.apps.common.testing.accessibility.framework.replacements; 2 3 import com.google.android.apps.common.testing.accessibility.framework.uielement.proto.AndroidFrameworkProtos.LayoutParamsProto; 4 import org.checkerframework.checker.nullness.qual.Nullable; 5 6 /** 7 * Used as a local immutable replacement for Android's {@link android.view.ViewGroup.LayoutParams} 8 */ 9 public final class LayoutParams { 10 11 /** @see android.view.ViewGroup.LayoutParams#MATCH_PARENT */ 12 public static final int MATCH_PARENT = -1; 13 14 /** @see android.view.ViewGroup.LayoutParams#WRAP_CONTENT */ 15 public static final int WRAP_CONTENT = -2; 16 17 private final int width; 18 19 private final int height; 20 LayoutParams(int width, int height)21 public LayoutParams(int width, int height) { 22 this.width = width; 23 this.height = height; 24 } 25 LayoutParams(LayoutParamsProto layoutParamsProto)26 public LayoutParams(LayoutParamsProto layoutParamsProto) { 27 this(layoutParamsProto.getWidth(), layoutParamsProto.getHeight()); 28 } 29 30 /** @see android.view.ViewGroup.LayoutParams#width */ getWidth()31 public int getWidth() { 32 return width; 33 } 34 35 /** @see android.view.ViewGroup.LayoutParams#height */ getHeight()36 public int getHeight() { 37 return height; 38 } 39 toProto()40 public LayoutParamsProto toProto() { 41 return LayoutParamsProto.newBuilder().setWidth(width).setHeight(height).build(); 42 } 43 44 @Override equals(@ullable Object o)45 public boolean equals(@Nullable Object o) { 46 if (this == o) { 47 return true; 48 } 49 50 if (o instanceof LayoutParams) { 51 LayoutParams params = (LayoutParams) o; 52 return (params.width == width) && (params.height == height); 53 } 54 return false; 55 } 56 57 @Override hashCode()58 public int hashCode() { 59 return 31 * width + height; 60 } 61 62 @Override toString()63 public String toString() { 64 return "LayoutParams(" + width + ", " + height + ")"; 65 } 66 } 67