Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
0f98ad4
add defaultConfig section with min/target sdk versions
martawoldanska Aug 6, 2014
6ab973b
introduce json file with list of avatars to be used soon instead of c…
martawoldanska Aug 6, 2014
e4e40e1
Helper method checking internet access
martawoldanska Aug 6, 2014
a061835
Switching Chuck Norris with Polidea's employees' faces in CoverFlowTe…
martawoldanska Aug 6, 2014
1c2f72c
ResourceImageAdapter reverted to the old version. NetworkImageAdapter…
martawoldanska Aug 6, 2014
5fc2bca
NetworkImageAdapter parses JSON file and shows Chuck Norris on every …
martawoldanska Aug 6, 2014
2a74148
Cleaning up the mess in activity
martawoldanska Aug 6, 2014
9cb10bd
Picasso added
martawoldanska Aug 6, 2014
618e3cf
I need getView to be not final in order to overload it in NetworkImag…
martawoldanska Aug 6, 2014
4e45e66
NetworkImageAdapter now uses Picasso to fetch Polidea's employees' av…
martawoldanska Aug 6, 2014
6228484
EmployeeAvatarTask removed
martawoldanska Aug 6, 2014
fbe5e84
Optimize imports
martawoldanska Aug 6, 2014
330684c
Comment about using ReflectingImageAdapter added
martawoldanska Aug 6, 2014
9ec5dbb
GSON used instead of manually parsing JSON
martawoldanska Aug 6, 2014
7f26a18
Retrofit added to build.gradle
martawoldanska Aug 7, 2014
e86ff04
Country and FlagsInterface added
martawoldanska Aug 7, 2014
b863868
Fetch flags button added
martawoldanska Aug 7, 2014
81c6351
Fetching flags with Retrofit on button click added
martawoldanska Aug 7, 2014
6150179
Unnecessary comments removed
martawoldanska Aug 7, 2014
bc95699
ReflectingImageAdapter removed from both testing activity and its lay…
martawoldanska Aug 7, 2014
5f8dad6
Reading string from file in NetworkImageAdapter now uses BufferedReader
martawoldanska Aug 7, 2014
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
4 changes: 4 additions & 0 deletions AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" android:versionCode="8" android:versionName="TEST_RELEASE" package="pl.polidea.coverflow">
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />

