RequestCreator.java 14.4 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 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544
package com.squareup.picasso;

import android.app.Notification;
import android.content.Context;
import android.content.res.Resources;
import android.graphics.Bitmap;
import android.graphics.Bitmap.Config;
import android.graphics.drawable.Drawable;
import android.net.Uri;
import android.widget.ImageView;
import android.widget.RemoteViews;
import java.io.IOException;
import java.util.List;
import java.util.Map;
import java.util.concurrent.atomic.AtomicInteger;
import se;
import sg;
import sj;
import sl;
import sn;
import so;
import ss;
import su;
import su.a;
import su.b;
import sx;
import sy;

public class RequestCreator
{
  private static final AtomicInteger b = new AtomicInteger();
  public boolean a;
  private final Picasso c;
  private final Request.Builder d;
  private boolean e;
  private boolean f = true;
  private int g;
  private int h;
  private int i;
  private int j;
  private Drawable k;
  private Drawable l;
  private Object m;
  
  RequestCreator()
  {
    this.c = null;
    this.d = new Request.Builder(null, 0, null);
  }
  
  RequestCreator(Picasso paramPicasso, Uri paramUri, int paramInt)
  {
    if (paramPicasso.p) {
      throw new IllegalStateException("Picasso instance already shut down. Cannot submit new requests.");
    }
    this.c = paramPicasso;
    this.d = new Request.Builder(paramUri, paramInt, paramPicasso.m);
  }
  
  private Drawable a()
  {
    if (this.g != 0) {
      return this.c.f.getResources().getDrawable(this.g);
    }
    return this.k;
  }
  
  private Request a(long paramLong)
  {
    int n = b.getAndIncrement();
    Request localRequest1 = this.d.build();
    localRequest1.a = n;
    localRequest1.b = paramLong;
    boolean bool = this.c.o;
    if (bool) {
      sy.a("Main", "created", localRequest1.b(), localRequest1.toString());
    }
    Picasso localPicasso = this.c;
    Request localRequest2 = localPicasso.d.transformRequest(localRequest1);
    if (localRequest2 == null) {
      throw new IllegalStateException("Request transformer " + localPicasso.d.getClass().getCanonicalName() + " returned null for " + localRequest1);
    }
    if (localRequest2 != localRequest1)
    {
      localRequest2.a = n;
      localRequest2.b = paramLong;
      if (bool) {
        sy.a("Main", "changed", localRequest2.a(), "into " + localRequest2);
      }
    }
    return localRequest2;
  }
  
  private void a(su paramsu)
  {
    if (MemoryPolicy.a(this.i))
    {
      Bitmap localBitmap = this.c.a(paramsu.i);
      if (localBitmap != null)
      {
        paramsu.a(localBitmap, Picasso.LoadedFrom.MEMORY);
        return;
      }
    }
    if (this.g != 0) {
      paramsu.a(this.g);
    }
    this.c.a(paramsu);
  }
  
  public RequestCreator centerCrop()
  {
    this.d.centerCrop();
    return this;
  }
  
  public RequestCreator centerInside()
  {
    this.d.centerInside();
    return this;
  }
  
  public RequestCreator config(Bitmap.Config paramConfig)
  {
    this.d.config(paramConfig);
    return this;
  }
  
  public RequestCreator error(int paramInt)
  {
    if (paramInt == 0) {
      throw new IllegalArgumentException("Error image resource invalid.");
    }
    if (this.l != null) {
      throw new IllegalStateException("Error image already set.");
    }
    this.h = paramInt;
    return this;
  }
  
  public RequestCreator error(Drawable paramDrawable)
  {
    if (paramDrawable == null) {
      throw new IllegalArgumentException("Error image may not be null.");
    }
    if (this.h != 0) {
      throw new IllegalStateException("Error image already set.");
    }
    this.l = paramDrawable;
    return this;
  }
  
  public void fetch()
  {
    fetch(null);
  }
  
