Example usage for android.widget RemoteViews setTextViewText

List of usage examples for android.widget RemoteViews setTextViewText

Introduction

In this page you can find the example usage for android.widget RemoteViews setTextViewText.

Prototype

public void setTextViewText(int viewId, CharSequence text) 

Source Link

Document

Equivalent to calling TextView#setText(CharSequence)

Usage

From source file:org.kei.android.phone.cellhistory.CellHistoryApp.java

private RemoteViews getRecorderRemoteViews(final long records, final String size, final int buffer,
        final int max) {
    final RemoteViews contentView = new RemoteViews(getApplicationContext().getPackageName(),
            R.layout.notification_recorder);
    contentView.setImageViewResource(R.id.imagenotileft, R.drawable.ic_launcher_green);
    contentView.setTextViewText(R.id.title, getString(R.string.app_name));
    contentView.setTextViewText(R.id.textBuffer, "Buffer: ");
    contentView.setTextViewText(R.id.textPackets, "Records: " + records);
    contentView.setTextViewText(R.id.textSize, "Size: " + size);
    contentView.setProgressBar(R.id.pbBuffer, max, buffer, false);
    return contentView;
}

From source file:name.gumartinm.weather.information.notification.NotificationIntentService.java

private void showNotification(final Current current, final WeatherLocation weatherLocation) {
    // 1. Update units of measurement.
    final UnitsConversor tempUnitsConversor = new TempUnitsConversor(this.getApplicationContext());

    // 2. Formatters
    final DecimalFormat tempFormatter = (DecimalFormat) NumberFormat.getNumberInstance(Locale.US);
    tempFormatter.applyPattern("###.##");

    // 3. Prepare data for RemoteViews.
    String tempMax = "";
    if (current.getMain().getTemp_max() != null) {
        double conversion = (Double) current.getMain().getTemp_max();
        conversion = tempUnitsConversor.doConversion(conversion);
        tempMax = tempFormatter.format(conversion) + tempUnitsConversor.getSymbol();
    }/*from w  ww  .  j av a  2  s  . c  om*/
    String tempMin = "";
    if (current.getMain().getTemp_min() != null) {
        double conversion = (Double) current.getMain().getTemp_min();
        conversion = tempUnitsConversor.doConversion(conversion);
        tempMin = tempFormatter.format(conversion) + tempUnitsConversor.getSymbol();
    }
    Bitmap picture;
    if ((current.getWeather().size() > 0) && (current.getWeather().get(0).getIcon() != null)
            && (IconsList.getIcon(current.getWeather().get(0).getIcon()) != null)) {
        final String icon = current.getWeather().get(0).getIcon();
        picture = BitmapFactory.decodeResource(this.getResources(),
                IconsList.getIcon(icon).getResourceDrawable());
    } else {
        picture = BitmapFactory.decodeResource(this.getResources(), R.drawable.weather_severe_alert);
    }
    final String city = weatherLocation.getCity();
    final String country = weatherLocation.getCountry();

    // 4. Insert data in RemoteViews.
    final RemoteViews remoteView = new RemoteViews(this.getApplicationContext().getPackageName(),
            R.layout.weather_notification);
    remoteView.setImageViewBitmap(R.id.weather_notification_image, picture);
    remoteView.setTextViewText(R.id.weather_notification_temperature_max, tempMax);
    remoteView.setTextViewText(R.id.weather_notification_temperature_min, tempMin);
    remoteView.setTextViewText(R.id.weather_notification_city, city);
    remoteView.setTextViewText(R.id.weather_notification_country, country);

    // 5. Activity launcher.
    final Intent resultIntent = new Intent(this.getApplicationContext(), MainTabsActivity.class);
    // The PendingIntent to launch our activity if the user selects this notification.
    // 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
    // your application to the Home screen.
    final TaskStackBuilder stackBuilder = TaskStackBuilder.create(this.getApplicationContext());
    // Adds the back stack for the Intent (but not the Intent itself)
    stackBuilder.addParentStack(MainTabsActivity.class);
    // Adds the Intent that starts the Activity to the top of the stack
    stackBuilder.addNextIntent(resultIntent);
    final PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0,
            PendingIntent.FLAG_UPDATE_CURRENT);

    final NotificationManagerCompat notificationManager = NotificationManagerCompat
            .from(this.getApplicationContext());

    // 6. Create notification.
    final NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(
            this.getApplicationContext()).setContent(remoteView).setSmallIcon(R.drawable.ic_launcher)
                    .setAutoCancel(true).setLocalOnly(true).setWhen(System.currentTimeMillis())
                    .setContentIntent(resultPendingIntent).setPriority(NotificationCompat.PRIORITY_DEFAULT);

    final Notification notification = notificationBuilder.build();
    notification.flags |= Notification.FLAG_AUTO_CANCEL;

    // Send the notification.
    // Sets an ID for the notification, so it can be updated (just in case)
    int notifyID = 1;
    notificationManager.notify(notifyID, notification);
}

