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.liuwuping.sm.ui.repodetail.RepoDetailActivity.java

@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_repodetail);
    setSupportActionBar(toolbar);/*from www. j ava2  s  . c o  m*/
    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:net.gsantner.opoc.util.ActivityUtils.java

public void showDialogWithHtmlTextView(@StringRes int resTitleId, String text, boolean isHtml,
        DialogInterface.OnDismissListener dismissedListener) {
    ScrollView scroll = new ScrollView(_context);
    AppCompatTextView textView = new AppCompatTextView(_context);
    int padding = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 16,
            _context.getResources().getDisplayMetrics());

    scroll.setPadding(padding, 0, padding, 0);
    scroll.addView(textView);/*from ww  w . j  av  a 2  s  .  co m*/
    textView.setMovementMethod(new LinkMovementMethod());
    textView.setText(isHtml ? new SpannableString(Html.fromHtml(text)) : text);

    AlertDialog.Builder dialog = new AlertDialog.Builder(_context).setPositiveButton(android.R.string.ok, null)
            .setOnDismissListener(dismissedListener).setTitle(resTitleId).setView(scroll);
    dialog.show();
}

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

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    if (fragmentView == null) {
        fragmentView = inflater.inflate(R.layout.group_create_layout, container, false);

        epmtyTextView = (TextView) fragmentView.findViewById(R.id.searchEmptyView);
        userSelectEditText = (EditText) fragmentView.findViewById(R.id.bubble_input_text);
        countTextView = (TextView) fragmentView.findViewById(R.id.bubble_counter_text);
        if (Build.VERSION.SDK_INT >= 11) {
            userSelectEditText.setTextIsSelectable(false);
        }//from w  ww . j a  va2s .  com
        userSelectEditText.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence charSequence, int start, int count, int after) {
                if (!ignoreChange) {
                    beforeChangeIndex = userSelectEditText.getSelectionStart();
                    changeString = new SpannableString(charSequence);
                }
            }

            @Override
            public void onTextChanged(CharSequence charSequence, int i, int i2, int i3) {

            }

            @Override
            public void afterTextChanged(Editable editable) {
                if (!ignoreChange) {
                    boolean search = false;
                    int afterChangeIndex = userSelectEditText.getSelectionEnd();
                    if (editable.toString().length() < changeString.toString().length()) {
                        String deletedString = "";
                        try {
                            deletedString = changeString.toString().substring(afterChangeIndex,
                                    beforeChangeIndex);
                        } catch (Exception e) {
                            FileLog.e("tmessages", e);
                        }
                        if (deletedString.length() > 0) {
                            if (searching && searchWas) {
                                search = true;
                            }
                            Spannable span = userSelectEditText.getText();
                            for (int a = 0; a < allSpans.size(); a++) {
                                Emoji.XImageSpan sp = allSpans.get(a);
                                if (span.getSpanStart(sp) == -1) {
                                    allSpans.remove(sp);
                                    selectedContacts.remove(sp.uid);
                                }
                            }
                            if (selectedContacts.isEmpty()) {
                                doneTextView.setText(getStringEntry(R.string.Done));
                            } else {
                                doneTextView.setText(
                                        getStringEntry(R.string.Done) + " (" + selectedContacts.size() + ")");
                            }
                            countTextView.setText(selectedContacts.size() + "/200");
                            listView.invalidateViews();
                        } else {
                            search = true;
                        }
                    } else {
                        search = true;
                    }
                    if (search) {
                        String text = userSelectEditText.getText().toString().replace("<", "");
                        if (text.length() != 0) {
                            searchDialogs(text);
                            searching = true;
                            searchWas = true;
                            epmtyTextView.setText(getStringEntry(R.string.NoResult));
                            listViewAdapter.notifyDataSetChanged();
                        } else {
                            searchResult = null;
                            searchResultNames = null;
                            searching = false;
                            searchWas = false;
                            epmtyTextView.setText(getStringEntry(R.string.NoContacts));
                            listViewAdapter.notifyDataSetChanged();
                        }
                    }
                }
            }
        });

        listView = (PinnedHeaderListView) fragmentView.findViewById(R.id.listView);
        listView.setEmptyView(epmtyTextView);
        listView.setVerticalScrollBarEnabled(false);

        listView.setAdapter(listViewAdapter = new ListAdapter(parentActivity));
        listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
                TLRPC.User user;
                int section = listViewAdapter.getSectionForPosition(i);
                int row = listViewAdapter.getPositionInSectionForPosition(i);
                if (searching && searchWas) {
                    user = searchResult.get(row);
                } else {
                    ArrayList<TLRPC.TL_contact> arr = ContactsController.Instance.usersSectionsDict
                            .get(ContactsController.Instance.sortedUsersSectionsArray.get(section));
                    user = MessagesController.Instance.users.get(arr.get(row).user_id);
                    listView.invalidateViews();
                }
                if (selectedContacts.containsKey(user.id)) {
                    Emoji.XImageSpan span = selectedContacts.get(user.id);
                    selectedContacts.remove(user.id);
                    SpannableStringBuilder text = new SpannableStringBuilder(userSelectEditText.getText());
                    text.delete(text.getSpanStart(span), text.getSpanEnd(span));
                    allSpans.remove(span);
                    ignoreChange = true;
                    userSelectEditText.setText(text);
                    userSelectEditText.setSelection(text.length());
                    ignoreChange = false;
                } else {
                    if (selectedContacts.size() == 200) {
                        return;
                    }
                    ignoreChange = true;
                    Emoji.XImageSpan span = createAndPutChipForUser(user);
                    span.uid = user.id;
                    ignoreChange = false;
                }
                if (selectedContacts.isEmpty()) {
                    doneTextView.setText(getStringEntry(R.string.Done));
                } else {
                    doneTextView.setText(getStringEntry(R.string.Done) + " (" + selectedContacts.size() + ")");
                }
                countTextView.setText(selectedContacts.size() + "/200");
                if (searching || searchWas) {
                    searching = false;
                    searchWas = false;
                    epmtyTextView.setText(getStringEntry(R.string.NoContacts));

                    ignoreChange = true;
                    SpannableStringBuilder ssb = new SpannableStringBuilder("");
                    for (ImageSpan sp : allSpans) {
                        ssb.append("<<");
                        ssb.setSpan(sp, ssb.length() - 2, ssb.length(),
                                SpannableStringBuilder.SPAN_EXCLUSIVE_EXCLUSIVE);
                    }
                    userSelectEditText.setText(ssb);
                    userSelectEditText.setSelection(ssb.length());
                    ignoreChange = false;

                    listViewAdapter.notifyDataSetChanged();
                } else {
                    listView.invalidateViews();
                }
            }
        });
    } else {
        ViewGroup parent = (ViewGroup) fragmentView.getParent();
        if (parent != null) {
            parent.removeView(fragmentView);
        }
    }
    return fragmentView;
}

