David 9 anni fa
parent
commit
3af79e913a

+ 1 - 0
.idea/inspectionProfiles/Project_Default.xml

@@ -1,6 +1,7 @@
 <component name="InspectionProjectProfileManager">
 <component name="InspectionProjectProfileManager">
   <profile version="1.0">
   <profile version="1.0">
     <option name="myName" value="Project Default" />
     <option name="myName" value="Project Default" />
+    <inspection_tool class="AndroidLintGradleCompatible" enabled="false" level="ERROR" enabled_by_default="false" />
     <inspection_tool class="LoggerInitializedWithForeignClass" enabled="false" level="WARNING" enabled_by_default="false">
     <inspection_tool class="LoggerInitializedWithForeignClass" enabled="false" level="WARNING" enabled_by_default="false">
       <option name="loggerClassName" value="org.apache.log4j.Logger,org.slf4j.LoggerFactory,org.apache.commons.logging.LogFactory,java.util.logging.Logger" />
       <option name="loggerClassName" value="org.apache.log4j.Logger,org.slf4j.LoggerFactory,org.apache.commons.logging.LogFactory,java.util.logging.Logger" />
       <option name="loggerFactoryMethodName" value="getLogger,getLogger,getLog,getLogger" />
       <option name="loggerFactoryMethodName" value="getLogger,getLogger,getLog,getLogger" />

+ 10 - 3
README.md

@@ -1,6 +1,6 @@
 LibreTasker is an event-based task performer, similar to Tasker.
 LibreTasker is an event-based task performer, similar to Tasker.
 
 
-This means that you can trigger Actions when events (filtered on input) occur, taking into consideration current state.
+This means that you can trigger Actions when events (filtered on input) occur, taking into consideration current state (which is the 'sum' of all events until now).
 
 
 Supported events (and their conditions):
 Supported events (and their conditions):
 - Network:
 - Network:
@@ -26,8 +26,6 @@ Supported events (and their conditions):
 	- Number (String)
 	- Number (String)
 	- State (String) { RINGING, IDLE }
 	- State (String) { RINGING, IDLE }
 
 
-There's an special event called 'State'. State takes a Key (String) and Value (Object). This gets triggered automatically when an Action with type 'State' **changes** its value.
-
 Supported Actions (and their parameters):
 Supported Actions (and their parameters):
 
 
 - Toast:
 - Toast:
@@ -61,3 +59,12 @@ If you don't want to be disturbed (except by someone in particular):
 - On PhoneCall with { Name : .. } or { Number:.. } with State == 'RINGING' -> Volume (Ringtone) to 100%
 - On PhoneCall with { Name : .. } or { Number:.. } with State == 'RINGING' -> Volume (Ringtone) to 100%
 - On PhoneCall with { Name : .. } or { Number:.. } with State == 'IDLE' -> Volume (Ringtone) to 0%
 - On PhoneCall with { Name : .. } or { Number:.. } with State == 'IDLE' -> Volume (Ringtone) to 0%
 - On SMS with { NameRegex : .. } or { Sender:.. } -> Volume (Notification) to 100%, Beep, Volume (Notification) to 0%
 - On SMS with { NameRegex : .. } or { Sender:.. } -> Volume (Notification) to 100%, Beep, Volume (Notification) to 0%
+
+
+And you can combine states:
+
+Events:
+- Time is between 09:00 and 18:00 and Wifi is { Connected, SSID = 'MySSID' } and you hang up with a contact(PhoneCall { State: IDLE, Name: 'Name' }
+
+Triggers:
+-> something

+ 1 - 0
app/build.gradle

@@ -30,5 +30,6 @@ dependencies {
     compile 'com.android.support:support-v4:24.2.1'
     compile 'com.android.support:support-v4:24.2.1'
     compile 'com.android.support:recyclerview-v7:24.2.1'
     compile 'com.android.support:recyclerview-v7:24.2.1'
     compile 'com.android.support:support-vector-drawable:24.2.1'
     compile 'com.android.support:support-vector-drawable:24.2.1'
+    compile 'org.honorato.multistatetogglebutton:multistatetogglebutton:0.2.2'
     testCompile 'junit:junit:4.12'
     testCompile 'junit:junit:4.12'
 }
 }

