1 /* 2 * Copyright (C) 2024 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package com.android.settings.notification.modes; 18 19 import android.content.Context; 20 21 import androidx.annotation.NonNull; 22 import androidx.annotation.Nullable; 23 import androidx.preference.Preference; 24 25 import com.android.settings.R; 26 import com.android.settings.dashboard.DashboardFragment; 27 import com.android.settings.widget.EntityHeaderController; 28 import com.android.settingslib.widget.LayoutPreference; 29 30 class ZenModeIconPickerIconPreferenceController extends AbstractZenModePreferenceController { 31 32 private final DashboardFragment mFragment; 33 private EntityHeaderController mHeaderController; 34 ZenModeIconPickerIconPreferenceController(@onNull Context context, @NonNull String key, @NonNull DashboardFragment fragment, @Nullable ZenModesBackend backend)35 ZenModeIconPickerIconPreferenceController(@NonNull Context context, @NonNull String key, 36 @NonNull DashboardFragment fragment, @Nullable ZenModesBackend backend) { 37 super(context, key, backend); 38 mFragment = fragment; 39 } 40 41 @Override updateState(Preference preference, @NonNull ZenMode zenMode)42 void updateState(Preference preference, @NonNull ZenMode zenMode) { 43 preference.setSelectable(false); 44 45 if (mHeaderController == null) { 46 final LayoutPreference pref = (LayoutPreference) preference; 47 mHeaderController = EntityHeaderController.newInstance( 48 mFragment.getActivity(), 49 mFragment, 50 pref.findViewById(R.id.entity_header)); 51 } 52 53 FutureUtil.whenDone( 54 zenMode.getIcon(mContext, IconLoader.getInstance()), 55 icon -> mHeaderController.setIcon(IconUtil.applyTint(mContext, icon)) 56 .done(/* rebindActions= */ false), 57 mContext.getMainExecutor()); 58 } 59 } 60