1 /* 2 * Copyright (C) 2017 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 package com.android.wallpaper.network; 17 18 import android.app.Activity; 19 import android.graphics.Bitmap; 20 import android.net.Uri; 21 22 import com.android.volley.Request; 23 import com.bumptech.glide.request.target.Target; 24 25 import java.io.File; 26 27 /** 28 * Interface for network requester service which can perform generic network requests. 29 */ 30 public interface Requester { 31 32 /** 33 * Adds the request to a Volley RequestQueue. 34 */ addToRequestQueue(Request<T> request)35 <T> void addToRequestQueue(Request<T> request); 36 37 /** 38 * Loads an image from Glide's image cache, or if the image has not already downloaded yet, 39 * downloads the image from the given URL. Returns a java.io.File for the unprocessed image. 40 * <p> 41 * This method should only be called from background threads, for example from 42 * AsyncTask#doInBackground. 43 */ loadImageFile(Uri imageUrl)44 File loadImageFile(Uri imageUrl); 45 46 /** 47 * Loads an image from Glide's image cache, or if the image has not already downloaded yet, 48 * downloads the image from the given URL. Returns a java.io.File for the unprocessed image. 49 * <p> 50 * This method should only be called from background threads, for example from 51 * AsyncTask#doInBackground. 52 * 53 * @param activity Activity in which this request is made. Allows for early cancellation if the 54 * activity leaves the foreground. 55 */ loadImageFileWithActivity(Activity activity, Uri imageUrl, Target<File> target)56 void loadImageFileWithActivity(Activity activity, Uri imageUrl, Target<File> target); 57 58 /** 59 * Loads an image as a bitmap into the target. This method may be called from either the main UI 60 * thread or a background thread, and internally the method will determine whether or not to 61 * spawn a separate thread for loading the image. 62 */ loadImageBitmap(Uri imageUrl, Target<Bitmap> target)63 void loadImageBitmap(Uri imageUrl, Target<Bitmap> target); 64 } 65