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.openbitcoinwidget.WidgetProvider.java

private static void updateAppWidget(final Context context, AppWidgetManager appWidgetManager, int appWidgetId) {

    WidgetPreferences preferences = PreferencesActivity.getWidgetPreferences(context, appWidgetId);

    if (preferences == null) {
        // Don't do anything unless the rate service has been chosen.
        // Show a "please remove this widget and add a new one"
        appWidgetManager.updateAppWidget(appWidgetId,
                new RemoteViews(context.getPackageName(), R.layout.appwidget_replace_me));
        return;//from w ww . j  a  va2s. c om
    }

    boolean isOnLockScreen = isWidgetShownOnLockScreen(appWidgetManager, appWidgetId);

    RemoteViews views;
    if (isOnLockScreen) {
        views = new RemoteViews(context.getPackageName(), R.layout.appwidget_provider_lock_screen);
    } else {
        views = new RemoteViews(context.getPackageName(), R.layout.appwidget_provider);
    }

    Intent clickIntent = new Intent(context, GraphPopupActivity.class);
    clickIntent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
    clickIntent.setAction("dummyAction"); // Needed to get the extra variables included in the call
    // Note: the appWidgetId needs to be sent in the pendingIntent as request code, otherwise only ONE
    //      cached intent will be used for all widget instances!
    PendingIntent pendingIntent = PendingIntent.getActivity(context, appWidgetId, clickIntent, 0);
    views.setOnClickPendingIntent(R.id.appwidget_box, pendingIntent);
    views.setTextViewText(R.id.appwidget_service_name, preferences.getRateService().getName());

    DataOpenHelper dbHelper = new DataOpenHelper(context);
    TickerData prevData = dbHelper.getLastTickerData(preferences);

    TickerData newData;
    String latestQuote = getLatestQuote(preferences);
    if (latestQuote != null && !latestQuote.equals("")) {
        newData = preferences.getRateService().parseJSON(latestQuote);
        newData.setCurrencyConversion(preferences.getCurrencyConversion());
        storeLastValueIfNotNull(dbHelper, newData);
        updateViews(views, prevData, newData, preferences);
    } else if (prevData != null) {
        newData = prevData;
        updateViews(views, prevData, newData, preferences);
    } else {
        updateViewsWithError(views, preferences);
    }
    appWidgetManager.updateAppWidget(appWidgetId, views);
}

From source file:org.chromium.chrome.browser.notifications.CustomNotificationBuilder.java

@Override
public Notification build() {
    RemoteViews compactView = new RemoteViews(mContext.getPackageName(), R.layout.web_notification);
    RemoteViews bigView = new RemoteViews(mContext.getPackageName(), R.layout.web_notification_big);

    String time = DateFormat.getTimeFormat(mContext).format(new Date());
    for (RemoteViews view : new RemoteViews[] { compactView, bigView }) {
        view.setTextViewText(R.id.time, time);
        view.setTextViewText(R.id.title, mTitle);
        view.setTextViewText(R.id.body, mBody);
        view.setTextViewText(R.id.origin, mOrigin);
        view.setImageViewBitmap(R.id.icon, mLargeIcon);
    }//from w w  w .  j  a  v  a2s.c  o m

    if (!mActions.isEmpty()) {
        bigView.setViewVisibility(R.id.button_divider, View.VISIBLE);
        bigView.setViewVisibility(R.id.buttons, View.VISIBLE);
        for (Action action : mActions) {
            RemoteViews button = new RemoteViews(mContext.getPackageName(), R.layout.web_notification_button);
            button.setTextViewCompoundDrawablesRelative(R.id.button, action.getIcon(), 0, 0, 0);
            button.setTextViewText(R.id.button, action.getTitle());
            button.setOnClickPendingIntent(R.id.button, action.getActionIntent());
            bigView.addView(R.id.buttons, button);
        }
    }

    NotificationCompat.Builder builder = new NotificationCompat.Builder(mContext);
    builder.setTicker(mTickerText);
    builder.setSmallIcon(mSmallIconId);
    builder.setContentIntent(mContentIntent);
    builder.setDeleteIntent(mDeleteIntent);
    builder.setDefaults(mDefaults);
    builder.setVibrate(mVibratePattern);
    builder.setContent(compactView);

    Notification notification = builder.build();
    notification.bigContentView = bigView;
    return notification;
}

From source file:com.rossier.shclechelles.service.MyGcmListenerService.java

/**
 * Create and show a simple notification containing the received GCM message.
 *
 * @param message GCM message received.//from   w  w  w  .  j  a va 2 s . com
 */
