Example #1
0
 private boolean checkForm() {
   boolean bolAlertPop = false;
   boolean bolCheckResult = true;
   Editable editableMobile = this.inputMobile.getText();
   if (!editableMobile.toString().matches(".{11,11}")) {
     bolAlertPop = true;
     bolCheckResult = false;
     this.inputMobile.requestFocus();
     Utils.Dialog(
         this,
         getString(R.string.dialog_form_check_title),
         getString(R.string.dialog_form_check_err_mobile));
   }
   Editable editablePassword = this.inputPassword.getText();
   if (!bolAlertPop && !editablePassword.toString().matches(".{6,50}")) {
     bolAlertPop = true;
     bolCheckResult = false;
     this.inputPassword.requestFocus();
     Utils.Dialog(
         this,
         getString(R.string.dialog_form_check_title),
         getString(R.string.dialog_form_check_err_password));
   }
   return bolCheckResult;
 }
Example #2
0
 public void afterTextChanged(Editable paramEditable) {
   if (TextUtils.isEmpty(paramEditable.toString())) {}
   for (int i = 0; ; i = (int) Double.parseDouble(paramEditable.toString()) * 1000) {
     AutoForwardActivity.c(this.a).b(this.a.j() + "_autoforward_delay", i);
     return;
   }
 }
  private void submitItemAtPosition(int position) {
    User user = (User) getAdapter().getItem(position);

    if (user == null) {
      return;
    }

    clearComposingText();

    int end = getSelectionEnd();
    int start = mTokenizer.findTokenStart(getText(), end);

    Editable editable = getText();
    QwertyKeyListener.markAsReplaced(editable, start, end, "");
    CharSequence chip = createChip(user, false);

    if (chip != null && start >= 0 && end >= 0) {
      // TODO chip 사이에 새 칩을 넣을 때tokenizer가
      // start를 end와 같은 위치로 잡음. 그래서 일단 start를 강제로 조절해놓음
      start = end - chip.length();
      editable.replace(start, end, chip);
      ((MemberSearchTextViewAdapter) getAdapter()).addExcludeIdxs(user.idx);
    }

    sanitizeBetween();
  }
  @Override
  public ExtractedText getExtractedText(ExtractedTextRequest req, int flags) {
    if (req == null) return null;

    final Editable content = getEditable();
    if (content == null) return null;

    if ((flags & GET_EXTRACTED_TEXT_MONITOR) != 0) mUpdateRequest = req;

    ExtractedText extract = new ExtractedText();
    extract.flags = 0;
    extract.partialStartOffset = -1;
    extract.partialEndOffset = -1;

    clampSelection();
    extract.selectionStart = Selection.getSelectionStart(content);
    extract.selectionEnd = Selection.getSelectionEnd(content);
    extract.startOffset = 0;

    try {
      extract.text = content.toString();
    } catch (IndexOutOfBoundsException iob) {
      Log.d(
          LOGTAG,
          "IndexOutOfBoundsException thrown from getExtractedText(). start: "
              + Selection.getSelectionStart(content)
              + " end: "
              + Selection.getSelectionEnd(content));
      return null;
    }
    return extract;
  }
 @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));
   }
 }
  @Override
  public ExtractedText getExtractedText(ExtractedTextRequest req, int flags) {
    if (req == null) return null;

    if ((flags & GET_EXTRACTED_TEXT_MONITOR) != 0) mUpdateRequest = req;

    Editable editable = getEditable();
    if (editable == null) {
      return null;
    }
    int selStart = Selection.getSelectionStart(editable);
    int selEnd = Selection.getSelectionEnd(editable);

    ExtractedText extract = new ExtractedText();
    extract.flags = 0;
    extract.partialStartOffset = -1;
    extract.partialEndOffset = -1;
    extract.selectionStart = selStart;
    extract.selectionEnd = selEnd;
    extract.startOffset = 0;
    if ((req.flags & GET_TEXT_WITH_STYLES) != 0) {
      extract.text = new SpannableString(editable);
    } else {
      extract.text = editable.toString();
    }
    return extract;
  }
  /** @see BaseInputConnection#setComposingRegion(int, int) */
  @Override
  public boolean setComposingRegion(int start, int end) {
    if (DEBUG) Log.w(TAG, "setComposingRegion [" + start + " " + end + "]");
    int textLength = mEditable.length();
    int a = Math.min(start, end);
    int b = Math.max(start, end);
    if (a < 0) a = 0;
    if (b < 0) b = 0;
    if (a > textLength) a = textLength;
    if (b > textLength) b = textLength;

    CharSequence regionText = null;
    if (a == b) {
      removeComposingSpans(mEditable);
    } else {
      if (a == 0 && b == mEditable.length()) {
        regionText = mEditable.subSequence(a, b);
        // If setting composing region that matches, at least in length, of the entire
        // editable region then check it for image placeholders.  If any are found,
        // don't continue this operation.
        // This fixes the problem where, on Android 4.3, pasting an image is followed
        // by setting the composing region which then causes the image to be deleted.
        // http://crbug.com/466755
        for (int i = a; i < b; ++i) {
          if (regionText.charAt(i) == '\uFFFC') return true;
        }
      }
      super.setComposingRegion(a, b);
    }
    updateSelectionIfRequired();

    return mImeAdapter.setComposingRegion(regionText, a, b);
  }
  @Override
  public void afterTextChanged(Editable s) {
    String mask = mMask;
    String value = s.toString();
    if (value.equals(mResult)) return;
    try {
        /* prepare the formatter*/
      MaskedFormatter formatter = new MaskedFormatter(mask);
      formatter.setValueContainsLiteralCharacters(false);
      formatter.setPlaceholderCharacter(
          (char) 1); /* get a string with applied mask and placeholder chars*/
      value = formatter.valueToString(value);
      try {
          /* find first placeholder*/
        value = value.substring(0, value.indexOf((char) 1)); /*process a mask char*/
        if (value.charAt(value.length() - 1) == mask.charAt(value.length() - 1))
          value = value.substring(0, value.length() - 1);

      } catch (Exception e) {
      }

      mResult = value;

      s.replace(0, s.length(), value);

    } catch (ParseException e) {

      // the entered value does not match a mask
      int offset = e.getErrorOffset();
      value = removeCharAt(value, offset);
      s.replace(0, s.length(), value);
    }
  }
