List of usage examples for android.text Spannable setSpan
public void setSpan(Object what, int start, int end, int flags);
start…end
of the text, or move the object to that range if it was already attached elsewhere. From source file:com.hitesh_sahu.retailapp.view.fragment.ProductDetailsFragment.java
public void fillProductData() { if (!isFromCart) { //Fetch and display item from Gloabl Data Model itemName.setText(CenterRepository.getCenterRepository().getMapOfProductsInCategory().get(subcategoryKey) .get(productListNumber).getItemName()); quanitity.setText(CenterRepository.getCenterRepository().getMapOfProductsInCategory() .get(subcategoryKey).get(productListNumber).getQuantity()); itemdescription.setText(CenterRepository.getCenterRepository().getMapOfProductsInCategory() .get(subcategoryKey).get(productListNumber).getItemDetail()); String sellCostString = Money .rupees(BigDecimal.valueOf(Long.valueOf(CenterRepository.getCenterRepository() .getMapOfProductsInCategory().get(subcategoryKey).get(productListNumber).getSellMRP()))) .toString() + " "; String buyMRP = Money/*from w w w . j ava 2s . co m*/ .rupees(BigDecimal.valueOf(Long.valueOf(CenterRepository.getCenterRepository() .getMapOfProductsInCategory().get(subcategoryKey).get(productListNumber).getMRP()))) .toString(); String costString = sellCostString + buyMRP; itemSellPrice.setText(costString, BufferType.SPANNABLE); Spannable spannable = (Spannable) itemSellPrice.getText(); spannable.setSpan(new StrikethroughSpan(), sellCostString.length(), costString.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); mDrawableBuilder = TextDrawable.builder().beginConfig().withBorder(4).endConfig().roundRect(10); drawable = mDrawableBuilder.build( String.valueOf(CenterRepository.getCenterRepository().getMapOfProductsInCategory() .get(subcategoryKey).get(productListNumber).getItemName().charAt(0)), mColorGenerator.getColor(CenterRepository.getCenterRepository().getMapOfProductsInCategory() .get(subcategoryKey).get(productListNumber).getItemName())); Picasso.with(getActivity()) .load(CenterRepository.getCenterRepository().getMapOfProductsInCategory().get(subcategoryKey) .get(productListNumber).getImageURL()) .placeholder(drawable).error(drawable).fit().centerCrop().networkPolicy(NetworkPolicy.OFFLINE) .into(itemImage, new Callback() { @Override public void onSuccess() { } @Override public void onError() { // Try again online if cache failed Picasso.with(getActivity()) .load(CenterRepository.getCenterRepository().getMapOfProductsInCategory() .get(subcategoryKey).get(productListNumber).getImageURL()) .placeholder(drawable).error(drawable).fit().centerCrop().into(itemImage); } }); LabelView label = new LabelView(getActivity()); label.setText(CenterRepository.getCenterRepository().getMapOfProductsInCategory().get(subcategoryKey) .get(productListNumber).getDiscount()); label.setBackgroundColor(0xffE91E63); label.setTargetView(itemImage, 10, LabelView.Gravity.RIGHT_TOP); } else { //Fetch and display products from Shopping list itemName.setText(CenterRepository.getCenterRepository().getListOfProductsInShoppingList() .get(productListNumber).getItemName()); quanitity.setText(CenterRepository.getCenterRepository().getListOfProductsInShoppingList() .get(productListNumber).getQuantity()); itemdescription.setText(CenterRepository.getCenterRepository().getListOfProductsInShoppingList() .get(productListNumber).getItemDetail()); String sellCostString = Money .rupees(BigDecimal.valueOf(Long.valueOf(CenterRepository.getCenterRepository() .getListOfProductsInShoppingList().get(productListNumber).getSellMRP()))) .toString() + " "; String buyMRP = Money.rupees(BigDecimal.valueOf(Long.valueOf(CenterRepository.getCenterRepository() .getListOfProductsInShoppingList().get(productListNumber).getMRP()))).toString(); String costString = sellCostString + buyMRP; itemSellPrice.setText(costString, BufferType.SPANNABLE); Spannable spannable = (Spannable) itemSellPrice.getText(); spannable.setSpan(new StrikethroughSpan(), sellCostString.length(), costString.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); mDrawableBuilder = TextDrawable.builder().beginConfig().withBorder(4).endConfig().roundRect(10); drawable = mDrawableBuilder.build( String.valueOf(CenterRepository.getCenterRepository().getListOfProductsInShoppingList() .get(productListNumber).getItemName().charAt(0)), mColorGenerator.getColor(CenterRepository.getCenterRepository() .getListOfProductsInShoppingList().get(productListNumber).getItemName())); Picasso.with(getActivity()) .load(CenterRepository.getCenterRepository().getListOfProductsInShoppingList() .get(productListNumber).getImageURL()) .placeholder(drawable).error(drawable).fit().centerCrop().networkPolicy(NetworkPolicy.OFFLINE) .into(itemImage, new Callback() { @Override public void onSuccess() { } @Override public void onError() { // Try again online if cache failed Picasso.with(getActivity()) .load(CenterRepository.getCenterRepository().getListOfProductsInShoppingList() .get(productListNumber).getImageURL()) .placeholder(drawable).error(drawable).fit().centerCrop().into(itemImage); } }); LabelView label = new LabelView(getActivity()); label.setText(CenterRepository.getCenterRepository().getListOfProductsInShoppingList() .get(productListNumber).getDiscount()); label.setBackgroundColor(0xffE91E63); label.setTargetView(itemImage, 10, LabelView.Gravity.RIGHT_TOP); } }
From source file:com.lloydtorres.stately.helpers.SparkleHelper.java
/** * Overloaded to deal with spoilers.//from w w w . ja v a2s. co m */ public static void setStyledTextView(Context c, TextView t, String holder, List<Spoiler> spoilers, FragmentManager fm) { if (t instanceof HtmlTextView) { try { ((HtmlTextView) t).setHtml(holder); } catch (Exception e) { logError(e.toString()); t.setText(c.getString(R.string.bbcode_parse_error)); t.setTypeface(t.getTypeface(), Typeface.ITALIC); } } else { t.setText(fromHtml(holder)); } // Deal with spoilers here styleLinkifiedTextView(c, t); // Ensures TextView contains a spannable Spannable span = new SpannableString(t.getText()); String rawSpan = span.toString(); int startFromIndex = 0; for (int i = 0; i < spoilers.size(); i++) { Spoiler s = spoilers.get(i); int start = rawSpan.indexOf(s.replacer, startFromIndex); if (start != -1) { int end = start + s.replacer.length(); startFromIndex = end; SpoilerSpan clickyDialog = new SpoilerSpan(c, s, fm); span.setSpan(clickyDialog, start, end, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); } } t.setText(span); }
From source file:com.tilusnet.wayta.MainActivity2.java
protected void highlightText(String json) throws JSONException { JSONArray jsonArray = new JSONArray(json); Spannable sps = editText.getText(); for (int i = 0; i < jsonArray.length(); i++) { JSONObject jsonObj = jsonArray.getJSONObject(i); JSONObject jsonGeoName = jsonObj.getJSONObject("geoname"); String matchedName = jsonObj.getString("matchedName"); JSONObject jsonLocation = jsonObj.getJSONObject("location"); int pos = jsonLocation.getInt("position"); double confid = jsonObj.getDouble("confidence"); final long id = jsonGeoName.getLong("geonameID"); sps.setSpan(new WordSpan(0, (int) (200 * confid) + 10) { // sps.setSpan(new ClickableSpan() { @Override/*from w w w. j a v a 2 s .c o m*/ public void onClick(View widget) { map.animateCamera(CameraUpdateFactory.newLatLngZoom(markers.get(id).getPosition(), 9)); } }, pos, pos + matchedName.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); // }, i * 10 + 0, i * 10 + 5, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); } // editText.setEnabled(false); }
From source file:com.jecelyin.editor.v2.core.text.TextUtils.java
private static void readSpan(Parcel p, Spannable sp, Object o) { sp.setSpan(o, p.readInt(), p.readInt(), p.readInt()); }
From source file:com.android.mail.browse.MessageHeaderView.java
private static void stripUnderlines(TextView textView, Account account) { final Spannable spannable = (Spannable) textView.getText(); final URLSpan[] urls = textView.getUrls(); for (URLSpan span : urls) { final int start = spannable.getSpanStart(span); final int end = spannable.getSpanEnd(span); spannable.removeSpan(span);//from w w w . ja va 2 s . c om span = new EmailAddressSpan(account, span.getURL().substring(7)); spannable.setSpan(span, start, end, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); } }
From source file:com.cw.litenote.note.Note_adapter.java
private String getHtmlStringWithViewPort(int position, int viewPort) { int mStyle = Note.mStyle; System.out.println("Note_adapter / _getHtmlStringWithViewPort"); String strTitle = db_page.getNoteTitle(position, true); String strBody = db_page.getNoteBody(position, true); String linkUri = db_page.getNoteLinkUri(position, true); // replace note title //TitleBody,YouTube linkWeb linkTitlelinktitle,Gray? boolean bSetGray = false; if (Util.isEmptyString(strTitle) && Util.isEmptyString(strBody)) { if (Util.isYouTubeLink(linkUri)) { strTitle = Util.getYouTubeTitle(linkUri); bSetGray = true;/*from w w w . ja v a 2 s .c o m*/ } else if (linkUri.startsWith("http")) { strTitle = mWebTitle; bSetGray = true; } } Long createTime = db_page.getNoteCreatedTime(position, true); String head = "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>" + "<html><head>" + "<meta http-equiv=\"content-type\" content=\"text/html; charset=utf-8\" />"; if (viewPort == VIEW_PORT_BY_NONE) { head = head + "<head>"; } else if (viewPort == VIEW_PORT_BY_DEVICE_WIDTH) { head = head + "<meta name=\"viewport\" content=\"width=device-width, initial-scale=1\">" + "<head>"; } else if (viewPort == VIEW_PORT_BY_SCREEN_WIDTH) { // int screen_width = UtilImage.getScreenWidth(act); int screen_width = 640; head = head + "<meta name=\"viewport\" content=\"width=" + String.valueOf(screen_width) + ", initial-scale=1\">" + "<head>"; } String separatedLineTitle = (!Util.isEmptyString(strTitle)) ? "<hr size=2 color=blue width=99% >" : ""; String separatedLineBody = (!Util.isEmptyString(strBody)) ? "<hr size=1 color=black width=99% >" : ""; // title if (!Util.isEmptyString(strTitle)) { Spannable spanTitle = new SpannableString(strTitle); Linkify.addLinks(spanTitle, Linkify.ALL); spanTitle.setSpan(new AlignmentSpan.Standard(Alignment.ALIGN_CENTER), 0, spanTitle.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); //ref http://stackoverflow.com/questions/3282940/set-color-of-textview-span-in-android if (bSetGray) { ForegroundColorSpan foregroundSpan = new ForegroundColorSpan(Color.GRAY); spanTitle.setSpan(foregroundSpan, 0, spanTitle.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); } strTitle = Html.toHtml(spanTitle); } else strTitle = ""; // body if (!Util.isEmptyString(strBody)) { Spannable spanBody = new SpannableString(strBody); Linkify.addLinks(spanBody, Linkify.ALL); strBody = Html.toHtml(spanBody); } else strBody = ""; // set web view text color String colorStr = Integer.toHexString(ColorSet.mText_ColorArray[mStyle]); colorStr = colorStr.substring(2); String bgColorStr = Integer.toHexString(ColorSet.mBG_ColorArray[mStyle]); bgColorStr = bgColorStr.substring(2); return head + "<body color=\"" + bgColorStr + "\">" + "<br>" + //Note: text mode needs this, otherwise title is overlaid "<p align=\"center\"><b>" + "<font color=\"" + colorStr + "\">" + strTitle + "</font>" + "</b></p>" + separatedLineTitle + "<p>" + "<font color=\"" + colorStr + "\">" + strBody + "</font>" + "</p>" + separatedLineBody + "<p align=\"right\">" + "<font color=\"" + colorStr + "\">" + Util.getTimeString(createTime) + "</font>" + "</p>" + "</body></html>"; }
From source file:com.juick.android.TagsFragment.java
private void onTagClick(String tagg, int uid) { if (!multi) { parentActivity.onTagClick(tagg, uid); } else {/*from w w w .ja v a2 s .c om*/ TextView tv = (TextView) myView.findViewById(R.id.tags); Spannable text = (Spannable) tv.getText(); TagOffsets tagOffsets1 = tagOffsets.get(tagg); if (!selectedTags.remove(tagg)) { if (selectedTags.size() == 5) { Toast.makeText(getActivity(), getString(R.string.TooManyTags), Toast.LENGTH_LONG).show(); return; } else { selectedTags.add(tagg); tagOffsets1.existingSpan = new StyleSpan(Typeface.BOLD); text.setSpan(tagOffsets1.existingSpan, tagOffsets1.offset, tagOffsets1.end, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); } } else { text.removeSpan(tagOffsets1.existingSpan); tagOffsets1.existingSpan = null; } final TextView selected = (TextView) myView.findViewById(R.id.selected); StringBuilder sb = new StringBuilder(); for (String selectedTag : selectedTags) { sb.append("*"); sb.append(selectedTag); sb.append(" "); } selected.setText(sb.toString().trim()); } }
From source file:com.weebly.opus1269.copyeverywhere.ui.clipviewer.ClipViewerFragment.java
/** * Highlight all occurrences of the given String * * @param highlightText the text to highlight (case insensitive) *//*from ww w. j av a 2s . c o m*/ public void setHighlightText(String highlightText) { if (Collator.getInstance().equals(mHighlightText, highlightText)) { return; } mHighlightText = highlightText; final TextView textView = (TextView) getActivity().findViewById(R.id.clipViewerText); if (textView == null) { return; } if (TextUtils.isEmpty(highlightText)) { // make sure to reset spans textView.setText(mClipItem.getText()); } else { final String text = mClipItem.getText(); final Spannable spanText = Spannable.Factory.getInstance().newSpannable(text); final int color = ContextCompat.getColor(getContext(), R.color.accent_highlight); final Pattern p = Pattern.compile(highlightText, Pattern.CASE_INSENSITIVE); final Matcher m = p.matcher(text); final int length = highlightText.length(); while (m.find()) { final int start = m.start(); final int stop = start + length; //noinspection ObjectAllocationInLoop spanText.setSpan(new BackgroundColorSpan(color), start, stop, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); } textView.setText(spanText); } }
From source file:org.catrobat.catroid.ui.fragment.SpritesListFragment.java
private void updateActionModeTitle() { int numberOfSelectedItems = spriteAdapter.getAmountOfCheckedSprites(); if (numberOfSelectedItems == 0) { actionMode.setTitle(multiSelectActionModeTitle); } else {/*w w w . j a va 2 s . c o m*/ String appendix = multipleItemAppendixMultiSelectActionMode; if (numberOfSelectedItems == 1) { appendix = singleItemAppendixMultiSelectActionMode; } String numberOfItems = Integer.toString(numberOfSelectedItems); String completeTitle = multiSelectActionModeTitle + " " + numberOfItems + " " + appendix; int titleLength = multiSelectActionModeTitle.length(); Spannable completeSpannedTitle = new SpannableString(completeTitle); completeSpannedTitle.setSpan( new ForegroundColorSpan(getResources().getColor(R.color.actionbar_title_color)), titleLength + 1, titleLength + (1 + numberOfItems.length()), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); actionMode.setTitle(completeSpannedTitle); } }
From source file:com.cesarsk.say_it.ui.fragments.SettingsFragment.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); addPreferencesFromResource(R.xml.preferences); // Use an activity context to get the rewarded video instance. mRewardedVideoAd = MobileAds.getRewardedVideoAdInstance(getActivity()); mRewardedVideoAd.setRewardedVideoAdListener(this); loadRewardedVideoAd();/* w w w .j av a 2 s.c om*/ PackageInfo pInfo = null; try { pInfo = getActivity().getPackageManager().getPackageInfo(getActivity().getPackageName(), 0); } catch (PackageManager.NameNotFoundException e) { e.printStackTrace(); } String version = pInfo.versionName; final Preference app_version = getPreferenceManager().findPreference("app_version"); app_version.setSummary("Version: " + version + " (Click for Privacy Policy)"); final Context context = getActivity(); if (context instanceof Callback) { mCallback = (Callback) context; } else { throw new IllegalStateException("Owner must implement URLCallback interface"); } // add listeners for non-default actions Preference preference = findPreference(KEY_1); preference.setOnPreferenceClickListener(this); Preference open_source_licenses = findPreference(KEY_2); open_source_licenses.setOnPreferenceClickListener(this); Preference rate_us = getPreferenceManager().findPreference("rate_us"); rate_us.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() { @Override public boolean onPreferenceClick(Preference preference) { rateUs(getActivity()); return false; } }); Preference contact_us = getPreferenceManager().findPreference("contact_us"); contact_us.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() { @Override public boolean onPreferenceClick(Preference preference) { shareToMail(emails, "[CONTACT US - SAY IT!]", getActivity()); return false; } }); Preference bug_report = getPreferenceManager().findPreference("bug_report"); bug_report.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() { @Override public boolean onPreferenceClick(Preference preference) { shareToMail(emails, "[CONTACT US - SAY IT!]", getActivity()); return false; } }); Preference donate_ad = getPreferenceManager().findPreference("donation_ad"); donate_ad.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() { @Override public boolean onPreferenceClick(Preference preference) { //Launch AD if (mRewardedVideoAd.isLoaded()) { mRewardedVideoAd.show(); } return false; } }); final Preference about_us = getPreferenceManager().findPreference("about_us"); about_us.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() { @Override public boolean onPreferenceClick(Preference preference) { Utility.openURL(getActivity(), "https://lucacesaranoblog.wordpress.com/2017/07/18/about-us/"); return false; } }); final Preference eula = getPreferenceManager().findPreference("eula"); eula.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() { @Override public boolean onPreferenceClick(Preference preference) { Utility.openURL(getActivity(), "https://lucacesaranoblog.wordpress.com/2017/04/28/say-it-eula-agreement/"); return false; } }); /*final Preference github = getPreferenceManager().findPreference("github"); github.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() { @Override public boolean onPreferenceClick(Preference preference) { Utility.openURL(getActivity(), "https://github.com/Cesarsk/Say_it"); return false; } });*/ final Preference other_apps = getPreferenceManager().findPreference("other_apps"); other_apps.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() { @Override public boolean onPreferenceClick(Preference preference) { Utility.openURL(getActivity(), "https://play.google.com/store/apps/developer?id=Cesarsk+Dev+Team"); return false; } }); final Preference voice_settings = getPreferenceManager().findPreference("tts_settings"); voice_settings.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() { @Override public boolean onPreferenceClick(Preference preference) { Intent intent = new Intent(); intent.setAction("com.android.settings.TTS_SETTINGS"); intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); context.startActivity(intent); return false; } }); // compute your public key and store it in base64EncodedPublicKey mHelper = new IabHelper(getActivity(), LCSecurity.base64EncodedPublicKey); mHelper.startSetup(new IabHelper.OnIabSetupFinishedListener() { public void onIabSetupFinished(IabResult result) { if (!result.isSuccess()) { // Oh no, there was a problem. if (MainActivity.isLoggingEnabled) Log.d("Say It!", "Problem setting up In-app Billing: " + result); } // Hooray, IAB is fully set up! if (MainActivity.isLoggingEnabled) Log.d("Say It!", "Hooray. IAB is fully set up!" + result); } }); mIabPurchaseFinishedListener = new IabHelper.OnIabPurchaseFinishedListener() { @Override public void onIabPurchaseFinished(IabResult result, Purchase info) { if (result.isFailure()) { Toast.makeText(getActivity(), "Purchase Failed! Perhaps have you already purchased the item?", Toast.LENGTH_SHORT).show(); } else if (info.getSku().equals(PlayActivity.no_ads_in_app)) { UtilitySharedPrefs.loadAdsStatus(getActivity()); UtilitySharedPrefs.savePrefs(getActivity(), true, MainActivity.NO_ADS_STATUS_KEY); } } }; mQueryFinishedListener = new IabHelper.QueryInventoryFinishedListener() { public void onQueryInventoryFinished(IabResult result, Inventory inventory) { if (result.isFailure()) { if (MainActivity.isLoggingEnabled) Toast.makeText(getActivity(), "Query Failed!", Toast.LENGTH_SHORT).show(); return; } //Open Purchase Dialog try { mHelper.flagEndAsync(); mHelper.launchPurchaseFlow(getActivity(), PlayActivity.no_ads_in_app, 64000, mIabPurchaseFinishedListener); } catch (IabHelper.IabAsyncInProgressException e) { e.printStackTrace(); } } }; final Preference remove_ads = getPreferenceManager().findPreference("remove_ads"); if (MainActivity.NO_ADS) { remove_ads.setEnabled(false); remove_ads.setSummary("Thank you for supporting us ?"); } else { remove_ads.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() { @Override public boolean onPreferenceClick(Preference preference) { //helper to remove ads List<String> additionalSkuList = new ArrayList<>(); additionalSkuList.add(PlayActivity.no_ads_in_app); try { mHelper.flagEndAsync(); mHelper.queryInventoryAsync(true, additionalSkuList, mQueryFinishedListener); } catch (IabHelper.IabAsyncInProgressException e) { e.printStackTrace(); } return false; } }); } final Preference reset_tutorial = getPreferenceManager().findPreference("reset_showcase"); reset_tutorial.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() { @Override public boolean onPreferenceClick(Preference preference) { Random rand = new Random(); int randomNum = rand.nextInt((10000 - 10) + 1) + 10; //(max - min) + 1 + min MainActivity.id_showcase_playactivity = "" + randomNum; Toast.makeText(getActivity(), "Tutorial has been reset", Toast.LENGTH_SHORT).show(); //MainActivity.id_showcase_fragments = "" + randomNum2; //int randomNum2 = rand.nextInt((10000 - 10) + 1) + 10; //(max - min) + 1 + min //These two statements are commented because MaterialShowCase often crashes on fragments and while pressing the back button. return false; } }); //setting an own Alert Dialog's title color final Spannable title = new SpannableString("Delete Recordings"); title.setSpan(new ForegroundColorSpan(Color.DKGRAY), 0, title.length(), 0); final Spannable message = new SpannableString("Are you sure you want to delete all recordings?"); message.setSpan(new ForegroundColorSpan(Color.GRAY), 0, message.length(), 0); final Preference delete_recordings = getPreferenceManager().findPreference("delete_recordings"); delete_recordings.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() { @Override public boolean onPreferenceClick(Preference preference) { new AlertDialog.Builder(getActivity()).setTitle(title).setMessage(message) .setPositiveButton(android.R.string.yes, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { Utility.delete_recordings(getActivity()); Toast.makeText(getActivity(), "Recordings deleted!", Toast.LENGTH_SHORT).show(); } }).setNegativeButton(android.R.string.no, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { //do nothing } }).show(); return true; } }); final ListPreference button_vibration = (ListPreference) getPreferenceManager() .findPreference("button_vibration"); button_vibration.setSummary(button_vibration.getEntry()); final Spannable default_vibration_settings_title = new SpannableString("Vibration Settings"); default_vibration_settings_title.setSpan(new ForegroundColorSpan(Color.DKGRAY), 0, default_vibration_settings_title.length(), 0); button_vibration.setDialogTitle(default_vibration_settings_title); button_vibration.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() { @Override public boolean onPreferenceChange(Preference preference, Object newValue) { String new_value = newValue.toString(); index_default_vibration = button_vibration.findIndexOfValue(new_value); CharSequence[] entries = button_vibration.getEntries(); UtilitySharedPrefs.savePrefs(getActivity(), new_value, MainActivity.DEFAULT_VIBRATION_KEY); button_vibration .setSummary(button_vibration.getEntries()[button_vibration.findIndexOfValue(new_value)]); Toast.makeText(getActivity(), String.valueOf(entries[index_default_vibration]), Toast.LENGTH_SHORT) .show(); UtilitySharedPrefs.loadSettingsPrefs(context); return true; } }); final ListPreference default_accent = (ListPreference) getPreferenceManager() .findPreference("default_accent"); default_accent.setSummary(default_accent.getEntry()); final Spannable default_accent_title = new SpannableString("Default Accent"); default_accent_title.setSpan(new ForegroundColorSpan(Color.DKGRAY), 0, default_accent_title.length(), 0); default_accent.setDialogTitle(default_accent_title); default_accent.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() { @Override public boolean onPreferenceChange(Preference preference, Object newValue) { String new_value = newValue.toString(); index_default_accent = default_accent.findIndexOfValue(new_value); CharSequence[] entries = default_accent.getEntries(); UtilitySharedPrefs.savePrefs(getActivity(), new_value, MainActivity.DEFAULT_ACCENT_KEY); default_accent.setSummary(default_accent.getEntries()[default_accent.findIndexOfValue(new_value)]); //Toast.makeText(getActivity(), String.valueOf(entries[index_default_accent]), Toast.LENGTH_SHORT).show(); UtilitySharedPrefs.loadSettingsPrefs(context); return true; } }); final ListPreference theme_selector = (ListPreference) getPreferenceManager() .findPreference("theme_selector"); final Spannable theme_selector_title = new SpannableString("Theme"); theme_selector_title.setSpan(new ForegroundColorSpan(Color.DKGRAY), 0, theme_selector_title.length(), 0); theme_selector.setDialogTitle(theme_selector_title); theme_selector.setSummary(theme_selector.getEntry()); theme_selector.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() { @Override public boolean onPreferenceChange(Preference preference, Object newValue) { String new_value = newValue.toString(); index_default_theme = theme_selector.findIndexOfValue(new_value); CharSequence[] entries = theme_selector.getEntries(); UtilitySharedPrefs.savePrefs(getActivity(), new_value, MainActivity.DEFAULT_THEME_KEY); theme_selector.setSummary(theme_selector.getEntries()[theme_selector.findIndexOfValue(new_value)]); //Toast.makeText(getActivity(), String.valueOf(entries[index_default_theme]), Toast.LENGTH_SHORT).show(); UtilitySharedPrefs.loadSettingsPrefs(context); Toast.makeText(getActivity(), "Done! Reboot to see changes.", Toast.LENGTH_SHORT).show(); return true; } }); Preference acknowledgements = getPreferenceManager().findPreference("acknowledgements"); acknowledgements.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() { @Override public boolean onPreferenceClick(Preference preference) { final Intent preference_intent = new Intent(getActivity(), FileTextActivity.class); Bundle args = new Bundle(); args.putString(FileTextActivity.PREFERENCE, "acknowledgements"); preference_intent.putExtras(args); startActivity(preference_intent, ActivityOptions.makeSceneTransitionAnimation(getActivity()).toBundle()); return false; } }); app_version.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() { @Override public boolean onPreferenceClick(Preference preference) { Utility.openURL(getActivity(), "https://lucacesaranoblog.wordpress.com/2017/04/18/privacy-policy/"); return false; } }); }