Merge "Fix default constructor for DisplayAdjustments" into rvc-dev
This commit is contained in:
@@ -16,6 +16,8 @@
|
||||
|
||||
package android.view;
|
||||
|
||||
import android.annotation.NonNull;
|
||||
import android.annotation.Nullable;
|
||||
import android.compat.annotation.UnsupportedAppUsage;
|
||||
import android.content.res.CompatibilityInfo;
|
||||
import android.content.res.Configuration;
|
||||
@@ -27,25 +29,25 @@ public class DisplayAdjustments {
|
||||
public static final DisplayAdjustments DEFAULT_DISPLAY_ADJUSTMENTS = new DisplayAdjustments();
|
||||
|
||||
private volatile CompatibilityInfo mCompatInfo = CompatibilityInfo.DEFAULT_COMPATIBILITY_INFO;
|
||||
private Configuration mConfiguration;
|
||||
private final Configuration mConfiguration = new Configuration(Configuration.EMPTY);
|
||||
|
||||
@UnsupportedAppUsage
|
||||
public DisplayAdjustments() {
|
||||
}
|
||||
|
||||
public DisplayAdjustments(Configuration configuration) {
|
||||
mConfiguration = new Configuration(configuration != null
|
||||
? configuration : Configuration.EMPTY);
|
||||
public DisplayAdjustments(@Nullable Configuration configuration) {
|
||||
if (configuration != null) {
|
||||
mConfiguration.setTo(configuration);
|
||||
}
|
||||
}
|
||||
|
||||
public DisplayAdjustments(DisplayAdjustments daj) {
|
||||
public DisplayAdjustments(@NonNull DisplayAdjustments daj) {
|
||||
setCompatibilityInfo(daj.mCompatInfo);
|
||||
mConfiguration = new Configuration(daj.mConfiguration != null
|
||||
? daj.mConfiguration : Configuration.EMPTY);
|
||||
mConfiguration.setTo(daj.getConfiguration());
|
||||
}
|
||||
|
||||
@UnsupportedAppUsage
|
||||
public void setCompatibilityInfo(CompatibilityInfo compatInfo) {
|
||||
public void setCompatibilityInfo(@Nullable CompatibilityInfo compatInfo) {
|
||||
if (this == DEFAULT_DISPLAY_ADJUSTMENTS) {
|
||||
throw new IllegalArgumentException(
|
||||
"setCompatbilityInfo: Cannot modify DEFAULT_DISPLAY_ADJUSTMENTS");
|
||||
@@ -62,7 +64,13 @@ public class DisplayAdjustments {
|
||||
return mCompatInfo;
|
||||
}
|
||||
|
||||
public void setConfiguration(Configuration configuration) {
|
||||
/**
|
||||
* Updates the configuration for the DisplayAdjustments with new configuration.
|
||||
* Default to EMPTY configuration if new configuration is {@code null}
|
||||
* @param configuration new configuration
|
||||
* @throws IllegalArgumentException if trying to modify DEFAULT_DISPLAY_ADJUSTMENTS
|
||||
*/
|
||||
public void setConfiguration(@Nullable Configuration configuration) {
|
||||
if (this == DEFAULT_DISPLAY_ADJUSTMENTS) {
|
||||
throw new IllegalArgumentException(
|
||||
"setConfiguration: Cannot modify DEFAULT_DISPLAY_ADJUSTMENTS");
|
||||
@@ -71,6 +79,7 @@ public class DisplayAdjustments {
|
||||
}
|
||||
|
||||
@UnsupportedAppUsage
|
||||
@NonNull
|
||||
public Configuration getConfiguration() {
|
||||
return mConfiguration;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,70 @@
|
||||
/*
|
||||
* Copyright (C) 2020 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package android.view;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
import android.content.res.Configuration;
|
||||
|
||||
import androidx.test.ext.junit.runners.AndroidJUnit4;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
/**
|
||||
* Tests for {@link DisplayAdjustmentsTests}.
|
||||
*
|
||||
* <p>Build/Install/Run:
|
||||
* atest FrameworksCoreTests:DisplayAdjustmentsTests
|
||||
*/
|
||||
@RunWith(AndroidJUnit4.class)
|
||||
public class DisplayAdjustmentsTests {
|
||||
|
||||
@Test
|
||||
public void testDefaultConstructor_hasEmptyConfiguration() {
|
||||
DisplayAdjustments emptyAdjustments = new DisplayAdjustments();
|
||||
|
||||
assertEquals(Configuration.EMPTY, emptyAdjustments.getConfiguration());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConfigurationConstructor_nullConfigurationBecomesEmpty() {
|
||||
DisplayAdjustments emptyAdjustments = new DisplayAdjustments((Configuration) null);
|
||||
|
||||
assertEquals(Configuration.EMPTY, emptyAdjustments.getConfiguration());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConfigurationConstructor_copiesConfiguration() {
|
||||
Configuration configuration = new Configuration();
|
||||
configuration.colorMode = 1000;
|
||||
DisplayAdjustments adjustments = new DisplayAdjustments(configuration);
|
||||
|
||||
assertEquals(configuration, adjustments.getConfiguration());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDisplayAdjustmentsConstructor_copiesConfiguration() {
|
||||
Configuration configuration = new Configuration();
|
||||
configuration.colorMode = 1000;
|
||||
DisplayAdjustments oldAdjustments = new DisplayAdjustments(configuration);
|
||||
|
||||
DisplayAdjustments newAdjustments = new DisplayAdjustments(oldAdjustments);
|
||||
|
||||
assertEquals(configuration, newAdjustments.getConfiguration());
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user