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

Commit 5d5416be authored by tom hsu's avatar tom hsu Committed by Automerger Merge Worker
Browse files

[Panlingual] Improve and refactor revamped UI am: 213b3ce4

parents a31477d5 213b3ce4
Loading
Loading
Loading
Loading

res/layout/app_locale_picker.xml

deleted100644 → 0
+0 −33
Original line number Diff line number Diff line
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (C) 2022 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.
-->

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:id="@+id/app_locale_detail_container"
    android:orientation="vertical">

    <FrameLayout
        android:id="@+id/app_locale_detail"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"/>

    <FrameLayout
        android:id="@+id/app_locale_picker_with_region"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"/>

</LinearLayout>
 No newline at end of file
+3 −0
Original line number Diff line number Diff line
@@ -37,4 +37,7 @@

    <!-- For a menu item allowing users to edit a SIM display name -->
    <item type="id" name="edit_sim_name" />

    <!-- For a layout container to add AppLocaleDetails into -->
    <item type="id" name="layout_app_locale_details" />
</resources>
+52 −19
Original line number Diff line number Diff line
@@ -18,12 +18,16 @@ package com.android.settings.localepicker;

import android.app.FragmentTransaction;
import android.app.LocaleManager;
import android.net.Uri;
import android.os.Bundle;
import android.os.LocaleList;
import android.text.TextUtils;
import android.util.Log;
import android.view.MenuItem;
import android.view.View;
import android.widget.FrameLayout;

import com.android.internal.annotations.VisibleForTesting;
import com.android.internal.app.LocalePickerWithRegion;
import com.android.internal.app.LocaleStore;
import com.android.settings.R;
@@ -39,11 +43,19 @@ public class AppLocalePickerActivity extends SettingsBaseActivity
    private static final String TAG = AppLocalePickerActivity.class.getSimpleName();

    private String mPackageName;
    private LocalePickerWithRegion mLocalePickerWithRegion;
    private AppLocaleDetails mAppLocaleDetails;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        mPackageName = getIntent().getData().getSchemeSpecificPart();
        Uri data = getIntent().getData();
        if (data == null) {
            Log.d(TAG, "There is no uri data.");
            finish();
            return;
        }
        mPackageName = data.getSchemeSpecificPart();
        if (TextUtils.isEmpty(mPackageName)) {
            Log.d(TAG, "There is no package name.");
            finish();
@@ -51,25 +63,13 @@ public class AppLocalePickerActivity extends SettingsBaseActivity
        }

        getActionBar().setDisplayHomeAsUpEnabled(true);
        setContentView(R.layout.app_locale_picker);

        // Create App locale info detail part.
        AppLocaleDetails appLocaleDetails = AppLocaleDetails.newInstance(mPackageName);
        getSupportFragmentManager()
                .beginTransaction()
                .replace(R.id.app_locale_detail, appLocaleDetails)
                .commit();
        mLocalePickerWithRegion = LocalePickerWithRegion.createLanguagePicker(
                this, AppLocalePickerActivity.this, false /* translate only */, mPackageName);
        mAppLocaleDetails = AppLocaleDetails.newInstance(mPackageName);

        // Create Locale picker part.
        final LocalePickerWithRegion selector = LocalePickerWithRegion.createLanguagePicker(
                this, AppLocalePickerActivity.this, false /* translate only */);
        // LocalePickerWithRegion use android.app.ListFragment. Thus, it can not user
        // getSupportFragmentManager() to add this into container.
        getFragmentManager()
                .beginTransaction()
                .setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN)
                .replace(R.id.app_locale_picker_with_region, selector)
                .commit();
        // Launch Locale picker part.
        launchLocalePickerPage();
    }

    @Override
@@ -114,5 +114,38 @@ public class AppLocalePickerActivity extends SettingsBaseActivity
        }
        localeManager.setApplicationLocales(mPackageName, LocaleList.forLanguageTags(languageTag));
    }

    private View launchAppLocaleDetailsPage() {
        FrameLayout appLocaleDetailsContainer = new FrameLayout(this);
        appLocaleDetailsContainer.setId(R.id.layout_app_locale_details);
        getSupportFragmentManager()
                .beginTransaction()
                .replace(R.id.layout_app_locale_details, mAppLocaleDetails)
                .commit();
        return appLocaleDetailsContainer;
    }

    @VisibleForTesting
    void launchLocalePickerPage() {
        // LocalePickerWithRegion use android.app.ListFragment. Thus, it can not use
        // getSupportFragmentManager() to add this into container.
        android.app.FragmentManager fragmentManager = getFragmentManager();
        fragmentManager.registerFragmentLifecycleCallbacks(
                new android.app.FragmentManager.FragmentLifecycleCallbacks() {
                @Override
                public void onFragmentViewCreated(
                        android.app.FragmentManager fm,
                        android.app.Fragment f,
                        View v,
                        Bundle savedInstanceState) {
                    super.onFragmentViewCreated(fm, f, v, savedInstanceState);
                    mLocalePickerWithRegion
                        .getListView().addHeaderView(launchAppLocaleDetailsPage());
                }
            }, true);
        fragmentManager.beginTransaction()
                .setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN)
                .replace(R.id.content_frame, mLocalePickerWithRegion)
                .commit();
    }
}