package uk.co.blatech.blaupload; import android.app.Application; import com.nostra13.universalimageloader.core.ImageLoader; import com.nostra13.universalimageloader.core.ImageLoaderConfiguration; public class BlauploadApplication extends Application { @Override public void onCreate() { super.onCreate(); ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder(getApplicationContext()).build(); ImageLoader.getInstance().init(config); } }X-Content-Type-Options: nosniff Content-Security-Policy: default-src 'none' Content-Type: text/plain; charset=UTF-8 Content-Length: 3983 Content-Disposition: inline; filename="HomeScreen.java" Last-Modified: Thu, 14 Nov 2024 16:25:57 GMT Expires: Thu, 14 Nov 2024 16:30:57 GMT ETag: "cb280d34fb13a7c1a1cbd2668a85375084d41cb4" package uk.co.blatech.blaupload; import android.app.Activity; import android.app.ActionBar; import android.app.FragmentManager; import android.net.Uri; import android.os.Bundle; import android.view.Menu; import android.view.MenuItem; import android.support.v4.widget.DrawerLayout; /** * 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, UploadFragment.OnFragmentInteractionListener{ /** * Fragment managing the behaviors, interactions and presentation of the navigation drawer. */ private NavigationDrawerFragment mNavigationDrawerFragment; /** * Used to store the last screen title. For use in {@link #restoreActionBar()}. */ private CharSequence mTitle; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_home_screen); mNavigationDrawerFragment = (NavigationDrawerFragment) getFragmentManager().findFragmentById(R.id.navigation_drawer); mTitle = getTitle(); // Set up the drawer. mNavigationDrawerFragment.setUp( R.id.navigation_drawer, (DrawerLayout) findViewById(R.id.drawer_layout)); } @Override public void onNavigationDrawerItemSelected(int position) { // update the main content by replacing fragments FragmentManager fragmentManager = getFragmentManager(); 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) { switch (number) { case 1: mTitle = getString(R.string.title_section1); break; case 2: mTitle = getString(R.string.title_section2); break; case 3: mTitle = getString(R.string.title_section3); break; } } public void restoreActionBar() { ActionBar actionBar = getActionBar(); actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_STANDARD); actionBar.setDisplayShowTitleEnabled(true); actionBar.setTitle(mTitle); } @Override public boolean onCreateOptionsMenu(Menu menu) { if (!mNavigationDrawerFragment.isDrawerOpen()) { // Only show items in the action bar relevant to this screen // if the drawer is not showing. Otherwise, let the drawer // decide what to show in the action bar. getMenuInflater().inflate(R.menu.home_screen, menu); restoreActionBar(); return true; } return super.onCreateOptionsMenu(menu); } @Override public boolean onOptionsItemSelected(MenuItem item) { // Handle action bar item clicks here. The action bar will // automatically handle clicks on the Home/Up button, so long // as you specify a parent activity in AndroidManifest.xml. int id = item.getItemId(); return id == R.id.action_settings || super.onOptionsItemSelected(item); } @Override public void onFragmentInteraction(Uri uri) { } } X-Content-Type-Options: nosniff Content-Security-Policy: default-src 'none' Content-Type: text/plain; charset=UTF-8 Content-Length: 5537 Content-Disposition: inline; filename="HomeScreenFragment.java" Last-Modified: Thu, 14 Nov 2024 16:25:57 GMT Expires: Thu, 14 Nov 2024 16:30:57 GMT ETag: "88ed453af1702788e57c3b5e900583b4c37d9833" 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; 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.BlaImageLoader; import uk.co.blatech.blaupload.util.EventBus; 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 thumbnails; private GridViewAdapter gridAdapter; private GridView gridView; private ArrayList filenames; private JSONArray json; /** * 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(); gridAdapter = new GridViewAdapter(getActivity(), R.layout.grid_item, thumbnails); gridView.setAdapter(gridAdapter); filenames = new ArrayList(); //Open the full image in a pager when clicked 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(); Intent mIntent = new Intent(getActivity(), ImagePager.class); mIntent.putExtra("json", json.toString()); mIntent.putExtra("position", position); startActivity(mIntent); } }); } @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=6"); } @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. *

