// 初始化博客列表控件
  private void initLvBlog() {
    lvBlog_footer = getLayoutInflater().inflate(R.layout.listview_footer, null);
    lvBlog_foot_more = (TextView) lvBlog_footer.findViewById(R.id.listview_foot_more);
    lvBlog_foot_progress = (ProgressBar) lvBlog_footer.findViewById(R.id.listview_foot_progress);

    lvBlogAdapter =
        new ListViewBlogAdapter(this, BlogList.CATALOG_USER, lvBlogData, R.layout.blog_listitem);
    mLvBlog = (PullToRefreshListView) findViewById(R.id.user_center_bloglist);

    mLvBlog.addFooterView(lvBlog_footer); // 添加底部视图  必须在setAdapter前
    mLvBlog.setAdapter(lvBlogAdapter);
    mLvBlog.setOnItemClickListener(
        new AdapterView.OnItemClickListener() {
          public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            // 点击头部、底部栏无效
            if (position == 0 || view == lvBlog_footer) return;

            TextView txt = (TextView) view.findViewById(R.id.blog_listitem_title);
            Blog blog = (Blog) txt.getTag();
            // 跳转
            UIHelper.showUrlRedirect(view.getContext(), blog.getUrl());
          }
        });
    mLvBlog.setOnScrollListener(
        new AbsListView.OnScrollListener() {
          public void onScrollStateChanged(AbsListView view, int scrollState) {
            mLvBlog.onScrollStateChanged(view, scrollState);

            // 数据为空--不用继续下面代码了
            if (lvBlogData.size() == 0) return;

            // 判断是否滚动到底部
            boolean scrollEnd = false;
            try {
              if (view.getPositionForView(lvBlog_footer) == view.getLastVisiblePosition())
                scrollEnd = true;
            } catch (Exception e) {
              scrollEnd = false;
            }

            if (scrollEnd && curLvBlogDataState == UIHelper.LISTVIEW_DATA_MORE) {
              mLvBlog.setTag(UIHelper.LISTVIEW_DATA_LOADING);
              lvBlog_foot_more.setText(R.string.load_ing);
              lvBlog_foot_progress.setVisibility(View.VISIBLE);
              // 当前页数
              int pageIndex = lvBlogSumData / _pageSize;
              loadLvBlogData(mBlogHandler, pageIndex, UIHelper.LISTVIEW_ACTION_SCROLL);
            }
          }

          public void onScroll(
              AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
            mLvBlog.onScroll(view, firstVisibleItem, visibleItemCount, totalItemCount);
          }
        });
    mLvBlog.setOnItemLongClickListener(
        new AdapterView.OnItemLongClickListener() {
          public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) {
            // 点击头部、底部栏无效
            if (position == 0 || view == lvBlog_footer) return false;

            Blog _blog = null;
            // 判断是否是TextView
            if (view instanceof TextView) {
              _blog = (Blog) view.getTag();
            } else {
              TextView txt = (TextView) view.findViewById(R.id.blog_listitem_title);
              _blog = (Blog) txt.getTag();
            }
            if (_blog == null) return false;

            final Blog blog = _blog;

            final AppContext ac = (AppContext) getApplication();
            // 操作--删除
            final int uid = ac.getLoginUid();
            // 判断该博客是否是当前登录用户发表的
            if (uid == blog.getAuthorId()) {
              final Handler handler =
                  new Handler() {
                    public void handleMessage(Message msg) {
                      if (msg.what == 1) {
                        Result res = (Result) msg.obj;
                        if (res.OK()) {
                          lvBlogData.remove(blog);
                          lvBlogAdapter.notifyDataSetChanged();
                        }
                        UIHelper.ToastMessage(UserCenter.this, res.getErrorMessage());
                      } else {
                        ((AppException) msg.obj).makeToast(UserCenter.this);
                      }
                    }
                  };
              final Thread thread =
                  new Thread() {
                    public void run() {
                      Message msg = new Message();
                      try {
                        Result res = ac.delBlog(uid, blog.getAuthorId(), blog.getId());
                        msg.what = 1;
                        msg.obj = res;
                      } catch (AppException e) {
                        e.printStackTrace();
                        msg.what = -1;
                        msg.obj = e;
                      }
                      handler.sendMessage(msg);
                    }
                  };
              UIHelper.showBlogOptionDialog(UserCenter.this, thread);
            } else {
              UIHelper.showBlogOptionDialog(UserCenter.this, null);
            }
            return true;
          }
        });
    mLvBlog.setOnRefreshListener(
        new PullToRefreshListView.OnRefreshListener() {
          public void onRefresh() {
            loadLvBlogData(mBlogHandler, 0, UIHelper.LISTVIEW_ACTION_REFRESH);
          }
        });
  }
示例#2
0
  // 初始化视图控件
  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);
          }
        });
  }