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:co.carlosjimenez.android.currencyalerts.app.widget.DetailWidgetProvider.java

/**
 * Helper method to set the main currency information on the header of the widget.
 *
 * @param context       Context to use for resource localization
 * @param views         Remote Views where we set the widget information
 * @param appWidgetIds  Ids of every widget present.
 *//*ww  w . j  a v a 2 s .c o m*/
public void setMainCurrencyDetails(Context context, @NonNull final RemoteViews views, int[] appWidgetIds) {
    Currency mainCurrency = Utility.getMainCurrency(context);

    if (mainCurrency == null)
        return;

    AppWidgetTarget appWidgetTarget = new AppWidgetTarget(context, views, R.id.widget_main_currency_flag,
            appWidgetIds);

    Glide.with(context).load(mainCurrency.getCountryFlag()).asBitmap().error(R.drawable.globe)
            .into(appWidgetTarget);

    views.setTextViewText(R.id.widget_main_currency_id, mainCurrency.getId());
}

From source file:ar.com.martinrevert.argenteam.GcmIntentService.java

/**
 * Issues a notification to inform the user that server has sent a message.
 *//*w  ww . j a va2s  . c  o  m*/
private void generarNotification(Context context, String message, String urlimagen, String urlarticulo,
        String tipo, String fecha) {
    SharedPreferences preferencias = PreferenceManager.getDefaultSharedPreferences(getBaseContext());
    boolean vib = preferencias.getBoolean("vibraoff", false);
    boolean movieoff = preferencias.getBoolean("movieoff", false);
    boolean tvoff = preferencias.getBoolean("tvoff", false);
    String ringmovie = preferencias.getString("prefRingtonemovie", "");
    String ringtv = preferencias.getString("prefRingtonetv", "");
    //Todo traducir ticker
    String ticker = "Nuevo subttulo " + tipo + " en aRGENTeaM";

    Random randomGenerator = new Random();
    int randomInt = randomGenerator.nextInt(100);

    Bitmap bitmap = getRemoteImage(urlimagen, tipo);

    Vibrator v = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE);

    int dash = 500;
    int short_gap = 200;

    long[] pattern = { 0, // Start immediately
            dash, short_gap, dash, short_gap, dash };

    Intent notificationIntent;
    String ringtone;
    int ledlight;

    if (tipo.equalsIgnoreCase("Movie")) {
        ringtone = ringmovie;
        notificationIntent = new Intent(context, Peli.class);
        ledlight = preferencias.getInt("ledMovie", 0);

    } else {
        notificationIntent = new Intent(context, Tv.class);
        ringtone = ringtv;
        ledlight = preferencias.getInt("ledTV", 0);
        System.out.println(ledlight);
    }
    notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    notificationIntent.putExtra("passed", urlarticulo);

    PendingIntent pendingIntent;

    pendingIntent = PendingIntent.getActivity(context, randomInt, notificationIntent, 0);

    Notification myNotification;
    myNotification = new NotificationCompat.Builder(context).setPriority(1).setContentTitle(message)
            .setTicker(ticker).setLights(ledlight, 300, 300).setWhen(System.currentTimeMillis())
            .setContentIntent(pendingIntent).setSound(Uri.parse(ringtone)).setAutoCancel(true)
            .setSmallIcon(R.drawable.ic_stat_ic_argenteam_gcm).build();

    if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
        RemoteViews views;
        views = new RemoteViews(getPackageName(), R.layout.custom_notification);
        views.setImageViewBitmap(R.id.big_picture, bitmap);
        views.setImageViewBitmap(R.id.big_icon,
                BitmapFactory.decodeResource(getResources(), R.drawable.ic_stat_ic_argenteam_gcm));
        views.setTextViewText(R.id.title, message);
        myNotification.bigContentView = views;
    }

    NotificationManager notificationManager = (NotificationManager) context
            .getSystemService(Context.NOTIFICATION_SERVICE);

    if (movieoff && tipo.equalsIgnoreCase("Movie")) {
        if (vib) {
            v.vibrate(pattern, -1);
        }
        notificationManager.notify(randomInt, myNotification);

    }

    if (tvoff && tipo.equalsIgnoreCase("Serie TV")) {
        if (vib) {
            v.vibrate(pattern, -1);
        }
        notificationManager.notify(randomInt, myNotification);

    }

}

From source file:org.solovyev.android.calculator.widget.CalculatorWidget.java

