List of usage examples for android.widget RemoteViews RemoteViews
public RemoteViews(RemoteViews landscape, RemoteViews portrait)
From source file:me.sandrin.xkcdwidget.XKCDAppWidgetProvider.java
private void update(Context context) { AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(context); RemoteViews remoteViews = new RemoteViews(context.getPackageName(), R.layout.app_widget_layout); ComponentName watchWidget = new ComponentName(context, XKCDAppWidgetProvider.class); title = context.getResources().getString(R.string.error_title); image = null;/*from www .j a v a2 s . co m*/ altText = context.getResources().getString(R.string.error_text); updateComicInfo(); updateRemoteViews(context, remoteViews); appWidgetManager.updateAppWidget(watchWidget, remoteViews); }
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 ww.ja v a 2s. co 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: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.xengar.android.stocktracker.widget.ListWidgetProvider.java
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) { RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.widget_list); // Create an Intent to launch MainActivity Intent intent = new Intent(context, MainActivity.class); PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, intent, 0); views.setOnClickPendingIntent(R.id.widget, pendingIntent); // Set up the collection if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) { setRemoteAdapter(context, views); } else {/*w ww . j av a 2 s . co m*/ setRemoteAdapterV11(context, views); } boolean useDetailActivity = context.getResources().getBoolean(R.bool.use_detail_activity); Intent clickIntentTemplate = useDetailActivity ? new Intent(context, DetailActivity.class) : new Intent(context, MainActivity.class); PendingIntent clickPendingIntentTemplate = TaskStackBuilder.create(context) .addNextIntentWithParentStack(clickIntentTemplate) .getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT); views.setPendingIntentTemplate(R.id.widget_list, clickPendingIntentTemplate); views.setEmptyView(R.id.widget_list, R.id.widget_empty); // Tell the AppWidgetManager to perform an update on the current app widget appWidgetManager.updateAppWidget(appWidgetId, views); } }
From source file:org.dalol.orthodoxmezmurmedia.modules.player.PlayerNotificationDelegate.java
public void showNotification(MezmurPlayerService service, String text) { Intent playerIntent = new Intent(service, MezmursPlayerActivity.class); Intent dashboardIntent = new Intent(service, MezmurDashboardActivity.class); PendingIntent intent = TaskStackBuilder.create(service).addNextIntentWithParentStack(dashboardIntent) .addNextIntent(playerIntent).getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT); RemoteViews views = new RemoteViews(service.getPackageName(), R.layout.player_small_notification); views.setOnClickPendingIntent(R.id.player_pause, getPendingAction(service, "pause")); views.setOnClickPendingIntent(R.id.player_previous, getPendingAction(service, "previous")); views.setOnClickPendingIntent(R.id.player_next, getPendingAction(service, "next")); views.setOnClickPendingIntent(R.id.player_close, getPendingAction(service, "stop")); views.setTextViewText(R.id.player_song_name, text); views.setViewVisibility(R.id.player_progress_bar, View.GONE); mNotificationBuilder = new NotificationCompat.Builder(service).setSmallIcon(R.mipmap.ic_launcher) .setPriority(NotificationCompat.PRIORITY_MAX).setWhen(System.currentTimeMillis()) .setContentIntent(intent).setOngoing(true).setContent(views); service.startForeground(NOTIFICATION_ID, mNotificationBuilder.build()); }
From source file:com.ravi.apps.android.newsbytes.widget.NewsWidgetProvider.java
@Override public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) { Log.d(LOG_TAG, context.getString(R.string.log_on_update)); // Update each app widget instance with remote view and corresponding remote adapter. for (int appWidgetId : appWidgetIds) { // Create the remote views object for the widget instance. RemoteViews remoteView = new RemoteViews(context.getPackageName(), R.layout.widget_news); // Create the intent that starts the service which will provide the views for this collection. Intent serviceIntent = new Intent(context, NewsWidgetRemoteViewsService.class); // Add the app widget id to the intent extras. serviceIntent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId); serviceIntent.setData(Uri.parse(serviceIntent.toUri(Intent.URI_INTENT_SCHEME))); // Set the remote adapter onto the scores list view in the remote view. if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) { remoteView.setRemoteAdapter(R.id.widget_list_view, serviceIntent); } else {//from w w w . j av a2s .co m remoteView.setRemoteAdapter(appWidgetId, R.id.widget_list_view, serviceIntent); } // Create an intent to launch the main activity and set it on the remote view's title. Intent intent = new Intent(context, MainActivity.class); PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, intent, 0); remoteView.setOnClickPendingIntent(R.id.widget, pendingIntent); // Create and add the list item click pending intent template. Intent listItemClickIntent = new Intent(context, MainActivity.class); listItemClickIntent.setAction(context.getString(R.string.action_item_clicked)) .setData(Uri.parse(listItemClickIntent.toUri(Intent.URI_INTENT_SCHEME))); // Set the pending intent template. PendingIntent clickPendingIntentTemplate = TaskStackBuilder.create(context) .addNextIntentWithParentStack(listItemClickIntent) .getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT); remoteView.setPendingIntentTemplate(R.id.widget_list_view, clickPendingIntentTemplate); // Set an empty view in case of no data. remoteView.setEmptyView(R.id.widget_list_view, R.id.widget_empty); // Call app widget manager to update the app widget instance. appWidgetManager.updateAppWidget(appWidgetId, remoteView); } super.onUpdate(context, appWidgetManager, appWidgetIds); }
From source file:com.chainsaw.clearweather.OpenWeatherAPI.java
public OpenWeatherAPI(final Context context, final int widgetId) { final RemoteViews remote = new RemoteViews(context.getPackageName(), R.layout.widget_layout); final AppWidgetManager manager = AppWidgetManager.getInstance(context); asyncLoader = new BackgroundFetch(context) { @Override/*w w w . j a v a 2 s . c o m*/ protected void onPostExecute(WeatherData result) { remote.setViewVisibility(R.id.loading, View.INVISIBLE); if (OpenWeatherAPI.this.listener != null) OpenWeatherAPI.this.listener.onDataReady(result); } @Override protected void onProgressUpdate(Integer... values) { remote.setViewVisibility(R.id.temp, View.INVISIBLE); remote.setViewVisibility(R.id.tempUnit, View.INVISIBLE); remote.setViewVisibility(R.id.humidity, View.INVISIBLE); remote.setViewVisibility(R.id.humidityUnit, View.INVISIBLE); remote.setViewVisibility(R.id.location, View.INVISIBLE); remote.setViewVisibility(R.id.weather, View.INVISIBLE); remote.setViewVisibility(R.id.timestamp, View.INVISIBLE); remote.setViewVisibility(R.id.loading, View.VISIBLE); remote.setProgressBar(R.id.loading, 10, 5, true); manager.updateAppWidget(widgetId, remote); super.onProgressUpdate(values); } }; }
From source file:com.udacity.stockhawk.widget.StockAppWidgetProvider.java
@Override public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) { for (int appWidgetId : appWidgetIds) { RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.stock_app_widget); // Set up the collection views.setRemoteAdapter(R.id.lv_stock_list, new Intent(context, StockAppRemoteViewsService.class)); Intent clickIntentTemplate = new Intent(context, ChartActivity.class); PendingIntent clickPendingIntentTemplate = TaskStackBuilder.create(context) .addNextIntentWithParentStack(clickIntentTemplate) .getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT); views.setPendingIntentTemplate(R.id.lv_stock_list, clickPendingIntentTemplate); views.setEmptyView(R.id.lv_stock_list, R.id.tv_widget_empty); // Tell the AppWidgetManager to perform an update on the current app widget appWidgetManager.updateAppWidget(appWidgetId, views); }/* w w w .j a v a 2 s. com*/ }
From source file:st.brothas.mtgoxwidget.MtGoxWidgetProvider.java
static void updateAppWidget(final Context context, AppWidgetManager appWidgetManager, int appWidgetId) { WidgetPreferences preferences = MtGoxPreferencesActivity.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 v a 2 s . c o m*/ } RemoteViews 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()); MtGoxDataOpenHelper dbHelper = new MtGoxDataOpenHelper(context); MtGoxTickerData prevData = dbHelper.getLastTickerData(preferences); MtGoxTickerData newData; JSONObject latestQuoteJSON = getLatestQuoteJSON(preferences); if (latestQuoteJSON != null) { newData = preferences.getRateService().parseJSON(latestQuoteJSON); 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:com.ratusapparatus.tapsaff.TapsAff.java
@Override public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) { super.onUpdate(context, appWidgetManager, appWidgetIds); ComponentName thisWidget = new ComponentName(context, TapsAff.class); RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.widget_layout); views.setTextViewText(R.id.main, "ehh..."); appWidgetManager.updateAppWidget(thisWidget, views); RetreiveFeedTask task = new RetreiveFeedTask(); task.context = context;// w w w. j a v a 2 s . c om task.appWidgetManager = appWidgetManager; task.execute("http://www.taps-aff.co.uk/taps.json"); }