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:eltos.simpledialogfragments.FlatFragmentActivity.java

/**
 * Let the hosting fragment or activity implement this interface
 * to receive results from the dialog//from w w  w .ja  va  2s  .  c om
 *
 * @param dialogTag the tag passed to {@link SimpleDialog#show}
 * @param which result type, one of {@link #BUTTON_POSITIVE}, {@link #BUTTON_NEGATIVE},
 *              {@link #BUTTON_NEUTRAL} or {@link #CANCELED}
 * @param extras the extras passed to {@link SimpleDialog#extra(Bundle)}
 * @return true if the result was handled, false otherwise
 */
@Override
public boolean onResult(@NonNull String dialogTag, int which, @NonNull Bundle extras) {

    // handle results as usual
    if (COLOR_FRAGMENT.equals(dialogTag) && which == BUTTON_POSITIVE) {
        @ColorInt
        int color = extras.getInt(SimpleColorDialog.COLOR);

        // Sets action bar colors
        if (getSupportActionBar() != null) {
            getSupportActionBar().setBackgroundDrawable(new ColorDrawable(0xFF000000 | color));

            boolean dark = Color.red(color) * 0.299 + Color.green(color) * 0.587
                    + Color.blue(color) * 0.114 < 180;
            SpannableString s = new SpannableString(getSupportActionBar().getTitle());
            s.setSpan(new ForegroundColorSpan(dark ? Color.WHITE : Color.BLACK), 0, s.length(),
                    Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
            getSupportActionBar().setTitle(s);
        }

        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            float[] hsv = new float[3];
            Color.colorToHSV(color, hsv);
            hsv[2] *= 0.75;
            getWindow().setStatusBarColor(Color.HSVToColor(hsv));
        }

        return true;
    }
    return false;
}

From source file:ru.tinkoff.acquiring.sample.ui.PaymentResultActivity.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_payment_result);
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);

    final TextView textView = (TextView) findViewById(R.id.tv_confirm);
    Intent intent = getIntent();//from   ww w  .j ava  2 s . c o m
    if (intent.hasExtra(EXTRA_PRICE)) {
        final Money price = (Money) intent.getSerializableExtra(EXTRA_PRICE);

        final SpannableString coloredPrice = new SpannableString(price.toString());
        coloredPrice.setSpan(new ForegroundColorSpan(ContextCompat.getColor(this, R.color.colorPrimary)), 0,
                coloredPrice.length(), SpannedString.SPAN_INCLUSIVE_INCLUSIVE);

        final String text = getString(R.string.payment_result_success, coloredPrice);
        textView.setText(text);
    } else {
        String cardId = intent.getStringExtra(EXTRA_CARD_ID);
        final String text = getString(R.string.attachment_result_success, cardId);
        textView.setText(text);
    }
}

From source file:com.senior.fragments.HomeFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    Log.i("HomeFrag", "View Created");

    view = inflater.inflate(R.layout.home_fragment, container, false);

    titletext = (TextView) view.findViewById(R.id.calenderevents);

    SpannableString NewTitle = new SpannableString("Calendar Of Events");

    NewTitle.setSpan(new UnderlineSpan(), 0, NewTitle.length(), 0);

    titletext.setText(NewTitle);/*from w  w  w.  j a v a  2  s.  co  m*/

    mListView = (ListView) view.findViewById(android.R.id.list);

    reloadButton = (Button) view.findViewById(R.id.refresh);
    reloadButton.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View arg0) {
            getArticles();
        }

    });

    progress = (ProgressBar) view.findViewById(R.id.progress);

    return view;
}

From source file:li.barter.AbstractBarterLiActivity.java

protected final void setActionBarTitle(final String title) {

    final SpannableString s = new SpannableString(title);
    s.setSpan(new TypefacedSpan(this, TypefaceCache.ALEGREYA_BLACK_ITALIC), 0, s.length(),
            Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);

    // Update the action bar title with the TypefaceSpan instance
    final ActionBar actionBar = getActionBar();
    actionBar.setTitle(s);/*w w  w .java 2  s  .c o  m*/
}

