Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 5eecd869 authored by Zoey Chen's avatar Zoey Chen
Browse files

[Regional Pref] Add footer in Regional preference page

Bug: 277436632
Test: local test
Change-Id: I596f440696830374225d9b56fb8c4f0d5d5d5d61
parent 11648c70
Loading
Loading
Loading
Loading
+6 −0
Original line number Diff line number Diff line
@@ -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,
+7 −0
Original line number Diff line number Diff line
@@ -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>
+11 −5
Original line number Diff line number Diff line
@@ -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");
        }
    }
}
+74 −0
Original line number Diff line number Diff line
/**
 * 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");
        }
    }
}
+62 −0
Original line number Diff line number Diff line
/**
 * 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());
    }
}