+ 131 - 0
app/src/main/java/com/example/david/libretasker/InputSelector/State.java

@@ -0,0 +1,131 @@
+package com.example.david.libretasker.InputSelector;
+
+import android.content.Context;
+import android.net.Uri;
+import android.os.Bundle;
+import android.support.v4.app.Fragment;
+import android.util.AttributeSet;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.view.ViewGroup;
+import android.widget.FrameLayout;
+import android.widget.TextView;
+
+import com.example.david.libretasker.R;
+
+import org.honorato.multistatetogglebutton.MultiStateToggleButton;
+
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.List;
+
+/**
+ * A simple {@link Fragment} subclass.
+ * Activities that contain this fragment must implement the
+ * {@link State.OnFragmentInteractionListener} interface
+ * to handle interaction events.
+ * Use the {@link State#newInstance} factory method to
+ * create an instance of this fragment.
+ */
+public class State extends Fragment {
+    // TODO: Rename parameter arguments, choose names that match
+    // the fragment initialization parameters, e.g. ARG_ITEM_NUMBER
+    private static final String ARG_ELEMS = "elems";
+    private static final String ARG_MULTI = "multi";
+    private static final String ARG_KEY = "key";
+
+    // TODO: Rename and change types of parameters
+    private String[] elems;
+    private boolean multi;
+    private String key;
+
+    private OnFragmentInteractionListener mListener;
+
+    public State() {
+        // Required empty public constructor
+    }
+
+    /**
+     * Use this factory method to create a new instance of
+     * this fragment using the provided parameters.
+     *
+     * @param elems Parameter 1.
+     * @param multi Parameter 2.
+     * @return A new instance of fragment State.
+     */
+    // TODO: Rename and change types and number of parameters
+    public static State newInstance(String[] elems, boolean multi, String key) {
+        State fragment = new State();
+        Bundle args = new Bundle();
+        args.putStringArray(ARG_ELEMS, elems);
+        args.putBoolean(ARG_MULTI, multi);
+        args.putString(ARG_KEY, key);
+        fragment.setArguments(args);
+        return fragment;
+    }
+
+    @Override
+    public void onCreate(Bundle savedInstanceState) {
+        super.onCreate(savedInstanceState);
+        if (getArguments() != null) {
+            elems = getArguments().getStringArray(ARG_ELEMS);
+            multi = getArguments().getBoolean(ARG_MULTI);
+            key =  getArguments().getString(ARG_KEY);
+        }
+    }
+
+    @Override
+    public View onCreateView(LayoutInflater inflater, ViewGroup container,
+                             Bundle savedInstanceState) {
+        // Inflate the layout for this fragment
+        View v = inflater.inflate(R.layout.fragment_state, container, false);
+        FrameLayout f = (FrameLayout) v.findViewById(R.id.statelayout);
+
+        TextView tv = (TextView) v.findViewById(R.id.textView5);
+        tv.setText(key);
+        MultiStateToggleButton button = (MultiStateToggleButton) v.findViewById(R.id.mstb_multi_id);
+        button.setElements(elems);
+        button.enableMultipleChoice(multi);
+        return v;
+    }
+
+    // TODO: Rename method, update argument and hook method into UI event
+    public void onButtonPressed(Uri uri) {
+        if (mListener != null) {
+            mListener.onFragmentInteraction(uri);
+        }
+    }
+
+    @Override
+    public void onAttach(Context context) {
+        super.onAttach(context);
+        /*if (context instanceof OnFragmentInteractionListener) {
+            mListener = (OnFragmentInteractionListener) context;
+        } else {
+            throw new RuntimeException(context.toString()
+                    + " must implement OnFragmentInteractionListener");
+        }*/
+
+    }
+
+    @Override
+    public void onDetach() {
+        super.onDetach();
+        mListener = null;
+    }
+
+    /**
+     * This interface must be implemented by activities that contain this
+     * fragment to allow an interaction in this fragment to be communicated
+     * to the activity and potentially other fragments contained in that
+     * activity.
+     * <p>
+     * See the Android Training lesson <a href=
+     * "http://developer.android.com/training/basics/fragments/communicating.html"
+     * >Communicating with Other Fragments</a> for more information.
+     */
+    public interface OnFragmentInteractionListener {
+        // TODO: Update argument type and name
+        void onFragmentInteraction(Uri uri);
+    }
+}

