341 lines
		
	
	
		
			13 KiB
		
	
	
	
		
			Java
		
	
	
	
	
	
			
		
		
	
	
			341 lines
		
	
	
		
			13 KiB
		
	
	
	
		
			Java
		
	
	
	
	
	
| package androidx.appcompat.app;
 | |
| 
 | |
| import android.R;
 | |
| import android.app.Activity;
 | |
| import android.content.Context;
 | |
| import android.content.res.Configuration;
 | |
| import android.content.res.TypedArray;
 | |
| import android.graphics.drawable.Drawable;
 | |
| import android.util.Log;
 | |
| import android.view.MenuItem;
 | |
| import android.view.View;
 | |
| import androidx.appcompat.app.ActionBarDrawerToggleHoneycomb;
 | |
| import androidx.appcompat.graphics.drawable.DrawerArrowDrawable;
 | |
| import androidx.appcompat.widget.Toolbar;
 | |
| import androidx.core.view.GravityCompat;
 | |
| import androidx.drawerlayout.widget.DrawerLayout;
 | |
| 
 | |
| /* loaded from: classes.dex */
 | |
| public class ActionBarDrawerToggle implements DrawerLayout.DrawerListener {
 | |
|     private final Delegate mActivityImpl;
 | |
|     private final int mCloseDrawerContentDescRes;
 | |
|     boolean mDrawerIndicatorEnabled;
 | |
|     private final DrawerLayout mDrawerLayout;
 | |
|     private boolean mDrawerSlideAnimationEnabled;
 | |
|     private boolean mHasCustomUpIndicator;
 | |
|     private Drawable mHomeAsUpIndicator;
 | |
|     private final int mOpenDrawerContentDescRes;
 | |
|     private DrawerArrowDrawable mSlider;
 | |
|     View.OnClickListener mToolbarNavigationClickListener;
 | |
|     private boolean mWarnedForDisplayHomeAsUp;
 | |
| 
 | |
|     public interface Delegate {
 | |
|         Context getActionBarThemedContext();
 | |
| 
 | |
|         Drawable getThemeUpIndicator();
 | |
| 
 | |
|         boolean isNavigationVisible();
 | |
| 
 | |
|         void setActionBarDescription(int i);
 | |
| 
 | |
|         void setActionBarUpIndicator(Drawable drawable, int i);
 | |
|     }
 | |
| 
 | |
|     public interface DelegateProvider {
 | |
|         Delegate getDrawerToggleDelegate();
 | |
|     }
 | |
| 
 | |
|     public DrawerArrowDrawable getDrawerArrowDrawable() {
 | |
|         return this.mSlider;
 | |
|     }
 | |
| 
 | |
|     public View.OnClickListener getToolbarNavigationClickListener() {
 | |
|         return this.mToolbarNavigationClickListener;
 | |
|     }
 | |
| 
 | |
|     public boolean isDrawerIndicatorEnabled() {
 | |
|         return this.mDrawerIndicatorEnabled;
 | |
|     }
 | |
| 
 | |
|     public boolean isDrawerSlideAnimationEnabled() {
 | |
|         return this.mDrawerSlideAnimationEnabled;
 | |
|     }
 | |
| 
 | |
|     @Override // androidx.drawerlayout.widget.DrawerLayout.DrawerListener
 | |
|     public void onDrawerStateChanged(int i) {
 | |
|     }
 | |
| 
 | |
|     public void setToolbarNavigationClickListener(View.OnClickListener onClickListener) {
 | |
|         this.mToolbarNavigationClickListener = onClickListener;
 | |
|     }
 | |
| 
 | |
|     public ActionBarDrawerToggle(Activity activity, DrawerLayout drawerLayout, int i, int i2) {
 | |
|         this(activity, null, drawerLayout, null, i, i2);
 | |
|     }
 | |
| 
 | |
|     public ActionBarDrawerToggle(Activity activity, DrawerLayout drawerLayout, Toolbar toolbar, int i, int i2) {
 | |
|         this(activity, toolbar, drawerLayout, null, i, i2);
 | |
|     }
 | |
| 
 | |
|     /* JADX WARN: Multi-variable type inference failed */
 | |
|     ActionBarDrawerToggle(Activity activity, Toolbar toolbar, DrawerLayout drawerLayout, DrawerArrowDrawable drawerArrowDrawable, int i, int i2) {
 | |
|         this.mDrawerSlideAnimationEnabled = true;
 | |
|         this.mDrawerIndicatorEnabled = true;
 | |
|         this.mWarnedForDisplayHomeAsUp = false;
 | |
|         if (toolbar != null) {
 | |
|             this.mActivityImpl = new ToolbarCompatDelegate(toolbar);
 | |
|             toolbar.setNavigationOnClickListener(new View.OnClickListener() { // from class: androidx.appcompat.app.ActionBarDrawerToggle.1
 | |
|                 @Override // android.view.View.OnClickListener
 | |
|                 public void onClick(View view) {
 | |
|                     if (ActionBarDrawerToggle.this.mDrawerIndicatorEnabled) {
 | |
|                         ActionBarDrawerToggle.this.toggle();
 | |
|                     } else if (ActionBarDrawerToggle.this.mToolbarNavigationClickListener != null) {
 | |
|                         ActionBarDrawerToggle.this.mToolbarNavigationClickListener.onClick(view);
 | |
|                     }
 | |
|                 }
 | |
|             });
 | |
|         } else if (activity instanceof DelegateProvider) {
 | |
|             this.mActivityImpl = ((DelegateProvider) activity).getDrawerToggleDelegate();
 | |
|         } else {
 | |
|             this.mActivityImpl = new FrameworkActionBarDelegate(activity);
 | |
|         }
 | |
|         this.mDrawerLayout = drawerLayout;
 | |
|         this.mOpenDrawerContentDescRes = i;
 | |
|         this.mCloseDrawerContentDescRes = i2;
 | |
|         if (drawerArrowDrawable == null) {
 | |
|             this.mSlider = new DrawerArrowDrawable(this.mActivityImpl.getActionBarThemedContext());
 | |
|         } else {
 | |
|             this.mSlider = drawerArrowDrawable;
 | |
|         }
 | |
|         this.mHomeAsUpIndicator = getThemeUpIndicator();
 | |
|     }
 | |
| 
 | |
|     public void syncState() {
 | |
|         if (this.mDrawerLayout.isDrawerOpen(GravityCompat.START)) {
 | |
|             setPosition(1.0f);
 | |
|         } else {
 | |
|             setPosition(0.0f);
 | |
|         }
 | |
|         if (this.mDrawerIndicatorEnabled) {
 | |
|             setActionBarUpIndicator(this.mSlider, this.mDrawerLayout.isDrawerOpen(GravityCompat.START) ? this.mCloseDrawerContentDescRes : this.mOpenDrawerContentDescRes);
 | |
|         }
 | |
|     }
 | |
| 
 | |
|     public void onConfigurationChanged(Configuration configuration) {
 | |
|         if (!this.mHasCustomUpIndicator) {
 | |
|             this.mHomeAsUpIndicator = getThemeUpIndicator();
 | |
|         }
 | |
|         syncState();
 | |
|     }
 | |
| 
 | |
|     public boolean onOptionsItemSelected(MenuItem menuItem) {
 | |
|         if (menuItem == null || menuItem.getItemId() != 16908332 || !this.mDrawerIndicatorEnabled) {
 | |
|             return false;
 | |
|         }
 | |
|         toggle();
 | |
|         return true;
 | |
|     }
 | |
| 
 | |
|     void toggle() {
 | |
|         int drawerLockMode = this.mDrawerLayout.getDrawerLockMode(GravityCompat.START);
 | |
|         if (this.mDrawerLayout.isDrawerVisible(GravityCompat.START) && drawerLockMode != 2) {
 | |
|             this.mDrawerLayout.closeDrawer(GravityCompat.START);
 | |
|         } else if (drawerLockMode != 1) {
 | |
|             this.mDrawerLayout.openDrawer(GravityCompat.START);
 | |
|         }
 | |
|     }
 | |
| 
 | |
|     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 ? this.mDrawerLayout.getResources().getDrawable(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 setDrawerArrowDrawable(DrawerArrowDrawable drawerArrowDrawable) {
 | |
|         this.mSlider = drawerArrowDrawable;
 | |
|         syncState();
 | |
|     }
 | |
| 
 | |
|     public void setDrawerSlideAnimationEnabled(boolean z) {
 | |
|         this.mDrawerSlideAnimationEnabled = z;
 | |
|         if (z) {
 | |
|             return;
 | |
|         }
 | |
|         setPosition(0.0f);
 | |
|     }
 | |
| 
 | |
|     @Override // androidx.drawerlayout.widget.DrawerLayout.DrawerListener
 | |
|     public void onDrawerSlide(View view, float f) {
 | |
|         if (this.mDrawerSlideAnimationEnabled) {
 | |
|             setPosition(Math.min(1.0f, Math.max(0.0f, f)));
 | |
|         } else {
 | |
|             setPosition(0.0f);
 | |
|         }
 | |
|     }
 | |
| 
 | |
|     @Override // androidx.drawerlayout.widget.DrawerLayout.DrawerListener
 | |
|     public void onDrawerOpened(View view) {
 | |
|         setPosition(1.0f);
 | |
|         if (this.mDrawerIndicatorEnabled) {
 | |
|             setActionBarDescription(this.mCloseDrawerContentDescRes);
 | |
|         }
 | |
|     }
 | |
| 
 | |
|     @Override // androidx.drawerlayout.widget.DrawerLayout.DrawerListener
 | |
|     public void onDrawerClosed(View view) {
 | |
|         setPosition(0.0f);
 | |
|         if (this.mDrawerIndicatorEnabled) {
 | |
|             setActionBarDescription(this.mOpenDrawerContentDescRes);
 | |
|         }
 | |
|     }
 | |
| 
 | |
|     void setActionBarUpIndicator(Drawable drawable, int i) {
 | |
|         if (!this.mWarnedForDisplayHomeAsUp && !this.mActivityImpl.isNavigationVisible()) {
 | |
|             Log.w("ActionBarDrawerToggle", "DrawerToggle may not show up because NavigationIcon is not visible. You may need to call actionbar.setDisplayHomeAsUpEnabled(true);");
 | |
|             this.mWarnedForDisplayHomeAsUp = true;
 | |
|         }
 | |
|         this.mActivityImpl.setActionBarUpIndicator(drawable, i);
 | |
|     }
 | |
| 
 | |
|     void setActionBarDescription(int i) {
 | |
|         this.mActivityImpl.setActionBarDescription(i);
 | |
|     }
 | |
| 
 | |
|     Drawable getThemeUpIndicator() {
 | |
|         return this.mActivityImpl.getThemeUpIndicator();
 | |
|     }
 | |
| 
 | |
|     private void setPosition(float f) {
 | |
|         if (f == 1.0f) {
 | |
|             this.mSlider.setVerticalMirror(true);
 | |
|         } else if (f == 0.0f) {
 | |
|             this.mSlider.setVerticalMirror(false);
 | |
|         }
 | |
|         this.mSlider.setProgress(f);
 | |
|     }
 | |
| 
 | |
|     private static class FrameworkActionBarDelegate implements Delegate {
 | |
|         private final Activity mActivity;
 | |
|         private ActionBarDrawerToggleHoneycomb.SetIndicatorInfo mSetIndicatorInfo;
 | |
| 
 | |
|         FrameworkActionBarDelegate(Activity activity) {
 | |
|             this.mActivity = activity;
 | |
|         }
 | |
| 
 | |
|         @Override // androidx.appcompat.app.ActionBarDrawerToggle.Delegate
 | |
|         public Drawable getThemeUpIndicator() {
 | |
|             TypedArray obtainStyledAttributes = getActionBarThemedContext().obtainStyledAttributes(null, new int[]{R.attr.homeAsUpIndicator}, R.attr.actionBarStyle, 0);
 | |
|             Drawable drawable = obtainStyledAttributes.getDrawable(0);
 | |
|             obtainStyledAttributes.recycle();
 | |
|             return drawable;
 | |
|         }
 | |
| 
 | |
|         @Override // androidx.appcompat.app.ActionBarDrawerToggle.Delegate
 | |
|         public Context getActionBarThemedContext() {
 | |
|             android.app.ActionBar actionBar = this.mActivity.getActionBar();
 | |
|             return actionBar != null ? actionBar.getThemedContext() : this.mActivity;
 | |
|         }
 | |
| 
 | |
|         @Override // androidx.appcompat.app.ActionBarDrawerToggle.Delegate
 | |
|         public boolean isNavigationVisible() {
 | |
|             android.app.ActionBar actionBar = this.mActivity.getActionBar();
 | |
|             return (actionBar == null || (actionBar.getDisplayOptions() & 4) == 0) ? false : true;
 | |
|         }
 | |
| 
 | |
|         @Override // androidx.appcompat.app.ActionBarDrawerToggle.Delegate
 | |
|         public void setActionBarUpIndicator(Drawable drawable, int i) {
 | |
|             android.app.ActionBar actionBar = this.mActivity.getActionBar();
 | |
|             if (actionBar != null) {
 | |
|                 Api18Impl.setHomeAsUpIndicator(actionBar, drawable);
 | |
|                 Api18Impl.setHomeActionContentDescription(actionBar, i);
 | |
|             }
 | |
|         }
 | |
| 
 | |
|         @Override // androidx.appcompat.app.ActionBarDrawerToggle.Delegate
 | |
|         public void setActionBarDescription(int i) {
 | |
|             android.app.ActionBar actionBar = this.mActivity.getActionBar();
 | |
|             if (actionBar != null) {
 | |
|                 Api18Impl.setHomeActionContentDescription(actionBar, i);
 | |
|             }
 | |
|         }
 | |
| 
 | |
|         static class Api18Impl {
 | |
|             private Api18Impl() {
 | |
|             }
 | |
| 
 | |
|             static void setHomeActionContentDescription(android.app.ActionBar actionBar, int i) {
 | |
|                 actionBar.setHomeActionContentDescription(i);
 | |
|             }
 | |
| 
 | |
|             static void setHomeAsUpIndicator(android.app.ActionBar actionBar, Drawable drawable) {
 | |
|                 actionBar.setHomeAsUpIndicator(drawable);
 | |
|             }
 | |
|         }
 | |
|     }
 | |
| 
 | |
|     static class ToolbarCompatDelegate implements Delegate {
 | |
|         final CharSequence mDefaultContentDescription;
 | |
|         final Drawable mDefaultUpIndicator;
 | |
|         final Toolbar mToolbar;
 | |
| 
 | |
|         @Override // androidx.appcompat.app.ActionBarDrawerToggle.Delegate
 | |
|         public Drawable getThemeUpIndicator() {
 | |
|             return this.mDefaultUpIndicator;
 | |
|         }
 | |
| 
 | |
|         @Override // androidx.appcompat.app.ActionBarDrawerToggle.Delegate
 | |
|         public boolean isNavigationVisible() {
 | |
|             return true;
 | |
|         }
 | |
| 
 | |
|         ToolbarCompatDelegate(Toolbar toolbar) {
 | |
|             this.mToolbar = toolbar;
 | |
|             this.mDefaultUpIndicator = toolbar.getNavigationIcon();
 | |
|             this.mDefaultContentDescription = toolbar.getNavigationContentDescription();
 | |
|         }
 | |
| 
 | |
|         @Override // androidx.appcompat.app.ActionBarDrawerToggle.Delegate
 | |
|         public void setActionBarUpIndicator(Drawable drawable, int i) {
 | |
|             this.mToolbar.setNavigationIcon(drawable);
 | |
|             setActionBarDescription(i);
 | |
|         }
 | |
| 
 | |
|         @Override // androidx.appcompat.app.ActionBarDrawerToggle.Delegate
 | |
|         public void setActionBarDescription(int i) {
 | |
|             if (i == 0) {
 | |
|                 this.mToolbar.setNavigationContentDescription(this.mDefaultContentDescription);
 | |
|             } else {
 | |
|                 this.mToolbar.setNavigationContentDescription(i);
 | |
|             }
 | |
|         }
 | |
| 
 | |
|         @Override // androidx.appcompat.app.ActionBarDrawerToggle.Delegate
 | |
|         public Context getActionBarThemedContext() {
 | |
|             return this.mToolbar.getContext();
 | |
|         }
 | |
|     }
 | |
| }
 |