Merge pull request #2488 from material-components/revert-2406-master

Revert "[Material Toolbar] Change logo scaleType and set logo adjustViewBounds"
This commit is contained in:
Dan Nizri 2021-12-01 19:04:06 -05:00 committed by GitHub
commit 5b6c878cbb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 0 additions and 132 deletions

View File

@ -706,13 +706,6 @@ Element | Attribute | Related meth
**Height** | `app:height` | N/A | `?attr/actionBarSize`
**Overlay window** | `app:windowActionModeOverlay` (in app theme) | N/A | `false`
#### Toolbar logo attributes
Element | Attribute | Related method(s) | Default value
--------------------- | -------------------------------------------- | ----------------- | -------------
**AdjustViewBounds** | `app:logoAdjustViewBounds` | `setLogoAdjustViewBounds`<br>`isLogoAdjustViewBounds` | `false`
**ScaleType** | `app:logoScaleType` | `setLogoScaleType`<br>`getLogoScaleType` | `fitCenter`
#### Styles
Element | Style

View File

@ -33,7 +33,6 @@ import androidx.appcompat.widget.Toolbar;
import android.util.AttributeSet;
import android.util.Pair;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;
import androidx.annotation.ColorInt;
import androidx.annotation.NonNull;
@ -70,24 +69,10 @@ public class MaterialToolbar extends Toolbar {
private static final int DEF_STYLE_RES = R.style.Widget_MaterialComponents_Toolbar;
private static final ImageView.ScaleType[] LOGO_SCALE_TYPE_ARRAY = {
ImageView.ScaleType.MATRIX,
ImageView.ScaleType.FIT_XY,
ImageView.ScaleType.FIT_START,
ImageView.ScaleType.FIT_CENTER,
ImageView.ScaleType.FIT_END,
ImageView.ScaleType.CENTER,
ImageView.ScaleType.CENTER_CROP,
ImageView.ScaleType.CENTER_INSIDE
};
@Nullable private Integer navigationIconTint;
private boolean titleCentered;
private boolean subtitleCentered;
private ImageView.ScaleType logoScaleType;
private boolean logoAdjustViewBounds;
public MaterialToolbar(@NonNull Context context) {
this(context, null);
}
@ -112,15 +97,6 @@ public class MaterialToolbar extends Toolbar {
titleCentered = a.getBoolean(R.styleable.MaterialToolbar_titleCentered, false);
subtitleCentered = a.getBoolean(R.styleable.MaterialToolbar_subtitleCentered, false);
final int index = a.getInt(R.styleable.MaterialToolbar_logoScaleType, -1);
if (index >= 0 && index < LOGO_SCALE_TYPE_ARRAY.length) {
logoScaleType = (LOGO_SCALE_TYPE_ARRAY[index]);
} else {
logoScaleType = ImageView.ScaleType.FIT_CENTER;
}
logoAdjustViewBounds = a.getBoolean(R.styleable.MaterialToolbar_logoAdjustViewBounds, false);
a.recycle();
initBackground(context);
@ -131,7 +107,6 @@ public class MaterialToolbar extends Toolbar {
super.onLayout(changed, left, top, right, bottom);
maybeCenterTitleViews();
updateLogoImageView();
}
private void maybeCenterTitleViews() {
@ -157,15 +132,6 @@ public class MaterialToolbar extends Toolbar {
}
}
private void updateLogoImageView() {
ImageView logoImageView = ToolbarUtils.getLogoImageView(this);
if (logoImageView != null) {
logoImageView.setAdjustViewBounds(logoAdjustViewBounds);
logoImageView.setScaleType(logoScaleType);
}
}
private Pair<Integer, Integer> calculateTitleBoundLimits(
@Nullable TextView titleTextView, @Nullable TextView subtitleTextView) {
int width = getMeasuredWidth();
@ -295,45 +261,6 @@ public class MaterialToolbar extends Toolbar {
}
}
/**
* Returns scale type of logo's ImageView
*
* @see #setLogoScaleType(ImageView.ScaleType). Default - fitCenter
*/
public ImageView.ScaleType getLogoScaleType() {
return logoScaleType;
}
/**
* Sets ImageView.ScaleType for logo's ImageView.
*/
public void setLogoScaleType(ImageView.ScaleType logoScaleType) {
if (this.logoScaleType != logoScaleType) {
this.logoScaleType = logoScaleType;
requestLayout();
}
}
/**
* Returns logo's ImageView adjustViewBounds
*
* @see #setLogoAdjustViewBounds(boolean). Default - false
*/
public boolean isLogoAdjustViewBounds() {
return logoAdjustViewBounds;
}
/**
* Sets ImageView.adjustViewBounds for logo's ImageView.
*/
public void setLogoAdjustViewBounds(boolean logoAdjustViewBounds) {
if (this.logoAdjustViewBounds != logoAdjustViewBounds) {
this.logoAdjustViewBounds = logoAdjustViewBounds;
requestLayout();
}
}
/**
* Returns whether the subtitle text corresponding to the {@link #setSubtitle(int)} method should
* be centered horizontally within the toolbar.

View File

@ -85,7 +85,5 @@
<public name="titleCentered" type="attr"/>
<public name="subtitleCentered" type="attr"/>
<public name="titlePositionInterpolator" type="attr"/>
<public name="logoAdjustViewBounds" type="attr"/>
<public name="logoScaleType" type="attr"/>
</resources>

View File

@ -276,34 +276,6 @@
should be centered horizontally within the toolbar. Default is false.
-->
<attr name="subtitleCentered" format="boolean" />
<!-- adjust view bounds for logo's imageView. Default is false. -->
<attr name="logoAdjustViewBounds" format="boolean" />
<!-- scale type for logo's imageView. Default is fitCenter. -->
<attr name="logoScaleType">
<!-- Scale using the image matrix when drawing. See
{@link android.widget.ImageView#setImageMatrix(Matrix)}. -->
<enum name="matrix" value="0" />
<!-- Scale the image using {@link android.graphics.Matrix.ScaleToFit#FILL}. -->
<enum name="fitXY" value="1" />
<!-- Scale the image using {@link android.graphics.Matrix.ScaleToFit#START}. -->
<enum name="fitStart" value="2" />
<!-- Scale the image using {@link android.graphics.Matrix.ScaleToFit#CENTER}. -->
<enum name="fitCenter" value="3" />
<!-- Scale the image using {@link android.graphics.Matrix.ScaleToFit#END}. -->
<enum name="fitEnd" value="4" />
<!-- Center the image in the view, but perform no scaling. -->
<enum name="center" value="5" />
<!-- Scale the image uniformly (maintain the image's aspect ratio) so both dimensions
(width and height) of the image will be equal to or larger than the corresponding
dimension of the view (minus padding). The image is then centered in the view. -->
<enum name="centerCrop" value="6" />
<!-- Scale the image uniformly (maintain the image's aspect ratio) so that both
dimensions (width and height) of the image will be equal to or less than the
corresponding dimension of the view (minus padding). The image is then centered in
the view. -->
<enum name="centerInside" value="7" />
</attr>
</declare-styleable>
</resources>

View File

@ -23,7 +23,6 @@ import androidx.appcompat.widget.Toolbar;
import android.text.TextUtils;
import android.view.View;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.TextView;
import androidx.annotation.IdRes;
import androidx.annotation.NonNull;
@ -53,11 +52,6 @@ public class ToolbarUtils {
return getTextView(toolbar, toolbar.getSubtitle());
}
@Nullable
public static ImageView getLogoImageView(@NonNull Toolbar toolbar) {
return getImageView(toolbar, toolbar.getLogo());
}
@Nullable
private static TextView getTextView(@NonNull Toolbar toolbar, CharSequence text) {
for (int i = 0; i < toolbar.getChildCount(); i++) {
@ -72,22 +66,6 @@ public class ToolbarUtils {
return null;
}
@Nullable
private static ImageView getImageView(@NonNull Toolbar toolbar, @Nullable Drawable content) {
for (int i = 0; i < toolbar.getChildCount(); i++) {
View child = toolbar.getChildAt(i);
if (child instanceof ImageView) {
ImageView imageView = (ImageView) child;
if (content != null
&& imageView.getDrawable().getConstantState().equals(content.getConstantState())
) {
return imageView;
}
}
}
return null;
}
@Nullable
public static View getSecondaryActionMenuItemView(@NonNull Toolbar toolbar) {
ActionMenuView actionMenuView = getActionMenuView(toolbar);