Merge "Describe requested visibilities in public types (6/n: clean up)"
This commit is contained in:
committed by
Android (Google) Code Review
commit
e07a11a59e
@@ -53,7 +53,6 @@ import android.view.IWindowSessionCallback;
|
||||
import android.view.KeyEvent;
|
||||
import android.view.InputEvent;
|
||||
import android.view.InsetsState;
|
||||
import android.view.InsetsVisibilities;
|
||||
import android.view.MagnificationSpec;
|
||||
import android.view.MotionEvent;
|
||||
import android.view.InputChannel;
|
||||
|
||||
@@ -1,19 +0,0 @@
|
||||
/**
|
||||
* Copyright (c) 2021, 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;
|
||||
|
||||
parcelable InsetsVisibilities;
|
||||
@@ -1,134 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2021 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 android.annotation.NonNull;
|
||||
import android.os.Parcel;
|
||||
import android.os.Parcelable;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.StringJoiner;
|
||||
|
||||
/**
|
||||
* A collection of visibilities of insets. This is used for carrying the requested visibilities.
|
||||
* @hide
|
||||
*/
|
||||
public class InsetsVisibilities implements Parcelable {
|
||||
|
||||
private static final int UNSPECIFIED = 0;
|
||||
private static final int VISIBLE = 1;
|
||||
private static final int INVISIBLE = -1;
|
||||
|
||||
private final int[] mVisibilities = new int[InsetsState.SIZE];
|
||||
|
||||
public InsetsVisibilities() {
|
||||
}
|
||||
|
||||
public InsetsVisibilities(InsetsVisibilities other) {
|
||||
set(other);
|
||||
}
|
||||
|
||||
public InsetsVisibilities(Parcel in) {
|
||||
in.readIntArray(mVisibilities);
|
||||
}
|
||||
|
||||
/**
|
||||
* Copies from another {@link InsetsVisibilities}.
|
||||
*
|
||||
* @param other an instance of {@link InsetsVisibilities}.
|
||||
*/
|
||||
public void set(InsetsVisibilities other) {
|
||||
System.arraycopy(other.mVisibilities, InsetsState.FIRST_TYPE, mVisibilities,
|
||||
InsetsState.FIRST_TYPE, InsetsState.SIZE);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets a visibility to a type.
|
||||
*
|
||||
* @param type The {@link @InsetsState.InternalInsetsType}.
|
||||
* @param visible {@code true} represents visible; {@code false} represents invisible.
|
||||
*/
|
||||
public void setVisibility(@InsetsState.InternalInsetsType int type, boolean visible) {
|
||||
mVisibilities[type] = visible ? VISIBLE : INVISIBLE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the specified insets visibility of the type. If it has never been specified,
|
||||
* this returns the default visibility.
|
||||
*
|
||||
* @param type The {@link @InsetsState.InternalInsetsType}.
|
||||
* @return The specified visibility or the default one if it is not specified.
|
||||
*/
|
||||
public boolean getVisibility(@InsetsState.InternalInsetsType int type) {
|
||||
final int visibility = mVisibilities[type];
|
||||
return visibility == UNSPECIFIED
|
||||
? InsetsState.getDefaultVisibility(type)
|
||||
: visibility == VISIBLE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
StringJoiner joiner = new StringJoiner(", ");
|
||||
for (int type = InsetsState.FIRST_TYPE; type <= InsetsState.LAST_TYPE; type++) {
|
||||
final int visibility = mVisibilities[type];
|
||||
if (visibility != UNSPECIFIED) {
|
||||
joiner.add(InsetsState.typeToString(type) + ": "
|
||||
+ (visibility == VISIBLE ? "visible" : "invisible"));
|
||||
}
|
||||
}
|
||||
return joiner.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Arrays.hashCode(mVisibilities);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object other) {
|
||||
if (!(other instanceof InsetsVisibilities)) {
|
||||
return false;
|
||||
}
|
||||
return Arrays.equals(mVisibilities, ((InsetsVisibilities) other).mVisibilities);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int describeContents() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToParcel(Parcel dest, int flags) {
|
||||
dest.writeIntArray(mVisibilities);
|
||||
}
|
||||
|
||||
public void readFromParcel(@NonNull Parcel in) {
|
||||
in.readIntArray(mVisibilities);
|
||||
}
|
||||
|
||||
public static final @NonNull Creator<InsetsVisibilities> CREATOR =
|
||||
new Creator<InsetsVisibilities>() {
|
||||
|
||||
public InsetsVisibilities createFromParcel(Parcel in) {
|
||||
return new InsetsVisibilities(in);
|
||||
}
|
||||
|
||||
public InsetsVisibilities[] newArray(int size) {
|
||||
return new InsetsVisibilities[size];
|
||||
}
|
||||
};
|
||||
}
|
||||
@@ -1493,37 +1493,37 @@ public final class WindowInsets {
|
||||
public static String toString(@InsetsType int types) {
|
||||
StringBuilder result = new StringBuilder();
|
||||
if ((types & STATUS_BARS) != 0) {
|
||||
result.append("statusBars |");
|
||||
result.append("statusBars ");
|
||||
}
|
||||
if ((types & NAVIGATION_BARS) != 0) {
|
||||
result.append("navigationBars |");
|
||||
result.append("navigationBars ");
|
||||
}
|
||||
if ((types & CAPTION_BAR) != 0) {
|
||||
result.append("captionBar |");
|
||||
result.append("captionBar ");
|
||||
}
|
||||
if ((types & IME) != 0) {
|
||||
result.append("ime |");
|
||||
result.append("ime ");
|
||||
}
|
||||
if ((types & SYSTEM_GESTURES) != 0) {
|
||||
result.append("systemGestures |");
|
||||
result.append("systemGestures ");
|
||||
}
|
||||
if ((types & MANDATORY_SYSTEM_GESTURES) != 0) {
|
||||
result.append("mandatorySystemGestures |");
|
||||
result.append("mandatorySystemGestures ");
|
||||
}
|
||||
if ((types & TAPPABLE_ELEMENT) != 0) {
|
||||
result.append("tappableElement |");
|
||||
result.append("tappableElement ");
|
||||
}
|
||||
if ((types & DISPLAY_CUTOUT) != 0) {
|
||||
result.append("displayCutout |");
|
||||
result.append("displayCutout ");
|
||||
}
|
||||
if ((types & WINDOW_DECOR) != 0) {
|
||||
result.append("windowDecor |");
|
||||
result.append("windowDecor ");
|
||||
}
|
||||
if ((types & SYSTEM_OVERLAYS) != 0) {
|
||||
result.append("systemOverlays |");
|
||||
result.append("systemOverlays ");
|
||||
}
|
||||
if (result.length() > 0) {
|
||||
result.delete(result.length() - 2, result.length());
|
||||
result.delete(result.length() - 1, result.length());
|
||||
}
|
||||
return result.toString();
|
||||
}
|
||||
|
||||
@@ -1,121 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2021 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 android.view.InsetsState.FIRST_TYPE;
|
||||
import static android.view.InsetsState.LAST_TYPE;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNotEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import android.platform.test.annotations.Presubmit;
|
||||
import android.view.InsetsState.InternalInsetsType;
|
||||
|
||||
import androidx.test.runner.AndroidJUnit4;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
/**
|
||||
* Tests for {@link InsetsVisibilities}.
|
||||
*
|
||||
* <p>Build/Install/Run:
|
||||
* atest FrameworksCoreTests:InsetsVisibilities
|
||||
*
|
||||
* <p>This test class is a part of Window Manager Service tests and specified in
|
||||
* {@link com.android.server.wm.test.filters.FrameworksTestsFilter}.
|
||||
*/
|
||||
@Presubmit
|
||||
@RunWith(AndroidJUnit4.class)
|
||||
public class InsetsVisibilitiesTest {
|
||||
|
||||
@Test
|
||||
public void testEquals() {
|
||||
final InsetsVisibilities v1 = new InsetsVisibilities();
|
||||
final InsetsVisibilities v2 = new InsetsVisibilities();
|
||||
final InsetsVisibilities v3 = new InsetsVisibilities();
|
||||
assertEquals(v1, v2);
|
||||
assertEquals(v1, v3);
|
||||
|
||||
for (@InternalInsetsType int type = FIRST_TYPE; type <= LAST_TYPE; type++) {
|
||||
v1.setVisibility(type, false);
|
||||
v2.setVisibility(type, false);
|
||||
}
|
||||
assertEquals(v1, v2);
|
||||
assertNotEquals(v1, v3);
|
||||
|
||||
for (@InternalInsetsType int type = FIRST_TYPE; type <= LAST_TYPE; type++) {
|
||||
v1.setVisibility(type, true);
|
||||
v2.setVisibility(type, true);
|
||||
}
|
||||
assertEquals(v1, v2);
|
||||
assertNotEquals(v1, v3);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSet() {
|
||||
for (@InternalInsetsType int type = FIRST_TYPE; type <= LAST_TYPE; type++) {
|
||||
final InsetsVisibilities v1 = new InsetsVisibilities();
|
||||
final InsetsVisibilities v2 = new InsetsVisibilities();
|
||||
|
||||
v1.setVisibility(type, true);
|
||||
assertNotEquals(v1, v2);
|
||||
|
||||
v2.set(v1);
|
||||
assertEquals(v1, v2);
|
||||
|
||||
v2.setVisibility(type, false);
|
||||
assertNotEquals(v1, v2);
|
||||
|
||||
v1.set(v2);
|
||||
assertEquals(v1, v2);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCopyConstructor() {
|
||||
for (@InternalInsetsType int type = FIRST_TYPE; type <= LAST_TYPE; type++) {
|
||||
final InsetsVisibilities v1 = new InsetsVisibilities();
|
||||
v1.setVisibility(type, true);
|
||||
final InsetsVisibilities v2 = new InsetsVisibilities(v1);
|
||||
assertEquals(v1, v2);
|
||||
|
||||
v2.setVisibility(type, false);
|
||||
assertNotEquals(v1, v2);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetterAndSetter() {
|
||||
final InsetsVisibilities v1 = new InsetsVisibilities();
|
||||
final InsetsVisibilities v2 = new InsetsVisibilities();
|
||||
|
||||
for (@InternalInsetsType int type = FIRST_TYPE; type <= LAST_TYPE; type++) {
|
||||
assertEquals(InsetsState.getDefaultVisibility(type), v1.getVisibility(type));
|
||||
}
|
||||
|
||||
for (@InternalInsetsType int type = FIRST_TYPE; type <= LAST_TYPE; type++) {
|
||||
v1.setVisibility(type, true);
|
||||
assertTrue(v1.getVisibility(type));
|
||||
|
||||
v2.setVisibility(type, false);
|
||||
assertFalse(v2.getVisibility(type));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -6814,10 +6814,9 @@ class DisplayContent extends RootDisplayArea implements WindowManagerPolicy.Disp
|
||||
|
||||
@Override
|
||||
public boolean isRequestedVisible(@InsetsType int types) {
|
||||
if (types == ime()) {
|
||||
return getInsetsStateController().getImeSourceProvider().isImeShowing();
|
||||
}
|
||||
return (mRequestedVisibleTypes & types) != 0;
|
||||
return ((types & ime()) != 0
|
||||
&& getInsetsStateController().getImeSourceProvider().isImeShowing())
|
||||
|| (mRequestedVisibleTypes & types) != 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -88,46 +88,7 @@ public class ControllerActivity extends Activity implements View.OnApplyWindowIn
|
||||
}
|
||||
|
||||
private static String insetsTypesToString(int types) {
|
||||
if (types == 0) {
|
||||
return "none";
|
||||
}
|
||||
final StringBuilder sb = new StringBuilder();
|
||||
if ((types & Type.statusBars()) != 0) {
|
||||
types &= ~Type.statusBars();
|
||||
sb.append("statusBars ");
|
||||
}
|
||||
if ((types & Type.navigationBars()) != 0) {
|
||||
types &= ~Type.navigationBars();
|
||||
sb.append("navigationBars ");
|
||||
}
|
||||
if ((types & Type.captionBar()) != 0) {
|
||||
types &= ~Type.captionBar();
|
||||
sb.append("captionBar ");
|
||||
}
|
||||
if ((types & Type.ime()) != 0) {
|
||||
types &= ~Type.ime();
|
||||
sb.append("ime ");
|
||||
}
|
||||
if ((types & Type.systemGestures()) != 0) {
|
||||
types &= ~Type.systemGestures();
|
||||
sb.append("systemGestures ");
|
||||
}
|
||||
if ((types & Type.mandatorySystemGestures()) != 0) {
|
||||
types &= ~Type.mandatorySystemGestures();
|
||||
sb.append("mandatorySystemGestures ");
|
||||
}
|
||||
if ((types & Type.tappableElement()) != 0) {
|
||||
types &= ~Type.tappableElement();
|
||||
sb.append("tappableElement ");
|
||||
}
|
||||
if ((types & Type.displayCutout()) != 0) {
|
||||
types &= ~Type.displayCutout();
|
||||
sb.append("displayCutout ");
|
||||
}
|
||||
if (types != 0) {
|
||||
sb.append("unknownTypes:").append(types);
|
||||
}
|
||||
return sb.toString();
|
||||
return types == 0 ? "none" : WindowInsets.Type.toString(types);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Reference in New Issue
Block a user