|
@@ -8,29 +8,45 @@ import android.media.Ringtone;
|
|
|
import android.media.RingtoneManager;
|
|
import android.media.RingtoneManager;
|
|
|
import android.net.Uri;
|
|
import android.net.Uri;
|
|
|
import android.support.v4.app.NotificationCompat;
|
|
import android.support.v4.app.NotificationCompat;
|
|
|
|
|
+import android.view.KeyEvent;
|
|
|
import android.widget.Toast;
|
|
import android.widget.Toast;
|
|
|
|
|
|
|
|
import com.example.david.libretasker.Events.Event;
|
|
import com.example.david.libretasker.Events.Event;
|
|
|
import com.example.david.libretasker.R;
|
|
import com.example.david.libretasker.R;
|
|
|
-import com.example.david.libretasker.State.State;
|
|
|
|
|
|
|
+import com.example.david.libretasker.Store.Store;
|
|
|
|
|
|
|
|
import java.util.ArrayList;
|
|
import java.util.ArrayList;
|
|
|
import java.util.Arrays;
|
|
import java.util.Arrays;
|
|
|
import java.util.HashMap;
|
|
import java.util.HashMap;
|
|
|
|
|
+import java.util.List;
|
|
|
|
|
|
|
|
import static android.content.Context.NOTIFICATION_SERVICE;
|
|
import static android.content.Context.NOTIFICATION_SERVICE;
|
|
|
|
|
+import static android.view.KeyEvent.KEYCODE_MEDIA_NEXT;
|
|
|
|
|
+import static android.view.KeyEvent.KEYCODE_MEDIA_PAUSE;
|
|
|
|
|
+import static android.view.KeyEvent.KEYCODE_MEDIA_PLAY;
|
|
|
|
|
+import static android.view.KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE;
|
|
|
|
|
+import static android.view.KeyEvent.KEYCODE_MEDIA_PREVIOUS;
|
|
|
|
|
+import static android.view.KeyEvent.KEYCODE_MEDIA_STOP;
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
* Created by david on 01/01/17.
|
|
* Created by david on 01/01/17.
|
|
|
*/
|
|
*/
|
|
|
|
|
|
|
|
public class Actions {
|
|
public class Actions {
|
|
|
|
|
+ static final List<Integer> MediaKeys = Arrays.asList(
|
|
|
|
|
+ KEYCODE_MEDIA_PREVIOUS,
|
|
|
|
|
+ KEYCODE_MEDIA_NEXT,
|
|
|
|
|
+ KEYCODE_MEDIA_PLAY,
|
|
|
|
|
+ KEYCODE_MEDIA_PAUSE,
|
|
|
|
|
+ KEYCODE_MEDIA_STOP,
|
|
|
|
|
+ KEYCODE_MEDIA_PLAY_PAUSE);
|
|
|
|
|
+
|
|
|
public static ArrayList<String> list() {
|
|
public static ArrayList<String> list() {
|
|
|
ArrayList<String> ret = new ArrayList<>();
|
|
ArrayList<String> ret = new ArrayList<>();
|
|
|
ret.add("Toast");
|
|
ret.add("Toast");
|
|
|
ret.add("Notification");
|
|
ret.add("Notification");
|
|
|
ret.add("Beep");
|
|
ret.add("Beep");
|
|
|
- ret.add("State");
|
|
|
|
|
|
|
+ ret.add("Store");
|
|
|
/*
|
|
/*
|
|
|
* Display: Lock, Auto brightness
|
|
* Display: Lock, Auto brightness
|
|
|
* Media: Music Play | skip | stop, Record audio, Record audio stop, Take Photo
|
|
* Media: Music Play | skip | stop, Record audio, Record audio stop, Take Photo
|
|
@@ -67,13 +83,14 @@ public class Actions {
|
|
|
Ringtone r = RingtoneManager.getRingtone(context.getApplicationContext(), notification);
|
|
Ringtone r = RingtoneManager.getRingtone(context.getApplicationContext(), notification);
|
|
|
r.play();
|
|
r.play();
|
|
|
return;
|
|
return;
|
|
|
- case "State":
|
|
|
|
|
|
|
+ case "Store":
|
|
|
HashMap<String, Object> s = (HashMap<String, Object>)payload;
|
|
HashMap<String, Object> s = (HashMap<String, Object>)payload;
|
|
|
- if (State.set((String) s.get("Key"), s.get("Value"))) { //Did the state change? Trigger events
|
|
|
|
|
|
|
+ /*if (Store.dispatch ((String) s.get("Key"), s.get("Value"))) { //Did the state change? Trigger events
|
|
|
Intent i = new Intent(Event.STATE_CHANGED);
|
|
Intent i = new Intent(Event.STATE_CHANGED);
|
|
|
- i.setData(Uri.parse("State"));
|
|
|
|
|
|
|
+ i.setData(Uri.parse("Store"));
|
|
|
context.sendBroadcast(i);
|
|
context.sendBroadcast(i);
|
|
|
- }
|
|
|
|
|
|
|
+ }*/
|
|
|
|
|
+ //FIXME
|
|
|
return;
|
|
return;
|
|
|
case "Volume":
|
|
case "Volume":
|
|
|
HashMap<String, Integer> v = (HashMap<String, Integer>)payload;
|
|
HashMap<String, Integer> v = (HashMap<String, Integer>)payload;
|
|
@@ -98,6 +115,15 @@ public class Actions {
|
|
|
audio.setStreamVolume(streamType, finalVolume, AudioManager.FLAG_REMOVE_SOUND_AND_VIBRATE);
|
|
audio.setStreamVolume(streamType, finalVolume, AudioManager.FLAG_REMOVE_SOUND_AND_VIBRATE);
|
|
|
//audio.setStreamVolume(streamType, finalVolume, AudioManager.FLAG_SHOW_UI);
|
|
//audio.setStreamVolume(streamType, finalVolume, AudioManager.FLAG_SHOW_UI);
|
|
|
return;
|
|
return;
|
|
|
|
|
+ case "MediaKey":
|
|
|
|
|
+ if ( !MediaKeys.contains((int)payload) )
|
|
|
|
|
+ throw new AssertionError("Payload is not a valid media keycode");
|
|
|
|
|
+
|
|
|
|
|
+ KeyEvent keyEvent = new KeyEvent(KeyEvent.ACTION_DOWN, (int)payload);
|
|
|
|
|
+ Intent intent = new Intent(Intent.ACTION_MEDIA_BUTTON);
|
|
|
|
|
+ intent.putExtra(Intent.EXTRA_KEY_EVENT, keyEvent);
|
|
|
|
|
+ context.sendBroadcast(intent);
|
|
|
|
|
+ return;
|
|
|
default:
|
|
default:
|
|
|
Toast.makeText(context, name + " " + (String)payload, Toast.LENGTH_SHORT).show();
|
|
Toast.makeText(context, name + " " + (String)payload, Toast.LENGTH_SHORT).show();
|
|
|
return;
|
|
return;
|