Example usage for android.text SpannableString SpannableString

List of usage examples for android.text SpannableString SpannableString

Introduction

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

Prototype

public SpannableString(CharSequence source) 

Source Link

Document

For the backward compatibility reasons, this constructor copies all spans including android.text.NoCopySpan .

Usage

From source file:com.jelly.music.player.NowPlayingQueueActivity.NowPlayingQueueActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {

    mContext = this;
    sharedPreferences = getSharedPreferences("com.jelly.music.player", Context.MODE_PRIVATE);

    //Get the screen's parameters.
    DisplayMetrics displayMetrics = new DisplayMetrics();
    this.getWindowManager().getDefaultDisplay().getMetrics(displayMetrics);
    int screenWidth = displayMetrics.widthPixels;

    //Set the UI theme.
    if (sharedPreferences.getString(Common.CURRENT_THEME, "LIGHT_CARDS_THEME").equals("DARK_THEME")
            || sharedPreferences.getString(Common.CURRENT_THEME, "LIGHT_CARDS_THEME")
                    .equals("DARK_CARDS_THEME")) {
        setTheme(R.style.AppTheme);/* www .  j a v  a 2  s.c  o m*/
    } else {
        setTheme(R.style.AppThemeLight);
    }

    super.onCreate(savedInstanceState);

    if (getOrientation().equals("PORTRAIT")) {

        //Finish this activity and relaunch the activity that called this one.
        Intent intent = new Intent(this, (Class<?>) getIntent().getSerializableExtra("CALLING_CLASS"));
        intent.putExtras(getIntent());
        intent.putExtra("NEW_PLAYLIST", false);
        intent.putExtra("CALLED_FROM_FOOTER", true);
        intent.setFlags(intent.getFlags() | Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
        finish();
        startActivity(intent);

        return;

    } else {

        setContentView(R.layout.activity_now_playing_queue);

        final Fragment nowPlayingQueueFragment = new NowPlayingQueueFragment();
        FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
        transaction.add(R.id.now_playing_queue_container, nowPlayingQueueFragment, "nowPlayingQueueFragment");
        transaction.commit();

        SpannableString s = new SpannableString(getResources().getString(R.string.current_queue));
        s.setSpan(new TypefaceSpan(this, "RobotoCondensed-Light"), 0, s.length(),
                Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);

        // Update the action bar title with the TypefaceSpan instance.
        ActionBar actionBar = getActionBar();
        actionBar.setTitle(s);
        actionBar.setBackgroundDrawable(getResources().getDrawable(R.drawable.holo_gray_selector));

    }

}

From source file:de.azapps.mirakel.new_ui.adapter.AutoCompleteAdapter.java

@Override
public void bindView(View view, Context context, Cursor cursor) {
    final AutocompleteViewHolder viewHolder = (AutocompleteViewHolder) view.getTag();
    final SearchObject searchObject = new SearchObject(cursor);
    // This is ok for tasks and a fallback variant for tags
    viewHolder.taskName.setText(searchObject.getName());
    switch (searchObject.getAutocompleteType()) {
    case TASK:/*from   w  w w . ja v  a 2 s.com*/
        if (searchObject.isDone()) {
            viewHolder.taskName
                    .setPaintFlags(viewHolder.taskName.getPaintFlags() | Paint.STRIKE_THRU_TEXT_FLAG);
        } else {
            viewHolder.taskName
                    .setPaintFlags(viewHolder.taskName.getPaintFlags() & ~Paint.STRIKE_THRU_TEXT_FLAG);
        }
        break;
    case TAG:
        final Tag tag = new Tag(searchObject.getObjId(), searchObject.getName(),
                searchObject.getBackgroundColor(), false);
        TagSpan tagSpan = new TagSpan(tag, context);
        SpannableStringBuilder stringBuilder = new SpannableStringBuilder();
        stringBuilder.append(new SpannableString(tag.getName()));
        stringBuilder.setSpan(tagSpan, 0, tag.getName().length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
        viewHolder.taskName.setText(stringBuilder, TextView.BufferType.SPANNABLE);
        break;
    }
}

From source file:com.aniruddhc.acemusic.player.NowPlayingQueueActivity.NowPlayingQueueActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {

    mContext = this;
    sharedPreferences = getSharedPreferences("com.aniruddhc.acemusic.player", Context.MODE_PRIVATE);

    //Get the screen's parameters.
    DisplayMetrics displayMetrics = new DisplayMetrics();
    this.getWindowManager().getDefaultDisplay().getMetrics(displayMetrics);
    int screenWidth = displayMetrics.widthPixels;

    //Set the UI theme.
    if (sharedPreferences.getString(Common.CURRENT_THEME, "LIGHT_CARDS_THEME").equals("DARK_THEME")
            || sharedPreferences.getString(Common.CURRENT_THEME, "LIGHT_CARDS_THEME")
                    .equals("DARK_CARDS_THEME")) {
        setTheme(R.style.AppTheme);/*from   w  w  w.  j  a  v a 2s .c  om*/
    } else {
        setTheme(R.style.AppThemeLight);
    }

    super.onCreate(savedInstanceState);

    if (getOrientation().equals("PORTRAIT")) {

        //Finish this activity and relaunch the activity that called this one.
        Intent intent = new Intent(this, (Class<?>) getIntent().getSerializableExtra("CALLING_CLASS"));
        intent.putExtras(getIntent());
        intent.putExtra("NEW_PLAYLIST", false);
        intent.putExtra("CALLED_FROM_FOOTER", true);
        intent.setFlags(intent.getFlags() | Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
        finish();
        startActivity(intent);

        return;

    } else {

        setContentView(R.layout.activity_now_playing_queue);

        final Fragment nowPlayingQueueFragment = new NowPlayingQueueFragment();
        FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
        transaction.add(R.id.now_playing_queue_container, nowPlayingQueueFragment, "nowPlayingQueueFragment");
        transaction.commit();

        SpannableString s = new SpannableString(getResources().getString(R.string.current_queue));
        s.setSpan(new TypefaceSpan(this, "RobotoCondensed-Light"), 0, s.length(),
                Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);

        // Update the action bar title with the TypefaceSpan instance.
        ActionBar actionBar = getActionBar();
        actionBar.setTitle(s);
        actionBar.setBackgroundDrawable(getResources().getDrawable(R.drawable.holo_gray_selector));

    }

}

From source file:com.normalexception.app.rx8club.view.profile.ProfileViewArrayAdapter.java

public View getView(int position, View convertView, ViewGroup parent) {
    View vi = convertView;/*from  w w  w .  j a v  a2 s.  c o m*/
    if (vi == null) {
        vi = new TextView(sourceFragment.getActivity());
    }

    TextView tv = (TextView) vi;
    final ProfileModel pm = data.get(position);
    String text = String.format("%s\n%s", pm.getName(), pm.getText());
    SpannableString spanString = new SpannableString(text);
    spanString.setSpan(new StyleSpan(Typeface.BOLD), 0, text.indexOf("\n"), 0);
    spanString.setSpan(new StyleSpan(Typeface.ITALIC), text.indexOf("\n") + 1, text.length(), 0);
    tv.setText(spanString);
    tv.setPadding(1, 10, 1, 10);
    tv.setBackgroundColor(Color.DKGRAY);
    tv.setTextColor(Color.WHITE);
    tv.setTextSize(10);
    tv.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View arg0) {
            Bundle args = new Bundle();
            args.putString("link", pm.getLink());
            args.putString("title", pm.getName());
            FragmentUtils.fragmentTransaction(sourceFragment.getActivity(), ThreadFragment.newInstance(), false,
                    true, args);
        }
    });

    return vi;
}

