GestureDetectorCompat.java 13.3 KB
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479
package android.support.v4.view;

import android.content.Context;
import android.os.Build.VERSION;
import android.os.Handler;
import android.os.Message;
import android.view.GestureDetector;
import android.view.GestureDetector.OnDoubleTapListener;
import android.view.GestureDetector.OnGestureListener;
import android.view.MotionEvent;
import android.view.VelocityTracker;
import android.view.ViewConfiguration;

public final class GestureDetectorCompat
{
  private final a a;
  
  public GestureDetectorCompat(Context paramContext, GestureDetector.OnGestureListener paramOnGestureListener)
  {
    this(paramContext, paramOnGestureListener, null);
  }
  
  public GestureDetectorCompat(Context paramContext, GestureDetector.OnGestureListener paramOnGestureListener, Handler paramHandler)
  {
    if (Build.VERSION.SDK_INT > 17)
    {
      this.a = new c(paramContext, paramOnGestureListener, paramHandler);
      return;
    }
    this.a = new b(paramContext, paramOnGestureListener, paramHandler);
  }
  
  public final boolean isLongpressEnabled()
  {
    return this.a.a();
  }
  
  public final boolean onTouchEvent(MotionEvent paramMotionEvent)
  {
    return this.a.a(paramMotionEvent);
  }
  
  public final void setIsLongpressEnabled(boolean paramBoolean)
  {
    this.a.a(paramBoolean);
  }
  
  public final void setOnDoubleTapListener(GestureDetector.OnDoubleTapListener paramOnDoubleTapListener)
  {
    this.a.a(paramOnDoubleTapListener);
  }
  
  static abstract interface a
  {
    public abstract void a(GestureDetector.OnDoubleTapListener paramOnDoubleTapListener);
    
    public abstract void a(boolean paramBoolean);
    
    public abstract boolean a();
    
    public abstract boolean a(MotionEvent paramMotionEvent);
  }
  
