List of usage examples for android.text SpannableString SpannableString
public SpannableString(CharSequence source)
From source file:org.mariotaku.twidere.view.holder.ActivityTitleSummaryViewHolder.java
public void displayActivity(ParcelableActivity activity, boolean byFriends) { final Context context = adapter.getContext(); final Resources resources = adapter.getContext().getResources(); switch (activity.action) { case Activity.ACTION_FOLLOW: { activityTypeView.setImageResource(R.drawable.ic_activity_action_follow); activityTypeView.setColorFilter(ContextCompat.getColor(context, R.color.highlight_follow), Mode.SRC_ATOP);//from w w w.java2 s. c o m if (byFriends) { titleView.setText(getTitleStringByFriends(R.string.activity_by_friends_follow, R.string.activity_by_friends_follow_multi, activity.sources, activity.target_users)); } else { titleView.setText(getTitleStringAboutMe(R.string.activity_about_me_follow, R.string.activity_about_me_follow_multi, activity.sources)); } displayUserProfileImages(activity.sources); summaryView.setVisibility(View.GONE); break; } case Activity.ACTION_FAVORITE: { if (adapter.shouldUseStarsForLikes()) { activityTypeView.setImageResource(R.drawable.ic_activity_action_favorite); activityTypeView.setColorFilter(ContextCompat.getColor(context, R.color.highlight_favorite), Mode.SRC_ATOP); if (byFriends) { titleView.setText(getTitleStringByFriends(R.string.activity_by_friends_favorite, R.string.activity_by_friends_favorite_multi, activity.sources, activity.target_statuses)); } else { titleView.setText(getTitleStringAboutMe(R.string.activity_about_me_favorite, R.string.activity_about_me_favorite_multi, activity.sources)); } } else { activityTypeView.setImageResource(R.drawable.ic_activity_action_like); activityTypeView.setColorFilter(ContextCompat.getColor(context, R.color.highlight_like), Mode.SRC_ATOP); if (byFriends) { titleView.setText(getTitleStringByFriends(R.string.activity_by_friends_like, R.string.activity_by_friends_like_multi, activity.sources, activity.target_statuses)); } else { titleView.setText(getTitleStringAboutMe(R.string.activity_about_me_like, R.string.activity_about_me_like_multi, activity.sources)); } } displayUserProfileImages(activity.sources); summaryView.setText(activity.target_statuses[0].text_unescaped); summaryView.setVisibility(View.VISIBLE); break; } case Activity.ACTION_RETWEET: { activityTypeView.setImageResource(R.drawable.ic_activity_action_retweet); activityTypeView.setColorFilter(ContextCompat.getColor(context, R.color.highlight_retweet), Mode.SRC_ATOP); if (byFriends) { titleView.setText(getTitleStringByFriends(R.string.activity_by_friends_retweet, R.string.activity_by_friends_retweet_multi, activity.sources, activity.target_statuses)); } else titleView.setText(getTitleStringAboutMe(R.string.activity_about_me_retweet, R.string.activity_about_me_retweet_multi, activity.sources)); displayUserProfileImages(activity.sources); summaryView.setText(activity.target_statuses[0].text_unescaped); summaryView.setVisibility(View.VISIBLE); break; } case Activity.ACTION_FAVORITED_RETWEET: { if (byFriends) { showNotSupported(); return; } if (adapter.shouldUseStarsForLikes()) { activityTypeView.setImageResource(R.drawable.ic_activity_action_favorite); activityTypeView.setColorFilter(ContextCompat.getColor(context, R.color.highlight_favorite), Mode.SRC_ATOP); titleView.setText(getTitleStringAboutMe(R.string.activity_about_me_favorited_retweet, R.string.activity_about_me_favorited_retweet_multi, activity.sources)); } else { activityTypeView.setImageResource(R.drawable.ic_activity_action_like); activityTypeView.setColorFilter(ContextCompat.getColor(context, R.color.highlight_like), Mode.SRC_ATOP); titleView.setText(getTitleStringAboutMe(R.string.activity_about_me_liked_retweet, R.string.activity_about_me_liked_retweet_multi, activity.sources)); } displayUserProfileImages(activity.sources); summaryView.setText(activity.target_statuses[0].text_unescaped); summaryView.setVisibility(View.VISIBLE); break; } case Activity.ACTION_RETWEETED_RETWEET: { if (byFriends) { showNotSupported(); return; } activityTypeView.setImageResource(R.drawable.ic_activity_action_retweet); activityTypeView.setColorFilter(ContextCompat.getColor(context, R.color.highlight_retweet), Mode.SRC_ATOP); titleView.setText(getTitleStringAboutMe(R.string.activity_about_me_retweeted_retweet, R.string.activity_about_me_retweeted_retweet_multi, activity.sources)); displayUserProfileImages(activity.sources); summaryView.setText(activity.target_statuses[0].text_unescaped); summaryView.setVisibility(View.VISIBLE); break; } case Activity.ACTION_RETWEETED_MENTION: { if (byFriends) { showNotSupported(); return; } activityTypeView.setImageResource(R.drawable.ic_activity_action_retweet); activityTypeView.setColorFilter(ContextCompat.getColor(context, R.color.highlight_retweet), Mode.SRC_ATOP); titleView.setText(getTitleStringAboutMe(R.string.activity_about_me_retweeted_mention, R.string.activity_about_me_retweeted_mention_multi, activity.sources)); displayUserProfileImages(activity.sources); summaryView.setText(activity.target_statuses[0].text_unescaped); summaryView.setVisibility(View.VISIBLE); break; } case Activity.ACTION_FAVORITED_MENTION: { if (byFriends) { showNotSupported(); return; } if (adapter.shouldUseStarsForLikes()) { activityTypeView.setImageResource(R.drawable.ic_activity_action_favorite); activityTypeView.setColorFilter(ContextCompat.getColor(context, R.color.highlight_favorite), Mode.SRC_ATOP); titleView.setText(getTitleStringAboutMe(R.string.activity_about_me_favorited_mention, R.string.activity_about_me_favorited_mention_multi, activity.sources)); } else { activityTypeView.setImageResource(R.drawable.ic_activity_action_like); activityTypeView.setColorFilter(ContextCompat.getColor(context, R.color.highlight_like), Mode.SRC_ATOP); titleView.setText(getTitleStringAboutMe(R.string.activity_about_me_liked_mention, R.string.activity_about_me_liked_mention_multi, activity.sources)); } displayUserProfileImages(activity.sources); summaryView.setText(activity.target_statuses[0].text_unescaped); summaryView.setVisibility(View.VISIBLE); break; } case Activity.ACTION_LIST_CREATED: { if (!byFriends) { showNotSupported(); return; } activityTypeView.setImageResource(R.drawable.ic_activity_action_list_added); activityTypeView.setColorFilter(activityTypeView.getDefaultColor(), Mode.SRC_ATOP); titleView.setText(getTitleStringByFriends(R.string.activity_by_friends_list_created, R.string.activity_by_friends_list_created_multi, activity.sources, activity.target_object_user_lists)); displayUserProfileImages(activity.sources); boolean firstLine = true; summaryView.setText(""); for (ParcelableUserList item : activity.target_object_user_lists) { if (!firstLine) { summaryView.append("\n"); } summaryView.append(item.description); firstLine = false; } summaryView.setVisibility(View.VISIBLE); break; } case Activity.ACTION_LIST_MEMBER_ADDED: { if (byFriends) { showNotSupported(); return; } activityTypeView.setImageResource(R.drawable.ic_activity_action_list_added); activityTypeView.setColorFilter(activityTypeView.getDefaultColor(), Mode.SRC_ATOP); if (activity.sources.length == 1 && activity.target_object_user_lists != null && activity.target_object_user_lists.length == 1) { final UserColorNameManager manager = adapter.getUserColorNameManager(); final SpannableString firstDisplayName = new SpannableString( manager.getDisplayName(activity.sources[0], adapter.isNameFirst(), false)); final SpannableString listName = new SpannableString(activity.target_object_user_lists[0].name); firstDisplayName.setSpan(new StyleSpan(Typeface.BOLD), 0, firstDisplayName.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); listName.setSpan(new StyleSpan(Typeface.BOLD), 0, listName.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); final String format = context.getString(R.string.activity_about_me_list_member_added_with_name); final Configuration configuration = resources.getConfiguration(); titleView.setText(SpanFormatter.format(configuration.locale, format, firstDisplayName, listName)); } else { titleView.setText(getTitleStringAboutMe(R.string.activity_about_me_list_member_added, R.string.activity_about_me_list_member_added_multi, activity.sources)); } displayUserProfileImages(activity.sources); summaryView.setVisibility(View.GONE); break; } } }
From source file:com.coinblesk.client.utils.UIUtils.java
private static SpannableString coinFiatSpannable(Context context, String amountFirst, String codeFirst, String amountSecond, String codeSecond, float secondaryRelativeSize) { if (amountFirst == null) amountFirst = ""; if (codeFirst == null) codeFirst = ""; if (amountSecond == null) amountSecond = ""; if (codeSecond == null) codeSecond = ""; StringBuffer resultBuffer = new StringBuffer(); resultBuffer.append(amountFirst).append(" "); int lenFirstAmount = resultBuffer.length(); resultBuffer.append(codeFirst);//from www . j a v a 2 s .c o m int lenFirstCode = resultBuffer.length(); resultBuffer.append(" ").append(amountSecond).append(" ").append(codeSecond); int lenSecond = resultBuffer.length(); SpannableString formattedString = new SpannableString(resultBuffer); formattedString.setSpan(new ForegroundColorSpan(Color.WHITE), 0, lenFirstAmount, 0); formattedString.setSpan(new ForegroundColorSpan(ContextCompat.getColor(context, R.color.colorAccent)), lenFirstAmount, lenFirstCode, 0); formattedString.setSpan(new RelativeSizeSpan(secondaryRelativeSize), lenFirstAmount, lenFirstCode, 0); formattedString.setSpan(new ForegroundColorSpan(ContextCompat.getColor(context, R.color.main_color_400)), lenFirstCode, lenSecond, 0); formattedString.setSpan(new RelativeSizeSpan(secondaryRelativeSize), lenFirstCode, lenSecond, 0); return formattedString; }
From source file:com.nextgis.maplibui.util.ControlHelper.java
public static void highlightText(TextView textView) { final CharSequence text = textView.getText(); final SpannableString spannableString = new SpannableString(text); spannableString.setSpan(new URLSpan(""), 0, spannableString.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); textView.setText(spannableString, TextView.BufferType.SPANNABLE); }
From source file:com.chen.mail.browse.SendersView.java
public static void handlePriority(Context context, int maxChars, String messageInfoString, ConversationInfo conversationInfo, ArrayList<SpannableString> styledSenders, ArrayList<String> displayableSenderNames, ArrayList<String> displayableSenderEmails, String account, final TextAppearanceSpan unreadStyleSpan, final CharacterStyle readStyleSpan) { boolean shouldAddPhotos = displayableSenderEmails != null; int maxPriorityToInclude = -1; // inclusive int numCharsUsed = messageInfoString.length(); // draft, number drafts, // count int numSendersUsed = 0; int numCharsToRemovePerWord = 0; int maxFoundPriority = 0; if (numCharsUsed > maxChars) { numCharsToRemovePerWord = numCharsUsed - maxChars; }//from w w w . j a v a2s . c o m final Map<Integer, Integer> priorityToLength = PRIORITY_LENGTH_MAP_CACHE.get(); try { priorityToLength.clear(); int senderLength; for (MessageInfo info : conversationInfo.messageInfos) { senderLength = !TextUtils.isEmpty(info.sender) ? info.sender.length() : 0; priorityToLength.put(info.priority, senderLength); maxFoundPriority = Math.max(maxFoundPriority, info.priority); } while (maxPriorityToInclude < maxFoundPriority) { if (priorityToLength.containsKey(maxPriorityToInclude + 1)) { int length = numCharsUsed + priorityToLength.get(maxPriorityToInclude + 1); if (numCharsUsed > 0) length += 2; // We must show at least two senders if they exist. If we don't // have space for both // then we will truncate names. if (length > maxChars && numSendersUsed >= 2) { break; } numCharsUsed = length; numSendersUsed++; } maxPriorityToInclude++; } } finally { PRIORITY_LENGTH_MAP_CACHE.release(priorityToLength); } // We want to include this entry if // 1) The onlyShowUnread flags is not set // 2) The above flag is set, and the message is unread MessageInfo currentMessage; SpannableString spannableDisplay; String nameString; CharacterStyle style; boolean appendedElided = false; Map<String, Integer> displayHash = Maps.newHashMap(); String firstDisplayableSenderEmail = null; String firstDisplayableSender = null; for (int i = 0; i < conversationInfo.messageInfos.size(); i++) { currentMessage = conversationInfo.messageInfos.get(i); nameString = !TextUtils.isEmpty(currentMessage.sender) ? currentMessage.sender : ""; if (nameString.length() == 0) { nameString = getMe(context); } if (numCharsToRemovePerWord != 0) { nameString = nameString.substring(0, Math.max(nameString.length() - numCharsToRemovePerWord, 0)); } final int priority = currentMessage.priority; style = !currentMessage.read ? getWrappedStyleSpan(unreadStyleSpan) : getWrappedStyleSpan(readStyleSpan); if (priority <= maxPriorityToInclude) { spannableDisplay = new SpannableString(sBidiFormatter.unicodeWrap(nameString)); // Don't duplicate senders; leave the first instance, unless the // current instance is also unread. int oldPos = displayHash.containsKey(currentMessage.sender) ? displayHash.get(currentMessage.sender) : DOES_NOT_EXIST; // If this sender doesn't exist OR the current message is // unread, add the sender. if (oldPos == DOES_NOT_EXIST || !currentMessage.read) { // If the sender entry already existed, and is right next to the // current sender, remove the old entry. if (oldPos != DOES_NOT_EXIST && i > 0 && oldPos == i - 1 && oldPos < styledSenders.size()) { // Remove the old one! styledSenders.set(oldPos, null); if (shouldAddPhotos && !TextUtils.isEmpty(currentMessage.senderEmail)) { displayableSenderEmails.remove(currentMessage.senderEmail); displayableSenderNames.remove(currentMessage.sender); } } displayHash.put(currentMessage.sender, i); spannableDisplay.setSpan(style, 0, spannableDisplay.length(), 0); styledSenders.add(spannableDisplay); } } else { if (!appendedElided) { spannableDisplay = new SpannableString(sElidedString); spannableDisplay.setSpan(style, 0, spannableDisplay.length(), 0); appendedElided = true; styledSenders.add(spannableDisplay); } } if (shouldAddPhotos) { String senderEmail = TextUtils.isEmpty(currentMessage.sender) ? account : TextUtils.isEmpty(currentMessage.senderEmail) ? currentMessage.sender : currentMessage.senderEmail; if (i == 0) { // Always add the first sender! firstDisplayableSenderEmail = senderEmail; firstDisplayableSender = currentMessage.sender; } else { if (!Objects.equal(firstDisplayableSenderEmail, senderEmail)) { int indexOf = displayableSenderEmails.indexOf(senderEmail); if (indexOf > -1) { displayableSenderEmails.remove(indexOf); displayableSenderNames.remove(indexOf); } displayableSenderEmails.add(senderEmail); displayableSenderNames.add(currentMessage.sender); if (displayableSenderEmails.size() > DividedImageCanvas.MAX_DIVISIONS) { displayableSenderEmails.remove(0); displayableSenderNames.remove(0); } } } } } if (shouldAddPhotos && !TextUtils.isEmpty(firstDisplayableSenderEmail)) { if (displayableSenderEmails.size() < DividedImageCanvas.MAX_DIVISIONS) { displayableSenderEmails.add(0, firstDisplayableSenderEmail); displayableSenderNames.add(0, firstDisplayableSender); } else { displayableSenderEmails.set(0, firstDisplayableSenderEmail); displayableSenderNames.set(0, firstDisplayableSender); } } }
From source file:org.catrobat.catroid.ui.fragment.SpritesListFragment.java
private void updateActionModeTitle() { int numberOfSelectedItems = spriteAdapter.getAmountOfCheckedSprites(); if (numberOfSelectedItems == 0) { actionMode.setTitle(multiSelectActionModeTitle); } else {//from w w w . ja v a2s . c om 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.glandorf1.joe.wsprnetviewer.app.WsprFragment.java
@Override public Loader<Cursor> onCreateLoader(int id, Bundle args) { // This is called when a new Loader needs to be created. This // fragment only uses one loader, so we don't care about checking the id. // TODO: Filter the query to only return data from today and the previous N days. // Calendar cal = Calendar.getInstance(); // cal.setTime(new Date()); // cal.add(Calendar.DATE, -7); // N= 7 // Date cutoffDate = cal.getTime(); // String startTimestamp = WsprNetContract.getDbTimestampString(cutoffDate); // Sort order: Descending, by timestamp. String sortOrder = WsprNetContract.SignalReportEntry.COLUMN_TIMESTAMPTEXT + " DESC"; String txCall = Utility.getFilterCallsign(getActivity(), true), rxCall = Utility.getFilterCallsign(getActivity(), false); String txGridsquare = Utility.getFilterGridsquare(getActivity(), true), rxGridsquare = Utility.getFilterGridsquare(getActivity(), false); txCall = Utility.filterCleanupForSQL(txCall); rxCall = Utility.filterCleanupForSQL(rxCall); txGridsquare = Utility.filterCleanupForSQL(txGridsquare); rxGridsquare = Utility.filterCleanupForSQL(rxGridsquare); mSelection = ""; if (Utility.isFiltered(getActivity())) { // When adding filters, be sure to update onResume(), and save the preference value below, too. String prefAndOr = Utility.isFilterAnd(getActivity()) ? " and " : " or "; String sAndOr = " "; if (txCall.length() > 0) { sAndOr = (mSelection.length() > 0) ? prefAndOr : ""; mSelection += sAndOr + "(" + WsprNetContract.SignalReportEntry.COLUMN_TX_CALLSIGN + " like '" + txCall + "')"; }/*from www. j a v a 2s . c o m*/ if (rxCall.length() > 0) { sAndOr = (mSelection.length() > 0) ? prefAndOr : ""; mSelection += sAndOr + "(" + WsprNetContract.SignalReportEntry.COLUMN_RX_CALLSIGN + " like '" + rxCall + "')"; } if (txGridsquare.length() > 0) { sAndOr = (mSelection.length() > 0) ? prefAndOr : ""; mSelection += sAndOr + "(" + WsprNetContract.SignalReportEntry.COLUMN_TX_GRIDSQUARE + " like '" + txGridsquare + "')"; } if (rxGridsquare.length() > 0) { sAndOr = (mSelection.length() > 0) ? prefAndOr : ""; mSelection += sAndOr + "(" + WsprNetContract.SignalReportEntry.COLUMN_RX_GRIDSQUARE + " like '" + rxGridsquare + "')"; } // Examples of resulting 'selection' clause: // tx_callsign like 'D%' // (tx_gridsquare like 'D%') and (rx_callsign like 'N%') // (tx_gridsquare like 'D%') or (rx_callsign like 'N%') if (mSelection.length() > 0) { // Remind user that items are filtered, in case the result is not what they expect. Toast.makeText(getActivity(), getActivity().getString(R.string.toast_filter_items), Toast.LENGTH_LONG).show(); } } int mainDisplayPreference = Utility.getMainDisplayPreference(getActivity()); if (mWsprAdapter.mainDisplayFormat != mainDisplayPreference) { // Update the gridsquare/callsign heading text based on the display layout. switch (mainDisplayPreference) { case Utility.MAIN_DISPLAY_CALLSIGN: // fit everything into 2 lines of display mTVGridCallHeader.setText(getActivity().getString(R.string.callsign)); mTVGridCallHeader.setTextColor(getResources().getColor(R.color.wspr_brown)); break; case Utility.MAIN_DISPLAY_GRIDCALL: // fit everything into 4 lines of display String g = getActivity().getString(R.string.grid); String c = getActivity().getString(R.string.call); Spannable s = new SpannableString(g + "/" + c); // In "Grid/Call", make "grid" black, "Call" brown, and "/" somewhere between. // Release: For "Grid", set the span to be 1 extra character. s.setSpan(new ForegroundColorSpan(Color.BLACK), 0, g.length() + 0, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); // Debug: For the "/", set the span to be 2 characters; it will won't display in the color if the span is only 1 character. s.setSpan(new ForegroundColorSpan(getResources().getColor(R.color.wspr_brown2)), g.length() + 0, g.length() + 1, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); s.setSpan(new ForegroundColorSpan(getResources().getColor(R.color.wspr_brown)), g.length() + 1, s.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); mTVGridCallHeader.setText(s); break; case Utility.MAIN_DISPLAY_GRIDSQUARE: // fit everything into 2 lines of display default: mTVGridCallHeader.setText(getActivity().getString(R.string.gridsquare)); mTVGridCallHeader.setTextColor(Color.BLACK); } } // Save some of the preferences to detect if they've changed in onResume(). mGridsquare = Utility.getPreferredGridsquare(getActivity()); mWsprAdapter.mainDisplayFormat = mainDisplayPreference; mFilterTxCallsign = Utility.getFilterCallsign(getActivity(), true); mFilterRxCallsign = Utility.getFilterCallsign(getActivity(), false); mFilterTxGridsquare = Utility.getFilterGridsquare(getActivity(), true); mFilterRxGridsquare = Utility.getFilterGridsquare(getActivity(), false); mFilterAnd = Utility.isFilterAnd(getActivity()); mFiltered = Utility.isFiltered(getActivity()); Uri wsprUri; wsprUri = WsprNetContract.SignalReportEntry.buildWspr(); // Create and return a CursorLoader that will take care of creating a Cursor for the data being displayed. return new CursorLoader(getActivity(), // context wsprUri, // URI WSPR_COLUMNS, // String[] projection mSelection, // String selection null, // String[] selectionArgs sortOrder // String sortOrder ); }
From source file:au.org.ala.fielddata.mobile.CollectSurveyData.java
public void onSpeciesSelected(Species selectedSpecies) { surveyViewModel.speciesSelected(selectedSpecies); pager.setCurrentItem(1);/*from w w w. j av a 2s . c o m*/ SpannableString title = new SpannableString(selectedSpecies.scientificName); title.setSpan(new StyleSpan(Typeface.ITALIC), 0, title.length(), 0); getSupportActionBar().setTitle(title); getSupportActionBar().setSubtitle(selectedSpecies.commonName); }
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 a v a 2 s . com*/ 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; } }); }
From source file:org.bobstuff.bobball.ActivityStateEnum.java
private void showWonScreen() { activityState = ActivityStateEnum.GAMEWON; Statistics.saveHighestLevel(numPlayers, gameManager.getLevel() + 1); levelSeries++;/*from w w w . ja v a 2s .co m*/ Statistics.saveLongestSeries(levelSeries); GameState gs = gameManager.getCurrGameState(); Grid currGrid = gs.getGrid(); SpannableStringBuilder percentageCleared = new SpannableStringBuilder(); String percentageString = currGrid.getPercentCompleteFloat(1) + "%"; String totalPercentageString = getString(R.string.percentageCleared, percentageString); int player1Color = gs.getPlayer(1).getColor(); SpannableString percentage = new SpannableString(totalPercentageString); int percentageStart = totalPercentageString.length() - percentageString.length(); int percentageEnd = totalPercentageString.length(); percentage.setSpan(new ForegroundColorSpan(player1Color), percentageStart, percentageEnd, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); percentageCleared.append(percentage); messageView.setText(getString(R.string.levelCompleted, gameManager.getLevel())); button.setText(R.string.nextLevel); retryButton.setVisibility(View.GONE); button.setVisibility(View.VISIBLE); backToLevelSelectButton.setVisibility(View.GONE); this.percentageCleared.setText(percentageCleared); this.percentageCleared.setVisibility(View.VISIBLE); if (numPlayers > 1) { totalPercentageCleared .setText(getString(R.string.totalPercentageCleared, currGrid.getPercentCompleteFloat() + "%")); totalPercentageCleared.setVisibility(View.VISIBLE); } bonusPoints.setText(getString(R.string.bonusPoints, gameManager.getBonusPoints(gs, gs.getPlayer(1)))); bonusPoints.setVisibility(View.VISIBLE); setMessageViewsVisible(true); }