use of com.android.volley.toolbox.ImageRequest in project FastDev4Android by jiangqqlmj.
the class VolleyTestActivity method backLinearClick.
@Click({ R.id.top_bar_linear_back, R.id.btn_string, R.id.btn_json, R.id.btn_image_request, R.id.btn_image_loader, R.id.btn_image_network, R.id.btn_string_post, R.id.btn_loader_list, R.id.btn_gson, R.id.btn_fdv_get_params, R.id.btn_fdv_post_params })
public void backLinearClick(View view) {
switch(view.getId()) {
case R.id.top_bar_linear_back:
this.finish();
break;
case R.id.btn_string:
//获取字符串
Log.d(TAG, "点击获取字符串...");
new Fdv_StringRequest(VolleyTestActivity.this).get("http://www.baidu.com", new Fdv_CallBackListener<String>() {
@Override
public void onSuccessResponse(String response) {
tv_result.setVisibility(View.VISIBLE);
img_result.setVisibility(View.GONE);
img_result_network.setVisibility(View.GONE);
tv_result.setText(response.toString());
}
@Override
public void onErrorResponse(VolleyError error) {
}
});
break;
case R.id.btn_json:
//获取json
Log.d(TAG, "点击获取json...");
new Fdv_JsonObjectRequest(VolleyTestActivity.this).get("http://interface.zttmall.com/update/mallUpdate", new Fdv_CallBackListener<JSONObject>() {
@Override
public void onSuccessResponse(JSONObject response) {
Gson gson = new Gson();
tv_result.setVisibility(View.VISIBLE);
img_result.setVisibility(View.GONE);
img_result_network.setVisibility(View.GONE);
tv_result.setText(gson.fromJson(response.toString(), UpdateBean.class).toString());
}
@Override
public void onErrorResponse(VolleyError error) {
}
});
break;
case R.id.btn_image_request:
//获取图片
//http:\/\/interface.zttmall.com\/Images\/upload\/image\/20150325\/20150325083110_0898.jpg
Log.d(TAG, "点击获取图片...");
ImageRequest imageRequest = new ImageRequest("http://interface.zttmall.com/Images/upload/image/20150325/20150325083110_0898.jpg", new Response.Listener<Bitmap>() {
@Override
public void onResponse(Bitmap response) {
tv_result.setVisibility(View.GONE);
img_result.setVisibility(View.VISIBLE);
img_result.setImageBitmap(response);
img_result_network.setVisibility(View.GONE);
}
}, 0, 0, ImageView.ScaleType.FIT_XY, Bitmap.Config.ARGB_8888, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
}
});
requestQueue.add(imageRequest);
break;
case R.id.btn_image_loader:
//使用imageloader进行获取图片
ImageLoader imageLoader = new ImageLoader(requestQueue, new Fdv_ImageCache());
tv_result.setVisibility(View.GONE);
img_result.setVisibility(View.VISIBLE);
img_result_network.setVisibility(View.GONE);
ImageLoader.ImageListener listener = ImageLoader.getImageListener(img_result, R.drawable.ic_loading, R.drawable.ic_loading);
imageLoader.get("http://interface.zttmall.com//Images//upload//image//20150328//20150328105404_2392.jpg", listener);
break;
case R.id.btn_image_network:
//采用NetworkImageView imageview控件
ImageLoader network_imageLoader = new ImageLoader(requestQueue, new Fdv_ImageCache());
img_result.setVisibility(View.GONE);
tv_result.setVisibility(View.GONE);
img_result_network.setVisibility(View.VISIBLE);
img_result_network.setImageUrl("http://interface.zttmall.com//Images//upload//image//20150325//20150325083214_8280.jpg", network_imageLoader);
break;
case R.id.btn_string_post:
//修改Volley源代码,扩展StringRequest支持post参数设置
final Map<String, String> params = new HashMap<String, String>();
params.put("username", "张三");
params.put("password", "12345");
StringRequest post_stringRequest = new StringRequest(Request.Method.POST, "http://10.18.3.123:8080/SalesWebTest/TestVolleyPost", new Response.Listener<String>() {
@Override
public void onResponse(String response) {
tv_result.setVisibility(View.VISIBLE);
img_result.setVisibility(View.GONE);
img_result_network.setVisibility(View.GONE);
tv_result.setText(response.toString());
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
}
}) {
@Override
protected Map<String, String> getParams() throws AuthFailureError {
return params;
}
};
requestQueue.add(post_stringRequest);
break;
case R.id.btn_loader_list:
//进行使用ImageLoader加载图片列表
openActivity(VolleyLoaderActivity_.class);
break;
case R.id.btn_gson:
//使用扩展工具 GsonRequest进行请求
GsonRequest<UpdateBean> gsonRequest = new GsonRequest<UpdateBean>("http://interface.zttmall.com/update/mallUpdate", new Response.Listener<UpdateBean>() {
@Override
public void onResponse(UpdateBean response) {
tv_result.setVisibility(View.VISIBLE);
img_result.setVisibility(View.GONE);
img_result_network.setVisibility(View.GONE);
tv_result.setText(response.toString());
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
}
}, UpdateBean.class);
requestQueue.add(gsonRequest);
break;
case R.id.btn_fdv_get_params:
//get请求 传入请求参数
Map<String, String> params_get = new HashMap<String, String>();
params_get.put("username", "张三");
params_get.put("password", "12345");
new Fdv_StringRequest(this).get("http://10.18.3.123:8080/SalesWebTest/TestVolleyPost", new Fdv_CallBackListener<String>() {
@Override
public void onSuccessResponse(String response) {
tv_result.setVisibility(View.VISIBLE);
img_result.setVisibility(View.GONE);
img_result_network.setVisibility(View.GONE);
tv_result.setText(response.toString());
}
@Override
public void onErrorResponse(VolleyError error) {
}
}, params_get);
break;
case R.id.btn_fdv_post_params:
//post请求 传入请求参数
Map<String, String> params_post = new HashMap<String, String>();
params_post.put("username", "张三");
params_post.put("password", "12345");
new Fdv_StringRequest(this).post("http://10.18.3.123:8080/SalesWebTest/TestVolleyPost", new Fdv_CallBackListener<String>() {
@Override
public void onSuccessResponse(String response) {
tv_result.setVisibility(View.VISIBLE);
img_result.setVisibility(View.GONE);
img_result_network.setVisibility(View.GONE);
tv_result.setText(response.toString());
}
@Override
public void onErrorResponse(VolleyError error) {
}
}, params_post);
break;
}
}
use of com.android.volley.toolbox.ImageRequest in project iosched by google.
the class ImageLoader method get.
/**
* Issues a bitmap request with the given URL if that image is not available
* in the cache, and returns a bitmap container that contains all of the data
* relating to the request (as well as the default image if the requested
* image is not available).
* @param requestUrl The url of the remote image
* @param imageListener The listener to call when the remote image is loaded
* @param maxWidth The maximum width of the returned image.
* @param maxHeight The maximum height of the returned image.
* @return A container object that contains all of the properties of the request, as well as
* the currently available image (default if remote is not loaded).
*/
public ImageContainer get(String requestUrl, ImageListener imageListener, int maxWidth, int maxHeight) {
// only fulfill requests that were initiated from the main thread.
throwIfNotOnMainThread();
final String cacheKey = getCacheKey(requestUrl, maxWidth, maxHeight);
// Try to look up the request in the cache of remote images.
Bitmap cachedBitmap = mCache.getBitmap(cacheKey);
if (cachedBitmap != null) {
// Return the cached bitmap.
ImageContainer container = new ImageContainer(cachedBitmap, requestUrl, null, null);
imageListener.onResponse(container, true);
return container;
}
// The bitmap did not exist in the cache, fetch it!
ImageContainer imageContainer = new ImageContainer(null, requestUrl, cacheKey, imageListener);
// Update the caller to let them know that they should use the default bitmap.
imageListener.onResponse(imageContainer, true);
// Check to see if a request is already in-flight.
BatchedImageRequest request = mInFlightRequests.get(cacheKey);
if (request != null) {
// If it is, add this request to the list of listeners.
request.addContainer(imageContainer);
return imageContainer;
}
// The request is not already in flight. Send the new request to the network and
// track it.
Request<?> newRequest = new ImageRequest(requestUrl, new Listener<Bitmap>() {
@Override
public void onResponse(Bitmap response) {
onGetImageSuccess(cacheKey, response);
}
}, maxWidth, maxHeight, Config.RGB_565, new ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
onGetImageError(cacheKey, error);
}
});
mRequestQueue.add(newRequest);
mInFlightRequests.put(cacheKey, new BatchedImageRequest(newRequest, imageContainer));
return imageContainer;
}
use of com.android.volley.toolbox.ImageRequest in project saga-android by AnandChowdhary.
the class DownloadReceiver method onReceive.
@Override
public void onReceive(final Context context, final Intent intent) {
DownloadManager dMgr = (DownloadManager) context.getSystemService(Context.DOWNLOAD_SERVICE);
Long downloadId = intent.getExtras().getLong(DownloadManager.EXTRA_DOWNLOAD_ID);
Cursor c = dMgr.query(new DownloadManager.Query().setFilterById(downloadId));
if (c.moveToFirst()) {
int status = c.getInt(c.getColumnIndex(DownloadManager.COLUMN_STATUS));
if (status == DownloadManager.STATUS_SUCCESSFUL) {
final String title = c.getString(c.getColumnIndex(DownloadManager.COLUMN_TITLE));
Log.d("Receiver", "Title:" + title);
if (title.equalsIgnoreCase(context.getString(R.string.app_name) + " " + context.getString(R.string.update))) {
Intent install = new Intent(Intent.ACTION_VIEW);
install.setDataAndType(Uri.parse(c.getString(c.getColumnIndex(DownloadManager.COLUMN_LOCAL_URI))), "application/vnd.android.package-archive");
install.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(install);
} else {
try {
TagOptionSingleton.getInstance().setAndroid(true);
final File file = new File(Utils.getStoragePath(context) + "/" + title);
final AudioFile f = AudioFileIO.read(file);
final Tag tag = f.getTag();
String json = readFromFile(context, title);
String url = null;
if (json != null) {
JSONObject jsonObject = new JSONObject(json);
if (jsonObject.getString("track") != null) {
if (jsonObject.getString("artist") != null) {
url = Utils.getAlbumArt(jsonObject.getString("track"), jsonObject.getString("artist"));
} else {
url = Utils.getAlbumArt(jsonObject.getString("track"), null);
}
}
if (jsonObject.getString("artist") != null)
tag.setField(FieldKey.ARTIST, jsonObject.getString("artist"));
if (jsonObject.getString("artist") != null)
tag.setField(FieldKey.ALBUM_ARTIST, jsonObject.getString("artist"));
if (jsonObject.getString("release") != null)
tag.setField(FieldKey.YEAR, jsonObject.getString("release"));
if (jsonObject.getString("trackno") != null)
tag.setField(FieldKey.TRACK, jsonObject.getString("trackno"));
if (jsonObject.getString("album") != null)
tag.setField(FieldKey.ALBUM, jsonObject.getString("album"));
if (jsonObject.getString("genre") != null)
tag.setField(FieldKey.GENRE, jsonObject.getString("genre"));
tag.setField(FieldKey.COMMENT, "Downloaded from Saga");
} else {
url = Utils.getAlbumArt(title.substring(0, title.length() - 4), null);
}
if (url != null) {
ImageRequest request = new ImageRequest(url, new Response.Listener<Bitmap>() {
@Override
public void onResponse(Bitmap bitmap) {
FileOutputStream out = null;
try {
String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date());
String imageFileName = "JPEG_" + timeStamp + "_";
File storageDir = context.getCacheDir();
File cover = File.createTempFile(imageFileName, /* prefix */
".jpg", /* suffix */
storageDir);
out = new FileOutputStream(cover);
bitmap.compress(Bitmap.CompressFormat.JPEG, 100, out);
AndroidArtwork artwork = AndroidArtwork.createArtworkFromFile(cover);
tag.setField(artwork);
Log.d(TAG, "AlbumArt deleted " + cover.delete());
} catch (Exception e) {
e.printStackTrace();
} finally {
commitAudio(context, f, file);
try {
if (out != null) {
out.close();
}
} catch (IOException e) {
e.printStackTrace();
}
}
}
}, 0, 0, null, new Response.ErrorListener() {
public void onErrorResponse(VolleyError error) {
error.printStackTrace();
commitAudio(context, f, file);
}
});
request.setShouldCache(false);
VolleySingleton.getInstance(context).addToRequestQueue(request);
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
}
}
Aggregations