Load zen mode type icon options from the proper resources

* Move default mode icons from Settings res to core res.
* Add array resources for the icon options and their descriptions.
* As the initial version of the list, use the default mode icons.

Bug: 333901673
Test: atest IconOptionsProviderImplTest
Flag: android.app.modes_ui
Change-Id: I66669e67a9d607268c05d5ed3df6c9555e57864c
This commit is contained in:
Matías Hernández
2024-06-13 14:37:35 +02:00
parent 37bdf39ad6
commit 22c325a099
17 changed files with 177 additions and 289 deletions

View File

@@ -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<IconOptionsProvider.IconInfo> 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();
}
}
}

View File

@@ -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<IconInfo> getIcons() {
return ImmutableList.of(
new IconInfo(R.drawable.ic_android, "android"),