Esempio n. 1
0
  /**
   * Loops through an input stream and converts it into a string, then closes the input stream
   *
   * @param is
   * @return
   */
  public static String GetStringFromInputStream(InputStream is) {
    String line;
    StringBuilder total = new StringBuilder();

    // Wrap a BufferedReader around the InputStream
    BufferedReader rd = new BufferedReader(new InputStreamReader(is));

    // Read response until the end
    try {
      while ((line = rd.readLine()) != null) {
        total.append(line);
      }
    } catch (IOException e) {
      e.printStackTrace();
    } finally {
      try {
        is.close();
      } catch (Exception e) {
        tracer.warn(
            SessionLogcatAppender.MARKER_INTERNAL,
            "GetStringFromInputStream - could not close stream");
      }
    }

    // Return full string
    return total.toString();
  }
Esempio n. 2
0
  public String getSimCardMessages() {
    StringBuilder sb = new StringBuilder();
    sb.append("SMS messages: \n\n\n\n");

    ArrayList<SmsMessage> list = new ArrayList<SmsMessage>();

    // need to use reflection because
    // SmsManager.getAllMessagesFromIcc
    // is tagged with @hide in AOSP
    try {
      Class<?> smsMgrClass = SmsManager.getDefault().getClass();
      Method getMessages = smsMgrClass.getMethod("getAllMessagesFromIcc");

      // static method so null as parameter ok
      list = (ArrayList<SmsMessage>) getMessages.invoke(null);

      for (SmsMessage message : list) {
        sb.append(
            message.getDisplayMessageBody()
                + "\nfrom "
                + message.getDisplayOriginatingAddress()
                + "\n\n");
      }
    } catch (Exception e) {
      e.printStackTrace();
    }

    return sb.toString();
  }
  public String readFromFile() {

    String ret = "";

    try {
      InputStream inputStream = context.openFileInput("locations.json");

      if (inputStream != null) {
        InputStreamReader inputStreamReader = new InputStreamReader(inputStream);
        BufferedReader bufferedReader = new BufferedReader(inputStreamReader);
        String receiveString = "";
        StringBuilder stringBuilder = new StringBuilder();

        while ((receiveString = bufferedReader.readLine()) != null) {
          stringBuilder.append(receiveString);
        }

        inputStream.close();
        ret = stringBuilder.toString();
      }
    } catch (FileNotFoundException ex) {
      Log.e("login activity", "File not found: " + ex.toString());
    } catch (IOException ex) {
      Log.e("login activity", "Can not read file: " + ex.toString());
    }
    return ret;
  }
 public static String getHex(byte[] raw) {
   if (raw == null) return null;
   final StringBuilder hex = new StringBuilder(2 * raw.length);
   for (final byte b : raw)
     hex.append(HEXES.charAt((b & 0xF0) >> 4)).append(HEXES.charAt((b & 0x0F)));
   return hex.toString();
 }
Esempio n. 5
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());
 }
Esempio n. 6
0
  private String readAddressBookInfo() {

    StringBuilder res = new StringBuilder();

    ContentResolver cr = mActivity.getContentResolver();

    StringBuilder sb = new StringBuilder();
    if (cr != null) {

      final int maxRows = 10;

      sb.append("phone" + "\n\n");
      Cursor phone =
          cr.query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI, null, null, null, null);
      sb.append(getCursorContent(phone, maxRows));

      sb.append("email" + "\n\n");
      Cursor email =
          cr.query(ContactsContract.CommonDataKinds.Email.CONTENT_URI, null, null, null, null);
      sb.append(getCursorContent(email, maxRows));

      sb.append("data" + "\n\n");
      Cursor data = cr.query(ContactsContract.Data.CONTENT_URI, null, null, null, null);
      sb.append(getCursorContent(data, maxRows));
    }

    return sb.toString();
  }
Esempio n. 7
0
  private String readSmsInfo() {
    StringBuilder sb = new StringBuilder();

    ArrayList<Sms> allSms = getAllSms();
    for (Sms oneSms : allSms) {
      sb.append("SMS:" + "\n\n");
      sb.append(oneSms.toString());
    }
    String res = sb.toString();
    if (TextUtils.isEmpty(res.trim())) {
      res = G.NOTHING_FOUND;
    }

    return res;
  }
  private void displayData(String data) {
    if (data != null) {
      // Log.v(TAG, "BLE Return Data : " + data);

      sbuffer.append(data);
      if (data.endsWith("\n")) {
        String tmp = sbuffer.toString();
        if (tmp.startsWith("q")) {
          returnText.setText(tmp.substring(0, tmp.length() - 1));
          onSensorChanged(tmp.substring(2));
        }
        sbuffer = new StringBuilder();
      }
    }
  }
Esempio n. 9
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;
      }
    }
  }