private void updateEditorState(@Nonnull Context context, @Nonnull RemoteViews views, @Nonnull EditorState state,
        @Nonnull SimpleTheme theme) {// ww  w . jav  a  2s .co m
    final boolean unspan = App.getTheme().light != theme.light;

    final CharSequence text = state.text;
    final int selection = state.selection;
    if (selection < 0 || selection > text.length()) {
        views.setTextViewText(R.id.calculator_editor, unspan ? App.unspan(text) : text);
        return;
    }

    final SpannableStringBuilder result;
    // inject cursor
    if (unspan) {
        final CharSequence beforeCursor = text.subSequence(0, selection);
        final CharSequence afterCursor = text.subSequence(selection, text.length());

        result = new SpannableStringBuilder();
        result.append(App.unspan(beforeCursor));
        result.append(getCursorString(context));
        result.append(App.unspan(afterCursor));
    } else {
        result = new SpannableStringBuilder(text);
        result.insert(selection, getCursorString(context));
    }
    views.setTextViewText(R.id.calculator_editor, result);
}

From source file:com.wizardsofm.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, com.wizardsofm.deskclock.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(com.wizardsofm.deskclock.R.string.timer_times_up);
        } else {//from   www .jav  a 2s . com
            stateText = label;
        }

        // Left button: Reset single timer
        final CharSequence title1 = context.getString(com.wizardsofm.deskclock.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, com.wizardsofm.deskclock.R.drawable.ic_add_24dp);
        final CharSequence title2 = context.getString(com.wizardsofm.deskclock.R.string.timer_plus_1_min);
        actions.add(new Notification.Action.Builder(icon2, title2, intent2).build());

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

        // Left button: Reset all timers
        final CharSequence title1 = context.getString(com.wizardsofm.deskclock.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,
            com.wizardsofm.deskclock.R.layout.chronometer_notif_content);
    contentView.setChronometerCountDown(com.wizardsofm.deskclock.R.id.chronometer, true);
    contentView.setChronometer(com.wizardsofm.deskclock.R.id.chronometer, base, null, true);
    contentView.setTextViewText(com.wizardsofm.deskclock.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, com.wizardsofm.deskclock.R.color.default_background))
            .setSmallIcon(com.wizardsofm.deskclock.R.drawable.stat_notify_timer)
            .setFullScreenIntent(pendingFullScreen, true).setStyle(new Notification.DecoratedCustomViewStyle())
            .setActions(actions.toArray(new Notification.Action[actions.size()])).build();
}

From source file:org.sipdroid.sipua.ui.Receiver.java

