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 import android.content.res.TypedArray; 21 import android.util.Log; 22 23 import androidx.annotation.DrawableRes; 24 import androidx.annotation.NonNull; 25 26 import com.android.settings.R; 27 28 import com.google.common.collect.ImmutableList; 29 30 class IconOptionsProviderImpl implements IconOptionsProvider { 31 32 private static final String TAG = "IconOptionsProviderImpl"; 33 34 private final Context mContext; 35 IconOptionsProviderImpl(Context context)36 IconOptionsProviderImpl(Context context) { 37 mContext = context.getApplicationContext(); 38 } 39 40 @Override 41 @NonNull getIcons()42 public ImmutableList<IconInfo> getIcons() { 43 ImmutableList.Builder<IconInfo> list = ImmutableList.builder(); 44 try (TypedArray icons = mContext.getResources().obtainTypedArray( 45 R.array.zen_mode_icon_options)) { 46 String[] descriptions = mContext.getResources().getStringArray( 47 R.array.zen_mode_icon_options_descriptions); 48 if (icons.length() != descriptions.length) { 49 Log.wtf(TAG, "Size mismatch between zen_mode_icon_options (" + icons.length() 50 + ") and zen_mode_icon_options_descriptions (" + descriptions.length + ")"); 51 } 52 53 for (int i = 0; i < Math.min(icons.length(), descriptions.length); i++) { 54 @DrawableRes int resId = icons.getResourceId(i, 0); 55 if (resId != 0) { 56 list.add(new IconInfo(resId, descriptions[i])); 57 } 58 } 59 } 60 return list.build(); 61 } 62 } 63