コード例 #1
0
  private void setTextFieldValues(String jsonString) {

    JSONObject inventory = null;
    String name = "";
    String ram = "";
    String processor = "";
    try {
      inventory = new JSONObject(jsonString);
      name = inventory.getString("name");
      ram = inventory.getString("ram");
      processor = inventory.getString("processor");
    } catch (JSONException e) {
      Log.e(TAG, "Couldn't parse JSON: ", e);
    }

    Editable nameField = mName.getText();
    nameField.clear();
    nameField.append(name);

    Editable ramField = mRAM.getText();
    ramField.clear();
    ramField.append(ram);

    Editable processorField = mProcessor.getText();
    processorField.clear();
    processorField.append(processor);
  }
コード例 #2
0
ファイル: HtmlUtils.java プロジェクト: kapetan/Gitskarios
        public void handleTag(
            final boolean opening,
            final String tag,
            final Editable output,
            final XMLReader xmlReader) {
          if (TAG_DEL.equalsIgnoreCase(tag)) {
            if (opening) startSpan(new StrikethroughSpan(), output);
            else endSpan(StrikethroughSpan.class, output);
            return;
          }

          if (TAG_UL.equalsIgnoreCase(tag) || TAG_OL.equalsIgnoreCase(tag)) {
            if (opening) {
              listElements.add(new ListSeparator(TAG_OL.equalsIgnoreCase(tag)));
            } else if (!listElements.isEmpty()) {
              listElements.removeLast();
            }

            if (!opening && listElements.isEmpty()) output.append('\n');
            return;
          }

          if (TAG_LI.equalsIgnoreCase(tag) && opening && !listElements.isEmpty()) {
            listElements.getLast().append(output, listElements.size());
            return;
          }

          if (TAG_CODE.equalsIgnoreCase(tag)) {
            if (opening) startSpan(new TypefaceSpan("monospace"), output);
            else endSpan(TypefaceSpan.class, output);
          }

          if (TAG_PRE.equalsIgnoreCase(tag)) {
            output.append('\n');
            if (opening) startSpan(new TypefaceSpan("monospace"), output);
            else endSpan(TypefaceSpan.class, output);
          }

          if ((TAG_ROOT.equalsIgnoreCase(tag) || TAG_HTML.equalsIgnoreCase(tag)) && !opening) {
            // Remove leading newlines
            while (output.length() > 0 && output.charAt(0) == '\n') output.delete(0, 1);

            // Remove trailing newlines
            int last = output.length() - 1;
            while (last >= 0 && output.charAt(last) == '\n') {
              output.delete(last, last + 1);
              last = output.length() - 1;
            }

            QuoteSpan[] quoteSpans = output.getSpans(0, output.length(), QuoteSpan.class);
            for (QuoteSpan span : quoteSpans) {
              int start = output.getSpanStart(span);
              int end = output.getSpanEnd(span);
              output.removeSpan(span);
              output.setSpan(new ReplySpan(), start, end, SPAN_EXCLUSIVE_EXCLUSIVE);
            }
          }
        }
コード例 #3
0
ファイル: HtmlUtils.java プロジェクト: kapetan/Gitskarios
 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(' ');
 }
コード例 #4
0
  public void insertMention(int uid) {
    UserVM user = users().get(uid);
    String name = user.getName().get();
    String nick = user.getNick().get();
    Editable text = messageEditText.getText();
    if (text.length() > 0 && text.charAt(text.length() - 1) != ' ') text.append(" ");

    String mentionString = ((nick != null && !nick.isEmpty()) ? "@" + nick : name) + ": ";

    text.append(mentionString);
    messageEditText.requestFocus();
    keyboardUtils.setImeVisibility(messageEditText, true);
  }
コード例 #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));
 }
