1 /**
2  * Copyright (C) 2023 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.regionalpreferences;
18 
19 import android.content.Context;
20 import android.content.Intent;
21 import android.util.Log;
22 
23 import androidx.annotation.VisibleForTesting;
24 import androidx.preference.PreferenceScreen;
25 
26 import com.android.settings.R;
27 import com.android.settings.core.BasePreferenceController;
28 import com.android.settingslib.HelpUtils;
29 import com.android.settingslib.widget.FooterPreference;
30 
31 /**
32  * Preference controller for regional preference footer.
33  */
34 public class RegionalFooterPreferenceController extends BasePreferenceController {
35 
36     private static final String TAG = "RegionalFooterPreferenceController";
37 
RegionalFooterPreferenceController(Context context, String preferenceKey)38     public RegionalFooterPreferenceController(Context context, String preferenceKey) {
39         super(context, preferenceKey);
40     }
41 
42     @Override
getAvailabilityStatus()43     public int getAvailabilityStatus() {
44         return AVAILABLE_UNSEARCHABLE;
45     }
46 
47     @Override
displayPreference(PreferenceScreen screen)48     public void displayPreference(PreferenceScreen screen) {
49         super.displayPreference(screen);
50         FooterPreference footerPreference = screen.findPreference(getPreferenceKey());
51         setupFooterPreference(footerPreference);
52     }
53 
54     @VisibleForTesting
setupFooterPreference(FooterPreference footerPreference)55     void setupFooterPreference(FooterPreference footerPreference) {
56         if (footerPreference != null) {
57             footerPreference.setLearnMoreAction(v -> openLocaleLearnMoreLink());
58             footerPreference.setLearnMoreText(mContext.getString(
59                     R.string.desc_regional_pref_footer_learn_more));
60         }
61     }
62 
openLocaleLearnMoreLink()63     private void openLocaleLearnMoreLink() {
64         Intent intent = HelpUtils.getHelpIntent(
65                 mContext,
66                 mContext.getString(R.string.regional_pref_footer_learn_more_link),
67                 mContext.getClass().getName());
68         if (intent != null) {
69             mContext.startActivity(intent);
70         } else {
71             Log.w(TAG, "HelpIntent is null");
72         }
73     }
74 }
75