Example usage for android.text SpannableString setSpan

List of usage examples for android.text SpannableString setSpan

Introduction

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

Prototype

public void setSpan(Object what, int start, int end, int flags) 

Source Link

Usage

From source file:task.application.com.colette.navigation.AppNavigationViewAsDrawerImpl.java

private void applyFontToMenuItem(MenuItem mi) {
    Typeface font = FontCache.getTypeface("Nunito-SemiBold.ttf", mActivity);
    SpannableString mNewTitle = new SpannableString(mi.getTitle());
    mNewTitle.setSpan(new CustomTypefaceSpan("", font), 0, mNewTitle.length(),
            Spannable.SPAN_INCLUSIVE_INCLUSIVE);
    mi.setTitle(mNewTitle);/*  www  . j  a v a  2 s . c o m*/
}

From source file:com.github.jobs.ui.fragment.JobDetailsFragment.java

@Override
public void onActivityCreated(Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);

    Bundle arguments = getArguments();/*from   w w w  . jav  a2  s  .c  o m*/
    String jobId = arguments.getString(KEY_JOB_ID);
    mJob = new Job();
    mJob.setId(jobId);
    mJob = adapter.findFirst(mJob);
    if (mJob == null) {
        mJob = new Job();
        Toast.makeText(getActivity(), R.string.error_getting_job_info, Toast.LENGTH_LONG).show();
    }
    setHasOptionsMenu(true);

    TextView title = (TextView) getView().findViewById(R.id.title);
    title.setText(StringUtils.trim(mJob.getTitle()));

    TextView description = (TextView) getView().findViewById(R.id.description);
    String jobDescription = mJob.getDescription();
    if (jobDescription != null) {
        description.setText(Html.fromHtml(jobDescription));
        description.setMovementMethod(LinkMovementMethod.getInstance());
    }

    TextView company = (TextView) getView().findViewById(R.id.company);
    company.setText(mJob.getCompany());

    TextView companyUrl = (TextView) getView().findViewById(R.id.company_url);
    if (mJob.getCompanyUrl() == null) {
        companyUrl.setVisibility(View.GONE);
    } else {
        SpannableString content = new SpannableString(mJob.getCompanyUrl());
        content.setSpan(new UnderlineSpan(), 0, content.length(), 0);
        companyUrl.setText(content);
        companyUrl.setOnClickListener(this);
        companyUrl.setVisibility(View.VISIBLE);
    }

    TextView companyLocation = (TextView) getView().findViewById(R.id.company_location);
    if (mJob.getLocation() == null) {
        companyLocation.setVisibility(View.GONE);
    } else {
        companyLocation.setText(mJob.getLocation());
        companyLocation.setVisibility(View.VISIBLE);
    }

    if (!JobDetailsActivity.FULL_TIME.equalsIgnoreCase(mJob.getType())) {
        getView().findViewById(R.id.full_time).setVisibility(View.INVISIBLE);
    }

    mBackground = (ImageView) getView().findViewById(R.id.job_details_background);
    setLogoBackground();
}

From source file:com.android.settings.applications.ClearDefaultsPreference.java