* See the Android Training lesson Communicating with Other Fragments 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) { json = event.getResult(); 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 BlaImageLoader(getResources()).execute("http://www.lc8n.com/bla100/", 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(); } } X-Content-Type-Options: nosniff Content-Security-Policy: default-src 'none' Content-Type: text/plain; charset=UTF-8 Content-Length: 2572 Content-Disposition: inline; filename="ImagePager.java" Last-Modified: Thu, 14 Nov 2024 16:25:57 GMT Expires: Thu, 14 Nov 2024 16:30:57 GMT ETag: "f562e2f4ada4f9a2ce9fc3ab254e396a98e46be3" package uk.co.blatech.blaupload; import android.app.Activity; import android.os.Bundle; import android.util.Log; import android.view.Menu; import android.view.MenuItem; import com.nostra13.universalimageloader.core.ImageLoader; import com.nostra13.universalimageloader.core.ImageLoaderConfiguration; import org.json.JSONArray; import org.json.JSONException; import org.json.JSONObject; import java.util.ArrayList; import uk.co.blatech.blaupload.ui.ImagePagerAdapter; import uk.co.blatech.blaupload.ui.ZoomViewPager; import uk.co.blatech.blaupload.util.EventBus; public class ImagePager extends Activity { private ZoomViewPager mViewPager; private JSONArray json; private ArrayList urls; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_image_pager); mViewPager = (ZoomViewPager) findViewById(R.id.imagePager); EventBus.getInstance().register(this); urls = new ArrayList(); String jsonText = getIntent().getStringExtra("json"); int id = getIntent().getIntExtra("position", 0); try { json = new JSONArray(jsonText); } catch (JSONException e) { //TODO: Error handling if we got something other than JSON Log.e(ImagePager.class.toString(), "Failed to parse JSON"); e.printStackTrace(); } for (int i = 0; i < json.length(); i++) { try { JSONObject item = json.getJSONObject(i); urls.add("http://www.lc8n.com/bla500/"+item.getString("filename")); } catch (JSONException e) { e.printStackTrace(); } } ImagePagerAdapter adapter = new ImagePagerAdapter(ImagePager.this, urls); mViewPager.setAdapter(adapter); } @Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.image_pager, menu); return true; } @Override public boolean onOptionsItemSelected(MenuItem item) { // Handle action bar item clicks here. The action bar will // 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); } } X-Content-Type-Options: nosniff Content-Security-Policy: default-src 'none' Content-Type: text/plain; charset=UTF-8 Content-Length: 10603 Content-Disposition: inline; filename="NavigationDrawerFragment.java" Last-Modified: Thu, 14 Nov 2024 16:25:57 GMT Expires: Thu, 14 Nov 2024 16:30:57 GMT ETag: "b86dfa3e5d7f1b41f2092a81960100aea3e397d1" package uk.co.blatech.blaupload; import android.app.Activity; import android.app.ActionBar; import android.app.Fragment; import android.support.v4.app.ActionBarDrawerToggle; import android.support.v4.view.GravityCompat; import android.support.v4.widget.DrawerLayout; import android.content.SharedPreferences; import android.content.res.Configuration; import android.os.Bundle; import android.preference.PreferenceManager; import android.view.LayoutInflater; import android.view.Menu; import android.view.MenuInflater; import android.view.MenuItem; import android.view.View; import android.view.ViewGroup; import android.widget.AdapterView; import android.widget.ArrayAdapter; import android.widget.ListView; import android.widget.Toast; /** * Fragment used for managing interactions for and presentation of a navigation drawer. * See the * design guidelines for a complete explanation of the behaviors implemented here. */ public class NavigationDrawerFragment extends Fragment { /** * Remember the position of the selected item. */ private static final String STATE_SELECTED_POSITION = "selected_navigation_drawer_position"; /** * Per the design guidelines, you should show the drawer on launch until the user manually * expands it. This shared preference tracks this. */ private static final String PREF_USER_LEARNED_DRAWER = "navigation_drawer_learned"; /** * A pointer to the current callbacks instance (the Activity). */ private NavigationDrawerCallbacks mCallbacks; /** * Helper component that ties the action bar to the navigation drawer. */ private ActionBarDrawerToggle mDrawerToggle; private DrawerLayout mDrawerLayout; private ListView mDrawerListView; private View mFragmentContainerView; private int mCurrentSelectedPosition = 0; private boolean mFromSavedInstanceState; private boolean mUserLearnedDrawer; public NavigationDrawerFragment() { } @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // Read in the flag indicating whether or not the user has demonstrated awareness of the // drawer. See PREF_USER_LEARNED_DRAWER for details. SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(getActivity()); mUserLearnedDrawer = sp.getBoolean(PREF_USER_LEARNED_DRAWER, false); if (savedInstanceState != null) { mCurrentSelectedPosition = savedInstanceState.getInt(STATE_SELECTED_POSITION); mFromSavedInstanceState = true; } // Select either the default item (0) or the last selected item. selectItem(mCurrentSelectedPosition); } @Override public void onActivityCreated (Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); // Indicate that this fragment would like to influence the set of actions in the action bar. setHasOptionsMenu(true); } @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { mDrawerListView = (ListView) inflater.inflate( R.layout.fragment_navigation_drawer, container, false); mDrawerListView.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView parent, View view, int position, long id) { selectItem(position); } }); mDrawerListView.setAdapter(new ArrayAdapter( getActionBar().getThemedContext(), android.R.layout.simple_list_item_activated_1, android.R.id.text1, new String[]{ getString(R.string.title_section1), getString(R.string.title_section2), getString(R.string.title_section3), })); mDrawerListView.setItemChecked(mCurrentSelectedPosition, true); return mDrawerListView; } public boolean isDrawerOpen() { return mDrawerLayout != null && mDrawerLayout.isDrawerOpen(mFragmentContainerView); } /** * Users of this fragment must call this method to set up the navigation drawer interactions. * * @param fragmentId The android:id of this fragment in its activity's layout. * @param drawerLayout The DrawerLayout containing this fragment's UI. */ public void setUp(int fragmentId, DrawerLayout drawerLayout) { mFragmentContainerView = getActivity().findViewById(fragmentId); mDrawerLayout = drawerLayout; // set a custom shadow that overlays the main content when the drawer opens mDrawerLayout.setDrawerShadow(R.drawable.drawer_shadow, GravityCompat.START); // set up the drawer's list view with items and click listener ActionBar actionBar = getActionBar(); actionBar.setDisplayHomeAsUpEnabled(true); actionBar.setHomeButtonEnabled(true); // ActionBarDrawerToggle ties together the the proper interactions // between the navigation drawer and the action bar app icon. mDrawerToggle = new ActionBarDrawerToggle( getActivity(), /* host Activity */ mDrawerLayout, /* DrawerLayout object */ R.drawable.ic_drawer, /* nav drawer image to replace 'Up' caret */ R.string.navigation_drawer_open, /* "open drawer" description for accessibility */ R.string.navigation_drawer_close /* "close drawer" description for accessibility */ ) { @Override public void onDrawerClosed(View drawerView) { super.onDrawerClosed(drawerView); if (!isAdded()) { return; } getActivity().invalidateOptionsMenu(); // calls onPrepareOptionsMenu() } @Override public void onDrawerOpened(View drawerView) { super.onDrawerOpened(drawerView); if (!isAdded()) { return; } if (!mUserLearnedDrawer) { // The user manually opened the drawer; store this flag to prevent auto-showing // the navigation drawer automatically in the future. mUserLearnedDrawer = true; SharedPreferences sp = PreferenceManager .getDefaultSharedPreferences(getActivity()); sp.edit().putBoolean(PREF_USER_LEARNED_DRAWER, true).apply(); } getActivity().invalidateOptionsMenu(); // calls onPrepareOptionsMenu() } }; // If the user hasn't 'learned' about the drawer, open it to introduce them to the drawer, // per the navigation drawer design guidelines. if (!mUserLearnedDrawer && !mFromSavedInstanceState) { mDrawerLayout.openDrawer(mFragmentContainerView); } // Defer code dependent on restoration of previous instance state. mDrawerLayout.post(new Runnable() { @Override public void run() { mDrawerToggle.syncState(); } }); mDrawerLayout.setDrawerListener(mDrawerToggle); } private void selectItem(int position) { mCurrentSelectedPosition = position; if (mDrawerListView != null) { mDrawerListView.setItemChecked(position, true); } if (mDrawerLayout != null) { mDrawerLayout.closeDrawer(mFragmentContainerView); } if (mCallbacks != null) { mCallbacks.onNavigationDrawerItemSelected(position); } } @Override public void onAttach(Activity activity) { super.onAttach(activity); try { mCallbacks = (NavigationDrawerCallbacks) activity; } catch (ClassCastException e) { throw new ClassCastException("Activity must implement NavigationDrawerCallbacks."); } } @Override public void onDetach() { super.onDetach(); mCallbacks = null; } @Override public void onSaveInstanceState(Bundle outState) { super.onSaveInstanceState(outState); outState.putInt(STATE_SELECTED_POSITION, mCurrentSelectedPosition); } @Override public void onConfigurationChanged(Configuration newConfig) { super.onConfigurationChanged(newConfig); // Forward the new configuration the drawer toggle component. mDrawerToggle.onConfigurationChanged(newConfig); } @Override public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { // If the drawer is open, show the global app actions in the action bar. See also // showGlobalContextActionBar, which controls the top-left area of the action bar. if (mDrawerLayout != null && isDrawerOpen()) { inflater.inflate(R.menu.global, menu); showGlobalContextActionBar(); } super.onCreateOptionsMenu(menu, inflater); } @Override public boolean onOptionsItemSelected(MenuItem item) { if (mDrawerToggle.onOptionsItemSelected(item)) { return true; } if (item.getItemId() == R.id.action_example) { Toast.makeText(getActivity(), "Example action.", Toast.LENGTH_SHORT).show(); return true; } return super.onOptionsItemSelected(item); } /** * Per the navigation drawer design guidelines, updates the action bar to show the global app * 'context', rather than just what's in the current screen. */ private void showGlobalContextActionBar() { ActionBar actionBar = getActionBar(); actionBar.setDisplayShowTitleEnabled(true); actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_STANDARD); actionBar.setTitle(R.string.app_name); } private ActionBar getActionBar() { return getActivity().getActionBar(); } /** * Callbacks interface that all activities using this fragment must implement. */ public static interface NavigationDrawerCallbacks { /** * Called when an item in the navigation drawer is selected. */ void onNavigationDrawerItemSelected(int position); } } X-Content-Type-Options: nosniff Content-Security-Policy: default-src 'none' Content-Type: text/plain; charset=UTF-8 Content-Length: 3972 Content-Disposition: inline; filename="UploadFragment.java" Last-Modified: Thu, 14 Nov 2024 16:25:57 GMT Expires: Thu, 14 Nov 2024 16:30:57 GMT ETag: "7ef458c11204f47355239af1081c67c6dd9d3bc1" 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. *

* See the Android Training lesson Communicating with Other Fragments for more information. */ public interface OnFragmentInteractionListener { // TODO: Update argument type and name public void onFragmentInteraction(Uri uri); } } Content-Type: text/plain; charset=UTF-8 Content-Length: 3972 Content-Disposition: inline; filename="UploadFragment.java" Last-Modified: Thu, 14 Nov 2024 16:25:57 GMT Expires: Thu, 14 Nov 2024 16:30:57 GMT ETag: "1bc7321c9552a0711b572c8af45b544c2bcbdf68" /app/src/main/java/uk/co/blatech/blaupload/data/

/app/src/main/java/uk/co/blatech/blaupload/data/