Merge "[Regional Pref] Add footer in Regional preference page" into udc-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
d81b473fe0
@@ -427,6 +427,12 @@
|
||||
<string name="friday_first_day_of_week">Friday</string>
|
||||
<!-- The title of saturday for preference of first day of week. [CHAR LIMIT=50] -->
|
||||
<string name="saturday_first_day_of_week">Saturday</string>
|
||||
<!-- Title for regional preference footer. [CHAR LIMIT=NONE] -->
|
||||
<string name="title_regional_pref_footer">If an app doesn’t support regional preferences, the app will use its default locale settings.</string>
|
||||
<!-- Description for text in regional preference footer. [CHAR LIMIT=NONE] -->
|
||||
<string name="desc_regional_pref_footer_learn_more">Learn more about language preferences.</string>
|
||||
<!-- TODO(b/277573274): Update the learn more url in the regional preference. -->
|
||||
<string name="regional_pref_footer_learn_more_link" translatable="false">https://support.google.com/android</string>
|
||||
|
||||
<!-- The title of the confirmation dialog shown when the user selects one / several languages and tries to remove them [CHAR LIMIT=60] -->
|
||||
<string name="dlg_remove_locales_title">{count, plural,
|
||||
|
@@ -66,4 +66,11 @@
|
||||
android:value="arg_value_language_select" />
|
||||
</Preference>
|
||||
|
||||
<com.android.settingslib.widget.FooterPreference
|
||||
android:key="regional_pref_footer"
|
||||
android:title="@string/title_regional_pref_footer"
|
||||
android:selectable="false"
|
||||
settings:searchable="false"
|
||||
settings:controller="com.android.settings.regionalpreferences.RegionalFooterPreferenceController"/>
|
||||
|
||||
</PreferenceScreen>
|
||||
|
@@ -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(
|
||||
Intent intent = HelpUtils.getHelpIntent(
|
||||
mContext,
|
||||
mContext.getString(R.string.link_locale_picker_footer_learn_more),
|
||||
/*backupContext=*/""));
|
||||
mContext.getClass().getName());
|
||||
if (intent != null) {
|
||||
mContext.startActivity(intent);
|
||||
} else {
|
||||
Log.w(TAG, "HelpIntent is null");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -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");
|
||||
}
|
||||
}
|
||||
}
|
@@ -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());
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user