List of usage examples for android.text SpannableString length
int length();
From source file:com.gm.goldencity.util.Utils.java
/** * Apply typeface to a plane text and return spannableString * * @param text Text that you want to apply typeface * @param typeface Typeface that you want to apply to your text * @return spannableString/* ww w . j a va2s.c om*/ */ public static SpannableString applyTypefaceToString(String text, final Typeface typeface) { SpannableString spannableString = new SpannableString(text); spannableString.setSpan(new MetricAffectingSpan() { @Override public void updateMeasureState(TextPaint p) { p.setTypeface(typeface); // Note: This flag is required for proper typeface rendering p.setFlags(p.getFlags() | Paint.SUBPIXEL_TEXT_FLAG); } @Override public void updateDrawState(TextPaint tp) { tp.setTypeface(typeface); // Note: This flag is required for proper typeface rendering tp.setFlags(tp.getFlags() | Paint.SUBPIXEL_TEXT_FLAG); } }, 0, spannableString.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); return spannableString; }
From source file:org.thoughtcrime.securesms.components.webrtc.WebRtcCallScreen.java
public void setUntrustedIdentity(Recipient personInfo, IdentityKey untrustedIdentity) { String name = recipient.toShortString(); String introduction = String.format(getContext().getString(R.string.WebRtcCallScreen_new_safety_numbers), name, name);/* w ww . j a va2s . co m*/ SpannableString spannableString = new SpannableString(introduction + " " + getContext().getString(R.string.WebRtcCallScreen_you_may_wish_to_verify_this_contact)); spannableString.setSpan(new VerifySpan(getContext(), personInfo.getRecipientId(), untrustedIdentity), introduction.length() + 1, spannableString.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); setPersonInfo(personInfo); this.incomingCallOverlay.setActiveCall(); this.status.setText(R.string.WebRtcCallScreen_new_safety_numbers_title); this.untrustedIdentityContainer.setVisibility(View.VISIBLE); this.untrustedIdentityExplanation.setText(spannableString); this.untrustedIdentityExplanation.setMovementMethod(LinkMovementMethod.getInstance()); this.endCallButton.setVisibility(View.INVISIBLE); }
From source file:org.floens.chan.ui.controller.ThemeSettingsController.java
@Override public void onCreate() { super.onCreate(); navigationItem.setTitle(R.string.settings_screen_theme); navigationItem.swipeable = false;/*from w w w .j a v a 2 s .c o m*/ view = inflateRes(R.layout.controller_theme); themeHelper = ThemeHelper.getInstance(); themes = themeHelper.getThemes(); pager = (ViewPager) view.findViewById(R.id.pager); done = (FloatingActionButton) view.findViewById(R.id.add); done.setOnClickListener(this); textView = (TextView) view.findViewById(R.id.text); SpannableString changeAccentColor = new SpannableString(getString(R.string.setting_theme_accent)); changeAccentColor.setSpan(new ClickableSpan() { @Override public void onClick(View widget) { showAccentColorPicker(); } }, 0, changeAccentColor.length(), 0); textView.setText(TextUtils.concat(getString(R.string.setting_theme_explanation), changeAccentColor)); textView.setMovementMethod(LinkMovementMethod.getInstance()); adapter = new Adapter(); pager.setAdapter(adapter); ChanSettings.ThemeColor currentSettingsTheme = ChanSettings.getThemeAndColor(); for (int i = 0; i < themeHelper.getThemes().size(); i++) { Theme theme = themeHelper.getThemes().get(i); ThemeHelper.PrimaryColor primaryColor = theme.primaryColor; if (theme.name.equals(currentSettingsTheme.theme)) { // Current theme pager.setCurrentItem(i, false); } selectedPrimaryColors.add(primaryColor); } selectedAccentColor = themeHelper.getTheme().accentColor; done.setBackgroundTintList(ColorStateList.valueOf(selectedAccentColor.color)); }
From source file:eu.veldsoft.adsbobball.ActivityStateEnum.java
protected void update(final Canvas canvas, final GameState currGameState, long frameCounter) { final Player currPlayer = currGameState.getPlayer(playerId); if ((gameView != null)) { gameView.draw(canvas, currGameState); }//from w ww . ja va2s .c om if (frameCounter % displayLoop.ITERATIONS_PER_STATUSUPDATE == 0) { SpannableStringBuilder timeLeftStr = SpannableStringBuilder .valueOf(getString(R.string.timeLeftLabel, gameManager.timeLeft() / 10)); SpannableStringBuilder livesStr = formatPerPlayer(getString(R.string.livesLabel), new playstat() { @Override public int call(Player p) { return p.getLives(); } }); SpannableStringBuilder scoreStr = formatPerPlayer(getString(R.string.scoreLabel), new playstat() { @Override public int call(Player p) { return p.getScore(); } }); SpannableStringBuilder clearedStr = formatPerPlayer(getString(R.string.areaClearedLabel), new playstat() { @Override public int call(Player p) { Grid grid = currGameState.getGrid(); if (grid != null) return currGameState.getGrid().getPercentComplete(p.getPlayerId()); else return 0; } }); // display fps if (secretHandshake >= 3) { float fps = displayLoop.getFPS(); int color = (fps < NUMBER_OF_FRAMES_PER_SECOND * 0.98f ? Color.RED : Color.GREEN); SpannableString s = new SpannableString(String.format(" FPS: %2.1f", fps)); s.setSpan(new ForegroundColorSpan(color), 0, s.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); timeLeftStr.append(s); color = (gameManager.getUPS() < gameManager.NUMBER_OF_UPDATES_PER_SECOND * 0.98f ? Color.RED : Color.GREEN); s = new SpannableString(String.format(" UPS: %3.1f", gameManager.getUPS())); s.setSpan(new ForegroundColorSpan(color), 0, s.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); timeLeftStr.append(s); } statusTopleft.setText(timeLeftStr); statusTopright.setText(livesStr); statusBotleft.setText(scoreStr); statusBotright.setText(clearedStr); } if (gameManager.hasWonLevel()) { showWonScreen(); } else if (gameManager.isGameLost()) { if ((numPlayers == 1) && scores.isTopScore(currPlayer.getScore())) { promptUsername(); } showDeadScreen(); } }
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 {/* w w w . j a v a 2s . c om*/ 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.ubercab.client.feature.notification.handler.TripNotificationHandler.java
private NotificationCompat.InboxStyle buildStyleInbox(NotificationCompat.Builder paramBuilder, TripNotificationData paramTripNotificationData, String paramString) { NotificationCompat.InboxStyle localInboxStyle = new NotificationCompat.InboxStyle(paramBuilder) .setSummaryText(paramString); Iterator localIterator = paramTripNotificationData.getFareSplitClients().iterator(); while (localIterator.hasNext()) { TripNotificationData.FareSplitClient localFareSplitClient = (TripNotificationData.FareSplitClient) localIterator .next();/*from w w w . ja v a 2 s. co m*/ SpannableString localSpannableString = new SpannableString(localFareSplitClient.getName()); localSpannableString.setSpan(new StyleSpan(1), 0, localSpannableString.length(), 33); SpannableStringBuilder localSpannableStringBuilder = new SpannableStringBuilder(); localSpannableStringBuilder.append(localSpannableString); localSpannableStringBuilder.append(" "); localSpannableStringBuilder.append(localFareSplitClient.getDisplayStatus(getContext())); localInboxStyle.addLine(localSpannableStringBuilder); } return localInboxStyle; }
From source file:com.example.lowviscam.GalleryActivity.java
@Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu items for use in the action bar MenuInflater inflater = getMenuInflater(); if (isLight == true) { inflater.inflate(R.menu.gallery, menu); } else {// w w w. j av a 2 s. c o m inflater.inflate(R.menu.gallery_dark, menu); } // Get the SearchView and set the searchable configuration SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE); SearchView searchView = (SearchView) menu.findItem(R.id.action_search).getActionView(); // Assumes current activity is the searchable activity searchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName())); searchView.setIconifiedByDefault(false); // Do not iconify the widget; expand it by default searchView.setSubmitButtonEnabled(true); searchView.setOnQueryTextListener(new OnQueryTextListener() { @Override public boolean onQueryTextSubmit(String query) { search(query); // First image toast String firstResult; if (numSearchResults == 0) { firstResult = "No results found for " + query + "."; } else { firstResult = "The first image result is titled " + tagList[0]; } SpannableString s = new SpannableString(firstResult); s.setSpan(new TypefaceSpan(GalleryActivity.this, "APHont-Regular_q15c.otf"), 0, s.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); Toast.makeText(GalleryActivity.this, s, Toast.LENGTH_LONG).show(); return true; } @Override public boolean onQueryTextChange(String newText) { if (TextUtils.isEmpty(newText)) { search(""); } return true; } public void search(String query) { // hide keyboard InputMethodManager inputManager = (InputMethodManager) GalleryActivity.this .getSystemService(Context.INPUT_METHOD_SERVICE); inputManager.hideSoftInputFromWindow(GalleryActivity.this.getCurrentFocus().getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS); // 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); try { gridView.setAdapter(new CouponAdapter(inflater, createSearchedCoupons(query))); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } }); return true; //return super.onCreateOptionsMenu(menu); }
From source file:cw.kop.autobackground.tutorial.FinishFragment.java
@Override public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { View view = inflater.inflate(R.layout.tutorial_finish_fragment, container, false); int colorFilterInt = AppSettings.getColorFilterInt(appContext); TextView titleText = (TextView) view.findViewById(R.id.title_text); titleText.setTextColor(colorFilterInt); titleText.setText("That's it."); TextView tutorialText = (TextView) view.findViewById(R.id.tutorial_text); tutorialText.setTextColor(colorFilterInt); tutorialText.setText("Now you're ready to use AutoBackground. I'd suggest adding a new source first " + "and then hitting download." + "\n" + "\n" + "If you have any questions, concerns, suggestions, or whatever else, feel free to " + "email me at "); SpannableString emailString = new SpannableString("chiuwinson@gmail.com"); ClickableSpan clickableSpan = new ClickableSpan() { @Override//from w w w . j a va2s . c o m public void onClick(View widget) { Log.i(TAG, "Clicked"); Intent emailIntent = new Intent(Intent.ACTION_SENDTO, Uri.fromParts("mailto", "chiuwinson@gmail.com", null)); emailIntent.putExtra(Intent.EXTRA_SUBJECT, "AutoBackground Feedback"); startActivity(Intent.createChooser(emailIntent, "Send email")); } }; emailString.setSpan(clickableSpan, 0, emailString.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); tutorialText.append(emailString); tutorialText.append("."); tutorialText.setMovementMethod(LinkMovementMethod.getInstance()); return view; }
From source file:uk.co.threeonefour.android.snowball.activities.game.GameActivity.java
@Override public void processCommand(String command) { if (!initialised) { return;/*from w w w . ja va 2s.com*/ } 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.example.lowviscam.GalleryActivity.java
@Override public boolean onOptionsItemSelected(MenuItem item) { // Handle presses on the action bar items switch (item.getItemId()) { case R.id.action_search: return true; case R.id.action_about: // 1. Instantiate an AlertDialog.Builder with its constructor AlertDialog.Builder builder = new AlertDialog.Builder(this); // 2. Chain together various setter methods to set the dialog characteristics String aboutString = getResources().getString(R.string.dialog_message); String titleString = getResources().getString(R.string.dialog_title); SpannableString sa = new SpannableString(aboutString); SpannableString st = new SpannableString(titleString); sa.setSpan(new TypefaceSpan(this, "APHont-Regular_q15c.otf"), 0, sa.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); st.setSpan(new TypefaceSpan(this, "APHont-Bold_q15c.otf"), 0, st.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); builder.setMessage(sa).setTitle(st).setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { // User clicked OK button }/*from w ww .j a v a 2 s .co m*/ }); ; // 3. Get the AlertDialog from create() AlertDialog dialog = builder.create(); dialog.show(); return true; default: return super.onOptionsItemSelected(item); } }