Exemplo n.º 1
0
  @Override
  public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
    // TODO Auto-generated method stub

    Object itemAdapter = parent.getAdapter();

    if (itemAdapter instanceof EmotionGvAdapter) {
      // 点击的是表情
      EmotionGvAdapter emotionGvAdapter = (EmotionGvAdapter) itemAdapter;

      if (position == emotionGvAdapter.getCount() - 1) {
        // 如果点击了最后一个回退按钮,则调用删除键事件
        msg.dispatchKeyEvent(new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_DEL));

      } else {

        // 如果点击了表情,则添加到输入框中
        String emotionName = (String) emotionGvAdapter.getItem(position);

        // 获取当前光标位置,在指定位置上添加表情图片文本
        int curPosition = msg.getSelectionStart();
        StringBuilder sb = new StringBuilder(msg.getText().toString());
        sb.insert(curPosition, emotionName);

        // 特殊文字处理,将表情等转换一下

        msg.setText(StringUtils.getEmotionContent(this, msg, sb.toString()));

        // 将光标设置到新增完表情的右侧
        msg.setSelection(curPosition + emotionName.length());
      }
    }
  }
Exemplo n.º 2
0
 @Override
 public void onKey(int primaryCode, int[] keyCodes) {
   Editable editable = ed.getText();
   int start = ed.getSelectionStart();
   if (primaryCode == Keyboard.KEYCODE_CANCEL) { // 完成
     hideKeyboard();
   } else if (primaryCode == Keyboard.KEYCODE_DELETE) { // 回退
     if (editable != null && editable.length() > 0) {
       if (start > 0) {
         editable.delete(start - 1, start);
       }
     }
   } else if (primaryCode == Keyboard.KEYCODE_SHIFT) { // 大小写切换
     changeKey();
     keyboardView.setKeyboard(k1);
   } else if (primaryCode == Keyboard.KEYCODE_MODE_CHANGE) { // 数字键盘切换
     if (isnun) {
       isnun = false;
       keyboardView.setKeyboard(k1);
     } else {
       isnun = true;
       keyboardView.setKeyboard(k2);
     }
   } else if (primaryCode == 57419) { // go left
     if (start > 0) {
       ed.setSelection(start - 1);
     }
   } else if (primaryCode == 57421) { // go right
     if (start < ed.length()) {
       ed.setSelection(start + 1);
     }
   } else {
     editable.insert(start, Character.toString((char) primaryCode));
   }
 }
Exemplo n.º 3
0
 public static void wrapNewline(String wrapText, EditText editText) {
   int start = Math.max(editText.getSelectionStart(), 0);
   int end = Math.max(editText.getSelectionEnd(), 0);
   String s = editText.getText().toString().substring(Math.min(start, end), Math.max(start, end));
   s = s.replace("\n", "\n" + wrapText);
   editText.getText().replace(Math.min(start, end), Math.max(start, end), s);
 }
Exemplo n.º 4
0
  @Override
  protected void onPause() {
    super.onPause();

    if (mUri != null) {
      String bodyText = mBodyText.getText().toString();
      int length = bodyText.length();

      if ((mState == STATE_INSERT) && isFinishing() && (length == 0)) {
        // If inserting and finishing and no text then delete the note.
        setResult(RESULT_CANCELED);
        deleteNote();
      } else {
        ContentValues values = mOriginalNote.getContentValues();
        if (values.containsKey(Note._ID)) values.remove(Note._ID);

        if (mState == STATE_INSERT) {
          String[] lines = bodyText.split("[\n\\.]");
          String title = (lines.length > 0) ? lines[0] : getString(android.R.string.untitled);
          if (title.length() > 30) {
            int lastSpace = title.lastIndexOf(' ');
            if (lastSpace > 0) {
              title = title.substring(0, lastSpace);
            }
          }
          values.put(Note.TITLE, title);
        }
        values.put(Note.BODY, bodyText);
        values.put(Note.CURSOR, mBodyText.getSelectionStart());
        values.put(Note.SCROLL_Y, mBodyText.getScrollY());

        getContentResolver().update(mUri, values, null, null);
      }
    }
  }
Exemplo n.º 5
0
 /** 表情点击事件 */
 @Override
 public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
   int index = replyContent.getSelectionStart();
   Editable e = replyContent.getEditableText();
   if (index < 0 || index > e.length()) e.append(FaceUtil.getFaceList().get(position));
   else e.insert(index, FaceUtil.getFaceList().get(position));
 }
