Example usage for android.text SpannableStringBuilder append

List of usage examples for android.text SpannableStringBuilder append

Introduction

In this page you can find the example usage for android.text SpannableStringBuilder append.

Prototype

public SpannableStringBuilder append(char text) 

Source Link

Usage

From source file:com.android.mms.ui.MessageListItem.java

private CharSequence formatMessage(MessageItem msgItem, String body, String subject, Pattern highlight,
        String contentType) {/*from   w w  w  .ja  v  a 2s  .com*/
    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;
}

From source file:com.juick.android.MessageMenu.java

protected void runActions() {
    if (!isDialogMode()) {
        AlertDialog.Builder builder = new AlertDialog.Builder(activity);
        final CharSequence[] items = new CharSequence[menuActions.size()];
        for (int j = 0; j < items.length; j++) {
            items[j] = menuActions.get(j).title;
        }//www.  j  a va  2s .  c  o  m
        builder.setItems(items, this);
        final AlertDialog alertDialog = builder.create();
        alertDialog.setOnShowListener(new DialogInterface.OnShowListener() {
            @Override
            public void onShow(DialogInterface dialog) {
                ColorsTheme.ColorTheme colorTheme = JuickMessagesAdapter.getColorTheme(activity);
                ColorDrawable divider = new ColorDrawable(
                        colorTheme.getColor(ColorsTheme.ColorKey.COMMON_BACKGROUND, 0xFFFFFFFF));
                alertDialog.getListView().setDivider(divider);
                alertDialog.getListView().setDividerHeight(1);
            }
        });
        alertDialog.show();

        final ListAdapter adapter = alertDialog.getListView().getAdapter();
        SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(activity);
        float menuFontScale = 1;
        try {
            menuFontScale = Float.parseFloat(sp.getString("menuFontScale", "1.0"));
        } catch (Exception e) {
            e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
        }
        final boolean compressedMenu = sp.getBoolean("compressedMenu", false);
        final boolean singleLineMenu = sp.getBoolean("singleLineMenu", false);
        final float finalMenuFontScale = menuFontScale;
        final int screenHeight = activity.getWindow().getWindowManager().getDefaultDisplay().getHeight();
        alertDialog.getListView().setAdapter(new ListAdapter() {
            @Override
            public boolean areAllItemsEnabled() {
                return adapter.areAllItemsEnabled();
            }

            @Override
            public boolean isEnabled(int position) {
                return adapter.isEnabled(position);
            }

            @Override
            public void registerDataSetObserver(DataSetObserver observer) {
                adapter.registerDataSetObserver(observer);
            }

            @Override
            public void unregisterDataSetObserver(DataSetObserver observer) {
                adapter.unregisterDataSetObserver(observer);
            }

            @Override
            public int getCount() {
                return items.length;
            }

            @Override
            public Object getItem(int position) {
                return adapter.getItem(position);
            }

            @Override
            public long getItemId(int position) {
                return adapter.getItemId(position);
            }

            @Override
            public boolean hasStableIds() {
                return adapter.hasStableIds();
            }

            @Override
            public View getView(int position, View convertView, ViewGroup parent) {
                View retval = adapter.getView(position, null, parent);
                if (retval instanceof TextView) {
                    TextView tv = (TextView) retval;
                    if (compressedMenu) {
                        int minHeight = (int) ((screenHeight * 0.7) / getCount());
                        tv.setMinHeight(minHeight);
                        tv.setMinimumHeight(minHeight);
                    }
                    if (singleLineMenu) {
                        tv.setSingleLine(true);
                        tv.setEllipsize(TextUtils.TruncateAt.MIDDLE);
                    }
                    tv.setTextSize(22 * finalMenuFontScale);
                }
                return retval;
            }

            @Override
            public int getItemViewType(int position) {
                return adapter.getItemViewType(position);
            }

            @Override
            public int getViewTypeCount() {
                return adapter.getViewTypeCount();
            }

            @Override
            public boolean isEmpty() {
                return adapter.isEmpty();
            }
        });
    } else {
        AlertDialog.Builder builder = new AlertDialog.Builder(
                new ContextThemeWrapper(activity, R.style.Theme_Sherlock));
        View dialogView = activity.getLayoutInflater().inflate(R.layout.message_menu2, null);
        builder.setView(dialogView);
        builder.setCancelable(true);
        int width = activity.getWindowManager().getDefaultDisplay().getWidth();
        View scrollView = dialogView.findViewById(R.id.scrollView);
        scrollView.getLayoutParams().width = (int) (width * 0.90);
        final AlertDialog alertDialog = builder.create();
        alertDialog.setOnShowListener(new DialogInterface.OnShowListener() {
            @Override
            public void onShow(DialogInterface dialog) {
                //MainActivity.restyleChildrenOrWidget(alertDialog.getWindow().getDecorView());
            }
        });
        TextView messageNo = (TextView) dialogView.findViewById(R.id.message_no);
        messageNo.setText(listSelectedItem.getDisplayMessageNo());
        Spinner openUrl = (Spinner) dialogView.findViewById(R.id.open_url);
        Button singleURL = (Button) dialogView.findViewById(R.id.single_url);
        if (urls != null && urls.size() == 1) {
            singleURL.setVisibility(View.VISIBLE);
            openUrl.setVisibility(View.GONE);
            SpannableStringBuilder sb = new SpannableStringBuilder();
            sb.append(urls.get(0));
            sb.setSpan(new UnderlineSpan(), 0, sb.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
            singleURL.setText(sb);
            singleURL.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    alertDialog.dismiss();
                    launchURL(listSelectedItem.getMID(), urls.get(0));
                }
            });
        } else if (urls != null && urls.size() > 0) {
            singleURL.setVisibility(View.GONE);
            openUrl.setVisibility(View.VISIBLE);
            openUrl.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
                @Override
                public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
                    if (position != 0) {
                        alertDialog.dismiss();
                        launchURL(listSelectedItem.getMID(), urls.get(position));
                    }
                }

                @Override
                public void onNothingSelected(AdapterView<?> parent) {
                    //To change body of implemented methods use File | Settings | File Templates.
                }
            });
            urls.add(0, activity.getString(R.string.ClickToSelectURL));
            openUrl.setAdapter(new BaseAdapter() {
                @Override
                public int getCount() {
                    return urls.size();
                }

                @Override
                public Object getItem(int position) {
                    return position;
                }

                @Override
                public long getItemId(int position) {
                    return position;
                }

                @Override
                public View getView(int position, View convertView, ViewGroup parent) {
                    View rowView = activity.getLayoutInflater().inflate(android.R.layout.simple_list_item_1,
                            null);
                    TextView textView = (TextView) rowView.findViewById(android.R.id.text1);
                    textView.setSingleLine(false);
                    textView.setMaxLines(5);
                    SpannableStringBuilder sb = new SpannableStringBuilder();
                    sb.append(urls.get(position));
                    if (position == 0) {
                        textView.setTextColor(0xFF808080);
                    } else {
                        sb.setSpan(new UnderlineSpan(), 0, sb.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
                    }
                    textView.setText(sb);
                    return rowView;
                }
            });
        } else {
            openUrl.setVisibility(View.GONE);
            singleURL.setVisibility(View.GONE);
        }
        final String UName = listSelectedItem.User.UName;
        View recommendMessage = dialogView.findViewById(R.id.recommend_message);
        View deleteMessage = dialogView.findViewById(R.id.delete_message);
        View saveMessage = dialogView.findViewById(R.id.save_message);
        View unsaveMessage = dialogView.findViewById(R.id.unsave_message);
        //View subscribeUser = dialogView.findViewById(R.id.subscribe_user);
        View subscribeMessage = dialogView.findViewById(R.id.subscribe_message);
        //View unsubscribeUser = dialogView.findViewById(R.id.unsubscribe_user);
        View unsubscribeMessage = dialogView.findViewById(R.id.unsubscribe_message);
        View translateMessage = dialogView.findViewById(R.id.translate_message);
        View shareMessage = dialogView.findViewById(R.id.share_message);
        //View blacklistUser = dialogView.findViewById(R.id.blacklist_user);
        //View filterUser = dialogView.findViewById(R.id.filter_user);
        //View userBlog = dialogView.findViewById(R.id.user_blog);
        //View userStats = dialogView.findViewById(R.id.user_stats);
        View openMessageInBrowser = dialogView.findViewById(R.id.open_message_in_browser);
        Button userCenter = (Button) dialogView.findViewById(R.id.user_center);
        if (null == dialogView.findViewById(R.id.column_3)) {
            // only for portrait
            userCenter.setText("@" + listSelectedItem.User.UName + " " + userCenter.getText());
        }

        unsubscribeMessage.setEnabled(listSelectedItem.getRID() == 0);
        subscribeMessage.setEnabled(listSelectedItem.getRID() == 0);
        unsaveMessage.setEnabled(listSelectedItem.getRID() == 0);
        recommendMessage.setEnabled(listSelectedItem.getRID() == 0);

        if (UName.equalsIgnoreCase(JuickAPIAuthorizer.getJuickAccountName(activity.getApplicationContext()))) {
            recommendMessage.setVisibility(View.GONE);
        } else {
            deleteMessage.setVisibility(View.GONE);
        }
        if (messagesSource instanceof SavedMessagesSource) {
            saveMessage.setVisibility(View.GONE);
        } else {
            unsaveMessage.setVisibility(View.GONE);
        }
        recommendMessage.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                alertDialog.dismiss();
                actionRecommendMessage();
            }
        });
        deleteMessage.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                alertDialog.dismiss();
                actionDeleteMessage();
            }
        });
        saveMessage.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                alertDialog.dismiss();
                actionSaveMessage();
            }
        });
        unsaveMessage.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                alertDialog.dismiss();
                actionUnsaveMessage();
            }
        });
        //            subscribeUser.setOnClickListener(new View.OnClickListener() {
        //                @Override
        //                public void onClick(View v) {
        //                    alertDialog.dismiss();
        //                    actionSubscribeUser();
        //                }
        //            });
        subscribeMessage.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                alertDialog.dismiss();
                actionSubscribeMessage();
            }
        });
        //            unsubscribeUser.setOnClickListener(new View.OnClickListener() {
        //                @Override
        //                public void onClick(View v) {
        //                    alertDialog.dismiss();
        //                    actionUnsubscribeUser();
        //                }
        //            });
        unsubscribeMessage.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                alertDialog.dismiss();
                actionUnsubscribeMessage();
            }
        });
        translateMessage.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                alertDialog.dismiss();
                actionTranslateMessage();
            }
        });
        shareMessage.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                alertDialog.dismiss();
                actionShareMessage();
            }
        });
        //            blacklistUser.setOnClickListener(new View.OnClickListener() {
        //                @Override
        //                public void onClick(View v) {
        //                    alertDialog.dismiss();
        //                    actionBlacklistUser();
        //                }
        //            });
        //            filterUser.setOnClickListener(new View.OnClickListener() {
        //                @Override
        //                public void onClick(View v) {
        //                    alertDialog.dismiss();
        //                    actionFilterUser(UName);
        //                }
        //            });
        //            userBlog.setOnClickListener(new View.OnClickListener() {
        //                @Override
        //                public void onClick(View v) {
        //                    alertDialog.dismiss();
        //                    actionUserBlog();
        //                }
        //            });
        //            userStats.setOnClickListener(new View.OnClickListener() {
        //                @Override
        //                public void onClick(View v) {
        //                    alertDialog.dismiss();
        //                    actionUserStats();
        //                }
        //            });
        openMessageInBrowser.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                alertDialog.dismiss();
                actionOpenMessageInBrowser();
            }
        });
        userCenter.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                alertDialog.dismiss();
                actionUserCenter();
            }
        });
        completeInitDialogMode(alertDialog, dialogView);
        alertDialog.show();
    }
}

