merge 29891-networkconfig into trunk
@@ -15,10 +15,12 @@ | ||
15 | 15 | import jp.sourceforge.observoice.entity.Comment; |
16 | 16 | import jp.sourceforge.observoice.entity.WatchingCourseInfo; |
17 | 17 | import jp.sourceforge.observoice.exception.ObsvException; |
18 | +import jp.sourceforge.observoice.network.RequestConfiguration; | |
18 | 19 | import jp.sourceforge.observoice.network.response.CommentListResponse; |
19 | 20 | import jp.sourceforge.observoice.network.response.ObsvResponseObject; |
20 | 21 | import jp.sourceforge.observoice.network.task.GetCommentListTask; |
21 | 22 | import jp.sourceforge.observoice.network.task.ObsvNetworkListener; |
23 | +import jp.sourceforge.observoice.util.Util; | |
22 | 24 | import roboguice.activity.RoboActivity; |
23 | 25 | import roboguice.inject.InjectExtra; |
24 | 26 | import roboguice.inject.InjectView; |
@@ -35,7 +37,7 @@ | ||
35 | 37 | |
36 | 38 | /** |
37 | 39 | * 復習画面 |
38 | - * | |
40 | + * | |
39 | 41 | * @author torikawa |
40 | 42 | * @author rtakizawa |
41 | 43 | */ |
@@ -49,7 +51,7 @@ | ||
49 | 51 | private WatchingCourseInfo mReviewLecture; |
50 | 52 | |
51 | 53 | private int mCourceId; |
52 | - | |
54 | + | |
53 | 55 | private Context mContext; |
54 | 56 | |
55 | 57 | /** |
@@ -64,11 +66,15 @@ | ||
64 | 66 | |
65 | 67 | private ReviewLecturePagerAdapter mPagerAdapter; |
66 | 68 | |
69 | + private RequestConfiguration mRequestConfiguration; | |
70 | + | |
67 | 71 | @Override |
68 | 72 | protected void onCreate(Bundle savedInstanceState) { |
69 | 73 | super.onCreate(savedInstanceState); |
70 | 74 | this.setContentView(R.layout.review_lecture); |
71 | - | |
75 | + | |
76 | + mRequestConfiguration = RequestConfiguration.load(Util.getObsvSharedPreferences(this)); | |
77 | + | |
72 | 78 | mContext = this; |
73 | 79 | |
74 | 80 | mCourceId = mReviewLecture.getCourse().getCourceId(); |
@@ -76,7 +82,7 @@ | ||
76 | 82 | |
77 | 83 | mPagerAdapter = new ReviewLecturePagerAdapter( |
78 | 84 | (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE)); |
79 | - mViewPager.setAdapter(mPagerAdapter); | |
85 | + mViewPager.setAdapter(mPagerAdapter); | |
80 | 86 | } |
81 | 87 | |
82 | 88 | @Override |
@@ -86,7 +92,7 @@ | ||
86 | 92 | //TODO: |
87 | 93 | // 10000件でたぶん全部とれるけどあんまりよくないし、コメントまでとってくるので無駄。 |
88 | 94 | // いずれ別のAPI(コメント投稿日付リストAPI)みたいなのに置き換わる予定。 |
89 | - GetCommentListTask task = new GetCommentListTask(mCourceId, 10000, null, null); | |
95 | + GetCommentListTask task = new GetCommentListTask(mRequestConfiguration, mCourceId, 10000, null, null); | |
90 | 96 | task.setListener(new ObsvNetworkListener() { |
91 | 97 | |
92 | 98 | @Override |
@@ -110,7 +116,7 @@ | ||
110 | 116 | |
111 | 117 | /** |
112 | 118 | * レスポンスのコメントリストからcommentMapへのマップを作成 |
113 | - * | |
119 | + * | |
114 | 120 | * @param responseComments |
115 | 121 | */ |
116 | 122 | private void mapComments(List<Comment> responseComments) { |
@@ -130,7 +136,7 @@ | ||
130 | 136 | |
131 | 137 | /** |
132 | 138 | * コメントリストから日付のリストをもつアダプターを作成する |
133 | - * | |
139 | + * | |
134 | 140 | * @return |
135 | 141 | */ |
136 | 142 | private ArrayAdapter<String> createCommentDatesAdapter() { |
@@ -149,7 +155,7 @@ | ||
149 | 155 | |
150 | 156 | /** |
151 | 157 | * Calendarから日付の文字列表現を得る |
152 | - * | |
158 | + * | |
153 | 159 | * @param cal |
154 | 160 | * @return |
155 | 161 | */ |
@@ -156,16 +162,16 @@ | ||
156 | 162 | private String getDateString(Calendar cal) { |
157 | 163 | return mFormat.format(cal.getTime()); |
158 | 164 | } |
159 | - | |
165 | + | |
160 | 166 | /** |
161 | 167 | * 日付選択ドロップダウンのリスナー |
162 | - * | |
168 | + * | |
163 | 169 | * @author rtakizawa |
164 | 170 | */ |
165 | 171 | private class DaySelectorListener implements AdapterView.OnItemSelectedListener { |
166 | - | |
172 | + | |
167 | 173 | private Context mContext; |
168 | - | |
174 | + | |
169 | 175 | public DaySelectorListener(Context context) { |
170 | 176 | mContext = context; |
171 | 177 | } |
@@ -182,7 +188,7 @@ | ||
182 | 188 | @Override |
183 | 189 | public void onNothingSelected(AdapterView<?> arg0) { |
184 | 190 | } |
185 | - | |
191 | + | |
186 | 192 | } |
187 | 193 | |
188 | 194 | } |
@@ -8,6 +8,7 @@ | ||
8 | 8 | import jp.sourceforge.observoice.debugactivity.DebugMenu; |
9 | 9 | import jp.sourceforge.observoice.debugactivity.NetworkTaskDebugMenu; |
10 | 10 | import jp.sourceforge.observoice.exception.ObsvException; |
11 | +import jp.sourceforge.observoice.network.RequestConfiguration; | |
11 | 12 | import jp.sourceforge.observoice.network.response.ObsvResponseObject; |
12 | 13 | import jp.sourceforge.observoice.network.task.GetAccountTask; |
13 | 14 | import jp.sourceforge.observoice.network.task.GetCommentListTask; |
@@ -18,6 +19,7 @@ | ||
18 | 19 | import jp.sourceforge.observoice.network.task.ObsvNetworkListener; |
19 | 20 | import jp.sourceforge.observoice.network.task.PostCommentTask; |
20 | 21 | import jp.sourceforge.observoice.util.ObsvSetting; |
22 | +import jp.sourceforge.observoice.util.Util; | |
21 | 23 | import roboguice.activity.RoboActivity; |
22 | 24 | import roboguice.inject.InjectView; |
23 | 25 | import android.content.Intent; |
@@ -51,15 +53,25 @@ | ||
51 | 53 | private TextView responseView; |
52 | 54 | |
53 | 55 | 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 | + | |
54 | 66 | // ネットワークAPIを叩くだけの簡単なデバッグ項目はここへ追加する。 |
55 | 67 | 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) | |
63 | 75 | ); |
64 | 76 | // インテントを投げるだけの簡単なデバッグ項目はここへ追加する。 |
65 | 77 | final List<ActivityDebugMenu> debugMenuListOfActivity = Arrays.asList( |
@@ -73,7 +85,7 @@ | ||
73 | 85 | } |
74 | 86 | |
75 | 87 | // デバッグ項目リストへすべてのデバッグ項目を追加する。 |
76 | - this.debugMenuList = new ArrayList<DebugMenu>(debugMenuListOfNetwork); | |
88 | + this.debugMenuList.addAll(debugMenuListOfNetwork); | |
77 | 89 | this.debugMenuList.addAll(debugMenuListOfActivity); |
78 | 90 | this.debugMenuList.add(new DebugMenu(R.string.restart) { |
79 | 91 | @Override |
@@ -89,13 +101,7 @@ | ||
89 | 101 | loadApiKey(); |
90 | 102 | } |
91 | 103 | }); |
92 | - } | |
93 | 104 | |
94 | - @Override | |
95 | - protected void onCreate(Bundle savedInstanceState) { | |
96 | - super.onCreate(savedInstanceState); | |
97 | - setContentView(R.layout.debug); | |
98 | - | |
99 | 105 | responseView.setKeyListener(null); |
100 | 106 | loadApiKey(); |
101 | 107 | } |
@@ -15,6 +15,8 @@ | ||
15 | 15 | |
16 | 16 | import android.widget.LinearLayout; |
17 | 17 | |
18 | +import jp.sourceforge.observoice.network.RequestConfiguration; | |
19 | +import jp.sourceforge.observoice.util.Util; | |
18 | 20 | import jp.sourceforge.observoice.util.WidgetUtil; |
19 | 21 | |
20 | 22 | import roboguice.activity.RoboFragmentActivity; |
@@ -38,7 +40,8 @@ | ||
38 | 40 | mChartFragment = (UnderstandabilityChartFragment) |
39 | 41 | getSupportFragmentManager().findFragmentById(R.id.chart_engine_test_chart_fragment); |
40 | 42 | |
41 | - mCommentGetter = new CommentListIntervalGetter(1, new Handler()); | |
43 | + mCommentGetter = new CommentListIntervalGetter(1, new Handler(), | |
44 | + RequestConfiguration.load(Util.getObsvSharedPreferences(this))); | |
42 | 45 | mCommentGetter.addOnReceivedListener(this); |
43 | 46 | } |
44 | 47 |
@@ -6,11 +6,13 @@ | ||
6 | 6 | import jp.sourceforge.observoice.adapter.SearchedLectureListAdapter; |
7 | 7 | import jp.sourceforge.observoice.entity.Course; |
8 | 8 | import jp.sourceforge.observoice.exception.ObsvException; |
9 | +import jp.sourceforge.observoice.network.RequestConfiguration; | |
9 | 10 | import jp.sourceforge.observoice.network.response.LectureInfoListResponse; |
10 | 11 | import jp.sourceforge.observoice.network.response.ObsvResponseObject; |
11 | 12 | import jp.sourceforge.observoice.network.task.GetLectureInfoListTask; |
12 | 13 | import jp.sourceforge.observoice.network.task.ObsvNetworkListener; |
13 | 14 | import jp.sourceforge.observoice.network.task.ObsvNetworkTask; |
15 | +import jp.sourceforge.observoice.util.Util; | |
14 | 16 | import roboguice.activity.RoboActivity; |
15 | 17 | import roboguice.inject.InjectView; |
16 | 18 | import android.app.AlertDialog; |
@@ -56,11 +58,15 @@ | ||
56 | 58 | java.util.Calendar.TUESDAY, java.util.Calendar.WEDNESDAY, java.util.Calendar.THURSDAY, |
57 | 59 | java.util.Calendar.FRIDAY, java.util.Calendar.SATURDAY, java.util.Calendar.SUNDAY }; |
58 | 60 | |
61 | + private RequestConfiguration mRequestConfiguration; | |
62 | + | |
59 | 63 | @Override |
60 | 64 | protected void onCreate(Bundle savedInstanceState) { |
61 | 65 | super.onCreate(savedInstanceState); |
62 | 66 | setContentView(R.layout.lecture_search); |
63 | 67 | |
68 | + mRequestConfiguration = RequestConfiguration.load(Util.getObsvSharedPreferences(this)); | |
69 | + | |
64 | 70 | searchButton.setOnClickListener(this); |
65 | 71 | |
66 | 72 | // エンター押下で検索実行 |
@@ -101,8 +107,8 @@ | ||
101 | 107 | |
102 | 108 | // 講義情報一覧取得を表すオブジェクトを作成。 |
103 | 109 | // 検索したくない項目には 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); | |
106 | 112 | |
107 | 113 | // 自分自身 |
108 | 114 | final LectureSearchActivity self = this; |
@@ -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 | +} |
@@ -1,15 +1,20 @@ | ||
1 | 1 | package jp.sourceforge.observoice.network.task; |
2 | 2 | |
3 | +import jp.sourceforge.observoice.network.RequestConfiguration; | |
3 | 4 | import jp.sourceforge.observoice.network.requestmethod.GetAccountMethod; |
4 | 5 | import jp.sourceforge.observoice.network.requestmethod.ObsvRequestMethod; |
5 | 6 | |
6 | 7 | /** |
7 | 8 | * アカウントタスク |
8 | - * | |
9 | + * | |
9 | 10 | * @author rtakizawa |
10 | 11 | */ |
11 | 12 | public class GetAccountTask extends ObsvNetworkTask { |
12 | 13 | |
14 | + public GetAccountTask(RequestConfiguration requestConfiguration) { | |
15 | + super(requestConfiguration); | |
16 | + } | |
17 | + | |
13 | 18 | @Override |
14 | 19 | protected ObsvRequestMethod createRequestMethod() { |
15 | 20 | return new GetAccountMethod(); |
@@ -1,12 +1,14 @@ | ||
1 | 1 | package jp.sourceforge.observoice.network.task; |
2 | 2 | |
3 | 3 | import java.util.Calendar; |
4 | + | |
5 | +import jp.sourceforge.observoice.network.RequestConfiguration; | |
4 | 6 | import jp.sourceforge.observoice.network.requestmethod.ObsvRequestMethod; |
5 | 7 | import jp.sourceforge.observoice.network.requestmethod.GetCommentListMethod; |
6 | 8 | |
7 | 9 | /** |
8 | 10 | * courceIdの講義のコメントリストを取得する操作 |
9 | - * | |
11 | + * | |
10 | 12 | * @author rtakizawa |
11 | 13 | */ |
12 | 14 | public class GetCommentListTask extends ObsvNetworkTask { |
@@ -18,10 +20,13 @@ | ||
18 | 20 | /** |
19 | 21 | * デフォルト設定 |
20 | 22 | * 現在時刻の90分前から現在までのコメントを100件まで取得 |
21 | - * | |
23 | + * | |
22 | 24 | * @param courceId 講義ID |
23 | 25 | */ |
24 | - public GetCommentListTask(int courceId) { | |
26 | + public GetCommentListTask(RequestConfiguration requestConfiguration, | |
27 | + int courceId) { | |
28 | + super(requestConfiguration); | |
29 | + | |
25 | 30 | this.courceId = courceId; |
26 | 31 | this.count = 100; |
27 | 32 | this.since = Calendar.getInstance(); |
@@ -35,7 +40,10 @@ | ||
35 | 40 | * @param since この日時以降のコメントを取得 (nullなら指定なし) |
36 | 41 | * @param until この日時以前のコメントを取得 (nullなら指定なし) |
37 | 42 | */ |
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 | + | |
39 | 47 | this.courceId = courceId; |
40 | 48 | this.count = count; |
41 | 49 | this.since = since; |
@@ -1,15 +1,20 @@ | ||
1 | 1 | package jp.sourceforge.observoice.network.task; |
2 | 2 | |
3 | +import jp.sourceforge.observoice.network.RequestConfiguration; | |
3 | 4 | import jp.sourceforge.observoice.network.requestmethod.ObsvRequestMethod; |
4 | 5 | import jp.sourceforge.observoice.network.requestmethod.GetCurrentLectureInfoListMethod; |
5 | 6 | |
6 | 7 | /** |
7 | 8 | * 開講中の講義情報リストを取得する操作を表すクラス |
8 | - * | |
9 | + * | |
9 | 10 | * @author rtakizawa |
10 | 11 | */ |
11 | 12 | public class GetCurrentLectureInfoListTask extends ObsvNetworkTask { |
12 | 13 | |
14 | + public GetCurrentLectureInfoListTask(RequestConfiguration requestConfiguration) { | |
15 | + super(requestConfiguration); | |
16 | + } | |
17 | + | |
13 | 18 | @Override |
14 | 19 | protected ObsvRequestMethod createRequestMethod() { |
15 | 20 | return new GetCurrentLectureInfoListMethod(); |
@@ -1,11 +1,12 @@ | ||
1 | 1 | package jp.sourceforge.observoice.network.task; |
2 | 2 | |
3 | +import jp.sourceforge.observoice.network.RequestConfiguration; | |
3 | 4 | import jp.sourceforge.observoice.network.requestmethod.ObsvRequestMethod; |
4 | 5 | import jp.sourceforge.observoice.network.requestmethod.GetLectureInfoMethod; |
5 | 6 | |
6 | 7 | /** |
7 | 8 | * 講義情報取得操作を表す |
8 | - * | |
9 | + * | |
9 | 10 | * @author rtakizawa |
10 | 11 | */ |
11 | 12 | public class GetLectureInfoTask extends ObsvNetworkTask { |
@@ -15,7 +16,10 @@ | ||
15 | 16 | /** |
16 | 17 | * @param courceId 講義ID |
17 | 18 | */ |
18 | - public GetLectureInfoTask(int courceId) { | |
19 | + public GetLectureInfoTask(RequestConfiguration requestConfiguration, | |
20 | + int courceId) { | |
21 | + super(requestConfiguration); | |
22 | + | |
19 | 23 | this.courceId = courceId; |
20 | 24 | } |
21 | 25 |
@@ -3,6 +3,7 @@ | ||
3 | 3 | import android.os.AsyncTask; |
4 | 4 | import jp.sourceforge.observoice.exception.ObsvException; |
5 | 5 | import jp.sourceforge.observoice.exception.ObsvRuntimeException; |
6 | +import jp.sourceforge.observoice.network.RequestConfiguration; | |
6 | 7 | import jp.sourceforge.observoice.network.requestmethod.ObsvRequestMethod; |
7 | 8 | import jp.sourceforge.observoice.network.response.ObsvResponseObject; |
8 | 9 | import jp.sourceforge.observoice.network.task.ObsvNetworkListener; |
@@ -18,7 +19,13 @@ | ||
18 | 19 | private ObsvNetworkListener listener; |
19 | 20 | // doInBackground中で投げられた例外 |
20 | 21 | private Exception thrownException; |
22 | + // APIリクエストの送信設定 | |
23 | + private RequestConfiguration requestConfiguration; | |
21 | 24 | |
25 | + public ObsvNetworkTask(RequestConfiguration requestConfiguration) { | |
26 | + this.requestConfiguration = requestConfiguration; | |
27 | + } | |
28 | + | |
22 | 29 | /** |
23 | 30 | * リスナーの登録 |
24 | 31 | * |
@@ -39,7 +46,7 @@ | ||
39 | 46 | // 対応するリクエストメソッドを生成 |
40 | 47 | ObsvRequestMethod requestMethod = createRequestMethod(); |
41 | 48 | // 送信して結果を返す |
42 | - return requestMethod.send(); | |
49 | + return requestMethod.send(requestConfiguration); | |
43 | 50 | } catch (ObsvException e) { |
44 | 51 | // 発生した(RuntimeException以外の)例外を補足 |
45 | 52 | this.thrownException = e; |
@@ -1,5 +1,6 @@ | ||
1 | 1 | package jp.sourceforge.observoice.network.task; |
2 | 2 | |
3 | +import jp.sourceforge.observoice.network.RequestConfiguration; | |
3 | 4 | import jp.sourceforge.observoice.network.requestmethod.GetWatchingCourseInfoListMethod; |
4 | 5 | import jp.sourceforge.observoice.network.requestmethod.ObsvRequestMethod; |
5 | 6 |
@@ -10,7 +11,8 @@ | ||
10 | 11 | */ |
11 | 12 | public class GetWatchingCoursesTask extends ObsvNetworkTask { |
12 | 13 | |
13 | - public GetWatchingCoursesTask() { | |
14 | + public GetWatchingCoursesTask(RequestConfiguration requestConfiguration) { | |
15 | + super(requestConfiguration); | |
14 | 16 | } |
15 | 17 | |
16 | 18 | @Override |
@@ -1,5 +1,6 @@ | ||
1 | 1 | package jp.sourceforge.observoice.network.task; |
2 | 2 | |
3 | +import jp.sourceforge.observoice.network.RequestConfiguration; | |
3 | 4 | import jp.sourceforge.observoice.network.requestmethod.ObsvRequestMethod; |
4 | 5 | import jp.sourceforge.observoice.network.requestmethod.PostCommentMethod; |
5 | 6 |
@@ -16,7 +17,10 @@ | ||
16 | 17 | * @param type 理解度(0 or 1) |
17 | 18 | * @param content コメント内容 |
18 | 19 | */ |
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 | + | |
20 | 24 | this.courceId = courceId; |
21 | 25 | this.userId = userId; |
22 | 26 | this.type = type; |
@@ -1,5 +1,6 @@ | ||
1 | 1 | package jp.sourceforge.observoice.network.task; |
2 | 2 | |
3 | +import jp.sourceforge.observoice.network.RequestConfiguration; | |
3 | 4 | import jp.sourceforge.observoice.network.requestmethod.WatchLectureMethod; |
4 | 5 | import jp.sourceforge.observoice.network.requestmethod.ObsvRequestMethod; |
5 | 6 |
@@ -12,7 +13,10 @@ | ||
12 | 13 | |
13 | 14 | private final int courceId; |
14 | 15 | |
15 | - public WatchLectureTask(int courceId) { | |
16 | + public WatchLectureTask(RequestConfiguration requestConfiguration, | |
17 | + int courceId) { | |
18 | + super(requestConfiguration); | |
19 | + | |
16 | 20 | this.courceId = courceId; |
17 | 21 | } |
18 | 22 |
@@ -1,11 +1,12 @@ | ||
1 | 1 | package jp.sourceforge.observoice.network.task; |
2 | 2 | |
3 | +import jp.sourceforge.observoice.network.RequestConfiguration; | |
3 | 4 | import jp.sourceforge.observoice.network.requestmethod.ObsvRequestMethod; |
4 | 5 | import jp.sourceforge.observoice.network.requestmethod.GetLectureInfoListMethod; |
5 | 6 | |
6 | 7 | /** |
7 | 8 | * 講義情報リスト取得操作を表す |
8 | - * | |
9 | + * | |
9 | 10 | * @author rtakizawa |
10 | 11 | */ |
11 | 12 | public class GetLectureInfoListTask extends ObsvNetworkTask { |
@@ -17,10 +18,13 @@ | ||
17 | 18 | |
18 | 19 | /** |
19 | 20 | * count件数の講義情報リストを取得するタスクのコンストラクタ |
20 | - * | |
21 | + * | |
21 | 22 | * @param count |
22 | 23 | */ |
23 | - public GetLectureInfoListTask(int count) { | |
24 | + public GetLectureInfoListTask(RequestConfiguration requestConfiguration, | |
25 | + int count) { | |
26 | + super(requestConfiguration); | |
27 | + | |
24 | 28 | this.count = count; |
25 | 29 | this.day = 0; |
26 | 30 | this.period = 0; |
@@ -29,13 +33,16 @@ | ||
29 | 33 | |
30 | 34 | /** |
31 | 35 | * 条件に合う講義情報リストを取得するタスクのコンストラクタ |
32 | - * | |
36 | + * | |
33 | 37 | * @param count 取得する講義情報の件数 |
34 | 38 | * @param day 曜日(or 0(=指定なし)) |
35 | 39 | * @param period 時限(or 0(=指定なし)) |
36 | 40 | * @param q 検索文字列(or null(=指定なし)) |
37 | 41 | */ |
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 | + | |
39 | 46 | this.count = count; |
40 | 47 | this.day = day; |
41 | 48 | this.period = period; |
@@ -2,6 +2,7 @@ | ||
2 | 2 | |
3 | 3 | import java.io.IOException; |
4 | 4 | import java.io.UnsupportedEncodingException; |
5 | + | |
5 | 6 | import java.util.ArrayList; |
6 | 7 | import java.util.List; |
7 | 8 | import java.util.Map; |
@@ -9,7 +10,6 @@ | ||
9 | 10 | import jp.sourceforge.observoice.R; |
10 | 11 | import jp.sourceforge.observoice.exception.ObsvException; |
11 | 12 | import jp.sourceforge.observoice.exception.ObsvRuntimeException; |
12 | -import jp.sourceforge.observoice.util.ObsvSetting; | |
13 | 13 | |
14 | 14 | import org.apache.http.HttpEntity; |
15 | 15 | import org.apache.http.HttpResponse; |
@@ -77,7 +77,7 @@ | ||
77 | 77 | // 接続のタイムアウトを設定 |
78 | 78 | HttpConnectionParams.setConnectionTimeout(params, timeout); |
79 | 79 | HttpConnectionParams.setSoTimeout(params, timeout); |
80 | - | |
80 | + | |
81 | 81 | // コンテンツの文字コードをUTF-8に設定 |
82 | 82 | HttpProtocolParams.setContentCharset(params, encoding); |
83 | 83 | } |
@@ -88,7 +88,7 @@ | ||
88 | 88 | |
89 | 89 | /** |
90 | 90 | * getメソッドを送る |
91 | - * | |
91 | + * | |
92 | 92 | * @param url |
93 | 93 | * @param qParams |
94 | 94 | * クエリパラメータの辞書 |
@@ -101,7 +101,7 @@ | ||
101 | 101 | |
102 | 102 | /** |
103 | 103 | * POSTメソッドを送る |
104 | - * | |
104 | + * | |
105 | 105 | * @param url |
106 | 106 | * @param qParams |
107 | 107 | * クエリパラメータの辞書 |
@@ -117,7 +117,7 @@ | ||
117 | 117 | |
118 | 118 | /** |
119 | 119 | * サーバにmethodを送りレスポンスを返す |
120 | - * | |
120 | + * | |
121 | 121 | * @param method |
122 | 122 | * GETもしくはPOSTメソッドを表すオブジェクト(HttpGet or HttpPost) |
123 | 123 | * @return |
@@ -160,7 +160,7 @@ | ||
160 | 160 | |
161 | 161 | /** |
162 | 162 | * GETメソッドを表すオブジェクト(HttpGet)を作って返す |
163 | - * | |
163 | + * | |
164 | 164 | * @param url |
165 | 165 | * @param qParams |
166 | 166 | * クエリパラメータの辞書 |
@@ -170,7 +170,6 @@ | ||
170 | 170 | String query = createQuery(qParams); |
171 | 171 | |
172 | 172 | HttpGet httpGet = new HttpGet(url + "?" + query); |
173 | - httpGet.setHeader("host", ObsvSetting.getInstance().loadHostName()); | |
174 | 173 | httpGet.setHeader("User-Agent", userAgentName); |
175 | 174 | httpGet.setHeader("Accept-Charset", encoding); |
176 | 175 |
@@ -179,7 +178,7 @@ | ||
179 | 178 | |
180 | 179 | /** |
181 | 180 | * POSTメソッドを表すオブジェクト(HttpPost)を作って返す |
182 | - * | |
181 | + * | |
183 | 182 | * @param url |
184 | 183 | * @param qParams |
185 | 184 | * クエリパラメータの辞書 |
@@ -193,8 +192,6 @@ | ||
193 | 192 | HttpPost httpPost = new HttpPost(url + "?" + query); |
194 | 193 | httpPost.setEntity(createUrlEncodedFormEntity(fParams)); |
195 | 194 | |
196 | - httpPost.setHeader("host", ObsvSetting.getInstance().loadHostName()); | |
197 | - | |
198 | 195 | // Content-Typeに文字コードを含めないとPOSTコンテンツが正しくエンコードされない |
199 | 196 | // これはorg.apache.httpの仕様による |
200 | 197 | httpPost.setHeader("Content-Type", "application/x-www-form-urlencoded; charset=" + encoding); |
@@ -207,7 +204,7 @@ | ||
207 | 204 | |
208 | 205 | /** |
209 | 206 | * クエリパラメータの辞書からクエリパラメータを作成 |
210 | - * | |
207 | + * | |
211 | 208 | * @param qParams |
212 | 209 | * @return |
213 | 210 | */ |
@@ -221,7 +218,7 @@ | ||
221 | 218 | |
222 | 219 | /** |
223 | 220 | * フォームパラメータの辞書からフォームパラメータのエンティティを作成 |
224 | - * | |
221 | + * | |
225 | 222 | * @param fParams |
226 | 223 | * @return |
227 | 224 | */ |
@@ -12,12 +12,11 @@ | ||
12 | 12 | |
13 | 13 | /** |
14 | 14 | * コメント一覧取得を要求するリクエストメソッド |
15 | - * | |
15 | + * | |
16 | 16 | * @author rtakizawa |
17 | 17 | */ |
18 | 18 | public class GetCommentListMethod extends ObsvGetRequestMethod { |
19 | 19 | |
20 | - private int courceId; | |
21 | 20 | private int count; |
22 | 21 | private String since, until; |
23 | 22 |
@@ -28,7 +27,8 @@ | ||
28 | 27 | * @param until この日付以前のコメントを取得 (nullなら指定なし) |
29 | 28 | */ |
30 | 29 | public GetCommentListMethod(int courceId, int count, Calendar since, Calendar until) { |
31 | - this.courceId = courceId; | |
30 | + super("/courses/" + courceId + "/comments.json"); | |
31 | + | |
32 | 32 | this.count = count; |
33 | 33 | if (since != null) { |
34 | 34 | this.since = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss Z", Locale.US).format(since.getTime()); |
@@ -39,8 +39,8 @@ | ||
39 | 39 | } |
40 | 40 | |
41 | 41 | @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); | |
44 | 44 | |
45 | 45 | queryParameters.put("count", String.valueOf(count)); |
46 | 46 | if (since != null) { |
@@ -49,15 +49,10 @@ | ||
49 | 49 | if (until != null) { |
50 | 50 | queryParameters.put("until", until); |
51 | 51 | } |
52 | - | |
52 | + | |
53 | 53 | return queryParameters; |
54 | 54 | } |
55 | 55 | |
56 | - @Override | |
57 | - protected String createUrlString() { | |
58 | - return "http://" + hostName + "/api/courses/" + courceId + "/comments.json"; | |
59 | - } | |
60 | - | |
61 | 56 | public ObsvResponseObject createResponseObject(String response) throws JSONException { |
62 | 57 | return new CommentListResponse(response); |
63 | 58 | } |
@@ -6,14 +6,13 @@ | ||
6 | 6 | |
7 | 7 | /** |
8 | 8 | * 開講中の講義情報リストを取得するリクエストメソッド |
9 | - * | |
9 | + * | |
10 | 10 | * @author rtakizawa |
11 | 11 | */ |
12 | 12 | public class GetCurrentLectureInfoListMethod extends ObsvGetRequestMethod { |
13 | 13 | |
14 | - @Override | |
15 | - protected String createUrlString() { | |
16 | - return "http://" + hostName + "/api/courses/current.json"; | |
14 | + public GetCurrentLectureInfoListMethod() { | |
15 | + super("/courses/current.json"); | |
17 | 16 | } |
18 | 17 | |
19 | 18 | @Override |
@@ -7,26 +7,19 @@ | ||
7 | 7 | |
8 | 8 | /** |
9 | 9 | * 講義情報取得メソッド |
10 | - * | |
10 | + * | |
11 | 11 | * @author rtakizawa |
12 | 12 | */ |
13 | 13 | public class GetLectureInfoMethod extends ObsvGetRequestMethod { |
14 | 14 | |
15 | - private int courceId; | |
16 | - | |
17 | 15 | /** |
18 | 16 | * @param courceId 講義ID |
19 | 17 | */ |
20 | 18 | public GetLectureInfoMethod(int courceId) { |
21 | - this.courceId = courceId; | |
19 | + super("/courses/" + courceId + ".json"); | |
22 | 20 | } |
23 | 21 | |
24 | 22 | @Override |
25 | - protected String createUrlString() { | |
26 | - return "http://" + hostName + "/api/courses/" + courceId + ".json"; | |
27 | - } | |
28 | - | |
29 | - @Override | |
30 | 23 | public ObsvResponseObject createResponseObject(String response) throws JSONException { |
31 | 24 | return new LectureInfoResponse(response); |
32 | 25 | } |
@@ -7,26 +7,31 @@ | ||
7 | 7 | import jp.sourceforge.observoice.exception.ObsvException; |
8 | 8 | import jp.sourceforge.observoice.exception.ObsvRuntimeException; |
9 | 9 | import jp.sourceforge.observoice.network.ObsvHttpClient; |
10 | +import jp.sourceforge.observoice.network.RequestConfiguration; | |
10 | 11 | import jp.sourceforge.observoice.network.response.ObsvResponseObject; |
11 | 12 | |
12 | 13 | /** |
13 | 14 | * Observoiceのクライアントからサーバーへ送信するGETリクエストメソッドデータを表す抽象クラス。 |
14 | 15 | * 実際のリクエストメソッドのデータは子クラスになる。 |
15 | - * | |
16 | + * | |
16 | 17 | * @author rtakizawa |
17 | 18 | */ |
18 | 19 | public abstract class ObsvGetRequestMethod extends ObsvRequestMethod { |
19 | 20 | |
21 | + protected ObsvGetRequestMethod(String apiPath) { | |
22 | + super(apiPath); | |
23 | + } | |
24 | + | |
20 | 25 | /** |
21 | 26 | * Observoiceリクエストメソッドの送信 |
22 | - * | |
27 | + * | |
23 | 28 | * @return サーバーからのレスポンス |
24 | 29 | * @throws ObsvException |
25 | 30 | */ |
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 | + | |
30 | 35 | try { |
31 | 36 | String res = ObsvHttpClient.getInstance().get(urlStr, queryParameters); |
32 | 37 | return createResponseObject(res); |
@@ -1,5 +1,6 @@ | ||
1 | 1 | package jp.sourceforge.observoice.network.requestmethod; |
2 | 2 | |
3 | +import java.net.InetSocketAddress; | |
3 | 4 | import java.util.HashMap; |
4 | 5 | import java.util.Map; |
5 | 6 |
@@ -6,31 +7,24 @@ | ||
6 | 7 | import org.json.JSONException; |
7 | 8 | |
8 | 9 | import jp.sourceforge.observoice.exception.ObsvException; |
9 | -import jp.sourceforge.observoice.network.ObsvHttpClient; | |
10 | +import jp.sourceforge.observoice.network.RequestConfiguration; | |
10 | 11 | import jp.sourceforge.observoice.network.response.ObsvResponseObject; |
11 | -import jp.sourceforge.observoice.util.ObsvSetting; | |
12 | 12 | |
13 | 13 | /** |
14 | 14 | * Observoiceのクライアントからサーバーへ送信するリクエストメソッドデータクラス。 |
15 | - * | |
15 | + * | |
16 | 16 | * @author rtakizawa |
17 | 17 | */ |
18 | 18 | public abstract class ObsvRequestMethod { |
19 | 19 | |
20 | - /** | |
21 | - * apiKey | |
22 | - */ | |
23 | - protected String apiKey; | |
20 | + private String apiPath; | |
24 | 21 | |
25 | 22 | /** |
26 | - * サーバのホスト名 | |
23 | + * APIリクエストを生成 | |
24 | + * @param apiPath APIへのパス(例: /courses.json) | |
27 | 25 | */ |
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; | |
34 | 28 | } |
35 | 29 | |
36 | 30 | /** |
@@ -37,7 +31,7 @@ | ||
37 | 31 | * クエリパラメータの辞書を返す |
38 | 32 | * サブクラスでこのメソッドを実装する場合は必ずこのスーパーメソッドを呼び出す必要がある |
39 | 33 | */ |
40 | - protected Map<String, String> createQueryParameters() { | |
34 | + protected Map<String, String> createQueryParameters(String apiKey) { | |
41 | 35 | Map<String, String> queryParams = new HashMap<String, String>(); |
42 | 36 | queryParams.put("apiKey", apiKey); |
43 | 37 | return queryParams; |
@@ -44,21 +38,29 @@ | ||
44 | 38 | } |
45 | 39 | |
46 | 40 | /** |
47 | - * リクエストメソッドを送信する対象URL文字列を返す | |
41 | + * リクエストの送信先URLを生成する | |
42 | + * | |
43 | + * @param host 送信先ホスト | |
44 | + * @param apiBasePath APIのベースパス(例: /api) | |
45 | + * @return | |
48 | 46 | */ |
49 | - protected abstract String createUrlString(); | |
47 | + public String createUrlString(InetSocketAddress host, String apiBasePath) { | |
48 | + return "http://" + host.toString() + apiBasePath + apiPath; | |
49 | + } | |
50 | 50 | |
51 | 51 | /** |
52 | 52 | * リクエストメソッドを送信する |
53 | - * | |
53 | + * | |
54 | + * @param host 送信先ホスト名とポート番号 | |
55 | + * @param apiBasePath APIのベースパス(例: /api) | |
54 | 56 | * @return |
55 | 57 | */ |
56 | - public abstract ObsvResponseObject send() throws ObsvException; | |
58 | + public abstract ObsvResponseObject send(RequestConfiguration conf) throws ObsvException; | |
57 | 59 | |
58 | 60 | /** |
59 | - * | |
61 | + * | |
60 | 62 | * リクエストメソッドに対応するレスポンスオブジェクトを生成 |
61 | - * | |
63 | + * | |
62 | 64 | * @param response |
63 | 65 | * @return |
64 | 66 | * @throws JSONException |
@@ -8,27 +8,32 @@ | ||
8 | 8 | import jp.sourceforge.observoice.exception.ObsvException; |
9 | 9 | import jp.sourceforge.observoice.exception.ObsvRuntimeException; |
10 | 10 | import jp.sourceforge.observoice.network.ObsvHttpClient; |
11 | +import jp.sourceforge.observoice.network.RequestConfiguration; | |
11 | 12 | import jp.sourceforge.observoice.network.response.ObsvResponseObject; |
12 | 13 | |
13 | 14 | /** |
14 | 15 | * Observoiceのクライアントからサーバーへ送信するPOSTリクエストメソッドデータを表す抽象クラス。 |
15 | 16 | * 実際のリクエストメソッドのデータは子クラスになる。 |
16 | - * | |
17 | + * | |
17 | 18 | * @author rtakizawa |
18 | 19 | */ |
19 | 20 | public abstract class ObsvPostRequestMethod extends ObsvRequestMethod { |
20 | 21 | |
22 | + protected ObsvPostRequestMethod(String apiPath) { | |
23 | + super(apiPath); | |
24 | + } | |
25 | + | |
21 | 26 | /** |
22 | 27 | * Observoiceリクエストメソッドの送信 |
23 | - * | |
28 | + * | |
24 | 29 | * @return サーバーからのレスポンスを表すレスポンスオブジェクト |
25 | 30 | * @throws ObsvException |
26 | 31 | */ |
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()); | |
30 | 35 | Map<String, String> formParameters = createFormParameters(); |
31 | - | |
36 | + | |
32 | 37 | try { |
33 | 38 | String response = ObsvHttpClient.getInstance().post(urlStr, queryParameters, formParameters); |
34 | 39 | return createResponseObject(response); |
@@ -8,18 +8,18 @@ | ||
8 | 8 | |
9 | 9 | /** |
10 | 10 | * サーバにコメント投稿する際に送信するリクエストメソッドを表す |
11 | - * | |
11 | + * | |
12 | 12 | * @author rtakizawa |
13 | 13 | */ |
14 | 14 | public class PostCommentMethod extends ObsvPostRequestMethod { |
15 | 15 | |
16 | - private int courceId; | |
17 | 16 | private String userId; |
18 | 17 | private int type; |
19 | 18 | private String content; |
20 | 19 | |
21 | 20 | public PostCommentMethod(int courceId, String userId, int type, String content) { |
22 | - this.courceId = courceId; | |
21 | + super("/courses/" + courceId + "/comments/post.json"); | |
22 | + | |
23 | 23 | this.userId = userId; |
24 | 24 | this.type = type; |
25 | 25 | this.content = content; |
@@ -41,9 +41,4 @@ | ||
41 | 41 | return formParameters; |
42 | 42 | } |
43 | 43 | |
44 | - @Override | |
45 | - protected String createUrlString() { | |
46 | - return "http://" + hostName + "/api/courses/" + courceId + "/comments/post.json"; | |
47 | - } | |
48 | - | |
49 | 44 | } |
@@ -11,20 +11,13 @@ | ||
11 | 11 | */ |
12 | 12 | public class WatchLectureMethod extends ObsvPostRequestMethod { |
13 | 13 | |
14 | - private final int courceId; | |
15 | - | |
16 | 14 | /** |
17 | 15 | * @param courceId 講義ID |
18 | 16 | */ |
19 | 17 | 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"); | |
26 | 19 | } |
27 | - | |
20 | + | |
28 | 21 | @Override |
29 | 22 | public ObsvResponseObject createResponseObject(String response) |
30 | 23 | throws JSONException { |
@@ -9,7 +9,7 @@ | ||
9 | 9 | |
10 | 10 | /** |
11 | 11 | * 講義情報リストを取得するリクエストメソッド |
12 | - * | |
12 | + * | |
13 | 13 | * @author rtakizawa |
14 | 14 | */ |
15 | 15 | public class GetLectureInfoListMethod extends ObsvGetRequestMethod { |
@@ -21,7 +21,7 @@ | ||
21 | 21 | |
22 | 22 | /** |
23 | 23 | * 条件に合う講義情報のリストを取得 |
24 | - * | |
24 | + * | |
25 | 25 | * @param count 取得する講義情報の件数 |
26 | 26 | * @param day 曜日(or 0(=指定なし)) |
27 | 27 | * @param period 時限(or 0(=指定なし)) |
@@ -28,6 +28,8 @@ | ||
28 | 28 | * @param q 検索文字列(or null(=指定なし)) |
29 | 29 | */ |
30 | 30 | public GetLectureInfoListMethod(int count, int day, int period, String q) { |
31 | + super("/courses.json"); | |
32 | + | |
31 | 33 | this.count = count; |
32 | 34 | this.day = day; |
33 | 35 | this.period = period; |
@@ -35,9 +37,9 @@ | ||
35 | 37 | } |
36 | 38 | |
37 | 39 | @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 | + | |
41 | 43 | queryParameters.put("count", String.valueOf(count)); |
42 | 44 | if (day != 0) { |
43 | 45 | queryParameters.put("day", String.valueOf(day)); |
@@ -48,16 +50,11 @@ | ||
48 | 50 | if (q != null) { |
49 | 51 | queryParameters.put("q", q); |
50 | 52 | } |
51 | - | |
53 | + | |
52 | 54 | return queryParameters; |
53 | 55 | } |
54 | 56 | |
55 | 57 | @Override |
56 | - protected String createUrlString() { | |
57 | - return "http://" + hostName + "/api/courses.json"; | |
58 | - } | |
59 | - | |
60 | - @Override | |
61 | 58 | public ObsvResponseObject createResponseObject(String response) |
62 | 59 | throws JSONException { |
63 | 60 | return new LectureInfoListResponse(response); |
@@ -7,14 +7,13 @@ | ||
7 | 7 | |
8 | 8 | /** |
9 | 9 | * アカウント情報取得API用リクエストメソッド |
10 | - * | |
10 | + * | |
11 | 11 | * @author rtakizawa |
12 | 12 | */ |
13 | 13 | public class GetAccountMethod extends ObsvGetRequestMethod { |
14 | 14 | |
15 | - @Override | |
16 | - protected String createUrlString() { | |
17 | - return "http://" + hostName + "/api/account.json"; | |
15 | + public GetAccountMethod() { | |
16 | + super("/account.json"); | |
18 | 17 | } |
19 | 18 | |
20 | 19 | @Override |
@@ -15,14 +15,10 @@ | ||
15 | 15 | /** |
16 | 16 | */ |
17 | 17 | public GetWatchingCourseInfoListMethod() { |
18 | + super("/courses/watching.json"); | |
18 | 19 | } |
19 | 20 | |
20 | 21 | @Override |
21 | - protected String createUrlString() { | |
22 | - return "http://" + hostName + "/api/courses/watching.json"; | |
23 | - } | |
24 | - | |
25 | - @Override | |
26 | 22 | public ObsvResponseObject createResponseObject(String response) |
27 | 23 | throws JSONException { |
28 | 24 | return new WatchingCourseInfoListResponse(response); |
@@ -9,6 +9,7 @@ | ||
9 | 9 | import jp.sourceforge.observoice.entity.TimeSlot; |
10 | 10 | import jp.sourceforge.observoice.entity.WatchingCourseInfo; |
11 | 11 | import jp.sourceforge.observoice.exception.ObsvException; |
12 | +import jp.sourceforge.observoice.network.RequestConfiguration; | |
12 | 13 | import jp.sourceforge.observoice.network.response.LectureInfoListResponse; |
13 | 14 | import jp.sourceforge.observoice.network.response.ObsvResponseObject; |
14 | 15 | import jp.sourceforge.observoice.network.response.WatchingCourseInfoListResponse; |
@@ -17,6 +18,7 @@ | ||
17 | 18 | import jp.sourceforge.observoice.network.task.GetWatchingCoursesTask; |
18 | 19 | import jp.sourceforge.observoice.network.task.ObsvNetworkListener; |
19 | 20 | import jp.sourceforge.observoice.network.task.ObsvNetworkTask; |
21 | +import jp.sourceforge.observoice.util.Util; | |
20 | 22 | |
21 | 23 | import roboguice.activity.RoboActivity; |
22 | 24 | import roboguice.inject.InjectView; |
@@ -62,22 +64,22 @@ | ||
62 | 64 | private static final int[] CALENDAR_DAY_OF_WEEK = new int[] { 0, java.util.Calendar.MONDAY, |
63 | 65 | java.util.Calendar.TUESDAY, java.util.Calendar.WEDNESDAY, java.util.Calendar.THURSDAY, |
64 | 66 | java.util.Calendar.FRIDAY, java.util.Calendar.SATURDAY, java.util.Calendar.SUNDAY }; |
65 | - | |
67 | + | |
66 | 68 | NextLectureListAdapter listAdapter; |
67 | 69 | private ListView lectureListView; |
68 | 70 | private List<Course> lectures = new ArrayList<Course>(); |
69 | - | |
71 | + | |
70 | 72 | //今日は何曜日? |
71 | 73 | private int today = 0; |
72 | - | |
74 | + | |
75 | + // ネットワークタスク実行用 | |
76 | + private RequestConfiguration mRequestConfiguration; | |
77 | + | |
73 | 78 | @Override |
74 | 79 | public void onCreate(Bundle savedInstanceState) { |
75 | 80 | super.onCreate(savedInstanceState); |
76 | 81 | setContentView(R.layout.start); |
77 | 82 | |
78 | - // final Button runReviewActivityButton = | |
79 | - // (Button)findViewById(R.id.runLectureActivityButton); | |
80 | - | |
81 | 83 | /* 講義検索画面と復習画面への遷移を登録 */ |
82 | 84 | runLectureSearchActivityButton |
83 | 85 | .setOnClickListener(new View.OnClickListener() { |
@@ -111,18 +113,22 @@ | ||
111 | 113 | MyPagerAdapter mPagerAdapter = new MyPagerAdapter(); |
112 | 114 | mViewPager.setAdapter(mPagerAdapter); |
113 | 115 | lectureListView = mPagerAdapter.getNextLectureListView(); |
114 | - | |
116 | + | |
115 | 117 | //検索用データの設定 |
116 | 118 | String freeWord = ""; |
117 | 119 | int periodToSearch = 0; |
118 | 120 | |
119 | 121 | //今日は何曜日? |
120 | - Calendar cal = Calendar.getInstance(); | |
122 | + Calendar cal = Calendar.getInstance(); | |
121 | 123 | today = cal.get(Calendar.DAY_OF_WEEK); |
122 | - | |
123 | - ObsvNetworkTask getLectureInfos = new GetLectureInfoListTask(100, | |
124 | - getDayOfWeek(), periodToSearch, freeWord); | |
125 | 124 | |
125 | + // ネットワークタスク実行用設定をロード | |
126 | + mRequestConfiguration = RequestConfiguration.load( | |
127 | + Util.getObsvSharedPreferences(this)); | |
128 | + | |
129 | + ObsvNetworkTask getLectureInfos = new GetLectureInfoListTask(mRequestConfiguration, | |
130 | + 100, getDayOfWeek(), periodToSearch, freeWord); | |
131 | + | |
126 | 132 | // 自分自身 |
127 | 133 | final StartActivity self = this; |
128 | 134 |
@@ -133,7 +139,7 @@ | ||
133 | 139 | // 一つ目のタイトル(course_idが-1) |
134 | 140 | // TODO courseIDとして―1が有り得るならNextLectureListAdapterと併せて変更の必要 |
135 | 141 | lectures.add(new Course(-1, "現在行われている授業(getLecturesInfo)")); |
136 | - | |
142 | + | |
137 | 143 | LectureInfoListResponse response_ = (LectureInfoListResponse) response; |
138 | 144 | ArrayList<Course> lectureInfoList; |
139 | 145 | lectureInfoList = response_.getLectureInfoList(); |
@@ -140,11 +146,11 @@ | ||
140 | 146 | |
141 | 147 | //該当する授業が無い場合 |
142 | 148 | boolean noLectures = true; |
143 | - | |
149 | + | |
144 | 150 | //取得する授業の最大数 |
145 | 151 | int limit = 5; |
146 | 152 | int i = 0; |
147 | - | |
153 | + | |
148 | 154 | for (Course info : lectureInfoList) { |
149 | 155 | if(i < limit){ |
150 | 156 | lectures.add(info); |
@@ -155,10 +161,10 @@ | ||
155 | 161 | |
156 | 162 | if (noLectures) { |
157 | 163 | lectures.add(new Course(-2, "ただいま授業は行われていません")); |
158 | - } | |
159 | - | |
164 | + } | |
165 | + | |
160 | 166 | listAdapter = new NextLectureListAdapter(self, R.layout.next_lecture_item, lectures); |
161 | - | |
167 | + | |
162 | 168 | lectureListView.setAdapter(listAdapter); |
163 | 169 | lectureListView.setOnItemClickListener(self); |
164 | 170 | } |
@@ -175,9 +181,10 @@ | ||
175 | 181 | }); |
176 | 182 | // 講義情報一覧取得タスク開始 |
177 | 183 | getLectureInfos.execute(); |
178 | - | |
184 | + | |
179 | 185 | // ウォッチ情報一覧取得後のUI更新処理を記述 |
180 | - GetWatchingCoursesTask getWatchingLectures = new GetWatchingCoursesTask(); | |
186 | + GetWatchingCoursesTask getWatchingLectures = | |
187 | + new GetWatchingCoursesTask(mRequestConfiguration); | |
181 | 188 | getWatchingLectures.setListener(new ObsvNetworkListener() { |
182 | 189 | // responseがサーバからのレスポンスを表すオブジェクト |
183 | 190 | public void onSuccess(ObsvResponseObject response) { |
@@ -189,7 +196,7 @@ | ||
189 | 196 | |
190 | 197 | //該当する授業が無い場合 |
191 | 198 | boolean noWatches = true; |
192 | - | |
199 | + | |
193 | 200 | //取得する授業の最大数 |
194 | 201 | int limit = 5; |
195 | 202 | int i = 0; |
@@ -209,13 +216,13 @@ | ||
209 | 216 | } |
210 | 217 | } |
211 | 218 | } |
212 | - | |
219 | + | |
213 | 220 | if (noWatches) { |
214 | 221 | lectures.add(new Course(-2, "この曜日の授業は受けていません")); |
215 | - } | |
216 | - | |
222 | + } | |
223 | + | |
217 | 224 | listAdapter = new NextLectureListAdapter(self, R.layout.next_lecture_item, lectures); |
218 | - | |
225 | + | |
219 | 226 | lectureListView.setAdapter(listAdapter); |
220 | 227 | lectureListView.setOnItemClickListener(self); |
221 | 228 |
@@ -231,12 +238,13 @@ | ||
231 | 238 | .setTitle(e.getClass().getSimpleName()).setMessage(errorMes).show(); |
232 | 239 | } |
233 | 240 | }); |
234 | - | |
241 | + | |
235 | 242 | // ウォッチ情報一覧取得タスク開始 |
236 | 243 | getWatchingLectures.execute(); |
237 | - | |
244 | + | |
238 | 245 | // カレント情報一覧取得後のUI更新処理を記述 |
239 | - GetCurrentLectureInfoListTask getCurrentLectures = new GetCurrentLectureInfoListTask(); | |
246 | + GetCurrentLectureInfoListTask getCurrentLectures = | |
247 | + new GetCurrentLectureInfoListTask(mRequestConfiguration); | |
240 | 248 | // 講義情報一覧取得後のUI更新処理を記述 |
241 | 249 | getCurrentLectures.setListener(new ObsvNetworkListener() { |
242 | 250 | // responseがサーバからのレスポンスを表すオブジェクト |
@@ -244,7 +252,7 @@ | ||
244 | 252 | // 一つ目のタイトル(course_idが-1) |
245 | 253 | // TODO courseIDとして―1が有り得るならNextLectureListAdapterと併せて変更の必要 |
246 | 254 | lectures.add(new Course(-1, "現在行われている授業(CurrentLectures)")); |
247 | - | |
255 | + | |
248 | 256 | LectureInfoListResponse response_ = (LectureInfoListResponse) response; |
249 | 257 | ArrayList<Course> lectureInfoList; |
250 | 258 | lectureInfoList = response_.getLectureInfoList(); |
@@ -251,11 +259,11 @@ | ||
251 | 259 | |
252 | 260 | //該当する授業が無い場合 |
253 | 261 | boolean noLectures = true; |
254 | - | |
262 | + | |
255 | 263 | //取得する授業の最大数 |
256 | 264 | int limit = 5; |
257 | 265 | int i = 0; |
258 | - | |
266 | + | |
259 | 267 | for (Course info : lectureInfoList) { |
260 | 268 | if(i < limit){ |
261 | 269 | lectures.add(info); |
@@ -266,10 +274,10 @@ | ||
266 | 274 | |
267 | 275 | if (noLectures) { |
268 | 276 | lectures.add(new Course(-2, "ただいま授業は行われていません")); |
269 | - } | |
270 | - | |
277 | + } | |
278 | + | |
271 | 279 | listAdapter = new NextLectureListAdapter(self, R.layout.next_lecture_item, lectures); |
272 | - | |
280 | + | |
273 | 281 | lectureListView.setAdapter(listAdapter); |
274 | 282 | lectureListView.setOnItemClickListener(self); |
275 | 283 | } |
@@ -284,11 +292,11 @@ | ||
284 | 292 | .setTitle(e.getClass().getSimpleName()).setMessage(errorMes).show(); |
285 | 293 | } |
286 | 294 | }); |
287 | - | |
295 | + | |
288 | 296 | // 講義情報一覧取得タスク開始 |
289 | 297 | getCurrentLectures.execute(); |
290 | - | |
291 | - | |
298 | + | |
299 | + | |
292 | 300 | } |
293 | 301 | |
294 | 302 | // フリップで切り替え可能なサブビュー用のアダプタ |
@@ -303,7 +311,7 @@ | ||
303 | 311 | mCommentListView = (ListView) inflater.inflate(R.layout.comment_list_fragment, null); |
304 | 312 | mLectureAbstractView = (TextView) inflater.inflate(R.layout.lecture_abstract, null); |
305 | 313 | } |
306 | - | |
314 | + | |
307 | 315 | @Override |
308 | 316 | public Object instantiateItem(ViewGroup container, int position) { |
309 | 317 | int[] pages = { R.layout.next_lecture, |
@@ -312,7 +320,7 @@ | ||
312 | 320 | View view = null; |
313 | 321 | switch (page) { |
314 | 322 | case R.layout.next_lecture: |
315 | - view = mNextLecture; | |
323 | + view = mNextLecture; | |
316 | 324 | break; |
317 | 325 | case R.layout.comment_list_fragment: |
318 | 326 | view = mCommentListView; |
@@ -339,7 +347,7 @@ | ||
339 | 347 | public boolean isViewFromObject(View view, Object object) { |
340 | 348 | return view.equals(object); |
341 | 349 | } |
342 | - | |
350 | + | |
343 | 351 | public ListView getNextLectureListView() { |
344 | 352 | return mNextLecture; |
345 | 353 | } |
@@ -370,7 +378,7 @@ | ||
370 | 378 | @Override |
371 | 379 | public void onClick(View arg0) { |
372 | 380 | // TODO Auto-generated method stub |
373 | - | |
381 | + | |
374 | 382 | } |
375 | 383 | |
376 | 384 | @Override |
@@ -7,10 +7,12 @@ | ||
7 | 7 | |
8 | 8 | import jp.sourceforge.observoice.entity.WatchingCourseInfo; |
9 | 9 | import jp.sourceforge.observoice.exception.ObsvException; |
10 | +import jp.sourceforge.observoice.network.RequestConfiguration; | |
10 | 11 | import jp.sourceforge.observoice.network.response.ObsvResponseObject; |
11 | 12 | import jp.sourceforge.observoice.network.response.WatchingCourseInfoListResponse; |
12 | 13 | import jp.sourceforge.observoice.network.task.GetWatchingCoursesTask; |
13 | 14 | import jp.sourceforge.observoice.network.task.ObsvNetworkListener; |
15 | +import jp.sourceforge.observoice.util.Util; | |
14 | 16 | import roboguice.activity.RoboActivity; |
15 | 17 | import roboguice.inject.InjectView; |
16 | 18 | import android.content.Intent; |
@@ -23,7 +25,7 @@ | ||
23 | 25 | |
24 | 26 | /** |
25 | 27 | * 復習講義選択画面 |
26 | - * | |
28 | + * | |
27 | 29 | * @author uchan |
28 | 30 | * @author torikawa |
29 | 31 | */ |
@@ -34,16 +36,20 @@ | ||
34 | 36 | private ListView searched_lectures; |
35 | 37 | private ArrayList<WatchingCourseInfo> infoList; |
36 | 38 | |
39 | + private RequestConfiguration mRequestConfiguration; | |
40 | + | |
37 | 41 | @Override |
38 | 42 | protected void onCreate(Bundle savedInstanceState) { |
39 | 43 | super.onCreate(savedInstanceState); |
40 | 44 | this.setContentView(R.layout.review_lecture_search); |
41 | 45 | |
46 | + mRequestConfiguration = RequestConfiguration.load(Util.getObsvSharedPreferences(this)); | |
47 | + | |
42 | 48 | getWatchingLectures(); |
43 | 49 | } |
44 | 50 | |
45 | 51 | private void getWatchingLectures() { |
46 | - GetWatchingCoursesTask task = new GetWatchingCoursesTask(); | |
52 | + GetWatchingCoursesTask task = new GetWatchingCoursesTask(mRequestConfiguration); | |
47 | 53 | task.setListener(this); |
48 | 54 | task.execute(); |
49 | 55 | } |
@@ -8,6 +8,7 @@ | ||
8 | 8 | |
9 | 9 | import jp.sourceforge.observoice.entity.Comment; |
10 | 10 | import jp.sourceforge.observoice.exception.ObsvException; |
11 | +import jp.sourceforge.observoice.network.RequestConfiguration; | |
11 | 12 | import jp.sourceforge.observoice.network.response.CommentListResponse; |
12 | 13 | import jp.sourceforge.observoice.network.response.ObsvResponseObject; |
13 | 14 | import jp.sourceforge.observoice.network.task.GetCommentListTask; |
@@ -30,17 +31,19 @@ | ||
30 | 31 | |
31 | 32 | private int courceId; |
32 | 33 | private final Handler mHandler; // UIスレッドで実行する機能のためのハンドラ |
34 | + private final RequestConfiguration mRequestConfiguration; | |
33 | 35 | private Timer mTimer = null; |
34 | 36 | private List<OnReceivedListener> mListeners; |
35 | 37 | |
36 | - public CommentListIntervalGetter(int courceId, Handler handler) { | |
38 | + public CommentListIntervalGetter(int courceId, Handler handler, RequestConfiguration requestConfiguration) { | |
37 | 39 | this.courceId = courceId; |
38 | 40 | mListeners = Collections.synchronizedList(new ArrayList<OnReceivedListener>()); |
39 | 41 | mHandler = handler; |
42 | + mRequestConfiguration = requestConfiguration; | |
40 | 43 | } |
41 | 44 | |
42 | 45 | private GetCommentListTask createTask() { |
43 | - GetCommentListTask mTask = new GetCommentListTask(courceId, 100, null, null); | |
46 | + GetCommentListTask mTask = new GetCommentListTask(mRequestConfiguration, courceId, 100, null, null); | |
44 | 47 | // コメントリストがサーバーから到達したときのリスナを作成し登録 |
45 | 48 | mTask.setListener(new ObsvNetworkListener() { |
46 | 49 | @Override |
@@ -7,10 +7,12 @@ | ||
7 | 7 | import jp.sourceforge.observoice.entity.Comment; |
8 | 8 | import jp.sourceforge.observoice.entity.Course; |
9 | 9 | import jp.sourceforge.observoice.exception.ObsvException; |
10 | +import jp.sourceforge.observoice.network.RequestConfiguration; | |
10 | 11 | import jp.sourceforge.observoice.network.response.ObsvResponseObject; |
11 | 12 | import jp.sourceforge.observoice.network.task.ObsvNetworkListener; |
12 | 13 | import jp.sourceforge.observoice.network.task.PostCommentTask; |
13 | 14 | import jp.sourceforge.observoice.network.task.WatchLectureTask; |
15 | +import jp.sourceforge.observoice.util.Util; | |
14 | 16 | import jp.sourceforge.observoice.util.WidgetUtil; |
15 | 17 | import roboguice.activity.RoboFragmentActivity; |
16 | 18 | import roboguice.inject.InjectExtra; |
@@ -34,7 +36,7 @@ | ||
34 | 36 | |
35 | 37 | /** |
36 | 38 | * 講義中に理解度フィードバックやそれらのデータ閲覧を行うアクティビティ |
37 | - * | |
39 | + * | |
38 | 40 | * @author meganetan |
39 | 41 | * @author uchan_nos |
40 | 42 | * @author torikawa |
@@ -62,12 +64,15 @@ | ||
62 | 64 | // サーバーから一定間隔で取得する機能を提供するクラス |
63 | 65 | private CommentListIntervalGetter commentListIntervalGetter; |
64 | 66 | |
67 | + private RequestConfiguration mRequestConfiguration; | |
68 | + | |
65 | 69 | @Override |
66 | 70 | protected void onCreate(Bundle savedInstanceState) { |
67 | 71 | super.onCreate(savedInstanceState); |
68 | 72 | setContentView(R.layout.lecture); |
69 | 73 | |
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); | |
71 | 76 | |
72 | 77 | // コメント入力フィールドのキー入力設定 |
73 | 78 | commentField.setOnKeyListener(this); |
@@ -98,7 +103,7 @@ | ||
98 | 103 | |
99 | 104 | /** |
100 | 105 | * コメント投稿ボタンのクリック可能属性を設定するメソッド |
101 | - * | |
106 | + * | |
102 | 107 | * @param b |
103 | 108 | */ |
104 | 109 | private void setButtonsClickable(boolean b) { |
@@ -143,7 +148,7 @@ | ||
143 | 148 | |
144 | 149 | /** |
145 | 150 | * コメント投稿ボタンのリスナ |
146 | - * | |
151 | + * | |
147 | 152 | * @author rtakizawa |
148 | 153 | */ |
149 | 154 | private class PostCommentButtonListener implements View.OnClickListener { |
@@ -162,7 +167,7 @@ | ||
162 | 167 | setButtonsClickable(false); |
163 | 168 | |
164 | 169 | String comment = commentField.getText().toString(); |
165 | - PostCommentTask task = new PostCommentTask(lecture.getCourceId(), "hoge", type, | |
170 | + PostCommentTask task = new PostCommentTask(mRequestConfiguration, lecture.getCourceId(), "hoge", type, | |
166 | 171 | comment); |
167 | 172 | task.setListener(new PostCommentListener()); |
168 | 173 | task.execute(); |
@@ -171,7 +176,7 @@ | ||
171 | 176 | |
172 | 177 | /** |
173 | 178 | * コメント投稿タスクのリスナー |
174 | - * | |
179 | + * | |
175 | 180 | * @author rtakizawa |
176 | 181 | */ |
177 | 182 | private class PostCommentListener implements ObsvNetworkListener { |
@@ -219,7 +224,7 @@ | ||
219 | 224 | switch (item.getItemId()) { |
220 | 225 | case R.id.watchLecture: |
221 | 226 | // 講義を選択したことをサーバーに通知する |
222 | - new WatchLectureTask(lecture.getCourceId()).execute(); | |
227 | + new WatchLectureTask(mRequestConfiguration, lecture.getCourceId()).execute(); | |
223 | 228 | default: |
224 | 229 | return super.onOptionsItemSelected(item); |
225 | 230 | } |
@@ -1,6 +1,8 @@ | ||
1 | 1 | package jp.sourceforge.observoice; |
2 | 2 | |
3 | +import jp.sourceforge.observoice.network.RequestConfiguration; | |
3 | 4 | import jp.sourceforge.observoice.util.ObsvSetting; |
5 | +import jp.sourceforge.observoice.util.Util; | |
4 | 6 | import roboguice.activity.RoboActivity; |
5 | 7 | import roboguice.inject.InjectResource; |
6 | 8 | import roboguice.inject.InjectView; |
@@ -24,16 +26,18 @@ | ||
24 | 26 | @InjectView(R.id.apiKey) |
25 | 27 | TextView text; |
26 | 28 | |
27 | - @InjectResource(R.string.observoice_uri) | |
28 | - private String mObservoiceUri; | |
29 | 29 | @InjectResource(R.string.login_path) |
30 | 30 | private String mLoginPath; |
31 | 31 | |
32 | + private RequestConfiguration mRequestConfiguration; | |
33 | + | |
32 | 34 | @Override |
33 | 35 | protected void onCreate(Bundle savedInstanceState) { |
34 | 36 | super.onCreate(savedInstanceState); |
35 | 37 | setContentView(R.layout.login); |
36 | 38 | |
39 | + mRequestConfiguration = RequestConfiguration.load(Util.getObsvSharedPreferences(this)); | |
40 | + | |
37 | 41 | initWebView(); |
38 | 42 | } |
39 | 43 |
@@ -58,7 +62,7 @@ | ||
58 | 62 | } |
59 | 63 | |
60 | 64 | private String getLoginUri() { |
61 | - return mObservoiceUri + mLoginPath; | |
65 | + return "http://" + mRequestConfiguration.getHost().toString() + mLoginPath; | |
62 | 66 | } |
63 | 67 | |
64 | 68 | private AlertDialog createRetryDialog(int messageId) { |
@@ -1,20 +1,14 @@ | ||
1 | 1 | package jp.sourceforge.observoice.util; |
2 | 2 | |
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; | |
11 | 3 | import android.content.Context; |
12 | 4 | 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; | |
14 | 8 | |
15 | 9 | /** |
16 | 10 | * observoiceの設定API用のsingletonクラス instance生成前にsetContextを少なくとも1回呼び出す必要がある |
17 | - * | |
11 | + * | |
18 | 12 | * @author rtakizawa |
19 | 13 | */ |
20 | 14 | public final class ObsvSetting extends ContextWrapper { |
@@ -43,11 +37,9 @@ | ||
43 | 37 | ObsvSetting.context = context; |
44 | 38 | } |
45 | 39 | |
46 | - private String filename = "settings.json"; | |
47 | - private JSONObject json; | |
40 | + private SharedPreferences pref; | |
48 | 41 | |
49 | 42 | private String apiKey; |
50 | - private String hostName; | |
51 | 43 | |
52 | 44 | /** |
53 | 45 | * インスタンス変数の値を設定ファイルロード前の初期状態にセット |
@@ -54,7 +46,6 @@ | ||
54 | 46 | */ |
55 | 47 | private void initFields() { |
56 | 48 | apiKey = null; |
57 | - hostName = "localhost:8080"; | |
58 | 49 | } |
59 | 50 | |
60 | 51 | /** |
@@ -61,28 +52,9 @@ | ||
61 | 52 | * 設定ファイルからデータをロード |
62 | 53 | */ |
63 | 54 | 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(); | |
86 | 58 | } |
87 | 59 | |
88 | 60 | /** |
@@ -89,50 +61,34 @@ | ||
89 | 61 | * 更新された設定をファイルに保存 |
90 | 62 | */ |
91 | 63 | 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(); | |
104 | 66 | } |
105 | 67 | |
106 | 68 | /** |
107 | - * 設定ファイルから得たJSONObjectでオブジェクトのインスタンス変数を更新 | |
108 | - * | |
109 | - * @throws JSONException | |
69 | + * 設定ファイルでオブジェクトのインスタンス変数を更新 | |
110 | 70 | */ |
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); | |
117 | 73 | } |
118 | 74 | |
119 | 75 | /** |
120 | - * インスタンス変数からJSONObjectを更新 | |
121 | - * | |
122 | - * @throws JSONException | |
76 | + * インスタンス変数から設定ファイルを更新 | |
123 | 77 | */ |
124 | - private void updateJsonFromFields() throws JSONException { | |
125 | - JSONObject json = new JSONObject(); | |
78 | + private void updatePrefFromFields() { | |
79 | + Editor editor = pref.edit(); | |
126 | 80 | |
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); | |
129 | 83 | |
130 | - this.json = json; | |
84 | + editor.commit(); | |
85 | + | |
86 | + Log.d("obsv", "written API_KEY: " + pref.getString("API_KEY", "default")); | |
131 | 87 | } |
132 | 88 | |
133 | 89 | /** |
134 | 90 | * API Keyを返す 設定ファイルがない場合はnull |
135 | - * | |
91 | + * | |
136 | 92 | * @return API Key or null |
137 | 93 | */ |
138 | 94 | public String loadApiKey() { |
@@ -141,7 +97,7 @@ | ||
141 | 97 | |
142 | 98 | /** |
143 | 99 | * 引数のAPI Keyを設定ファイルに保存する |
144 | - * | |
100 | + * | |
145 | 101 | * @param apiKey |
146 | 102 | */ |
147 | 103 | public void saveApiKey(String apiKey) { |
@@ -156,14 +112,4 @@ | ||
156 | 112 | this.apiKey = null; |
157 | 113 | save(); |
158 | 114 | } |
159 | - | |
160 | - /** | |
161 | - * observoiceが使用するサーバのホスト名を返す | |
162 | - * | |
163 | - * @return | |
164 | - */ | |
165 | - public String loadHostName() { | |
166 | - return hostName; | |
167 | - } | |
168 | - | |
169 | 115 | } |
@@ -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 | +} |
@@ -1,6 +1,8 @@ | ||
1 | 1 | <?xml version="1.0" encoding="utf-8"?> |
2 | 2 | <resources> |
3 | 3 | |
4 | + <string name="shared_preferences_filename">obsv</string> | |
5 | + | |
4 | 6 | <string name="hello">Hello World, ObservoiceActivity!</string> |
5 | 7 | <string name="app_name">observoice</string> |
6 | 8 | <string name="text">test</string> |
@@ -18,7 +20,6 @@ | ||
18 | 20 | <string name="LectureSearch_start_label">GO</string> |
19 | 21 | <string name="retry">リトライ</string> |
20 | 22 | <string name="exit">終了</string> |
21 | - <string name="observoice_uri">http://localhost:8080</string> | |
22 | 23 | <string name="login_path">/web/login</string> |
23 | 24 | <string name="login_connect_failed">サーバに接続できませんでした</string> |
24 | 25 | <string name="login_host_lookup_failed">ホスト名を解決できませんでした</string> |