• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2025 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.settingslib.metadata
18 
19 import android.content.Context
20 
21 /** Returns the preference screen title. */
getPreferenceScreenTitlenull22 fun PreferenceScreenMetadata.getPreferenceScreenTitle(context: Context): CharSequence? =
23     when {
24         screenTitle != 0 -> context.getString(screenTitle)
25         else -> getScreenTitle(context) ?: (this as? PreferenceTitleProvider)?.getTitle(context)
26     }
27 
28 /** Returns the preference title. */
getPreferenceTitlenull29 fun PreferenceMetadata.getPreferenceTitle(context: Context): CharSequence? =
30     when {
31         title != 0 -> context.getText(title)
32         this is PreferenceTitleProvider -> getTitle(context)
33         else -> null
34     }
35 
36 /** Returns the preference summary. */
getPreferenceSummarynull37 fun PreferenceMetadata.getPreferenceSummary(context: Context): CharSequence? =
38     when {
39         summary != 0 -> context.getText(summary)
40         this is PreferenceSummaryProvider -> getSummary(context)
41         else -> null
42     }
43 
44 /** Returns the preference icon. */
PreferenceMetadatanull45 fun PreferenceMetadata.getPreferenceIcon(context: Context): Int =
46     when {
47         icon != 0 -> icon
48         this is PreferenceIconProvider -> getIcon(context)
49         else -> 0
50     }
51