From source file:org.telegram.ui.ChannelCreateActivity.java

private ChipSpan createAndPutChipForUser(TLRPC.User user) {
    try {/*w  w  w . ja  v  a 2s.co  m*/
        LayoutInflater lf = (LayoutInflater) ApplicationLoader.applicationContext
                .getSystemService(Activity.LAYOUT_INFLATER_SERVICE);
        View textView = lf.inflate(R.layout.group_create_bubble, null);
        TextView text = (TextView) textView.findViewById(R.id.bubble_text_view);
        String name = UserObject.getUserName(user);
        if (name.length() == 0 && user.phone != null && user.phone.length() != 0) {
            name = PhoneFormat.getInstance().format("+" + user.phone);
        }
        text.setText(name + ", ");

        int spec = View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED);
        textView.measure(spec, spec);
        textView.layout(0, 0, textView.getMeasuredWidth(), textView.getMeasuredHeight());
        Bitmap b = Bitmap.createBitmap(textView.getWidth(), textView.getHeight(), Bitmap.Config.ARGB_8888);
        Canvas canvas = new Canvas(b);
        canvas.translate(-textView.getScrollX(), -textView.getScrollY());
        textView.draw(canvas);
        textView.setDrawingCacheEnabled(true);
        Bitmap cacheBmp = textView.getDrawingCache();
        Bitmap viewBmp = cacheBmp.copy(Bitmap.Config.ARGB_8888, true);
        textView.destroyDrawingCache();

        final BitmapDrawable bmpDrawable = new BitmapDrawable(b);
        bmpDrawable.setBounds(0, 0, b.getWidth(), b.getHeight());

        SpannableStringBuilder ssb = new SpannableStringBuilder("");
        ChipSpan span = new ChipSpan(bmpDrawable, ImageSpan.ALIGN_BASELINE);
        allSpans.add(span);
        selectedContacts.put(user.id, span);
        for (ImageSpan sp : allSpans) {
            ssb.append("<<");
            ssb.setSpan(sp, ssb.length() - 2, ssb.length(), SpannableStringBuilder.SPAN_EXCLUSIVE_EXCLUSIVE);
        }
        nameTextView.setText(ssb);
        nameTextView.setSelection(ssb.length());
        return span;
    } catch (Exception e) {
        FileLog.e("tmessages", e);
    }
    return null;
}

