Merge "Load zen mode type icon options from the proper resources" into main
This commit is contained in:
committed by
Android (Google) Code Review
commit
e3570eb633
@@ -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));
|
||||
}
|
||||
|
||||
@@ -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<IconInfo> getIcons();
|
||||
@NonNull ImmutableList<IconInfo> getIcons();
|
||||
|
||||
record IconInfo(@DrawableRes int resId, String description) { }
|
||||
}
|
||||
|
||||
@@ -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<IconInfo> getIcons() {
|
||||
ImmutableList.Builder<IconInfo> 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();
|
||||
}
|
||||
}
|
||||
@@ -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<IconInfo> 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());
|
||||
}
|
||||
}
|
||||
@@ -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));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user