public boolean updateUI(PreferenceViewHolder view) {
    boolean hasBindAppWidgetPermission = mAppWidgetManager
            .hasBindAppWidgetPermission(mAppEntry.info.packageName);

    TextView autoLaunchView = (TextView) view.findViewById(R.id.auto_launch);
    boolean autoLaunchEnabled = AppUtils.hasPreferredActivities(mPm, mPackageName)
            || isDefaultBrowser(mPackageName) || AppUtils.hasUsbDefaults(mUsbManager, mPackageName);
    if (!autoLaunchEnabled && !hasBindAppWidgetPermission) {
        resetLaunchDefaultsUi(autoLaunchView);
    } else {//from   w ww  .  j  a  va2  s .  c  om
        boolean useBullets = hasBindAppWidgetPermission && autoLaunchEnabled;

        if (hasBindAppWidgetPermission) {
            autoLaunchView.setText(R.string.auto_launch_label_generic);
        } else {
            autoLaunchView.setText(R.string.auto_launch_label);
        }

        Context context = getContext();
        CharSequence text = null;
        int bulletIndent = context.getResources()
                .getDimensionPixelSize(R.dimen.installed_app_details_bullet_offset);
        if (autoLaunchEnabled) {
            CharSequence autoLaunchEnableText = context.getText(R.string.auto_launch_enable_text);
            SpannableString s = new SpannableString(autoLaunchEnableText);
            if (useBullets) {
                s.setSpan(new BulletSpan(bulletIndent), 0, autoLaunchEnableText.length(), 0);
            }
            text = (text == null) ? TextUtils.concat(s, "\n") : TextUtils.concat(text, "\n", s, "\n");
        }
        if (hasBindAppWidgetPermission) {
            CharSequence alwaysAllowBindAppWidgetsText = context
                    .getText(R.string.always_allow_bind_appwidgets_text);
            SpannableString s = new SpannableString(alwaysAllowBindAppWidgetsText);
            if (useBullets) {
                s.setSpan(new BulletSpan(bulletIndent), 0, alwaysAllowBindAppWidgetsText.length(), 0);
            }
            text = (text == null) ? TextUtils.concat(s, "\n") : TextUtils.concat(text, "\n", s, "\n");
        }
        autoLaunchView.setText(text);
        mActivitiesButton.setEnabled(true);
    }
    return true;
}

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   www  .  jav  a  2s .  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:com.Duo.music.player.NowPlayingQueueActivity.NowPlayingQueueActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {

    mContext = this;
    sharedPreferences = getSharedPreferences("com.jams.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);/*w  w  w  .jav a 2s. com*/
    } 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.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);//from   w w w  . j  av  a2s .  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:com.csipsimple.utils.contacts.ContacksSearchGridAdapter.java