public static void onText(int type, String text, int mInCallResId, long base) {
    if (mSipdroidEngine != null && type == REGISTER_NOTIFICATION + mSipdroidEngine.pref) {
        cache_text = text;// ww w  .  j  a v a2 s.  c o m
        cache_res = mInCallResId;
    }
    if (type >= REGISTER_NOTIFICATION && mInCallResId == R.drawable.sym_presence_available
            && !PreferenceManager.getDefaultSharedPreferences(Receiver.mContext).getBoolean(
                    org.sipdroid.sipua.ui.Settings.PREF_REGISTRATION,
                    org.sipdroid.sipua.ui.Settings.DEFAULT_REGISTRATION))
        text = null;
    NotificationManager mNotificationMgr = (NotificationManager) mContext
            .getSystemService(Context.NOTIFICATION_SERVICE);
    if (text != null) {
        Notification notification = new Notification();
        NotificationCompat.Builder builder = new NotificationCompat.Builder(mContext);

        notification.icon = mInCallResId;
        if (type == MISSED_CALL_NOTIFICATION) {
            notification.flags |= Notification.FLAG_AUTO_CANCEL;
            //TODO
            /*notification.setLatestEventInfo(mContext, text, mContext.getString(R.string.app_name),
                  PendingIntent.getActivity(mContext, 0, createCallLogIntent(), 0));
            if (PreferenceManager.getDefaultSharedPreferences(Receiver.mContext).getBoolean(org.sipdroid.sipua.ui.Settings.PREF_NOTIFY, org.sipdroid.sipua.ui.Settings.DEFAULT_NOTIFY)) {
               notification.flags |= Notification.FLAG_SHOW_LIGHTS;
               notification.ledARGB = 0xff0000ff;  blue 
               notification.ledOnMS = 125;
               notification.ledOffMS = 2875;
            }*/
        } else {
            switch (type) {
            case MWI_NOTIFICATION:
                notification.flags |= Notification.FLAG_AUTO_CANCEL;
                notification.contentIntent = PendingIntent.getActivity(mContext, 0, createMWIIntent(), 0);
                notification.flags |= Notification.FLAG_SHOW_LIGHTS;
                notification.ledARGB = 0xff00ff00; /* green */
                notification.ledOnMS = 125;
                notification.ledOffMS = 2875;
                break;
            case AUTO_ANSWER_NOTIFICATION:
                notification.contentIntent = PendingIntent.getActivity(mContext, 0,
                        createIntent(AutoAnswer.class), 0);
                break;
            default:
                if (type >= REGISTER_NOTIFICATION && mSipdroidEngine != null
                        && type != REGISTER_NOTIFICATION + mSipdroidEngine.pref
                        && mInCallResId == R.drawable.sym_presence_available) {
                    int key = type - REGISTER_NOTIFICATION;
                    Intent in = createIntent(ChangeAccount.class);
                    in.setAction(Long.toString(type));
                    in.putExtra(ChangeAccount.ChangeAccountKey, key);
                    in.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
                    notification.contentIntent = PendingIntent.getActivity(mContext, key, in,
                            PendingIntent.FLAG_UPDATE_CURRENT);
                } else
                    notification.contentIntent = PendingIntent.getActivity(mContext, 0,
                            createIntent(Sipdroid.class), 0);
                if (mInCallResId == R.drawable.sym_presence_away) {
                    notification.flags |= Notification.FLAG_SHOW_LIGHTS;
                    notification.ledARGB = 0xffff0000; /* red */
                    notification.ledOnMS = 125;
                    notification.ledOffMS = 2875;
                }
                notification.flags |= Notification.FLAG_ONGOING_EVENT;
                break;
            }

            RemoteViews contentView = new RemoteViews(mContext.getPackageName(),
                    R.layout.ongoing_call_notification);
            contentView.setImageViewResource(R.id.icon, notification.icon);
            if (base != 0) {
                contentView.setChronometer(R.id.text1, base, text + " (%s)", true);
            } else if (type >= REGISTER_NOTIFICATION) {
                if (PreferenceManager.getDefaultSharedPreferences(mContext).getBoolean(
                        org.sipdroid.sipua.ui.Settings.PREF_POS, org.sipdroid.sipua.ui.Settings.DEFAULT_POS))
                    contentView.setTextViewText(R.id.text2,
                            text + "/" + mContext.getString(R.string.settings_pos3));
                else
                    contentView.setTextViewText(R.id.text2, text);
                if (mSipdroidEngine != null)
                    contentView.setTextViewText(R.id.text1,
                            mSipdroidEngine.user_profiles[type - REGISTER_NOTIFICATION].username + "@"
                                    + mSipdroidEngine.user_profiles[type - REGISTER_NOTIFICATION].realm_orig);
            } else
                contentView.setTextViewText(R.id.text1, text);
            notification.contentView = contentView;
        }
        mNotificationMgr.notify(type, notification);
    } else {
        mNotificationMgr.cancel(type);
    }
    if (type != AUTO_ANSWER_NOTIFICATION)
        updateAutoAnswer();
    if (mSipdroidEngine != null && type >= REGISTER_NOTIFICATION
            && type != REGISTER_NOTIFICATION + mSipdroidEngine.pref)
        onText(REGISTER_NOTIFICATION + mSipdroidEngine.pref, cache_text, cache_res, 0);
}

From source file:cm.aptoide.pt.DownloadQueueService.java

