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:eu.power_switch.widget.activity.ConfigureReceiverWidgetActivity.java

private void saveCurrentConfiguration() {
    try {//w  w  w  .j a va  2 s  . c  o  m
        // First, get the App Widget ID from the Intent that launched the Activity:
        Intent intent = getIntent();
        Bundle extras = intent.getExtras();
        if (extras != null && extras.containsKey(AppWidgetManager.EXTRA_APPWIDGET_ID)) {
            int appWidgetId = extras.getInt(AppWidgetManager.EXTRA_APPWIDGET_ID,
                    AppWidgetManager.INVALID_APPWIDGET_ID);
            // Perform your App Widget configuration:
            Apartment selectedApartment = getSelectedApartment();
            Room selectedRoom = selectedApartment.getRoom(spinnerRoom.getSelectedItem().toString());
            Receiver selectedReceiver = selectedRoom.getReceiver(spinnerReceiver.getSelectedItem().toString());

            // save new widget data to database
            ReceiverWidget receiverWidget = new ReceiverWidget(appWidgetId, selectedRoom.getId(),
                    selectedReceiver.getId());
            DatabaseHandler.addReceiverWidget(receiverWidget);
            // When the configuration is complete, get an instance of
            // the AppWidgetManager by calling getInstance(Context):
            AppWidgetManager appWidgetManager = AppWidgetManager
                    .getInstance(ConfigureReceiverWidgetActivity.this);
            // Update the App Widget with a RemoteViews layout by
            // calling updateAppWidget(int, RemoteViews):
            RemoteViews remoteViews = new RemoteViews(getString(eu.power_switch.shared.R.string.PACKAGE_NAME),
                    R.layout.widget_receiver);

            LinkedList<Button> buttons = selectedReceiver.getButtons();

            remoteViews.setTextViewText(R.id.textView_receiver_widget_name, selectedApartment.getName() + ": "
                    + selectedRoom.getName() + ": " + selectedReceiver.getName());

            int buttonOffset = 0;
            for (Button button : buttons) {
                // set button action
                RemoteViews buttonView = new RemoteViews(
                        getString(eu.power_switch.shared.R.string.PACKAGE_NAME),
                        R.layout.widget_receiver_button_layout);
                SpannableString s = new SpannableString(button.getName());
                s.setSpan(new StyleSpan(Typeface.BOLD), 0, button.getName().length(), 0);
                buttonView.setTextViewText(R.id.button_widget_universal, s);

                if (SmartphonePreferencesHandler.getHighlightLastActivatedButton()
                        && selectedReceiver.getLastActivatedButtonId().equals(button.getId())) {
                    buttonView.setTextColor(R.id.button_widget_universal,
                            ContextCompat.getColor(getApplicationContext(), R.color.color_light_blue_a700));
                }

                PendingIntent pendingIntent = WidgetIntentReceiver.buildReceiverWidgetActionPendingIntent(
                        getApplicationContext(), selectedApartment, selectedRoom, selectedReceiver, button,
                        appWidgetId * 15 + buttonOffset);

                buttonView.setOnClickPendingIntent(R.id.button_widget_universal, pendingIntent);

                remoteViews.addView(R.id.linearlayout_receiver_widget, buttonView);
                buttonOffset++;
            }

            appWidgetManager.updateAppWidget(appWidgetId, remoteViews);

            // Finally, create the return Intent, set it with the
            // Activity result, and finish the Activity:
            Intent resultValue = new Intent();
            resultValue.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
            setResult(RESULT_OK, resultValue);
            finish();
        }
    } catch (Exception e) {
        StatusMessageHandler.showErrorMessage(this, e);
    }
}

From source file:com.playground.notification.app.fragments.AboutDialogFragment.java

