diff --git a/res/drawable/ic_zen_mode_type_bedtime.xml b/res/drawable/ic_zen_mode_type_bedtime.xml deleted file mode 100644 index 7428a71b262..00000000000 --- a/res/drawable/ic_zen_mode_type_bedtime.xml +++ /dev/null @@ -1,25 +0,0 @@ - - - - \ No newline at end of file diff --git a/res/drawable/ic_zen_mode_type_driving.xml b/res/drawable/ic_zen_mode_type_driving.xml deleted file mode 100644 index 3cc0066c46b..00000000000 --- a/res/drawable/ic_zen_mode_type_driving.xml +++ /dev/null @@ -1,25 +0,0 @@ - - - - \ No newline at end of file diff --git a/res/drawable/ic_zen_mode_type_immersive.xml b/res/drawable/ic_zen_mode_type_immersive.xml deleted file mode 100644 index 70913579b62..00000000000 --- a/res/drawable/ic_zen_mode_type_immersive.xml +++ /dev/null @@ -1,25 +0,0 @@ - - - - \ No newline at end of file diff --git a/res/drawable/ic_zen_mode_type_managed.xml b/res/drawable/ic_zen_mode_type_managed.xml deleted file mode 100644 index 5e224ebbf72..00000000000 --- a/res/drawable/ic_zen_mode_type_managed.xml +++ /dev/null @@ -1,25 +0,0 @@ - - - - \ No newline at end of file diff --git a/res/drawable/ic_zen_mode_type_other.xml b/res/drawable/ic_zen_mode_type_other.xml deleted file mode 100644 index d236b0d7202..00000000000 --- a/res/drawable/ic_zen_mode_type_other.xml +++ /dev/null @@ -1,25 +0,0 @@ - - - - \ No newline at end of file diff --git a/res/drawable/ic_zen_mode_type_schedule_calendar.xml b/res/drawable/ic_zen_mode_type_schedule_calendar.xml deleted file mode 100644 index 40004899ad8..00000000000 --- a/res/drawable/ic_zen_mode_type_schedule_calendar.xml +++ /dev/null @@ -1,25 +0,0 @@ - - - - - diff --git a/res/drawable/ic_zen_mode_type_schedule_time.xml b/res/drawable/ic_zen_mode_type_schedule_time.xml deleted file mode 100644 index 57d596a98f6..00000000000 --- a/res/drawable/ic_zen_mode_type_schedule_time.xml +++ /dev/null @@ -1,26 +0,0 @@ - - - - - \ No newline at end of file diff --git a/res/drawable/ic_zen_mode_type_theater.xml b/res/drawable/ic_zen_mode_type_theater.xml deleted file mode 100644 index cc66b32391a..00000000000 --- a/res/drawable/ic_zen_mode_type_theater.xml +++ /dev/null @@ -1,25 +0,0 @@ - - - - \ No newline at end of file diff --git a/res/drawable/ic_zen_mode_type_unknown.xml b/res/drawable/ic_zen_mode_type_unknown.xml deleted file mode 100644 index c1afd44ecfc..00000000000 --- a/res/drawable/ic_zen_mode_type_unknown.xml +++ /dev/null @@ -1,25 +0,0 @@ - - - - \ No newline at end of file diff --git a/res/values/arrays.xml b/res/values/arrays.xml index 98d93a0cb4e..adaea1bd921 100644 --- a/res/values/arrays.xml +++ b/res/values/arrays.xml @@ -1525,4 +1525,31 @@ 2 + + + @*android:drawable/ic_zen_mode_type_bedtime + @*android:drawable/ic_zen_mode_type_driving + @*android:drawable/ic_zen_mode_type_immersive + @*android:drawable/ic_zen_mode_type_managed + @*android:drawable/ic_zen_mode_type_other + @*android:drawable/ic_zen_mode_type_schedule_calendar + @*android:drawable/ic_zen_mode_type_schedule_time + @*android:drawable/ic_zen_mode_type_theater + @*android:drawable/ic_zen_mode_type_unknown + + + + + + Bedtime + Driving + Immersive + Managed + Star + Calendar + Time + Theater + Flower + diff --git a/src/com/android/settings/notification/modes/IconLoader.java b/src/com/android/settings/notification/modes/IconLoader.java index 8a02093633e..c5902856423 100644 --- a/src/com/android/settings/notification/modes/IconLoader.java +++ b/src/com/android/settings/notification/modes/IconLoader.java @@ -36,8 +36,6 @@ import androidx.annotation.NonNull; import androidx.annotation.VisibleForTesting; import androidx.appcompat.content.res.AppCompatResources; -import com.android.settings.R; - import com.google.common.util.concurrent.FluentFuture; import com.google.common.util.concurrent.Futures; import com.google.common.util.concurrent.ListenableFuture; @@ -123,17 +121,26 @@ class IconLoader { private static Drawable getFallbackIcon(Context context, int ruleType) { int iconResIdFromType = switch (ruleType) { - case AutomaticZenRule.TYPE_UNKNOWN -> R.drawable.ic_zen_mode_type_unknown; - case AutomaticZenRule.TYPE_OTHER -> R.drawable.ic_zen_mode_type_other; - case AutomaticZenRule.TYPE_SCHEDULE_TIME -> R.drawable.ic_zen_mode_type_schedule_time; + case AutomaticZenRule.TYPE_UNKNOWN -> + com.android.internal.R.drawable.ic_zen_mode_type_unknown; + case AutomaticZenRule.TYPE_OTHER -> + com.android.internal.R.drawable.ic_zen_mode_type_other; + case AutomaticZenRule.TYPE_SCHEDULE_TIME -> + com.android.internal.R.drawable.ic_zen_mode_type_schedule_time; case AutomaticZenRule.TYPE_SCHEDULE_CALENDAR -> - R.drawable.ic_zen_mode_type_schedule_calendar; - case AutomaticZenRule.TYPE_BEDTIME -> R.drawable.ic_zen_mode_type_bedtime; - case AutomaticZenRule.TYPE_DRIVING -> R.drawable.ic_zen_mode_type_driving; - case AutomaticZenRule.TYPE_IMMERSIVE -> R.drawable.ic_zen_mode_type_immersive; - case AutomaticZenRule.TYPE_THEATER -> R.drawable.ic_zen_mode_type_theater; - case AutomaticZenRule.TYPE_MANAGED -> R.drawable.ic_zen_mode_type_managed; - default -> R.drawable.ic_zen_mode_type_unknown; + com.android.internal.R.drawable.ic_zen_mode_type_schedule_calendar; + case AutomaticZenRule.TYPE_BEDTIME -> + com.android.internal.R.drawable.ic_zen_mode_type_bedtime; + case AutomaticZenRule.TYPE_DRIVING -> + com.android.internal.R.drawable.ic_zen_mode_type_driving; + case AutomaticZenRule.TYPE_IMMERSIVE -> + com.android.internal.R.drawable.ic_zen_mode_type_immersive; + case AutomaticZenRule.TYPE_THEATER -> + com.android.internal.R.drawable.ic_zen_mode_type_theater; + case AutomaticZenRule.TYPE_MANAGED -> + com.android.internal.R.drawable.ic_zen_mode_type_managed; + default -> + com.android.internal.R.drawable.ic_zen_mode_type_unknown; }; return requireNonNull(context.getDrawable(iconResIdFromType)); } diff --git a/src/com/android/settings/notification/modes/IconOptionsProvider.java b/src/com/android/settings/notification/modes/IconOptionsProvider.java index 288aff258fc..cd0066408a4 100644 --- a/src/com/android/settings/notification/modes/IconOptionsProvider.java +++ b/src/com/android/settings/notification/modes/IconOptionsProvider.java @@ -17,12 +17,13 @@ package com.android.settings.notification.modes; import androidx.annotation.DrawableRes; +import androidx.annotation.NonNull; import com.google.common.collect.ImmutableList; interface IconOptionsProvider { - ImmutableList getIcons(); + @NonNull ImmutableList getIcons(); record IconInfo(@DrawableRes int resId, String description) { } } diff --git a/src/com/android/settings/notification/modes/IconOptionsProviderImpl.java b/src/com/android/settings/notification/modes/IconOptionsProviderImpl.java new file mode 100644 index 00000000000..f296ae1b9b8 --- /dev/null +++ b/src/com/android/settings/notification/modes/IconOptionsProviderImpl.java @@ -0,0 +1,62 @@ +/* + * 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.settings.notification.modes; + +import android.content.Context; +import android.content.res.TypedArray; +import android.util.Log; + +import androidx.annotation.DrawableRes; +import androidx.annotation.NonNull; + +import com.android.settings.R; + +import com.google.common.collect.ImmutableList; + +class IconOptionsProviderImpl implements IconOptionsProvider { + + private static final String TAG = "IconOptionsProviderImpl"; + + private final Context mContext; + + IconOptionsProviderImpl(Context context) { + mContext = context.getApplicationContext(); + } + + @Override + @NonNull + public ImmutableList getIcons() { + ImmutableList.Builder list = ImmutableList.builder(); + try (TypedArray icons = mContext.getResources().obtainTypedArray( + R.array.zen_mode_icon_options)) { + String[] descriptions = mContext.getResources().getStringArray( + R.array.zen_mode_icon_options_descriptions); + if (icons.length() != descriptions.length) { + Log.wtf(TAG, "Size mismatch between zen_mode_icon_options (" + icons.length() + + ") and zen_mode_icon_options_descriptions (" + descriptions.length + ")"); + } + + for (int i = 0; i < Math.min(icons.length(), descriptions.length); i++) { + @DrawableRes int resId = icons.getResourceId(i, 0); + if (resId != 0) { + list.add(new IconInfo(resId, descriptions[i])); + } + } + } + return list.build(); + } +} diff --git a/src/com/android/settings/notification/modes/TempIconOptionsProvider.java b/src/com/android/settings/notification/modes/TempIconOptionsProvider.java deleted file mode 100644 index 06c5c273ffe..00000000000 --- a/src/com/android/settings/notification/modes/TempIconOptionsProvider.java +++ /dev/null @@ -1,48 +0,0 @@ -/* - * 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.settings.notification.modes; - -import com.google.common.collect.ImmutableList; - -import java.lang.reflect.Modifier; -import java.util.Arrays; -import java.util.Comparator; -import java.util.Objects; - -/** Temporary implementation of {@link IconOptionsProvider} until we have the real list. */ -class TempIconOptionsProvider implements IconOptionsProvider { - @Override - public ImmutableList getIcons() { - return ImmutableList.copyOf( - Arrays.stream(com.android.internal.R.drawable.class.getFields()) - .filter( - f -> Modifier.isStatic(f.getModifiers()) - && Modifier.isFinal(f.getModifiers()) - && f.getName().startsWith("ic_")) - .limit(20) - .map(f -> { - try { - return new IconInfo(f.getInt(null), f.getName()); - } catch (IllegalAccessException e) { - return null; - } - }) - .filter(Objects::nonNull) - .sorted(Comparator.comparing(IconInfo::resId).reversed()) - .toList()); - } -} diff --git a/src/com/android/settings/notification/modes/ZenModeIconPickerFragment.java b/src/com/android/settings/notification/modes/ZenModeIconPickerFragment.java index 553d3ebc2e5..760b1835f70 100644 --- a/src/com/android/settings/notification/modes/ZenModeIconPickerFragment.java +++ b/src/com/android/settings/notification/modes/ZenModeIconPickerFragment.java @@ -44,7 +44,6 @@ public class ZenModeIconPickerFragment extends ZenModeFragmentBase { new ZenModeIconPickerIconPreferenceController(context, "current_icon", this, mBackend), new ZenModeIconPickerListPreferenceController(context, "icon_list", this, - // TODO: b/333901673 - Replace with correct icon list. - new TempIconOptionsProvider(), mBackend)); + new IconOptionsProviderImpl(mContext), mBackend)); } } diff --git a/tests/robotests/src/com/android/settings/notification/modes/IconOptionsProviderImplTest.java b/tests/robotests/src/com/android/settings/notification/modes/IconOptionsProviderImplTest.java new file mode 100644 index 00000000000..d5430b15d2f --- /dev/null +++ b/tests/robotests/src/com/android/settings/notification/modes/IconOptionsProviderImplTest.java @@ -0,0 +1,64 @@ +/* + * 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.settings.notification.modes; + +import static com.google.common.truth.Truth.assertThat; +import static com.google.common.truth.Truth.assertWithMessage; + +import android.content.Context; +import android.content.res.TypedArray; + +import com.android.settings.R; + +import com.google.common.collect.ImmutableList; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.robolectric.RobolectricTestRunner; +import org.robolectric.RuntimeEnvironment; + +@RunWith(RobolectricTestRunner.class) +public class IconOptionsProviderImplTest { + + private static final int EXPECTED_NUMBER_OF_ICON_OPTIONS = 9; + + @Test + public void iconResources_correctResources() { + Context context = RuntimeEnvironment.getApplication(); + String[] descriptions = context.getResources().getStringArray( + R.array.zen_mode_icon_options_descriptions); + assertThat(descriptions).hasLength(EXPECTED_NUMBER_OF_ICON_OPTIONS); + + try (TypedArray icons = context.getResources().obtainTypedArray( + R.array.zen_mode_icon_options)) { + assertThat(icons.length()).isEqualTo(EXPECTED_NUMBER_OF_ICON_OPTIONS); + } + } + + @Test + public void getIcons_returnsList() { + Context context = RuntimeEnvironment.getApplication(); + IconOptionsProviderImpl provider = new IconOptionsProviderImpl(context); + + ImmutableList iconOptions = provider.getIcons(); + assertThat(iconOptions).hasSize(EXPECTED_NUMBER_OF_ICON_OPTIONS); + for (int i = 0; i < iconOptions.size(); i++) { + assertWithMessage("Checking description of item #" + i) + .that(iconOptions.get(i).description()).isNotEmpty(); + } + } +} diff --git a/tests/robotests/src/com/android/settings/notification/modes/ZenModeIconPickerListPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/notification/modes/ZenModeIconPickerListPreferenceControllerTest.java index 5f7ffa29ecc..ba9a6b81862 100644 --- a/tests/robotests/src/com/android/settings/notification/modes/ZenModeIconPickerListPreferenceControllerTest.java +++ b/tests/robotests/src/com/android/settings/notification/modes/ZenModeIconPickerListPreferenceControllerTest.java @@ -27,6 +27,7 @@ import android.app.AutomaticZenRule; import android.content.Context; import android.net.Uri; +import androidx.annotation.NonNull; import androidx.preference.PreferenceScreen; import androidx.recyclerview.widget.RecyclerView; @@ -95,6 +96,7 @@ public class ZenModeIconPickerListPreferenceControllerTest { private static class TestIconOptionsProvider implements IconOptionsProvider { @Override + @NonNull public ImmutableList getIcons() { return ImmutableList.of( new IconInfo(R.drawable.ic_android, "android"),