+ 109 - 0
app/src/main/java/com/example/david/libretasker/InputSelector/Text.java

@@ -0,0 +1,109 @@
+package com.example.david.libretasker.InputSelector;
+
+import android.content.Context;
+import android.net.Uri;
+import android.os.Bundle;
+import android.support.v4.app.Fragment;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.view.ViewGroup;
+
+import com.example.david.libretasker.R;
+
+/**
+ * A simple {@link Fragment} subclass.
+ * Activities that contain this fragment must implement the
+ * {@link Text.OnFragmentInteractionListener} interface
+ * to handle interaction events.
+ * Use the {@link Text#newInstance} factory method to
+ * create an instance of this fragment.
+ */
+public class Text extends Fragment {
+    // TODO: Rename parameter arguments, choose names that match
+    // the fragment initialization parameters, e.g. ARG_ITEM_NUMBER
+    private static final String ARG_PARAM1 = "param1";
+    private static final String ARG_PARAM2 = "param2";
+
+    // TODO: Rename and change types of parameters
+    private String mParam1;
+    private String mParam2;
+
+    private OnFragmentInteractionListener mListener;
+
+    public Text() {
+        // Required empty public constructor
+    }
+
+    /**
+     * Use this factory method to create a new instance of
+     * this fragment using the provided parameters.
+     *
+     * @param param1 Parameter 1.
+     * @param param2 Parameter 2.
+     * @return A new instance of fragment Text.
+     */
+    // TODO: Rename and change types and number of parameters
+    public static Text newInstance(String param1, String param2) {
+        Text fragment = new Text();
+        Bundle args = new Bundle();
+        args.putString(ARG_PARAM1, param1);
+        args.putString(ARG_PARAM2, param2);
+        fragment.setArguments(args);
+        return fragment;
+    }
+
+    @Override
+    public void onCreate(Bundle savedInstanceState) {
+        super.onCreate(savedInstanceState);
+        if (getArguments() != null) {
+            mParam1 = getArguments().getString(ARG_PARAM1);
+            mParam2 = getArguments().getString(ARG_PARAM2);
+        }
+    }
+
+    @Override
+    public View onCreateView(LayoutInflater inflater, ViewGroup container,
+                             Bundle savedInstanceState) {
+        // Inflate the layout for this fragment
+        return inflater.inflate(R.layout.fragment_text, container, false);
+    }
+
+    // TODO: Rename method, update argument and hook method into UI event
+    public void onButtonPressed(Uri uri) {
+        if (mListener != null) {
+            mListener.onFragmentInteraction(uri);
+        }
+    }
+
+    @Override
+    public void onAttach(Context context) {
+        super.onAttach(context);
+        /*if (context instanceof OnFragmentInteractionListener) {
+            mListener = (OnFragmentInteractionListener) context;
+        } else {
+            throw new RuntimeException(context.toString()
+                    + " must implement OnFragmentInteractionListener");
+        }*/
+    }
+
+    @Override
+    public void onDetach() {
+        super.onDetach();
+        mListener = null;
+    }
+
+    /**
+     * This interface must be implemented by activities that contain this
+     * fragment to allow an interaction in this fragment to be communicated
+     * to the activity and potentially other fragments contained in that
+     * activity.
+     * <p>
+     * See the Android Training lesson <a href=
+     * "http://developer.android.com/training/basics/fragments/communicating.html"
+     * >Communicating with Other Fragments</a> for more information.
+     */
+    public interface OnFragmentInteractionListener {
+        // TODO: Update argument type and name
+        void onFragmentInteraction(Uri uri);
+    }
+}

+ 7 - 1
app/src/main/java/com/example/david/libretasker/MainService.java