  public void fetch(Callback paramCallback)
  {
    long l1 = System.nanoTime();
    if (this.a) {
      throw new IllegalStateException("Fit cannot be used with fetch.");
    }
    if (this.d.a()) {
      if (this.d.c == null) {
        break label143;
      }
    }
    Request localRequest;
    String str;
    label143:
    for (int n = 1;; n = 0)
    {
      if (n == 0) {
        this.d.priority(Picasso.Priority.LOW);
      }
      localRequest = a(l1);
      str = sy.a(localRequest, new StringBuilder());
      if (this.c.a(str) == null) {
        break;
      }
      if (this.c.o) {
        sy.a("Main", "completed", localRequest.b(), "from " + Picasso.LoadedFrom.MEMORY);
      }
      if (paramCallback != null) {
        paramCallback.onSuccess();
      }
      return;
    }
    paramCallback = new sl(this.c, localRequest, this.i, this.j, this.m, str, paramCallback);
    this.c.b(paramCallback);
  }
  
  public RequestCreator fit()
  {
    this.a = true;
    return this;
  }
  
  public Bitmap get()
    throws IOException
  {
    long l1 = System.nanoTime();
    sy.a();
    if (this.a) {
      throw new IllegalStateException("Fit cannot be used with get.");
    }
    if (!this.d.a()) {
      return null;
    }
    Object localObject = a(l1);
    String str = sy.a((Request)localObject, new StringBuilder());
    localObject = new sn(this.c, (Request)localObject, this.i, this.j, this.m, str);
    return sg.a(this.c, this.c.g, this.c.h, this.c.i, (se)localObject).a();
  }
  
  public void into(ImageView paramImageView)
  {
    into(paramImageView, null);
  }
  
  public void into(ImageView paramImageView, Callback paramCallback)
  {
    long l1 = System.nanoTime();
    sy.b();
    if (paramImageView == null) {
      throw new IllegalArgumentException("Target must not be null.");
    }
    if (!this.d.a())
    {
      this.c.cancelRequest(paramImageView);
      if (this.f) {
        ss.a(paramImageView, a());
      }
    }
    Object localObject;
    String str;
    do
    {
      return;
      if (this.a)
      {
        localObject = this.d;
        if ((((Request.Builder)localObject).a != 0) || (((Request.Builder)localObject).b != 0)) {}
        for (int n = 1; n != 0; n = 0) {
          throw new IllegalStateException("Fit cannot be used with resize.");
        }
        n = paramImageView.getWidth();
        int i1 = paramImageView.getHeight();
        if ((n == 0) || (i1 == 0))
        {
          if (this.f) {
            ss.a(paramImageView, a());
          }
          localObject = this.c;
          paramCallback = new sj(this, paramImageView, paramCallback);
          ((Picasso)localObject).k.put(paramImageView, paramCallback);
          return;
        }
        this.d.resize(n, i1);
      }
      localObject = a(l1);
      str = sy.a((Request)localObject);
      if (!MemoryPolicy.a(this.i)) {
        break;
      }
      Bitmap localBitmap = this.c.a(str);
      if (localBitmap == null) {
        break;
      }
      this.c.cancelRequest(paramImageView);
      ss.a(paramImageView, this.c.f, localBitmap, Picasso.LoadedFrom.MEMORY, this.e, this.c.n);
      if (this.c.o) {
        sy.a("Main", "completed", ((Request)localObject).b(), "from " + Picasso.LoadedFrom.MEMORY);
      }
    } while (paramCallback == null);
    paramCallback.onSuccess();
    return;
    if (this.f) {
      ss.a(paramImageView, a());
    }
    paramImageView = new so(this.c, paramImageView, (Request)localObject, this.i, this.j, this.h, this.l, str, this.m, paramCallback, this.e);
    this.c.a(paramImageView);
  }
  