From source file:com.abhijitvalluri.android.fitnotifications.widget.ServiceToggle.java

@Override
public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) {

    // Perform this loop procedure for each App Widget that belongs to this provider
    for (int appWidgetId : appWidgetIds) {
        // Get the layout for the App Widget and attach an on-click listener
        // to the button
        RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.service_toggle_widget);
        if (NLService.isEnabled()) {
            views.setImageViewResource(R.id.widgetToggleButton, R.drawable.ic_speaker_notes_white_48dp);
            views.setInt(R.id.widgetToggleButton, "setBackgroundResource", R.drawable.round_rectangle_green);
            views.setTextViewText(R.id.widgetToggleText, context.getString(R.string.widget_on_text));
            views.setTextColor(R.id.widgetToggleText, ContextCompat.getColor(context, R.color.green));
        } else {//from   w w  w .  j a v a2  s.c o m
            views.setImageViewResource(R.id.widgetToggleButton, R.drawable.ic_speaker_notes_off_white_48dp);
            views.setInt(R.id.widgetToggleButton, "setBackgroundResource", R.drawable.round_rectangle_red);
            views.setTextViewText(R.id.widgetToggleText, context.getString(R.string.widget_off_text));
            views.setTextColor(R.id.widgetToggleText, ContextCompat.getColor(context, R.color.red));
        }

        views.setOnClickPendingIntent(R.id.widgetToggleButton,
                getPendingSelfIntent(context, appWidgetId, TOGGLE_CLICKED));

        // Tell the AppWidgetManager to perform an update on the current app widget
        appWidgetManager.updateAppWidget(appWidgetId, views);
    }
}

From source file:net.naonedbus.appwidget.HoraireWidgetProvider.java

/**
 * Prparer le widget avec les lments fixes (nom, ligne, sens...)
 *//*w  ww  . j  ava2 s .co m*/
protected void prepareWidgetViewInit(final Context context, final RemoteViews views, final Favori favori) {
    views.setTextViewText(R.id.itemSymbole, favori.getLettre());

    // Uniquement pour 2.2 et sup
    if (Build.VERSION.SDK_INT > 7) {
        views.setTextColor(R.id.itemSymbole, favori.getCouleurTexte());
        views.setTextColor(R.id.itemTitle, favori.getCouleurTexte());
        views.setTextColor(R.id.itemDescription, favori.getCouleurTexte());

        final GradientDrawable gradientDrawable = ColorUtils.getGradiant(favori.getCouleurBackground());
        final Bitmap bitmap = Bitmap.createBitmap(100, 100, Bitmap.Config.ARGB_8888);
        final Canvas canvas = new Canvas(bitmap);
        gradientDrawable.setBounds(0, 0, canvas.getWidth(), canvas.getHeight());
        gradientDrawable.draw(canvas);
        views.setImageViewBitmap(R.id.widgetHeaderBackground, bitmap);
    }

    if (favori.getNomFavori() == null) {
        views.setTextViewText(R.id.itemTitle, favori.getNomArret());
        views.setTextViewText(R.id.itemDescription, FormatUtils.formatSens(favori.getNomSens()));
    } else {
        views.setTextViewText(R.id.itemTitle, favori.getNomArret());
        views.setTextViewText(R.id.itemDescription,
                FormatUtils.formatSens(favori.getNomArret(), favori.getNomSens()));
    }

    views.setViewVisibility(R.id.widgetLoading, View.GONE);
}