Exemplo n.º 6
0
 private void insertEmote(String emote) {
   selectionStart = mMessage.getSelectionStart();
   mMessage.getEditableText().insert(selectionStart, emote);
   mMessage.setSelection(selectionStart + emote.length());
   selectionStart = -1; // reset them for next time
   selectionEnd = -1;
 }
Exemplo n.º 7
0
 public void insertEmotion(String emotionChar) {
   String ori = content.getText().toString();
   int index = content.getSelectionStart();
   StringBuilder stringBuilder = new StringBuilder(ori);
   stringBuilder.insert(index, emotionChar);
   content.setText(stringBuilder.toString());
   content.setSelection(index + emotionChar.length());
 }
 public void saveInputState() {
   ChatManager.getInstance()
       .setTyped(
           account,
           user,
           inputView.getText().toString(),
           inputView.getSelectionStart(),
           inputView.getSelectionEnd());
 }
Exemplo n.º 9
0
 @Override
 public void onReplyToComment(Comment comment) {
   mCommentEdit
       .getText()
       .replace(
           mCommentEdit.getSelectionStart(),
           mCommentEdit.getSelectionEnd(),
           DoubanUtils.getAtUserString(comment.author));
   onComment();
 }
Exemplo n.º 10
0
 private void setStateFromView() {
   PostState state = PostState.getState();
   state.removeListener();
   state
       .beginTransaction()
       .setText(editText.getText().toString())
       .setSelection(editText.getSelectionStart(), editText.getSelectionEnd())
       .commit();
   state.setListener(this);
 }
Exemplo n.º 11
0
        public void process(String str, EditText box) {
          String oldstr = box.getText().toString();
          int stPos = Math.max(box.getSelectionStart(), 0);
          int endPos = Math.max(box.getSelectionEnd(), 0);

          if (oldstr.length() > 0)
            box.setText(
                oldstr
                    .substring(0, Math.max(stPos - 1, 0))
                    .concat(oldstr.substring(Math.max(endPos, stPos), oldstr.length())));
          box.setSelection(Math.max(stPos - 1, 0));
        }
Exemplo n.º 12
0
 /**
  * Any time we are paused we need to save away the current state, so it will be restored correctly
  * when we are resumed.
  */
 @Override
 protected void onPause() {
   super.onPause();
   MobclickAgent.onPause(this); // BY贺思明 2012-7-23
   if (getinfo() == null) {
     if (!on) {
       SharedPreferences.Editor editor = getPreferences(0).edit();
       editor.putString("phoneNumText", phoneNum_edit.getText().toString());
       editor.putInt("selection-start", phoneNum_edit.getSelectionStart());
       editor.putInt("selection-end", phoneNum_edit.getSelectionEnd());
       editor.commit();
     }
   }
 }
Exemplo n.º 13
0
 @Override
 public void afterTextChanged(Editable s) {
   editStart = mSignatureEt.getSelectionStart();
   editEnd = mSignatureEt.getSelectionEnd();
   if (temp.length() > 0) {
     mTextCountTv.setText("" + (30 - temp.length()) + "");
   }
   if (temp.length() > 30) {
     s.delete(editStart - 1, editEnd);
     int tempSelection = editStart;
     mSignatureEt.setText(s);
     mSignatureEt.setSelection(tempSelection);
   }
 }
Exemplo n.º 14
0
 private void insertTrendSoftware() {
   // 在光标所在处插入“#软件名#”
   int curTextLength = mEtInput.getText().length();
   if (curTextLength >= MAX_TEXT_LENGTH) return;
   String software = TEXT_SOFTWARE;
   int start, end;
   if ((MAX_TEXT_LENGTH - curTextLength) >= software.length()) {
     start = mEtInput.getSelectionStart() + 1;
     end = start + software.length() - 2;
   } else {
     int num = MAX_TEXT_LENGTH - curTextLength;
     if (num < software.length()) {
       software = software.substring(0, num);
     }
     start = mEtInput.getSelectionStart() + 1;
     end = start + software.length() - 1;
   }
   if (start > MAX_TEXT_LENGTH || end > MAX_TEXT_LENGTH) {
     start = MAX_TEXT_LENGTH;
     end = MAX_TEXT_LENGTH;
   }
   mEtInput.getText().insert(mEtInput.getSelectionStart(), software);
   mEtInput.setSelection(start, end); // 设置选中文字
 }
 @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个数字的时候,改变字体颜色为红色
          }
        }
