-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Doesn't do anything fancy, just loads images into a GridView.
- Loading branch information
1 parent
11bfabb
commit 4ac8fab
Showing
23 changed files
with
562 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<classpath> | ||
<classpathentry kind="src" path="src"/> | ||
<classpathentry kind="src" path="gen"/> | ||
<classpathentry kind="con" path="com.android.ide.eclipse.adt.ANDROID_FRAMEWORK"/> | ||
<classpathentry kind="con" path="com.android.ide.eclipse.adt.LIBRARIES"/> | ||
<classpathentry kind="output" path="bin/classes"/> | ||
</classpath> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<projectDescription> | ||
<name>Folly</name> | ||
<comment></comment> | ||
<projects> | ||
</projects> | ||
<buildSpec> | ||
<buildCommand> | ||
<name>com.android.ide.eclipse.adt.ResourceManagerBuilder</name> | ||
<arguments> | ||
</arguments> | ||
</buildCommand> | ||
<buildCommand> | ||
<name>com.android.ide.eclipse.adt.PreCompilerBuilder</name> | ||
<arguments> | ||
</arguments> | ||
</buildCommand> | ||
<buildCommand> | ||
<name>org.eclipse.jdt.core.javabuilder</name> | ||
<arguments> | ||
</arguments> | ||
</buildCommand> | ||
<buildCommand> | ||
<name>com.android.ide.eclipse.adt.ApkBuilder</name> | ||
<arguments> | ||
</arguments> | ||
</buildCommand> | ||
</buildSpec> | ||
<natures> | ||
<nature>com.android.ide.eclipse.adt.AndroidNature</nature> | ||
<nature>org.eclipse.jdt.core.javanature</nature> | ||
</natures> | ||
</projectDescription> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<manifest xmlns:android="http://schemas.android.com/apk/res/android" | ||
package="com.evancharlton.folly" | ||
android:versionCode="1" | ||
android:versionName="1.0" > | ||
|
||
<uses-permission android:name="android.permission.INTERNET" /> | ||
|
||
<uses-sdk | ||
android:minSdkVersion="8" | ||
android:targetSdkVersion="17" /> | ||
|
||
<application | ||
android:allowBackup="true" | ||
android:icon="@drawable/ic_launcher" | ||
android:label="@string/app_name" | ||
android:theme="@style/AppTheme" | ||
android:name=".FollyApp"> | ||
<activity | ||
android:name="com.evancharlton.folly.MainActivity" | ||
android:label="@string/app_name" > | ||
<intent-filter> | ||
<action android:name="android.intent.action.MAIN" /> | ||
|
||
<category android:name="android.intent.category.LAUNCHER" /> | ||
</intent-filter> | ||
</activity> | ||
</application> | ||
|
||
</manifest> |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" | ||
xmlns:tools="http://schemas.android.com/tools" | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent" | ||
tools:context=".MainActivity" > | ||
|
||
<Button android:id="@+id/search" | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:layout_alignParentTop="true" | ||
android:layout_alignParentRight="true" | ||
android:text="@string/search" /> | ||
|
||
<EditText android:id="@+id/query" | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:layout_alignParentTop="true" | ||
android:layout_alignParentLeft="true" | ||
android:layout_toLeftOf="@id/search" | ||
android:text="@string/default_query" | ||
android:hint="@string/query" /> | ||
|
||
<GridView android:id="@+id/grid" | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:layout_below="@id/search" | ||
android:layout_alignParentLeft="true" | ||
android:layout_alignParentRight="true" | ||
android:layout_alignParentBottom="true" | ||
android:numColumns="4" /> | ||
|
||
</RelativeLayout> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<com.android.volley.toolbox.NetworkImageView xmlns:android="http://schemas.android.com/apk/res/android" | ||
android:id="@+id/thumbnail" | ||
android:layout_width="75dp" | ||
android:layout_height="75dp" /> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<menu xmlns:android="http://schemas.android.com/apk/res/android" > | ||
|
||
<item | ||
android:id="@+id/menu_settings" | ||
android:orderInCategory="100" | ||
android:showAsAction="never" | ||
android:title="@string/menu_settings"/> | ||
|
||
</menu> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<resources> | ||
|
||
<!-- | ||
Base application theme for API 11+. This theme completely replaces | ||
AppBaseTheme from res/values/styles.xml on API 11+ devices. | ||
--> | ||
<style name="AppBaseTheme" parent="android:Theme.Holo.Light"> | ||
<!-- API 11 theme customizations can go here. --> | ||
</style> | ||
|
||
</resources> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<resources> | ||
|
||
<!-- | ||
Base application theme for API 14+. This theme completely replaces | ||
AppBaseTheme from BOTH res/values/styles.xml and | ||
res/values-v11/styles.xml on API 14+ devices. | ||
--> | ||
<style name="AppBaseTheme" parent="android:Theme.Holo.Light.DarkActionBar"> | ||
<!-- API 14 theme customizations can go here. --> | ||
</style> | ||
|
||
</resources> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<resources> | ||
|
||
<string name="app_name">Folly</string> | ||
<string name="menu_settings">Settings</string> | ||
|
||
<string name="search">Search</string> | ||
|
||
<string name="default_query">android</string> | ||
<string name="query">Search query</string> | ||
|
||
</resources> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<resources> | ||
|
||
<!-- | ||
Base application theme, dependent on API level. This theme is replaced | ||
by AppBaseTheme from res/values-vXX/styles.xml on newer devices. | ||
--> | ||
<style name="AppBaseTheme" parent="android:Theme.Light"> | ||
<!-- | ||
Theme customizations available in newer API levels can go in | ||
res/values-vXX/styles.xml, while customizations related to | ||
backward-compatibility can go here. | ||
--> | ||
</style> | ||
|
||
<!-- Application theme. --> | ||
<style name="AppTheme" parent="AppBaseTheme"> | ||
<!-- All customizations that are NOT specific to a particular API-level can go here. --> | ||
</style> | ||
|
||
</resources> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
|
||
package com.evancharlton.folly; | ||
|
||
import android.graphics.Bitmap; | ||
|
||
import com.android.volley.Request; | ||
import com.android.volley.RequestQueue; | ||
import com.android.volley.Response.ErrorListener; | ||
import com.android.volley.Response.Listener; | ||
import com.android.volley.toolbox.ImageRequest; | ||
import com.evancharlton.folly.api.FlickrResponse.Photos; | ||
import com.evancharlton.folly.api.FlickrResponse.Photos.Photo; | ||
|
||
public class FlickrApi { | ||
private final RequestQueue mQueue; | ||
|
||
public FlickrApi(RequestQueue queue) { | ||
mQueue = queue; | ||
} | ||
|
||
public Request<?> search(String query, int pageNum, Listener<Photos> listener, | ||
ErrorListener errorListener) { | ||
return mQueue.add(new FlickrSearch(query, pageNum, listener, errorListener)); | ||
} | ||
|
||
public Request<?> thumbnail(Photo photo, int maxWidth, int maxHeight, | ||
Listener<Bitmap> listener, ErrorListener errorListener) { | ||
return mQueue.add(new ImageRequest(photo.getUrl(), listener, maxWidth, maxHeight, null, | ||
errorListener)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
|
||
package com.evancharlton.folly; | ||
|
||
import com.android.volley.NetworkResponse; | ||
import com.android.volley.Request; | ||
import com.android.volley.Response; | ||
import com.android.volley.Response.ErrorListener; | ||
import com.android.volley.Response.Listener; | ||
import com.evancharlton.folly.api.FlickrResponse; | ||
import com.evancharlton.folly.api.FlickrResponse.Photos; | ||
import com.google.gson.Gson; | ||
|
||
public class FlickrSearch extends Request<Photos> { | ||
public static final String API_KEY = "96e3cd93b482b82c5acacff05d77fdab"; | ||
|
||
private final Listener<Photos> mListener; | ||
|
||
private final Gson mGson = new Gson(); | ||
|
||
public FlickrSearch(String query, int page, Listener<Photos> listener, | ||
ErrorListener errorListener) { | ||
super(Method.GET, getUrl(query, page), errorListener); | ||
mListener = listener; | ||
} | ||
|
||
@Override | ||
protected void deliverResponse(Photos response) { | ||
mListener.onResponse(response); | ||
} | ||
|
||
@Override | ||
protected Response<Photos> parseNetworkResponse(NetworkResponse response) { | ||
String jsonString = new String(response.data); | ||
FlickrResponse flickrResponse = mGson.fromJson(jsonString, FlickrResponse.class); | ||
return Response.success(flickrResponse.getPhotos(), getCacheEntry()); | ||
} | ||
|
||
private static String getUrl(String query, int page) { | ||
return "http://api.flickr.com/services/rest/?method=flickr.photos.search" | ||
+ "&api_key=" + API_KEY | ||
+ "&text=" + query | ||
+ "&page=" + page | ||
+ "&per_page=" + ResultsAdapter.PER_PAGE | ||
+ "&format=json&nojsoncallback=1"; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
|
||
package com.evancharlton.folly; | ||
|
||
import android.app.Application; | ||
import android.graphics.Bitmap; | ||
import android.support.v4.util.LruCache; | ||
|
||
import com.android.volley.RequestQueue; | ||
import com.android.volley.toolbox.ImageLoader; | ||
import com.android.volley.toolbox.ImageLoader.ImageCache; | ||
import com.android.volley.toolbox.Volley; | ||
|
||
public class FollyApp extends Application { | ||
private static FollyApp sInstance; | ||
|
||
public static FollyApp get() { | ||
return sInstance; | ||
} | ||
|
||
private final LruCache<String, Bitmap> mImageCache = new LruCache<String, Bitmap>(20); | ||
|
||
private FlickrApi mApi; | ||
|
||
private ImageLoader mImageLoader; | ||
|
||
@Override | ||
public void onCreate() { | ||
super.onCreate(); | ||
sInstance = this; | ||
|
||
RequestQueue queue = Volley.newRequestQueue(this); | ||
mApi = new FlickrApi(queue); | ||
|
||
ImageCache imageCache = new ImageCache() { | ||
@Override | ||
public void putBitmap(String key, Bitmap value) { | ||
mImageCache.put(key, value); | ||
} | ||
|
||
@Override | ||
public Bitmap getBitmap(String key) { | ||
return mImageCache.get(key); | ||
} | ||
}; | ||
|
||
mImageLoader = new ImageLoader(queue, imageCache); | ||
} | ||
|
||
public FlickrApi getApi() { | ||
return mApi; | ||
} | ||
|
||
public ImageLoader getImageLoader() { | ||
return mImageLoader; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
|
||
package com.evancharlton.folly; | ||
|
||
import android.util.Log; | ||
|
||
public final class FollyLog { | ||
private static final String TAG = "Folly"; | ||
|
||
private FollyLog() { | ||
} | ||
|
||
public static void d(String msg, Object... args) { | ||
if (args != null && args.length > 0) { | ||
msg = String.format(msg, args); | ||
} | ||
Log.d(TAG, msg); | ||
} | ||
|
||
public static void e(Throwable t, String msg, Object... args) { | ||
if (args != null && args.length > 0) { | ||
msg = String.format(msg, args); | ||
} | ||
Log.e(TAG, msg, t); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
|
||
package com.evancharlton.folly; | ||
|
||
import android.app.Activity; | ||
import android.os.Bundle; | ||
import android.view.Menu; | ||
import android.view.View; | ||
import android.widget.AdapterView; | ||
import android.widget.Button; | ||
import android.widget.EditText; | ||
|
||
public class MainActivity extends Activity { | ||
private AdapterView<ResultsAdapter> mGridView; | ||
private EditText mQuery; | ||
private Button mSearch; | ||
|
||
private ResultsAdapter mAdapter; | ||
|
||
@SuppressWarnings("unchecked") | ||
@Override | ||
protected void onCreate(Bundle savedInstanceState) { | ||
super.onCreate(savedInstanceState); | ||
setContentView(R.layout.activity_main); | ||
|
||
mQuery = (EditText) findViewById(R.id.query); | ||
mSearch = (Button) findViewById(R.id.search); | ||
|
||
mSearch.setOnClickListener(new View.OnClickListener() { | ||
@Override | ||
public void onClick(View v) { | ||
mAdapter.setQuery(mQuery.getText().toString()); | ||
} | ||
}); | ||
|
||
mGridView = (AdapterView<ResultsAdapter>) findViewById(R.id.grid); | ||
mAdapter = new ResultsAdapter(this, FollyApp.get().getImageLoader()); | ||
mGridView.setAdapter(mAdapter); | ||
} | ||
|
||
@Override | ||
public boolean onCreateOptionsMenu(Menu menu) { | ||
getMenuInflater().inflate(R.menu.activity_main, menu); | ||
return true; | ||
} | ||
} |
Oops, something went wrong.