From source file:cgeo.geocaching.CacheDetailActivity.java

static void appendClickableList(final SpannableStringBuilder builder, final View view, final Integer listId) {
    final int start = builder.length();
    builder.append(DataStore.getList(listId).getTitle());
    builder.setSpan(new ClickableSpan() {
        @Override/*  ww w  .  ja  va 2 s.c  o  m*/
        public void onClick(final View widget) {
            Settings.setLastDisplayedList(listId);
            CacheListActivity.startActivityOffline(view.getContext());
        }
    }, start, builder.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
}

From source file:cgeo.geocaching.CacheDetailActivity.java

static void updateCacheLists(final View view, final Geocache cache, final Resources res) {
    final SpannableStringBuilder builder = new SpannableStringBuilder();
    for (final Integer listId : cache.getLists()) {
        if (builder.length() > 0) {
            builder.append(", ");
        }/* w w  w.  java2s  .co  m*/
        appendClickableList(builder, view, listId);
    }
    builder.insert(0, res.getString(R.string.list_list_headline) + " ");
    final TextView offlineLists = ButterKnife.findById(view, R.id.offline_lists);
    offlineLists.setText(builder);
    offlineLists.setMovementMethod(LinkMovementMethod.getInstance());
}

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 ww.  ja v a  2  s .  c o  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:lewa.support.v7.widget.SearchView.java

private CharSequence getDecoratedHint(CharSequence hintText) {
    // If the field is always expanded, then don't add the search icon to the hint
    if (!mIconifiedByDefault)
        return hintText;

    SpannableStringBuilder ssb = new SpannableStringBuilder("   "); // for the icon
    ssb.append(hintText);
    Drawable searchIcon = getContext().getResources().getDrawable(mSearchIconResId);
    int textSize = (int) (mQueryTextView.getTextSize() * 1.25);
    searchIcon.setBounds(0, 0, textSize, textSize);
    ssb.setSpan(new ImageSpan(searchIcon), 1, 2, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
    return ssb;/*from w  ww  . ja v a 2s .  c o m*/
}

From source file:cm.aptoide.com.actionbarsherlock.widget.SearchView.java

private CharSequence getDecoratedHint(CharSequence hintText) {
    // If the field is always expanded, then don't add the search icon to the hint
    if (!mIconifiedByDefault)
        return hintText;

    SpannableStringBuilder ssb = new SpannableStringBuilder("   "); // for the icon
    ssb.append(hintText);
    Drawable searchIcon = getContext().getResources().getDrawable(getSearchIconId());
    int textSize = (int) (mQueryTextView.getTextSize() * 1.25);
    searchIcon.setBounds(0, 0, textSize, textSize);
    ssb.setSpan(new ImageSpan(searchIcon), 1, 2, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
    return ssb;/*from   w ww.  ja  va2  s  .co  m*/
}

From source file:com.android.mail.utils.NotificationUtils.java

private static SpannableStringBuilder ellipsizeStyledSenders(final Context context,
        ArrayList<SpannableString> styledSenders) {
    if (sSendersSplitToken == null) {
        sSendersSplitToken = context.getString(R.string.senders_split_token);
        sElidedPaddingToken = context.getString(R.string.elided_padding_token);
    }/*  www .jav a  2 s .  c  o m*/

    SpannableStringBuilder builder = new SpannableStringBuilder();
    SpannableString prevSender = null;
    for (SpannableString sender : styledSenders) {
        if (sender == null) {
            LogUtils.e(LOG_TAG, "null sender iterating over styledSenders");
            continue;
        }
        CharacterStyle[] spans = sender.getSpans(0, sender.length(), CharacterStyle.class);
        if (SendersView.sElidedString.equals(sender.toString())) {
            prevSender = sender;
            sender = copyStyles(spans, sElidedPaddingToken + sender + sElidedPaddingToken);
        } else if (builder.length() > 0
                && (prevSender == null || !SendersView.sElidedString.equals(prevSender.toString()))) {
            prevSender = sender;
            sender = copyStyles(spans, sSendersSplitToken + sender);
        } else {
            prevSender = sender;
        }
        builder.append(sender);
    }
    return builder;
}

From source file:com.amazon.android.ui.widget.EllipsizedTextView.java

/**
 * Sets ellipsis properties./*from   ww  w.j  a va  2 s . c  o  m*/
 *
 * @param widthMeasureSpec  Ellipsis width.
 * @param heightMeasureSpec Ellipsis height.
 * @param layout            Layout for ellipsis.
 * @param lastLine          Last line length for ellipsis.
 * @param maxLines          Max lines in ellipsis.
 */
private void setEllipsis(int widthMeasureSpec, int heightMeasureSpec, Layout layout, int lastLine,
        int maxLines) {

    mIsEllipsized = true;
    setFocusable(true);
    setClickable(true);
    final SpannableString ss = new SpannableString(mCharSequence);
    String visibleText = mCharSequence.toString();

    mEllipsisImage = new StateImageSpan(getContext(), mGuillemetDrawableId, ImageSpan.ALIGN_BASELINE);

    final SpannableStringBuilder spannedText = new SpannableStringBuilder();
    int ellipsisIndex = layout.getLineStart(Math.min(lastLine + 1, maxLines));

    // Keep chopping words off until the ellipsis is on a visible line or there is only one
    // line left.
    do {
        // Only truncate the last line for long description.
        if (lastLine >= maxLines) {
            // Getting the first word break index before the last index of maxline.
            int safeBreakIndex = breakBefore(visibleText, ellipsisIndex, BreakIterator.getWordInstance());
            final int maxLineStart = layout.getLineStart(maxLines - 1);

            // If this check pass, it means we just truncated a word that is longer than a line.
            if (safeBreakIndex < maxLineStart) {
                // Need to check character by character and break in the middle now. Checking
                // word by word should cover most cases, only do this if a word is longer than
                // line width.
                safeBreakIndex = breakBefore(visibleText, ellipsisIndex, BreakIterator.getCharacterInstance());
            }
            ellipsisIndex = safeBreakIndex;
        }

        visibleText = visibleText.substring(0, ellipsisIndex);
        final CharSequence charOutput = ss.subSequence(0, ellipsisIndex);

        // Re-add ellipsis and convert to image
        spannedText.replace(0, spannedText.length(), charOutput);
        spannedText.append(ELLIPSIS);

        spannedText.setSpan(mEllipsisImage, ellipsisIndex, ellipsisIndex + 1, Spanned.SPAN_INCLUSIVE_INCLUSIVE);

        // Reset text and re-measure.
        super.setText(spannedText, BufferType.SPANNABLE);
        super.onMeasure(widthMeasureSpec, heightMeasureSpec);

    } while (getLineCount() > getMaxLines() && getLineCount() > 1);
    requestFocus();
}