private static String buildComment(
      ThreadRowInfo row, String fgColor, boolean showImage, int imageQuality) {
    if (row == null || row.getComments() == null || row.getComments().size() == 0) {
      return "";
    }

    StringBuilder ret = new StringBuilder();
    ret.append("<br/></br>").append(comment).append("<hr/><br/>");
    ret.append("<table border='1px' cellspacing='0px' style='border-collapse:collapse;");
    ret.append("color:");
    ret.append(fgColor);
    ret.append("'>");

    ret.append("<tbody>");

    Iterator<ThreadRowInfo> it = row.getComments().iterator();
    while (it.hasNext()) {
      ThreadRowInfo comment = it.next();
      ret.append("<tr><td>");
      ret.append("<span style='font-weight:bold' >");
      ret.append(comment.getAuthor());
      ret.append("</span><br/>");
      ret.append("<img src='");
      String avatarUrl = FunctionUtil.parseAvatarUrl(comment.getJs_escap_avatar());
      ret.append(avatarUrl);
      ret.append("' style= 'max-width:32;'>");

      ret.append("</td><td>");
      ret.append(StringUtil.decodeForumTag(comment.getContent(), showImage, imageQuality, null));
      ret.append("</td></tr>");
    }
    ret.append("</tbody></table>");
    return ret.toString();
  }
    public void handleReply(View v1) {

      act.setTo_(toText.getText().toString());
      act.setPost_subject_(titleText.getText().toString());
      if (bodyText.getText().toString().length() > 0) {
        act.setPost_content_(FunctionUtil.ColorTxtCheck(bodyText.getText().toString()));
        new MessagePostTask(MessagePostActivity.this).execute(url, act.toString());
      }
    }
  private void handleAvatar(ImageView avatarIV, ThreadRowInfo row) {

    final int lou = row.getLou();
    final String avatarUrl = FunctionUtil.parseAvatarUrl(row.getJs_escap_avatar()); //
    final String userId = String.valueOf(row.getAuthorid());
    if (PhoneConfiguration.getInstance().nikeWidth < 3) {
      avatarIV.setImageBitmap(null);
      return;
    }
    if (defaultAvatar == null
        || defaultAvatar.getWidth() != PhoneConfiguration.getInstance().nikeWidth) {
      Resources res = avatarIV.getContext().getResources();
      InputStream is = res.openRawResource(R.drawable.default_avatar);
      InputStream is2 = res.openRawResource(R.drawable.default_avatar);
      this.defaultAvatar = ImageUtil.loadAvatarFromStream(is, is2);
    }

    Object tagObj = avatarIV.getTag();
    if (tagObj instanceof AvatarTag) {
      AvatarTag origTag = (AvatarTag) tagObj;
      if (origTag.isDefault == false) {
        ImageUtil.recycleImageView(avatarIV);
        // Log.d(TAG, "recycle avatar:" + origTag.lou);
      } else {
        // Log.d(TAG, "default avatar, skip recycle");
      }
    }

    AvatarTag tag = new AvatarTag(lou, true);
    avatarIV.setImageBitmap(defaultAvatar);
    avatarIV.setTag(tag);
    if (!StringUtil.isEmpty(avatarUrl)) {
      final String avatarPath = ImageUtil.newImage(avatarUrl, userId);
      if (avatarPath != null) {
        File f = new File(avatarPath);
        if (f.exists() && !isPending(avatarUrl)) {

          Bitmap bitmap = ImageUtil.loadAvatarFromSdcard(avatarPath);
          if (bitmap != null) {
            avatarIV.setImageBitmap(bitmap);
            tag.isDefault = false;
          } else f.delete();
          long date = f.lastModified();
          if ((System.currentTimeMillis() - date) / 1000 > 30 * 24 * 3600) {
            f.delete();
          }

        } else {
          final boolean downImg =
              isInWifi() || PhoneConfiguration.getInstance().isDownAvatarNoWifi();

          new AvatarLoadTask(avatarIV, null, downImg, lou, this)
              .execute(avatarUrl, avatarPath, userId);
        }
      }
    }
  }
  /*
   * (non-Javadoc)
   *
   * @see android.app.Activity#onCreate(android.os.Bundle)
   */
  @Override
  protected void onCreate(Bundle savedInstanceState) {

    int orentation = ThemeManager.getInstance().screenOrentation;
    if (orentation == ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE
        || orentation == ActivityInfo.SCREEN_ORIENTATION_PORTRAIT) {
      setRequestedOrientation(orentation);
    } else {
      setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED);
    }

    super.onCreate(savedInstanceState);
    v = this.getLayoutInflater().inflate(R.layout.messagereply, null);
    v.setBackgroundColor(getResources().getColor(ThemeManager.getInstance().getBackgroundColor()));
    this.setContentView(v);

    if (PhoneConfiguration.getInstance().uploadLocation
        && PhoneConfiguration.getInstance().location == null) {
      ActivityUtil.reflushLocation(this);
    }

    Intent intent = this.getIntent();
    prefix = intent.getStringExtra("prefix");
    // if(prefix!=null){
    // prefix=prefix.replaceAll("\\n\\n", "\n");
    // }
    tousername = intent.getStringExtra("to");
    action = intent.getStringExtra("action");
    mid = intent.getIntExtra("mid", 0);
    String title = intent.getStringExtra("title");

    titleText = (EditText) findViewById(R.id.reply_titile_edittext);
    toText = (EditText) findViewById(R.id.reply_titile_edittext_to);
    bodyText = (EditText) findViewById(R.id.reply_body_edittext);

    if (action.equals("new")) {
      getSupportActionBar().setTitle(R.string.new_message);
    } else if (action.equals("reply")) {
      getSupportActionBar().setTitle(R.string.reply_message);
    }
    titleText.setSelected(true);

    act = new MessagePostAction(mid, "", "");
    act.setAction_(action);
    this.act.set__ngaClientChecksum(FunctionUtil.getngaClientChecksum(this));
    loading = false;

    if (!StringUtil.isEmpty(tousername)) {
      toText.setText(tousername);
      if (!StringUtil.isEmpty(title)) {
        titleText.setText(title);
      }
    } else {
      if (!StringUtil.isEmpty(title)) {
        titleText.setText(title);
      }
    }
    if (prefix != null) {
      if (prefix.startsWith("[quote][pid=") && prefix.endsWith("[/quote]\n")) {
        SpannableString spanString = new SpannableString(prefix);
        spanString.setSpan(
            new BackgroundColorSpan(-1513240),
            0,
            prefix.length(),
            Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
        spanString.setSpan(
            new StyleSpan(android.graphics.Typeface.BOLD),
            prefix.indexOf("[b]Post by"),
            prefix.indexOf("):[/b]") + 5,
            Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
        bodyText.append(spanString);
      } else {
        bodyText.append(prefix);
      }
      bodyText.setSelection(prefix.length());
    }
    ThemeManager tm = ThemeManager.getInstance();
    if (tm.getMode() == ThemeManager.MODE_NIGHT) {
      bodyText.setBackgroundResource(tm.getBackgroundColor());
      toText.setBackgroundResource(tm.getBackgroundColor());
      titleText.setBackgroundResource(tm.getBackgroundColor());
      int textColor = this.getResources().getColor(tm.getForegroundColor());
      bodyText.setTextColor(textColor);
      titleText.setTextColor(textColor);
      toText.setTextColor(textColor);
    }
  }
  @SuppressWarnings("deprecation")
  @Override
  public int finishUpload(String attachments, String attachmentsCheck, String picUrl, Uri uri) {
    String selectedImagePath2 = FunctionUtil.getPath(this, uri);
    final int index = bodyText.getSelectionStart();
    this.act.appendAttachments_(attachments);
    act.appendAttachments_check_(attachmentsCheck);
    String spantmp = "[img]./" + picUrl + "[/img]";
    if (!StringUtil.isEmpty(selectedImagePath2)) {
      BitmapFactory.Options options = new BitmapFactory.Options();
      options.inJustDecodeBounds = true;
      Bitmap bitmap = BitmapFactory.decodeFile(selectedImagePath2, options); // 此时返回 bm 为空
      options.inJustDecodeBounds = false;
      DisplayMetrics dm = new DisplayMetrics();
      getWindowManager().getDefaultDisplay().getMetrics(dm);
      int screenwidth = (int) (dm.widthPixels * 0.75);
      int screenheigth = (int) (dm.heightPixels * 0.75);
      int width = options.outWidth;
      int height = options.outHeight;
      float scaleWidth = ((float) screenwidth) / width;
      float scaleHeight = ((float) screenheigth) / height;
      if (scaleWidth < scaleHeight && scaleWidth < 1f) { // 不能放大啊,然后主要是哪个小缩放到哪个就行了
        options.inSampleSize = (int) (1 / scaleWidth);
      } else if (scaleWidth >= scaleHeight && scaleHeight < 1f) {
        options.inSampleSize = (int) (1 / scaleHeight);
      } else {
        options.inSampleSize = 1;
      }
      bitmap = BitmapFactory.decodeFile(selectedImagePath2, options);
      BitmapDrawable bd = new BitmapDrawable(bitmap);
      Drawable drawable = (Drawable) bd;
      drawable.setBounds(0, 0, drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight());
      SpannableString spanStringS = new SpannableString(spantmp);
      ImageSpan span = new ImageSpan(drawable, ImageSpan.ALIGN_BASELINE);
      spanStringS.setSpan(span, 0, spantmp.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);

      if (bodyText.getText().toString().replaceAll("\\n", "").trim().equals("")) { // NO INPUT DATA
        bodyText.append(spanStringS);
        bodyText.append("\n");
      } else {
        if (index <= 0 || index >= bodyText.length()) { // pos @ begin /
          // end
          if (bodyText.getText().toString().endsWith("\n")) {
            bodyText.append(spanStringS);
            bodyText.append("\n");
          } else {
            bodyText.append("\n");
            bodyText.append(spanStringS);
            bodyText.append("\n");
          }
        } else {
          bodyText.getText().insert(index, spanStringS);
        }
      }
    } else {
      if (bodyText.getText().toString().replaceAll("\\n", "").trim().equals("")) { // NO INPUT DATA
        bodyText.append("[img]./" + picUrl + "[/img]\n");
      } else {
        if (index <= 0 || index >= bodyText.length()) { // pos @ begin /
          // end
          if (bodyText.getText().toString().endsWith("\n")) {
            bodyText.append("[img]./" + picUrl + "[/img]\n");
          } else {
            bodyText.append("\n[img]./" + picUrl + "[/img]\n");
          }
        } else {
          bodyText.getText().insert(index, "[img]./" + picUrl + "[/img]");
        }
      }
    }
    InputMethodManager imm =
        (InputMethodManager) bodyText.getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
    imm.toggleSoftInput(0, InputMethodManager.SHOW_FORCED);
    return 1;
  }
  @Override
  public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
      case R.id.upload:
        Intent intent = new Intent();
        intent.setType("image/*");
        intent.setAction(Intent.ACTION_GET_CONTENT);
        startActivityForResult(intent, REQUEST_CODE_SELECT_PIC);
        break;
      case R.id.emotion:
        FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
        Fragment prev = getSupportFragmentManager().findFragmentByTag(EMOTION_CATEGORY_TAG);
        if (prev != null) {
          ft.remove(prev);
        }

        DialogFragment newFragment = new EmotionCategorySelectFragment();
        newFragment.show(ft, EMOTION_CATEGORY_TAG);
        break;
      case R.id.supertext:
        FunctionUtil.handleSupertext(bodyText, this, v);
        break;
      case R.id.send:
        if (StringUtil.isEmpty(toText.getText().toString())) {
          if (toast != null) {
            toast.setText("请输入收件人");
            toast.setDuration(Toast.LENGTH_SHORT);
            toast.show();
          } else {
            toast = Toast.makeText(MessagePostActivity.this, "请输入收件人", Toast.LENGTH_SHORT);
            toast.show();
          }
        } else if (StringUtil.isEmpty(titleText.getText().toString())) {
          if (toast != null) {
            toast.setText("请输入标题");
            toast.setDuration(Toast.LENGTH_SHORT);
            toast.show();
          } else {
            toast = Toast.makeText(MessagePostActivity.this, "请输入标题", Toast.LENGTH_SHORT);
            toast.show();
          }
        } else if (StringUtil.isEmpty(bodyText.getText().toString())) {
          if (toast != null) {
            toast.setText("请输入内容");
            toast.setDuration(Toast.LENGTH_SHORT);
            toast.show();
          } else {
            toast = Toast.makeText(MessagePostActivity.this, "请输入内容", Toast.LENGTH_SHORT);
            toast.show();
          }
        } else {
          if (commitListener == null) {
            commitListener = new ButtonCommitListener(REPLY_URL);
          }
          commitListener.onClick(null);
        }
        break;
      default:
        finish();
    }
    return true;
  } // OK
  public View getView(int position, View view, ViewGroup parent) {
    final ThreadRowInfo row = data.getRowList().get(position);

    int lou = -1;
    if (row != null) lou = row.getLou();
    ViewHolder holder = null;
    boolean needin = false;
    SoftReference<View> ref = viewCache.get(position);
    View cachedView = null;
    if (ref != null) {
      cachedView = ref.get();
    }
    if (cachedView != null) {
      if (((ViewHolder) cachedView.getTag()).position == position) {
        Log.d(TAG, "get view from cache ,floor " + lou);
        return cachedView;
      } else {
        view = LayoutInflater.from(activity).inflate(R.layout.relative_aritclelist, parent, false);
        holder = initHolder(view);
        holder.position = position;
        view.setTag(holder);
        viewCache.put(position, new SoftReference<View>(view));
      }
    } else {
      view = LayoutInflater.from(activity).inflate(R.layout.relative_aritclelist, parent, false);
      holder = initHolder(view);
      holder.position = position;
      view.setTag(holder);
      viewCache.put(position, new SoftReference<View>(view));
    }
    if (!PhoneConfiguration.getInstance().showReplyButton) {
      holder.viewBtn.setVisibility(View.GONE);
    } else {
      MyListenerForReply myListenerForReply = new MyListenerForReply(position, data, activity);
      holder.viewBtn.setOnClickListener(myListenerForReply);
    }
    ThemeManager theme = ThemeManager.getInstance();
    int colorId = theme.getBackgroundColor(position);
    view.setBackgroundResource(colorId);

    // colorId = theme.getBackgroundColor(2);

    if (row == null) {
      return view;
    }

    handleAvatar(holder.avatarIV, row);

    int fgColorId = ThemeManager.getInstance().getForegroundColor();
    final int fgColor = parent.getContext().getResources().getColor(fgColorId);

    FunctionUtil.handleNickName(row, fgColor, holder.nickNameTV, activity);

    final int bgColor = parent.getContext().getResources().getColor(colorId);

    final WebView contentTV = holder.contentTV;

    final String floor = String.valueOf(lou);
    TextView floorTV = holder.floorTV;
    floorTV.setText("[" + floor + " 楼]");
    floorTV.setTextColor(fgColor);

    if (!StringUtil.isEmpty(row.getFromClientModel())) {
      MyListenerForClient myListenerForClient =
          new MyListenerForClient(position, data, activity, parent);
      String from_client_model = row.getFromClientModel();
      if (from_client_model.equals("ios")) {
        holder.clientBtn.setImageResource(R.drawable.ios); // IOS
      } else if (from_client_model.equals("wp")) {
        holder.clientBtn.setImageResource(R.drawable.wp); // WP
      } else if (from_client_model.equals("unknown")) {
        holder.clientBtn.setImageResource(R.drawable.unkonwn); // 未知orBB
      }
      holder.clientBtn.setVisibility(View.VISIBLE);
      holder.clientBtn.setOnClickListener(myListenerForClient);
    }
    if (ActivityUtil.isLessThan_4_3()) {
      new Thread(
              new Runnable() {
                public void run() {
                  FunctionUtil.handleContentTV(
                      contentTV, row, bgColor, fgColor, activity, null, client);
                }
              })
          .start();
    } else if (ActivityUtil.isLessThan_4_4()) {
      ((Activity) parent.getContext())
          .runOnUiThread(
              new Runnable() {
                public void run() {
                  FunctionUtil.handleContentTV(
                      contentTV, row, bgColor, fgColor, activity, null, client);
                }
              });
    } else {
      FunctionUtil.handleContentTV(contentTV, row, bgColor, fgColor, activity, null, client);
    }
    TextView postTimeTV = holder.postTimeTV;
    postTimeTV.setText(row.getPostdate());
    postTimeTV.setTextColor(fgColor);
    if (needin) {
      view.invalidate();
    }
    return view;
  }