package com.td;
+import java.util.Calendar;
+import java.util.Iterator;
import java.util.List;
+import java.util.Set;
import android.app.AlarmManager;
import android.app.AlertDialog;
import android.widget.TextView;
import com.td.broadcast.DelayReceiver;
+import com.td.db.Keyword;
import com.td.db.Monitor;
import com.td.db.MonitorDao;
import com.td.db.Train;
import com.td.db.TrainDao;
import com.td.service.SchedulerTest;
+import com.td.service.TrainDelayedService;
import com.td.service.TrainDelayedServiceImpl;
+import com.td.service.TrainService;
+import com.td.service.TrainTwitterAdapterTest;
import com.td.utility.BaseActivity;
+import com.td.utility.Debug;
import com.td.utility.EditPrefUtil;
+import com.td.utility.StatusFlag;
+import com.td.utility.StatusFlagTest;
+import com.td.utility.StringMap;
+import com.td.wait.TrainServiceWaiting;
-public class TrainDelayedActivity extends BaseActivity {
+public class TrainDelayedActivity extends BaseActivity implements TrainDelayedService {
+ public static final String PREF_TRD_DELAY = "TRD_DELAY";
+ public static final String PREF_TRD_DELAY_MSG = "TRD_DELAY_MSG";
+
+ private TextView textView0;
private TextView textView1;
private Button button1;
private Button button2;
private Button button6;
private Button button7;
private Button button9;
+ private Button buttonz;
+ private LinearLayout linearLayout0;
private LinearLayout linearLayout1;
private LinearLayout linearLayout2;
private LinearLayout linearLayout3;
private int prefSvsStatus;
private boolean isClick = false;
- //private DelayReceiver receiver = new DelayReceiver(this);
+ // \88ê\82©\8f\8a\82É\92è\8b`\82µ\82½\82¢
+ // \8fC\90³ // TODO
+ //pref.put(TrainDelayedServiceImpl.PREF_SVS_STATUS
+ private StatusFlag tsSf = new StatusFlag(this,
+ TrainService.class.getName(), StatusFlag.TERM_30M);
+
private BroadcastReceiver receiver = new BroadcastReceiver(){
@Override
public void onReceive(Context context, Intent intent) {
else if (action.compareTo(DelayReceiver.STOP_SERVICE) == 0){
// \96¢\8eg\97p
}
+ else if (action.compareTo(DelayReceiver.UPDATE) == 0){
+ setStatus();
+ }
+ else if (action.compareTo(DelayReceiver.DELAY) == 0){
+ updateDelay(intent);
+
+ setStatus();
+ }
}
};
IntentFilter intentFilter = new IntentFilter();
intentFilter.addAction(DelayReceiver.START_SERVICE);
intentFilter.addAction(DelayReceiver.STOP_SERVICE);
+ intentFilter.addAction(DelayReceiver.UPDATE);
+ intentFilter.addAction(DelayReceiver.DELAY);
registerReceiver(receiver, intentFilter);
button1 = (Button) this.findViewById(R.id.button01);
button1.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
- Intent intent = new Intent("com.td.broadcast.DelayReceiver");
- intent.putExtra("TEXT", "\83T\83\93\83v\83\8b\83\81\83b\83Z\81[\83W");
- sendBroadcast(intent);
+ if (isClick){
+ return;
+ }
+ isClick = true;
- SchedulerTest.repeat(TrainDelayedActivity.this);
- SchedulerTest.main();
+ new AlertDialog.Builder(TrainDelayedActivity.this)
+ .setTitle(getString(R.string.warn_dialog_title))
+ .setMessage(getString(R.string.update_route_qmsg))
+ .setPositiveButton(getString(R.string.yes_button), new DialogInterface.OnClickListener() {
+ public void onClick(DialogInterface dialog, int whichButton) {
+ tsSf.setOn();
+
+ Intent intent = new Intent(TrainDelayedActivity.this,
+ (Class<?>) WaitActivity.class);
+ intent.putExtra(WaitActivity.CLASS,
+ TrainServiceWaiting.class.getName());
+ intent.putExtra(WaitActivity.MESSAGE1,
+ getString(R.string.start_rouote_msg));
+ intent.putExtra(WaitActivity.MESSAGE2,
+ getString(R.string.end_rouote_msg));
+ intent.putExtra(WaitActivity.MESSAGE3,
+ "");
+
+ WaitActivity.init(TrainDelayedActivity.this);
+ startActivityForResult(intent, -1);
+
+ isClick = false;
+ }
+ })
+ .setNegativeButton(getString(R.string.cancel_button), new DialogInterface.OnClickListener() {
+ public void onClick(DialogInterface dialog, int whichButton) {
+ isClick = false;
+ }
+ })
+ .create().show();
}});
button2 = (Button) this.findViewById(R.id.button02);
button2.setOnClickListener(new OnClickListener() {
public void onClick(View view) {
Intent intent = new Intent(TrainDelayedActivity.this,
- (Class<?>) TrainListActivity.class);
+ (Class<?>) PrefectureListActivity.class);
startActivityForResult(intent, -1);
}
});
return;
}
isClick = true;
+
new AlertDialog.Builder(TrainDelayedActivity.this)
.setTitle(getString(R.string.warn_dialog_title))
.setMessage(getString(R.string.start_service_qmsg))
return;
}
isClick = true;
- // TODO
- //HistoryDao.getInstance().delete(TrainDelayedActivity.this);
new AlertDialog.Builder(TrainDelayedActivity.this)
.setTitle(getString(R.string.warn_dialog_title))
button7.setOnClickListener(new OnClickListener() {
public void onClick(View view) {
Intent intent = new Intent(TrainDelayedActivity.this,
- (Class<?>)SearchWordActivity.class);
+ (Class<?>)ConfActivity.class);
startActivityForResult(intent, -1);
}
});
}
});
+// buttonf = (Button) this.findViewById(R.id.button0f);
+// buttonf.setOnClickListener(new OnClickListener() {
+// public void onClick(View view) {
+// // TODO \83_\83C\83A\83\8d\83O\82Å\8am\94F
+// initizlize();
+// }
+// });
+
+ buttonz = (Button) this.findViewById(R.id.button0z);
+ buttonz.setOnClickListener(new OnClickListener() {
+ public void onClick(View view) {
+ debug();
+ }
+ });
+ if (!Debug.isDebug()){
+ buttonz.setVisibility(View.GONE);
+ }
+
+ linearLayout0 = (LinearLayout) this.findViewById(R.id.linearLayout00);
linearLayout1 = (LinearLayout) this.findViewById(R.id.linearLayout01);
linearLayout2 = (LinearLayout) this.findViewById(R.id.linearLayout02);
linearLayout3 = (LinearLayout) this.findViewById(R.id.linearLayout03);
linearLayout7 = (LinearLayout) this.findViewById(R.id.linearLayout07);
linearLayout9 = (LinearLayout) this.findViewById(R.id.linearLayout09);
+ textView0 = (TextView) this.findViewById(R.id.textView00);
textView1 = (TextView) this.findViewById(R.id.textView01);
+
+ // TODO
+ linearLayout0.setVisibility(View.GONE);
}
@Override
+ protected void onDestroy() {
+ if (receiver != null){
+ unregisterReceiver(receiver);
+ }
+
+ super.onDestroy();
+ }
+
+ @Override
protected void onStart() {
super.onStart();
setStatus();
}
+ public void updateDelay(Intent intent){
+ StringMap map = new StringMap();
+ String data = pref.get(PREF_TRD_DELAY);
+ if (data != null){
+ map.setData(data);
+ }
+ Calendar cal = Calendar.getInstance();
+ long t = cal.getTimeInMillis();
+
+ long id = intent.getLongExtra("ID", -1);
+ map.put(String.valueOf(id), String.valueOf(t));
+
+ data = map.getData();
+ pref.put(PREF_TRD_DELAY, data);
+ pref.update();
+ }
+
+ public boolean updateDelayMsg(){
+ Calendar cal = Calendar.getInstance();
+ long t = cal.getTimeInMillis();
+
+ return updateDelayMsg(t);
+ }
+
+ public boolean updateDelayMsg(long t){
+ StringMap map = new StringMap();
+ String data = pref.get(PREF_TRD_DELAY);
+ if (data != null){
+ map.setData(data);
+ }
+
+ Set<String> ks = map.keySet();
+ for (Iterator<String> it = ks.iterator(); it.hasNext(); ){
+ String key = it.next();
+ String value = map.get(key);
+ long dt = Long.valueOf(value);
+
+ if (t - dt > 5 * 60 * 1000){ // 5\95ª
+ map.remove(key);
+ }
+ }
+
+ StringBuffer sb = new StringBuffer();
+ TrainDao dao = TrainDao.getInstance();
+ for (Iterator<String> it = ks.iterator(); it.hasNext(); ){
+ String key = it.next();
+
+ long id = Long.valueOf(key);
+ Train train = dao.searchById(id);
+ if (train != null){
+ if (sb.length() > 0){
+ sb.append("\81A");
+ }
+ sb.append(train.getName());
+ }
+ }
+ if (sb.length() > 0){
+ sb.append("\82ª\92x\89\84\82µ\82Ä\82¢\82é\82©\82à\82µ\82ê\82Ü\82¹\82ñ\81B\8fÚ\8d×\82Í\81A\97\9a\97ð\82ð\8eQ\8fÆ\82µ\82Ä\82\82¾\82³\82¢");
+
+ String text = sb.toString();
+ pref.put(PREF_TRD_DELAY_MSG, text);
+
+ textView0.setTag(text);
+
+ return true;
+ }
+ else {
+ pref.remove(PREF_TRD_DELAY_MSG);
+ return false;
+ }
+
+ }
+
private void setStatus() {
String text = "";
prefSvsStatus = pref.getInt(TrainDelayedServiceImpl.PREF_SVS_STATUS, 0);
boolean enabled9 = true;
int c0 = Color.rgb(0xff, 0xff, 0xff);
- int c1 = Color.rgb(0xff, 0x33, 0x33);
+ int c1 = Color.rgb(0xcc, 0x33, 0x33);
int color1 = c0;
int color2 = c0;
int color3 = c0;
int msgNo = -1;
+ if (tsSf.isOn()){
+ enabled1 = false;
+ enabled2 = false;
+ enabled3 = false;
+ enabled4 = false;
+ enabled5 = false;
+ enabled6 = false;
+ enabled7 = false;
+ msgNo = 0;
+ }
+
+ int count = TrainDao.getInstance().count();
+ if (count <= 0){
+ enabled2 = false;
+ enabled3 = false;
+ enabled4 = false;
+ enabled5 = false;
+ enabled6 = false;
+ enabled7 = false;
+ msgNo = 1;
+ }
+
List<Train> trainList = TrainDao.getInstance().search(true);
int trainCount = trainList.size();
if (trainCount == 0){
enabled5 = false;
break;
case 1:
+ msgNo = (msgNo < 0)? 5 : msgNo;
+ enabled1 = false;
+ enabled2 = false;
+ enabled3 = false;
enabled4 = false;
enabled5 = false;
+ enabled6 = false;
+ enabled7 = false;
break;
case 2:
enabled4 = false;
button9.setEnabled(enabled9);
switch (msgNo){
+ case 0:
+ // TODO
+ text = "\98H\90ü\82Ì\8fî\95ñ\82ð\8dX\90V\82µ\82Ä\82¢\82Ü\82·";
+ break;
+ case 1:
+ text = getString(R.string.update_route_msg);
+ color1 = c1;
+ break;
case 2:
text = getString(R.string.conf_route_msg);
color2 = c1;
text = getString(R.string.start_service_msg);
color4 = c1;
break;
+ case 5:
+ text = getString(R.string.starting_service_msg);
+ break;
default:
if (trainCount > 0){
StringBuffer sb = new StringBuffer();
break;
}
+ boolean msgFlag = updateDelayMsg();
+ if (msgFlag){
+ linearLayout0.setVisibility(View.VISIBLE);
+ color6 = c1;
+ }
+ else {
+ linearLayout0.setVisibility(View.GONE);
+ }
+
textView1.setText(text);
linearLayout1.setBackgroundColor(color1);
linearLayout2.setBackgroundColor(color2);
linearLayout7.setBackgroundColor(color7);
linearLayout9.setBackgroundColor(color9);
}
+
+ private void debug(){
+ int n = 7;
+
+ switch (n){
+ case 1:
+ // \83T\81[\83r\83X\83t\83\89\83O\83N\83\8a\83A
+ pref.put(TrainDelayedServiceImpl.PREF_SVS_STATUS, 0);
+ pref.update();
+ setStatus();
+ break;
+ case 2:
+ // \83X\83P\83W\83\85\81[\83\8b\82Ì\83e\83X\83g
+ SchedulerTest.repeat(TrainDelayedActivity.this);
+ SchedulerTest.main();
+ break;
+ case 3:
+ // \83u\83\8d\81[\83h\83L\83\83\83X\83g
+ Intent intent = new Intent("com.td.broadcast.DelayReceiver");
+ intent.putExtra("TEXT", "\83T\83\93\83v\83\8b\83\81\83b\83Z\81[\83W");
+ sendBroadcast(intent);
+ break;
+ case 4:
+ // StatusFlag\82Ì\83e\83X\83g
+ StatusFlagTest.main(this);
+ break;
+ case 5:
+ tsSf.setOff();
+ break;
+ case 6:
+ TrainTwitterAdapterTest.main(this);
+ break;
+ case 7:
+ TrainDelayedActivityTest.main(this);
+ break;
+ default:
+ break;
+ }
+ }
+
+ public Context getContext() {
+ return this;
+ }
+
+ public List<Train> getTrains() {
+ return null;
+ }
+
+ public List<Keyword> getKeywords() {
+ return null;
+ }
+
+ public void notificate(String name) {
+
+ }
}
\ No newline at end of file