List of usage examples for android.text Spanned SPAN_EXCLUSIVE_EXCLUSIVE
int SPAN_EXCLUSIVE_EXCLUSIVE
To view the source code for android.text Spanned SPAN_EXCLUSIVE_EXCLUSIVE.
Click Source Link
From source file:map.IconGeneratorDemoActivity.java
private CharSequence makeCharSequence() { String prefix = "Mixing "; String suffix = "different fonts"; String sequence = prefix + suffix; SpannableStringBuilder ssb = new SpannableStringBuilder(sequence); ssb.setSpan(new StyleSpan(ITALIC), 0, prefix.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); ssb.setSpan(new StyleSpan(BOLD), prefix.length(), sequence.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); return ssb;//from w ww . j a va 2s .c om }
From source file:eu.veldsoft.adsbobball.ActivityStateEnum.java
public SpannableStringBuilder formatPerPlayer(String fixed, playstat query) { SpannableStringBuilder sps = SpannableStringBuilder.valueOf(fixed); for (Player p : gameManager.getCurrGameState().getPlayers()) { if (p.getPlayerId() == 0) continue; SpannableString s = new SpannableString(String.valueOf(query.call(p)) + " "); s.setSpan(new ForegroundColorSpan(p.getColor()), 0, s.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); sps.append(s);//from www . ja v a 2 s. com } return sps; }
From source file:org.telegram.ui.IdenticonActivity.java
@Override public View createView(Context context) { actionBar.setBackButtonImage(R.drawable.ic_ab_back); actionBar.setAllowOverlayTitle(true); actionBar.setTitle(LocaleController.getString("EncryptionKey", R.string.EncryptionKey)); actionBar.setActionBarMenuOnItemClick(new ActionBar.ActionBarMenuOnItemClick() { @Override/*from w w w . jav a2 s . c o m*/ public void onItemClick(int id) { if (id == -1) { finishFragment(); } } }); fragmentView = new LinearLayout(context); LinearLayout linearLayout = (LinearLayout) fragmentView; linearLayout.setOrientation(LinearLayout.VERTICAL); linearLayout.setWeightSum(100); linearLayout.setBackgroundColor(ContextCompat.getColor(context, R.color.card_background)); fragmentView.setOnTouchListener(new View.OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { return true; } }); FrameLayout frameLayout = new FrameLayout(context); frameLayout.setPadding(AndroidUtilities.dp(20), AndroidUtilities.dp(20), AndroidUtilities.dp(20), AndroidUtilities.dp(20)); linearLayout.addView(frameLayout, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT, 50.0f)); ImageView identiconView = new ImageView(context); identiconView.setScaleType(ImageView.ScaleType.FIT_XY); frameLayout.addView(identiconView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT)); frameLayout = new FrameLayout(context); frameLayout.setBackgroundColor(ContextCompat.getColor(context, R.color.background)); frameLayout.setPadding(AndroidUtilities.dp(10), 0, AndroidUtilities.dp(10), AndroidUtilities.dp(10)); linearLayout.addView(frameLayout, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT, 50.0f)); TextView textView = new TextView(context); textView.setTextColor(ContextCompat.getColor(context, R.color.secondary_text)); textView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 16); textView.setLinksClickable(true); textView.setClickable(true); textView.setMovementMethod(new LinkMovementMethodMy()); //textView.setAutoLinkMask(Linkify.WEB_URLS); textView.setLinkTextColor(Theme.MSG_LINK_TEXT_COLOR); textView.setGravity(Gravity.CENTER); frameLayout.addView(textView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT)); TLRPC.EncryptedChat encryptedChat = MessagesController.getInstance().getEncryptedChat(chat_id); if (encryptedChat != null) { IdenticonDrawable drawable = new IdenticonDrawable(); identiconView.setImageDrawable(drawable); drawable.setEncryptedChat(encryptedChat); TLRPC.User user = MessagesController.getInstance().getUser(encryptedChat.user_id); SpannableStringBuilder hash = new SpannableStringBuilder(); if (encryptedChat.key_hash.length > 16) { String hex = Utilities.bytesToHex(encryptedChat.key_hash); for (int a = 0; a < 32; a++) { if (a != 0) { if (a % 8 == 0) { hash.append('\n'); } else if (a % 4 == 0) { hash.append(' '); } } hash.append(hex.substring(a * 2, a * 2 + 2)); hash.append(' '); } hash.append("\n\n"); } hash.append(AndroidUtilities.replaceTags(LocaleController.formatString("EncryptionKeyDescription", R.string.EncryptionKeyDescription, user.first_name, user.first_name))); final String url = "telegram.org"; int index = hash.toString().indexOf(url); if (index != -1) { hash.setSpan( new URLSpanReplacement( LocaleController.getString("EncryptionKeyLink", R.string.EncryptionKeyLink)), index, index + url.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); } textView.setText(hash); } return fragmentView; }
From source file:nya.miku.wishmaster.ui.settings.AutohideActivity.java
@SuppressLint("InflateParams") @Override// w ww . j a v a 2s .c om protected void onListItemClick(ListView l, View v, int position, long id) { super.onListItemClick(l, v, position, id); Object item = l.getItemAtPosition(position); final int changeId; if (item instanceof AutohideRule) { changeId = position - 1; } else { changeId = -1; //-1 - ? } Context dialogContext = Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB ? new ContextThemeWrapper(this, R.style.Neutron_Medium) : this; View dialogView = LayoutInflater.from(dialogContext).inflate(R.layout.dialog_autohide_rule, null); final EditText regexEditText = (EditText) dialogView.findViewById(R.id.dialog_autohide_regex); final Spinner chanSpinner = (Spinner) dialogView.findViewById(R.id.dialog_autohide_chan_spinner); final EditText boardEditText = (EditText) dialogView.findViewById(R.id.dialog_autohide_boardname); final EditText threadEditText = (EditText) dialogView.findViewById(R.id.dialog_autohide_threadnum); final CheckBox inCommentCheckBox = (CheckBox) dialogView.findViewById(R.id.dialog_autohide_in_comment); final CheckBox inSubjectCheckBox = (CheckBox) dialogView.findViewById(R.id.dialog_autohide_in_subject); final CheckBox inNameCheckBox = (CheckBox) dialogView.findViewById(R.id.dialog_autohide_in_name); chanSpinner.setAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, chans)); if (changeId != -1) { AutohideRule rule = (AutohideRule) item; regexEditText.setText(rule.regex); int chanPosition = chans.indexOf(rule.chanName); chanSpinner.setSelection(chanPosition != -1 ? chanPosition : 0); boardEditText.setText(rule.boardName); threadEditText.setText(rule.threadNumber); inCommentCheckBox.setChecked(rule.inComment); inSubjectCheckBox.setChecked(rule.inSubject); inNameCheckBox.setChecked(rule.inName); } else { chanSpinner.setSelection(0); } DialogInterface.OnClickListener save = new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { String regex = regexEditText.getText().toString(); if (regex.length() == 0) { Toast.makeText(AutohideActivity.this, R.string.autohide_error_empty_regex, Toast.LENGTH_LONG) .show(); return; } try { Pattern.compile(regex, Pattern.CASE_INSENSITIVE | Pattern.UNICODE_CASE | Pattern.DOTALL); } catch (Exception e) { CharSequence message = null; if (e instanceof PatternSyntaxException) { String eMessage = e.getMessage(); if (!TextUtils.isEmpty(eMessage)) { SpannableStringBuilder a = new SpannableStringBuilder( getString(R.string.autohide_error_incorrect_regex)); a.append('\n'); int startlen = a.length(); a.append(eMessage); a.setSpan(new TypefaceSpan("monospace"), startlen, a.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); message = a; } } if (message == null) message = getString(R.string.error_unknown); Toast.makeText(AutohideActivity.this, message, Toast.LENGTH_LONG).show(); return; } AutohideRule rule = new AutohideRule(); int spinnerSelectedPosition = chanSpinner.getSelectedItemPosition(); rule.regex = regex; rule.chanName = spinnerSelectedPosition > 0 ? chans.get(spinnerSelectedPosition) : ""; // 0 ? = ? rule.boardName = boardEditText.getText().toString(); rule.threadNumber = threadEditText.getText().toString(); rule.inComment = inCommentCheckBox.isChecked(); rule.inSubject = inSubjectCheckBox.isChecked(); rule.inName = inNameCheckBox.isChecked(); if (!rule.inComment && !rule.inSubject && !rule.inName) { Toast.makeText(AutohideActivity.this, R.string.autohide_error_no_condition, Toast.LENGTH_LONG) .show(); return; } if (changeId == -1) { rulesJson.put(rule.toJson()); } else { rulesJson.put(changeId, rule.toJson()); } rulesChanged(); } }; AlertDialog dialog = new AlertDialog.Builder(this).setView(dialogView) .setTitle(changeId == -1 ? R.string.autohide_add_rule_title : R.string.autohide_edit_rule_title) .setPositiveButton(R.string.autohide_save_button, save) .setNegativeButton(android.R.string.cancel, null).create(); dialog.setCanceledOnTouchOutside(false); dialog.show(); }
From source file:com.zd.vpn.fragments.AboutFragment.java
private void createPlayBuyOptions(ArrayList<String> ownedSkus, ArrayList<String> responseList) { try {//from w ww . j a v a 2s.co m Vector<Pair<String, String>> gdonation = new Vector<Pair<String, String>>(); gdonation.add(new Pair<String, String>(getString(R.string.donatePlayStore), null)); HashMap<String, SkuResponse> responseMap = new HashMap<String, SkuResponse>(); for (String thisResponse : responseList) { JSONObject object = new JSONObject(thisResponse); responseMap.put(object.getString("productId"), new SkuResponse(object.getString("price"), object.getString("title"))); } for (String sku : donationSkus) if (responseMap.containsKey(sku)) gdonation.add( getSkuTitle(sku, responseMap.get(sku).title, responseMap.get(sku).price, ownedSkus)); String gmsTextString = ""; for (int i = 0; i < gdonation.size(); i++) { if (i == 1) gmsTextString += " "; else if (i > 1) gmsTextString += ", "; gmsTextString += gdonation.elementAt(i).first; } SpannableString gmsText = new SpannableString(gmsTextString); int lStart = 0; int lEnd = 0; for (Pair<String, String> item : gdonation) { lEnd = lStart + item.first.length(); if (item.second != null) { final String mSku = item.second; ClickableSpan cspan = new ClickableSpan() { @Override public void onClick(View widget) { triggerBuy(mSku); } }; gmsText.setSpan(cspan, lStart, lEnd, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); } lStart = lEnd + 2; // Account for ", " between items } if (gmsTextView != null) { gmsTextView.setText(gmsText); gmsTextView.setMovementMethod(LinkMovementMethod.getInstance()); gmsTextView.setVisibility(View.VISIBLE); } } catch (JSONException e) { VpnStatus.logException("Parsing Play Store IAP", e); } }
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));//from w ww. ja 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:com.popdeem.sdk.uikit.adapter.PDUIFeedRecyclerViewAdapter.java
@Deprecated private Spannable getRedemptionText(Context context, String firstName, String secondName, String reward, String brandName, boolean isCheckin) { String fullName = firstName + " " + secondName; String redemptionName;// w w w .j a v a 2 s. co m if (fullName.equalsIgnoreCase(mCurrentUserName)) { redemptionName = "You"; } else { redemptionName = fullName; } String redemptionAction; if (isCheckin) { redemptionAction = "checked in and redeemed"; } else { redemptionAction = "shared an image and redeemed"; } Spannable spannable = new SpannableString( redemptionName + " " + redemptionAction + " " + reward + " at " + brandName); spannable.setSpan( new ForegroundColorSpan(ContextCompat.getColor(context, R.color.pd_feed_item_name_text_color)), 0, redemptionName.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); spannable.setSpan( new ForegroundColorSpan(ContextCompat.getColor(context, R.color.pd_feed_item_title_text_color)), (redemptionName + " " + redemptionAction).length(), (redemptionName + " " + redemptionAction + " ").length() + reward.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); spannable.setSpan( new ForegroundColorSpan(ContextCompat.getColor(context, R.color.pd_feed_item_title_text_color)), (redemptionName + " " + redemptionAction + " " + reward + " at").length(), (redemptionName + " " + redemptionAction + " " + reward + " at ").length() + brandName.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); return spannable; }
From source file:com.ruesga.rview.tasks.AsyncTextDiffProcessor.java
private List<DiffView.AbstractModel> processSideBySideDiffs() { final List<DiffView.AbstractModel> model = new ArrayList<>(); addBinaryAdviseIfNeeded(model);/*from w w w.ja v a2 s. c om*/ if (mDiffs == null) { return model; } int lineNumberA = 0; int lineNumberB = 0; final Spannable.Factory spannableFactory = Spannable.Factory.getInstance(); final int noColor = ContextCompat.getColor(mContext, android.R.color.transparent); final int addedBgColor = ContextCompat.getColor(mContext, R.color.diffAddedBackgroundColor); final int addedFgColor = ContextCompat.getColor(mContext, R.color.diffAddedForegroundColor); final int deletedBgColor = ContextCompat.getColor(mContext, R.color.diffDeletedBackgroundColor); final int deletedFgColor = ContextCompat.getColor(mContext, R.color.diffDeletedForegroundColor); boolean noDiffs = mDiffs.length == 1 && mDiffs[0].a == null && mDiffs[0].b == null; int j = 0; for (DiffContentInfo diff : mDiffs) { if (diff.ab != null) { // Unchanged lines int[] p = processUnchangedLines(diff, model, j, lineNumberA, lineNumberB, noColor, noDiffs); lineNumberA = p[0]; lineNumberB = p[1]; } else { int posA = 0; int posB = 0; int count = Math.max(diff.a == null ? 0 : diff.a.length, diff.b == null ? 0 : diff.b.length); for (int i = 0; i < count; i++) { DiffInfoModel m = new DiffInfoModel(); m.colorA = noColor; m.colorB = noColor; if (diff.a != null && i < diff.a.length) { String line = diff.a[i]; m.a = ++lineNumberA; m.lineNumberA = String.valueOf(m.a); if (diff.editA != null) { Spannable span = spannableFactory.newSpannable(prepareTabs(line)); if (mHighlightIntralineDiffs) { int s2 = 0; for (ArrayList<Integer> intra : diff.editA) { int s1 = s2 + intra.get(0); s2 = s1 + intra.get(1); int l = posA + line.length(); if ((s1 >= posA && s1 <= l) || (s2 >= posA && s2 <= l) || (s1 <= posA && s2 >= l)) { span.setSpan(new BackgroundColorSpan(deletedFgColor), Math.max(posA, s1) - posA, Math.min(l, s2) - posA, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); } } } m.lineA = span; } else { // No intraline data, but it still could differ at start or at end processNoIntralineDataA(diff, m, line, deletedFgColor); } m.colorA = deletedBgColor; posA += line.length() + 1; } if (diff.b != null && i < diff.b.length) { String line = diff.b[i]; m.b = ++lineNumberB; m.lineNumberB = String.valueOf(m.b); if (diff.editB != null) { Spannable span = spannableFactory.newSpannable(prepareTabs(line)); if (mHighlightIntralineDiffs) { int s2 = 0; for (ArrayList<Integer> intra : diff.editB) { int s1 = s2 + intra.get(0); s2 = s1 + intra.get(1); int l = posB + line.length(); if ((s1 >= posB && s1 <= l) || (s2 >= posB && s2 <= l) || (s1 <= posB && s2 >= l)) { span.setSpan(new BackgroundColorSpan(addedFgColor), Math.max(posB, s1) - posB, Math.min(l, s2) - posB, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); } } } m.lineB = span; } else { // No intraline data, but it still could differ at start or at end processNoIntralineDataB(diff, m, line, addedFgColor); } m.colorB = addedBgColor; posB += line.length() + 1; } processHighlights(m); model.add(m); } } j++; } return model; }
From source file:org.jraf.android.dcn.handheld.app.geofencing.GeofencingService.java
private void showEnteredNotification(AddressInfo addressInfo) { Log.d("addressInfo=" + addressInfo); String titleShort = getNotificationTitle(addressInfo, false); String titleLong = getNotificationTitle(addressInfo, true); String textShort = getNotificationText(addressInfo, false); String textLong = getNotificationText(addressInfo, true); NotificationCompat.Builder mainNotifBuilder = new NotificationCompat.Builder(this); // Small icon mainNotifBuilder.setSmallIcon(R.drawable.ic_stat_entered); // Make a bigger title SpannableString titleSpannable = new SpannableString(titleShort); Object span = new TextAppearanceSpan(this, R.style.NotificationContentTitleTextAppearance); titleSpannable.setSpan(span, 0, titleShort.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); // Title//from w ww.j a v a 2 s. c o m mainNotifBuilder.setContentTitle(titleSpannable); // Ticker mainNotifBuilder.setTicker(titleShort); // Text (short) mainNotifBuilder.setContentText(textShort); // Text (long) mainNotifBuilder.setStyle(new NotificationCompat.BigTextStyle().bigText(textLong)); // 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 mainNotifBuilder.setLights(0, 0, 0); // No light mainNotifBuilder.setShowWhen(false); // No date mainNotifBuilder.addPerson(addressInfo.contactInfo.contentLookupUri.toString()); // Contact photo Bitmap contactPhoto = addressInfo.getContactPhoto(this); if (contactPhoto != null) mainNotifBuilder.setLargeIcon(contactPhoto); // Dismiss intent Intent dismissIntent = new Intent(ACTION_DISMISS_NOTIFICATION, null, this, getClass()); PendingIntent dismissPendingIntent = PendingIntent.getService(this, 0, dismissIntent, PendingIntent.FLAG_UPDATE_CURRENT); mainNotifBuilder.setDeleteIntent(dismissPendingIntent); // Main action (click on the notification itself) Intent mainIntent = new Intent(Intent.ACTION_VIEW); mainIntent.setData(addressInfo.contactInfo.contentLookupUri); PendingIntent mainPendingIntent = PendingIntent.getActivity(this, 0, mainIntent, PendingIntent.FLAG_UPDATE_CURRENT); mainNotifBuilder.setContentIntent(mainPendingIntent); String phoneNumber = addressInfo.getContactPhoneNumber(this); if (phoneNumber != null) { // Call action Intent callIntent = new Intent(Intent.ACTION_DIAL); callIntent.setData(Uri.parse("tel:" + phoneNumber)); PendingIntent callPendingIntent = PendingIntent.getActivity(this, 0, callIntent, PendingIntent.FLAG_UPDATE_CURRENT); String callText = getString(R.string.notification_action_call); mainNotifBuilder.addAction(R.drawable.ic_action_call, callText, callPendingIntent); // Sms action Intent smsIntent = new Intent(Intent.ACTION_VIEW); smsIntent.setData(Uri.parse("sms:" + phoneNumber)); smsIntent.putExtra("sms_body", getString(R.string.notification_action_sms_body)); PendingIntent smsPendingIntent = PendingIntent.getActivity(this, 0, smsIntent, PendingIntent.FLAG_UPDATE_CURRENT); String smsText = getString(R.string.notification_action_sms); mainNotifBuilder.addAction(R.drawable.ic_action_sms, smsText, smsPendingIntent); } // Since we have a specific Wear notification, show this one only on handheld mainNotifBuilder.setLocalOnly(true); // Show it Notification notification = mainNotifBuilder.build(); NotificationManager notificationManager = (NotificationManager) getSystemService( Context.NOTIFICATION_SERVICE); notificationManager.notify(NOTIFICATION_ID, notification); // Show a Wear notification // Blocking mWearHelper.connect(this); mWearHelper.putNotification(titleLong, textShort, textLong, contactPhoto, addressInfo.contactInfo.contentLookupUri, phoneNumber); }
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); }/*w w w. j av a 2s .co m*/ 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(); } }