ADD week 5
This commit is contained in:
		
										
											
												File diff suppressed because it is too large
												Load Diff
											
										
									
								
							| @@ -0,0 +1,8 @@ | ||||
| package com.google.android.material.snackbar; | ||||
|  | ||||
| /* loaded from: classes.dex */ | ||||
| public interface ContentViewCallback { | ||||
|     void animateContentIn(int i, int i2); | ||||
|  | ||||
|     void animateContentOut(int i, int i2); | ||||
| } | ||||
| @@ -0,0 +1,314 @@ | ||||
| package com.google.android.material.snackbar; | ||||
|  | ||||
| import android.content.Context; | ||||
| import android.content.res.ColorStateList; | ||||
| import android.content.res.TypedArray; | ||||
| import android.graphics.PorterDuff; | ||||
| import android.graphics.drawable.Drawable; | ||||
| import android.os.Build; | ||||
| import android.text.TextUtils; | ||||
| import android.util.AttributeSet; | ||||
| import android.view.LayoutInflater; | ||||
| import android.view.View; | ||||
| import android.view.ViewGroup; | ||||
| import android.view.accessibility.AccessibilityManager; | ||||
| import android.widget.Button; | ||||
| import android.widget.FrameLayout; | ||||
| import android.widget.TextView; | ||||
| import androidx.constraintlayout.core.widgets.analyzer.BasicMeasure; | ||||
| import androidx.coordinatorlayout.widget.CoordinatorLayout; | ||||
| import com.google.android.material.R; | ||||
| import com.google.android.material.snackbar.BaseTransientBottomBar; | ||||
|  | ||||
| /* loaded from: classes.dex */ | ||||
| public class Snackbar extends BaseTransientBottomBar<Snackbar> { | ||||
|     private static final int[] SNACKBAR_BUTTON_STYLE_ATTR = {R.attr.snackbarButtonStyle}; | ||||
|     private static final int[] SNACKBAR_CONTENT_STYLE_ATTRS = {R.attr.snackbarButtonStyle, R.attr.snackbarTextViewStyle}; | ||||
|     private final AccessibilityManager accessibilityManager; | ||||
|     private BaseTransientBottomBar.BaseCallback<Snackbar> callback; | ||||
|     private boolean hasAction; | ||||
|  | ||||
|     public static class Callback extends BaseTransientBottomBar.BaseCallback<Snackbar> { | ||||
|         public static final int DISMISS_EVENT_ACTION = 1; | ||||
|         public static final int DISMISS_EVENT_CONSECUTIVE = 4; | ||||
|         public static final int DISMISS_EVENT_MANUAL = 3; | ||||
|         public static final int DISMISS_EVENT_SWIPE = 0; | ||||
|         public static final int DISMISS_EVENT_TIMEOUT = 2; | ||||
|  | ||||
|         @Override // com.google.android.material.snackbar.BaseTransientBottomBar.BaseCallback | ||||
|         public void onDismissed(Snackbar snackbar, int i) { | ||||
|         } | ||||
|  | ||||
|         @Override // com.google.android.material.snackbar.BaseTransientBottomBar.BaseCallback | ||||
|         public void onShown(Snackbar snackbar) { | ||||
|         } | ||||
|     } | ||||
|  | ||||
|     private Snackbar(Context context, ViewGroup viewGroup, View view, ContentViewCallback contentViewCallback) { | ||||
|         super(context, viewGroup, view, contentViewCallback); | ||||
|         this.accessibilityManager = (AccessibilityManager) viewGroup.getContext().getSystemService("accessibility"); | ||||
|     } | ||||
|  | ||||
|     @Override // com.google.android.material.snackbar.BaseTransientBottomBar | ||||
|     public void show() { | ||||
|         super.show(); | ||||
|     } | ||||
|  | ||||
|     @Override // com.google.android.material.snackbar.BaseTransientBottomBar | ||||
|     public void dismiss() { | ||||
|         super.dismiss(); | ||||
|     } | ||||
|  | ||||
|     @Override // com.google.android.material.snackbar.BaseTransientBottomBar | ||||
|     public boolean isShown() { | ||||
|         return super.isShown(); | ||||
|     } | ||||
|  | ||||
|     public static Snackbar make(View view, CharSequence charSequence, int i) { | ||||
|         return makeInternal(null, view, charSequence, i); | ||||
|     } | ||||
|  | ||||
|     public static Snackbar make(Context context, View view, CharSequence charSequence, int i) { | ||||
|         return makeInternal(context, view, charSequence, i); | ||||
|     } | ||||
|  | ||||
|     private static Snackbar makeInternal(Context context, View view, CharSequence charSequence, int i) { | ||||
|         int i2; | ||||
|         ViewGroup findSuitableParent = findSuitableParent(view); | ||||
|         if (findSuitableParent == null) { | ||||
|             throw new IllegalArgumentException("No suitable parent found from the given view. Please provide a valid view."); | ||||
|         } | ||||
|         if (context == null) { | ||||
|             context = findSuitableParent.getContext(); | ||||
|         } | ||||
|         LayoutInflater from = LayoutInflater.from(context); | ||||
|         if (hasSnackbarContentStyleAttrs(context)) { | ||||
|             i2 = R.layout.mtrl_layout_snackbar_include; | ||||
|         } else { | ||||
|             i2 = R.layout.design_layout_snackbar_include; | ||||
|         } | ||||
|         SnackbarContentLayout snackbarContentLayout = (SnackbarContentLayout) from.inflate(i2, findSuitableParent, false); | ||||
|         Snackbar snackbar = new Snackbar(context, findSuitableParent, snackbarContentLayout, snackbarContentLayout); | ||||
|         snackbar.setText(charSequence); | ||||
|         snackbar.setDuration(i); | ||||
|         return snackbar; | ||||
|     } | ||||
|  | ||||
|     @Deprecated | ||||
|     protected static boolean hasSnackbarButtonStyleAttr(Context context) { | ||||
|         TypedArray obtainStyledAttributes = context.obtainStyledAttributes(SNACKBAR_BUTTON_STYLE_ATTR); | ||||
|         int resourceId = obtainStyledAttributes.getResourceId(0, -1); | ||||
|         obtainStyledAttributes.recycle(); | ||||
|         return resourceId != -1; | ||||
|     } | ||||
|  | ||||
|     private static boolean hasSnackbarContentStyleAttrs(Context context) { | ||||
|         TypedArray obtainStyledAttributes = context.obtainStyledAttributes(SNACKBAR_CONTENT_STYLE_ATTRS); | ||||
|         int resourceId = obtainStyledAttributes.getResourceId(0, -1); | ||||
|         int resourceId2 = obtainStyledAttributes.getResourceId(1, -1); | ||||
|         obtainStyledAttributes.recycle(); | ||||
|         return (resourceId == -1 || resourceId2 == -1) ? false : true; | ||||
|     } | ||||
|  | ||||
|     public static Snackbar make(View view, int i, int i2) { | ||||
|         return make(view, view.getResources().getText(i), i2); | ||||
|     } | ||||
|  | ||||
|     private static ViewGroup findSuitableParent(View view) { | ||||
|         ViewGroup viewGroup = null; | ||||
|         while (!(view instanceof CoordinatorLayout)) { | ||||
|             if (view instanceof FrameLayout) { | ||||
|                 if (view.getId() == 16908290) { | ||||
|                     return (ViewGroup) view; | ||||
|                 } | ||||
|                 viewGroup = (ViewGroup) view; | ||||
|             } | ||||
|             if (view != null) { | ||||
|                 Object parent = view.getParent(); | ||||
|                 view = parent instanceof View ? (View) parent : null; | ||||
|             } | ||||
|             if (view == null) { | ||||
|                 return viewGroup; | ||||
|             } | ||||
|         } | ||||
|         return (ViewGroup) view; | ||||
|     } | ||||
|  | ||||
|     public Snackbar setText(CharSequence charSequence) { | ||||
|         getMessageView().setText(charSequence); | ||||
|         return this; | ||||
|     } | ||||
|  | ||||
|     public Snackbar setText(int i) { | ||||
|         return setText(getContext().getText(i)); | ||||
|     } | ||||
|  | ||||
|     public Snackbar setAction(int i, View.OnClickListener onClickListener) { | ||||
|         return setAction(getContext().getText(i), onClickListener); | ||||
|     } | ||||
|  | ||||
|     public Snackbar setAction(CharSequence charSequence, final View.OnClickListener onClickListener) { | ||||
|         Button actionView = getActionView(); | ||||
|         if (TextUtils.isEmpty(charSequence) || onClickListener == null) { | ||||
|             actionView.setVisibility(8); | ||||
|             actionView.setOnClickListener(null); | ||||
|             this.hasAction = false; | ||||
|         } else { | ||||
|             this.hasAction = true; | ||||
|             actionView.setVisibility(0); | ||||
|             actionView.setText(charSequence); | ||||
|             actionView.setOnClickListener(new View.OnClickListener() { // from class: com.google.android.material.snackbar.Snackbar$$ExternalSyntheticLambda1 | ||||
|                 @Override // android.view.View.OnClickListener | ||||
|                 public final void onClick(View view) { | ||||
|                     Snackbar.this.m265lambda$setAction$0$comgoogleandroidmaterialsnackbarSnackbar(onClickListener, view); | ||||
|                 } | ||||
|             }); | ||||
|         } | ||||
|         return this; | ||||
|     } | ||||
|  | ||||
|     /* renamed from: lambda$setAction$0$com-google-android-material-snackbar-Snackbar, reason: not valid java name */ | ||||
|     /* synthetic */ void m265lambda$setAction$0$comgoogleandroidmaterialsnackbarSnackbar(View.OnClickListener onClickListener, View view) { | ||||
|         onClickListener.onClick(view); | ||||
|         dispatchDismiss(1); | ||||
|     } | ||||
|  | ||||
|     @Override // com.google.android.material.snackbar.BaseTransientBottomBar | ||||
|     public int getDuration() { | ||||
|         int recommendedTimeoutMillis; | ||||
|         int duration = super.getDuration(); | ||||
|         if (duration == -2) { | ||||
|             return -2; | ||||
|         } | ||||
|         if (Build.VERSION.SDK_INT >= 29) { | ||||
|             recommendedTimeoutMillis = this.accessibilityManager.getRecommendedTimeoutMillis(duration, (this.hasAction ? 4 : 0) | 3); | ||||
|             return recommendedTimeoutMillis; | ||||
|         } | ||||
|         if (this.hasAction && this.accessibilityManager.isTouchExplorationEnabled()) { | ||||
|             return -2; | ||||
|         } | ||||
|         return duration; | ||||
|     } | ||||
|  | ||||
|     public Snackbar setTextColor(ColorStateList colorStateList) { | ||||
|         getMessageView().setTextColor(colorStateList); | ||||
|         return this; | ||||
|     } | ||||
|  | ||||
|     public Snackbar setTextColor(int i) { | ||||
|         getMessageView().setTextColor(i); | ||||
|         return this; | ||||
|     } | ||||
|  | ||||
|     public Snackbar setTextMaxLines(int i) { | ||||
|         getMessageView().setMaxLines(i); | ||||
|         return this; | ||||
|     } | ||||
|  | ||||
|     public Snackbar setActionTextColor(ColorStateList colorStateList) { | ||||
|         getActionView().setTextColor(colorStateList); | ||||
|         return this; | ||||
|     } | ||||
|  | ||||
|     public Snackbar setMaxInlineActionWidth(int i) { | ||||
|         getContentLayout().setMaxInlineActionWidth(i); | ||||
|         return this; | ||||
|     } | ||||
|  | ||||
|     public Snackbar setActionTextColor(int i) { | ||||
|         getActionView().setTextColor(i); | ||||
|         return this; | ||||
|     } | ||||
|  | ||||
|     public Snackbar setBackgroundTint(int i) { | ||||
|         return setBackgroundTintList(ColorStateList.valueOf(i)); | ||||
|     } | ||||
|  | ||||
|     public Snackbar setBackgroundTintList(ColorStateList colorStateList) { | ||||
|         this.view.setBackgroundTintList(colorStateList); | ||||
|         return this; | ||||
|     } | ||||
|  | ||||
|     public Snackbar setBackgroundTintMode(PorterDuff.Mode mode) { | ||||
|         this.view.setBackgroundTintMode(mode); | ||||
|         return this; | ||||
|     } | ||||
|  | ||||
|     @Deprecated | ||||
|     public Snackbar setCallback(Callback callback) { | ||||
|         BaseTransientBottomBar.BaseCallback<Snackbar> baseCallback = this.callback; | ||||
|         if (baseCallback != null) { | ||||
|             removeCallback(baseCallback); | ||||
|         } | ||||
|         if (callback != null) { | ||||
|             addCallback(callback); | ||||
|         } | ||||
|         this.callback = callback; | ||||
|         return this; | ||||
|     } | ||||
|  | ||||
|     public static final class SnackbarLayout extends BaseTransientBottomBar.SnackbarBaseLayout { | ||||
|         @Override // com.google.android.material.snackbar.BaseTransientBottomBar.SnackbarBaseLayout, android.view.View | ||||
|         public /* bridge */ /* synthetic */ void setBackground(Drawable drawable) { | ||||
|             super.setBackground(drawable); | ||||
|         } | ||||
|  | ||||
|         @Override // com.google.android.material.snackbar.BaseTransientBottomBar.SnackbarBaseLayout, android.view.View | ||||
|         public /* bridge */ /* synthetic */ void setBackgroundDrawable(Drawable drawable) { | ||||
|             super.setBackgroundDrawable(drawable); | ||||
|         } | ||||
|  | ||||
|         @Override // com.google.android.material.snackbar.BaseTransientBottomBar.SnackbarBaseLayout, android.view.View | ||||
|         public /* bridge */ /* synthetic */ void setBackgroundTintList(ColorStateList colorStateList) { | ||||
|             super.setBackgroundTintList(colorStateList); | ||||
|         } | ||||
|  | ||||
|         @Override // com.google.android.material.snackbar.BaseTransientBottomBar.SnackbarBaseLayout, android.view.View | ||||
|         public /* bridge */ /* synthetic */ void setBackgroundTintMode(PorterDuff.Mode mode) { | ||||
|             super.setBackgroundTintMode(mode); | ||||
|         } | ||||
|  | ||||
|         @Override // com.google.android.material.snackbar.BaseTransientBottomBar.SnackbarBaseLayout, android.view.View | ||||
|         public /* bridge */ /* synthetic */ void setLayoutParams(ViewGroup.LayoutParams layoutParams) { | ||||
|             super.setLayoutParams(layoutParams); | ||||
|         } | ||||
|  | ||||
|         @Override // com.google.android.material.snackbar.BaseTransientBottomBar.SnackbarBaseLayout, android.view.View | ||||
|         public /* bridge */ /* synthetic */ void setOnClickListener(View.OnClickListener onClickListener) { | ||||
|             super.setOnClickListener(onClickListener); | ||||
|         } | ||||
|  | ||||
|         public SnackbarLayout(Context context) { | ||||
|             super(context); | ||||
|         } | ||||
|  | ||||
|         public SnackbarLayout(Context context, AttributeSet attributeSet) { | ||||
|             super(context, attributeSet); | ||||
|         } | ||||
|  | ||||
|         @Override // com.google.android.material.snackbar.BaseTransientBottomBar.SnackbarBaseLayout, android.widget.FrameLayout, android.view.View | ||||
|         protected void onMeasure(int i, int i2) { | ||||
|             super.onMeasure(i, i2); | ||||
|             int childCount = getChildCount(); | ||||
|             int measuredWidth = (getMeasuredWidth() - getPaddingLeft()) - getPaddingRight(); | ||||
|             for (int i3 = 0; i3 < childCount; i3++) { | ||||
|                 View childAt = getChildAt(i3); | ||||
|                 if (childAt.getLayoutParams().width == -1) { | ||||
|                     childAt.measure(View.MeasureSpec.makeMeasureSpec(measuredWidth, BasicMeasure.EXACTLY), View.MeasureSpec.makeMeasureSpec(childAt.getMeasuredHeight(), BasicMeasure.EXACTLY)); | ||||
|                 } | ||||
|             } | ||||
|         } | ||||
|     } | ||||
|  | ||||
|     private TextView getMessageView() { | ||||
|         return getContentLayout().getMessageView(); | ||||
|     } | ||||
|  | ||||
|     private Button getActionView() { | ||||
|         return getContentLayout().getActionView(); | ||||
|     } | ||||
|  | ||||
|     private SnackbarContentLayout getContentLayout() { | ||||
|         return (SnackbarContentLayout) this.view.getChildAt(0); | ||||
|     } | ||||
| } | ||||
| @@ -0,0 +1,129 @@ | ||||
| package com.google.android.material.snackbar; | ||||
|  | ||||
| import android.animation.TimeInterpolator; | ||||
| import android.content.Context; | ||||
| import android.text.Layout; | ||||
| import android.util.AttributeSet; | ||||
| import android.view.View; | ||||
| import android.widget.Button; | ||||
| import android.widget.LinearLayout; | ||||
| import android.widget.TextView; | ||||
| import androidx.core.view.ViewCompat; | ||||
| import com.google.android.material.R; | ||||
| import com.google.android.material.animation.AnimationUtils; | ||||
| import com.google.android.material.color.MaterialColors; | ||||
| import com.google.android.material.motion.MotionUtils; | ||||
|  | ||||
| /* loaded from: classes.dex */ | ||||
| public class SnackbarContentLayout extends LinearLayout implements ContentViewCallback { | ||||
|     private Button actionView; | ||||
|     private final TimeInterpolator contentInterpolator; | ||||
|     private int maxInlineActionWidth; | ||||
|     private TextView messageView; | ||||
|  | ||||
|     public Button getActionView() { | ||||
|         return this.actionView; | ||||
|     } | ||||
|  | ||||
|     public TextView getMessageView() { | ||||
|         return this.messageView; | ||||
|     } | ||||
|  | ||||
|     public void setMaxInlineActionWidth(int i) { | ||||
|         this.maxInlineActionWidth = i; | ||||
|     } | ||||
|  | ||||
|     public SnackbarContentLayout(Context context) { | ||||
|         this(context, null); | ||||
|     } | ||||
|  | ||||
|     public SnackbarContentLayout(Context context, AttributeSet attributeSet) { | ||||
|         super(context, attributeSet); | ||||
|         this.contentInterpolator = MotionUtils.resolveThemeInterpolator(context, R.attr.motionEasingEmphasizedInterpolator, AnimationUtils.FAST_OUT_SLOW_IN_INTERPOLATOR); | ||||
|     } | ||||
|  | ||||
|     @Override // android.view.View | ||||
|     protected void onFinishInflate() { | ||||
|         super.onFinishInflate(); | ||||
|         this.messageView = (TextView) findViewById(R.id.snackbar_text); | ||||
|         this.actionView = (Button) findViewById(R.id.snackbar_action); | ||||
|     } | ||||
|  | ||||
|     void updateActionTextColorAlphaIfNeeded(float f) { | ||||
|         if (f != 1.0f) { | ||||
|             this.actionView.setTextColor(MaterialColors.layer(MaterialColors.getColor(this, R.attr.colorSurface), this.actionView.getCurrentTextColor(), f)); | ||||
|         } | ||||
|     } | ||||
|  | ||||
|     @Override // android.widget.LinearLayout, android.view.View | ||||
|     protected void onMeasure(int i, int i2) { | ||||
|         super.onMeasure(i, i2); | ||||
|         if (getOrientation() == 1) { | ||||
|             return; | ||||
|         } | ||||
|         int dimensionPixelSize = getResources().getDimensionPixelSize(R.dimen.design_snackbar_padding_vertical_2lines); | ||||
|         int dimensionPixelSize2 = getResources().getDimensionPixelSize(R.dimen.design_snackbar_padding_vertical); | ||||
|         Layout layout = this.messageView.getLayout(); | ||||
|         boolean z = layout != null && layout.getLineCount() > 1; | ||||
|         if (z && this.maxInlineActionWidth > 0 && this.actionView.getMeasuredWidth() > this.maxInlineActionWidth) { | ||||
|             if (!updateViewsWithinLayout(1, dimensionPixelSize, dimensionPixelSize - dimensionPixelSize2)) { | ||||
|                 return; | ||||
|             } | ||||
|         } else { | ||||
|             if (!z) { | ||||
|                 dimensionPixelSize = dimensionPixelSize2; | ||||
|             } | ||||
|             if (!updateViewsWithinLayout(0, dimensionPixelSize, dimensionPixelSize)) { | ||||
|                 return; | ||||
|             } | ||||
|         } | ||||
|         super.onMeasure(i, i2); | ||||
|     } | ||||
|  | ||||
|     private boolean updateViewsWithinLayout(int i, int i2, int i3) { | ||||
|         boolean z; | ||||
|         if (i != getOrientation()) { | ||||
|             setOrientation(i); | ||||
|             z = true; | ||||
|         } else { | ||||
|             z = false; | ||||
|         } | ||||
|         if (this.messageView.getPaddingTop() == i2 && this.messageView.getPaddingBottom() == i3) { | ||||
|             return z; | ||||
|         } | ||||
|         updateTopBottomPadding(this.messageView, i2, i3); | ||||
|         return true; | ||||
|     } | ||||
|  | ||||
|     private static void updateTopBottomPadding(View view, int i, int i2) { | ||||
|         if (ViewCompat.isPaddingRelative(view)) { | ||||
|             ViewCompat.setPaddingRelative(view, ViewCompat.getPaddingStart(view), i, ViewCompat.getPaddingEnd(view), i2); | ||||
|         } else { | ||||
|             view.setPadding(view.getPaddingLeft(), i, view.getPaddingRight(), i2); | ||||
|         } | ||||
|     } | ||||
|  | ||||
|     @Override // com.google.android.material.snackbar.ContentViewCallback | ||||
|     public void animateContentIn(int i, int i2) { | ||||
|         this.messageView.setAlpha(0.0f); | ||||
|         long j = i2; | ||||
|         long j2 = i; | ||||
|         this.messageView.animate().alpha(1.0f).setDuration(j).setInterpolator(this.contentInterpolator).setStartDelay(j2).start(); | ||||
|         if (this.actionView.getVisibility() == 0) { | ||||
|             this.actionView.setAlpha(0.0f); | ||||
|             this.actionView.animate().alpha(1.0f).setDuration(j).setInterpolator(this.contentInterpolator).setStartDelay(j2).start(); | ||||
|         } | ||||
|     } | ||||
|  | ||||
|     @Override // com.google.android.material.snackbar.ContentViewCallback | ||||
|     public void animateContentOut(int i, int i2) { | ||||
|         this.messageView.setAlpha(1.0f); | ||||
|         long j = i2; | ||||
|         long j2 = i; | ||||
|         this.messageView.animate().alpha(0.0f).setDuration(j).setInterpolator(this.contentInterpolator).setStartDelay(j2).start(); | ||||
|         if (this.actionView.getVisibility() == 0) { | ||||
|             this.actionView.setAlpha(1.0f); | ||||
|             this.actionView.animate().alpha(0.0f).setDuration(j).setInterpolator(this.contentInterpolator).setStartDelay(j2).start(); | ||||
|         } | ||||
|     } | ||||
| } | ||||
| @@ -0,0 +1,199 @@ | ||||
| package com.google.android.material.snackbar; | ||||
|  | ||||
| import android.os.Handler; | ||||
| import android.os.Looper; | ||||
| import android.os.Message; | ||||
| import java.lang.ref.WeakReference; | ||||
|  | ||||
| /* loaded from: classes.dex */ | ||||
| class SnackbarManager { | ||||
|     private static final int LONG_DURATION_MS = 2750; | ||||
|     static final int MSG_TIMEOUT = 0; | ||||
|     private static final int SHORT_DURATION_MS = 1500; | ||||
|     private static SnackbarManager snackbarManager; | ||||
|     private SnackbarRecord currentSnackbar; | ||||
|     private SnackbarRecord nextSnackbar; | ||||
|     private final Object lock = new Object(); | ||||
|     private final Handler handler = new Handler(Looper.getMainLooper(), new Handler.Callback() { // from class: com.google.android.material.snackbar.SnackbarManager.1 | ||||
|         @Override // android.os.Handler.Callback | ||||
|         public boolean handleMessage(Message message) { | ||||
|             if (message.what != 0) { | ||||
|                 return false; | ||||
|             } | ||||
|             SnackbarManager.this.handleTimeout((SnackbarRecord) message.obj); | ||||
|             return true; | ||||
|         } | ||||
|     }); | ||||
|  | ||||
|     interface Callback { | ||||
|         void dismiss(int i); | ||||
|  | ||||
|         void show(); | ||||
|     } | ||||
|  | ||||
|     static SnackbarManager getInstance() { | ||||
|         if (snackbarManager == null) { | ||||
|             snackbarManager = new SnackbarManager(); | ||||
|         } | ||||
|         return snackbarManager; | ||||
|     } | ||||
|  | ||||
|     private SnackbarManager() { | ||||
|     } | ||||
|  | ||||
|     public void show(int i, Callback callback) { | ||||
|         synchronized (this.lock) { | ||||
|             if (isCurrentSnackbarLocked(callback)) { | ||||
|                 this.currentSnackbar.duration = i; | ||||
|                 this.handler.removeCallbacksAndMessages(this.currentSnackbar); | ||||
|                 scheduleTimeoutLocked(this.currentSnackbar); | ||||
|                 return; | ||||
|             } | ||||
|             if (isNextSnackbarLocked(callback)) { | ||||
|                 this.nextSnackbar.duration = i; | ||||
|             } else { | ||||
|                 this.nextSnackbar = new SnackbarRecord(i, callback); | ||||
|             } | ||||
|             SnackbarRecord snackbarRecord = this.currentSnackbar; | ||||
|             if (snackbarRecord == null || !cancelSnackbarLocked(snackbarRecord, 4)) { | ||||
|                 this.currentSnackbar = null; | ||||
|                 showNextSnackbarLocked(); | ||||
|             } | ||||
|         } | ||||
|     } | ||||
|  | ||||
|     public void dismiss(Callback callback, int i) { | ||||
|         synchronized (this.lock) { | ||||
|             if (isCurrentSnackbarLocked(callback)) { | ||||
|                 cancelSnackbarLocked(this.currentSnackbar, i); | ||||
|             } else if (isNextSnackbarLocked(callback)) { | ||||
|                 cancelSnackbarLocked(this.nextSnackbar, i); | ||||
|             } | ||||
|         } | ||||
|     } | ||||
|  | ||||
|     public void onDismissed(Callback callback) { | ||||
|         synchronized (this.lock) { | ||||
|             if (isCurrentSnackbarLocked(callback)) { | ||||
|                 this.currentSnackbar = null; | ||||
|                 if (this.nextSnackbar != null) { | ||||
|                     showNextSnackbarLocked(); | ||||
|                 } | ||||
|             } | ||||
|         } | ||||
|     } | ||||
|  | ||||
|     public void onShown(Callback callback) { | ||||
|         synchronized (this.lock) { | ||||
|             if (isCurrentSnackbarLocked(callback)) { | ||||
|                 scheduleTimeoutLocked(this.currentSnackbar); | ||||
|             } | ||||
|         } | ||||
|     } | ||||
|  | ||||
|     public void pauseTimeout(Callback callback) { | ||||
|         synchronized (this.lock) { | ||||
|             if (isCurrentSnackbarLocked(callback) && !this.currentSnackbar.paused) { | ||||
|                 this.currentSnackbar.paused = true; | ||||
|                 this.handler.removeCallbacksAndMessages(this.currentSnackbar); | ||||
|             } | ||||
|         } | ||||
|     } | ||||
|  | ||||
|     public void restoreTimeoutIfPaused(Callback callback) { | ||||
|         synchronized (this.lock) { | ||||
|             if (isCurrentSnackbarLocked(callback) && this.currentSnackbar.paused) { | ||||
|                 this.currentSnackbar.paused = false; | ||||
|                 scheduleTimeoutLocked(this.currentSnackbar); | ||||
|             } | ||||
|         } | ||||
|     } | ||||
|  | ||||
|     public boolean isCurrent(Callback callback) { | ||||
|         boolean isCurrentSnackbarLocked; | ||||
|         synchronized (this.lock) { | ||||
|             isCurrentSnackbarLocked = isCurrentSnackbarLocked(callback); | ||||
|         } | ||||
|         return isCurrentSnackbarLocked; | ||||
|     } | ||||
|  | ||||
|     public boolean isCurrentOrNext(Callback callback) { | ||||
|         boolean z; | ||||
|         synchronized (this.lock) { | ||||
|             z = isCurrentSnackbarLocked(callback) || isNextSnackbarLocked(callback); | ||||
|         } | ||||
|         return z; | ||||
|     } | ||||
|  | ||||
|     private static class SnackbarRecord { | ||||
|         final WeakReference<Callback> callback; | ||||
|         int duration; | ||||
|         boolean paused; | ||||
|  | ||||
|         SnackbarRecord(int i, Callback callback) { | ||||
|             this.callback = new WeakReference<>(callback); | ||||
|             this.duration = i; | ||||
|         } | ||||
|  | ||||
|         boolean isSnackbar(Callback callback) { | ||||
|             return callback != null && this.callback.get() == callback; | ||||
|         } | ||||
|     } | ||||
|  | ||||
|     private void showNextSnackbarLocked() { | ||||
|         SnackbarRecord snackbarRecord = this.nextSnackbar; | ||||
|         if (snackbarRecord != null) { | ||||
|             this.currentSnackbar = snackbarRecord; | ||||
|             this.nextSnackbar = null; | ||||
|             Callback callback = snackbarRecord.callback.get(); | ||||
|             if (callback != null) { | ||||
|                 callback.show(); | ||||
|             } else { | ||||
|                 this.currentSnackbar = null; | ||||
|             } | ||||
|         } | ||||
|     } | ||||
|  | ||||
|     private boolean cancelSnackbarLocked(SnackbarRecord snackbarRecord, int i) { | ||||
|         Callback callback = snackbarRecord.callback.get(); | ||||
|         if (callback == null) { | ||||
|             return false; | ||||
|         } | ||||
|         this.handler.removeCallbacksAndMessages(snackbarRecord); | ||||
|         callback.dismiss(i); | ||||
|         return true; | ||||
|     } | ||||
|  | ||||
|     private boolean isCurrentSnackbarLocked(Callback callback) { | ||||
|         SnackbarRecord snackbarRecord = this.currentSnackbar; | ||||
|         return snackbarRecord != null && snackbarRecord.isSnackbar(callback); | ||||
|     } | ||||
|  | ||||
|     private boolean isNextSnackbarLocked(Callback callback) { | ||||
|         SnackbarRecord snackbarRecord = this.nextSnackbar; | ||||
|         return snackbarRecord != null && snackbarRecord.isSnackbar(callback); | ||||
|     } | ||||
|  | ||||
|     private void scheduleTimeoutLocked(SnackbarRecord snackbarRecord) { | ||||
|         int i; | ||||
|         if (snackbarRecord.duration == -2) { | ||||
|             return; | ||||
|         } | ||||
|         if (snackbarRecord.duration > 0) { | ||||
|             i = snackbarRecord.duration; | ||||
|         } else { | ||||
|             i = snackbarRecord.duration == -1 ? SHORT_DURATION_MS : LONG_DURATION_MS; | ||||
|         } | ||||
|         this.handler.removeCallbacksAndMessages(snackbarRecord); | ||||
|         Handler handler = this.handler; | ||||
|         handler.sendMessageDelayed(Message.obtain(handler, 0, snackbarRecord), i); | ||||
|     } | ||||
|  | ||||
|     void handleTimeout(SnackbarRecord snackbarRecord) { | ||||
|         synchronized (this.lock) { | ||||
|             if (this.currentSnackbar == snackbarRecord || this.nextSnackbar == snackbarRecord) { | ||||
|                 cancelSnackbarLocked(snackbarRecord, 2); | ||||
|             } | ||||
|         } | ||||
|     } | ||||
| } | ||||
		Reference in New Issue
	
	Block a user