Merge "Fix a flicker problem on top app bar" into sc-dev am: e7b17ece47
Original change: https://googleplex-android-review.googlesource.com/c/platform/packages/apps/Settings/+/15067023 Change-Id: I28cd085bdee109258f09cb0caf7f43a0d7d6fd2b
This commit is contained in:
@@ -48,7 +48,8 @@ import com.google.android.setupcompat.util.WizardManagerHelper;
|
|||||||
import com.google.android.setupdesign.util.ThemeHelper;
|
import com.google.android.setupdesign.util.ThemeHelper;
|
||||||
|
|
||||||
/** Base activity for Settings pages */
|
/** Base activity for Settings pages */
|
||||||
public class SettingsBaseActivity extends FragmentActivity implements CategoryHandler {
|
public class SettingsBaseActivity extends FragmentActivity implements CategoryHandler,
|
||||||
|
AppBarLayout.OnOffsetChangedListener {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* What type of page transition should be apply.
|
* What type of page transition should be apply.
|
||||||
@@ -58,11 +59,15 @@ public class SettingsBaseActivity extends FragmentActivity implements CategoryHa
|
|||||||
protected static final boolean DEBUG_TIMING = false;
|
protected static final boolean DEBUG_TIMING = false;
|
||||||
private static final String TAG = "SettingsBaseActivity";
|
private static final String TAG = "SettingsBaseActivity";
|
||||||
private static final int DEFAULT_REQUEST = -1;
|
private static final int DEFAULT_REQUEST = -1;
|
||||||
|
private static final int FULLY_EXPANDED_OFFSET = 0;
|
||||||
|
private static final int TOOLBAR_MAX_LINE_NUMBER = 2;
|
||||||
|
private static final String KEY_IS_TOOLBAR_COLLAPSED = "is_toolbar_collapsed";
|
||||||
|
|
||||||
protected CategoryMixin mCategoryMixin;
|
protected CategoryMixin mCategoryMixin;
|
||||||
protected CollapsingToolbarLayout mCollapsingToolbarLayout;
|
protected CollapsingToolbarLayout mCollapsingToolbarLayout;
|
||||||
protected AppBarLayout mAppBarLayout;
|
protected AppBarLayout mAppBarLayout;
|
||||||
private Toolbar mToolbar;
|
private Toolbar mToolbar;
|
||||||
|
private boolean mIsToolbarCollapsed;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public CategoryMixin getCategoryMixin() {
|
public CategoryMixin getCategoryMixin() {
|
||||||
@@ -100,6 +105,11 @@ public class SettingsBaseActivity extends FragmentActivity implements CategoryHa
|
|||||||
super.setContentView(R.layout.collapsing_toolbar_base_layout);
|
super.setContentView(R.layout.collapsing_toolbar_base_layout);
|
||||||
mCollapsingToolbarLayout = findViewById(R.id.collapsing_toolbar);
|
mCollapsingToolbarLayout = findViewById(R.id.collapsing_toolbar);
|
||||||
mAppBarLayout = findViewById(R.id.app_bar);
|
mAppBarLayout = findViewById(R.id.app_bar);
|
||||||
|
mAppBarLayout.addOnOffsetChangedListener(this);
|
||||||
|
if (savedInstanceState != null) {
|
||||||
|
mIsToolbarCollapsed = savedInstanceState.getBoolean(KEY_IS_TOOLBAR_COLLAPSED);
|
||||||
|
}
|
||||||
|
initCollapsingToolbar();
|
||||||
disableCollapsingToolbarLayoutScrollingBehavior();
|
disableCollapsingToolbarLayoutScrollingBehavior();
|
||||||
} else {
|
} else {
|
||||||
super.setContentView(R.layout.settings_base_layout);
|
super.setContentView(R.layout.settings_base_layout);
|
||||||
@@ -191,6 +201,23 @@ public class SettingsBaseActivity extends FragmentActivity implements CategoryHa
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onOffsetChanged(AppBarLayout appBarLayout, int offset) {
|
||||||
|
if (offset == FULLY_EXPANDED_OFFSET) {
|
||||||
|
mIsToolbarCollapsed = false;
|
||||||
|
} else {
|
||||||
|
mIsToolbarCollapsed = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onSaveInstanceState(@NonNull Bundle outState) {
|
||||||
|
super.onSaveInstanceState(outState);
|
||||||
|
if (isChangingConfigurations()) {
|
||||||
|
outState.putBoolean(KEY_IS_TOOLBAR_COLLAPSED, mIsToolbarCollapsed);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* SubSetting page should show a toolbar by default. If the page wouldn't show a toolbar,
|
* SubSetting page should show a toolbar by default. If the page wouldn't show a toolbar,
|
||||||
* override this method and return false value.
|
* override this method and return false value.
|
||||||
@@ -238,6 +265,9 @@ public class SettingsBaseActivity extends FragmentActivity implements CategoryHa
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void disableCollapsingToolbarLayoutScrollingBehavior() {
|
private void disableCollapsingToolbarLayoutScrollingBehavior() {
|
||||||
|
if (mAppBarLayout == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
final CoordinatorLayout.LayoutParams params =
|
final CoordinatorLayout.LayoutParams params =
|
||||||
(CoordinatorLayout.LayoutParams) mAppBarLayout.getLayoutParams();
|
(CoordinatorLayout.LayoutParams) mAppBarLayout.getLayoutParams();
|
||||||
final AppBarLayout.Behavior behavior = new AppBarLayout.Behavior();
|
final AppBarLayout.Behavior behavior = new AppBarLayout.Behavior();
|
||||||
@@ -254,4 +284,39 @@ public class SettingsBaseActivity extends FragmentActivity implements CategoryHa
|
|||||||
private int getTransitionType(Intent intent) {
|
private int getTransitionType(Intent intent) {
|
||||||
return intent.getIntExtra(EXTRA_PAGE_TRANSITION_TYPE, TransitionType.TRANSITION_NONE);
|
return intent.getIntExtra(EXTRA_PAGE_TRANSITION_TYPE, TransitionType.TRANSITION_NONE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("RestrictTo")
|
||||||
|
private void initCollapsingToolbar() {
|
||||||
|
if (mCollapsingToolbarLayout == null || mAppBarLayout == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
mCollapsingToolbarLayout.addOnLayoutChangeListener(new View.OnLayoutChangeListener() {
|
||||||
|
@Override
|
||||||
|
public void onLayoutChange(View v, int left, int top, int right, int bottom,
|
||||||
|
int oldLeft, int oldTop, int oldRight, int oldBottom) {
|
||||||
|
v.removeOnLayoutChangeListener(this);
|
||||||
|
if (mIsToolbarCollapsed) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
final int count = mCollapsingToolbarLayout.getLineCount();
|
||||||
|
if (count > TOOLBAR_MAX_LINE_NUMBER) {
|
||||||
|
final ViewGroup.LayoutParams lp = mCollapsingToolbarLayout.getLayoutParams();
|
||||||
|
lp.height = getResources()
|
||||||
|
.getDimensionPixelSize(R.dimen.toolbar_three_lines_height);
|
||||||
|
mCollapsingToolbarLayout.setScrimVisibleHeightTrigger(
|
||||||
|
getResources().getDimensionPixelSize(
|
||||||
|
R.dimen.scrim_visible_height_trigger_three_lines));
|
||||||
|
mCollapsingToolbarLayout.setLayoutParams(lp);
|
||||||
|
} else if (count == TOOLBAR_MAX_LINE_NUMBER) {
|
||||||
|
final ViewGroup.LayoutParams lp = mCollapsingToolbarLayout.getLayoutParams();
|
||||||
|
lp.height = getResources()
|
||||||
|
.getDimensionPixelSize(R.dimen.toolbar_two_lines_height);
|
||||||
|
mCollapsingToolbarLayout.setScrimVisibleHeightTrigger(
|
||||||
|
getResources().getDimensionPixelSize(
|
||||||
|
R.dimen.scrim_visible_height_trigger_two_lines));
|
||||||
|
mCollapsingToolbarLayout.setLayoutParams(lp);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user