David il y a 9 ans
Parent
commit
e8c1aed80c

+ 1 - 0
app/src/main/java/com/example/david/libretasker/Helpers.java

@@ -11,6 +11,7 @@ import android.provider.ContactsContract;
  */
 
 public class Helpers {
+    public static int globalID = 10000;
     public static String getContactName(Context context, String phoneNumber) {
         ContentResolver cr = context.getContentResolver();
         Uri uri = Uri.withAppendedPath(ContactsContract.PhoneLookup.CONTENT_FILTER_URI, Uri.encode(phoneNumber));

+ 216 - 0
app/src/main/java/com/example/david/libretasker/InputSelector/Event.java

@@ -0,0 +1,216 @@
+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.support.v4.app.FragmentTransaction;
+import android.util.AttributeSet;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.view.ViewGroup;
+import android.widget.AdapterView;
+import android.widget.ArrayAdapter;
+import android.widget.LinearLayout;
+import android.widget.Spinner;
+import android.widget.TextView;
+
+import com.example.david.libretasker.Helpers;
+import com.example.david.libretasker.R;
+
+import java.util.Arrays;
+import java.util.List;
+
+/**
+ * A simple {@link Fragment} subclass.
+ * Activities that contain this fragment must implement the
+ * {@link Event.OnFragmentInteractionListener} interface
+ * to handle interaction events.
+ * Use the {@link Event#newInstance} factory method to
+ * create an instance of this fragment.
+ */
+public class Event 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";
+    private LinearLayout fragmentContainer;
+
+    // TODO: Rename and change types of parameters
+    private String mParam1;
+    private String mParam2;
+
+    private OnFragmentInteractionListener mListener;
+
+    public Event() {
+        // 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 Event.
+     */
+    // TODO: Rename and change types and number of parameters
+    public static Event newInstance(String param1, String param2) {
+        Event fragment = new Event();
+        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
+        //View v = inflater.inflate(R.layout.fragment_event, container, false);
+        LinearLayout root = new LinearLayout(getContext());
+        LinearLayout spinnerContainer = new LinearLayout(getContext());
+
+        root.setOrientation(LinearLayout.VERTICAL);
+
+        fragmentContainer = new LinearLayout(getContext());
+        fragmentContainer.setOrientation(LinearLayout.VERTICAL);
+        fragmentContainer.setId(Helpers.globalID++);
+
+
+        Spinner spinner = new Spinner(getContext());
+        spinner.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT, 1f));
+
+        TextView spinnerLabel = new TextView(getContext());
+        spinnerLabel.setText("Event Type");
+        spinnerLabel.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT, 2f));
+
+        spinnerContainer.addView(spinnerLabel);
+        spinnerContainer.addView(spinner);
+
+        root.addView(spinnerContainer);
+        root.addView(fragmentContainer);
+//        v.setLayoutParams(ll.getLayoutParams());
+
+
+
+        //Spinner spinner = (Spinner) v.findViewById(R.id.spinner);
+        List<String> l = Arrays.asList("Screen", "Time", "Network", "Phone", "SMS");
+        final ArrayAdapter<CharSequence> adapter = new ArrayAdapter(getContext(), android.R.layout.simple_spinner_item, l);
+        adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
+        // Apply the adapter to the spinner
+        spinner.setAdapter(adapter);
+
+
+        //v.setLayoutParams(ll.getLayoutParams());
+
+
+        spinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
+            @Override
+            public void onItemSelected(AdapterView<?> adapterView, View view, int pos, long id) {
+
+                String[] a;
+                boolean multi;
+                if ( adapter.getItem(pos) == null )
+                    return;
+
+
+                int fragmentID = fragmentContainer.getId();
+                //R.id.your_placeholder;
+                //v.findViewWithTag("container").getId(); //v.findViewById(R.id.your_placeholder).getId();
+                
+                FragmentTransaction ft = getFragmentManager().beginTransaction();
+                if ( adapter.getItem(pos).equals("Screen")) {
+                    a = new String[]{"On", "Off", "Any"};
+                    ft.replace(fragmentID, MultiStateInRows.newInstance(a, false, "State", 1));
+                    ft.commit();
+
+                } else if ( adapter.getItem(pos).equals("Time")) {
+                    a = new String[]{"Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"};
+                    ft.replace(fragmentID, MultiStateInRows.newInstance(a, true, "Months", 2 ));
+
+                    a = new String[]{"Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"};
+                    ft.add(fragmentID, MultiStateInRows.newInstance(a, true, "DOW", 1 ));
+
+                    a = new String[31];
+                    for (int i = 0; i< a.length; i++)
+                        a[i]=Integer.toString(i+1);
+                    ft.add(fragmentID, MultiStateInRows.newInstance(a, true, "DOM", 4 ));
+
+                    a = new String[24];
+                    for (int i = 0; i< a.length; i++)
+                        a[i]=Integer.toString(i);
+
+                    ft.add(fragmentID, MultiStateInRows.newInstance(a, true, "Hour", 2 ));
+
+                    //TODO: Minutes
+
+
+                    ft.commit();
+                } else if ( adapter.getItem(pos).equals("SMS") ) {
+                    ft.replace(fragmentID, Contact.newInstance());
+                    ft.add(fragmentID, Text.newInstance("Body"));
+                    ft.commit();
+                } else if ( adapter.getItem(pos).equals("Phone") ) {
+                    a = new String[]{"Ringing", "Idle", "Any"};
+                    ft.replace(fragmentID, Contact.newInstance());
+                    ft.add(fragmentID, MultiStateInRows.newInstance(a, false, "State", 1));
+                    ft.commit();
+                } else if ( adapter.getItem(pos).equals("Network") ) {
+                    ft.replace(fragmentID, Network.newInstance());
+                    ft.commit();
+                }
+            }
+
+            @Override
+            public void onNothingSelected(AdapterView<?> adapterView) {
+
+            }
+        });
+        //return v;
+        return root;
+    }
+
+    // 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);
+    }
+
+    @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);
+    }
+}

