Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .idea/gradle.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 17 additions & 1 deletion .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 0 additions & 6 deletions .idea/vcs.xml

This file was deleted.

1 change: 1 addition & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,5 @@ dependencies {
compile 'com.android.support:appcompat-v7:24.2.1'
compile 'com.android.volley:volley:1.0.0'
testCompile 'junit:junit:4.12'
testCompile 'org.mockito:mockito-core:1.10.19'
}
2 changes: 1 addition & 1 deletion app/src/main/java/com/example/samplegallery/APIKeys.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@
* keys publically!
*/
public class APIKeys {
public static final String FLICKR_API_KEY = "64ffdc1fd4b18211f4f98513848d2335";
public static final String FLICKR_API_KEY = "b189cbcb6aeea9a8ae5d0a10ec002496";
}
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;

Expand Down Expand Up @@ -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 progressSpinner = (ProgressBar) rootView.findViewById(R.id.blowup_progress_bar);
// / create a request for photo title
JsonObjectRequest photoInfoRequest = new JsonObjectRequest(
Request.Method.GET,
getPhotosInfoUrl(),
Expand Down Expand Up @@ -86,16 +90,32 @@ public void onResponse(JSONObject response) {
try {
sizes = response.getJSONObject("sizes").getJSONArray("size");
photoUrl = sizes
.getJSONObject(sizes.length() - 1)
.getJSONObject(sizes.length() - 1) //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());
//isnt onResponse on the uithread? would moving it off the main thread speed things up? would it be possible to?
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, it's on the ui thread but only after the response is fetched. That's necessary though since you're updating the ui! The request itself in not on the ui thread



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);
progressSpinner.setVisibility(View.GONE); //removes the progress spinner from the background
}
};
Response.ErrorListener errorListener = new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
error.printStackTrace();
}
};
//solution is deprecated: better, worse or equivalent to hacky?
ImageRequest getImgReq = new ImageRequest(photoUrl, imgListener, 0,0,null,errorListener);
VolleyRequestQueue.getInstance(getContext()).addToRequestQueue(getImgReq);
}
},
new VolleyErrorListener(getContext())
Expand Down
6 changes: 4 additions & 2 deletions app/src/main/res/layout/photo_blowup_fragment.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,17 @@
<ProgressBar
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/blowup_progress_bar"
style="@android:style/Widget.ProgressBar.Large"
android:layout_centerInParent="true"/>

<com.android.volley.toolbox.NetworkImageView
<ImageView
android:id="@+id/photo_blowup"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:scaleType="centerCrop"/>
android:scaleType="centerCrop"
android:contentDescription="@string/desc"/>

<TextView
android:id="@+id/photo_description"
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@
<string name="app_name">SampleGallery</string>
<string name="flickr_base_url">https://api.flickr.com/services/rest/?</string>
<string name="yale_album_id">12208415@N08</string>
<string name="desc">fullscreen photo</string>
</resources>
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package com.example.samplegallery.Utilities;

import android.content.Context;
import android.util.DisplayMetrics;

import org.junit.Test;
import org.mockito.Mock;
import org.mockito.Mockito;


import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat;
import static org.mockito.Mockito.when;

/**
* Created by cr554 on 3/3/2017.
*
*/

public class LruBitmapCacheTest{
@Mock
Context mCtx;

@Test
public void getCacheSizeTest() throws Exception{
//set up an environment
DisplayMetrics dm = new DisplayMetrics();
dm.heightPixels = 4;
dm.widthPixels = 2;

//deep
//I want to mock context; but i declared it as a member var so, its not necessary to say that
mCtx = Mockito.mock(Context.class, Mockito.RETURNS_DEEP_STUBS);
//DEEP STUBBIN'
when(mCtx.getResources().getDisplayMetrics()).thenReturn(dm); // plain english: When we get the display metric from the rsource of the context, give it the mock dm we made (this is the hot dog supplied to the cook)

//now we assert that what we're testing is what we expect it to be.
assertThat(LruBitmapCache.getCacheSize(mCtx),is(4*2*4*4)); //4h * 2w * 4pages * 4bytes

//does including these #'s in the test necessitate putting that shit into an asset? ALso why x4 for 3 pages???
//"any constant that is used 2+ should be an asset"
}

}