3 import java.util.Calendar;
\r
4 import java.util.Date;
\r
5 import java.util.List;
\r
7 import org.afree.chart.AFreeChart;
\r
8 import org.afree.chart.ChartFactory;
\r
9 import org.afree.chart.plot.PlotOrientation;
\r
10 import org.afree.data.category.DefaultCategoryDataset;
\r
12 import android.content.Context;
\r
13 import android.content.Intent;
\r
14 import android.content.res.Configuration;
\r
15 import android.os.Bundle;
\r
16 import android.view.View;
\r
17 import android.view.View.OnClickListener;
\r
18 import android.widget.Button;
\r
19 import android.widget.HorizontalScrollView;
\r
20 import android.widget.TextView;
\r
22 import com.td.db.History;
\r
23 import com.td.db.HistoryDao;
\r
24 import com.td.utility.BaseActivity;
\r
25 import com.td.utility.DateUtil;
\r
26 import com.td.utility.Debug;
\r
27 import com.td.utility.EditPrefUtil;
\r
29 public class HistoryActivity extends BaseActivity {
\r
30 public static final String PREF_HIS_YEAR = "HIS_YEAR";
\r
31 public static final String PREF_HIS_MONTH = "HIS_MONTH";
\r
32 public static final String PREF_HIS_DAY = "HIS_DAY";
\r
33 public static final String PREF_HIS_YMD_POS = "HIS_YMD_POS";
\r
35 public static final String PREF_HIS_ST_HOUR = "HIS_ST_HOUR";
\r
36 public static final String PREF_HIS_ST_MINUTE = "HIS_ST_MINUTE";
\r
37 public static final String PREF_HIS_EN_HOUR = "HIS_EN_HOUR";
\r
38 public static final String PREF_HIS_EN_MINUTE = "HIS_EN_MINUTE";
\r
40 public static final String PREF_HIS_UNIT = "HIS_UNIT";
\r
42 public static final int[] unit = { 10, 30, 60 };
\r
44 private TextView textView1;
\r
45 private EditPrefUtil pref = new EditPrefUtil(this);
\r
46 private HorizontalScrollView scrollView;
\r
50 private int prefYear;
\r
51 private int prefMonth;
\r
52 private int prefDay;
\r
53 private int prefYmdPos;
\r
54 private int prefUnit;
\r
56 private int prefStHour;
\r
57 private int prefStMinute;
\r
58 private int prefEnHour;
\r
59 private int prefEnMinute;
\r
61 private Date currentDate;
\r
64 public void onCreate(Bundle savedInstanceState) {
\r
65 super.onCreate(savedInstanceState);
\r
66 setContentView(R.layout.history);
\r
69 Button button1 = (Button) findViewById(R.id.button11);
\r
70 button1.setOnClickListener(new OnClickListener() {
\r
71 public void onClick(View view) {
\r
72 Intent intent = new Intent(HistoryActivity.this,
\r
73 (Class<?>) HistoryConfActivity.class);
\r
74 startActivityForResult(intent, -1);
\r
78 Button button2 = (Button) findViewById(R.id.button12);
\r
79 button2.setOnClickListener(new OnClickListener() {
\r
80 public void onClick(View view) {
\r
81 HistoryActivity.this.finish();
\r
85 textView1 = (TextView) findViewById(R.id.textView11);
\r
86 scrollView = (HorizontalScrollView) findViewById(R.id.scrollView11);
\r
88 spcv = (HistoryView) findViewById(R.id.spcv);
\r
89 // HistoryDao dao = HistoryDao.getInstance();
\r
90 // // List<History> list = dao.search(this);
\r
91 // Calendar cal = Calendar.getInstance();
\r
92 // Date date = cal.getTime();
\r
93 // int ymd = DateUtil.getYmd(date);
\r
94 // List<History> list = dao.search(this, ymd, DateUtil.HM_MIN,
\r
95 // DateUtil.HM_MAX);
\r
97 // DefaultCategoryDataset dataset = new DefaultCategoryDataset();
\r
98 // for (History history : list) {
\r
99 // int period = history.getPeriod();
\r
101 // if (period > 0) {
\r
103 // // val = history.getNum() * 60 / period;
\r
104 // val = history.getNum();
\r
106 // int hm = history.getHm();
\r
107 // String text = (hm / 100) + ":" + (hm % 100);
\r
108 // String route = "<none>";
\r
109 // switch (history.getRouteId()) {
\r
111 // route = "
\8b\9e\95l
\93\8c\96k
\90ü";
\r
114 // route = "
\93\8c\8aC
\93¹
\90ü";
\r
117 // route = "
\8b\9e\8b}
\90ü";
\r
120 // Debug.d(this, route + " " + text + " " + val);
\r
121 // dataset.setValue(val, route, text);
\r
124 // AFreeChart chart = ChartFactory.createLineChart("
\82Â
\82Ô
\82â
\82«
\97\9a\97ð", "
\8e\9e\8d\8f",
\r
125 // "
\82Â
\82Ô
\82â
\82«
\90\94(
\89ñ/
\8e\9e)", dataset, PlotOrientation.VERTICAL, true,
\r
128 // HistoryView spcv = (HistoryView) findViewById(R.id.spcv);
\r
129 // spcv.setChart(chart);
\r
130 } catch (Exception e) {
\r
132 Debug.d(this, null, e);
\r
138 public void onWindowFocusChanged(boolean hasFocus) {
\r
139 int width = scrollView.getWidth();
\r
140 int height = scrollView.getHeight();
\r
142 spcv.setMinimumWidth(width);
\r
143 spcv.setMinimumWidth(height);
\r
145 width = spcv.getWidth();
\r
146 height = spcv.getHeight();
\r
148 // TODO Auto-generated method stub
\r
149 super.onWindowFocusChanged(hasFocus);
\r
153 public void onConfigurationChanged(Configuration newConfig ) {
\r
154 int width = scrollView.getWidth();
\r
155 int height = scrollView.getHeight();
\r
157 super.onConfigurationChanged(newConfig);
\r
161 protected void onStart() {
\r
165 Calendar cal = Calendar.getInstance();
\r
166 Date date = cal.getTime();
\r
167 prefYear = pref.getInt(PREF_HIS_YEAR, date.getYear());
\r
168 prefMonth = pref.getInt(PREF_HIS_MONTH, date.getMonth());
\r
169 prefDay = pref.getInt(PREF_HIS_DAY, date.getDate());
\r
172 prefEnHour = pref.getInt(PREF_HIS_EN_HOUR, date.getHours());
\r
173 prefEnMinute = pref.getInt(PREF_HIS_EN_MINUTE, date.getMinutes());
\r
174 cal = Calendar.getInstance();
\r
175 cal.set(Calendar.HOUR_OF_DAY, prefEnHour);
\r
176 cal.set(Calendar.MINUTE, prefEnMinute);
\r
177 date = cal.getTime();
\r
178 cal.add(Calendar.HOUR, -H);
\r
179 Date startDate = cal.getTime();
\r
182 if (date.getDate() == startDate.getDate()) {
\r
183 hour = startDate.getHours();
\r
184 minute = startDate.getMinutes();
\r
186 prefStHour = pref.getInt(PREF_HIS_ST_HOUR, hour);
\r
187 prefStMinute = pref.getInt(PREF_HIS_ST_MINUTE, minute);
\r
190 prefYmdPos = pref.getInt(PREF_HIS_YMD_POS, M - 1);
\r
192 cal.add(Calendar.DATE, -(M - (prefYmdPos + 1)));
\r
193 currentDate = cal.getTime();
\r
195 prefUnit = pref.getInt(PREF_HIS_UNIT, 0);
\r
200 HistoryDao dao = HistoryDao.getInstance();
\r
201 // // List<History> list = dao.search(this);
\r
202 // Calendar cal = Calendar.getInstance();
\r
203 // Date date = cal.getTime();
\r
204 // int ymd = DateUtil.getYmd(date);
\r
206 // int ymd = (1900 + currentDate.getYear()) * 10000
\r
207 // + (currentDate.getMonth() + 1) * 100
\r
208 // + currentDate.getDate();
\r
209 // int from = prefStHour * 100 + prefStMinute;
\r
210 // int to = prefEnHour * 100 + prefEnMinute;
\r
211 int ymd = DateUtil.getYmd(currentDate.getYear(), currentDate.getMonth(), currentDate.getDate());
\r
212 int from = DateUtil.getHm(prefStHour, prefStMinute);
\r
213 int to = DateUtil.getHm(prefEnHour, prefEnMinute);
\r
214 List<History> list = dao.search(this, ymd, from, to);
\r
216 DefaultCategoryDataset dataset = new DefaultCategoryDataset();
\r
217 for (History history : list) {
\r
218 int period = history.getPeriod();
\r
222 // val = history.getNum() * 60 / period;
\r
223 val = history.getNum();
\r
225 int hm = history.getHm();
\r
227 //String text = (hm / 100) + ":" + (hm % 100);
\r
228 String text = DateUtil.formattedHm(hm);
\r
229 String route = "<none>";
\r
230 switch (history.getRouteId()) {
\r
232 route = "
\8b\9e\95l
\93\8c\96k
\90ü";
\r
235 route = "
\93\8c\8aC
\93¹
\90ü";
\r
238 route = "
\8b\9e\8b}
\90ü";
\r
241 Debug.d(this, route + " " + text + " " + val);
\r
242 dataset.setValue(val, route, text);
\r
245 AFreeChart chart = ChartFactory.createLineChart("
\82Â
\82Ô
\82â
\82«
\97\9a\97ð", "
\8e\9e\8d\8f",
\r
246 "
\82Â
\82Ô
\82â
\82«
\90\94(
\89ñ/
\8e\9e)", dataset, PlotOrientation.VERTICAL, true,
\r
249 HistoryView spcv = (HistoryView) findViewById(R.id.spcv);
\r
250 spcv.setChart(chart);
\r
252 String text = DateUtil.formattedDate(ymd, from, to);
\r
253 textView1.setText(text);
\r
255 } catch (Exception e) {
\r
257 Debug.d(this, null, e);
\r
261 public static void init(Context context) {
\r
262 EditPrefUtil pref = new EditPrefUtil(context);
\r
264 pref.remove(PREF_HIS_YEAR);
\r
265 pref.remove(PREF_HIS_MONTH);
\r
266 pref.remove(PREF_HIS_DAY);
\r
267 pref.remove(PREF_HIS_YMD_POS);
\r
269 pref.remove(PREF_HIS_ST_HOUR);
\r
270 pref.remove(PREF_HIS_ST_MINUTE);
\r
271 pref.remove(PREF_HIS_EN_HOUR);
\r
272 pref.remove(PREF_HIS_EN_MINUTE);
\r
274 pref.remove(PREF_HIS_UNIT);
\r