diff options
author | 2021-03-23 17:10:00 +0800 | |
---|---|---|
committer | 2021-03-24 14:52:40 +0800 | |
commit | 841580f523af3ef27a0648f498b272e37e0c515f (patch) | |
tree | 47a3ee55e74da64f57dfa7ed3ccf68f97b40af5f | |
parent | d2f65cf16400d4a95a99e4c382f67d940cf53bd7 (diff) |
Create SettingsTransitionHelper
This transition helper is created to share with settings that are
injected/out of Settings codebase to ensure the page transitions are
consistent across Settings app.
Bug: 177480673
Test: rebuild and test with Settings
Change-Id: Ibb51d102db4d5365ae82f81d91c4bae7092d6e31
5 files changed, 174 insertions, 3 deletions
diff --git a/packages/SettingsLib/Android.bp b/packages/SettingsLib/Android.bp index d6c66b5663af..5e69a4ee395c 100644 --- a/packages/SettingsLib/Android.bp +++ b/packages/SettingsLib/Android.bp @@ -17,8 +17,8 @@ android_library { // TODO(b/149540986): revert this change. static_libs: [ - // All other dependent components should be put in - // "SettingsLibDependenciesWithoutWifiTracker". + // All other dependent components should be put in + // "SettingsLibDependenciesWithoutWifiTracker". "WifiTrackerLib", ], @@ -27,7 +27,10 @@ android_library { resource_dirs: ["res"], - srcs: ["src/**/*.java", "src/**/*.kt"], + srcs: [ + "src/**/*.java", + "src/**/*.kt", + ], min_sdk_version: "21", @@ -68,6 +71,7 @@ java_defaults { "SettingsLibUsageProgressBarPreference", "SettingsLibCollapsingToolbarBaseActivity", "SettingsLibTwoTargetPreference", + "SettingsLibSettingsTransition", ], } diff --git a/packages/SettingsLib/SettingsTransition/Android.bp b/packages/SettingsLib/SettingsTransition/Android.bp new file mode 100644 index 000000000000..c12f6f748cba --- /dev/null +++ b/packages/SettingsLib/SettingsTransition/Android.bp @@ -0,0 +1,22 @@ +package { + // See: http://go/android-license-faq + // A large-scale-change added 'default_applicable_licenses' to import + // all of the 'license_kinds' from "frameworks_base_license" + // to get the below license kinds: + // SPDX-license-identifier-Apache-2.0 + default_applicable_licenses: ["frameworks_base_license"], +} + +android_library { + name: "SettingsLibSettingsTransition", + + srcs: ["src/**/*.java"], + resource_dirs: ["res"], + + static_libs: [ + "com.google.android.material_material", + ], + + sdk_version: "system_current", + min_sdk_version: "21", +} diff --git a/packages/SettingsLib/SettingsTransition/AndroidManifest.xml b/packages/SettingsLib/SettingsTransition/AndroidManifest.xml new file mode 100644 index 000000000000..11660a5fe444 --- /dev/null +++ b/packages/SettingsLib/SettingsTransition/AndroidManifest.xml @@ -0,0 +1,23 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- + Copyright (C) 2021 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. +--> + +<manifest xmlns:android="http://schemas.android.com/apk/res/android" + package="com.android.settingslib.transition"> + + <uses-sdk android:minSdkVersion="21" /> + +</manifest> diff --git a/packages/SettingsLib/SettingsTransition/res/values/dimens.xml b/packages/SettingsLib/SettingsTransition/res/values/dimens.xml new file mode 100644 index 000000000000..0630ca85b621 --- /dev/null +++ b/packages/SettingsLib/SettingsTransition/res/values/dimens.xml @@ -0,0 +1,19 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- Copyright (C) 2021 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. +--> + +<resources> + <dimen name="settings_shared_axis_x_slide_distance">96dp</dimen> +</resources>
\ No newline at end of file diff --git a/packages/SettingsLib/SettingsTransition/src/com/android/settingslib/transition/SettingsTransitionHelper.java b/packages/SettingsLib/SettingsTransition/src/com/android/settingslib/transition/SettingsTransitionHelper.java new file mode 100644 index 000000000000..f99fda05c3c9 --- /dev/null +++ b/packages/SettingsLib/SettingsTransition/src/com/android/settingslib/transition/SettingsTransitionHelper.java @@ -0,0 +1,103 @@ +/* + * Copyright (C) 2021 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.settingslib.transition; + +import android.app.Activity; +import android.content.Context; +import android.util.Log; +import android.view.Window; +import android.view.animation.AnimationUtils; +import android.view.animation.Interpolator; + +import com.google.android.material.transition.platform.MaterialSharedAxis; +import com.google.android.material.transition.platform.SlideDistanceProvider; + +/** + * A helper class to apply Settings Transition + */ +public class SettingsTransitionHelper { + + private static final String TAG = "SettingsTransitionHelper"; + private static final long DURATION = 450L; + + private static MaterialSharedAxis createSettingsSharedAxis(Context context, boolean forward) { + final MaterialSharedAxis transition = new MaterialSharedAxis(MaterialSharedAxis.X, forward); + transition.excludeTarget(android.R.id.statusBarBackground, true); + transition.excludeTarget(android.R.id.navigationBarBackground, true); + + final SlideDistanceProvider forwardDistanceProvider = + (SlideDistanceProvider) transition.getPrimaryAnimatorProvider(); + final int distance = context.getResources().getDimensionPixelSize( + R.dimen.settings_shared_axis_x_slide_distance); + forwardDistanceProvider.setSlideDistance(distance); + transition.setDuration(DURATION); + + final Interpolator interpolator = + AnimationUtils.loadInterpolator(context, + android.R.interpolator.fast_out_extra_slow_in); + transition.setInterpolator(interpolator); + + // TODO(b/177480673): Update fade through threshold once (cl/362065364) is released + + return transition; + } + + /** + * Apply the forward transition to the {@link Activity}, including Exit Transition and Enter + * Transition. + * + * The Exit Transition takes effect when leaving the page, while the Enter Transition is + * triggered when the page is launched/entering. + */ + public static void applyForwardTransition(Activity activity) { + if (activity == null) { + Log.w(TAG, "applyForwardTransition: Invalid activity!"); + return; + } + final Window window = activity.getWindow(); + if (window == null) { + Log.w(TAG, "applyForwardTransition: Invalid window!"); + return; + } + final MaterialSharedAxis forward = createSettingsSharedAxis(activity, true); + window.setExitTransition(forward); + window.setEnterTransition(forward); + } + + /** + * Apply the backward transition to the {@link Activity}, including Return Transition and + * Reenter Transition. + * + * Return Transition will be used to move Views out of the scene when the Window is preparing + * to close. Reenter Transition will be used to move Views in to the scene when returning from a + * previously-started Activity. + */ + public static void applyBackwardTransition(Activity activity) { + if (activity == null) { + Log.w(TAG, "applyBackwardTransition: Invalid activity!"); + return; + } + final Window window = activity.getWindow(); + if (window == null) { + Log.w(TAG, "applyBackwardTransition: Invalid window!"); + return; + } + final MaterialSharedAxis backward = createSettingsSharedAxis(activity, false); + window.setReturnTransition(backward); + window.setReenterTransition(backward); + } +} |