From source file:org.mixare.MixListView.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    //      mixCtx = MixView.ctx;
    dataView = MixView.dataView;/*w ww. j  a  v a 2 s .  c om*/
    ctx = this;
    mixContext = dataView.getContext();

    switch (list) {
    case 1:
        adapter = new ListItemAdapter(this);
        //adapter.colorSource(getDataSource());
        getListView().setTextFilterEnabled(true);

        setListAdapter(adapter);
        break;

    case 2:
        selectedItem = new Vector<Marker>();
        listViewMenu = new Vector<SpannableString>();
        DataHandler jLayer = dataView.getDataHandler();
        /*add all marker items to a title and a URL Vector*/
        for (int i = 0; i < jLayer.getMarkerCount(); i++) {
            Marker ma = jLayer.getMarker(i);
            if (ma.isActive()) {
                listViewMenu.add(new SpannableString(ma.getTitle()));
                selectedItem.add(ma);
            }
        }

        if (dataView.isFrozen()) {

            TextView searchNotificationTxt = new TextView(this);
            searchNotificationTxt.setVisibility(View.VISIBLE);
            searchNotificationTxt.setText(getString(DataView.SEARCH_ACTIVE_1) + " "
                    + DataSourceList.getDataSourcesStringList() + getString(DataView.SEARCH_ACTIVE_2));
            searchNotificationTxt.setWidth(MixView.dWindow.getWidth());

            searchNotificationTxt.setPadding(10, 2, 0, 0);
            searchNotificationTxt.setBackgroundColor(Color.DKGRAY);
            searchNotificationTxt.setTextColor(Color.WHITE);

            getListView().addHeaderView(searchNotificationTxt);

        }

        setListAdapter(
                new ArrayAdapter<SpannableString>(this, android.R.layout.simple_list_item_1, listViewMenu));
        getListView().setTextFilterEnabled(true);
        break;
    case 3:
        String addr = this.getIntent().getExtras().getString("address");
        Map<String, Location> locs = DataInterface.getRouteSuggestions(addr);

        suggestionItems = new Vector<String>();
        suggestionLocations = new Vector<Location>();

        for (Map.Entry<String, Location> l : locs.entrySet()) {
            suggestionItems.add(l.getKey());
            suggestionLocations.add(l.getValue());
        }

        setListAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, suggestionItems));
        getListView().setTextFilterEnabled(true);
        break;
    }
}

