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

Commit d53777f9 authored by danielwbhuang's avatar danielwbhuang
Browse files

Use flag to control the hierarchy tree changes

This change includes these:
Regional preferences
-Temperature
-First day of week
-Numbering system
-Footer preference

Bug: 379962955
Flag: com.android.settings.flags.regional_preferences_api_enabled
Test: check hsv and atest FirstDayOfWeekControllerTest, NumberingSystemControllerTest, TemperatureUnitControllerTest
Change-Id: Icb628640c05f1f4bb974416c35dce16a14f84a6c
parent 9571a0d3
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -480,6 +480,8 @@
    <string name="regional_preferences_main_page_sub_title">Let apps know your regional preferences so they can personalize your experience.</string>
    <!-- The subtitle of option's page of regional preferences for Temperature units, Calendar and First day of week. [CHAR LIMIT=NONE] -->
    <string name="regional_preferences_option_page_sub_title">Apps will use your regional preferences where possible.</string>
    <!-- Category for the regional preferences. [CHAR LIMIT=NONE]-->
    <string name="regional_preferences_category_title">Regional preferences</string>
    <!-- The title of menu entry of Temperature unit preference. [CHAR LIMIT=50] -->
    <string name="temperature_preferences_title">Temperature</string>
    <!-- The title of the  menu entry of First day of week preference. [CHAR LIMIT=50]  -->
+46 −0
Original line number Diff line number Diff line
@@ -48,6 +48,45 @@

    </PreferenceCategory>

    <PreferenceCategory
        android:key="regional_preferences_category"
        android:title="@string/regional_preferences_category_title"
        settings:controller="com.android.settings.regionalpreferences.RegionalPreferencesCategoryController">

        <Preference
            android:key="temperature_preference"
            android:title="@string/temperature_preferences_title"
            android:summary="@string/default_string_of_regional_preference"
            settings:controller="com.android.settings.regionalpreferences.NewTemperatureUnitController"
            settings:fragment="com.android.settings.regionalpreferences.TemperatureUnitFragment">
            <extra
                android:name="arg_key_regional_preference"
                android:value="mu"/>
        </Preference>

        <Preference
            android:key="first_day_of_week_preference"
            android:title="@string/first_day_of_week_preferences_title"
            android:summary="@string/default_string_of_regional_preference"
            settings:controller="com.android.settings.regionalpreferences.NewFirstDayOfWeekController"
            settings:fragment="com.android.settings.regionalpreferences.FirstDayOfWeekItemFragment">
            <extra
                android:name="arg_key_regional_preference"
                android:value="fw"/>
        </Preference>

        <Preference
            android:key="numbering_system_preference"
            android:title="@string/numbers_preferences_title"
            android:summary="@string/default_string_of_regional_preference"
            settings:controller="com.android.settings.regionalpreferences.NewNumberingSystemController"
            settings:fragment="com.android.settings.regionalpreferences.NumberingPreferencesFragment">
            <extra
                android:name="arg_key_regional_preference"
                android:value="arg_value_language_select"/>
        </Preference>
    </PreferenceCategory>

    <PreferenceCategory
        android:key="speech_category"
        android:title="@string/speech_category_title">
@@ -69,4 +108,11 @@
            android:fragment="com.android.settings.tts.TextToSpeechSettings"
            settings:searchable="false"/>
    </PreferenceCategory>

    <com.android.settingslib.widget.FooterPreference
        android:key="new_regional_pref_footer"
        android:title="@string/title_regional_pref_footer"
        android:selectable="false"
        settings:searchable="false"
        settings:controller="com.android.settings.regionalpreferences.NewRegionalFooterPreferenceController"/>
</PreferenceScreen>
+74 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2024 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.provider.Settings;

import androidx.annotation.NonNull;
import androidx.core.text.util.LocalePreferences;

import com.android.settings.R;
import com.android.settings.core.BasePreferenceController;
import com.android.settings.flags.Flags;

import java.util.Locale;

/** A controller for the entry of First Day of Week's page */
public class NewFirstDayOfWeekController extends BasePreferenceController {

    public NewFirstDayOfWeekController(@NonNull Context context, @NonNull String preferenceKey) {
        super(context, preferenceKey);
    }

    /**
     * @return {@link AvailabilityStatus} for the Setting. This status is used to determine if the
     * Setting should be shown or disabled in Settings. Further, it can be used to produce
     * appropriate error / warning Slice in the case of unavailability.
     * </p>
     * The status is used for the convenience methods: {@link #isAvailable()}, {@link
     * #isSupported()}
     * </p>
     * The inherited class doesn't need to check work profile if android:forWork="true" is set in
     * preference xml.
     */
    @Override
    public int getAvailabilityStatus() {
        if (Flags.regionalPreferencesApiEnabled()) {
            return AVAILABLE;
        }
        return CONDITIONALLY_UNAVAILABLE;
    }

