blob: 4ede5fc7bf696e8bd72a42640ed2428dd5ccc522 (
plain)
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
|
package org.ryuslash.Dailies;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.TimePicker;
public class AddActivity extends Activity
{
private DailiesDataSource datasource;
private long id;
public void saveDaily()
{
EditText name_entry = (EditText) findViewById(R.id.name_entry);
CheckBox alarm_entry =
(CheckBox) findViewById(R.id.alarm_entry);
TimePicker time_entry =
(TimePicker) findViewById(R.id.time_entry);
String name = name_entry.getText().toString();
boolean alarm = alarm_entry.isChecked();
int hour = alarm ? time_entry.getCurrentHour() : 0;
int minute = alarm ? time_entry.getCurrentMinute() : 0;
if (id > 0)
datasource.updateDaily(id, name, alarm, hour, minute, null);
else
datasource.createDaily(name, alarm, hour, minute);
}
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.add);
datasource = new DailiesDataSource(this);
datasource.open();
Intent intent = getIntent();
id = intent.getLongExtra(SQLiteHelper.COLUMN_ID, 0l);
if (id > 0) {
Daily daily = datasource.getById(id);
EditText name_entry =
(EditText) findViewById(R.id.name_entry);
CheckBox alarm_entry =
(CheckBox) findViewById(R.id.alarm_entry);
TimePicker time_entry =
(TimePicker) findViewById(R.id.alarm_entry);
name_entry.setText(daily.getTitle());
alarm_entry.setChecked(daily.getAlarm());
time_entry.setCurrentHour(daily.getHour());
time_entry.setCurrentMinute(daily.getMinute());
}
}
@Override
public boolean onCreateOptionsMenu(Menu menu)
{
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.add_activity, menu);
return true;
}
@Override
protected void onDestroy()
{
datasource.close();
super.onDestroy();
}
@Override
public boolean onOptionsItemSelected(MenuItem item)
{
switch (item.getItemId()) {
case R.id.add_menu_save:
saveDaily();
finish();
return true;
}
return false;
}
@Override
protected void onPause()
{
datasource.close();
super.onPause();
}
@Override
protected void onResume()
{
datasource.open();
super.onResume();
}
}
|