Loading src/com/android/settings/notification/modes/IconOptionsProvider.java 0 → 100644 +28 −0 Original line number Diff line number Diff line /* * 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 androidx.annotation.DrawableRes; import com.google.common.collect.ImmutableList; interface IconOptionsProvider { ImmutableList<IconInfo> getIcons(); record IconInfo(@DrawableRes int resId, String description) { } } src/com/android/settings/notification/modes/TempIconOptionsProvider.java 0 → 100644 +48 −0 Original line number Diff line number Diff line /* * 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()); } } src/com/android/settings/notification/modes/ZenModeActionsPreferenceController.java +0 −2 Original line number Diff line number Diff line Loading @@ -31,8 +31,6 @@ import com.android.settingslib.widget.ActionButtonsPreference; class ZenModeActionsPreferenceController extends AbstractZenModePreferenceController { private ActionButtonsPreference mPreference; ZenModeActionsPreferenceController(@NonNull Context context, @NonNull String key, @Nullable ZenModesBackend backend) { super(context, key, backend); Loading src/com/android/settings/notification/modes/ZenModeIconPickerFragment.java +2 −1 Original line number Diff line number Diff line Loading @@ -44,6 +44,7 @@ public class ZenModeIconPickerFragment extends ZenModeFragmentBase { new ZenModeIconPickerIconPreferenceController(context, "current_icon", this, mBackend), new ZenModeIconPickerListPreferenceController(context, "icon_list", this, mBackend)); // TODO: b/333901673 - Replace with correct icon list. new TempIconOptionsProvider(), mBackend)); } } src/com/android/settings/notification/modes/ZenModeIconPickerListPreferenceController.java +10 −33 Original line number Diff line number Diff line Loading @@ -37,22 +37,18 @@ import com.android.settingslib.widget.LayoutPreference; import com.google.common.collect.ImmutableList; import java.lang.reflect.Field; import java.lang.reflect.Modifier; import java.util.Arrays; import java.util.Comparator; import java.util.List; import java.util.Objects; class ZenModeIconPickerListPreferenceController extends AbstractZenModePreferenceController { private final DashboardFragment mFragment; private IconAdapter mAdapter; private final IconOptionsProvider mIconOptionsProvider; @Nullable private IconAdapter mAdapter; ZenModeIconPickerListPreferenceController(@NonNull Context context, @NonNull String key, @NonNull DashboardFragment fragment, @Nullable ZenModesBackend backend) { @NonNull DashboardFragment fragment, @NonNull IconOptionsProvider iconOptionsProvider, @Nullable ZenModesBackend backend) { super(context, key, backend); mFragment = fragment; mIconOptionsProvider = iconOptionsProvider; } @Override Loading @@ -64,24 +60,7 @@ class ZenModeIconPickerListPreferenceController extends AbstractZenModePreferenc } if (mAdapter == null) { // TODO: b/333901673 - This is just an example; replace with correct list. List<IconInfo> exampleIcons = Arrays.stream(android.R.drawable.class.getFields()) .filter( f -> Modifier.isStatic(f.getModifiers()) && f.getName().startsWith("ic_")) .sorted(Comparator.comparing(Field::getName)) .limit(20) .map(f -> { try { return new IconInfo(f.getInt(null), f.getName()); } catch (IllegalAccessException e) { return null; } }) .filter(Objects::nonNull) .toList(); mAdapter = new IconAdapter(exampleIcons); mAdapter = new IconAdapter(mIconOptionsProvider); } RecyclerView recyclerView = pref.findViewById(R.id.icon_list); recyclerView.setLayoutManager(new AutoFitGridLayoutManager(mContext)); Loading @@ -103,8 +82,6 @@ class ZenModeIconPickerListPreferenceController extends AbstractZenModePreferenc // Nothing to do, the current icon is shown in a different preference. } private record IconInfo(@DrawableRes int resId, String description) { } private class IconHolder extends RecyclerView.ViewHolder { private final ImageView mImageView; Loading @@ -114,7 +91,7 @@ class ZenModeIconPickerListPreferenceController extends AbstractZenModePreferenc mImageView = itemView.findViewById(R.id.icon_image_view); } void bindIcon(IconInfo icon) { void bindIcon(IconOptionsProvider.IconInfo icon) { mImageView.setImageDrawable( IconUtil.makeIconCircle(itemView.getContext(), icon.resId())); itemView.setContentDescription(icon.description()); Loading @@ -124,10 +101,10 @@ class ZenModeIconPickerListPreferenceController extends AbstractZenModePreferenc private class IconAdapter extends RecyclerView.Adapter<IconHolder> { private final ImmutableList<IconInfo> mIconResources; private final ImmutableList<IconOptionsProvider.IconInfo> mIconResources; private IconAdapter(List<IconInfo> iconOptions) { mIconResources = ImmutableList.copyOf(iconOptions); private IconAdapter(IconOptionsProvider iconOptionsProvider) { mIconResources = iconOptionsProvider.getIcons(); } @NonNull Loading Loading
src/com/android/settings/notification/modes/IconOptionsProvider.java 0 → 100644 +28 −0 Original line number Diff line number Diff line /* * 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 androidx.annotation.DrawableRes; import com.google.common.collect.ImmutableList; interface IconOptionsProvider { ImmutableList<IconInfo> getIcons(); record IconInfo(@DrawableRes int resId, String description) { } }
src/com/android/settings/notification/modes/TempIconOptionsProvider.java 0 → 100644 +48 −0 Original line number Diff line number Diff line /* * 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()); } }
src/com/android/settings/notification/modes/ZenModeActionsPreferenceController.java +0 −2 Original line number Diff line number Diff line Loading @@ -31,8 +31,6 @@ import com.android.settingslib.widget.ActionButtonsPreference; class ZenModeActionsPreferenceController extends AbstractZenModePreferenceController { private ActionButtonsPreference mPreference; ZenModeActionsPreferenceController(@NonNull Context context, @NonNull String key, @Nullable ZenModesBackend backend) { super(context, key, backend); Loading
src/com/android/settings/notification/modes/ZenModeIconPickerFragment.java +2 −1 Original line number Diff line number Diff line Loading @@ -44,6 +44,7 @@ public class ZenModeIconPickerFragment extends ZenModeFragmentBase { new ZenModeIconPickerIconPreferenceController(context, "current_icon", this, mBackend), new ZenModeIconPickerListPreferenceController(context, "icon_list", this, mBackend)); // TODO: b/333901673 - Replace with correct icon list. new TempIconOptionsProvider(), mBackend)); } }
src/com/android/settings/notification/modes/ZenModeIconPickerListPreferenceController.java +10 −33 Original line number Diff line number Diff line Loading @@ -37,22 +37,18 @@ import com.android.settingslib.widget.LayoutPreference; import com.google.common.collect.ImmutableList; import java.lang.reflect.Field; import java.lang.reflect.Modifier; import java.util.Arrays; import java.util.Comparator; import java.util.List; import java.util.Objects; class ZenModeIconPickerListPreferenceController extends AbstractZenModePreferenceController { private final DashboardFragment mFragment; private IconAdapter mAdapter; private final IconOptionsProvider mIconOptionsProvider; @Nullable private IconAdapter mAdapter; ZenModeIconPickerListPreferenceController(@NonNull Context context, @NonNull String key, @NonNull DashboardFragment fragment, @Nullable ZenModesBackend backend) { @NonNull DashboardFragment fragment, @NonNull IconOptionsProvider iconOptionsProvider, @Nullable ZenModesBackend backend) { super(context, key, backend); mFragment = fragment; mIconOptionsProvider = iconOptionsProvider; } @Override Loading @@ -64,24 +60,7 @@ class ZenModeIconPickerListPreferenceController extends AbstractZenModePreferenc } if (mAdapter == null) { // TODO: b/333901673 - This is just an example; replace with correct list. List<IconInfo> exampleIcons = Arrays.stream(android.R.drawable.class.getFields()) .filter( f -> Modifier.isStatic(f.getModifiers()) && f.getName().startsWith("ic_")) .sorted(Comparator.comparing(Field::getName)) .limit(20) .map(f -> { try { return new IconInfo(f.getInt(null), f.getName()); } catch (IllegalAccessException e) { return null; } }) .filter(Objects::nonNull) .toList(); mAdapter = new IconAdapter(exampleIcons); mAdapter = new IconAdapter(mIconOptionsProvider); } RecyclerView recyclerView = pref.findViewById(R.id.icon_list); recyclerView.setLayoutManager(new AutoFitGridLayoutManager(mContext)); Loading @@ -103,8 +82,6 @@ class ZenModeIconPickerListPreferenceController extends AbstractZenModePreferenc // Nothing to do, the current icon is shown in a different preference. } private record IconInfo(@DrawableRes int resId, String description) { } private class IconHolder extends RecyclerView.ViewHolder { private final ImageView mImageView; Loading @@ -114,7 +91,7 @@ class ZenModeIconPickerListPreferenceController extends AbstractZenModePreferenc mImageView = itemView.findViewById(R.id.icon_image_view); } void bindIcon(IconInfo icon) { void bindIcon(IconOptionsProvider.IconInfo icon) { mImageView.setImageDrawable( IconUtil.makeIconCircle(itemView.getContext(), icon.resId())); itemView.setContentDescription(icon.description()); Loading @@ -124,10 +101,10 @@ class ZenModeIconPickerListPreferenceController extends AbstractZenModePreferenc private class IconAdapter extends RecyclerView.Adapter<IconHolder> { private final ImmutableList<IconInfo> mIconResources; private final ImmutableList<IconOptionsProvider.IconInfo> mIconResources; private IconAdapter(List<IconInfo> iconOptions) { mIconResources = ImmutableList.copyOf(iconOptions); private IconAdapter(IconOptionsProvider iconOptionsProvider) { mIconResources = iconOptionsProvider.getIcons(); } @NonNull Loading