Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -296,21 +296,15 @@ public CollapsingToolbarLayout(
collapsingTitleEnabled = a.getBoolean(R.styleable.CollapsingToolbarLayout_titleEnabled, true);
setTitle(a.getText(R.styleable.CollapsingToolbarLayout_title));

// First load the default text appearances
collapsingTitleHelper.setExpandedTextAppearance(
R.style.TextAppearance_Design_CollapsingToolbar_Expanded);
collapsingTitleHelper.setCollapsedTextAppearance(
androidx.appcompat.R.style.TextAppearance_AppCompat_Widget_ActionBar_Title);
a.getResourceId(
R.styleable.CollapsingToolbarLayout_expandedTitleTextAppearance,
R.style.TextAppearance_Design_CollapsingToolbar_Expanded));

// Now overlay any custom text appearances
if (a.hasValue(R.styleable.CollapsingToolbarLayout_expandedTitleTextAppearance)) {
collapsingTitleHelper.setExpandedTextAppearance(
a.getResourceId(R.styleable.CollapsingToolbarLayout_expandedTitleTextAppearance, 0));
}
if (a.hasValue(R.styleable.CollapsingToolbarLayout_collapsedTitleTextAppearance)) {
collapsingTitleHelper.setCollapsedTextAppearance(
a.getResourceId(R.styleable.CollapsingToolbarLayout_collapsedTitleTextAppearance, 0));
}
collapsingTitleHelper.setCollapsedTextAppearance(
a.getResourceId(
R.styleable.CollapsingToolbarLayout_collapsedTitleTextAppearance,
androidx.appcompat.R.style.TextAppearance_AppCompat_Widget_ActionBar_Title));

// Now overlay any custom text Ellipsize
if (a.hasValue(R.styleable.CollapsingToolbarLayout_titleTextEllipsize)) {
Expand Down Expand Up @@ -358,18 +352,17 @@ public CollapsingToolbarLayout(

collapsingSubtitleHelper.setExpandedTextGravity(titleExpandedGravity);
collapsingSubtitleHelper.setCollapsedTextGravity(titleCollapsedGravity);

collapsingSubtitleHelper.setExpandedTextAppearance(
androidx.appcompat.R.style.TextAppearance_AppCompat_Headline);
a.getResourceId(
R.styleable.CollapsingToolbarLayout_expandedSubtitleTextAppearance,
androidx.appcompat.R.style.TextAppearance_AppCompat_Headline));

collapsingSubtitleHelper.setCollapsedTextAppearance(
androidx.appcompat.R.style.TextAppearance_AppCompat_Widget_ActionBar_Subtitle);
if (a.hasValue(R.styleable.CollapsingToolbarLayout_expandedSubtitleTextAppearance)) {
collapsingSubtitleHelper.setExpandedTextAppearance(
a.getResourceId(R.styleable.CollapsingToolbarLayout_expandedSubtitleTextAppearance, 0));
}
if (a.hasValue(R.styleable.CollapsingToolbarLayout_collapsedSubtitleTextAppearance)) {
collapsingSubtitleHelper.setCollapsedTextAppearance(
a.getResourceId(R.styleable.CollapsingToolbarLayout_collapsedSubtitleTextAppearance, 0));
}
a.getResourceId(
R.styleable.CollapsingToolbarLayout_collapsedSubtitleTextAppearance,
androidx.appcompat.R.style.TextAppearance_AppCompat_Widget_ActionBar_Subtitle));

if (a.hasValue(R.styleable.CollapsingToolbarLayout_expandedSubtitleTextColor)) {
collapsingSubtitleHelper.setExpandedTextColor(
MaterialResources.getColorStateList(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ public final class CollapsingTextHelper {

private static final float FADE_MODE_THRESHOLD_FRACTION_RELATIVE = 0.5f;

private static final float MIN_EXPANDED_COLLAPSED_TEXT_SIZE = 0.1f;

private static final boolean DEBUG_DRAW = false;
@Nullable private static final Paint DEBUG_DRAW_PAINT;

Expand Down Expand Up @@ -452,18 +454,15 @@ public int getCollapsedTextGravity() {
public void setCollapsedTextAppearance(int resId) {
TextAppearance textAppearance = new TextAppearance(view.getContext(), resId);

if (textAppearance.getTextColor() != null) {
collapsedTextColor = textAppearance.getTextColor();
}
if (textAppearance.getTextSize() != 0) {
collapsedTextSize = textAppearance.getTextSize();
}
if (textAppearance.shadowColor != null) {
collapsedShadowColor = textAppearance.shadowColor;
}
collapsedTextSize = textAppearance.getTextSize() > 0
? textAppearance.getTextSize()
: MIN_EXPANDED_COLLAPSED_TEXT_SIZE;

collapsedTextColor = textAppearance.getTextColor();
collapsedShadowDx = textAppearance.shadowDx;
collapsedShadowDy = textAppearance.shadowDy;
collapsedShadowRadius = textAppearance.shadowRadius;
collapsedShadowColor = textAppearance.shadowColor;
collapsedLetterSpacing = textAppearance.letterSpacing;

// Cancel pending async fetch, if any, and replace with a new one.
Expand All @@ -486,18 +485,16 @@ public void apply(Typeface font) {

public void setExpandedTextAppearance(int resId) {
TextAppearance textAppearance = new TextAppearance(view.getContext(), resId);
if (textAppearance.getTextColor() != null) {
expandedTextColor = textAppearance.getTextColor();
}
if (textAppearance.getTextSize() != 0) {
expandedTextSize = textAppearance.getTextSize();
}
if (textAppearance.shadowColor != null) {
expandedShadowColor = textAppearance.shadowColor;
}

expandedTextSize = textAppearance.getTextSize() > 0
? textAppearance.getTextSize()
: MIN_EXPANDED_COLLAPSED_TEXT_SIZE;

expandedTextColor = textAppearance.getTextColor();
expandedShadowDx = textAppearance.shadowDx;
expandedShadowDy = textAppearance.shadowDy;
expandedShadowRadius = textAppearance.shadowRadius;
expandedShadowColor = textAppearance.shadowColor;
expandedLetterSpacing = textAppearance.letterSpacing;

// Cancel pending async fetch, if any, and replace with a new one.
Expand Down