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.android.mms.transaction.MessagingNotification.java

private static CharSequence getAttachmentTypeString(Context context, int attachmentType) {
    final TextAppearanceSpan notificationAttachmentSpan = new TextAppearanceSpan(context,
            R.style.NotificationSecondaryText);
    int id = 0;//from www. j  a  v a  2 s .  c  o m
    switch (attachmentType) {
    case WorkingMessage.AUDIO:
        id = R.string.attachment_audio;
        break;
    case WorkingMessage.VIDEO:
        id = R.string.attachment_video;
        break;
    case WorkingMessage.SLIDESHOW:
        id = R.string.attachment_slideshow;
        break;
    case WorkingMessage.IMAGE:
        id = R.string.attachment_picture;
        break;
    }
    if (id > 0) {
        final SpannableString spannableString = new SpannableString(context.getString(id));
        spannableString.setSpan(notificationAttachmentSpan, 0, spannableString.length(), 0);
        return spannableString;
    }
    return null;
}

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

private SpannableString formatTimeStamp(Date date, int messageType, DateFormat format,
        MessageView.DeliveryState delivery, EncryptionState encryptionState) {

    StringBuilder deliveryText = new StringBuilder();
    deliveryText.append(format.format(date));
    deliveryText.append(' ');

    if (delivery != null) {
        //this is for delivery
        if (delivery == DeliveryState.DELIVERED) {

            deliveryText.append(DELIVERED_SUCCESS);

        } else if (delivery == DeliveryState.UNDELIVERED) {

            deliveryText.append(DELIVERED_FAIL);

        }//from w  w w  . j a  v  a 2s . com

    }

    if (messageType != Imps.MessageType.POSTPONED)
        deliveryText.append(DELIVERED_SUCCESS);//this is for sent, so we know show 2 checks like WhatsApp!

    SpannableString spanText = null;

    if (encryptionState == EncryptionState.ENCRYPTED) {
        deliveryText.append('X');
        spanText = new SpannableString(deliveryText.toString());
        int len = spanText.length();

        spanText.setSpan(new ImageSpan(getContext(), R.drawable.lock16), len - 1, len,
                Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);

    } else if (encryptionState == EncryptionState.ENCRYPTED_AND_VERIFIED) {
        deliveryText.append('X');
        spanText = new SpannableString(deliveryText.toString());
        int len = spanText.length();

        spanText.setSpan(new ImageSpan(getContext(), R.drawable.lock16), len - 1, len,
                Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);

    } else {
        spanText = new SpannableString(deliveryText.toString());
        int len = spanText.length();

    }

    //   spanText.setSpan(new StyleSpan(Typeface.SANS_SERIF), 0, len, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);

    // spanText.setSpan(new RelativeSizeSpan(0.8f), 0, len, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
    //    spanText.setSpan(new ForegroundColorSpan(R.color.soft_grey),
    //        0, len, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);

    return spanText;
}

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

/**
 * Default empty constructor//from  w  w  w  .  j a  v  a  2 s.c om
 */
public ListenNowFragment() {
    mScrollListener = new ScrollStatusBarColorListener() {
        @Override
        public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
            if (view.getChildCount() == 0 || getActivity() == null) {
                return;
            }

            final float heroHeight = mHeaderView.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 & mBackgroundColor);

            SpannableString spannableTitle = new SpannableString(
                    ((MainActivity) getActivity()).getFragmentTitle());
            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);
            }

            mCardSearchBox.setAlpha(1.0f - toolbarBgAlpha);
        }
    };
}

From source file:com.github.guwenk.smuradio.SignInDialog.java

