-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRingSchedule.java
More file actions
109 lines (100 loc) · 3.55 KB
/
RingSchedule.java
File metadata and controls
109 lines (100 loc) · 3.55 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
package rom.Ring.Schedule;
import android.app.ListActivity;
import android.content.Context;
import android.content.Intent;
import android.database.Cursor;
import android.os.Bundle;
import android.view.ContextMenu;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ContextMenu.ContextMenuInfo;
import android.widget.ListView;
import android.widget.SimpleCursorAdapter;
import android.widget.AdapterView.AdapterContextMenuInfo;
public class RingSchedule extends ListActivity {
/** Called when the activity is first created. */
private static final int ACTIVITY_CREATE = 0;
private static final int ACTIVITY_EDIT = 1;
public static final int ADD_ID = Menu.FIRST;
public static final int DELETE_ID = Menu.FIRST + 1;
int cHour, hour, cMinutes, minutes;
int previousRingerMode= 2;
public NotesDbAdapter database;
Intent ScheduleService; //TODO move back down...
Context starter;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
database = new NotesDbAdapter(this);
database.open(); //TODO badddd coding, leaving database open
starter = getBaseContext();
ScheduleService = new Intent(this, ScheduleService.class);
starter.startService(ScheduleService);
populateList();
registerForContextMenu(getListView());
}
public void populateList()
{
//database.open();
Cursor c = database.fetchAllReminders();
startManagingCursor(c);
String[] from = new String[] { NotesDbAdapter.KEY_TITLE };
int[] to = new int[] { R.id.text1 };
// Now create an array adapter and set it to display using our row
SimpleCursorAdapter tasks = new SimpleCursorAdapter(this, R.layout.task_row, c, from, to);
setListAdapter(tasks);
//database.close();
}
@Override
public void onCreateContextMenu(ContextMenu menu, View v,
ContextMenuInfo menuInfo) {
super.onCreateContextMenu(menu, v, menuInfo);
menu.add(0, DELETE_ID, 0, "Delete Schedule");
}
@Override
public boolean onContextItemSelected(MenuItem item) {
switch(item.getItemId()) {
case DELETE_ID:
AdapterContextMenuInfo info = (AdapterContextMenuInfo) item.getMenuInfo();
//database.open();
database.deleteReminder(info.id);
//database.close();
populateList();
return true;
}
return super.onContextItemSelected(item);
}
@Override
public boolean onCreateOptionsMenu(Menu menu)
{
super.onCreateOptionsMenu(menu);
menu.add(0, ADD_ID, 0, "Add Schedule");
menu.add(0, 54, 0, "Stp Service");//TODO remove
return true;
}
@Override
public boolean onMenuItemSelected(int featureId, MenuItem item) {
switch(item.getItemId()) {
case ADD_ID:
createNote();
return true;
case 54:
starter.stopService(ScheduleService);
return true;
}
return super.onMenuItemSelected(featureId, item);
}
@Override
protected void onListItemClick(ListView l, View v, int position, long id) {
super.onListItemClick(l, v, position, id);
Intent i = new Intent(this, EditSchedule.class);
i.putExtra(NotesDbAdapter.KEY_ROWID, id);
startActivityForResult(i, ACTIVITY_EDIT);
}
private void createNote() {
Intent i = new Intent(this, EditSchedule.class);
startActivityForResult(i, ACTIVITY_CREATE);
}
}