From 5eecd8698273b39e10b0054a9c3228186be92538 Mon Sep 17 00:00:00 2001 From: Zoey Chen Date: Mon, 10 Apr 2023 09:12:33 +0000 Subject: [PATCH] [Regional Pref] Add footer in Regional preference page Bug: 277436632 Test: local test Change-Id: I596f440696830374225d9b56fb8c4f0d5d5d5d61 --- res/values/strings.xml | 6 ++ res/xml/regional_preference_main_page.xml | 7 ++ .../LocaleHelperPreferenceController.java | 16 ++-- .../RegionalFooterPreferenceController.java | 74 +++++++++++++++++++ ...egionalFooterPreferenceControllerTest.java | 62 ++++++++++++++++ 5 files changed, 160 insertions(+), 5 deletions(-) create mode 100644 src/com/android/settings/regionalpreferences/RegionalFooterPreferenceController.java create mode 100644 tests/unit/src/com/android/settings/regionalpreferences/RegionalFooterPreferenceControllerTest.java diff --git a/res/values/strings.xml b/res/values/strings.xml index 844d8cea6fb..a67c713bfdc 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -427,6 +427,12 @@ Friday Saturday + + If an app doesn’t support regional preferences, the app will use its default locale settings. + + Learn more about language preferences. + + https://support.google.com/android {count, plural, diff --git a/res/xml/regional_preference_main_page.xml b/res/xml/regional_preference_main_page.xml index de9d3d8e00d..27a1d83818c 100644 --- a/res/xml/regional_preference_main_page.xml +++ b/res/xml/regional_preference_main_page.xml @@ -66,4 +66,11 @@ android:value="arg_value_language_select" /> + + diff --git a/src/com/android/settings/localepicker/LocaleHelperPreferenceController.java b/src/com/android/settings/localepicker/LocaleHelperPreferenceController.java index 05c740139cc..a639c9d297a 100644 --- a/src/com/android/settings/localepicker/LocaleHelperPreferenceController.java +++ b/src/com/android/settings/localepicker/LocaleHelperPreferenceController.java @@ -17,6 +17,8 @@ package com.android.settings.localepicker; import android.content.Context; +import android.content.Intent; +import android.util.Log; import androidx.annotation.VisibleForTesting; import androidx.preference.PreferenceScreen; @@ -65,10 +67,14 @@ public class LocaleHelperPreferenceController extends AbstractPreferenceControll } private void openLocaleLearnMoreLink() { - mContext.startActivity( - HelpUtils.getHelpIntent( - mContext, - mContext.getString(R.string.link_locale_picker_footer_learn_more), - /*backupContext=*/"")); + Intent intent = HelpUtils.getHelpIntent( + mContext, + mContext.getString(R.string.link_locale_picker_footer_learn_more), + mContext.getClass().getName()); + if (intent != null) { + mContext.startActivity(intent); + } else { + Log.w(TAG, "HelpIntent is null"); + } } } diff --git a/src/com/android/settings/regionalpreferences/RegionalFooterPreferenceController.java b/src/com/android/settings/regionalpreferences/RegionalFooterPreferenceController.java new file mode 100644 index 00000000000..6ba9d187032 --- /dev/null +++ b/src/com/android/settings/regionalpreferences/RegionalFooterPreferenceController.java @@ -0,0 +1,74 @@ +/** + * Copyright (C) 2023 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.settings.regionalpreferences; + +import android.content.Context; +import android.content.Intent; +import android.util.Log; + +import androidx.annotation.VisibleForTesting; +import androidx.preference.PreferenceScreen; + +import com.android.settings.R; +import com.android.settings.core.BasePreferenceController; +import com.android.settingslib.HelpUtils; +import com.android.settingslib.widget.FooterPreference; + +/** + * Preference controller for regional preference footer. + */ +public class RegionalFooterPreferenceController extends BasePreferenceController { + + private static final String TAG = "RegionalFooterPreferenceController"; + + public RegionalFooterPreferenceController(Context context, String preferenceKey) { + super(context, preferenceKey); + } + + @Override + public int getAvailabilityStatus() { + return AVAILABLE_UNSEARCHABLE; + } + + @Override + public void displayPreference(PreferenceScreen screen) { + super.displayPreference(screen); + FooterPreference footerPreference = screen.findPreference(getPreferenceKey()); + setupFooterPreference(footerPreference); + } + + @VisibleForTesting + void setupFooterPreference(FooterPreference footerPreference) { + if (footerPreference != null) { + footerPreference.setLearnMoreAction(v -> openLocaleLearnMoreLink()); + footerPreference.setLearnMoreText(mContext.getString( + R.string.desc_regional_pref_footer_learn_more)); + } + } + + private void openLocaleLearnMoreLink() { + Intent intent = HelpUtils.getHelpIntent( + mContext, + mContext.getString(R.string.regional_pref_footer_learn_more_link), + mContext.getClass().getName()); + if (intent != null) { + mContext.startActivity(intent); + } else { + Log.w(TAG, "HelpIntent is null"); + } + } +} diff --git a/tests/unit/src/com/android/settings/regionalpreferences/RegionalFooterPreferenceControllerTest.java b/tests/unit/src/com/android/settings/regionalpreferences/RegionalFooterPreferenceControllerTest.java new file mode 100644 index 00000000000..f0197931f04 --- /dev/null +++ b/tests/unit/src/com/android/settings/regionalpreferences/RegionalFooterPreferenceControllerTest.java @@ -0,0 +1,62 @@ +/** + * Copyright (C) 2023 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.settings.regionalpreferences; + +import static org.mockito.Mockito.anyString; +import static org.mockito.Mockito.verify; + +import android.content.Context; +import android.os.Looper; + +import androidx.test.core.app.ApplicationProvider; +import androidx.test.ext.junit.runners.AndroidJUnit4; + +import com.android.settingslib.widget.FooterPreference; + +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Mock; +import org.mockito.MockitoAnnotations; + +@RunWith(AndroidJUnit4.class) +public class RegionalFooterPreferenceControllerTest { + + private static String KEY_FOOTER_PREFERENCE = "regional_pref_footer"; + private Context mContext; + private RegionalFooterPreferenceController mRegionalFooterPreferenceController; + + @Mock + private FooterPreference mMockFooterPreference; + + @Before + public void setUp() { + MockitoAnnotations.initMocks(this); + if (Looper.myLooper() == null) { + Looper.prepare(); + } + mContext = ApplicationProvider.getApplicationContext(); + mRegionalFooterPreferenceController = new RegionalFooterPreferenceController(mContext, + KEY_FOOTER_PREFERENCE); + } + + @Test + public void setupFooterPreference_shouldSetAsTextInLearnMore() { + mRegionalFooterPreferenceController.setupFooterPreference(mMockFooterPreference); + verify(mMockFooterPreference).setLearnMoreText(anyString()); + } +}