講義画面、復習画面における理解度グラフの見た目を改善
@@ -1,13 +1,10 @@ | ||
1 | 1 | package jp.sourceforge.observoice.adapter; |
2 | 2 | |
3 | -import jp.sourceforge.observoice.R; | |
4 | -import android.support.v4.view.PagerAdapter; | |
5 | -import android.support.v4.view.ViewPager; | |
6 | -import android.view.LayoutInflater; | |
7 | -import android.view.View; | |
8 | -import android.view.ViewGroup; | |
9 | -import android.widget.ImageView; | |
10 | -import android.widget.ListView; | |
3 | +import jp.sourceforge.observoice.fragment.CommentListFragment; | |
4 | +import jp.sourceforge.observoice.fragment.UnderstandabilityChartFragment; | |
5 | +import android.support.v4.app.Fragment; | |
6 | +import android.support.v4.app.FragmentManager; | |
7 | +import android.support.v4.app.FragmentStatePagerAdapter; | |
11 | 8 | |
12 | 9 | /** |
13 | 10 | * 復習ページのスワイプ部分のアダプタ |
@@ -14,51 +11,35 @@ | ||
14 | 11 | * |
15 | 12 | * @author rtakizawa |
16 | 13 | */ |
17 | -public class ReviewLecturePagerAdapter extends PagerAdapter { | |
14 | +public class ReviewLecturePagerAdapter extends FragmentStatePagerAdapter { | |
18 | 15 | |
19 | - private ListView mReviewCommentListView; | |
20 | - private ImageView mGraphView; //dummy | |
16 | + private Fragment[] fragments = new Fragment[2]; | |
21 | 17 | |
22 | - private int[] pages = { R.layout.comment_list_fragment, R.layout.graph_fragment }; | |
23 | - | |
24 | - public ReviewLecturePagerAdapter(LayoutInflater inflater) { | |
25 | - mReviewCommentListView = (ListView) inflater.inflate(R.layout.comment_list_fragment, null); | |
26 | - mGraphView = (ImageView) inflater.inflate(R.layout.graph_fragment, null); | |
18 | + public ReviewLecturePagerAdapter(FragmentManager fm) { | |
19 | + super(fm); | |
27 | 20 | } |
28 | 21 | |
29 | 22 | @Override |
30 | - public Object instantiateItem(ViewGroup container, int position) { | |
31 | - View view = null; | |
32 | - switch (pages[position]) { | |
33 | - case R.layout.comment_list_fragment: | |
34 | - view = mReviewCommentListView; | |
35 | - break; | |
36 | - case R.layout.graph_fragment: | |
37 | - view = mGraphView; | |
38 | - break; | |
39 | - } | |
40 | - container.addView(view); | |
41 | - return view; | |
23 | + public Fragment getItem(int position) { | |
24 | + Fragment f = null; | |
25 | + switch (position) { | |
26 | + case 0: | |
27 | + f = new CommentListFragment(); | |
28 | + break; | |
29 | + case 1: | |
30 | + f = new UnderstandabilityChartFragment(); | |
31 | + break; | |
32 | + } | |
33 | + fragments[position] = f; | |
34 | + return f; | |
42 | 35 | } |
43 | 36 | |
44 | 37 | @Override |
45 | 38 | public int getCount() { |
46 | - return pages.length; | |
39 | + return 2; | |
47 | 40 | } |
48 | 41 | |
49 | - @Override | |
50 | - public void destroyItem(ViewGroup container, int position, Object object) { | |
51 | - ((ViewPager) container).removeView((View) object); | |
42 | + public Fragment getCachedItem(int position) { | |
43 | + return fragments[position]; | |
52 | 44 | } |
53 | - | |
54 | - @Override | |
55 | - public boolean isViewFromObject(View view, Object object) { | |
56 | - // TODO Auto-generated method stub | |
57 | - return view.equals(object); | |
58 | - } | |
59 | - | |
60 | - public ListView getCommentListView() { | |
61 | - return mReviewCommentListView; | |
62 | - } | |
63 | - | |
64 | 45 | } |
@@ -4,16 +4,16 @@ | ||
4 | 4 | import java.text.SimpleDateFormat; |
5 | 5 | import java.util.ArrayList; |
6 | 6 | import java.util.Calendar; |
7 | -import java.util.Date; | |
8 | 7 | import java.util.HashMap; |
9 | 8 | import java.util.List; |
10 | 9 | import java.util.Map; |
11 | 10 | |
12 | -import jp.sourceforge.observoice.adapter.CommentListAdapter; | |
13 | 11 | import jp.sourceforge.observoice.adapter.ReviewLecturePagerAdapter; |
14 | 12 | import jp.sourceforge.observoice.entity.Comment; |
15 | 13 | import jp.sourceforge.observoice.entity.WatchingCourseInfo; |
16 | 14 | import jp.sourceforge.observoice.exception.ObsvException; |
15 | +import jp.sourceforge.observoice.fragment.CommentListFragment; | |
16 | +import jp.sourceforge.observoice.fragment.UnderstandabilityChartFragment; | |
17 | 17 | import jp.sourceforge.observoice.network.RequestConfiguration; |
18 | 18 | import jp.sourceforge.observoice.network.response.CommentListResponse; |
19 | 19 | import jp.sourceforge.observoice.network.response.ObsvResponseObject; |
@@ -20,21 +20,20 @@ | ||
20 | 20 | import jp.sourceforge.observoice.network.task.GetCommentListTask; |
21 | 21 | import jp.sourceforge.observoice.network.task.ObsvNetworkListener; |
22 | 22 | import jp.sourceforge.observoice.util.Util; |
23 | -import roboguice.activity.RoboActivity; | |
23 | +import roboguice.activity.RoboFragmentActivity; | |
24 | 24 | import roboguice.inject.InjectExtra; |
25 | 25 | import roboguice.inject.InjectView; |
26 | 26 | import android.app.AlertDialog; |
27 | 27 | import android.app.DatePickerDialog; |
28 | 28 | import android.app.DatePickerDialog.OnDateSetListener; |
29 | -import android.content.Context; | |
30 | 29 | import android.os.Bundle; |
30 | +import android.support.v4.app.Fragment; | |
31 | 31 | import android.support.v4.view.ViewPager; |
32 | -import android.view.LayoutInflater; | |
32 | +import android.util.Log; | |
33 | 33 | import android.view.View; |
34 | 34 | import android.view.View.OnClickListener; |
35 | 35 | import android.widget.Button; |
36 | 36 | import android.widget.DatePicker; |
37 | -import android.widget.ListView; | |
38 | 37 | |
39 | 38 | /** |
40 | 39 | * 復習画面 |
@@ -42,7 +41,7 @@ | ||
42 | 41 | * @author torikawa |
43 | 42 | * @author rtakizawa |
44 | 43 | */ |
45 | -public class ReviewLectureActivity extends RoboActivity | |
44 | +public class ReviewLectureActivity extends RoboFragmentActivity | |
46 | 45 | implements OnClickListener { |
47 | 46 | |
48 | 47 | /** |
@@ -74,8 +73,6 @@ | ||
74 | 73 | |
75 | 74 | private int mCourceId; |
76 | 75 | |
77 | - private Context mContext; | |
78 | - | |
79 | 76 | private SelectedDate mSelectedDateBegin, mSelectedDateEnd; |
80 | 77 | |
81 | 78 | /** |
@@ -99,13 +96,14 @@ | ||
99 | 96 | |
100 | 97 | mRequestConfiguration = RequestConfiguration.load(Util.getObsvSharedPreferences(this)); |
101 | 98 | |
102 | - mContext = this; | |
103 | - | |
104 | 99 | mCourceId = mReviewLecture.getCourse().getCourceId(); |
105 | 100 | mCommentMap = new HashMap<String, List<Comment>>(); |
106 | 101 | |
102 | + /* | |
107 | 103 | mPagerAdapter = new ReviewLecturePagerAdapter( |
108 | 104 | (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE)); |
105 | + */ | |
106 | + mPagerAdapter = new ReviewLecturePagerAdapter(getSupportFragmentManager()); | |
109 | 107 | mViewPager.setAdapter(mPagerAdapter); |
110 | 108 | |
111 | 109 | Calendar today = Calendar.getInstance(); |
@@ -131,9 +129,6 @@ | ||
131 | 129 | List<Comment> responseComments = ((CommentListResponse) response).getCommentList(); |
132 | 130 | mapComments(responseComments); |
133 | 131 | |
134 | - //mDaySelector.setAdapter(createCommentDatesAdapter()); | |
135 | - //mDaySelector.setOnItemSelectedListener(new DaySelectorListener(mContext)); | |
136 | - | |
137 | 132 | mDayBeginButton.setOnClickListener(ReviewLectureActivity.this); |
138 | 133 | mDayEndButton.setOnClickListener(ReviewLectureActivity.this); |
139 | 134 |
@@ -171,14 +166,9 @@ | ||
171 | 166 | } |
172 | 167 | |
173 | 168 | /** |
174 | -<<<<<<< .working | |
175 | 169 | * Calendarから日付の文字列表現を得る |
176 | 170 | * |
177 | 171 | * @param cal |
178 | -======= | |
179 | - * コメントリストから日付のリストをもつアダプターを作成する | |
180 | - * | |
181 | ->>>>>>> .merge-right.r281 | |
182 | 172 | * @return |
183 | 173 | */ |
184 | 174 | private String getDateString(Calendar cal) { |
@@ -233,7 +223,10 @@ | ||
233 | 223 | * @return 変換された日付を表す文字列 |
234 | 224 | */ |
235 | 225 | private static String toStringWithFormat(DateFormat f, SelectedDate d) { |
236 | - return f.format(new Date(d.year, d.month, d.dayOfMonth)); | |
226 | + //return f.format(new Date(d.year - 1900, d.month, d.dayOfMonth)); | |
227 | + Calendar c = Calendar.getInstance(); | |
228 | + c.set(d.year, d.month, d.dayOfMonth); | |
229 | + return f.format(c.getTime()); | |
237 | 230 | } |
238 | 231 | |
239 | 232 | /** |
@@ -243,11 +236,16 @@ | ||
243 | 236 | List<Comment> comments = new ArrayList<Comment>(); |
244 | 237 | |
245 | 238 | // 日付をbeginからendまで走査する |
246 | - Calendar date = Calendar.getInstance(); | |
247 | - date.set(mSelectedDateBegin.year, mSelectedDateBegin.month, mSelectedDateBegin.dayOfMonth); | |
239 | + // 開始日と終了日を完全に含めたいので、終了日を+1日する | |
240 | + Calendar dateBegin = Calendar.getInstance(); | |
241 | + dateBegin.set(mSelectedDateBegin.year, mSelectedDateBegin.month, mSelectedDateBegin.dayOfMonth); | |
242 | + setToBeginningOfTheDay(dateBegin); | |
248 | 243 | Calendar dateEnd = Calendar.getInstance(); |
249 | 244 | dateEnd.set(mSelectedDateEnd.year, mSelectedDateEnd.month, mSelectedDateEnd.dayOfMonth); |
245 | + setToBeginningOfTheDay(dateEnd); | |
246 | + dateEnd.add(Calendar.DAY_OF_MONTH, 1); | |
250 | 247 | |
248 | + Calendar date = (Calendar) dateBegin.clone(); | |
251 | 249 | // dateが表す日付にコメントがあれば、それをcommentsに追加する |
252 | 250 | for (; date.compareTo(dateEnd) <= 0; date.add(Calendar.DAY_OF_MONTH, 1)) { |
253 | 251 | List<Comment> commentsOfDay = mCommentMap.get(mFormat.format(date.getTime())); |
@@ -256,9 +254,34 @@ | ||
256 | 254 | } |
257 | 255 | } |
258 | 256 | |
259 | - // commentsを表示 | |
260 | - ListView v = mPagerAdapter.getCommentListView(); | |
261 | - CommentListAdapter adapter = new CommentListAdapter(mContext, comments); | |
262 | - v.setAdapter(adapter); | |
257 | + for (int i = 0; i < mPagerAdapter.getCount(); ++i) { | |
258 | + Fragment f = mPagerAdapter.getCachedItem(i); | |
259 | + if (f != null) { | |
260 | + if (f instanceof UnderstandabilityChartFragment) { | |
261 | + UnderstandabilityChartFragment ucf = (UnderstandabilityChartFragment) f; | |
262 | + | |
263 | + long beginToEnd = dateEnd.getTimeInMillis() - dateBegin.getTimeInMillis(); | |
264 | + ucf.setDivision((beginToEnd + 9) / 10, 10); | |
265 | + ucf.setDateFormat(new SimpleDateFormat("MM-dd")); | |
266 | + | |
267 | + Log.d("obsv", "setDivision: " + beginToEnd + "msec"); | |
268 | + | |
269 | + ucf.update(comments, dateEnd.getTimeInMillis()); | |
270 | + } else if (f instanceof CommentListFragment) { | |
271 | + ((CommentListFragment) f).update(comments); | |
272 | + } | |
273 | + } | |
274 | + } | |
263 | 275 | } |
276 | + | |
277 | + /** | |
278 | + * カレンダーを0時ちょうどに修正する | |
279 | + * @param c | |
280 | + */ | |
281 | + private void setToBeginningOfTheDay(Calendar c) { | |
282 | + c.set(Calendar.HOUR_OF_DAY, 0); | |
283 | + c.set(Calendar.MINUTE, 0); | |
284 | + c.set(Calendar.SECOND, 0); | |
285 | + c.set(Calendar.MILLISECOND, 0); | |
286 | + } | |
264 | 287 | } |
@@ -1,5 +1,6 @@ | ||
1 | 1 | package jp.sourceforge.observoice; |
2 | 2 | |
3 | +import java.text.SimpleDateFormat; | |
3 | 4 | import java.util.List; |
4 | 5 | |
5 | 6 | import jp.sourceforge.observoice.fragment.CommentListFragment; |
@@ -126,7 +127,9 @@ | ||
126 | 127 | Fragment f = null; |
127 | 128 | switch (position) { |
128 | 129 | case 0: |
129 | - f = new UnderstandabilityChartFragment(); | |
130 | + UnderstandabilityChartFragment ucf = new UnderstandabilityChartFragment(); | |
131 | + ucf.setDateFormat(new SimpleDateFormat("ss")); | |
132 | + f = ucf; | |
130 | 133 | break; |
131 | 134 | case 1: |
132 | 135 | f = new CommentListFragment(); |
@@ -47,6 +47,11 @@ | ||
47 | 47 | private XYMultipleSeriesRenderer mChartRenderer = null; |
48 | 48 | private LinearLayout mLayout = null; |
49 | 49 | |
50 | + private long mDateDivision = 1 * 1000; // データの区切り時間 | |
51 | + private int mNumDivision = 10; // グラフに表示するデータ数 | |
52 | + | |
53 | + private DateFormat mDateFormat = DateFormat.getTimeInstance(DateFormat.MEDIUM); | |
54 | + | |
50 | 55 | @Override |
51 | 56 | public void onCreate(Bundle savedInstanceState) { |
52 | 57 | Log.d("chart", "UCF.onCreate"); |
@@ -90,6 +95,7 @@ | ||
90 | 95 | renderer.setChartTitleTextSize(20); |
91 | 96 | renderer.setLabelsTextSize(15); |
92 | 97 | renderer.setLegendTextSize(15); |
98 | + renderer.setPanEnabled(false, false); | |
93 | 99 | for (int i = 0; i < colors.length; i++) { |
94 | 100 | SimpleSeriesRenderer r = new SimpleSeriesRenderer(); |
95 | 101 | r.setColor(colors[i]); |
@@ -129,10 +135,7 @@ | ||
129 | 135 | public void update(List<Comment> comments, long currentTime) { |
130 | 136 | Log.d("chart", "UCF.update"); |
131 | 137 | |
132 | - final DateFormat dateFormat = DateFormat.getTimeInstance(DateFormat.MEDIUM); | |
133 | - final long dateBegin = currentTime - 10 * 1000; // グラフに表示したいデータの開始時刻 | |
134 | - final long dateDivision = 1000; // グラフに表示したいデータの間隔 | |
135 | - final int numDivision = 10; // グラフに表示するデータの数 | |
138 | + final long dateBegin = currentTime - mDateDivision * mNumDivision; // グラフに表示したいデータの開始時刻 | |
136 | 139 | |
137 | 140 | for (Comment c : comments) { |
138 | 141 | mChartManager.addReaction(new Reaction( |
@@ -143,13 +146,13 @@ | ||
143 | 146 | |
144 | 147 | // 指定した時刻範囲のデータからチャートデータを生成 |
145 | 148 | XYMultipleSeriesDataset dataset = |
146 | - mChartManager.buildDataset(dateBegin, dateDivision, numDivision, true); | |
149 | + mChartManager.buildDataset(dateBegin, mDateDivision, mNumDivision, true); | |
147 | 150 | |
148 | 151 | // X軸のラベルを設定 |
149 | 152 | mChartRenderer.clearXTextLabels(); |
150 | - for (int i = 0; i < numDivision; ++i) { | |
153 | + for (int i = 0; i < mNumDivision; ++i) { | |
151 | 154 | mChartRenderer.addXTextLabel(i + 1, |
152 | - dateFormat.format(new Date(dateBegin + dateDivision * i))); | |
155 | + mDateFormat.format(new Date(dateBegin + mDateDivision * i))); | |
153 | 156 | } |
154 | 157 | |
155 | 158 | // Y軸の表示範囲を設定 |
@@ -163,4 +166,22 @@ | ||
163 | 166 | // 再描画を指示 |
164 | 167 | mLayout.invalidate(); |
165 | 168 | } |
169 | + | |
170 | + /** | |
171 | + * データの分割方法を設定する | |
172 | + * @param dateDivision データ1つの時間間隔 | |
173 | + * @param numDivision データの分割個数 | |
174 | + */ | |
175 | + public void setDivision(long dateDivision, int numDivision) { | |
176 | + this.mDateDivision = dateDivision; | |
177 | + this.mNumDivision = numDivision; | |
178 | + } | |
179 | + | |
180 | + /** | |
181 | + * X軸のラベル描画に用いる時刻フォーマットをセットする | |
182 | + * @param dateFormat | |
183 | + */ | |
184 | + public void setDateFormat(DateFormat dateFormat) { | |
185 | + this.mDateFormat = dateFormat; | |
186 | + } | |
166 | 187 | } |