Merge "Refactor some transition codes." into sc-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
8c1c7b63a7
@@ -233,18 +233,6 @@ public class SettingsActivity extends SettingsBaseActivity
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedState) {
|
||||
if (FeatureFlagUtils.isEnabled(this, FeatureFlags.SILKY_HOME)) {
|
||||
// Enable Activity transitions
|
||||
getWindow().requestFeature(Window.FEATURE_ACTIVITY_TRANSITIONS);
|
||||
final MaterialSharedAxis enterTransition = new MaterialSharedAxis(
|
||||
MaterialSharedAxis.X, /* forward */true);
|
||||
getWindow().setEnterTransition(enterTransition);
|
||||
|
||||
final MaterialSharedAxis returnTransition = new MaterialSharedAxis(
|
||||
MaterialSharedAxis.X, /* forward */false);
|
||||
getWindow().setReturnTransition(returnTransition);
|
||||
}
|
||||
|
||||
super.onCreate(savedState);
|
||||
Log.d(LOG_TAG, "Starting onCreate");
|
||||
long startTime = System.currentTimeMillis();
|
||||
|
@@ -77,6 +77,7 @@ public class SettingsBaseActivity extends FragmentActivity {
|
||||
|
||||
protected CollapsingToolbarLayout mCollapsingToolbarLayout;
|
||||
private int mCategoriesUpdateTaskCount;
|
||||
private Toolbar mToolbar;
|
||||
|
||||
@Override
|
||||
protected void onCreate(@Nullable Bundle savedInstanceState) {
|
||||
@@ -129,21 +130,39 @@ public class SettingsBaseActivity extends FragmentActivity {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setActionBar(@androidx.annotation.Nullable Toolbar toolbar) {
|
||||
super.setActionBar(toolbar);
|
||||
|
||||
mToolbar = toolbar;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onNavigateUp() {
|
||||
if (!super.onNavigateUp()) {
|
||||
finish();
|
||||
finishAfterTransition();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(@NonNull MenuItem item) {
|
||||
final int id = item.getItemId();
|
||||
if (id == android.R.id.home) {
|
||||
// Make the up button behave the same as the back button.
|
||||
finishAfterTransition();
|
||||
return true;
|
||||
}
|
||||
return super.onOptionsItemSelected(item);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void startActivity(Intent intent) {
|
||||
if (!Utils.isPageTransitionEnabled(this)) {
|
||||
super.startActivity(intent);
|
||||
return;
|
||||
}
|
||||
super.startActivity(intent, getActivityOptionsBundle());
|
||||
super.startActivity(intent, createActivityOptionsBundleForTransition(null));
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -152,11 +171,7 @@ public class SettingsBaseActivity extends FragmentActivity {
|
||||
super.startActivity(intent, options);
|
||||
return;
|
||||
}
|
||||
if (options != null) {
|
||||
super.startActivity(intent, getMergedBundleForTransition(options));
|
||||
return;
|
||||
}
|
||||
super.startActivity(intent, getActivityOptionsBundle());
|
||||
super.startActivity(intent, createActivityOptionsBundleForTransition(options));
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -167,7 +182,8 @@ public class SettingsBaseActivity extends FragmentActivity {
|
||||
super.startActivityForResult(intent, requestCode);
|
||||
return;
|
||||
}
|
||||
super.startActivityForResult(intent, requestCode, getActivityOptionsBundle());
|
||||
super.startActivityForResult(intent, requestCode,
|
||||
createActivityOptionsBundleForTransition(null));
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -177,12 +193,8 @@ public class SettingsBaseActivity extends FragmentActivity {
|
||||
super.startActivityForResult(intent, requestCode, options);
|
||||
return;
|
||||
}
|
||||
if (options != null) {
|
||||
super.startActivityForResult(intent, requestCode,
|
||||
getMergedBundleForTransition(options));
|
||||
return;
|
||||
}
|
||||
super.startActivityForResult(intent, requestCode, getActivityOptionsBundle());
|
||||
super.startActivityForResult(intent, requestCode,
|
||||
createActivityOptionsBundleForTransition(options));
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -192,7 +204,8 @@ public class SettingsBaseActivity extends FragmentActivity {
|
||||
super.startActivityForResultAsUser(intent, requestCode, userHandle);
|
||||
return;
|
||||
}
|
||||
super.startActivityForResultAsUser(intent, requestCode, getActivityOptionsBundle(),
|
||||
super.startActivityForResultAsUser(intent, requestCode,
|
||||
createActivityOptionsBundleForTransition(null),
|
||||
userHandle);
|
||||
}
|
||||
|
||||
@@ -242,17 +255,6 @@ public class SettingsBaseActivity extends FragmentActivity {
|
||||
((ViewGroup) findViewById(R.id.content_frame)).addView(view, params);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(@NonNull MenuItem item) {
|
||||
final int id = item.getItemId();
|
||||
if (id == android.R.id.home) {
|
||||
// Make the up button behave the same as the back button.
|
||||
onBackPressed();
|
||||
return true;
|
||||
}
|
||||
return super.onOptionsItemSelected(item);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setTitle(CharSequence title) {
|
||||
if (mCollapsingToolbarLayout != null) {
|
||||
@@ -341,20 +343,21 @@ public class SettingsBaseActivity extends FragmentActivity {
|
||||
}
|
||||
}
|
||||
|
||||
private Bundle getActivityOptionsBundle() {
|
||||
final Toolbar toolbar = findViewById(R.id.action_bar);
|
||||
return ActivityOptions.makeSceneTransitionAnimation(this, toolbar,
|
||||
"shared_element_view").toBundle();
|
||||
}
|
||||
|
||||
private Bundle getMergedBundleForTransition(@NonNull Bundle options) {
|
||||
final Bundle mergedBundle = new Bundle();
|
||||
mergedBundle.putAll(options);
|
||||
final Bundle activityOptionsBundle = getActivityOptionsBundle();
|
||||
if (activityOptionsBundle != null) {
|
||||
mergedBundle.putAll(activityOptionsBundle);
|
||||
@androidx.annotation.Nullable
|
||||
private Bundle createActivityOptionsBundleForTransition(
|
||||
@androidx.annotation.Nullable Bundle options) {
|
||||
if (mToolbar == null) {
|
||||
Log.w(TAG, "setActionBar(Toolbar) is not called. Cannot apply settings transition!");
|
||||
return options;
|
||||
}
|
||||
return mergedBundle;
|
||||
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;
|
||||
}
|
||||
|
||||
public interface CategoryListener {
|
||||
|
Reference in New Issue
Block a user