@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
    // Get app version
    PackageManager pm = getActivity().getPackageManager();
    String packageName = getActivity().getPackageName();
    String versionName;//from  w  w  w  .ja  v a  2 s.com
    try {
        PackageInfo info = pm.getPackageInfo(packageName, 0);
        versionName = info.versionName;
    } catch (PackageManager.NameNotFoundException e) {
        versionName = VERSION_UNAVAILABLE;
    }

    // About.
    SpannableStringBuilder aboutBody = new SpannableStringBuilder();
    aboutBody.append(
            Html.fromHtml(getString(R.string.about_body, getString(R.string.application_name), versionName)));

    // Licenses.
    SpannableString licensesLink = new SpannableString(getString(R.string.about_licenses));
    licensesLink.setSpan(new ClickableSpan() {
        @Override
        public void onClick(View view) {
            showOpenSourceLicenses(getActivity());
        }
    }, 0, licensesLink.length(), 0);
    aboutBody.append("\n\n");
    aboutBody.append(licensesLink);

    // End User License Agreement.
    SpannableString eulaLink = new SpannableString(getString(R.string.about_eula));
    eulaLink.setSpan(new ClickableSpan() {
        @Override
        public void onClick(View view) {
            showEula(getActivity());
        }
    }, 0, eulaLink.length(), 0);
    aboutBody.append("\n\n");
    aboutBody.append(eulaLink);

    // Show "About" dialog.
    LayoutInflater layoutInflater = (LayoutInflater) getActivity()
            .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    View dialogV = layoutInflater.inflate(R.layout.fragment_dialog_about, null);
    ;
    TextView aboutBodyView = (TextView) dialogV.findViewById(R.id.dialog_text_tv);
    aboutBodyView.setText(aboutBody);
    aboutBodyView.setMovementMethod(new LinkMovementMethod());

    dialogV.findViewById(R.id.powered_by_ll).setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            Utils.openExternalBrowser(getActivity(), "http://" + getString(R.string.support_spielplatz_radar));
        }
    });

    dialogV.findViewById(R.id.weather_by_ll).setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            Utils.openExternalBrowser(getActivity(), "http://" + getString(R.string.support_openweathermap));
        }
    });

    return new AlertDialog.Builder(getActivity()).setTitle(R.string.action_about).setView(dialogV)
            .setPositiveButton(R.string.btn_ok, new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int whichButton) {
                    dialog.dismiss();
                }
            }).create();
}

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

protected static CharSequence buildTickerMessage(Context context, String address, String subject, String body) {
    String displayAddress = Contact.get(address, true).getName();

    StringBuilder buf = new StringBuilder(
            displayAddress == null ? "" : displayAddress.replace('\n', ' ').replace('\r', ' '));
    buf.append(':').append(' ');

    int offset = buf.length();
    if (!TextUtils.isEmpty(subject)) {
        subject = subject.replace('\n', ' ').replace('\r', ' ');
        buf.append(subject);/*from   w w  w .ja  va 2 s .co  m*/
        buf.append(' ');
    }

    if (!TextUtils.isEmpty(body)) {
        body = body.replace('\n', ' ').replace('\r', ' ');
        buf.append(body);
    }

    SpannableString spanText = new SpannableString(buf.toString());
    spanText.setSpan(new StyleSpan(Typeface.BOLD), 0, offset, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);

    return spanText;
}

From source file:crackerjack.education.Indijisites.StartUp.java

