summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoe Robinson <joe@lc8n.com>2014-08-03 03:51:13 +0100
committerJoe Robinson <joe@lc8n.com>2014-08-03 03:51:13 +0100
commit3398c580fd742d785ce5cc90ba2d1c720874fb3f (patch)
tree23268d04efd62f0fb2954c76ecee63dcee7fd464
parent848cfa51b7de694fbcef75b41818b33ed81b7359 (diff)
Created the home screen with a grid of images from blaupload
-rw-r--r--.idea/libraries/otto_1_3_5.xml9
-rw-r--r--.idea/misc.xml3
-rw-r--r--app/app.iml1
-rw-r--r--app/build.gradle1
-rw-r--r--app/src/main/AndroidManifest.xml5
-rw-r--r--app/src/main/java/uk/co/blatech/blaupload/HomeScreen.java81
-rw-r--r--app/src/main/java/uk/co/blatech/blaupload/HomeScreenFragment.java171
-rw-r--r--app/src/main/java/uk/co/blatech/blaupload/UploadFragment.java118
-rw-r--r--app/src/main/java/uk/co/blatech/blaupload/data/ImageItem.java46
-rw-r--r--app/src/main/java/uk/co/blatech/blaupload/ui/GridViewAdapter.java56
-rw-r--r--app/src/main/java/uk/co/blatech/blaupload/util/EventBus.java17
-rw-r--r--app/src/main/java/uk/co/blatech/blaupload/util/ImageLoader.java95
-rw-r--r--app/src/main/java/uk/co/blatech/blaupload/util/ImageLoaderResultEvent.java16
-rw-r--r--app/src/main/java/uk/co/blatech/blaupload/util/JSONLoader.java103
-rw-r--r--app/src/main/java/uk/co/blatech/blaupload/util/JSONLoaderResultEvent.java16
-rw-r--r--app/src/main/res/layout/fragment_home_screen.xml19
-rw-r--r--app/src/main/res/layout/fragment_upload.xml13
-rw-r--r--app/src/main/res/layout/grid_item.xml33
-rw-r--r--app/src/main/res/values/strings.xml7
19 files changed, 752 insertions, 58 deletions
diff --git a/.idea/libraries/otto_1_3_5.xml b/.idea/libraries/otto_1_3_5.xml
new file mode 100644
index 0000000..8e9e540
--- /dev/null
+++ b/.idea/libraries/otto_1_3_5.xml
@@ -0,0 +1,9 @@
+<component name="libraryTable">
+ <library name="otto-1.3.5">
+ <CLASSES>
+ <root url="jar://$PROJECT_DIR$/app/libs/otto-1.3.5.jar!/" />
+ </CLASSES>
+ <JAVADOC />
+ <SOURCES />
+ </library>
+</component> \ No newline at end of file
diff --git a/.idea/misc.xml b/.idea/misc.xml
index 046b31d..71d8660 100644
--- a/.idea/misc.xml
+++ b/.idea/misc.xml
@@ -1,5 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
+ <component name="EntryPointsManager">
+ <entry_points version="2.0" />
+ </component>
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_6" assert-keyword="true" jdk-15="true" project-jdk-name="JDK" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/build/classes" />
</component>
diff --git a/app/app.iml b/app/app.iml
index f1be0f2..1576984 100644
--- a/app/app.iml
+++ b/app/app.iml
@@ -62,6 +62,7 @@
<orderEntry type="jdk" jdkName="Android API 19 Platform" jdkType="Android SDK" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" exported="" name="support-v4-19.1.0" level="project" />
+ <orderEntry type="library" exported="" name="otto-1.3.5" level="project" />
</component>
</module>
diff --git a/app/build.gradle b/app/build.gradle
index 3ef0b30..b522f85 100644
--- a/app/build.gradle
+++ b/app/build.gradle
@@ -23,4 +23,5 @@ dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
// You must install or update the Support Repository through the SDK manager to use this dependency.
compile 'com.android.support:support-v4:19.+'
+ compile files('libs/otto-1.3.5.jar')
}
diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml
index bc2ebf6..2700bb3 100644
--- a/app/src/main/AndroidManifest.xml
+++ b/app/src/main/AndroidManifest.xml
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="uk.co.blatech.blaupload" >
-
+ <uses-permission android:name="android.permission.INTERNET"/>
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
@@ -14,6 +14,9 @@
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
+ <action android:name="android.intent.action.SEND_MULTIPLE" />
+ <category android:name="android.intent.category.DEFAULT" />
+ <data android:mimeType="image/*" />
</intent-filter>
</activity>
</application>
diff --git a/app/src/main/java/uk/co/blatech/blaupload/HomeScreen.java b/app/src/main/java/uk/co/blatech/blaupload/HomeScreen.java
index 3c20697..cb280d3 100644
--- a/app/src/main/java/uk/co/blatech/blaupload/HomeScreen.java
+++ b/app/src/main/java/uk/co/blatech/blaupload/HomeScreen.java
@@ -3,24 +3,21 @@ package uk.co.blatech.blaupload;
import android.app.Activity;
import android.app.ActionBar;
-import android.app.Fragment;
import android.app.FragmentManager;
-import android.content.Context;
-import android.os.Build;
+import android.net.Uri;
import android.os.Bundle;
-import android.view.Gravity;
-import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
-import android.view.View;
-import android.view.ViewGroup;
import android.support.v4.widget.DrawerLayout;
-import android.widget.ArrayAdapter;
-import android.widget.TextView;
+/**
+ * Home screen activity class
+ * This class doesn't do much on it's own, just pulls together the HomeScreenFragment
+ * with the NavigationDrawerFragment. Mostly auto generated by Android Studio
+ */
public class HomeScreen extends Activity
- implements NavigationDrawerFragment.NavigationDrawerCallbacks {
+ implements NavigationDrawerFragment.NavigationDrawerCallbacks, UploadFragment.OnFragmentInteractionListener{
/**
* Fragment managing the behaviors, interactions and presentation of the navigation drawer.
@@ -51,9 +48,23 @@ public class HomeScreen extends Activity
public void onNavigationDrawerItemSelected(int position) {
// update the main content by replacing fragments
FragmentManager fragmentManager = getFragmentManager();
- fragmentManager.beginTransaction()
- .replace(R.id.container, PlaceholderFragment.newInstance(position + 1))
- .commit();
+ switch (position) {
+ case 0:
+ fragmentManager.beginTransaction()
+ .replace(R.id.container, HomeScreenFragment.newInstance())
+ .commit();
+ break;
+ case 1:
+ fragmentManager.beginTransaction()
+ .replace(R.id.container, UploadFragment.newInstance(null, null))
+ .commit();
+ break;
+ case 2:
+ fragmentManager.beginTransaction()
+ .replace(R.id.container, HomeScreenFragment.newInstance())
+ .commit();
+ }
+
}
public void onSectionAttached(int number) {
@@ -97,50 +108,12 @@ public class HomeScreen extends Activity
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
- if (id == R.id.action_settings) {
- return true;
- }
- return super.onOptionsItemSelected(item);
+ return id == R.id.action_settings || super.onOptionsItemSelected(item);
}
- /**
- * A placeholder fragment containing a simple view.
- */
- public static class PlaceholderFragment extends Fragment {
- /**
- * The fragment argument representing the section number for this
- * fragment.
- */
- private static final String ARG_SECTION_NUMBER = "section_number";
-
- /**
- * Returns a new instance of this fragment for the given section
- * number.
- */
- public static PlaceholderFragment newInstance(int sectionNumber) {
- PlaceholderFragment fragment = new PlaceholderFragment();
- Bundle args = new Bundle();
- args.putInt(ARG_SECTION_NUMBER, sectionNumber);
- fragment.setArguments(args);
- return fragment;
- }
-
- public PlaceholderFragment() {
- }
-
- @Override
- public View onCreateView(LayoutInflater inflater, ViewGroup container,
- Bundle savedInstanceState) {
- View rootView = inflater.inflate(R.layout.fragment_home_screen, container, false);
- return rootView;
- }
+ @Override
+ public void onFragmentInteraction(Uri uri) {
- @Override
- public void onAttach(Activity activity) {
- super.onAttach(activity);
- ((HomeScreen) activity).onSectionAttached(
- getArguments().getInt(ARG_SECTION_NUMBER));
- }
}
}
diff --git a/app/src/main/java/uk/co/blatech/blaupload/HomeScreenFragment.java b/app/src/main/java/uk/co/blatech/blaupload/HomeScreenFragment.java
new file mode 100644
index 0000000..6e6369b
--- /dev/null
+++ b/app/src/main/java/uk/co/blatech/blaupload/HomeScreenFragment.java
@@ -0,0 +1,171 @@
+package uk.co.blatech.blaupload;
+
+import android.app.Activity;
+import android.net.Uri;
+import android.os.Bundle;
+import android.app.Fragment;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.view.ViewGroup;
+import android.widget.AdapterView;
+import android.widget.GridView;
+import android.widget.Toast;
+
+import com.squareup.otto.Subscribe;
+
+import org.json.JSONArray;
+import org.json.JSONException;
+import org.json.JSONObject;
+
+import java.util.ArrayList;
+
+import uk.co.blatech.blaupload.data.ImageItem;
+import uk.co.blatech.blaupload.ui.GridViewAdapter;
+import uk.co.blatech.blaupload.util.EventBus;
+import uk.co.blatech.blaupload.util.ImageLoader;
+import uk.co.blatech.blaupload.util.ImageLoaderResultEvent;
+import uk.co.blatech.blaupload.util.JSONLoader;
+import uk.co.blatech.blaupload.util.JSONLoaderResultEvent;
+
+
+/**
+ * A simple {@link Fragment} subclass.
+ * This is the main part of the home screen.
+ * Currently it displays the 9 most recent files from blaupload in a grid
+ *
+ */
+public class HomeScreenFragment extends Fragment {
+
+ private OnFragmentInteractionListener mListener;
+ private ArrayList<ImageItem> thumbnails;
+ private GridViewAdapter gridAdapter;
+ private GridView gridView;
+ /**
+ * Returns a new instance of this fragment
+ */
+ public static HomeScreenFragment newInstance() {
+ HomeScreenFragment fragment = new HomeScreenFragment();
+ Bundle args = new Bundle();
+ fragment.setArguments(args);
+ return fragment;
+ }
+
+ public HomeScreenFragment() {
+ }
+
+ @Override
+ public View onCreateView(LayoutInflater inflater, ViewGroup container,
+ Bundle savedInstanceState) {
+
+ View rootView = inflater.inflate(R.layout.fragment_home_screen, container, false);
+ EventBus.getInstance().register(this);
+ gridView = (GridView) rootView.findViewById(R.id.gridView);
+
+ return rootView;
+ }
+
+ @Override
+ public void onActivityCreated(Bundle savedInstanceState)
+ {
+ super.onCreate(savedInstanceState);
+ thumbnails = new ArrayList<ImageItem>();
+ gridAdapter =
+ new GridViewAdapter(getActivity(), R.layout.grid_item, thumbnails);
+ gridView.setAdapter(gridAdapter);
+
+ //Display a message when an item is clicked
+ //TODO: Make it display the full image
+ gridView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
+ public void onItemClick(AdapterView<?> parent, View v,
+ int position, long id) {
+ Toast.makeText(getActivity(), "Clicked image #"+position, Toast.LENGTH_SHORT).show();
+
+ }
+
+ });
+ }
+
+ @Override
+ public void onAttach(Activity activity) {
+ super.onAttach(activity);
+
+ //Start loading the JSON file list in a thread as soon as we start
+ new JSONLoader().execute("http://www.blaupload.co.uk/?format=json&last=9");
+
+ }
+
+
+ @Override
+ public void onDetach() {
+ super.onDetach();
+ mListener = null;
+ }
+
+
+ /**
+ * This interface must be implemented by activities that contain this
+ * fragment to allow an interaction in this fragment to be communicated
+ * to the activity and potentially other fragments contained in that
+ * activity.
+ * <p>
+ * See the Android Training lesson <a href=
+ * "http://developer.android.com/training/basics/fragments/communicating.html"
+ * >Communicating with Other Fragments</a> for more information.
+ */
+ public interface OnFragmentInteractionListener {
+ // TODO: Update argument type and name
+ public void onFragmentInteraction(Uri uri);
+ }
+
+ /**
+ * This function is called when the JSONLoader thread finishes
+ * It processes the JSON and then starts loading the image thumbnails
+ * @param event Event containing the JSONArray of files
+ */
+ @Subscribe
+ public void onAsyncTaskResult(JSONLoaderResultEvent event) {
+
+ JSONArray json = event.getResult();
+ ArrayList<String> filenames = new ArrayList<String>();
+
+ if (json != null) {
+
+ try {
+ // Get the filename out of each JSON item
+ for (int i = 0; i < json.length(); i++) {
+ JSONObject item = json.getJSONObject(i);
+ filenames.add(item.getString("filename"));
+
+ }
+ } catch (JSONException e) {
+ //TODO: Error handling
+ e.printStackTrace();
+ }
+
+
+ //Load the thumbnail for each item on a thread
+ int id = 0;
+ for (String filename : filenames) {
+ new ImageLoader(getResources()).execute("http://www.lc8n.com/blathumbs/", filename, String.valueOf(id));
+ id++;
+ }
+
+
+ }
+ }
+
+ /**
+ * This function is called when an ImageLoader thread finishes
+ * It puts the image into the grid
+ * @param event Event containing an ImageItem with a bitmap and image details
+ */
+ @Subscribe
+ public void onAsyncTaskResult(ImageLoaderResultEvent event) {
+
+ ImageItem image = event.getResult();
+ thumbnails.add(image.getId(), image);
+ gridAdapter.notifyDataSetChanged();
+
+ }
+
+}
diff --git a/app/src/main/java/uk/co/blatech/blaupload/UploadFragment.java b/app/src/main/java/uk/co/blatech/blaupload/UploadFragment.java
new file mode 100644
index 0000000..7ef458c
--- /dev/null
+++ b/app/src/main/java/uk/co/blatech/blaupload/UploadFragment.java
@@ -0,0 +1,118 @@
+package uk.co.blatech.blaupload;
+
+import android.app.Activity;
+import android.content.Intent;
+import android.net.Uri;
+import android.os.Bundle;
+import android.app.Fragment;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.view.ViewGroup;
+
+
+
+/**
+ * A simple {@link Fragment} subclass.
+ * Activities that contain this fragment must implement the
+ * {@link UploadFragment.OnFragmentInteractionListener} interface
+ * to handle interaction events.
+ * Use the {@link UploadFragment#newInstance} factory method to
+ * create an instance of this fragment.
+ *
+ * Currently just auto generated code from Android Studio
+ * TODO: Add the upload screen
+ *
+ */
+public class UploadFragment extends Fragment {
+ // TODO: Rename parameter arguments, choose names that match
+ // the fragment initialization parameters, e.g. ARG_ITEM_NUMBER
+ private static final String ARG_PARAM1 = "param1";
+ private static final String ARG_PARAM2 = "param2";
+
+ // TODO: Rename and change types of parameters
+ private String mParam1;
+ private String mParam2;
+
+ private OnFragmentInteractionListener mListener;
+
+ /**
+ * Use this factory method to create a new instance of
+ * this fragment using the provided parameters.
+ *
+ * @param param1 Parameter 1.
+ * @param param2 Parameter 2.
+ * @return A new instance of fragment UploadFragment.
+ */
+ // TODO: Rename and change types and number of parameters
+ public static UploadFragment newInstance(String param1, String param2) {
+ UploadFragment fragment = new UploadFragment();
+ Bundle args = new Bundle();
+ args.putString(ARG_PARAM1, param1);
+ args.putString(ARG_PARAM2, param2);
+ fragment.setArguments(args);
+ return fragment;
+ }
+ public UploadFragment() {
+ // Required empty public constructor
+ }
+
+ @Override
+ public void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ if (getArguments() != null) {
+ mParam1 = getArguments().getString(ARG_PARAM1);
+ mParam2 = getArguments().getString(ARG_PARAM2);
+ }
+ Intent photoPickerIntent = new Intent(Intent.ACTION_PICK);
+ photoPickerIntent.setType("image/*");
+ photoPickerIntent.putExtra(Intent.EXTRA_ALLOW_MULTIPLE, true);
+ startActivityForResult(photoPickerIntent, 1);
+ }
+
+ @Override
+ public View onCreateView(LayoutInflater inflater, ViewGroup container,
+ Bundle savedInstanceState) {
+ // Inflate the layout for this fragment
+ return inflater.inflate(R.layout.fragment_upload, container, false);
+ }
+
+ // TODO: Rename method, update argument and hook method into UI event
+ public void onButtonPressed(Uri uri) {
+ if (mListener != null) {
+ mListener.onFragmentInteraction(uri);
+ }
+ }
+
+ @Override
+ public void onAttach(Activity activity) {
+ super.onAttach(activity);
+ try {
+ mListener = (OnFragmentInteractionListener) activity;
+ } catch (ClassCastException e) {
+ throw new ClassCastException(activity.toString()
+ + " must implement OnFragmentInteractionListener");
+ }
+ }
+
+ @Override
+ public void onDetach() {
+ super.onDetach();
+ mListener = null;
+ }
+
+ /**
+ * This interface must be implemented by activities that contain this
+ * fragment to allow an interaction in this fragment to be communicated
+ * to the activity and potentially other fragments contained in that
+ * activity.
+ * <p>
+ * See the Android Training lesson <a href=
+ * "http://developer.android.com/training/basics/fragments/communicating.html"
+ * >Communicating with Other Fragments</a> for more information.
+ */
+ public interface OnFragmentInteractionListener {
+ // TODO: Update argument type and name
+ public void onFragmentInteraction(Uri uri);
+ }
+
+}
diff --git a/app/src/main/java/uk/co/blatech/blaupload/data/ImageItem.java b/app/src/main/java/uk/co/blatech/blaupload/data/ImageItem.java
new file mode 100644
index 0000000..928101d
--- /dev/null
+++ b/app/src/main/java/uk/co/blatech/blaupload/data/ImageItem.java
@@ -0,0 +1,46 @@
+package uk.co.blatech.blaupload.data;
+
+import android.graphics.Bitmap;
+
+/**
+ * Simple object to store images with extra details
+ * ID is used in the UI for ordering things
+ *
+ */
+public class ImageItem {
+
+ private int id;
+ private Bitmap image;
+ private String title;
+
+ public ImageItem(int id, Bitmap image, String title) {
+ super();
+ this.id = id;
+ this.image = image;
+ this.title = title;
+ }
+
+ public Bitmap getImage() {
+ return image;
+ }
+
+ public void setImage(Bitmap image) {
+ this.image = image;
+ }
+
+ public String getTitle() {
+ return title;
+ }
+
+ public void setTitle(String title) {
+ this.title = title;
+ }
+
+ public int getId() {
+ return id;
+ }
+
+ public void setId(int id) {
+ this.id = id;
+ }
+} \ No newline at end of file
diff --git a/app/src/main/java/uk/co/blatech/blaupload/ui/GridViewAdapter.java b/app/src/main/java/uk/co/blatech/blaupload/ui/GridViewAdapter.java
new file mode 100644
index 0000000..d22b74b
--- /dev/null
+++ b/app/src/main/java/uk/co/blatech/blaupload/ui/GridViewAdapter.java
@@ -0,0 +1,56 @@
+package uk.co.blatech.blaupload.ui;
+
+
+import java.util.ArrayList;
+import android.app.Activity;
+import android.content.Context;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.view.ViewGroup;
+import android.widget.ArrayAdapter;
+import android.widget.ImageView;
+import android.widget.TextView;
+
+import uk.co.blatech.blaupload.R;
+import uk.co.blatech.blaupload.data.ImageItem;
+
+public class GridViewAdapter extends ArrayAdapter {
+ private Context context;
+ private int layoutResourceId;
+ private ArrayList data = new ArrayList();
+
+ public GridViewAdapter(Context context, int layoutResourceId,
+ ArrayList data) {
+ super(context, layoutResourceId, data);
+ this.layoutResourceId = layoutResourceId;
+ this.context = context;
+ this.data = data;
+ }
+
+ @Override
+ public View getView(int position, View convertView, ViewGroup parent) {
+ View row = convertView;
+ ViewHolder holder;
+
+ if (row == null) {
+ LayoutInflater inflater = ((Activity) context).getLayoutInflater();
+ row = inflater.inflate(layoutResourceId, parent, false);
+ holder = new ViewHolder();
+ holder.imageTitle = (TextView) row.findViewById(R.id.thumbtitle);
+ holder.image = (ImageView) row.findViewById(R.id.thumbimage);
+ row.setTag(holder);
+ } else {
+ holder = (ViewHolder) row.getTag();
+ }
+
+ ImageItem item = (ImageItem) data.get(position);
+ holder.imageTitle.setText(item.getTitle());
+ holder.image.setImageBitmap(item.getImage());
+ return row;
+ }
+
+ static class ViewHolder {
+ TextView imageTitle;
+ ImageView image;
+ }
+} \ No newline at end of file
diff --git a/app/src/main/java/uk/co/blatech/blaupload/util/EventBus.java b/app/src/main/java/uk/co/blatech/blaupload/util/EventBus.java
new file mode 100644
index 0000000..073a6a3
--- /dev/null
+++ b/app/src/main/java/uk/co/blatech/blaupload/util/EventBus.java
@@ -0,0 +1,17 @@
+package uk.co.blatech.blaupload.util;
+
+import com.squareup.otto.Bus;
+
+/**
+ * Simple class for sending messages between threads using the Otto library
+ *
+ * Created by joe on 03/08/14.
+ */
+public class EventBus {
+
+ private static final Bus BUS = new Bus();
+
+ public static Bus getInstance() {
+ return BUS;
+ }
+}
diff --git a/app/src/main/java/uk/co/blatech/blaupload/util/ImageLoader.java b/app/src/main/java/uk/co/blatech/blaupload/util/ImageLoader.java
new file mode 100644
index 0000000..9af9a26
--- /dev/null
+++ b/app/src/main/java/uk/co/blatech/blaupload/util/ImageLoader.java
@@ -0,0 +1,95 @@
+package uk.co.blatech.blaupload.util;
+
+import android.content.res.Resources;
+import android.graphics.Bitmap;
+import android.graphics.BitmapFactory;
+import android.os.AsyncTask;
+
+import org.apache.http.HttpEntity;
+import org.apache.http.HttpResponse;
+import org.apache.http.StatusLine;
+import org.apache.http.client.ClientProtocolException;
+import org.apache.http.client.methods.HttpGet;
+import org.apache.http.impl.client.DefaultHttpClient;
+import org.apache.http.util.EntityUtils;
+
+import java.io.IOException;
+
+import uk.co.blatech.blaupload.R;
+import uk.co.blatech.blaupload.data.ImageItem;
+
+/**
+ * This class is used for loading images in the background
+ *
+ * Created by joe on 02/08/14.
+ */
+public class ImageLoader extends AsyncTask<String, Void, ImageItem> {
+
+ private Resources res;
+
+ //Get the resources object from the UI thread so we can load a placeholder image
+ public ImageLoader(Resources resources) {
+ this.res = resources;
+ }
+
+ /**
+ *
+ * @param args host, filename, id
+ * host - the hostname to download from, eg http://www.blaupload.co.uk
+ * filename - the filename with no path, eg image.jpg
+ * id - the ID of the image used by the UI to order the images
+ *
+ * TODO: Some generic way of adding the suffix used for thumbnails
+ *
+ * @return an ImageItem object which contains the ID, a Bitmap image object, and the filename
+ */
+ @Override
+ protected ImageItem doInBackground(String... args) {
+
+ Bitmap bmp = null;
+ String host = args[0];
+ String filename = args[1];
+ int id = Integer.parseInt(args[2]);
+
+ //Add an extra .png on the end to match the current thumbnail filenames
+ String url = host + filename + ".png";
+
+ DefaultHttpClient client = new DefaultHttpClient();
+ HttpGet httpGet = new HttpGet(url);
+
+
+ try {
+ HttpResponse response = client.execute(httpGet);
+ StatusLine statusLine = response.getStatusLine();
+ int statusCode = statusLine.getStatusCode();
+
+ //Create the Bitmap if the file exists
+ if (statusCode == 200) {
+ // If the thumbnail wasn't found, show a placeholder
+ HttpEntity entity = response.getEntity();
+ byte[] bytes = EntityUtils.toByteArray(entity);
+ bmp = BitmapFactory.decodeByteArray(bytes, 0, bytes.length);
+ } else {
+ //If the file doesn't exist, use the placeholder instead
+ bmp = BitmapFactory.decodeResource(res, R.drawable.x);
+
+ }
+
+ //TODO: Error handling (Not sure how we get here)
+ } catch (ClientProtocolException e) {
+ e.printStackTrace();
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+
+ ImageItem image = new ImageItem(id, bmp, filename);
+ return image;
+ }
+
+ @Override
+ protected void onPostExecute(ImageItem result) {
+ EventBus.getInstance().post(new ImageLoaderResultEvent(result));
+
+ }
+
+}
diff --git a/app/src/main/java/uk/co/blatech/blaupload/util/ImageLoaderResultEvent.java b/app/src/main/java/uk/co/blatech/blaupload/util/ImageLoaderResultEvent.java
new file mode 100644
index 0000000..31acc6c
--- /dev/null
+++ b/app/src/main/java/uk/co/blatech/blaupload/util/ImageLoaderResultEvent.java
@@ -0,0 +1,16 @@
+package uk.co.blatech.blaupload.util;
+
+import uk.co.blatech.blaupload.data.ImageItem;
+
+public class ImageLoaderResultEvent {
+
+ private ImageItem result;
+
+ public ImageLoaderResultEvent(ImageItem result) {
+ this.result = result;
+ }
+
+ public ImageItem getResult() {
+ return result;
+ }
+}
diff --git a/app/src/main/java/uk/co/blatech/blaupload/util/JSONLoader.java b/app/src/main/java/uk/co/blatech/blaupload/util/JSONLoader.java
new file mode 100644
index 0000000..028202a
--- /dev/null
+++ b/app/src/main/java/uk/co/blatech/blaupload/util/JSONLoader.java
@@ -0,0 +1,103 @@
+package uk.co.blatech.blaupload.util;
+
+import android.os.AsyncTask;
+import android.util.Log;
+
+import org.apache.http.HttpEntity;
+import org.apache.http.HttpResponse;
+import org.apache.http.StatusLine;
+import org.apache.http.client.ClientProtocolException;
+import org.apache.http.client.CookieStore;
+import org.apache.http.client.methods.HttpGet;
+import org.apache.http.impl.client.BasicCookieStore;
+import org.apache.http.impl.client.DefaultHttpClient;
+import org.apache.http.impl.cookie.BasicClientCookie;
+import org.json.JSONArray;
+import org.json.JSONException;
+
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+
+
+/**
+ * This class is used for loading a JSON array from a given URL
+ *
+ * TODO: Make the cookie stuff generic
+ * Created by joe on 02/08/14.
+ */
+public class JSONLoader extends AsyncTask<String, Void, JSONArray> {
+
+ private String url;
+
+
+ /**
+ *
+ * @param url - The URL to load JSON from
+ * @return JSONArray of data from the URL
+ */
+ @Override
+ protected JSONArray doInBackground(String... url) {
+
+ this.url = url[0];
+ String jsonText = readJSON();
+ JSONArray json = null;
+ try {
+ json = new JSONArray(jsonText);
+ } catch (JSONException e) {
+ //TODO: Error handling if we got something other than JSON
+ Log.e(JSONLoader.class.toString(), "Failed to parse JSON");
+ e.printStackTrace();
+ }
+ return json;
+ }
+
+ private String readJSON() {
+
+ StringBuilder builder = new StringBuilder();
+ DefaultHttpClient client = new DefaultHttpClient();
+ CookieStore cookieStore = new BasicCookieStore();
+ //TODO: Don't hard code the cookie.
+ BasicClientCookie cookie = new BasicClientCookie("password", "PASSWORDHASHHERE");
+ cookie.setDomain(".blaupload.co.uk");
+ cookie.setPath("/");
+ cookieStore.addCookie(cookie);
+ client.setCookieStore(cookieStore);
+
+ HttpGet httpGet = new HttpGet(url);
+
+ try {
+ //Read the JSON from the URL
+ HttpResponse response = client.execute(httpGet);
+ StatusLine statusLine = response.getStatusLine();
+ int statusCode = statusLine.getStatusCode();
+ if (statusCode == 200) {
+ HttpEntity entity = response.getEntity();
+ InputStream content = entity.getContent();
+ BufferedReader reader = new BufferedReader(new InputStreamReader(content));
+ String line;
+ while ((line = reader.readLine()) != null) {
+ builder.append(line);
+ }
+ } else {
+ //TODO: Error handling if there's no JSON there
+ Log.e(JSONLoader.class.toString(), "Failed to download file");
+ }
+ } catch (ClientProtocolException e) {
+ e.printStackTrace();
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ return builder.toString();
+ }
+
+ @Override
+ protected void onPostExecute(JSONArray result) {
+ EventBus.getInstance().post(new JSONLoaderResultEvent(result));
+
+ }
+
+
+}
+
diff --git a/app/src/main/java/uk/co/blatech/blaupload/util/JSONLoaderResultEvent.java b/app/src/main/java/uk/co/blatech/blaupload/util/JSONLoaderResultEvent.java
new file mode 100644
index 0000000..fd2af3a
--- /dev/null
+++ b/app/src/main/java/uk/co/blatech/blaupload/util/JSONLoaderResultEvent.java
@@ -0,0 +1,16 @@
+package uk.co.blatech.blaupload.util;
+
+import org.json.JSONArray;
+
+public class JSONLoaderResultEvent {
+
+ private JSONArray result;
+
+ public JSONLoaderResultEvent(JSONArray result) {
+ this.result = result;
+ }
+
+ public JSONArray getResult() {
+ return result;
+ }
+}
diff --git a/app/src/main/res/layout/fragment_home_screen.xml b/app/src/main/res/layout/fragment_home_screen.xml
index 3f50a40..884e98a 100644
--- a/app/src/main/res/layout/fragment_home_screen.xml
+++ b/app/src/main/res/layout/fragment_home_screen.xml
@@ -13,4 +13,23 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
+ <TextView
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:textAppearance="@android:style/TextAppearance.DeviceDefault.Medium"
+ android:text="Recent Images"
+ android:id="@+id/textView"
+ android:layout_alignParentTop="true"
+ android:layout_alignParentLeft="true"
+ android:layout_alignParentStart="true" />
+
+ <GridView
+ android:layout_width="fill_parent"
+ android:layout_height="fill_parent"
+ android:numColumns="3"
+ android:id="@+id/gridView"
+ android:layout_below="@+id/section_label"
+ android:layout_alignParentLeft="true"
+ android:layout_alignParentStart="true" />
+
</RelativeLayout>
diff --git a/app/src/main/res/layout/fragment_upload.xml b/app/src/main/res/layout/fragment_upload.xml
new file mode 100644
index 0000000..01fe6e8
--- /dev/null
+++ b/app/src/main/res/layout/fragment_upload.xml
@@ -0,0 +1,13 @@
+<FrameLayout 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="uk.co.blatech.blaupload.UploadFragment">
+
+ <!-- TODO: Update blank fragment layout -->
+ <TextView
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"
+ android:text="@string/hello_blank_fragment" />
+
+</FrameLayout>
diff --git a/app/src/main/res/layout/grid_item.xml b/app/src/main/res/layout/grid_item.xml
new file mode 100644
index 0000000..1d8b860
--- /dev/null
+++ b/app/src/main/res/layout/grid_item.xml
@@ -0,0 +1,33 @@
+<?xml version="1.0" encoding="utf-8"?>
+
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+ xmlns:tools="http://schemas.android.com/tools"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_marginTop="5dp"
+ android:orientation="vertical"
+ android:padding="5dp"
+ android:clickable="false"
+ android:focusable="false">
+
+ <ImageView
+ android:id="@+id/thumbimage"
+ android:layout_width="100dp"
+ android:layout_height="100dp"
+ android:clickable="false"
+ android:focusable="false"
+ android:focusableInTouchMode="false">
+ </ImageView>
+
+ <TextView
+ android:id="@+id/thumbtitle"
+ android:layout_width="fill_parent"
+ android:layout_height="wrap_content"
+ android:layout_marginTop="5dp"
+ android:gravity="center"
+ android:textSize="12sp"
+ android:clickable="false"
+ android:focusable="false">
+ </TextView>
+
+</LinearLayout> \ No newline at end of file
diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml
index edcacd6..25d7732 100644
--- a/app/src/main/res/values/strings.xml
+++ b/app/src/main/res/values/strings.xml
@@ -2,12 +2,13 @@
<resources>
<string name="app_name">blaupload</string>
- <string name="title_section1">Section 1</string>
- <string name="title_section2">Section 2</string>
- <string name="title_section3">Section 3</string>
+ <string name="title_section1">Images</string>
+ <string name="title_section2">Upload</string>
+ <string name="title_section3">Locate</string>
<string name="navigation_drawer_open">Open navigation drawer</string>
<string name="navigation_drawer_close">Close navigation drawer</string>
<string name="action_example">Example action</string>
<string name="action_settings">Settings</string>
+ <string name="hello_blank_fragment">Hello blank fragment</string>
</resources>