Example usage for android.text SpannableString setSpan

List of usage examples for android.text SpannableString setSpan

Introduction

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

Prototype

public void setSpan(Object what, int start, int end, int flags) 

Source Link

Usage

From source file:com.example.adbird.MenuTabActivity.java

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.tab_menu);//from   w w w.  j a va  2 s .c  o  m
    mContext = this.getApplicationContext();

    SharedPreferences prefs = getSharedPreferences("prefs", MODE_PRIVATE);
    String lang = prefs.getString("lang", null);
    Locale locale = new Locale(lang);
    Locale.setDefault(locale);
    Configuration config = new Configuration();
    config.locale = locale;
    getBaseContext().getResources().updateConfiguration(config,
            getBaseContext().getResources().getDisplayMetrics());
    SpannableString s = new SpannableString(mContext.getResources().getString(R.string.ads_title));
    s.setSpan(new TypefaceSpan(this, "GothaProReg.otf"), 0, s.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
    mAppSectionsPagerAdapter = new AppSectionsPagerAdapter(getSupportFragmentManager());

    // Set up the action bar.
    final ActionBar actionBar = getActionBar();
    actionBar.setTitle(s);
    actionBar.setHomeButtonEnabled(false);

    // Specify that we will be displaying tabs in the action bar.
    actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
    mViewPager = (ViewPager) findViewById(R.id.pager);
    mViewPager.setAdapter(mAppSectionsPagerAdapter);
    mViewPager.setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() {
        @Override
        public void onPageSelected(int position) {
            actionBar.setSelectedNavigationItem(position);

            SpannableString s = new SpannableString(mAppSectionsPagerAdapter.getPageTitle(position));
            s.setSpan(new TypefaceSpan(getApplicationContext(), "GothaProReg.otf"), 0, s.length(),
                    Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);

            actionBar.setTitle(s);
        }
    });

    // For each of the sections in the app, add a tab to the action bar.
    for (int i = 0; i < mAppSectionsPagerAdapter.getCount(); i++) {
        actionBar.addTab(
                actionBar.newTab().setIcon(mAppSectionsPagerAdapter.getPageIcon(i)).setTabListener(this));

    }

}

From source file:com.atwal.wakeup.battery.util.Utilities.java