private void render(Marker marker, View view) {
    int badge;/*  w w  w  . j  a va 2  s .c o m*/
    if (marker.equals(mBrisbane)) {
        badge = R.drawable.badge_qld;
    } else {
        badge = 0;
    }
    ((ImageView) view.findViewById(R.id.badge)).setImageResource(badge);

    String title = marker.getTitle();
    TextView titleUi = ((TextView) view.findViewById(R.id.title));
    if (title != null) {
        // Spannable string allows us to edit the formatting of the text.
        SpannableString titleText = new SpannableString(title);
        titleText.setSpan(new ForegroundColorSpan(Color.RED), 0, titleText.length(), 0);
        titleUi.setText(titleText);
    } else {
        titleUi.setText("");
    }

    String snippet = marker.getSnippet();
    TextView snippetUi = ((TextView) view.findViewById(R.id.snippet));
    if (snippet != null && snippet.length() > 12) {
        SpannableString snippetText = new SpannableString(snippet);
        snippetText.setSpan(new ForegroundColorSpan(Color.BLUE), 0, snippet.length(), 0);
        snippetUi.setText(snippetText);
    } else {
        snippetUi.setText("");
    }
}

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

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    MenuInflater inflater = getMenuInflater();
    inflater.inflate(R.menu.blacklist_manager, menu);

    ActionBar actionBar = getActionBar();
    actionBar.setBackgroundDrawable(UIElementsHelper.getGeneralActionBarBackground(mContext));
    SpannableString s = new SpannableString(getResources().getString(R.string.blacklist_manager));
    s.setSpan(new TypefaceSpan(this, "RobotoCondensed-Light"), 0, s.length(),
            Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
    actionBar.setTitle(s);//from w  ww .  j av  a 2 s.c om

    return super.onCreateOptionsMenu(menu);
}

From source file:com.liuwuping.sm.ui.repodetail.RepoDetailActivity.java

@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_repodetail);
    setSupportActionBar(toolbar);// ww w  . j  av a 2  s  . c om
    ActionBar bar = getSupportActionBar();
    bar.setDisplayHomeAsUpEnabled(true);
    bar.setDisplayShowHomeEnabled(true);
    bar.setDisplayShowTitleEnabled(false);
    bar.setHomeButtonEnabled(true);

    Bundle bundle = getIntent().getExtras();
    repo = (Repo) bundle.get("repo");
    String[] names = repo.getFull_name().split("/");
    login = names[0];
    repoName = names[1];

    appBar.addOnOffsetChangedListener(new AppBarLayout.OnOffsetChangedListener() {
        boolean isShow = false;
        int scrollRange = -1;

        @Override
        public void onOffsetChanged(AppBarLayout appBarLayout, int verticalOffset) {
            if (scrollRange == -1) {
                scrollRange = appBarLayout.getTotalScrollRange();
            }
            if (scrollRange + verticalOffset == 0) {
                collapsingToolbarLayout.setTitle(repoName);
                isShow = true;
            } else if (isShow) {
                collapsingToolbarLayout.setTitle("");
                isShow = false;
            }

        }
    });

    repoNameTv.setText(repoName);
    SpannableString spannableString = new SpannableString(login);
    spannableString.setSpan(new UnderlineSpan(), 0, login.length(), 0);
    repoOwnerTv.setText(spannableString);
    starTv.setText(String.valueOf(repo.getStargazers_count()));
    forkTv.setText(String.valueOf(repo.getForks()));
    issueTv.setText(String.valueOf(repo.getOpen_issues()));

    recyclerView.setLayoutManager(new LinearLayoutManager(this));
    SimpleDividerDecoration decoration = new SimpleDividerDecoration(this);
    recyclerView.addItemDecoration(decoration);
    recyclerView.setHasFixedSize(true);
    adapter = new TagAdapter();
    recyclerView.setAdapter(adapter);
    RecyclerItemClickSupport.addTo(recyclerView)
            .setOnItemClickListener(new RecyclerItemClickSupport.OnItemClickListener() {
                @Override
                public void onItemClicked(RecyclerView recyclerView, int position, View v) {
                    Tag tag = tagList.get(position);
                    repo.setTagId(tag.getId());
                    presenter.addRepoToTag(repo);

                }
            });

    presenter = new RepoDetailPresenter(this);
    presenter.getReadMeUrl(login, repoName);
    presenter.getAvatarUrl(login);
    presenter.isStar(login, repoName);
    presenter.loadTags();

    webView.getSettings().setJavaScriptEnabled(true);
    webView.setWebViewClient(new WebViewClient() {
        @Override
        public void onPageFinished(WebView view, String url) {
            super.onPageFinished(view, url);
            webViewProgressBar.setVisibility(View.INVISIBLE);
        }
    });

}