@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {

    builder = new AlertDialog.Builder(getActivity());
    View signInDialogView = getActivity().getLayoutInflater().inflate(R.layout.dialog_sign_in, null);
    builder.setView(signInDialogView);// w  w  w  .  ja va  2 s . c  o m
    builder.setMessage(R.string.upload_your_song);

    checkBox = (CheckBox) signInDialogView.findViewById(R.id.checkBox2);

    int currentOrientation = getResources().getConfiguration().orientation;
    if (currentOrientation == Configuration.ORIENTATION_LANDSCAPE) {
        getActivity().setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE);
    } else {
        getActivity().setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT);
    }

    check1 = false;
    check2 = false;
    check3 = false;
    // Log.d(AuthTag, "onCreateDialog " + check1 + " " + check2 + " " + check3);

    this.mGoogleApiClient = OrderActivity.getmGoogleApiClient();
    mAuth = FirebaseAuth.getInstance();

    selectFileButton = (Button) signInDialogView.findViewById(R.id.selectFileButton);
    selectFileButton.setOnClickListener(new customButtonClickListener());

    signInButton = (SignInButton) signInDialogView.findViewById(R.id.sign_in_button);
    signInButton.setStyle(SignInButton.SIZE_WIDE, SignInButton.COLOR_AUTO);
    signInButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            signIn();
        }
    });

    builder.setPositiveButton(getString(R.string.next), new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            // TODO upload song
        }
    });

    builder.setNegativeButton(R.string.close, new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {

        }
    });

    SpannableString ss = new SpannableString(getString(R.string.you_accepting_license_agreement));
    ClickableSpan clickableSpan = new ClickableSpan() {
        @Override
        public void onClick(View textView) {
            Log.d(AuthTag, "click");
            LicenseDialog licenseDialog = new LicenseDialog();
            licenseDialog.show(getFragmentManager(), "Sing in dialog");
        }

        @Override
        public void updateDrawState(TextPaint ds) {
            super.updateDrawState(ds);
            ds.setUnderlineText(true);
        }
    };
    ss.setSpan(clickableSpan, 14, ss.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
    TextView textView = (TextView) signInDialogView.findViewById(R.id.textView);
    textView.setText(ss);
    textView.setMovementMethod(LinkMovementMethod.getInstance());
    textView.setHighlightColor(Color.TRANSPARENT);

    checkBox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
        @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            check2 = isChecked;
            Log.d(AuthTag, "Checked: " + isChecked);
            buttonStatus();
        }
    });

    mStorageRef = FirebaseStorage.getInstance().getReference();

    alert = builder.create();
    return alert;
}

From source file:com.kyakujin.android.tagnotepad.ui.NoteListFragment.java

/**
 * About/*from   w w w . ja v  a  2 s. c o m*/
 */
private void showAboutDialog() {
    PackageManager pm = getActivity().getPackageManager();
    String packageName = getActivity().getPackageName();
    String versionName;
    try {
        PackageInfo info = pm.getPackageInfo(packageName, 0);
        versionName = info.versionName;
    } catch (PackageManager.NameNotFoundException e) {
        versionName = "N/A";
    }

    SpannableStringBuilder aboutBody = new SpannableStringBuilder();

    SpannableString mailAddress = new SpannableString(getString(R.string.mailto));
    mailAddress.setSpan(new ClickableSpan() {
        @Override
        public void onClick(View view) {
            Intent intent = new Intent();
            intent.setAction(Intent.ACTION_SENDTO);
            intent.setData(Uri.parse(getString(R.string.description_mailto)));
            intent.putExtra(Intent.EXTRA_SUBJECT, getString(R.string.description_mail_subject));
            startActivity(intent);
        }
    }, 0, mailAddress.length(), 0);

    aboutBody.append(Html.fromHtml(getString(R.string.about_body, versionName)));
    aboutBody.append("\n");
    aboutBody.append(mailAddress);

    LayoutInflater layoutInflater = (LayoutInflater) getActivity()
            .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    TextView aboutBodyView = (TextView) layoutInflater.inflate(R.layout.fragment_about_dialog, null);
    aboutBodyView.setText(aboutBody);
    aboutBodyView.setMovementMethod(LinkMovementMethod.getInstance());

    AlertDialog dlg = new AlertDialog.Builder(getActivity()).setTitle(R.string.alert_title_about)
            .setView(aboutBodyView).setPositiveButton("OK", new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    dialog.dismiss();
                }
            }).create();
    dlg.show();
}

From source file:com.todoroo.astrid.actfm.ActFmLoginActivity.java

