diff options
| author | schneefux <schneefux+commit@schneefux.xyz> | 2015-12-25 13:38:31 +0100 |
|---|---|---|
| committer | schneefux <schneefux+commit@schneefux.xyz> | 2015-12-25 13:38:31 +0100 |
| commit | 76edd6c448c55c4f9bcf37509ec372149c966993 (patch) | |
| tree | c4eed3c1ecb40987cbe2b77df47b2e6e23c71494 /AndroidClient/app/src/main/java/winter/snowman/notifications | |
| download | weather-snowman-76edd6c448c55c4f9bcf37509ec372149c966993.tar.gz weather-snowman-76edd6c448c55c4f9bcf37509ec372149c966993.zip | |
first commit
Diffstat (limited to 'AndroidClient/app/src/main/java/winter/snowman/notifications')
| -rw-r--r-- | AndroidClient/app/src/main/java/winter/snowman/notifications/NotifListenerService.java | 129 | ||||
| -rw-r--r-- | AndroidClient/app/src/main/java/winter/snowman/notifications/WebViewActivity.java | 17 |
2 files changed, 146 insertions, 0 deletions
diff --git a/AndroidClient/app/src/main/java/winter/snowman/notifications/NotifListenerService.java b/AndroidClient/app/src/main/java/winter/snowman/notifications/NotifListenerService.java new file mode 100644 index 0000000..dde3d1f --- /dev/null +++ b/AndroidClient/app/src/main/java/winter/snowman/notifications/NotifListenerService.java @@ -0,0 +1,129 @@ +package winter.snowman.notifications; + +import android.content.BroadcastReceiver; +import android.content.Context; +import android.content.Intent; +import android.content.IntentFilter; +import android.service.notification.NotificationListenerService; +import android.service.notification.StatusBarNotification; +import android.util.Log; + +import java.net.URL; +import java.io.InputStream; +import java.io.BufferedInputStream; +import java.net.URLConnection; +import java.net.HttpURLConnection; + +/** + * Created by christian on 1/1/15. + */ +public class NotifListenerService extends NotificationListenerService { + private String TAG = this.getClass().getSimpleName(); + + private NotifListenerServiceReceiver notifListenerServiceReceiver; + + @Override + public void onCreate() { + super.onCreate(); + notifListenerServiceReceiver = new NotifListenerServiceReceiver(); + + IntentFilter filter = new IntentFilter(); + filter.addAction("com.cle.ambientnotifications.NOTIFICATION_LISTENER_SERVICE"); + registerReceiver(notifListenerServiceReceiver, filter); + + Log.d(TAG, "NotifListenerService is running"); + } + + @Override + public void onDestroy() { + super.onDestroy(); + unregisterReceiver(notifListenerServiceReceiver); + } + + private void notificationOff() { + Log.i(TAG, "********** notification off"); + URL url; + HttpURLConnection urlConnection; + try { + url = new URL("http://snowman/api?led2=clear"); + urlConnection = (HttpURLConnection) url.openConnection(); + } catch (Exception e) { + e.printStackTrace(); + return; + } + try { + InputStream in = new BufferedInputStream(urlConnection.getInputStream()); + } catch (Exception e) { + e.printStackTrace(); + } finally { + urlConnection.disconnect(); + } + } + + private void notificationOn() { + Log.i(TAG, "********** notification on"); + URL url; + HttpURLConnection urlConnection; + try { + url = new URL("http://snowman/api?led2=blink"); + urlConnection = (HttpURLConnection) url.openConnection(); + } catch (Exception e) { + e.printStackTrace(); + return; + } + try { + InputStream in = new BufferedInputStream(urlConnection.getInputStream()); + } catch (Exception e) { + e.printStackTrace(); + } finally { + urlConnection.disconnect(); + } + } + + @Override + public void onNotificationPosted(StatusBarNotification notif) { + Log.i(TAG, "********** onNotificationPosted"); + Log.i(TAG,"ID :" + notif.getId() + "t" + notif.getNotification().tickerText + + "t" + notif.getPackageName()); + notificationOn(); + } + + @Override + public void onNotificationRemoved(StatusBarNotification notif) { + Log.i(TAG, "********** onNotificationRemoved"); + Log.i(TAG,"ID :" + notif.getId() + "t" + notif.getNotification().tickerText + + "t" + notif.getPackageName()); + notificationOff(); + }; + + class NotifListenerServiceReceiver extends BroadcastReceiver { + + @Override + public void onReceive(Context context, Intent intent) { + if (intent.getStringExtra("command").equals("clearall")) { + NotifListenerService.this.cancelAllNotifications(); + } else if (intent.getStringExtra("command").equals("list")) { + Log.d(TAG, "command received"); + + Intent i = new Intent("com.cle.ambientnotifications.NOTIFICATION_LISTENER"); + i.putExtra("notification_event", "========="); + sendBroadcast(i); + + int counter = 1; + for (StatusBarNotification notif : NotifListenerService.this.getActiveNotifications()) { + Intent notifIntent = + new Intent("com.cle.ambientnotifications.NOTIFICATION_LISTENER"); + notifIntent.putExtra("notification_event", counter + " " + + notif.getPackageName() + "\n"); + sendBroadcast(notifIntent); + counter += 1; + } + + Intent listIntent = + new Intent("com.cle.ambientnotifications.NOTIFICATION_LISTENER"); + listIntent.putExtra("notification_event", "==== Notification List ===="); + sendBroadcast(listIntent); + } + } + } +} diff --git a/AndroidClient/app/src/main/java/winter/snowman/notifications/WebViewActivity.java b/AndroidClient/app/src/main/java/winter/snowman/notifications/WebViewActivity.java new file mode 100644 index 0000000..0618fd2 --- /dev/null +++ b/AndroidClient/app/src/main/java/winter/snowman/notifications/WebViewActivity.java @@ -0,0 +1,17 @@ +package winter.snowman.notifications; + +import android.app.Activity; +import android.webkit.WebView; +import android.os.Bundle; + +public class WebViewActivity extends Activity { + + private WebView webView; + + public void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.main); + webView = (WebView) findViewById(R.id.webView); + webView.loadUrl("http://snowman"); + } +} |