From source file:app.philm.in.AndroidDisplay.java

private CharSequence convertToCondensed(final CharSequence string) {
    if (TextUtils.isEmpty(string)) {
        return string;
    }// w w w. j  a v  a  2 s  .  c  om

    SpannableString s = new SpannableString(string);
    s.setSpan(mDefaultTitleSpan, 0, s.length(), Spannable.SPAN_INCLUSIVE_INCLUSIVE);
    return s;
}

From source file:info.guardianproject.otr.app.im.app.ContactView.java

public void bind(Cursor cursor, String underLineText, boolean showChatMsg, boolean scrolling) {

    mHolder = (ViewHolder) getTag();// ww  w .  ja va2 s. c o m

    long providerId = cursor.getLong(COLUMN_CONTACT_PROVIDER);
    String address = cursor.getString(COLUMN_CONTACT_USERNAME);
    String nickname = cursor.getString(COLUMN_CONTACT_NICKNAME);
    int type = cursor.getInt(COLUMN_CONTACT_TYPE);
    String statusText = cursor.getString(COLUMN_CONTACT_CUSTOM_STATUS);
    String lastMsg = cursor.getString(COLUMN_LAST_MESSAGE);

    int presence = cursor.getInt(COLUMN_CONTACT_PRESENCE_STATUS);

    if (!TextUtils.isEmpty(underLineText)) {
        // highlight/underline the word being searched
        String lowercase = nickname.toLowerCase();
        int start = lowercase.indexOf(underLineText.toLowerCase());
        if (start >= 0) {
            int end = start + underLineText.length();
            SpannableString str = new SpannableString(nickname);
            str.setSpan(new UnderlineSpan(), start, end, Spannable.SPAN_INCLUSIVE_INCLUSIVE);

            mHolder.mLine1.setText(str);

        } else
            mHolder.mLine1.setText(nickname);

    } else
        mHolder.mLine1.setText(nickname);

    if (mHolder.mAvatar != null) {
        if (Imps.Contacts.TYPE_GROUP == type) {
            mHolder.mAvatar.setImageResource(R.drawable.group_chat);

        } else {

            Drawable avatar = DatabaseUtils.getAvatarFromCursor(cursor, COLUMN_AVATAR_DATA,
                    ImApp.DEFAULT_AVATAR_WIDTH, ImApp.DEFAULT_AVATAR_HEIGHT);

            if (avatar != null)
                mHolder.mAvatar.setImageDrawable(avatar);
            else
                mHolder.mAvatar.setImageDrawable(mAvatarUnknown);
        }
    }

    if (showChatMsg && lastMsg != null) {

        if (mHolder.mAvatar != null) {
            setBackgroundResource(R.color.holo_blue_bright);
            mHolder.mLine1.setBackgroundColor(getResources().getColor(R.color.holo_blue_bright));
            mHolder.mLine1.setTextColor(Color.WHITE);
        } else if (mHolder.mStatusBlock != null) {
            mHolder.mStatusBlock.setBackgroundColor(getResources().getColor(R.color.holo_blue_bright));

        }

        if (mHolder.mLine2 != null)
            mHolder.mLine2.setText(android.text.Html.fromHtml(lastMsg).toString());

    } else {
        if (mHolder.mLine2 != null) {

            if (statusText == null || statusText.length() == 0) {

                if (Imps.Contacts.TYPE_GROUP == type) {
                    statusText = mContext.getString(R.string.menu_new_group_chat);
                } else {
                    ImApp app = ((ImApp) ((Activity) mContext).getApplication());
                    BrandingResources brandingRes = app.getBrandingResource(providerId);
                    statusText = brandingRes.getString(PresenceUtils.getStatusStringRes(presence));
                }
            }

            mHolder.mLine2.setText(statusText);

        }

        if (presence == Imps.Presence.AVAILABLE) {
            if (mHolder.mAvatar != null) {
                setBackgroundColor(getResources().getColor(R.color.holo_green_light));
                mHolder.mLine1.setBackgroundColor(getResources().getColor(R.color.holo_green_dark));
                mHolder.mLine1.setTextColor(getResources().getColor(R.color.contact_status_fg_light));
            } else if (mHolder.mStatusBlock != null) {
                mHolder.mStatusBlock.setBackgroundColor(getResources().getColor(R.color.holo_green_light));

            }

        } else if (presence == Imps.Presence.AWAY || presence == Imps.Presence.IDLE) {
            if (mHolder.mAvatar != null) {
                setBackgroundColor(getResources().getColor(R.color.holo_orange_light));
                mHolder.mLine1.setBackgroundColor(getResources().getColor(R.color.holo_orange_dark));
                mHolder.mLine1.setTextColor(getResources().getColor(R.color.contact_status_fg_light));
            } else if (mHolder.mStatusBlock != null) {
                mHolder.mStatusBlock.setBackgroundColor(getResources().getColor(R.color.holo_orange_light));

            }

        } else if (presence == Imps.Presence.DO_NOT_DISTURB) {
            if (mHolder.mAvatar != null) {
                setBackgroundColor(getResources().getColor(R.color.holo_red_light));
                mHolder.mLine1.setBackgroundColor(getResources().getColor(R.color.holo_red_dark));
                mHolder.mLine1.setTextColor(getResources().getColor(R.color.contact_status_fg_light));
            } else if (mHolder.mStatusBlock != null) {
                mHolder.mStatusBlock.setBackgroundColor(getResources().getColor(R.color.holo_red_light));

            }
        } else {
            if (mHolder.mAvatar != null) {
                setBackgroundColor(Color.LTGRAY);
                mHolder.mLine1.setBackgroundColor(Color.LTGRAY);
            } else if (mHolder.mStatusBlock != null) {
                mHolder.mStatusBlock.setBackgroundColor(Color.LTGRAY);

            }
        }

    }

}

