boolean needsMatrixTransform() { return hasSize() || rotationDegrees != 0; }
/** Create the immutable {@link Request} object. */ @NonNull public Request build() { if (centerInside && centerCrop) { throw new IllegalStateException("Center crop and center inside can not be used together."); } if (centerCrop && (targetWidth == 0 && targetHeight == 0)) { throw new IllegalStateException( "Center crop requires calling resize with positive width and height."); } if (centerInside && (targetWidth == 0 && targetHeight == 0)) { throw new IllegalStateException( "Center inside requires calling resize with positive width and height."); } if (priority == null) { priority = Priority.NORMAL; } return new Request(this); } }
private String createKey() { String result = createKey(MAIN_THREAD_KEY_BUILDER); MAIN_THREAD_KEY_BUILDER.setLength(0); return result; }
/** Create the request optionally passing it through the request transformer. */ private Request createRequest(long started) { int id = nextId.getAndIncrement(); Request request = data.build(); request.id = id; request.started = started; boolean loggingEnabled = picasso.loggingEnabled; if (loggingEnabled) { log(OWNER_MAIN, VERB_CREATED, request.plainId(), request.toString()); } Request transformed = picasso.transformRequest(request); if (transformed != request) { // If the request was changed, copy over the id and timestamp from the original. transformed.id = id; transformed.started = started; if (loggingEnabled) { log(OWNER_MAIN, VERB_CHANGED, transformed.logId(), "into " + transformed); } } return transformed; }
if (!request.hasSize() && !alwaysTransform) { return request; Request.Builder newRequest = request.newBuilder(); if (request.hasSize()) { urlBuilder.resize(request.targetWidth, request.targetHeight); newRequest.clearResize();
stats.dispatchCacheHit(); if (picasso.loggingEnabled) { log(OWNER_HUNTER, VERB_DECODED, data.logId(), "from cache"); data = data.newBuilder().networkPolicy(NetworkPolicy.OFFLINE).build(); if (bitmap != null) { if (picasso.loggingEnabled) { log(OWNER_HUNTER, VERB_DECODED, data.logId()); if (data.needsMatrixTransform() || result.getExifRotation() != 0) { transformations.add(new MatrixTransformation(data));
hunter.data = hunter.data.newBuilder().networkPolicy(NetworkPolicy.NO_CACHE).build();
static String getLogIdsForHunter(BitmapHunter hunter, String prefix) { StringBuilder builder = new StringBuilder(prefix); Action action = hunter.getAction(); if (action != null) { builder.append(action.request.logId()); } List<Action> actions = hunter.getActions(); if (actions != null) { for (int i = 0, count = actions.size(); i < count; i++) { if (i > 0 || action != null) builder.append(", "); builder.append(actions.get(i).request.logId()); } } return builder.toString(); }
static void updateThreadName(Request data) { String name = data.getName(); StringBuilder builder = NAME_BUILDER.get(); builder.ensureCapacity(Utils.THREAD_PREFIX.length() + name.length()); builder.replace(Utils.THREAD_PREFIX.length(), builder.length(), name); Thread.currentThread().setName(builder.toString()); }
if (data.needsMatrixTransform() || exifOrientation != 0) { int targetWidth = data.targetWidth; int targetHeight = data.targetHeight;
@Test public void bitmapConfig() { for (Bitmap.Config config : Bitmap.Config.values()) { Request data = new Request.Builder(URI_1).config(config).build(); Request copy = data.newBuilder().build(); assertThat(createBitmapOptions(data).inPreferredConfig).isSameAs(config); assertThat(createBitmapOptions(copy).inPreferredConfig).isSameAs(config); } }
private void flushFailedActions() { if (!failedActions.isEmpty()) { Iterator<Action> iterator = failedActions.values().iterator(); while (iterator.hasNext()) { Action action = iterator.next(); iterator.remove(); if (action.picasso.loggingEnabled) { log(OWNER_DISPATCHER, VERB_REPLAYING, action.request.logId()); } performSubmit(action, false); } } }
if (bitmap != null) { if (picasso.loggingEnabled) { log(OWNER_MAIN, VERB_COMPLETED, request.plainId(), "from " + MEMORY);
/** * Lazily create {@link BitmapFactory.Options} based in given * {@link Request}, only instantiating them if needed. */ @Nullable static BitmapFactory.Options createBitmapOptions(Request data) { final boolean justBounds = data.hasSize(); BitmapFactory.Options options = null; if (justBounds || data.config != null || data.purgeable) { options = new BitmapFactory.Options(); options.inJustDecodeBounds = justBounds; options.inInputShareable = data.purgeable; options.inPurgeable = data.purgeable; if (data.config != null) { options.inPreferredConfig = data.config; } } return options; }
void performCancel(Action action) { String key = action.request.key; BitmapHunter hunter = hunterMap.get(key); if (hunter != null) { hunter.detach(action); if (hunter.cancel()) { hunterMap.remove(key); if (action.picasso.loggingEnabled) { log(OWNER_DISPATCHER, VERB_CANCELED, action.request.logId()); } } } if (pausedTags.contains(action.getTag())) { pausedActions.remove(action.getTarget()); if (action.picasso.loggingEnabled) { log(OWNER_DISPATCHER, VERB_CANCELED, action.request.logId(), "because paused request got canceled"); } } Action remove = failedActions.remove(action.getTarget()); if (remove != null && remove.picasso.loggingEnabled) { log(OWNER_DISPATCHER, VERB_CANCELED, remove.request.logId(), "from replaying"); } }
setResult(target, picasso.context, result, noFade, picasso.indicatorsEnabled); if (picasso.loggingEnabled) { log(OWNER_MAIN, VERB_COMPLETED, request.plainId(), "from " + MEMORY);
if (data.hasSize()) { builder.append("resize:").append(data.targetWidth).append('x').append(data.targetHeight); builder.append(KEY_SEPARATOR);
void attach(Action action) { boolean loggingEnabled = picasso.loggingEnabled; Request request = action.request; if (this.action == null) { this.action = action; if (loggingEnabled) { if (actions == null || actions.isEmpty()) { log(OWNER_HUNTER, VERB_JOINED, request.logId(), "to empty hunter"); } else { log(OWNER_HUNTER, VERB_JOINED, request.logId(), getLogIdsForHunter(this, "to ")); } } return; } if (actions == null) { actions = new ArrayList<>(3); } actions.add(action); if (loggingEnabled) { log(OWNER_HUNTER, VERB_JOINED, request.logId(), getLogIdsForHunter(this, "to ")); } Priority actionPriority = action.request.priority; if (actionPriority.ordinal() > priority.ordinal()) { priority = actionPriority; } }