@@ -76,6 +76,7 @@ public class ToolbarLayout extends LinearLayout {
7676 public static final int MAIN_CONTENT = 6 ;
7777 public static final int FOOTER_CONTENT = 7 ;
7878 private static String TAG = "ToolbarLayout" ;
79+ private boolean mIsOneUI4 ;
7980 public ViewGroup navigationBadgeBackground ;
8081 public TextView navigationBadgeText ;
8182 public ViewGroup moreOverflowBadgeBackground ;
@@ -170,6 +171,8 @@ public ToolbarLayout(Context context, @Nullable AttributeSet attrs) {
170171 mContext = context ;
171172 mActivity = getActivity ();
172173
174+ mIsOneUI4 = context .getTheme ().obtainStyledAttributes (new int []{R .attr .isOneUI4 }).getBoolean (0 , false );
175+
173176 TypedArray attr = mContext .getTheme ().obtainStyledAttributes (attrs , R .styleable .ToolBarLayout , 0 , 0 );
174177
175178 try {
@@ -283,10 +286,17 @@ public LayoutParams generateLayoutParams(AttributeSet attrs) {
283286 return new Drawer_Toolbar_LayoutParams (getContext (), attrs );
284287 }
285288
289+ @ Override
290+ public void onAttachedToWindow () {
291+ super .onAttachedToWindow ();
292+ resetToolbarHeight ();
293+ }
294+
286295 @ Override
287296 protected void onConfigurationChanged (Configuration newConfig ) {
288297 super .onConfigurationChanged (newConfig );
289298 refreshLayout (newConfig );
299+ resetToolbarHeight ();
290300 }
291301
292302 private AppCompatActivity getActivity () {
@@ -304,6 +314,10 @@ private float getDIPForPX(int i) {
304314 return TypedValue .applyDimension (TypedValue .COMPLEX_UNIT_DIP , (float ) i , getResources ().getDisplayMetrics ());
305315 }
306316
317+ private int getToolbarTopPadding () {
318+ return mIsOneUI4 ? getResources ().getDimensionPixelSize (R .dimen .sesl4_action_bar_top_padding ) : 0 ;
319+ }
320+
307321 private int getWindowHeight () {
308322 try {
309323 WindowManager windowManager = (WindowManager ) mContext .getSystemService (Context .WINDOW_SERVICE );
@@ -342,14 +356,14 @@ private void resetAppBarHeight() {
342356 if (getResources ().getConfiguration ().orientation == Configuration .ORIENTATION_LANDSCAPE ) {
343357 appBarLayout .setActivated (false );
344358 bottomPadding = 0 ;
345- params .height = (int ) getResources ().getDimension (R .dimen .sesl_action_bar_default_height );
359+ params .height = (int ) getResources ().getDimension (mIsOneUI4 ? R . dimen . sesl4_action_bar_default_height : R .dimen .sesl_action_bar_default_height );
346360 } else {
347361 appBarLayout .setActivated (true );
348362 setExpanded (mExpanded , false );
349- bottomPadding = getResources ().getDimensionPixelSize (R .dimen .sesl_extended_appbar_bottom_padding );
363+ bottomPadding = mIsOneUI4 ? 0 : getResources ().getDimensionPixelSize (R .dimen .sesl_extended_appbar_bottom_padding );
350364
351365 TypedValue outValue = new TypedValue ();
352- getResources ().getValue (R .dimen .sesl_appbar_height_proportion , outValue , true );
366+ getResources ().getValue (mIsOneUI4 ? R . dimen . sesl4_appbar_height_proportion : R .dimen .sesl_appbar_height_proportion , outValue , true );
353367
354368 params .height = (int ) ((float ) windowHeight * outValue .getFloat ());
355369 }
@@ -360,6 +374,17 @@ private void resetAppBarHeight() {
360374 Log .w (TAG + ".resetAppBarHeight" , "appBarLayout is null." );
361375 }
362376
377+ private void resetToolbarHeight () {
378+ if (toolbar != null ) {
379+ toolbar .setPaddingRelative (mSelectMode || mSearchMode || navigationButtonVisible ? 0 : getResources ().getDimensionPixelSize (R .dimen .sesl_action_bar_content_inset ), getToolbarTopPadding (), 0 , 0 );
380+
381+ ViewGroup .LayoutParams lp = toolbar .getLayoutParams ();
382+ lp .height = lp .height + getToolbarTopPadding ();
383+ toolbar .setLayoutParams (lp );
384+ } else
385+ Log .w (TAG + ".resetToolbarHeight" , "toolbar is null." );
386+ }
387+
363388 //
364389 // AppBar methods
365390 //
@@ -396,7 +421,7 @@ public void setSubtitle(CharSequence subtitle) {
396421
397422 private void updateCollapsedSubtitleVisibility () {
398423 TypedValue outValue = new TypedValue ();
399- getResources ().getValue (R .dimen .sesl_appbar_height_proportion , outValue , true );
424+ getResources ().getValue (mIsOneUI4 ? R . dimen . sesl4_appbar_height_proportion : R .dimen .sesl_appbar_height_proportion , outValue , true );
400425 if (!mExpandable || outValue .getFloat () == 0.0 ) {
401426 collapsedSubTitleView .setVisibility ((mSubtitle != null && mSubtitle .length () != 0 ) ? VISIBLE : GONE );
402427 } else {
@@ -667,7 +692,7 @@ public void setNavigationButtonIcon(Drawable navigationIcon) {
667692 public void setNavigationButtonVisible (boolean visible ) {
668693 navigationButtonContainer .setVisibility (visible ? View .VISIBLE : View .GONE );
669694 if (!(mSelectMode || mSearchMode )) navigationButtonVisible = visible ;
670- toolbar .setPaddingRelative (mSelectMode || mSearchMode || visible ? 0 : getResources ().getDimensionPixelSize (R .dimen .sesl_action_bar_content_inset ), 0 , 0 , 0 );
695+ toolbar .setPaddingRelative (mSelectMode || mSearchMode || visible ? 0 : getResources ().getDimensionPixelSize (R .dimen .sesl_action_bar_content_inset ), getToolbarTopPadding () , 0 , 0 );
671696 }
672697
673698 public void setNavigationButtonBadge (int count ) {
@@ -754,7 +779,7 @@ private void addActionButton(MenuItem item) {
754779
755780 ToolbarImageButton actionButton = new ToolbarImageButton (mContext );
756781
757- ViewGroup .LayoutParams lp = new ViewGroup .LayoutParams (getResources ().getDimensionPixelSize (R .dimen .sesl_overflow_button_min_width ), getResources ().getDimensionPixelSize (R .dimen .sesl_action_bar_default_height ));
782+ ViewGroup .LayoutParams lp = new ViewGroup .LayoutParams (getResources ().getDimensionPixelSize (R .dimen .sesl_overflow_button_min_width ), getResources ().getDimensionPixelSize (mIsOneUI4 ? R . dimen . sesl4_action_bar_default_height : R .dimen .sesl_action_bar_default_height ));
758783
759784 actionButton .setBackgroundResource (R .drawable .sesl_action_bar_item_background );
760785 actionButton .setImageDrawable (item .getIcon ());
@@ -790,7 +815,7 @@ private void setOverflowMenu(ArrayList<MenuItem> overflowItems) {
790815
791816 overflowButton = new ToolbarImageButton (mContext );
792817
793- ViewGroup .LayoutParams lp2 = new ViewGroup .LayoutParams (getResources ().getDimensionPixelSize (R .dimen .sesl_overflow_button_min_width ), getResources ().getDimensionPixelSize (R .dimen .sesl_action_bar_default_height ));
818+ ViewGroup .LayoutParams lp2 = new ViewGroup .LayoutParams (getResources ().getDimensionPixelSize (R .dimen .sesl_overflow_button_min_width ), getResources ().getDimensionPixelSize (mIsOneUI4 ? R . dimen . sesl4_action_bar_default_height : R .dimen .sesl_action_bar_default_height ));
794819
795820 overflowButton .setBackgroundResource (R .drawable .sesl_action_bar_item_background );
796821 overflowButton .setImageResource (R .drawable .sesl_ic_menu_overflow );
@@ -958,7 +983,7 @@ public void onOffsetChanged(SamsungAppBarLayout layout, int verticalOffset) {
958983
959984 LinearLayout collapsedTitleContainer = findViewById (R .id .toolbar_layout_collapsed_title_container );
960985
961- if (appBarLayout .getHeight () <= ((int ) getResources ().getDimension (R .dimen .sesl_action_bar_height_with_padding ))) {
986+ if (appBarLayout .getHeight () <= ((int ) getResources ().getDimension (mIsOneUI4 ? R . dimen . sesl4_action_bar_height_with_padding : R .dimen .sesl_action_bar_height_with_padding ))) {
962987 collapsedTitleContainer .setAlpha (1.0f );
963988 } else {
964989 float collapsedTitleAlpha = ((150.0f / alphaRange ) * (((float ) layoutPosition ) - toolbarTitleAlphaStart ));
0 commit comments