@@ -69,7 +69,13 @@ public class MainService extends Service {
         Phonecall n = new Phonecall(match);
         Phonecall n = new Phonecall(match);
         conditions.put("Phonecall", n);
         conditions.put("Phonecall", n);
 
 
-        Store.subscribe(createRunnable(conditions, new ArrayList<HashMap<String, Object>>()));
+
+        ArrayList<HashMap<String, Object>> actions = new ArrayList<HashMap<String, Object>>();
+        HashMap<String, Object> action = new HashMap<>();
+        action.put("Payload",Intent.ACTION_MEDIA_BUTTON);
+        action.put("Type","MediaKey");
+        actions.add(action);
+        Store.subscribe(createRunnable(conditions, actions));
 
 
         IntentFilter filter = new IntentFilter();
         IntentFilter filter = new IntentFilter();
         filter.addAction(ConnectivityManager.CONNECTIVITY_ACTION);
         filter.addAction(ConnectivityManager.CONNECTIVITY_ACTION);

+ 59 - 43
app/src/main/java/com/example/david/libretasker/NewEventActivity.java

@@ -1,21 +1,16 @@
 package com.example.david.libretasker;
 package com.example.david.libretasker;
 
 
-import android.content.Context;
-import android.content.Intent;
-import android.support.v7.app.AppCompatActivity;
 import android.os.Bundle;
 import android.os.Bundle;
-import android.view.LayoutInflater;
+import android.support.v4.app.FragmentTransaction;
+import android.support.v7.app.AppCompatActivity;
 import android.view.View;
 import android.view.View;
 import android.widget.AdapterView;
 import android.widget.AdapterView;
 import android.widget.ArrayAdapter;
 import android.widget.ArrayAdapter;
-import android.widget.Button;
-import android.widget.LinearLayout;
-import android.widget.ListView;
 import android.widget.Spinner;
 import android.widget.Spinner;
 
 
-import com.example.david.libretasker.Actions.Actions;
+import com.example.david.libretasker.InputSelector.State;
+import com.example.david.libretasker.InputSelector.Text;
 
 
-import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Arrays;
 import java.util.List;
 import java.util.List;
 
 
@@ -23,10 +18,12 @@ public class NewEventActivity extends AppCompatActivity {
 
 
     @Override
     @Override
     protected void onCreate(Bundle savedInstanceState) {
     protected void onCreate(Bundle savedInstanceState) {
+
+
         super.onCreate(savedInstanceState);
         super.onCreate(savedInstanceState);
         setContentView(R.layout.activity_new_event);
         setContentView(R.layout.activity_new_event);
         Spinner spinner = (Spinner) findViewById(R.id.spinner);
         Spinner spinner = (Spinner) findViewById(R.id.spinner);
-        List<String> l = Arrays.asList("Screen", "Network", "Phone");
+        List<String> l = Arrays.asList("Screen", "Time", "Network", "Phone");
         final ArrayAdapter<CharSequence> adapter = new ArrayAdapter(this, android.R.layout.simple_spinner_item, l);
         final ArrayAdapter<CharSequence> adapter = new ArrayAdapter(this, android.R.layout.simple_spinner_item, l);
         adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
         adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
         // Apply the adapter to the spinner
         // Apply the adapter to the spinner
@@ -35,15 +32,58 @@ public class NewEventActivity extends AppCompatActivity {
         spinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
         spinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
             @Override
             @Override
             public void onItemSelected(AdapterView<?> adapterView, View view, int pos, long id) {
             public void onItemSelected(AdapterView<?> adapterView, View view, int pos, long id) {
-                /*
-                //Actions.Launch(getApplicationContext(), "Toast", adapter.getItem(pos));
-                Button b = new Button(getApplicationContext());
-                b.setText(adapter.getItem(pos));
-                //View view = inflater.inflate(R.layout.activity_new_event, null);
-                LinearLayout ll = (LinearLayout) findViewById(R.id.EventFields);
-                ll.addView(b);*/
-                Intent i = new Intent(getApplicationContext(), EventDisplaySettings.class);
-                startActivity(i);
+
+                String[] a;
+                boolean multi;
+                if ( adapter.getItem(pos) == null )
+                    return;
+
+                FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
+
+                if ( adapter.getItem(pos).equals("Screen")) {
+                    a = new String[]{"On", "Off", "Any"};
+                    multi = false;
+                    ft.replace(R.id.your_placeholder, State.newInstance(a,multi,"Screen"));
+                    ft.commit();
+
+                } else if ( adapter.getItem(pos).equals("Time")) {
+                    Bundle args = new Bundle();
+
+                    String[] b = {"Jan", "Feb", "Mar", "April"};
+                    multi = true;
+
+                    State s2 = new State();
+                    args = new Bundle();
+                    args.putStringArray("elems", b);
+                    args.putBoolean("multi", multi);
+                    args.putString("key", "Months");
+                    s2.setArguments(args);
+
+                    ft.replace(R.id.your_placeholder, s2, "testtag2");
+
+                    State s = new State();
+                    a = new String[]{"Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"};
+                    multi = true;
+                    args = new Bundle();
+                    args.putString("key", "Days");
+                    args.putStringArray("elems", a);
+                    args.putBoolean("multi", multi);
+                    s.setArguments(args);
+
+                    ft.add(R.id.your_placeholder, s, "testtag1");
+                    ft.commit();
+//#####################################################################################################
+
+
+                    ft = getSupportFragmentManager().beginTransaction();
+                    ft.add(R.id.your_placeholder, Text.newInstance("asd","dsa"));
+                    ft.commit();
+                } else {
+                    return;
+                }
+                // or ft.add(R.id.your_placeholder, new FooFragment());
+
+
             }
             }
 
 
             @Override
             @Override
@@ -52,30 +92,6 @@ public class NewEventActivity extends AppCompatActivity {
             }
             }
         });
         });
 
 
