Пример #1
0
  // 初始化视图控件
  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);
          }
        });
  }
Пример #2
0
  // 初始化动态列表控件
  private void initLvActive() {
    lvActive_footer = getLayoutInflater().inflate(R.layout.listview_footer, null);
    lvActive_foot_more = (TextView) lvActive_footer.findViewById(R.id.listview_foot_more);
    lvActive_foot_progress =
        (ProgressBar) lvActive_footer.findViewById(R.id.listview_foot_progress);

    lvActiveAdapter =
        new ListViewActiveAdapter(this, lvActiveData, R.layout.active_listitem, false);
    mLvActive = (PullToRefreshListView) findViewById(R.id.user_center_activelist);

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

            ImageView img = (ImageView) view.findViewById(R.id.active_listitem_userface);
            Active active = (Active) img.getTag();
            // 跳转
            UIHelper.showActiveRedirect(view.getContext(), active);
          }
        });
    mLvActive.setOnScrollListener(
        new AbsListView.OnScrollListener() {
          public void onScrollStateChanged(AbsListView view, int scrollState) {
            mLvActive.onScrollStateChanged(view, scrollState);

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

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

            if (scrollEnd && curLvActiveDataState == UIHelper.LISTVIEW_DATA_MORE) {
              mLvActive.setTag(UIHelper.LISTVIEW_DATA_LOADING);
              lvActive_foot_more.setText(R.string.load_ing);
              lvActive_foot_progress.setVisibility(View.VISIBLE);
              // 当前页数
              int pageIndex = lvActiveSumData / _pageSize;
              loadLvActiveData(mActiveHandler, pageIndex, UIHelper.LISTVIEW_ACTION_SCROLL);
            }
          }

          public void onScroll(
              AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
            mLvActive.onScroll(view, firstVisibleItem, visibleItemCount, totalItemCount);
          }
        });
    mLvActive.setOnRefreshListener(
        new PullToRefreshListView.OnRefreshListener() {
          public void onRefresh() {
            loadLvActiveData(mActiveHandler, 0, UIHelper.LISTVIEW_ACTION_REFRESH);
          }
        });
  }
Пример #3
0
  // 初始化博客列表控件
  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);
          }
        });
  }
Пример #4
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);
          }
        });
  }