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:me.jreilly.JamesTweet.TweetView.TweetFragment.java

public void setTweet(RealmResults<TweetRealm> mDataset) {

    int i = 0;/*from w  w  w. j  a va  2 s. com*/
    String user_img = mDataset.get(i).getProfileImageUrl();
    final String user_screen = mDataset.get(i).getScreename();
    String media_url = "null";
    Date created = mDataset.get(i).getDate();
    boolean retweeted = mDataset.get(i).isRetweetedStatus();
    String original = mDataset.get(i).getRetweetedBy();
    String username = mDataset.get(i).getName();
    String text = mDataset.get(i).getText();
    final long tId = mDataset.get(i).getId();

    //Load Profile Image
    Picasso.with(mProfileImage.getContext()).load(user_img).transform(new CircleTransform())
            .into(mProfileImage);

    //Set profile image to go to the users profile
    mProfileImage.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            mActivity.swapToProfile(user_screen, mProfileImage);
        }
    });

    final String imageUrl = media_url;
    ViewGroup.LayoutParams params = mImage.getLayoutParams();

    //Set Cropped Media image and zoomImage animation
    if (!imageUrl.equals("null")) {

        mImage.getLayoutParams().height = 400;
        Picasso.with(mImage.getContext()).load(imageUrl).fit().centerCrop().into(mImage);

    } else {
        //Media is not need so it is hidden.
        mImage.setImageDrawable(null);

        mImage.getLayoutParams().height = 0;

    }

    //Set Username Text Field
    Calendar cal = Calendar.getInstance();
    mDate.setText(DateUtils.getRelativeTimeSpanString(created.getTime()));
    mUser.setText(username);
    String tweetText = text;

    //Highlight Profile names/hashtags and their clickable spans
    ArrayList<int[]> hashtagSpans = getSpans(tweetText, '#');
    ArrayList<int[]> profileSpans = getSpans(tweetText, '@');

    SpannableString tweetContent = new SpannableString(tweetText);

    for (int j = 0; j < profileSpans.size(); j++) {
        int[] span = profileSpans.get(j);
        int profileStart = span[0];
        int profileEnd = span[1];

        tweetContent.setSpan(new ProfileLink(mTweet.getContext(), mActivity), profileStart, profileEnd, 0);
    }
    mTweet.setMovementMethod(LinkMovementMethod.getInstance());
    mTweet.setText(tweetContent);
}

From source file:com.tassadar.multirommgr.MainActivity.java

@TargetApi(20)
private void showDeprecatedLAlert() {
    SpannableString msg = new SpannableString(getString(R.string.deprecated_l_text));
    Linkify.addLinks(msg, Linkify.ALL);//from  w w w .j  a v  a 2s . c om

    AlertDialog.Builder b = new AlertDialog.Builder(this);
    b.setTitle(R.string.deprecated_l_title).setCancelable(false).setMessage(msg)
            .setNegativeButton(R.string.deprecated_l_btn, new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialogInterface, int i) {
                    finish();
                }
            });

    AlertDialog d = b.create();
    d.show();

    TextView msgView = (TextView) d.findViewById(android.R.id.message);
    msgView.setMovementMethod(LinkMovementMethod.getInstance());
}

From source file:com.aboveware.sms.contacts.ContactSuggestionsAdapter.java

