Example usage for android.text.style TextAppearanceSpan TextAppearanceSpan

List of usage examples for android.text.style TextAppearanceSpan TextAppearanceSpan

Introduction

In this page you can find the example usage for android.text.style TextAppearanceSpan TextAppearanceSpan.

Prototype

public TextAppearanceSpan(Context context, int appearance) 

Source Link

Document

Uses the specified TextAppearance resource to determine the text appearance.

Usage

From source file:io.plaidapp.designernews.ui.story.StoryActivity.java

private CharSequence getStoryPosterTimeText(String userDisplayName, String userJob, Date createdAt) {
    SpannableString poster = new SpannableString(userDisplayName.toLowerCase());
    poster.setSpan(new TextAppearanceSpan(this, io.plaidapp.R.style.TextAppearance_CommentAuthor), 0,
            poster.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
    CharSequence job = !TextUtils.isEmpty(userJob) ? "\n" + userJob.toLowerCase() : "";
    CharSequence timeAgo = DateUtils.getRelativeTimeSpanString(createdAt.getTime(), System.currentTimeMillis(),
            DateUtils.SECOND_IN_MILLIS).toString().toLowerCase();

    return TextUtils.concat(poster, job, "\n", timeAgo);
}

From source file:com.waz.zclient.controllers.notifications.NotificationsController.java

@TargetApi(21)
private SpannableString getMessageSpannable(String header, String body) {
    SpannableString messageSpannable = new SpannableString(header + body);
    final int textAppearance;
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        textAppearance = android.R.style.TextAppearance_Material_Notification_Title;
    } else {/* w ww. ja v  a 2s  .c o  m*/
        textAppearance = android.R.style.TextAppearance_StatusBar_EventContent_Title;
    }
    final TextAppearanceSpan textAppearanceSpan = new TextAppearanceSpan(context, textAppearance);
    messageSpannable.setSpan(new ForegroundColorSpan(textAppearanceSpan.getTextColor().getDefaultColor()), 0,
            header.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
    return messageSpannable;
}

From source file:com.mattprecious.notisync.service.SecondaryService.java

/**
 * Taken and modified from AOSP MMS app.
 * src/com/android/mms/transaction/MessagingNotification.java
 *//*from  ww  w  .  j a  va2 s.c  o  m*/
private Notification buildRichNotification(NotificationCompat.Builder builder,
        List<List<NotificationData>> threadList, Bitmap photoIfSingleThread) {
    if (threadList.size() == 0) {
        return builder.build();
    }

    final TextAppearanceSpan primarySpan = new TextAppearanceSpan(this, R.style.NotificationPrimaryText);
    final TextAppearanceSpan secondarySpan = new TextAppearanceSpan(this, R.style.NotificationSecondaryText);

    // only one thread
    if (threadList.size() == 1) {
        List<NotificationData> thread = threadList.get(0);

        NotificationData lastData = thread.get(thread.size() - 1);
        builder.setContentTitle(lastData.sender);

        if (photoIfSingleThread != null) {
            builder.setLargeIcon(resizePhoto(photoIfSingleThread));
        }

        // only one message, display the whole thing
        if (thread.size() == 1) {
            String message = dedupeNewlines(lastData.message);

            builder.setContentText(message);

            return new NotificationCompat.BigTextStyle(builder).bigText(message)
                    // Forcibly show the last line, with the smallIcon in
                    // it, if we kicked the smallIcon out with a photo
                    // bitmap
                    .setSummaryText((photoIfSingleThread == null) ? null : " ").build();
        } else {
            // multiple messages for the same thread
            SpannableStringBuilder buf = new SpannableStringBuilder();

            boolean first = true;
            for (NotificationData data : thread) {
                // remove extra newlines
                String message = dedupeNewlines(data.message);

                if (first) {
                    first = false;
                } else {
                    buf.append('\n');
                }

                buf.append(message);
            }

            builder.setContentTitle(getString(R.string.noti_title_new_messages, thread.size()));

            return new NotificationCompat.BigTextStyle(builder).bigText(buf)
                    // Forcibly show the last line, with the smallIcon in
                    // it, if we kicked the smallIcon out with a photo
                    // bitmap
                    .setSummaryText((photoIfSingleThread == null) ? null : " ").build();
        }
    } else {
        // multiple threads

        String separator = ", ";
        SpannableStringBuilder contentStringBuilder = new SpannableStringBuilder();

        boolean first = true;
        int totalMessageCount = 0;
        for (List<NotificationData> thread : threadList) {
            totalMessageCount += thread.size();

            if (first) {
                first = false;
            } else {
                contentStringBuilder.append(separator);
            }

            NotificationData lastData = thread.get(thread.size() - 1);
            contentStringBuilder.append(lastData.sender);

        }

        builder.setContentTitle(getString(R.string.noti_title_new_messages, totalMessageCount));
        builder.setContentText(contentStringBuilder);

        NotificationCompat.InboxStyle inboxStyle = new NotificationCompat.InboxStyle(builder);

        // We have to set the summary text to non-empty so the content text
        // doesn't show up when expanded.
        inboxStyle.setSummaryText(" ");

        int c = 0;
        for (List<NotificationData> dataList : threadList) {
            if (c == 8)
                break;

            NotificationData lastData = dataList.get(dataList.size() - 1);

            SpannableStringBuilder inboxStringBuilder = new SpannableStringBuilder();

            int senderLength = lastData.sender.length();
            inboxStringBuilder.append(lastData.sender).append(": ");
            inboxStringBuilder.setSpan(primarySpan, 0, senderLength, 0);

            inboxStringBuilder.append(dedupeNewlines(lastData.message));
            inboxStringBuilder.setSpan(secondarySpan, senderLength, senderLength + lastData.sender.length(), 0);

            inboxStyle.addLine(inboxStringBuilder);
        }

        return inboxStyle.build();
    }
}

From source file:com.heath_bar.tvdb.SeriesOverview.java

/** Update the GUI with the specified rating */
private void setUserRatingTextView(int rating) {

    try {/*from   w w w. j  a va2s.c om*/
        TextView ratingTextView = (TextView) findViewById(R.id.rating);
        String communityRating = (seriesInfo == null) ? "?" : seriesInfo.getRating();
        String communityRatingText = communityRating + " / 10";

        String ratingTextA = communityRatingText + "  (";
        String ratingTextB = (rating == 0) ? "rate" : String.valueOf(rating);
        String ratingTextC = ")";

        int start = ratingTextA.length();
        int end = ratingTextA.length() + ratingTextB.length();

        SpannableStringBuilder ssb = new SpannableStringBuilder(ratingTextA + ratingTextB + ratingTextC);

        ssb.setSpan(new NonUnderlinedClickableSpan() {
            @Override
            public void onClick(View v) {
                showRatingDialog();
            }
        }, start, end, 0);

        ssb.setSpan(new TextAppearanceSpan(getApplicationContext(), R.style.episode_link), start, end, 0); // Set the style of the text
        ratingTextView.setText(ssb, BufferType.SPANNABLE);
        ratingTextView.setMovementMethod(LinkMovementMethod.getInstance());
    } catch (Exception e) {
        Log.e("SeriesOverview", "Failed to setUserRatingTextView: " + e.getMessage());
    }
}

From source file:com.android.tv.dvr.ui.DvrUiHelper.java

@NonNull
public static CharSequence getStyledTitleWithEpisodeNumber(Context context, String title, String seasonNumber,
        String episodeNumber, int episodeNumberStyleResId) {
    if (TextUtils.isEmpty(title)) {
        return "";
    }/*from  w w w .j a  v  a  2s.  co m*/
    SpannableStringBuilder builder;
    if (TextUtils.isEmpty(seasonNumber) || seasonNumber.equals("0")) {
        builder = TextUtils.isEmpty(episodeNumber) ? new SpannableStringBuilder(title)
                : new SpannableStringBuilder(Html.fromHtml(context.getString(
                        R.string.program_title_with_episode_number_no_season, title, episodeNumber)));
    } else {
        builder = new SpannableStringBuilder(Html.fromHtml(context
                .getString(R.string.program_title_with_episode_number, title, seasonNumber, episodeNumber)));
    }
    Object[] spans = builder.getSpans(0, builder.length(), Object.class);
    if (spans.length > 0) {
        if (episodeNumberStyleResId != 0) {
            builder.setSpan(new TextAppearanceSpan(context, episodeNumberStyleResId),
                    builder.getSpanStart(spans[0]), builder.getSpanEnd(spans[0]),
                    Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
        }
        builder.removeSpan(spans[0]);
    }
    return new SpannableString(builder);
}

From source file:com.tct.mail.browse.ConversationItemView.java

private static synchronized void getItemViewResources(Context context) {
    if (sConfigurationChangedReceiver == null) {
        sConfigurationChangedReceiver = new BroadcastReceiver() {
            @Override/*from   w ww .j a va2s .c  om*/
            public void onReceive(Context context, Intent intent) {
                STAR_OFF = null;
                //[BUGFIX]-Mod-BEGIN by TCTNB.caixia.chen,01/07/2015,PR 893304
                getItemViewResources(context.getApplicationContext());
                //[BUGFIX]-Mod-END by TCTNB.caixia.chen
            }
        };
        context.registerReceiver(sConfigurationChangedReceiver,
                new IntentFilter(Intent.ACTION_CONFIGURATION_CHANGED));
    }
    if (STAR_OFF == null) {
        final Resources res = context.getResources();
        // Initialize static bitmaps.
        //TS: junwei-xu 2015-09-02 EMAIL BUGFIX-546917 MOD-S
        // star off will not show in list item.
        //STAR_OFF = BitmapFactory.decodeResource(res, R.drawable.ic_star_outline_20dp);
        STAR_OFF = BitmapFactory.decodeResource(res, R.drawable.ic_importance_normal);
        //TS: junwei-xu 2015-09-02 EMAIL BUGFIX-546917 MOD-S
        STAR_ON = BitmapFactory.decodeResource(res, R.drawable.ic_star_20dp);
        ATTACHMENT = BitmapFactory.decodeResource(res, R.drawable.ic_attach_file_20dp);
        ONLY_TO_ME = BitmapFactory.decodeResource(res, R.drawable.ic_email_caret_double);
        TO_ME_AND_OTHERS = BitmapFactory.decodeResource(res, R.drawable.ic_email_caret_single);
        IMPORTANT_ONLY_TO_ME = BitmapFactory.decodeResource(res,
                R.drawable.ic_email_caret_double_important_unread);
        IMPORTANT_TO_ME_AND_OTHERS = BitmapFactory.decodeResource(res,
                R.drawable.ic_email_caret_single_important_unread);
        IMPORTANT = BitmapFactory.decodeResource(res, R.drawable.ic_email_caret_none_important_unread);
        STATE_REPLIED = BitmapFactory.decodeResource(res, R.drawable.ic_badge_reply_holo_light);
        STATE_FORWARDED = BitmapFactory.decodeResource(res, R.drawable.ic_badge_forward_holo_light);
        STATE_REPLIED_AND_FORWARDED = BitmapFactory.decodeResource(res,
                R.drawable.ic_badge_reply_forward_holo_light);
        STATE_CALENDAR_INVITE = BitmapFactory.decodeResource(res, R.drawable.ic_badge_invite_holo_light);
        VISIBLE_CONVERSATION_HIGHLIGHT = res.getDrawable(R.drawable.visible_conversation_highlight);
        RIGHT_EDGE_TABLET = res.getDrawable(R.drawable.list_edge_tablet);
        //[FEATURE]-Add-BEGIN by TSCD.chao zhang,04/17/2014,FR 631895(porting from FR514398)
        sHighPriorityIcon = BitmapFactory.decodeResource(res, R.drawable.ic_high_priority);
        sLowPriorityIcon = BitmapFactory.decodeResource(res, R.drawable.ic_low_priority);
        sNormalPriorityIcon = BitmapFactory.decodeResource(res, R.drawable.ic_importance_normal);
        //[FEATURE]-Add-END by TSCD.chao zhang

        // Initialize colors.
        sActivatedTextSpan = CharacterStyle
                .wrap(new ForegroundColorSpan(res.getColor(R.color.senders_text_color)));
        sSendersTextColor = res.getColor(R.color.senders_text_color);
        sSubjectTextUnreadSpan = new TextAppearanceSpan(context, R.style.SubjectAppearanceUnreadStyle);
        sSubjectTextReadSpan = new TextAppearanceSpan(context, R.style.SubjectAppearanceReadStyle);

        sBadgeTextSpan = new TextAppearanceSpan(context, R.style.BadgeTextStyle);
        sBadgeBackgroundSpan = new BackgroundColorSpan(res.getColor(R.color.badge_background_color));
        sDateTextColorRead = res.getColor(R.color.date_text_color_read);
        sDateTextColorUnread = res.getColor(R.color.date_text_color_unread);
        sStarTouchSlop = res.getDimensionPixelSize(R.dimen.star_touch_slop);
        sSenderImageTouchSlop = res.getDimensionPixelSize(R.dimen.sender_image_touch_slop);
        sShrinkAnimationDuration = res.getInteger(R.integer.shrink_animation_duration);
        sSlideAnimationDuration = res.getInteger(R.integer.slide_animation_duration);
        // Initialize static color.
        sSendersSplitToken = res.getString(R.string.senders_split_token);
        sElidedPaddingToken = res.getString(R.string.elided_padding_token);
        sScrollSlop = res.getInteger(R.integer.swipeScrollSlop);
        sFoldersStartPadding = res.getDimensionPixelOffset(R.dimen.folders_start_padding);
        sFoldersInnerPadding = res.getDimensionPixelOffset(R.dimen.folder_cell_content_padding);
        sFoldersMaxCount = res.getInteger(R.integer.conversation_list_max_folder_count);
        sFoldersOverflowGradientPadding = res.getDimensionPixelOffset(R.dimen.folders_gradient_padding);
        sCabAnimationDuration = res.getInteger(R.integer.conv_item_view_cab_anim_duration);
        sBadgePaddingExtraWidth = res.getDimensionPixelSize(R.dimen.badge_padding_extra_width);
        sBadgeRoundedCornerRadius = res.getDimensionPixelSize(R.dimen.badge_rounded_corner_radius);
        sFolderRoundedCornerRadius = res.getDimensionPixelOffset(R.dimen.folder_rounded_corner_radius);
        sDividerColor = res.getColor(R.color.conversation_list_divider_color);
        sDividerInset = res.getDimensionPixelSize(R.dimen.conv_list_divider_inset);
        sDividerHeight = res.getDimensionPixelSize(R.dimen.divider_height);
    }
}

From source file:com.android.mms.transaction.MessagingNotification.java

private static CharSequence formatSenders(Context context, ArrayList<NotificationInfo> senders) {
    final TextAppearanceSpan notificationSenderSpan = new TextAppearanceSpan(context,
            R.style.NotificationPrimaryText);

    String separator = context.getString(R.string.enumeration_comma); // ", "
    SpannableStringBuilder spannableStringBuilder = new SpannableStringBuilder();
    int len = senders.size();
    for (int i = 0; i < len; i++) {
        if (i > 0) {
            spannableStringBuilder.append(separator);
        }//  ww  w  .jav a  2s.com
        spannableStringBuilder.append(senders.get(i).mSender.getName());
    }
    spannableStringBuilder.setSpan(notificationSenderSpan, 0, spannableStringBuilder.length(), 0);
    return spannableStringBuilder;
}

From source file:com.android.mms.transaction.MessagingNotification.java

private static CharSequence getAttachmentTypeString(Context context, int attachmentType) {
    final TextAppearanceSpan notificationAttachmentSpan = new TextAppearanceSpan(context,
            R.style.NotificationSecondaryText);
    int id = 0;//from   w w  w .  jav  a 2s.  c  o  m
    switch (attachmentType) {
    case WorkingMessage.AUDIO:
        id = R.string.attachment_audio;
        break;
    case WorkingMessage.VIDEO:
        id = R.string.attachment_video;
        break;
    case WorkingMessage.SLIDESHOW:
        id = R.string.attachment_slideshow;
        break;
    case WorkingMessage.IMAGE:
        id = R.string.attachment_picture;
        break;
    }
    if (id > 0) {
        final SpannableString spannableString = new SpannableString(context.getString(id));
        spannableString.setSpan(notificationAttachmentSpan, 0, spannableString.length(), 0);
        return spannableString;
    }
    return null;
}

From source file:com.csipsimple.ui.incall.CallActivity.java

/**
 * Controls buttons (accept, reject etc).
 * @param whichAction what action has been done
 * @param call//from  w  w  w . j av  a2 s  .  co  m
 */
@Override
public void onTrigger(int whichAction, final SipCallSession call) {

    // Sanity check for actions requiring valid call id
    if (whichAction == TAKE_CALL || whichAction == REJECT_CALL || whichAction == DONT_TAKE_CALL
            || whichAction == TERMINATE_CALL || whichAction == DETAILED_DISPLAY || whichAction == TOGGLE_HOLD
            || whichAction == START_RECORDING || whichAction == STOP_RECORDING || whichAction == DTMF_DISPLAY
            || whichAction == XFER_CALL || whichAction == TRANSFER_CALL || whichAction == START_VIDEO
            || whichAction == STOP_VIDEO) {
        // We check that current call is valid for any actions
        if (call == null) {
            Log.e(TAG, "Try to do an action on a null call !!!");
            return;
        }
        if (call.getCallId() == SipCallSession.INVALID_CALL_ID) {
            Log.e(TAG, "Try to do an action on an invalid call !!!");
            return;
        }
    }

    // Reset proximity sensor timer
    proximityManager.restartTimer();

    try {
        switch (whichAction) {
        case TAKE_CALL: {
            if (service != null) {
                Log.i(TAG, "Answering call " + call.getCallId());

                boolean shouldHoldOthers = false;

                // Well actually we should be always before confirmed
                if (call.isBeforeConfirmed()) {
                    shouldHoldOthers = true;
                }

                service.answer(call.getCallId(), StatusCode.OK);

                // if it's a ringing call, we assume that user wants to
                // hold other calls
                if (shouldHoldOthers && callsInfo != null) {
                    for (SipCallSession callInfo : callsInfo) {
                        // For each active and running call
                        if (SipCallSession.InvState.CONFIRMED == callInfo.getCallState()
                                && !callInfo.isLocalHeld() && callInfo.getCallId() != call.getCallId()) {

                            Log.d(TAG, "Hold call " + callInfo.getCallId());
                            service.hold(callInfo.getCallId());

                        }
                    }
                }
            }
            break;
        }
        case DONT_TAKE_CALL: {
            if (service != null) {
                Log.i(TAG, "Rejecting the call with BUSY_HERE");
                service.hangup(call.getCallId(), StatusCode.BUSY_HERE);
            }
            break;
        }
        case REJECT_CALL:
            if (service != null) {
                Log.i(TAG, "Rejecting the call");
                service.hangup(call.getCallId(), 0);
            }
            break;
        case TERMINATE_CALL: {
            if (service != null) {
                Log.i(TAG, "Terminating the call");
                service.hangup(call.getCallId(), 0);
            }
            break;
        }
        case CANCEL_CALL: {
            if (service != null) {
                Log.i(TAG, "Cancelling the call");
                service.hangup(call.getCallId(), 0);
            }
            sendCancelCallBroadcast();
            break;
        }
        case MUTE_ON:
        case MUTE_OFF: {
            if (service != null) {
                Log.i(TAG, "Set mute " + (whichAction == MUTE_ON));
                service.setMicrophoneMute((whichAction == MUTE_ON) ? true : false);
            }
            break;
        }
        case SPEAKER_ON:
        case SPEAKER_OFF: {
            if (service != null) {
                Log.d(TAG, "Set speaker " + (whichAction == SPEAKER_ON));
                useAutoDetectSpeaker = false;
                service.setSpeakerphoneOn((whichAction == SPEAKER_ON) ? true : false);
            }
            break;
        }
        case BLUETOOTH_ON:
        case BLUETOOTH_OFF: {
            if (service != null) {
                Log.d(TAG, "Set bluetooth " + (whichAction == BLUETOOTH_ON));
                service.setBluetoothOn((whichAction == BLUETOOTH_ON) ? true : false);
            }
            break;
        }
        case DTMF_DISPLAY: {
            Log.d(TAG, "DTMF_DISPLAY");
            showDialpad(call.getCallId());
            break;
        }
        case DETAILED_DISPLAY: {
            if (service != null) {
                if (infoDialog != null) {
                    infoDialog.dismiss();
                }
                String infos = service.showCallInfosDialog(call.getCallId());
                String natType = service.getLocalNatType();
                SpannableStringBuilder buf = new SpannableStringBuilder();
                Builder builder = new Builder(this);

                buf.append(infos);
                if (!TextUtils.isEmpty(natType)) {
                    buf.append("\r\nLocal NAT type detected : ");
                    buf.append(natType);
                }
                TextAppearanceSpan textSmallSpan = new TextAppearanceSpan(this,
                        android.R.style.TextAppearance_Small);
                buf.setSpan(textSmallSpan, 0, buf.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);

                infoDialog = builder.setIcon(android.R.drawable.ic_dialog_info).setMessage(buf)
                        .setNeutralButton(R.string.ok, null).create();
                infoDialog.show();
            }
            break;
        }
        case TOGGLE_HOLD: {
            if (service != null) {
                // Log.d(TAG,
                // "Current state is : "+callInfo.getCallState().name()+" / "+callInfo.getMediaStatus().name());
                if (call.getMediaStatus() == SipCallSession.MediaState.LOCAL_HOLD
                        || call.getMediaStatus() == SipCallSession.MediaState.NONE) {
                    service.reinvite(call.getCallId(), true);
                } else {
                    service.hold(call.getCallId());
                }
            }
            break;
        }
        case MEDIA_SETTINGS: {
            startActivity(new Intent(this, InCallMediaControl.class));
            break;
        }
        case XFER_CALL: {
            Intent pickupIntent = new Intent(this, PickupSipUri.class);
            pickupIntent.putExtra(CALL_ID, call.getCallId());
            startActivityForResult(pickupIntent, PICKUP_SIP_URI_XFER);
            break;
        }
        case TRANSFER_CALL: {
            final ArrayList<SipCallSession> remoteCalls = new ArrayList<SipCallSession>();
            if (callsInfo != null) {
                for (SipCallSession remoteCall : callsInfo) {
                    // Verify not current call
                    if (remoteCall.getCallId() != call.getCallId() && remoteCall.isOngoing()) {
                        remoteCalls.add(remoteCall);
                    }
                }
            }

            if (remoteCalls.size() > 0) {
                Builder builder = new Builder(this);
                CharSequence[] simpleAdapter = new String[remoteCalls.size()];
                for (int i = 0; i < remoteCalls.size(); i++) {
                    simpleAdapter[i] = remoteCalls.get(i).getRemoteContact();
                }
                builder.setSingleChoiceItems(simpleAdapter, -1, new Dialog.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        if (service != null) {
                            try {
                                // 1 = PJSUA_XFER_NO_REQUIRE_REPLACES
                                service.xferReplace(call.getCallId(), remoteCalls.get(which).getCallId(), 1);
                            } catch (RemoteException e) {
                                Log.e(TAG, "Was not able to call service method", e);
                            }
                        }
                        dialog.dismiss();
                    }
                }).setCancelable(true).setNeutralButton(R.string.cancel, new Dialog.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        dialog.dismiss();
                    }
                }).show();
            }

            break;
        }
        case ADD_CALL: {
            Intent pickupIntent = new Intent(this, PickupSipUri.class);
            startActivityForResult(pickupIntent, PICKUP_SIP_URI_NEW_CALL);
            break;
        }
        case START_RECORDING: {
            if (service != null) {
                // TODO : add a tweaky setting for two channel recording in different files.
                // Would just result here in two calls to start recording with different bitmask
                service.startRecording(call.getCallId(), SipManager.BITMASK_ALL);
            }
            break;
        }
        case STOP_RECORDING: {
            if (service != null) {
                service.stopRecording(call.getCallId());
            }
            break;
        }
        case START_VIDEO:
        case STOP_VIDEO: {
            if (service != null) {
                Bundle opts = new Bundle();
                opts.putBoolean(SipCallSession.OPT_CALL_VIDEO, whichAction == START_VIDEO);
                service.updateCallOptions(call.getCallId(), opts);
            }
            break;
        }
        case ZRTP_TRUST: {
            if (service != null) {
                service.zrtpSASVerified(call.getCallId());
            }
            break;
        }
        case ZRTP_REVOKE: {
            if (service != null) {
                service.zrtpSASRevoke(call.getCallId());
            }
            break;
        }
        }
    } catch (RemoteException e) {
        Log.e(TAG, "Was not able to call service method", e);
    }
}

