MaterialProgressDrawable.java 12.5 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
package android.support.v4.widget;

import android.content.Context;
import android.content.res.Resources;
import android.graphics.Canvas;
import android.graphics.ColorFilter;
import android.graphics.Paint;
import android.graphics.Paint.Cap;
import android.graphics.Paint.Style;
import android.graphics.Path;
import android.graphics.Path.FillType;
import android.graphics.Rect;
import android.graphics.RectF;
import android.graphics.drawable.Animatable;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.Drawable.Callback;
import android.support.annotation.NonNull;
import android.support.v4.view.animation.FastOutSlowInInterpolator;
import android.util.DisplayMetrics;
import android.view.View;
import android.view.animation.Animation;
import android.view.animation.Animation.AnimationListener;
import android.view.animation.Interpolator;
import android.view.animation.LinearInterpolator;
import android.view.animation.Transformation;
import java.lang.annotation.Annotation;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.util.ArrayList;

final class MaterialProgressDrawable
  extends Drawable
  implements Animatable
{
  static final Interpolator a = new FastOutSlowInInterpolator();
  private static final Interpolator e = new LinearInterpolator();
  private static final int[] f = { -16777216 };
  final a b;
  float c;
  boolean d;
  private final ArrayList<Animation> g = new ArrayList();
  private float h;
  private Resources i;
  private View j;
  private Animation k;
  private double l;
  private double m;
  private final Drawable.Callback n = new Drawable.Callback()
  {
    public final void invalidateDrawable(Drawable paramAnonymousDrawable)
    {
      MaterialProgressDrawable.this.invalidateSelf();
    }
    
    public final void scheduleDrawable(Drawable paramAnonymousDrawable, Runnable paramAnonymousRunnable, long paramAnonymousLong)
    {
      MaterialProgressDrawable.this.scheduleSelf(paramAnonymousRunnable, paramAnonymousLong);
    }
    
    public final void unscheduleDrawable(Drawable paramAnonymousDrawable, Runnable paramAnonymousRunnable)
    {
      MaterialProgressDrawable.this.unscheduleSelf(paramAnonymousRunnable);
    }
  };
  
  MaterialProgressDrawable(final Context paramContext, View paramView)
  {
    this.j = paramView;
    this.i = paramContext.getResources();
    this.b = new a(this.n);
    this.b.a(f);
    a(1);
    paramContext = this.b;
    paramView = new Animation()
    {
      public final void applyTransformation(float paramAnonymousFloat, Transformation paramAnonymousTransformation)
      {
        if (MaterialProgressDrawable.this.d)
        {
          paramAnonymousTransformation = paramContext;
          MaterialProgressDrawable.a(paramAnonymousFloat, paramAnonymousTransformation);
          f1 = (float)(Math.floor(paramAnonymousTransformation.m / 0.8F) + 1.0D);
          f2 = MaterialProgressDrawable.a(paramAnonymousTransformation);
          f3 = paramAnonymousTransformation.k;
          paramAnonymousTransformation.a((paramAnonymousTransformation.l - f2 - paramAnonymousTransformation.k) * paramAnonymousFloat + f3);
          paramAnonymousTransformation.b(paramAnonymousTransformation.l);
          f2 = paramAnonymousTransformation.m;
          paramAnonymousTransformation.c((f1 - paramAnonymousTransformation.m) * paramAnonymousFloat + f2);
          return;
        }
        float f1 = MaterialProgressDrawable.a(paramContext);
        float f2 = paramContext.l;
        float f4 = paramContext.k;
        float f3 = paramContext.m;
        MaterialProgressDrawable.a(paramAnonymousFloat, paramContext);
        if (paramAnonymousFloat <= 0.5F)
        {
          float f5 = paramAnonymousFloat / 0.5F;
          f5 = MaterialProgressDrawable.a.getInterpolation(f5);
          paramContext.a(f4 + f5 * (0.8F - f1));
        }
        if (paramAnonymousFloat > 0.5F)
        {
          f4 = (paramAnonymousFloat - 0.5F) / 0.5F;
          f4 = MaterialProgressDrawable.a.getInterpolation(f4);
          paramContext.b((0.8F - f1) * f4 + f2);
        }
        paramContext.c(0.25F * paramAnonymousFloat + f3);
        f1 = MaterialProgressDrawable.this.c / 5.0F;
        MaterialProgressDrawable.this.c(216.0F * paramAnonymousFloat + 1080.0F * f1);
      }
    };
    paramView.setRepeatCount(-1);
    paramView.setRepeatMode(1);
    paramView.setInterpolator(e);
    paramView.setAnimationListener(new Animation.AnimationListener()
    {
      public final void onAnimationEnd(Animation paramAnonymousAnimation) {}
      
      public final void onAnimationRepeat(Animation paramAnonymousAnimation)
      {
        paramContext.b();
        MaterialProgressDrawable.a locala = paramContext;
        locala.a(locala.a());
        paramContext.a(paramContext.e);
        if (MaterialProgressDrawable.this.d)
        {
          MaterialProgressDrawable.this.d = false;
          paramAnonymousAnimation.setDuration(1332L);
          paramContext.a(false);
          return;
        }
        MaterialProgressDrawable.this.c = ((MaterialProgressDrawable.this.c + 1.0F) % 5.0F);
      }
      
      public final void onAnimationStart(Animation paramAnonymousAnimation)
      {
        MaterialProgressDrawable.this.c = 0.0F;
      }
    });
    this.k = paramView;
  }
  
  static float a(a parama)
  {
    return (float)Math.toRadians(parama.g / (6.283185307179586D * parama.q));
  }
  
  private void a(double paramDouble1, double paramDouble2, double paramDouble3, double paramDouble4, float paramFloat1, float paramFloat2)
  {
    a locala = this.b;
    float f1 = this.i.getDisplayMetrics().density;
    this.l = (f1 * paramDouble1);
    this.m = (f1 * paramDouble2);
    float f2 = (float)paramDouble4 * f1;
    locala.g = f2;
    locala.b.setStrokeWidth(f2);
    locala.d();
    locala.q = (f1 * paramDouble3);
    locala.a(0);
    locala.r = ((int)(paramFloat1 * f1));
    locala.s = ((int)(f1 * paramFloat2));
    paramFloat1 = Math.min((int)this.l, (int)this.m);
    if ((locala.q <= 0.0D) || (paramFloat1 < 0.0F)) {}
    for (paramFloat1 = (float)Math.ceil(locala.g / 2.0F);; paramFloat1 = (float)(paramFloat1 / 2.0F - locala.q))
    {
      locala.h = paramFloat1;
      return;
    }
  }
  
  static void a(float paramFloat, a parama)
  {
    if (paramFloat > 0.75F)
    {
      paramFloat = (paramFloat - 0.75F) / 0.25F;
      int i1 = parama.i[parama.j];
      int i5 = parama.i[parama.a()];
      int i4 = Integer.valueOf(i1).intValue();
      i1 = i4 >> 24 & 0xFF;
      int i2 = i4 >> 16 & 0xFF;
      int i3 = i4 >> 8 & 0xFF;
      i4 &= 0xFF;
      i5 = Integer.valueOf(i5).intValue();
      int i6 = (int)(((i5 >> 24 & 0xFF) - i1) * paramFloat);
      int i7 = (int)(((i5 >> 16 & 0xFF) - i2) * paramFloat);
      int i8 = (int)(((i5 >> 8 & 0xFF) - i3) * paramFloat);
      parama.w = ((int)(paramFloat * ((i5 & 0xFF) - i4)) + i4 | i1 + i6 << 24 | i2 + i7 << 16 | i8 + i3 << 8);
    }
  }
  
  public final void a(float paramFloat)
  {
    a locala = this.b;
    if (paramFloat != locala.p)
    {
      locala.p = paramFloat;
      locala.d();
    }
  }
  
  public final void a(int paramInt)
  {
    if (paramInt == 0)
    {
      a(56.0D, 56.0D, 12.5D, 3.0D, 12.0F, 6.0F);
      return;
    }
    a(40.0D, 40.0D, 8.75D, 2.5D, 10.0F, 5.0F);
  }
  
  public final void a(boolean paramBoolean)
  {
    this.b.a(paramBoolean);
  }
  
  public final void b(float paramFloat)
  {
    this.b.a(0.0F);
    this.b.b(paramFloat);
  }
  
  public final void b(int paramInt)
  {
    this.b.v = paramInt;
  }
  
  final void c(float paramFloat)
  {
    this.h = paramFloat;
    invalidateSelf();
  }
  
  public final void draw(Canvas paramCanvas)
  {
    Rect localRect = getBounds();
    int i1 = paramCanvas.save();
    paramCanvas.rotate(this.h, localRect.exactCenterX(), localRect.exactCenterY());
    a locala = this.b;
    RectF localRectF = locala.a;
    localRectF.set(localRect);
    localRectF.inset(locala.h, locala.h);
    float f1 = 360.0F * (locala.d + locala.f);
    float f2 = (locala.e + locala.f) * 360.0F - f1;
    locala.b.setColor(locala.w);
    paramCanvas.drawArc(localRectF, f1, f2, false, locala.b);
    if (locala.n)
    {
      if (locala.o != null) {
        break label436;
      }
      locala.o = new Path();
      locala.o.setFillType(Path.FillType.EVEN_ODD);
    }
    for (;;)
    {
      float f3 = (int)locala.h / 2;
      float f4 = locala.p;
      float f5 = (float)(locala.q * Math.cos(0.0D) + localRect.exactCenterX());
      float f6 = (float)(locala.q * Math.sin(0.0D) + localRect.exactCenterY());
      locala.o.moveTo(0.0F, 0.0F);
      locala.o.lineTo(locala.r * locala.p, 0.0F);
      locala.o.lineTo(locala.r * locala.p / 2.0F, locala.s * locala.p);
      locala.o.offset(f5 - f3 * f4, f6);
      locala.o.close();
      locala.c.setColor(locala.w);
      paramCanvas.rotate(f1 + f2 - 5.0F, localRect.exactCenterX(), localRect.exactCenterY());
      paramCanvas.drawPath(locala.o, locala.c);
      if (locala.t < 255)
      {
        locala.u.setColor(locala.v);
        locala.u.setAlpha(255 - locala.t);
        paramCanvas.drawCircle(localRect.exactCenterX(), localRect.exactCenterY(), localRect.width() / 2, locala.u);
      }
      paramCanvas.restoreToCount(i1);
      return;
      label436:
      locala.o.reset();
    }
  }
  
  public final int getAlpha()
  {
    return this.b.t;
  }
  
  public final int getIntrinsicHeight()
  {
    return (int)this.m;
  }
  
  public final int getIntrinsicWidth()
  {
    return (int)this.l;
  }
  
  public final int getOpacity()
  {
    return -3;
  }
  
  public final boolean isRunning()
  {
    ArrayList localArrayList = this.g;
    int i2 = localArrayList.size();
    int i1 = 0;
    while (i1 < i2)
    {
      Animation localAnimation = (Animation)localArrayList.get(i1);
      if ((localAnimation.hasStarted()) && (!localAnimation.hasEnded())) {
        return true;
      }
      i1 += 1;
    }
    return false;
  }
  
  public final void setAlpha(int paramInt)
  {
    this.b.t = paramInt;
  }
  
  public final void setColorFilter(ColorFilter paramColorFilter)
  {
    a locala = this.b;
    locala.b.setColorFilter(paramColorFilter);
    locala.d();
  }
  
  public final void start()
  {
    this.k.reset();
    this.b.b();
    if (this.b.e != this.b.d)
    {
      this.d = true;
      this.k.setDuration(666L);
      this.j.startAnimation(this.k);
      return;
    }
    this.b.a(0);
    this.b.c();
    this.k.setDuration(1332L);
    this.j.startAnimation(this.k);
  }
  
  public final void stop()
  {
    this.j.clearAnimation();
    c(0.0F);
    this.b.a(false);
    this.b.a(0);
    this.b.c();
  }
  
  @Retention(RetentionPolicy.SOURCE)
  public static @interface ProgressDrawableSize {}
  
  static final class a
  {
    final RectF a = new RectF();
    final Paint b = new Paint();
    final Paint c = new Paint();
    float d = 0.0F;
    float e = 0.0F;
    float f = 0.0F;
    float g = 5.0F;
    float h = 2.5F;
    int[] i;
    int j;
    float k;
    float l;
    float m;
    boolean n;
    Path o;
    float p;
    double q;
    int r;
    int s;
    int t;
    final Paint u = new Paint(1);
    int v;
    int w;
    private final Drawable.Callback x;
    
    a(Drawable.Callback paramCallback)
    {
      this.x = paramCallback;
      this.b.setStrokeCap(Paint.Cap.SQUARE);
      this.b.setAntiAlias(true);
      this.b.setStyle(Paint.Style.STROKE);
      this.c.setStyle(Paint.Style.FILL);
      this.c.setAntiAlias(true);
    }
    
    final int a()
    {
      return (this.j + 1) % this.i.length;
    }
    
    public final void a(float paramFloat)
    {
      this.d = paramFloat;
      d();
    }
    
    public final void a(int paramInt)
    {
      this.j = paramInt;
      this.w = this.i[this.j];
    }
    
    public final void a(boolean paramBoolean)
    {
      if (this.n != paramBoolean)
      {
        this.n = paramBoolean;
        d();
      }
    }
    
    public final void a(@NonNull int[] paramArrayOfInt)
    {
      this.i = paramArrayOfInt;
      a(0);
    }
    
    public final void b()
    {
      this.k = this.d;
      this.l = this.e;
      this.m = this.f;
    }
    
    public final void b(float paramFloat)
    {
      this.e = paramFloat;
      d();
    }
    
    public final void c()
    {
      this.k = 0.0F;
      this.l = 0.0F;
      this.m = 0.0F;
      a(0.0F);
      b(0.0F);
      c(0.0F);
    }
    
    public final void c(float paramFloat)
    {
      this.f = paramFloat;
      d();
    }
    
    final void d()
    {
      this.x.invalidateDrawable(null);
    }
  }
}


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