From source file:org.kontalk.ui.view.ContactsListItem.java

public final void bind(Context context, final Contact contact, String prependStatus,
        CharacterStyle prependStyle, boolean subscribed) {
    mContact = contact;//from w w w .  j ava  2 s . c  o  m

    setChecked(false);

    loadAvatar(contact);

    mText1.setText(contact.getDisplayName());

    CharSequence text2 = contact.getStatus();
    if (text2 == null) {
        text2 = contact.getNumber();
        mText2.setTextColor(ContextCompat.getColor(context, R.color.grayed_out));
    } else {
        int color = ContextCompat.getColor(context,
                SystemUtils.getThemedResource(getContext(), android.R.attr.textColorSecondary));
        mText2.setTextColor(color);
    }
    if (prependStatus != null) {
        if (prependStyle != null) {
            text2 = new SpannableString(prependStatus + " " + text2);
            ((SpannableString) text2).setSpan(prependStyle, 0, prependStatus.length(),
                    Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
        } else {
            text2 = prependStatus + " " + text2;
        }
    }
    mText2.setText(text2);

    if (mTrustStatus != null) {
        int resId;

        if (!subscribed) {
            resId = R.drawable.ic_denied;
        } else if (contact.isKeyChanged()) {
            // the key has changed and was not trusted yet
            resId = R.drawable.ic_trust_unknown;
        } else {
            switch (contact.getTrustedLevel()) {
            case MyUsers.Keys.TRUST_UNKNOWN:
                resId = R.drawable.ic_trust_unknown;
                break;
            case MyUsers.Keys.TRUST_IGNORED:
                resId = R.drawable.ic_trust_ignored;
                break;
            case MyUsers.Keys.TRUST_VERIFIED:
                resId = R.drawable.ic_trust_verified;
                break;
            default:
                resId = -1;
            }
        }

        if (resId > 0) {
            mTrustStatus.setImageResource(resId);
        } else {
            mTrustStatus.setImageDrawable(null);
        }
    }

}

From source file:com.inter.trade.ui.fragment.smsreceivepayment.SmsSuccessFragment.java

private void initView(View view) {
    if (requsetData != null) {
        TextView tv_content = (TextView) view.findViewById(R.id.tv_content);
        String s1 = "????";
        String s2 = requsetData.getValue("fumobile");
        String s3 = "??";
        String s4 = "" + requsetData.getValue("money");
        String s5 = ",??1";
        String content = s1 + s2 + s3 + s4 + s5;
        int len = 0;
        /**//from  w  w w.j  a  v a  2s  . c  om
         * ?TEXTVIEW??
         */
        SpannableString ss = new SpannableString(content);
        ss.setSpan(new ForegroundColorSpan(getResources().getColor(R.color.agent_apply_yellow)),
                len = s1.length() + s2.length() + s3.length(), len + s4.length(),
                Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
        tv_content.setText(ss);
        tv_content.setMovementMethod(LinkMovementMethod.getInstance());

        //         String content = "????"
        //               +requsetData.getValue("fumobile")
        //               +"??"
        //               +requsetData.getValue("money")
        //               +",??1";
        //         tv_content.setText(content);

        TextView tv_shou_bank = (TextView) view.findViewById(R.id.tv_shou_bank);
        String shou_bank = "" + requsetData.getValue("shoucardbank");
        tv_shou_bank.setText(shou_bank);

        TextView tv_shou_card = (TextView) view.findViewById(R.id.tv_shou_card);
        String shou_card = "?" + requsetData.getValue("shoucardno");
        tv_shou_card.setText(shou_card);
    }

    Button see_history = (Button) view.findViewById(R.id.see_history);
    see_history.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub
            getActivity().setResult(Constants.ACTIVITY_FINISH);
            getActivity().finish();
        }
    });

    Button btnAgain = (Button) view.findViewById(R.id.btn_again);
    btnAgain.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            /**
             * ??
             */
            SmsReceivePaymentMainFragment.isComeBackFromPaySuccess = true;
            Intent intent = new Intent(getActivity(), IndexActivity.class);
            intent.putExtra(FragmentFactory.INDEX_KEY, FuncMap.SMSRECEIPT_INDEX_FUNC);
            intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
            startActivity(intent);
        }
    });

}