Exemplo n.º 17
0
  /** attempts to perform tab completion on the current input */
  @SuppressLint("SetTextI18n")
  private void tryTabComplete() {
    if (DEBUG_TAB_COMPLETE) logger.debug("tryTabComplete()");
    if (buffer == null) return;

    String txt = uiInput.getText().toString();
    if (!tcInProgress) {
      // find the end of the word to be completed
      // blabla nick|
      tcWordEnd = uiInput.getSelectionStart();
      if (tcWordEnd <= 0) return;

      // find the beginning of the word to be completed
      // blabla |nick
      tcWordStart = tcWordEnd;
      while (tcWordStart > 0 && txt.charAt(tcWordStart - 1) != ' ') tcWordStart--;

      // get the word to be completed, lowercase
      if (tcWordStart == tcWordEnd) return;
      String prefix = txt.substring(tcWordStart, tcWordEnd).toLowerCase();

      // compute a list of possible matches
      // nicks is ordered in last used comes first way, so we just pick whatever comes first
      // if computed list is empty, abort
      tcMatches = new Vector<>();

      for (String nick : buffer.getLastUsedNicksCopy())
        if (nick.toLowerCase().startsWith(prefix)) tcMatches.add(nick.trim());
      if (tcMatches.size() == 0) return;

      tcIndex = 0;
    } else {
      tcIndex = (tcIndex + 1) % tcMatches.size();
    }

    // get new nickname, adjust the end of the word marker
    // and finally set the text and place the cursor on the end of completed word
    String nick = tcMatches.get(tcIndex);
    if (tcWordStart == 0) nick += ": ";
    uiInput.setText(txt.substring(0, tcWordStart) + nick + txt.substring(tcWordEnd));
    tcWordEnd = tcWordStart + nick.length();
    uiInput.setSelection(tcWordEnd);
    // altering text in the input box sets tcInProgress to false,
    // so this is the last thing we do in this function:
    tcInProgress = true;
  }
Exemplo n.º 18
0
 @Override
 public void doAction(int paramInt, String paramString) {
   // TODO Auto-generated method stub
   EditText localEditBlogView = mEditAnswer;
   int i = localEditBlogView.getSelectionStart();
   int j = localEditBlogView.getSelectionStart();
   String str1 = "[" + paramString + "]";
   String str2 = localEditBlogView.getText().toString();
   SpannableStringBuilder localSpannableStringBuilder = new SpannableStringBuilder();
   localSpannableStringBuilder.append(str2, 0, i);
   localSpannableStringBuilder.append(str1);
   localSpannableStringBuilder.append(str2, j, str2.length());
   SociaxUIUtils.highlightContent(QuestionDetailsActivity.this, localSpannableStringBuilder);
   localEditBlogView.setText(localSpannableStringBuilder, TextView.BufferType.SPANNABLE);
   localEditBlogView.setSelection(i + str1.length());
   Log.v("Tag", localEditBlogView.getText().toString());
 }
Exemplo n.º 19
0
  /**
   * insert text into the EditText at the current cursor position
   *
   * @param moveCursor place the cursor after the inserted text
   */
  public static void insertAtPosition(
      final EditText editText, final String insertText, final boolean moveCursor) {
    final int selectionStart = editText.getSelectionStart();
    final int selectionEnd = editText.getSelectionEnd();
    final int start = Math.min(selectionStart, selectionEnd);
    final int end = Math.max(selectionStart, selectionEnd);

    final String content = editText.getText().toString();
    final String completeText;
    if (start > 0 && !Character.isWhitespace(content.charAt(start - 1))) {
      completeText = " " + insertText;
    } else {
      completeText = insertText;
    }

    editText.getText().replace(start, end, completeText);
    final int newCursor = moveCursor ? start + completeText.length() : start;
    editText.setSelection(newCursor);
  }
Exemplo n.º 20
0
 protected void handleButtonClickByCaption(final String buttonCaption) {
   final EditText editText = this.lastFocusedPostcodeEditText;
   if (buttonCaption.equals("" + AbstractKeyBoardLayout.BUTTONGRID_BACKCAPTION)) {
     final Editable et = editText.getText();
     final int len = et.length();
     if (len > 0) {
       editText.getText().delete(len - 1, len);
     }
   } else {
     /* Append the Buttons caption it to the streetNameEditText. */
     final int selStart = editText.getSelectionStart();
     final int selEnd = editText.getSelectionEnd();
     if (selStart < selEnd) {
       editText.getText().replace(selStart, selEnd, "");
     }
     editText.getText().append(buttonCaption);
     editText.invalidate();
   }
 }
  @SuppressWarnings("deprecation")
  protected void setPasswordButtonShown(boolean shouldShow) {
    // Changing input type loses position in edit text; let's try to maintain it.
    int start = passwordEdit.getSelectionStart();
    int stop = passwordEdit.getSelectionEnd();

    if (!shouldShow) {
      passwordEdit.setTransformationMethod(PasswordTransformationMethod.getInstance());
      showPasswordButton.setText(R.string.fxaccount_password_show);
      showPasswordButton.setBackgroundDrawable(
          getResources().getDrawable(R.drawable.fxaccount_password_button_show_background));
      showPasswordButton.setTextColor(
          getResources().getColor(R.color.fxaccount_password_show_textcolor));
    } else {
      passwordEdit.setTransformationMethod(SingleLineTransformationMethod.getInstance());
      showPasswordButton.setText(R.string.fxaccount_password_hide);
      showPasswordButton.setBackgroundDrawable(
          getResources().getDrawable(R.drawable.fxaccount_password_button_hide_background));
      showPasswordButton.setTextColor(
          getResources().getColor(R.color.fxaccount_password_hide_textcolor));
    }
    passwordEdit.setSelection(start, stop);
  }