Example #9
0
 private static void endSpan(Class<?> type, Editable output) {
   int length = output.length();
   Object span = getLast(output, type);
   int start = output.getSpanStart(span);
   output.removeSpan(span);
   if (start != length) output.setSpan(span, start, length, SPAN_EXCLUSIVE_EXCLUSIVE);
 }
    @Override
    public void afterTextChanged(Editable s) {

      boolean updated = false;
      int value;
      try {
        value = Integer.parseInt(s.toString());
      } catch (NumberFormatException e) {
        value = mDefault;
      }

      if (value < mMin) {
        value = mMin;
        updated = true;
      } else if (value > mMax) {
        updated = true;
        value = mMax;
      }

      // Update UI
      if (updated) {
        s.clear();
        s.append(Integer.toString(value));
      }

      updateDoneButtonState();
      onChange(value);
    }
Example #11
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));
 }
    public void onClick() {
      Editable text = getText();
      if (text == null) return;

      switch (tokenClickStyle) {
        case Select:
        case SelectDeselect:
          if (!view.isSelected()) {
            clearSelections();
            view.setSelected(true);
            break;
          }

          if (tokenClickStyle == TokenClickStyle.SelectDeselect) {
            view.setSelected(false);
            invalidate();
            break;
          }

          // If the view is already selected, we want to delete it
        case Delete:
          removeSpan(this);
          break;
        case None:
        default:
          if (getSelectionStart() != text.getSpanEnd(this) + 1) {
            // Make sure the selection is not in the middle of the span
            setSelection(text.getSpanEnd(this) + 1);
          }
      }
    }
  @Override
  protected void replaceText(CharSequence text) {
    clearComposingText();
    SpannableStringBuilder ssb = buildSpannableForText(text);
    TokenImageSpan tokenSpan = buildSpanForObject(selectedObject);

    Editable editable = getText();
    int end = getSelectionEnd();
    int start = tokenizer.findTokenStart(editable, end);
    if (start < prefix.length()) {
      start = prefix.length();
    }
    String original = TextUtils.substring(editable, start, end);

    if (editable != null) {
      if (tokenSpan == null) {
        editable.replace(start, end, " ");
      } else if (!allowDuplicates && objects.contains(tokenSpan.getToken())) {
        editable.replace(start, end, " ");
      } else {
        QwertyKeyListener.markAsReplaced(editable, start, end, original);
        editable.replace(start, end, ssb);
        editable.setSpan(
            tokenSpan, start, start + ssb.length() - 1, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
      }
    }
  }
    @Override
    public void onTextChanged(CharSequence s, int start, int before, int count) {
      Editable text = getText();
      if (text == null) return;

      clearSelections();
      updateHint();

      TokenImageSpan[] spans =
          text.getSpans(start - before, start - before + count, TokenImageSpan.class);

      for (TokenImageSpan token : spans) {

        int position = start + count;
        if (text.getSpanStart(token) < position && position <= text.getSpanEnd(token)) {
          // We may have to manually reverse the auto-complete and remove the extra ,'s
          int spanStart = text.getSpanStart(token);
          int spanEnd = text.getSpanEnd(token);

          removeToken(token, text);

          // The end of the span is the character index after it
          spanEnd--;

          if (spanEnd >= 0 && text.charAt(spanEnd) == ',') {
            text.delete(spanEnd, spanEnd + 1);
          }

          if (spanStart >= 0 && text.charAt(spanStart) == ',') {
            text.delete(spanStart, spanStart + 1);
          }
        }
      }
    }
 private void sanitizeBetween() {
   // Find the last chip.
   MemberChip[] recips = getSortedRecipients();
   if (recips != null && recips.length > 0) {
     MemberChip last = recips[recips.length - 1];
     MemberChip beforeLast = null;
     if (recips.length > 1) {
       beforeLast = recips[recips.length - 2];
     }
     int startLooking = 0;
     int end = getSpannable().getSpanStart(last);
     if (beforeLast != null) {
       startLooking = getSpannable().getSpanEnd(beforeLast);
       Editable text = getText();
       if (startLooking == -1 || startLooking > text.length() - 1) {
         // There is nothing after this chip.
         return;
       }
       if (text.charAt(startLooking) == ' ') {
         startLooking++;
       }
     }
     if (startLooking >= 0 && end >= 0 && startLooking < end) {
       getText().delete(startLooking, end);
     }
   }
 }
 /**
  * 光标移动到最后
  *
  * @param editText
  */
 private void moveCursor(EditText editText) {
   Editable etext = editText.getText();
   if (etext.length() < 1) {
   } else {
     Selection.setSelection(etext, etext.length());
   }
 }
  @Override
  public void onClick(DialogInterface dialog, int which) {
    switch (which) {
      case DialogInterface.BUTTON_POSITIVE:
        Editable text = mPunctuationCharacters.getText();
        String characters = null;
        int level;
        if (text != null) {
          characters = text.toString();
        }

        if (mNone.isChecked()) {
          level = SpeechSynthesis.PUNCT_NONE;
        } else if (characters == null || characters.isEmpty()) {
          level = mAll.isChecked() ? SpeechSynthesis.PUNCT_ALL : SpeechSynthesis.PUNCT_NONE;
        } else {
          level = mAll.isChecked() ? SpeechSynthesis.PUNCT_ALL : SpeechSynthesis.PUNCT_SOME;
        }

        onDataChanged(level, characters);

        if (shouldCommit()) {
          SharedPreferences.Editor editor = getEditor();
          if (editor != null) {
            editor.putString(VoiceSettings.PREF_PUNCTUATION_CHARACTERS, characters);
            editor.putString(VoiceSettings.PREF_PUNCTUATION_LEVEL, Integer.toString(level));
            editor.commit();
          }
        }
        break;
    }
    super.onClick(dialog, which);
  }
Example #18
0
  @Override
  public void onClick(View v) {
    /*  botones de centreo */
    if (v.getId() == R.id.btn_adelante) {
      try {
        connectionFuture.get().write(("a").getBytes());
        displayedTextBox.setText("adelante");
      } catch (IOException e) {
        debug("Write failed.");
      }
    }

    if (v.getId() == R.id.btn_atras) {
      try {
        connectionFuture.get().write(("b").getBytes());
        displayedTextBox.setText("atras");
      } catch (IOException e) {
        debug("Write failed.");
      }
    }
    if (v.getId() == R.id.btn_izquiera) {
      try {
        connectionFuture.get().write(("c").getBytes());
        displayedTextBox.setText("izquierda");
      } catch (IOException e) {
        debug("Write failed.");
      }
    }
    if (v.getId() == R.id.btn_derecha) {
      try {
        connectionFuture.get().write(("d").getBytes());
        displayedTextBox.setText("derecha");
      } catch (IOException e) {
        debug("Write failed.");
      }
    }
    if (v.getId() == R.id.btn_stop) {
      try {
        connectionFuture.get().write(("e").getBytes());
        displayedTextBox.setText("stop");
      } catch (IOException e) {
        debug("Write failed.");
      }
    }
    if (v.getId() == R.id.button_transmit) {
      synchronized (transmitTextBox) {
        Editable transmitText = transmitTextBox.getText();
        String text = transmitText.toString();
        transmitText.clear();
        try {
          // Disable and block until this is ready
          connectionFuture.get().write(text.getBytes());
          displayedTextBox.setText("CMD : " + text);
          debug("Wrote message: " + text);
        } catch (IOException e) {
          debug("Write failed.");
        }
      }
    }
  }
Example #19
0
 @Override
 public void afterTextChanged(Editable edt) {
   if (filterFlag > 0) {
     try {
       String temp = edt.toString();
       String tem = temp.substring(temp.length() - 1, temp.length());
       char[] temC = tem.toCharArray();
       int mid = temC[0];
       if (filterFlag == 1 || filterFlag == 2) {
         if (mid >= 48 && mid <= 57) { // 数字
           return;
         }
         if (mid >= 65 && mid <= 90) { // 大写字母 和@
           return;
         }
         if (mid >= 97 && mid <= 122) { // 小写字母
           return;
         }
         if (mid == 46) { // .
           return;
         }
         if (mid == 64) { // @
           return;
         }
       } else {
         if (mid >= 33 && mid <= 126) {
           return;
         }
       }
       edt.delete(temp.length() - 1, temp.length());
     } catch (Exception e) {
     }
   }
 }
  @TestTargetNew(
      level = TestLevel.COMPLETE,
      method = "onKeyUp",
      args = {
        android.view.View.class,
        android.text.Editable.class,
        int.class,
        android.view.KeyEvent.class
      })
  public void testReleaseKey() {
    final CharSequence str = "123456";
    final MetaKeyKeyListener numberKeyListener = new DateKeyListener();
    final View view = new ImageView(getContext());
    final Editable content = Editable.Factory.getInstance().newEditable(str);

    content.setSpan(Selection.SELECTION_START, 0, 0, Spanned.SPAN_POINT_POINT);
    content.setSpan(Selection.SELECTION_END, 0, 0, Spanned.SPAN_POINT_POINT);
    numberKeyListener.onKeyUp(
        view, content, KeyEvent.KEYCODE_0, new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_0));
    assertEquals(str.charAt(0), content.charAt(0));

    content.setSpan(Selection.SELECTION_START, 1, 1, Spanned.SPAN_POINT_POINT);
    content.setSpan(Selection.SELECTION_END, 1, 1, Spanned.SPAN_POINT_POINT);
    numberKeyListener.onKeyUp(
        view, content, KeyEvent.KEYCODE_2, new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_2));
    assertEquals(str.charAt(1), content.charAt(1));

    content.setSpan(Selection.SELECTION_START, 3, 3, Spanned.SPAN_POINT_POINT);
    content.setSpan(Selection.SELECTION_END, 3, 3, Spanned.SPAN_POINT_POINT);
    numberKeyListener.onKeyUp(
        view, content, KeyEvent.KEYCODE_3, new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_3));
    assertEquals(str.charAt(3), content.charAt(3));
  }
