Example usage for android.widget RemoteViews RemoteViews

List of usage examples for android.widget RemoteViews RemoteViews

Introduction

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

Prototype

public RemoteViews(RemoteViews landscape, RemoteViews portrait) 

Source Link

Document

Create a new RemoteViews object that will inflate as the specified landspace or portrait RemoteViews, depending on the current configuration.

Usage

From source file:com.karma.konnect.PwoDiscoveryService.java

/**
 * Create the big view for the summary notification.
 *//*www  .ja  v a  2  s . c  o m*/
private RemoteViews updateSummaryNotificationRemoteViews(List<PwoMetadata> pwoMetadataList) {
    RemoteViews remoteViews = new RemoteViews(getPackageName(), R.layout.notification_big_view);

    // Fill in the data for the top two beacon views
    updateSummaryNotificationRemoteViewsFirstBeacon(pwoMetadataList.get(0), remoteViews);
    updateSummaryNotificationRemoteViewsSecondBeacon(pwoMetadataList.get(1), remoteViews);

    // Create a pending intent that will open the physical web app
    // TODO(cco3): Use a clickListener on the VIEW MORE button to do this
    PendingIntent pendingIntent = createReturnToAppPendingIntent();
    remoteViews.setOnClickPendingIntent(R.id.otherBeaconsLayout, pendingIntent);

    return remoteViews;
}

From source file:au.com.wallaceit.reddinator.SubredditSelectActivity.java

public void onBackPressed() {
    if (widgetFirstTimeSetup) {
        finishWidgetSetup();//from  w w  w  . j a  va2  s  .c o m
        return;
    }
    // check if sort has changed
    if (needsFeedUpdate || needsFeedViewUpdate || needsThemeUpdate) {
        if (mAppWidgetId != 0) {
            AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(SubredditSelectActivity.this);
            RemoteViews views = new RemoteViews(getPackageName(), R.layout.widget);
            views.setViewVisibility(R.id.srloader, View.VISIBLE);
            views.setViewVisibility(R.id.erroricon, View.INVISIBLE);
            // bypass the cached entrys only if the sorting preference has changed
            if (needsFeedUpdate) {
                global.setBypassCache(true);
            } else {
                global.setRefreshView();
            }
            if (needsThemeUpdate) {
                WidgetProvider.updateAppWidgets(SubredditSelectActivity.this, appWidgetManager,
                        new int[] { mAppWidgetId }, false);
            } else {
                appWidgetManager.partiallyUpdateAppWidget(mAppWidgetId, views);
            }
            appWidgetManager.notifyAppWidgetViewDataChanged(mAppWidgetId, R.id.listview);
        } else {
            Intent intent = new Intent();
            intent.putExtra("themeupdate", needsThemeUpdate);
            if (needsFeedUpdate) {
                setResult(2, intent); // reload feed and prefs
            } else {
                setResult(1, intent); // tells main activity to update feed prefs
            }
            if (needsThemeUpdate) {
                global.setRefreshView();
                AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(SubredditSelectActivity.this);
                int[] widgetIds = appWidgetManager
                        .getAppWidgetIds(new ComponentName(SubredditSelectActivity.this, WidgetProvider.class));
                WidgetProvider.updateAppWidgets(SubredditSelectActivity.this, appWidgetManager, widgetIds,
                        false);
                appWidgetManager.notifyAppWidgetViewDataChanged(widgetIds, R.id.listview);
            }
        }
    } else {
        setResult(0);
    }
    finish();
}

From source file:com.kasungunathilaka.sarigama.service.PlayerService.java

