Skip to content
Browse files

Adding funtionality and expanding which clients can use it.

* Adding staff view
* Added navigation button
* changed API to Android 1.5 (API level 3)

(rev 3)
  • Loading branch information...
1 parent cdd4ce7 commit c17b32694dcda901270508ed42221155392b29cf @fkautz committed Nov 13, 2011
View
11 AndroidManifest.xml
@@ -1,19 +1,20 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.hackerdojo.android.infoapp"
- android:versionCode="0" android:versionName="0.0.1">
- <uses-sdk android:minSdkVersion="10" />
+ android:versionCode="0" android:versionName="0.0.2">
+ <uses-sdk android:minSdkVersion="3" />
<uses-permission android:name="android.permission.INTERNET"></uses-permission>
<application android:icon="@drawable/icon" android:label="@string/app_name">
- <activity android:name=".HackerDojoActivity"
+ <activity android:name=".EventActivity"
android:label="@string/app_name"
- android:theme="@android:style/Theme.NoTitleBar.Fullscreen">
+ android:theme="@android:style/Theme.NoTitleBar">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
-
+ <activity android:name=".StaffActivity"
+ android:theme="@android:style/Theme.NoTitleBar"/>
</application>
</manifest>
View
2 default.properties
@@ -8,4 +8,4 @@
# project structure.
# Project target.
-target=android-10
+target=android-3
View
0 res/layout/entry.xml → res/layout/event.xml
File renamed without changes.
View
9 res/layout/header.xml
@@ -1,9 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<TextView xmlns:android="http://schemas.android.com/apk/res/android"
- android:layout_width="fill_parent"
- android:layout_height="fill_parent"
- android:padding="10dp"
- android:textSize="16sp"
- android:textColor="@android:color/black"
- >
-</TextView>
View
22 res/layout/main.xml
@@ -7,8 +7,8 @@
>
<ImageView
android:id="@+id/imageView1"
+ android:layout_width="fill_parent"
android:layout_height="wrap_content"
- android:layout_width="match_parent"
android:layout_marginTop="10px"
android:src="@drawable/hacker_dojo_logo_transparent"
/>
@@ -39,24 +39,40 @@
android:textSize="16pt"
android:layout_weight="1"
/>
+ <TextView
+ android:id="@+id/empty"
+ android:layout_height="fill_parent"
+ android:layout_width="fill_parent"
+ android:gravity="center_vertical|center_horizontal"
+ android:textSize="16pt"
+ android:layout_weight="1"
+ android:visibility="gone"
+ />
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="0"
- android:visibility="gone"
>
<Button
+ android:id="@+id/eventsButton"
+ android:layout_width="fill_parent"
+ android:layout_height="wrap_content"
+ android:text="Events"
+ android:layout_weight="2"
+ />
+ <Button
+ android:id="@+id/staffButton"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Staff on Site"
android:layout_weight="2"
/>
<Button
+ android:id="@+id/navigateButton"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Find the Dojo"
android:layout_weight="2"
/>
-
</LinearLayout>
</LinearLayout>
View
13 res/layout/staff.xml
@@ -0,0 +1,13 @@
+<?xml version="1.0" encoding="utf-8"?>
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:orientation="horizontal"
+ android:padding="10sp"
+ >
+ <LinearLayout android:layout_width="fill_parent" android:layout_height="wrap_content" android:id="@+id/linearLayout1" android:orientation="horizontal" android:gravity="center_vertical">
+ <TextView android:id="@+id/textView1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:textColor="#005500" android:visibility="gone"></TextView>
+ <TextView android:id="@+id/textView2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:textColor="#990000" ></TextView>
+ </LinearLayout>
+ <TextView android:id="@+id/textView3" android:layout_width="wrap_content" android:layout_height="wrap_content" android:textColor="@android:color/black" android:layout_gravity="center_vertical|right" android:layout_marginLeft="10px"></TextView>
+</LinearLayout>
View
2 res/values/strings.xml
@@ -2,5 +2,5 @@
<resources>
<string name="hello">Hello World, HackerDojoActivity!</string>
<string name="app_name">Hacker Dojo</string>
- <string name="emptyEvents">No events scheduled</string>
+ <string name="emptyEvents"></string>
</resources>
View
168 src/com/hackerdojo/android/infoapp/EventActivity.java
@@ -0,0 +1,168 @@
+package com.hackerdojo.android.infoapp;
+
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.text.ParseException;
+import java.text.SimpleDateFormat;
+import java.util.ArrayList;
+import java.util.Calendar;
+import java.util.Collections;
+import java.util.Date;
+import java.util.List;
+
+import org.apache.http.HttpEntity;
+import org.apache.http.HttpResponse;
+import org.apache.http.client.ClientProtocolException;
+import org.apache.http.client.HttpClient;
+import org.apache.http.client.methods.HttpGet;
+import org.apache.http.impl.client.DefaultHttpClient;
+import org.json.JSONArray;
+import org.json.JSONException;
+import org.json.JSONObject;
+
+import android.util.Log;
+import android.view.View;
+import android.view.View.OnClickListener;
+import android.widget.Button;
+import android.widget.TextView;
+
+public class EventActivity extends HackerDojoActivity implements OnClickListener {
+ private static final String HACKER_DOJO = "HACKER_DOJO";
+ private static List<Event> events;
+ private static Calendar lastUpdated = Calendar.getInstance();
+ private static List<String> startDates;
+ private static List<String> endDates;
+ private static List<String> titles;
+ static {
+ lastUpdated.setTime(new Date(0));
+ }
+
+
+ private List<Event> getEvents() {
+ HttpClient client = new DefaultHttpClient();
+ StringBuffer sb = new StringBuffer();
+ try {
+ Log.i(HACKER_DOJO, "FETCHING EVENTS");
+ HttpResponse response = client.execute(new HttpGet("http://events.hackerdojo.com/events.json"));
+ HttpEntity entity = response.getEntity();
+ char[] buf = new char[1024];
+ InputStream content = entity.getContent();
+ BufferedReader reader = new BufferedReader(new InputStreamReader(content));
+ int c=0;
+ while(c != -1) {
+ c = reader.read(buf);
+ if(c > 0) {
+ sb.append(buf, 0, c);
+ }
+ }
+ } catch (ClientProtocolException e) {
+ Log.e(HACKER_DOJO, e.getMessage(), e);
+ } catch (IOException e) {
+ Log.e(HACKER_DOJO, e.getMessage(), e);
+ }
+
+ ArrayList<Event> events = new ArrayList<Event>();
+ try {
+ JSONArray json = new JSONArray(sb.toString());
+ for(int i=0; i<json.length(); i++) {
+ Event event = new Event();
+ JSONObject jsonObject = json.getJSONObject(i);
+ if(jsonObject.has("status") && jsonObject.has("start_time") && jsonObject.has("end_time") && jsonObject.has("name") && jsonObject.has("member") && jsonObject.has("rooms")) {
+ if(jsonObject.getString("status").equals("approved")) {
+ SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");
+ Date startDate = format.parse(jsonObject.getString("start_time")); // hardcode date for parsing
+ Date endDate = format.parse(jsonObject.getString("end_time"));
+ event.setStartDate(startDate);
+ event.setEndDate(endDate);
+ event.setTitle(jsonObject.getString("name"));
+ event.setLocation(jsonObject.getString("rooms"));
+ event.setHost(jsonObject.getString("member"));
+ events.add(event);
+ }
+ }
+ }
+ } catch (JSONException e) {
+ Log.e(HACKER_DOJO, e.getMessage(), e);
+ } catch (ParseException e) {
+ Log.e(HACKER_DOJO, e.getMessage(), e);
+ }
+ Collections.sort(events);
+ return events;
+ }
+
+ @Override
+ public void onClick(View v) {
+ super.onClick(v);
+ }
+
+ @Override
+ public void initializeView() {
+ setHeader("Events");
+ if(Calendar.getInstance().getTimeInMillis() - lastUpdated.getTimeInMillis() > 600000 /* 10 minutes */) {
+ lastUpdated = Calendar.getInstance();
+
+ events = getEvents();
+
+ startDates = new ArrayList<String>();
+ endDates = new ArrayList<String>();
+ titles = new ArrayList<String>();
+ Date lastDate = new Date(0);
+ Date today = new Date();
+ SimpleDateFormat format = new SimpleDateFormat("EEEE, MM/dd/yyyy");
+ TextView emptyMessage = (TextView) findViewById(R.id.empty);
+ if(events.size() == 0) {
+ emptyMessage.setText("Check your network connection.");
+ emptyMessage.setVisibility(View.VISIBLE);
+ lastUpdated.setTime(new Date(0));
+ } else {
+ emptyMessage.setVisibility(View.GONE);
+ }
+ for(int i=0; i<events.size(); i++) {
+ Event event = events.get(i);
+ if(event.getEndDate().before(new Date())) {
+ continue;
+ }
+ if(event.getStartDate().getYear()>lastDate.getYear() || event.getStartDate().getMonth() > lastDate.getMonth() || event.getStartDate().getDate() > lastDate.getDate()) {
+ startDates.add("");
+ endDates.add("");
+ Date date = event.getStartDate();
+ if(date.getYear() == today.getYear() && date.getMonth() == today.getMonth() && date.getDate() == today.getDate()) {
+ titles.add("Today");
+ } else {
+ String dateString = format.format(date);
+ titles.add(dateString);
+ }
+ lastDate = event.getStartDate();
+ }
+ String startMeridiem = "am";
+ String endMeridiem = "am";
+ int startHour = event.getStartDate().getHours();
+ int endHour = event.getEndDate().getHours();
+ if(startHour >= 12) {
+ startMeridiem = "pm";
+ startHour = startHour - 12;
+ }
+ if(endHour >= 12) {
+ endMeridiem = "pm";
+ endHour = endHour - 12;
+ }
+ if(startHour == 0) {
+ startHour = 12;
+ }
+ if(endHour == 0) {
+ endHour = 12;
+ }
+ startDates.add(String.format("%02d:%02d %s", startHour, event.getStartDate().getMinutes(),startMeridiem));
+ endDates.add(String.format("%02d:%02d %s", endHour, event.getEndDate().getMinutes(),endMeridiem));
+ titles.add(event.getTitle());
+ }
+ }
+ EventArrayAdapter adapter2 = new EventArrayAdapter(this, startDates, endDates, titles);
+ setListAdapter(adapter2);
+
+ Button eventButton = (Button)findViewById(R.id.eventsButton);
+ eventButton.setVisibility(View.GONE);
+ }
+}
View
4 src/com/hackerdojo/android/infoapp/EventArrayAdapter.java
@@ -16,7 +16,7 @@
private List<String> titles;
public EventArrayAdapter(Activity context, List<String> startTimes, List<String> endTimes, List<String> titles) {
- super(context, R.layout.entry, new String[titles.size()]);
+ super(context, R.layout.event, new String[titles.size()]);
this.context = context;
this.startTimes = startTimes;
this.endTimes = endTimes;
@@ -25,7 +25,7 @@ public EventArrayAdapter(Activity context, List<String> startTimes, List<String>
public View getView(int position, View view, ViewGroup viewGroup) {
LayoutInflater inflator = context.getLayoutInflater();
- View newView = inflator.inflate(R.layout.entry, null, true);
+ View newView = inflator.inflate(R.layout.event, null, true);
TextView textView1 = (TextView) newView.findViewById(R.id.textView1);
TextView textView2 = (TextView) newView.findViewById(R.id.textView2);
TextView textView3 = (TextView) newView.findViewById(R.id.textView3);
View
190 src/com/hackerdojo/android/infoapp/HackerDojoActivity.java
@@ -1,45 +1,18 @@
package com.hackerdojo.android.infoapp;
-import java.io.BufferedReader;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.InputStreamReader;
-import java.text.ParseException;
-import java.text.SimpleDateFormat;
-import java.util.ArrayList;
-import java.util.Calendar;
-import java.util.Collections;
-import java.util.Date;
-import java.util.List;
-
-import org.apache.http.HttpEntity;
-import org.apache.http.HttpResponse;
-import org.apache.http.client.ClientProtocolException;
-import org.apache.http.client.HttpClient;
-import org.apache.http.client.methods.HttpGet;
-import org.apache.http.impl.client.DefaultHttpClient;
-import org.json.JSONArray;
-import org.json.JSONException;
-import org.json.JSONObject;
-
import android.app.ListActivity;
+import android.content.Intent;
+import android.net.Uri;
import android.os.Bundle;
import android.util.Log;
import android.view.Surface;
import android.view.View;
import android.view.View.OnClickListener;
+import android.widget.Button;
import android.widget.TextView;
-public class HackerDojoActivity extends ListActivity implements OnClickListener {
+public abstract class HackerDojoActivity extends ListActivity implements OnClickListener {
private static final String HACKER_DOJO = "HACKER_DOJO";
- private static List<Event> events;
- private static Calendar lastUpdated = Calendar.getInstance();
- private static List<String> startDates;
- private static List<String> endDates;
- private static List<String> titles;
- static {
- lastUpdated.setTime(new Date(0));
- }
/** Called when the activity is first created. */
@Override
@@ -51,121 +24,54 @@ public void onCreate(Bundle savedInstanceState) {
@Override
public void onResume() {
super.onResume();
+ initializeView();
+ Button evenButton = (Button) findViewById(R.id.eventsButton);
+ evenButton.setOnClickListener(this);
+ Button staffButton = (Button) findViewById(R.id.staffButton);
+ staffButton.setOnClickListener(this);
+ Button navigateButton = (Button) findViewById(R.id.navigateButton);
+ navigateButton.setOnClickListener(this);
+ }
+
+ @Override
+ public void onClick(View v) {
+ Log.e(HACKER_DOJO, "Button Click: " + v.getId());
+ if(v.getId() == R.id.eventsButton) {
+ openEvents();
+ } else if(v.getId() == R.id.staffButton) {
+ openStaff();
+ } else if(v.getId() == R.id.navigateButton) {
+ openNavigation();
+ }
+ }
+
+ private void openEvents() {
+ Intent intent = new Intent(HackerDojoActivity.this, EventActivity.class);
+ startActivity(intent);
+ }
+
+ private void openStaff() {
+ Intent intent = new Intent(HackerDojoActivity.this, StaffActivity.class);
+ startActivity(intent);
+ }
+
+ private void openNavigation() {
+ Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("google.navigation:q=140%20whisman%20rd%2C%20mountain%20view%2C%20ca"));
+ startActivity(intent);
+ }
+
+ protected void setHeader(String headerString) {
View dojoLogo = findViewById(R.id.imageView1);
- if(this.getWindowManager().getDefaultDisplay().getRotation() == Surface.ROTATION_180 || this.getWindowManager().getDefaultDisplay().getRotation() == Surface.ROTATION_0) {
+ TextView header = (TextView) findViewById(R.id.header);
+// if(this.getWindowManager().getDefaultDisplay().getRotation() == Surface.ROTATION_180 || this.getWindowManager().getDefaultDisplay().getRotation() == Surface.ROTATION_0) {
+ if(this.getWindowManager().getDefaultDisplay().getOrientation() == Surface.ROTATION_180 || this.getWindowManager().getDefaultDisplay().getOrientation() == Surface.ROTATION_0) {
dojoLogo.setVisibility(View.VISIBLE);
+ header.setText(headerString);
} else {
dojoLogo.setVisibility(View.GONE);
+ header.setText("Hacker Dojo " + headerString);
}
- TextView header = (TextView) findViewById(R.id.header);
- header.setText("Events");
- if(Calendar.getInstance().getTimeInMillis() - lastUpdated.getTimeInMillis() > 600000 /* 10 minutes */) {
- lastUpdated = Calendar.getInstance();
-
-
- events = getEvents();
-
- startDates = new ArrayList<String>();
- endDates = new ArrayList<String>();
- titles = new ArrayList<String>();
- Date lastDate = new Date(0);
- for(int i=0; i<events.size(); i++) {
- Event event = events.get(i);
- if(event.getEndDate().before(new Date())) {
- continue;
- }
- if(event.getStartDate().getYear()>lastDate.getYear() || event.getStartDate().getMonth() > lastDate.getMonth() || event.getStartDate().getDate() > lastDate.getDate()) {
- startDates.add("");
- endDates.add("");
- titles.add(String.format("%02d/%d/%04d", event.getStartDate().getMonth()+1, event.getStartDate().getDate(), event.getStartDate().getYear() + 1900));
- lastDate = event.getStartDate();
- }
- String startMeridiem = "am";
- String endMeridiem = "am";
- int startHour = event.getStartDate().getHours();
- int endHour = event.getEndDate().getHours();
- if(startHour >= 12) {
- startMeridiem = "pm";
- startHour = startHour - 12;
- }
- if(endHour >= 12) {
- endMeridiem = "pm";
- endHour = endHour - 12;
- }
- if(startHour == 0) {
- startHour = 12;
- }
- if(endHour == 0) {
- endHour = 12;
- }
- startDates.add(String.format("%02d:%02d %s", startHour, event.getStartDate().getMinutes(),startMeridiem));
- endDates.add(String.format("%02d:%02d %s", endHour, event.getEndDate().getMinutes(),endMeridiem));
- titles.add(event.getTitle());
- }
- }
- EventArrayAdapter adapter2 = new EventArrayAdapter(this, startDates, endDates, titles);
- setListAdapter(adapter2);
- }
-
- private List<Event> getEvents() {
- HttpClient client = new DefaultHttpClient();
- StringBuffer sb = new StringBuffer();
- try {
- Log.i(HACKER_DOJO, "FETCHING EVENTS");
- HttpResponse response = client.execute(new HttpGet("http://events.hackerdojo.com/events.json"));
- HttpEntity entity = response.getEntity();
- char[] buf = new char[1024];
- InputStream content = entity.getContent();
- BufferedReader reader = new BufferedReader(new InputStreamReader(content));
- int c=0;
- while(c != -1) {
- c = reader.read(buf);
- if(c > 0) {
- sb.append(buf, 0, c);
- }
- }
- } catch (ClientProtocolException e) {
- Log.e(HACKER_DOJO, e.getMessage(), e);
- } catch (IOException e) {
- Log.e(HACKER_DOJO, e.getMessage(), e);
- }
-
- ArrayList<Event> events = new ArrayList<Event>();
- try {
- JSONArray json = new JSONArray(sb.toString());
- for(int i=0; i<json.length(); i++) {
- Event event = new Event();
- JSONObject jsonObject = json.getJSONObject(i);
- if(jsonObject.has("status") && jsonObject.has("start_time") && jsonObject.has("end_time") && jsonObject.has("name") && jsonObject.has("member") && jsonObject.has("rooms")) {
- if(jsonObject.getString("status").equals("approved")) {
- SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");
- Date startDate = format.parse(jsonObject.getString("start_time")); // hardcode date for parsing
- Date endDate = format.parse(jsonObject.getString("end_time"));
- event.setStartDate(startDate);
- event.setEndDate(endDate);
- event.setTitle(jsonObject.getString("name"));
- event.setLocation(jsonObject.getString("rooms"));
- event.setHost(jsonObject.getString("member"));
- events.add(event);
- }
- }
- }
- } catch (JSONException e) {
- Log.e(HACKER_DOJO, e.getMessage(), e);
- } catch (ParseException e) {
- Log.e(HACKER_DOJO, e.getMessage(), e);
- }
- Collections.sort(events);
- return events;
- }
-
- @SuppressWarnings("unused")
- private Person getPeople() {
- return null;
- }
-
- @Override
- public void onClick(View v) {
-
}
+
+ protected abstract void initializeView();
}
View
28 src/com/hackerdojo/android/infoapp/Person.java
@@ -1,5 +1,31 @@
package com.hackerdojo.android.infoapp;
-public class Person {
+import java.util.Date;
+public class Person implements Comparable<Person> {
+ private String name;
+ private Date created;
+ private String imageUrl;
+ public String getName() {
+ return name;
+ }
+ public void setName(String name) {
+ this.name = name;
+ }
+ public Date getCreated() {
+ return created;
+ }
+ public void setCreated(Date created) {
+ this.created = created;
+ }
+ public String getImageUrl() {
+ return imageUrl;
+ }
+ public void setImageUrl(String imageUrl) {
+ this.imageUrl = imageUrl;
+ }
+ @Override
+ public int compareTo(Person arg0) {
+ return this.getName().compareTo(arg0.getName());
+ }
}
View
173 src/com/hackerdojo/android/infoapp/StaffActivity.java
@@ -0,0 +1,173 @@
+package com.hackerdojo.android.infoapp;
+
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.text.ParseException;
+import java.text.SimpleDateFormat;
+import java.util.ArrayList;
+import java.util.Calendar;
+import java.util.Collections;
+import java.util.Date;
+import java.util.List;
+import java.util.TimeZone;
+
+import org.apache.http.HttpEntity;
+import org.apache.http.HttpResponse;
+import org.apache.http.client.ClientProtocolException;
+import org.apache.http.client.HttpClient;
+import org.apache.http.client.methods.HttpGet;
+import org.apache.http.impl.client.DefaultHttpClient;
+import org.json.JSONArray;
+import org.json.JSONException;
+import org.json.JSONObject;
+
+import android.os.Bundle;
+import android.util.Log;
+import android.view.View;
+import android.view.View.OnClickListener;
+import android.widget.Button;
+import android.widget.TextView;
+
+public class StaffActivity extends HackerDojoActivity implements OnClickListener {
+ private static final String HACKER_DOJO = "HACKER_DOJO";
+ private static List<Person> currentStaff;
+ private static Calendar lastUpdated = Calendar.getInstance();
+ private static List<String> names;
+ private static List<String> timeHere;
+ private static List<String> images;
+ static {
+ lastUpdated.setTime(new Date(0));
+ }
+
+ /** Called when the activity is first created. */
+ @Override
+ public void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ setContentView(R.layout.main);
+ }
+
+ private List<Person> getStaff() {
+ HttpClient client = new DefaultHttpClient();
+ StringBuffer sb = new StringBuffer();
+ try {
+ Log.i(HACKER_DOJO, "FETCHING EVENTS");
+ HttpResponse response = client.execute(new HttpGet("http://hackerdojo-signin.appspot.com/staffjson"));
+ HttpEntity entity = response.getEntity();
+ char[] buf = new char[1024];
+ InputStream content = entity.getContent();
+ BufferedReader reader = new BufferedReader(new InputStreamReader(content));
+ int c=0;
+ while(c != -1) {
+ c = reader.read(buf);
+ if(c > 0) {
+ sb.append(buf, 0, c);
+ }
+ }
+ } catch (ClientProtocolException e) {
+ Log.e(HACKER_DOJO, e.getMessage(), e);
+ } catch (IOException e) {
+ Log.e(HACKER_DOJO, e.getMessage(), e);
+ }
+
+ ArrayList<Person> currentStaffBuilder = new ArrayList<Person>();
+ try {
+ JSONArray json = new JSONArray(sb.toString());
+ for(int i=0; i<json.length(); i++) {
+ Person person = new Person();
+ JSONObject jsonObject = json.getJSONObject(i);
+ if(jsonObject.has("name") && jsonObject.has("created") && jsonObject.has("image_url") && jsonObject.has("name")) {
+ SimpleDateFormat format = new SimpleDateFormat("MM-dd-yyyy HH:mm:ss");
+
+ String name = jsonObject.getString("name");
+ Log.e(HACKER_DOJO, "created: " + jsonObject.getString("created"));
+ Date created = format.parse(jsonObject.getString("created")); // hardcode date for parsing
+ String imageUrl = jsonObject.getString("image_url");
+
+ person.setName(name);
+ person.setCreated(created);
+ person.setImageUrl(imageUrl);
+ currentStaffBuilder.add(person);
+ }
+ }
+ } catch (JSONException e) {
+ Log.e(HACKER_DOJO, e.getMessage(), e);
+ } catch (ParseException e) {
+ Log.e(HACKER_DOJO, e.getMessage(), e);
+ }
+ Collections.sort(currentStaffBuilder);
+ return currentStaffBuilder;
+ }
+
+ @Override
+ public void onClick(View v) {
+ super.onClick(v);
+ }
+
+ @Override
+ protected void initializeView() {
+ setHeader("Staff on Site");
+ if(Calendar.getInstance().getTimeInMillis() - lastUpdated.getTimeInMillis() > 600000 /* 10 minutes */) {
+ lastUpdated = Calendar.getInstance();
+
+ currentStaff = getStaff();
+
+ names = new ArrayList<String>();
+ timeHere = new ArrayList<String>();
+ images = new ArrayList<String>();
+ TextView emptyMessage = (TextView) findViewById(R.id.empty);
+ if(currentStaff.size() == 0) {
+ emptyMessage.setText("Dojo is closed");
+ emptyMessage.setVisibility(View.VISIBLE);
+ lastUpdated.setTime(new Date(0));
+ } else {
+ emptyMessage.setVisibility(View.GONE);
+ }
+ for(int i=0; i<currentStaff.size(); i++) {
+ Person person = currentStaff.get(i);
+ Calendar timeEntered = Calendar.getInstance();
+ timeEntered.setTime(person.getCreated());
+
+ long timeRadix = lastUpdated.getTimeInMillis() - timeEntered.getTimeInMillis();
+
+ // normalize for timezone
+ long offset = TimeZone.getDefault().getRawOffset();
+ timeRadix = timeRadix - offset;
+
+ timeRadix = timeRadix / 60;
+ timeRadix = timeRadix / 1000;
+ Log.e(HACKER_DOJO, "lastUpdated: " + lastUpdated);
+ Log.e(HACKER_DOJO, "timeEntered: " + timeEntered);
+ Log.e(HACKER_DOJO, "radix: " + timeRadix);
+
+ // time is UTC
+
+ long minutes = timeRadix % 60;
+ timeRadix = timeRadix / 60;
+ long hours = timeRadix % 24;
+ timeRadix = timeRadix / 24;
+ long days = timeRadix;
+
+ StringBuffer time = new StringBuffer();
+ if(days > 0) {
+ time.append(days + " days ");
+ }
+ if(days > 0 || hours > 0) {
+ time.append(hours + " hours ");
+ }
+ if(days > 0 || hours > 0 || minutes > 0) {
+ time.append(minutes + " minutes");
+ }
+ names.add(person.getName());
+ timeHere.add(time.toString());
+ images.add("[image]");
+ }
+ }
+ StaffArrayAdapter adapter2 = new StaffArrayAdapter(this, images, names, timeHere);
+ setListAdapter(adapter2);
+
+ Button staffButton = (Button)findViewById(R.id.staffButton);
+ staffButton.setVisibility(View.GONE);
+ }
+}
View
37 src/com/hackerdojo/android/infoapp/StaffArrayAdapter.java
@@ -0,0 +1,37 @@
+package com.hackerdojo.android.infoapp;
+
+import java.util.List;
+
+import android.app.Activity;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.view.ViewGroup;
+import android.widget.ArrayAdapter;
+import android.widget.TextView;
+
+public class StaffArrayAdapter extends ArrayAdapter<String> {
+ private Activity context;
+ private List<String> startTimes;
+ private List<String> endTimes;
+ private List<String> titles;
+
+ public StaffArrayAdapter(Activity context, List<String> startTimes, List<String> endTimes, List<String> titles) {
+ super(context, R.layout.event, new String[titles.size()]);
+ this.context = context;
+ this.startTimes = startTimes;
+ this.endTimes = endTimes;
+ this.titles = titles;
+ }
+
+ public View getView(int position, View view, ViewGroup viewGroup) {
+ LayoutInflater inflator = context.getLayoutInflater();
+ View newView = inflator.inflate(R.layout.staff, null, true);
+ TextView textView1 = (TextView) newView.findViewById(R.id.textView1);
+ TextView textView2 = (TextView) newView.findViewById(R.id.textView2);
+ TextView textView3 = (TextView) newView.findViewById(R.id.textView3);
+ textView1.setText(startTimes.get(position));
+ textView2.setText(endTimes.get(position));
+ textView3.setText(titles.get(position));
+ return newView;
+ }
+}

0 comments on commit c17b326

Please sign in to comment.
Something went wrong with that request. Please try again.