private boolean highlightTextViewSearch(TextView tv) {
    if (currentFilter.length() > 0) {
        String value = tv.getText().toString();
        int foundIdx = value.toLowerCase().indexOf(currentFilter);
        if (foundIdx >= 0) {
            SpannableString spn = new SpannableString(value);
            spn.setSpan(boldStyle, foundIdx, foundIdx + currentFilter.length(),
                    Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
            spn.setSpan(highlightStyle, foundIdx, foundIdx + currentFilter.length(),
                    Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
            tv.setText(spn);//w ww  .j  a v a  2 s .c  o  m
            return true;
        }
    }
    return false;
}

From source file:com.android.example.notificationshowcase.NotificationService.java

@Override
protected void onHandleIntent(Intent intent) {
    ArrayList<Notification> mNotifications = new ArrayList<Notification>();
    NotificationManager noMa = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);

    int bigtextId = mNotifications.size();
    mNotifications.add(makeBigTextNotification(this, 0, bigtextId, System.currentTimeMillis()));

    int uploadId = mNotifications.size();
    long uploadWhen = System.currentTimeMillis();
    mNotifications.add(makeUploadNotification(this, 10, uploadWhen));

    Notification phoneCall = new NotificationCompat.Builder(this).setContentTitle("Incoming call")
            .setContentText("Matias Duarte").setLargeIcon(getBitmap(this, R.drawable.matias_hed))
            .setSmallIcon(R.drawable.stat_sys_phone_call).setDefaults(Notification.DEFAULT_SOUND)
            .setPriority(NotificationCompat.PRIORITY_MAX)
            .setContentIntent(ToastService.getPendingIntent(this, "Clicked on Matias"))
            .addAction(R.drawable.ic_dial_action_call, "Answer",
                    ToastService.getPendingIntent(this, "call answered"))
            .addAction(R.drawable.ic_end_call, "Ignore", ToastService.getPendingIntent(this, "call ignored"))
            .setAutoCancel(true).build();
    phoneCall.flags |= Notification.FLAG_INSISTENT;
    mNotifications.add(phoneCall);/*from   w  ww  . j  a  v a  2  s.c o m*/

    mNotifications.add(
            new NotificationCompat.Builder(this).setContentTitle("Stopwatch PRO").setContentText("Counting up")
                    .setContentIntent(ToastService.getPendingIntent(this, "Clicked on Stopwatch"))
                    .setSmallIcon(R.drawable.stat_notify_alarm).setUsesChronometer(true).build());

    mNotifications.add(
            new NotificationCompat.Builder(this).setContentTitle("J Planning").setContentText("The Botcave")
                    .setWhen(System.currentTimeMillis()).setSmallIcon(R.drawable.stat_notify_calendar)
                    .setContentIntent(ToastService.getPendingIntent(this, "Clicked on calendar event"))
                    .setContentInfo("7PM")
                    .addAction(R.drawable.stat_notify_snooze, "+10 min",
                            ToastService.getPendingIntent(this, "snoozed 10 min"))
                    .addAction(R.drawable.stat_notify_snooze_longer, "+1 hour",
                            ToastService.getPendingIntent(this, "snoozed 1 hr"))
                    .addAction(R.drawable.stat_notify_email, "Email",
                            makeEmailIntent(this, "gabec@example.com,mcleron@example.com,dsandler@example.com"))
                    .build());

    BitmapDrawable d = (BitmapDrawable) getResources().getDrawable(R.drawable.romainguy_rockaway);
    mNotifications.add(new NotificationCompat.BigPictureStyle(new NotificationCompat.Builder(this)
            .setContentTitle("Romain Guy")
            .setContentText("I was lucky to find a Canon 5D Mk III at a local Bay Area "
                    + "store last week but I had not been able to try it in the field "
                    + "until tonight. After a few days of rain the sky finally cleared "
                    + "up. Rockaway Beach did not disappoint and I was finally able to "
                    + "see what my new camera feels like when shooting landscapes.")
            .setSmallIcon(R.drawable.ic_stat_gplus)
            .setContentIntent(ToastService.getPendingIntent(this, "Clicked on bigPicture"))
            .setLargeIcon(getBitmap(this, R.drawable.romainguy_hed))
            .addAction(R.drawable.add, "Add to Gallery",
                    ToastService.getPendingIntent(this, "added! (just kidding)"))
            .setSubText("talk rocks!")).bigPicture(d.getBitmap()).build());

    // Note: this may conflict with real email notifications
    StyleSpan bold = new StyleSpan(Typeface.BOLD);
    SpannableString line1 = new SpannableString("Alice: hey there!");
    line1.setSpan(bold, 0, 5, 0);
    SpannableString line2 = new SpannableString("Bob: hi there!");
    line2.setSpan(bold, 0, 3, 0);
    SpannableString line3 = new SpannableString("Charlie: Iz IN UR EMAILZ!!");
    line3.setSpan(bold, 0, 7, 0);
    mNotifications.add(new NotificationCompat.InboxStyle(
            new NotificationCompat.Builder(this).setContentTitle("24 new messages")
                    .setContentText("You have mail!").setSubText("test.hugo2@gmail.com")
                    .setContentIntent(ToastService.getPendingIntent(this, "Clicked on Email"))
                    .setSmallIcon(R.drawable.stat_notify_email)).setSummaryText("+21 more").addLine(line1)
                            .addLine(line2).addLine(line3).build());

    mNotifications
            .add(new NotificationCompat.Builder(this).setContentTitle("Twitter").setContentText("New mentions")
                    .setContentIntent(ToastService.getPendingIntent(this, "Clicked on Twitter"))
                    .setSmallIcon(R.drawable.twitter_icon).setNumber(15)
                    .setPriority(NotificationCompat.PRIORITY_LOW).build());

    for (int i = 0; i < mNotifications.size(); i++) {
        noMa.notify(NOTIFICATION_ID + i, mNotifications.get(i));
    }

    ProgressService.startProgressUpdater(this, uploadId, uploadWhen, 0);
}

From source file:com.jbirdvegas.mgerrit.cards.PatchSetPropertiesCard.java

private void setImageCaption(TextView textView, int resID, String authorName) {
    String title = mContext.getResources().getString(resID);
    if (title == null || authorName == null)
        return;//from  w w w  . ja  v a 2 s  .  c om

    SpannableString text = new SpannableString(title + "\n" + authorName);
    text.setSpan(new TextAppearanceSpan(mContext, R.style.CardText_CommitOwnerText), 0, title.length(), 0);

    int end = title.length() + 1;
    text.setSpan(new TextAppearanceSpan(mContext, R.style.CardText_CommitOwnerDetails), end,
            end + authorName.length(), 0);

    textView.setText(text, TextView.BufferType.SPANNABLE);
}

From source file:io.vit.vitio.Settings.SettingsActivity.java

private void setToolbar() {

    toolbar.setBackgroundColor(getResources().getColor(R.color.darkgray));
    setSupportActionBar(toolbar);/*from  w  w w.  j a  va  2s.co  m*/
    SpannableString s = new SpannableString("SETTINGS");
    myTheme.refreshTheme();
    s.setSpan(myTheme.getMyThemeTypeFaceSpan(), 0, s.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
    getSupportActionBar().setTitle(s);
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    toolbar.setNavigationOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            returnBack();

        }
    });
    changeStatusBarColor(getResources().getColor(R.color.darkergray));
}