コード例 #6
0
ファイル: MessageActivity.java プロジェクト: hgl888/TeamTalk
 @Override
 public void onItemClick(int facesPos, int viewIndex) {
   int deleteId = (++viewIndex) * (SysConstant.pageSize - 1);
   if (deleteId > Emoparser.getInstance(MessageActivity.this).getResIdList().length) {
     deleteId = Emoparser.getInstance(MessageActivity.this).getResIdList().length;
   }
   if (deleteId == facesPos) {
     String msgContent = messageEdt.getText().toString();
     if (msgContent.isEmpty()) return;
     if (msgContent.contains("["))
       msgContent = msgContent.substring(0, msgContent.lastIndexOf("["));
     messageEdt.setText(msgContent);
   } else {
     int resId = Emoparser.getInstance(MessageActivity.this).getResIdList()[facesPos];
     String pharse = Emoparser.getInstance(MessageActivity.this).getIdPhraseMap().get(resId);
     int startIndex = messageEdt.getSelectionStart();
     Editable edit = messageEdt.getEditableText();
     if (startIndex < 0 || startIndex >= edit.length()) {
       if (null != pharse) {
         edit.append(pharse);
       }
     } else {
       if (null != pharse) {
         edit.insert(startIndex, pharse);
       }
     }
   }
   Editable edtable = messageEdt.getText();
   int position = edtable.length();
   Selection.setSelection(edtable, position);
 }
    @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);
    }
コード例 #8
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);
 }
コード例 #9
0
ファイル: NFCard.java プロジェクト: wangzhen90/MyApp
 @Override
 public void handleTag(boolean opening, String tag, Editable output, XMLReader xmlReader) {
   if (!opening && "version".equals(tag)) {
     try {
       output.append(getPackageManager().getPackageInfo(getPackageName(), 0).versionName);
     } catch (NameNotFoundException e) {
     }
   }
 }
コード例 #10
0
  /**
   * Parse a NWS date string into a Unix timestamp. Assumes incoming values are in the format
   * "2009-03-23T18:00:00-07:00", which we adjust slightly to correctly follow RFC 3339 before
   * parsing.
   */
  private static long parseDate(String raw) throws TimeFormatException {
    // Inject milliseconds so that NWS dates follow RFC
    sEditable.clear();
    sEditable.append(raw);
    sEditable.insert(19, ".000");

    String rfcFormat = sEditable.toString();
    sTime.parse3339(rfcFormat);
    return sTime.toMillis(false);
  }
コード例 #11
0
  public void appendMemberClip(User user) {
    CharSequence chip = createChip(user, false);
    Editable editable = getText();

    if (chip != null) {
      editable.append(chip);
      ((MemberSearchTextViewAdapter) getAdapter()).addExcludeIdxs(user.idx);
    }

    setSelection(editable.length());
  }
コード例 #12
0
ファイル: MaskedEditText.java プロジェクト: jinkg/MyFavorate
  public String getUnmaskedText() {
    Editable text = super.getText();
    if (mask != null && !mask.isEmpty()) {
      Editable unMaskedText = new SpannableStringBuilder();
      for (Integer index : listValidCursorPositions) {
        if (text != null) {
          unMaskedText.append(text.charAt(index));
        }
      }
      if (format != null && !format.isEmpty()) return formatText(unMaskedText.toString(), format);
      else return unMaskedText.toString().trim();
    }

    return text.toString().trim();
  }
