private void bindView() {
    hideProgressDialog();

    icon.setVisibility(View.VISIBLE);
    icon.setImageResource(mFileObject.getIconResourceId());

    iconTxt.setVisibility(View.GONE);

    name.setText(mFileObject.getName());

    content.setText(Global.HumanReadableFilesize(mFileObject.getSize()));

    tvDownload.setText(
        String.format(
            downloadFormat,
            Global.HumanReadableFilesize(0.0),
            Global.HumanReadableFilesize(mFileObject.getSize())));
    progressBar.setMax(mFileObject.getSize());
    mainLayout.setVisibility(View.VISIBLE);

    mFile =
        FileUtil.getDestinationInExternalPublicDir(
            getFileDownloadPath(), mFileObject.getSaveName(mProjectObjectId));
    Log.d(TAG, "downloadId:" + downloadId);

    File file =
        FileUtil.getDestinationInExternalPublicDir(
            getFileDownloadPath(), mAttachmentFileObject.getSaveName(mProjectObjectId));
    if (file.exists() && file.isFile()) {
      showState(STATE_FINISHDOWNLOAD);
    } else {
      showState(STATE_NEEDDOWNLOAD);
    }
  }
        @Override
        public void onClick(View v) {
          if (mMaopaoObject == null) {
            showButtomToast(R.string.maopao_load_fail_comment);
            return;
          }

          EditText content = mEnterLayout.content;
          String input = content.getText().toString();

          if (EmojiFilter.containsEmptyEmoji(v.getContext(), input)) {
            return;
          }

          Maopao.Comment comment = (Maopao.Comment) content.getTag();
          String uri = String.format(ADD_COMMENT, comment.tweet_id);

          RequestParams params = new RequestParams();

          String contentString;
          if (comment.id == 0) {
            contentString = Global.encodeInput("", input);
          } else {
            contentString = Global.encodeInput(comment.owner.name, input);
          }
          params.put("content", contentString);
          postNetwork(uri, params, ADD_COMMENT, 0, comment);

          showProgressBar(R.string.sending_comment);
        }
 @AfterViews
 protected final void initAttachmentsTextDetailActivity() {
   if (mExtraFile != null) {
     textView.setText(Global.readTextFile(mExtraFile));
     findViewById(R.id.layout_dynamic_history).setVisibility(View.GONE);
   } else {
     urlFiles = String.format(urlFiles, mProjectObjectId, mAttachmentFileObject.file_id);
     if (mFile.exists()) {
       textView.setText(Global.readTextFile(mFile));
     } else {
       showDialogLoading();
       getFileUrlFromNetwork();
     }
   }
 }
  private void initActionView(MenuItem searchItem) {
    if (searchView != null) return;
    searchView = (SearchView) MenuItemCompat.getActionView(searchItem);
    try { // 更改搜索按钮的icon
      int searchImgId = getResources().getIdentifier("android:id/search_button", null, null);
      ImageView v = (ImageView) searchView.findViewById(searchImgId);
      v.setImageResource(R.drawable.ic_menu_search);
    } catch (Exception e) {
      Global.errorLog(e);
    }
    searchView.setOnQueryTextListener(
        new SearchView.OnQueryTextListener() {
          @Override
          public boolean onQueryTextSubmit(String s) {
            return true;
          }

          @Override
          public boolean onQueryTextChange(String s) {
            ++sSearchPos;
            searchAdapter.reload(searchView.getQuery().toString());
            return true;
          }
        });
  }
 @OptionsItem
 void action_info() {
   AlertDialog.Builder builder = new AlertDialog.Builder(this);
   AlertDialog dialog =
       builder
           .setTitle("文件信息")
           .setMessage(
               String.format(
                   fileInfoFormat,
                   mAttachmentFileObject.fileType,
                   Global.HumanReadableFilesize(mAttachmentFileObject.getSize()),
                   Global.dayToNow(mAttachmentFileObject.created_at),
                   Global.dayToNow(mAttachmentFileObject.updated_at),
                   mAttachmentFileObject.owner.name))
           .setPositiveButton("确定", null)
           .show();
   dialogTitleLineColor(dialog);
 }
 protected final void action_copy() {
   String link = getLink();
   if (link.isEmpty()) {
     showButtomToast("复制链接失败");
   } else {
     Global.copy(this, link);
     showButtomToast("已复制链接 " + link);
   }
 }
 public static void writeFile(File srcFile, String content) {
   try {
     FileOutputStream fos = new FileOutputStream(srcFile);
     fos.write(content.getBytes());
     fos.close();
   } catch (Exception e) {
     Global.errorLog(e);
   }
 }
 @OptionsItem
 protected final void action_copy() {
   String preViewUrl = mAttachmentFileObject.owner_preview;
   int pos = preViewUrl.lastIndexOf("imagePreview");
   if (pos != -1) {
     preViewUrl = preViewUrl.substring(0, pos) + "download";
   }
   Global.copy(this, preViewUrl);
   showButtomToast("已复制 " + preViewUrl);
 }
  private void updateLoadFile() {
    if (mAttachmentFileObject == null || mProjectObjectId == 0) {
      return;
    }

    mFile =
        FileUtil.getDestinationInExternalPublicDir(
            getFileDownloadPath(), mAttachmentFileObject.getSaveName(mProjectObjectId));
    if (mFile != null && mFile.exists()) {
      textView.setText(Global.readTextFile(mFile));
    }
  }
  @Override
  public View getView(int position, View convertView, ViewGroup parent) {
    ViewHolder viewHolder = null;
    if (convertView == null) {

      convertView = LayoutInflater.from(mContext).inflate(R.layout.subject_search_list_item, null);
      viewHolder = new ViewHolder();
      viewHolder.content = (TextView) convertView.findViewById(R.id.maopao_content);
      viewHolder.likeCountView = (TextView) convertView.findViewById(R.id.maopao_item_like_count);
      viewHolder.timeView = (TextView) convertView.findViewById(R.id.maopao_item_time);
      viewHolder.commentView = (TextView) convertView.findViewById(R.id.maopao_item_comment);
      viewHolder.userNameView = (TextView) convertView.findViewById(R.id.maopao_item_user_name);
      viewHolder.userIconView = (CircleImageView) convertView.findViewById(R.id.maopao_user_icon);
      convertView.setTag(viewHolder);

    } else {
      viewHolder = (ViewHolder) convertView.getTag();
    }
    if (maopaoObjectItems != null && position >= 0 && position < maopaoObjectItems.size()) {
      Maopao.MaopaoObject maopaoObject = maopaoObjectItems.get(position);
      if (maopaoObject != null) {
        Global.MessageParse parse = HtmlContent.parseMessage(maopaoObject.content);
        viewHolder.content.setText(
            Global.changeHyperlinkColor(
                HtmlContent.parseReplacePhotoMonkey(parse.text), mImageGetter, Global.tagHandler));
        viewHolder.likeCountView.setText(String.valueOf(maopaoObject.likes));
        if (maopaoObject.owner != null && !TextUtils.isEmpty(maopaoObject.owner.avatar))
          mImageLoadTool.loadImage(viewHolder.userIconView, maopaoObject.owner.avatar);
        viewHolder.timeView.setText(Global.dayToNow(maopaoObject.created_at));
        if (maopaoObject.owner != null && !TextUtils.isEmpty(maopaoObject.owner.avatar))
          viewHolder.userNameView.setText(String.valueOf(maopaoObject.owner.name));
        viewHolder.commentView.setText(String.valueOf(maopaoObject.comments));
      }
    }
    return convertView;
  }
  private String readTextFile(InputStream inputStream) {
    ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
    byte buf[] = new byte[1024];
    int len;
    try {
      while ((len = inputStream.read(buf)) != -1) {
        outputStream.write(buf, 0, len);
      }
      outputStream.close();
      inputStream.close();

    } catch (IOException e) {
      Global.errorLog(e);
    }
    return outputStream.toString();
  }
  @AfterViews
  protected final void initMaopaoDetailActivity() {
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);

    mEnterLayout =
        new EnterEmojiLayout(
            this, onClickSend, EnterLayout.Type.TextOnly, EnterEmojiLayout.EmojiType.SmallOnly);
    mEnterLayout.content.addTextChangedListener(new TextWatcherAt(this, this, RESULT_REQUEST_AT));

    try {
      bubble = readTextFile(getAssets().open("bubble"));
    } catch (Exception e) {
      Global.errorLog(e);
    }

    swipeRefreshLayout.setOnRefreshListener(this);
    swipeRefreshLayout.setColorSchemeResources(R.color.green);
    loadData();
  }
  void prepareAddComment(Object data, boolean popKeyboard) {
    Maopao.Comment comment = null;
    EditText content = mEnterLayout.content;
    if (data instanceof Maopao.Comment) {
      comment = (Maopao.Comment) data;
      content.setHint("回复 " + comment.owner.name);
      content.setTag(comment);
    } else if (data instanceof Maopao.MaopaoObject) {
      comment = new Maopao.Comment((Maopao.MaopaoObject) data);
      content.setHint("评论冒泡");
      content.setTag(comment);
    }

    mEnterLayout.restoreLoad(comment);

    if (popKeyboard) {
      content.requestFocus();
      Global.popSoftkeyboard(MaopaoDetailActivity.this, content, true);
    }
  }
    @Override
    public void handleMessage(Message msg) {
      super.handleMessage(msg);

      switch (msg.what) {
        case 0:
          int status = (Integer) msg.obj;
          if (isDownloading(status)) {
            showState(STATE_STARTDOWNLOAD);

            if (msg.arg2 < 0) {
              tvDownload.setText(
                  String.format(
                      downloadFormat,
                      Global.HumanReadableFilesize(0.00),
                      Global.HumanReadableFilesize(mFileObject.getSize())));
              progressBar.setProgress(0);

            } else {
              tvDownload.setText(
                  String.format(
                      downloadFormat,
                      Global.HumanReadableFilesize(msg.arg1),
                      Global.HumanReadableFilesize(msg.arg2)));
              progressBar.setProgress(msg.arg1);
            }
          } else {

            if (status == DownloadManager.STATUS_FAILED) {
              // downloadButton.setText(getString(R.string.app_status_download_fail));
              showButtomToast("下载失败,请重试");
              showState(STATE_NEEDDOWNLOAD);
            } else if (status == DownloadManager.STATUS_SUCCESSFUL) {
              downloadListEditor.remove(mFileObject.file_id);
              downloadListEditor.commit();
              showState(STATE_FINISHDOWNLOAD);
              downloadId = 0L;

              //                            jumpTextHtmlActivity();
              //                            if (mAttachmentFileObject.isMd())
              //                            finish();
              Intent intent = new Intent();
              mAttachmentFileObject.isDownload = true;
              intent.putExtra(AttachmentFileObject.RESULT, mAttachmentFileObject);
              if (mAttachmentFileObject.needJump()) {
                intent.putExtra(
                    AttachmentsActivity.FileActions.ACTION_NAME,
                    AttachmentsActivity.FileActions.ACTION_DOWNLOAD_OPEN);
                setResult(RESULT_OK, intent);
                finish();
              } else {
                intent.putExtra(
                    AttachmentsActivity.FileActions.ACTION_NAME,
                    AttachmentsActivity.FileActions.ACTION_DOWNLOAD_OPEN);
                setResult(RESULT_OK, intent);
              }

            } else {
              showState(STATE_NEEDDOWNLOAD);
            }
          }
          break;
      }
    }
  void initHead() {
    if (mListHead == null) {
      mListHead = mInflater.inflate(R.layout.activity_maopao_detail_head, null, false);
      listView.addHeaderView(mListHead, null, false);
    }

    ImageView icon = (ImageView) mListHead.findViewById(R.id.icon);
    icon.setOnClickListener(mOnClickUser);

    TextView name = (TextView) mListHead.findViewById(R.id.name);
    name.setOnClickListener(mOnClickUser);

    TextView time = (TextView) mListHead.findViewById(R.id.time);
    time.setText(Global.dayToNow(mMaopaoObject.created_at));

    iconfromNetwork(icon, mMaopaoObject.owner.avatar);
    icon.setTag(mMaopaoObject.owner.global_key);

    name.setText(mMaopaoObject.owner.name);
    name.setTag(mMaopaoObject.owner.global_key);

    WebView webView = (WebView) mListHead.findViewById(R.id.comment);
    Global.initWebView(webView);
    String replaceContent = bubble.replace("${webview_content}", mMaopaoObject.content);
    webView.loadDataWithBaseURL(null, replaceContent, "text/html", "UTF-8", null);
    webView.setWebViewClient(new CustomWebViewClient(this, mMaopaoObject.content));

    mListHead.setOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View v) {
            prepareAddComment(mMaopaoObject, true);
          }
        });

    mListHead
        .findViewById(R.id.shareBtn)
        .setOnClickListener(
            new View.OnClickListener() {
              @Override
              public void onClick(View v) {
                action_share_third();
              }
            });

    likeBtn = (CheckBox) mListHead.findViewById(R.id.likeBtn);
    mListHead
        .findViewById(R.id.commentBtn)
        .setOnClickListener(
            new View.OnClickListener() {
              @Override
              public void onClick(View v) {
                prepareAddComment(mMaopaoObject, true);
              }
            });

    likeBtn.setChecked(mMaopaoObject.liked);
    likeBtn.setOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View v) {
            if (mMaopaoObject == null) {
              showMiddleToast(R.string.maopao_load_fail_like);
              return;
            }

            boolean like = ((CheckBox) v).isChecked();
            String type = like ? "like" : "unlike";
            if (like) {
              View good = mListHead.findViewById(R.id.maopaoGood);
              MaopaoLikeAnimation.playAnimation(good, v);
            }
            String uri = String.format(HOST_GOOD, mMaopaoObject.id, type);

            postNetwork(uri, new RequestParams(), HOST_GOOD, 0, mMaopaoObject);
          }
        });

    likeUsersArea = new LikeUsersArea(mListHead, this, getImageLoad(), mOnClickUser);

    likeUsersArea.likeUsersLayout.setTag(MaopaoListFragment.TAG_MAOPAO, mMaopaoObject);
    if (mMaopaoObject.like_users.isEmpty() && mMaopaoObject.likes > 0) {
      String hostLikes = String.format(LikeUsersListActivity.HOST_LIKES_USER, mMaopaoObject.id);
      getNetwork(hostLikes, TAG_LIKE_USERS);
    }
    likeUsersArea.displayLikeUser();

    TextView locationView = (TextView) mListHead.findViewById(R.id.location);
    MaopaoLocationArea.bind(locationView, mMaopaoObject);

    TextView photoType = (TextView) mListHead.findViewById(R.id.photoType);
    String device = mMaopaoObject.device;
    if (!device.isEmpty()) {
      final String format = "来自 %s";
      photoType.setText(String.format(format, device));
      photoType.setVisibility(View.VISIBLE);
    } else {
      photoType.setText("");
      photoType.setVisibility(View.GONE);
    }

    View deleteButton = mListHead.findViewById(R.id.deleteButton);
    if (mMaopaoObject.owner.isMe()) {
      deleteButton.setVisibility(View.VISIBLE);
      deleteButton.setOnClickListener(onClickDeleteMaopao);
    } else {
      deleteButton.setVisibility(View.INVISIBLE);
    }
  }
 public int getActionBarSize() {
   return Global.dpToPx(48);
 }