SwipeDismissBehavior.java 10 KB
package android.support.design.widget;

import android.support.annotation.NonNull;
import android.support.v4.view.MotionEventCompat;
import android.support.v4.view.ViewCompat;
import android.support.v4.widget.ViewDragHelper;
import android.support.v4.widget.ViewDragHelper.Callback;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewParent;

public class SwipeDismissBehavior<V extends View>
  extends CoordinatorLayout.Behavior<V>
{
  public static final int STATE_DRAGGING = 1;
  public static final int STATE_IDLE = 0;
  public static final int STATE_SETTLING = 2;
  public static final int SWIPE_DIRECTION_ANY = 2;
  public static final int SWIPE_DIRECTION_END_TO_START = 1;
  public static final int SWIPE_DIRECTION_START_TO_END = 0;
  private boolean a;
  ViewDragHelper b;
  OnDismissListener c;
  int d = 2;
  float e = 0.5F;
  float f = 0.0F;
  float g = 0.5F;
  private float h = 0.0F;
  private boolean i;
  private final ViewDragHelper.Callback j = new ViewDragHelper.Callback()
  {
    private int b;
    private int c = -1;
    
    public final int clampViewPositionHorizontal(View paramAnonymousView, int paramAnonymousInt1, int paramAnonymousInt2)
    {
      int i;
      if (ViewCompat.getLayoutDirection(paramAnonymousView) == 1)
      {
        paramAnonymousInt2 = 1;
        if (SwipeDismissBehavior.this.d != 0) {
          break label72;
        }
        if (paramAnonymousInt2 == 0) {
          break label53;
        }
        paramAnonymousInt2 = this.b - paramAnonymousView.getWidth();
        i = this.b;
      }
      for (;;)
      {
        return SwipeDismissBehavior.a(paramAnonymousInt2, paramAnonymousInt1, i);
        paramAnonymousInt2 = 0;
        break;
        label53:
        paramAnonymousInt2 = this.b;
        i = this.b + paramAnonymousView.getWidth();
        continue;
        label72:
        if (SwipeDismissBehavior.this.d == 1)
        {
          if (paramAnonymousInt2 != 0)
          {
            paramAnonymousInt2 = this.b;
            i = this.b + paramAnonymousView.getWidth();
          }
          else
          {
            paramAnonymousInt2 = this.b - paramAnonymousView.getWidth();
            i = this.b;
          }
        }
        else
        {
          paramAnonymousInt2 = this.b - paramAnonymousView.getWidth();
          i = this.b + paramAnonymousView.getWidth();
        }
      }
    }
    
    public final int clampViewPositionVertical(View paramAnonymousView, int paramAnonymousInt1, int paramAnonymousInt2)
    {
      return paramAnonymousView.getTop();
    }
    
    public final int getViewHorizontalDragRange(View paramAnonymousView)
    {
      return paramAnonymousView.getWidth();
    }
    
    public final void onViewCaptured(View paramAnonymousView, int paramAnonymousInt)
    {
      this.c = paramAnonymousInt;
      this.b = paramAnonymousView.getLeft();
      paramAnonymousView = paramAnonymousView.getParent();
      if (paramAnonymousView != null) {
        paramAnonymousView.requestDisallowInterceptTouchEvent(true);
      }
    }
    
    public final void onViewDragStateChanged(int paramAnonymousInt)
    {
      if (SwipeDismissBehavior.this.c != null) {
        SwipeDismissBehavior.this.c.onDragStateChanged(paramAnonymousInt);
      }
    }
    
    public final void onViewPositionChanged(View paramAnonymousView, int paramAnonymousInt1, int paramAnonymousInt2, int paramAnonymousInt3, int paramAnonymousInt4)
    {
      float f1 = this.b + paramAnonymousView.getWidth() * SwipeDismissBehavior.this.f;
      float f2 = this.b + paramAnonymousView.getWidth() * SwipeDismissBehavior.this.g;
      if (paramAnonymousInt1 <= f1)
      {
        ViewCompat.setAlpha(paramAnonymousView, 1.0F);
        return;
      }
      if (paramAnonymousInt1 >= f2)
      {
        ViewCompat.setAlpha(paramAnonymousView, 0.0F);
        return;
      }
      ViewCompat.setAlpha(paramAnonymousView, SwipeDismissBehavior.a(1.0F - SwipeDismissBehavior.a(f1, f2, paramAnonymousInt1)));
    }
    
    public final void onViewReleased(View paramAnonymousView, float paramAnonymousFloat1, float paramAnonymousFloat2)
    {
      boolean bool = true;
      this.c = -1;
      int j = paramAnonymousView.getWidth();
      int i;
      if (paramAnonymousFloat1 != 0.0F) {
        if (ViewCompat.getLayoutDirection(paramAnonymousView) == 1)
        {
          i = 1;
          if (SwipeDismissBehavior.this.d != 2) {
            break label114;
          }
          i = 1;
          label45:
          if (i == 0) {
            break label290;
          }
          if (paramAnonymousView.getLeft() >= this.b) {
            break label278;
          }
          i = this.b - j;
          label70:
          if (!SwipeDismissBehavior.this.b.settleCapturedViewAt(i, paramAnonymousView.getTop())) {
            break label302;
          }
          ViewCompat.postOnAnimation(paramAnonymousView, new SwipeDismissBehavior.a(SwipeDismissBehavior.this, paramAnonymousView, bool));
        }
      }
      label114:
      label278:
      label290:
      label302:
      while ((!bool) || (SwipeDismissBehavior.this.c == null))
      {
        return;
        i = 0;
        break;
        if (SwipeDismissBehavior.this.d == 0)
        {
          if (i != 0)
          {
            if (paramAnonymousFloat1 < 0.0F)
            {
              i = 1;
              break label45;
            }
            i = 0;
            break label45;
          }
          if (paramAnonymousFloat1 > 0.0F)
          {
            i = 1;
            break label45;
          }
          i = 0;
          break label45;
        }
        if (SwipeDismissBehavior.this.d == 1)
        {
          if (i != 0)
          {
            if (paramAnonymousFloat1 > 0.0F)
            {
              i = 1;
              break label45;
            }
            i = 0;
            break label45;
          }
          if (paramAnonymousFloat1 < 0.0F)
          {
            i = 1;
            break label45;
          }
          i = 0;
          break label45;
          i = paramAnonymousView.getLeft();
          int k = this.b;
          int m = Math.round(paramAnonymousView.getWidth() * SwipeDismissBehavior.this.e);
          if (Math.abs(i - k) >= m)
          {
            i = 1;
            break label45;
          }
          i = 0;
          break label45;
        }
        i = 0;
        break label45;
        i = this.b + j;
        break label70;
        i = this.b;
        bool = false;
        break label70;
      }
      SwipeDismissBehavior.this.c.onDismiss(paramAnonymousView);
    }
    
    public final boolean tryCaptureView(View paramAnonymousView, int paramAnonymousInt)
    {
      return (this.c == -1) && (SwipeDismissBehavior.this.canSwipeDismissView(paramAnonymousView));
    }
  };
  
  static float a(float paramFloat)
  {
    return Math.min(Math.max(0.0F, paramFloat), 1.0F);
  }
  
  static float a(float paramFloat1, float paramFloat2, float paramFloat3)
  {
    return (paramFloat3 - paramFloat1) / (paramFloat2 - paramFloat1);
  }
  
  static int a(int paramInt1, int paramInt2, int paramInt3)
  {
    return Math.min(Math.max(paramInt1, paramInt2), paramInt3);
  }
  
  public boolean canSwipeDismissView(@NonNull View paramView)
  {
    return true;
  }
  
  public int getDragState()
  {
    if (this.b != null) {
      return this.b.getViewDragState();
    }
    return 0;
  }
  
  public boolean onInterceptTouchEvent(CoordinatorLayout paramCoordinatorLayout, V paramV, MotionEvent paramMotionEvent)
  {
    boolean bool2 = false;
    boolean bool3 = this.a;
    boolean bool1 = bool3;
    switch (MotionEventCompat.getActionMasked(paramMotionEvent))
    {
    default: 
      bool1 = bool3;
    case 2: 
      if (bool1) {
        if (this.b == null) {
          if (!this.i) {
            break label142;
          }
        }
      }
      break;
    }
    label142:
    for (paramCoordinatorLayout = ViewDragHelper.create(paramCoordinatorLayout, this.h, this.j);; paramCoordinatorLayout = ViewDragHelper.create(paramCoordinatorLayout, this.j))
    {
      this.b = paramCoordinatorLayout;
      bool2 = this.b.shouldInterceptTouchEvent(paramMotionEvent);
      return bool2;
      this.a = paramCoordinatorLayout.isPointInChildBounds(paramV, (int)paramMotionEvent.getX(), (int)paramMotionEvent.getY());
      bool1 = this.a;
      break;
      this.a = false;
      bool1 = bool3;
      break;
    }
  }
  
  public boolean onTouchEvent(CoordinatorLayout paramCoordinatorLayout, V paramV, MotionEvent paramMotionEvent)
  {
    if (this.b != null)
    {
      this.b.processTouchEvent(paramMotionEvent);
      return true;
    }
    return false;
  }
  
  public void setDragDismissDistance(float paramFloat)
  {
    this.e = a(paramFloat);
  }
  
  public void setEndAlphaSwipeDistance(float paramFloat)
  {
    this.g = a(paramFloat);
  }
  
  public void setListener(OnDismissListener paramOnDismissListener)
  {
    this.c = paramOnDismissListener;
  }
  
  public void setSensitivity(float paramFloat)
  {
    this.h = paramFloat;
    this.i = true;
  }
  
  public void setStartAlphaSwipeDistance(float paramFloat)
  {
    this.f = a(paramFloat);
  }
  
  public void setSwipeDirection(int paramInt)
  {
    this.d = paramInt;
  }
  
  public static abstract interface OnDismissListener
  {
    public abstract void onDismiss(View paramView);
    
    public abstract void onDragStateChanged(int paramInt);
  }
  
  final class a
    implements Runnable
  {
    private final View b;
    private final boolean c;
    
    a(View paramView, boolean paramBoolean)
    {
      this.b = paramView;
      this.c = paramBoolean;
    }
    
    public final void run()
    {
      if ((SwipeDismissBehavior.this.b != null) && (SwipeDismissBehavior.this.b.continueSettling(true))) {
        ViewCompat.postOnAnimation(this.b, this);
      }
      while ((!this.c) || (SwipeDismissBehavior.this.c == null)) {
        return;
      }
      SwipeDismissBehavior.this.c.onDismiss(this.b);
    }
  }
}


/* Location:              /home/merong/decompile/hackery-dex2jar.jar!/android/support/design/widget/SwipeDismissBehavior.class
 * Java compiler version: 6 (50.0)
 * JD-Core Version:       0.7.1
 */