From source file:com.racoon.ampdroid.Mp3PlayerService.java

private void setNotifiction() {
    RemoteViews notificationView = new RemoteViews(this.getPackageName(), R.layout.player_notification);
    notificationView.setTextViewText(R.id.notificationSongArtist, getArtist());
    notificationView.setTextViewText(R.id.notificationSongTitle, getCurrentTitle());
    /* 1. Setup Notification Builder */
    Notification.Builder builder = new Notification.Builder(this);

    /* 2. Configure Notification Alarm */
    builder.setSmallIcon(R.drawable.ic_stat_notify).setAutoCancel(true).setWhen(System.currentTimeMillis())
            .setTicker(getCurrentTitle());

    Intent intent = new Intent(this, MainActivity.class);
    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_SINGLE_TOP);
    PendingIntent notifIntent = PendingIntent.getActivity(this, 0, intent, 0);

    builder.setContentIntent(notifIntent);
    builder.setContent(notificationView);

    /* 4. Create Notification and use Manager to launch it */
    Notification notification = builder.getNotification();
    String ns = Context.NOTIFICATION_SERVICE;
    notifManager = (NotificationManager) getSystemService(ns);
    notifManager.notify(NOTIFICATION_ID, notification);
    startForeground(NOTIFICATION_ID, notification);
}

From source file:com.gelakinetic.mtgfam.helpers.DbUpdaterService.java

protected void switchToUpdating(String title) {
    final RemoteViews contentView = new RemoteViews(getPackageName(), R.layout.progress_notification);
    contentView.setProgressBar(R.id.progress_notification_bar, 100, 0, false);
    contentView.setTextViewText(R.id.progress_notification_title, title);

    mUpdateNotification.contentView = contentView;
    mUpdateNotification.contentIntent = mNotificationIntent;

    mNotificationManager.notify(STATUS_NOTIFICATION, mUpdateNotification);

    mProgressUpdater = new Runnable() {
        public void run() {
            contentView.setProgressBar(R.id.progress_notification_bar, 100, mProgress, false);
            mNotificationManager.notify(STATUS_NOTIFICATION, mUpdateNotification);
            mHandler.postDelayed(mProgressUpdater, 200);
        }//from  w  ww .j  a v  a  2  s  .co  m
    };
    mHandler.postDelayed(mProgressUpdater, 200);
}

From source file:com.example.android.customnotifications.MainActivity.java

/**
 * This sample demonstrates notifications with custom content views.
 *
 * <p>On API level 16 and above a big content view is also defined that is used for the
 * 'expanded' notification. The notification is created by the NotificationCompat.Builder.
 * The expanded content view is set directly on the {@link android.app.Notification} once it has been build.
 * (See {@link android.app.Notification#bigContentView}.) </p>
 *
 * <p>The content views are inflated as {@link android.widget.RemoteViews} directly from their XML layout
 * definitions using {@link android.widget.RemoteViews#RemoteViews(String, int)}.</p>
 *///from   w  w w . j  a  v a  2  s  .  co  m