From source file:net.yoching.android.MainActivity.java

private void setupDrawer() {
    mDrawerToggle = new ActionBarDrawerToggle(this, mDrawerLayout, R.string.drawer_open,
            R.string.drawer_close) {/* w w w .j  av  a 2  s.  c  o m*/

        /** Called when a drawer has settled in a completely open state. */
        public void onDrawerOpened(View drawerView) {
            super.onDrawerOpened(drawerView);

            SpannableString s = new SpannableString("64 WREXAGRAMS");
            s.setSpan(new TypefaceSpan("Exo-Bold.otf"), 0, s.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
            getSupportActionBar().setTitle(s);

            // invalidateOptionsMenu(); // creates call to onPrepareOptionsMenu()
        }

        /** Called when a drawer has settled in a completely closed state. */
        public void onDrawerClosed(View view) {
            super.onDrawerClosed(view);
            getSupportActionBar().setTitle(mActivityTitle);
            //   invalidateOptionsMenu(); // creates call to onPrepareOptionsMenu()

        }
    };

    mDrawerToggle.setDrawerIndicatorEnabled(true);
    mDrawerLayout.setDrawerListener(mDrawerToggle);
}

From source file:app.philm.in.AndroidDisplay.java

private CharSequence convertToCondensed(final CharSequence string, int color) {
    if (TextUtils.isEmpty(string)) {
        return string;
    }/* w  ww .ja  va 2  s  .c  o  m*/

    SpannableString s = new SpannableString(string);
    s.setSpan(new PhilmTypefaceSpan(mActivity, FontTextView.FONT_ROBOTO_CONDENSED, color), 0, s.length(),
            Spannable.SPAN_INCLUSIVE_INCLUSIVE);
    return s;
}