| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
package android.view; |
| 18 |
|
| 19 |
import android.annotation.NonNull; |
| 20 |
import android.annotation.Nullable; |
| 21 |
import android.compat.annotation.UnsupportedAppUsage; |
| 22 |
import android.content.res.CompatibilityInfo; |
| 23 |
import android.content.res.Configuration; |
| 24 |
|
| 25 |
import java.util.Objects; |
| 26 |
|
| 27 |
|
| 28 |
public class DisplayAdjustments { |
| 29 |
public static final DisplayAdjustments DEFAULT_DISPLAY_ADJUSTMENTS = new DisplayAdjustments(); |
| 30 |
|
| 31 |
private volatile CompatibilityInfo mCompatInfo = CompatibilityInfo.DEFAULT_COMPATIBILITY_INFO; |
| 32 |
private final Configuration mConfiguration = new Configuration(Configuration.EMPTY); |
| 33 |
|
| 34 |
@UnsupportedAppUsage |
| 35 |
public DisplayAdjustments() { |
| 36 |
} |
| 37 |
|
| 38 |
public DisplayAdjustments(@Nullable Configuration configuration) { |
| 39 |
if (configuration != null) { |
| 40 |
mConfiguration.setTo(configuration); |
| 41 |
} |
| 42 |
} |
| 43 |
|
| 44 |
public DisplayAdjustments(@NonNull DisplayAdjustments daj) { |
| 45 |
setCompatibilityInfo(daj.mCompatInfo); |
| 46 |
mConfiguration.setTo(daj.getConfiguration()); |
| 47 |
} |
| 48 |
|
| 49 |
@UnsupportedAppUsage |
| 50 |
public void setCompatibilityInfo(@Nullable CompatibilityInfo compatInfo) { |
| 51 |
if (this == DEFAULT_DISPLAY_ADJUSTMENTS) { |
| 52 |
throw new IllegalArgumentException( |
| 53 |
"setCompatbilityInfo: Cannot modify DEFAULT_DISPLAY_ADJUSTMENTS"); |
| 54 |
} |
| 55 |
if (compatInfo != null && (compatInfo.isScalingRequired() |
| 56 |
|| !compatInfo.supportsScreen())) { |
| 57 |
mCompatInfo = compatInfo; |
| 58 |
} else { |
| 59 |
mCompatInfo = CompatibilityInfo.DEFAULT_COMPATIBILITY_INFO; |
| 60 |
} |
| 61 |
} |
| 62 |
|
| 63 |
public CompatibilityInfo getCompatibilityInfo() { |
| 64 |
return mCompatInfo; |
| 65 |
} |
| 66 |
|
| 67 |
|
| 68 |
|
| 69 |
|
| 70 |
|
| 71 |
|
| 72 |
|
| 73 |
public void setConfiguration(@Nullable Configuration configuration) { |
| 74 |
if (this == DEFAULT_DISPLAY_ADJUSTMENTS) { |
| 75 |
throw new IllegalArgumentException( |
| 76 |
"setConfiguration: Cannot modify DEFAULT_DISPLAY_ADJUSTMENTS"); |
| 77 |
} |
| 78 |
mConfiguration.setTo(configuration != null ? configuration : Configuration.EMPTY); |
| 79 |
} |
| 80 |
|
| 81 |
@UnsupportedAppUsage |
| 82 |
@NonNull |
| 83 |
public Configuration getConfiguration() { |
| 84 |
return mConfiguration; |
| 85 |
} |
| 86 |
|
| 87 |
@Override |
| 88 |
public int hashCode() { |
| 89 |
int hash = 17; |
| 90 |
hash = hash * 31 + Objects.hashCode(mCompatInfo); |
| 91 |
hash = hash * 31 + Objects.hashCode(mConfiguration); |
| 92 |
return hash; |
| 93 |
} |
| 94 |
|
| 95 |
@Override |
| 96 |
public boolean equals(@Nullable Object o) { |
| 97 |
if (!(o instanceof DisplayAdjustments)) { |
| 98 |
return false; |
| 99 |
} |
| 100 |
DisplayAdjustments daj = (DisplayAdjustments)o; |
| 101 |
return Objects.equals(daj.mCompatInfo, mCompatInfo) |
| 102 |
&& Objects.equals(daj.mConfiguration, mConfiguration); |
| 103 |
} |
| 104 |
} |