public static SpannableString highlightKeywords(int color, String text, String keywords,
        boolean actionFirstMatch) {

    if (text != null && keywords != null && text.trim().length() == keywords.trim().length()) {
        return SpannableString.valueOf(text.trim());
    }//  w  ww.  j  a v a 2s .  c om

    SpannableString s = new SpannableString(text);
    Pattern p = Pattern.compile(keywords, Pattern.LITERAL);
    Matcher m = p.matcher(s);
    while (m.find()) {
        int end = m.end();
        try {
            if (s.charAt(end) != ' ') {
                s.setSpan(new UnderlineSpan(), end, s.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
            } else {
                s.setSpan(new UnderlineSpan(), end + 1, s.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }

        if (actionFirstMatch) {
            break;
        }
    }
    return s;
}

From source file:com.ntsync.android.sync.activities.KeyPasswordActivity.java

@Override
public void onCreate(Bundle icicle) {
    super.onCreate(icicle);
    SystemHelper.initSystem(this);

    Log.i(TAG, "loading data from Intent");
    final Intent intent = getIntent();
    mUsername = intent.getStringExtra(PARAM_USERNAME);
    pwdSalt = intent.getByteArrayExtra(PARAM_SALT);
    pwdCheck = intent.getByteArrayExtra(PARAM_CHECK);

    requestWindowFeature(Window.FEATURE_LEFT_ICON);
    setContentView(R.layout.keypassword_activity);
    getWindow().setFeatureDrawableResource(Window.FEATURE_LEFT_ICON, R.drawable.key);
    mMessage = (TextView) findViewById(R.id.message_bottom);

    mPasswordEdit = new AutoCompleteTextView[5];
    mPasswordEdit[0] = (AutoCompleteTextView) findViewById(R.id.pwd1_edit);
    mPasswordEdit[1] = (AutoCompleteTextView) findViewById(R.id.pwd2_edit);
    mPasswordEdit[2] = (AutoCompleteTextView) findViewById(R.id.pwd3_edit);
    mPasswordEdit[3] = (AutoCompleteTextView) findViewById(R.id.pwd4_edit);
    mPasswordEdit[4] = (AutoCompleteTextView) findViewById(R.id.pwd5_edit);
    for (AutoCompleteTextView textView : mPasswordEdit) {
        textView.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_FLAG_AUTO_COMPLETE
                | InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS | InputType.TYPE_TEXT_VARIATION_PASSWORD);
    }/*from   ww w  .j a  va2 s.  c  o m*/

    if (pwdSalt == null || pwdSalt.length != ClientKeyHelper.SALT_LENGHT || pwdCheck == null) {
        // disable password input
        for (AutoCompleteTextView textView : mPasswordEdit) {
            if (textView != null) {
                textView.setEnabled(false);
            }
        }
    }
    msgNewKey = (TextView) findViewById(R.id.message_newkey);
    SpannableString newKeyText = SpannableString.valueOf(getText(R.string.keypwd_activity_newkey_label));

    newKeyText.setSpan(new InternalURLSpan(this), 0, newKeyText.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
    msgNewKey.setText(newKeyText, BufferType.SPANNABLE);
    msgNewKey.setMovementMethod(LinkMovementMethod.getInstance());
}

From source file:com.fuzz.emptyhusk.BoldTextCellGenerator.java

@NonNull
@Override//w ww .  j  a  v a2 s .  c om
protected Spannable getTextFor(@NonNull Context context, int position) {
    String[] introStrings = context.getResources().getStringArray(R.array.introductory_messages);

    SpannableString ssb = new SpannableString(introStrings[position]);
    MigratoryStyleSpan span = new MigratoryStyleSpan(BOLD);

    // Order matters when setting spans. The base color must be in place first

    ForegroundColorSpan colorSpan = new ForegroundColorSpan(
            ContextCompat.getColor(context, R.color.colorSecondary));
    ssb.setSpan(colorSpan, 0, ssb.length(), Spannable.SPAN_INCLUSIVE_INCLUSIVE);

    // Only then should custom MigratorySpans be set.

    MigratoryRange<Integer> coverage = span.getCoverage(ssb);
    int start = coverage.getLower();
    int end = coverage.getUpper();
    ssb.setSpan(span, start, end, span.preferredFlags(0));

    MigratoryForegroundColorSpan boldColorSpan = new MigratoryForegroundColorSpan(
            ContextCompat.getColor(context, R.color.colorAccent));
    ssb.setSpan(boldColorSpan, start, end, boldColorSpan.preferredFlags(0));

    return ssb;
}

From source file:com.citrus.sdk.fragments.SavedOptions.java

private void showSignInFlow(String errorMessage) {
    signInLayout = (RelativeLayout) returnView.findViewById(R.id.signInLayout);
    signInLayout.setVisibility(View.VISIBLE);
    usernameET = (EditText) returnView.findViewById(R.id.username);
    passwordET = (EditText) returnView.findViewById(R.id.password);
    errorText = (TextView) returnView.findViewById(R.id.errorText);

    resetPass = (TextView) returnView.findViewById(R.id.resetPass);

    passwordET.requestFocus();//from   w  w w .j a v a2 s .  co  m

    String udata = "Reset Password?";
    SpannableString content = new SpannableString(udata);
    content.setSpan(new UnderlineSpan(), 0, udata.length(), 0);
    resetPass.setText(content);

    usernameET.setText(OneClicksignup.getDefaultGmail(getActivity()));
    errorText.setText(errorMessage);
    Button signIn = (Button) returnView.findViewById(R.id.signIn);
    signIn.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            String username = usernameET.getText().toString();
            String password = passwordET.getText().toString();
            String params[] = new String[] { username, password };
            signInLayout.setVisibility(View.INVISIBLE);
            progressBar.setVisibility(View.VISIBLE);
            new SignInAsynch(getActivity(), signInListener).execute(params);
        }
    });

    resetPass.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View view) {
            showPopup();
        }
    });
}

From source file:org.anoopam.main.anoopamvideo.VideoCatListActivity.java

