diff options
| author | 2024-07-09 10:50:27 +0000 | |
|---|---|---|
| committer | 2024-07-10 11:37:09 +0000 | |
| commit | d9d2b61fa0809a204eb126a01e5065cbda06a503 (patch) | |
| tree | bce82cec461a450ddb56afe628c68d951a31f75c | |
| parent | 0792d0dc0f37fd88ffae7c9d7b3b91e29556115c (diff) | |
Move DimenPxIntSupplier to shared utils
Flag: EXEMPT refactor
Test: atest LetterboxConfigurationTest
Bug: 280496681
Change-Id: I24f01d1d559d7d62cd470d2c7e2c81e4ed8f242d
| -rw-r--r-- | services/core/java/com/android/server/wm/LetterboxConfiguration.java | 31 | ||||
| -rw-r--r-- | services/core/java/com/android/server/wm/utils/DimenPxIntSupplier.java | 54 |
2 files changed, 55 insertions, 30 deletions
diff --git a/services/core/java/com/android/server/wm/LetterboxConfiguration.java b/services/core/java/com/android/server/wm/LetterboxConfiguration.java index b5af8065726d..0161ae5b5473 100644 --- a/services/core/java/com/android/server/wm/LetterboxConfiguration.java +++ b/services/core/java/com/android/server/wm/LetterboxConfiguration.java @@ -19,7 +19,6 @@ package com.android.server.wm; import static com.android.server.wm.ActivityTaskManagerDebugConfig.TAG_ATM; import static com.android.server.wm.ActivityTaskManagerDebugConfig.TAG_WITH_CLASS_NAME; -import android.annotation.DimenRes; import android.annotation.IntDef; import android.annotation.NonNull; import android.annotation.Nullable; @@ -29,11 +28,11 @@ import android.provider.DeviceConfig; import com.android.internal.R; import com.android.internal.annotations.VisibleForTesting; +import com.android.server.wm.utils.DimenPxIntSupplier; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.util.function.Function; -import java.util.function.IntSupplier; /** Reads letterbox configs from resources and controls their overrides at runtime. */ final class LetterboxConfiguration { @@ -308,34 +307,6 @@ final class LetterboxConfiguration { // Flags dynamically updated with {@link android.provider.DeviceConfig}. @NonNull private final SynchedDeviceConfig mDeviceConfig; - // Cached version of IntSupplier customised to evaluate new dimen in pixels - // when density changes - private static class DimenPxIntSupplier implements IntSupplier { - - @NonNull - private final Context mContext; - - private final int mResourceId; - - private float mLastDensity = Float.MIN_VALUE; - private int mValue = 0; - - private DimenPxIntSupplier(@NonNull Context context, @DimenRes int resourceId) { - mContext = context; - mResourceId = resourceId; - } - - @Override - public int getAsInt() { - final float newDensity = mContext.getResources().getDisplayMetrics().density; - if (newDensity != mLastDensity) { - mLastDensity = newDensity; - mValue = mContext.getResources().getDimensionPixelSize(mResourceId); - } - return mValue; - } - } - LetterboxConfiguration(@NonNull final Context systemUiContext) { this(systemUiContext, new LetterboxConfigurationPersister( () -> readLetterboxHorizontalReachabilityPositionFromConfig( diff --git a/services/core/java/com/android/server/wm/utils/DimenPxIntSupplier.java b/services/core/java/com/android/server/wm/utils/DimenPxIntSupplier.java new file mode 100644 index 000000000000..5e4934500154 --- /dev/null +++ b/services/core/java/com/android/server/wm/utils/DimenPxIntSupplier.java @@ -0,0 +1,54 @@ +/* + * Copyright (C) 2024 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 com.android.server.wm.utils; + +import android.annotation.DimenRes; +import android.annotation.NonNull; +import android.content.Context; + +import java.util.function.IntSupplier; + +/** + * Cached version of IntSupplier customised to evaluate new dimen in pixels + * when density changes. + * @hide + */ +public class DimenPxIntSupplier implements IntSupplier { + + @NonNull + private final Context mContext; + + private final int mResourceId; + + private float mLastDensity = Float.MIN_VALUE; + private int mValue = 0; + + public DimenPxIntSupplier(@NonNull Context context, @DimenRes int resourceId) { + mContext = context; + mResourceId = resourceId; + } + + @Override + public int getAsInt() { + final float newDensity = mContext.getResources().getDisplayMetrics().density; + if (newDensity != mLastDensity) { + mLastDensity = newDensity; + mValue = mContext.getResources().getDimensionPixelSize(mResourceId); + } + return mValue; + } +} |