From source file:com.android.messaging.datamodel.MessageNotificationState.java

/**
 * Performs a query on the database.//from  www. ja  v a  2 s. c  o  m
 */
private static ConversationInfoList createConversationInfoList() {
    // Map key is conversation id. We use LinkedHashMap to ensure that entries are iterated in
    // the same order they were originally added. We scan unseen messages from newest to oldest,
    // so the corresponding conversations are added in that order, too.
    final Map<String, ConversationLineInfo> convLineInfos = new LinkedHashMap<>();
    int messageCount = 0;

    Cursor convMessageCursor = null;
    try {
        final Context context = Factory.get().getApplicationContext();
        final DatabaseWrapper db = DataModel.get().getDatabase();

        convMessageCursor = db.rawQuery(ConversationMessageData.getNotificationQuerySql(), null);

        if (convMessageCursor != null && convMessageCursor.moveToFirst()) {
            if (LogUtil.isLoggable(TAG, LogUtil.VERBOSE)) {
                LogUtil.v(TAG, "MessageNotificationState: Found unseen message notifications.");
            }
            final ConversationMessageData convMessageData = new ConversationMessageData();

            HashMap<String, Integer> firstNames = null;
            String conversationIdForFirstNames = null;
            String groupConversationName = null;
            final int maxMessages = getMaxMessagesInConversationNotification();

            do {
                convMessageData.bind(convMessageCursor);

                // First figure out if this is a valid message.
                String authorFullName = convMessageData.getSenderFullName();
                String authorFirstName = convMessageData.getSenderFirstName();
                final String messageText = convMessageData.getText();

                final String convId = convMessageData.getConversationId();
                final String messageId = convMessageData.getMessageId();

                CharSequence text = messageText;
                final boolean isManualDownloadNeeded = convMessageData.getIsMmsNotification();
                if (isManualDownloadNeeded) {
                    // Don't try and convert the text from html if it's sms and not a sms push
                    // notification.
                    Assert.equals(MessageData.BUGLE_STATUS_INCOMING_YET_TO_MANUAL_DOWNLOAD,
                            convMessageData.getStatus());
                    text = context.getResources().getString(R.string.message_title_manual_download);
                }
                ConversationLineInfo currConvInfo = convLineInfos.get(convId);
                if (currConvInfo == null) {
                    final ConversationListItemData convData = ConversationListItemData
                            .getExistingConversation(db, convId);
                    if (!convData.getNotificationEnabled()) {
                        // Skip conversations that have notifications disabled.
                        continue;
                    }
                    final int subId = BugleDatabaseOperations.getSelfSubscriptionId(db, convData.getSelfId());
                    groupConversationName = convData.getName();
                    final Uri avatarUri = AvatarUriUtil.createAvatarUri(
                            convMessageData.getSenderProfilePhotoUri(), convMessageData.getSenderFullName(),
                            convMessageData.getSenderNormalizedDestination(),
                            convMessageData.getSenderContactLookupKey());
                    currConvInfo = new ConversationLineInfo(convId, convData.getIsGroup(),
                            groupConversationName, convData.getIncludeEmailAddress(),
                            convMessageData.getReceivedTimeStamp(), convData.getSelfId(),
                            convData.getNotificationSoundUri(), convData.getNotificationEnabled(),
                            convData.getNotifiationVibrate(), avatarUri,
                            convMessageData.getSenderContactLookupUri(), subId, convData.getParticipantCount());
                    convLineInfos.put(convId, currConvInfo);
                }
                // Prepare the message line
                if (currConvInfo.mTotalMessageCount < maxMessages) {
                    if (currConvInfo.mIsGroup) {
                        if (authorFirstName == null) {
                            // authorFullName might be null as well. In that case, we won't
                            // show an author. That is better than showing all the group
                            // names again on the 2nd line.
                            authorFirstName = authorFullName;
                        }
                    } else {
                        // don't recompute this if we don't need to
                        if (!TextUtils.equals(conversationIdForFirstNames, convId)) {
                            firstNames = scanFirstNames(convId);
                            conversationIdForFirstNames = convId;
                        }
                        if (firstNames != null) {
                            final Integer count = firstNames.get(authorFirstName);
                            if (count != null && count > 1) {
                                authorFirstName = authorFullName;
                            }
                        }

                        if (authorFullName == null) {
                            authorFullName = groupConversationName;
                        }
                        if (authorFirstName == null) {
                            authorFirstName = groupConversationName;
                        }
                    }
                    final String subjectText = MmsUtils.cleanseMmsSubject(context.getResources(),
                            convMessageData.getMmsSubject());
                    if (!TextUtils.isEmpty(subjectText)) {
                        final String subjectLabel = context.getString(R.string.subject_label);
                        final SpannableStringBuilder spanBuilder = new SpannableStringBuilder();

                        spanBuilder.append(
                                context.getString(R.string.notification_subject, subjectLabel, subjectText));
                        spanBuilder.setSpan(new TextAppearanceSpan(context, R.style.NotificationSubjectText), 0,
                                subjectLabel.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
                        if (!TextUtils.isEmpty(text)) {
                            // Now add the actual message text below the subject header.
                            spanBuilder.append(System.getProperty("line.separator") + text);
                        }
                        text = spanBuilder;
                    }
                    // If we've got attachments, find the best one. If one of the messages is
                    // a photo, save the url so we'll display a big picture notification.
                    // Otherwise, show the first one we find.
                    Uri attachmentUri = null;
                    String attachmentType = null;
                    final MessagePartData messagePartData = getMostInterestingAttachment(convMessageData);
                    if (messagePartData != null) {
                        attachmentUri = messagePartData.getContentUri();
                        attachmentType = messagePartData.getContentType();
                    }
                    currConvInfo.mLineInfos
                            .add(new MessageLineInfo(currConvInfo.mIsGroup, authorFullName, authorFirstName,
                                    text, attachmentUri, attachmentType, isManualDownloadNeeded, messageId));
                }
                messageCount++;
                currConvInfo.mTotalMessageCount++;
            } while (convMessageCursor.moveToNext());
        }
    } finally {
        if (convMessageCursor != null) {
            convMessageCursor.close();
        }
    }
    if (convLineInfos.isEmpty()) {
        return null;
    } else {
        return new ConversationInfoList(messageCount, Lists.newLinkedList(convLineInfos.values()));
    }
}