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

Commit 5312a66d authored by Heemin Seog's avatar Heemin Seog
Browse files

Theme secondary default app picker screen for car settings

One major difference is that car settings doesn't use radio buttons.
Instead it uses "Selected" string in the summary field to denote the
default app.

For (system apps)s, the text will appear as "Selected - (System app)"

Bug: 130348508
Test: manual
Change-Id: Iac2e45add29cd923b77c685064aa0d5d65e39965
parent ead4dfd1
Loading
Loading
Loading
Loading
+6 −0
Original line number Diff line number Diff line
@@ -765,6 +765,12 @@
    <!-- Label when there are no apps available for a default app [CHAR LIMIT=30] -->
    <string name="default_app_no_apps">No apps</string>

    <!-- Label for the selected default app for default app [CHAR LIMIT=30] -->
    <string name="car_default_app_selected">Selected</string>

    <!-- Label for the selected default app for default app when it has additional information to show [CHAR LIMIT=30] -->
    <string name="car_default_app_selected_with_info">Selected - <xliff:g id="additional_info" example="(System default)">%1$s</xliff:g></string>

    <!-- Keyword in the Settings app's search functionality that can be used to find links to the special app access management screens [CHAR LIMIT=none] -->
    <string name="special_app_access_search_keyword">special app access</string>

+1 −6
Original line number Diff line number Diff line
@@ -23,11 +23,6 @@
        <item name="preferenceCategoryTitleTextAppearance">@style/TextAppearance.CategoryTitle</item>
    </style>

    <style name="Settings.NoActionBar" parent="Settings">
        <item name="android:windowActionBar">false</item>
        <item name="android:windowNoTitle">true</item>
    </style>

    <style name="TextAppearance.CategoryTitle"
           parent="@android:style/TextAppearance.DeviceDefault.Medium">
        <item name="android:textAllCaps">true</item>
@@ -84,7 +79,7 @@
           parent="@android:style/Theme.DeviceDefault.Light.Dialog.NoActionBar">
    </style>

    <style name="CarSettings" parent="Settings.NoActionBar">
    <style name="CarSettings" parent="@android:style/Theme.DeviceDefault.NoActionBar">
        <item name="preferenceTheme">@style/CarPreferenceTheme</item>
        <item name="carDividerColor">@*android:color/car_list_divider</item>
    </style>
+15 −2
Original line number Diff line number Diff line
@@ -26,11 +26,15 @@ import android.view.WindowManager;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentActivity;

import com.android.packageinstaller.DeviceUtils;
import com.android.packageinstaller.role.model.Role;
import com.android.packageinstaller.role.model.Roles;
import com.android.packageinstaller.role.ui.auto.AutoDefaultAppFragment;
import com.android.packageinstaller.role.ui.handheld.HandheldDefaultAppFragment;
import com.android.permissioncontroller.R;

/**
 * Activity for a default app.
@@ -58,6 +62,11 @@ public class DefaultAppActivity extends FragmentActivity {

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        if (DeviceUtils.isAuto(this)) {
            // Automotive relies on a different theme. Apply before calling super so that
            // fragments are restored properly on configuration changes.
            setTheme(R.style.CarSettings);
        }
        super.onCreate(savedInstanceState);

        getWindow().addSystemFlags(
@@ -89,8 +98,12 @@ public class DefaultAppActivity extends FragmentActivity {
        }

        if (savedInstanceState == null) {
            HandheldDefaultAppFragment fragment = HandheldDefaultAppFragment.newInstance(roleName,
                    user);
            Fragment fragment;
            if (DeviceUtils.isAuto(this)) {
                fragment = AutoDefaultAppFragment.newInstance(roleName, user);
            } else {
                fragment = HandheldDefaultAppFragment.newInstance(roleName, user);
            }
            getSupportFragmentManager().beginTransaction()
                    .add(android.R.id.content, fragment)
                    .commit();
+104 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2019 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.packageinstaller.role.ui.auto;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.os.UserHandle;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.preference.Preference;
import androidx.preference.TwoStatePreference;

import com.android.packageinstaller.role.model.Role;
import com.android.packageinstaller.role.ui.DefaultAppChildFragment;
import com.android.permissioncontroller.R;

/** Screen to pick a default app for a particular {@link Role}. */
public class AutoDefaultAppFragment extends DefaultAppFrameFragment implements
        DefaultAppChildFragment.Parent {

    private String mRoleName;

    private UserHandle mUser;

    /**
     * Create a new instance of this fragment.
     *
     * @param roleName the name of the role for the default app
     * @param user     the user for the default app
     * @return a new instance of this fragment
     */
    @NonNull
    public static AutoDefaultAppFragment newInstance(@NonNull String roleName,
            @NonNull UserHandle user) {
        AutoDefaultAppFragment fragment = new AutoDefaultAppFragment();
        Bundle arguments = new Bundle();
        arguments.putString(Intent.EXTRA_ROLE_NAME, roleName);
        arguments.putParcelable(Intent.EXTRA_USER, user);
        fragment.setArguments(arguments);
        return fragment;
    }

    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        Bundle arguments = getArguments();
        mRoleName = arguments.getString(Intent.EXTRA_ROLE_NAME);
        mUser = arguments.getParcelable(Intent.EXTRA_USER);
    }

    @Override
    public void onActivityCreated(@Nullable Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);

        if (savedInstanceState == null) {
            DefaultAppChildFragment fragment = DefaultAppChildFragment.newInstance(mRoleName,
                    mUser);
            getChildFragmentManager().beginTransaction()
                    .add(fragment, null)
                    .commit();
        }
    }

    @Override
    public void setTitle(@NonNull CharSequence title) {
        setHeaderLabel(title);
    }

    @NonNull
    @Override
    public TwoStatePreference createApplicationPreference(@NonNull Context context) {
        return new AutoDefaultAppPreference(context);
    }

    @NonNull
    @Override
    public Preference createFooterPreference(@NonNull Context context) {
        Preference preference = new Preference(context);
        preference.setIcon(R.drawable.ic_info_outline);
        preference.setSelectable(false);
        return preference;
    }

    @Override
    public void onPreferenceScreenChanged() {
    }
}
+72 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2019 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.packageinstaller.role.ui.auto;

import android.content.Context;
import android.text.TextUtils;
import android.util.AttributeSet;
import android.view.View;
import android.widget.TextView;

import androidx.preference.PreferenceViewHolder;
import androidx.preference.TwoStatePreference;

import com.android.permissioncontroller.R;

/** Preference used to represent apps that can be picked as a default app. */
public class AutoDefaultAppPreference extends TwoStatePreference {

    public AutoDefaultAppPreference(Context context, AttributeSet attrs,
            int defStyleAttr, int defStyleRes) {
        super(context, attrs, defStyleAttr, defStyleRes);
    }

    public AutoDefaultAppPreference(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

    public AutoDefaultAppPreference(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    public AutoDefaultAppPreference(Context context) {
        super(context);
    }

    @Override
    public void onBindViewHolder(PreferenceViewHolder holder) {
        super.onBindViewHolder(holder);

        TextView summaryView = (TextView) holder.findViewById(android.R.id.summary);
        if (summaryView == null) {
            return;
        }

        if (isChecked()) {
            CharSequence current = getSummary();
            CharSequence selected = getContext().getString(R.string.car_default_app_selected);
            if (!TextUtils.isEmpty(current)) {
                selected = getContext().getString(R.string.car_default_app_selected_with_info,
                        current);
            }
            summaryView.setText(selected);
            summaryView.setVisibility(View.VISIBLE);
        } else {
            summaryView.setVisibility(View.GONE);
        }
    }
}
Loading