    @Override
    @NonNull
    public CharSequence getSummary() {
        String record = Settings.System.getString(
                mContext.getContentResolver(), Settings.System.LOCALE_PREFERENCES);
        String result = "";
        if (record != null) {
            result = LocalePreferences.getFirstDayOfWeek(Locale.forLanguageTag(record), false);
        }

        if (result.isEmpty()) {
            result = LocalePreferences.getFirstDayOfWeek(false);
        }
        return result.isEmpty()
            ? mContext.getString(R.string.default_string_of_regional_preference)
            : RegionalPreferencesDataUtils.dayConverter(mContext, result);
    }
}
+89 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2024 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.os.LocaleList;

import androidx.annotation.NonNull;

import com.android.internal.app.LocaleStore;
import com.android.settings.core.BasePreferenceController;
import com.android.settings.flags.Flags;
import com.android.settings.localepicker.LocaleFeatureProviderImpl;

import java.util.HashSet;
import java.util.Locale;
import java.util.Set;

/** A controller for the entry of Numbering System's page */
public class NewNumberingSystemController extends BasePreferenceController {
    private static final String TAG = NewNumberingSystemController.class.getSimpleName();

    private LocaleList mLocaleList;
    public NewNumberingSystemController(@NonNull Context context, @NonNull String preferenceKey) {
        super(context, preferenceKey);
        // Initialize the supported languages to LocaleInfos
        LocaleStore.fillCache(context);
        mLocaleList = getNumberingSystemLocale();
    }

    /**
     * @return {@link AvailabilityStatus} for the Setting. This status is used to determine if the
     * Setting should be shown or disabled in Settings. Further, it can be used to produce
     * appropriate error / warning Slice in the case of unavailability.
     * </p>
     * The status is used for the convenience methods: {@link #isAvailable()}, {@link
     * #isSupported()}
     * </p>
     * The inherited class doesn't need to check work profile if android:forWork="true" is set in
     * preference xml.
     */
    @Override
    public int getAvailabilityStatus() {
        if (Flags.regionalPreferencesApiEnabled()) {
            return mLocaleList.isEmpty() ? CONDITIONALLY_UNAVAILABLE : AVAILABLE;
        }
        return CONDITIONALLY_UNAVAILABLE;
    }

    private static LocaleList getNumberingSystemLocale() {
        LocaleList localeList = LocaleList.getDefault();
        Set<Locale> localesHasNumberingSystems = new HashSet<>();
        for (int i = 0; i < localeList.size(); i++) {
            Locale locale = localeList.get(i);
            LocaleStore.LocaleInfo localeInfo = LocaleStore.getLocaleInfo(locale);
            if (localeInfo.hasNumberingSystems()) {
                localesHasNumberingSystems.add(locale);
            }
        }
        return convertToLocaleList(localesHasNumberingSystems);
    }

    private static LocaleList convertToLocaleList(Set<Locale> locales) {
        if (locales.isEmpty()) {
            return LocaleList.getEmptyLocaleList();
        }
        return new LocaleList(locales.stream().toArray(Locale[]::new));
    }

    @Override
    @NonNull
    public CharSequence getSummary() {
        return new LocaleFeatureProviderImpl().getLocaleNames(getNumberingSystemLocale());
    }
}
+79 −0
Original line number Diff line number Diff line
/**
 * Copyright (C) 2024 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.NonNull;
import androidx.annotation.VisibleForTesting;
import androidx.preference.PreferenceScreen;

import com.android.settings.R;
import com.android.settings.core.BasePreferenceController;
import com.android.settings.flags.Flags;
import com.android.settingslib.HelpUtils;
import com.android.settingslib.widget.FooterPreference;

/**
 * Preference controller for regional preference footer.
 */
public class NewRegionalFooterPreferenceController extends BasePreferenceController {

    private static final String TAG = "NewRegionalFooterPreferenceController";

    public NewRegionalFooterPreferenceController(@NonNull Context context, @NonNull String key) {
        super(context, key);
    }

    @Override
    public int getAvailabilityStatus() {
        if (Flags.regionalPreferencesApiEnabled()) {
            return AVAILABLE_UNSEARCHABLE;
        }
        return CONDITIONALLY_UNAVAILABLE;
    }

    @Override
    public void displayPreference(@NonNull 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");
        }
    }
}
Loading