<application android:icon="@drawable/icon" android:label="@string/app_name">
<activity android:label="@string/app_name" android:name=".testingactivity.CoverFlowTestingActivity">
<intent-filter>
Expand Down
168 changes: 168 additions & 0 deletions assets/faces.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,168 @@
{
"people":[
{
"gravatar":"http://www.gravatar.com/avatar/feb86e26302b2efd0f937afa72a16fc6?d=monsterid&s=240",
"id":"0"
},
{
"gravatar":"http://www.gravatar.com/avatar/487bb9d69c8795b5dd1e67332cfb8221?d=monsterid&s=240",
"id":"1"
},
{
"gravatar":"http://www.gravatar.com/avatar/f31e2458313b36730a066ec703e51b11?d=monsterid&s=240",
"id":"2"
},
{
"gravatar":"http://www.gravatar.com/avatar/7f8727786f6bb1a0c352acc4e4419a83?d=monsterid&s=240",
"id":"3"
},
{
"gravatar":"http://www.gravatar.com/avatar/2dc3eab78ab131cc3a8acbc972c92b73?d=monsterid&s=240",
"id":"4"
},
{
"gravatar":"http://www.gravatar.com/avatar/705da853dcc90e5aca80b4d085c1d214?d=monsterid&s=240",
"id":"5"
},
{
"gravatar":"http://www.gravatar.com/avatar/28be0f28848e9b280845436bf3fad6ca?d=monsterid&s=240",
"id":"6"
},
{
"gravatar":"http://www.gravatar.com/avatar/1c364f4cad4f61aa08dc8f112931e39f?d=monsterid&s=240",
"id":"7"
},
{
"gravatar":"http://www.gravatar.com/avatar/bb03b2dafcda985bbeb52a4f446cc754?d=monsterid&s=240",
"id":"8"
},
{
"gravatar":"http://www.gravatar.com/avatar/ec43363ba46bdb76aae3999edf692871?d=monsterid&s=240",
"id":"9"
},
{
"gravatar":"http://www.gravatar.com/avatar/e32aee082c585f111fe3405d470112b0?d=monsterid&s=240",
"id":"10"
},
{
"gravatar":"http://www.gravatar.com/avatar/c770015076fd08e56be5cfd4ca387298?d=monsterid&s=240",
"id":"11"
},
{
"gravatar":"http://www.gravatar.com/avatar/53abc38c639a22f80174261df7f35f0d?d=monsterid&s=240",
"id":"12"
},
{
"gravatar":"http://www.gravatar.com/avatar/cd68c5cafec543474541a2211dc7444f?d=monsterid&s=240",
"id":"13"
},
{
"gravatar":"http://www.gravatar.com/avatar/2b7031546b140aa0612e4d2ce8f922c0?d=monsterid&s=240",
"id":"14"
},
{
"gravatar":"http://www.gravatar.com/avatar/bcb735972933b10b1eb269886c7c799a?d=monsterid&s=240",
"id":"15"
},
{
"gravatar":"http://www.gravatar.com/avatar/ab7fa42a14263894835ba1e5be031111?d=monsterid&s=240",
"id":"16"
},
{
"gravatar":"http://www.gravatar.com/avatar/35287768ccb0b3c68067a511c4c3503f?d=monsterid&s=240",
"id":"17"
},
{
"gravatar":"http://www.gravatar.com/avatar/45bba01ac921f96e49059da127800d6d?d=monsterid&s=240",
"id":"18"
},
{
"gravatar":"http://www.gravatar.com/avatar/289040ff9f5916ba6d88c660334660ec?d=monsterid&s=240",
"id":"19"
},
{
"gravatar":"http://www.gravatar.com/avatar/0808d58e098c64a5e9a1a411bce8d0d8?d=monsterid&s=240",
"id":"20"
},
{
"gravatar":"http://www.gravatar.com/avatar/81801d4f62de321a0bd6903fe9459a5a?d=monsterid&s=240",
"id":"21"
},
{
"gravatar":"http://www.gravatar.com/avatar/0cbc8aace3690ac2288754bfb12ef43c?d=monsterid&s=240",
"id":"22"
},
{
"gravatar":"http://www.gravatar.com/avatar/dae071222608e84f665fdfd4678e8f2e?d=monsterid&s=240",
"id":"23"
},
{
"gravatar":"http://www.gravatar.com/avatar/9b14143dfed8f4fa57428ad3e547bc0e?d=monsterid&s=240",
"id":"24"
},
{
"gravatar":"http://www.gravatar.com/avatar/e0a27844ea90b44bcebfa3bec7a583bd?d=monsterid&s=240",
"id":"25"
},
{
"gravatar":"http://www.gravatar.com/avatar/e60ecae6d42227896b877fe5ae80dcbf?d=monsterid&s=240",
"id":"26"
},
{
"gravatar":"http://www.gravatar.com/avatar/cb8004fd244c846ef07902d30be3d584?d=monsterid&s=240",
"id":"27"
},
{
"gravatar":"http://www.gravatar.com/avatar/5f68d5e3481bbd4e143454820f33d9b6?d=monsterid&s=240",
"id":"28"
},
{
"gravatar":"http://www.gravatar.com/avatar/eae907f53220bbcaabfe0cda31be29d8?d=monsterid&s=240",
"id":"29"
},
{
"gravatar":"http://www.gravatar.com/avatar/cd26f838cf344a14b8a1add418f8f2b8?d=monsterid&s=240",
"id":"30"
},
{
"gravatar":"http://www.gravatar.com/avatar/35bbb9b6fbad099dcbb2901d281a8d8e?d=monsterid&s=240",
"id":"31"
},
{
"gravatar":"http://www.gravatar.com/avatar/335ee931be900e9d28e769e5c9537084?d=monsterid&s=240",
"id":"32"
},
{
"gravatar":"http://www.gravatar.com/avatar/547db7c434e8a83737d99f0f4eab2290?d=monsterid&s=240",
"id":"33"
},
{
"gravatar":"http://www.gravatar.com/avatar/96dbb97764ca7f5d56073ccf401a9753?d=monsterid&s=240",
"id":"34"
},
{
"gravatar":"http://www.gravatar.com/avatar/fedd24fdaae013b925eff616ad55fee8?d=monsterid&s=240",
"id":"35"
},
{
"gravatar":"http://www.gravatar.com/avatar/fa0a22c3463a9ee3cb1acd6bc05b9a3e?d=monsterid&s=240",
"id":"36"
},
{
"gravatar":"http://www.gravatar.com/avatar/674f1d9793c903baeb7607655cd0f787?d=monsterid&s=240",
"id":"37"
},
{
"gravatar":"http://www.gravatar.com/avatar/ee5179d5ce0b3172b6b34c5ec94a61c0?d=monsterid&s=240",
"id":"38"
},
{
"gravatar":"http://www.gravatar.com/avatar/fde11b1d20465b0dcb7c9879aca299a3?d=monsterid&s=240",
"id":"39"
},
{
"gravatar":"http://www.gravatar.com/avatar/e6f6d95ae0cad8073ccac961c3c9e9d7?d=monsterid&s=240",
"id":"40"
}
]
}
11 changes: 11 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,21 @@ repositories {
}
}

dependencies {
compile 'com.squareup.picasso:picasso:2.3.3'
compile 'com.google.code.gson:gson:2.2.4'
compile 'com.squareup.retrofit:retrofit:1.6.1'
}