private void setupNotification(Song song, String notificationType) {
    Bitmap remote_picture = null;/* w  w  w.  j ava2  s.c o  m*/
    RemoteViews smallNotification;
    RemoteViews bigNotification;
    Notification notification;

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

    if (song != null) {
        if (song.getSongImage().contentEquals("http://sarigama.lk/img/songs/default.jpg")) {
            remote_picture = BitmapFactory.decodeResource(PlayerService.this.getResources(),
                    R.drawable.default_song_art);
        } else {
            try {
                remote_picture = BitmapFactory
                        .decodeStream((InputStream) new URL(song.getSongImage()).getContent());
            } catch (Exception e) {
                remote_picture = BitmapFactory.decodeResource(PlayerService.this.getResources(),
                        R.drawable.default_song_art);
                e.printStackTrace();
            }
        }
    }

    switch (notificationType) {
    case HomeActivity.NOTIFICATION_TYPE_PLAY:
        try {
            smallNotification = new RemoteViews(getPackageName(), R.layout.notification_layout_small);
            smallNotification.setImageViewBitmap(R.id.ivSmallNotificationSongImage, remote_picture);
            smallNotification.setTextViewText(R.id.tvSmallNotificationSong, song.getSongTitle());
            smallNotification.setTextViewText(R.id.tvSmallNotificationArtist, song.getSongArtist());
            smallNotification.setImageViewResource(R.id.ibSmallPlay, R.drawable.ic_pause_white);
            smallNotification.setOnClickPendingIntent(R.id.flSmallPlay, playIntent);
            smallNotification.setOnClickPendingIntent(R.id.ivSmallNext, nextIntent);

            bigNotification = new RemoteViews(getPackageName(), R.layout.notification_layout_big);
            bigNotification.setImageViewBitmap(R.id.ivBigNotificationSongImage, remote_picture);
            bigNotification.setTextViewText(R.id.tvBigNotificationSong, song.getSongTitle());
            bigNotification.setTextViewText(R.id.tvBigNotificationArtist, song.getSongArtist());
            bigNotification.setImageViewResource(R.id.ibBigPlay, R.drawable.ic_pause_white);
            bigNotification.setOnClickPendingIntent(R.id.ibBigNext, nextIntent);
            bigNotification.setOnClickPendingIntent(R.id.ibBigPlay, playIntent);
            bigNotification.setOnClickPendingIntent(R.id.ibBigPrevious, previousIntent);

            notification = new NotificationCompat.Builder(this).setSmallIcon(R.drawable.ic_play_white)
                    .setAutoCancel(false).setOngoing(true).setContent(smallNotification)
                    .setContentIntent(startIntent).build();

            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
                notification.bigContentView = bigNotification;
            }
            notificationManager.notify(NOTIFICATION_ID, notification);
        } catch (Exception e) {
            e.printStackTrace();
        }
        break;
    case HomeActivity.NOTIFICATION_TYPE_PAUSE:
        try {
            smallNotification = new RemoteViews(getPackageName(), R.layout.notification_layout_small);
            smallNotification.setImageViewResource(R.id.ibSmallPlay, R.drawable.ic_play_white);

            bigNotification = new RemoteViews(getPackageName(), R.layout.notification_layout_big);
            bigNotification.setImageViewBitmap(R.id.ivBigNotificationSongImage, remote_picture);
            bigNotification.setTextViewText(R.id.tvBigNotificationSong, song.getSongTitle());
            bigNotification.setTextViewText(R.id.tvBigNotificationArtist, song.getSongArtist());
            bigNotification.setImageViewResource(R.id.ibBigPlay, R.drawable.ic_play_white);
            bigNotification.setOnClickPendingIntent(R.id.ibBigNext, nextIntent);
            bigNotification.setOnClickPendingIntent(R.id.ibBigPlay, playIntent);
            bigNotification.setOnClickPendingIntent(R.id.ibBigPrevious, previousIntent);

            notification = new NotificationCompat.Builder(this).setSmallIcon(R.drawable.ic_pause_white)
                    .setOngoing(false).setAutoCancel(false).setContent(smallNotification)
                    .setContentIntent(startIntent).build();

            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
                notification.bigContentView = bigNotification;
            }
            notificationManager.notify(NOTIFICATION_ID, notification);
        } catch (Exception e) {
            e.printStackTrace();
        }
        break;
    case HomeActivity.NOTIFICATION_TYPE_DISMISS:
        notificationManager.cancel(NOTIFICATION_ID);
        break;
    }
}

From source file:com.piusvelte.taplock.client.core.TapLockService.java