-        ArrayList<String> list = new ArrayList<>();
-        list.add("Test1");
-        list.add("Test2");
-        ArrayAdapter ActionsAdapter = new ArrayAdapter( this, android.R.layout.simple_list_item_1, list);
 
 
-        ListView listview = (ListView) findViewById(R.id.ActionsList);
-        listview.setAdapter(ActionsAdapter);
-        listview.setOnItemClickListener(new AdapterView.OnItemClickListener() {
-
-            @Override
-            public void onItemClick(AdapterView<?> parent, final View view,
-                                    int position, long id) {
-                final String item = (String) parent.getItemAtPosition(position);
-                view.animate().setDuration(200).alpha(0)
-                        .withEndAction(new Runnable() {
-                            @Override
-                            public void run() {
-                                //list.remove(item);
-                                //ActionsAdapter .notifyDataSetChanged();
-                                view.setAlpha(1);
-                            }
-                        });
-            }
-
-        });
     }
     }
 }
 }

+ 0 - 2
app/src/main/res/layout/activity_main.xml

@@ -26,6 +26,4 @@
         android:layout_gravity="end|bottom"
         android:layout_gravity="end|bottom"
         android:layout_marginBottom="15dp"
         android:layout_marginBottom="15dp"
         android:layout_marginRight="15dp"/>
         android:layout_marginRight="15dp"/>
-    >
-
 </RelativeLayout>
 </RelativeLayout>

+ 24 - 7
app/src/main/res/layout/activity_new_event.xml

@@ -1,6 +1,14 @@
 <?xml version="1.0" encoding="utf-8"?>
 <?xml version="1.0" encoding="utf-8"?>
-<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+
+<ScrollView
+    xmlns:android="http://schemas.android.com/apk/res/android"
     xmlns:tools="http://schemas.android.com/tools"
     xmlns:tools="http://schemas.android.com/tools"
+    android:layout_width="match_parent"
+    android:layout_height="match_parent"
+    android:layout_weight="5">
+
+<LinearLayout
+
     android:id="@+id/activity_new_event"
     android:id="@+id/activity_new_event"
     android:layout_width="match_parent"
     android:layout_width="match_parent"
     android:layout_height="match_parent"
     android:layout_height="match_parent"