From source file:com.nasageek.utexasutilities.activities.AboutMeActivity.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.aboutme_layout);

    actionbar = getSupportActionBar();//from w  ww  . j ava  2  s .c  om
    actionbar.setTitle("About");
    actionbar.setNavigationMode(ActionBar.NAVIGATION_MODE_STANDARD);
    actionbar.setHomeButtonEnabled(true);
    actionbar.setDisplayHomeAsUpEnabled(true);

    // force the License Dialog link to be underlined so it looks "linky"
    TextView licenseView = (TextView) findViewById(R.id.library_license_link);
    SpannableString underlinedLicenseLink = new SpannableString(getString(R.string.library_license_link));
    underlinedLicenseLink.setSpan(new UnderlineSpan(), 0, underlinedLicenseLink.length(), 0);
    licenseView.setText(underlinedLicenseLink);
    licenseView.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            FragmentManager fm = getSupportFragmentManager();
            LibraryLicenseDialog libraryLicenseDlg = new LibraryLicenseDialog();
            libraryLicenseDlg.show(fm, "fragment_license");
        }
    });
    // do the same thing with the Privacy Policy link
    TextView policyView = (TextView) findViewById(R.id.privacy_policy_link);
    SpannableString underlinedPolicyLink = new SpannableString(getString(R.string.privacy_policy_link));
    underlinedPolicyLink.setSpan(new UnderlineSpan(), 0, underlinedPolicyLink.length(), 0);
    policyView.setText(underlinedPolicyLink);
    policyView.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            FragmentManager fm = getSupportFragmentManager();
            PrivacyPolicyDialog privacyPolicyDlg = new PrivacyPolicyDialog();
            privacyPolicyDlg.show(fm, "fragment_privacy_policy");
        }
    });

    TextView versionNumberView = (TextView) findViewById(R.id.version);
    String versionName = "";
    try {
        versionName = getPackageManager().getPackageInfo(getPackageName(), 0).versionName;
    } catch (NameNotFoundException e) {
        // of course UTilities is installed...
        e.printStackTrace();
    }
    versionNumberView.setText(versionName);
}

From source file:com.flowzr.activity.AbstractActionBarActivity.java

public void setMyTitle(String t) {
    SpannableString s = new SpannableString(t);
    s.setSpan(new TypefaceSpan("sans-serif"), 0, s.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
    actionBar.setTitle(s);/*from   w  w w  . ja  va 2s  .  c o  m*/
}

From source file:com.handpoint.headstart.client.ui.LoginActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    HeadstartService.removeProperty("last_activity");
    mPreferences = PreferenceManager.getDefaultSharedPreferences(this);
    long elapsedTime = SystemClock.elapsedRealtime();
    long lastAttempt = getLastAttempt();
    if (elapsedTime > lastAttempt && lastAttempt > 0 && lastAttempt + ATTEMPT_DELAY > elapsedTime) {
        long timeToWait = ATTEMPT_DELAY - (elapsedTime - lastAttempt);
        Toast.makeText(this, getString(R.string.warn_wait_message, formatTime(timeToWait)), Toast.LENGTH_LONG)
                .show();/*  w w w. ja  v  a2 s.c om*/
        finish();
        return;
    }
    setLastAttempt(0);
    setContentView(R.layout.login);

    Button loginButton = (Button) findViewById(R.id.login_button);
    loginButton.setOnClickListener(this);

    TextView forgotLink = (TextView) findViewById(R.id.forgot_password_link);
    SpannableString content = new SpannableString(getString(R.string.forgot_password_link_label));
    content.setSpan(new UnderlineSpan(), 0, content.length(), 0);
    forgotLink.setText(content);
    forgotLink.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            DialogFragment newFragment = new ForgotPasscodeDialog();
            newFragment.show(getSupportFragmentManager(), "forgot_passcode");
        }
    });
}

From source file:cw.kop.autobackground.tutorial.AppFragment.java

