Merge "Revert transition codes in SettingsLib" into sc-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
b26f7ed9cc
@@ -21,8 +21,7 @@
|
|||||||
android:id="@+id/content_parent"
|
android:id="@+id/content_parent"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
android:fitsSystemWindows="true"
|
android:fitsSystemWindows="true">
|
||||||
android:transitionGroup="true">
|
|
||||||
|
|
||||||
<com.google.android.material.appbar.AppBarLayout
|
<com.google.android.material.appbar.AppBarLayout
|
||||||
android:id="@+id/app_bar"
|
android:id="@+id/app_bar"
|
||||||
|
|||||||
@@ -16,22 +16,8 @@
|
|||||||
|
|
||||||
package com.android.settingslib.collapsingtoolbar;
|
package com.android.settingslib.collapsingtoolbar;
|
||||||
|
|
||||||
import static com.android.settingslib.transition.SettingsTransitionHelper.EXTRA_PAGE_TRANSITION_TYPE;
|
|
||||||
|
|
||||||
import android.app.ActivityOptions;
|
|
||||||
import android.content.Intent;
|
|
||||||
import android.os.Bundle;
|
|
||||||
import android.util.Log;
|
|
||||||
import android.view.Window;
|
|
||||||
import android.widget.Toolbar;
|
|
||||||
|
|
||||||
import androidx.annotation.Nullable;
|
|
||||||
import androidx.core.os.BuildCompat;
|
|
||||||
import androidx.fragment.app.FragmentActivity;
|
import androidx.fragment.app.FragmentActivity;
|
||||||
|
|
||||||
import com.android.settingslib.transition.SettingsTransitionHelper;
|
|
||||||
import com.android.settingslib.transition.SettingsTransitionHelper.TransitionType;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A base Activity for Settings-specific page transition. Activities extending it will get
|
* A base Activity for Settings-specific page transition. Activities extending it will get
|
||||||
* Settings transition applied.
|
* Settings transition applied.
|
||||||
@@ -39,57 +25,7 @@ import com.android.settingslib.transition.SettingsTransitionHelper.TransitionTyp
|
|||||||
public abstract class SettingsTransitionActivity extends FragmentActivity {
|
public abstract class SettingsTransitionActivity extends FragmentActivity {
|
||||||
private static final String TAG = "SettingsTransitionActivity";
|
private static final String TAG = "SettingsTransitionActivity";
|
||||||
|
|
||||||
private Toolbar mToolbar;
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void onCreate(@Nullable Bundle savedInstanceState) {
|
|
||||||
if (isSettingsTransitionEnabled()) {
|
|
||||||
getWindow().requestFeature(Window.FEATURE_ACTIVITY_TRANSITIONS);
|
|
||||||
SettingsTransitionHelper.applyForwardTransition(this);
|
|
||||||
SettingsTransitionHelper.applyBackwardTransition(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
super.onCreate(savedInstanceState);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void setActionBar(@Nullable Toolbar toolbar) {
|
|
||||||
super.setActionBar(toolbar);
|
|
||||||
|
|
||||||
mToolbar = toolbar;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void startActivityForResult(Intent intent, int requestCode, @Nullable Bundle options) {
|
|
||||||
final int transitionType = intent.getIntExtra(EXTRA_PAGE_TRANSITION_TYPE,
|
|
||||||
TransitionType.TRANSITION_SHARED_AXIS);
|
|
||||||
if (!isSettingsTransitionEnabled() ||
|
|
||||||
transitionType == TransitionType.TRANSITION_NONE) {
|
|
||||||
super.startActivityForResult(intent, requestCode, options);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
super.startActivityForResult(intent, requestCode,
|
|
||||||
createActivityOptionsBundleForTransition(options));
|
|
||||||
}
|
|
||||||
|
|
||||||
protected boolean isSettingsTransitionEnabled() {
|
protected boolean isSettingsTransitionEnabled() {
|
||||||
return BuildCompat.isAtLeastS();
|
return false;
|
||||||
}
|
|
||||||
|
|
||||||
@Nullable
|
|
||||||
private Bundle createActivityOptionsBundleForTransition(@Nullable Bundle options) {
|
|
||||||
if (mToolbar == null) {
|
|
||||||
Log.w(TAG, "setActionBar(Toolbar) is not called. Cannot apply settings transition!");
|
|
||||||
return options;
|
|
||||||
}
|
|
||||||
final Bundle transitionOptions = ActivityOptions.makeSceneTransitionAnimation(this,
|
|
||||||
mToolbar, "shared_element_view").toBundle();
|
|
||||||
if (options == null) {
|
|
||||||
return transitionOptions;
|
|
||||||
}
|
|
||||||
final Bundle mergedOptions = new Bundle(options);
|
|
||||||
mergedOptions.putAll(transitionOptions);
|
|
||||||
return mergedOptions;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,7 +11,6 @@ android_library {
|
|||||||
name: "SettingsLibSettingsTransition",
|
name: "SettingsLibSettingsTransition",
|
||||||
|
|
||||||
srcs: ["src/**/*.java"],
|
srcs: ["src/**/*.java"],
|
||||||
resource_dirs: ["res"],
|
|
||||||
|
|
||||||
static_libs: [
|
static_libs: [
|
||||||
"com.google.android.material_material",
|
"com.google.android.material_material",
|
||||||
|
|||||||
@@ -1,19 +0,0 @@
|
|||||||
<?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
|
|
||||||
-->
|
|
||||||
|
|
||||||
<pathInterpolator xmlns:android="http://schemas.android.com/apk/res/android"
|
|
||||||
android:pathData="M 0,0 C 0.05, 0, 0.133333, 0.06, 0.166666, 0.4 C 0.208333, 0.82, 0.25, 1, 1, 1"/>
|
|
||||||
@@ -1,19 +0,0 @@
|
|||||||
<?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>
|
|
||||||
@@ -16,21 +16,11 @@
|
|||||||
|
|
||||||
package com.android.settingslib.transition;
|
package com.android.settingslib.transition;
|
||||||
|
|
||||||
import androidx.annotation.IntDef;
|
|
||||||
import android.app.Activity;
|
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 androidx.core.os.BuildCompat;
|
import androidx.annotation.IntDef;
|
||||||
import androidx.fragment.app.Fragment;
|
import androidx.fragment.app.Fragment;
|
||||||
|
|
||||||
import com.google.android.material.transition.platform.FadeThroughProvider;
|
|
||||||
import com.google.android.material.transition.platform.MaterialSharedAxis;
|
|
||||||
import com.google.android.material.transition.platform.SlideDistanceProvider;
|
|
||||||
|
|
||||||
import java.lang.annotation.Retention;
|
import java.lang.annotation.Retention;
|
||||||
import java.lang.annotation.RetentionPolicy;
|
import java.lang.annotation.RetentionPolicy;
|
||||||
|
|
||||||
@@ -59,31 +49,6 @@ public class SettingsTransitionHelper {
|
|||||||
public static final String EXTRA_PAGE_TRANSITION_TYPE = "page_transition_type";
|
public static final String EXTRA_PAGE_TRANSITION_TYPE = "page_transition_type";
|
||||||
|
|
||||||
private static final String TAG = "SettingsTransitionHelper";
|
private static final String TAG = "SettingsTransitionHelper";
|
||||||
private static final long DURATION = 450L;
|
|
||||||
private static final float FADE_THROUGH_THRESHOLD = 0.22F;
|
|
||||||
|
|
||||||
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 FadeThroughProvider fadeThroughProvider =
|
|
||||||
(FadeThroughProvider) transition.getSecondaryAnimatorProvider();
|
|
||||||
fadeThroughProvider.setProgressThreshold(FADE_THROUGH_THRESHOLD);
|
|
||||||
|
|
||||||
final Interpolator interpolator =
|
|
||||||
AnimationUtils.loadInterpolator(context, R.interpolator.fast_out_extra_slow_in);
|
|
||||||
transition.setInterpolator(interpolator);
|
|
||||||
|
|
||||||
return transition;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Apply the forward transition to the {@link Activity}, including Exit Transition and Enter
|
* Apply the forward transition to the {@link Activity}, including Exit Transition and Enter
|
||||||
@@ -92,23 +57,16 @@ public class SettingsTransitionHelper {
|
|||||||
* The Exit Transition takes effect when leaving the page, while the Enter Transition is
|
* The Exit Transition takes effect when leaving the page, while the Enter Transition is
|
||||||
* triggered when the page is launched/entering.
|
* triggered when the page is launched/entering.
|
||||||
*/
|
*/
|
||||||
public static void applyForwardTransition(Activity activity) {
|
public static void applyForwardTransition(Activity activity) {}
|
||||||
if (!isSettingsTransitionEnabled()) {
|
|
||||||
return;
|
/**
|
||||||
}
|
* Apply the forward transition to the {@link Fragment}, including Exit Transition and Enter
|
||||||
if (activity == null) {
|
* Transition.
|
||||||
Log.w(TAG, "applyForwardTransition: Invalid activity!");
|
*
|
||||||
return;
|
* The Exit Transition takes effect when leaving the page, while the Enter Transition is
|
||||||
}
|
* triggered when the page is launched/entering.
|
||||||
final Window window = activity.getWindow();
|
*/
|
||||||
if (window == null) {
|
public static void applyForwardTransition(Fragment fragment) {}
|
||||||
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
|
* Apply the backward transition to the {@link Activity}, including Return Transition and
|
||||||
@@ -118,43 +76,7 @@ public class SettingsTransitionHelper {
|
|||||||
* to close. Reenter Transition will be used to move Views in to the scene when returning from a
|
* to close. Reenter Transition will be used to move Views in to the scene when returning from a
|
||||||
* previously-started Activity.
|
* previously-started Activity.
|
||||||
*/
|
*/
|
||||||
public static void applyBackwardTransition(Activity activity) {
|
public static void applyBackwardTransition(Activity activity) {}
|
||||||
if (!isSettingsTransitionEnabled()) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Apply the forward transition to the {@link Fragment}, 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(Fragment fragment) {
|
|
||||||
if (!isSettingsTransitionEnabled()) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (fragment == null) {
|
|
||||||
Log.w(TAG, "applyForwardTransition: Invalid fragment!");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
final MaterialSharedAxis forward = createSettingsSharedAxis(fragment.getContext(), true);
|
|
||||||
fragment.setExitTransition(forward);
|
|
||||||
fragment.setEnterTransition(forward);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Apply the backward transition to the {@link Fragment}, including Return Transition and
|
* Apply the backward transition to the {@link Fragment}, including Return Transition and
|
||||||
@@ -164,20 +86,5 @@ public class SettingsTransitionHelper {
|
|||||||
* to close. Reenter Transition will be used to move Views in to the scene when returning from a
|
* to close. Reenter Transition will be used to move Views in to the scene when returning from a
|
||||||
* previously-started Fragment.
|
* previously-started Fragment.
|
||||||
*/
|
*/
|
||||||
public static void applyBackwardTransition(Fragment fragment) {
|
public static void applyBackwardTransition(Fragment fragment) {}
|
||||||
if (!isSettingsTransitionEnabled()) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (fragment == null) {
|
|
||||||
Log.w(TAG, "applyBackwardTransition: Invalid fragment!");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
final MaterialSharedAxis backward = createSettingsSharedAxis(fragment.getContext(), false);
|
|
||||||
fragment.setReturnTransition(backward);
|
|
||||||
fragment.setReenterTransition(backward);
|
|
||||||
}
|
|
||||||
|
|
||||||
private static boolean isSettingsTransitionEnabled() {
|
|
||||||
return BuildCompat.isAtLeastS();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user