@@ -13,6 +21,12 @@
     android:weightSum="1">
     android:weightSum="1">
 
 
 
 
+
+        <LinearLayout
+            android:layout_width="match_parent"
+            android:layout_height="wrap_content"
+            android:orientation="vertical" />
+
     <LinearLayout
     <LinearLayout
             android:orientation="horizontal"
             android:orientation="horizontal"
             android:layout_width="match_parent"
             android:layout_width="match_parent"
@@ -68,7 +82,13 @@
         android:orientation="horizontal"
         android:orientation="horizontal"
         android:layout_width="match_parent"
         android:layout_width="match_parent"
         android:layout_height="wrap_content"
         android:layout_height="wrap_content"
-        android:id="@+id/EventFields"></LinearLayout>
+        android:id="@+id/EventFields" />
+
+    <LinearLayout
+        android:id="@+id/your_placeholder"
+        android:orientation="vertical"
+        android:layout_width="match_parent"
+        android:layout_height="wrap_content" />
 
 
     <LinearLayout
     <LinearLayout
         android:orientation="horizontal"
         android:orientation="horizontal"
@@ -88,11 +108,8 @@
             android:layout_height="wrap_content"
             android:layout_height="wrap_content"
             android:id="@+id/button"
             android:id="@+id/button"
             android:layout_weight="1" />
             android:layout_weight="1" />
-    </LinearLayout>
 
 
-    <ListView
-        android:layout_width="match_parent"
-        android:layout_height="match_parent"
-        android:id="@+id/ActionsList"/>
+    </LinearLayout>
 
 
 </LinearLayout>
 </LinearLayout>
+</ScrollView>

+ 31 - 0
app/src/main/res/layout/fragment_state.xml

@@ -0,0 +1,31 @@
+<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
+    xmlns:tools="http://schemas.android.com/tools"
+    xmlns:mstb="http://schemas.android.com/apk/res-auto"
+    android:id="@+id/statelayout"
+    android:layout_width="match_parent"
+    android:layout_height="wrap_content"
+    tools:context="com.example.david.libretasker.InputSelector.State">
+
+    <LinearLayout
+        android:orientation="vertical"
+        android:layout_width="match_parent"
+        android:layout_height="wrap_content">
+
+        <TextView
+            android:text="TextView"
+            android:layout_width="match_parent"
+            android:layout_height="wrap_content"
+            android:id="@+id/textView5"
+            android:textAppearance="@style/TextAppearance.AppCompat"/>
+
+        <org.honorato.multistatetogglebutton.MultiStateToggleButton
+            android:id="@+id/mstb_multi_id"
+            android:layout_width="match_parent"
+            android:layout_height="wrap_content"
+            android:layout_marginTop="10dip"
+            mstb:mstbPrimaryColor="@color/black"
+            mstb:mstbSecondaryColor="@color/gray"
+            />
+    </LinearLayout>
+
+</FrameLayout>

+ 15 - 0
app/src/main/res/layout/fragment_text.xml

@@ -0,0 +1,15 @@
+<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
+    xmlns:tools="http://schemas.android.com/tools"
+    android:layout_width="match_parent"
+    android:layout_height="match_parent"
+    tools:context="com.example.david.libretasker.InputSelector.Text">
+
+    <!-- TODO: Update blank fragment layout -->
+    <TextView
+        android:layout_width="match_parent"
+        android:layout_height="209dp"
+        android:text="@string/hello_blank_fragment"
+        android:layout_gravity="bottom"
+        android:textAppearance="@style/TextAppearance.AppCompat.Display2" />
+
+</FrameLayout>

+ 2 - 0
app/src/main/res/values/colors.xml

@@ -3,4 +3,6 @@
     <color name="colorPrimary">#3f51b5</color>
     <color name="colorPrimary">#3f51b5</color>
     <color name="colorPrimaryDark">#303F9F</color>
     <color name="colorPrimaryDark">#303F9F</color>
     <color name="colorAccent">#FF4081</color>
     <color name="colorAccent">#FF4081</color>
+    <color name="gray">#DDD</color>
+    <color name="black">#888</color>
 </resources>
 </resources>