private void sendNotification(String from, String message) {
    Gson gson = new GsonBuilder().create();
    String messageUTF8 = "";
    try {
        messageUTF8 = new String(message.getBytes(), "UTF-8");
    } catch (UnsupportedEncodingException e) {
        e.printStackTrace();
    }
    Log.i("MyGCMListenerService", message);
    Log.i("MyGCMListenerService", messageUTF8);
    if (messageUTF8 == "")
        return;
    MatchNotification match = gson.fromJson(messageUTF8, MatchNotification.class);
    Intent intent = new Intent(this, MainActivity.class);
    intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    PendingIntent pendingIntent = PendingIntent.getActivity(this, 0 /* Request code */, intent,
            PendingIntent.FLAG_ONE_SHOT);

    int icon = R.drawable.ic_launcher_shc;
    long when = System.currentTimeMillis();
    // Notification notification = new Notification(icon, "Nouveaux rsultats", when);
    Notification notification = new Notification.Builder(this.getBaseContext())
            .setContentText("Nouveaux rsultats").setSmallIcon(icon).setWhen(when).build();

    NotificationManager mNotificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);

    RemoteViews contentView = new RemoteViews(getPackageName(), R.layout.match_notif_layout);
    contentView.setTextViewText(R.id.notif_team_home, match.getTeam_home());
    contentView.setTextViewText(R.id.notif_team_away, match.getTeam_away());
    contentView.setTextViewText(R.id.notif_result_home, match.getResult_home() + "");
    contentView.setTextViewText(R.id.notif_result_away, match.getResult_away() + "");
    contentView.setTextViewText(R.id.notif_ligue, match.getLigue());
    contentView.setImageViewResource(R.id.notif_team_loc_logo, Utils.getLogo(match.getTeam_home()));
    contentView.setImageViewResource(R.id.notif_team_away_logo, Utils.getLogo(match.getTeam_away()));
    notification.contentView = contentView;

    Intent notificationIntent = new Intent(this, MainActivity.class);
    PendingIntent contentIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0);
    notification.contentIntent = contentIntent;

    //notification.flags |= Notification.FLAG_ONGOING_EVENT; //Do not clear the notification
    notification.defaults |= Notification.DEFAULT_LIGHTS; // LED
    notification.defaults |= Notification.DEFAULT_VIBRATE; //Vibration
    notification.defaults |= Notification.DEFAULT_SOUND; // Sound

    //get topics name
    String[] topic = from.split("/");

    mNotificationManager.notify(topic[2].hashCode(), notification);
}

From source file:com.mathi_amorim.emmanuel.metrictime.UpdateTimeService.java

private void updateWidget() {
    mCalendar.setTimeInMillis(System.currentTimeMillis());

    MetricTime time = MetricTimeConverter.currentMetricTime();
    String currentTime = String.format("%1$01d:%2$02d", time.hours, time.minutes);

    RemoteViews mRemoteViews = new RemoteViews(getPackageName(), R.layout.metric_time_widget);
    mRemoteViews.setTextViewText(R.id.widget1label, currentTime);

    Intent intent = new Intent(this, MainActivity.class);
    PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, 0);
    mRemoteViews.setOnClickPendingIntent(R.id.widget1label, pendingIntent);

    ComponentName mComponentName = new ComponentName(this, MetricTimeWidgetProvider.class);
    AppWidgetManager mAppWidgetManager = AppWidgetManager.getInstance(this);
    mAppWidgetManager.updateAppWidget(mComponentName, mRemoteViews);
}

From source file:com.fbartnitzek.tasteemall.widget.StatsWidgetIntentService.java

