Rabbit-R1/android (non root)/java/sources/com/google/android/material/navigationrail/NavigationRailView.java
2024-05-21 17:08:36 -04:00

204 lines
9.7 KiB
Java

package com.google.android.material.navigationrail;
import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.FrameLayout;
import androidx.appcompat.widget.TintTypedArray;
import androidx.core.graphics.Insets;
import androidx.core.view.ViewCompat;
import androidx.core.view.WindowInsetsCompat;
import com.google.android.material.R;
import com.google.android.material.animation.AnimationUtils;
import com.google.android.material.internal.ThemeEnforcement;
import com.google.android.material.internal.ViewUtils;
import com.google.android.material.navigation.NavigationBarView;
import com.google.android.material.resources.MaterialResources;
/* loaded from: classes2.dex */
public class NavigationRailView extends NavigationBarView {
private static final int DEFAULT_HEADER_GRAVITY = 49;
static final int DEFAULT_MENU_GRAVITY = 49;
static final int MAX_ITEM_COUNT = 7;
static final int NO_ITEM_MINIMUM_HEIGHT = -1;
private View headerView;
private Boolean paddingBottomSystemWindowInsets;
private Boolean paddingStartSystemWindowInsets;
private Boolean paddingTopSystemWindowInsets;
private final int topMargin;
public View getHeaderView() {
return this.headerView;
}
@Override // com.google.android.material.navigation.NavigationBarView
public int getMaxItemCount() {
return 7;
}
public NavigationRailView(Context context) {
this(context, null);
}
public NavigationRailView(Context context, AttributeSet attributeSet) {
this(context, attributeSet, R.attr.navigationRailStyle);
}
public NavigationRailView(Context context, AttributeSet attributeSet, int i) {
this(context, attributeSet, i, R.style.Widget_MaterialComponents_NavigationRailView);
}
public NavigationRailView(Context context, AttributeSet attributeSet, int i, int i2) {
super(context, attributeSet, i, i2);
this.paddingTopSystemWindowInsets = null;
this.paddingBottomSystemWindowInsets = null;
this.paddingStartSystemWindowInsets = null;
this.topMargin = getResources().getDimensionPixelSize(R.dimen.mtrl_navigation_rail_margin);
Context context2 = getContext();
TintTypedArray obtainTintedStyledAttributes = ThemeEnforcement.obtainTintedStyledAttributes(context2, attributeSet, R.styleable.NavigationRailView, i, i2, new int[0]);
int resourceId = obtainTintedStyledAttributes.getResourceId(R.styleable.NavigationRailView_headerLayout, 0);
if (resourceId != 0) {
addHeaderView(resourceId);
}
setMenuGravity(obtainTintedStyledAttributes.getInt(R.styleable.NavigationRailView_menuGravity, 49));
if (obtainTintedStyledAttributes.hasValue(R.styleable.NavigationRailView_itemMinHeight)) {
setItemMinimumHeight(obtainTintedStyledAttributes.getDimensionPixelSize(R.styleable.NavigationRailView_itemMinHeight, -1));
}
if (obtainTintedStyledAttributes.hasValue(R.styleable.NavigationRailView_paddingTopSystemWindowInsets)) {
this.paddingTopSystemWindowInsets = Boolean.valueOf(obtainTintedStyledAttributes.getBoolean(R.styleable.NavigationRailView_paddingTopSystemWindowInsets, false));
}
if (obtainTintedStyledAttributes.hasValue(R.styleable.NavigationRailView_paddingBottomSystemWindowInsets)) {
this.paddingBottomSystemWindowInsets = Boolean.valueOf(obtainTintedStyledAttributes.getBoolean(R.styleable.NavigationRailView_paddingBottomSystemWindowInsets, false));
}
if (obtainTintedStyledAttributes.hasValue(R.styleable.NavigationRailView_paddingStartSystemWindowInsets)) {
this.paddingStartSystemWindowInsets = Boolean.valueOf(obtainTintedStyledAttributes.getBoolean(R.styleable.NavigationRailView_paddingStartSystemWindowInsets, false));
}
int dimensionPixelOffset = getResources().getDimensionPixelOffset(R.dimen.m3_navigation_rail_item_padding_top_with_large_font);
int dimensionPixelOffset2 = getResources().getDimensionPixelOffset(R.dimen.m3_navigation_rail_item_padding_bottom_with_large_font);
float lerp = AnimationUtils.lerp(0.0f, 1.0f, 0.3f, 1.0f, MaterialResources.getFontScale(context2) - 1.0f);
float lerp2 = AnimationUtils.lerp(getItemPaddingTop(), dimensionPixelOffset, lerp);
float lerp3 = AnimationUtils.lerp(getItemPaddingBottom(), dimensionPixelOffset2, lerp);
setItemPaddingTop(Math.round(lerp2));
setItemPaddingBottom(Math.round(lerp3));
obtainTintedStyledAttributes.recycle();
applyWindowInsets();
}
private void applyWindowInsets() {
ViewUtils.doOnApplyWindowInsets(this, new ViewUtils.OnApplyWindowInsetsListener() { // from class: com.google.android.material.navigationrail.NavigationRailView.1
@Override // com.google.android.material.internal.ViewUtils.OnApplyWindowInsetsListener
public WindowInsetsCompat onApplyWindowInsets(View view, WindowInsetsCompat windowInsetsCompat, ViewUtils.RelativePadding relativePadding) {
Insets insets = windowInsetsCompat.getInsets(WindowInsetsCompat.Type.systemBars());
NavigationRailView navigationRailView = NavigationRailView.this;
if (navigationRailView.shouldApplyWindowInsetPadding(navigationRailView.paddingTopSystemWindowInsets)) {
relativePadding.top += insets.top;
}
NavigationRailView navigationRailView2 = NavigationRailView.this;
if (navigationRailView2.shouldApplyWindowInsetPadding(navigationRailView2.paddingBottomSystemWindowInsets)) {
relativePadding.bottom += insets.bottom;
}
NavigationRailView navigationRailView3 = NavigationRailView.this;
if (navigationRailView3.shouldApplyWindowInsetPadding(navigationRailView3.paddingStartSystemWindowInsets)) {
relativePadding.start += ViewUtils.isLayoutRtl(view) ? insets.right : insets.left;
}
relativePadding.applyToView(view);
return windowInsetsCompat;
}
});
}
/* JADX INFO: Access modifiers changed from: private */
public boolean shouldApplyWindowInsetPadding(Boolean bool) {
return bool != null ? bool.booleanValue() : ViewCompat.getFitsSystemWindows(this);
}
@Override // android.widget.FrameLayout, android.view.View
protected void onMeasure(int i, int i2) {
int makeMinWidthSpec = makeMinWidthSpec(i);
super.onMeasure(makeMinWidthSpec, i2);
if (isHeaderViewVisible()) {
measureChild(getNavigationRailMenuView(), makeMinWidthSpec, View.MeasureSpec.makeMeasureSpec((getMeasuredHeight() - this.headerView.getMeasuredHeight()) - this.topMargin, Integer.MIN_VALUE));
}
}
@Override // android.widget.FrameLayout, android.view.ViewGroup, android.view.View
protected void onLayout(boolean z, int i, int i2, int i3, int i4) {
super.onLayout(z, i, i2, i3, i4);
NavigationRailMenuView navigationRailMenuView = getNavigationRailMenuView();
int i5 = 0;
if (isHeaderViewVisible()) {
int bottom = this.headerView.getBottom() + this.topMargin;
int top = navigationRailMenuView.getTop();
if (top < bottom) {
i5 = bottom - top;
}
} else if (navigationRailMenuView.isTopGravity()) {
i5 = this.topMargin;
}
if (i5 > 0) {
navigationRailMenuView.layout(navigationRailMenuView.getLeft(), navigationRailMenuView.getTop() + i5, navigationRailMenuView.getRight(), navigationRailMenuView.getBottom() + i5);
}
}
public void addHeaderView(int i) {
addHeaderView(LayoutInflater.from(getContext()).inflate(i, (ViewGroup) this, false));
}
public void addHeaderView(View view) {
removeHeaderView();
this.headerView = view;
FrameLayout.LayoutParams layoutParams = new FrameLayout.LayoutParams(-2, -2);
layoutParams.gravity = 49;
layoutParams.topMargin = this.topMargin;
addView(view, 0, layoutParams);
}
public void removeHeaderView() {
View view = this.headerView;
if (view != null) {
removeView(view);
this.headerView = null;
}
}
public void setMenuGravity(int i) {
getNavigationRailMenuView().setMenuGravity(i);
}
public int getMenuGravity() {
return getNavigationRailMenuView().getMenuGravity();
}
public int getItemMinimumHeight() {
return ((NavigationRailMenuView) getMenuView()).getItemMinimumHeight();
}
public void setItemMinimumHeight(int i) {
((NavigationRailMenuView) getMenuView()).setItemMinimumHeight(i);
}
private NavigationRailMenuView getNavigationRailMenuView() {
return (NavigationRailMenuView) getMenuView();
}
/* JADX INFO: Access modifiers changed from: protected */
@Override // com.google.android.material.navigation.NavigationBarView
public NavigationRailMenuView createNavigationBarMenuView(Context context) {
return new NavigationRailMenuView(context);
}
private int makeMinWidthSpec(int i) {
int suggestedMinimumWidth = getSuggestedMinimumWidth();
if (View.MeasureSpec.getMode(i) == 1073741824 || suggestedMinimumWidth <= 0) {
return i;
}
return View.MeasureSpec.makeMeasureSpec(Math.min(View.MeasureSpec.getSize(i), suggestedMinimumWidth + getPaddingLeft() + getPaddingRight()), 1073741824);
}
private boolean isHeaderViewVisible() {
View view = this.headerView;
return (view == null || view.getVisibility() == 8) ? false : true;
}
}