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:com.android.mms.widget.MmsWidgetProvider.java

/**
 * Update the widget appWidgetId//w  w  w  .j a  v  a2 s .  co  m
 */
private static void updateWidget(Context context, int appWidgetId) {
    if (Log.isLoggable(LogTag.WIDGET, Log.VERBOSE)) {
        Log.v(TAG, "updateWidget appWidgetId: " + appWidgetId);
    }
    RemoteViews remoteViews = new RemoteViews(context.getPackageName(), R.layout.widget);
    PendingIntent clickIntent;

    // Launch an intent to avoid ANRs
    final Intent intent = new Intent(context, MmsWidgetService.class);
    intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
    intent.setData(Uri.parse(intent.toUri(Intent.URI_INTENT_SCHEME)));
    remoteViews.setRemoteAdapter(appWidgetId, R.id.conversation_list, intent);

    remoteViews.setTextViewText(R.id.widget_label, context.getString(R.string.sms_app_label));

    // Open Mms's app conversation list when click on header
    final Intent convIntent = new Intent(context, ConversationList.class);
    clickIntent = PendingIntent.getActivity(context, 0, convIntent, PendingIntent.FLAG_UPDATE_CURRENT);
    remoteViews.setOnClickPendingIntent(R.id.widget_header, clickIntent);

    // On click intent for Compose
    final Intent composeIntent = new Intent(context, ComposeMessageActivity.class);
    composeIntent.setAction(Intent.ACTION_SENDTO);
    clickIntent = PendingIntent.getActivity(context, 0, composeIntent, PendingIntent.FLAG_UPDATE_CURRENT);
    remoteViews.setOnClickPendingIntent(R.id.widget_compose, clickIntent);

    // On click intent for Conversation
    TaskStackBuilder taskStackBuilder = TaskStackBuilder.create(context);
    taskStackBuilder.addParentStack(ComposeMessageActivity.class);
    Intent msgIntent = new Intent(Intent.ACTION_VIEW);
    msgIntent.setType("vnd.android-dir/mms-sms");
    taskStackBuilder.addNextIntent(msgIntent);
    remoteViews.setPendingIntentTemplate(R.id.conversation_list,
            taskStackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT));

    AppWidgetManager.getInstance(context).updateAppWidget(appWidgetId, remoteViews);
}

From source file:com.concentriclivers.mms.com.android.mms.widget.MmsWidgetProvider.java

/**
 * Update the widget appWidgetId/*ww w.  ja v a 2 s  .c o m*/
 */
private static void updateWidget(Context context, int appWidgetId) {
    //        if (Log.isLoggable(LogTag.WIDGET, Log.VERBOSE)) {
    Log.v(TAG, "updateWidget appWidgetId: " + appWidgetId);
    //        }
    RemoteViews remoteViews = new RemoteViews(context.getPackageName(), R.layout.widget);
    PendingIntent clickIntent;

    // Launch an intent to avoid ANRs
    final Intent intent = new Intent(context, MmsWidgetService.class);
    intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
    intent.setData(Uri.parse(intent.toUri(Intent.URI_INTENT_SCHEME)));
    remoteViews.setRemoteAdapter(appWidgetId, R.id.conversation_list, intent);

    remoteViews.setTextViewText(R.id.widget_label, context.getString(R.string.app_label));

    // Open Mms's app conversation list when click on header
    final Intent convIntent = new Intent(context, ConversationList.class);
    clickIntent = PendingIntent.getActivity(context, 0, convIntent, PendingIntent.FLAG_UPDATE_CURRENT);
    remoteViews.setOnClickPendingIntent(R.id.widget_header, clickIntent);

    // On click intent for Compose
    final Intent composeIntent = new Intent(context, ComposeMessageActivity.class);
    composeIntent.setAction(Intent.ACTION_SENDTO);
    clickIntent = PendingIntent.getActivity(context, 0, composeIntent, PendingIntent.FLAG_UPDATE_CURRENT);
    remoteViews.setOnClickPendingIntent(R.id.widget_compose, clickIntent);

    // On click intent for Conversation
    TaskStackBuilder taskStackBuilder = TaskStackBuilder.create(context);
    taskStackBuilder.addParentStack(ComposeMessageActivity.class);
    Intent msgIntent = new Intent(Intent.ACTION_VIEW);
    msgIntent.setType("vnd.android-dir/mms-sms");
    taskStackBuilder.addNextIntent(msgIntent);
    remoteViews.setPendingIntentTemplate(R.id.conversation_list,
            taskStackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT));

    AppWidgetManager.getInstance(context).updateAppWidget(appWidgetId, remoteViews);
}

From source file:st.brothas.mtgoxwidget.MtGoxWidgetProvider.java