private void setNotification(int apkidHash, int progress) {

    String apkid = notifications.get(apkidHash).get("apkid");
    int size = Integer.parseInt(notifications.get(apkidHash).get("intSize"));
    String version = notifications.get(apkidHash).get("version");

    RemoteViews contentView = new RemoteViews(getPackageName(), R.layout.download_notification);
    contentView.setImageViewResource(R.id.download_notification_icon, R.drawable.ic_notification);
    contentView.setTextViewText(R.id.download_notification_name,
            getString(R.string.download_alrt) + " " + apkid + " v." + version);
    contentView.setProgressBar(R.id.download_notification_progress_bar, size * KBYTES_TO_BYTES, progress,
            false);//w w  w .j  a  v  a2s .  c  o m

    Intent onClick = new Intent();
    onClick.setClassName("cm.aptoide.pt", "cm.aptoide.pt");
    onClick.setFlags(Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT | Intent.FLAG_ACTIVITY_NEW_TASK);
    onClick.setAction("cm.aptoide.pt.FROM_NOTIFICATION");

    // The PendingIntent to launch our activity if the user selects this notification
    PendingIntent onClickAction = PendingIntent.getActivity(context, 0, onClick, 0);

    Notification notification = new Notification(R.drawable.ic_notification,
            getString(R.string.download_alrt) + " " + apkid, System.currentTimeMillis());
    notification.flags |= Notification.FLAG_NO_CLEAR | Notification.FLAG_ONGOING_EVENT;
    notification.contentView = contentView;

    // Set the info for the notification panel.
    notification.contentIntent = onClickAction;
    //       notification.setLatestEventInfo(this, getText(R.string.app_name), getText(R.string.add_repo_text), contentIntent);

    notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
    // Send the notification.
    // We use the position because it is a unique number.  We use it later to cancel.
    notificationManager.notify(apkidHash, notification);

    //      Log.d("Aptoide-DownloadQueueService", "Notification Set");
}

From source file:ru.org.sevn.audiobookplayer.AppService.java

private NotificationCompat.Builder makeNotify(Context ctx, String title, String text) {
    //Notification notification = new Notification(R.drawable.ic_launcher, null, System.currentTimeMillis());
    NotificationCompat.Builder mBuilder = makeNotifyBuilder(ctx, title, text);

    RemoteViews notificationView = new RemoteViews(getPackageName(), R.layout.notification);
    notificationView.setTextViewText(R.id.tvTitle, title);
    notificationView.setTextViewText(R.id.textView1, "" + makeNotifyNumber() + " " + text);
    notificationView.setImageViewBitmap(R.id.imageView1, getLargeNotificationIcon());
    mBuilder.setContent(notificationView);
    mBuilder.setContentIntent(makePendingNotificationIntent(makeNotificationIntent()));

    //       notification.contentView = notificationView;
    //       notification.contentIntent = makePendingNotificationIntent(makeNotificationIntent());
    //       notification.flags |= Notification.FLAG_NO_CLEAR;

    notificationView.setOnClickPendingIntent(R.id.btn_prev, makeActionPendingIntent(ACTION_PREV));
    notificationView.setOnClickPendingIntent(R.id.btn_play, makeActionPendingIntent(ACTION_PLAY_PAUSE));
    notificationView.setOnClickPendingIntent(R.id.btn_next, makeActionPendingIntent(ACTION_NEXT));
    notificationView.setOnClickPendingIntent(R.id.btn_exit, makeActionPendingIntent(ACTION_EXIT));

    return mBuilder;
}

From source file:no.firestorm.weathernotificatonservice.WeatherNotificationService.java

/**
 * Make notification and post it to the NotificationManager
 * /*ww  w . jav  a  2  s  .  com*/
 * @param tickerIcon
 *            Icon shown in notification bar
 * @param contentIcon
 *            Icon shown in notification
 * @param tickerText
 *            Text shown in notification bar
 * @param contentTitle
 *            Title shown in notification
 * @param contentText
 *            Description shown in notification
 * @param contentTime
 *            Time shown in notification
 * @param when2
 */
private void makeNotification(int tickerIcon, int contentIcon, CharSequence tickerText,
        CharSequence contentTitle, CharSequence contentText, CharSequence contentTime, long when2,
        Float temperature) {
    final long when = System.currentTimeMillis();
    // Make notification
    Notification notification = null;

    final Intent notificationIntent = new Intent(WeatherNotificationService.this,
            WeatherNotificationService.class);
    final PendingIntent contentIntent = PendingIntent.getService(WeatherNotificationService.this, 0,
            notificationIntent, 0);

    // Check if Notification.Builder exists (11+)
    if (Build.VERSION.SDK_INT >= 11) {
        // Honeycomb ++
        NotificationBuilder builder = new NotificationBuilder(this);
        builder.setAutoCancel(false);
        builder.setContentTitle(contentTitle);
        builder.setContentText(contentText);
        builder.setTicker(tickerText);
        builder.setWhen(when2);
        builder.setSmallIcon(tickerIcon);
        builder.setOngoing(true);
        builder.setContentIntent(contentIntent);
        if (temperature != null)
            builder.makeContentView(contentTitle, contentText, when2, temperature, tickerIcon);
        notification = builder.getNotification();
    } else {
        // Gingerbread --
        notification = new Notification(tickerIcon, tickerText, when);
        notification.flags = Notification.FLAG_ONGOING_EVENT;

        final RemoteViews contentView = new RemoteViews(getPackageName(), R.layout.weathernotification);
        contentView.setImageViewResource(R.id.icon, contentIcon);
        contentView.setTextViewText(R.id.title, contentTitle);
        contentView.setTextViewText(R.id.title, contentTitle);
        contentView.setTextViewText(R.id.text, contentText);
        contentView.setTextViewText(R.id.time, contentTime);
        notification.contentView = contentView;
    }
    notification.contentIntent = contentIntent;

    // Post notification
    final NotificationManager mNotificationManager = (NotificationManager) getSystemService(
            Context.NOTIFICATION_SERVICE);
    mNotificationManager.notify(1, notification);
}