  static final class b
    implements GestureDetectorCompat.a
  {
    private static final int l = ;
    private static final int m = ViewConfiguration.getTapTimeout();
    private static final int n = ViewConfiguration.getDoubleTapTimeout();
    final Handler a;
    final GestureDetector.OnGestureListener b;
    GestureDetector.OnDoubleTapListener c;
    boolean d;
    boolean e;
    boolean f;
    MotionEvent g;
    private int h;
    private int i;
    private int j;
    private int k;
    private boolean o;
    private boolean p;
    private MotionEvent q;
    private boolean r;
    private float s;
    private float t;
    private float u;
    private float v;
    private boolean w;
    private VelocityTracker x;
    
    public b(Context paramContext, GestureDetector.OnGestureListener paramOnGestureListener, Handler paramHandler)
    {
      if (paramHandler != null) {}
      for (this.a = new a(paramHandler);; this.a = new a())
      {
        this.b = paramOnGestureListener;
        if ((paramOnGestureListener instanceof GestureDetector.OnDoubleTapListener)) {
          this.c = ((GestureDetector.OnDoubleTapListener)paramOnGestureListener);
        }
        if (paramContext != null) {
          break;
        }
        throw new IllegalArgumentException("Context must not be null");
      }
      if (this.b == null) {
        throw new IllegalArgumentException("OnGestureListener must not be null");
      }
      this.w = true;
      paramContext = ViewConfiguration.get(paramContext);
      int i1 = paramContext.getScaledTouchSlop();
      int i2 = paramContext.getScaledDoubleTapSlop();
      this.j = paramContext.getScaledMinimumFlingVelocity();
      this.k = paramContext.getScaledMaximumFlingVelocity();
      this.h = (i1 * i1);
      this.i = (i2 * i2);
    }
    
    public final void a(GestureDetector.OnDoubleTapListener paramOnDoubleTapListener)
    {
      this.c = paramOnDoubleTapListener;
    }
    
    public final void a(boolean paramBoolean)
    {
      this.w = paramBoolean;
    }
    
    public final boolean a()
    {
      return this.w;
    }
    
    public final boolean a(MotionEvent paramMotionEvent)
    {
      int i6 = paramMotionEvent.getAction();
      if (this.x == null) {
        this.x = VelocityTracker.obtain();
      }
      this.x.addMovement(paramMotionEvent);
      int i1;
      if ((i6 & 0xFF) == 6)
      {
        i1 = 1;
        if (i1 == 0) {
          break label127;
        }
      }
      int i5;
      int i4;
      float f1;
      float f2;
      float f4;
      float f3;
      label127:
      for (int i3 = MotionEventCompat.getActionIndex(paramMotionEvent);; i3 = -1)
      {
        i5 = paramMotionEvent.getPointerCount();
        i4 = 0;
        f1 = 0.0F;
        for (f2 = 0.0F; i4 < i5; f2 = f3)
        {
          f4 = f1;
          f3 = f2;
          if (i3 != i4)
          {
            f3 = f2 + paramMotionEvent.getX(i4);
            f4 = f1 + paramMotionEvent.getY(i4);
          }
          i4 += 1;
          f1 = f4;
        }
        i1 = 0;
        break;
      }
      if (i1 != 0)
      {
        i1 = i5 - 1;
        f2 /= i1;
        f1 /= i1;
      }
      boolean bool2;
      MotionEvent localMotionEvent;
      Object localObject;
      label757:
      int i2;
      switch (i6 & 0xFF)
      {
      case 4: 
      default: 
      case 5: 
      case 6: 
      case 0: 
      case 2: 
        do
        {
          do
          {
            return false;
            i1 = i5;
            break;
            this.s = f2;
            this.u = f2;
            this.t = f1;
            this.v = f1;
            this.a.removeMessages(1);
            this.a.removeMessages(2);
            this.a.removeMessages(3);
            this.r = false;
            this.o = false;
            this.p = false;
            this.e = false;
          } while (!this.f);
          this.f = false;
          return false;
          this.s = f2;
          this.u = f2;
          this.t = f1;
          this.v = f1;
          this.x.computeCurrentVelocity(1000, this.k);
          i3 = MotionEventCompat.getActionIndex(paramMotionEvent);
          i1 = paramMotionEvent.getPointerId(i3);
          f1 = VelocityTrackerCompat.getXVelocity(this.x, i1);
          f2 = VelocityTrackerCompat.getYVelocity(this.x, i1);
          i1 = 0;
          while (i1 < i5)
          {
            if (i1 != i3)
            {
              i4 = paramMotionEvent.getPointerId(i1);
              f3 = VelocityTrackerCompat.getXVelocity(this.x, i4);
              if (VelocityTrackerCompat.getYVelocity(this.x, i4) * f2 + f3 * f1 < 0.0F)
              {
                this.x.clear();
                return false;
              }
            }
            i1 += 1;
          }
          if (this.c != null)
          {
            bool2 = this.a.hasMessages(3);
            if (bool2) {
              this.a.removeMessages(3);
            }
            if ((this.g != null) && (this.q != null) && (bool2))
            {
              localMotionEvent = this.g;
              localObject = this.q;
              if ((this.p) && (paramMotionEvent.getEventTime() - ((MotionEvent)localObject).getEventTime() <= n))
              {
                i1 = (int)localMotionEvent.getX() - (int)paramMotionEvent.getX();
                i3 = (int)localMotionEvent.getY() - (int)paramMotionEvent.getY();
                if (i3 * i3 + i1 * i1 < this.i)
                {
                  i1 = 1;
                  if (i1 == 0) {
                    break label757;
                  }
                  this.r = true;
                }
              }
            }
          }
          for (boolean bool1 = this.c.onDoubleTap(this.g) | false | this.c.onDoubleTapEvent(paramMotionEvent);; bool1 = false)
          {
            this.s = f2;
            this.u = f2;
            this.t = f1;
            this.v = f1;
            if (this.g != null) {
              this.g.recycle();
            }
            this.g = MotionEvent.obtain(paramMotionEvent);
            this.o = true;
            this.p = true;
            this.d = true;
            this.f = false;
            this.e = false;
            if (this.w)
            {
              this.a.removeMessages(2);
              this.a.sendEmptyMessageAtTime(2, this.g.getDownTime() + m + l);
            }
            this.a.sendEmptyMessageAtTime(1, this.g.getDownTime() + m);
            return bool1 | this.b.onDown(paramMotionEvent);
            bool1 = false;
            break;
            this.a.sendEmptyMessageDelayed(3, n);
          }
        } while (this.f);
        f3 = this.s - f2;
        f4 = this.t - f1;
        if (this.r) {
          return this.c.onDoubleTapEvent(paramMotionEvent) | false;
        }
        if (this.o)
        {
          i2 = (int)(f2 - this.u);
          i3 = (int)(f1 - this.v);
          i2 = i2 * i2 + i3 * i3;
          if (i2 <= this.h) {
            break label1350;
          }
          bool2 = this.b.onScroll(this.g, paramMotionEvent, f3, f4);
          this.s = f2;
          this.t = f1;
          this.o = false;
          this.a.removeMessages(3);
          this.a.removeMessages(1);
          this.a.removeMessages(2);
        }
        break;
      }
      for (;;)
      {
        if (i2 > this.h) {
          this.p = false;
        }
        return bool2;
        if ((Math.abs(f3) < 1.0F) && (Math.abs(f4) < 1.0F)) {
          break;
        }
        bool2 = this.b.onScroll(this.g, paramMotionEvent, f3, f4);
        this.s = f2;
        this.t = f1;
        return bool2;
        this.d = false;
        localMotionEvent = MotionEvent.obtain(paramMotionEvent);
        if (this.r) {
          bool2 = this.c.onDoubleTapEvent(paramMotionEvent) | false;
        }
        for (;;)
        {
          if (this.q != null) {
            this.q.recycle();
          }
          this.q = localMotionEvent;
          if (this.x != null)
          {
            this.x.recycle();
            this.x = null;
          }
          this.r = false;
          this.e = false;
          this.a.removeMessages(1);
          this.a.removeMessages(2);
          return bool2;
          if (this.f)
          {
            this.a.removeMessages(3);
            this.f = false;
            bool2 = false;
          }
          else if (this.o)
          {
            boolean bool3 = this.b.onSingleTapUp(paramMotionEvent);
            bool2 = bool3;
            if (this.e)
            {
              bool2 = bool3;
              if (this.c != null)
              {
                this.c.onSingleTapConfirmed(paramMotionEvent);
                bool2 = bool3;
              }
            }
          }
          else
          {
            localObject = this.x;
            i2 = paramMotionEvent.getPointerId(0);
            ((VelocityTracker)localObject).computeCurrentVelocity(1000, this.k);
            f1 = VelocityTrackerCompat.getYVelocity((VelocityTracker)localObject, i2);
            f2 = VelocityTrackerCompat.getXVelocity((VelocityTracker)localObject, i2);
            if ((Math.abs(f1) > this.j) || (Math.abs(f2) > this.j))
            {
              bool2 = this.b.onFling(this.g, paramMotionEvent, f2, f1);
              continue;
              this.a.removeMessages(1);
              this.a.removeMessages(2);
              this.a.removeMessages(3);
              this.x.recycle();
              this.x = null;
              this.r = false;
              this.d = false;
              this.o = false;
              this.p = false;
              this.e = false;
              if (!this.f) {
                break;
              }
              this.f = false;
              return false;
            }
            bool2 = false;
          }
        }
        label1350:
        bool2 = false;
      }
    }
    
    final class a
      extends Handler
    {
      a() {}
      
      a(Handler paramHandler)
      {
        super();
      }
      
      public final void handleMessage(Message paramMessage)
      {
        switch (paramMessage.what)
        {
        default: 
          throw new RuntimeException("Unknown message " + paramMessage);
        case 1: 
          GestureDetectorCompat.b.this.b.onShowPress(GestureDetectorCompat.b.this.g);
        }
        do
        {
          return;
          paramMessage = GestureDetectorCompat.b.this;
          paramMessage.a.removeMessages(3);
          paramMessage.e = false;
          paramMessage.f = true;
          paramMessage.b.onLongPress(paramMessage.g);
          return;
        } while (GestureDetectorCompat.b.this.c == null);
        if (!GestureDetectorCompat.b.this.d)
        {
          GestureDetectorCompat.b.this.c.onSingleTapConfirmed(GestureDetectorCompat.b.this.g);
          return;
        }
        GestureDetectorCompat.b.this.e = true;
      }
    }
  }
  
  static final class c
    implements GestureDetectorCompat.a
  {
    private final GestureDetector a;
    
    public c(Context paramContext, GestureDetector.OnGestureListener paramOnGestureListener, Handler paramHandler)
    {
      this.a = new GestureDetector(paramContext, paramOnGestureListener, paramHandler);
    }
    
    public final void a(GestureDetector.OnDoubleTapListener paramOnDoubleTapListener)
    {
      this.a.setOnDoubleTapListener(paramOnDoubleTapListener);
    }
    
    public final void a(boolean paramBoolean)
    {
      this.a.setIsLongpressEnabled(paramBoolean);
    }
    
    public final boolean a()
    {
      return this.a.isLongpressEnabled();
    }
    
    public final boolean a(MotionEvent paramMotionEvent)
    {
      return this.a.onTouchEvent(paramMotionEvent);
    }
  }
}


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