List of usage examples for android.widget RemoteViews setTextViewText
public void setTextViewText(int viewId, CharSequence text)
From source file:ru.kaefik.isaifutdinov.an_weather_widget.AnWeatherWidget.java
@Override public void onReceive(Context context, Intent intent) { Log.i(TAG_SERVICE, " onReceive " + intent.getAction()); super.onReceive(context, intent); if (FORCE_WIDGET_UPDATE.equals(intent.getAction())) { String nameCity = intent.getStringExtra(PARAM_CITY); String tempCity = intent.getStringExtra(PARAM_TEMP); String windCity = intent.getStringExtra(PARAM_WIND); String timeRefreshCity = intent.getStringExtra(PARAM_TIMEREFRESH); String weatherImageCity = intent.getStringExtra(PARAM_WEATHERIMAGE); String descriptionWeather = intent.getStringExtra(PARAM_DESCWEATHER); int WidgetId = intent.getIntExtra(PARAM_WIDGETID, 0); //TODO: ? , ?. ? ? GetWeatherCityService Log.i(TAG_SERVICE, "onReceive " + nameCity + " -> " + tempCity); // /* w w w . j a v a2 s . c o m*/ AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(context); ComponentName thisWidget = new ComponentName(context, AnWeatherWidget.class); int[] appWidgetId = appWidgetManager.getAppWidgetIds(thisWidget); for (int i = 0; i < appWidgetId.length; i++) { Log.i(TAG_SERVICE, "onReceive -> appWidgetId = " + String.valueOf(appWidgetId[i])); RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.an_weather_widget); if (WidgetId == appWidgetId[i]) { views.setTextViewText(R.id.cityNameText, nameCity); views.setTextViewText(R.id.tempCityText, tempCity); views.setTextViewText(R.id.windText, windCity); views.setTextViewText(R.id.timeRefreshText, timeRefreshCity); views.setTextViewText(R.id.descriptionWeatherText, descriptionWeather); views.setImageViewUri(R.id.weatherImageView, Uri.parse("android.resource://ru.kaefik.isaifutdinov.an_weather_widget/mipmap/" + "weather" + weatherImageCity)); // ? CLICK_WIDGET_BUTTON onReceive // Intent ? Broadcast Intent active = new Intent(context, AnWeatherWidget.class); active.setAction(CLICK_WIDGET_BUTTON); //? ? PendingIntent actionPendingIntent = PendingIntent.getBroadcast(context, 0, active, 0); //? ? views.setOnClickPendingIntent(R.id.refreshButton, actionPendingIntent); //? // END - ? CLICK_WIDGET_BUTTON onReceive appWidgetManager.updateAppWidget(appWidgetId[i], views); break; } appWidgetManager.updateAppWidget(appWidgetId[i], views); } } if (CLICK_WIDGET_BUTTON.equals(intent.getAction())) { Log.i(TAG_SERVICE, " "); // AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(context); ComponentName thisWidget = new ComponentName(context, AnWeatherWidget.class); int[] appWidgetId = appWidgetManager.getAppWidgetIds(thisWidget); RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.an_weather_widget); // ? for (int i = 0; i < appWidgetId.length; i++) { Log.i(TAG_SERVICE, "id -> " + String.valueOf(appWidgetId[i])); String nameCity = ConfigActivity.loadStringParametersFromFile(context, String.valueOf(appWidgetId[i])); startGetWeatherCityService(context, appWidgetId[i], new CityModel(nameCity)); } } }
From source file:org.droidkit.app.UpdateService.java
private void notifyDownloading(String json) { Intent intent = new Intent(this, UpdateActivity.class); intent.putExtra("downloading", true); intent.putExtra("json", json); String desc = "Downloading " + getString(getApplicationInfo().labelRes); PendingIntent pending = PendingIntent.getActivity(this, 0, intent, 0); Notification n = new Notification(android.R.drawable.stat_sys_download, "Downloading update...", System.currentTimeMillis()); n.flags = Notification.FLAG_ONGOING_EVENT; n.contentIntent = pending;/*w ww . j a v a 2 s . co m*/ RemoteViews view = new RemoteViews(getPackageName(), Resources.getId(this, "update_notification", Resources.TYPE_LAYOUT)); view.setTextViewText(Resources.getId(this, "update_title_text", Resources.TYPE_ID), desc); view.setProgressBar(Resources.getId(this, "update_progress_bar", Resources.TYPE_ID), 100, 0, true); view.setImageViewResource(Resources.getId(this, "update_notif_icon", Resources.TYPE_ID), android.R.drawable.stat_sys_download); n.contentView = view; mNotificationManager.notify("Downloading update...", UPDATE_DOWNLOADING_ID, n); }
From source file:de.ub0r.android.portaltimer.UpdateReceiver.java
private boolean updateNotification(final Context context) { Log.d(TAG, "updateNotification()"); lastUpdate = System.currentTimeMillis(); NotificationManager nm = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); ArrayList<Timer> timers = new ArrayList<Timer>(); mNow = System.currentTimeMillis(); mNextTarget = 0;/*from ww w .ja v a 2 s . co m*/ boolean alert = false; Log.d(TAG, "mNow: " + mNow); for (int j = 0; j < Timer.TIMER_IDS.length; j++) { Timer t = new Timer(context, j); timers.add(t); long tt = t.getTarget(); Log.d(TAG, "target(" + j + "): " + tt); if (tt > 0) { if (mNextTarget == 0 || tt < mNextTarget) { mNextTarget = tt; } if (tt < mNow) { alert = true; t.reset(context); } } } Log.d(TAG, "mNextTarget: " + mNextTarget); NotificationCompat.Builder b = new NotificationCompat.Builder(context); b.setPriority(1000); Intent i = new Intent(context, MainActivity.class); i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); b.setContentIntent(PendingIntent.getActivity(context, 0, i, PendingIntent.FLAG_CANCEL_CURRENT)); b.setContentTitle(context.getString(R.string.app_name)); b.setLargeIcon(BitmapFactory.decodeResource(context.getResources(), R.drawable.ic_launcher)); b.setSmallIcon(R.drawable.ic_stat_timer); b.setAutoCancel(false); if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB) { // GB- b.setContentText(context.getString(R.string.notification_text, timers.get(0).getFormatted(), timers.get(1).getFormatted(), timers.get(2).getFormatted())); } else { // HC+ RemoteViews v = new RemoteViews(context.getPackageName(), R.layout.notification); for (int j = 0; j < Timer.TIMER_IDS.length; j++) { v.setTextViewText(Timer.TIMER_IDS[j], timers.get(j).getFormatted().toString()); Intent ij = new Intent(Timer.TIMER_KEYS[j], null, context, UpdateReceiver.class); v.setOnClickPendingIntent(Timer.TIMER_IDS[j], PendingIntent.getBroadcast(context, 0, ij, PendingIntent.FLAG_UPDATE_CURRENT)); } v.setOnClickPendingIntent(R.id.settings, PendingIntent.getActivity(context, 0, new Intent(context, SettingsActivity.class), PendingIntent.FLAG_UPDATE_CURRENT)); b.setContent(v); } if (mNextTarget <= 0 && !alert) { // we don't need any notification b.setOngoing(false); nm.notify(0, b.build()); return false; } else if (alert) { // show notification without running Timer b.setOngoing(mNextTarget > 0); SharedPreferences p = PreferenceManager.getDefaultSharedPreferences(context); if (p.getBoolean("vibrate", true)) { b.setVibrate(VIBRATE); } String n = p.getString("notification", null); if (n == null) { // default b.setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION)); } else if (n.length() > 1) { try { b.setSound(Uri.parse(n)); } catch (Exception e) { Log.e(TAG, "invalid notification uri", e); b.setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION)); } } // else: silent nm.notify(0, b.build()); return true; } else { // show notification with running Timer b.setOngoing(true); nm.notify(0, b.build()); return true; } }
From source file:com.abhijitvalluri.android.fitnotifications.HomeFragment.java
private void initializeDemoButton() { mDemoTV.setOnClickListener(new View.OnClickListener() { @Override/* w w w .j a v a 2 s .c o m*/ public void onClick(View v) { Bundle newExtra = new Bundle(); NotificationCompat.Builder builder = new NotificationCompat.Builder(mContext); String notificationText = "Sample notification subject"; String notificationBigText = "Sample notification body. This is where the details of the notification will be shown."; StringBuilder sb = new StringBuilder(); sb.append("[").append("example").append("] "); sb.append(notificationText); if (notificationBigText.length() > 0) { sb.append(" -- ").append(notificationBigText); } RemoteViews contentView = new RemoteViews(mContext.getPackageName(), R.layout.custom_notification); contentView.setTextViewText(R.id.customNotificationText, getString(R.string.placeholder_notification_text)); builder.setSmallIcon(R.drawable.ic_sms_white_24dp).setContentText(sb.toString()).setExtras(newExtra) .setContentTitle("Sample Notification Title").setContent(contentView); // Creates an explicit intent for the SettingsActivity in the app Intent settingsIntent = new Intent(mContext, SettingsActivity.class); // The stack builder object will contain an artificial back stack for the // started Activity. // This ensures that navigating backward from the Activity leads out of // the application to the Home screen. TaskStackBuilder stackBuilder = TaskStackBuilder.create(mContext); // Adds the back stack for the Intent (but not the Intent itself) stackBuilder.addParentStack(SettingsActivity.class); // Adds the Intent that starts the Activity to the top of the stack stackBuilder.addNextIntent(settingsIntent); PendingIntent settingsPendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT); builder.setContentIntent(settingsPendingIntent).setAutoCancel(true); ((NotificationManager) mContext.getSystemService(Context.NOTIFICATION_SERVICE)) .notify(Constants.NOTIFICATION_ID, builder.build()); Toast.makeText(mContext, getString(R.string.test_notification_sent), Toast.LENGTH_LONG).show(); if (mDismissPlaceholderNotif) { mHandler.postDelayed(new Runnable() { @Override public void run() { ((NotificationManager) mContext.getSystemService(Context.NOTIFICATION_SERVICE)) .cancel(Constants.NOTIFICATION_ID); } }, mPlaceholderNotifDismissDelayMillis); } } }); }
From source file:com.tortel.deploytrack.service.NotificationService.java
@SuppressLint("NewApi") private void showNotification() { // If there isnt an ID saved, shut down the service if (deploymentId == -1) { stopSelf();/*from w w w . j a v a 2s . c o m*/ return; } if (DEBUG) { Toast.makeText(this, "NotificationService loading notification", Toast.LENGTH_SHORT).show(); } // Load the Deployment object Deployment deployment = DatabaseManager.getInstance(this).getDeployment(deploymentId); SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this); RemoteViews view = new RemoteViews(getPackageName(), R.layout.notification); view.setImageViewBitmap(R.id.notification_pie, WidgetProvider.getChartBitmap(deployment, SIZE)); view.setTextViewText(R.id.notification_title, deployment.getName()); view.setTextViewText(R.id.notification_main, getResources().getString(R.string.small_notification, deployment.getPercentage(), deployment.getCompleted(), deployment.getLength())); if (prefs.getBoolean(Prefs.KEY_HIDE_DATE, false)) { view.setViewVisibility(R.id.notification_daterange, View.GONE); } else { view.setTextViewText(R.id.notification_daterange, getResources().getString(R.string.date_range, deployment.getFormattedStart(), deployment.getFormattedEnd())); } NotificationCompat.Builder builder = new NotificationCompat.Builder(this); builder.setContentTitle(deployment.getName()); builder.setContentText(getResources().getString(R.string.small_notification, deployment.getPercentage(), deployment.getCompleted(), deployment.getLength())); builder.setOngoing(true); // Hide the time, its persistent builder.setWhen(0); builder.setSmallIcon(R.drawable.ic_notification); builder.setPriority(Integer.MAX_VALUE); Notification notification = builder.build(); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { notification.bigContentView = view; } notificationManager.notify(NOTIFICATION_ID, notification); //Schedule an update at midnight AlarmManager alarmManager = (AlarmManager) getSystemService(Context.ALARM_SERVICE); DateTime now = new DateTime(); DateTime tomorrow = new DateTime(now.plusDays(1)).withTimeAtStartOfDay(); PendingIntent pending = PendingIntent.getBroadcast(getBaseContext(), 0, new Intent(UPDATE_INTENT), PendingIntent.FLAG_UPDATE_CURRENT); //Adding 100msec to make sure its triggered after midnight Log.d("Scheduling notification update for " + tomorrow.getMillis() + 100); if (Build.VERSION.SDK_INT > Build.VERSION_CODES.JELLY_BEAN_MR2) { alarmManager.setExact(AlarmManager.RTC, tomorrow.getMillis() + 100, pending); } else { alarmManager.set(AlarmManager.RTC, tomorrow.getMillis() + 100, pending); } }
From source file:com.actionbarsherlock.sample.hcgallery.MainActivity.java
void showNotification(boolean custom) { final Resources res = getResources(); final NotificationManager notificationManager = (NotificationManager) getSystemService( NOTIFICATION_SERVICE);//from w w w .j av a 2 s . c om Notification.Builder builder = new Notification.Builder(this) .setSmallIcon(R.drawable.ic_stat_notify_example).setAutoCancel(true) .setTicker(getString(R.string.notification_text)) .setContentIntent(getDialogPendingIntent("Tapped the notification entry.")); if (custom) { // Sets a custom content view for the notification, including an image button. RemoteViews layout = new RemoteViews(getPackageName(), R.layout.notification); layout.setTextViewText(R.id.notification_title, getString(R.string.app_name)); layout.setOnClickPendingIntent(R.id.notification_button, getDialogPendingIntent("Tapped the 'dialog' button in the notification.")); builder.setContent(layout); // Notifications in Android 3.0 now have a standard mechanism for displaying large // bitmaps such as contact avatars. Here, we load an example image and resize it to the // appropriate size for large bitmaps in notifications. Bitmap largeIconTemp = BitmapFactory.decodeResource(res, R.drawable.notification_default_largeicon); Bitmap largeIcon = Bitmap.createScaledBitmap(largeIconTemp, res.getDimensionPixelSize(android.R.dimen.notification_large_icon_width), res.getDimensionPixelSize(android.R.dimen.notification_large_icon_height), false); largeIconTemp.recycle(); builder.setLargeIcon(largeIcon); } else { builder.setNumber(7) // An example number. .setContentTitle(getString(R.string.app_name)) .setContentText(getString(R.string.notification_text)); } notificationManager.notify(NOTIFICATION_DEFAULT, builder.getNotification()); }
From source file:org.kei.android.phone.cellhistory.CellHistoryApp.java
private RemoteViews getRemoteViews(final String name, final int cellid, final int lac, final int ss, final int ssp, final long rxsp, final long txsp) { final RemoteViews contentView = new RemoteViews(getApplicationContext().getPackageName(), R.layout.notifications_main); contentView.setImageViewResource(R.id.imagenotileft, R.drawable.ic_launcher); contentView.setTextViewText(R.id.title, getString(R.string.app_name)); contentView.setTextViewText(R.id.textInfo, "CellID: " + cellid + ", LAC: " + lac); String speeds = "Rx:" + RecorderCtx.convertToHuman(rxsp, false) + "/s, Tx:" + RecorderCtx.convertToHuman(txsp, false) + "/s"; contentView.setTextViewText(R.id.textNetwork, "Network: " + name + ", " + speeds); contentView.setTextViewText(R.id.textSS, "Signal strength: " + ss + " dBm (" + ssp + "%)"); return contentView; }
From source file:com.fanfou.app.opensource.service.DownloadService.java
private void updateProgress(final int progress) { final RemoteViews view = new RemoteViews(getPackageName(), R.layout.download_notification); view.setTextViewText(R.id.download_notification_text, "? " + progress + "%"); view.setInt(R.id.download_notification_progress, "setProgress", progress); this.notification.contentView = view; this.nm.notify(DownloadService.NOTIFICATION_PROGRESS_ID, this.notification); }
From source file:org.solovyev.android.calculator.widget.CalculatorWidget.java
private void updateDisplayState(@Nonnull Context context, @Nonnull RemoteViews views, @Nonnull DisplayState displayState, @Nonnull SimpleTheme theme) { final boolean error = !displayState.valid; if (!error) { views.setTextViewText(R.id.calculator_display, displayState.text); }/*from w w w .java 2s.co m*/ views.setTextColor(R.id.calculator_display, ContextCompat.getColor(context, theme.getDisplayTextColor(error))); }
From source file:com.fanfou.app.opensource.service.DownloadService.java
private void showProgress() { this.notification = new Notification(R.drawable.ic_notify_download, "?", System.currentTimeMillis()); this.notification.flags |= Notification.FLAG_ONGOING_EVENT; this.notification.flags |= Notification.FLAG_AUTO_CANCEL; this.notification.contentIntent = PendingIntent.getActivity(this, 0, new Intent(), 0); final RemoteViews view = new RemoteViews(getPackageName(), R.layout.download_notification); view.setTextViewText(R.id.download_notification_text, "? 0%"); view.setProgressBar(R.id.download_notification_progress, 100, 0, false); this.notification.contentView = view; this.nm.notify(DownloadService.NOTIFICATION_PROGRESS_ID, this.notification); }