+ 12 - 72
app/src/main/java/com/example/david/libretasker/NewEventActivity.java

@@ -4,90 +4,30 @@ import android.os.Bundle;
 import android.support.v4.app.FragmentTransaction;
 import android.support.v7.app.AppCompatActivity;
 import android.view.View;
-import android.widget.AdapterView;
-import android.widget.ArrayAdapter;
-import android.widget.Spinner;
+import android.widget.Button;
 
-import com.example.david.libretasker.InputSelector.Contact;
-import com.example.david.libretasker.InputSelector.MultiStateInRows;
-import com.example.david.libretasker.InputSelector.Text;
-import com.example.david.libretasker.InputSelector.Network;
+import com.example.david.libretasker.InputSelector.Event;
 
-import java.util.Arrays;
-import java.util.List;
+import java.util.ArrayList;
 
 public class NewEventActivity extends AppCompatActivity {
 
+    ArrayList<Event> events = new ArrayList<>();
+
     @Override
     protected void onCreate(Bundle savedInstanceState) {
         super.onCreate(savedInstanceState);
         setContentView(R.layout.activity_new_event);
-        Spinner spinner = (Spinner) findViewById(R.id.spinner);
-        List<String> l = Arrays.asList("Screen", "Time", "Network", "Phone", "SMS");
-        final ArrayAdapter<CharSequence> adapter = new ArrayAdapter(this, android.R.layout.simple_spinner_item, l);
-        adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
-        // Apply the adapter to the spinner
-        spinner.setAdapter(adapter);
-
-        spinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
+        Button event = (Button) findViewById(R.id.addEventButton);
+        event.setOnClickListener(new View.OnClickListener() {
             @Override
-            public void onItemSelected(AdapterView<?> adapterView, View view, int pos, long id) {
-
-                String[] a;
-                boolean multi;
-                if ( adapter.getItem(pos) == null )
-                    return;
-
+            public void onClick(View view) {
                 FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
-
-                if ( adapter.getItem(pos).equals("Screen")) {
-                    a = new String[]{"On", "Off", "Any"};
-                    ft.replace(R.id.your_placeholder, MultiStateInRows.newInstance(a, false, "State", 1));
-                    ft.commit();
-
-                } else if ( adapter.getItem(pos).equals("Time")) {
-                    a = new String[]{"Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"};
-                    ft.replace(R.id.your_placeholder, MultiStateInRows.newInstance(a, true, "Months", 2 ));
-
-                    a = new String[]{"Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"};
-                    ft.add(R.id.your_placeholder, MultiStateInRows.newInstance(a, true, "DOW", 1 ));
-
-                    a = new String[31];
-                    for (int i = 0; i< a.length; i++)
-                        a[i]=Integer.toString(i+1);
-                    ft.add(R.id.your_placeholder, MultiStateInRows.newInstance(a, true, "DOM", 4 ));
-
-                    a = new String[24];
-                    for (int i = 0; i< a.length; i++)
-                        a[i]=Integer.toString(i);
-
-                    ft.add(R.id.your_placeholder, MultiStateInRows.newInstance(a, true, "Hour", 2 ));
-
-                    //TODO: Minutes
-
-
-                    ft.commit();
-                } else if ( adapter.getItem(pos).equals("SMS") ) {
-                    ft.replace(R.id.your_placeholder, Contact.newInstance());
-                    ft.add(R.id.your_placeholder, Text.newInstance("Body"));
-                    ft.commit();
-                } else if ( adapter.getItem(pos).equals("Phone") ) {
-                    a = new String[]{"Ringing", "Idle", "Any"};
-                    ft.replace(R.id.your_placeholder, Contact.newInstance());
-                    ft.add(R.id.your_placeholder, MultiStateInRows.newInstance(a, false, "State", 1));
-                    ft.commit();
-                } else if ( adapter.getItem(pos).equals("Network") ) {
-                    ft.replace(R.id.your_placeholder, Network.newInstance());
-                    ft.commit();
-                }
-            }
-
-            @Override
-            public void onNothingSelected(AdapterView<?> adapterView) {
-
+                Event e = new Event();
+                events.add(e);
+                ft.add(R.id.eventContainer, e);
+                ft.commit();
             }
         });
-
-
     }
 }

+ 17 - 50
app/src/main/res/layout/activity_new_event.xml

@@ -19,10 +19,6 @@
     android:orientation="vertical"
     tools:context="com.example.david.libretasker.NewEventActivity"
     android:weightSum="1">
-    <LinearLayout
-        android:layout_width="match_parent"
-        android:layout_height="wrap_content"
-        android:orientation="vertical" />
 
     <LinearLayout
             android:orientation="horizontal"
@@ -31,7 +27,7 @@
             android:layout_gravity="center_vertical">
 
             <TextView
-                android:text="Name"
+                android:text="Profile name"
                 android:layout_width="fill_parent"
                 android:layout_height="wrap_content"
                 android:id="@+id/textView"
@@ -44,62 +40,33 @@
                 android:layout_weight="1"
                 android:id="@+id/editText" />
 
-        </LinearLayout>
-
-        <LinearLayout
-            android:orientation="horizontal"
-            android:layout_width="match_parent"
-            android:layout_height="wrap_content">
-
-            <TextView
-                android:text="Event"
-                android:layout_width="fill_parent"
-                android:layout_height="wrap_content"
-                android:id="@+id/textView2"
-                android:layout_gravity="center_vertical"
-                android:layout_weight="2"   />
-
-            <Spinner
-                android:layout_width="fill_parent"
-                android:layout_height="wrap_content"
-                android:id="@+id/spinner"
-                android:layout_gravity="center_vertical"
-                android:layout_weight="1" />
+    </LinearLayout>
 
-        </LinearLayout>
 
     <LinearLayout
-        android:orientation="horizontal"
+        android:orientation="vertical"
+        android:layout_width="match_parent"
+        android:layout_height="match_parent"
+        android:id="@+id/eventContainer"></LinearLayout>
+
+    <Button
+        android:text="Add Event"
         android:layout_width="match_parent"
         android:layout_height="wrap_content"
-        android:id="@+id/EventFields" />
+        android:id="@+id/addEventButton" />
 
     <LinearLayout
-        android:id="@+id/your_placeholder"
         android:orientation="vertical"
         android:layout_width="match_parent"
-        android:layout_height="wrap_content" />
+        android:layout_height="match_parent"
+        android:id="@+id/actionContainer"></LinearLayout>
 
-    <LinearLayout
-        android:orientation="horizontal"
+    <Button
+        android:text="Add Action"
         android:layout_width="match_parent"
-        android:layout_height="wrap_content">
-
-        <TextView
-            android:text="Actions"
-            android:layout_width="wrap_content"
-            android:id="@+id/textView3"
-            android:layout_height="wrap_content"
-            android:layout_weight="5" />
-
-        <Button
-            android:text="+"
-            android:layout_width="wrap_content"
-            android:layout_height="wrap_content"
-            android:id="@+id/button"
-            android:layout_weight="1" />
-
-    </LinearLayout>
+        android:layout_height="wrap_content"
+        android:id="@+id/addActionButton"
+        android:layout_weight="1" />
 
 </LinearLayout>
 </ScrollView>

+ 1 - 1
app/src/main/res/layout/fragment_contact.xml

@@ -25,7 +25,7 @@
             android:ems="10"
             android:id="@+id/contactName"
             android:layout_weight="1"
-            android:singleLine="true" />
+            android:maxLines="1" />
     </LinearLayout>
 
     <LinearLayout

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

@@ -1,29 +0,0 @@
-<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.MultiState">
-
-    <LinearLayout
-        android:orientation="vertical"
-        android:layout_width="match_parent"
-        android:layout_height="wrap_content">
-
-        <TextView
-            android:layout_width="match_parent"
-            android:layout_height="wrap_content"
-            android:id="@+id/textView5" />
-
-        <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>