Exemplo n.º 22
0
  protected void onActivityResult(int requestCode, int resultCode, Intent intent) {
    super.onActivityResult(requestCode, resultCode, intent);

    if (resultCode == RESULT_OK) {
      switch (requestCode) {
        case CAMERA_RESULT:
          if (TextUtils.isEmpty(content.getText().toString())) {
            content.setText(getString(R.string.share_pic));
            content.setSelection(content.getText().toString().length());
          }

          picPath = getPicPathFromUri(imageFileUri);
          havePic.setVisibility(View.VISIBLE);
          break;
        case PIC_RESULT:
          if (TextUtils.isEmpty(content.getText().toString())) {
            content.setText(getString(R.string.share_pic));
            content.setSelection(content.getText().toString().length());
          }

          Uri imageFileUri = intent.getData();
          picPath = getPicPathFromUri(imageFileUri);
          havePic.setVisibility(View.VISIBLE);
          break;
        case AT_USER:
          String name = intent.getStringExtra("name");
          String ori = content.getText().toString();
          int index = content.getSelectionStart();
          StringBuilder stringBuilder = new StringBuilder(ori);
          stringBuilder.insert(index, name);
          content.setText(stringBuilder.toString());
          content.setSelection(index + name.length());
          break;
      }
    }
  }
Exemplo n.º 23
0
 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:
       String link = this.getClipboardLink();
       if (link != null) {
         startTag = "[url=" + link + "]";
       } else {
         startTag = "[url]";
       }
       // startTag = "[url]";
       endTag = "[/url]";
       break;
     case QUOTE:
       startTag = "[quote]";
       endTag = "[/quote]";
       break;
     case IMAGE:
       String imageLink = this.getClipboardLink();
       if (imageLink != null) {
         startTag = "[img]" + imageLink;
       } else {
         startTag = "[img]";
       }
       endTag = "[/img]";
       break;
     case THUMBNAIL:
       String timageLink = this.getClipboardLink();
       if (timageLink != null) {
         startTag = "[timg]" + timageLink;
       } else {
         startTag = "[timg]";
       }
       endTag = "[/timg]";
       break;
     case VIDEO:
       startTag = "[video]";
       endTag = "[/video]";
       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;
 }
