diff options
| author | 2022-01-28 11:45:43 -0800 | |
|---|---|---|
| committer | 2022-01-28 11:46:42 -0800 | |
| commit | d2c3a184cdad5eeebb47ce0b8e9527380365bb82 (patch) | |
| tree | 62f565c95217497d88fdeeb176ec9e3e67da37fd | |
| parent | 86d5713de2ca2a3a6c0c3de89289b4150eac70e3 (diff) | |
Reintroduce complication types.
This change was removed during the ComplicationProvider to Complication refactor.
Test: atest ComplicationUtilsTest
Bug: 214038720
Change-Id: Iabaecd2d4748b84e3c5d24e4b3662aa972d54e1f
3 files changed, 129 insertions, 0 deletions
diff --git a/packages/SystemUI/src/com/android/systemui/dreams/complication/Complication.java b/packages/SystemUI/src/com/android/systemui/dreams/complication/Complication.java index 96cf50d58d10..4332f5880e2e 100644 --- a/packages/SystemUI/src/com/android/systemui/dreams/complication/Complication.java +++ b/packages/SystemUI/src/com/android/systemui/dreams/complication/Complication.java @@ -154,6 +154,27 @@ public interface Complication { int CATEGORY_SYSTEM = 1 << 1; /** + * The type of dream complications which can be provided by a {@link Complication}. + */ + @IntDef(prefix = {"COMPLICATION_TYPE_"}, flag = true, value = { + COMPLICATION_TYPE_NONE, + COMPLICATION_TYPE_TIME, + COMPLICATION_TYPE_DATE, + COMPLICATION_TYPE_WEATHER, + COMPLICATION_TYPE_AIR_QUALITY, + COMPLICATION_TYPE_CAST_INFO + }) + @Retention(RetentionPolicy.SOURCE) + @interface ComplicationType {} + + int COMPLICATION_TYPE_NONE = 0; + int COMPLICATION_TYPE_TIME = 1; + int COMPLICATION_TYPE_DATE = 1 << 1; + int COMPLICATION_TYPE_WEATHER = 1 << 2; + int COMPLICATION_TYPE_AIR_QUALITY = 1 << 3; + int COMPLICATION_TYPE_CAST_INFO = 1 << 4; + + /** * The {@link Host} interface specifies a way a {@link Complication} to communicate with its * parent entity for information and actions. */ diff --git a/packages/SystemUI/src/com/android/systemui/dreams/complication/ComplicationUtils.java b/packages/SystemUI/src/com/android/systemui/dreams/complication/ComplicationUtils.java new file mode 100644 index 000000000000..3a2a6ef60f03 --- /dev/null +++ b/packages/SystemUI/src/com/android/systemui/dreams/complication/ComplicationUtils.java @@ -0,0 +1,53 @@ +/* + * Copyright (C) 2022 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.systemui.dreams.complication; + +import static com.android.systemui.dreams.complication.Complication.COMPLICATION_TYPE_AIR_QUALITY; +import static com.android.systemui.dreams.complication.Complication.COMPLICATION_TYPE_CAST_INFO; +import static com.android.systemui.dreams.complication.Complication.COMPLICATION_TYPE_DATE; +import static com.android.systemui.dreams.complication.Complication.COMPLICATION_TYPE_NONE; +import static com.android.systemui.dreams.complication.Complication.COMPLICATION_TYPE_TIME; +import static com.android.systemui.dreams.complication.Complication.COMPLICATION_TYPE_WEATHER; + +import com.android.settingslib.dream.DreamBackend; + +/** + * A collection of utility methods for working with {@link Complication}. + */ +public class ComplicationUtils { + /** + * Converts a {@link com.android.settingslib.dream.DreamBackend.ComplicationType} to + * {@link ComplicationType}. + */ + @Complication.ComplicationType + public static int convertComplicationType(@DreamBackend.ComplicationType int type) { + switch (type) { + case DreamBackend.COMPLICATION_TYPE_TIME: + return COMPLICATION_TYPE_TIME; + case DreamBackend.COMPLICATION_TYPE_DATE: + return COMPLICATION_TYPE_DATE; + case DreamBackend.COMPLICATION_TYPE_WEATHER: + return COMPLICATION_TYPE_WEATHER; + case DreamBackend.COMPLICATION_TYPE_AIR_QUALITY: + return COMPLICATION_TYPE_AIR_QUALITY; + case DreamBackend.COMPLICATION_TYPE_CAST_INFO: + return COMPLICATION_TYPE_CAST_INFO; + default: + return COMPLICATION_TYPE_NONE; + } + } +} diff --git a/packages/SystemUI/tests/src/com/android/systemui/dreams/complication/ComplicationUtilsTest.java b/packages/SystemUI/tests/src/com/android/systemui/dreams/complication/ComplicationUtilsTest.java new file mode 100644 index 000000000000..f1978b214594 --- /dev/null +++ b/packages/SystemUI/tests/src/com/android/systemui/dreams/complication/ComplicationUtilsTest.java @@ -0,0 +1,55 @@ +/* + * Copyright (C) 2022 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.systemui.dreams.complication; + +import static com.android.systemui.dreams.complication.Complication.COMPLICATION_TYPE_AIR_QUALITY; +import static com.android.systemui.dreams.complication.Complication.COMPLICATION_TYPE_CAST_INFO; +import static com.android.systemui.dreams.complication.Complication.COMPLICATION_TYPE_DATE; +import static com.android.systemui.dreams.complication.Complication.COMPLICATION_TYPE_TIME; +import static com.android.systemui.dreams.complication.Complication.COMPLICATION_TYPE_WEATHER; +import static com.android.systemui.dreams.complication.ComplicationUtils.convertComplicationType; + + +import static com.google.common.truth.Truth.assertThat; + +import android.testing.AndroidTestingRunner; + +import androidx.test.filters.SmallTest; + +import com.android.settingslib.dream.DreamBackend; +import com.android.systemui.SysuiTestCase; + +import org.junit.Test; +import org.junit.runner.RunWith; + +@SmallTest +@RunWith(AndroidTestingRunner.class) +public class ComplicationUtilsTest extends SysuiTestCase { + @Test + public void testConvertComplicationType() { + assertThat(convertComplicationType(DreamBackend.COMPLICATION_TYPE_TIME)) + .isEqualTo(COMPLICATION_TYPE_TIME); + assertThat(convertComplicationType(DreamBackend.COMPLICATION_TYPE_DATE)) + .isEqualTo(COMPLICATION_TYPE_DATE); + assertThat(convertComplicationType(DreamBackend.COMPLICATION_TYPE_WEATHER)) + .isEqualTo(COMPLICATION_TYPE_WEATHER); + assertThat(convertComplicationType(DreamBackend.COMPLICATION_TYPE_AIR_QUALITY)) + .isEqualTo(COMPLICATION_TYPE_AIR_QUALITY); + assertThat(convertComplicationType(DreamBackend.COMPLICATION_TYPE_CAST_INFO)) + .isEqualTo(COMPLICATION_TYPE_CAST_INFO); + } +} |