【发布时间】:2016-02-13 12:48:44
【问题描述】:
我有一个 GridView,其中的图像是由 Volley 库从网络中获取的。 当我单击一个项目时,图像在下载后以全屏全分辨率打开,这需要一些时间。 所以我用 AppBar 更改了它,但我仍然使用相同的方法来显示它,这同样需要相同的时间。
这是:
private void fetchFullResolutionImage() {
String url = selectedPhoto.getPhotoJson();
// volley's json obj request
JsonObjectRequest jsonObjReq = new JsonObjectRequest(Request.Method.GET, url,
(String)null, new Response.Listener<JSONObject>() {
@Override
public void onResponse(JSONObject response) {
Log.d(TAG,
"Image full resolution json: "
+ response.toString());
try {
// Parsing the json response
JSONObject entry = response
.getJSONObject(TAG_ENTRY);
JSONArray mediacontentArry = entry.getJSONObject(
TAG_MEDIA_GROUP).getJSONArray(
TAG_MEDIA_CONTENT);
JSONObject mediaObj = (JSONObject) mediacontentArry
.get(0);
String fullResolutionUrl = mediaObj
.getString(TAG_IMG_URL);
// image full resolution widht and height
final int width = mediaObj.getInt(TAG_IMG_WIDTH);
final int height = mediaObj.getInt(TAG_IMG_HEIGHT);
Log.d(TAG, "Full resolution image. url: "
+ fullResolutionUrl + ", w: " + width
+ ", h: " + height);
ImageLoader imageLoader = AppController
.getInstance().getImageLoader();
// We download image into ImageView instead of
// NetworkImageView to have callback methods
// Currently NetworkImageView doesn't have callback
// methods
imageLoader.get(fullResolutionUrl,
new ImageLoader.ImageListener() {
@Override
public void onErrorResponse(
VolleyError arg0) {
Toast.makeText(
getApplicationContext(),
getString(R.string.msg_wall_fetch_error),
Toast.LENGTH_LONG).show();
}
@Override
public void onResponse(
ImageLoader.ImageContainer response,
boolean arg1) {
if (response.getBitmap() != null) {
// load bitmap into imageview
backdrop
.setImageBitmap(response
.getBitmap());
}
}
});
} catch (JSONException e) {
e.printStackTrace();
Toast.makeText(getApplicationContext(),
getString(R.string.msg_unknown_error),
Toast.LENGTH_LONG).show();
}
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
Log.e(TAG, "Error: " + error.getMessage());
// unable to fetch wallpapers
// either google username is wrong or
// devices doesn't have internet connection
Toast.makeText(getApplicationContext(),
getString(R.string.msg_wall_fetch_error),
Toast.LENGTH_LONG).show();
}
});
// Remove the url from cache
AppController.getInstance().getRequestQueue().getCache().remove(url);
// Disable the cache for this url, so that it always fetches updated
// json
jsonObjReq.setShouldCache(false);
// Adding request to request queue
AppController.getInstance().addToRequestQueue(jsonObjReq);
}
所以我的想法可能是以某种方式显示 AppBar 中的下一个活动的图像将是相同的网络图像(缩略图),它已经加载到网格视图中,因此它可能会很快。
因此,我要求的是在下一个 Activity 的 NetworkImageView 中显示从 gridView 中选择的相同图像。
【问题讨论】:
标签: android gridview android-volley