package com.brink.main;
import java.io.BufferedInputStream;
import java.io.InputStream;
import java.io.UnsupportedEncodingException;
import java.net.URL;
import java.net.URLConnection;
import java.net.URLEncoder;
import java.util.ArrayList;
import java.util.HashMap;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import android.app.Application;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.net.http.AndroidHttpClient;
import android.util.Log;
import com.brink.main.Stored.BarList;
import com.brink.main.Utility.FlushedInputStream;
public class IncomingAPI extends Application{
/*
* Method Used for Asynchronously loading the profile pic on the ViewHandler Page.
*/
public static Bitmap RetrieveFacebookAvatar()
{
AndroidHttpClient httpclient = null;
try {
URL aURL = new URL(Stored.UserInformation.retrieveUsersPictureURL());
URLConnection conn = aURL.openConnection();
conn.connect();
InputStream is = conn.getInputStream();
BufferedInputStream bis = new BufferedInputStream(is);
Stored.UserInformation.setUsersPicture(BitmapFactory.decodeStream(new FlushedInputStream(is)));
bis.close();
is.close();
} catch (Exception e) {
e.printStackTrace();
} finally {
if (httpclient != null) {
httpclient.close();
}
}
return Stored.UserInformation.retrieveUsersPicture();
}
//API INCOMING for cities that are supported near the user.
//Retrieve for BarSearch page
public static void populateBarList()
{
//TODO grab API from our server and store the values of the bars in the ArrayList that is in Stored.
//Depends on location that person is at
HashMap<String,String> temp = new HashMap<String,String>();
temp.put("bar","Freds");
temp.put("location", "TigerLand");
temp.put("cover", "Cover: $10.00");
temp.put("checked in", "25 People Checked In Here");
Stored.barList.add(temp);
HashMap<String,String> temp1 = new HashMap<String,String>();
temp1.put("bar","JL's");
temp1.put("location", "TigerLand");
temp1.put("cover", "$10.00");
temp1.put("checked in", "25 People Checked In Here");
Stored.barList.add(temp1);
HashMap<String,String> temp2 = new HashMap<String,String>();
temp2.put("bar","Mike's");
temp2.put("location", "TigerLand");
temp2.put("cover", "$10.00");
temp2.put("checked in", "25 People Checked In Here");
Stored.barList.add(temp2);
HashMap<String,String> temp3 = new HashMap<String,String>();
temp3.put("bar","Reggies");
temp3.put("location", "TigerLand");
temp3.put("cover", "$10.00");
temp3.put("checked in", "25 People Checked In Here");
Stored.barList.add(temp3);
HashMap<String,String> temp4 = new HashMap<String,String>();
temp4.put("bar","The House");
temp4.put("location", "TigerLand");
temp4.put("cover", "$10.00");
temp4.put("checked in", "25 People Checked In Here");
Stored.barList.add(temp4);
}
public static Boolean populatedBarPage(String barname)
{
//TODO Tie in the populateBarPage with the API of the server.
//TODO Find out whether we are getting back a url with the photo from the server or we are sending the full photo.
//The barname was sent to this method so that it could be sent to the server with the region to look up the bar info.
StoredBar.address = "1234 Sunshine Way";
StoredBar.amountChecked = "25 people are checked in here";
StoredBar.barsLocation = "TigerLand";
Log.w("Variables", "set");
StoredBar.specialsBundle.putString("monday", "Free Drinks from 8-10");
StoredBar.specialsBundle.putString("tuesday", "Live Performace: Lil' Moe");
StoredBar.specialsBundle.putString("wednesday","Penny Pitchers");
StoredBar.specialsBundle.putString("thursday", "Ladies Night Free No Cover!");
StoredBar.specialsBundle.putString("friday", "Free Cover from 8-10");
StoredBar.specialsBundle.putString("saturday", "DJ Tiesto Live DJ Performance");
StoredBar.specialsBundle.putString("sunday", "No Specials Closed");
Log.w("Bundle done", "set");
//SET THESE IMAGES!!!!!!!!!
//StoredBar.imageTaken1 = ????????
//StoredBar.imageTaken2 = ???????????
//StoredBar.imageTaken3 = ???????????
//StoredBar.barLogo = ??????????????
return true;
}
/*
* Method: populateBarPick()
* Description: Will call on the API to send back a list of bars located in the City that the user is in.
*
*/
public static ArrayList<Stored.BarList> populateBarPick(String zone)
{
ArrayList<Stored.BarList> results = new ArrayList<Stored.BarList>();
String url = OutgoingAPI.ApiUrl + "bars/Baton%20Rouge/";
RestClient client = new RestClient(url);
//client.AddHeader("Content-Type", "application/json");
try {
client.Execute(RequestMethod.GET);
} catch (Exception e) {
e.printStackTrace();
}
Log.i("In populateBarPick", "IncomingAPI");
JSONArray bars = null;
try {
bars = new JSONArray(client.getResponse());
for (int i = 0; i < bars.length(); i++) {
JSONObject bar = bars.getJSONObject(i);
Stored.BarList item = new Stored.BarList();
item.setBarsName(bar.getString("barname"));
results.add(item);
Log.w(item.retrieveBarsName(), "BarName for Spinner Item");
}
} catch (JSONException e) {
Log.i("Caught Exception", "Converting JSONARRAY");
e.printStackTrace();
return results;
}
return results;
}
}