• R/O
  • SSH
  • HTTPS

observoice: Commit


Commit MetaInfo

Revision279 (tree)
Zeit2012-10-24 16:21:26
Autoruchan_nos

Log Message

merge 29891-networkconfig into trunk

Ändern Zusammenfassung

Diff

--- trunk/ov-client/observoice/src/jp/sourceforge/observoice/ReviewLectureActivity.java (revision 278)
+++ trunk/ov-client/observoice/src/jp/sourceforge/observoice/ReviewLectureActivity.java (revision 279)
@@ -15,10 +15,12 @@
1515 import jp.sourceforge.observoice.entity.Comment;
1616 import jp.sourceforge.observoice.entity.WatchingCourseInfo;
1717 import jp.sourceforge.observoice.exception.ObsvException;
18+import jp.sourceforge.observoice.network.RequestConfiguration;
1819 import jp.sourceforge.observoice.network.response.CommentListResponse;
1920 import jp.sourceforge.observoice.network.response.ObsvResponseObject;
2021 import jp.sourceforge.observoice.network.task.GetCommentListTask;
2122 import jp.sourceforge.observoice.network.task.ObsvNetworkListener;
23+import jp.sourceforge.observoice.util.Util;
2224 import roboguice.activity.RoboActivity;
2325 import roboguice.inject.InjectExtra;
2426 import roboguice.inject.InjectView;
@@ -35,7 +37,7 @@
3537
3638 /**
3739 * 復習画面
38- *
40+ *
3941 * @author torikawa
4042 * @author rtakizawa
4143 */
@@ -49,7 +51,7 @@
4951 private WatchingCourseInfo mReviewLecture;
5052
5153 private int mCourceId;
52-
54+
5355 private Context mContext;
5456
5557 /**
@@ -64,11 +66,15 @@
6466
6567 private ReviewLecturePagerAdapter mPagerAdapter;
6668
69+ private RequestConfiguration mRequestConfiguration;
70+
6771 @Override
6872 protected void onCreate(Bundle savedInstanceState) {
6973 super.onCreate(savedInstanceState);
7074 this.setContentView(R.layout.review_lecture);
71-
75+
76+ mRequestConfiguration = RequestConfiguration.load(Util.getObsvSharedPreferences(this));
77+
7278 mContext = this;
7379
7480 mCourceId = mReviewLecture.getCourse().getCourceId();
@@ -76,7 +82,7 @@
7682
7783 mPagerAdapter = new ReviewLecturePagerAdapter(
7884 (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE));
79- mViewPager.setAdapter(mPagerAdapter);
85+ mViewPager.setAdapter(mPagerAdapter);
8086 }
8187
8288 @Override
@@ -86,7 +92,7 @@
8692 //TODO:
8793 // 10000件でたぶん全部とれるけどあんまりよくないし、コメントまでとってくるので無駄。
8894 // いずれ別のAPI(コメント投稿日付リストAPI)みたいなのに置き換わる予定。
89- GetCommentListTask task = new GetCommentListTask(mCourceId, 10000, null, null);
95+ GetCommentListTask task = new GetCommentListTask(mRequestConfiguration, mCourceId, 10000, null, null);
9096 task.setListener(new ObsvNetworkListener() {
9197
9298 @Override
@@ -110,7 +116,7 @@
110116
111117 /**
112118 * レスポンスのコメントリストからcommentMapへのマップを作成
113- *
119+ *
114120 * @param responseComments
115121 */
116122 private void mapComments(List<Comment> responseComments) {
@@ -130,7 +136,7 @@
130136
131137 /**
132138 * コメントリストから日付のリストをもつアダプターを作成する
133- *
139+ *
134140 * @return
135141 */
136142 private ArrayAdapter<String> createCommentDatesAdapter() {
@@ -149,7 +155,7 @@
149155
150156 /**
151157 * Calendarから日付の文字列表現を得る
152- *
158+ *
153159 * @param cal
154160 * @return
155161 */
@@ -156,16 +162,16 @@
156162 private String getDateString(Calendar cal) {
157163 return mFormat.format(cal.getTime());
158164 }
159-
165+
160166 /**
161167 * 日付選択ドロップダウンのリスナー
162- *
168+ *
163169 * @author rtakizawa
164170 */
165171 private class DaySelectorListener implements AdapterView.OnItemSelectedListener {
166-
172+
167173 private Context mContext;
168-
174+
169175 public DaySelectorListener(Context context) {
170176 mContext = context;
171177 }
@@ -182,7 +188,7 @@
182188 @Override
183189 public void onNothingSelected(AdapterView<?> arg0) {
184190 }
185-
191+
186192 }
187193
188194 }
--- trunk/ov-client/observoice/src/jp/sourceforge/observoice/DebugActivity.java (revision 278)
+++ trunk/ov-client/observoice/src/jp/sourceforge/observoice/DebugActivity.java (revision 279)
@@ -8,6 +8,7 @@
88 import jp.sourceforge.observoice.debugactivity.DebugMenu;
99 import jp.sourceforge.observoice.debugactivity.NetworkTaskDebugMenu;
1010 import jp.sourceforge.observoice.exception.ObsvException;
11+import jp.sourceforge.observoice.network.RequestConfiguration;
1112 import jp.sourceforge.observoice.network.response.ObsvResponseObject;
1213 import jp.sourceforge.observoice.network.task.GetAccountTask;
1314 import jp.sourceforge.observoice.network.task.GetCommentListTask;
@@ -18,6 +19,7 @@
1819 import jp.sourceforge.observoice.network.task.ObsvNetworkListener;
1920 import jp.sourceforge.observoice.network.task.PostCommentTask;
2021 import jp.sourceforge.observoice.util.ObsvSetting;
22+import jp.sourceforge.observoice.util.Util;
2123 import roboguice.activity.RoboActivity;
2224 import roboguice.inject.InjectView;
2325 import android.content.Intent;
@@ -51,15 +53,25 @@
5153 private TextView responseView;
5254
5355 public DebugActivity() {
56+ this.debugMenuList = new ArrayList<DebugMenu>();
57+ }
58+
59+ @Override
60+ protected void onCreate(Bundle savedInstanceState) {
61+ super.onCreate(savedInstanceState);
62+ setContentView(R.layout.debug);
63+
64+ RequestConfiguration reqconf = RequestConfiguration.load(Util.getObsvSharedPreferences(this));
65+
5466 // ネットワークAPIを叩くだけの簡単なデバッグ項目はここへ追加する。
5567 final List<NetworkTaskDebugMenu> debugMenuListOfNetwork = Arrays.asList(
56- new NetworkTaskDebugMenu(new GetLectureInfoListTask(COUNT), R.string.get_courses),
57- new NetworkTaskDebugMenu(new GetCommentListTask(COURSE_ID), R.string.get_comments),
58- new NetworkTaskDebugMenu(new GetLectureInfoTask(COURSE_ID), R.string.get_course),
59- new NetworkTaskDebugMenu(new GetCurrentLectureInfoListTask(), R.string.get_current_courses),
60- new NetworkTaskDebugMenu(new PostCommentTask(COURSE_ID, USER_ID, TYPE, CONTENT), R.string.post_comment),
61- new NetworkTaskDebugMenu(new GetWatchingCoursesTask(), R.string.get_watching_courses),
62- new NetworkTaskDebugMenu(new GetAccountTask(), R.string.get_account)
68+ new NetworkTaskDebugMenu(new GetLectureInfoListTask(reqconf, COUNT), R.string.get_courses),
69+ new NetworkTaskDebugMenu(new GetCommentListTask(reqconf, COURSE_ID), R.string.get_comments),
70+ new NetworkTaskDebugMenu(new GetLectureInfoTask(reqconf, COURSE_ID), R.string.get_course),
71+ new NetworkTaskDebugMenu(new GetCurrentLectureInfoListTask(reqconf), R.string.get_current_courses),
72+ new NetworkTaskDebugMenu(new PostCommentTask(reqconf, COURSE_ID, USER_ID, TYPE, CONTENT), R.string.post_comment),
73+ new NetworkTaskDebugMenu(new GetWatchingCoursesTask(reqconf), R.string.get_watching_courses),
74+ new NetworkTaskDebugMenu(new GetAccountTask(reqconf), R.string.get_account)
6375 );
6476 // インテントを投げるだけの簡単なデバッグ項目はここへ追加する。
6577 final List<ActivityDebugMenu> debugMenuListOfActivity = Arrays.asList(
@@ -73,7 +85,7 @@
7385 }
7486
7587 // デバッグ項目リストへすべてのデバッグ項目を追加する。
76- this.debugMenuList = new ArrayList<DebugMenu>(debugMenuListOfNetwork);
88+ this.debugMenuList.addAll(debugMenuListOfNetwork);
7789 this.debugMenuList.addAll(debugMenuListOfActivity);
7890 this.debugMenuList.add(new DebugMenu(R.string.restart) {
7991 @Override
@@ -89,13 +101,7 @@
89101 loadApiKey();
90102 }
91103 });
92- }
93104
94- @Override
95- protected void onCreate(Bundle savedInstanceState) {
96- super.onCreate(savedInstanceState);
97- setContentView(R.layout.debug);
98-
99105 responseView.setKeyListener(null);
100106 loadApiKey();
101107 }
--- trunk/ov-client/observoice/src/jp/sourceforge/observoice/ChartEngineTestActivity.java (revision 278)
+++ trunk/ov-client/observoice/src/jp/sourceforge/observoice/ChartEngineTestActivity.java (revision 279)
@@ -15,6 +15,8 @@
1515
1616 import android.widget.LinearLayout;
1717
18+import jp.sourceforge.observoice.network.RequestConfiguration;
19+import jp.sourceforge.observoice.util.Util;
1820 import jp.sourceforge.observoice.util.WidgetUtil;
1921
2022 import roboguice.activity.RoboFragmentActivity;
@@ -38,7 +40,8 @@
3840 mChartFragment = (UnderstandabilityChartFragment)
3941 getSupportFragmentManager().findFragmentById(R.id.chart_engine_test_chart_fragment);
4042
41- mCommentGetter = new CommentListIntervalGetter(1, new Handler());
43+ mCommentGetter = new CommentListIntervalGetter(1, new Handler(),
44+ RequestConfiguration.load(Util.getObsvSharedPreferences(this)));
4245 mCommentGetter.addOnReceivedListener(this);
4346 }
4447
--- trunk/ov-client/observoice/src/jp/sourceforge/observoice/LectureSearchActivity.java (revision 278)
+++ trunk/ov-client/observoice/src/jp/sourceforge/observoice/LectureSearchActivity.java (revision 279)
@@ -6,11 +6,13 @@
66 import jp.sourceforge.observoice.adapter.SearchedLectureListAdapter;
77 import jp.sourceforge.observoice.entity.Course;
88 import jp.sourceforge.observoice.exception.ObsvException;
9+import jp.sourceforge.observoice.network.RequestConfiguration;
910 import jp.sourceforge.observoice.network.response.LectureInfoListResponse;
1011 import jp.sourceforge.observoice.network.response.ObsvResponseObject;
1112 import jp.sourceforge.observoice.network.task.GetLectureInfoListTask;
1213 import jp.sourceforge.observoice.network.task.ObsvNetworkListener;
1314 import jp.sourceforge.observoice.network.task.ObsvNetworkTask;
15+import jp.sourceforge.observoice.util.Util;
1416 import roboguice.activity.RoboActivity;
1517 import roboguice.inject.InjectView;
1618 import android.app.AlertDialog;
@@ -56,11 +58,15 @@
5658 java.util.Calendar.TUESDAY, java.util.Calendar.WEDNESDAY, java.util.Calendar.THURSDAY,
5759 java.util.Calendar.FRIDAY, java.util.Calendar.SATURDAY, java.util.Calendar.SUNDAY };
5860
61+ private RequestConfiguration mRequestConfiguration;
62+
5963 @Override
6064 protected void onCreate(Bundle savedInstanceState) {
6165 super.onCreate(savedInstanceState);
6266 setContentView(R.layout.lecture_search);
6367
68+ mRequestConfiguration = RequestConfiguration.load(Util.getObsvSharedPreferences(this));
69+
6470 searchButton.setOnClickListener(this);
6571
6672 // エンター押下で検索実行
@@ -101,8 +107,8 @@
101107
102108 // 講義情報一覧取得を表すオブジェクトを作成。
103109 // 検索したくない項目には 0 または空文字列を指定すれば、その項目では絞りこまなくなる
104- ObsvNetworkTask getLectureInfos = new GetLectureInfoListTask(100,
105- CALENDAR_DAY_OF_WEEK[dayOfWeekSelected], periodToSearch, freeWord);
110+ ObsvNetworkTask getLectureInfos = new GetLectureInfoListTask(mRequestConfiguration,
111+ 100, CALENDAR_DAY_OF_WEEK[dayOfWeekSelected], periodToSearch, freeWord);
106112
107113 // 自分自身
108114 final LectureSearchActivity self = this;
--- trunk/ov-client/observoice/src/jp/sourceforge/observoice/network/RequestConfiguration.java (nonexistent)
+++ trunk/ov-client/observoice/src/jp/sourceforge/observoice/network/RequestConfiguration.java (revision 279)
@@ -0,0 +1,53 @@
1+package jp.sourceforge.observoice.network;
2+
3+import java.net.InetSocketAddress;
4+
5+import android.content.SharedPreferences;
6+import android.util.Log;
7+
8+/**
9+ * APIリクエストの送信先情報などを格納する
10+ * @author uchan_nos
11+ *
12+ */
13+public class RequestConfiguration {
14+ private InetSocketAddress host;
15+ private String apiBasePath;
16+ private String apiKey;
17+
18+ public InetSocketAddress getHost() {
19+ return host;
20+ }
21+ public void setHost(InetSocketAddress host) {
22+ this.host = host;
23+ }
24+ public String getApiBasePath() {
25+ return apiBasePath;
26+ }
27+ public void setApiBasePath(String apiBasePath) {
28+ this.apiBasePath = apiBasePath;
29+ }
30+ public String getApiKey() {
31+ return apiKey;
32+ }
33+ public void setApiKey(String apiKey) {
34+ this.apiKey = apiKey;
35+ }
36+
37+ /**
38+ * 指定されたSharedPreferencesから値を読み取り、RequestConfigurationを生成して返す.
39+ * @param pref 設定読み取り元のSharedPreferences
40+ * @return SharedPreferencesの設定値およびデフォルト値で初期化されたリクエスト設定
41+ */
42+ public static RequestConfiguration load(SharedPreferences pref) {
43+ RequestConfiguration conf = new RequestConfiguration();
44+ conf.setHost(InetSocketAddress.createUnresolved(
45+ pref.getString("HOST_NAME", "localhost"),
46+ pref.getInt("HOST_PORT", 8080)));
47+ conf.setApiBasePath(pref.getString("API_BASE_PATH", "/api"));
48+ conf.setApiKey(pref.getString("API_KEY", ""));
49+
50+ Log.d("obsv", "API_KEY is " + conf.getApiKey());
51+ return conf;
52+ }
53+}
Added: svn:mime-type
## -0,0 +1 ##
+text/plain
\ No newline at end of property
--- trunk/ov-client/observoice/src/jp/sourceforge/observoice/network/task/GetAccountTask.java (revision 278)
+++ trunk/ov-client/observoice/src/jp/sourceforge/observoice/network/task/GetAccountTask.java (revision 279)
@@ -1,15 +1,20 @@
11 package jp.sourceforge.observoice.network.task;
22
3+import jp.sourceforge.observoice.network.RequestConfiguration;
34 import jp.sourceforge.observoice.network.requestmethod.GetAccountMethod;
45 import jp.sourceforge.observoice.network.requestmethod.ObsvRequestMethod;
56
67 /**
78 * アカウントタスク
8- *
9+ *
910 * @author rtakizawa
1011 */
1112 public class GetAccountTask extends ObsvNetworkTask {
1213
14+ public GetAccountTask(RequestConfiguration requestConfiguration) {
15+ super(requestConfiguration);
16+ }
17+
1318 @Override
1419 protected ObsvRequestMethod createRequestMethod() {
1520 return new GetAccountMethod();
--- trunk/ov-client/observoice/src/jp/sourceforge/observoice/network/task/GetCommentListTask.java (revision 278)
+++ trunk/ov-client/observoice/src/jp/sourceforge/observoice/network/task/GetCommentListTask.java (revision 279)
@@ -1,12 +1,14 @@
11 package jp.sourceforge.observoice.network.task;
22
33 import java.util.Calendar;
4+
5+import jp.sourceforge.observoice.network.RequestConfiguration;
46 import jp.sourceforge.observoice.network.requestmethod.ObsvRequestMethod;
57 import jp.sourceforge.observoice.network.requestmethod.GetCommentListMethod;
68
79 /**
810 * courceIdの講義のコメントリストを取得する操作
9- *
11+ *
1012 * @author rtakizawa
1113 */
1214 public class GetCommentListTask extends ObsvNetworkTask {
@@ -18,10 +20,13 @@
1820 /**
1921 * デフォルト設定
2022 * 現在時刻の90分前から現在までのコメントを100件まで取得
21- *
23+ *
2224 * @param courceId 講義ID
2325 */
24- public GetCommentListTask(int courceId) {
26+ public GetCommentListTask(RequestConfiguration requestConfiguration,
27+ int courceId) {
28+ super(requestConfiguration);
29+
2530 this.courceId = courceId;
2631 this.count = 100;
2732 this.since = Calendar.getInstance();
@@ -35,7 +40,10 @@
3540 * @param since この日時以降のコメントを取得 (nullなら指定なし)
3641 * @param until この日時以前のコメントを取得 (nullなら指定なし)
3742 */
38- public GetCommentListTask(int courceId, int count, Calendar since, Calendar until) {
43+ public GetCommentListTask(RequestConfiguration requestConfiguration,
44+ int courceId, int count, Calendar since, Calendar until) {
45+ super(requestConfiguration);
46+
3947 this.courceId = courceId;
4048 this.count = count;
4149 this.since = since;
--- trunk/ov-client/observoice/src/jp/sourceforge/observoice/network/task/GetCurrentLectureInfoListTask.java (revision 278)
+++ trunk/ov-client/observoice/src/jp/sourceforge/observoice/network/task/GetCurrentLectureInfoListTask.java (revision 279)
@@ -1,15 +1,20 @@
11 package jp.sourceforge.observoice.network.task;
22
3+import jp.sourceforge.observoice.network.RequestConfiguration;
34 import jp.sourceforge.observoice.network.requestmethod.ObsvRequestMethod;
45 import jp.sourceforge.observoice.network.requestmethod.GetCurrentLectureInfoListMethod;
56
67 /**
78 * 開講中の講義情報リストを取得する操作を表すクラス
8- *
9+ *
910 * @author rtakizawa
1011 */
1112 public class GetCurrentLectureInfoListTask extends ObsvNetworkTask {
1213
14+ public GetCurrentLectureInfoListTask(RequestConfiguration requestConfiguration) {
15+ super(requestConfiguration);
16+ }
17+
1318 @Override
1419 protected ObsvRequestMethod createRequestMethod() {
1520 return new GetCurrentLectureInfoListMethod();
--- trunk/ov-client/observoice/src/jp/sourceforge/observoice/network/task/GetLectureInfoTask.java (revision 278)
+++ trunk/ov-client/observoice/src/jp/sourceforge/observoice/network/task/GetLectureInfoTask.java (revision 279)
@@ -1,11 +1,12 @@
11 package jp.sourceforge.observoice.network.task;
22
3+import jp.sourceforge.observoice.network.RequestConfiguration;
34 import jp.sourceforge.observoice.network.requestmethod.ObsvRequestMethod;
45 import jp.sourceforge.observoice.network.requestmethod.GetLectureInfoMethod;
56
67 /**
78 * 講義情報取得操作を表す
8- *
9+ *
910 * @author rtakizawa
1011 */
1112 public class GetLectureInfoTask extends ObsvNetworkTask {
@@ -15,7 +16,10 @@
1516 /**
1617 * @param courceId 講義ID
1718 */
18- public GetLectureInfoTask(int courceId) {
19+ public GetLectureInfoTask(RequestConfiguration requestConfiguration,
20+ int courceId) {
21+ super(requestConfiguration);
22+
1923 this.courceId = courceId;
2024 }
2125
--- trunk/ov-client/observoice/src/jp/sourceforge/observoice/network/task/ObsvNetworkTask.java (revision 278)
+++ trunk/ov-client/observoice/src/jp/sourceforge/observoice/network/task/ObsvNetworkTask.java (revision 279)
@@ -3,6 +3,7 @@
33 import android.os.AsyncTask;
44 import jp.sourceforge.observoice.exception.ObsvException;
55 import jp.sourceforge.observoice.exception.ObsvRuntimeException;
6+import jp.sourceforge.observoice.network.RequestConfiguration;
67 import jp.sourceforge.observoice.network.requestmethod.ObsvRequestMethod;
78 import jp.sourceforge.observoice.network.response.ObsvResponseObject;
89 import jp.sourceforge.observoice.network.task.ObsvNetworkListener;
@@ -18,7 +19,13 @@
1819 private ObsvNetworkListener listener;
1920 // doInBackground中で投げられた例外
2021 private Exception thrownException;
22+ // APIリクエストの送信設定
23+ private RequestConfiguration requestConfiguration;
2124
25+ public ObsvNetworkTask(RequestConfiguration requestConfiguration) {
26+ this.requestConfiguration = requestConfiguration;
27+ }
28+
2229 /**
2330 * リスナーの登録
2431 *
@@ -39,7 +46,7 @@
3946 // 対応するリクエストメソッドを生成
4047 ObsvRequestMethod requestMethod = createRequestMethod();
4148 // 送信して結果を返す
42- return requestMethod.send();
49+ return requestMethod.send(requestConfiguration);
4350 } catch (ObsvException e) {
4451 // 発生した(RuntimeException以外の)例外を補足
4552 this.thrownException = e;
--- trunk/ov-client/observoice/src/jp/sourceforge/observoice/network/task/GetWatchingCoursesTask.java (revision 278)
+++ trunk/ov-client/observoice/src/jp/sourceforge/observoice/network/task/GetWatchingCoursesTask.java (revision 279)
@@ -1,5 +1,6 @@
11 package jp.sourceforge.observoice.network.task;
22
3+import jp.sourceforge.observoice.network.RequestConfiguration;
34 import jp.sourceforge.observoice.network.requestmethod.GetWatchingCourseInfoListMethod;
45 import jp.sourceforge.observoice.network.requestmethod.ObsvRequestMethod;
56
@@ -10,7 +11,8 @@
1011 */
1112 public class GetWatchingCoursesTask extends ObsvNetworkTask {
1213
13- public GetWatchingCoursesTask() {
14+ public GetWatchingCoursesTask(RequestConfiguration requestConfiguration) {
15+ super(requestConfiguration);
1416 }
1517
1618 @Override
--- trunk/ov-client/observoice/src/jp/sourceforge/observoice/network/task/PostCommentTask.java (revision 278)
+++ trunk/ov-client/observoice/src/jp/sourceforge/observoice/network/task/PostCommentTask.java (revision 279)
@@ -1,5 +1,6 @@
11 package jp.sourceforge.observoice.network.task;
22
3+import jp.sourceforge.observoice.network.RequestConfiguration;
34 import jp.sourceforge.observoice.network.requestmethod.ObsvRequestMethod;
45 import jp.sourceforge.observoice.network.requestmethod.PostCommentMethod;
56
@@ -16,7 +17,10 @@
1617 * @param type 理解度(0 or 1)
1718 * @param content コメント内容
1819 */
19- public PostCommentTask(int courceId, String userId, int type, String content) {
20+ public PostCommentTask(RequestConfiguration requestConfiguration,
21+ int courceId, String userId, int type, String content) {
22+ super(requestConfiguration);
23+
2024 this.courceId = courceId;
2125 this.userId = userId;
2226 this.type = type;
--- trunk/ov-client/observoice/src/jp/sourceforge/observoice/network/task/WatchLectureTask.java (revision 278)
+++ trunk/ov-client/observoice/src/jp/sourceforge/observoice/network/task/WatchLectureTask.java (revision 279)
@@ -1,5 +1,6 @@
11 package jp.sourceforge.observoice.network.task;
22
3+import jp.sourceforge.observoice.network.RequestConfiguration;
34 import jp.sourceforge.observoice.network.requestmethod.WatchLectureMethod;
45 import jp.sourceforge.observoice.network.requestmethod.ObsvRequestMethod;
56
@@ -12,7 +13,10 @@
1213
1314 private final int courceId;
1415
15- public WatchLectureTask(int courceId) {
16+ public WatchLectureTask(RequestConfiguration requestConfiguration,
17+ int courceId) {
18+ super(requestConfiguration);
19+
1620 this.courceId = courceId;
1721 }
1822
--- trunk/ov-client/observoice/src/jp/sourceforge/observoice/network/task/GetLectureInfoListTask.java (revision 278)
+++ trunk/ov-client/observoice/src/jp/sourceforge/observoice/network/task/GetLectureInfoListTask.java (revision 279)
@@ -1,11 +1,12 @@
11 package jp.sourceforge.observoice.network.task;
22
3+import jp.sourceforge.observoice.network.RequestConfiguration;
34 import jp.sourceforge.observoice.network.requestmethod.ObsvRequestMethod;
45 import jp.sourceforge.observoice.network.requestmethod.GetLectureInfoListMethod;
56
67 /**
78 * 講義情報リスト取得操作を表す
8- *
9+ *
910 * @author rtakizawa
1011 */
1112 public class GetLectureInfoListTask extends ObsvNetworkTask {
@@ -17,10 +18,13 @@
1718
1819 /**
1920 * count件数の講義情報リストを取得するタスクのコンストラクタ
20- *
21+ *
2122 * @param count
2223 */
23- public GetLectureInfoListTask(int count) {
24+ public GetLectureInfoListTask(RequestConfiguration requestConfiguration,
25+ int count) {
26+ super(requestConfiguration);
27+
2428 this.count = count;
2529 this.day = 0;
2630 this.period = 0;
@@ -29,13 +33,16 @@
2933
3034 /**
3135 * 条件に合う講義情報リストを取得するタスクのコンストラクタ
32- *
36+ *
3337 * @param count 取得する講義情報の件数
3438 * @param day 曜日(or 0(=指定なし))
3539 * @param period 時限(or 0(=指定なし))
3640 * @param q 検索文字列(or null(=指定なし))
3741 */
38- public GetLectureInfoListTask(int count, int day, int period, String q) {
42+ public GetLectureInfoListTask(RequestConfiguration requestConfiguration,
43+ int count, int day, int period, String q) {
44+ super(requestConfiguration);
45+
3946 this.count = count;
4047 this.day = day;
4148 this.period = period;
--- trunk/ov-client/observoice/src/jp/sourceforge/observoice/network/ObsvHttpClient.java (revision 278)
+++ trunk/ov-client/observoice/src/jp/sourceforge/observoice/network/ObsvHttpClient.java (revision 279)
@@ -2,6 +2,7 @@
22
33 import java.io.IOException;
44 import java.io.UnsupportedEncodingException;
5+
56 import java.util.ArrayList;
67 import java.util.List;
78 import java.util.Map;
@@ -9,7 +10,6 @@
910 import jp.sourceforge.observoice.R;
1011 import jp.sourceforge.observoice.exception.ObsvException;
1112 import jp.sourceforge.observoice.exception.ObsvRuntimeException;
12-import jp.sourceforge.observoice.util.ObsvSetting;
1313
1414 import org.apache.http.HttpEntity;
1515 import org.apache.http.HttpResponse;
@@ -77,7 +77,7 @@
7777 // 接続のタイムアウトを設定
7878 HttpConnectionParams.setConnectionTimeout(params, timeout);
7979 HttpConnectionParams.setSoTimeout(params, timeout);
80-
80+
8181 // コンテンツの文字コードをUTF-8に設定
8282 HttpProtocolParams.setContentCharset(params, encoding);
8383 }
@@ -88,7 +88,7 @@
8888
8989 /**
9090 * getメソッドを送る
91- *
91+ *
9292 * @param url
9393 * @param qParams
9494 * クエリパラメータの辞書
@@ -101,7 +101,7 @@
101101
102102 /**
103103 * POSTメソッドを送る
104- *
104+ *
105105 * @param url
106106 * @param qParams
107107 * クエリパラメータの辞書
@@ -117,7 +117,7 @@
117117
118118 /**
119119 * サーバにmethodを送りレスポンスを返す
120- *
120+ *
121121 * @param method
122122 * GETもしくはPOSTメソッドを表すオブジェクト(HttpGet or HttpPost)
123123 * @return
@@ -160,7 +160,7 @@
160160
161161 /**
162162 * GETメソッドを表すオブジェクト(HttpGet)を作って返す
163- *
163+ *
164164 * @param url
165165 * @param qParams
166166 * クエリパラメータの辞書
@@ -170,7 +170,6 @@
170170 String query = createQuery(qParams);
171171
172172 HttpGet httpGet = new HttpGet(url + "?" + query);
173- httpGet.setHeader("host", ObsvSetting.getInstance().loadHostName());
174173 httpGet.setHeader("User-Agent", userAgentName);
175174 httpGet.setHeader("Accept-Charset", encoding);
176175
@@ -179,7 +178,7 @@
179178
180179 /**
181180 * POSTメソッドを表すオブジェクト(HttpPost)を作って返す
182- *
181+ *
183182 * @param url
184183 * @param qParams
185184 * クエリパラメータの辞書
@@ -193,8 +192,6 @@
193192 HttpPost httpPost = new HttpPost(url + "?" + query);
194193 httpPost.setEntity(createUrlEncodedFormEntity(fParams));
195194
196- httpPost.setHeader("host", ObsvSetting.getInstance().loadHostName());
197-
198195 // Content-Typeに文字コードを含めないとPOSTコンテンツが正しくエンコードされない
199196 // これはorg.apache.httpの仕様による
200197 httpPost.setHeader("Content-Type", "application/x-www-form-urlencoded; charset=" + encoding);
@@ -207,7 +204,7 @@
207204
208205 /**
209206 * クエリパラメータの辞書からクエリパラメータを作成
210- *
207+ *
211208 * @param qParams
212209 * @return
213210 */
@@ -221,7 +218,7 @@
221218
222219 /**
223220 * フォームパラメータの辞書からフォームパラメータのエンティティを作成
224- *
221+ *
225222 * @param fParams
226223 * @return
227224 */
--- trunk/ov-client/observoice/src/jp/sourceforge/observoice/network/requestmethod/GetCommentListMethod.java (revision 278)
+++ trunk/ov-client/observoice/src/jp/sourceforge/observoice/network/requestmethod/GetCommentListMethod.java (revision 279)
@@ -12,12 +12,11 @@
1212
1313 /**
1414 * コメント一覧取得を要求するリクエストメソッド
15- *
15+ *
1616 * @author rtakizawa
1717 */
1818 public class GetCommentListMethod extends ObsvGetRequestMethod {
1919
20- private int courceId;
2120 private int count;
2221 private String since, until;
2322
@@ -28,7 +27,8 @@
2827 * @param until この日付以前のコメントを取得 (nullなら指定なし)
2928 */
3029 public GetCommentListMethod(int courceId, int count, Calendar since, Calendar until) {
31- this.courceId = courceId;
30+ super("/courses/" + courceId + "/comments.json");
31+
3232 this.count = count;
3333 if (since != null) {
3434 this.since = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss Z", Locale.US).format(since.getTime());
@@ -39,8 +39,8 @@
3939 }
4040
4141 @Override
42- protected Map<String, String> createQueryParameters() {
43- Map<String, String> queryParameters = super.createQueryParameters();
42+ protected Map<String, String> createQueryParameters(String apiKey) {
43+ Map<String, String> queryParameters = super.createQueryParameters(apiKey);
4444
4545 queryParameters.put("count", String.valueOf(count));
4646 if (since != null) {
@@ -49,15 +49,10 @@
4949 if (until != null) {
5050 queryParameters.put("until", until);
5151 }
52-
52+
5353 return queryParameters;
5454 }
5555
56- @Override
57- protected String createUrlString() {
58- return "http://" + hostName + "/api/courses/" + courceId + "/comments.json";
59- }
60-
6156 public ObsvResponseObject createResponseObject(String response) throws JSONException {
6257 return new CommentListResponse(response);
6358 }
--- trunk/ov-client/observoice/src/jp/sourceforge/observoice/network/requestmethod/GetCurrentLectureInfoListMethod.java (revision 278)
+++ trunk/ov-client/observoice/src/jp/sourceforge/observoice/network/requestmethod/GetCurrentLectureInfoListMethod.java (revision 279)
@@ -6,14 +6,13 @@
66
77 /**
88 * 開講中の講義情報リストを取得するリクエストメソッド
9- *
9+ *
1010 * @author rtakizawa
1111 */
1212 public class GetCurrentLectureInfoListMethod extends ObsvGetRequestMethod {
1313
14- @Override
15- protected String createUrlString() {
16- return "http://" + hostName + "/api/courses/current.json";
14+ public GetCurrentLectureInfoListMethod() {
15+ super("/courses/current.json");
1716 }
1817
1918 @Override
--- trunk/ov-client/observoice/src/jp/sourceforge/observoice/network/requestmethod/GetLectureInfoMethod.java (revision 278)
+++ trunk/ov-client/observoice/src/jp/sourceforge/observoice/network/requestmethod/GetLectureInfoMethod.java (revision 279)
@@ -7,26 +7,19 @@
77
88 /**
99 * 講義情報取得メソッド
10- *
10+ *
1111 * @author rtakizawa
1212 */
1313 public class GetLectureInfoMethod extends ObsvGetRequestMethod {
1414
15- private int courceId;
16-
1715 /**
1816 * @param courceId 講義ID
1917 */
2018 public GetLectureInfoMethod(int courceId) {
21- this.courceId = courceId;
19+ super("/courses/" + courceId + ".json");
2220 }
2321
2422 @Override
25- protected String createUrlString() {
26- return "http://" + hostName + "/api/courses/" + courceId + ".json";
27- }
28-
29- @Override
3023 public ObsvResponseObject createResponseObject(String response) throws JSONException {
3124 return new LectureInfoResponse(response);
3225 }
--- trunk/ov-client/observoice/src/jp/sourceforge/observoice/network/requestmethod/ObsvGetRequestMethod.java (revision 278)
+++ trunk/ov-client/observoice/src/jp/sourceforge/observoice/network/requestmethod/ObsvGetRequestMethod.java (revision 279)
@@ -7,26 +7,31 @@
77 import jp.sourceforge.observoice.exception.ObsvException;
88 import jp.sourceforge.observoice.exception.ObsvRuntimeException;
99 import jp.sourceforge.observoice.network.ObsvHttpClient;
10+import jp.sourceforge.observoice.network.RequestConfiguration;
1011 import jp.sourceforge.observoice.network.response.ObsvResponseObject;
1112
1213 /**
1314 * Observoiceのクライアントからサーバーへ送信するGETリクエストメソッドデータを表す抽象クラス。
1415 * 実際のリクエストメソッドのデータは子クラスになる。
15- *
16+ *
1617 * @author rtakizawa
1718 */
1819 public abstract class ObsvGetRequestMethod extends ObsvRequestMethod {
1920
21+ protected ObsvGetRequestMethod(String apiPath) {
22+ super(apiPath);
23+ }
24+
2025 /**
2126 * Observoiceリクエストメソッドの送信
22- *
27+ *
2328 * @return サーバーからのレスポンス
2429 * @throws ObsvException
2530 */
26- public ObsvResponseObject send() throws ObsvException {
27- String urlStr = createUrlString();
28- Map<String, String> queryParameters = createQueryParameters();
29-
31+ public ObsvResponseObject send(RequestConfiguration conf) throws ObsvException {
32+ String urlStr = createUrlString(conf.getHost(), conf.getApiBasePath());
33+ Map<String, String> queryParameters = createQueryParameters(conf.getApiKey());
34+
3035 try {
3136 String res = ObsvHttpClient.getInstance().get(urlStr, queryParameters);
3237 return createResponseObject(res);
--- trunk/ov-client/observoice/src/jp/sourceforge/observoice/network/requestmethod/ObsvRequestMethod.java (revision 278)
+++ trunk/ov-client/observoice/src/jp/sourceforge/observoice/network/requestmethod/ObsvRequestMethod.java (revision 279)
@@ -1,5 +1,6 @@
11 package jp.sourceforge.observoice.network.requestmethod;
22
3+import java.net.InetSocketAddress;
34 import java.util.HashMap;
45 import java.util.Map;
56
@@ -6,31 +7,24 @@
67 import org.json.JSONException;
78
89 import jp.sourceforge.observoice.exception.ObsvException;
9-import jp.sourceforge.observoice.network.ObsvHttpClient;
10+import jp.sourceforge.observoice.network.RequestConfiguration;
1011 import jp.sourceforge.observoice.network.response.ObsvResponseObject;
11-import jp.sourceforge.observoice.util.ObsvSetting;
1212
1313 /**
1414 * Observoiceのクライアントからサーバーへ送信するリクエストメソッドデータクラス。
15- *
15+ *
1616 * @author rtakizawa
1717 */
1818 public abstract class ObsvRequestMethod {
1919
20- /**
21- * apiKey
22- */
23- protected String apiKey;
20+ private String apiPath;
2421
2522 /**
26- * サーバのホスト名
23+ * APIリクエストを生成
24+ * @param apiPath APIへのパス(例: /courses.json)
2725 */
28- protected String hostName;
29-
30- protected ObsvRequestMethod() {
31- ObsvSetting setting = ObsvSetting.getInstance();
32- this.hostName = setting.loadHostName();
33- this.apiKey = setting.loadApiKey();
26+ protected ObsvRequestMethod(String apiPath) {
27+ this.apiPath = apiPath;
3428 }
3529
3630 /**
@@ -37,7 +31,7 @@
3731 * クエリパラメータの辞書を返す
3832 * サブクラスでこのメソッドを実装する場合は必ずこのスーパーメソッドを呼び出す必要がある
3933 */
40- protected Map<String, String> createQueryParameters() {
34+ protected Map<String, String> createQueryParameters(String apiKey) {
4135 Map<String, String> queryParams = new HashMap<String, String>();
4236 queryParams.put("apiKey", apiKey);
4337 return queryParams;
@@ -44,21 +38,29 @@
4438 }
4539
4640 /**
47- * リクエストメソッドを送信する対象URL文字列を返す
41+ * リクエストの送信先URLを生成する
42+ *
43+ * @param host 送信先ホスト
44+ * @param apiBasePath APIのベースパス(例: /api)
45+ * @return
4846 */
49- protected abstract String createUrlString();
47+ public String createUrlString(InetSocketAddress host, String apiBasePath) {
48+ return "http://" + host.toString() + apiBasePath + apiPath;
49+ }
5050
5151 /**
5252 * リクエストメソッドを送信する
53- *
53+ *
54+ * @param host 送信先ホスト名とポート番号
55+ * @param apiBasePath APIのベースパス(例: /api)
5456 * @return
5557 */
56- public abstract ObsvResponseObject send() throws ObsvException;
58+ public abstract ObsvResponseObject send(RequestConfiguration conf) throws ObsvException;
5759
5860 /**
59- *
61+ *
6062 * リクエストメソッドに対応するレスポンスオブジェクトを生成
61- *
63+ *
6264 * @param response
6365 * @return
6466 * @throws JSONException
--- trunk/ov-client/observoice/src/jp/sourceforge/observoice/network/requestmethod/ObsvPostRequestMethod.java (revision 278)
+++ trunk/ov-client/observoice/src/jp/sourceforge/observoice/network/requestmethod/ObsvPostRequestMethod.java (revision 279)
@@ -8,27 +8,32 @@
88 import jp.sourceforge.observoice.exception.ObsvException;
99 import jp.sourceforge.observoice.exception.ObsvRuntimeException;
1010 import jp.sourceforge.observoice.network.ObsvHttpClient;
11+import jp.sourceforge.observoice.network.RequestConfiguration;
1112 import jp.sourceforge.observoice.network.response.ObsvResponseObject;
1213
1314 /**
1415 * Observoiceのクライアントからサーバーへ送信するPOSTリクエストメソッドデータを表す抽象クラス。
1516 * 実際のリクエストメソッドのデータは子クラスになる。
16- *
17+ *
1718 * @author rtakizawa
1819 */
1920 public abstract class ObsvPostRequestMethod extends ObsvRequestMethod {
2021
22+ protected ObsvPostRequestMethod(String apiPath) {
23+ super(apiPath);
24+ }
25+
2126 /**
2227 * Observoiceリクエストメソッドの送信
23- *
28+ *
2429 * @return サーバーからのレスポンスを表すレスポンスオブジェクト
2530 * @throws ObsvException
2631 */
27- public ObsvResponseObject send() throws ObsvException {
28- String urlStr = createUrlString();
29- Map<String, String> queryParameters = createQueryParameters();
32+ public ObsvResponseObject send(RequestConfiguration conf) throws ObsvException {
33+ String urlStr = createUrlString(conf.getHost(), conf.getApiBasePath());
34+ Map<String, String> queryParameters = createQueryParameters(conf.getApiKey());
3035 Map<String, String> formParameters = createFormParameters();
31-
36+
3237 try {
3338 String response = ObsvHttpClient.getInstance().post(urlStr, queryParameters, formParameters);
3439 return createResponseObject(response);
--- trunk/ov-client/observoice/src/jp/sourceforge/observoice/network/requestmethod/PostCommentMethod.java (revision 278)
+++ trunk/ov-client/observoice/src/jp/sourceforge/observoice/network/requestmethod/PostCommentMethod.java (revision 279)
@@ -8,18 +8,18 @@
88
99 /**
1010 * サーバにコメント投稿する際に送信するリクエストメソッドを表す
11- *
11+ *
1212 * @author rtakizawa
1313 */
1414 public class PostCommentMethod extends ObsvPostRequestMethod {
1515
16- private int courceId;
1716 private String userId;
1817 private int type;
1918 private String content;
2019
2120 public PostCommentMethod(int courceId, String userId, int type, String content) {
22- this.courceId = courceId;
21+ super("/courses/" + courceId + "/comments/post.json");
22+
2323 this.userId = userId;
2424 this.type = type;
2525 this.content = content;
@@ -41,9 +41,4 @@
4141 return formParameters;
4242 }
4343
44- @Override
45- protected String createUrlString() {
46- return "http://" + hostName + "/api/courses/" + courceId + "/comments/post.json";
47- }
48-
4944 }
--- trunk/ov-client/observoice/src/jp/sourceforge/observoice/network/requestmethod/WatchLectureMethod.java (revision 278)
+++ trunk/ov-client/observoice/src/jp/sourceforge/observoice/network/requestmethod/WatchLectureMethod.java (revision 279)
@@ -11,20 +11,13 @@
1111 */
1212 public class WatchLectureMethod extends ObsvPostRequestMethod {
1313
14- private final int courceId;
15-
1614 /**
1715 * @param courceId 講義ID
1816 */
1917 public WatchLectureMethod(int courceId) {
20- this.courceId = courceId;
21- }
22-
23- @Override
24- protected String createUrlString() {
25- return "http://" + hostName + "/api/courses/" + courceId + "/watch.json";
18+ super("/courses/" + courceId + "/watch.json");
2619 }
27-
20+
2821 @Override
2922 public ObsvResponseObject createResponseObject(String response)
3023 throws JSONException {
--- trunk/ov-client/observoice/src/jp/sourceforge/observoice/network/requestmethod/GetLectureInfoListMethod.java (revision 278)
+++ trunk/ov-client/observoice/src/jp/sourceforge/observoice/network/requestmethod/GetLectureInfoListMethod.java (revision 279)
@@ -9,7 +9,7 @@
99
1010 /**
1111 * 講義情報リストを取得するリクエストメソッド
12- *
12+ *
1313 * @author rtakizawa
1414 */
1515 public class GetLectureInfoListMethod extends ObsvGetRequestMethod {
@@ -21,7 +21,7 @@
2121
2222 /**
2323 * 条件に合う講義情報のリストを取得
24- *
24+ *
2525 * @param count 取得する講義情報の件数
2626 * @param day 曜日(or 0(=指定なし))
2727 * @param period 時限(or 0(=指定なし))
@@ -28,6 +28,8 @@
2828 * @param q 検索文字列(or null(=指定なし))
2929 */
3030 public GetLectureInfoListMethod(int count, int day, int period, String q) {
31+ super("/courses.json");
32+
3133 this.count = count;
3234 this.day = day;
3335 this.period = period;
@@ -35,9 +37,9 @@
3537 }
3638
3739 @Override
38- protected Map<String, String> createQueryParameters() {
39- Map<String, String> queryParameters = super.createQueryParameters();
40-
40+ protected Map<String, String> createQueryParameters(String apiKey) {
41+ Map<String, String> queryParameters = super.createQueryParameters(apiKey);
42+
4143 queryParameters.put("count", String.valueOf(count));
4244 if (day != 0) {
4345 queryParameters.put("day", String.valueOf(day));
@@ -48,16 +50,11 @@
4850 if (q != null) {
4951 queryParameters.put("q", q);
5052 }
51-
53+
5254 return queryParameters;
5355 }
5456
5557 @Override
56- protected String createUrlString() {
57- return "http://" + hostName + "/api/courses.json";
58- }
59-
60- @Override
6158 public ObsvResponseObject createResponseObject(String response)
6259 throws JSONException {
6360 return new LectureInfoListResponse(response);
--- trunk/ov-client/observoice/src/jp/sourceforge/observoice/network/requestmethod/GetAccountMethod.java (revision 278)
+++ trunk/ov-client/observoice/src/jp/sourceforge/observoice/network/requestmethod/GetAccountMethod.java (revision 279)
@@ -7,14 +7,13 @@
77
88 /**
99 * アカウント情報取得API用リクエストメソッド
10- *
10+ *
1111 * @author rtakizawa
1212 */
1313 public class GetAccountMethod extends ObsvGetRequestMethod {
1414
15- @Override
16- protected String createUrlString() {
17- return "http://" + hostName + "/api/account.json";
15+ public GetAccountMethod() {
16+ super("/account.json");
1817 }
1918
2019 @Override
--- trunk/ov-client/observoice/src/jp/sourceforge/observoice/network/requestmethod/GetWatchingCourseInfoListMethod.java (revision 278)
+++ trunk/ov-client/observoice/src/jp/sourceforge/observoice/network/requestmethod/GetWatchingCourseInfoListMethod.java (revision 279)
@@ -15,14 +15,10 @@
1515 /**
1616 */
1717 public GetWatchingCourseInfoListMethod() {
18+ super("/courses/watching.json");
1819 }
1920
2021 @Override
21- protected String createUrlString() {
22- return "http://" + hostName + "/api/courses/watching.json";
23- }
24-
25- @Override
2622 public ObsvResponseObject createResponseObject(String response)
2723 throws JSONException {
2824 return new WatchingCourseInfoListResponse(response);
--- trunk/ov-client/observoice/src/jp/sourceforge/observoice/StartActivity.java (revision 278)
+++ trunk/ov-client/observoice/src/jp/sourceforge/observoice/StartActivity.java (revision 279)
@@ -9,6 +9,7 @@
99 import jp.sourceforge.observoice.entity.TimeSlot;
1010 import jp.sourceforge.observoice.entity.WatchingCourseInfo;
1111 import jp.sourceforge.observoice.exception.ObsvException;
12+import jp.sourceforge.observoice.network.RequestConfiguration;
1213 import jp.sourceforge.observoice.network.response.LectureInfoListResponse;
1314 import jp.sourceforge.observoice.network.response.ObsvResponseObject;
1415 import jp.sourceforge.observoice.network.response.WatchingCourseInfoListResponse;
@@ -17,6 +18,7 @@
1718 import jp.sourceforge.observoice.network.task.GetWatchingCoursesTask;
1819 import jp.sourceforge.observoice.network.task.ObsvNetworkListener;
1920 import jp.sourceforge.observoice.network.task.ObsvNetworkTask;
21+import jp.sourceforge.observoice.util.Util;
2022
2123 import roboguice.activity.RoboActivity;
2224 import roboguice.inject.InjectView;
@@ -62,22 +64,22 @@
6264 private static final int[] CALENDAR_DAY_OF_WEEK = new int[] { 0, java.util.Calendar.MONDAY,
6365 java.util.Calendar.TUESDAY, java.util.Calendar.WEDNESDAY, java.util.Calendar.THURSDAY,
6466 java.util.Calendar.FRIDAY, java.util.Calendar.SATURDAY, java.util.Calendar.SUNDAY };
65-
67+
6668 NextLectureListAdapter listAdapter;
6769 private ListView lectureListView;
6870 private List<Course> lectures = new ArrayList<Course>();
69-
71+
7072 //今日は何曜日?
7173 private int today = 0;
72-
74+
75+ // ネットワークタスク実行用
76+ private RequestConfiguration mRequestConfiguration;
77+
7378 @Override
7479 public void onCreate(Bundle savedInstanceState) {
7580 super.onCreate(savedInstanceState);
7681 setContentView(R.layout.start);
7782
78- // final Button runReviewActivityButton =
79- // (Button)findViewById(R.id.runLectureActivityButton);
80-
8183 /* 講義検索画面と復習画面への遷移を登録 */
8284 runLectureSearchActivityButton
8385 .setOnClickListener(new View.OnClickListener() {
@@ -111,18 +113,22 @@
111113 MyPagerAdapter mPagerAdapter = new MyPagerAdapter();
112114 mViewPager.setAdapter(mPagerAdapter);
113115 lectureListView = mPagerAdapter.getNextLectureListView();
114-
116+
115117 //検索用データの設定
116118 String freeWord = "";
117119 int periodToSearch = 0;
118120
119121 //今日は何曜日?
120- Calendar cal = Calendar.getInstance();
122+ Calendar cal = Calendar.getInstance();
121123 today = cal.get(Calendar.DAY_OF_WEEK);
122-
123- ObsvNetworkTask getLectureInfos = new GetLectureInfoListTask(100,
124- getDayOfWeek(), periodToSearch, freeWord);
125124
125+ // ネットワークタスク実行用設定をロード
126+ mRequestConfiguration = RequestConfiguration.load(
127+ Util.getObsvSharedPreferences(this));
128+
129+ ObsvNetworkTask getLectureInfos = new GetLectureInfoListTask(mRequestConfiguration,
130+ 100, getDayOfWeek(), periodToSearch, freeWord);
131+
126132 // 自分自身
127133 final StartActivity self = this;
128134
@@ -133,7 +139,7 @@
133139 // 一つ目のタイトル(course_idが-1)
134140 // TODO courseIDとして―1が有り得るならNextLectureListAdapterと併せて変更の必要
135141 lectures.add(new Course(-1, "現在行われている授業(getLecturesInfo)"));
136-
142+
137143 LectureInfoListResponse response_ = (LectureInfoListResponse) response;
138144 ArrayList<Course> lectureInfoList;
139145 lectureInfoList = response_.getLectureInfoList();
@@ -140,11 +146,11 @@
140146
141147 //該当する授業が無い場合
142148 boolean noLectures = true;
143-
149+
144150 //取得する授業の最大数
145151 int limit = 5;
146152 int i = 0;
147-
153+
148154 for (Course info : lectureInfoList) {
149155 if(i < limit){
150156 lectures.add(info);
@@ -155,10 +161,10 @@
155161
156162 if (noLectures) {
157163 lectures.add(new Course(-2, "ただいま授業は行われていません"));
158- }
159-
164+ }
165+
160166 listAdapter = new NextLectureListAdapter(self, R.layout.next_lecture_item, lectures);
161-
167+
162168 lectureListView.setAdapter(listAdapter);
163169 lectureListView.setOnItemClickListener(self);
164170 }
@@ -175,9 +181,10 @@
175181 });
176182 // 講義情報一覧取得タスク開始
177183 getLectureInfos.execute();
178-
184+
179185 // ウォッチ情報一覧取得後のUI更新処理を記述
180- GetWatchingCoursesTask getWatchingLectures = new GetWatchingCoursesTask();
186+ GetWatchingCoursesTask getWatchingLectures =
187+ new GetWatchingCoursesTask(mRequestConfiguration);
181188 getWatchingLectures.setListener(new ObsvNetworkListener() {
182189 // responseがサーバからのレスポンスを表すオブジェクト
183190 public void onSuccess(ObsvResponseObject response) {
@@ -189,7 +196,7 @@
189196
190197 //該当する授業が無い場合
191198 boolean noWatches = true;
192-
199+
193200 //取得する授業の最大数
194201 int limit = 5;
195202 int i = 0;
@@ -209,13 +216,13 @@
209216 }
210217 }
211218 }
212-
219+
213220 if (noWatches) {
214221 lectures.add(new Course(-2, "この曜日の授業は受けていません"));
215- }
216-
222+ }
223+
217224 listAdapter = new NextLectureListAdapter(self, R.layout.next_lecture_item, lectures);
218-
225+
219226 lectureListView.setAdapter(listAdapter);
220227 lectureListView.setOnItemClickListener(self);
221228
@@ -231,12 +238,13 @@
231238 .setTitle(e.getClass().getSimpleName()).setMessage(errorMes).show();
232239 }
233240 });
234-
241+
235242 // ウォッチ情報一覧取得タスク開始
236243 getWatchingLectures.execute();
237-
244+
238245 // カレント情報一覧取得後のUI更新処理を記述
239- GetCurrentLectureInfoListTask getCurrentLectures = new GetCurrentLectureInfoListTask();
246+ GetCurrentLectureInfoListTask getCurrentLectures =
247+ new GetCurrentLectureInfoListTask(mRequestConfiguration);
240248 // 講義情報一覧取得後のUI更新処理を記述
241249 getCurrentLectures.setListener(new ObsvNetworkListener() {
242250 // responseがサーバからのレスポンスを表すオブジェクト
@@ -244,7 +252,7 @@
244252 // 一つ目のタイトル(course_idが-1)
245253 // TODO courseIDとして―1が有り得るならNextLectureListAdapterと併せて変更の必要
246254 lectures.add(new Course(-1, "現在行われている授業(CurrentLectures)"));
247-
255+
248256 LectureInfoListResponse response_ = (LectureInfoListResponse) response;
249257 ArrayList<Course> lectureInfoList;
250258 lectureInfoList = response_.getLectureInfoList();
@@ -251,11 +259,11 @@
251259
252260 //該当する授業が無い場合
253261 boolean noLectures = true;
254-
262+
255263 //取得する授業の最大数
256264 int limit = 5;
257265 int i = 0;
258-
266+
259267 for (Course info : lectureInfoList) {
260268 if(i < limit){
261269 lectures.add(info);
@@ -266,10 +274,10 @@
266274
267275 if (noLectures) {
268276 lectures.add(new Course(-2, "ただいま授業は行われていません"));
269- }
270-
277+ }
278+
271279 listAdapter = new NextLectureListAdapter(self, R.layout.next_lecture_item, lectures);
272-
280+
273281 lectureListView.setAdapter(listAdapter);
274282 lectureListView.setOnItemClickListener(self);
275283 }
@@ -284,11 +292,11 @@
284292 .setTitle(e.getClass().getSimpleName()).setMessage(errorMes).show();
285293 }
286294 });
287-
295+
288296 // 講義情報一覧取得タスク開始
289297 getCurrentLectures.execute();
290-
291-
298+
299+
292300 }
293301
294302 // フリップで切り替え可能なサブビュー用のアダプタ
@@ -303,7 +311,7 @@
303311 mCommentListView = (ListView) inflater.inflate(R.layout.comment_list_fragment, null);
304312 mLectureAbstractView = (TextView) inflater.inflate(R.layout.lecture_abstract, null);
305313 }
306-
314+
307315 @Override
308316 public Object instantiateItem(ViewGroup container, int position) {
309317 int[] pages = { R.layout.next_lecture,
@@ -312,7 +320,7 @@
312320 View view = null;
313321 switch (page) {
314322 case R.layout.next_lecture:
315- view = mNextLecture;
323+ view = mNextLecture;
316324 break;
317325 case R.layout.comment_list_fragment:
318326 view = mCommentListView;
@@ -339,7 +347,7 @@
339347 public boolean isViewFromObject(View view, Object object) {
340348 return view.equals(object);
341349 }
342-
350+
343351 public ListView getNextLectureListView() {
344352 return mNextLecture;
345353 }
@@ -370,7 +378,7 @@
370378 @Override
371379 public void onClick(View arg0) {
372380 // TODO Auto-generated method stub
373-
381+
374382 }
375383
376384 @Override
--- trunk/ov-client/observoice/src/jp/sourceforge/observoice/ReviewLectureSearch.java (revision 278)
+++ trunk/ov-client/observoice/src/jp/sourceforge/observoice/ReviewLectureSearch.java (revision 279)
@@ -7,10 +7,12 @@
77
88 import jp.sourceforge.observoice.entity.WatchingCourseInfo;
99 import jp.sourceforge.observoice.exception.ObsvException;
10+import jp.sourceforge.observoice.network.RequestConfiguration;
1011 import jp.sourceforge.observoice.network.response.ObsvResponseObject;
1112 import jp.sourceforge.observoice.network.response.WatchingCourseInfoListResponse;
1213 import jp.sourceforge.observoice.network.task.GetWatchingCoursesTask;
1314 import jp.sourceforge.observoice.network.task.ObsvNetworkListener;
15+import jp.sourceforge.observoice.util.Util;
1416 import roboguice.activity.RoboActivity;
1517 import roboguice.inject.InjectView;
1618 import android.content.Intent;
@@ -23,7 +25,7 @@
2325
2426 /**
2527 * 復習講義選択画面
26- *
28+ *
2729 * @author uchan
2830 * @author torikawa
2931 */
@@ -34,16 +36,20 @@
3436 private ListView searched_lectures;
3537 private ArrayList<WatchingCourseInfo> infoList;
3638
39+ private RequestConfiguration mRequestConfiguration;
40+
3741 @Override
3842 protected void onCreate(Bundle savedInstanceState) {
3943 super.onCreate(savedInstanceState);
4044 this.setContentView(R.layout.review_lecture_search);
4145
46+ mRequestConfiguration = RequestConfiguration.load(Util.getObsvSharedPreferences(this));
47+
4248 getWatchingLectures();
4349 }
4450
4551 private void getWatchingLectures() {
46- GetWatchingCoursesTask task = new GetWatchingCoursesTask();
52+ GetWatchingCoursesTask task = new GetWatchingCoursesTask(mRequestConfiguration);
4753 task.setListener(this);
4854 task.execute();
4955 }
--- trunk/ov-client/observoice/src/jp/sourceforge/observoice/CommentListIntervalGetter.java (revision 278)
+++ trunk/ov-client/observoice/src/jp/sourceforge/observoice/CommentListIntervalGetter.java (revision 279)
@@ -8,6 +8,7 @@
88
99 import jp.sourceforge.observoice.entity.Comment;
1010 import jp.sourceforge.observoice.exception.ObsvException;
11+import jp.sourceforge.observoice.network.RequestConfiguration;
1112 import jp.sourceforge.observoice.network.response.CommentListResponse;
1213 import jp.sourceforge.observoice.network.response.ObsvResponseObject;
1314 import jp.sourceforge.observoice.network.task.GetCommentListTask;
@@ -30,17 +31,19 @@
3031
3132 private int courceId;
3233 private final Handler mHandler; // UIスレッドで実行する機能のためのハンドラ
34+ private final RequestConfiguration mRequestConfiguration;
3335 private Timer mTimer = null;
3436 private List<OnReceivedListener> mListeners;
3537
36- public CommentListIntervalGetter(int courceId, Handler handler) {
38+ public CommentListIntervalGetter(int courceId, Handler handler, RequestConfiguration requestConfiguration) {
3739 this.courceId = courceId;
3840 mListeners = Collections.synchronizedList(new ArrayList<OnReceivedListener>());
3941 mHandler = handler;
42+ mRequestConfiguration = requestConfiguration;
4043 }
4144
4245 private GetCommentListTask createTask() {
43- GetCommentListTask mTask = new GetCommentListTask(courceId, 100, null, null);
46+ GetCommentListTask mTask = new GetCommentListTask(mRequestConfiguration, courceId, 100, null, null);
4447 // コメントリストがサーバーから到達したときのリスナを作成し登録
4548 mTask.setListener(new ObsvNetworkListener() {
4649 @Override
--- trunk/ov-client/observoice/src/jp/sourceforge/observoice/LectureActivity.java (revision 278)
+++ trunk/ov-client/observoice/src/jp/sourceforge/observoice/LectureActivity.java (revision 279)
@@ -7,10 +7,12 @@
77 import jp.sourceforge.observoice.entity.Comment;
88 import jp.sourceforge.observoice.entity.Course;
99 import jp.sourceforge.observoice.exception.ObsvException;
10+import jp.sourceforge.observoice.network.RequestConfiguration;
1011 import jp.sourceforge.observoice.network.response.ObsvResponseObject;
1112 import jp.sourceforge.observoice.network.task.ObsvNetworkListener;
1213 import jp.sourceforge.observoice.network.task.PostCommentTask;
1314 import jp.sourceforge.observoice.network.task.WatchLectureTask;
15+import jp.sourceforge.observoice.util.Util;
1416 import jp.sourceforge.observoice.util.WidgetUtil;
1517 import roboguice.activity.RoboFragmentActivity;
1618 import roboguice.inject.InjectExtra;
@@ -34,7 +36,7 @@
3436
3537 /**
3638 * 講義中に理解度フィードバックやそれらのデータ閲覧を行うアクティビティ
37- *
39+ *
3840 * @author meganetan
3941 * @author uchan_nos
4042 * @author torikawa
@@ -62,12 +64,15 @@
6264 // サーバーから一定間隔で取得する機能を提供するクラス
6365 private CommentListIntervalGetter commentListIntervalGetter;
6466
67+ private RequestConfiguration mRequestConfiguration;
68+
6569 @Override
6670 protected void onCreate(Bundle savedInstanceState) {
6771 super.onCreate(savedInstanceState);
6872 setContentView(R.layout.lecture);
6973
70- this.commentListIntervalGetter = new CommentListIntervalGetter(this.lecture.getCourceId(), new Handler());
74+ this.mRequestConfiguration = RequestConfiguration.load(Util.getObsvSharedPreferences(this));
75+ this.commentListIntervalGetter = new CommentListIntervalGetter(this.lecture.getCourceId(), new Handler(), mRequestConfiguration);
7176
7277 // コメント入力フィールドのキー入力設定
7378 commentField.setOnKeyListener(this);
@@ -98,7 +103,7 @@
98103
99104 /**
100105 * コメント投稿ボタンのクリック可能属性を設定するメソッド
101- *
106+ *
102107 * @param b
103108 */
104109 private void setButtonsClickable(boolean b) {
@@ -143,7 +148,7 @@
143148
144149 /**
145150 * コメント投稿ボタンのリスナ
146- *
151+ *
147152 * @author rtakizawa
148153 */
149154 private class PostCommentButtonListener implements View.OnClickListener {
@@ -162,7 +167,7 @@
162167 setButtonsClickable(false);
163168
164169 String comment = commentField.getText().toString();
165- PostCommentTask task = new PostCommentTask(lecture.getCourceId(), "hoge", type,
170+ PostCommentTask task = new PostCommentTask(mRequestConfiguration, lecture.getCourceId(), "hoge", type,
166171 comment);
167172 task.setListener(new PostCommentListener());
168173 task.execute();
@@ -171,7 +176,7 @@
171176
172177 /**
173178 * コメント投稿タスクのリスナー
174- *
179+ *
175180 * @author rtakizawa
176181 */
177182 private class PostCommentListener implements ObsvNetworkListener {
@@ -219,7 +224,7 @@
219224 switch (item.getItemId()) {
220225 case R.id.watchLecture:
221226 // 講義を選択したことをサーバーに通知する
222- new WatchLectureTask(lecture.getCourceId()).execute();
227+ new WatchLectureTask(mRequestConfiguration, lecture.getCourceId()).execute();
223228 default:
224229 return super.onOptionsItemSelected(item);
225230 }
--- trunk/ov-client/observoice/src/jp/sourceforge/observoice/LoginActivity.java (revision 278)
+++ trunk/ov-client/observoice/src/jp/sourceforge/observoice/LoginActivity.java (revision 279)
@@ -1,6 +1,8 @@
11 package jp.sourceforge.observoice;
22
3+import jp.sourceforge.observoice.network.RequestConfiguration;
34 import jp.sourceforge.observoice.util.ObsvSetting;
5+import jp.sourceforge.observoice.util.Util;
46 import roboguice.activity.RoboActivity;
57 import roboguice.inject.InjectResource;
68 import roboguice.inject.InjectView;
@@ -24,16 +26,18 @@
2426 @InjectView(R.id.apiKey)
2527 TextView text;
2628
27- @InjectResource(R.string.observoice_uri)
28- private String mObservoiceUri;
2929 @InjectResource(R.string.login_path)
3030 private String mLoginPath;
3131
32+ private RequestConfiguration mRequestConfiguration;
33+
3234 @Override
3335 protected void onCreate(Bundle savedInstanceState) {
3436 super.onCreate(savedInstanceState);
3537 setContentView(R.layout.login);
3638
39+ mRequestConfiguration = RequestConfiguration.load(Util.getObsvSharedPreferences(this));
40+
3741 initWebView();
3842 }
3943
@@ -58,7 +62,7 @@
5862 }
5963
6064 private String getLoginUri() {
61- return mObservoiceUri + mLoginPath;
65+ return "http://" + mRequestConfiguration.getHost().toString() + mLoginPath;
6266 }
6367
6468 private AlertDialog createRetryDialog(int messageId) {
--- trunk/ov-client/observoice/src/jp/sourceforge/observoice/util/ObsvSetting.java (revision 278)
+++ trunk/ov-client/observoice/src/jp/sourceforge/observoice/util/ObsvSetting.java (revision 279)
@@ -1,20 +1,14 @@
11 package jp.sourceforge.observoice.util;
22
3-import java.io.BufferedReader;
4-import java.io.BufferedWriter;
5-import java.io.InputStreamReader;
6-import java.io.OutputStreamWriter;
7-import java.io.FileNotFoundException;
8-import java.io.IOException;
9-import org.json.JSONObject;
10-import org.json.JSONException;
113 import android.content.Context;
124 import android.content.ContextWrapper;
13-import jp.sourceforge.observoice.exception.ObsvRuntimeException;
5+import android.content.SharedPreferences;
6+import android.content.SharedPreferences.Editor;
7+import android.util.Log;
148
159 /**
1610 * observoiceの設定API用のsingletonクラス instance生成前にsetContextを少なくとも1回呼び出す必要がある
17- *
11+ *
1812 * @author rtakizawa
1913 */
2014 public final class ObsvSetting extends ContextWrapper {
@@ -43,11 +37,9 @@
4337 ObsvSetting.context = context;
4438 }
4539
46- private String filename = "settings.json";
47- private JSONObject json;
40+ private SharedPreferences pref;
4841
4942 private String apiKey;
50- private String hostName;
5143
5244 /**
5345 * インスタンス変数の値を設定ファイルロード前の初期状態にセット
@@ -54,7 +46,6 @@
5446 */
5547 private void initFields() {
5648 apiKey = null;
57- hostName = "localhost:8080";
5849 }
5950
6051 /**
@@ -61,28 +52,9 @@
6152 * 設定ファイルからデータをロード
6253 */
6354 private void load() {
64- try {
65- StringBuffer jsonStr = new StringBuffer();
66- BufferedReader br = new BufferedReader(new InputStreamReader(openFileInput(filename)));
67- String line = br.readLine();
68- while (line != null) {
69- jsonStr.append(line);
70- line = br.readLine();
71- }
72- br.close();
73- // 設定ファイルから読みだしたJSON文字列をJSONObjectに
74- json = new JSONObject(jsonStr.toString());
75- // インスタンス変数の値を更新
76- updateFieldsFromJson();
77- } catch (FileNotFoundException e) {
78- // ファイルがないだけなので
79- initFields();
80- return;
81- } catch (IOException e) {
82- throw new ObsvRuntimeException(e);
83- } catch (JSONException e) {
84- throw new ObsvRuntimeException(e);
85- }
55+ pref = Util.getObsvSharedPreferences(context.getApplicationContext());
56+ // インスタンス変数の値を更新
57+ updateFieldsFromPreferences();
8658 }
8759
8860 /**
@@ -89,50 +61,34 @@
8961 * 更新された設定をファイルに保存
9062 */
9163 private void save() {
92- try {
93- // 現在のインスタンス変数の値でJSONObjectを更新
94- updateJsonFromFields();
95- BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(openFileOutput(filename,
96- MODE_PRIVATE)));
97- bw.write(json.toString());
98- bw.close();
99- } catch (IOException e) {
100- throw new ObsvRuntimeException(e);
101- } catch (JSONException e) {
102- throw new ObsvRuntimeException(e);
103- }
64+ // 現在のインスタンス変数の値で設定を更新
65+ updatePrefFromFields();
10466 }
10567
10668 /**
107- * 設定ファイルから得たJSONObjectでオブジェクトのインスタンス変数を更新
108- *
109- * @throws JSONException
69+ * 設定ファイルでオブジェクトのインスタンス変数を更新
11070 */
111- private void updateFieldsFromJson() throws JSONException {
112- this.apiKey = json.getString("apiKey");
113- if (apiKey.equals(JSONObject.NULL.toString())) {
114- this.apiKey = null;
115- }
116- this.hostName = json.getString("hostName");
71+ private void updateFieldsFromPreferences() {
72+ this.apiKey = pref.getString("API_KEY", null);
11773 }
11874
11975 /**
120- * インスタンス変数からJSONObjectを更新
121- *
122- * @throws JSONException
76+ * インスタンス変数から設定ファイルを更新
12377 */
124- private void updateJsonFromFields() throws JSONException {
125- JSONObject json = new JSONObject();
78+ private void updatePrefFromFields() {
79+ Editor editor = pref.edit();
12680
127- json.put("apiKey", (this.apiKey == null) ? JSONObject.NULL : this.apiKey);
128- json.put("hostName", this.hostName);
81+ Log.d("obsv", "saving API_KEY: " + this.apiKey);
82+ editor.putString("API_KEY", this.apiKey);
12983
130- this.json = json;
84+ editor.commit();
85+
86+ Log.d("obsv", "written API_KEY: " + pref.getString("API_KEY", "default"));
13187 }
13288
13389 /**
13490 * API Keyを返す 設定ファイルがない場合はnull
135- *
91+ *
13692 * @return API Key or null
13793 */
13894 public String loadApiKey() {
@@ -141,7 +97,7 @@
14197
14298 /**
14399 * 引数のAPI Keyを設定ファイルに保存する
144- *
100+ *
145101 * @param apiKey
146102 */
147103 public void saveApiKey(String apiKey) {
@@ -156,14 +112,4 @@
156112 this.apiKey = null;
157113 save();
158114 }
159-
160- /**
161- * observoiceが使用するサーバのホスト名を返す
162- *
163- * @return
164- */
165- public String loadHostName() {
166- return hostName;
167- }
168-
169115 }
--- trunk/ov-client/observoice/src/jp/sourceforge/observoice/util/Util.java (nonexistent)
+++ trunk/ov-client/observoice/src/jp/sourceforge/observoice/util/Util.java (revision 279)
@@ -0,0 +1,15 @@
1+package jp.sourceforge.observoice.util;
2+
3+import android.content.Context;
4+import android.content.SharedPreferences;
5+import android.util.Log;
6+
7+import jp.sourceforge.observoice.R;
8+
9+public abstract class Util {
10+ public static SharedPreferences getObsvSharedPreferences(Context context) {
11+ String filename = context.getApplicationContext().getString(R.string.shared_preferences_filename);
12+ Log.d("obsv", "getting shared preferences: " + filename);
13+ return context.getSharedPreferences(filename, Context.MODE_PRIVATE);
14+ }
15+}
Added: svn:mime-type
## -0,0 +1 ##
+text/plain
\ No newline at end of property
--- trunk/ov-client/observoice/res/values/strings.xml (revision 278)
+++ trunk/ov-client/observoice/res/values/strings.xml (revision 279)
@@ -1,6 +1,8 @@
11 <?xml version="1.0" encoding="utf-8"?>
22 <resources>
33
4+ <string name="shared_preferences_filename">obsv</string>
5+
46 <string name="hello">Hello World, ObservoiceActivity!</string>
57 <string name="app_name">observoice</string>
68 <string name="text">test</string>
@@ -18,7 +20,6 @@
1820 <string name="LectureSearch_start_label">GO</string>
1921 <string name="retry">リトライ</string>
2022 <string name="exit">終了</string>
21- <string name="observoice_uri">http://localhost:8080</string>
2223 <string name="login_path">/web/login</string>
2324 <string name="login_connect_failed">サーバに接続できませんでした</string>
2425 <string name="login_host_lookup_failed">ホスト名を解決できませんでした</string>
Show on old repository browser