private CharSequence formatUrl(CharSequence url) {
    if (mUrlColor == null) {
        // Lazily get the URL color from the current theme.
        TypedValue colorValue = new TypedValue();
        mContext.getTheme().resolveAttribute(R.attr.textColorSearchUrl, colorValue, true);
        mUrlColor = mContext.getResources().getColorStateList(colorValue.resourceId);
    }/*  ww  w. j  ava  2 s  .  c o  m*/

    SpannableString text = new SpannableString(url);
    text.setSpan(new TextAppearanceSpan(null, 0, 0, mUrlColor, null), 0, url.length(),
            Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
    return text;
}

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

private CharSequence convertToCondensed(final CharSequence string) {
    if (TextUtils.isEmpty(string)) {
        return string;
    }//from   w  w  w .ja  va  2 s . c  om

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

From source file:org.anoopam.main.anoopamaudio.AudioListActivity.java

@Override
public void manageAppBar(ActionBar actionBar, Toolbar toolbar, ActionBarDrawerToggle actionBarDrawerToggle) {

    actionBar.setDisplayHomeAsUpEnabled(true);
    toolbar.setNavigationOnClickListener(new View.OnClickListener() {
        @Override/*  w  w w .j av  a2  s .  c  om*/
        public void onClick(View v) {

            handleBackPress();

        }
    });
    toolbar.setTitle(getString(R.string.nav_audio_title));
    SpannableString spannableString = new SpannableString(currentAlbumName);
    spannableString.setSpan(new StyleSpan(Typeface.ITALIC), 0, spannableString.length(), 0);
    toolbar.setSubtitle(spannableString);
}

From source file:com.fastbootmobile.encore.app.fragments.PlaylistViewFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    // Inflate the layout for this fragment
    View root = inflater.inflate(R.layout.fragment_playlist_view, container, false);
    assert root != null;

    if (mPlaylist == null) {
        // If playlist couldn't load, abort early
        return root;
    }// w ww .j a  v  a2  s . c o m

    mListViewContents = (PlaylistListView) root.findViewById(R.id.lvPlaylistContents);

    // Setup the parallaxed header
    View headerView = inflater.inflate(R.layout.header_listview_songs, mListViewContents, false);
    mListViewContents.addParallaxedHeaderView(headerView);

    mAdapter = new PlaylistAdapter();
    mListViewContents.setAdapter(mAdapter);
    mListViewContents.setOnScrollListener(new ScrollStatusBarColorListener() {
        @Override
        public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
            if (view.getChildCount() == 0 || getActivity() == null) {
                return;
            }

            final float heroHeight = mIvHero.getMeasuredHeight();
            final float scrollY = getScroll(view);
            final float toolbarBgAlpha = Math.min(1, scrollY / heroHeight);
            final int toolbarAlphaInteger = (((int) (toolbarBgAlpha * 255)) << 24) | 0xFFFFFF;
            mColorDrawable.setColor(toolbarAlphaInteger & getResources().getColor(R.color.primary));

            SpannableString spannableTitle = new SpannableString(
                    mPlaylist.getName() != null ? mPlaylist.getName() : "");
            mAlphaSpan.setAlpha(toolbarBgAlpha);

            ActionBar actionbar = ((AppActivity) getActivity()).getSupportActionBar();
            if (actionbar != null) {
                actionbar.setBackgroundDrawable(mColorDrawable);
                spannableTitle.setSpan(mAlphaSpan, 0, spannableTitle.length(),
                        Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
                actionbar.setTitle(spannableTitle);
                if (Utils.hasLollipop()) {
                    getActivity().getWindow().setStatusBarColor(
                            toolbarAlphaInteger & getResources().getColor(R.color.primary_dark));
                }
            }
        }
    });

    headerView.findViewById(R.id.pbAlbumLoading).setVisibility(View.GONE);

    mIvHero = (ImageView) headerView.findViewById(R.id.ivHero);

    mTvPlaylistName = (TextView) headerView.findViewById(R.id.tvAlbumName);

    // Download button
    mOfflineBtn = (CircularProgressButton) headerView.findViewById(R.id.cpbOffline);
    mOfflineBtn.setAlpha(0.0f);
    mOfflineBtn.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            ProviderIdentifier pi = mPlaylist.getProvider();
            IMusicProvider provider = PluginsLookup.getDefault().getProvider(pi).getBinder();
            try {
                if (mPlaylist.getOfflineStatus() == BoundEntity.OFFLINE_STATUS_NO) {
                    provider.setPlaylistOfflineMode(mPlaylist.getRef(), true);
                    mOfflineBtn.setIndeterminateProgressMode(true);
                    mOfflineBtn.setProgress(1);

                    if (ProviderAggregator.getDefault().isOfflineMode()) {
                        Toast.makeText(getActivity(), R.string.toast_offline_playlist_sync, Toast.LENGTH_SHORT)
                                .show();
                    }
                } else {
                    provider.setPlaylistOfflineMode(mPlaylist.getRef(), false);
                    mOfflineBtn.setProgress(0);
                }
            } catch (RemoteException e) {
                Log.e(TAG, "Cannot set this playlist to offline mode", e);
                mOfflineBtn.setProgress(-1);
            }
        }
    });

    mHandler.sendEmptyMessageDelayed(UPDATE_OFFLINE_STATUS, 300);
    mTvPlaylistName.setText(mPlaylist.getName());

    Bitmap hero = Utils.dequeueBitmap(PlaylistActivity.BITMAP_PLAYLIST_HERO);
    if (hero == null) {
        mIvHero.setImageResource(R.drawable.album_placeholder);
    } else {
        mIvHero.setImageBitmap(hero);

        // Request the higher resolution
        loadArt();
    }

    mPlayFab = (FloatingActionButton) headerView.findViewById(R.id.fabPlay);

    // Set source logo
    mIvSource = (ImageView) headerView.findViewById(R.id.ivSourceLogo);
    mLogoBitmap = PluginsLookup.getDefault().getCachedLogo(getResources(), mPlaylist);
    mIvSource.setImageDrawable(mLogoBitmap);

    // Set the FAB animated drawable
    mFabDrawable = new PlayPauseDrawable(getResources(), 1);
    mFabDrawable.setShape(PlayPauseDrawable.SHAPE_PLAY);
    mFabDrawable.setYOffset(6);

    mPlayFab.setImageDrawable(mFabDrawable);
    mPlayFab.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            if (mFabDrawable.getCurrentShape() == PlayPauseDrawable.SHAPE_PLAY) {
                if (mFabShouldResume) {
                    PlaybackProxy.play();
                    mFabDrawable.setShape(PlayPauseDrawable.SHAPE_PAUSE);
                    mFabDrawable.setBuffering(true);
                } else {
                    playNow();
                }

                if (Utils.hasLollipop()) {
                    showMaterialReelBar(mPlayFab);
                }
            } else {
                mFabShouldResume = true;
                PlaybackProxy.pause();
                mFabDrawable.setBuffering(true);
            }
        }
    });

    // Fill the playlist
    mAdapter.setPlaylist(mPlaylist);

    // Set the list listener
    mListViewContents.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
            Song song = mAdapter.getItem(i - 1);
            if (Utils.canPlaySong(song)) {
                PlaybackProxy.clearQueue();
                PlaybackProxy.queuePlaylist(mPlaylist, false);
                PlaybackProxy.playAtIndex(i - 1);

                // Update FAB
                mFabShouldResume = true;
                mFabDrawable.setShape(PlayPauseDrawable.SHAPE_PAUSE);
                mFabDrawable.setBuffering(true);

                if (Utils.hasLollipop()) {
                    showMaterialReelBar(mPlayFab);
                }
            }
        }
    });

    // Set the display animation
    AlphaAnimation anim = new AlphaAnimation(0.f, 1.f);
    anim.setDuration(200);
    mListViewContents.setLayoutAnimation(new LayoutAnimationController(anim));

    setupMaterialReelBar(root, mReelFabClickListener);

    // Setup the opening animations for non-Lollipop devices
    if (!Utils.hasLollipop()) {
        mTvPlaylistName.setVisibility(View.VISIBLE);
        mTvPlaylistName.setAlpha(0.0f);
        mTvPlaylistName.animate().alpha(1.0f).setDuration(AlbumActivity.BACK_DELAY).start();
    }

    mIvSource.setAlpha(0.0f);
    mIvSource.animate().alpha(1).setDuration(200).start();

    return root;
}

