List of usage examples for android.content Context getString
@NonNull public final String getString(@StringRes int resId)
From source file:im.delight.android.baselib.Social.java
/** * Constructs an SMS Intent for the given message details and opens the application chooser for this Intent * * @param recipient the recipient's phone number or `null` * @param body the body of the message//w ww . j a v a2 s . com * @param captionRes the string resource ID for the application chooser's window title * @param context the Context instance to start the Intent from * @throws Exception if there was an error trying to launch the SMS Intent */ public static void sendSMS(final String recipient, final String body, final int captionRes, final Context context) throws Exception { final Intent intent = new Intent(Intent.ACTION_SENDTO); intent.setType(HTTP.PLAIN_TEXT_TYPE); if (recipient != null && recipient.length() > 0) { intent.setData(Uri.parse("smsto:" + recipient)); } else { intent.setData(Uri.parse("sms:")); } intent.putExtra("sms_body", body); intent.putExtra(Intent.EXTRA_TEXT, body); if (context != null) { // offer a selection of all applications that can handle the SMS Intent context.startActivity(Intent.createChooser(intent, context.getString(captionRes))); } }
From source file:com.tct.email.LegacyConversions.java
/** * Infer mailbox type from mailbox name. Used by MessagingController (for live folder sync). * * Deprecation: this should be configured in the UI, in conjunction with RF6154 support *//* w w w. ja v a2 s .c o m*/ @Deprecated public static synchronized int inferMailboxTypeFromName(Context context, String mailboxName) { if (sServerMailboxNames.size() == 0) { // preload the hashmap, one time only sServerMailboxNames.put(context.getString(R.string.mailbox_name_server_inbox), Mailbox.TYPE_INBOX); sServerMailboxNames.put(context.getString(R.string.mailbox_name_server_outbox), Mailbox.TYPE_OUTBOX); sServerMailboxNames.put(context.getString(R.string.mailbox_name_server_drafts), Mailbox.TYPE_DRAFTS); sServerMailboxNames.put(context.getString(R.string.mailbox_name_server_trash), Mailbox.TYPE_TRASH); sServerMailboxNames.put(context.getString(R.string.mailbox_name_server_sent), Mailbox.TYPE_SENT); sServerMailboxNames.put(context.getString(R.string.mailbox_name_server_junk), Mailbox.TYPE_JUNK); //[BUGFIX]-Add-BEGIN by TSNJ wei huang,24/10/2014 // TS: xiaolin.li 2014-11-25 EMAIL READ_PLF MOD_S //if (context.getResources().getBoolean(R.bool.feature_email_spamQuarantaineIsJunkFolder_on)) { if (PLFUtils.getBoolean(context, "feature_email_spamQuarantaineIsJunkFolder_on")) { // TS: xiaolin.li 2014-11-25 EMAIL READ_PLF MOD_S sServerMailboxNames.put("spam", Mailbox.TYPE_JUNK); sServerMailboxNames.put("quarantaine", Mailbox.TYPE_JUNK); // TS: zhonghua.tuo 2015-03-19 EMAIL BUGFIX- 935798 ADD_S sServerMailboxNames.put("spam".toUpperCase(), Mailbox.TYPE_JUNK); sServerMailboxNames.put("quarantaine".toUpperCase(), Mailbox.TYPE_JUNK); // TS: zhonghua.tuo 2015-03-19 EMAIL BUGFIX- 935798 ADD_E } //[BUGFIX]-Add-END by TSNJ wei.huang } if (mailboxName == null || mailboxName.length() == 0) { return Mailbox.TYPE_MAIL; } Integer type = sServerMailboxNames.get(mailboxName); if (type != null) { return type; } return Mailbox.TYPE_MAIL; }
From source file:com.none.tom.simplerssreader.utils.SharedPrefUtils.java
public static void addSubscriptions(final Context context, final List outlines) { final LinkedListMultimap<String, String> subscriptions = getSubscriptions(context); for (final Object outline : outlines) { if (outline instanceof Outline) { final String text = ((Outline) outline).getText(); final String xmlUrl = ((Outline) outline).getXmlUrl(); final String category = context.getString(R.string.uncategorized); if (!TextUtils.isEmpty(xmlUrl) && !TextUtils.isEmpty(text) && !subscriptions.containsKey(text)) { subscriptions.putAll(text.trim(), Arrays.asList(category, "", xmlUrl)); }/*from w w w . ja v a 2 s .c o m*/ } else { for (final Outline subOutline : ((OutlineGroup) outline).getOutlines()) { final String text = subOutline.getText(); final String xmlUrl = subOutline.getXmlUrl(); final String category = ((OutlineGroup) outline).getText(); if (!TextUtils.isEmpty(xmlUrl) && !TextUtils.isEmpty(text) && !subscriptions.containsKey(text)) { subscriptions.putAll(text.trim(), Arrays.asList(category, "", xmlUrl)); } } } } final String currentTitle = getCurrentFeedTitle(context); saveSubscriptions(context, subscriptions); updateCurrentFeedPosition(context, currentTitle); }
From source file:org.quantumbadger.redreader.reddit.api.RedditOAuth.java
private static FetchRefreshTokenResult fetchRefreshTokenSynchronous(final Context context, final Uri redirectUri) { final String error = redirectUri.getQueryParameter("error"); if (error != null) { if (error.equals("access_denied")) { return new FetchRefreshTokenResult(FetchRefreshTokenResultStatus.USER_REFUSED_PERMISSION, new RRError(context.getString(R.string.error_title_login_user_denied_permission), context.getString(R.string.error_message_login_user_denied_permission))); } else {//from w w w .ja v a 2 s . c om return new FetchRefreshTokenResult(FetchRefreshTokenResultStatus.INVALID_REQUEST, new RRError(context.getString(R.string.error_title_login_unknown_reddit_error) + error, context.getString(R.string.error_unknown_message))); } } final String code = redirectUri.getQueryParameter("code"); if (code == null) { return new FetchRefreshTokenResult(FetchRefreshTokenResultStatus.INVALID_RESPONSE, new RRError(context.getString(R.string.error_unknown_title), context.getString(R.string.error_unknown_message))); } final String uri = ACCESS_TOKEN_URL; StatusLine responseStatus = null; try { final HttpClient httpClient = CacheManager.createHttpClient(context); final HttpPost request = new HttpPost(uri); final ArrayList<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(3); nameValuePairs.add(new BasicNameValuePair("grant_type", "authorization_code")); nameValuePairs.add(new BasicNameValuePair("code", code)); nameValuePairs.add(new BasicNameValuePair("redirect_uri", REDIRECT_URI)); request.setEntity(new UrlEncodedFormEntity(nameValuePairs)); request.addHeader("Authorization", "Basic " + Base64.encodeToString((CLIENT_ID + ":").getBytes(), Base64.URL_SAFE | Base64.NO_WRAP)); final HttpResponse response = httpClient.execute(request); responseStatus = response.getStatusLine(); if (responseStatus.getStatusCode() != 200) { return new FetchRefreshTokenResult(FetchRefreshTokenResultStatus.UNKNOWN_ERROR, new RRError(context.getString(R.string.error_unknown_title), context.getString(R.string.message_cannotlogin), null, responseStatus, request.getURI().toString())); } final JsonValue jsonValue = new JsonValue(response.getEntity().getContent()); jsonValue.buildInThisThread(); final JsonBufferedObject responseObject = jsonValue.asObject(); final RefreshToken refreshToken = new RefreshToken(responseObject.getString("refresh_token")); final AccessToken accessToken = new AccessToken(responseObject.getString("access_token")); return new FetchRefreshTokenResult(refreshToken, accessToken); } catch (IOException e) { return new FetchRefreshTokenResult(FetchRefreshTokenResultStatus.CONNECTION_ERROR, new RRError(context.getString(R.string.error_connection_title), context.getString(R.string.error_connection_message), e, responseStatus, uri)); } catch (Throwable t) { return new FetchRefreshTokenResult(FetchRefreshTokenResultStatus.UNKNOWN_ERROR, new RRError(context.getString(R.string.error_unknown_title), context.getString(R.string.error_unknown_message), t, responseStatus, uri)); } }
From source file:com.example.igorklimov.popularmoviesdemo.sync.SyncAdapter.java
public static void syncImmediately(Context context) { Log.d(LOG_TAG, "syncImmediately: "); ConnectivityManager systemService = (ConnectivityManager) context .getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo activeNetworkInfo = systemService.getActiveNetworkInfo(); if (activeNetworkInfo == null) { new NoInternet().show(((MainActivity) context).getSupportFragmentManager(), "1"); }//from www. j a v a2 s . c o m Bundle bundle = new Bundle(); bundle.putBoolean(ContentResolver.SYNC_EXTRAS_EXPEDITED, true); bundle.putBoolean(ContentResolver.SYNC_EXTRAS_MANUAL, true); ContentResolver.requestSync(getSyncAccount(context), context.getString(R.string.content_authority), bundle); }
From source file:com.android.email.LegacyConversions.java
/** * Infer mailbox type from mailbox name. Used by MessagingController (for live folder sync) * and for legacy account upgrades./* www . j a v a 2s. com*/ */ public static synchronized int inferMailboxTypeFromName(Context context, String mailboxName) { if (sServerMailboxNames.size() == 0) { // preload the hashmap, one time only sServerMailboxNames.put(context.getString(R.string.mailbox_name_server_inbox).toLowerCase(), Mailbox.TYPE_INBOX); sServerMailboxNames.put(context.getString(R.string.mailbox_name_server_outbox).toLowerCase(), Mailbox.TYPE_OUTBOX); sServerMailboxNames.put(context.getString(R.string.mailbox_name_server_drafts).toLowerCase(), Mailbox.TYPE_DRAFTS); sServerMailboxNames.put(context.getString(R.string.mailbox_name_server_trash).toLowerCase(), Mailbox.TYPE_TRASH); sServerMailboxNames.put(context.getString(R.string.mailbox_name_server_sent).toLowerCase(), Mailbox.TYPE_SENT); sServerMailboxNames.put(context.getString(R.string.mailbox_name_server_junk).toLowerCase(), Mailbox.TYPE_JUNK); } if (mailboxName == null || mailboxName.length() == 0) { return EmailContent.Mailbox.TYPE_MAIL; } String lowerCaseName = mailboxName.toLowerCase(); Integer type = sServerMailboxNames.get(lowerCaseName); if (type != null) { return type; } return EmailContent.Mailbox.TYPE_MAIL; }
From source file:com.frostwire.android.gui.util.UIUtils.java
/** * @param context - containing Context. * @param showInstallationCompleteSection - true if you want to display "Your installation is now complete. Thank You" section * @param dismissListener - what happens when the dialog is dismissed. * @param referrerContextSuffix - string appended at the end of social pages click urls's ?ref=_android_ parameter. *//*from w w w .j a v a 2 s.c o m*/ public static void showSocialLinksDialog(final Context context, boolean showInstallationCompleteSection, DialogInterface.OnDismissListener dismissListener, String referrerContextSuffix) { AlertDialog.Builder builder = new AlertDialog.Builder(context); View customView = View.inflate(context, R.layout.view_social_buttons, null); builder.setView(customView); builder.setPositiveButton(context.getString(android.R.string.ok), (dialog, which) -> dialog.dismiss()); final AlertDialog socialLinksDialog = builder.create(); socialLinksDialog.requestWindowFeature(Window.FEATURE_NO_TITLE); socialLinksDialog.setOnDismissListener(dismissListener); ImageButton fbButton = customView.findViewById(R.id.view_social_buttons_facebook_button); ImageButton twitterButton = customView.findViewById(R.id.view_social_buttons_twitter_button); ImageButton redditButton = customView.findViewById(R.id.view_social_buttons_reddit_button); final String referrerParam = "?ref=android_" + ((referrerContextSuffix != null) ? referrerContextSuffix.trim() : ""); fbButton.setOnClickListener( v -> UIUtils.openURL(v.getContext(), Constants.SOCIAL_URL_FACEBOOK_PAGE + referrerParam)); twitterButton.setOnClickListener( v -> UIUtils.openURL(v.getContext(), Constants.SOCIAL_URL_TWITTER_PAGE + referrerParam)); redditButton.setOnClickListener( v -> UIUtils.openURL(v.getContext(), Constants.SOCIAL_URL_REDDIT_PAGE + referrerParam)); if (showInstallationCompleteSection) { LinearLayout installationCompleteLayout = customView .findViewById(R.id.view_social_buttons_installation_complete_layout); installationCompleteLayout.setVisibility(View.VISIBLE); ImageButton dismissCheckButton = customView.findViewById(R.id.view_social_buttons_dismiss_check); dismissCheckButton.setOnClickListener(v -> socialLinksDialog.dismiss()); } socialLinksDialog.show(); }
From source file:net.kourlas.voipms_sms.Utils.java
/** * Formats a date for display in the application. * * @param applicationContext The application context. * @param date The date to format. * @param hideTime Omits the time in the formatted date if true. * @return the formatted date.//from ww w .jav a 2 s . co m */ public static String getFormattedDate(Context applicationContext, Date date, boolean hideTime) { Calendar calendar = Calendar.getInstance(); calendar.setTime(date); Calendar oneMinuteAgo = Calendar.getInstance(); oneMinuteAgo.add(Calendar.MINUTE, -1); if (oneMinuteAgo.getTime().before(date)) { // Last minute: X seconds ago long seconds = (Calendar.getInstance().getTime().getTime() - calendar.getTime().getTime()) / 1000; if (seconds < 10) { return applicationContext.getString(R.string.utils_date_just_now); } else { return seconds + " " + applicationContext.getString(R.string.utils_date_seconds_ago); } } Calendar oneHourAgo = Calendar.getInstance(); oneHourAgo.add(Calendar.HOUR_OF_DAY, -1); if (oneHourAgo.getTime().before(date)) { // Last hour: X minutes ago long minutes = (Calendar.getInstance().getTime().getTime() - calendar.getTime().getTime()) / (1000 * 60); if (minutes == 1) { return applicationContext.getString(R.string.utils_date_one_minute_ago); } else { return minutes + " " + applicationContext.getString(R.string.utils_date_minutes_ago); } } if (compareDateWithoutTime(Calendar.getInstance(), calendar) == 0) { // Today: h:mm a DateFormat format = new SimpleDateFormat("h:mm a", Locale.getDefault()); return format.format(date); } if (Calendar.getInstance().get(Calendar.WEEK_OF_YEAR) == calendar.get(Calendar.WEEK_OF_YEAR) && Calendar.getInstance().get(Calendar.YEAR) == calendar.get(Calendar.YEAR)) { if (hideTime) { // This week: EEE DateFormat format = new SimpleDateFormat("EEE", Locale.getDefault()); return format.format(date); } else { // This week: EEE h:mm a DateFormat format = new SimpleDateFormat("EEE h:mm a", Locale.getDefault()); return format.format(date); } } if (Calendar.getInstance().get(Calendar.YEAR) == calendar.get(Calendar.YEAR)) { if (hideTime) { // This year: MMM d DateFormat format = new SimpleDateFormat("MMM d", Locale.getDefault()); return format.format(date); } else { // This year: MMM d h:mm a DateFormat format = new SimpleDateFormat("MMM d, h:mm a", Locale.getDefault()); return format.format(date); } } if (hideTime) { // Any: MMM d, yyyy DateFormat format = new SimpleDateFormat("MMM d, yyyy", Locale.getDefault()); return format.format(date); } else { // Any: MMM d, yyyy h:mm a DateFormat format = new SimpleDateFormat("MMM d, yyyy, h:mm a", Locale.getDefault()); return format.format(date); } }
From source file:com.katamaditya.apps.weather4u.weathersync.Weather4USyncAdapter.java
private static void onAccountCreated(Account newAccount, Context context) { /*/*from w w w . j a v a2s . c o m*/ * Since we've created an account */ Weather4USyncAdapter.configurePeriodicSync(context, SYNC_INTERVAL, SYNC_FLEXTIME); /* * Without calling setSyncAutomatically, our periodic sync will not be enabled. */ ContentResolver.setSyncAutomatically(newAccount, context.getString(R.string.content_authority), true); /* * Finally, let's do a sync to get things started */ syncImmediately(context); }
From source file:com.grarak.kerneladiutor.utils.kernel.cpu.CPUFreq.java
public static List<String> getAdjustedFreq(int cpu, Context context) { List<String> freqs = new ArrayList<>(); if (getFreqs(cpu) != null) { for (int freq : getFreqs(cpu)) { freqs.add((freq / 1000) + context.getString(R.string.mhz)); }//from ww w .j a va 2 s . com } return freqs; }