@Override
protected void onHandleIntent(Intent intent) {

    //        Log.v(LOG_TAG, "onHandleIntent, hashCode=" + this.hashCode() + ", " + "intent = [" + intent + "]");

    // get all widget ids
    AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(this);
    int[] appWidgetIds = appWidgetManager.getAppWidgetIds(new ComponentName(this, StatsWidgetProvider.class));

    // query all entities
    int numLocations = queryAndGetCount(DatabaseContract.LocationEntry.CONTENT_URI,
            QueryColumns.Widget.LocationQuery.COLUMNS);
    int numProducers = queryAndGetCount(DatabaseContract.ProducerEntry.CONTENT_URI,
            QueryColumns.Widget.ProviderQuery.COLUMNS);
    int numDrinks = queryAndGetCount(DatabaseContract.DrinkEntry.CONTENT_URI,
            QueryColumns.Widget.DrinkQuery.COLUMNS);
    int numUsers = queryAndGetCount(DatabaseContract.UserEntry.CONTENT_URI,
            QueryColumns.Widget.UserQuery.COLUMNS);
    int numReviews = queryAndGetCount(DatabaseContract.ReviewEntry.CONTENT_URI,
            QueryColumns.Widget.ReviewQuery.COLUMNS);

    // TODO: results are getting "cached" or something like that ...
    // maybe that helps: http://stackoverflow.com/questions/9497270/widget-with-content-provider-impossible-to-use-readpermission
    Log.v(LOG_TAG,//from w w w.  ja  v  a2s .c om
            "onHandleIntent, producer=" + numProducers + ", drinks=" + numDrinks + ", reviews=" + numReviews);

    for (int appWidgetId : appWidgetIds) {
        // dynamically adapt widget width ... later

        RemoteViews views = new RemoteViews(getPackageName(), R.layout.info_widget);

        // fill stats
        views.setTextViewText(R.id.stats_locations,
                getString(R.string.widget_statistics_locations, numLocations));

        views.setTextViewText(R.id.stats_producers,
                getString(R.string.widget_statistics_producers, numProducers));

        views.setTextViewText(R.id.stats_drinks, getString(R.string.widget_statistics_drinks, numDrinks));

        views.setTextViewText(R.id.stats_users, getString(R.string.widget_statistics_users, numUsers));

        views.setTextViewText(R.id.stats_reviews, getString(R.string.widget_statistics_reviews, numReviews));

        // seems to be impossible to get contentDescription for whole widget...
        //            views.setContentDescription(R.id.widget_layout,
        //                    getString(R.string.a11y_widget_statistics_all, numProducers, numDrinks, numReviews));

        views.setContentDescription(R.id.stats_reviews,
                getString(R.string.a11y_widget_statistics_all, numProducers, numDrinks, numReviews));

        // set on click listener for add and search on every update (kind of useless...)

        // add button - create backStack for add
        Intent addIntent = new Intent(this, AddReviewActivity.class);
        PendingIntent addPendingIntent = TaskStackBuilder.create(this).addNextIntentWithParentStack(addIntent)
                .getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);
        views.setOnClickPendingIntent(R.id.widget_add_button, addPendingIntent);

        // search button
        PendingIntent searchPendingIntent = PendingIntent.getActivity(this, 0,
                new Intent(this, MainActivity.class), 0);
        views.setOnClickPendingIntent(R.id.widget_search_button, searchPendingIntent);

        // update each StatsWidget
        appWidgetManager.updateAppWidget(appWidgetId, views);
    }
}

From source file:ch.fixme.status.Widget.java

protected static void updateWidget(final Context ctxt, int widgetId, AppWidgetManager manager, Bitmap bitmap,
        String text) {/*ww w .ja v a  2 s.com*/
    RemoteViews views = new RemoteViews(ctxt.getPackageName(), R.layout.widget);
    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(ctxt);
    Editor edit = prefs.edit();
    if (prefs.getBoolean(Prefs.KEY_WIDGET_TRANSPARENCY, Prefs.DEFAULT_WIDGET_TRANSPARENCY)) {
        views.setInt(R.id.widget_image, "setBackgroundResource", 0);
    } else {
        views.setInt(R.id.widget_image, "setBackgroundResource", android.R.drawable.btn_default_small);
    }
    if (bitmap != null) {
        views.setImageViewBitmap(R.id.widget_image, bitmap);
        edit.putBoolean(Main.PREF_FORCE_WIDGET + widgetId, false); // Don't
        // need
        // to
        // force
    } else {
        views.setImageViewResource(R.id.widget_image, android.R.drawable.ic_popup_sync);
        edit.putBoolean(Main.PREF_FORCE_WIDGET + widgetId, true); // Something
        // went
        // wrong
    }
    if (text != null) {
        views.setTextViewText(R.id.widget_status, text);
        views.setViewVisibility(R.id.widget_status, View.VISIBLE);
    } else {
        views.setViewVisibility(R.id.widget_status, View.GONE);
    }
    Intent clickIntent = new Intent(ctxt, Main.class);
    clickIntent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, widgetId);
    PendingIntent pendingIntent = PendingIntent.getActivity(ctxt, widgetId, clickIntent,
            PendingIntent.FLAG_CANCEL_CURRENT);
    views.setOnClickPendingIntent(R.id.widget_image, pendingIntent);
    manager.updateAppWidget(widgetId, views);
    // Is initialized
    edit.putBoolean(Main.PREF_INIT_WIDGET + widgetId, true);
    edit.commit();
}

