summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHeemin Seog <hseog@google.com>2019-04-17 09:12:45 -0700
committerHeemin Seog <hseog@google.com>2019-05-02 15:34:19 -0700
commit91d9ba6744b447bdf95273b4afbec1017ddbd165 (patch)
tree5fd6f779189afd09d1718ad2df69eb04043b4377
parent0d3ea56d8f195852ed59659393df85ef1002d0d6 (diff)
downloadandroid_packages_apps_PackageInstaller-91d9ba6744b447bdf95273b4afbec1017ddbd165.tar.gz
android_packages_apps_PackageInstaller-91d9ba6744b447bdf95273b4afbec1017ddbd165.tar.bz2
android_packages_apps_PackageInstaller-91d9ba6744b447bdf95273b4afbec1017ddbd165.zip
Theme roles to look like Car Settings
Requires some changes to existing code to special case with DeviceUtils.isAuto(). At the activity level, this is consistent with how the permissions screens are set up. Bug: 130348508 Test: manual Change-Id: I323ed0cd2fdf8f7c7c5fd279b13ddb76f8de2697
-rw-r--r--res/layout/car_default_app_frame.xml55
-rw-r--r--res/values/attrs.xml4
-rw-r--r--res/values/dimens.xml5
-rw-r--r--res/values/styles.xml17
-rw-r--r--res/values/themes.xml16
-rw-r--r--src/com/android/packageinstaller/role/ui/DefaultAppListActivity.java16
-rw-r--r--src/com/android/packageinstaller/role/ui/auto/AutoDefaultAppListFragment.java62
-rw-r--r--src/com/android/packageinstaller/role/ui/auto/AutoSettingsPreference.java55
-rw-r--r--src/com/android/packageinstaller/role/ui/auto/DefaultAppFrameFragment.java71
9 files changed, 300 insertions, 1 deletions
diff --git a/res/layout/car_default_app_frame.xml b/res/layout/car_default_app_frame.xml
new file mode 100644
index 00000000..2fe0856e
--- /dev/null
+++ b/res/layout/car_default_app_frame.xml
@@ -0,0 +1,55 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+ Copyright 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.
+-->
+
+<LinearLayout
+ xmlns:android="http://schemas.android.com/apk/res/android"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"
+ android:orientation="vertical">
+ <LinearLayout
+ android:layout_width="match_parent"
+ android:layout_height="@dimen/car_action_bar_height"
+ android:gravity="center_vertical"
+ android:orientation="horizontal">
+ <FrameLayout
+ android:id="@+id/back_button"
+ android:layout_width="@dimen/car_margin"
+ android:layout_height="match_parent">
+ <ImageView
+ android:layout_width="@dimen/car_icon_size"
+ android:layout_height="@dimen/car_icon_size"
+ android:layout_gravity="center"
+ android:scaleType="fitCenter"
+ android:src="@drawable/ic_arrow_back"
+ android:tint="?android:attr/textColorPrimary"/>
+ </FrameLayout>
+
+ <TextView
+ android:id="@+id/label"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:singleLine="true"
+ android:textAppearance="?android:attr/textAppearanceLarge"/>
+ </LinearLayout>
+
+ <FrameLayout
+ android:id="@android:id/list_container"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"
+ android:paddingEnd="@dimen/car_margin"
+ android:paddingStart="@dimen/car_margin"/>
+</LinearLayout>
diff --git a/res/values/attrs.xml b/res/values/attrs.xml
index e220f4c8..f8144d74 100644
--- a/res/values/attrs.xml
+++ b/res/values/attrs.xml
@@ -32,4 +32,8 @@
<attr name="circle_radius_pressed_percent" format="fraction" />
</declare-styleable>
<!-- END: Ported from WearableSupport -->
+
+ <!-- START: Car Settings Preferences -->
+ <attr name="carDividerColor" format="color"/>
+ <!-- END: Car Settings Preferences -->
</resources>
diff --git a/res/values/dimens.xml b/res/values/dimens.xml
index bac131a6..04ec00ce 100644
--- a/res/values/dimens.xml
+++ b/res/values/dimens.xml
@@ -54,4 +54,9 @@
<dimen name="incident_image_width">150dp</dimen>
<dimen name="incident_image_height">200dp</dimen>
+ <!-- Auto related dimensions -->
+ <dimen name="car_action_bar_height">@*android:dimen/car_app_bar_height</dimen>
+ <dimen name="car_margin">@*android:dimen/car_margin</dimen>
+ <dimen name="car_icon_size">@*android:dimen/car_primary_icon_size</dimen>
+
</resources>
diff --git a/res/values/styles.xml b/res/values/styles.xml
index 9da063d7..b8fbc380 100644
--- a/res/values/styles.xml
+++ b/res/values/styles.xml
@@ -858,4 +858,21 @@
<!-- END ACCESSIBILITY SERVICE DIALOG ITEM -->
+ <!-- START CAR SETTINGS PREFERENCE STYLES -->
+
+ <style name="CarPreferenceFragment">
+ <item name="android:layout">@layout/car_default_app_frame</item>
+ </style>
+
+ <style name="CarPreferenceFragmentList">
+ <item name="android:paddingTop">0dp</item>
+ <item name="android:paddingBottom">0dp</item>
+ <item name="android:paddingStart">0dp</item>
+ <item name="android:paddingEnd">0dp</item>
+ <item name="android:paddingLeft">0dp</item>
+ <item name="android:paddingRight">0dp</item>
+ </style>
+
+ <!-- END CAR SETTINGS PREFERENCE STYLES -->
+
</resources>
diff --git a/res/values/themes.xml b/res/values/themes.xml
index 4dd6e326..848cd78a 100644
--- a/res/values/themes.xml
+++ b/res/values/themes.xml
@@ -22,6 +22,12 @@
<item name="preferenceTheme">@style/PreferenceThemeOverlay</item>
<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>
@@ -78,4 +84,14 @@
parent="@android:style/Theme.DeviceDefault.Light.Dialog.NoActionBar">
</style>
+ <style name="CarSettings" parent="Settings.NoActionBar">
+ <item name="preferenceTheme">@style/CarPreferenceTheme</item>
+ <item name="carDividerColor">@*android:color/car_list_divider</item>
+ </style>
+
+ <style name="CarPreferenceTheme">
+ <item name="preferenceFragmentCompatStyle">@style/CarPreferenceFragment</item>
+ <item name="preferenceFragmentListStyle">@style/CarPreferenceFragmentList</item>
+ </style>
+
</resources>
diff --git a/src/com/android/packageinstaller/role/ui/DefaultAppListActivity.java b/src/com/android/packageinstaller/role/ui/DefaultAppListActivity.java
index 15de1786..e312d8d6 100644
--- a/src/com/android/packageinstaller/role/ui/DefaultAppListActivity.java
+++ b/src/com/android/packageinstaller/role/ui/DefaultAppListActivity.java
@@ -20,9 +20,13 @@ import android.os.Bundle;
import android.view.WindowManager;
import androidx.annotation.Nullable;
+import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentActivity;
+import com.android.packageinstaller.DeviceUtils;
+import com.android.packageinstaller.role.ui.auto.AutoDefaultAppListFragment;
import com.android.packageinstaller.role.ui.handheld.HandheldDefaultAppListFragment;
+import com.android.permissioncontroller.R;
/**
* Activity for the list of default apps.
@@ -31,13 +35,23 @@ public class DefaultAppListActivity 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(
WindowManager.LayoutParams.SYSTEM_FLAG_HIDE_NON_SYSTEM_OVERLAY_WINDOWS);
if (savedInstanceState == null) {
- HandheldDefaultAppListFragment fragment = HandheldDefaultAppListFragment.newInstance();
+ Fragment fragment;
+ if (DeviceUtils.isAuto(this)) {
+ fragment = AutoDefaultAppListFragment.newInstance();
+ } else {
+ fragment = HandheldDefaultAppListFragment.newInstance();
+ }
getSupportFragmentManager().beginTransaction()
.add(android.R.id.content, fragment)
.commit();
diff --git a/src/com/android/packageinstaller/role/ui/auto/AutoDefaultAppListFragment.java b/src/com/android/packageinstaller/role/ui/auto/AutoDefaultAppListFragment.java
new file mode 100644
index 00000000..2d6fbacd
--- /dev/null
+++ b/src/com/android/packageinstaller/role/ui/auto/AutoDefaultAppListFragment.java
@@ -0,0 +1,62 @@
+/*
+ * 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.os.Bundle;
+
+import androidx.annotation.NonNull;
+import androidx.annotation.Nullable;
+
+import com.android.packageinstaller.role.ui.DefaultAppListChildFragment;
+import com.android.packageinstaller.role.ui.TwoTargetPreference;
+import com.android.permissioncontroller.R;
+
+/** Shows various roles for which a default app can be picked. */
+public class AutoDefaultAppListFragment extends DefaultAppFrameFragment implements
+ DefaultAppListChildFragment.Parent {
+
+ /** Create a new instance of this fragment. */
+ @NonNull
+ public static AutoDefaultAppListFragment newInstance() {
+ return new AutoDefaultAppListFragment();
+ }
+
+ @Override
+ public void onActivityCreated(@Nullable Bundle savedInstanceState) {
+ super.onActivityCreated(savedInstanceState);
+
+ if (savedInstanceState == null) {
+ DefaultAppListChildFragment fragment = DefaultAppListChildFragment.newInstance();
+ getChildFragmentManager().beginTransaction()
+ .add(fragment, null)
+ .commit();
+ }
+
+ setHeaderLabel(getString(R.string.default_apps));
+ }
+
+ @NonNull
+ @Override
+ public TwoTargetPreference createPreference(@NonNull Context context) {
+ return new AutoSettingsPreference(context);
+ }
+
+ @Override
+ public void onPreferenceScreenChanged() {
+ }
+}
diff --git a/src/com/android/packageinstaller/role/ui/auto/AutoSettingsPreference.java b/src/com/android/packageinstaller/role/ui/auto/AutoSettingsPreference.java
new file mode 100644
index 00000000..56e16a63
--- /dev/null
+++ b/src/com/android/packageinstaller/role/ui/auto/AutoSettingsPreference.java
@@ -0,0 +1,55 @@
+/*
+ * 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.util.AttributeSet;
+
+import androidx.annotation.NonNull;
+import androidx.annotation.Nullable;
+
+import com.android.packageinstaller.role.ui.TwoTargetPreference;
+
+/**
+ * Preference to show default app list. Extends {@link TwoTargetPreference} in order to make sure of
+ * shared logic between phone and auto settings UI.
+ */
+public class AutoSettingsPreference extends TwoTargetPreference {
+
+ public AutoSettingsPreference(@NonNull Context context,
+ @Nullable AttributeSet attrs, int defStyleAttr, int defStyleRes) {
+ super(context, attrs, defStyleAttr, defStyleRes);
+ }
+
+ public AutoSettingsPreference(@NonNull Context context, @Nullable AttributeSet attrs,
+ int defStyleAttr) {
+ super(context, attrs, defStyleAttr);
+ }
+
+ public AutoSettingsPreference(@NonNull Context context, @Nullable AttributeSet attrs) {
+ super(context, attrs);
+ }
+
+ public AutoSettingsPreference(@NonNull Context context) {
+ super(context);
+ }
+
+ @Override
+ public void setOnSecondTargetClickListener(@Nullable OnSecondTargetClickListener listener) {
+ return;
+ }
+}
diff --git a/src/com/android/packageinstaller/role/ui/auto/DefaultAppFrameFragment.java b/src/com/android/packageinstaller/role/ui/auto/DefaultAppFrameFragment.java
new file mode 100644
index 00000000..8733a851
--- /dev/null
+++ b/src/com/android/packageinstaller/role/ui/auto/DefaultAppFrameFragment.java
@@ -0,0 +1,71 @@
+/*
+ * 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.os.Bundle;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.view.ViewGroup;
+import android.widget.TextView;
+
+import androidx.annotation.NonNull;
+import androidx.annotation.Nullable;
+import androidx.preference.PreferenceFragmentCompat;
+
+import com.android.permissioncontroller.R;
+
+/** Base fragment to be used by car variants of the default app settings screens. */
+public class DefaultAppFrameFragment extends PreferenceFragmentCompat {
+
+ private TextView mLabelView;
+ private CharSequence mLabel;
+
+ @Override
+ public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container,
+ @Nullable Bundle savedInstanceState) {
+ View rootView = super.onCreateView(inflater, container, savedInstanceState);
+ View backButton = rootView.findViewById(R.id.back_button);
+ backButton.setOnClickListener(v -> getActivity().onBackPressed());
+
+ mLabelView = rootView.findViewById(R.id.label);
+ updateHeaderLabel();
+
+ return rootView;
+ }
+
+ /** Sets the header text of this fragment. */
+ public void setHeaderLabel(CharSequence label) {
+ mLabel = label;
+ updateHeaderLabel();
+ }
+
+ /** Gets the header text of this fragment. */
+ public CharSequence getHeaderLabel() {
+ return mLabel;
+ }
+
+ @Override
+ public void onCreatePreferences(Bundle bundle, String s) {
+ // We'll manually add preferences later.
+ }
+
+ private void updateHeaderLabel() {
+ if (mLabelView != null) {
+ mLabelView.setText(mLabel);
+ }
+ }
+}