private void resetFabricText(boolean use) {

    SpannableString text;
    if (use) {/*from w ww .jav  a 2  s  .  c o m*/
        text = new SpannableString("Thanks!");
        text.setSpan(new ForegroundColorSpan(getResources().getColor(R.color.BLUE_OPAQUE)), 0, text.length(),
                Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
    } else {
        text = new SpannableString("Send reports?");
    }
    fabricText.setText(text);
    fabricText.invalidate();

}

From source file:cw.kop.autobackground.tutorial.CardFragment.java

@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container,
        @Nullable Bundle savedInstanceState) {

    final View view = AppSettings.getTheme().equals(AppSettings.APP_LIGHT_THEME)
            ? inflater.inflate(R.layout.tutorial_card_fragment, container, false)
            : inflater.inflate(R.layout.tutorial_card_fragment_dark, container, false);
    View sourceCard = view.findViewById(R.id.source_card);
    sourceCard.setOnClickListener(this);

    int colorFilterInt = AppSettings.getColorFilterInt(appContext);

    TextView sourceTitle = (TextView) view.findViewById(R.id.source_title);
    sourceTitle.setOnClickListener(new View.OnClickListener() {
        @Override/*  w  w w . j a  v  a  2  s  .c o  m*/
        public void onClick(View v) {
            CardFragment.this.onClick(view);
        }
    });

    ImageView deleteButton = (ImageView) view.findViewById(R.id.source_delete_button);
    ImageView viewButton = (ImageView) view.findViewById(R.id.source_view_image_button);
    ImageView editButton = (ImageView) view.findViewById(R.id.source_edit_button);

    Drawable deleteDrawable = getResources().getDrawable(R.drawable.ic_delete_white_24dp);
    Drawable viewDrawable = getResources().getDrawable(R.drawable.ic_photo_white_24dp);
    Drawable editDrawable = getResources().getDrawable(R.drawable.ic_edit_white_24dp);

    deleteDrawable.setColorFilter(colorFilterInt, PorterDuff.Mode.MULTIPLY);
    viewDrawable.setColorFilter(colorFilterInt, PorterDuff.Mode.MULTIPLY);
    editDrawable.setColorFilter(colorFilterInt, PorterDuff.Mode.MULTIPLY);

    deleteButton.setImageDrawable(deleteDrawable);
    viewButton.setImageDrawable(viewDrawable);
    editButton.setImageDrawable(editDrawable);

    deleteButton.setOnClickListener(null);
    viewButton.setOnClickListener(null);
    editButton.setOnClickListener(null);

    TextView sourceType = (TextView) view.findViewById(R.id.source_type);
    TextView sourceData = (TextView) view.findViewById(R.id.source_data);
    TextView sourceNum = (TextView) view.findViewById(R.id.source_num);
    TextView sourceTime = (TextView) view.findViewById(R.id.source_time);

    int colorPrimary = getResources().getColor(R.color.BLUE_OPAQUE);
    SpannableString typePrefix = new SpannableString("Type: ");
    typePrefix.setSpan(new ForegroundColorSpan(colorPrimary), 0, typePrefix.length(),
            Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
    SpannableString dataPrefix = new SpannableString("Data: ");
    dataPrefix.setSpan(new ForegroundColorSpan(colorPrimary), 0, dataPrefix.length(),
            Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
    SpannableString numPrefix = new SpannableString("Number of Images: ");
    numPrefix.setSpan(new ForegroundColorSpan(colorPrimary), 0, numPrefix.length(),
            Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
    SpannableString timePrefix = new SpannableString("Active Time: ");
    timePrefix.setSpan(new ForegroundColorSpan(colorPrimary), 0, timePrefix.length(),
            Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);

    sourceType.setText(typePrefix);
    sourceData.setText(dataPrefix);
    sourceNum.setText(numPrefix);
    sourceTime.setText(timePrefix);

    ImageView image = (ImageView) view.findViewById(R.id.source_image);
    Picasso.with(appContext).load(R.drawable.preview_image_0).fit().centerCrop().into(image);

    TextView titleText = (TextView) view.findViewById(R.id.title_text);
    titleText.setTextColor(colorFilterInt);
    titleText.setText("Sources");

    TextView tutorialText = (TextView) view.findViewById(R.id.tutorial_text);
    tutorialText.setTextColor(colorFilterInt);
    tutorialText.setText("These are the parts that make up your wallpaper. "
            + "Each represents an image source like an album from Imgur or "
            + "a subreddit. Note that not all websites or entries can work " + "with AutoBackground.");

    return view;
}

From source file:io.vit.vitio.Settings.SettingsActivity.java

@Override
protected void onResume() {
    super.onResume();
    toolbar.setBackgroundColor(getResources().getColor(R.color.darkgray));
    SpannableString s = new SpannableString("SETTINGS");
    s.setSpan(myTheme.getMyThemeTypeFaceSpan(), 0, s.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
    getSupportActionBar().setTitle(s);/*w w  w.jav  a 2  s  . c  o m*/
}