  public void into(RemoteViews paramRemoteViews, int paramInt1, int paramInt2, Notification paramNotification)
  {
    long l1 = System.nanoTime();
    if (paramRemoteViews == null) {
      throw new IllegalArgumentException("RemoteViews must not be null.");
    }
    if (paramNotification == null) {
      throw new IllegalArgumentException("Notification must not be null.");
    }
    if (this.a) {
      throw new IllegalStateException("Fit cannot be used with RemoteViews.");
    }
    if ((this.k != null) || (this.g != 0) || (this.l != null)) {
      throw new IllegalArgumentException("Cannot use placeholder or error drawables with remote views.");
    }
    Request localRequest = a(l1);
    String str = sy.a(localRequest, new StringBuilder());
    a(new su.b(this.c, localRequest, paramRemoteViews, paramInt1, paramInt2, paramNotification, this.i, this.j, str, this.m, this.h));
  }
  
  public void into(RemoteViews paramRemoteViews, int paramInt, int[] paramArrayOfInt)
  {
    long l1 = System.nanoTime();
    if (paramRemoteViews == null) {
      throw new IllegalArgumentException("remoteViews must not be null.");
    }
    if (paramArrayOfInt == null) {
      throw new IllegalArgumentException("appWidgetIds must not be null.");
    }
    if (this.a) {
      throw new IllegalStateException("Fit cannot be used with remote views.");
    }
    if ((this.k != null) || (this.g != 0) || (this.l != null)) {
      throw new IllegalArgumentException("Cannot use placeholder or error drawables with remote views.");
    }
    Request localRequest = a(l1);
    String str = sy.a(localRequest, new StringBuilder());
    a(new su.a(this.c, localRequest, paramRemoteViews, paramInt, paramArrayOfInt, this.i, this.j, str, this.m, this.h));
  }
  
  public void into(Target paramTarget)
  {
    Object localObject = null;
    Request localRequest = null;
    long l1 = System.nanoTime();
    sy.b();
    if (paramTarget == null) {
      throw new IllegalArgumentException("Target must not be null.");
    }
    if (this.a) {
      throw new IllegalStateException("Fit cannot be used with a Target.");
    }
    if (!this.d.a())
    {
      this.c.cancelRequest(paramTarget);
      localObject = localRequest;
      if (this.f) {
        localObject = a();
      }
      paramTarget.onPrepareLoad((Drawable)localObject);
      return;
    }
    localRequest = a(l1);
    String str = sy.a(localRequest);
    if (MemoryPolicy.a(this.i))
    {
      Bitmap localBitmap = this.c.a(str);
      if (localBitmap != null)
      {
        this.c.cancelRequest(paramTarget);
        paramTarget.onBitmapLoaded(localBitmap, Picasso.LoadedFrom.MEMORY);
        return;
      }
    }
    if (this.f) {
      localObject = a();
    }
    paramTarget.onPrepareLoad((Drawable)localObject);
    paramTarget = new sx(this.c, paramTarget, localRequest, this.i, this.j, this.l, str, this.m, this.h);
    this.c.a(paramTarget);
  }
  
  public RequestCreator memoryPolicy(MemoryPolicy paramMemoryPolicy, MemoryPolicy... paramVarArgs)
  {
    if (paramMemoryPolicy == null) {
      throw new IllegalArgumentException("Memory policy cannot be null.");
    }
    this.i |= paramMemoryPolicy.a;
    if (paramVarArgs == null) {
      throw new IllegalArgumentException("Memory policy cannot be null.");
    }
    if (paramVarArgs.length > 0)
    {
      int i1 = paramVarArgs.length;
      int n = 0;
      while (n < i1)
      {
        paramMemoryPolicy = paramVarArgs[n];
        if (paramMemoryPolicy == null) {
          throw new IllegalArgumentException("Memory policy cannot be null.");
        }
        int i2 = this.i;
        this.i = (paramMemoryPolicy.a | i2);
        n += 1;
      }
    }
    return this;
  }
  