コード例 #13
0
ファイル: Calc.java プロジェクト: Nanocoder15/nav_drawer
  @Override
  public void onClick(View arg0) {
    Editable str = disp.getText();
    switch (arg0.getId()) {
      case R.id.zero:
        if (op2 != 0) {
          op2 = 0;
          disp.setText("");
        }
        str = str.append(zero.getText());
        disp.setText(str);
        break;
      case R.id.one:
        if (op2 != 0) {
          op2 = 0;
          disp.setText("");
        }
        str = str.append(one.getText());
        disp.setText(str);
        break;
      case R.id.two:
        if (op2 != 0) {
          op2 = 0;
          disp.setText("");
        }
        str = str.append(two.getText());
        disp.setText(str);
        break;
      case R.id.three:
        if (op2 != 0) {
          op2 = 0;
          disp.setText("");
        }
        str = str.append(three.getText());
        disp.setText(str);
        break;
      case R.id.four:
        if (op2 != 0) {
          op2 = 0;
          disp.setText("");
        }
        str = str.append(four.getText());
        disp.setText(str);
        break;
      case R.id.five:
        if (op2 != 0) {
          op2 = 0;
          disp.setText("");
        }
        str = str.append(five.getText());
        disp.setText(str);
        break;
      case R.id.six:
        if (op2 != 0) {
          op2 = 0;
          disp.setText("");
        }
        str = str.append(six.getText());
        disp.setText(str);
        break;
      case R.id.seven:
        if (op2 != 0) {
          op2 = 0;
          disp.setText("");
        }
        str = str.append(seven.getText());
        disp.setText(str);
        break;
      case R.id.eight:
        if (op2 != 0) {
          op2 = 0;
          disp.setText("");
        }
        str = str.append(eight.getText());
        disp.setText(str);

        break;
      case R.id.nine:
        if (op2 != 0) {
          op2 = 0;
          disp.setText("");
        }
        str = str.append(nine.getText());
        disp.setText(str);

        break;
      case R.id.Reset:
        op1 = 0;
        op2 = 0;
        disp.setText("");

        break;
      case R.id.add:
        optr = "+";
        if (op1 == 0) {
          op1 = Float.parseFloat(disp.getText().toString());
          disp.setText("");
        } else if (op2 != 0) {
          op2 = 0;
          disp.setText("");
        } else {
          op2 = Float.parseFloat(disp.getText().toString());
          disp.setText("");
          op1 = op1 + op2;
          disp.setText("Result : " + Float.toString(op1));
        }
        break;
      case R.id.sub:
        optr = "-";
        if (op1 == 0) {
          op1 = Float.parseFloat(disp.getText().toString());
          disp.setText("");
        } else if (op2 != 0) {
          op2 = 0;
          disp.setText("");
        } else {
          op2 = Float.parseFloat(disp.getText().toString());
          disp.setText("");
          op1 = op1 - op2;
          disp.setText("Result : " + Float.toString(op1));
        }
        break;
      case R.id.mul:
        optr = "*";
        if (op1 == 0) {
          op1 = Float.parseFloat(disp.getText().toString());
          disp.setText("");
        } else if (op2 != 0) {
          op2 = 0;
          disp.setText("");
        } else {
          op2 = Float.parseFloat(disp.getText().toString());
          disp.setText("");
          op1 = op1 * op2;
          disp.setText("Result : " + Float.toString(op1));
        }
        break;
      case R.id.div:
        optr = "/";
        if (op1 == 0) {
          op1 = Float.parseFloat(disp.getText().toString());
          disp.setText("");
        } else if (op2 != 0) {
          op2 = 0;
          disp.setText("");
        } else {
          op2 = Float.parseFloat(disp.getText().toString());
          disp.setText("");
          op1 = op1 / op2;
          disp.setText("Result : " + Float.toString(op1));
        }
        break;
      case R.id.equal:
        if (!optr.equals(null)) {
          if (op2 != 0) {
            if (optr.equals("+")) {
              disp.setText("");
              /*op1 = op1 + op2;*/
              disp.setText("Result : " + Float.toString(op1));
            } else if (optr.equals("-")) {
              disp.setText(""); /*
							op1 = op1 - op2;*/
              disp.setText("Result : " + Float.toString(op1));
            } else if (optr.equals("*")) {
              disp.setText(""); /*
							op1 = op1 * op2;*/
              disp.setText("Result : " + Float.toString(op1));
            } else if (optr.equals("/")) {
              disp.setText(""); /*
							op1 = op1 / op2;*/
              disp.setText("Result : " + Float.toString(op1));
            }
          } else {
            operation();
          }
        }
        break;
    }
  }