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 package com.android.settings.notification.modes; 17 18 import android.app.Flags; 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 ZenModeHeaderController extends AbstractZenModePreferenceController { 31 32 private final DashboardFragment mFragment; 33 private EntityHeaderController mHeaderController; 34 ZenModeHeaderController( @onNull Context context, @NonNull String key, @NonNull DashboardFragment fragment, @Nullable ZenModesBackend backend)35 ZenModeHeaderController( 36 @NonNull Context context, 37 @NonNull String key, 38 @NonNull DashboardFragment fragment, 39 @Nullable ZenModesBackend backend) { 40 super(context, key, backend); 41 mFragment = fragment; 42 } 43 44 @Override isAvailable()45 public boolean isAvailable() { 46 return Flags.modesApi(); 47 } 48 49 @Override updateState(Preference preference, @NonNull ZenMode zenMode)50 public void updateState(Preference preference, @NonNull ZenMode zenMode) { 51 if (mFragment == null) { 52 return; 53 } 54 preference.setSelectable(false); 55 56 if (mHeaderController == null) { 57 final LayoutPreference pref = (LayoutPreference) preference; 58 mHeaderController = EntityHeaderController.newInstance( 59 mFragment.getActivity(), 60 mFragment, 61 pref.findViewById(R.id.entity_header)); 62 } 63 64 FutureUtil.whenDone( 65 zenMode.getIcon(mContext, IconLoader.getInstance()), 66 icon -> mHeaderController.setIcon(IconUtil.applyTint(mContext, icon)) 67 .done(/* rebindActions= */ false), 68 mContext.getMainExecutor()); 69 } 70 } 71