package androidx.legacy.app; import android.R; import android.app.ActionBar; import android.app.Activity; import android.content.Context; import android.content.res.Configuration; import android.content.res.TypedArray; import android.graphics.Canvas; import android.graphics.Rect; import android.graphics.drawable.Drawable; import android.graphics.drawable.InsetDrawable; import android.view.MenuItem; import android.view.View; import android.view.ViewGroup; import android.widget.ImageView; import androidx.annotation.DrawableRes; import androidx.annotation.NonNull; import androidx.annotation.Nullable; import androidx.annotation.StringRes; import androidx.core.content.ContextCompat; import androidx.core.view.GravityCompat; import androidx.core.view.ViewCompat; import androidx.drawerlayout.widget.DrawerLayout; import java.lang.reflect.Method; @Deprecated /* loaded from: classes.dex */ public class ActionBarDrawerToggle implements DrawerLayout.DrawerListener { private static final int ID_HOME = 16908332; private static final String TAG = "ActionBarDrawerToggle"; private static final int[] THEME_ATTRS = {R.attr.homeAsUpIndicator}; private static final float TOGGLE_DRAWABLE_OFFSET = 0.33333334f; final Activity mActivity; private final Delegate mActivityImpl; private final int mCloseDrawerContentDescRes; private Drawable mDrawerImage; private final int mDrawerImageResource; private boolean mDrawerIndicatorEnabled; private final DrawerLayout mDrawerLayout; private boolean mHasCustomUpIndicator; private Drawable mHomeAsUpIndicator; private final int mOpenDrawerContentDescRes; private SetIndicatorInfo mSetIndicatorInfo; private SlideDrawable mSlider; @Deprecated public interface Delegate { @Nullable Drawable getThemeUpIndicator(); void setActionBarDescription(@StringRes int i); void setActionBarUpIndicator(Drawable drawable, @StringRes int i); } @Deprecated public interface DelegateProvider { @Nullable Delegate getDrawerToggleDelegate(); } public boolean isDrawerIndicatorEnabled() { return this.mDrawerIndicatorEnabled; } @Override // androidx.drawerlayout.widget.DrawerLayout.DrawerListener public void onDrawerStateChanged(int i) { } public ActionBarDrawerToggle(Activity activity, DrawerLayout drawerLayout, @DrawableRes int i, @StringRes int i2, @StringRes int i3) { this(activity, drawerLayout, !assumeMaterial(activity), i, i2, i3); } private static boolean assumeMaterial(Context context) { return context.getApplicationInfo().targetSdkVersion >= 21; } /* JADX WARN: Multi-variable type inference failed */ public ActionBarDrawerToggle(Activity activity, DrawerLayout drawerLayout, boolean z, @DrawableRes int i, @StringRes int i2, @StringRes int i3) { this.mDrawerIndicatorEnabled = true; this.mActivity = activity; if (activity instanceof DelegateProvider) { this.mActivityImpl = ((DelegateProvider) activity).getDrawerToggleDelegate(); } else { this.mActivityImpl = null; } this.mDrawerLayout = drawerLayout; this.mDrawerImageResource = i; this.mOpenDrawerContentDescRes = i2; this.mCloseDrawerContentDescRes = i3; this.mHomeAsUpIndicator = getThemeUpIndicator(); this.mDrawerImage = ContextCompat.getDrawable(activity, i); SlideDrawable slideDrawable = new SlideDrawable(this.mDrawerImage); this.mSlider = slideDrawable; slideDrawable.setOffset(z ? TOGGLE_DRAWABLE_OFFSET : 0.0f); } public void syncState() { if (this.mDrawerLayout.isDrawerOpen(GravityCompat.START)) { this.mSlider.setPosition(1.0f); } else { this.mSlider.setPosition(0.0f); } if (this.mDrawerIndicatorEnabled) { setActionBarUpIndicator(this.mSlider, this.mDrawerLayout.isDrawerOpen(GravityCompat.START) ? this.mCloseDrawerContentDescRes : this.mOpenDrawerContentDescRes); } } public void setHomeAsUpIndicator(Drawable drawable) { if (drawable == null) { this.mHomeAsUpIndicator = getThemeUpIndicator(); this.mHasCustomUpIndicator = false; } else { this.mHomeAsUpIndicator = drawable; this.mHasCustomUpIndicator = true; } if (this.mDrawerIndicatorEnabled) { return; } setActionBarUpIndicator(this.mHomeAsUpIndicator, 0); } public void setHomeAsUpIndicator(int i) { setHomeAsUpIndicator(i != 0 ? ContextCompat.getDrawable(this.mActivity, i) : null); } public void setDrawerIndicatorEnabled(boolean z) { if (z != this.mDrawerIndicatorEnabled) { if (z) { setActionBarUpIndicator(this.mSlider, this.mDrawerLayout.isDrawerOpen(GravityCompat.START) ? this.mCloseDrawerContentDescRes : this.mOpenDrawerContentDescRes); } else { setActionBarUpIndicator(this.mHomeAsUpIndicator, 0); } this.mDrawerIndicatorEnabled = z; } } public void onConfigurationChanged(Configuration configuration) { if (!this.mHasCustomUpIndicator) { this.mHomeAsUpIndicator = getThemeUpIndicator(); } this.mDrawerImage = ContextCompat.getDrawable(this.mActivity, this.mDrawerImageResource); syncState(); } public boolean onOptionsItemSelected(MenuItem menuItem) { if (menuItem == null || menuItem.getItemId() != 16908332 || !this.mDrawerIndicatorEnabled) { return false; } if (this.mDrawerLayout.isDrawerVisible(GravityCompat.START)) { this.mDrawerLayout.closeDrawer(GravityCompat.START); return true; } this.mDrawerLayout.openDrawer(GravityCompat.START); return true; } @Override // androidx.drawerlayout.widget.DrawerLayout.DrawerListener public void onDrawerSlide(View view, float f) { float min; float position = this.mSlider.getPosition(); if (f > 0.5f) { min = Math.max(position, Math.max(0.0f, f - 0.5f) * 2.0f); } else { min = Math.min(position, f * 2.0f); } this.mSlider.setPosition(min); } @Override // androidx.drawerlayout.widget.DrawerLayout.DrawerListener public void onDrawerOpened(View view) { this.mSlider.setPosition(1.0f); if (this.mDrawerIndicatorEnabled) { setActionBarDescription(this.mCloseDrawerContentDescRes); } } @Override // androidx.drawerlayout.widget.DrawerLayout.DrawerListener public void onDrawerClosed(View view) { this.mSlider.setPosition(0.0f); if (this.mDrawerIndicatorEnabled) { setActionBarDescription(this.mOpenDrawerContentDescRes); } } private Drawable getThemeUpIndicator() { Delegate delegate = this.mActivityImpl; if (delegate != null) { return delegate.getThemeUpIndicator(); } ActionBar actionBar = this.mActivity.getActionBar(); TypedArray obtainStyledAttributes = (actionBar != null ? actionBar.getThemedContext() : this.mActivity).obtainStyledAttributes(null, THEME_ATTRS, R.attr.actionBarStyle, 0); Drawable drawable = obtainStyledAttributes.getDrawable(0); obtainStyledAttributes.recycle(); return drawable; } private void setActionBarUpIndicator(Drawable drawable, int i) { Delegate delegate = this.mActivityImpl; if (delegate != null) { delegate.setActionBarUpIndicator(drawable, i); return; } ActionBar actionBar = this.mActivity.getActionBar(); if (actionBar != null) { actionBar.setHomeAsUpIndicator(drawable); actionBar.setHomeActionContentDescription(i); } } private void setActionBarDescription(int i) { Delegate delegate = this.mActivityImpl; if (delegate != null) { delegate.setActionBarDescription(i); return; } ActionBar actionBar = this.mActivity.getActionBar(); if (actionBar != null) { actionBar.setHomeActionContentDescription(i); } } public static class SetIndicatorInfo { Method mSetHomeActionContentDescription; Method mSetHomeAsUpIndicator; ImageView mUpIndicatorView; public SetIndicatorInfo(Activity activity) { try { this.mSetHomeAsUpIndicator = ActionBar.class.getDeclaredMethod("setHomeAsUpIndicator", Drawable.class); this.mSetHomeActionContentDescription = ActionBar.class.getDeclaredMethod("setHomeActionContentDescription", Integer.TYPE); } catch (NoSuchMethodException unused) { View findViewById = activity.findViewById(16908332); if (findViewById == null) { return; } ViewGroup viewGroup = (ViewGroup) findViewById.getParent(); if (viewGroup.getChildCount() != 2) { return; } View childAt = viewGroup.getChildAt(0); childAt = childAt.getId() == 16908332 ? viewGroup.getChildAt(1) : childAt; if (childAt instanceof ImageView) { this.mUpIndicatorView = (ImageView) childAt; } } } } public class SlideDrawable extends InsetDrawable implements Drawable.Callback { private final boolean mHasMirroring; private float mOffset; private float mPosition; private final Rect mTmpRect; public float getPosition() { return this.mPosition; } public SlideDrawable(Drawable drawable) { super(drawable, 0); this.mHasMirroring = true; this.mTmpRect = new Rect(); } public void setPosition(float f) { this.mPosition = f; invalidateSelf(); } public void setOffset(float f) { this.mOffset = f; invalidateSelf(); } @Override // android.graphics.drawable.DrawableWrapper, android.graphics.drawable.Drawable public void draw(@NonNull Canvas canvas) { copyBounds(this.mTmpRect); canvas.save(); boolean z = ViewCompat.getLayoutDirection(ActionBarDrawerToggle.this.mActivity.getWindow().getDecorView()) == 1; int i = z ? -1 : 1; float width = this.mTmpRect.width(); canvas.translate((-this.mOffset) * width * this.mPosition * i, 0.0f); if (z && !this.mHasMirroring) { canvas.translate(width, 0.0f); canvas.scale(-1.0f, 1.0f); } super.draw(canvas); canvas.restore(); } } }