|
|
@@ -1,91 +0,0 @@
|
|
|
-package com.example.david.libretasker;
|
|
|
-
|
|
|
-import android.telephony.TelephonyManager;
|
|
|
-import android.annotation.TargetApi;
|
|
|
-import android.content.BroadcastReceiver;
|
|
|
-import android.content.Context;
|
|
|
-import android.content.Intent;
|
|
|
-import android.net.ConnectivityManager;
|
|
|
-import android.os.Build;
|
|
|
-import android.os.Bundle;
|
|
|
-import android.provider.Telephony;
|
|
|
-import android.telephony.SmsMessage;
|
|
|
-import android.util.Log;
|
|
|
-
|
|
|
-import com.example.david.libretasker.Actions.Actions;
|
|
|
-import com.example.david.libretasker.Events.Event;
|
|
|
-import com.example.david.libretasker.Events.NetworkEvent;
|
|
|
-import com.example.david.libretasker.Events.PhoneEvent;
|
|
|
-import com.example.david.libretasker.Events.SMSEvent;
|
|
|
-import com.example.david.libretasker.Events.ScreenEvent;
|
|
|
-import com.example.david.libretasker.Events.StateEvent;
|
|
|
-import com.example.david.libretasker.Events.TimeEvent;
|
|
|
-import com.example.david.libretasker.UserData.UserData;
|
|
|
-
|
|
|
-import java.util.ArrayList;
|
|
|
-import java.util.HashMap;
|
|
|
-
|
|
|
-/**
|
|
|
- * Created by david on 01/01/17.
|
|
|
- */
|
|
|
-
|
|
|
-public class EventReceiver extends BroadcastReceiver {
|
|
|
- String TAG = " EventReceiver";
|
|
|
- @Override
|
|
|
- public void onReceive(Context context, Intent intent) {
|
|
|
- Event e = null;
|
|
|
- HashMap<String, Object> data = new HashMap<>();
|
|
|
- HashMap<String, Object> eventData;
|
|
|
- ArrayList<HashMap<String, Object>> actions;
|
|
|
-
|
|
|
- switch (intent.getAction()) {
|
|
|
- case ConnectivityManager.CONNECTIVITY_ACTION:
|
|
|
- e = new NetworkEvent();
|
|
|
- data = UserData.getData("Network");
|
|
|
- break;
|
|
|
- case Intent.ACTION_TIME_TICK:
|
|
|
- case Intent.ACTION_TIME_CHANGED:
|
|
|
- case Intent.ACTION_TIMEZONE_CHANGED:
|
|
|
- e = new TimeEvent();
|
|
|
- data = UserData.getData("DateTime");
|
|
|
- break;
|
|
|
-
|
|
|
- case Intent.ACTION_SCREEN_ON:
|
|
|
- case Intent.ACTION_SCREEN_OFF:
|
|
|
- e = new ScreenEvent();
|
|
|
- data = UserData.getData("Screen");
|
|
|
- break;
|
|
|
- case Telephony.Sms.Intents.SMS_RECEIVED_ACTION:
|
|
|
- e = new SMSEvent();
|
|
|
- data = UserData.getData("SMS");
|
|
|
- break;
|
|
|
- case Event.STATE_CHANGED:
|
|
|
- e = new StateEvent();
|
|
|
- String s = intent.getDataString();
|
|
|
-
|
|
|
- break;
|
|
|
- case TelephonyManager.ACTION_PHONE_STATE_CHANGED:
|
|
|
- e = new PhoneEvent();
|
|
|
- data = UserData.getData("PhoneCall");
|
|
|
- break;
|
|
|
- default:
|
|
|
- Log.d(TAG, intent.getAction());
|
|
|
- return;
|
|
|
- }
|
|
|
-
|
|
|
- if ( e == null )
|
|
|
- return;
|
|
|
-
|
|
|
- if ( data == null )
|
|
|
- throw new AssertionError("Data is null! WTF!");
|
|
|
-
|
|
|
- actions = (ArrayList<HashMap<String, Object>>)data.get("Actions");
|
|
|
- eventData = (HashMap<String, Object>)data.get("Event");
|
|
|
- eventData.put("Intent", intent);
|
|
|
- if (e.trigger(context, eventData)) {
|
|
|
- for (HashMap<String, Object> a : actions) {
|
|
|
- Actions.Launch(context, (String) a.get("Type"), a.get("Value"));
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-}
|