List of usage examples for android.text SpannableString SpannableString
public SpannableString(CharSequence source)
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//ww w. java 2s . 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:com.nkahoang.screenstandby.Main.java
private void warning() { try {// w w w. j av a 2s . co m String build = android.os.Build.MODEL.toLowerCase(); if (build.contains("i535") || build.contains("d2vzw") || build.contains("d2spr") || build.contains("d2tmo")) { TextView tv = (TextView) this.findViewById(R.id.textView1); Spannable warning = new SpannableString( "IMPORTANT! This app is currently has compatibility problem with your device (" + build + ") as it may freezes up the screen. I am sorry for the problem and is trying my best to fix this"); warning.setSpan(new ForegroundColorSpan(Color.RED), 0, warning.length(), 0); tv.setText(warning); } } catch (Exception ex) { } }
From source file:at.jclehner.rxdroid.SplashScreenActivity.java
@TargetApi(11) @Override/*w w w . j a va 2 s .com*/ protected void onCreate(Bundle savedInstanceState) { Settings.init(); setTheme(Theme.get()); setContentView(R.layout.loader); mDate = Settings.getActiveDate(); final SpannableString dateString = new SpannableString(DateTime.toNativeDate(mDate)); Util.applyStyle(dateString, new RelativeSizeSpan(0.75f)); Util.applyStyle(dateString, new UnderlineSpan()); getSupportActionBar().setSubtitle(dateString); try { Class.forName(com.michaelnovakjr.numberpicker.NumberPicker.class.getName()); } catch (ClassNotFoundException e) { throw new WrappedCheckedException("NumberPicker library is missing", e); } super.onCreate(savedInstanceState); }
From source file:com.example.lowviscam.GalleryActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); isLight = getIntent().getExtras().getBoolean("isLight"); if (isLight == false) { this.setTheme(R.style.AppBaseThemeDark); } else {/* www. j a v a2 s . co m*/ this.setTheme(R.style.AppBaseTheme); } setContentView(R.layout.activity_gallery); // Retrieve APHont font and apply it mFace = Typeface.createFromAsset(getAssets(), "fonts/APHont-Regular_q15c.otf"); SpannableString s = new SpannableString("Image Gallery"); s.setSpan(new TypefaceSpan(this, "APHont-Bold_q15c.otf"), 0, s.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); // Update the action bar title with the TypefaceSpan instance ActionBar actionBar = getActionBar(); actionBar.setTitle(s); actionBar.setDisplayHomeAsUpEnabled(true); // Fetch the {@link LayoutInflater} service so that new views can be created LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE); // Find the {@link GridView} that was already defined in the XML layout GridView gridView = (GridView) findViewById(R.id.grid); // Initialize the adapter with all the coupons. Set the adapter on the {@link GridView}. try { gridView.setAdapter(new CouponAdapter(inflater, createAllCoupons())); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } // Set a click listener for each picture in the grid gridView.setOnItemClickListener(this); gridView.setOnTouchListener(new OnSwipeTouchListener() { public void onSwipeTop() { //Toast.makeText(GalleryActivity.this, "top", Toast.LENGTH_SHORT).show(); } public void onSwipeRight() { //Toast.makeText(GalleryActivity.this, "right", Toast.LENGTH_SHORT).show(); } public void onSwipeLeft() { //Toast.makeText(GalleryActivity.this, "left", Toast.LENGTH_SHORT).show(); } public void onSwipeBottom() { //Toast.makeText(GalleryActivity.this, "bottom", Toast.LENGTH_SHORT).show(); } }); gridView.setOnItemLongClickListener(new OnItemLongClickListener() { public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) { // Find coupon that was clicked based off of position in adapter Coupon coupon = (Coupon) parent.getItemAtPosition(position); //Get absolutepath of image for adding. File list[] = mediaStorageDir.listFiles(); File tmpFile = list[list.length - position - 1]; String photoUri = coupon.mImageUri.toString(); try { photoUri = MediaStore.Images.Media.insertImage(getContentResolver(), tmpFile.getAbsolutePath(), null, null); } catch (FileNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } // Create share intent Intent shareIntent = ShareCompat.IntentBuilder.from(GalleryActivity.this).setText(coupon.mTitle) .setType("image/jpeg").setStream(Uri.parse(photoUri)) .setChooserTitle(getString(R.string.share_using)).createChooserIntent(); startActivity(shareIntent); return true; } }); }
From source file:com.orange.ocara.ui.activity.BaseActivityManagingAudit.java
public void showAuditObjectProgress(AuditObject auditObject, final boolean terminateActivityWhenDone) { CharSequence info = getText(com.orange.ocara.R.string.auditing_progress_info); Spannable auditingStatus = new SpannableString(""); int color = getResources().getColor(com.orange.ocara.R.color.black); switch (auditObject.getResponse()) { case OK:/*from ww w . ja v a 2s . c o m*/ auditingStatus = new SpannableString(getText(com.orange.ocara.R.string.auditing_progress_status_ok)); color = getResources().getColor(com.orange.ocara.R.color.green); break; case NOK: if (auditObject.hasAtLeastOneBlockingRule()) { auditingStatus = new SpannableString( getText(com.orange.ocara.R.string.auditing_progress_status_nok)); color = getResources().getColor(com.orange.ocara.R.color.red); } else { auditingStatus = new SpannableString( getText(com.orange.ocara.R.string.auditing_progress_status_anoying)); color = getResources().getColor(com.orange.ocara.R.color.orange); } break; case DOUBT: auditingStatus = new SpannableString(getText(com.orange.ocara.R.string.auditing_progress_status_doubt)); color = getResources().getColor(com.orange.ocara.R.color.yellow); break; case NoAnswer: auditingStatus = new SpannableString( getText(com.orange.ocara.R.string.auditing_progress_status_no_answer)); color = getResources().getColor(com.orange.ocara.R.color.blue); break; } auditingStatus.setSpan(new ForegroundColorSpan(color), info.length(), auditingStatus.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); StringBuffer stringBuffer = new StringBuffer(info); stringBuffer.append("<br>").append(auditingStatus); // get application preference to know if he wants to audit object now SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this); int displayAuditingProgessDialog = Integer.parseInt(sharedPreferences .getString(getString(com.orange.ocara.R.string.setting_display_auditing_progress_key), "1")); switch (displayAuditingProgessDialog) { case 1: final NotificationDialogBuilder dialogBuilder = new NotificationDialogBuilder(this); final AlertDialog dialog = dialogBuilder.setInfo(auditingStatus) .setOption(getString(com.orange.ocara.R.string.auditing_progress_option)).setCancelable(false) .setTitle(com.orange.ocara.R.string.auditing_progress_title) .setOnDismissListener(new DialogInterface.OnDismissListener() { @Override public void onDismiss(DialogInterface dialog) { auditingProgressDismiss(dialogBuilder.getOptionValue()); if (terminateActivityWhenDone) { BaseActivityManagingAudit.this.finish(); } } }).setPositiveButton(com.orange.ocara.R.string.action_close, null).create(); Handler handler = new Handler(); handler.postDelayed(new Runnable() { @Override public void run() { dialog.dismiss(); } }, 3500); dialog.show(); break; default: if (terminateActivityWhenDone) { BaseActivityManagingAudit.this.finish(); } break; } }
From source file:com.liuwuping.sm.ui.user.UserActivity.java
private SpannableString newTabTitle(CharSequence old, int add) { int start = old.length(); String newStr = old.toString() + "\n" + add; CharSequence newCs = newStr;/* w ww .j a v a2s.c o m*/ SpannableString ss = new SpannableString(newCs); ss.setSpan(new TextAppearanceSpan(this, R.style.TabTitleNum), start, newCs.length(), 0); return ss; }
From source file:org.cnc.mombot.utils.ContactsEditText.java
private void init(Context context) { // Set image height mDropdownItemHeight = 48;/*from w ww . ja v a2 s . c o m*/ // Set default image BitmapFactory.Options options = new BitmapFactory.Options(); options.inJustDecodeBounds = true; BitmapFactory.decodeResource(context.getResources(), R.drawable.ic_contact_picture_holo_light, options); options.inSampleSize = Utils.calculateInSampleSize(options, mDropdownItemHeight, mDropdownItemHeight); options.inJustDecodeBounds = false; mLoadingImage = BitmapFactory.decodeResource(context.getResources(), R.drawable.ic_contact_picture_holo_light, options); // Set adapter mAdapter = new ContactsAdapter(context); setAdapter(mAdapter); mAdapter.swapCursor(mAdapter.runQueryOnBackgroundThread("")); // Separate entries by commas setTokenizer(new Tokenizer() { @Override public CharSequence terminateToken(CharSequence text) { int i = text.length(); while (i > 0 && text.charAt(i - 1) == ' ') { i--; } if (i > 0 && text.charAt(i - 1) == ' ') { return text; } else { if (text instanceof Spanned) { SpannableString sp = new SpannableString(text + " "); TextUtils.copySpansFrom((Spanned) text, 0, text.length(), Object.class, sp, 0); return sp; } else { return text + " "; } } } @Override public int findTokenStart(CharSequence text, int cursor) { int i = cursor; while (i > 0 && text.charAt(i - 1) != ' ') { i--; } // Check if token really started with ' ', else we don't have a valid token if (i < 1 || text.charAt(i - 1) != ' ') { return cursor; } return i; } @Override public int findTokenEnd(CharSequence text, int cursor) { int i = cursor; int len = text.length(); while (i < len) { if (text.charAt(i) == ' ') { return i; } else { i++; } } return len; } }); // Pop up suggestions after 1 character is typed. setThreshold(1); setOnClickListener(this); setOnFocusChangeListener(this); }
From source file:com.todoroo.astrid.tags.TagsControlSet.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)).replace(' ', NO_BREAK_SPACE);/*from w ww . ja v a2 s.co m*/ SpannableString string = new SpannableString(NO_BREAK_SPACE + tagName + NO_BREAK_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 source file:com.csipsimple.utils.contacts.ContacksSearchGridAdapter.java
private boolean highlightTextViewSearch(TextView tv) { if (currentFilter.length() > 0) { String value = tv.getText().toString(); int foundIdx = value.toLowerCase().indexOf(currentFilter); if (foundIdx >= 0) { SpannableString spn = new SpannableString(value); spn.setSpan(boldStyle, foundIdx, foundIdx + currentFilter.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); spn.setSpan(highlightStyle, foundIdx, foundIdx + currentFilter.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); tv.setText(spn);/*from ww w . ja va 2s . c o m*/ return true; } } return false; }
From source file:org.medankulinar.MixListView.java
private void doMixSearch(String query) { DataHandler jLayer = dataView.getDataHandler(); if (!dataView.isFrozen()) { originalMarkerList = jLayer.getMarkerList(); MixMap.originalMarkerList = jLayer.getMarkerList(); }//from w w w .j a v a 2s. c o m originalMarkerList = jLayer.getMarkerList(); searchResultMarkers = new ArrayList<Marker>(); Log.d("SEARCH-------------------0", "" + query); setSearchQuery(query); selectedItemURL = new Vector<String>(); listViewMenu = new Vector<SpannableString>(); for (int i = 0; i < jLayer.getMarkerCount(); i++) { Marker ma = jLayer.getMarker(i); if (ma.getTitle().toLowerCase().indexOf(searchQuery.toLowerCase()) != -1) { searchResultMarkers.add(ma); listViewMenu.add(new SpannableString(ma.getTitle())); /*the website for the corresponding title*/ if (ma.getURL() != null) selectedItemURL.add(ma.getURL()); /*if no website is available for a specific title*/ else selectedItemURL.add(""); } } if (listViewMenu.size() == 0) { Toast.makeText(this, getString(R.string.search_failed_notification), Toast.LENGTH_LONG).show(); } else { jLayer.setMarkerList(searchResultMarkers); dataView.setFrozen(true); finish(); Intent intent1 = new Intent(this, MixListView.class); startActivityForResult(intent1, 42); } }