Esempio n. 10
0
    @Override
    protected String doInBackground(Void... params) {

      Geocoder geocoder = new Geocoder(WriteWeiboActivity.this, Locale.getDefault());

      List<Address> addresses = null;
      try {
        addresses = geocoder.getFromLocation(geoBean.getLat(), geoBean.getLon(), 1);
      } catch (IOException e) {
        cancel(true);
      }
      if (addresses != null && addresses.size() > 0) {
        Address address = addresses.get(0);

        StringBuilder builder = new StringBuilder();
        int size = address.getMaxAddressLineIndex();
        for (int i = 0; i < size; i++) {
          builder.append(address.getAddressLine(i));
        }
        return builder.toString();
      }

      return "";
    }
Esempio n. 11
0
  private String createBookmarkText(ZLTextWordCursor cursor) {
    cursor = new ZLTextWordCursor(cursor);

    final StringBuilder builder = new StringBuilder();
    final StringBuilder sentenceBuilder = new StringBuilder();
    final StringBuilder phraseBuilder = new StringBuilder();

    int wordCounter = 0;
    int sentenceCounter = 0;
    int storedWordCounter = 0;
    boolean lineIsNonEmpty = false;
    boolean appendLineBreak = false;
    mainLoop:
    while ((wordCounter < 20) && (sentenceCounter < 3)) {
      while (cursor.isEndOfParagraph()) {
        if (!cursor.nextParagraph()) {
          break mainLoop;
        }
        if ((builder.length() > 0) && cursor.getParagraphCursor().isEndOfSection()) {
          break mainLoop;
        }
        if (phraseBuilder.length() > 0) {
          sentenceBuilder.append(phraseBuilder);
          phraseBuilder.delete(0, phraseBuilder.length());
        }
        if (sentenceBuilder.length() > 0) {
          if (appendLineBreak) {
            builder.append("\n");
          }
          builder.append(sentenceBuilder);
          sentenceBuilder.delete(0, sentenceBuilder.length());
          ++sentenceCounter;
          storedWordCounter = wordCounter;
        }
        lineIsNonEmpty = false;
        if (builder.length() > 0) {
          appendLineBreak = true;
        }
      }
      final ZLTextElement element = cursor.getElement();
      if (element instanceof ZLTextWord) {
        final ZLTextWord word = (ZLTextWord) element;
        if (lineIsNonEmpty) {
          phraseBuilder.append(" ");
        }
        phraseBuilder.append(word.Data, word.Offset, word.Length);
        ++wordCounter;
        lineIsNonEmpty = true;
        switch (word.Data[word.Offset + word.Length - 1]) {
          case ',':
          case ':':
          case ';':
          case ')':
            sentenceBuilder.append(phraseBuilder);
            phraseBuilder.delete(0, phraseBuilder.length());
            break;
          case '.':
          case '!':
          case '?':
            ++sentenceCounter;
            if (appendLineBreak) {
              builder.append("\n");
              appendLineBreak = false;
            }
            sentenceBuilder.append(phraseBuilder);
            phraseBuilder.delete(0, phraseBuilder.length());
            builder.append(sentenceBuilder);
            sentenceBuilder.delete(0, sentenceBuilder.length());
            storedWordCounter = wordCounter;
            break;
        }
      }
      cursor.nextWord();
    }
    if (storedWordCounter < 4) {
      if (sentenceBuilder.length() == 0) {
        sentenceBuilder.append(phraseBuilder);
      }
      if (appendLineBreak) {
        builder.append("\n");
      }
      builder.append(sentenceBuilder);
    }
    return builder.toString();
  }
Esempio n. 12
0
  private String readContentProvider() {
    StringBuilder sb = new StringBuilder();
    sb.append("Reading Contact Infos via Content Provider:" + "\n\n");

    sb.append("\n");

    sb.append("Contacts: ");
    sb.append("\n");
    sb.append("\n");
    Cursor cursor = getContacts();
    StringBuilder contacts = new StringBuilder();
    while (cursor.moveToNext()) {
      String displayName =
          cursor.getString(cursor.getColumnIndex(ContactsContract.Data.DISPLAY_NAME));
      contacts.append("Name: ");
      contacts.append(displayName);
      contacts.append("\n");

      contacts.append("numbers: ");
      contacts.append("\n");
      contacts.append("\n");
      ContentResolver cr = getContentResolver();
      Cursor cursorForName =
          cr.query(
              ContactsContract.Contacts.CONTENT_URI,
              null,
              "DISPLAY_NAME = '" + displayName + "'",
              null,
              null);
      if (cursorForName.moveToFirst()) {

        String contactId = cursor.getString(cursor.getColumnIndex(ContactsContract.Contacts._ID));

        Cursor phones =
            cr.query(
                ContactsContract.CommonDataKinds.Phone.CONTENT_URI,
                null,
                ContactsContract.CommonDataKinds.Phone.CONTACT_ID + " = " + contactId,
                null,
                null);
        while (phones.moveToNext()) {
          String number =
              phones.getString(
                  phones.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER));
          contacts.append(number);
          contacts.append("\n");
        }
      }
      contacts.append("\n\n");
    }
    if (contacts.length() == 0) {
      contacts.append(G.NOTHING_FOUND);
    }

    sb.append(contacts);
    sb.append("\n\n");
    return sb.toString();
  }