diff options
author | Heemin Seog <hseog@google.com> | 2019-05-06 19:56:07 +0000 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2019-05-06 19:56:07 +0000 |
commit | 36454356ed1256745041705d33fe6493fb121aaf (patch) | |
tree | 465bfe06961a9d03f8f01dec01080ee9d45fbc19 | |
parent | 21141655e400e4edd11b4cb108863c5c3f828d1b (diff) | |
parent | 5312a66d761666a67f5e75012638e398ccffeeb1 (diff) | |
download | android_packages_apps_PackageInstaller-36454356ed1256745041705d33fe6493fb121aaf.tar.gz android_packages_apps_PackageInstaller-36454356ed1256745041705d33fe6493fb121aaf.tar.bz2 android_packages_apps_PackageInstaller-36454356ed1256745041705d33fe6493fb121aaf.zip |
Merge "Theme secondary default app picker screen for car settings" into qt-dev
6 files changed, 198 insertions, 9 deletions
diff --git a/res/values/strings.xml b/res/values/strings.xml index 6129a0d9..bc469f08 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -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> diff --git a/res/values/themes.xml b/res/values/themes.xml index 848cd78a..1f064bda 100644 --- a/res/values/themes.xml +++ b/res/values/themes.xml @@ -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> diff --git a/src/com/android/packageinstaller/role/ui/DefaultAppActivity.java b/src/com/android/packageinstaller/role/ui/DefaultAppActivity.java index 502a87a7..8c905f58 100644 --- a/src/com/android/packageinstaller/role/ui/DefaultAppActivity.java +++ b/src/com/android/packageinstaller/role/ui/DefaultAppActivity.java @@ -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(); diff --git a/src/com/android/packageinstaller/role/ui/auto/AutoDefaultAppFragment.java b/src/com/android/packageinstaller/role/ui/auto/AutoDefaultAppFragment.java new file mode 100644 index 00000000..daa3456b --- /dev/null +++ b/src/com/android/packageinstaller/role/ui/auto/AutoDefaultAppFragment.java @@ -0,0 +1,104 @@ +/* + * 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() { + } +} diff --git a/src/com/android/packageinstaller/role/ui/auto/AutoDefaultAppPreference.java b/src/com/android/packageinstaller/role/ui/auto/AutoDefaultAppPreference.java new file mode 100644 index 00000000..0eba6b4e --- /dev/null +++ b/src/com/android/packageinstaller/role/ui/auto/AutoDefaultAppPreference.java @@ -0,0 +1,72 @@ +/* + * 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); + } + } +} diff --git a/src/com/android/packageinstaller/role/ui/auto/AutoSettingsPreference.java b/src/com/android/packageinstaller/role/ui/auto/AutoSettingsPreference.java index 56e16a63..dec66186 100644 --- a/src/com/android/packageinstaller/role/ui/auto/AutoSettingsPreference.java +++ b/src/com/android/packageinstaller/role/ui/auto/AutoSettingsPreference.java @@ -50,6 +50,5 @@ public class AutoSettingsPreference extends TwoTargetPreference { @Override public void setOnSecondTargetClickListener(@Nullable OnSecondTargetClickListener listener) { - return; } } |