@Override
 public void onClick(View v) {
   if (v.getId() == R.id.bbcode) {
     selectionStart =
         mMessage
             .getSelectionStart(); // work around the ICS text selection actionbar, bane of my
                                   // existence
     selectionEnd = mMessage.getSelectionEnd();
     BBCodeFragment fragment = new BBCodeFragment();
     fragment.show(getActivity().getSupportFragmentManager(), "select_bbcode_dialog");
   }
   if (v.getId() == R.id.emotes) {
     Toast.makeText(v.getContext(), "EMOTIONALLY UNAVAILABLE", Toast.LENGTH_LONG).show();
   }
 }
        @Override
        public void afterTextChanged(Editable s) {
          Log.v("TextWatcher-afterTextChanged-->", s.toString() + "length" + s.length());
          // 输入的时候,只有一个光标,那么这两个值应该是相等的。。。
          editStart = et_user_ban.getSelectionStart();
          editEnd = et_user_ban.getSelectionEnd();

          // 限定EditText只能输入19个数字,并且达到19个的时候用红色显示
          if (charSequence.length() > 19) {
            Toast.makeText(AddBankCardActivity.this, "你输入的字数已经超过了限制,不能再输入!", Toast.LENGTH_SHORT)
                .show();
            // 默认光标在最前端,所以当输入第19个数字的时候,删掉(光标位置从11-1到11)的数字,这样就无法输入超过19个以后的数字
            s.delete(editStart - 1, editEnd);
            // 当输入超过第19个数字的时候,改变字体颜色为红色
          }
        }
 public void insertBBCode(BBCODE code) {
   if (selectionStart < 0) { // we might be getting this from an earlier point
     selectionStart = mMessage.getSelectionStart();
     selectionEnd = mMessage.getSelectionEnd();
   }
   boolean highlighted = selectionStart != selectionEnd;
   String startTag = null;
   String endTag = null;
   switch (code) {
     case BOLD:
       startTag = "[b]";
       endTag = "[/b]";
       break;
     case ITALICS:
       startTag = "[i]";
       endTag = "[/i]";
       break;
     case UNDERLINE:
       startTag = "[u]";
       endTag = "[/u]";
       break;
     case STRIKEOUT:
       startTag = "[s]";
       endTag = "[/s]";
       break;
     case URL:
       /* clipboard code, probably need to implement an alertdialog for this
       String link = null;
       if(Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB){
       	ClipboardManager cb = (ClipboardManager) getActivity().getSystemService(Context.CLIPBOARD_SERVICE);
       	String copy = String.valueOf(cb.getText());
       	if(copy.startsWith("http://") || copy.startsWith("https://")){
       		link = copy;
       	}
       }else{
       	android.content.ClipboardManager cb = (android.content.ClipboardManager) getActivity().getSystemService(Context.CLIPBOARD_SERVICE);
       	String copy = String.valueOf(cb.getText());
       	if(copy.startsWith("http://") || copy.startsWith("https://")){
       		link = copy;
       	}
       }
       if(link != null){
       	startTag = "[url="+link+"]";
       }else{
       	startTag = "[url]";
       }
       */
       startTag = "[url]";
       endTag = "[/url]";
       break;
     case QUOTE:
       startTag = "[quote]";
       endTag = "[/quote]";
       break;
     case IMAGE:
       startTag = "[img]";
       endTag = "[/img]";
       break;
     case SPOILER:
       startTag = "[spoiler]";
       endTag = "[/spoiler]";
       break;
     case CODE:
       startTag = "[code]";
       endTag = "[/code]";
       break;
   }
   if (startTag != null && endTag != null) {
     if (highlighted) {
       mMessage.getEditableText().insert(selectionStart, startTag);
       mMessage.getEditableText().insert(selectionEnd + startTag.length(), endTag);
       mMessage.setSelection(selectionStart + startTag.length());
     } else {
       mMessage.getEditableText().insert(selectionStart, startTag + endTag);
       mMessage.setSelection(selectionStart + startTag.length());
     }
   }
   selectionStart = -1; // reset them for next time
   selectionEnd = -1;
 }