From source file:cl.monsoon.s1next.binding.TextViewBindingAdapter.java

@BindingAdapter({ "eventBus", "post" })
public static void setCount(TextView textView, EventBus eventBus, Post post) {
    String text = "#" + post.getCount();
    // there is no need to quote #1
    if ("1".equals(post.getCount())) {
        textView.setText(text);//from ww  w. j a  v a 2 s. c om
    } else {
        Spannable spannable = new SpannableString(text);
        URLSpan urlSpan = new URLSpan(StringUtils.EMPTY) {
            @Override
            public void onClick(@NonNull View widget) {
                eventBus.post(new QuoteEvent(post.getId(), post.getCount()));
            }
        };
        spannable.setSpan(urlSpan, 0, spannable.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
        textView.setText(spannable);
    }
}

From source file:com.doomy.decode.ResultDialogFragment.java

@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {

    LayoutInflater mLayoutInflater = LayoutInflater.from(getActivity());
    View mView = mLayoutInflater.inflate(R.layout.view_result, null);

    TextView mTextViewFormat = (TextView) mView.findViewById(R.id.textViewFormat);
    TextView mTextViewContent = (TextView) mView.findViewById(R.id.textViewContent);

    if (mTitle.equals("EAN 13") && mMessage.startsWith("978")) {
        GetResponseTask mGetResponseTask = new GetResponseTask();
        mGetResponseTask.execute(mMessage);

        try {/* w w w .j  a  va 2 s  .c  o  m*/
            if (mGetResponseTask.get().equals("")) {
                mTitle = "ISBN";
                mTextViewContent.setText(mMessage);
            } else {
                mTitle = "ISBN";
                mMessage = mGetResponseTask.get();
                SpannableString mSpan = new SpannableString(mMessage);
                mSpan.setSpan(new UnderlineSpan(), 0, mMessage.length(), 0);
                mTextViewContent.setText(mSpan);
                mTextViewContent.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        createURLIntent(makeURLSearch(mMessage));
                    }
                });
            }
        } catch (InterruptedException e) {
            e.printStackTrace();
        } catch (ExecutionException e) {
            e.printStackTrace();
        }
    } else if (mTitle.equals("ISBN")) {
        if (!mMessage.startsWith("978")) {
            SpannableString mSpan = new SpannableString(mMessage);
            mSpan.setSpan(new UnderlineSpan(), 0, mMessage.length(), 0);
            mTextViewContent.setText(mSpan);
            mTextViewContent.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    createURLIntent(makeURLSearch(mMessage));
                }
            });
        } else {
            mTextViewContent.setText(mMessage);
        }
    } else if (mMessage.startsWith("www") || mMessage.startsWith("http://")
            || mMessage.startsWith("https://")) {
        SpannableString mSpan = new SpannableString(mMessage);
        mSpan.setSpan(new UnderlineSpan(), 0, mMessage.length(), 0);
        mTextViewContent.setText(mSpan);
        mTextViewContent.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                createURLIntent(mMessage);
            }
        });
    } else {
        mTextViewContent.setText(mMessage);
    }

    if (mKey) {
        SimpleDateFormat mDateFormat = new SimpleDateFormat("dd/MM/yyyy-HH:mm");
        String mDate = mDateFormat.format(new Date());
        Scan mScan = new Scan(mTitle, mMessage, mDate);
        mDB.addOne(mScan);
    }

    mTextViewFormat.setText(mTitle);

    AlertDialog.Builder mAlertBuilder = new AlertDialog.Builder(getActivity(), Utils.setThemeDialog());

    mAlertBuilder.setTitle(getString(R.string.info)).setView(mView).setPositiveButton(getString(R.string.okay),
            new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int id) {
                    if (mListener != null) {
                        mListener.onDialogPositiveClick(ResultDialogFragment.this);
                    }
                }
            });

    return mAlertBuilder.create();
}

