David 9 лет назад
Родитель
Сommit
1f65f8e891

+ 4 - 4
app/src/main/AndroidManifest.xml

@@ -4,8 +4,10 @@
     android:installLocation="internalOnly">
 
     <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
-    <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
+    <uses-permission android:name="android.permission.CHANGE_NETWORK_STATE"/>
+    <uses-permission android:name="android.permission.CHANGE_WIFI_STATE"/>
     <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
+    <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
     <uses-permission android:name="android.permission.RECEIVE_SMS" />
     <uses-permission android:name="android.permission.READ_SMS" />
     <uses-permission android:name="android.permission.SEND_SMS" />
@@ -44,9 +46,7 @@
             android:enabled="true" />
 
         <activity android:name=".NewEventActivity" />
-        <activity
-            android:name=".EventDisplaySettings"
-            android:label="@string/title_activity_event_display_settings" />
+
     </application>
 
 </manifest>

+ 1 - 1
app/src/main/java/com/example/david/libretasker/InputSelector/MultiList.java

@@ -138,7 +138,7 @@ public class MultiList extends Fragment {
                 view.setLayoutParams(new ViewGroup.LayoutParams(desiredWidth, FrameLayout.LayoutParams.WRAP_CONTENT));
 
             view.measure(desiredWidth, View.MeasureSpec.UNSPECIFIED);
-            totalHeight += view.getMeasuredHeight();
+            totalHeight += view.getMeasuredHeight()*1.5;
         }
         ViewGroup.LayoutParams params = listView.getLayoutParams();
         params.height = totalHeight + (listView.getDividerHeight() * (listAdapter.getCount() - 1));

+ 159 - 0
app/src/main/java/com/example/david/libretasker/InputSelector/Network.java

@@ -0,0 +1,159 @@
+package com.example.david.libretasker.InputSelector;
+
+import android.content.Context;
+import android.net.Uri;
+import android.net.wifi.WifiConfiguration;
+import android.net.wifi.WifiManager;
+import android.os.Bundle;
+import android.support.v4.app.Fragment;
+import android.support.v4.app.FragmentTransaction;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.view.ViewGroup;
+import android.widget.AdapterView;
+import android.widget.ArrayAdapter;
+import android.widget.Spinner;
+
+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 Network.OnFragmentInteractionListener} interface
+ * to handle interaction events.
+ * Use the {@link Network#newInstance} factory method to
+ * create an instance of this fragment.
+ */
+public class Network 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 Network() {
+        // Required empty public constructor
+    }
+
+    // TODO: Rename and change types and number of parameters
+    public static Network newInstance() {
+        return new Network();
+    }
+
+    @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_wifi, container, false);
+        Spinner state = (Spinner) v.findViewById(R.id.NetworkStateSpinner);
+        List<String> l = Arrays.asList("Connected", "Connecting", "Disconnected", "Disconnecting");
+        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
+        state.setAdapter(adapter);
+
+        Spinner type = (Spinner) v.findViewById(R.id.NetworkTypeSpinner);
+        List<String> ltype = Arrays.asList("Wifi", "Mobile", "VPN");
+        final ArrayAdapter<CharSequence> typeadapter = new ArrayAdapter(getContext(), android.R.layout.simple_spinner_item, ltype);
+        typeadapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
+        // Apply the adapter to the spinner
+        type.setAdapter(typeadapter);
+
+        type.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
+            Fragment f = null;
+            @Override
+            public void onItemSelected(AdapterView<?> adapterView, View view, int pos, long id) {
+                if ( typeadapter.getItem(pos) == null )
+                    return;
+                FragmentTransaction ft = getFragmentManager().beginTransaction();
+
+                if ( typeadapter.getItem(pos).equals("Wifi")) {
+                    String[] a = new String[]{"On", "Off", "Any"};
+                    f = MultiList.newInstance("SSIDs", connectionInfo());
+                    ft.replace(R.id.networkFrame, f);
+                    ft.commit();
+                } else {
+                    if ( f != null ) {
+                         ft.remove(f);
+                        ft.commit();
+                    }
+                }
+
+            }
+
+            @Override
+            public void onNothingSelected(AdapterView<?> adapterView) {
+
+            }
+        });
+
+        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);
+    }
+
+    @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);
+    }
+
+    private String[] connectionInfo() {
+        WifiManager wm = (WifiManager) getContext().getSystemService(Context.WIFI_SERVICE);
+        if ( !wm.isWifiEnabled() ) {
+            wm.setWifiEnabled(true);
+        }
+        List<WifiConfiguration> configs = wm.getConfiguredNetworks();
+        if (configs == null)
+            return null;
+
+        String[] SSIDs = new String[configs.size()];
+        int i = 0;
+        for (WifiConfiguration c : configs)
+            SSIDs[i++] = c.SSID.substring(1, c.SSID.length()-1);
+        Arrays.sort(SSIDs);
+        return SSIDs;
+    }
+}

+ 3 - 4
app/src/main/java/com/example/david/libretasker/NewEventActivity.java

@@ -11,6 +11,7 @@ import android.widget.Spinner;
 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 java.util.Arrays;
 import java.util.List;
@@ -75,12 +76,10 @@ public class NewEventActivity extends AppCompatActivity {
                     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();
                 }
-                // or ft.add(R.id.your_placeholder, new FooFragment());
-
-
             }
 
             @Override

+ 70 - 0
app/src/main/res/layout/fragment_wifi.xml

@@ -0,0 +1,70 @@
+<LinearLayout 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.Network"
+    android:id="@+id/wifiLayout"
+    android:orientation="vertical">
+
+    <LinearLayout
+        android:orientation="horizontal"
+        android:layout_width="match_parent"
+        android:layout_height="wrap_content"
+        android:paddingTop="10dp">
+
+        <TextView
+            android:text="State"
+            android:layout_width="match_parent"
+            android:layout_height="wrap_content"
+            android:id="@+id/textView6"
+            android:layout_weight="1" />
+
+        <Spinner
+            android:layout_width="match_parent"
+            android:layout_height="wrap_content"
+            android:id="@+id/NetworkStateSpinner"
+            android:layout_weight="1" />
+    </LinearLayout>
+
+
+
+    <LinearLayout
+        android:orientation="horizontal"
+        android:layout_width="match_parent"
+        android:layout_height="wrap_content"
+        android:paddingTop="10dp">
+
+        <TextView
+            android:text="Type"
+            android:layout_width="match_parent"
+            android:layout_height="wrap_content"
+            android:id="@+id/textView4"
+            android:layout_weight="1" />
+
+        <Spinner
+            android:layout_width="match_parent"
+            android:layout_height="wrap_content"
+            android:id="@+id/NetworkTypeSpinner"
+            android:layout_weight="1" />
+
+
+
+
+    </LinearLayout>
+    <TextView
+        android:text="SSIDs"
+        android:layout_width="match_parent"
+        android:layout_height="wrap_content"
+        android:id="@+id/textView7"
+        android:layout_weight="1" />
+
+    <FrameLayout
+        android:layout_width="match_parent"
+        android:layout_height="wrap_content"
+        android:layout_weight="1"
+        android:id="@+id/networkFrame"
+        android:layout_marginTop="10dp"
+        android:layout_marginBottom="10dp">
+
+    </FrameLayout>
+</LinearLayout>