Example #21
0
  @Override
  public void onClick(@NonNull final View widget) {
    if (!(widget instanceof MentionsEditText)) {
      return;
    }

    // Get reference to the MentionsEditText
    MentionsEditText editText = (MentionsEditText) widget;
    Editable text = editText.getText();

    if (text == null) {
      return;
    }

    // Set cursor behind span in EditText
    int newCursorPos = text.getSpanEnd(this);
    editText.setSelection(newCursorPos);

    // If we are going to select this span, deselect all others
    boolean isSelected = isSelected();
    if (!isSelected) {
      editText.deselectAllSpans();
    }

    // Toggle whether the view is selected
    setSelected(!isSelected());

    // Update the span (forces it to redraw)
    editText.updateSpan(this);
  }
Example #22
0
 /** 登录联网操作 */
 private void beginLogin() {
   // showDialog(DIALOG_PROGRESS);
   EditText password_edit = (EditText) findViewById(R.id.password_edit);
   Editable password = password_edit.getText();
   final String password_string = String.valueOf(password);
   if (remPwd_checkBox.isChecked()) shellRW.putStringValue("password", password_string);
   // 判断手机号长度是否正确
   EditText phone_name_Text = (EditText) findViewById(R.id.phoneNum_edit);
   Editable editText = phone_name_Text.getText();
   // fqc edit 7/3/2010 判断密码长度 必须在6~16之间
   EditText password_text = (EditText) findViewById(R.id.password_edit);
   int passwordLength = password_text.getText().toString().length();
   if (editText.toString().equals("")) {
     Toast.makeText(this, "用户名不能为空!", Toast.LENGTH_LONG).show();
   } else if (passwordLength < 6 || passwordLength > 16) {
     password_edit.startAnimation(shake);
     Toast.makeText(this, "密码必须为6~16位!", Toast.LENGTH_LONG).show();
   } else { //
     //			if(auto_login_checkBox.isChecked()){
     //				isAutoLogin = "******";
     //			}else{
     //				isAutoLogin = "******";
     //			}
     regToLogin(String.valueOf(phoneNum_edit.getText()), password_string, isAutoLogin);
   }
 }
