@Override
  protected void onCreate(Bundle bundle) {
    super.onCreate(bundle);

    setContentView(R.layout.umeng_comm_post_feed_layout);
    setFragmentContainerId(ResFinder.getId("umeng_comm_select_layout"));
    initViews();
    initLocationLayout();
    initPresenter();
    Bundle extraBundle = getIntent().getExtras();
    if (extraBundle == null) {
      return;
    }
    isRepost = extraBundle.getBoolean(Constants.POST_FAILED, false);
    // 设置是否是重新发送
    mPostPresenter.setRepost(isRepost);
    // 从话题详情页面进入到发送新鲜事页面
    Topic mTopic = extraBundle.getParcelable(Constants.TAG_TOPIC);
    if (mTopic != null) {
      mSelecteTopics.add(mTopic);
      if (CommConfig.getConfig().isDisplayTopicOnPostFeedPage()) { // 检查是否在编辑框添加此话题
        mEditText.insertTopics(mSelecteTopics);
      }
      startFadeOutAnimForTopicTipView();
    }
  }
 @Override
 protected void onSaveInstanceState(Bundle outState) {
   super.onSaveInstanceState(outState);
   String content = mEditText.getText().toString();
   if (!TextUtils.isEmpty(content)) {
     outState.putString(EDIT_CONTENT_KEY, content);
   }
 }
 private boolean isCharsOverflow(String extraText) {
   int extraTextLen = 0;
   if (!TextUtils.isEmpty(extraText)) {
     extraTextLen = extraText.length();
   }
   int len = mEditText.getText().length();
   return len + extraTextLen >= CommConfig.getConfig().mFeedLen;
 }
 @Override
 protected void onRestoreInstanceState(Bundle savedInstanceState) {
   super.onRestoreInstanceState(savedInstanceState);
   String content = savedInstanceState.getString(EDIT_CONTENT_KEY);
   if (!TextUtils.isEmpty(content)) {
     mEditText.setText(content);
   }
 }
 /**
  * 移除字符</br>
  *
  * @param c
  */
 private void removeChar(char c) {
   Editable editable = mEditText.getText();
   if (editable.length() <= 0) {
     return;
   }
   if (editable.charAt(editable.length() - 1) == c) {
     editable.delete(editable.length() - 1, editable.length());
   }
 }
 /** 清除状态</br> */
 @Override
 public void clearState() {
   mEditText.setText("");
   mEditText.mAtMap.clear();
   mEditText.mTopicMap.clear();
   mImageSelectedAdapter.getDataSource().clear();
   mTopicButton.setChecked(false);
   // mPhotoButton.setChecked(false);
 }
  /** 初始化EditView并设置回调</br> */
  private void initEditView() {

    mEditText = (FeedEditText) findViewById(ResFinder.getId("umeng_comm_post_msg_edittext"));
    mEditText.setFocusableInTouchMode(true);
    mEditText.requestFocus();
    mEditText.setMinimumHeight(DeviceUtils.dp2px(this, 150));

    mEditText.setOnClickListener(
        new OnClickListener() {

          @Override
          public void onClick(View v) {
            mEditText.mCursorIndex = mEditText.getSelectionStart();
            mFragmentLatout.setVisibility(View.GONE);
            mTopicButton.setChecked(false);
          }
        });

    mEditText.addTextChangedListener(
        new TextWatcher() {

          @Override
          public void onTextChanged(CharSequence s, int start, int before, int count) {
            if (count == 1) {
              String newChar = s.subSequence(start, start + count).toString();
              // 转发时不显示话题
              if (CHAR_WELL.equals(newChar) && !isForwardFeed) {
                showTopicFragment();
              } else if (CHAR_AT.equals(newChar)) {
                showAtFriendsDialog();
              }
            }
          }

          @Override
          public void beforeTextChanged(CharSequence s, int start, int count, int after) {}

          @Override
          public void afterTextChanged(Editable s) {}
        });
  }
  /** 显示选择话题的Fragment</br> */
  private void showTopicFragment() {
    mFragmentLatout.setVisibility(View.VISIBLE);
    hideInputMethod(mEditText);

    if (mTopicFragment == null) {
      mTopicFragment = new TopicPickerFragment();
    }
    showFragment(mTopicFragment);
    // 新增话题的回调
    mTopicFragment.addTopicListener(
        new ResultListener<Topic>() {

          @Override
          public void onRemove(Topic topic) {
            mEditText.removeTopic(topic);
          }

          @Override
          public void onAdd(Topic topic) {
            Log.d(TAG, "### topic = " + topic);
            if (isCharsOverflow(topic.name)) {
              ToastMsg.showShortMsgByResName("umeng_comm_overflow_tips");
              return;
            }
            if (!mEditText.mTopicMap.containsValue(topic)) {
              removeChar('#');
              List<Topic> topics = new ArrayList<Topic>();
              topics.add(topic);
              mEditText.insertTopics(topics);
              mSelecteTopics.add(topic);
              startFadeOutAnimForTopicTipView();
            }

            showKeyboard();
          }
        });

    // 删除话题时的回调
    mEditText.setTopicListener(
        new ResultListener<Topic>() {

          @Override
          public void onRemove(Topic topic) {
            mTopicFragment.uncheckTopic(topic);
            if (mEditText.mTopicMap.size() == 0 && !isForwardFeed) {
              startAnimationForTopicTipView();
            }
          }

          @Override
          public void onAdd(Topic topic) {}
        });
  }
  @Override
  public void restoreFeedItem(FeedItem feedItem) {
    mEditText.setText(feedItem.text);
    mLocationTv.setText(feedItem.locationAddr);
    mImageSelectedAdapter.getDataSource().clear();

    int count = feedItem.imageUrls.size();
    for (int i = 0; i < count; i++) {
      // 图片
      mImageSelectedAdapter.getDataSource().add(feedItem.imageUrls.get(i).originImageUrl);
    }
    // 图片
    if (mImageSelectedAdapter.getDataSource().size() < 9) {
      mImageSelectedAdapter.getDataSource().add(0, Constants.ADD_IMAGE_PATH_SAMPLE);
    }
    mImageSelectedAdapter.notifyDataSetChanged();
    // 好友
    mSelectFriends.addAll(feedItem.atFriends);
    // 话题
    mSelecteTopics.addAll(feedItem.topics);
    FeedViewRender.parseTopicsAndFriends(mEditText, feedItem);
    // 设置光标位置
    mEditText.setSelection(mEditText.getText().length());
  }
  /** 显示@好友列表的Dialog</br> */
  private void showAtFriendsDialog() {

    if (mAtFriendDlg == null) {
      mAtFriendDlg =
          new AtFriendDialog(
              PostFeedActivity.this, ResFinder.getStyle("umeng_comm_dialog_fullscreen"));
    }
    mAtFriendDlg.setOwnerActivity(PostFeedActivity.this);
    // 数据获取监听器
    mAtFriendDlg.setDataListener(
        new SimpleFetchListener<CommUser>() {

          @Override
          public void onComplete(CommUser user) {
            if (user != null) {
              if (isCharsOverflow(user.name)) {
                ToastMsg.showShortMsgByResName("umeng_comm_overflow_tips");
                return;
              }
              removeChar('@');
              mSelectFriends.add(user);
              // 插入数据
              mEditText.atFriends(mSelectFriends);
            }
            // // 显示输入框
            showKeyboard();
          }
        });

    mEditText.setResultListener(
        new ResultListener<CommUser>() {

          @Override
          public void onAdd(CommUser t) {}

          @Override
          public void onRemove(CommUser friend) {
            mSelectFriends.remove(friend);
          }
        });
    mAtFriendDlg.show();
  }
  /** 准备feed数据</br> */
  protected FeedItem prepareFeed() {
    FeedItem mNewFeed = new FeedItem();
    mNewFeed.text = mEditText.getText().toString().trim();
    mNewFeed.locationAddr = getLocationAddr();
    mNewFeed.location = mLocation;

    // 移除添加图标
    mImageSelectedAdapter.getDataSource().remove(Constants.ADD_IMAGE_PATH_SAMPLE);

    for (String url : mImageSelectedAdapter.getDataSource()) {
      // 图片地址
      mNewFeed.imageUrls.add(new ImageItem("", "", url));
    }

    // 话题
    mNewFeed.topics.addAll(mSelecteTopics);
    // @好友
    mNewFeed.atFriends.addAll(mSelectFriends);
    // 发表的用户
    mNewFeed.creator = CommConfig.getConfig().loginedUser;
    mNewFeed.type = mNewFeed.creator.permisson == Permisson.ADMIN ? 1 : 0;
    Log.d(TAG, " @@@ my new Feed = " + mNewFeed);
    return mNewFeed;
  }