List of usage examples for android.text SpannableString setSpan
public void setSpan(Object what, int start, int end, int flags)
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();/* w ww.j av a 2 s. com*/ 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: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//from w w w.j a va2s .com 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.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);/*ww w. j a va 2s. c om*/ }
From source file:de.busse_apps.hmintpmd.gui.ResultFragment.java
private void setValueText(double value, int level) { String valueString;/*from w ww . j a v a 2 s . c o m*/ if (level < WSIKMCalculator.MAX_LEVEL) { valueString = String.format(Locale.getDefault(), "%.1f", value); } else { valueString = "\u221E"; } SpannableString msg = new SpannableString(valueString + " kDoil"); msg.setSpan(new ForegroundColorSpan(WSIKMCalculator.getColorForLevel(getActivity(), level)), 0, valueString.length(), 0); mResultValue.setText(msg); }
From source file:com.inter.trade.ui.fragment.smsreceivepayment.SmsSuccessFragment.java
private void initView(View view) { if (requsetData != null) { TextView tv_content = (TextView) view.findViewById(R.id.tv_content); String s1 = "????"; String s2 = requsetData.getValue("fumobile"); String s3 = "??"; String s4 = "" + requsetData.getValue("money"); String s5 = ",??1"; String content = s1 + s2 + s3 + s4 + s5; int len = 0; /**/*from w w w . j a v a 2 s . c o m*/ * ?TEXTVIEW?? */ SpannableString ss = new SpannableString(content); ss.setSpan(new ForegroundColorSpan(getResources().getColor(R.color.agent_apply_yellow)), len = s1.length() + s2.length() + s3.length(), len + s4.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); tv_content.setText(ss); tv_content.setMovementMethod(LinkMovementMethod.getInstance()); // String content = "????" // +requsetData.getValue("fumobile") // +"??" // +requsetData.getValue("money") // +",??1"; // tv_content.setText(content); TextView tv_shou_bank = (TextView) view.findViewById(R.id.tv_shou_bank); String shou_bank = "" + requsetData.getValue("shoucardbank"); tv_shou_bank.setText(shou_bank); TextView tv_shou_card = (TextView) view.findViewById(R.id.tv_shou_card); String shou_card = "?" + requsetData.getValue("shoucardno"); tv_shou_card.setText(shou_card); } Button see_history = (Button) view.findViewById(R.id.see_history); see_history.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { // TODO Auto-generated method stub getActivity().setResult(Constants.ACTIVITY_FINISH); getActivity().finish(); } }); Button btnAgain = (Button) view.findViewById(R.id.btn_again); btnAgain.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { /** * ?? */ SmsReceivePaymentMainFragment.isComeBackFromPaySuccess = true; Intent intent = new Intent(getActivity(), IndexActivity.class); intent.putExtra(FragmentFactory.INDEX_KEY, FuncMap.SMSRECEIPT_INDEX_FUNC); intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); startActivity(intent); } }); }
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();/*from w ww . j ava2 s .co m*/ 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:eu.power_switch.widget.provider.ReceiverWidgetProvider.java
@Override public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) { Log.d("Updating Receiver Widgets..."); // Perform this loop procedure for each App Widget that belongs to this provider for (int i = 0; i < appWidgetIds.length; i++) { int appWidgetId = appWidgetIds[i]; RemoteViews remoteViews = new RemoteViews( context.getResources().getString(eu.power_switch.shared.R.string.PACKAGE_NAME), R.layout.widget_receiver); try {/*ww w . j a v a 2s . c o m*/ ReceiverWidget receiverWidget = DatabaseHandler.getReceiverWidget(appWidgetId); Room room = DatabaseHandler.getRoom(receiverWidget.getRoomId()); if (room != null) { Receiver receiver = DatabaseHandler.getReceiver(receiverWidget.getReceiverId()); if (receiver != null) { Apartment apartment = DatabaseHandler.getApartment(room.getApartmentId()); // update UI remoteViews.setTextViewText(R.id.textView_receiver_widget_name, apartment.getName() + ": " + room.getName() + ": " + receiver.getName()); LinkedList<Button> buttons = receiver.getButtons(); // remove all previous buttons remoteViews.removeAllViews(R.id.linearlayout_receiver_widget); // add buttons from database int buttonOffset = 0; for (Button button : buttons) { // set button action RemoteViews buttonView = new RemoteViews( context.getResources().getString(eu.power_switch.shared.R.string.PACKAGE_NAME), R.layout.widget_receiver_button_layout); SpannableString s = new SpannableString(button.getName()); s.setSpan(new StyleSpan(Typeface.BOLD), 0, button.getName().length(), 0); buttonView.setTextViewText(R.id.button_widget_universal, s); if (SmartphonePreferencesHandler.getHighlightLastActivatedButton() && receiver.getLastActivatedButtonId().equals(button.getId())) { buttonView.setTextColor(R.id.button_widget_universal, ContextCompat.getColor(context, R.color.color_light_blue_a700)); } PendingIntent intent = WidgetIntentReceiver.buildReceiverWidgetActionPendingIntent( context, apartment, room, receiver, button, appWidgetId * 15 + buttonOffset); buttonView.setOnClickPendingIntent(R.id.button_widget_universal, intent); remoteViews.addView(R.id.linearlayout_receiver_widget, buttonView); buttonOffset++; } remoteViews.setViewVisibility(R.id.linearlayout_receiver_widget, View.VISIBLE); } else { remoteViews.setTextViewText(R.id.textView_receiver_widget_name, context.getString(R.string.receiver_not_found)); remoteViews.removeAllViews(R.id.linearlayout_receiver_widget); remoteViews.setViewVisibility(R.id.linearlayout_receiver_widget, View.GONE); } } else { remoteViews.setTextViewText(R.id.textView_receiver_widget_name, context.getString(R.string.room_not_found)); remoteViews.removeAllViews(R.id.linearlayout_receiver_widget); remoteViews.setViewVisibility(R.id.linearlayout_receiver_widget, View.GONE); } } catch (Exception e) { Log.e(e); remoteViews.setTextViewText(R.id.textView_receiver_widget_name, context.getString(R.string.unknown_error)); remoteViews.removeAllViews(R.id.linearlayout_receiver_widget); remoteViews.setViewVisibility(R.id.linearlayout_receiver_widget, View.GONE); } appWidgetManager.updateAppWidget(appWidgetId, remoteViews); } super.onUpdate(context, appWidgetManager, appWidgetIds); }
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 ww.j ava2s .co m*/ }
From source file:com.doomonafireball.hackerswiperfree.android.activity.MainActivity.java
private SpannableString makeLinkSpan(CharSequence text, View.OnClickListener listener) { SpannableString link = new SpannableString(text); link.setSpan(new ClickableString(listener), 0, text.length(), SpannableString.SPAN_INCLUSIVE_EXCLUSIVE); return link;//from w w w. j a v a2 s . c o m }
From source file:eu.faircode.netguard.AdapterAccess.java
@Override public void bindView(final View view, final Context context, final Cursor cursor) { // Get values final int version = cursor.getInt(colVersion); final int protocol = cursor.getInt(colProtocol); final String daddr = cursor.getString(colDaddr); final int dport = cursor.getInt(colDPort); long time = cursor.getLong(colTime); int allowed = cursor.getInt(colAllowed); int block = cursor.getInt(colBlock); int count = cursor.getInt(colCount); long sent = cursor.isNull(colSent) ? -1 : cursor.getLong(colSent); long received = cursor.isNull(colReceived) ? -1 : cursor.getLong(colReceived); int connections = cursor.isNull(colConnections) ? -1 : cursor.getInt(colConnections); // Get views/*ww w .j a va 2 s . c o m*/ TextView tvTime = view.findViewById(R.id.tvTime); ImageView ivBlock = view.findViewById(R.id.ivBlock); final TextView tvDest = view.findViewById(R.id.tvDest); LinearLayout llTraffic = view.findViewById(R.id.llTraffic); TextView tvConnections = view.findViewById(R.id.tvConnections); TextView tvTraffic = view.findViewById(R.id.tvTraffic); // Set values tvTime.setText(new SimpleDateFormat("dd HH:mm").format(time)); if (block < 0) ivBlock.setImageDrawable(null); else { ivBlock.setImageResource(block > 0 ? R.drawable.host_blocked : R.drawable.host_allowed); if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) { Drawable wrap = DrawableCompat.wrap(ivBlock.getDrawable()); DrawableCompat.setTint(wrap, block > 0 ? colorOff : colorOn); } } String dest = Util.getProtocolName(protocol, version, true) + " " + daddr + (dport > 0 ? "/" + dport : "") + (count > 1 ? " ?" + count : ""); SpannableString span = new SpannableString(dest); span.setSpan(new UnderlineSpan(), 0, dest.length(), 0); tvDest.setText(span); if (Util.isNumericAddress(daddr)) new AsyncTask<String, Object, String>() { @Override protected void onPreExecute() { ViewCompat.setHasTransientState(tvDest, true); } @Override protected String doInBackground(String... args) { try { return InetAddress.getByName(args[0]).getHostName(); } catch (UnknownHostException ignored) { return args[0]; } } @Override protected void onPostExecute(String addr) { tvDest.setText(Util.getProtocolName(protocol, version, true) + " >" + addr + (dport > 0 ? "/" + dport : "")); ViewCompat.setHasTransientState(tvDest, false); } }.execute(daddr); if (allowed < 0) tvDest.setTextColor(colorText); else if (allowed > 0) tvDest.setTextColor(colorOn); else tvDest.setTextColor(colorOff); llTraffic.setVisibility(connections > 0 || sent > 0 || received > 0 ? View.VISIBLE : View.GONE); if (connections > 0) tvConnections.setText(context.getString(R.string.msg_count, connections)); if (sent > 1024 * 1204 * 1024L || received > 1024 * 1024 * 1024L) tvTraffic.setText(context.getString(R.string.msg_gb, (sent > 0 ? sent / (1024 * 1024 * 1024f) : 0), (received > 0 ? received / (1024 * 1024 * 1024f) : 0))); else if (sent > 1204 * 1024L || received > 1024 * 1024L) tvTraffic.setText(context.getString(R.string.msg_mb, (sent > 0 ? sent / (1024 * 1024f) : 0), (received > 0 ? received / (1024 * 1024f) : 0))); else tvTraffic.setText(context.getString(R.string.msg_kb, (sent > 0 ? sent / 1024f : 0), (received > 0 ? received / 1024f : 0))); }