Support different types of transitions.

In Settings, some cases are not suitable to apply the shared x-axis
transition, and some pages shared with SUW may need to apply other
transitions. Hence, create a mechanism for flexibility.

Bug: 187542491
Test: robotest & navigate though settings pages
Change-Id: I041bbb5e1d9177f234860864651f618700867b96
This commit is contained in:
Yi-Ling Chuang
2021-05-24 16:23:45 +08:00
parent 56713ae05c
commit 8db5cb03eb
3 changed files with 65 additions and 3 deletions

View File

@@ -50,6 +50,7 @@ import com.android.settings.dashboard.CategoryManager;
import com.android.settingslib.core.lifecycle.HideNonSystemOverlayMixin;
import com.android.settingslib.drawer.Tile;
import com.android.settingslib.transition.SettingsTransitionHelper;
import com.android.settingslib.transition.SettingsTransitionHelper.TransitionType;
import com.google.android.material.appbar.CollapsingToolbarLayout;
import com.google.android.material.resources.TextAppearanceConfig;
@@ -63,6 +64,11 @@ import java.util.Set;
public class SettingsBaseActivity extends FragmentActivity {
/**
* What type of page transition should be apply.
*/
public static final String EXTRA_PAGE_TRANSITION_TYPE = "extra_page_transition_type";
protected static final boolean DEBUG_TIMING = false;
private static final String TAG = "SettingsBaseActivity";
private static final String DATA_SCHEME_PKG = "package";
@@ -162,26 +168,53 @@ public class SettingsBaseActivity extends FragmentActivity {
super.startActivity(intent);
return;
}
final int transitionType = getTransitionType(intent);
if (transitionType == TransitionType.TRANSITION_SLIDE) {
super.startActivity(intent, null);
overridePendingTransition(R.anim.sud_slide_next_in, R.anim.sud_slide_next_out);
return;
} else if (transitionType == TransitionType.TRANSITION_NONE) {
super.startActivity(intent, null);
return;
}
super.startActivity(intent, createActivityOptionsBundleForTransition(null));
}
@Override
public void startActivity(Intent intent, @androidx.annotation.Nullable Bundle options) {
if (!Utils.isPageTransitionEnabled(this)) {
final int transitionType = getTransitionType(intent);
if (!Utils.isPageTransitionEnabled(this) ||
transitionType == TransitionType.TRANSITION_NONE) {
super.startActivity(intent, options);
return;
}
if (transitionType == TransitionType.TRANSITION_SLIDE) {
super.startActivity(intent, options);
overridePendingTransition(R.anim.sud_slide_next_in, R.anim.sud_slide_next_out);
return;
}
super.startActivity(intent, createActivityOptionsBundleForTransition(options));
}
@Override
public void startActivityForResult(Intent intent, int requestCode) {
final int transitionType = getTransitionType(intent);
// startActivity() will eventually calls startActivityForResult() with requestCode -1.
// Adding this condition to avoid multiple calls.
if (!Utils.isPageTransitionEnabled(this) || requestCode == DEFAULT_REQUEST) {
if (!Utils.isPageTransitionEnabled(this) || requestCode == DEFAULT_REQUEST
|| transitionType == TransitionType.TRANSITION_NONE) {
super.startActivityForResult(intent, requestCode);
return;
}
if (transitionType == TransitionType.TRANSITION_SLIDE) {
super.startActivityForResult(intent, requestCode, null);
overridePendingTransition(R.anim.sud_slide_next_in, R.anim.sud_slide_next_out);
return;
}
super.startActivityForResult(intent, requestCode,
createActivityOptionsBundleForTransition(null));
}
@@ -189,10 +222,19 @@ public class SettingsBaseActivity extends FragmentActivity {
@Override
public void startActivityForResult(Intent intent, int requestCode,
@androidx.annotation.Nullable Bundle options) {
if (!Utils.isPageTransitionEnabled(this) || requestCode == DEFAULT_REQUEST) {
final int transitionType = getTransitionType(intent);
if (!Utils.isPageTransitionEnabled(this) || requestCode == DEFAULT_REQUEST
|| transitionType == TransitionType.TRANSITION_NONE) {
super.startActivityForResult(intent, requestCode, options);
return;
}
if (transitionType == TransitionType.TRANSITION_SLIDE) {
super.startActivityForResult(intent, requestCode, options);
overridePendingTransition(R.anim.sud_slide_next_in, R.anim.sud_slide_next_out);
return;
}
super.startActivityForResult(intent, requestCode,
createActivityOptionsBundleForTransition(options));
}
@@ -343,6 +385,11 @@ public class SettingsBaseActivity extends FragmentActivity {
}
}
private int getTransitionType(Intent intent) {
return intent.getIntExtra(EXTRA_PAGE_TRANSITION_TYPE,
SettingsTransitionHelper.TransitionType.TRANSITION_SHARED_AXIS);
}
@androidx.annotation.Nullable
private Bundle createActivityOptionsBundleForTransition(
@androidx.annotation.Nullable Bundle options) {

View File

@@ -34,6 +34,7 @@ import com.android.settings.SettingsActivity;
import com.android.settings.SubSettings;
import com.android.settings.Utils;
import com.android.settingslib.core.instrumentation.MetricsFeatureProvider;
import com.android.settingslib.transition.SettingsTransitionHelper.TransitionType;
public class SubSettingLauncher {
@@ -47,6 +48,7 @@ public class SubSettingLauncher {
}
mContext = context;
mLaunchRequest = new LaunchRequest();
mLaunchRequest.transitionType = TransitionType.TRANSITION_SHARED_AXIS;
}
public SubSettingLauncher setDestination(String fragmentName) {
@@ -120,6 +122,11 @@ public class SubSettingLauncher {
return this;
}
public SubSettingLauncher setTransitionType(int transitionType) {
mLaunchRequest.transitionType = transitionType;
return this;
}
public void launch() {
if (mLaunched) {
throw new IllegalStateException(
@@ -166,6 +173,9 @@ public class SubSettingLauncher {
mLaunchRequest.titleResId);
intent.putExtra(SettingsActivity.EXTRA_SHOW_FRAGMENT_TITLE, mLaunchRequest.title);
intent.addFlags(mLaunchRequest.flags);
intent.putExtra(SettingsBaseActivity.EXTRA_PAGE_TRANSITION_TYPE,
mLaunchRequest.transitionType);
return intent;
}
@@ -219,6 +229,7 @@ public class SubSettingLauncher {
Fragment mResultListener;
int mRequestCode;
UserHandle userHandle;
int transitionType;
Bundle arguments;
Bundle extras;
}

View File

@@ -37,6 +37,7 @@ import androidx.fragment.app.FragmentActivity;
import com.android.settings.SettingsActivity;
import com.android.settings.testutils.shadow.ShadowUtils;
import com.android.settingslib.core.instrumentation.MetricsFeatureProvider;
import com.android.settingslib.transition.SettingsTransitionHelper;
import org.junit.Before;
import org.junit.Test;
@@ -97,6 +98,7 @@ public class SubSettingLauncherTest {
.setDestination(SubSettingLauncherTest.class.getName())
.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
.setSourceMetricsCategory(123)
.setTransitionType(SettingsTransitionHelper.TransitionType.TRANSITION_SLIDE)
.launch();
doNothing().when(launcher).launch(any(Intent.class));
verify(launcher).launch(intentArgumentCaptor.capture());
@@ -109,6 +111,8 @@ public class SubSettingLauncherTest {
assertThat(intent.getFlags()).isEqualTo(Intent.FLAG_ACTIVITY_NEW_TASK);
assertThat(intent.getIntExtra(MetricsFeatureProvider.EXTRA_SOURCE_METRICS_CATEGORY, -1))
.isEqualTo(123);
assertThat(intent.getIntExtra(SettingsBaseActivity.EXTRA_PAGE_TRANSITION_TYPE, -1))
.isEqualTo(SettingsTransitionHelper.TransitionType.TRANSITION_SLIDE);
}
@Test