Example #23
0
 /**
  * Add a chip to this view
  *
  * @param chip The chip to add
  */
 public void addChip(Chip chip) {
   Editable text = getText();
   Spannable span = getChipSpan(chip);
   text.append(span);
   setText(text);
   setSelection(text.length());
   onChipAdded(chip);
 }
Example #24
0
 public static char[] getPassword(Editable s) {
   int length = s.length();
   char[] password = new char[length];
   for (int i = 0; i < length; i++) {
     password[i] = s.charAt(i);
   }
   return password;
 }
 public static void insertSeparators(Editable s) {
   final int[] positions = {4, 9, 14};
   for (int i : positions) {
     if (s.length() > i) {
       s.insert(i, SEPARATOR);
     }
   }
 }
 private void cutContent() {
   final Editable text = getText();
   int textLength = text.length();
   setSelection(0, textLength);
   setPrimaryClip(ClipData.newPlainText(null, text));
   ((Editable) getText()).delete(0, textLength);
   setSelection(0);
 }
  /**
   * In HTML mode, applies formatting to selected text, or inserts formatting tag at current cursor
   * position
   *
   * @param toggleButton format bar button which was clicked
   * @param tag identifier tag
   */
  private void applyFormattingHtmlMode(ToggleButton toggleButton, String tag) {
    if (mSourceViewContent == null) {
      return;
    }

    // Replace style tags with their proper HTML tags
    String htmlTag;
    if (tag.equals(getString(R.string.format_bar_tag_bold))) {
      htmlTag = "b";
    } else if (tag.equals(getString(R.string.format_bar_tag_italic))) {
      htmlTag = "i";
    } else if (tag.equals(getString(R.string.format_bar_tag_strikethrough))) {
      htmlTag = "del";
    } else if (tag.equals(getString(R.string.format_bar_tag_unorderedList))) {
      htmlTag = "ul";
    } else if (tag.equals(getString(R.string.format_bar_tag_orderedList))) {
      htmlTag = "ol";
    } else {
      htmlTag = tag;
    }

    int selectionStart = mSourceViewContent.getSelectionStart();
    int selectionEnd = mSourceViewContent.getSelectionEnd();

    if (selectionStart > selectionEnd) {
      int temp = selectionEnd;
      selectionEnd = selectionStart;
      selectionStart = temp;
    }

    boolean textIsSelected = selectionEnd > selectionStart;

    String startTag = "<" + htmlTag + ">";
    String endTag = "</" + htmlTag + ">";

    // Add li tags together with ul and ol tags
    if (htmlTag.equals("ul") || htmlTag.equals("ol")) {
      startTag = startTag + "\n\t<li>";
      endTag = "</li>\n" + endTag;
    }

    Editable content = mSourceViewContent.getText();
    if (textIsSelected) {
      // Surround selected text with opening and closing tags
      content.insert(selectionStart, startTag);
      content.insert(selectionEnd + startTag.length(), endTag);
      toggleButton.setChecked(false);
      mSourceViewContent.setSelection(selectionEnd + startTag.length() + endTag.length());
    } else if (toggleButton.isChecked()) {
      // Insert opening tag
      content.insert(selectionStart, startTag);
      mSourceViewContent.setSelection(selectionEnd + startTag.length());
    } else {
      // Insert closing tag
      content.insert(selectionEnd, endTag);
      mSourceViewContent.setSelection(selectionEnd + endTag.length());
    }
  }
  private void press(Editable content, Object what) {
    int state = content.getSpanFlags(what);

    if (state == PRESSED) ; // repeat before use
    else if (state == RELEASED) content.setSpan(what, 0, 0, LOCKED);
    else if (state == USED) ; // repeat after use
    else if (state == LOCKED) content.removeSpan(what);
    else content.setSpan(what, 0, 0, PRESSED);
  }
 @Override
 public void afterTextChanged(Editable editable) {
   if (onResponseChangedListener != null
       && (lastString != null && lastString.length() > 0)) {
     String response = editable.length() > 0 ? editable.toString() : null;
     onResponseChangedListener.onResponseChanged(rule, response);
   }
   lastString = editable.toString();
 }
Example #30
0
 public void append(Editable output, int indentLevel) {
   output.append('\n');
   for (int i = 0; i < indentLevel * 2; i++) output.append(' ');
   if (count != -1) {
     output.append(Integer.toString(count)).append('.');
     count++;
   } else output.append('\u2022');
   output.append(' ').append(' ');
 }