List of usage examples for android.widget RemoteViews RemoteViews
public RemoteViews(RemoteViews landscape, RemoteViews portrait)
From source file:org.gaeproxy.GAEProxyService.java
/** Called when the activity is closed. */ @Override/*from ww w . jav a2 s . c o m*/ public void onDestroy() { EasyTracker.getTracker().trackEvent("service", "stop", getVersionName(), 0L); if (mShutdownReceiver != null) { unregisterReceiver(mShutdownReceiver); mShutdownReceiver = null; } statusLock = true; stopForegroundCompat(1); notifyAlert(getString(R.string.forward_stop), getString(R.string.service_stopped), Notification.FLAG_AUTO_CANCEL); try { if (dnsServer != null) dnsServer.close(); } catch (Exception e) { Log.e(TAG, "DNS Server close unexpected"); } new Thread() { @Override public void run() { // Make sure the connection is closed, important here onDisconnect(); } }.start(); // for widget, maybe exception here try { RemoteViews views = new RemoteViews(getPackageName(), R.layout.gaeproxy_appwidget); views.setImageViewResource(R.id.serviceToggle, R.drawable.off); AppWidgetManager awm = AppWidgetManager.getInstance(this); awm.updateAppWidget(awm.getAppWidgetIds(new ComponentName(this, GAEProxyWidgetProvider.class)), views); } catch (Exception ignore) { // Nothing } Editor ed = settings.edit(); ed.putBoolean("isRunning", false); ed.putBoolean("isConnecting", false); ed.commit(); try { notificationManager.cancel(0); } catch (Exception ignore) { // Nothing } try { ProxySettings.resetProxy(this); } catch (Exception ignore) { // Nothing } super.onDestroy(); statusLock = false; markServiceStopped(); }
From source file:org.videolan.vlc.MediaService.java
@TargetApi(Build.VERSION_CODES.JELLY_BEAN) private void showNotification() { try {//from w w w . j a v a 2 s. c o m Bitmap cover = AudioUtil.getCover(this, mCurrentMedia, 64); String title = mCurrentMedia.getTitle(); String artist = mCurrentMedia.getArtist(); String album = mCurrentMedia.getAlbum(); Notification notification; // add notification to status bar NotificationCompat.Builder builder = new NotificationCompat.Builder(this) .setSmallIcon(R.drawable.ic_stat_vlc).setTicker(title + " - " + artist).setAutoCancel(false) .setOngoing(true); Intent notificationIntent = new Intent(this, mIsVout ? MediaPlayerActivity.class : AudioPlayerActivity.class); notificationIntent.setAction(Intent.ACTION_MAIN); notificationIntent.addCategory(Intent.CATEGORY_LAUNCHER); notificationIntent.putExtra(START_FROM_NOTIFICATION, true); PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT); if (Util.isJellyBeanOrLater()) { Intent iBackward = new Intent(ACTION_REMOTE_BACKWARD); Intent iPlay = new Intent(ACTION_REMOTE_PLAYPAUSE); Intent iForward = new Intent(ACTION_REMOTE_FORWARD); Intent iStop = new Intent(ACTION_REMOTE_STOP); PendingIntent piBackward = PendingIntent.getBroadcast(this, 0, iBackward, PendingIntent.FLAG_UPDATE_CURRENT); PendingIntent piPlay = PendingIntent.getBroadcast(this, 0, iPlay, PendingIntent.FLAG_UPDATE_CURRENT); PendingIntent piForward = PendingIntent.getBroadcast(this, 0, iForward, PendingIntent.FLAG_UPDATE_CURRENT); PendingIntent piStop = PendingIntent.getBroadcast(this, 0, iStop, PendingIntent.FLAG_UPDATE_CURRENT); RemoteViews view = new RemoteViews(getPackageName(), R.layout.notification); if (cover != null) view.setImageViewBitmap(R.id.cover, cover); view.setTextViewText(R.id.songName, title); view.setTextViewText(R.id.artist, artist); view.setImageViewResource(R.id.play_pause, mLibVLC.isPlaying() ? R.drawable.ic_pause : R.drawable.ic_play); view.setOnClickPendingIntent(R.id.play_pause, piPlay); view.setOnClickPendingIntent(R.id.forward, piForward); view.setOnClickPendingIntent(R.id.stop, piStop); view.setOnClickPendingIntent(R.id.content, pendingIntent); RemoteViews view_expanded = new RemoteViews(getPackageName(), R.layout.notification_expanded); if (cover != null) view_expanded.setImageViewBitmap(R.id.cover, cover); view_expanded.setTextViewText(R.id.songName, title); view_expanded.setTextViewText(R.id.artist, artist); view_expanded.setTextViewText(R.id.album, album); view_expanded.setImageViewResource(R.id.play_pause, mLibVLC.isPlaying() ? R.drawable.ic_pause : R.drawable.ic_play); view_expanded.setOnClickPendingIntent(R.id.backward, piBackward); view_expanded.setOnClickPendingIntent(R.id.play_pause, piPlay); view_expanded.setOnClickPendingIntent(R.id.forward, piForward); view_expanded.setOnClickPendingIntent(R.id.stop, piStop); view_expanded.setOnClickPendingIntent(R.id.content, pendingIntent); notification = builder.build(); notification.contentView = view; notification.bigContentView = view_expanded; } else { builder.setLargeIcon(cover).setContentTitle(title) .setContentText(Util.isJellyBeanOrLater() ? artist : mCurrentMedia.getSubtitle()) .setContentInfo(album).setContentIntent(pendingIntent); notification = builder.build(); } startForeground(3, notification); } catch (NoSuchMethodError e) { // Compat library is wrong on 3.2 // http://code.google.com/p/android/issues/detail?id=36359 // http://code.google.com/p/android/issues/detail?id=36502 } }
From source file:github.daneren2005.dsub.util.Util.java
public static void showPlayingNotification(final Context context, final DownloadServiceImpl downloadService, Handler handler, MusicDirectory.Entry song) { // Set the icon, scrolling text and timestamp final Notification notification = new Notification(R.drawable.stat_notify_playing, song.getTitle(), System.currentTimeMillis()); notification.flags |= Notification.FLAG_NO_CLEAR | Notification.FLAG_ONGOING_EVENT; boolean playing = downloadService.getPlayerState() == PlayerState.STARTED; if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { RemoteViews expandedContentView = new RemoteViews(context.getPackageName(), R.layout.notification_expanded); setupViews(expandedContentView, context, song, playing); notification.bigContentView = expandedContentView; }// www. j av a 2 s.co m RemoteViews smallContentView = new RemoteViews(context.getPackageName(), R.layout.notification); setupViews(smallContentView, context, song, playing); notification.contentView = smallContentView; Intent notificationIntent = new Intent(context, DownloadActivity.class); notification.contentIntent = PendingIntent.getActivity(context, 0, notificationIntent, 0); handler.post(new Runnable() { @Override public void run() { downloadService.startForeground(Constants.NOTIFICATION_ID_PLAYING, notification); } }); // Update widget DSubWidgetProvider.getInstance().notifyChange(context, downloadService, true); }
From source file:uk.org.ngo.squeezer.service.SqueezeService.java
/** * Manages the state of any ongoing notification based on the player and connection state. *///from w w w . j av a2 s . co m private void updateOngoingNotification() { Player activePlayer = this.mActivePlayer.get(); PlayerState activePlayerState = getActivePlayerState(); // Update scrobble state, if either we're currently scrobbling, or we // were (to catch the case where we started scrobbling a song, and the // user went in to settings to disable scrobbling). if (scrobblingEnabled || scrobblingPreviouslyEnabled) { scrobblingPreviouslyEnabled = scrobblingEnabled; Scrobble.scrobbleFromPlayerState(this, activePlayerState); } // If there's no active player then kill the notification and get out. // TODO: Have a "There are no connected players" notification text. if (activePlayer == null || activePlayerState == null) { clearOngoingNotification(); return; } boolean playing = activePlayerState.isPlaying(); // If the song is not playing and the user wants notifications only when playing then // kill the notification and get out. if (!playing && !mShowNotificationWhenNotPlaying) { clearOngoingNotification(); return; } // If there's no current song then kill the notification and get out. // TODO: Have a "There's nothing playing" notification text. final Song currentSong = activePlayerState.getCurrentSong(); if (currentSong == null) { clearOngoingNotification(); return; } // Compare the current state with the state when the notification was last updated. // If there are no changes (same song, same playing state) then there's nothing to do. String songName = currentSong.getName(); String albumName = currentSong.getAlbumName(); String artistName = currentSong.getArtist(); Uri url = currentSong.getArtworkUrl(); String playerName = activePlayer.getName(); if (mNotifiedPlayerState == null) { mNotifiedPlayerState = new PlayerState(); } else { boolean lastPlaying = mNotifiedPlayerState.isPlaying(); Song lastNotifiedSong = mNotifiedPlayerState.getCurrentSong(); // No change in state if (playing == lastPlaying && currentSong.equals(lastNotifiedSong)) { return; } } mNotifiedPlayerState.setCurrentSong(currentSong); mNotifiedPlayerState.setPlayStatus(activePlayerState.getPlayStatus()); final NotificationManagerCompat nm = NotificationManagerCompat.from(this); PendingIntent nextPendingIntent = getPendingIntent(ACTION_NEXT_TRACK); PendingIntent prevPendingIntent = getPendingIntent(ACTION_PREV_TRACK); PendingIntent playPendingIntent = getPendingIntent(ACTION_PLAY); PendingIntent pausePendingIntent = getPendingIntent(ACTION_PAUSE); PendingIntent closePendingIntent = getPendingIntent(ACTION_CLOSE); Intent showNowPlaying = new Intent(this, NowPlayingActivity.class) .setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_REORDER_TO_FRONT); PendingIntent pIntent = PendingIntent.getActivity(this, 0, showNowPlaying, 0); Notification notification; if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { final Notification.Builder builder = new Notification.Builder(this); builder.setContentIntent(pIntent); builder.setSmallIcon(R.drawable.squeezer_notification); builder.setVisibility(Notification.VISIBILITY_PUBLIC); builder.setShowWhen(false); builder.setContentTitle(songName); builder.setContentText(albumName); builder.setSubText(playerName); builder.setStyle(new Notification.MediaStyle().setShowActionsInCompactView(1, 2) .setMediaSession(mMediaSession.getSessionToken())); final MediaMetadata.Builder metaBuilder = new MediaMetadata.Builder(); metaBuilder.putString(MediaMetadata.METADATA_KEY_ARTIST, artistName); metaBuilder.putString(MediaMetadata.METADATA_KEY_ALBUM, albumName); metaBuilder.putString(MediaMetadata.METADATA_KEY_TITLE, songName); mMediaSession.setMetadata(metaBuilder.build()); // Don't set an ongoing notification, otherwise wearable's won't show it. builder.setOngoing(false); builder.setDeleteIntent(closePendingIntent); if (playing) { builder.addAction( new Notification.Action(R.drawable.ic_action_previous, "Previous", prevPendingIntent)) .addAction(new Notification.Action(R.drawable.ic_action_pause, "Pause", pausePendingIntent)) .addAction(new Notification.Action(R.drawable.ic_action_next, "Next", nextPendingIntent)); } else { builder.addAction( new Notification.Action(R.drawable.ic_action_previous, "Previous", prevPendingIntent)) .addAction(new Notification.Action(R.drawable.ic_action_play, "Play", playPendingIntent)) .addAction(new Notification.Action(R.drawable.ic_action_next, "Next", nextPendingIntent)); } ImageFetcher.getInstance(this).loadImage(url, getResources().getDimensionPixelSize(android.R.dimen.notification_large_icon_width), getResources().getDimensionPixelSize(android.R.dimen.notification_large_icon_height), new ImageWorker.ImageWorkerCallback() { @Override @TargetApi(Build.VERSION_CODES.LOLLIPOP) public void process(Object data, @Nullable Bitmap bitmap) { if (bitmap == null) { bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.icon_album_noart); } metaBuilder.putBitmap(MediaMetadata.METADATA_KEY_ALBUM_ART, bitmap); metaBuilder.putBitmap(MediaMetadata.METADATA_KEY_ART, bitmap); mMediaSession.setMetadata(metaBuilder.build()); builder.setLargeIcon(bitmap); nm.notify(PLAYBACKSERVICE_STATUS, builder.build()); } }); } else { NotificationCompat.Builder builder = new NotificationCompat.Builder(this); builder.setOngoing(true); builder.setCategory(NotificationCompat.CATEGORY_SERVICE); builder.setSmallIcon(R.drawable.squeezer_notification); RemoteViews normalView = new RemoteViews(this.getPackageName(), R.layout.notification_player_normal); RemoteViews expandedView = new RemoteViews(this.getPackageName(), R.layout.notification_player_expanded); normalView.setOnClickPendingIntent(R.id.next, nextPendingIntent); expandedView.setOnClickPendingIntent(R.id.previous, prevPendingIntent); expandedView.setOnClickPendingIntent(R.id.next, nextPendingIntent); builder.setContent(normalView); normalView.setTextViewText(R.id.trackname, songName); normalView.setTextViewText(R.id.albumname, albumName); expandedView.setTextViewText(R.id.trackname, songName); expandedView.setTextViewText(R.id.albumname, albumName); expandedView.setTextViewText(R.id.player_name, playerName); if (playing) { normalView.setImageViewResource(R.id.pause, R.drawable.ic_action_pause); normalView.setOnClickPendingIntent(R.id.pause, pausePendingIntent); expandedView.setImageViewResource(R.id.pause, R.drawable.ic_action_pause); expandedView.setOnClickPendingIntent(R.id.pause, pausePendingIntent); } else { normalView.setImageViewResource(R.id.pause, R.drawable.ic_action_play); normalView.setOnClickPendingIntent(R.id.pause, playPendingIntent); expandedView.setImageViewResource(R.id.pause, R.drawable.ic_action_play); expandedView.setOnClickPendingIntent(R.id.pause, playPendingIntent); } builder.setContentTitle(songName); builder.setContentText(getString(R.string.notification_playing_text, playerName)); builder.setContentIntent(pIntent); notification = builder.build(); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { notification.bigContentView = expandedView; } nm.notify(PLAYBACKSERVICE_STATUS, notification); ImageFetcher.getInstance(this).loadImage(this, url, normalView, R.id.album, getResources().getDimensionPixelSize(R.dimen.album_art_icon_normal_notification_width), getResources().getDimensionPixelSize(R.dimen.album_art_icon_normal_notification_height), nm, PLAYBACKSERVICE_STATUS, notification); ImageFetcher.getInstance(this).loadImage(this, url, expandedView, R.id.album, getResources().getDimensionPixelSize(R.dimen.album_art_icon_expanded_notification_width), getResources().getDimensionPixelSize(R.dimen.album_art_icon_expanded_notification_height), nm, PLAYBACKSERVICE_STATUS, notification); } }
From source file:com.android.mail.utils.NotificationActionUtils.java
public static Notification createUndoNotification(final Context context, final NotificationAction notificationAction, final int notificationId) { LogUtils.i(LOG_TAG, "createUndoNotification for %s", notificationAction.getNotificationActionType()); final NotificationCompat.Builder builder = new NotificationCompat.Builder(context); builder.setSmallIcon(R.drawable.ic_notification_mail_24dp); builder.setWhen(notificationAction.getWhen()); builder.setCategory(NotificationCompat.CATEGORY_EMAIL); final RemoteViews undoView = new RemoteViews(context.getPackageName(), R.layout.undo_notification); undoView.setTextViewText(R.id.description_text, context.getString(notificationAction.getActionTextResId())); final String packageName = context.getPackageName(); final Intent clickIntent = new Intent(NotificationActionIntentService.ACTION_UNDO); clickIntent.setPackage(packageName); clickIntent.setData(notificationAction.mConversation.uri); putNotificationActionExtra(clickIntent, notificationAction); final PendingIntent clickPendingIntent = PendingIntent.getService(context, notificationId, clickIntent, PendingIntent.FLAG_CANCEL_CURRENT); undoView.setOnClickPendingIntent(R.id.status_bar_latest_event_content, clickPendingIntent); builder.setContent(undoView);/*ww w .ja va 2 s . c om*/ // When the notification is cleared, we perform the destructive action final Intent deleteIntent = new Intent(NotificationActionIntentService.ACTION_DESTRUCT); deleteIntent.setPackage(packageName); deleteIntent.setData(notificationAction.mConversation.uri); putNotificationActionExtra(deleteIntent, notificationAction); final PendingIntent deletePendingIntent = PendingIntent.getService(context, notificationId, deleteIntent, PendingIntent.FLAG_CANCEL_CURRENT); builder.setDeleteIntent(deletePendingIntent); final Notification notification = builder.build(); return notification; }
From source file:com.sean.takeastand.alarmprocess.AlarmService.java
private void updateNotification() { /*if (!bRepeatingAlarmStepCheck) { mNotifTimePassed++;//from w w w. ja v a 2s .c o m } Log.i(TAG, "time since first notification: " + mNotifTimePassed + setMinutes(mNotifTimePassed));*/ NotificationManager notificationManager = (NotificationManager) this .getSystemService(Context.NOTIFICATION_SERVICE); PendingIntent[] pendingIntents = makeNotificationIntents(); RemoteViews rvRibbon = new RemoteViews(getPackageName(), R.layout.stand_notification); rvRibbon.setOnClickPendingIntent(R.id.btnStood, pendingIntents[1]); rvRibbon.setTextViewText(R.id.notificationTimeStamp, notificationClockTime); /*rvRibbon.setTextViewText(R.id.stand_up_minutes, mNotifTimePassed + setMinutes(mNotifTimePassed)); rvRibbon.setTextViewText(R.id.topTextView, getString(R.string.stand_up_time_up));*/ NotificationCompat.Builder alarmNotificationBuilder = new NotificationCompat.Builder(this); alarmNotificationBuilder.setContent(rvRibbon); alarmNotificationBuilder.setContentIntent(pendingIntents[0]).setAutoCancel(false) .setTicker(getString(R.string.stand_up_time_low)).setSmallIcon(R.drawable.ic_notification_small) .setContentTitle("Take A Stand ") //.setContentText("Mark Stood\n" + mNotifTimePassed + setMinutes(mNotifTimePassed)) .extend(new NotificationCompat.WearableExtender().addAction( new NotificationCompat.Action.Builder(R.drawable.ic_action_done, "Stood", pendingIntents[1]) .build()) .setContentAction(0).setHintHideIcon(true) // .setBackground(BitmapFactory.decodeResource(getResources(), R.drawable.alarm_schedule_passed)) ); boolean[] alertType; if (mCurrentAlarmSchedule != null) { alertType = mCurrentAlarmSchedule.getAlertType(); } else { alertType = Utils.getDefaultAlertType(this); } if ((alertType[0])) { alarmNotificationBuilder.setLights(238154000, 1000, 4000); } if (Utils.getRepeatAlerts(this)) { if (alertType[1]) { boolean bUseLastStepCounters = false; if (!bRepeatingAlarmStepCheck) { bRepeatingAlarmStepCheck = true; bUseLastStepCounters = UseLastStepCounters(null); } if (!bUseLastStepCounters) { bRepeatingAlarmStepCheck = false; alarmNotificationBuilder.setVibrate(mVibrationPattern); AudioManager audioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE); if (audioManager.getMode() == AudioManager.RINGER_MODE_SILENT && Utils.getVibrateOverride(this)) { Vibrator v = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE); v.vibrate(mVibrationPattern, -1); } } } if (alertType[2]) { Uri soundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); alarmNotificationBuilder.setSound(soundUri); } } Notification alarmNotification = alarmNotificationBuilder.build(); notificationManager.notify(R.integer.AlarmNotificationID, alarmNotification); }
From source file:com.tct.mail.utils.NotificationActionUtils.java
public static Notification createUndoNotification(final Context context, final NotificationAction notificationAction, final int notificationId) { LogUtils.i(LOG_TAG, "createUndoNotification for %s", notificationAction.getNotificationActionType()); final NotificationCompat.Builder builder = new NotificationCompat.Builder(context); builder.setSmallIcon(R.drawable.ic_notification_mail_24dp); builder.setWhen(notificationAction.getWhen()); final RemoteViews undoView = new RemoteViews(context.getPackageName(), R.layout.undo_notification); undoView.setTextViewText(R.id.description_text, context.getString(notificationAction.getActionTextResId())); final String packageName = context.getPackageName(); final Intent clickIntent = new Intent(NotificationActionIntentService.ACTION_UNDO); clickIntent.setPackage(packageName); clickIntent.setData(notificationAction.mConversation.uri); putNotificationActionExtra(clickIntent, notificationAction); final PendingIntent clickPendingIntent = PendingIntent.getService(context, notificationId, clickIntent, PendingIntent.FLAG_CANCEL_CURRENT); undoView.setOnClickPendingIntent(R.id.status_bar_latest_event_content, clickPendingIntent); builder.setContent(undoView);/* w w w . j a va 2 s . c om*/ // When the notification is cleared, we perform the destructive action final Intent deleteIntent = new Intent(NotificationActionIntentService.ACTION_DESTRUCT); deleteIntent.setPackage(packageName); deleteIntent.setData(notificationAction.mConversation.uri); putNotificationActionExtra(deleteIntent, notificationAction); final PendingIntent deletePendingIntent = PendingIntent.getService(context, notificationId, deleteIntent, PendingIntent.FLAG_CANCEL_CURRENT); builder.setDeleteIntent(deletePendingIntent); final Notification notification = builder.build(); return notification; }
From source file:com.yamin.kk.service.AudioService.java
@TargetApi(Build.VERSION_CODES.JELLY_BEAN) private void showNotification() { try {/*from ww w .ja v a 2 s.c o m*/ Bitmap cover = AudioUtil.getCover(this, getCurrentMedia(), 64); String title = getCurrentMedia().getTitle(); String artist = getCurrentMedia().getArtist(); String album = getCurrentMedia().getAlbum(); Notification notification; // add notification to status bar NotificationCompat.Builder builder = new NotificationCompat.Builder(this) .setSmallIcon(R.drawable.ic_stat_vlc).setTicker(title + " - " + artist).setAutoCancel(false) .setOngoing(true); Intent notificationIntent = new Intent(this, MainActivity.class); notificationIntent.setAction(MainActivity.ACTION_SHOW_PLAYER); notificationIntent.addCategory(Intent.CATEGORY_LAUNCHER); notificationIntent.putExtra(START_FROM_NOTIFICATION, true); PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT); if (Util.isJellyBeanOrLater()) { Intent iBackward = new Intent(ACTION_REMOTE_BACKWARD); Intent iPlay = new Intent(ACTION_REMOTE_PLAYPAUSE); Intent iForward = new Intent(ACTION_REMOTE_FORWARD); Intent iStop = new Intent(ACTION_REMOTE_STOP); PendingIntent piBackward = PendingIntent.getBroadcast(this, 0, iBackward, PendingIntent.FLAG_UPDATE_CURRENT); PendingIntent piPlay = PendingIntent.getBroadcast(this, 0, iPlay, PendingIntent.FLAG_UPDATE_CURRENT); PendingIntent piForward = PendingIntent.getBroadcast(this, 0, iForward, PendingIntent.FLAG_UPDATE_CURRENT); PendingIntent piStop = PendingIntent.getBroadcast(this, 0, iStop, PendingIntent.FLAG_UPDATE_CURRENT); RemoteViews view = new RemoteViews(getPackageName(), R.layout.notification); if (cover != null) view.setImageViewBitmap(R.id.cover, cover); view.setTextViewText(R.id.songName, title); view.setTextViewText(R.id.artist, artist); view.setImageViewResource(R.id.play_pause, mLibVLC.isPlaying() ? R.drawable.ic_pause : R.drawable.ic_play); view.setOnClickPendingIntent(R.id.play_pause, piPlay); view.setOnClickPendingIntent(R.id.forward, piForward); view.setOnClickPendingIntent(R.id.stop, piStop); view.setOnClickPendingIntent(R.id.content, pendingIntent); RemoteViews view_expanded = new RemoteViews(getPackageName(), R.layout.notification_expanded); if (cover != null) view_expanded.setImageViewBitmap(R.id.cover, cover); view_expanded.setTextViewText(R.id.songName, title); view_expanded.setTextViewText(R.id.artist, artist); view_expanded.setTextViewText(R.id.album, album); view_expanded.setImageViewResource(R.id.play_pause, mLibVLC.isPlaying() ? R.drawable.ic_pause : R.drawable.ic_play); view_expanded.setOnClickPendingIntent(R.id.backward, piBackward); view_expanded.setOnClickPendingIntent(R.id.play_pause, piPlay); view_expanded.setOnClickPendingIntent(R.id.forward, piForward); view_expanded.setOnClickPendingIntent(R.id.stop, piStop); view_expanded.setOnClickPendingIntent(R.id.content, pendingIntent); notification = builder.build(); notification.contentView = view; notification.bigContentView = view_expanded; } else { builder.setLargeIcon(cover).setContentTitle(title) .setContentText(Util.isJellyBeanOrLater() ? artist : getCurrentMedia().getSubtitle()) .setContentInfo(album).setContentIntent(pendingIntent); notification = builder.build(); } startService(new Intent(this, AudioService.class)); startForeground(3, notification); } catch (NoSuchMethodError e) { // Compat library is wrong on 3.2 // http://code.google.com/p/android/issues/detail?id=36359 // http://code.google.com/p/android/issues/detail?id=36502 } }
From source file:com.eugene.fithealthmaingit.UI.NavFragments.FragmentJournalMainHome.java
/** * Equation for all of the Nutrition and Meal information */// w w w . j a v a2s .c om private void equations() { double mCalorieGoal = Double.valueOf(sharedPreferences.getString(Globals.USER_CALORIES_TO_REACH_GOAL, "")); double mFatGoal = Double.valueOf(sharedPreferences.getString(Globals.USER_DAILY_FAT, "")); double mCarbGoal = Double.valueOf(sharedPreferences.getString(Globals.USER_DAILY_CARBOHYDRATES, "")); double mProteinGoal = Double.valueOf(sharedPreferences.getString(Globals.USER_DAILY_PROTEIN, "")); mCalorieGoalMeal = Double.valueOf(sharedPreferences.getString(Globals.USER_CALORIES_TO_REACH_GOAL, "")) / 4; icSnack = (ImageView) v.findViewById(R.id.icSnack); icBreakfast = (ImageView) v.findViewById(R.id.icBreakfast); icLunch = (ImageView) v.findViewById(R.id.icLunch); icDinner = (ImageView) v.findViewById(R.id.icDinner); // _________________________Calories Snack_____________________________ double mCalConsumedSnack = 0; for (LogMeal logMeal : mLogSnackAdapter.getLogs()) { mCalConsumedSnack += logMeal.getCalorieCount(); } mCalSnack.setText(df.format(mCalConsumedSnack)); // Set icon visible and color based on calories consumed for meal. if (mCalConsumedSnack >= mCalorieGoalMeal + 100) { icSnack.setImageResource(R.mipmap.ic_check_circle); icSnack.setColorFilter(Color.parseColor("#F44336"), android.graphics.PorterDuff.Mode.MULTIPLY); } else if (mCalConsumedSnack > mCalorieGoalMeal - 100 && mCalConsumedSnack < mCalorieGoalMeal + 99) { icSnack.setImageResource(R.mipmap.ic_check_circle); icSnack.setColorFilter(Color.parseColor("#4CAF50"), android.graphics.PorterDuff.Mode.MULTIPLY); } else { icSnack.setImageResource(R.mipmap.ic_check); icSnack.setColorFilter(Color.parseColor("#6D6D6D"), android.graphics.PorterDuff.Mode.MULTIPLY); } // _________________________Calories Breakfast_____________________________ double mCalConsumedBreakfast = 0; for (LogMeal logMeal : mLogBreakfastAdapter.getLogs()) { mCalConsumedBreakfast += logMeal.getCalorieCount(); } mCalBreakfast.setText(df.format(mCalConsumedBreakfast)); // Set icon visible and color based on calories consumed for meal. if (mCalConsumedBreakfast >= mCalorieGoalMeal + 100) { icBreakfast.setColorFilter(Color.parseColor("#F44336"), android.graphics.PorterDuff.Mode.MULTIPLY); icBreakfast.setImageResource(R.mipmap.ic_check_circle); } else if (mCalConsumedBreakfast > mCalorieGoalMeal - 100 && mCalConsumedBreakfast < mCalorieGoalMeal + 99) { icBreakfast.setColorFilter(Color.parseColor("#4CAF50"), android.graphics.PorterDuff.Mode.MULTIPLY); icBreakfast.setImageResource(R.mipmap.ic_check_circle); } else { icBreakfast.setImageResource(R.mipmap.ic_check); icBreakfast.setColorFilter(Color.parseColor("#6D6D6D"), android.graphics.PorterDuff.Mode.MULTIPLY); } // _________________________Calories Lunch_____________________________ double mCalConsumedLunch = 0; for (LogMeal logMeal : mLogLunchAdapter.getLogs()) { mCalConsumedLunch += logMeal.getCalorieCount(); } mCalLunch.setText(df.format(mCalConsumedLunch)); // Set icon visible and color based on calories consumed for meal. if (mCalConsumedLunch >= mCalorieGoalMeal + 100) { icLunch.setImageResource(R.mipmap.ic_check_circle); icLunch.setColorFilter(Color.parseColor("#F44336"), android.graphics.PorterDuff.Mode.MULTIPLY); } else if (mCalConsumedLunch > mCalorieGoalMeal - 100 && mCalConsumedLunch < mCalorieGoalMeal + 99) { icLunch.setImageResource(R.mipmap.ic_check_circle); icLunch.setColorFilter(Color.parseColor("#4CAF50"), android.graphics.PorterDuff.Mode.MULTIPLY); } else { icLunch.setImageResource(R.mipmap.ic_check); icLunch.setColorFilter(Color.parseColor("#6D6D6D"), android.graphics.PorterDuff.Mode.MULTIPLY); } // _________________________Calories Lunch_____________________________ double mCalConsumedDinner = 0; for (LogMeal logMeal : mLogDinnerAdapter.getLogs()) { mCalConsumedDinner += logMeal.getCalorieCount(); } mCalDinner.setText(df.format(mCalConsumedDinner)); // Set icon visible and color based on calories consumed for meal. if (mCalConsumedDinner >= mCalorieGoalMeal + 100) { icDinner.setImageResource(R.mipmap.ic_check_circle); icDinner.setColorFilter(Color.parseColor("#F44336"), android.graphics.PorterDuff.Mode.MULTIPLY); } else if (mCalConsumedDinner > mCalorieGoalMeal - 100 && mCalConsumedDinner < mCalorieGoalMeal + 99) { icDinner.setImageResource(R.mipmap.ic_check_circle); icDinner.setColorFilter(Color.parseColor("#4CAF50"), android.graphics.PorterDuff.Mode.MULTIPLY); } else { icDinner.setImageResource(R.mipmap.ic_check); icDinner.setColorFilter(Color.parseColor("#6D6D6D"), android.graphics.PorterDuff.Mode.MULTIPLY); } // _________________________Calories, Fat, Carbs, Protein All_____________________________ // Nutrition Consumed double mAllCaloriesConsumed = 0; double mAllFatConsumed = 0; double mAllCarbsConsumed = 0; double mAllProteinConsumed = 0; for (LogMeal logMeal : mLogAdapterAll.getLogs()) { mAllCaloriesConsumed += logMeal.getCalorieCount(); mAllFatConsumed += logMeal.getFatCount(); mAllCarbsConsumed += logMeal.getCarbCount(); mAllProteinConsumed += logMeal.getProteinCount(); } // Nutrition Goals // Remainder Nutrition mCaloriesRemainder.setText(df.format(mCalorieGoal - mAllCaloriesConsumed) + " Left"); mFatRemainder.setText(df.format(mFatGoal - mAllFatConsumed) + " Left"); mCarbRemainder.setText(df.format(mCarbGoal - mAllCarbsConsumed) + " Left"); mProteinRemainder.setText(df.format(mProteinGoal - mAllProteinConsumed) + " Left"); // Progress bars mPbCalories.setMax(Integer.valueOf(df.format(mCalorieGoal))); mPbCalories.setProgress(Integer.valueOf(df.format(mAllCaloriesConsumed))); mPbFat.setMax(Integer.valueOf(df.format(mFatGoal))); mPbFat.setProgress(Integer.valueOf(df.format(mAllFatConsumed))); mPbCarbs.setMax(Integer.valueOf(df.format(mCarbGoal))); mPbCarbs.setProgress(Integer.valueOf(df.format(mAllCarbsConsumed))); mPbProtein.setMax(Integer.valueOf(df.format(mProteinGoal))); mPbProtein.setProgress(Integer.valueOf(df.format(mAllProteinConsumed))); /** * Update Widget */ Context context = getActivity(); AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(context); if (appWidgetManager != null) { RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.new_app_widget); ComponentName thisWidget = new ComponentName(context, FitHealthWidget.class); views.setProgressBar(R.id.pbCal, Integer.valueOf(df.format(mCalorieGoal)), Integer.valueOf(df.format(mAllCaloriesConsumed)), false); views.setProgressBar(R.id.pbFat, Integer.valueOf(df.format(mFatGoal)), Integer.valueOf(df.format(mAllFatConsumed)), false); views.setProgressBar(R.id.pbCarb, Integer.valueOf(df.format(mCarbGoal)), Integer.valueOf(df.format(mAllCarbsConsumed)), false); views.setProgressBar(R.id.pbPro, Integer.valueOf(df.format(mProteinGoal)), Integer.valueOf(df.format(mAllProteinConsumed)), false); views.setTextViewText(R.id.txtRemainderCal, df.format(mCalorieGoal - mAllCaloriesConsumed)); views.setTextViewText(R.id.txtRemainderFat, df.format(mFatGoal - mAllFatConsumed)); views.setTextViewText(R.id.txtRemainderCarb, df.format(mCarbGoal - mAllCarbsConsumed)); views.setTextViewText(R.id.txtRemainderPro, df.format(mProteinGoal - mAllProteinConsumed)); appWidgetManager.updateAppWidget(thisWidget, views); } }