From source file:dk.cafeanalog.AnalogWidget.java

private void handleError(Context mContext) {
    AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(mContext);
    RemoteViews views = new RemoteViews(mContext.getPackageName(), R.layout.analog_widget);
    int[] appWidgetIds = appWidgetManager.getAppWidgetIds(new ComponentName(mContext, AnalogWidget.class));
    views.setTextViewText(R.id.appwidget_text, "Error");
    views.setOnClickPendingIntent(R.id.appwidget_text, getPendingSelfIntent(mContext));
    // Instruct the widget manager to update the widget
    for (int appWidgetId : appWidgetIds) {
        appWidgetManager.updateAppWidget(appWidgetId, views);
    }/* ww  w  .ja  v  a2  s .  c  om*/
}

From source file:org.artags.android.app.widget.AbstractWidgetProvider.java

private void updateTag(Tag tag) {
    setCurrentTag(tag);/*from  w w  w .j a v a  2s.c  o  m*/
    RemoteViews remoteViews = new RemoteViews(mContext.getPackageName(), R.layout.widget);
    remoteViews.setImageViewBitmap(R.id.widget_thumbnail, tag.getBitmap());
    remoteViews.setTextViewText(R.id.widget_text, tag.getText());
    Intent active = new Intent(mContext, getClass());
    active.setAction(Constants.ACTION_SHOW_TAG);
    PendingIntent actionPendingIntent = PendingIntent.getBroadcast(mContext, 0, active, 0);
    remoteViews.setOnClickPendingIntent(R.id.widget_thumbnail, actionPendingIntent);
    if ((tag != null) && (remoteViews != null)) {
        mAppWidgetManager.updateAppWidget(mAppWidgetIds, remoteViews);
        Log.d(Constants.LOG_TAG, "Widget updated");
    }
}

From source file:org.exobel.routerkeygen.AutoConnectService.java

private Notification createProgressBar(CharSequence title, CharSequence content, int progress) {
    final NotificationCompat.Builder builder = getSimple(title, content);
    final PendingIntent i = PendingIntent.getActivity(getApplicationContext(), 0,
            new Intent(this, CancelOperationActivity.class)
                    .putExtra(CancelOperationActivity.SERVICE_TO_TERMINATE, AutoConnectService.class.getName())
                    .putExtra(CancelOperationActivity.MESSAGE, getString(R.string.cancel_auto_test)),
            PendingIntent.FLAG_UPDATE_CURRENT);
    builder.setContentIntent(i);/* ww  w.  j  a  v a  2  s. c o  m*/
    builder.setOngoing(true);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
        builder.setProgress(keys.size(), progress, false);
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
            builder.addAction(android.R.drawable.ic_menu_close_clear_cancel, getString(android.R.string.cancel),
                    i);
        }
    } else {
        final RemoteViews contentView = new RemoteViews(getPackageName(), R.layout.notification);
        contentView.setTextViewText(R.id.text1, content);
        contentView.setProgressBar(R.id.progress, keys.size(), progress, false);
        final Notification not = builder.build();
        not.contentView = contentView;
        return not;
    }
    return builder.build();
}

From source file:com.android.talkbacktests.testsession.NotificationTest.java

private void showCustomNotification() {
    NotificationCompat.Builder builder = new NotificationCompat.Builder(getContext()).setAutoCancel(true)
            .setSmallIcon(android.R.drawable.ic_notification_overlay)
            .setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION));

    RemoteViews contentView = new RemoteViews(getContext().getPackageName(), R.layout.custom_notification);
    contentView.setImageViewResource(R.id.notification_image, android.R.drawable.ic_dialog_email);
    contentView.setTextViewText(R.id.notification_title, getString(R.string.custom_notification_title));
    contentView.setTextViewText(R.id.notification_text, getString(R.string.custom_notification_text));
    builder.setContent(contentView);//www  . ja v a 2  s  .  com

    Intent resultIntent = new Intent(getContext(), MainActivity.class);
    resultIntent.setAction(Intent.ACTION_MAIN);
    resultIntent.addCategory(Intent.CATEGORY_LAUNCHER);

    PendingIntent pendingIntent = PendingIntent.getActivity(getContext(), 0, resultIntent, 0);
    builder.setContentIntent(pendingIntent);

    NotificationManager notificationManager = (NotificationManager) getContext()
            .getSystemService(Context.NOTIFICATION_SERVICE);
    notificationManager.notify(NOTIFICATION_ID_LAST_VIEW, builder.build());
}