• R/O
  • SSH
  • HTTPS

observoice: Commit


Commit MetaInfo

Revision284 (tree)
Zeit2012-10-27 16:40:52
Autoruchan_nos

Log Message

講義画面、復習画面における理解度グラフの見た目を改善

Ändern Zusammenfassung

Diff

--- branches/29115-reviewgraph/observoice/src/jp/sourceforge/observoice/adapter/ReviewLecturePagerAdapter.java (revision 283)
+++ branches/29115-reviewgraph/observoice/src/jp/sourceforge/observoice/adapter/ReviewLecturePagerAdapter.java (revision 284)
@@ -1,13 +1,10 @@
11 package jp.sourceforge.observoice.adapter;
22
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;
118
129 /**
1310 * 復習ページのスワイプ部分のアダプタ
@@ -14,51 +11,35 @@
1411 *
1512 * @author rtakizawa
1613 */
17-public class ReviewLecturePagerAdapter extends PagerAdapter {
14+public class ReviewLecturePagerAdapter extends FragmentStatePagerAdapter {
1815
19- private ListView mReviewCommentListView;
20- private ImageView mGraphView; //dummy
16+ private Fragment[] fragments = new Fragment[2];
2117
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);
2720 }
2821
2922 @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;
4235 }
4336
4437 @Override
4538 public int getCount() {
46- return pages.length;
39+ return 2;
4740 }
4841
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];
5244 }
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-
6445 }
--- branches/29115-reviewgraph/observoice/src/jp/sourceforge/observoice/ReviewLectureActivity.java (revision 283)
+++ branches/29115-reviewgraph/observoice/src/jp/sourceforge/observoice/ReviewLectureActivity.java (revision 284)
@@ -4,16 +4,16 @@
44 import java.text.SimpleDateFormat;
55 import java.util.ArrayList;
66 import java.util.Calendar;
7-import java.util.Date;
87 import java.util.HashMap;
98 import java.util.List;
109 import java.util.Map;
1110
12-import jp.sourceforge.observoice.adapter.CommentListAdapter;
1311 import jp.sourceforge.observoice.adapter.ReviewLecturePagerAdapter;
1412 import jp.sourceforge.observoice.entity.Comment;
1513 import jp.sourceforge.observoice.entity.WatchingCourseInfo;
1614 import jp.sourceforge.observoice.exception.ObsvException;
15+import jp.sourceforge.observoice.fragment.CommentListFragment;
16+import jp.sourceforge.observoice.fragment.UnderstandabilityChartFragment;
1717 import jp.sourceforge.observoice.network.RequestConfiguration;
1818 import jp.sourceforge.observoice.network.response.CommentListResponse;
1919 import jp.sourceforge.observoice.network.response.ObsvResponseObject;
@@ -20,21 +20,20 @@
2020 import jp.sourceforge.observoice.network.task.GetCommentListTask;
2121 import jp.sourceforge.observoice.network.task.ObsvNetworkListener;
2222 import jp.sourceforge.observoice.util.Util;
23-import roboguice.activity.RoboActivity;
23+import roboguice.activity.RoboFragmentActivity;
2424 import roboguice.inject.InjectExtra;
2525 import roboguice.inject.InjectView;
2626 import android.app.AlertDialog;
2727 import android.app.DatePickerDialog;
2828 import android.app.DatePickerDialog.OnDateSetListener;
29-import android.content.Context;
3029 import android.os.Bundle;
30+import android.support.v4.app.Fragment;
3131 import android.support.v4.view.ViewPager;
32-import android.view.LayoutInflater;
32+import android.util.Log;
3333 import android.view.View;
3434 import android.view.View.OnClickListener;
3535 import android.widget.Button;
3636 import android.widget.DatePicker;
37-import android.widget.ListView;
3837
3938 /**
4039 * 復習画面
@@ -42,7 +41,7 @@
4241 * @author torikawa
4342 * @author rtakizawa
4443 */
45-public class ReviewLectureActivity extends RoboActivity
44+public class ReviewLectureActivity extends RoboFragmentActivity
4645 implements OnClickListener {
4746
4847 /**
@@ -74,8 +73,6 @@
7473
7574 private int mCourceId;
7675
77- private Context mContext;
78-
7976 private SelectedDate mSelectedDateBegin, mSelectedDateEnd;
8077
8178 /**
@@ -99,13 +96,14 @@
9996
10097 mRequestConfiguration = RequestConfiguration.load(Util.getObsvSharedPreferences(this));
10198
102- mContext = this;
103-
10499 mCourceId = mReviewLecture.getCourse().getCourceId();
105100 mCommentMap = new HashMap<String, List<Comment>>();
106101
102+ /*
107103 mPagerAdapter = new ReviewLecturePagerAdapter(
108104 (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE));
105+ */
106+ mPagerAdapter = new ReviewLecturePagerAdapter(getSupportFragmentManager());
109107 mViewPager.setAdapter(mPagerAdapter);
110108
111109 Calendar today = Calendar.getInstance();
@@ -131,9 +129,6 @@
131129 List<Comment> responseComments = ((CommentListResponse) response).getCommentList();
132130 mapComments(responseComments);
133131
134- //mDaySelector.setAdapter(createCommentDatesAdapter());
135- //mDaySelector.setOnItemSelectedListener(new DaySelectorListener(mContext));
136-
137132 mDayBeginButton.setOnClickListener(ReviewLectureActivity.this);
138133 mDayEndButton.setOnClickListener(ReviewLectureActivity.this);
139134
@@ -171,14 +166,9 @@
171166 }
172167
173168 /**
174-<<<<<<< .working
175169 * Calendarから日付の文字列表現を得る
176170 *
177171 * @param cal
178-=======
179- * コメントリストから日付のリストをもつアダプターを作成する
180- *
181->>>>>>> .merge-right.r281
182172 * @return
183173 */
184174 private String getDateString(Calendar cal) {
@@ -233,7 +223,10 @@
233223 * @return 変換された日付を表す文字列
234224 */
235225 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());
237230 }
238231
239232 /**
@@ -243,11 +236,16 @@
243236 List<Comment> comments = new ArrayList<Comment>();
244237
245238 // 日付を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);
248243 Calendar dateEnd = Calendar.getInstance();
249244 dateEnd.set(mSelectedDateEnd.year, mSelectedDateEnd.month, mSelectedDateEnd.dayOfMonth);
245+ setToBeginningOfTheDay(dateEnd);
246+ dateEnd.add(Calendar.DAY_OF_MONTH, 1);
250247
248+ Calendar date = (Calendar) dateBegin.clone();
251249 // dateが表す日付にコメントがあれば、それをcommentsに追加する
252250 for (; date.compareTo(dateEnd) <= 0; date.add(Calendar.DAY_OF_MONTH, 1)) {
253251 List<Comment> commentsOfDay = mCommentMap.get(mFormat.format(date.getTime()));
@@ -256,9 +254,34 @@
256254 }
257255 }
258256
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+ }
263275 }
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+ }
264287 }
--- branches/29115-reviewgraph/observoice/src/jp/sourceforge/observoice/LectureActivity.java (revision 283)
+++ branches/29115-reviewgraph/observoice/src/jp/sourceforge/observoice/LectureActivity.java (revision 284)
@@ -1,5 +1,6 @@
11 package jp.sourceforge.observoice;
22
3+import java.text.SimpleDateFormat;
34 import java.util.List;
45
56 import jp.sourceforge.observoice.fragment.CommentListFragment;
@@ -126,7 +127,9 @@
126127 Fragment f = null;
127128 switch (position) {
128129 case 0:
129- f = new UnderstandabilityChartFragment();
130+ UnderstandabilityChartFragment ucf = new UnderstandabilityChartFragment();
131+ ucf.setDateFormat(new SimpleDateFormat("ss"));
132+ f = ucf;
130133 break;
131134 case 1:
132135 f = new CommentListFragment();
--- branches/29115-reviewgraph/observoice/src/jp/sourceforge/observoice/fragment/UnderstandabilityChartFragment.java (revision 283)
+++ branches/29115-reviewgraph/observoice/src/jp/sourceforge/observoice/fragment/UnderstandabilityChartFragment.java (revision 284)
@@ -47,6 +47,11 @@
4747 private XYMultipleSeriesRenderer mChartRenderer = null;
4848 private LinearLayout mLayout = null;
4949
50+ private long mDateDivision = 1 * 1000; // データの区切り時間
51+ private int mNumDivision = 10; // グラフに表示するデータ数
52+
53+ private DateFormat mDateFormat = DateFormat.getTimeInstance(DateFormat.MEDIUM);
54+
5055 @Override
5156 public void onCreate(Bundle savedInstanceState) {
5257 Log.d("chart", "UCF.onCreate");
@@ -90,6 +95,7 @@
9095 renderer.setChartTitleTextSize(20);
9196 renderer.setLabelsTextSize(15);
9297 renderer.setLegendTextSize(15);
98+ renderer.setPanEnabled(false, false);
9399 for (int i = 0; i < colors.length; i++) {
94100 SimpleSeriesRenderer r = new SimpleSeriesRenderer();
95101 r.setColor(colors[i]);
@@ -129,10 +135,7 @@
129135 public void update(List<Comment> comments, long currentTime) {
130136 Log.d("chart", "UCF.update");
131137
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; // グラフに表示したいデータの開始時刻
136139
137140 for (Comment c : comments) {
138141 mChartManager.addReaction(new Reaction(
@@ -143,13 +146,13 @@
143146
144147 // 指定した時刻範囲のデータからチャートデータを生成
145148 XYMultipleSeriesDataset dataset =
146- mChartManager.buildDataset(dateBegin, dateDivision, numDivision, true);
149+ mChartManager.buildDataset(dateBegin, mDateDivision, mNumDivision, true);
147150
148151 // X軸のラベルを設定
149152 mChartRenderer.clearXTextLabels();
150- for (int i = 0; i < numDivision; ++i) {
153+ for (int i = 0; i < mNumDivision; ++i) {
151154 mChartRenderer.addXTextLabel(i + 1,
152- dateFormat.format(new Date(dateBegin + dateDivision * i)));
155+ mDateFormat.format(new Date(dateBegin + mDateDivision * i)));
153156 }
154157
155158 // Y軸の表示範囲を設定
@@ -163,4 +166,22 @@
163166 // 再描画を指示
164167 mLayout.invalidate();
165168 }
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+ }
166187 }
Show on old repository browser