android {
compileSdkVersion 19
buildToolsVersion "19.1.0"

defaultConfig {
minSdkVersion 5
targetSdkVersion 18
}

sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
Expand Down
11 changes: 6 additions & 5 deletions res/layout/main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,14 @@
android:layout_height="wrap_content" android:layout_marginTop="5dip">
</view>

<pl.polidea.coverflow.CoverFlow xmlns:coverflow="http://schemas.android.com/apk/res/pl.polidea.coverflow"
coverflow:imageWidth="100dip" coverflow:imageHeight="150dip" coverflow:withReflection="true"
coverflow:imageReflectionRatio="0.2" coverflow:reflectionGap="2dip" android:id="@+id/coverflowReflect"
android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_marginTop="5dip" />

<TextView android:text="STATUS" android:layout_width="fill_parent" android:layout_height="wrap_content"
android:padding="5dip" android:id="@+id/statusText"></TextView>

<Button
android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="FETCH FLAGS!" />

</LinearLayout>

10 changes: 5 additions & 5 deletions src/pl/polidea/coverflow/AbstractCoverFlowImageAdapter.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
package pl.polidea.coverflow;

import java.lang.ref.WeakReference;
import java.util.HashMap;
import java.util.Map;

import android.content.Context;
import android.graphics.Bitmap;
import android.util.Log;
Expand All @@ -12,6 +8,10 @@
import android.widget.BaseAdapter;
import android.widget.ImageView;

import java.lang.ref.WeakReference;
import java.util.HashMap;
import java.util.Map;

/**
* This class is an adapter that provides base, abstract class for images
* adapter.
Expand Down Expand Up @@ -100,7 +100,7 @@ public final synchronized long getItemId(final int position) {
* android.view.ViewGroup)
*/
@Override
public final synchronized ImageView getView(final int position, final View convertView, final ViewGroup parent) {
public synchronized ImageView getView(final int position, final View convertView, final ViewGroup parent) {
ImageView imageView;
if (convertView == null) {
final Context context = parent.getContext();
Expand Down
139 changes: 139 additions & 0 deletions src/pl/polidea/coverflow/NetworkImageAdapter.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
package pl.polidea.coverflow;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.drawable.BitmapDrawable;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import com.google.gson.Gson;
import com.squareup.picasso.Picasso;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.lang.ref.WeakReference;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;

import pl.polidea.coverflow.testingactivity.Country;
import pl.polidea.coverflow.testingactivity.Result;

/**
* This class is an adapter that provides images from a fixed set of resource
* ids. Bitmaps and ImageViews are kept as weak references so that they can be
* cleared by garbage collection when not needed.
*
*/
public class NetworkImageAdapter extends AbstractCoverFlowImageAdapter {
/** The Constant TAG. */
private static final String TAG = NetworkImageAdapter.class.getSimpleName();

/** The bitmap map. */
private final Map<Integer, WeakReference<Bitmap>> bitmapMap = new HashMap<Integer, WeakReference<Bitmap>>();

private final Context context;

private static final LinkedList<Result> RESULTS = new LinkedList<Result>();

public NetworkImageAdapter(final Context context)
{
super();

this.context = context;
try {
setResources(parseJSONResult(readStringFromInputStream(context.getAssets().open("faces.txt"))));
}
catch (IOException e)
{
e.printStackTrace();
}
}

public final synchronized void setResources(List<Result> results)
{
RESULTS.clear();

for (Result r : results)
{
RESULTS.add(r);
}

notifyDataSetChanged();
}

/*
* (non-Javadoc)
*
* @see android.widget.Adapter#getCount()
*/
@Override
public synchronized int getCount()
{
return RESULTS.size();
}

/*
* (non-Javadoc)
*
* @see pl.polidea.coverflow.AbstractCoverFlowImageAdapter#createBitmap(int)
*/
@Override
protected Bitmap createBitmap(final int position) {
return ((BitmapDrawable) context.getResources().getDrawable(R.drawable.image01)).getBitmap();
}

private String readStringFromInputStream(InputStream inputStream) throws IOException
{
StringBuilder builder = new StringBuilder();
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(inputStream));
String line;

while((line = bufferedReader.readLine()) != null)
{
builder.append(line);
}

return builder.toString();
}

public void setCountries(List<Country> countries)
{
RESULTS.clear();

for (Country country: countries) {
RESULTS.add(country.toResult());
}

notifyDataSetChanged();
}

private class Wrapper {
public LinkedList<Result> people = new LinkedList<Result>();
}

private LinkedList<Result> parseJSONResult(String json)
{
Gson gson = new Gson();

Wrapper wrapper = gson.fromJson(json, Wrapper.class);

return wrapper.people;
}

@Override
public synchronized ImageView getView(int position, View convertView, ViewGroup parent)
{
ImageView view = super.getView(position, convertView, parent);

Picasso.with(context).load(RESULTS.get(position).getAvatarURL()).into(view);

return view;
}
}
Loading