package jp.yokomark.remoteviews.app;

import android.annotation.TargetApi;
import android.os.Build;
import android.service.notification.NotificationListenerService;
import android.service.notification.StatusBarNotification;
import android.util.Log;
import android.widget.RemoteViews;

import java.util.List;

import jp.yokomark.remoteview.reader.RemoteViewsInfo;
import jp.yokomark.remoteview.reader.RemoteViewsReader;
import jp.yokomark.remoteview.reader.action.RemoteViewsAction;
import jp.yokomark.remoteview.reader.action.SetLaunchPendingIntentAction;
import jp.yokomark.remoteview.reader.action.SetOnClickPendingIntentAction;

/**
 * @author KeishinYokomaku
 */
@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR2)
public class NotificationWatcher extends NotificationListenerService {
	@Override
	public void onNotificationPosted(StatusBarNotification sbn) {
		RemoteViews views = sbn.getNotification().contentView;
		RemoteViewsInfo info = RemoteViewsReader.read(this, views);
		if (info == null)
			return;
		List<RemoteViewsAction> actions = info.getActions();
		for (RemoteViewsAction action : actions) {
			Log.v("NotificationWatcher", action.getActionName());
			if (action instanceof SetLaunchPendingIntentAction) {
				SetLaunchPendingIntentAction p = (SetLaunchPendingIntentAction) action;
				Log.v("NotificationWatcher", p.getContentIntent().toString());
			} else if (action instanceof SetOnClickPendingIntentAction) {
				SetOnClickPendingIntentAction p = (SetOnClickPendingIntentAction) action;
				Log.v("NotificationWatcher", p.getContentIntent().toString());
			}
		}
	}

	@Override
	public void onNotificationRemoved(StatusBarNotification sbn) {}
}

@@ -456,33 +456,31 @@
 .action.
-RemoteViewsAction
+IntentContainer
 ;%0Aimport
@@ -517,38 +517,27 @@
 .action.
-SetLaunchPendingIntent
+RemoteViews
 Action;%0A
@@ -580,39 +580,25 @@
 .action.
-SetOnClickPendingIntent
+ViewGroup
 Action;%0A
@@ -948,39 +948,8 @@
 s);%0A
-%09%09if (info == null)%0A%09%09%09return;%0A
 %09%09Li
@@ -999,16 +999,168 @@
 ions();%0A
+%09%09dump(actions);%0A%09%7D%0A%0A%09@Override%0A%09public void onNotificationRemoved(StatusBarNotification sbn) %7B%7D%0A%0A%09private void dump(List%3CRemoteViewsAction%3E actions) %7B%0A
 %09%09for (R
@@ -1282,106 +1282,67 @@
 eof 
-SetLaunchPendingIntentAction) %7B%0A%09%09%09%09SetLaunchPendingIntentAction p = (SetLaunchPendingIntentAction
+IntentContainer) %7B%0A%09%09%09%09IntentContainer p = (IntentContainer
 ) ac
@@ -1450,123 +1450,165 @@
 eof 
-SetOnClickPendingIntentAction) %7B%0A%09%09%09%09SetOnClickPendingIntent
+ViewGroupAction) %7B%0A%09%09%09%09ViewGroup
 Action 
-p
+v
  = (
-SetOnClickPendingIntentAction) action;
+ViewGroupAction) action;%0A%09%09%09%09RemoteViewsInfo nested = v.getNestedViewsInfo(this);%0A%09%09%09%09if (nested != null) %7B
 %0A%09%09%09%09
+%09
 Log.
@@ -1636,129 +1636,144 @@
 r%22, 
-p.getContentIntent().toString());%0A%09%09%09%7D%0A%09%09%7D%0A%09%7D%0A%0A%09@Override%0A%09public void onNotificationRemoved(StatusBarNotification sbn) %7B
+%22nested views found====%22);%0A%09%09%09%09%09dump(nested.getActions());%0A%09%09%09%09%09Log.v(%22NotificationWatcher%22, %22======================%22);%0A%09%09%09%09%7D%0A%09%09%09%7D%0A%09%09%7D%0A%09
 %7D%0A%7D%0A

Update sample project