  public RequestCreator networkPolicy(NetworkPolicy paramNetworkPolicy, NetworkPolicy... paramVarArgs)
  {
    if (paramNetworkPolicy == null) {
      throw new IllegalArgumentException("Network policy cannot be null.");
    }
    this.j |= paramNetworkPolicy.a;
    if (paramVarArgs == null) {
      throw new IllegalArgumentException("Network policy cannot be null.");
    }
    if (paramVarArgs.length > 0)
    {
      int i1 = paramVarArgs.length;
      int n = 0;
      while (n < i1)
      {
        paramNetworkPolicy = paramVarArgs[n];
        if (paramNetworkPolicy == null) {
          throw new IllegalArgumentException("Network policy cannot be null.");
        }
        int i2 = this.j;
        this.j = (paramNetworkPolicy.a | i2);
        n += 1;
      }
    }
    return this;
  }
  
  public RequestCreator noFade()
  {
    this.e = true;
    return this;
  }
  
  public RequestCreator noPlaceholder()
  {
    if (this.g != 0) {
      throw new IllegalStateException("Placeholder resource already set.");
    }
    if (this.k != null) {
      throw new IllegalStateException("Placeholder image already set.");
    }
    this.f = false;
    return this;
  }
  
  public RequestCreator onlyScaleDown()
  {
    this.d.onlyScaleDown();
    return this;
  }
  
  public RequestCreator placeholder(int paramInt)
  {
    if (!this.f) {
      throw new IllegalStateException("Already explicitly declared as no placeholder.");
    }
    if (paramInt == 0) {
      throw new IllegalArgumentException("Placeholder image resource invalid.");
    }
    if (this.k != null) {
      throw new IllegalStateException("Placeholder image already set.");
    }
    this.g = paramInt;
    return this;
  }
  
  public RequestCreator placeholder(Drawable paramDrawable)
  {
    if (!this.f) {
      throw new IllegalStateException("Already explicitly declared as no placeholder.");
    }
    if (this.g != 0) {
      throw new IllegalStateException("Placeholder image already set.");
    }
    this.k = paramDrawable;
    return this;
  }
  
  public RequestCreator priority(Picasso.Priority paramPriority)
  {
    this.d.priority(paramPriority);
    return this;
  }
  
  public RequestCreator resize(int paramInt1, int paramInt2)
  {
    this.d.resize(paramInt1, paramInt2);
    return this;
  }
  
  public RequestCreator resizeDimen(int paramInt1, int paramInt2)
  {
    Resources localResources = this.c.f.getResources();
    return resize(localResources.getDimensionPixelSize(paramInt1), localResources.getDimensionPixelSize(paramInt2));
  }
  
  public RequestCreator rotate(float paramFloat)
  {
    this.d.rotate(paramFloat);
    return this;
  }
  
  public RequestCreator rotate(float paramFloat1, float paramFloat2, float paramFloat3)
  {
    this.d.rotate(paramFloat1, paramFloat2, paramFloat3);
    return this;
  }
  
  @Deprecated
  public RequestCreator skipMemoryCache()
  {
    return memoryPolicy(MemoryPolicy.NO_CACHE, new MemoryPolicy[] { MemoryPolicy.NO_STORE });
  }
  
  public RequestCreator stableKey(String paramString)
  {
    this.d.stableKey(paramString);
    return this;
  }
  
  public RequestCreator tag(Object paramObject)
  {
    if (paramObject == null) {
      throw new IllegalArgumentException("Tag invalid.");
    }
    if (this.m != null) {
      throw new IllegalStateException("Tag already set.");
    }
    this.m = paramObject;
    return this;
  }
  
  public RequestCreator transform(Transformation paramTransformation)
  {
    this.d.transform(paramTransformation);
    return this;
  }
  
  public RequestCreator transform(List<? extends Transformation> paramList)
  {
    this.d.transform(paramList);
    return this;
  }
}


/* Location:              /home/merong/decompile/hackery-dex2jar.jar!/com/squareup/picasso/RequestCreator.class
 * Java compiler version: 6 (50.0)
 * JD-Core Version:       0.7.1
 */