Exemple #1
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();
  }
  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();
  }