@Override
public void manageAppBar(ActionBar actionBar, Toolbar toolbar, ActionBarDrawerToggle actionBarDrawerToggle) {
    actionBar.setDisplayHomeAsUpEnabled(true);
    toolbar.setNavigationOnClickListener(new View.OnClickListener() {
        @Override//www . j a  va2  s. c o  m
        public void onClick(View v) {

            handleBackPress();

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

From source file:xyz.getgoing.going.MainPagerAdapter.java

/** Fills action bar with icons */
@Override//from  ww  w .  j a va 2s. c  o m
public CharSequence getPageTitle(int position) {
    Drawable image = mMainActivity.getResources().getDrawable(mImageResIdsUnselected[position]);

    if (position == mCurrentPosition) {
        image = mMainActivity.getResources().getDrawable(mImageResIdsSelected[position]);
    }

    image.setBounds(0, 0, image.getIntrinsicWidth(), image.getIntrinsicWidth());
    SpannableString ss = new SpannableString(" ");
    ImageSpan imageSpan = new ImageSpan(image, ImageSpan.ALIGN_BOTTOM);
    ss.setSpan(imageSpan, 0, 1, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
    return ss;

}

From source file:org.jraf.android.dcn.wearable.app.notif.NotificationWearableListenerService.java

private void showNotification(String title, String textShort, String textLong, @Nullable Bitmap photo,
        Uri contactUri, @Nullable String phoneNumber) {
    Log.d();//from   ww  w  .j av  a  2s  .co  m
    NotificationCompat.Builder mainNotifBuilder = new NotificationCompat.Builder(this);

    // Small icon
    mainNotifBuilder.setSmallIcon(R.drawable.ic_launcher);

    // Title
    SpannableString spannableTitle = new SpannableString(title);
    Object appearanceSpan = new TextAppearanceSpan(this, R.style.NotificationContentTitleTextAppearance);
    spannableTitle.setSpan(appearanceSpan, 0, title.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
    mainNotifBuilder.setContentTitle(spannableTitle);

    // Text (short) -- This may be completely useless since the "big text style" (below) is always used instead
    SpannableString spannableTextShort = new SpannableString(textShort);
    appearanceSpan = new TextAppearanceSpan(this, R.style.NotificationContentTextTextAppearance);
    spannableTextShort.setSpan(appearanceSpan, 0, textShort.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
    mainNotifBuilder.setContentText(spannableTextShort);

    // Text (long)
    SpannableString spannableTextLong = new SpannableString(textLong);
    appearanceSpan = new TextAppearanceSpan(this, R.style.NotificationContentTextTextAppearance);
    spannableTextLong.setSpan(appearanceSpan, 0, textLong.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
    mainNotifBuilder.setStyle(new NotificationCompat.BigTextStyle().bigText(spannableTextLong));

    // Dismiss intent
    Intent dismissIntent = new Intent(NotificationIntentService.ACTION_DISMISS_NOTIFICATION, null, this,
            NotificationIntentService.class);
    PendingIntent dismissPendingIntent = PendingIntent.getService(this, 0, dismissIntent,
            PendingIntent.FLAG_UPDATE_CURRENT);
    mainNotifBuilder.setDeleteIntent(dismissPendingIntent);

    // Wear specifics
    NotificationCompat.WearableExtender wearableExtender = new NotificationCompat.WearableExtender();

    // Contact photo
    if (photo != null)
        wearableExtender.setBackground(photo);

    // Actions
    if (phoneNumber != null) {
        // Call action
        Intent callIntent = new Intent(NotificationIntentService.ACTION_CALL, null, this,
                NotificationIntentService.class);
        callIntent.putExtra(NotificationIntentService.EXTRA_PHONE_NUMBER, phoneNumber);
        PendingIntent callPendingIntent = PendingIntent.getService(this, 0, callIntent,
                PendingIntent.FLAG_UPDATE_CURRENT);
        String callText = getString(R.string.notification_action_call);
        wearableExtender.addAction(
                new NotificationCompat.Action(R.drawable.ic_action_call_full, callText, callPendingIntent));

        // Sms action
        Intent smsIntent = new Intent(NotificationIntentService.ACTION_SMS, null, this,
                NotificationIntentService.class);
        smsIntent.putExtra(NotificationIntentService.EXTRA_PHONE_NUMBER, phoneNumber);
        PendingIntent smsPendingIntent = PendingIntent.getService(this, 0, smsIntent,
                PendingIntent.FLAG_UPDATE_CURRENT);
        String smsText = getString(R.string.notification_action_sms);
        wearableExtender.addAction(
                new NotificationCompat.Action(R.drawable.ic_action_sms_full, smsText, smsPendingIntent));
    }

    // 'Show contact' action
    Intent showContactIntent = new Intent(NotificationIntentService.ACTION_SHOW_CONTACT, null, this,
            NotificationIntentService.class);
    showContactIntent.setData(contactUri);
    PendingIntent showContactPendingIntent = PendingIntent.getService(this, 0, showContactIntent,
            PendingIntent.FLAG_UPDATE_CURRENT);
    String showContactText = getString(R.string.notification_action_showContact);
    wearableExtender.addAction(new NotificationCompat.Action(R.drawable.ic_action_show_contact_full,
            showContactText, showContactPendingIntent));

    // Misc
    mainNotifBuilder.setPriority(NotificationCompat.PRIORITY_HIGH); // Time sensitive, try to appear on top
    mainNotifBuilder.setCategory(NotificationCompat.CATEGORY_STATUS); // Not sure if this category is really the most appropriate
    wearableExtender.setHintScreenTimeout(NotificationCompat.WearableExtender.SCREEN_TIMEOUT_LONG); // Could be useful

    mainNotifBuilder.extend(wearableExtender);

    // Show the notification
    Notification notification = mainNotifBuilder.build();
    NotificationManager notificationManager = (NotificationManager) getSystemService(
            Context.NOTIFICATION_SERVICE);
    notificationManager.notify(NOTIFICATION_ID, notification);
}

From source file:org.catnut.util.CatnutUtils.java

/**
 * ?//from www .j a  v  a  2  s .c  om
 *
 * @param boundPx the icon' s rectangle bound, if zero, use the default
 */
public static SpannableString text2Emotion(Context context, String key, int boundPx) {
    SpannableString spannable = new SpannableString(key);
    InputStream inputStream = null;
    Drawable drawable = null;
    try {
        inputStream = context.getAssets().open(TweetImageSpan.EMOTIONS_DIR + TweetImageSpan.EMOTIONS.get(key));
        drawable = Drawable.createFromStream(inputStream, null);
    } catch (IOException e) {
        Log.e(TAG, "load emotion error!", e);
    } finally {
        closeIO(inputStream);
    }
    if (drawable != null) {
        if (boundPx == 0) {
            drawable.setBounds(0, 0, drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight());
        } else {
            drawable.setBounds(0, 0, boundPx, boundPx);
        }
        ImageSpan span = new ImageSpan(drawable, ImageSpan.ALIGN_BASELINE);
        spannable.setSpan(span, 0, key.length(), Spannable.SPAN_INCLUSIVE_EXCLUSIVE);
    }
    return spannable;
}

From source file:com.ymt.demo1.main.sign.SignUpFragment.java

/**
 * ???/*from ww  w.java  2s  . c  om*/
 * ?????????
 */
protected void initView(View view) {
    /*
    
     */
    //?
    final EditText phoneTxt = (EditText) view.findViewById(R.id.input_phone_num);
    final EditText accountTxt = (EditText) view.findViewById(R.id.input_account);
    final EditText pswTxt = (EditText) view.findViewById(R.id.input_psw);
    final EditText rePswTxt = (EditText) view.findViewById(R.id.re_input_psw);
    final TextView licenseTxt = (TextView) view.findViewById(R.id.licence_txt);
    /*???? ??
     */
    final TextView getCheckNums = (TextView) view.findViewById(R.id.get_check_nums);
    final EditText inputCheckNums = (EditText) view.findViewById(R.id.input_check_nums);
    getCheckNums.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            //todo ????

        }
    });

    /**
     *  todo spannableString 
     *   ?
     */
    SpannableString spannableString = new SpannableString(getString(R.string.license));
    ForegroundColorSpan span = new ForegroundColorSpan(getResources().getColor(R.color.material_blue_grey_800));
    spannableString.setSpan(span, 0, 7, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
    licenseTxt.setText(spannableString);
    //switch(??)
    myCheckView = (MyCheckView) view.findViewById(R.id.switch_liscense);
    //
    Button signUpBtn = (Button) view.findViewById(R.id.do_sign_btn);
    signUpBtn.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {

            //
            String phoneNum = phoneTxt.getText().toString();
            String account = accountTxt.getText().toString();
            String psw = pswTxt.getText().toString();
            String rePsw = rePswTxt.getText().toString();
            //??
            String checkNums = inputCheckNums.getText().toString();
            //todo if(){}else{} ??

            if (!TextUtils.isEmpty(phoneNum) && !TextUtils.isEmpty(account) && !TextUtils.isEmpty(psw)
                    && psw.equals(rePsw)) {
                //?
                if (myCheckView.isChecked()) {
                    queue.add(signUpRequest(account, psw, phoneNum, NORMAL_USER));
                } else {
                    Toast.makeText(getActivity(), "?????",
                            Toast.LENGTH_SHORT).show();
                }

            } else if (TextUtils.isEmpty(phoneNum)) {
                //???
                Toast.makeText(getActivity(), "???", Toast.LENGTH_SHORT).show();
            } else if (TextUtils.isEmpty(account)) {
                //???
                Toast.makeText(getActivity(), "???", Toast.LENGTH_SHORT).show();
            } else {
                //???
                Toast.makeText(getActivity(), "???", Toast.LENGTH_SHORT)
                        .show();
            }
        }
    });

    LinearLayout licence = (LinearLayout) view.findViewById(R.id.liscense_layout);
    licence.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            myCheckView.callOnClick();
        }
    });
}