diff options
author | Lujiang Xue <rogerxue@google.com> | 2018-06-06 10:04:12 -0700 |
---|---|---|
committer | Lujiang Xue <rogerxue@google.com> | 2018-07-10 09:57:09 -0700 |
commit | d9c638109b95a96c16bbe2ec5ffeafedb7287bc9 (patch) | |
tree | 5d8517b0f22ccc0483f8f6e8db96e6a67d9deb1e | |
parent | 7b346256b7e49c69fd765949b1876842e8da3b76 (diff) | |
download | android_packages_apps_PackageInstaller-d9c638109b95a96c16bbe2ec5ffeafedb7287bc9.tar.gz android_packages_apps_PackageInstaller-d9c638109b95a96c16bbe2ec5ffeafedb7287bc9.tar.bz2 android_packages_apps_PackageInstaller-d9c638109b95a96c16bbe2ec5ffeafedb7287bc9.zip |
remove dependency on car-list
Bug: 109810925
Test: manually
Change-Id: I45891ac2b3e20a8069df0d4511323c992316294c
-rw-r--r-- | Android.mk | 1 | ||||
-rw-r--r-- | res/drawable/button_ripple_bg.xml | 23 | ||||
-rw-r--r-- | res/drawable/rectangle_ripple_mask.xml | 22 | ||||
-rw-r--r-- | res/layout/car_app_permissions.xml | 23 | ||||
-rw-r--r-- | src/com/android/packageinstaller/permission/ui/auto/AppPermissionsFragment.java | 110 |
5 files changed, 98 insertions, 81 deletions
@@ -23,7 +23,6 @@ LOCAL_STATIC_ANDROID_LIBRARIES += \ androidx.legacy_legacy-preference-v14 \ androidx.leanback_leanback \ androidx.leanback_leanback-preference \ - car-list \ SettingsLib LOCAL_STATIC_JAVA_LIBRARIES := \ diff --git a/res/drawable/button_ripple_bg.xml b/res/drawable/button_ripple_bg.xml new file mode 100644 index 00000000..dabacb10 --- /dev/null +++ b/res/drawable/button_ripple_bg.xml @@ -0,0 +1,23 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- + Copyright (C) 2018 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. +--> + +<ripple xmlns:android="http://schemas.android.com/apk/res/android" + android:color="@color/car_card_ripple_background" + android:radius="90dp"> + <item android:id="@android:id/mask" + android:drawable="@drawable/rectangle_ripple_mask" /> +</ripple> diff --git a/res/drawable/rectangle_ripple_mask.xml b/res/drawable/rectangle_ripple_mask.xml new file mode 100644 index 00000000..69eaf8bd --- /dev/null +++ b/res/drawable/rectangle_ripple_mask.xml @@ -0,0 +1,22 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- + Copyright (C) 2018 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. +--> + +<shape xmlns:android="http://schemas.android.com/apk/res/android" + android:shape="rectangle"> + <corners android:radius="@dimen/car_radius_1" /> + <solid android:color="@android:color/white" /> +</shape>
\ No newline at end of file diff --git a/res/layout/car_app_permissions.xml b/res/layout/car_app_permissions.xml index b8352640..e052b67a 100644 --- a/res/layout/car_app_permissions.xml +++ b/res/layout/car_app_permissions.xml @@ -16,6 +16,7 @@ <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" + xmlns:app="http://schemas.android.com/apk/res-auto" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical"> @@ -27,22 +28,22 @@ android:id="@+id/action_bar_icon_container" android:layout_width="@dimen/car_margin" android:layout_height="@dimen/car_app_bar_height" - android:foreground="@drawable/car_list_item_background" + android:foreground="@drawable/button_ripple_bg" android:layout_alignParentStart="true"> <ImageView - android:tint="@color/car_accent" + android:layout_width="@dimen/car_primary_icon_size" + android:layout_height="@dimen/car_primary_icon_size" + android:tint="@color/car_tint" + android:scaleType="fitCenter" android:layout_gravity="center" - android:src="@drawable/ic_arrow_back" - style="@style/ListIcon"/> + android:src="@drawable/ic_arrow_back"/> </FrameLayout> <TextView android:id="@+id/title" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginStart="@dimen/car_margin" - android:layout_marginTop="@dimen/optical_center_offset" - android:textAppearance="@style/TextAppearance.Car.Title" - android:textColor="@color/car_accent" + android:textAppearance="@style/TextAppearance.Car.Title2" android:text="@string/app_permissions" android:layout_gravity="center_vertical" android:layout_centerVertical="true" @@ -56,6 +57,12 @@ android:layout_height="@dimen/car_list_divider_height" android:background="@color/car_list_divider"/> - <include layout="@layout/list" /> + <androidx.car.widget.PagedListView + android:id="@+id/list" + android:layout_width="match_parent" + android:layout_height="match_parent" + app:showPagedListViewDivider="true" + app:alignDividerStartTo="@id/container" + app:gutter="both"/> </LinearLayout> diff --git a/src/com/android/packageinstaller/permission/ui/auto/AppPermissionsFragment.java b/src/com/android/packageinstaller/permission/ui/auto/AppPermissionsFragment.java index 20595a03..9bc75fc4 100644 --- a/src/com/android/packageinstaller/permission/ui/auto/AppPermissionsFragment.java +++ b/src/com/android/packageinstaller/permission/ui/auto/AppPermissionsFragment.java @@ -27,17 +27,16 @@ import android.content.pm.PackageManager; import android.os.Bundle; import android.util.Log; import android.view.LayoutInflater; -import android.view.MotionEvent; import android.view.View; import android.view.ViewGroup; -import android.widget.Switch; import android.widget.Toast; -import androidx.annotation.DrawableRes; +import androidx.car.widget.ListItem; +import androidx.car.widget.ListItemAdapter; +import androidx.car.widget.ListItemProvider; import androidx.car.widget.PagedListView; +import androidx.car.widget.TextListItem; -import com.android.car.list.IconToggleLineItem; -import com.android.car.list.TypedPagedListAdapter; import com.android.packageinstaller.R; import com.android.packageinstaller.permission.model.AppPermissionGroup; import com.android.packageinstaller.permission.model.AppPermissions; @@ -58,7 +57,7 @@ public final class AppPermissionsFragment extends Fragment{ private String mPackageName; protected PagedListView mListView; - protected TypedPagedListAdapter mPagedListAdapter; + protected ListItemAdapter mPagedListAdapter; /** @@ -82,7 +81,7 @@ public final class AppPermissionsFragment extends Fragment{ v -> getActivity().onBackPressed()); mListView = (PagedListView) getView().findViewById(R.id.list); - mPagedListAdapter = new TypedPagedListAdapter(getLineItems()); + mPagedListAdapter = new ListItemAdapter(getContext(), getItemProvider()); mListView.setAdapter(mPagedListAdapter); } @@ -142,11 +141,11 @@ public final class AppPermissionsFragment extends Fragment{ /** * Gets the list of the LineItems to show up in the list */ - public ArrayList<TypedPagedListAdapter.LineItem> getLineItems() { - ArrayList<TypedPagedListAdapter.LineItem> items = new ArrayList<>(); + public ListItemProvider getItemProvider() { + ArrayList<ListItem> items = new ArrayList<>(); Context context = getContext(); if (context == null) { - return items; + return new ListItemProvider.ListProvider(items); } for (AppPermissionGroup group : mAppPermissions.getPermissionGroups()) { @@ -155,7 +154,7 @@ public final class AppPermissionsFragment extends Fragment{ } items.add(new PermissionLineItem(group, context)); } - return items; + return new ListItemProvider.ListProvider(items); } private static PackageInfo getPackageInfo(Activity activity, String packageName) { @@ -170,69 +169,36 @@ public final class AppPermissionsFragment extends Fragment{ } } - private class PermissionLineItem extends IconToggleLineItem { - private final AppPermissionGroup mPermissionGroup; - private final Context mContext; + private class PermissionLineItem extends TextListItem { PermissionLineItem(AppPermissionGroup permissionGroup, Context context) { - super(permissionGroup.getLabel(), context); - mContext = context; - mPermissionGroup = permissionGroup; - } - - @Override - public boolean onToggleTouched(Switch toggleSwitch, MotionEvent event) { - if (event.getAction() != MotionEvent.ACTION_DOWN) { - return true; - } - if (!isChecked()) { - mPermissionGroup.grantRuntimePermissions(false); - toggleSwitch.performClick(); - } else { - final boolean grantedByDefault = - mPermissionGroup.hasGrantedByDefaultPermission(); - if (grantedByDefault || !mPermissionGroup.doesSupportRuntimePermissions()) { - new AlertDialog.Builder(mContext) - .setMessage(grantedByDefault - ? R.string.system_warning : R.string.old_sdk_deny_warning) - .setNegativeButton(R.string.cancel, null /* listener */) - .setPositiveButton(R.string.grant_dialog_button_deny_anyway, - (dialog, which) -> { - mPermissionGroup.revokeRuntimePermissions(false); - toggleSwitch.performClick(); - }) - .show(); - } else { - mPermissionGroup.revokeRuntimePermissions(false); - toggleSwitch.performClick(); - } - } - return true; - } - - @DrawableRes - public int getIcon() { - return mPermissionGroup.getIconResId(); - } - - @Override - public boolean isChecked() { - return mPermissionGroup.areRuntimePermissionsGranted(); - } - - @Override - public CharSequence getDesc() { - return null; - } - - @Override - public boolean isEnabled() { - return true; - } - - @Override - public boolean isExpandable() { - return false; + super(context); + setTitle(permissionGroup.getLabel().toString()); + setPrimaryActionIcon(permissionGroup.getIconResId(), /* useLargeIcon= */ false); + setSwitch( + permissionGroup.areRuntimePermissionsGranted(), + /* showDivider= */ false, + (button, isChecked) -> { + if (isChecked) { + permissionGroup.grantRuntimePermissions(/* fixedByTheUser= */ false); + return; + } + boolean grantedByDefault = permissionGroup.hasGrantedByDefaultPermission(); + if (!grantedByDefault && permissionGroup.doesSupportRuntimePermissions()) { + permissionGroup.revokeRuntimePermissions(/* fixedByTheUser= */ false); + return; + } + new AlertDialog.Builder(context) + .setMessage(grantedByDefault + ? R.string.system_warning + : R.string.old_sdk_deny_warning) + .setNegativeButton(R.string.cancel, /* listener= */ null) + .setPositiveButton(R.string.grant_dialog_button_deny_anyway, + (dialog, which) -> + permissionGroup.revokeRuntimePermissions( + /* fixedByTheUser= */ false)) + .show(); + }); } } } |