// 初始化@界面 private void initAtView(LayoutInflater inflater, List<View> listViews) { View at_view = inflater.inflate(R.layout.msg_at, null); listViews.add(at_view); lv_msg_at = (PullToRefreshListView) at_view.findViewById(R.id.lv_msg_at); // 下拉刷新 lv_msg_at.setOnRefreshListener( new OnRefreshListener() { @Override public void onRefresh() { at_current_state = AT_MORE_NEW; newAtTask(at_current_state, at_max_id, true); } }); lv_msg_at.setOnLoadOldListener( new onLoadOldListener() { @Override public void onLoadOld() { at_current_state = AT_MORE_OLD; newAtTask(at_current_state, at_max_id, true); } }); pb_at = (ProgressBar) at_view.findViewById(R.id.pb_at); View popup_window_at = LayoutInflater.from(this).inflate(R.layout.popup_window_at, null); popupWindow_at = createPopupWindow(popup_window_at, 230, LayoutParams.WRAP_CONTENT); final LinearLayout ll_msg_at_wb_comment = (LinearLayout) at_view.findViewById(R.id.ll_msg_at_wb_comment); ll_msg_at_wb_comment.setOnClickListener( new OnClickListener() { @Override public void onClick(View v) { popupWindow_at.showAsDropDown(ll_msg_at_wb_comment, 10, -5); } }); btn_at_wb_all = (Button) popup_window_at.findViewById(R.id.btn_at_wb_all); btn_at_wb_friends = (Button) popup_window_at.findViewById(R.id.btn_at_wb_friends); btn_at_wb_original = (Button) popup_window_at.findViewById(R.id.btn_at_wb_original); btn_at_comment_all = (Button) popup_window_at.findViewById(R.id.btn_at_comment_all); btn_at_comment_friends = (Button) popup_window_at.findViewById(R.id.btn_at_comment_friends); btn_at_wb_all.setOnClickListener(this); btn_at_wb_friends.setOnClickListener(this); btn_at_wb_original.setOnClickListener(this); btn_at_comment_all.setOnClickListener(this); btn_at_comment_friends.setOnClickListener(this); }
// 初始化Comment界面 private void initCommentView(LayoutInflater inflater, List<View> listViews) { // Comment View View comment_view = inflater.inflate(R.layout.msg_comment, null); listViews.add(comment_view); lv_msg_comment = (PullToRefreshListView) comment_view.findViewById(R.id.lv_msg_comment); lv_msg_comment.setOnRefreshListener( new OnRefreshListener() { @Override public void onRefresh() {} }); lv_msg_comment.setOnLoadOldListener( new onLoadOldListener() { @Override public void onLoadOld() {} }); pb_comment = (ProgressBar) comment_view.findViewById(R.id.pb_comment); // PopupWindow View View popup_window_comment = LayoutInflater.from(this).inflate(R.layout.popup_window_comment, null); popupWindow_comment = createPopupWindow(popup_window_comment, 230, LayoutParams.WRAP_CONTENT); final LinearLayout ll_msg_comment_to_by = (LinearLayout) comment_view.findViewById(R.id.ll_msg_comment_to_by); ll_msg_comment_to_by.setOnClickListener( new OnClickListener() { @Override public void onClick(View v) { popupWindow_comment.showAsDropDown(ll_msg_comment_to_by, 10, -5); } }); btn_comment_to_me_all = (Button) popup_window_comment.findViewById(R.id.btn_comment_to_me_all); btn_comment_to_me_friends = (Button) popup_window_comment.findViewById(R.id.btn_comment_to_me_friends); btn_comment_by_me_all = (Button) popup_window_comment.findViewById(R.id.btn_comment_by_me_all); btn_comment_to_me_all.setOnClickListener(this); btn_comment_to_me_friends.setOnClickListener(this); btn_comment_by_me_all.setOnClickListener(this); }
// 点击事件监听器 @Override public void onClick(View v) { Task task = null; HashMap<String, Object> taskParams = new HashMap<String, Object>(); popupWindow_at.dismiss(); popupWindow_comment.dismiss(); switch (v.getId()) { case R.id.btn_at_wb_all: task = new Task(Task.WEIBO_MSG_AT_WB, taskParams); pb_at.setVisibility(View.VISIBLE); break; case R.id.btn_at_wb_friends: lv_msg_at.refreshDrawableState(); taskParams.put("filter_by_author", 1); task = new Task(Task.WEIBO_MSG_AT_WB, taskParams); pb_at.setVisibility(View.VISIBLE); break; case R.id.btn_at_wb_original: taskParams.put("filter_by_type", 1); task = new Task(Task.WEIBO_MSG_AT_WB, taskParams); pb_at.setVisibility(View.VISIBLE); break; case R.id.btn_at_comment_all: task = new Task(Task.WEIBO_MSG_AT_COMMENT, taskParams); pb_at.setVisibility(View.VISIBLE); break; case R.id.btn_at_comment_friends: taskParams.put("filter_by_author", 1); task = new Task(Task.WEIBO_MSG_AT_COMMENT, taskParams); pb_at.setVisibility(View.VISIBLE); break; case R.id.btn_comment_to_me_all: task = new Task(Task.WEIBO_MSG_COMMENT_TO_ME, taskParams); pb_comment.setVisibility(View.VISIBLE); break; case R.id.btn_comment_to_me_friends: taskParams.put("filter_by_author", 1); task = new Task(Task.WEIBO_MSG_COMMENT_TO_ME, taskParams); pb_comment.setVisibility(View.VISIBLE); break; case R.id.btn_comment_by_me_all: task = new Task(Task.WEIBO_MSG_COMMENT_BY_ME, taskParams); pb_comment.setVisibility(View.VISIBLE); break; } MainService.addTask(task); MainService.addActivity(this); }
/** * 在ViewPage中的View移动时,加载数据; * * @param index */ private void loadData(int index) { switch (index) { case AT: break; case COMMENT: if (lv_msg_comment.getCount() == 0) { Task task = new Task(Task.WEIBO_MSG_COMMENT_TO_ME, null); MainService.addTask(task); MainService.addActivity(this); } break; case MESSAGE: break; case NOTIFICATION: break; } }
// 回调刷新 @Override public void refresh(Object... params) { int msg_witch = (Integer) params[1]; switch (msg_witch) { case AT: MsgAtAdapter aTAdapter = null; MsgCommentAdapter commentAdapter = null; if (params[2].equals("status")) { List<Status> statuses = (List<Status>) params[0]; aTAdapter = new MsgAtAdapter(statuses, this); if (statuses.size() != 0) { at_max_id = Long.parseLong(statuses.get(statuses.size() - 1).getMid()) - 1; switch (at_current_state) { case AT_INITIATE: lv_msg_at.setAdapter(aTAdapter); break; case AT_MORE_NEW: lv_msg_at.setAdapter(aTAdapter); lv_msg_at.onRefreshComplete(); break; case AT_MORE_OLD: aTAdapter.refresh(statuses); if (aTAdapter.getCount() >= 20) { lv_msg_at.setSelection(aTAdapter.getCount() - 20); } else { lv_msg_at.setSelection(aTAdapter.getCount() - 1); } lv_msg_at.resetFooter(); break; } } else { aTAdapter.notifyDataSetChanged(); Toast.makeText(this, "暂无数据", Toast.LENGTH_SHORT).show(); lv_msg_at.resetFooter(); } } else if (params[2].equals("comment")) { List<Comment> comments = (List<Comment>) params[0]; commentAdapter = new MsgCommentAdapter(comments, this); lv_msg_at.setAdapter(commentAdapter); if (comments.size() != 0) { lv_msg_at.setSelection(1); } else { commentAdapter.notifyDataSetChanged(); Toast.makeText(this, "暂无数据", Toast.LENGTH_SHORT).show(); } } pb_at.setVisibility(View.GONE); break; case COMMENT: @SuppressWarnings("unchecked") List<Comment> comments = (List<Comment>) params[0]; MsgCommentAdapter commentAdapter1 = new MsgCommentAdapter(comments, this); lv_msg_comment.setAdapter(commentAdapter1); if (comments.size() != 0) { lv_msg_comment.setSelection(1); } else { commentAdapter1.notifyDataSetChanged(); Toast.makeText(this, "暂无数据", Toast.LENGTH_SHORT).show(); } pb_comment.setVisibility(View.GONE); break; case MESSAGE: break; case NOTIFICATION: break; } }