private static void updateViews(RemoteViews views, MtGoxTickerData prevData, MtGoxTickerData newData,
        WidgetPreferences preferences) {
    String updated = "@ " + dateFormat.format(newData.getTimestamp());
    String lastRounded = round(newData.getLast());
    String lowRounded = round(newData.getLow());
    String highRounded = round(newData.getHigh());

    views.setTextViewText(R.id.appwidget_last, preferences.getCurrencyConversion().symbol + lastRounded);
    views.setTextColor(R.id.appwidget_updated, getColor(preferences.getColorMode(), WidgetColor.Normal));
    if (newData.getTimestamp().before(getDateMinutesAgo(DATA_IS_CONSIDERED_OLD_AFTER_MINUTES))) {
        // Data is old, show it by "old" and "warning" colors
        views.setTextColor(R.id.appwidget_last, Color.GRAY);
        views.setTextColor(R.id.appwidget_updated, getColor(preferences.getColorMode(), WidgetColor.Warning));
    } else if (prevData != null) {
        // We have previous data, compare to get the color
        views.setTextColor(R.id.appwidget_last,
                getColorFromValueChange(prevData.getLast(), newData.getLast(), preferences.getColorMode()));
    } else {//from   w  w w  .ja va2s  . com
        // No previous data, set standard color
        views.setTextColor(R.id.appwidget_last, getColor(preferences.getColorMode(), WidgetColor.StartValue));
    }
    views.setTextViewText(R.id.appwidget_high, highRounded);
    views.setTextViewText(R.id.appwidget_low, lowRounded);
    views.setTextViewText(R.id.appwidget_updated, updated);

    //aws
    if (preferences.getCurrencyConversion().toString().contains("LTC_")) {
        views.setImageViewResource(R.id.appwidget_logo, R.drawable.lc_logo_32);
    }
    //else default which is bitcoin logo
}

From source file:org.cowboycoders.cyclisimo.widgets.TrackWidgetProvider.java

/**
 * Updates average speed.//from  w w  w.jav  a  2s.  c  o m
 * 
 * @param context the context
 * @param remoteViews the remote views
 * @param ids the item's ids
 * @param tripStatistics the trip statistics
 * @param metricUnits true to use metric units
 * @param reportSpeed true to report speed
 */
private static void updateAverageSpeed(Context context, RemoteViews remoteViews, int[] ids,
        TripStatistics tripStatistics, boolean metricUnits, boolean reportSpeed) {
    String averageSpeedLabel = context
            .getString(reportSpeed ? R.string.stats_average_speed : R.string.stats_average_pace);
    remoteViews.setTextViewText(ids[0], averageSpeedLabel);

    Double speed = tripStatistics == null ? Double.NaN : tripStatistics.getAverageSpeed();
    String[] speedParts = StringUtils.getSpeedParts(context, speed, metricUnits, reportSpeed);
    remoteViews.setTextViewText(ids[1], speedParts[0]);
    remoteViews.setTextViewText(ids[2], speedParts[1]);
}

From source file:org.openbitcoinwidget.WidgetProvider.java

private static void updateViews(RemoteViews views, TickerData prevData, TickerData newData,
        WidgetPreferences preferences) {
    String updated = "@ " + dateFormat.format(newData.getTimestamp());
    String lastRounded = round(newData.getLast(), preferences);
    String lowRounded = round(newData.getLow(), preferences);
    String highRounded = round(newData.getHigh(), preferences);

    views.setTextViewText(R.id.appwidget_last, preferences.getCurrencyConversion().symbol + lastRounded);
    views.setTextColor(R.id.appwidget_updated, getColor(preferences.getColorMode(), WidgetColor.Normal));
    if (newData.getTimestamp().before(getDateMinutesAgo(DATA_IS_CONSIDERED_OLD_AFTER_MINUTES))) {
        // Data is old, show it by "old" and "warning" colors
        views.setTextColor(R.id.appwidget_last, Color.GRAY);
        views.setTextColor(R.id.appwidget_updated, getColor(preferences.getColorMode(), WidgetColor.Warning));
    } else if (prevData != null) {
        // We have previous data, compare to get the color
        views.setTextColor(R.id.appwidget_last,
                getColorFromValueChange(prevData.getLast(), newData.getLast(), preferences.getColorMode()));
    } else {//from   ww w . ja  v a2  s .c o  m
        // No previous data, set standard color
        views.setTextColor(R.id.appwidget_last, getColor(preferences.getColorMode(), WidgetColor.StartValue));
    }
    views.setTextViewText(R.id.appwidget_high, highRounded);
    views.setTextViewText(R.id.appwidget_low, lowRounded);
    views.setTextViewText(R.id.appwidget_updated, updated);

    // Set Litecoin logo if that is the chosen currency.
    switch (preferences.getCurrencyConversion().digitalCurrency) {
    case LITECOIN:
        views.setImageViewResource(R.id.appwidget_logo, R.drawable.logo);
        break;
    // The Bitcoin logo is default in the layout.
    }
}

From source file:br.com.bioscada.apps.biotracks.widgets.TrackWidgetProvider.java

/**
 * Updates moving time./*  w  w  w  . ja  v a 2s .  co  m*/
 * 
 * @param context the context
 * @param remoteViews the remote views
 * @param ids the item's ids
 * @param tripStatistics the trip statistics
 */