From source file:me.albertonicoletti.latex.activities.EditorActivity.java

private void startTextWatcher() {
    textWatcher = new TextWatcher() {

        private RelativeSizeSpan span;
        private SpannableString spannable;

        @Override/*from   w w  w .  j a  va2s  .c  o m*/
        public void beforeTextChanged(CharSequence s, int start, int count, int after) {
        }

        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {
            // count > 0 means it's not a backspace
            if (count > 0) {
                // It's a span that does nothing, used to mark where the text has changed
                span = new RelativeSizeSpan(1.0f);
                spannable = new SpannableString(s);
                spannable.setSpan(span, start, start + count, Spanned.SPAN_COMPOSING);
            }
        }

        @Override
        public void afterTextChanged(Editable s) {
            if (editor.getLayout() != null && spannable != null) {
                document.setSaved(false);
                setSaveButtonEnabled(true);
                menu.findItem(R.id.action_save).setEnabled(true);
                autoIndentAndTabEditor(s, spannable, span);
                highlightEditor();
                // Cleanup
                span = null;
                spannable = null;
            }
        }
    };
    editor.addTextChangedListener(textWatcher);
}

From source file:uk.co.threeonefour.android.snowball.activities.game.GameActivity.java

@Override
public void processCommand(String command) {

    if (!initialised) {
        return;/*from  w  ww  .  j av a 2s.  c om*/
    }

    SpannableString styledCommand = new SpannableString(command);
    styledCommand.setSpan(new StyleSpan(Typeface.BOLD), 0, styledCommand.length(),
            Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);

    textView.append(styledCommand);
    textView.append("\n");

    lastCommand = command;
    /* pre: intercept some commands like RESTORE */
    boolean continueExecute = true;
    if ("restore".equalsIgnoreCase(command)) {
        loadGame();
        continueExecute = false;
    }

    if (continueExecute) {
        /* execute command */
        level9.execute(command);
        String text = level9.getText().trim();

        /* post: intercept some commands */

        processOutput(text);
    }
}

From source file:com.github.andrewlord1990.snackbarbuilder.SnackbarWrapper.java

/**
 * Append text in the specified color to the Snackbar.
 *
 * @param message The text to append.//from  w w w.  jav  a2s . c o m
 * @param color   The color to apply to the text.
 * @return This instance.
 */
public SnackbarWrapper appendMessage(CharSequence message, @ColorInt int color) {
    Spannable spannable = new SpannableString(message);
    spannable.setSpan(new ForegroundColorSpan(color), 0, spannable.length(),
            Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
    messageView.append(spannable);
    return this;
}

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

private CharSequence convertToCondensed(final CharSequence string, int color) {
    if (TextUtils.isEmpty(string)) {
        return string;
    }//from   ww w.jav  a2  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;
}