@@ -83,8 +83,10 @@ public class ToolbarLayout extends LinearLayout {
8383 private NumberFormat numberFormat = NumberFormat .getInstance (Locale .getDefault ());
8484 private Drawable mNavigationIcon ;
8585 private int mLayout ;
86- private CharSequence mTitle ;
87- private CharSequence mSubtitle ;
86+ private CharSequence mTitleExpanded ;
87+ private CharSequence mTitleCollapsed ;
88+ private CharSequence mSubtitleExpanded ;
89+ private CharSequence mSubtitleCollapsed ;
8890 private Boolean mExpandable ;
8991 private Boolean mExpanded ;
9092 private SamsungAppBarLayout appBarLayout ;
@@ -93,11 +95,12 @@ public class ToolbarLayout extends LinearLayout {
9395 private FrameLayout navigationButtonContainer ;
9496 private ToolbarImageButton navigationButton ;
9597 private MaterialTextView collapsedTitleView ;
98+ private MaterialTextView collapsedSubTitleView ;
9699 private RoundLinearLayout mainContainer ;
97100 private LinearLayout bottomContainer ;
98101 private OnBackPressedCallback onBackPressedCallback ;
99102 private DrawerLayout drawerLayout ;
100- private int toolbar_padding_start = 0 ;
103+ private boolean navigationButtonVisible ;
101104
102105 public interface OnMenuItemClickListener {
103106 void onMenuItemClick (MenuItem item );
@@ -165,8 +168,8 @@ public ToolbarLayout(Context context, @Nullable AttributeSet attrs) {
165168 mExpandable = attr .getBoolean (R .styleable .ToolBarLayout_expandable , true );
166169 mExpanded = attr .getBoolean (R .styleable .ToolBarLayout_expanded , true );
167170 mLayout = attr .getResourceId (R .styleable .ToolBarLayout_android_layout , mExpandable ? R .layout .samsung_appbar_toolbarlayout : R .layout .samsung_toolbar_toolbarlayout );
168- mTitle = attr .getString (R .styleable .ToolBarLayout_title );
169- mSubtitle = attr .getString (R .styleable .ToolBarLayout_subtitle );
171+ mTitleExpanded = attr .getString (R .styleable .ToolBarLayout_title );
172+ mSubtitleExpanded = attr .getString (R .styleable .ToolBarLayout_subtitle );
170173 mNavigationIcon = attr .getDrawable (R .styleable .ToolBarLayout_navigationIcon );
171174 } finally {
172175 attr .recycle ();
@@ -178,12 +181,15 @@ public ToolbarLayout(Context context, @Nullable AttributeSet attrs) {
178181 if (mExpandable ) {
179182 appBarLayout = findViewById (R .id .toolbar_layout_app_bar );
180183 collapsingToolbarLayout = findViewById (R .id .toolbar_layout_collapsing_toolbar_layout );
184+
185+ appBarLayout .setLiftableState (false );
181186 }
182187 toolbar = findViewById (R .id .toolbar_layout_toolbar );
183188
184189 navigationButtonContainer = findViewById (R .id .toolbar_layout_navigationButton_container );
185190 navigationButton = findViewById (R .id .toolbar_layout_navigationButton );
186191 collapsedTitleView = findViewById (R .id .toolbar_layout_collapsed_title );
192+ collapsedSubTitleView = findViewById (R .id .toolbar_layout_collapsed_subtitle );
187193 actionButtonContainer = findViewById (R .id .toolbar_layout_overflow_container );
188194 overflowMenuPopupAnchor = findViewById (R .id .toolbar_layout_popup_window_anchor );
189195
@@ -213,11 +219,14 @@ public ToolbarLayout(Context context, @Nullable AttributeSet attrs) {
213219 mActivity .getSupportActionBar ().setDisplayShowTitleEnabled (false );
214220 mActivity .getSupportActionBar ().setDisplayHomeAsUpEnabled (false );
215221 setNavigationButtonIcon (mNavigationIcon );
216- setTitle (mTitle );
217- setSubtitle (mSubtitle );
222+ setTitle (mTitleExpanded );
223+ setSubtitle (mSubtitleExpanded );
218224
219- if (mExpandable )
225+ if (mExpandable ) {
220226 appBarLayout .addOnOffsetChangedListener (new AppBarOffsetListener ());
227+ } else {
228+ findViewById (R .id .toolbar_layout_collapsed_title_container ).setAlpha (1.0f );
229+ }
221230
222231 /*back logic*/
223232 onBackPressedCallback = new OnBackPressedCallback (false ) {
@@ -321,9 +330,9 @@ private void refreshLayout(Configuration newConfig) {
321330 ViewSupport .updateListBothSideMargin (mActivity , findViewById (R .id .toolbar_layout_bottom_corners ));
322331 ViewSupport .updateListBothSideMargin (mActivity , findViewById (R .id .toolbar_layout_footer_container ));
323332
324- if (mExpandable ) {
325- resetAppBarHeight ();
326- }
333+ if (mExpandable ) resetAppBarHeight ();
334+
335+ updateCollapsedSubtitleVisibility ();
327336 }
328337
329338 private void resetAppBarHeight () {
@@ -369,19 +378,37 @@ public void setTitle(CharSequence title) {
369378 }
370379
371380 public void setTitle (CharSequence expandedTitle , CharSequence collapsedTitle ) {
372- mTitle = collapsedTitle ;
381+ mTitleCollapsed = collapsedTitle ;
382+ mTitleExpanded = expandedTitle ;
373383 if (mExpandable ) {
374384 collapsingToolbarLayout .setTitle (expandedTitle );
375385 }
376- collapsedTitleView .setText (mTitle );
386+ collapsedTitleView .setText (collapsedTitle );
377387 }
378388
379389 public void setSubtitle (CharSequence subtitle ) {
380- mSubtitle = subtitle ;
390+ setSubtitle (subtitle , subtitle );
391+ }
392+
393+ public void setSubtitle (CharSequence expandedSubtitle , CharSequence collapsedSubtitle ) {
394+ mSubtitleCollapsed = collapsedSubtitle ;
395+ mSubtitleExpanded = expandedSubtitle ;
381396 if (mExpandable ) {
382- collapsingToolbarLayout .setSubtitle (mSubtitle );
383- } else
384- Log .d (TAG + ".setAppBarSubtitle" , "mExpandable is " + mExpandable );
397+ collapsingToolbarLayout .setSubtitle (expandedSubtitle );
398+ }
399+ collapsedSubTitleView .setText (collapsedSubtitle );
400+
401+ updateCollapsedSubtitleVisibility ();
402+ }
403+
404+ private void updateCollapsedSubtitleVisibility () {
405+ TypedValue outValue = new TypedValue ();
406+ getResources ().getValue (R .dimen .sesl_appbar_height_proportion , outValue , true );
407+ if (!mExpandable || outValue .getFloat () == 0.0 ) {
408+ collapsedSubTitleView .setVisibility ((mSubtitleCollapsed != null && mSubtitleCollapsed .length () != 0 ) ? VISIBLE : GONE );
409+ } else {
410+ collapsedSubTitleView .setVisibility (GONE );
411+ }
385412 }
386413
387414 public void setExpanded (boolean expanded , boolean animate ) {
@@ -415,7 +442,7 @@ public void showSelectMode() {
415442 mSelectMode = true ;
416443 lockDrawerIfAvailable (true );
417444 if (mSearchMode ) dismissSearchMode ();
418- toolbar . setPaddingRelative ( 0 , 0 , 0 , 0 );
445+ setNavigationButtonVisible ( false );
419446 selectModeCheckboxContainer .setVisibility (View .VISIBLE );
420447 setSelectModeCount (0 );
421448 actionButtonContainer .setVisibility (GONE );
@@ -487,9 +514,9 @@ public Menu getSelectModeBottomMenu() {
487514 public void dismissSelectMode () {
488515 mSelectMode = false ;
489516 lockDrawerIfAvailable (false );
490- toolbar . setPaddingRelative ( toolbar_padding_start , 0 , 0 , 0 );
517+ setNavigationButtonVisible ( navigationButtonVisible );
491518 selectModeCheckboxContainer .setVisibility (View .GONE );
492- setTitle (mTitle );
519+ setTitle (mTitleExpanded , mTitleCollapsed );
493520 actionButtonContainer .setVisibility (VISIBLE );
494521
495522 bottomContainer .setVisibility (VISIBLE );
@@ -520,7 +547,7 @@ public void setSelectModeAllChecked(boolean checked) {
520547 public void showSearchMode () {
521548 mSearchMode = true ;
522549 lockDrawerIfAvailable (true );
523- toolbar . setPaddingRelative ( 0 , 0 , 0 , 0 );
550+ setNavigationButtonVisible ( false );
524551 onBackPressedCallback .setEnabled (true );
525552 if (mSelectMode ) dismissSelectMode ();
526553 if (mExpandable )
@@ -568,15 +595,14 @@ public void setSearchModeListener(SearchModeListener listener) {
568595 public void dismissSearchMode () {
569596 mSearchMode = false ;
570597 lockDrawerIfAvailable (false );
571- toolbar . setPaddingRelative ( toolbar_padding_start , 0 , 0 , 0 );
598+ setNavigationButtonVisible ( navigationButtonVisible );
572599 onBackPressedCallback .setEnabled (false );
573600 setEditTextFocus (false );
574601 main_toolbar .setVisibility (VISIBLE );
575602 search_toolbar .setVisibility (GONE );
576603 bottomContainer .setVisibility (VISIBLE );
577604
578- if (mExpandable )
579- collapsingToolbarLayout .setTitle (mTitle );
605+ setTitle (mTitleExpanded , mTitleCollapsed );
580606 }
581607
582608 public boolean isSearchMode () {
@@ -635,8 +661,8 @@ public void setNavigationButtonIcon(Drawable navigationIcon) {
635661
636662 public void setNavigationButtonVisible (boolean visible ) {
637663 navigationButtonContainer .setVisibility (visible ? View .VISIBLE : View .GONE );
638- toolbar_padding_start = visible ? 0 : getResources (). getDimensionPixelSize ( R . dimen . sesl_action_bar_content_inset ) ;
639- toolbar .setPaddingRelative (mSelectMode || mSearchMode ? 0 : toolbar_padding_start , 0 , 0 , 0 );
664+ if (!( mSelectMode || mSearchMode )) navigationButtonVisible = visible ;
665+ toolbar .setPaddingRelative (mSelectMode || mSearchMode || visible ? 0 : getResources (). getDimensionPixelSize ( R . dimen . sesl_action_bar_content_inset ) , 0 , 0 , 0 );
640666 }
641667
642668 public void setNavigationButtonBadge (int count ) {
@@ -877,18 +903,20 @@ public void onOffsetChanged(SamsungAppBarLayout layout, int verticalOffset) {
877903 float alphaRange = ((float ) collapsingToolbarLayout .getHeight ()) * 0.17999999f ;
878904 float toolbarTitleAlphaStart = ((float ) collapsingToolbarLayout .getHeight ()) * 0.35f ;
879905
906+ LinearLayout collapsedTitleContainer = findViewById (R .id .toolbar_layout_collapsed_title_container );
907+
880908 if (appBarLayout .getHeight () <= ((int ) getResources ().getDimension (R .dimen .sesl_action_bar_height_with_padding ))) {
881- collapsedTitleView .setAlpha (1.0f );
909+ collapsedTitleContainer .setAlpha (1.0f );
882910 } else {
883911 float collapsedTitleAlpha = ((150.0f / alphaRange ) * (((float ) layoutPosition ) - toolbarTitleAlphaStart ));
884912
885913 if (collapsedTitleAlpha >= 0.0f && collapsedTitleAlpha <= 255.0f ) {
886914 collapsedTitleAlpha /= 255.0f ;
887- collapsedTitleView .setAlpha (collapsedTitleAlpha );
915+ collapsedTitleContainer .setAlpha (collapsedTitleAlpha );
888916 } else if (collapsedTitleAlpha < 0.0f )
889- collapsedTitleView .setAlpha (0.0f );
917+ collapsedTitleContainer .setAlpha (0.0f );
890918 else
891- collapsedTitleView .setAlpha (1.0f );
919+ collapsedTitleContainer .setAlpha (1.0f );
892920 }
893921 }
894922 }
0 commit comments