protected SpannableString getLinkStringWithCustomInterval(String base, String linkComponent, int start,
        int endOffset, final OnClickListener listener) {
    SpannableString link = new SpannableString(String.format("%s %s", //$NON-NLS-1$
            base, linkComponent));// w w  w.j a  v a  2 s.  c o  m
    ClickableSpan linkSpan = new ClickableSpan() {
        @Override
        public void onClick(View widget) {
            listener.onClick(widget);
        }

        @Override
        public void updateDrawState(TextPaint ds) {
            ds.setUnderlineText(true);
            ds.setColor(Color.rgb(68, 68, 68));
        }
    };
    link.setSpan(linkSpan, start, link.length() + endOffset, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
    return link;
}

From source file:org.awesomeapp.messenger.ui.MessageListItem.java

private CharSequence formatPresenceUpdates(String contact, int type, Date date, boolean isGroupChat,
        boolean scrolling) {
    String body;/*from   w w  w  .j  a  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;
    }

    body += " - ";
    body += formatTimeStamp(date, type, null, EncryptionState.NONE, 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: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//from  www.j  a  v  a 2  s  .  com
        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.aegiswallet.actions.MainActivity.java

@Override
public void setTitle(CharSequence title) {
    SpannableString s = new SpannableString(title);

    s.setSpan(new CustomTypefaceSpan(this, "regular.otf"), 0, s.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);

    //getActionBar().setTitle(s);
    mTitle = s;/*from   w w w .  ja  va  2 s  .c o m*/
}

From source file:com.timekeeping.app.activities.MainActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    Crashlytics.start(this);
    mSystemUiHelper = new SystemUiHelper(this, SystemUiHelper.LEVEL_IMMERSIVE, 0);

    mSystemUiHelper.hide();// w  w  w. j a  v a2  s  .c  om
    setContentView(LAYOUT);

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB
            && Build.VERSION.SDK_INT < VERSION_CODES.LOLLIPOP) {
        View decorView = getWindow().getDecorView();
        decorView.setOnSystemUiVisibilityChangeListener(new View.OnSystemUiVisibilityChangeListener() {
            @Override
            public void onSystemUiVisibilityChange(int visibility) {
                // Note that system bars will only be "visible" if none of the
                // LOW_PROFILE, HIDE_NAVIGATION, or FULLSCREEN flags are set.
                if ((visibility & View.SYSTEM_UI_FLAG_FULLSCREEN) == 0) {
                    // The system bars are visible.
                    animToolActionBar(getStatusBarHeight());
                } else {
                    if (mFistTimeHide) {
                        mFistTimeHide = false;
                        return;
                    }
                    // The system bars are NOT visible.
                    animToolActionBar(0);
                }
            }
        });
    }

    mToolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(mToolbar);

    calcActionBarHeight();
    initDrawer();

    //Let all columns to equal.
    mGv = (GridView) findViewById(R.id.schedule_gv);
    int screenWidth = DeviceUtils.getScreenSize(this, 0).Width;
    if (Prefs.getInstance(getApplication()).isLastAListView()) {
        mGv.setColumnWidth(screenWidth / 2);
    } else {
        mGv.setColumnWidth(screenWidth / 3);
    }
    mGv.setOnScrollListener(this);

    //Init speech-framework.
    Intent checkIntent = new Intent();
    checkIntent.setAction(TextToSpeech.Engine.ACTION_CHECK_TTS_DATA);
    startActivityForResult(checkIntent, 0x1);

    //Add new item.
    mAddNewV = findViewById(R.id.add_new_time_btn);
    mAddNewV.setOnClickListener(this);

    //Adapter for grid and dummy data.
    mAdp = new ItemsGridViewListAdapter();
    mGv.setAdapter(mAdp);
    refreshGrid();

    mGv.setOnItemLongClickListener(this);

    //Customized the title of ActionBar with a right font.
    SpannableString s = new SpannableString(getString(R.string.application_name));
    s.setSpan(new TypefaceSpan(this, Fonts.FONT_LIGHT), 0, s.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);

    // Update the action bar title with the TypefaceSpan instance
    ActionBar actionBar = getSupportActionBar();
    if (actionBar != null) {
        actionBar.setTitle(s);
    }
}