diff options
author | David Nelloms <davidln@google.com> | 2019-05-29 22:25:30 +0000 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2019-05-29 22:25:30 +0000 |
commit | 545d4b7a0f98956e9a6d3dab5ccb5d02d3088f5d (patch) | |
tree | 3586f65f70ed28973ea41c54430a7be4711dcfc9 /src | |
parent | 3f8f673c2bb4a653695e5a46e177b6e8eacc494c (diff) | |
parent | 6c5294933c8bb338d0dd98ceb74560e637a1991f (diff) | |
download | android_packages_apps_PackageInstaller-545d4b7a0f98956e9a6d3dab5ccb5d02d3088f5d.tar.gz android_packages_apps_PackageInstaller-545d4b7a0f98956e9a6d3dab5ccb5d02d3088f5d.tar.bz2 android_packages_apps_PackageInstaller-545d4b7a0f98956e9a6d3dab5ccb5d02d3088f5d.zip |
Merge "Add car-ified UI for special app access pages." into qt-dev
Diffstat (limited to 'src')
5 files changed, 202 insertions, 7 deletions
diff --git a/src/com/android/packageinstaller/role/ui/SpecialAppAccessActivity.java b/src/com/android/packageinstaller/role/ui/SpecialAppAccessActivity.java index 2f9fdb17..4ddf6f1a 100644 --- a/src/com/android/packageinstaller/role/ui/SpecialAppAccessActivity.java +++ b/src/com/android/packageinstaller/role/ui/SpecialAppAccessActivity.java @@ -24,11 +24,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.AutoSpecialAppAccessFragment; import com.android.packageinstaller.role.ui.handheld.HandheldSpecialAppAccessFragment; +import com.android.permissioncontroller.R; /** * Activity for a special app access. @@ -41,8 +45,7 @@ public class SpecialAppAccessActivity extends FragmentActivity { * Create an intent for starting this activity. * * @param roleName the name of the role for the special app access - * @param context the context to create the intent - * + * @param context the context to create the intent * @return an intent to start this activity */ @NonNull @@ -53,6 +56,11 @@ public class SpecialAppAccessActivity 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( @@ -78,8 +86,12 @@ public class SpecialAppAccessActivity extends FragmentActivity { } if (savedInstanceState == null) { - HandheldSpecialAppAccessFragment fragment = - HandheldSpecialAppAccessFragment.newInstance(roleName); + Fragment fragment; + if (DeviceUtils.isAuto(this)) { + fragment = AutoSpecialAppAccessFragment.newInstance(roleName); + } else { + fragment = HandheldSpecialAppAccessFragment.newInstance(roleName); + } getSupportFragmentManager().beginTransaction() .add(android.R.id.content, fragment) .commit(); diff --git a/src/com/android/packageinstaller/role/ui/SpecialAppAccessListActivity.java b/src/com/android/packageinstaller/role/ui/SpecialAppAccessListActivity.java index 6997375f..66cf6edd 100644 --- a/src/com/android/packageinstaller/role/ui/SpecialAppAccessListActivity.java +++ b/src/com/android/packageinstaller/role/ui/SpecialAppAccessListActivity.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.AutoSpecialAppAccessListFragment; import com.android.packageinstaller.role.ui.handheld.HandheldSpecialAppAccessListFragment; +import com.android.permissioncontroller.R; /** * Activity for the list of special app accesses. @@ -31,14 +35,23 @@ public class SpecialAppAccessListActivity 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) { - HandheldSpecialAppAccessListFragment fragment = - HandheldSpecialAppAccessListFragment.newInstance(); + Fragment fragment; + if (DeviceUtils.isAuto(this)) { + fragment = AutoSpecialAppAccessListFragment.newInstance(); + } else { + fragment = HandheldSpecialAppAccessListFragment.newInstance(); + } getSupportFragmentManager().beginTransaction() .add(android.R.id.content, fragment) .commit(); diff --git a/src/com/android/packageinstaller/role/ui/auto/AutoSettingsPreference.java b/src/com/android/packageinstaller/role/ui/auto/AutoSettingsPreference.java index dec66186..099c1adc 100644 --- a/src/com/android/packageinstaller/role/ui/auto/AutoSettingsPreference.java +++ b/src/com/android/packageinstaller/role/ui/auto/AutoSettingsPreference.java @@ -25,7 +25,7 @@ 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 + * Preference for use in auto lists. Extends {@link TwoTargetPreference} in order to make sure of * shared logic between phone and auto settings UI. */ public class AutoSettingsPreference extends TwoTargetPreference { diff --git a/src/com/android/packageinstaller/role/ui/auto/AutoSpecialAppAccessFragment.java b/src/com/android/packageinstaller/role/ui/auto/AutoSpecialAppAccessFragment.java new file mode 100644 index 00000000..02c999f5 --- /dev/null +++ b/src/com/android/packageinstaller/role/ui/auto/AutoSpecialAppAccessFragment.java @@ -0,0 +1,101 @@ +/* + * 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. + */ + +package com.android.packageinstaller.role.ui.auto; + +import android.content.Context; +import android.content.Intent; +import android.os.Bundle; + +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; +import androidx.preference.Preference; +import androidx.preference.SwitchPreference; +import androidx.preference.TwoStatePreference; + +import com.android.packageinstaller.auto.AutoSettingsFrameFragment; +import com.android.packageinstaller.role.ui.SpecialAppAccessChildFragment; +import com.android.permissioncontroller.R; + +/** Automotive fragment for displaying special app access for a role. */ +public class AutoSpecialAppAccessFragment extends AutoSettingsFrameFragment implements + SpecialAppAccessChildFragment.Parent { + + private String mRoleName; + + /** + * Returns a new instance of {@link AutoSpecialAppAccessFragment} for the given {@code + * roleName}. + */ + @NonNull + public static AutoSpecialAppAccessFragment newInstance(@NonNull String roleName) { + AutoSpecialAppAccessFragment fragment = new AutoSpecialAppAccessFragment(); + Bundle arguments = new Bundle(); + arguments.putString(Intent.EXTRA_ROLE_NAME, roleName); + 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); + } + + @Override + public void onCreatePreferences(Bundle bundle, String s) { + // Preferences will be added by the child fragment. + } + + @Override + public void onActivityCreated(@Nullable Bundle savedInstanceState) { + super.onActivityCreated(savedInstanceState); + + if (savedInstanceState == null) { + SpecialAppAccessChildFragment fragment = SpecialAppAccessChildFragment.newInstance( + mRoleName); + 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 SwitchPreference(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/AutoSpecialAppAccessListFragment.java b/src/com/android/packageinstaller/role/ui/auto/AutoSpecialAppAccessListFragment.java new file mode 100644 index 00000000..2f824dcf --- /dev/null +++ b/src/com/android/packageinstaller/role/ui/auto/AutoSpecialAppAccessListFragment.java @@ -0,0 +1,69 @@ +/* + * 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. + */ + +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.auto.AutoSettingsFrameFragment; +import com.android.packageinstaller.role.ui.SpecialAppAccessListChildFragment; +import com.android.packageinstaller.role.ui.TwoTargetPreference; +import com.android.permissioncontroller.R; + +/** Automotive fragment for the list of role related special app accesses. */ +public class AutoSpecialAppAccessListFragment extends AutoSettingsFrameFragment implements + SpecialAppAccessListChildFragment.Parent { + + /** Returns a new instance of {@link AutoSpecialAppAccessListFragment}. */ + @NonNull + public static AutoSpecialAppAccessListFragment newInstance() { + return new AutoSpecialAppAccessListFragment(); + } + + @Override + public void onCreatePreferences(Bundle bundle, String s) { + // Preferences will be added by the child fragment. + } + + @Override + public void onActivityCreated(@Nullable Bundle savedInstanceState) { + super.onActivityCreated(savedInstanceState); + + if (savedInstanceState == null) { + SpecialAppAccessListChildFragment fragment = + SpecialAppAccessListChildFragment.newInstance(); + getChildFragmentManager().beginTransaction() + .add(fragment, /* tag= */ null) + .commit(); + } + + setHeaderLabel(getString(R.string.special_app_access)); + } + + @NonNull + @Override + public TwoTargetPreference createPreference(@NonNull Context context) { + return new AutoSettingsPreference(context); + } + + @Override + public void onPreferenceScreenChanged() { + } +} |