private void buildWidget(int appWidgetId) {
    RemoteViews rv = new RemoteViews(getPackageName(), R.layout.widget);
    String deviceName = null;//from  w w w.  java 2 s  .co m
    for (JSONObject deviceJObj : mDevices) {
        if (deviceJObj.has(KEY_WIDGETS) && deviceJObj.has(KEY_NAME)) {
            JSONArray widgetsJArr = null;
            try {
                widgetsJArr = deviceJObj.getJSONArray(KEY_WIDGETS);
            } catch (JSONException e) {
                e.printStackTrace();
            }
            if (widgetsJArr != null) {
                for (int i = 0, l = widgetsJArr.length(); (i < l) && (deviceName == null); i++) {
                    int widgetId;
                    try {
                        widgetId = widgetsJArr.getInt(i);
                    } catch (JSONException e) {
                        widgetId = AppWidgetManager.INVALID_APPWIDGET_ID;
                        e.printStackTrace();
                    }
                    if ((widgetId != AppWidgetManager.INVALID_APPWIDGET_ID) && (appWidgetId == widgetId)) {
                        try {
                            deviceName = deviceJObj.getString(KEY_NAME);
                        } catch (JSONException e) {
                            e.printStackTrace();
                        }
                        break;
                    }
                }
            }
            if (deviceName != null)
                break;
        }
    }
    if (deviceName == null)
        deviceName = "unknown";
    rv.setTextViewText(R.id.device_name, deviceName);
    rv.setOnClickPendingIntent(R.id.widget_icon,
            PendingIntent.getActivity(this, 0,
                    TapLock.getPackageIntent(this, TapLockToggle.class)
                            .setData(Uri.parse(String.format(getString(R.string.device_uri), deviceName))),
                    Intent.FLAG_ACTIVITY_NEW_TASK));
    AppWidgetManager.getInstance(this).updateAppWidget(appWidgetId, rv);
}

From source file:com.android.launcher3.widget.DigitalAppWidgetProvider.java

private void refreshCityOrWeather(Context context, String what, int which) {
    AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(context);
    if (appWidgetManager != null) {
        int[] appWidgetIds = appWidgetManager.getAppWidgetIds(getComponentName(context));
        for (int appWidgetId : appWidgetIds) {
            RemoteViews widget = new RemoteViews(context.getPackageName(), R.layout.digital_appwidget);
            if (1 == which) {
                widget.setTextViewText(R.id.city, what);
            } else if (2 == which) {
                if (what.equals("")) {
                    //widget.setTextViewText(R.id.temperature, context.getString(R.string.weather_network_error));
                } else if (what.contains(",")) {
                    String weather = what.split(",")[0];
                    String temperature = what.split(",")[1];
                    String image = what.split(",")[2];
                    widget.setTextViewText(R.id.temperature, temperature);
                    widget.setImageViewResource(R.id.weather, getWeatherImageId(image));
                }/*from   ww w .ja v a  2s. co m*/
            }
            appWidgetManager.partiallyUpdateAppWidget(appWidgetId, widget);
        }
    }
}

From source file:com.darshancomputing.BatteryIndicatorPro.BatteryInfoService.java