Exemplo n.º 24
0
  @Override
  public boolean onOptionsItemSelected(MenuItem item) {
    if (DEBUG) Log.e(TAG, "onOptionsItemSelected");
    switch (item.getItemId()) {
      case R.id.bbcode_bold:
        insertBBCode(BBCODE.BOLD);
        break;
      case R.id.bbcode_italics:
        insertBBCode(BBCODE.ITALICS);
        break;
      case R.id.bbcode_underline:
        insertBBCode(BBCODE.UNDERLINE);
        break;
      case R.id.bbcode_strikeout:
        insertBBCode(BBCODE.STRIKEOUT);
        break;
      case R.id.bbcode_url:
        insertBBCode(BBCODE.URL);
        break;
      case R.id.bbcode_video:
        insertBBCode(BBCODE.VIDEO);
        break;
      case R.id.bbcode_image:
        insertBBCode(BBCODE.IMAGE);
        break;
      case R.id.bbcode_thumbnail:
        insertBBCode(BBCODE.THUMBNAIL);
        break;
      case R.id.bbcode_quote:
        insertBBCode(BBCODE.QUOTE);
        break;
      case R.id.bbcode_spoiler:
        insertBBCode(BBCODE.SPOILER);
        break;
      case R.id.bbcode_code:
        insertBBCode(BBCODE.CODE);
        break;
      case R.id.submit_button:
        postReply();
        break;
      case R.id.discard:
        deleteReply();
        getActivity().setResult(RESULT_CANCELLED);
        leave();
        break;
      case R.id.save_draft:
        saveReply();
        getActivity().setResult(RESULT_CANCELLED);
        leave();
        break;
      case R.id.emotes:
        selectionStart = mMessage.getSelectionStart();
        new EmoteFragment(this).show(getFragmentManager(), "emotes");
        break;
      case R.id.add_attachment:
        Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
        intent.setType("image/*");
        startActivityForResult(Intent.createChooser(intent, "Select Picture"), ADD_ATTACHMENT);

        break;
      case R.id.remove_attachment:
        this.mFileAttachment = null;
        Toast removeToast =
            Toast.makeText(
                getAwfulActivity(),
                getAwfulActivity().getResources().getText(R.string.file_removed),
                Toast.LENGTH_SHORT);
        removeToast.show();
        invalidateOptionsMenu();
        break;
      case R.id.signature:
        item.setChecked(!item.isChecked());
        postSignature = item.isChecked();
        break;
      case R.id.disableEmots:
        item.setChecked(!item.isChecked());
        disableEmots = item.isChecked();
        break;
      default:
        return super.onOptionsItemSelected(item);
    }

    return true;
  }
  @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;
  }
 int getSelectionStart() {
   EditText text = (EditText) getCurrentView();
   return text.getSelectionStart();
 }
 void insert(String delta) {
   EditText editor = (EditText) getCurrentView();
   int cursor = editor.getSelectionStart();
   editor.getText().insert(cursor, delta);
 }
 @SuppressWarnings("deprecation")
 @Override
 public void onEmotionPicked(String emotion) {
   final int index = bodyText.getSelectionStart();
   String urltemp = emotion.replaceAll("\\n", "");
   if (urltemp.indexOf("http") > 0) {
     urltemp = urltemp.substring(5, urltemp.length() - 6);
     String sourcefile = ExtensionEmotionAdapter.getPathByURI(urltemp);
     InputStream is = null;
     try {
       is = getResources().getAssets().open(sourcefile);
     } catch (IOException e) {
       // TODO Auto-generated catch block
       e.printStackTrace();
     }
     if (is != null) {
       Bitmap bitmap = BitmapFactory.decodeStream(is);
       BitmapDrawable bd = new BitmapDrawable(bitmap);
       Drawable drawable = (Drawable) bd;
       drawable.setBounds(0, 0, drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight());
       SpannableString spanString = new SpannableString(emotion);
       ImageSpan span = new ImageSpan(drawable, ImageSpan.ALIGN_BASELINE);
       spanString.setSpan(span, 0, emotion.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
       if (bodyText.getText().toString().replaceAll("\\n", "").trim().equals("")) {
         bodyText.append(spanString);
       } else {
         if (index <= 0 || index >= bodyText.length()) { // pos @
           // begin /
           // end
           bodyText.append(spanString);
         } else {
           bodyText.getText().insert(index, spanString);
         }
       }
     }
   } else {
     int[] emotions = {
       1, 2, 3, 24, 25, 26, 27, 28, 29, 30, 32, 33, 34, 35, 36, 37, 38, 39, 4, 40, 41, 42, 43, 5,
       6, 7, 8
     };
     for (int i = 0; i < 27; i++) {
       if (emotion.indexOf("[s:" + String.valueOf(emotions[i]) + "]") == 0) {
         String sourcefile = "a" + String.valueOf(emotions[i]) + ".gif";
         InputStream is = null;
         try {
           is = getResources().getAssets().open(sourcefile);
         } catch (IOException e) {
           // TODO Auto-generated catch block
           e.printStackTrace();
         }
         if (is != null) {
           Bitmap bitmap = BitmapFactory.decodeStream(is);
           BitmapDrawable bd = new BitmapDrawable(bitmap);
           Drawable drawable = (Drawable) bd;
           drawable.setBounds(0, 0, drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight());
           SpannableString spanString = new SpannableString(emotion);
           ImageSpan span = new ImageSpan(drawable, ImageSpan.ALIGN_BASELINE);
           spanString.setSpan(span, 0, emotion.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
           if (index <= 0 || index >= bodyText.length()) { // pos @
             // begin
             // / end
             bodyText.append(spanString);
           } else {
             bodyText.getText().insert(index, spanString);
           }
         } else {
           bodyText.append(emotion);
         }
         break;
       }
     }
   }
 } // OK
 @Override
 public void onDetach() {
   super.onDetach();
   mSelection = mMessage.getSelectionStart();
 }
 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;
 }