private void createNotification() {
    // BEGIN_INCLUDE(notificationCompat)
    NotificationCompat.Builder builder = new NotificationCompat.Builder(this);
    // END_INCLUDE(notificationCompat)

    // BEGIN_INCLUDE(intent)
    //Create Intent to launch this Activity again if the notification is clicked.
    Intent i = new Intent(this, MainActivity.class);
    i.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
    PendingIntent intent = PendingIntent.getActivity(this, 0, i, PendingIntent.FLAG_UPDATE_CURRENT);
    builder.setContentIntent(intent);
    // END_INCLUDE(intent)

    // BEGIN_INCLUDE(ticker)
    // Sets the ticker text
    builder.setTicker(getResources().getString(R.string.custom_notification));

    // Sets the small icon for the ticker
    builder.setSmallIcon(R.drawable.ic_stat_custom);
    // END_INCLUDE(ticker)

    // BEGIN_INCLUDE(buildNotification)
    // Cancel the notification when clicked
    builder.setAutoCancel(true);

    // Build the notification
    Notification notification = builder.build();
    // END_INCLUDE(buildNotification)

    // BEGIN_INCLUDE(customLayout)
    // Inflate the notification layout as RemoteViews
    RemoteViews contentView = new RemoteViews(getPackageName(), R.layout.notification);

    // Set text on a TextView in the RemoteViews programmatically.
    final String time = DateFormat.getTimeInstance().format(new Date()).toString();
    final String text = getResources().getString(R.string.collapsed, time);
    contentView.setTextViewText(R.id.textView, text);

    /* Workaround: Need to set the content view here directly on the notification.
     * NotificationCompatBuilder contains a bug that prevents this from working on platform
     * versions HoneyComb.
     * See https://code.google.com/p/android/issues/detail?id=30495
     */
    notification.contentView = contentView;

    // Add a big content view to the notification if supported.
    // Support for expanded notifications was added in API level 16.
    // (The normal contentView is shown when the notification is collapsed, when expanded the
    // big content view set here is displayed.)
    if (Build.VERSION.SDK_INT >= 16) {
        // Inflate and set the layout for the expanded notification view
        RemoteViews expandedView = new RemoteViews(getPackageName(), R.layout.notification_expanded);
        notification.bigContentView = expandedView;
    }
    // END_INCLUDE(customLayout)

    // START_INCLUDE(notify)
    // Use the NotificationManager to show the notification
    NotificationManager nm = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
    nm.notify(0, notification);
    // END_INCLUDE(notify)
}

From source file:app.jorge.mobile.com.transportalert.alarm.ServiceAlarm.java

private void createHeadsUpNotification(String label, StringBuilder text, int notificationID, int imageId) {
    String currentTimeString = new SimpleDateFormat("HH:mm").format(new Date());

    RemoteViews remoteViews = new RemoteViews(getPackageName(), R.layout.custom_notification);

    remoteViews.setTextViewText(R.id.titleNotification, label);
    remoteViews.setTextViewText(R.id.messageNotification, text.toString());
    remoteViews.setTextViewText(R.id.timeView, currentTimeString);
    remoteViews.setImageViewResource(R.id.imageNotification, imageId);

    NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(getApplicationContext())
            .setSmallIcon(R.drawable.notification_256x256).setPriority(NotificationCompat.PRIORITY_MAX)
            .setVibrate(new long[] { 1, 1, 1 }).setCategory(NotificationCompat.CATEGORY_MESSAGE)
            .setContent(remoteViews);/*w ww . j ava  2 s . co m*/

    notificationManager.notify(notificationID, notificationBuilder.build());
}

From source file:com.android.deskclock.data.TimerNotificationBuilderN.java

