List of usage examples for android.content Context getText
@NonNull public final CharSequence getText(@StringRes int resId)
From source file:com.googlecode.mindbell.MindBellPreferences.java
private void onPreferenceClickBatterySettings() { if (Build.VERSION.SDK_INT >= 23) { if (Utils.isAppWhitelisted(this)) { new AlertDialog.Builder(this) // .setTitle(R.string.prefsBatterySettings) // .setMessage(R.string.summaryBatterySettingsWhitelisted) // .setNegativeButton(android.R.string.cancel, null) // .setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { // Take user to the battery settings so he can check the settings startActivity(new Intent(Settings.ACTION_IGNORE_BATTERY_OPTIMIZATION_SETTINGS)); }//from w w w .j a va 2 s .c om }) // .show(); } else { new AlertDialog.Builder(this) // .setTitle(R.string.prefsBatterySettings) // .setMessage(R.string.summaryBatterySettingsNotWhitelisted) // .setNegativeButton(android.R.string.cancel, null) // .setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { // Take user to the battery settings instead of adding a new permission that might result in // suspending MindBell from Google Play Store. See the comments for this answer: // https://stackoverflow.com/a/33114136/2532583 startActivity(new Intent(Settings.ACTION_IGNORE_BATTERY_OPTIMIZATION_SETTINGS)); Context context = MindBellPreferences.this; Toast.makeText(context, context.getText(R.string.battery_settings_guidance1), Toast.LENGTH_LONG).show(); Toast.makeText(context, context.getText(R.string.battery_settings_guidance2), Toast.LENGTH_LONG).show(); Toast.makeText(context, context.getText(R.string.battery_settings_guidance3), Toast.LENGTH_LONG).show(); } }) // .show(); } } else { new AlertDialog.Builder(this) // .setTitle(R.string.prefsBatterySettings) // .setMessage(R.string.summaryBatterySettingsUnknown) // .setPositiveButton(android.R.string.ok, null) // .show(); } }
From source file:org.brandroid.openmanager.util.EventHandler.java
public static String getResourceString(Context mContext, int... resIds) { String ret = ""; for (int resId : resIds) ret += (ret == "" ? "" : " ") + mContext.getText(resId); return ret;//w w w. j a v a 2 s .c om }
From source file:com.rks.musicx.misc.utils.Helper.java
/** * Song Details/*from w w w . j a va 2 s .c om*/ * * @param context * @param title * @param album * @param artist * @param trackno * @param data */ public static void detailMusic(Context context, String title, String album, String artist, int trackno, String data) { if (data != null) { File file = new File(data); if (file.exists()) { float cal = (file.length() / 1024); String content = context.getText(R.string.song_Name) + title + "\n\n" + context.getText(R.string.album_name) + album + "\n\n" + context.getString(R.string.artist_name) + artist + "\n\n" + context.getText(R.string.trackno) + trackno + "\n\n" + context.getText(R.string.file_path) + data + "\n\n" + context.getText(R.string.file_size) + String.valueOf(String.format("%.2f", cal / 1024)) + " MB"; new MaterialDialog.Builder(context).title(R.string.action_details).content(content) .positiveText(R.string.okay).typeface(getFont(context), getFont(context)) .onPositive((materialDialog, dialogAction) -> materialDialog.dismiss()).show(); } else { Toast.makeText(context, "File path not found", Toast.LENGTH_SHORT).show(); } } else { Log.d("Helper", "path not found"); } }
From source file:no.firestorm.weathernotificatonservice.WeatherNotificationService.java
/** * Display a notification with temperature * //from ww w. ja v a 2s.c o m * @param weather * Weather element to with data to be shown in notification, if * null a message for that say that this station does not provide * data will be shown */ private void makeNotification(WeatherElement weather) { int tickerIcon, contentIcon; CharSequence tickerText, contentTitle, contentText, contentTime; final DateFormat df = DateFormat.getTimeInstance(DateFormat.SHORT); long when; Float temperatureF = null; if (weather != null) { // Has data final WeatherElement temperature = weather; // Find name final String stationName = WeatherNotificationSettings.getStationName(WeatherNotificationService.this); // Find icon tickerIcon = TempToDrawable.getDrawableFromTemp(Float.valueOf(temperature.getValue())); contentIcon = tickerIcon; // Set title tickerText = stationName; contentTitle = stationName; contentTime = df.format(temperature.getDate()); when = temperature.getDate().getTime(); final Context context = WeatherNotificationService.this; temperatureF = new Float(temperature.getValue()); contentText = String.format("%s %.1f C", context.getString(R.string.temperatur_), new Float(temperature.getValue())); updateAlarm(weather); } else { // No data contentIcon = android.R.drawable.stat_notify_error; final Context context = WeatherNotificationService.this; contentTime = df.format(new Date()); when = (new Date()).getTime(); tickerText = context.getText(R.string.no_available_data); contentTitle = context.getText(R.string.no_available_data); contentText = context.getString(R.string.try_another_station); tickerIcon = android.R.drawable.stat_notify_error; } makeNotification(tickerIcon, contentIcon, tickerText, contentTitle, contentText, contentTime, when, temperatureF); }
From source file:org.adblockplus.android.configurators.ManualProxyConfigurator.java
private synchronized void noTrafficReceived() { this.isRegistered = false; this.abortNoTrafficCheck(); this.uiHandler.post(new Runnable() { @Override/* www .java 2 s .co m*/ public void run() { final Context context = ManualProxyConfigurator.this.context; // Show warning notification final Intent intent = new Intent(context, ConfigurationActivity.class) .addFlags(Intent.FLAG_ACTIVITY_NEW_TASK) .putExtra("port", ManualProxyConfigurator.this.proxyProperties.getPort()); final PendingIntent contentIntent = PendingIntent.getActivity(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT); final NotificationCompat.Builder builder = new NotificationCompat.Builder(context) .setSmallIcon(R.drawable.ic_stat_warning).setWhen(System.currentTimeMillis()) .setAutoCancel(true).setContentIntent(contentIntent) .setContentTitle(context.getText(R.string.app_name)) .setContentText(context.getText(R.string.notif_notraffic)); final NotificationManager notificationManager = (NotificationManager) context .getSystemService(Context.NOTIFICATION_SERVICE); notificationManager.notify(NOTRAFFIC_NOTIFICATION_ID, builder.getNotification()); context.sendBroadcast(new Intent(ProxyService.PROXY_STATE_CHANGED_ACTION)); } }); }
From source file:com.noshufou.android.su.InstallReceiver.java
@Override public void onReceive(Context context, Intent intent) { PackageManager pm = context.getPackageManager(); String packageName = intent.getDataString().split(":")[1]; PackageInfo packageInfo = null;//from ww w. j a v a 2 s .c o m try { packageInfo = pm.getPackageInfo(packageName, PackageManager.GET_PERMISSIONS); } catch (NameNotFoundException e) { // This won't happen, but if it does, we don't continue Log.e(TAG, "PackageManager divided by zero...", e); return; } if (Util.isPackageMalicious(context, packageInfo) != 0) { NotificationManager nm = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); Intent notificationIntent = new Intent(Intent.ACTION_DELETE, intent.getData()); PendingIntent contentIntent = PendingIntent.getActivity(context, 0, notificationIntent, 0); Notification notification = new NotificationCompat.Builder(context).setSmallIcon(R.drawable.stat_su) .setTicker(context.getText(R.string.malicious_app_notification_ticker)) .setWhen(System.currentTimeMillis()).setContentTitle(context.getText(R.string.app_name)) .setContentText(context.getString(R.string.malicious_app_notification_text, pm.getApplicationLabel(packageInfo.applicationInfo))) .setContentIntent(contentIntent).setAutoCancel(true).getNotification(); nm.notify(0, notification); } }
From source file:cx.ring.model.Conference.java
public void showCallNotification(Context ctx) { NotificationManagerCompat notificationManager = NotificationManagerCompat.from(ctx); notificationManager.cancel(notificationId); if (getParticipants().isEmpty()) return;//from w w w. j av a 2s.co m SipCall call = getParticipants().get(0); CallContact contact = call.getContact(); final Uri call_uri = Uri.withAppendedPath(SipCall.CONTENT_URI, call.getCallId()); PendingIntent goto_intent = PendingIntent.getActivity(ctx, new Random().nextInt(), getViewIntent(ctx), PendingIntent.FLAG_ONE_SHOT); NotificationCompat.Builder noti = new NotificationCompat.Builder(ctx); if (isOnGoing()) { noti.setContentTitle(ctx.getString(R.string.notif_current_call_title, contact.getDisplayName())) .setContentText(ctx.getText(R.string.notif_current_call)).setContentIntent(goto_intent) .addAction(R.drawable.ic_call_end_white_24dp, ctx.getText(R.string.action_call_hangup), PendingIntent.getService( ctx, new Random().nextInt(), new Intent(LocalService.ACTION_CALL_END) .setClass(ctx, LocalService.class).setData(call_uri), PendingIntent.FLAG_ONE_SHOT)); } else if (isRinging()) { if (isIncoming()) { noti.setContentTitle(ctx.getString(R.string.notif_incoming_call_title, contact.getDisplayName())) .setPriority(NotificationCompat.PRIORITY_MAX) .setContentText(ctx.getText(R.string.notif_incoming_call)).setContentIntent(goto_intent) .setFullScreenIntent(goto_intent, true) .addAction(R.drawable.ic_action_accept, ctx.getText(R.string.action_call_accept), PendingIntent.getService(ctx, new Random().nextInt(), new Intent(LocalService.ACTION_CALL_ACCEPT) .setClass(ctx, LocalService.class).setData(call_uri), PendingIntent.FLAG_ONE_SHOT)) .addAction(R.drawable.ic_call_end_white_24dp, ctx.getText(R.string.action_call_decline), PendingIntent.getService(ctx, new Random().nextInt(), new Intent(LocalService.ACTION_CALL_REFUSE) .setClass(ctx, LocalService.class).setData(call_uri), PendingIntent.FLAG_ONE_SHOT)); } else { noti.setContentTitle(ctx.getString(R.string.notif_outgoing_call_title, contact.getDisplayName())) .setContentText(ctx.getText(R.string.notif_outgoing_call)).setContentIntent(goto_intent) .addAction(R.drawable.ic_call_end_white_24dp, ctx.getText(R.string.action_call_hangup), PendingIntent.getService( ctx, new Random().nextInt(), new Intent(LocalService.ACTION_CALL_END) .setClass(ctx, LocalService.class).setData(call_uri), PendingIntent.FLAG_ONE_SHOT)); } } else { notificationManager.cancel(notificationId); return; } noti.setOngoing(true).setCategory(NotificationCompat.CATEGORY_CALL).setSmallIcon(R.drawable.ic_launcher); if (contact.getPhoto() != null) { Resources res = ctx.getResources(); int height = (int) res.getDimension(android.R.dimen.notification_large_icon_height); int width = (int) res.getDimension(android.R.dimen.notification_large_icon_width); noti.setLargeIcon(Bitmap.createScaledBitmap(contact.getPhoto(), width, height, false)); } notificationManager.notify(notificationId, noti.build()); }
From source file:net.geniecode.ttr.ScheduleReceiver.java
@SuppressWarnings("deprecation") @SuppressLint("NewApi") private void setNotification(Context context) { ScrollingText = context.getString(R.string.schedule_postponed_scroll); NotificationText = context.getString(R.string.schedule_postponed_notify); // Trigger a notification that, when clicked, will activate airplane mode mNotificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); PendingIntent contentIntent = PendingIntent.getActivity(context, 0, new Intent(context, ActivateFlightMode.class), PendingIntent.FLAG_CANCEL_CURRENT); Notification notification;/*from w ww.j ava 2s. c o m*/ if (android.os.Build.VERSION.SDK_INT >= 11) { Notification.Builder builder = new Notification.Builder(context); builder.setContentIntent(contentIntent).setSmallIcon(R.drawable.ic_launcher).setTicker(ScrollingText) .setWhen(System.currentTimeMillis()).setAutoCancel(true).setOnlyAlertOnce(true) .setDefaults(Notification.DEFAULT_LIGHTS).setContentTitle(context.getText(R.string.app_name)) .setContentText(NotificationText); if (android.os.Build.VERSION.SDK_INT >= 16) { notification = builder.build(); } else { notification = builder.getNotification(); } } else { notification = new Notification(R.drawable.ic_launcher, ScrollingText, System.currentTimeMillis()); notification.setLatestEventInfo(context, context.getText(R.string.app_name), NotificationText, contentIntent); notification.flags |= Notification.FLAG_ONLY_ALERT_ONCE | Notification.FLAG_AUTO_CANCEL; notification.defaults |= Notification.DEFAULT_LIGHTS; } mNotificationManager.notify(NOTIFICATION_ID, notification); }
From source file:com.prey.net.PreyWebServices.java
public String checkPassword(String email, String password, Context ctx) throws PreyException { PreyConfig preyConfig = PreyConfig.getPreyConfig(ctx); HashMap<String, String> parameters = new HashMap<String, String>(); String xml;// w w w.j a v a 2 s .com try { xml = PreyRestHttpClient.getInstance(ctx) .get(PreyConfig.getPreyConfig(ctx).getPreyUrl().concat("profile.xml"), parameters, preyConfig, email, password) .getResponseAsString(); } catch (IOException e) { throw new PreyException(ctx.getText(R.string.error_communication_exception).toString(), e); } return xml; }
From source file:com.prey.net.PreyWebServices.java
public boolean forgotPassword(Context ctx) throws PreyException { PreyConfig preyConfig = PreyConfig.getPreyConfig(ctx); String URL = PreyConfig.getPreyConfig(ctx).getPreyUrl().concat("forgot"); HashMap<String, String> parameters = new HashMap<String, String>(); parameters.put("user[email]", preyConfig.getEmail()); try {/*from w w w. ja v a 2 s. co m*/ PreyHttpResponse response = PreyRestHttpClient.getInstance(ctx).post(URL, parameters); if (response.getStatusLine().getStatusCode() != 302) { throw new PreyException(ctx.getText(R.string.error_cant_report_forgotten_password).toString()); } } catch (IOException e) { throw new PreyException(ctx.getText(R.string.error_cant_report_forgotten_password).toString(), e); } return true; }