Example usage for android.text SpannableString length

List of usage examples for android.text SpannableString length

Introduction

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

Prototype

int length();

Source Link

Document

Returns the length of this character sequence.

Usage

From source file:com.github.socialc0de.gsw.android.MainActivity.java

private void fillLayout() {
    SpannableString s = new SpannableString(getString(R.string.app_name));
    s.setSpan(new com.github.socialc0de.gsw.android.TypefaceSpan(getApplicationContext(), "fabiolo.otf"), 0,
            s.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
    ((Toolbar) findViewById(R.id.app_bar)).setTitle(s);
    mTinyDB = new TinyDB(this);
    loadCategories();//w w w.  j a  va 2  s. c  o m
    loadAccount();
    if (mDrawer != null && mFragments != null) {
        for (int i = 0; i < mFragments.size(); i++) {
            mDrawer.removeItem(i);
        }
    }

    //create the drawer and remember the `Drawer` result object

    headerResult = new AccountHeaderBuilder().withActivity(this).withHeaderBackground(R.drawable.productback)
            .withOnAccountHeaderListener(new AccountHeader.OnAccountHeaderListener() {
                @Override
                public boolean onProfileChanged(View view, IProfile profile, boolean currentProfile) {
                    return false;
                }
            }).withSelectionListEnabledForSingleProfile(false).build();

    mFragments.clear();

    mFragments.add(new LocalFragment(this));
    mFragments.add(new CategoryFragment(this));
    mFragments.add(new ProfileFragment());
    mFragments.add(new PhraseFragment());
    mFragments.add(new FAQFragment());
    mFragments.add(new AuthorityMapFragment());
    mFragments.add(new DonateFragment());
    mFragments.add(new AboutFragment());

    if (mDrawer == null) {
        mDrawer = new DrawerBuilder().withActivity(this).withToolbar((Toolbar) findViewById(R.id.app_bar))
                .withActionBarDrawerToggle(true).withAccountHeader(headerResult)
                .addDrawerItems(
                        new PrimaryDrawerItem().withName(R.string.sharing_local)
                                .withIcon(R.drawable.ic_place_black_36dp),
                        new PrimaryDrawerItem().withName(R.string.sharing_categories)
                                .withIcon(R.drawable.ic_view_day_black_36dp),
                        new PrimaryDrawerItem().withName(R.string.profile)
                                .withIcon(R.drawable.ic_assignment_ind_black_36dp),
                        new PrimaryDrawerItem().withName(R.string.phrasebook)
                                .withIcon(R.drawable.ic_translate_black_36dp),
                        new PrimaryDrawerItem().withName(R.string.faq)
                                .withIcon(R.drawable.ic_question_answer_black_36dp),
                        new PrimaryDrawerItem().withName(R.string.authority_map)
                                .withIcon(R.drawable.ic_map_black_36dp),
                        new PrimaryDrawerItem().withName(R.string.donate)
                                .withIcon(R.drawable.ic_attach_money_black_36dp),
                        new PrimaryDrawerItem().withName(R.string.about)
                                .withIcon(R.drawable.ic_info_black_36dp))
                .withOnDrawerItemClickListener(new Drawer.OnDrawerItemClickListener() {
                    @Override
                    public boolean onItemClick(View view, int position, IDrawerItem drawerItem) {
                        // do something with the clicked item :D
                        if (getSupportFragmentManager().findFragmentByTag(
                                mFragments.get(position - 1).getClass().getSimpleName()) != null)
                            return false;
                        getSupportFragmentManager().popBackStack(null,
                                FragmentManager.POP_BACK_STACK_INCLUSIVE);
                        getSupportFragmentManager().beginTransaction()
                                .replace(R.id.container, mFragments.get(position - 1),
                                        mFragments.get(position - 1).getClass().getSimpleName())
                                .addToBackStack(null).commit();

                        // closes Drawer
                        return false;
                    }
                }).build();
    }

    getSupportFragmentManager().beginTransaction().replace(R.id.container, mFragments.get(0)).commit();
}

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

private CharSequence formatPresenceUpdates(String contact, int type, boolean isGroupChat, boolean scrolling) {
    String body;/*from  w  ww . ja v  a 2  s.  c o m*/

    Resources resources = getResources();

    switch (type) {
    case Imps.MessageType.PRESENCE_AVAILABLE:
        body = resources.getString(isGroupChat ? R.string.contact_joined : R.string.contact_online, contact);
        break;

    case Imps.MessageType.PRESENCE_AWAY:
        body = resources.getString(R.string.contact_away, contact);
        break;

    case Imps.MessageType.PRESENCE_DND:
        body = resources.getString(R.string.contact_busy, contact);
        break;

    case Imps.MessageType.PRESENCE_UNAVAILABLE:
        body = resources.getString(isGroupChat ? R.string.contact_left : R.string.contact_offline, contact);
        break;

    default:
        return null;
    }

    if (scrolling) {
        return body;
    } else {
        SpannableString spanText = new SpannableString(body);
        int len = spanText.length();
        spanText.setSpan(new StyleSpan(Typeface.ITALIC), 0, len, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
        spanText.setSpan(new RelativeSizeSpan((float) 0.8), 0, len, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
        return spanText;
    }
}

From source file:com.darly.im.ui.CCPActivityBase.java

/**
 *
 *///from  www.  j av  a  2s .co m
protected SpannableString buildActionTitle() {
    int dimensionPixelSize = mActionBarActivity.getResources().getDimensionPixelSize(R.dimen.BigTextSize);

    int mutIndex = 0;
    String format = "%s";
    if (isMute) {
        format = format + " #";
        mutIndex += 2;
    }

    SpannableString spannableString = EmoticonUtil.getTextFormat(mActionBarActivity,
            String.format(format, new Object[] { mTitleText }), dimensionPixelSize);
    if (isMute) {
        if (mMuteIcon == null) {
            mMuteIcon = getTitleIconTips(dimensionPixelSize, R.drawable.chat_mute_notify_title_icon);
        }
        int length = spannableString.length() - mutIndex + 1;
        spannableString.setSpan(mMuteIcon, length, length + 1, Spanned.SPAN_POINT_MARK);
    }
    return spannableString;
}

From source file:org.mariotaku.twidere.view.holder.ActivityTitleSummaryViewHolder.java

public void displayActivity(ParcelableActivity activity, boolean byFriends) {
    final Context context = adapter.getContext();
    final Resources resources = adapter.getContext().getResources();
    switch (activity.action) {
    case Activity.ACTION_FOLLOW: {
        activityTypeView.setImageResource(R.drawable.ic_activity_action_follow);
        activityTypeView.setColorFilter(ContextCompat.getColor(context, R.color.highlight_follow),
                Mode.SRC_ATOP);//from  w  w  w .j ava  2s  .c  o m
        if (byFriends) {
            titleView.setText(getTitleStringByFriends(R.string.activity_by_friends_follow,
                    R.string.activity_by_friends_follow_multi, activity.sources, activity.target_users));
        } else {
            titleView.setText(getTitleStringAboutMe(R.string.activity_about_me_follow,
                    R.string.activity_about_me_follow_multi, activity.sources));
        }
        displayUserProfileImages(activity.sources);
        summaryView.setVisibility(View.GONE);
        break;
    }
    case Activity.ACTION_FAVORITE: {
        if (adapter.shouldUseStarsForLikes()) {
            activityTypeView.setImageResource(R.drawable.ic_activity_action_favorite);
            activityTypeView.setColorFilter(ContextCompat.getColor(context, R.color.highlight_favorite),
                    Mode.SRC_ATOP);

            if (byFriends) {
                titleView.setText(getTitleStringByFriends(R.string.activity_by_friends_favorite,
                        R.string.activity_by_friends_favorite_multi, activity.sources,
                        activity.target_statuses));
            } else {
                titleView.setText(getTitleStringAboutMe(R.string.activity_about_me_favorite,
                        R.string.activity_about_me_favorite_multi, activity.sources));
            }
        } else {
            activityTypeView.setImageResource(R.drawable.ic_activity_action_like);
            activityTypeView.setColorFilter(ContextCompat.getColor(context, R.color.highlight_like),
                    Mode.SRC_ATOP);

            if (byFriends) {
                titleView.setText(getTitleStringByFriends(R.string.activity_by_friends_like,
                        R.string.activity_by_friends_like_multi, activity.sources, activity.target_statuses));
            } else {
                titleView.setText(getTitleStringAboutMe(R.string.activity_about_me_like,
                        R.string.activity_about_me_like_multi, activity.sources));
            }
        }
        displayUserProfileImages(activity.sources);
        summaryView.setText(activity.target_statuses[0].text_unescaped);
        summaryView.setVisibility(View.VISIBLE);
        break;
    }
    case Activity.ACTION_RETWEET: {
        activityTypeView.setImageResource(R.drawable.ic_activity_action_retweet);
        activityTypeView.setColorFilter(ContextCompat.getColor(context, R.color.highlight_retweet),
                Mode.SRC_ATOP);
        if (byFriends) {
            titleView.setText(getTitleStringByFriends(R.string.activity_by_friends_retweet,
                    R.string.activity_by_friends_retweet_multi, activity.sources, activity.target_statuses));
        } else
            titleView.setText(getTitleStringAboutMe(R.string.activity_about_me_retweet,
                    R.string.activity_about_me_retweet_multi, activity.sources));
        displayUserProfileImages(activity.sources);
        summaryView.setText(activity.target_statuses[0].text_unescaped);
        summaryView.setVisibility(View.VISIBLE);
        break;
    }
    case Activity.ACTION_FAVORITED_RETWEET: {
        if (byFriends) {
            showNotSupported();
            return;
        }
        if (adapter.shouldUseStarsForLikes()) {
            activityTypeView.setImageResource(R.drawable.ic_activity_action_favorite);
            activityTypeView.setColorFilter(ContextCompat.getColor(context, R.color.highlight_favorite),
                    Mode.SRC_ATOP);
            titleView.setText(getTitleStringAboutMe(R.string.activity_about_me_favorited_retweet,
                    R.string.activity_about_me_favorited_retweet_multi, activity.sources));
        } else {
            activityTypeView.setImageResource(R.drawable.ic_activity_action_like);
            activityTypeView.setColorFilter(ContextCompat.getColor(context, R.color.highlight_like),
                    Mode.SRC_ATOP);
            titleView.setText(getTitleStringAboutMe(R.string.activity_about_me_liked_retweet,
                    R.string.activity_about_me_liked_retweet_multi, activity.sources));
        }
        displayUserProfileImages(activity.sources);
        summaryView.setText(activity.target_statuses[0].text_unescaped);
        summaryView.setVisibility(View.VISIBLE);
        break;
    }
    case Activity.ACTION_RETWEETED_RETWEET: {
        if (byFriends) {
            showNotSupported();
            return;
        }
        activityTypeView.setImageResource(R.drawable.ic_activity_action_retweet);
        activityTypeView.setColorFilter(ContextCompat.getColor(context, R.color.highlight_retweet),
                Mode.SRC_ATOP);
        titleView.setText(getTitleStringAboutMe(R.string.activity_about_me_retweeted_retweet,
                R.string.activity_about_me_retweeted_retweet_multi, activity.sources));
        displayUserProfileImages(activity.sources);
        summaryView.setText(activity.target_statuses[0].text_unescaped);
        summaryView.setVisibility(View.VISIBLE);
        break;
    }
    case Activity.ACTION_RETWEETED_MENTION: {
        if (byFriends) {
            showNotSupported();
            return;
        }
        activityTypeView.setImageResource(R.drawable.ic_activity_action_retweet);
        activityTypeView.setColorFilter(ContextCompat.getColor(context, R.color.highlight_retweet),
                Mode.SRC_ATOP);
        titleView.setText(getTitleStringAboutMe(R.string.activity_about_me_retweeted_mention,
                R.string.activity_about_me_retweeted_mention_multi, activity.sources));
        displayUserProfileImages(activity.sources);
        summaryView.setText(activity.target_statuses[0].text_unescaped);
        summaryView.setVisibility(View.VISIBLE);
        break;
    }
    case Activity.ACTION_FAVORITED_MENTION: {
        if (byFriends) {
            showNotSupported();
            return;
        }
        if (adapter.shouldUseStarsForLikes()) {
            activityTypeView.setImageResource(R.drawable.ic_activity_action_favorite);
            activityTypeView.setColorFilter(ContextCompat.getColor(context, R.color.highlight_favorite),
                    Mode.SRC_ATOP);
            titleView.setText(getTitleStringAboutMe(R.string.activity_about_me_favorited_mention,
                    R.string.activity_about_me_favorited_mention_multi, activity.sources));
        } else {
            activityTypeView.setImageResource(R.drawable.ic_activity_action_like);
            activityTypeView.setColorFilter(ContextCompat.getColor(context, R.color.highlight_like),
                    Mode.SRC_ATOP);
            titleView.setText(getTitleStringAboutMe(R.string.activity_about_me_liked_mention,
                    R.string.activity_about_me_liked_mention_multi, activity.sources));
        }
        displayUserProfileImages(activity.sources);
        summaryView.setText(activity.target_statuses[0].text_unescaped);
        summaryView.setVisibility(View.VISIBLE);
        break;
    }
    case Activity.ACTION_LIST_CREATED: {
        if (!byFriends) {
            showNotSupported();
            return;
        }
        activityTypeView.setImageResource(R.drawable.ic_activity_action_list_added);
        activityTypeView.setColorFilter(activityTypeView.getDefaultColor(), Mode.SRC_ATOP);
        titleView.setText(getTitleStringByFriends(R.string.activity_by_friends_list_created,
                R.string.activity_by_friends_list_created_multi, activity.sources,
                activity.target_object_user_lists));
        displayUserProfileImages(activity.sources);
        boolean firstLine = true;
        summaryView.setText("");
        for (ParcelableUserList item : activity.target_object_user_lists) {
            if (!firstLine) {
                summaryView.append("\n");
            }
            summaryView.append(item.description);
            firstLine = false;
        }
        summaryView.setVisibility(View.VISIBLE);
        break;
    }
    case Activity.ACTION_LIST_MEMBER_ADDED: {
        if (byFriends) {
            showNotSupported();
            return;
        }
        activityTypeView.setImageResource(R.drawable.ic_activity_action_list_added);
        activityTypeView.setColorFilter(activityTypeView.getDefaultColor(), Mode.SRC_ATOP);
        if (activity.sources.length == 1 && activity.target_object_user_lists != null
                && activity.target_object_user_lists.length == 1) {
            final UserColorNameManager manager = adapter.getUserColorNameManager();
            final SpannableString firstDisplayName = new SpannableString(
                    manager.getDisplayName(activity.sources[0], adapter.isNameFirst(), false));
            final SpannableString listName = new SpannableString(activity.target_object_user_lists[0].name);
            firstDisplayName.setSpan(new StyleSpan(Typeface.BOLD), 0, firstDisplayName.length(),
                    Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
            listName.setSpan(new StyleSpan(Typeface.BOLD), 0, listName.length(),
                    Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
            final String format = context.getString(R.string.activity_about_me_list_member_added_with_name);
            final Configuration configuration = resources.getConfiguration();
            titleView.setText(SpanFormatter.format(configuration.locale, format, firstDisplayName, listName));
        } else {
            titleView.setText(getTitleStringAboutMe(R.string.activity_about_me_list_member_added,
                    R.string.activity_about_me_list_member_added_multi, activity.sources));
        }
        displayUserProfileImages(activity.sources);
        summaryView.setVisibility(View.GONE);
        break;
    }
    }
}

From source file:liqui.droid.activity.Base.java

/**
 * Creates the breadcrumb.// ww  w. j av a 2s  . c o  m
 *
 * @param subTitle the sub title
 * @param breadCrumbHolders the bread crumb holders
 */
public void createBreadcrumb(String subTitle, BreadCrumbHolder... breadCrumbHolders) {
    if (breadCrumbHolders != null) {
        LinearLayout llPart = (LinearLayout) this.findViewById(R.id.ll_part);
        for (int i = 0; i < breadCrumbHolders.length; i++) {
            TextView tvBreadCrumb = new TextView(getApplication());
            SpannableString part = new SpannableString(breadCrumbHolders[i].getLabel());
            part.setSpan(new UnderlineSpan(), 0, part.length(), 0);
            tvBreadCrumb.append(part);
            tvBreadCrumb.setTag(breadCrumbHolders[i]);
            tvBreadCrumb.setBackgroundResource(R.drawable.default_link);
            tvBreadCrumb.setTextAppearance(getApplication(), R.style.default_text_small);
            tvBreadCrumb.setSingleLine(true);
            tvBreadCrumb.setOnClickListener(new OnClickBreadCrumb(this));

            llPart.addView(tvBreadCrumb);

            if (i < breadCrumbHolders.length - 1) {
                TextView slash = new TextView(getApplication());
                slash.setText(" / ");
                slash.setTextAppearance(getApplication(), R.style.default_text_small);
                llPart.addView(slash);
            }
        }
    }

    ScrollingTextView tvSubtitle = (ScrollingTextView) this.findViewById(R.id.tv_subtitle);
    tvSubtitle.setText(subTitle);
}

From source file:org.tlhInganHol.android.klingonassistant.BaseActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    if (savedInstanceState != null) {
        mActivePosition = savedInstanceState.getInt(STATE_ACTIVE_POSITION);
    }/* www .ja  v  a  2 s  . co  m*/

    // Close the floating window, if there is one. Work around a race condition.
    Log.d(TAG, "Starting activity with non-floating window. Close floating window.");
    Handler killFloatingWindowHandler = new Handler();
    Runnable killFloatingWindowRunnable = new Runnable() {
        public void run() {
            StandOutWindow.closeAll(BaseActivity.this, FloatingWindow.class);
        }
    };
    killFloatingWindowHandler.postDelayed(killFloatingWindowRunnable, 100); // 100 ms

    // Get the action bar.
    ActionBar actionBar = getSupportActionBar();
    actionBar.setDisplayHomeAsUpEnabled(true);

    SharedPreferences sharedPrefs = PreferenceManager.getDefaultSharedPreferences(getBaseContext());
    if (sharedPrefs.getBoolean(Preferences.KEY_KLINGON_FONT_CHECKBOX_PREFERENCE, /* default */false)) {
        // Display the action bar title in Klingon font.
        SpannableString title = new SpannableString("?");
        Typeface klingonTypeface = KlingonAssistant.getKlingonFontTypeface(getBaseContext());
        title.setSpan(new KlingonTypefaceSpan("", klingonTypeface), 0, title.length(),
                Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
        actionBar.setTitle(title);
    }

    // If the device is in landscape orientation and the screen size is large (or bigger), then
    // make the slide-out menu static. Otherwise, hide it by default.
    MenuDrawer.Type drawerType = MenuDrawer.Type.BEHIND;
    if (isHorizontalTablet()) {
        drawerType = MenuDrawer.Type.STATIC;
    }
    mDrawer = MenuDrawer.attach(this, drawerType, Position.LEFT, MenuDrawer.MENU_DRAG_CONTENT);

    List<Object> items = new ArrayList<Object>();
    if (sharedPrefs.getBoolean(Preferences.KEY_KLINGON_UI_CHECKBOX_PREFERENCE, /* default */false)) {
        items.add(new SlideMenuCategory(R.string.menu_reference_tlh));
        items.add(new SlideMenuItem(R.string.menu_pronunciation_tlh, R.id.pronunciation, 0));
        items.add(new SlideMenuItem(R.string.menu_prefixes_tlh, R.id.prefixes, 0));
        items.add(new SlideMenuItem(R.string.menu_prefix_charts_tlh, R.id.prefix_charts, 0));
        items.add(new SlideMenuItem(R.string.menu_noun_suffixes_tlh, R.id.noun_suffixes, 0));
        items.add(new SlideMenuItem(R.string.menu_verb_suffixes_tlh, R.id.verb_suffixes, 0));
        items.add(new SlideMenuCategory(R.string.menu_phrases_tlh));
        items.add(new SlideMenuItem(R.string.beginners_conversation_tlh, R.id.beginners_conversation, 0));
        items.add(new SlideMenuItem(R.string.jokes_tlh, R.id.jokes, 0));
        items.add(new SlideMenuItem(R.string.nentay_tlh, R.id.nentay, 0));
        items.add(new SlideMenuItem(R.string.military_celebration_tlh, R.id.military_celebration, 0));
        items.add(new SlideMenuItem(R.string.toasts_tlh, R.id.toasts, 0));
        items.add(new SlideMenuItem(R.string.lyrics_tlh, R.id.lyrics, 0));
        items.add(new SlideMenuItem(R.string.curse_warfare_tlh, R.id.curse_warfare, 0));
        items.add(new SlideMenuItem(R.string.replacement_proverbs_tlh, R.id.replacement_proverbs, 0));
        items.add(new SlideMenuItem(R.string.secrecy_proverbs_tlh, R.id.secrecy_proverbs, 0));
        items.add(new SlideMenuItem(R.string.empire_union_day_tlh, R.id.empire_union_day, 0));
        items.add(new SlideMenuItem(R.string.rejection_tlh, R.id.rejection, 0));
        items.add(new SlideMenuCategory(R.string.menu_media_tlh));
        items.add(new SlideMenuItem(R.string.media_1_title_tlh, R.id.media_1, 0));
        items.add(new SlideMenuItem(R.string.media_2_title_tlh, R.id.media_2, 0));
        items.add(new SlideMenuItem(R.string.media_3_title_tlh, R.id.media_3, 0));
        items.add(new SlideMenuItem(R.string.media_4_title_tlh, R.id.media_4, 0));
        items.add(new SlideMenuItem(R.string.media_5_title_tlh, R.id.media_5, 0));
        items.add(new SlideMenuItem(R.string.media_6_title_tlh, R.id.media_6, 0));
        /*
        items.add(new SlideMenuCategory(R.string.menu_social_tlh));
        items.add(new SlideMenuItem(R.string.menu_gplus_tlh, R.id.gplus, 0));
        items.add(new SlideMenuItem(R.string.menu_facebook_tlh, R.id.facebook, 0));
        items.add(new SlideMenuItem(R.string.menu_kag_tlh, R.id.kag, 0));
        items.add(new SlideMenuItem(R.string.menu_kidc_tlh, R.id.kidc, 0));
        */
    } else {
        items.add(new SlideMenuCategory(R.string.menu_reference));
        items.add(new SlideMenuItem(R.string.menu_pronunciation, R.id.pronunciation, 0));
        items.add(new SlideMenuItem(R.string.menu_prefixes, R.id.prefixes, 0));
        items.add(new SlideMenuItem(R.string.menu_prefix_charts, R.id.prefix_charts, 0));
        items.add(new SlideMenuItem(R.string.menu_noun_suffixes, R.id.noun_suffixes, 0));
        items.add(new SlideMenuItem(R.string.menu_verb_suffixes, R.id.verb_suffixes, 0));
        items.add(new SlideMenuCategory(R.string.menu_phrases));
        items.add(new SlideMenuItem(R.string.beginners_conversation, R.id.beginners_conversation, 0));
        items.add(new SlideMenuItem(R.string.jokes, R.id.jokes, 0));
        items.add(new SlideMenuItem(R.string.nentay, R.id.nentay, 0));
        items.add(new SlideMenuItem(R.string.military_celebration, R.id.military_celebration, 0));
        items.add(new SlideMenuItem(R.string.toasts, R.id.toasts, 0));
        items.add(new SlideMenuItem(R.string.lyrics, R.id.lyrics, 0));
        items.add(new SlideMenuItem(R.string.curse_warfare, R.id.curse_warfare, 0));
        items.add(new SlideMenuItem(R.string.replacement_proverbs, R.id.replacement_proverbs, 0));
        items.add(new SlideMenuItem(R.string.secrecy_proverbs, R.id.secrecy_proverbs, 0));
        items.add(new SlideMenuItem(R.string.empire_union_day, R.id.empire_union_day, 0));
        items.add(new SlideMenuItem(R.string.rejection, R.id.rejection, 0));
        // Not all general proverbs are properly tagged yet.
        // Too many idioms; also no known Klingon term for "idiom".
        items.add(new SlideMenuCategory(R.string.menu_media));
        items.add(new SlideMenuItem(R.string.media_1_title, R.id.media_1, 0));
        items.add(new SlideMenuItem(R.string.media_2_title, R.id.media_2, 0));
        items.add(new SlideMenuItem(R.string.media_3_title, R.id.media_3, 0));
        items.add(new SlideMenuItem(R.string.media_4_title, R.id.media_4, 0));
        items.add(new SlideMenuItem(R.string.media_5_title, R.id.media_5, 0));
        items.add(new SlideMenuItem(R.string.media_6_title, R.id.media_6, 0));
        /*
        items.add(new SlideMenuCategory(R.string.menu_social));
        items.add(new SlideMenuItem(R.string.menu_gplus, R.id.gplus, 0));
        items.add(new SlideMenuItem(R.string.menu_facebook, R.id.facebook, 0));
        items.add(new SlideMenuItem(R.string.menu_kag, R.id.kag, 0));
        items.add(new SlideMenuItem(R.string.menu_kidc, R.id.kidc, 0));
        */
    }
    mList = new ListView(this);

    mAdapter = new SlideMenuAdapter(this, items);
    mAdapter.setListener(this);
    mAdapter.setActivePosition(mActivePosition);

    mList.setAdapter(mAdapter);
    mList.setOnItemClickListener(mItemClickListener);

    mDrawer.setMenuView(mList);

    // Allow the menu to slide out when any part of the screen is dragged.
    mDrawer.setTouchMode(MenuDrawer.TOUCH_MODE_FULLSCREEN);

    // The drawable that replaces the up indicator in the action bar.
    mDrawer.setSlideDrawable(R.drawable.ic_drawer);
    // Whether the previous drawable should be shown.
    mDrawer.setDrawerIndicatorEnabled(true);

    // Activate type-to-search for local search. Typing will automatically
    // start a search of the database.
    setDefaultKeyMode(DEFAULT_KEYS_SEARCH_LOCAL);

    // Register a receiver for the kill order.
    mKillReceiver = new KillReceiver();
    registerReceiver(mKillReceiver, IntentFilter.create(ACTION_KILL, KILL_TYPE));
}

From source file:org.thoughtcrime.securesms.ConversationItem.java

private SpannableString linkifyMessageBody(SpannableString messageBody, boolean shouldLinkifyAllLinks) {
    boolean hasLinks = Linkify.addLinks(messageBody, shouldLinkifyAllLinks ? Linkify.ALL : 0);

    if (hasLinks) {
        URLSpan[] urlSpans = messageBody.getSpans(0, messageBody.length(), URLSpan.class);
        for (URLSpan urlSpan : urlSpans) {
            int start = messageBody.getSpanStart(urlSpan);
            int end = messageBody.getSpanEnd(urlSpan);
            messageBody.setSpan(new LongClickCopySpan(urlSpan.getURL()), start, end,
                    Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
        }//from   w w  w  .j  av  a2 s  .c  o m
    }
    return messageBody;
}

From source file:com.android.purenexussettings.TinkerActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_tinker);
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);//www .  ja v a2 s . c o m

    // set up some defaults
    boolean cLockInstalled;
    FRAG_ARRAY_START = getResources().getIntArray(R.array.nav_drawer_cat_nums)[0];
    mTitle = mDrawerTitle = getTitle();
    mPackageName = getPackageName();
    LAST_SLIDE_BAR_TAB = 0;
    mBackPress = false;
    mIgnoreBack = false;
    mFromClick = false;
    mMenu = false;
    fullyClosed = true;
    openingHalf = true;

    // for backstack tracking
    fragmentStack = new Stack<>();

    // check if cLock installed
    try {
        PackageInfo pi = getPackageManager().getPackageInfo(KEY_LOCK_CLOCK_PACKAGE_NAME, 0);
        cLockInstalled = pi.applicationInfo.enabled;
    } catch (PackageManager.NameNotFoundException e) {
        cLockInstalled = false;
    }

    // load slide menu items - titles and frag names
    navMenuTitles = getResources().getStringArray(R.array.nav_drawer_items);
    navMenuFrags = getResources().getStringArray(R.array.nav_drawer_fragments);

    // nav drawer icons from resources
    TypedArray navMenuIcons = getResources().obtainTypedArray(R.array.nav_drawer_icons);

    mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);

    mNavView = (NavigationView) findViewById(R.id.slidermenu);

    // create navigationview items
    Menu menu = mNavView.getMenu();
    // pulled in crap menu in xml, need to clear it first
    menu.clear();

    // pull in category names and numbers in each
    String[] navMenuCats = getResources().getStringArray(R.array.nav_drawer_cats);
    int[] navMenuCatCounts = getResources().getIntArray(R.array.nav_drawer_cat_nums);

    // set up some counters
    int j = 0;
    int total = 0;
    SubMenu submenu = null;
    // go through the total possible menu list
    for (int i = 0; i < navMenuTitles.length; i++) {
        // when the count equals a threshold value, increment/sum and add submenu
        if (i == (total + navMenuCatCounts[j])) {
            total += navMenuCatCounts[j];
            // format submenu headings
            SpannableString strcat = new SpannableString(navMenuCats[j]);
            strcat.setSpan(new ForegroundColorSpan(getResources().getColor(R.color.alphawhite)), 0,
                    strcat.length(), 0);
            strcat.setSpan(new RelativeSizeSpan(0.85f), 0, strcat.length(), 0);
            strcat.setSpan(new AlignmentSpan.Standard(Layout.Alignment.ALIGN_CENTER), 0, strcat.length(), 0);
            // is the 10 * (j + 1) bit needed...? Maybe not... meh
            submenu = menu.addSubMenu((j + 1), 10 * (j + 1), 10 * (j + 1), strcat);
            j++;
        }
        // assuming all are skipped before first submenu, only add menu items if total <> 0
        if (total > 0) {
            // format menu item title
            SpannableString stritem = new SpannableString(navMenuTitles[i]);
            stritem.setSpan(new ForegroundColorSpan(getResources().getColor(R.color.alphawhite)), 0,
                    stritem.length(), 0);
            // group id is j, i is item id and order..., then title - includes logic for conditional entries
            if (cLockInstalled || !(navMenuTitles[i].equals("cLock"))) {
                // an attempt to add icon if included...
                if (navMenuIcons.getResourceId(i, -1) != -1) {
                    submenu.add(j, i, i, stritem).setIcon(navMenuIcons.getResourceId(i, -1));
                } else {
                    submenu.add(j, i, i, stritem);
                }
            }
        }
    }

    // remove icon tint from NavView
    mNavView.setItemIconTintList(null);

    mNavView.setNavigationItemSelectedListener(new NavigationView.OnNavigationItemSelectedListener() {
        @Override
        public boolean onNavigationItemSelected(MenuItem item) {
            // check for external app launching navdrawer items
            if (navMenuTitles[item.getItemId()].equals("cLock")) {
                mIgnore = true;
                mDrawerLayout.closeDrawer(mNavView);
                launchcLock();
            }

            // if nothing was caught in the above, do the usual prep to show frag stuff
            if (!mIgnore) {
                mItemPosition = item.getItemId();
                mFromClick = true;
                setTitle(navMenuTitles[mItemPosition]);
                removeCurrent();
                mDrawerLayout.closeDrawer(mNavView);
            }

            return true;
        }
    });

    // Recycle the typed array
    navMenuIcons.recycle();

    // enabling action bar app icon and behaving it as toggle button
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    getSupportActionBar().setHomeButtonEnabled(true);

    mDrawerToggle = new ActionBarDrawerToggle(this, mDrawerLayout, toolbar, //nav menu toggle icon
            R.string.app_name, // nav drawer open - description for accessibility
            R.string.app_name // nav drawer close - description for accessibility
    ) {
        @Override
        public void onDrawerClosed(View view) {
            mDrawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_UNLOCKED, mNavView);
            getSupportActionBar().setTitle(mTitle);
            // calling onPrepareOptionsMenu() to show action bar icons
            openingHalf = true;
            invalidateOptionsMenu();
            // now that the drawer animation is done - load fragment
            if (mIgnore || !mFromClick) {
                mIgnore = false;
            } else {
                displayView(mItemPosition);
            }
        }

        @Override
        public void onDrawerOpened(View drawerView) {
            getSupportActionBar().setTitle(mDrawerTitle);
            // calling onPrepareOptionsMenu() to hide action bar icons
            openingHalf = false;
            invalidateOptionsMenu();
        }

        @Override
        public void onDrawerSlide(View drawerView, float slideOffset) {
            super.onDrawerSlide(drawerView, slideOffset);
            fullyClosed = (slideOffset == 0.0f);
            if (slideOffset < 0.5f && !openingHalf) {
                openingHalf = true;
                invalidateOptionsMenu(); // calls onPrepareOptionsMenu()
            } else if (slideOffset > 0.5f && openingHalf) {
                openingHalf = false;
                invalidateOptionsMenu(); // calls onPrepareOptionsMenu()
            }
        }

    };

    mDrawerLayout.setDrawerListener(mDrawerToggle);

    fragmentManager = getFragmentManager();

    if (savedInstanceState == null) {
        // on first time display view for first nav item
        displayView(mItemPosition = getIntent().getIntExtra(EXTRA_START_FRAGMENT, 0));
    }
}

From source file:com.todoroo.astrid.adapter.TaskAdapter.java

private Function<TagData, SpannableString> tagToString(final float maxLength) {
    return tagData -> {
        String tagName = tagData.getName();
        tagName = tagName.substring(0, Math.min(tagName.length(), (int) maxLength));
        SpannableString string = new SpannableString(SPACE + tagName + SPACE);
        int themeIndex = tagData.getColor();
        ThemeColor color = themeIndex >= 0 ? themeCache.getThemeColor(themeIndex)
                : themeCache.getUntaggedColor();
        string.setSpan(new BackgroundColorSpan(color.getPrimaryColor()), 0, string.length(),
                Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
        string.setSpan(new ForegroundColorSpan(color.getActionBarTint()), 0, string.length(),
                Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
        return string;
    };//from  ww w  .j a v  a 2  s. com
}