List of usage examples for android.widget RemoteViews RemoteViews
public RemoteViews(RemoteViews landscape, RemoteViews portrait)
From source file:org.gaeproxy.GAEProxyService.java
public void handleCommand(Intent intent) { if (intent == null) { stopSelf();// w w w.ja va 2 s. co m return; } proxyType = settings.getString("proxyType", "GAE"); sitekey = settings.getString("sitekey", ""); try { port = Integer.valueOf(settings.getString("port", "1984")); } catch (NumberFormatException ex) { port = 1984; } isGlobalProxy = settings.getBoolean("isGlobalProxy", false); isGFWList = settings.getBoolean("isGFWList", false); isBypassApps = settings.getBoolean("isBypassApps", false); if (!parseProxyURL(settings.getString("proxy", "proxyofmax.appspot.com"))) { stopSelf(); return; } if (!"GAE".equals(proxyType) && !"PaaS".equals(proxyType)) { proxyType = "GAE"; } if ("fetch.py".equals(appPath)) appPath = "2"; Log.e(TAG, "Proxy: " + appId + " " + appPath); Log.e(TAG, "Local Port: " + port); new Thread(new Runnable() { @Override public void run() { handler.sendEmptyMessage(MSG_CONNECT_START); Log.d(TAG, "IPTABLES: " + Utils.getIptables()); // Test for Redirect Support hasRedirectSupport = Utils.getHasRedirectSupport(); if (handleConnection()) { // Connection and forward successful notifyAlert(getString(R.string.forward_success), getString(R.string.service_running)); handler.sendEmptyMessageDelayed(MSG_CONNECT_SUCCESS, 500); // for widget, maybe exception here try { RemoteViews views = new RemoteViews(getPackageName(), R.layout.gaeproxy_appwidget); views.setImageViewResource(R.id.serviceToggle, R.drawable.on); AppWidgetManager awm = AppWidgetManager.getInstance(GAEProxyService.this); awm.updateAppWidget( awm.getAppWidgetIds( new ComponentName(GAEProxyService.this, GAEProxyWidgetProvider.class)), views); } catch (Exception ignore) { // Nothing } } else { // Connection or forward unsuccessful notifyAlert(getString(R.string.forward_fail), getString(R.string.service_failed)); stopSelf(); handler.sendEmptyMessageDelayed(MSG_CONNECT_FAIL, 500); } handler.sendEmptyMessageDelayed(MSG_CONNECT_FINISH, 500); } }).start(); markServiceStarted(); }
From source file:gsoc.google.com.byop.utils.PW.UrlDeviceDiscoveryService.java
/** * Create the big view for the summary notification. *///from ww w .j a v a 2 s . com 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 // PendingIntent pendingIntent = createReturnToAppPendingIntent(); remoteViews.setOnClickPendingIntent(R.id.otherBeaconsLayout, pendingIntent); return remoteViews; }
From source file:com.gsoc.ijosa.liquidgalaxycontroller.PW.UrlDeviceDiscoveryService.java
/** * Create the big view for the summary notification. *//* www . ja va 2s. com*/ 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 PendingIntent pendingIntent = createReturnToAppPendingIntent(); remoteViews.setOnClickPendingIntent(R.id.otherBeaconsLayout, pendingIntent); return remoteViews; }
From source file:com.hang.exoplayer.PlayService.java
public void showNotification() { String title = "XXXXXXXX"; String description = "YYYYYYYYYYYYY"; NotificationCompat.Builder builder = new NotificationCompat.Builder(PlayService.this).setAutoCancel(false) .setOngoing(true);//ww w . j a va 2s . com Class<?> targetClass = PlayActivity.class; Intent notificationIntent = new Intent(PlayService.this, targetClass); PendingIntent pendingIntent = PendingIntent.getActivity(PlayService.this, 0, notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT); builder.setContentIntent(pendingIntent); Intent playPauseIntent = new Intent(ExoApplication.getApplication(), PlayService.class); playPauseIntent.putExtra(ACTION_PLAY_PAUSE, true); Intent previousIntent = new Intent(ExoApplication.getApplication(), PlayService.class); previousIntent.putExtra(ACTION_PREVIOUS, true); Intent nextIntent = new Intent(ExoApplication.getApplication(), PlayService.class); nextIntent.putExtra(ACTION_NEXT, true); Intent dismissIntent = new Intent(ExoApplication.getApplication(), PlayService.class); dismissIntent.putExtra(ACTION_EXIT, true); PendingIntent playPendingIntent = PendingIntent.getService(PlayService.this, 1, playPauseIntent, PendingIntent.FLAG_UPDATE_CURRENT); PendingIntent previousPendingIntent = PendingIntent.getService(PlayService.this, 2, previousIntent, PendingIntent.FLAG_UPDATE_CURRENT); PendingIntent nextPendingIntent = PendingIntent.getService(PlayService.this, 3, nextIntent, PendingIntent.FLAG_UPDATE_CURRENT); PendingIntent dismissPendingIntent = PendingIntent.getService(PlayService.this, 4, dismissIntent, PendingIntent.FLAG_UPDATE_CURRENT); RemoteViews contentView = new RemoteViews(getPackageName(), R.layout.notification_high_version_no_live); contentView.setTextViewText(R.id.songName, title); contentView.setTextViewText(R.id.artist, description); boolean isPlaying = SimplePlayer.getInstance().isPlaying(); // Log.d(TAG, "Notification is Playing?" + isPlaying); contentView.setImageViewResource(R.id.play_pause, isPlaying ? R.drawable.ic_noti_play_normal : R.drawable.ic_noti_pause_normal); contentView.setOnClickPendingIntent(R.id.play_pause, playPendingIntent); contentView.setOnClickPendingIntent(R.id.play_pre, previousPendingIntent); contentView.setOnClickPendingIntent(R.id.forward, nextPendingIntent); contentView.setOnClickPendingIntent(R.id.stop, dismissPendingIntent); // builder.setCustomContentView(contentView); builder.setContent(contentView); Notification notification = builder.setSmallIcon(R.mipmap.ic_launcher).build(); startForeground(ID_NOTIFICATION, notification); NotificationManager manager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); manager.notify(ID_NOTIFICATION, notification); }
From source file:com.andrewshu.android.reddit.common.Common.java
public static void newMailNotification(Context context, String mailNotificationStyle, int count) { Intent nIntent = new Intent(context, InboxActivity.class); PendingIntent contentIntent = PendingIntent.getActivity(context, 0, nIntent, 0); Notification notification = new Notification(R.drawable.mail, Constants.HAVE_MAIL_TICKER, System.currentTimeMillis()); if (Constants.PREF_MAIL_NOTIFICATION_STYLE_BIG_ENVELOPE.equals(mailNotificationStyle)) { RemoteViews contentView = new RemoteViews(context.getPackageName(), R.layout.big_envelope_notification); notification.contentView = contentView; } else {/*ww w. ja va 2 s . c o m*/ notification.setLatestEventInfo(context, Constants.HAVE_MAIL_TITLE, count + (count == 1 ? " unread message" : " unread messages"), contentIntent); } notification.defaults |= Notification.DEFAULT_SOUND; notification.flags |= Notification.FLAG_ONLY_ALERT_ONCE | Notification.FLAG_AUTO_CANCEL; notification.contentIntent = contentIntent; NotificationManager notificationManager = (NotificationManager) context .getSystemService(Context.NOTIFICATION_SERVICE); notificationManager.notify(Constants.NOTIFICATION_HAVE_MAIL, notification); }
From source file:com.wojtechnology.sunami.TheBrain.java
private void setNotification(FireMixtape song) { if (mPlaying == null) { stopForeground(true);/* ww w . j av a 2 s. c o m*/ return; } setMetadata(song); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { // Notification is created in setMetadata return; } if (mNotification == null || mNotificationView == null) { Intent notificationIntent = new Intent(this, MainActivity.class); PendingIntent pendingIntent = PendingIntent.getActivity(mContext, 1, notificationIntent, 0); mNotificationView = new RemoteViews(getPackageName(), R.layout.notification); mNotification = new Notification.Builder(this).setSmallIcon(R.mipmap.sunaminotif) .setContentIntent(pendingIntent).setContent(mNotificationView).build(); } Intent servicePlayIntent = new Intent(getApplicationContext(), TheBrain.class); servicePlayIntent.setAction(TheBrain.TOGGLE_PLAY); servicePlayIntent.addFlags(Intent.FLAG_RECEIVER_FOREGROUND); PendingIntent pendingPlayIntent = PendingIntent.getService(mContext, 1, servicePlayIntent, 0); Intent serviceNextIntent = new Intent(getApplicationContext(), TheBrain.class); serviceNextIntent.setAction(TheBrain.PLAY_NEXT); serviceNextIntent.addFlags(Intent.FLAG_RECEIVER_FOREGROUND); PendingIntent pendingNextIntent = PendingIntent.getService(mContext, 1, serviceNextIntent, 0); Intent serviceStopIntent = new Intent(getApplicationContext(), TheBrain.class); serviceStopIntent.setAction(TheBrain.PLAY_STOP); serviceStopIntent.addFlags(Intent.FLAG_RECEIVER_FOREGROUND); PendingIntent pendingStopIntent = PendingIntent.getService(mContext, 1, serviceStopIntent, 0); mNotificationView.setTextViewText(R.id.notif_title, song.title); mNotificationView.setTextViewText(R.id.notif_artist, song.artist); mNotificationView.setOnClickPendingIntent(R.id.play_notif_button, pendingPlayIntent); mNotificationView.setOnClickPendingIntent(R.id.next_notif_button, pendingNextIntent); mNotificationView.setOnClickPendingIntent(R.id.close_notif_button, pendingStopIntent); setNotificationStatus(true); }
From source file:au.com.wallaceit.reddinator.SubredditSelectActivity.java
private void updateFeedAndFinish() { if (widgetFirstTimeSetup) { finishWidgetSetup();//from w w w. ja va 2s . c om return; } if (mAppWidgetId != 0) { // refresh widget and close activity (NOTE: put in function) AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(SubredditSelectActivity.this); RemoteViews views = new RemoteViews(getPackageName(), R.layout.widget); views.setTextViewText(R.id.subreddittxt, global.getSubredditManager().getCurrentFeedName(mAppWidgetId)); views.setViewVisibility(R.id.srloader, View.VISIBLE); views.setViewVisibility(R.id.erroricon, View.INVISIBLE); // bypass cache if service not loaded global.setBypassCache(true); appWidgetManager.partiallyUpdateAppWidget(mAppWidgetId, views); appWidgetManager.notifyAppWidgetViewDataChanged(mAppWidgetId, R.id.listview); } else { Intent intent = new Intent(); intent.putExtra("themeupdate", needsThemeUpdate); setResult(2, intent); // update feed prefs + reload feed } finish(); }
From source file:fi.hut.soberit.sensors.services.BatchDataUploadService.java
private void showBatchUploadNotification(String text, int progress, boolean noClear) { if (notification == null) { notification = new Notification(R.drawable.ic_icon_export, text, System.currentTimeMillis()); // final Intent appIntent = new Intent(this, SIDE.class); final PendingIntent contentIntent = PendingIntent.getActivity(this, 0, null, 0); notification.setLatestEventInfo(this, getString(R.string.app_name), text, contentIntent); RemoteViews contentView = new RemoteViews(getPackageName(), R.layout.batch_upload_notification_layout); contentView.setImageViewResource(R.id.status_icon, R.drawable.ic_icon_export); notification.contentView = contentView; }//from w w w. j a v a 2 s . c o m notification.contentView.setTextViewText(R.id.status_text, text); notification.contentView.setProgressBar(R.id.progress_bar, MAX_PROGRESS, progress, false); if (noClear) { notification.flags |= Notification.FLAG_NO_CLEAR | Notification.FLAG_ONGOING_EVENT; } else { notificationManager.cancel(R.id.batch_upload); notification.flags ^= Notification.FLAG_NO_CLEAR | Notification.FLAG_ONGOING_EVENT; } notificationManager.notify(R.id.batch_upload, notification); }
From source file:org.zoumbox.mh_dla_notifier.Receiver.java
protected void checkForWidgetsUpdate(Context context, Troll troll) { try {// w w w .j a v a2s .c o m AppWidgetManager widgetManager = AppWidgetManager.getInstance(context); ComponentName componentName = new ComponentName(context, HomeScreenWidget.class); int[] appWidgetIds = widgetManager.getAppWidgetIds(componentName); if (appWidgetIds != null && appWidgetIds.length > 0) { // FIXME AThimel 14/02/14 Remove ASAP StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build(); StrictMode.setThreadPolicy(policy); String dlaText = Trolls.getWidgetDlaTextFunction(context).apply(troll); Bitmap blason = MhDlaNotifierUtils.loadBlasonForWidget(troll.getBlason(), context.getCacheDir()); for (int appWidgetId : appWidgetIds) { RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.home_screen_widget); views.setTextViewText(R.id.widgetDla, dlaText); if (blason == null) { views.setImageViewResource(R.id.widgetImage, R.drawable.trarnoll_square_transparent_128); } else { views.setImageViewBitmap(R.id.widgetImage, blason); } // Tell the AppWidgetManager to perform an update on the current app widget widgetManager.updateAppWidget(appWidgetId, views); } } } catch (Exception eee) { Log.e(TAG, "Unable to update widget(s)", eee); } }
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;/*from w w w . j a v a2s. 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); }