@Override
public Notification buildHeadsUp(Context context, List<Timer> expired) {
    final Timer timer = expired.get(0);

    // First action intent is to reset all timers.
    final Icon icon1 = Icon.createWithResource(context, R.drawable.ic_stop_24dp);
    final Intent reset = TimerService.createResetExpiredTimersIntent(context);
    final PendingIntent intent1 = Utils.pendingServiceIntent(context, reset);

    // Generate some descriptive text, a title, and an action name based on the timer count.
    final CharSequence stateText;
    final int count = expired.size();
    final List<Notification.Action> actions = new ArrayList<>(2);
    if (count == 1) {
        final String label = timer.getLabel();
        if (TextUtils.isEmpty(label)) {
            stateText = context.getString(R.string.timer_times_up);
        } else {/*from   w  w  w .java2  s  .c o  m*/
            stateText = label;
        }

        // Left button: Reset single timer
        final CharSequence title1 = context.getString(R.string.timer_stop);
        actions.add(new Notification.Action.Builder(icon1, title1, intent1).build());

        // Right button: Add minute
        final Intent addTime = TimerService.createAddMinuteTimerIntent(context, timer.getId());
        final PendingIntent intent2 = Utils.pendingServiceIntent(context, addTime);
        final Icon icon2 = Icon.createWithResource(context, R.drawable.ic_add_24dp);
        final CharSequence title2 = context.getString(R.string.timer_plus_1_min);
        actions.add(new Notification.Action.Builder(icon2, title2, intent2).build());

    } else {
        stateText = context.getString(R.string.timer_multi_times_up, count);

        // Left button: Reset all timers
        final CharSequence title1 = context.getString(R.string.timer_stop_all);
        actions.add(new Notification.Action.Builder(icon1, title1, intent1).build());
    }

    final long base = getChronometerBase(timer);

    final String pname = context.getPackageName();
    final RemoteViews contentView = new RemoteViews(pname, R.layout.chronometer_notif_content);
    contentView.setChronometerCountDown(R.id.chronometer, true);
    contentView.setChronometer(R.id.chronometer, base, null, true);
    contentView.setTextViewText(R.id.state, stateText);

    // Content intent shows the timer full screen when clicked.
    final Intent content = new Intent(context, ExpiredTimersActivity.class);
    final PendingIntent contentIntent = Utils.pendingActivityIntent(context, content);

    // Full screen intent has flags so it is different than the content intent.
    final Intent fullScreen = new Intent(context, ExpiredTimersActivity.class)
            .setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_NO_USER_ACTION);
    final PendingIntent pendingFullScreen = Utils.pendingActivityIntent(context, fullScreen);

    return new Notification.Builder(context).setOngoing(true).setLocalOnly(true).setShowWhen(false)
            .setAutoCancel(false).setContentIntent(contentIntent).setCustomContentView(contentView)
            .setPriority(Notification.PRIORITY_MAX).setDefaults(Notification.DEFAULT_LIGHTS)
            .setColor(ContextCompat.getColor(context, R.color.default_background))
            .setSmallIcon(R.drawable.stat_notify_timer).setFullScreenIntent(pendingFullScreen, true)
            .setStyle(new Notification.DecoratedCustomViewStyle())
            .setActions(actions.toArray(new Notification.Action[actions.size()])).build();
}

From source file:com.abhijitvalluri.android.fitnotifications.widget.ServiceToggle.java

@Override
public void onReceive(Context context, Intent intent) {
    super.onReceive(context, intent);

    if (TOGGLE_CLICKED.equals(intent.getAction())) {
        AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(context);
        RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.service_toggle_widget);
        if (NLService.isEnabled()) {
            NLService.setEnabled(false);
            views.setImageViewResource(R.id.widgetToggleButton, R.drawable.ic_speaker_notes_off_white_48dp);
            views.setInt(R.id.widgetToggleButton, "setBackgroundResource", R.drawable.round_rectangle_red);
            views.setTextViewText(R.id.widgetToggleText, context.getString(R.string.widget_off_text));
            views.setTextColor(R.id.widgetToggleText, ContextCompat.getColor(context, R.color.red));
        } else {//from w ww.  j a v a 2  s  . c  o  m
            NLService.setEnabled(true);
            views.setImageViewResource(R.id.widgetToggleButton, R.drawable.ic_speaker_notes_white_48dp);
            views.setInt(R.id.widgetToggleButton, "setBackgroundResource", R.drawable.round_rectangle_green);
            views.setTextViewText(R.id.widgetToggleText, context.getString(R.string.widget_on_text));
            views.setTextColor(R.id.widgetToggleText, ContextCompat.getColor(context, R.color.green));
        }

        views.setOnClickPendingIntent(R.id.widgetToggleButton,
                getPendingSelfIntent(context, 0, TOGGLE_CLICKED));

        ComponentName componentName = new ComponentName(context, ServiceToggle.class);
        appWidgetManager.updateAppWidget(componentName, views);
    }
}