From source file:it.gulch.linuxday.android.adapters.EventsAdapter.java

private void bindView(ViewHolder viewHolder, Event event) {
    viewHolder.event = event;//from   w w  w.ja va 2  s  .  co  m

    String eventTitle = event.getTitle();
    SpannableString spannableString;
    if (CollectionUtils.isEmpty(event.getPeople())) {
        spannableString = new SpannableString(eventTitle);
    } else {
        String personsSummary = StringUtils.join(event.getPeople(), ", ");
        spannableString = new SpannableString(String.format("%1$s\n%2$s", eventTitle, personsSummary));
    }

    spannableString.setSpan(viewHolder.titleSizeSpan, 0, eventTitle.length(),
            Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
    viewHolder.title.setText(spannableString);
    int bookmarkDrawable = event.isBookmarked() ? R.drawable.ic_small_starred : 0;
    viewHolder.title.setCompoundDrawablesWithIntrinsicBounds(0, 0, bookmarkDrawable, 0);

    viewHolder.trackName.setText(event.getTrack().getTitle());

    Date startTime = event.getStartDate();
    Date endTime = event.getEndDate();

    String startTimeString = (startTime != null) ? TIME_DATE_FORMAT.format(startTime) : "?";
    String endTimeString = (endTime != null) ? TIME_DATE_FORMAT.format(endTime) : "?";
    String details;

    String roomName = event.getTrack().getRoom().getName();
    if (showDay) {
        details = String.format("%1$s, %2$s  %3$s  |  %4$s", event.getTrack().getDay().getName(),
                startTimeString, endTimeString, roomName);
    } else {
        details = String.format("%1$s  %2$s  |  %3$s", startTimeString, endTimeString, roomName);
    }
    viewHolder.details.setText(details);
}

From source file:org.mozilla.gecko.DataReportingNotification.java

/**
 * Launch a notification of the data policy, and record notification time and version.
 *//*  ww w. j av a 2  s.co m*/
private static void notifyDataPolicy(Context context, SharedPreferences sharedPrefs) {
    boolean result = false;
    try {
        // Launch main App to launch Data choices when notification is clicked.
        Intent prefIntent = new Intent(GeckoApp.ACTION_LAUNCH_SETTINGS);
        prefIntent.setClassName(AppConstants.ANDROID_PACKAGE_NAME,
                AppConstants.MOZ_ANDROID_BROWSER_INTENT_CLASS);

        GeckoPreferences.setResourceToOpen(prefIntent, "preferences_vendor");
        prefIntent.putExtra(ALERT_NAME_DATAREPORTING_NOTIFICATION, true);

        PendingIntent contentIntent = PendingIntent.getActivity(context, 0, prefIntent,
                PendingIntent.FLAG_UPDATE_CURRENT);
        final Resources resources = context.getResources();

        // Create and send notification.
        String notificationTitle = resources.getString(R.string.datareporting_notification_title);
        String notificationSummary;
        if (Versions.preJB) {
            notificationSummary = resources.getString(R.string.datareporting_notification_action);
        } else {
            // Display partial version of Big Style notification for supporting devices.
            notificationSummary = resources.getString(R.string.datareporting_notification_summary);
        }
        String notificationAction = resources.getString(R.string.datareporting_notification_action);
        String notificationBigSummary = resources.getString(R.string.datareporting_notification_summary);

        // Make styled ticker text for display in notification bar.
        String tickerString = resources.getString(R.string.datareporting_notification_ticker_text);
        SpannableString tickerText = new SpannableString(tickerString);
        // Bold the notification title of the ticker text, which is the same string as notificationTitle.
        tickerText.setSpan(new StyleSpan(Typeface.BOLD), 0, notificationTitle.length(),
                Spannable.SPAN_INCLUSIVE_EXCLUSIVE);

        Notification notification = new NotificationCompat.Builder(context).setContentTitle(notificationTitle)
                .setContentText(notificationSummary).setSmallIcon(R.drawable.ic_status_logo).setAutoCancel(true)
                .setContentIntent(contentIntent)
                .setStyle(new NotificationCompat.BigTextStyle().bigText(notificationBigSummary))
                .addAction(R.drawable.firefox_settings_alert, notificationAction, contentIntent)
                .setTicker(tickerText).build();

        NotificationManager notificationManager = (NotificationManager) context
                .getSystemService(Context.NOTIFICATION_SERVICE);
        int notificationID = ALERT_NAME_DATAREPORTING_NOTIFICATION.hashCode();
        notificationManager.notify(notificationID, notification);

        // Record version and notification time.
        SharedPreferences.Editor editor = sharedPrefs.edit();
        long now = System.currentTimeMillis();
        editor.putLong(PREFS_POLICY_NOTIFIED_TIME, now);
        editor.putInt(PREFS_POLICY_VERSION, DATA_REPORTING_VERSION);
        editor.apply();
        result = true;
    } finally {
        // We want to track any errors, so record notification outcome.
        Telemetry.sendUIEvent(TelemetryContract.Event.POLICY_NOTIFICATION_SUCCESS, result);
    }
}