private void updateWidgets(BatteryInfo info) {
    //Intent mainWindowIntent = new Intent(this, BatteryInfoActivity.class);
    //PendingIntent mainWindowPendingIntent = PendingIntent.getActivity(this, RC_MAIN, mainWindowIntent, 0);
    //PendingIntent currentInfoPendingIntent = PendingIntent.getActivity(this, RC_MAIN, currentInfoIntent, 0);

    if (info == null) {
        cwbg.setLevel(0);//from   w  w w .  j  av a  2  s.com
    } else {
        bl.setLevel(info.percent);
        cwbg.setLevel(info.percent);
    }

    for (Integer widgetId : widgetIds) {
        RemoteViews rv;

        android.appwidget.AppWidgetProviderInfo awpInfo = widgetManager.getAppWidgetInfo(widgetId);
        if (awpInfo == null)
            continue; // Based on Developer Console crash reports, this can be null sometimes

        int initLayout = awpInfo.initialLayout;

        if (initLayout == R.layout.circle_app_widget) {
            rv = new RemoteViews(getPackageName(), R.layout.circle_app_widget);
            rv.setImageViewBitmap(R.id.circle_widget_image_view, cwbg.getBitmap());
        } else {
            rv = new RemoteViews(getPackageName(), R.layout.full_app_widget);

            if (info == null) {
                rv.setImageViewBitmap(R.id.battery_level_view, cwbg.getBitmap());
                rv.setTextViewText(R.id.fully_charged, "");
                rv.setTextViewText(R.id.time_remaining, "");
                rv.setTextViewText(R.id.until_what, "");
            } else {
                rv.setImageViewBitmap(R.id.battery_level_view, bl.getBitmap());

                if (info.prediction.what == BatteryInfo.Prediction.NONE) {
                    rv.setTextViewText(R.id.fully_charged, str.timeRemaining(info));
                    rv.setTextViewText(R.id.time_remaining, "");
                    rv.setTextViewText(R.id.until_what, "");
                } else {
                    rv.setTextViewText(R.id.fully_charged, "");
                    rv.setTextViewText(R.id.time_remaining, str.timeRemaining(info));
                    rv.setTextViewText(R.id.until_what, str.untilWhat(info));
                }
            }
        }

        if (info == null)
            rv.setTextViewText(R.id.level, "XX" + str.percent_symbol);
        else
            rv.setTextViewText(R.id.level, "" + info.percent + str.percent_symbol);

        rv.setOnClickPendingIntent(R.id.widget_layout, currentInfoPendingIntent);
        widgetManager.updateAppWidget(widgetId, rv);
    }
}

From source file:org.physical_web.physicalweb.UriBeaconDiscoveryService.java

/**
 * Create the big view for the summary notification
 *///from   w  w  w. j  av a  2 s  . c  o  m
private RemoteViews updateSummaryNotificationRemoteViews() {
    RemoteViews remoteViews = new RemoteViews(getPackageName(), R.layout.notification_big_view);

    // Fill in the data for the top two beacon views
    updateSummaryNotificationRemoteViewsFirstBeacon(mDeviceAddressToUrl.get(mSortedDevices.get(0)),
            remoteViews);
    updateSummaryNotificationRemoteViewsSecondBeacon(mDeviceAddressToUrl.get(mSortedDevices.get(1)),
            remoteViews);

    // Create a pending intent that will open the physical web app
    // TODO: Use a clickListener on the VIEW MORE button to do this
    PendingIntent pendingIntent = createReturnToAppPendingIntent();
    remoteViews.setOnClickPendingIntent(R.id.otherBeaconsLayout, pendingIntent);

    return remoteViews;
}

From source file:org.physical_web.physicalweb.UrlDeviceDiscoveryService.java

/**
 * Create the big view for the summary notification.
 *//*from www.  j ava  2  s.  c  o  m*/
private RemoteViews updateSummaryNotificationRemoteViews(List<PwPair> pwPairs) {
    RemoteViews remoteViews = new RemoteViews(getPackageName(), R.layout.notification_big_view);

    // Fill in the data for the top two beacon views
    updateSummaryNotificationRemoteViewsFirstBeacon(pwPairs.get(0), remoteViews);
    updateSummaryNotificationRemoteViewsSecondBeacon(pwPairs.get(1), remoteViews);

    // Create a pending intent that will open the physical web app
    // TODO(cco3): Use a clickListener on the VIEW MORE button to do this
    PendingIntent pendingIntent = createReturnToAppPendingIntent();
    remoteViews.setOnClickPendingIntent(R.id.otherBeaconsLayout, pendingIntent);

    return remoteViews;
}

From source file:com.androidinspain.deskclock.data.TimerNotificationBuilder.java

@TargetApi(Build.VERSION_CODES.N)
private RemoteViews buildChronometer(String pname, long base, boolean running, CharSequence stateText) {
    final RemoteViews content = new RemoteViews(pname,
            com.androidinspain.deskclock.R.layout.chronometer_notif_content);
    content.setChronometerCountDown(com.androidinspain.deskclock.R.id.chronometer, true);
    content.setChronometer(com.androidinspain.deskclock.R.id.chronometer, base, null, running);
    content.setTextViewText(com.androidinspain.deskclock.R.id.state, stateText);
    return content;
}

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);/*  www .j  a v a 2  s  . c  o m*/

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