From source file:com.simplifynowsoftware.flickrdemo.UserFragment.java

public void onClickShowUserInfo(final View v) {
    if (null != mUserData) {
        final Person user = mUserData.getPerson();

        // Assemble user data for display
        SpannableStringBuilder builder = new SpannableStringBuilder();

        StaticUtil.addPairToSpannable(builder, "Real Name", user.getRealname().getContent());
        StaticUtil.addPairToSpannable(builder, "User Name", user.getUsername().getContent());
        StaticUtil.addPairToSpannable(builder, "Profile URL", user.getProfileurl().getContent());
        StaticUtil.addPairToSpannable(builder, "Description", user.getDescription().getContent());

        StaticUtil.showOkAlert(getActivity(), new SpannableString(builder));
    }/*w  w  w.  ja va 2s. c  om*/
}

From source file:com.example.cassi.hal.adapter.CardPresenter.java

private Spannable getSeedAndLeech(T411TorrentItem item) {
    String text = "Seed : " + String.valueOf(item.getSeeders()) + " Leech : "
            + String.valueOf(item.getLeechers());
    Spannable spannable = new SpannableString(text);

    spannable.setSpan(new ForegroundColorSpan(ContextCompat.getColor(mContext, R.color.seedColor)),
            text.indexOf(String.valueOf(item.getSeeders())),
            text.indexOf(String.valueOf(item.getSeeders())) + String.valueOf(item.getSeeders()).length(),
            Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
    spannable.setSpan(new ForegroundColorSpan(ContextCompat.getColor(mContext, R.color.leechColor)),
            text.lastIndexOf(String.valueOf(item.getLeechers())),
            text.lastIndexOf(String.valueOf(item.getLeechers())) + String.valueOf(item.getLeechers()).length(),
            Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);

    return spannable;
}

From source file:com.benext.thibault.appsample.notification.builder.NotificationBuilder.java

public static NotificationCompat.Builder buildNotificationExtenderPages(Context context) {

    ArrayList<Notification> pages = new ArrayList<>();

    // Create first page notification
    Bitmap tableImg = BitmapFactory.decodeResource(context.getResources(), R.drawable.resto);
    Notification page1 = new NotificationCompat.Builder(context).extend(
            new NotificationCompat.WearableExtender().setHintShowBackgroundOnly(true).setBackground(tableImg))
            .build();//from   w  w w.  j ava  2  s  .  c o  m

    pages.add(page1);

    // Create second page notification
    Spannable meatTitle = new SpannableString(context.getString(R.string.menu_meats));
    meatTitle.setSpan(new StyleSpan(android.graphics.Typeface.BOLD), 0, meatTitle.length(),
            Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);

    NotificationCompat.InboxStyle secondPageStyle = new NotificationCompat.InboxStyle();
    secondPageStyle.setBigContentTitle("Page 2").setSummaryText("")
            .addLine(getSpannableString(context, R.string.menu_starters, Typeface.BOLD))
            .addLine(context.getString(R.string.menu_starters_content1))
            .addLine(context.getString(R.string.menu_starters_content2))
            .addLine(getSpannableString(context, R.string.menu_meats, Typeface.BOLD))
            .addLine(context.getString(R.string.menu_meats_content1))
            .addLine(context.getString(R.string.menu_meats_content2));

    Notification page2 = new NotificationCompat.Builder(context)
            .extend(new NotificationCompat.WearableExtender().setBackground(
                    BitmapFactory.decodeResource(context.getResources(), R.drawable.table_restaurant)))
            .setStyle(secondPageStyle).build();

    pages.add(page2);

    // Create builder for the main notification
    Bitmap restoImg = BitmapFactory.decodeResource(context.getResources(), R.drawable.resto);
    return (NotificationCompat.Builder) buildNotificationSimpleNBackground(context)
            .setStyle(new NotificationCompat.BigPictureStyle().bigPicture(restoImg))
            .extend(new NotificationCompat.WearableExtender().addPages(pages));
}

From source file:ca.mymenuapp.ui.activities.RestaurantActivity.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    inflateView(R.layout.activity_restaurant);

    tabStrip.setTextColorResource(android.R.color.white);

    init();//from w w  w . jav a2 s  .  c  o  m
    setupFancyScroll();

    myMenuDatabase.getRestaurantAndMenu(userPreference.get(), restaurantId,
            new EndlessObserver<RestaurantMenu>() {
                @Override
                public void onNext(RestaurantMenu restaurantMenu) {
                    menu = restaurantMenu;
                    setShareIntent(menu);
                    spannableString = new SpannableString(menu.getRestaurant().businessName);
                    picasso.load(menu.getRestaurant().businessPicture).fit().centerCrop()
                            .into(restaurantHeaderLogo);
                    restaurantHeaderBackground.loadImages(picasso, menu.getRandomMenuItem().picture,
                            menu.getRandomMenuItem().picture);
                    pager.setAdapter(new MenuCategoryAdapter(getFragmentManager(), menu));
                    tabStrip.setViewPager(pager);
                }
            });
}

From source file:com.inter.trade.ui.fragment.buylicensekey.BuyLicenseKeyMainFragment.java

private void initView(View view) {
    btn_buy_licensekey = (Button) view.findViewById(R.id.btn_buy_licensekey);
    tv_bind = (TextView) view.findViewById(R.id.tv_bind);

    product_price = (TextView) view.findViewById(R.id.product_price);

    // //from   www.j ava 2s  .  co  m
    SpannableString sp = new SpannableString(product_price.getText().toString());
    sp.setSpan(new StrikethroughSpan(), 0, product_price.getText().length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
    product_price.setText(sp);

    btn_buy_licensekey.setOnClickListener(this);
    tv_bind.setOnClickListener(this);
}

From source file:com.icecream.snorlax.module.feature.encounter.EncounterNotification.java

private Spannable getBoldSpannable(String text) {
    Spannable spannable = new SpannableString(text);
    spannable.setSpan(new StyleSpan(Typeface.BOLD), 0, spannable.length(), Spannable.SPAN_INCLUSIVE_INCLUSIVE);
    return spannable;
}