コード例 #1
0
  /** one CallForwardInfo + serviceClassMask -> one line of text */
  private CharSequence makeCFQueryResultMessage(CallForwardInfo info, int serviceClassMask) {
    CharSequence template;
    String sources[] = {"{0}", "{1}", "{2}"};
    CharSequence destinations[] = new CharSequence[3];
    boolean needTimeTemplate;

    // CF_REASON_NO_REPLY also has a time value associated with
    // it. All others don't.

    needTimeTemplate = (info.reason == CommandsInterface.CF_REASON_NO_REPLY);

    if (info.status == 1) {
      if (needTimeTemplate) {
        template = context.getText(com.android.internal.R.string.cfTemplateForwardedTime);
      } else {
        template = context.getText(com.android.internal.R.string.cfTemplateForwarded);
      }
    } else if (info.status == 0 && isEmptyOrNull(info.number)) {
      template = context.getText(com.android.internal.R.string.cfTemplateNotForwarded);
    } else {
        /* (info.status == 0) && !isEmptyOrNull(info.number) */
      // A call forward record that is not active but contains
      // a phone number is considered "registered"

      if (needTimeTemplate) {
        template = context.getText(com.android.internal.R.string.cfTemplateRegisteredTime);
      } else {
        template = context.getText(com.android.internal.R.string.cfTemplateRegistered);
      }
    }

    // In the template (from strings.xmls)
    //         {0} is one of "bearerServiceCode*"
    //        {1} is dialing number
    //      {2} is time in seconds

    destinations[0] = serviceClassToCFString(info.serviceClass & serviceClassMask);
    destinations[1] = PhoneNumberUtils.stringFromStringAndTOA(info.number, info.toa);
    destinations[2] = Integer.toString(info.timeSeconds);

    if (info.reason == CommandsInterface.CF_REASON_UNCONDITIONAL
        && (info.serviceClass & serviceClassMask) == CommandsInterface.SERVICE_CLASS_VOICE) {
      boolean cffEnabled = (info.status == 1);
      if (phone.mSIMRecords != null) {
        phone.setCallForwardingPreference(cffEnabled);
        phone.mSIMRecords.setVoiceCallForwardingFlag(1, cffEnabled);
      } else {
        Log.w(LOG_TAG, "setVoiceCallForwardingFlag aborted. sim records is null.");
      }
    }

    return TextUtils.replace(template, sources, destinations);
  }
コード例 #2
0
  public static String getSearchQueryFeed(String urlTemplate, String query) {
    final CharSequence feedUrl =
        TextUtils.replace(
            urlTemplate,
            new String[] {
              "{q}",
              "{searchAllVersions}",
              "{maxItems}",
              "{skipCount}",
              "{includeAllowableActions}",
              "{includeRelationships}"
            },
            new String[] {query, "false", "50", "0", "false", "false"});

    return feedUrl.toString();
  }
コード例 #3
0
  private CharSequence formatMessage(
      MessageItem msgItem,
      String contact,
      String body,
      String subject,
      Pattern highlight,
      String contentType) {
    SpannableStringBuilder buf = new SpannableStringBuilder();

    boolean hasSubject = !TextUtils.isEmpty(subject);
    SmileyParser parser = SmileyParser.getInstance();
    if (hasSubject) {
      CharSequence smilizedSubject = parser.addSmileySpans(subject);
      // Can't use the normal getString() with extra arguments for string replacement
      // because it doesn't preserve the SpannableText returned by addSmileySpans.
      // We have to manually replace the %s with our text.
      buf.append(
          TextUtils.replace(
              mContext.getResources().getString(R.string.inline_subject),
              new String[] {"%s"},
              new CharSequence[] {smilizedSubject}));
    }

    if (!TextUtils.isEmpty(body)) {
      // Converts html to spannable if ContentType is "text/html".
      if (contentType != null && ContentType.TEXT_HTML.equals(contentType)) {
        buf.append("\n");
        buf.append(Html.fromHtml(body));
      } else {
        if (hasSubject) {
          buf.append(" - ");
        }
        buf.append(parser.addSmileySpans(body));
      }
    }

    if (highlight != null) {
      Matcher m = highlight.matcher(buf.toString());
      while (m.find()) {
        buf.setSpan(new StyleSpan(Typeface.BOLD), m.start(), m.end(), 0);
      }
    }
    return buf;
  }
コード例 #4
0
  public static String getSearchQueryFeedCmisQuery(String urlTemplate, String cmisQuery) {
    String encodedCmisQuery = "";
    try {
      encodedCmisQuery = URLEncoder.encode(cmisQuery, "iso-8859-1");
    } catch (UnsupportedEncodingException e) {
      encodedCmisQuery = URLEncoder.encode(cmisQuery);
    }

    final CharSequence feedUrl =
        TextUtils.replace(
            urlTemplate,
            new String[] {
              "{q}",
              "{searchAllVersions}",
              "{maxItems}",
              "{skipCount}",
              "{includeAllowableActions}",
              "{includeRelationships}"
            },
            new String[] {encodedCmisQuery, "false", "50", "0", "false", "false"});

    return feedUrl.toString();
  }