private static void updateMovingTime(Context context, RemoteViews remoteViews, int[] ids,
        TripStatistics tripStatistics) {
    String movingTime = tripStatistics == null ? context.getString(R.string.value_unknown)
            : StringUtils.formatElapsedTime(tripStatistics.getMovingTime());
    remoteViews.setTextViewText(ids[0], context.getString(R.string.stats_moving_time));
    remoteViews.setTextViewText(ids[1], movingTime);
    remoteViews.setViewVisibility(ids[2], View.GONE);
}

From source file:org.cowboycoders.cyclisimo.widgets.TrackWidgetProvider.java

/**
 * Updates average moving speed.//w  ww . ja v  a  2 s .  c o m
 * 
 * @param context the context
 * @param remoteViews the remote views
 * @param ids the item's ids
 * @param tripStatistics the trip statistics
 * @param metricUnits true to use metric units
 * @param reportSpeed true to report speed
 */
private static void updateAverageMovingSpeed(Context context, RemoteViews remoteViews, int[] ids,
        TripStatistics tripStatistics, boolean metricUnits, boolean reportSpeed) {
    String averageMovingSpeedLabel = context
            .getString(reportSpeed ? R.string.stats_average_moving_speed : R.string.stats_average_moving_pace);
    remoteViews.setTextViewText(ids[0], averageMovingSpeedLabel);

    Double speed = tripStatistics == null ? Double.NaN : tripStatistics.getAverageMovingSpeed();
    String[] speedParts = StringUtils.getSpeedParts(context, speed, metricUnits, reportSpeed);
    remoteViews.setTextViewText(ids[1], speedParts[0]);
    remoteViews.setTextViewText(ids[2], speedParts[1]);
}

From source file:br.com.bioscada.apps.biotracks.widgets.TrackWidgetProvider.java

/**
 * Updates average speed.//from w  w w  . ja  v a  2s. co m
 * 
 * @param context the context
 * @param remoteViews the remote views
 * @param ids the item's ids
 * @param tripStatistics the trip statistics
 * @param metricUnits true to use metric units
 * @param reportSpeed true to report speed
 */
private static void updateAverageSpeed(Context context, RemoteViews remoteViews, int[] ids,
        TripStatistics tripStatistics, boolean metricUnits, boolean reportSpeed) {
    String averageSpeedLabel = context
            .getString(reportSpeed ? R.string.stats_average_speed : R.string.stats_average_pace);
    remoteViews.setTextViewText(ids[0], averageSpeedLabel);

    Double speed = tripStatistics == null ? Double.NaN : tripStatistics.getAverageSpeed();
    String[] speedParts = StringUtils.getSpeedParts(context, speed, metricUnits, reportSpeed);

    if (speedParts[0] == null) {
        speedParts[0] = context.getString(R.string.value_unknown);
    }

    remoteViews.setTextViewText(ids[1], speedParts[0]);
    remoteViews.setTextViewText(ids[2], speedParts[1]);
}

From source file:org.cowboycoders.cyclisimo.widgets.TrackWidgetProvider.java

/**
 * Updates distance.//  w  ww  .  j  a va2  s  . c  om
 * 
 * @param context the context
 * @param remoteViews the remote views
 * @param ids the item's ids
 * @param tripStatistics the trip statistics
 * @param metricUnits true to use metric units
 */
private static void updateDistance(Context context, RemoteViews remoteViews, int[] ids,
        TripStatistics tripStatistics, boolean metricUnits) {
    double totalDistance = tripStatistics == null ? Double.NaN : tripStatistics.getTotalDistance();
    String[] totalDistanceParts = StringUtils.getDistanceParts(context, totalDistance, metricUnits);
    remoteViews.setTextViewText(ids[0], context.getString(R.string.stats_distance));
    remoteViews.setTextViewText(ids[1], totalDistanceParts[0]);
    remoteViews.setTextViewText(ids[2], totalDistanceParts[1]);
}

From source file:br.com.bioscada.apps.biotracks.widgets.TrackWidgetProvider.java

/**
 * Updates average moving speed./*w  w  w.  j  a v  a 2 s. c om*/
 * 
 * @param context the context
 * @param remoteViews the remote views
 * @param ids the item's ids
 * @param tripStatistics the trip statistics
 * @param metricUnits true to use metric units
 * @param reportSpeed true to report speed
 */
private static void updateAverageMovingSpeed(Context context, RemoteViews remoteViews, int[] ids,
        TripStatistics tripStatistics, boolean metricUnits, boolean reportSpeed) {
    String averageMovingSpeedLabel = context
            .getString(reportSpeed ? R.string.stats_average_moving_speed : R.string.stats_average_moving_pace);
    remoteViews.setTextViewText(ids[0], averageMovingSpeedLabel);

    Double speed = tripStatistics == null ? Double.NaN : tripStatistics.getAverageMovingSpeed();
    String[] speedParts = StringUtils.getSpeedParts(context, speed, metricUnits, reportSpeed);

    if (speedParts[0] == null) {
        speedParts[0] = context.getString(R.string.value_unknown);
    }

    remoteViews.setTextViewText(ids[1], speedParts[0]);
    remoteViews.setTextViewText(ids[2], speedParts[1]);
}