List of usage examples for android.widget RemoteViews RemoteViews
public RemoteViews(RemoteViews landscape, RemoteViews portrait)
From source file:com.android.launcher3.widget.DigitalAppWidgetProvider.java
private void updateClock(Context context, AppWidgetManager appWidgetManager, int appWidgetId, float ratio) { RemoteViews widget = new RemoteViews(context.getPackageName(), R.layout.digital_appwidget); // Launch setinngs when clicking on the time in the widget only if not a lock screen widget Bundle newOptions = appWidgetManager.getAppWidgetOptions(appWidgetId); if (newOptions != null && newOptions.getInt(AppWidgetManager.OPTION_APPWIDGET_HOST_CATEGORY, -1) != AppWidgetProviderInfo.WIDGET_CATEGORY_KEYGUARD) { Intent mIntent = new Intent(Intent.ACTION_MAIN); mIntent.addCategory(Intent.CATEGORY_LAUNCHER); ComponentName component = new ComponentName("com.android.settings", "com.android.settings.Settings"); mIntent.setComponent(component); widget.setOnClickPendingIntent(R.id.digital_appwidget, PendingIntent.getActivity(context, 0, mIntent, 0)); }/*www .j av a 2s .c o m*/ //cg sai.pan begin refreshWifiStatus(context, widget); refreshBtStatus(context, widget); refreshAirplaneStatus(context, widget, Settings.Global.getInt(context.getContentResolver(), Settings.Global.AIRPLANE_MODE_ON, 0) != 0); mLocationManager = (LocationManager) context.getSystemService(context.LOCATION_SERVICE); refreshGpsStatus(context, widget, mLocationManager.isProviderEnabled(LocationManager.GPS_PROVIDER)); //refreshDataStatus(context, widget, Settings.Global.getInt(context.getContentResolver(), Settings.Global.MOBILE_DATA, 0) != 0); requestLocation(context); //cg sai.pan end // SPRD for bug421127 add am/pm for widget WidgetUtils.setTimeFormat(widget, (int) context.getResources().getDimension(R.dimen.widget_label_font_size), R.id.the_clock); WidgetUtils.setClockSize(context, widget, ratio); // Set today's date format CharSequence dateFormat = DateFormat.getBestDateTimePattern(Locale.getDefault(), context.getString(R.string.abbrev_wday_month_day_no_year)); widget.setCharSequence(R.id.date, "setFormat12Hour", dateFormat); widget.setCharSequence(R.id.date, "setFormat24Hour", dateFormat); appWidgetManager.updateAppWidget(appWidgetId, widget); }
From source file:com.freeme.filemanager.FileExplorerTabActivity.java
public void showButtonNotify() { mBuilder = new Builder(this); RemoteViews remoteViews = new RemoteViews(getPackageName(), R.layout.view_custom_button); if (IsFreemeOs.isFreemeOs()) { Bitmap bitMap = getApplicationContext().getPackageManager().getIconBitmapWithThemeBg( getResources().getDrawable(R.drawable.notification_clean), getApplicationContext().getPackageName(), 0); remoteViews.setImageViewBitmap(R.id.filemanager_notification_clean, bitMap); } else {//from www . j av a2 s. c o m remoteViews.setImageViewResource(R.id.filemanager_notification_clean, R.drawable.notification_clean); } remoteViews.setTextViewText(R.id.tv_custom_title, getString(R.string.fileManager)); remoteViews.setTextViewText(R.id.tv_custom_text, getString(R.string.clean_text)); Intent buttonIntent = new Intent(ACTION_BUTTON); buttonIntent.putExtra(INTENT_BUTTONID_TAG, BUTTON_CLEAN_ID); PendingIntent intent_clean = PendingIntent.getBroadcast(this, 1, buttonIntent, PendingIntent.FLAG_UPDATE_CURRENT); remoteViews.setOnClickPendingIntent(R.id.btn_custom, intent_clean); mBuilder.setContent(remoteViews).setContentIntent(getDefalutIntent(Notification.FLAG_AUTO_CANCEL)) .setWhen(System.currentTimeMillis()).setPriority(Notification.PRIORITY_DEFAULT).setOngoing(true) .setSmallIcon(R.drawable.notification_small_clean); notify = mBuilder.build(); notify.flags = Notification.FLAG_AUTO_CANCEL; mNotificationManager.notify(200, notify); }
From source file:com.google.sample.castcompanionlibrary.notification.VideoCastNotificationService.java
private RemoteViews build(MediaInfo info, Bitmap bitmap, boolean isPlaying) throws CastException, TransientNetworkDisconnectionException, NoConnectionException { if (mIsLollipopOrAbove) { buildForLollipopAndAbove(info, bitmap, isPlaying); return null; }//from w w w . j a v a 2 s. c o m Bundle mediaWrapper = Utils.fromMediaInfo(mCastManager.getRemoteMediaInformation()); Intent contentIntent = new Intent(this, mTargetActivity); contentIntent.putExtra("media", mediaWrapper); TaskStackBuilder stackBuilder = TaskStackBuilder.create(this); stackBuilder.addParentStack(mTargetActivity); stackBuilder.addNextIntent(contentIntent); if (stackBuilder.getIntentCount() > 1) { stackBuilder.editIntentAt(1).putExtra("media", mediaWrapper); } // Gets a PendingIntent containing the entire back stack PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(NOTIFICATION_ID, PendingIntent.FLAG_UPDATE_CURRENT); MediaMetadata mm = info.getMetadata(); RemoteViews rv = new RemoteViews(getPackageName(), R.layout.custom_notification); if (mIsIcsOrAbove) { addPendingIntents(rv, isPlaying, info); } if (null != bitmap) { rv.setImageViewBitmap(R.id.iconView, bitmap); } else { bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.dummy_album_art); rv.setImageViewBitmap(R.id.iconView, bitmap); } rv.setTextViewText(R.id.titleView, mm.getString(MediaMetadata.KEY_TITLE)); String castingTo = getResources().getString(R.string.casting_to_device, mCastManager.getDeviceName()); rv.setTextViewText(R.id.subTitleView, castingTo); mNotification = new NotificationCompat.Builder(this).setSmallIcon(R.drawable.ic_stat_action_notification) .setContentIntent(resultPendingIntent).setContent(rv).setAutoCancel(false).setOngoing(true).build(); // to get around a bug in GB version, we add the following line // see https://code.google.com/p/android/issues/detail?id=30495 mNotification.contentView = rv; return rv; }
From source file:name.gumartinm.weather.information.widget.WidgetIntentService.java
private RemoteViews makeErrorView(final int appWidgetId) { final RemoteViews remoteView = new RemoteViews(this.getApplicationContext().getPackageName(), R.layout.appwidget_error);/*from w ww. ja va2 s . c om*/ // 6. Activity launcher. final Intent resultIntent = new Intent(this.getApplicationContext(), WidgetConfigure.class); resultIntent.putExtra("actionFromUser", true); resultIntent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId); // From: http://stackoverflow.com/questions/4011178/multiple-instances-of-widget-only-updating-last-widget final Uri data = Uri.withAppendedPath(Uri.parse("PAIN" + "://widget/id/"), String.valueOf(appWidgetId)); resultIntent.setData(data); final TaskStackBuilder stackBuilder = TaskStackBuilder.create(this.getApplicationContext()); // Adds the back stack for the Intent (but not the Intent itself) stackBuilder.addParentStack(WidgetConfigure.class); // Adds the Intent that starts the Activity to the top of the stack stackBuilder.addNextIntent(resultIntent); final PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT); remoteView.setOnClickPendingIntent(R.id.weather_appwidget_error, resultPendingIntent); return remoteView; }
From source file:leoisasmendi.android.com.suricatepodcast.services.MediaPlayerService.java
private void updateWidgets(PlaybackStatus playbackStatus) { final RemoteViews view = new RemoteViews(getPackageName(), R.layout.podcast_widget_player); if (playbackStatus == PlaybackStatus.PLAYING) { view.setImageViewResource(R.id.widget_play, R.drawable.media_player_pause_24x24); } else if (playbackStatus == PlaybackStatus.PAUSED) { view.setImageViewResource(R.id.widget_play, R.drawable.media_player_play_24x24); }/*w ww . ja v a2 s.c o m*/ view.setTextViewText(R.id.widget_title, activeAudio.getTitle()); view.setTextViewText(R.id.widget_length, activeAudio.getDuration()); Picasso.with(getBaseContext()).setLoggingEnabled(true); Target target = new Target() { @Override public void onBitmapLoaded(Bitmap bitmap, Picasso.LoadedFrom from) { view.setImageViewBitmap(R.id.widget_thumbail, bitmap); } @Override public void onBitmapFailed(Drawable errorDrawable) { view.setImageViewResource(R.id.widget_thumbail, R.drawable.picture); } @Override public void onPrepareLoad(Drawable placeHolderDrawable) { view.setImageViewResource(R.id.widget_thumbail, R.drawable.picture); } }; Picasso.with(getBaseContext()).load(activeAudio.getPoster()).into(target); // Push update for this widget to the home screen ComponentName thisWidget = new ComponentName(this, PodcastWidgetProvider.class); AppWidgetManager manager = AppWidgetManager.getInstance(this); manager.updateAppWidget(thisWidget, view); }
From source file:au.com.wallaceit.reddinator.Rservice.java
@Override public RemoteViews getLoadingView() { RemoteViews rowload = new RemoteViews(mContext.getPackageName(), R.layout.listrowload); if (themeColors == null) { getThemeColors(); // prevents null pointer }// www . ja va2 s .c o m rowload.setTextColor(R.id.listloadtxt, themeColors[0]); return rowload; }
From source file:com.fanfou.app.opensource.service.DownloadService.java
private void showProgress() { this.notification = new Notification(R.drawable.ic_notify_download, "?", System.currentTimeMillis()); this.notification.flags |= Notification.FLAG_ONGOING_EVENT; this.notification.flags |= Notification.FLAG_AUTO_CANCEL; this.notification.contentIntent = PendingIntent.getActivity(this, 0, new Intent(), 0); final RemoteViews view = new RemoteViews(getPackageName(), R.layout.download_notification); view.setTextViewText(R.id.download_notification_text, "? 0%"); view.setProgressBar(R.id.download_notification_progress, 100, 0, false); this.notification.contentView = view; this.nm.notify(DownloadService.NOTIFICATION_PROGRESS_ID, this.notification); }
From source file:com.cognizant.glass.bluetoothconnect.DemoAppRecieverService.java
/** * method handles the Live card notifications * //from www . ja va 2 s .com * @param context * @param jsonArray * * whenever the user is in background and new message is received * a live card is created and if already present the values are * updated with the current message contents. */ private void publishCard(final Context context, final JSONArray jsonArray) { if (mLiveCard == null) { mLiveCard = new LiveCard(this, LIVE_CARD_TAG); } livecardView = new RemoteViews(context.getPackageName(), R.layout.activity_second); try { if (jsonArray.length() > 1) { String imageName1 = jsonArray.getJSONObject(0).getString(Constants.TAG_CASETITLE).toLowerCase(); imageName1 = imageName1.replace(" ", "_"); String imageName2 = jsonArray.getJSONObject(1).getString(Constants.TAG_CASETITLE).toLowerCase(); imageName2 = imageName2.replace(" ", "_"); livecardView.setTextViewText(R.id.text, jsonArray.getJSONObject(0).getString(Constants.TAG_CASETITLE)); livecardView.setTextViewText(R.id.livecard_ticketNo, jsonArray.getJSONObject(0).getString(Constants.TAG_TICKETCOUNT) + " ticket(s)"); livecardView.setTextViewText(R.id.text2, jsonArray.getJSONObject(1).getString(Constants.TAG_CASETITLE)); livecardView.setTextViewText(R.id.livecard_ticketNo2, jsonArray.getJSONObject(1).getString(Constants.TAG_TICKETCOUNT) + " ticket(s)"); try { String fnm = imageName1; // this is image // file name final String image2 = imageName2; String packageName = getApplicationContext().getPackageName(); final int imgId = getResources().getIdentifier(packageName + ":drawable/" + fnm, null, null); final int imgId2 = getResources().getIdentifier(packageName + ":drawable/" + image2, null, null); livecardView.setImageViewBitmap(R.id.image1_livecard, BitmapFactory.decodeResource(getResources(), imgId)); livecardView.setImageViewBitmap(R.id.image2_livecard, BitmapFactory.decodeResource(getResources(), imgId2)); } catch (Exception e) { e.printStackTrace(); } mLiveCard.setViews(livecardView); } else { livecardView.setTextViewText(R.id.text, jsonArray.getJSONObject(0).getString(Constants.TAG_CASETITLE)); livecardView.setTextViewText(R.id.livecard_ticketNo, jsonArray.getJSONObject(0).getString(Constants.TAG_TICKETCOUNT) + " ticket(s)"); livecardView.setTextViewText(R.id.text2, ""); livecardView.setTextViewText(R.id.livecard_ticketNo2, ""); mLiveCard.setViews(livecardView); } } catch (JSONException e) { // TODO Auto-generated catch block e.printStackTrace(); } // pending intent so that when user clicks the live card the // corresponding application is opened. Intent intent = new Intent(context, MainLauncherActivity.class); mLiveCard.setAction(PendingIntent.getActivity(context, 0, intent, 0)); if (!mLiveCard.isPublished()) { mLiveCard.publish(LiveCard.PublishMode.SILENT); } else { mLiveCard.setViews(livecardView); } }
From source file:org.messic.android.smartphone.notifications.MessicPlayerNotification.java
/** * Method to construct the notification cover * * @param playSong/* ww w . j ava 2 s .co m*/ */ private void constructNotificationCover(final MDMSong playSong) { createNotification(); if (currentNotificationCover == null) { Bitmap cover = acc.getCover(playSong.getAlbum(), new AlbumCoverCache.CoverListener() { public void setCover(Bitmap bitmap) { // we need to recreate the remote view due to memory buffer problems // with remote views and the image // we send RemoteViews bigContentView = new RemoteViews(service.getPackageName(), R.layout.notification_big); RemoteViews smallContentView = new RemoteViews(service.getPackageName(), R.layout.notification_small); notification.bigContentView = bigContentView; notification.contentView = smallContentView; notification.bigContentView.setTextViewText(R.id.bignotification_tvcurrent_author, playSong.getAlbum().getAuthor().getName()); notification.bigContentView.setTextViewText(R.id.bignotification_tvcurrent_song, playSong.getName()); notification.contentView.setTextViewText(R.id.bignotification_tvcurrent_author, playSong.getAlbum().getAuthor().getName()); notification.contentView.setTextViewText(R.id.bignotification_tvcurrent_song, playSong.getName()); Bitmap cover = UtilImage.resizeToNotificationImageSize(service.getApplicationContext(), bitmap, R.dimen.bignotification_cover_width, R.dimen.bignotification_cover_height); notification.bigContentView.setImageViewBitmap(R.id.bignotification_ivcurrent_cover, cover); notification.contentView.setImageViewBitmap(R.id.bignotification_ivcurrent_cover, cover); currentNotificationCover = cover; mNotificationManager.notify(ONGOING_NOTIFICATION_ID, notification); } public void failed(Exception e) { // TODO Auto-generated method stub } }); if (cover != null) { // we need to recreate the remote view due to memory buffer problems with remote views and the image we // send RemoteViews bigContentView = new RemoteViews(this.service.getPackageName(), R.layout.notification_big); RemoteViews smallContentView = new RemoteViews(this.service.getPackageName(), R.layout.notification_small); notification.bigContentView = bigContentView; notification.contentView = smallContentView; this.notification.bigContentView.setTextViewText(R.id.bignotification_tvcurrent_author, playSong.getAlbum().getAuthor().getName()); this.notification.bigContentView.setTextViewText(R.id.bignotification_tvcurrent_song, playSong.getName()); this.notification.contentView.setTextViewText(R.id.bignotification_tvcurrent_author, playSong.getAlbum().getAuthor().getName()); this.notification.contentView.setTextViewText(R.id.bignotification_tvcurrent_song, playSong.getName()); cover = UtilImage.resizeToNotificationImageSize(this.service.getApplicationContext(), cover, R.dimen.bignotification_cover_width, R.dimen.bignotification_cover_height); notification.bigContentView.setImageViewBitmap(R.id.bignotification_ivcurrent_cover, cover); notification.contentView.setImageViewBitmap(R.id.bignotification_ivcurrent_cover, cover); this.currentNotificationCover = cover; } else { notification.bigContentView.setImageViewResource(R.id.bignotification_ivcurrent_cover, R.mipmap.ic_launcher); notification.contentView.setImageViewResource(R.id.bignotification_ivcurrent_cover, R.mipmap.ic_launcher); } } }
From source file:com.fanfou.app.opensource.service.DownloadService.java
private void updateProgress(final int progress) { final RemoteViews view = new RemoteViews(getPackageName(), R.layout.download_notification); view.setTextViewText(R.id.download_notification_text, "? " + progress + "%"); view.setInt(R.id.download_notification_progress, "setProgress", progress); this.notification.contentView = view; this.nm.notify(DownloadService.NOTIFICATION_PROGRESS_ID, this.notification); }