Merge "Create SettingsTransitionHelper" into sc-dev

This commit is contained in:
Yi-Ling Chuang
2021-03-24 09:43:17 +00:00
committed by Android (Google) Code Review
5 changed files with 174 additions and 3 deletions

View File

@@ -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",
],
}

View File

@@ -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",
}

View File

@@ -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>

View File

@@ -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>

View File

@@ -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);
}
}