From source file:cm.aptoide.pt.DownloadQueueService.java

private void setFinishedNotification(int apkidHash, String localPath) {

    String apkid = notifications.get(apkidHash).get("apkid");
    int size = Integer.parseInt(notifications.get(apkidHash).get("intSize"));
    String version = notifications.get(apkidHash).get("version");

    RemoteViews contentView = new RemoteViews(getPackageName(), R.layout.download_notification);
    contentView.setImageViewResource(R.id.download_notification_icon, R.drawable.ic_notification);
    contentView.setTextViewText(R.id.download_notification_name,
            getString(R.string.finished_download_message) + " " + apkid + " v." + version);
    contentView.setProgressBar(R.id.download_notification_progress_bar, size * KBYTES_TO_BYTES,
            size * KBYTES_TO_BYTES, false);

    Intent onClick = new Intent("pt.caixamagica.aptoide.INSTALL_APK", Uri.parse("apk:" + apkid));
    onClick.setClassName("cm.aptoide.pt", "cm.aptoide.pt.RemoteInTab");
    onClick.setFlags(Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT | Intent.FLAG_ACTIVITY_NEW_TASK);
    onClick.putExtra("localPath", localPath);
    onClick.putExtra("apkid", apkid);
    onClick.putExtra("apkidHash", apkidHash);
    onClick.putExtra("isUpdate", Boolean.parseBoolean(notifications.get(apkid.hashCode()).get("isUpdate")));
    /*Changed by Rafael Campos*/
    onClick.putExtra("version", notifications.get(apkid.hashCode()).get("version"));
    Log.d("Aptoide-DownloadQueuService",
            "finished notification apkidHash: " + apkidHash + " localPath: " + localPath);

    // The PendingIntent to launch our activity if the user selects this notification
    PendingIntent onClickAction = PendingIntent.getActivity(context, 0, onClick, 0);

    Notification notification = new Notification(R.drawable.ic_notification,
            getString(R.string.finished_download_alrt) + " " + apkid, System.currentTimeMillis());
    notification.flags |= Notification.FLAG_AUTO_CANCEL;
    notification.contentView = contentView;

    // Set the info for the notification panel.
    notification.contentIntent = onClickAction;
    //       notification.setLatestEventInfo(this, getText(R.string.app_name), getText(R.string.add_repo_text), contentIntent);

    notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
    // Send the notification.
    // We use the position because it is a unique number.  We use it later to cancel.
    notificationManager.notify(apkidHash, notification);

    //      Log.d("Aptoide-DownloadQueueService", "Notification Set");

}

From source file:com.gdpi.app.UpdateManager.java

/**
 * ??/*from ww w  .  j  av a2 s .  c o  m*/
 */
@SuppressWarnings({ "deprecation", "unused" })
private void showNotify() {
    mNotificationManager = (NotificationManager) mContext.getSystemService(Context.NOTIFICATION_SERVICE);

    int icon = R.drawable.icon;
    CharSequence tickerText = "";
    long when = System.currentTimeMillis();
    nitify = new Notification(icon, tickerText, when);

    // "?"?
    nitify.flags = Notification.FLAG_ONGOING_EVENT;
    RemoteViews contentView = new RemoteViews(mContext.getPackageName(), R.layout.view_custom_progress);
    contentView.setTextViewText(R.id.tv_custom_progress_title, name);
    // 
    nitify.contentView = contentView;
    Intent intent = new Intent(mContext, MainFragment.class);
    PendingIntent contentIntent = PendingIntent.getActivity(mContext, 0, intent, 0);
    // ?
    nitify.contentIntent = contentIntent;
    mNotificationManager.notify(notifyId, nitify);
}