• R/O
  • SSH
  • HTTPS

nikocale: Commit


Commit MetaInfo

Revision312 (tree)
Zeit2011-01-16 18:59:19
Autortakezoe

Log Message

自動で同期するようにしてみた。

Ändern Zusammenfassung

Diff

--- nikocale_android/trunk/nikocale_android/src/jp/sf/amateras/nikocale/android/MainActivity.java (revision 311)
+++ nikocale_android/trunk/nikocale_android/src/jp/sf/amateras/nikocale/android/MainActivity.java (revision 312)
@@ -8,10 +8,8 @@
88 import jp.sf.amateras.nikocale.android.util.DialogUtils;
99 import jp.sf.amateras.nikocale.android.util.NikocaleDao;
1010 import jp.sf.amateras.nikocale.android.util.SyncTask;
11-import jp.sf.amateras.nikocale.android.util.SyncTask.SyncParam;
1211 import android.app.Activity;
1312 import android.content.Intent;
14-import android.content.SharedPreferences;
1513 import android.os.Bundle;
1614 import android.view.Menu;
1715 import android.view.MenuItem;
@@ -98,26 +96,11 @@
9896 @Override
9997 public void onStart(){
10098 super.onStart();
99+
101100 if(MainActivity.sync){
102101 MainActivity.sync = false;
102+ SyncTask.execute(this, year, month, false);
103103
104- SharedPreferences pref = getSharedPreferences("nikocale", MODE_PRIVATE);
105- String mailAddress = pref.getString(ConfigActivity.CONFIG_MAILADDRESS, "");
106- String password = pref.getString(ConfigActivity.CONFIG_PASSWORD, "");
107-
108- if(mailAddress.length() == 0 || password.length() == 0){
109- refleshList();
110- return ;
111- }
112-
113- SyncTask task = new SyncTask(this);
114- SyncParam param = new SyncParam();
115- param.mailAddress = mailAddress;
116- param.password = password;
117- param.year = year;
118- param.month = month;
119- task.execute(param);
120-
121104 } else {
122105 refleshList();
123106 }
@@ -162,22 +145,8 @@
162145 startActivity(intent);
163146
164147 } else if(item.getItemId() == Constants.MENU_SYNC){
165- SharedPreferences pref = getSharedPreferences("nikocale", MODE_PRIVATE);
166- String mailAddress = pref.getString(ConfigActivity.CONFIG_MAILADDRESS, "");
167- String password = pref.getString(ConfigActivity.CONFIG_PASSWORD, "");
148+ SyncTask.execute(this, year, month, true);
168149
169- if(mailAddress.length() == 0 || password.length() == 0){
170- DialogUtils.showDialog("同期の設定が行われていません。", this);
171- return true;
172- }
173-
174- SyncTask task = new SyncTask(this);
175- SyncParam param = new SyncParam();
176- param.mailAddress = mailAddress;
177- param.password = password;
178- param.year = year;
179- param.month = month;
180- task.execute(param);
181150 }
182151 return true;
183152 }
--- nikocale_android/trunk/nikocale_android/src/jp/sf/amateras/nikocale/android/CalendarActivity.java (revision 311)
+++ nikocale_android/trunk/nikocale_android/src/jp/sf/amateras/nikocale/android/CalendarActivity.java (revision 312)
@@ -7,6 +7,7 @@
77
88 import jp.sf.amateras.nikocale.android.util.DialogUtils;
99 import jp.sf.amateras.nikocale.android.util.NikocaleDao;
10+import jp.sf.amateras.nikocale.android.util.SyncTask;
1011 import android.app.Activity;
1112 import android.content.Intent;
1213 import android.graphics.Bitmap;
@@ -15,6 +16,7 @@
1516 import android.os.Bundle;
1617 import android.view.MotionEvent;
1718 import android.view.View;
19+import android.view.Window;
1820 import android.view.View.OnClickListener;
1921 import android.view.View.OnTouchListener;
2022 import android.widget.Button;
@@ -42,6 +44,7 @@
4244 @Override
4345 public void onCreate(Bundle savedInstanceState) {
4446 super.onCreate(savedInstanceState);
47+ requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
4548 setContentView(R.layout.calendar);
4649
4750 Calendar cal = Calendar.getInstance();
@@ -55,7 +58,7 @@
5558 Calendar cal = Calendar.getInstance();
5659 year = cal.get(Calendar.YEAR);
5760 month = cal.get(Calendar.MONTH) + 1;
58- refleshCalendar(false);
61+ refleshCalendar();
5962 }
6063 });
6164
@@ -68,7 +71,7 @@
6871 month = 12;
6972 year = year - 1;
7073 }
71- refleshCalendar(false);
74+ refleshCalendar();
7275 }
7376 });
7477
@@ -82,7 +85,7 @@
8285 month = 1;
8386 year = year + 1;
8487 }
85- refleshCalendar(false);
88+ refleshCalendar();
8689 }
8790 });
8891
@@ -93,13 +96,20 @@
9396 bad32_normal = BitmapFactory.decodeResource(getResources(), R.drawable.bad32);
9497 bad32_comment = BitmapFactory.decodeResource(getResources(), R.drawable.bad32_comment);
9598
96- refleshCalendar(false);
99+ refleshCalendar();
97100 }
98101
99102 @Override
100103 public void onStart(){
101104 super.onStart();
102- refleshCalendar(true);
105+
106+ if(MainActivity.sync){
107+ MainActivity.sync = false;
108+ SyncTask.execute(this, year, month, false);
109+
110+ } else {
111+ refleshCalendar();
112+ }
103113 }
104114
105115
@@ -246,7 +256,7 @@
246256 /**
247257 * マイニコカレを更新します。
248258 */
249- public void refleshCalendar(boolean reload) {
259+ public void refleshCalendar() {
250260 try {
251261 List<Map<String, Object>> data = NikocaleDao.getEntries(year, month);
252262 setData(data);
--- nikocale_android/trunk/nikocale_android/src/jp/sf/amateras/nikocale/android/util/SyncTask.java (revision 311)
+++ nikocale_android/trunk/nikocale_android/src/jp/sf/amateras/nikocale/android/util/SyncTask.java (revision 312)
@@ -6,10 +6,13 @@
66 import java.util.List;
77 import java.util.Map;
88
9+import jp.sf.amateras.nikocale.android.CalendarActivity;
10+import jp.sf.amateras.nikocale.android.ConfigActivity;
911 import jp.sf.amateras.nikocale.android.MainActivity;
1012 import jp.sf.amateras.nikocale.android.util.SyncTask.SyncParam;
1113 import net.arnx.jsonic.JSON;
1214 import android.app.Activity;
15+import android.content.SharedPreferences;
1316 import android.os.AsyncTask;
1417
1518 public class SyncTask extends AsyncTask<SyncParam, Integer, Void> {
@@ -28,6 +31,38 @@
2831 this.activity = activity;
2932 }
3033
34+ public static void execute(Activity activity, int year, int month, boolean showErrorDialog){
35+ refreshActivity(activity);
36+
37+ SharedPreferences pref = activity.getSharedPreferences("nikocale", Activity.MODE_PRIVATE);
38+ String mailAddress = pref.getString(ConfigActivity.CONFIG_MAILADDRESS, "");
39+ String password = pref.getString(ConfigActivity.CONFIG_PASSWORD, "");
40+
41+ if(mailAddress.length() == 0 || password.length() == 0){
42+ if(showErrorDialog){
43+ DialogUtils.showDialog("同期の設定が行われていません。", activity);
44+ }
45+ return;
46+ }
47+
48+ SyncTask task = new SyncTask(activity);
49+ SyncParam param = new SyncParam();
50+ param.mailAddress = mailAddress;
51+ param.password = password;
52+ param.year = year;
53+ param.month = month;
54+ task.execute(param);
55+ }
56+
57+ private static void refreshActivity(Activity activity){
58+ if(activity instanceof MainActivity){
59+ ((MainActivity) activity).refleshList();
60+
61+ } else if(activity instanceof CalendarActivity){
62+ ((CalendarActivity) activity).refleshCalendar();
63+ }
64+ }
65+
3166 @Override
3267 protected void onPreExecute() {
3368 activity.setProgressBarIndeterminateVisibility(true);
@@ -36,11 +71,7 @@
3671 @Override
3772 protected void onPostExecute(Void result) {
3873 activity.setProgressBarIndeterminateVisibility(false);
39-
40- // 画面をリフレッシュ
41- if(activity instanceof MainActivity){
42- ((MainActivity) activity).refleshList();
43- }
74+ refreshActivity(activity);
4475 }
4576
4677 @Override
Show on old repository browser