Skip to content
Browse files

Modifications... getting closer

  • Loading branch information...
1 parent d64f253 commit 867d36f282e15e1fcd6c76e1481e570e21963d02 @ardavis committed Mar 18, 2012
View
4 AndroidManifest.xml
@@ -20,6 +20,10 @@
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
+
+ <activity
+ android:name=".EventListActivity"
+ android:theme="@android:style/Theme.Black.NoTitleBar" ></activity>
</application>
</manifest>
View
BIN bin/AutoSilencer.apk
Binary file not shown.
View
BIN bin/classes.dex
Binary file not shown.
View
BIN bin/classes/edu/kettering/autosilencer/AutoSilencerActivity$1.class
Binary file not shown.
View
BIN bin/classes/edu/kettering/autosilencer/AutoSilencerActivity$2.class
Binary file not shown.
View
BIN bin/classes/edu/kettering/autosilencer/AutoSilencerActivity$3.class
Binary file not shown.
View
BIN bin/classes/edu/kettering/autosilencer/AutoSilencerActivity$4.class
Binary file not shown.
View
BIN bin/classes/edu/kettering/autosilencer/AutoSilencerActivity$5.class
Binary file not shown.
View
BIN bin/classes/edu/kettering/autosilencer/AutoSilencerActivity.class
Binary file not shown.
View
BIN bin/classes/edu/kettering/autosilencer/Event.class
Binary file not shown.
View
BIN bin/classes/edu/kettering/autosilencer/EventListActivity.class
Binary file not shown.
View
BIN bin/classes/edu/kettering/autosilencer/R$drawable.class
Binary file not shown.
View
BIN bin/classes/edu/kettering/autosilencer/R$id.class
Binary file not shown.
View
BIN bin/classes/edu/kettering/autosilencer/R$layout.class
Binary file not shown.
View
BIN bin/classes/edu/kettering/autosilencer/R$string.class
Binary file not shown.
View
BIN bin/classes/edu/kettering/autosilencer/R$style.class
Binary file not shown.
View
BIN bin/resources.ap_
Binary file not shown.
View
18 gen/edu/kettering/autosilencer/R.java
@@ -36,24 +36,30 @@
public static final int white=0x7f040012;
}
public static final class drawable {
- public static final int auto_silencer_logo=0x7f020000;
- public static final int blue_button_states=0x7f020001;
- public static final int ic_launcher=0x7f020002;
- public static final int title=0x7f020003;
- public static final int toggle_state_background=0x7f020004;
- public static final int toggle_state_text_color=0x7f020005;
+ public static final int as_icon=0x7f020000;
+ public static final int auto_silencer_logo=0x7f020001;
+ public static final int blue_button_states=0x7f020002;
+ public static final int ic_launcher=0x7f020003;
+ public static final int title=0x7f020004;
+ public static final int toggle_state_background=0x7f020005;
+ public static final int toggle_state_text_color=0x7f020006;
}
public static final class id {
public static final int addCalendarEvent=0x7f080005;
public static final int currentState=0x7f080001;
+ public static final int dayNumber=0x7f080007;
public static final int enableDisable=0x7f080003;
+ public static final int eventTimes=0x7f08000a;
+ public static final int eventTitle=0x7f080009;
public static final int mainMenuTitle=0x7f080000;
+ public static final int month=0x7f080008;
public static final int nextEvent=0x7f080002;
public static final int settings=0x7f080006;
public static final int viewUpEvents=0x7f080004;
}
public static final class layout {
public static final int main=0x7f030000;
+ public static final int upcoming_event_list_item_layout=0x7f030001;
}
public static final class string {
public static final int addCalendarEvent=0x7f050004;
View
BIN res/drawable-mdpi/as_icon.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
63 res/layout/upcoming_event_list_item_layout.xml
@@ -0,0 +1,63 @@
+<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
+ android:layout_width="fill_parent"
+ android:layout_height="?android:attr/listPreferredItemHeight"
+
+ android:padding="10dip">
+
+ <TextView
+ android:id="@+id/dayNumber"
+ android:layout_width="30dip"
+ android:layout_height="26dip"
+ android:layout_above="@+id/month"
+ android:layout_alignParentLeft="true"
+ android:layout_alignParentTop="true"
+ android:ellipsize="marquee"
+ android:singleLine="true"
+ android:textSize="25dip"
+ android:layout_marginRight="6dip"
+ android:text="27" />
+
+ <TextView
+ android:id="@+id/month"
+ android:layout_width="30dip"
+ android:layout_height="wrap_content"
+ android:layout_alignParentBottom="true"
+ android:layout_alignParentLeft="true"
+ android:layout_alignWithParentIfMissing="true"
+ android:gravity="center_vertical"
+ android:textSize="12dip"
+ android:layout_marginRight="6dip"
+ android:text="July" />
+
+ <TextView
+ android:id="@+id/eventTitle"
+ android:gravity="center_vertical"
+ android:layout_width="fill_parent"
+ android:layout_height="26dip"
+ android:textSize="20dip"
+
+ android:layout_toRightOf="@+id/dayNumber"
+ android:layout_alignParentTop="true"
+ android:layout_alignParentRight="true"
+ android:layout_above="@+id/eventTimes"
+
+ android:singleLine="true"
+ android:ellipsize="marquee"
+ android:text="Title" />
+
+ <TextView
+ android:id="@+id/eventTimes"
+
+ android:layout_width="fill_parent"
+ android:layout_height="wrap_content"
+ android:layout_gravity="center"
+ android:layout_toRightOf="@+id/month"
+ android:layout_alignParentBottom="true"
+ android:layout_alignParentRight="true"
+
+ android:layout_alignWithParentIfMissing="true"
+
+ android:gravity="center_vertical"
+ android:text="Start and End Time" />
+
+</RelativeLayout>
View
153 src/edu/kettering/autosilencer/AutoSilencerActivity.java
@@ -22,6 +22,7 @@
import android.widget.TextView;
import android.widget.Toast;
import android.widget.ToggleButton;
+import android.content.BroadcastReceiver;
import android.content.ContentResolver;
import android.content.ContentUris;
import android.content.Context;
@@ -42,32 +43,57 @@
// Global Variables
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("EEE, MMM dd hh:mm aaa");
- private TextView upcomingEventsText;
private TextView currentStateLabel;
private TextView nextEventLabel;
private ArrayList<Event> events = new ArrayList<Event>();
private Event nextEvent;
private Button addButton;
+ private Button viewUpEvents;
private ToggleButton toggleButton;
private Date lastQueryAt;
- private final static int INTERVAL = 1000 * 5; // 4 seconds
+ private final static int INTERVAL = 1000 * 60; // 10 seconds
+
private Handler handler;
- private Runnable handlerTask = new Runnable()
- {
+
+ private Runnable handlerTask = new Runnable() {
@Override
public void run() {
- // Check if current time is equal to the next event time
checkForEvent();
- //Toast.makeText(getApplicationContext(), "Is it time yet?", Toast.LENGTH_SHORT).show();
- handler.postDelayed(handlerTask, INTERVAL);
+ updateNextEventLabel();
}
};
+ private final BroadcastReceiver intentReceiver = new BroadcastReceiver() {
+
+ @Override
+ public void onReceive(Context context, Intent intent) {
+ final String action = intent.getAction();
+
+ if (Intent.ACTION_TIME_CHANGED.equals(action))
+ {
+ handler.post(handlerTask);
+ }
+
+ }
+ };
+
+// private Runnable handlerTask = new Runnable()
+// {
+// @Override
+// public void run() {
+// // Check if current time is equal to the next event time
+// checkForEvent();
+// updateNextEventLabel();
+// //Toast.makeText(getApplicationContext(), "Is it time yet?", Toast.LENGTH_SHORT).show();
+// handler.postDelayed(handlerTask, INTERVAL);
+// }
+// };
+//
private Boolean isEnabled = true;
// Audio Manager
@@ -85,6 +111,7 @@ public void onCreate(Bundle savedInstanceState) {
getUpcomingEvents(this);
prepareToggleButton();
+ prepareUpcomingEventsButton();
prepareAddButton();
handler = new Handler();
@@ -93,6 +120,37 @@ public void onCreate(Bundle savedInstanceState) {
}
+ @Override
+ protected void onRestart() {
+ super.onRestart();
+ getUpcomingEvents(this);
+ startCheckingForEvents();
+ }
+
+ @Override
+ protected void onStop() {
+ super.onStop();
+ stopCheckingForEvents();
+ }
+
+ public void prepareUpcomingEventsButton()
+ {
+ viewUpEvents = (Button) findViewById(R.id.viewUpEvents);
+ viewUpEvents.setOnClickListener(new OnClickListener() {
+
+ @Override
+ public void onClick(View v) {
+
+ Bundle bundle = new Bundle();
+ bundle.putSerializable("events", events);
+
+ Intent showUpcomingEvents = new Intent(getApplicationContext(), EventListActivity.class);
+ showUpcomingEvents.putExtras(bundle);
+ startActivity(showUpcomingEvents);
+ }
+ });
+ }
+
public void setupInitialState()
{
// Current Volume State of the Device
@@ -116,15 +174,22 @@ public void setupInitialState()
}
- // Next Event
- nextEventLabel = (TextView) findViewById(R.id.nextEvent);
- nextEventLabel.setText(simpleDateFormat.format(new Date()));
-
// Enabled or Disabled
toggleButton = (ToggleButton) findViewById(R.id.enableDisable);
toggleButton.setEnabled(isEnabled);
}
+ public void updateNextEventLabel()
+ {
+ // Next Event
+ try {
+ nextEventLabel = (TextView) findViewById(R.id.nextEvent);
+ nextEventLabel.setText(simpleDateFormat.format(nextEvent.beginTime()));
+ } catch (NullPointerException e) {
+ System.out.println("There are no events!");
+ }
+ }
+
public void setupAudioManager()
{
am = (AudioManager) getBaseContext().getSystemService(Context.AUDIO_SERVICE);
@@ -142,23 +207,28 @@ public void stopCheckingForEvents()
public void checkForEvent()
{
- Date currentTime = new Date();
- System.out.println("Current Time: " + currentTime.getTime());
- System.out.println("Next Event Time: " + simpleDateFormat.format(nextEvent.beginTime()));
- if (currentTime.getTime() > nextEvent.beginTime().getTime() && !events.isEmpty())
- {
- if (events.get(0) == nextEvent)
- {
- // Remove the "nextEvent" so another can take it's place
- events.remove(0);
- }
- getUpcomingEvents(AutoSilencerActivity.this);
- Toast.makeText(getApplicationContext(), "Checking for Events!", Toast.LENGTH_SHORT).show();
- }
- else
- {
- Toast.makeText(getApplicationContext(), "Next Event: " + simpleDateFormat.format(nextEvent.beginTime()), Toast.LENGTH_SHORT).show();
- }
+ try {
+ Date currentTime = new Date();
+ System.out.println("Current Time: " + currentTime.getTime());
+ System.out.println("N Event Time: " + nextEvent.beginTime().getTime());
+ if (currentTime.getTime() >= nextEvent.beginTime().getTime())
+ {
+ silent();
+
+ while (nextEvent.beginTime().getTime() <= currentTime.getTime())
+ {
+ events.remove(0);
+ nextEvent = events.get(0);
+ }
+ Toast.makeText(getApplicationContext(), "EVENT!!", Toast.LENGTH_SHORT).show();
+ }
+ else
+ {
+ Toast.makeText(getApplicationContext(), "Next Event: " + simpleDateFormat.format(nextEvent.beginTime()), Toast.LENGTH_SHORT).show();
+ }
+ } catch (Exception e) {
+ Toast.makeText(getApplicationContext(), "No events found within interval specified!", Toast.LENGTH_SHORT).show();
+ }
}
// Set the phone to vibrate
@@ -239,11 +309,16 @@ private void addEvent() {
}
- /*
- * Data Methods
- */
+
+ private void clearEvents()
+ {
+ events = new ArrayList<Event>();
+ }
private void getUpcomingEvents(Context context) {
+
+ clearEvents();
+
ContentResolver contentResolver = context.getContentResolver();
// Fetch a list of all calendars on the device,
@@ -275,33 +350,31 @@ private void getUpcomingEvents(Context context) {
//Uri.Builder builder = Uri.parse("content://com.android.calendar/events/instances/when").buildUpon();
Uri.Builder builder = Uri.parse("content://com.android.calendar/instances/when").buildUpon();
long now = new Date().getTime();
- //ContentUris.appendId(builder, now + (4 * DateUtils.WEEK_IN_MILLIS));
ContentUris.appendId(builder, now);
- ContentUris.appendId(builder, now + DateUtils.WEEK_IN_MILLIS);
+ ContentUris.appendId(builder, now + 4*DateUtils.WEEK_IN_MILLIS);
String[] eventProjection = new String[]{"title", "dtstart", "dtend", "allDay"};
String eventSelection = "calendar_id=" + id;
- String eventOrder = "dtstart DESC";
+ String eventOrder = "dtstart ASC, dtend ASC";
Cursor eventCursor = contentResolver.query(builder.build(), eventProjection, eventSelection, null, eventOrder);
while (eventCursor.moveToNext())
{
final String title = eventCursor.getString(0);
final Date begin = new Date(eventCursor.getLong(1));
final Date end = new Date(eventCursor.getLong(2));
- final Boolean allDay = !eventCursor.getString(3).equals("0");
+ //final Boolean allDay = !eventCursor.getString(3).equals("0");
Event newEvent = new Event(title, begin, end);
- // Add the event to the HashSet
- //if (begin.getTime() > now)
- events.add(newEvent);
+ // Add the event to the ArrayList
+ events.add(newEvent);
}
}
- if (!events.isEmpty());
+ if (!events.isEmpty())
{
- nextEvent = events.get(0);
+ nextEvent = events.get(0);
System.out.println("Title: " + nextEvent.title());
System.out.println("Start: " + nextEvent.beginTime());
lastQueryAt = new Date();
View
4 src/edu/kettering/autosilencer/Event.java
@@ -1,8 +1,10 @@
package edu.kettering.autosilencer;
+import java.io.Serializable;
+import java.lang.reflect.Array;
import java.util.Date;
-public class Event {
+public class Event implements Serializable {
// Properties
private String title;
View
71 src/edu/kettering/autosilencer/EventListActivity.java
@@ -0,0 +1,71 @@
+package edu.kettering.autosilencer;
+
+import java.io.Serializable;
+import java.text.SimpleDateFormat;
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.HashMap;
+
+import android.app.ListActivity;
+import android.content.Intent;
+import android.os.Bundle;
+import android.view.View;
+import android.widget.ListView;
+import android.widget.SimpleAdapter;
+import android.widget.Toast;
+
+public class EventListActivity extends ListActivity {
+ SimpleDateFormat sdf = new SimpleDateFormat("hh:mm aaa");
+ SimpleDateFormat day = new SimpleDateFormat("dd");
+ SimpleDateFormat month = new SimpleDateFormat("MMM");
+
+ ArrayList<Event> events;
+
+ public void onCreate(Bundle elist) {
+ super.onCreate(elist);
+
+ Intent i = getIntent();
+ events = (ArrayList<Event>) i.getSerializableExtra("events");
+
+ if (events != null)
+ {
+ ArrayList<HashMap<String, String>> list = initializeTestEvents();
+ String[] from = { "eventTitle", "eventTimes","dayNumber", "month" };
+ int[] to = {R.id.eventTitle, R.id.eventTimes, R.id.dayNumber, R.id.month };
+
+ SimpleAdapter adapter = new SimpleAdapter(EventListActivity.this,
+ list, R.layout.upcoming_event_list_item_layout, from, to);
+
+ setListAdapter(adapter);
+ }
+ }
+
+ public void onStart()
+ {
+ super.onStart();
+ events = null;
+ }
+
+ public ArrayList<HashMap<String, String>> initializeTestEvents()
+ {
+ ArrayList<HashMap<String, String>> list = new ArrayList<HashMap<String, String>>();
+ for (int i = 0; i < events.size(); i++)
+ {
+
+ list.add(putData(events.get(i).title(),
+ "Start: " + sdf.format(events.get(i).beginTime()) + " End: " + sdf.format(events.get(i).endTime()),
+ day.format(events.get(i).beginTime()),
+ month.format(events.get(i).beginTime())));
+ }
+ return list;
+ }
+
+ private HashMap<String, String> putData(String title, String times, String dayNumber, String month) {
+ HashMap<String, String> item = new HashMap<String, String>();
+ item.put("eventTitle", title);
+ item.put("eventTimes", times);
+ item.put("dayNumber", dayNumber);
+ item.put("month", month);
+ return item;
+ }
+}

0 comments on commit 867d36f

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