-
Notifications
You must be signed in to change notification settings - Fork 8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
syncronizedimages with their info, removed the progress bar, sped #17
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,23 @@ | ||
package com.example.samplegallery; | ||
|
||
import android.graphics.Bitmap; | ||
import android.net.Uri; | ||
import android.os.Bundle; | ||
import android.support.annotation.Nullable; | ||
import android.support.v4.app.Fragment; | ||
import android.view.LayoutInflater; | ||
import android.view.View; | ||
import android.view.ViewGroup; | ||
import android.widget.ImageView; | ||
import android.widget.RelativeLayout; | ||
import android.widget.ProgressBar; | ||
import android.widget.TextView; | ||
|
||
import com.android.volley.Request; | ||
import com.android.volley.Response; | ||
import com.android.volley.VolleyError; | ||
import com.android.volley.toolbox.ImageRequest; | ||
import com.android.volley.toolbox.JsonObjectRequest; | ||
import com.android.volley.toolbox.NetworkImageView; | ||
import com.example.samplegallery.Utilities.VolleyErrorListener; | ||
import com.example.samplegallery.Utilities.VolleyRequestQueue; | ||
|
||
|
@@ -43,11 +47,11 @@ public void onCreate(Bundle savedInstanceState) { | |
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { | ||
RelativeLayout rootView = (RelativeLayout) inflater. | ||
inflate(R.layout.photo_blowup_fragment, container, false); | ||
final NetworkImageView img = (NetworkImageView) rootView.findViewById(R.id.photo_blowup); | ||
final ImageView img = (ImageView) rootView.findViewById(R.id.photo_blowup); | ||
final TextView photoTitleView = (TextView) rootView.findViewById(R.id.photo_title); | ||
final TextView photoDescriptionView = | ||
(TextView) rootView.findViewById(R.id.photo_description); | ||
// create a request for photo title | ||
final TextView photoDescriptionView = (TextView) rootView.findViewById(R.id.photo_description); | ||
final ProgressBar progressBar = (ProgressBar) rootView.findViewById(R.id.blowup_progress_bar); | ||
// / create a request for photo title | ||
JsonObjectRequest photoInfoRequest = new JsonObjectRequest( | ||
Request.Method.GET, | ||
getPhotosInfoUrl(), | ||
|
@@ -86,16 +90,29 @@ public void onResponse(JSONObject response) { | |
try { | ||
sizes = response.getJSONObject("sizes").getJSONArray("size"); | ||
photoUrl = sizes | ||
.getJSONObject(sizes.length() - 1) | ||
.getJSONObject(sizes.length() - 3) //finding a smaller size will speed up load times | ||
.getString("source"); | ||
} catch (JSONException e) { | ||
e.printStackTrace(); | ||
} | ||
|
||
// finally set the url for the image | ||
img.setImageUrl( | ||
photoUrl, | ||
VolleyRequestQueue.getInstance(getContext()).getImgLoader()); | ||
Response.Listener<Bitmap> imgListener = new Response.Listener<Bitmap>() { | ||
@Override | ||
public void onResponse(Bitmap response) { | ||
img.setImageBitmap(response); | ||
photoDescriptionView.setVisibility(View.VISIBLE); | ||
photoTitleView.setVisibility(View.VISIBLE); | ||
progressBar.setVisibility(View.GONE); | ||
} | ||
}; | ||
Response.ErrorListener errorListener = new Response.ErrorListener() { | ||
@Override | ||
public void onErrorResponse(VolleyError error) { | ||
//things2 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Huh? |
||
} | ||
}; | ||
//solution is deprecated: better, worse or equivalent to hacky? | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What do you mean here? |
||
ImageRequest getImgReq = new ImageRequest(photoUrl, imgListener, 0,0,null,errorListener); | ||
VolleyRequestQueue.getInstance(getContext()).addToRequestQueue(getImgReq); | ||
} | ||
}, | ||
new VolleyErrorListener(getContext()) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Bug:
what if the length of sizes is less than 3?