Fix the transition of the up-button.

We've applied a new transition from Search to Settings, where if users
click on the up-button, the transition will not be applied. Hence, this
CL makes the up-button behave the same as the back key to address this.

- Also remove the transition target as it is not necessary.

Fixes: 177968777
Test: 1. Search "Gesture"
2. Click on "Gesture"
3. Tap the up-button and see the applied transition

Change-Id: I046424f244426750d98046703c05ae0a1d567c67
This commit is contained in:
Yi-Ling Chuang
2021-01-29 11:41:22 +08:00
parent 1e1c813354
commit c55901d2c0
2 changed files with 13 additions and 2 deletions

View File

@@ -238,12 +238,10 @@ public class SettingsActivity extends SettingsBaseActivity
getWindow().requestFeature(Window.FEATURE_ACTIVITY_TRANSITIONS); getWindow().requestFeature(Window.FEATURE_ACTIVITY_TRANSITIONS);
final MaterialSharedAxis enterTransition = new MaterialSharedAxis( final MaterialSharedAxis enterTransition = new MaterialSharedAxis(
MaterialSharedAxis.X, /* forward */true); MaterialSharedAxis.X, /* forward */true);
enterTransition.addTarget(R.id.content_parent);
getWindow().setEnterTransition(enterTransition); getWindow().setEnterTransition(enterTransition);
final MaterialSharedAxis returnTransition = new MaterialSharedAxis( final MaterialSharedAxis returnTransition = new MaterialSharedAxis(
MaterialSharedAxis.X, /* forward */false); MaterialSharedAxis.X, /* forward */false);
returnTransition.addTarget(R.id.content_parent);
getWindow().setReturnTransition(returnTransition); getWindow().setReturnTransition(returnTransition);
} }

View File

@@ -32,11 +32,13 @@ import android.util.ArraySet;
import android.util.FeatureFlagUtils; import android.util.FeatureFlagUtils;
import android.util.Log; import android.util.Log;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.MenuItem;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.view.Window; import android.view.Window;
import android.widget.Toolbar; import android.widget.Toolbar;
import androidx.annotation.NonNull;
import androidx.fragment.app.FragmentActivity; import androidx.fragment.app.FragmentActivity;
import com.android.settings.R; import com.android.settings.R;
@@ -167,6 +169,17 @@ public class SettingsBaseActivity extends FragmentActivity {
((ViewGroup) findViewById(R.id.content_frame)).addView(view, params); ((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 @Override
public void setTitle(CharSequence title) { public void setTitle(CharSequence title) {
if (mCollapsingToolbarLayout != null) { if (mCollapsingToolbarLayout != null) {