// 初始化视图控件 private void initView() { _hisuid = getIntent().getIntExtra("his_id", 0); _hisname = getIntent().getStringExtra("his_name"); _username = getIntent().getStringExtra("his_name"); _uid = ((AppContext) getApplication()).getLoginUid(); mBack = (ImageView) findViewById(R.id.user_center_back); mRefresh = (ImageView) findViewById(R.id.user_center_refresh); mHeadTitle = (TextView) findViewById(R.id.user_center_head_title); mProgressbar = (ProgressBar) findViewById(R.id.user_center_head_progress); mRelation = (RadioButton) findViewById(R.id.user_center_footbar_relation); mMessage = (RadioButton) findViewById(R.id.user_center_footbar_message); mAtme = (RadioButton) findViewById(R.id.user_center_footbar_atme); mTabActive = (Button) findViewById(R.id.user_center_btn_active); mTabBlog = (Button) findViewById(R.id.user_center_btn_blog); mUserinfoDialog = new UserInfoDialog(UserCenter.this); mUserface = (ImageView) mUserinfoDialog.findViewById(R.id.user_center_userface); mUsername = (TextView) mUserinfoDialog.findViewById(R.id.user_center_username); mFrom = (TextView) mUserinfoDialog.findViewById(R.id.user_center_from); mGender = (TextView) mUserinfoDialog.findViewById(R.id.user_center_gender); mJointime = (TextView) mUserinfoDialog.findViewById(R.id.user_center_jointime); mDevplatform = (TextView) mUserinfoDialog.findViewById(R.id.user_center_devplatform); mExpertise = (TextView) mUserinfoDialog.findViewById(R.id.user_center_expertise); mLatestonline = (TextView) mUserinfoDialog.findViewById(R.id.user_center_latestonline); mHeadTitle.setText(_username + " ▼"); // 设置第一选中项 mTabActive.setEnabled(false); mTabActive.setOnClickListener(tabBtnClick(mTabActive)); mTabBlog.setOnClickListener(tabBtnClick(mTabBlog)); mBack.setOnClickListener(UIHelper.finish(this)); mRefresh.setOnClickListener(refreshClickListener); mHeadTitle.setOnClickListener(headTitleClickListener); mMessage.setOnClickListener(messageClickListener); mAtme.setOnClickListener(atmeClickListener); mUserinfoDialog.setOnCancelListener(dialogCancelListener); this.initLvActive(); this.initLvBlog(); }
// 初始化视图控件 private void initView() { mBack = (ImageView) findViewById(R.id.friend_head_back); mBack.setOnClickListener(UIHelper.finish(this)); mProgressbar = (ProgressBar) findViewById(R.id.friend_head_progress); friend_type_fans = (Button) findViewById(R.id.friend_type_fans); friend_type_follower = (Button) findViewById(R.id.friend_type_follower); friend_type_fans.setOnClickListener( this.friendBtnClick(friend_type_fans, FriendList.TYPE_FANS)); friend_type_follower.setOnClickListener( this.friendBtnClick(friend_type_follower, FriendList.TYPE_FOLLOWER)); // 设置当前分类 curLvCatalog = getIntent().getIntExtra("friend_type", FriendList.TYPE_FOLLOWER); if (curLvCatalog == FriendList.TYPE_FANS) { friend_type_fans.setEnabled(false); } else { friend_type_follower.setEnabled(false); } // 设置粉丝与关注的数量 int followers = getIntent().getIntExtra("friend_followers", 0); int fans = getIntent().getIntExtra("friend_fans", 0); friend_type_follower.setText(getString(R.string.user_friend_follower, followers)); friend_type_fans.setText(getString(R.string.user_friend_fans, fans)); lvFriend_footer = getLayoutInflater().inflate(R.layout.listview_footer, null); lvFriend_foot_more = (TextView) lvFriend_footer.findViewById(R.id.listview_foot_more); lvFriend_foot_progress = (ProgressBar) lvFriend_footer.findViewById(R.id.listview_foot_progress); lvFriendAdapter = new ListViewFriendAdapter(this, lvFriendData, R.layout.friend_listitem); mlvFriend = (PullToRefreshListView) findViewById(R.id.friend_listview); mlvFriend.addFooterView(lvFriend_footer); // 添加底部视图 必须在setAdapter前 mlvFriend.setAdapter(lvFriendAdapter); mlvFriend.setOnItemClickListener( new AdapterView.OnItemClickListener() { public void onItemClick(AdapterView<?> parent, View view, int position, long id) { // 点击头部、底部栏无效 if (position == 0 || view == lvFriend_footer) return; TextView name = (TextView) view.findViewById(R.id.friend_listitem_name); Friend friend = (Friend) name.getTag(); if (friend == null) return; // 跳转 UIHelper.showUserCenter(view.getContext(), friend.getUserid(), friend.getName()); } }); mlvFriend.setOnScrollListener( new AbsListView.OnScrollListener() { public void onScrollStateChanged(AbsListView view, int scrollState) { mlvFriend.onScrollStateChanged(view, scrollState); // 数据为空--不用继续下面代码了 if (lvFriendData.size() == 0) return; // 判断是否滚动到底部 boolean scrollEnd = false; try { if (view.getPositionForView(lvFriend_footer) == view.getLastVisiblePosition()) scrollEnd = true; } catch (Exception e) { scrollEnd = false; } if (scrollEnd && curLvDataState == UIHelper.LISTVIEW_DATA_MORE) { lvFriend_foot_more.setText(R.string.load_ing); lvFriend_foot_progress.setVisibility(View.VISIBLE); // 当前pageIndex int pageIndex = lvSumData / 20; loadLvFriendData( curLvCatalog, pageIndex, mFriendHandler, UIHelper.LISTVIEW_ACTION_SCROLL); } } public void onScroll( AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) { mlvFriend.onScroll(view, firstVisibleItem, visibleItemCount, totalItemCount); } }); mlvFriend.setOnRefreshListener( new PullToRefreshListView.OnRefreshListener() { public void onRefresh() { loadLvFriendData(curLvCatalog, 0, mFriendHandler, UIHelper.LISTVIEW_ACTION_REFRESH); } }); }
// 初始化视图控件 private void initView() { curId = getIntent().getIntExtra("tweet_id", 0); curCatalog = CommentList.CATALOG_TWEET; if (curId > 0) tempCommentKey = AppConfig.TEMP_COMMENT + "_" + curCatalog + "_" + curId; mBack = (ImageView) findViewById(R.id.tweet_detail_back); mRefresh = (ImageView) findViewById(R.id.tweet_detail_refresh); mLinearlayout = (LinearLayout) findViewById(R.id.tweet_detail_linearlayout); mProgressbar = (ProgressBar) findViewById(R.id.tweet_detail_head_progress); mBack.setOnClickListener(UIHelper.finish(this)); mRefresh.setOnClickListener(refreshClickListener); imm = (InputMethodManager) getSystemService(INPUT_METHOD_SERVICE); mFootViewSwitcher = (ViewSwitcher) findViewById(R.id.tweet_detail_foot_viewswitcher); mFootPubcomment = (Button) findViewById(R.id.tweet_detail_foot_pubcomment); mFootPubcomment.setOnClickListener(commentpubClickListener); mFootEditebox = (ImageView) findViewById(R.id.tweet_detail_footbar_editebox); mFootEditebox.setOnClickListener( new View.OnClickListener() { public void onClick(View v) { mFootViewSwitcher.showNext(); mFootEditer.setVisibility(View.VISIBLE); mFootEditer.requestFocus(); mFootEditer.requestFocusFromTouch(); } }); mFootEditer = (EditText) findViewById(R.id.tweet_detail_foot_editer); mFootEditer.setOnFocusChangeListener( new View.OnFocusChangeListener() { public void onFocusChange(View v, boolean hasFocus) { if (hasFocus) { imm.showSoftInput(v, 0); } else { imm.hideSoftInputFromWindow(v.getWindowToken(), 0); } } }); mFootEditer.setOnKeyListener( new View.OnKeyListener() { public boolean onKey(View v, int keyCode, KeyEvent event) { if (keyCode == KeyEvent.KEYCODE_BACK) { if (mFootViewSwitcher.getDisplayedChild() == 1) { mFootViewSwitcher.setDisplayedChild(0); mFootEditer.clearFocus(); mFootEditer.setVisibility(View.GONE); } return true; } return false; } }); // 编辑器添加文本监听 mFootEditer.addTextChangedListener(UIHelper.getTextWatcher(this, tempCommentKey)); // 显示临时编辑内容 UIHelper.showTempEditContent(this, mFootEditer, tempCommentKey); lvHeader = View.inflate(this, R.layout.tweet_detail_content, null); userface = (ImageView) lvHeader.findViewById(R.id.tweet_listitem_userface); username = (TextView) lvHeader.findViewById(R.id.tweet_listitem_username); date = (TextView) lvHeader.findViewById(R.id.tweet_listitem_date); commentCount = (TextView) lvHeader.findViewById(R.id.tweet_listitem_commentCount); image = (ImageView) lvHeader.findViewById(R.id.tweet_listitem_image); content = (WebView) lvHeader.findViewById(R.id.tweet_listitem_content); content.getSettings().setJavaScriptEnabled(false); content.getSettings().setSupportZoom(true); content.getSettings().setBuiltInZoomControls(true); content.getSettings().setDefaultFontSize(12); lvComment_footer = getLayoutInflater().inflate(R.layout.listview_footer, null); lvComment_foot_more = (TextView) lvComment_footer.findViewById(R.id.listview_foot_more); lvComment_foot_progress = (ProgressBar) lvComment_footer.findViewById(R.id.listview_foot_progress); lvCommentAdapter = new ListViewCommentAdapter(this, lvCommentData, R.layout.comment_listitem); mLvComment = (PullToRefreshListView) findViewById(R.id.tweet_detail_commentlist); mLvComment.addHeaderView(lvHeader); // 把动弹详情放进listview头部 mLvComment.addFooterView(lvComment_footer); // 添加底部视图 必须在setAdapter前 mLvComment.setAdapter(lvCommentAdapter); mLvComment.setOnItemClickListener( new AdapterView.OnItemClickListener() { public void onItemClick(AdapterView<?> parent, View view, int position, long id) { // 点击头部、底部栏无效 if (position == 0 || view == lvComment_footer || position == 1 || view == lvHeader) return; Comment com = null; // 判断是否是TextView if (view instanceof TextView) { com = (Comment) view.getTag(); } else { ImageView img = (ImageView) view.findViewById(R.id.comment_listitem_userface); com = (Comment) img.getTag(); } if (com == null) return; // 跳转--回复评论界面 UIHelper.showCommentReply( TweetDetail.this, curId, curCatalog, com.getId(), com.getAuthorId(), com.getAuthor(), com.getContent()); } }); mLvComment.setOnScrollListener( new AbsListView.OnScrollListener() { public void onScrollStateChanged(AbsListView view, int scrollState) { mLvComment.onScrollStateChanged(view, scrollState); // 数据为空--不用继续下面代码了 if (lvCommentData.size() == 0) return; // 判断是否滚动到底部 boolean scrollEnd = false; try { if (view.getPositionForView(lvComment_footer) == view.getLastVisiblePosition()) scrollEnd = true; } catch (Exception e) { scrollEnd = false; } if (scrollEnd && curLvDataState == UIHelper.LISTVIEW_DATA_MORE) { lvComment_foot_more.setText(R.string.load_ing); lvComment_foot_progress.setVisibility(View.VISIBLE); // 当前pageIndex int pageIndex = lvSumData / 20; loadLvCommentData( curId, curCatalog, pageIndex, mCommentHandler, UIHelper.LISTVIEW_ACTION_SCROLL); } } public void onScroll( AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) { mLvComment.onScroll(view, firstVisibleItem, visibleItemCount, totalItemCount); } }); mLvComment.setOnItemLongClickListener( new AdapterView.OnItemLongClickListener() { public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) { // 点击头部、底部栏无效 if (position == 0 || view == lvComment_footer || position == 1 || view == lvHeader) return false; Comment _com = null; // 判断是否是TextView if (view instanceof TextView) { _com = (Comment) view.getTag(); } else { ImageView img = (ImageView) view.findViewById(R.id.comment_listitem_userface); _com = (Comment) img.getTag(); } if (_com == null) return false; final Comment com = _com; final AppContext ac = (AppContext) getApplication(); // 操作--回复 & 删除 int uid = ac.getLoginUid(); // 判断该评论是否是当前登录用户发表的:true--有删除操作 false--没有删除操作 if (uid == com.getAuthorId()) { final Handler handler = new Handler() { public void handleMessage(Message msg) { if (msg.what == 1) { Result res = (Result) msg.obj; if (res.OK()) { lvSumData--; lvCommentData.remove(com); lvCommentAdapter.notifyDataSetChanged(); } UIHelper.ToastMessage(TweetDetail.this, res.getErrorMessage()); } else { ((AppException) msg.obj).makeToast(TweetDetail.this); } } }; final Thread thread = new Thread() { public void run() { Message msg = new Message(); try { Result res = ac.delComment(curId, curCatalog, com.getId(), com.getAuthorId()); msg.what = 1; msg.obj = res; } catch (AppException e) { e.printStackTrace(); msg.what = -1; msg.obj = e; } handler.sendMessage(msg); } }; UIHelper.showCommentOptionDialog(TweetDetail.this, curId, curCatalog, com, thread); } else { UIHelper.showCommentOptionDialog(TweetDetail.this, curId, curCatalog, com, null); } return true; } }); mLvComment.setOnRefreshListener( new PullToRefreshListView.OnRefreshListener() { public void onRefresh() { loadLvCommentData( curId, curCatalog, 0, mCommentHandler, UIHelper.LISTVIEW_ACTION_REFRESH); } }); }