Change SoftAP Setup UI

Bug:20140630
Change-Id: I7f5696a5b78c70a6bc8ac38c5b99dd408e06a668
diff --git a/res/layout/wifi_ap_dialog.xml b/res/layout/wifi_ap_dialog.xml
index 7a038cb..5452cd0 100644
--- a/res/layout/wifi_ap_dialog.xml
+++ b/res/layout/wifi_ap_dialog.xml
@@ -67,30 +67,6 @@
                     android:prompt="@string/wifi_security"
                     android:entries="@array/wifi_ap_security" />
 
-            <TextView
-                    android:layout_width="match_parent"
-                    android:layout_height="wrap_content"
-                    style="@style/wifi_item_label"
-                    android:layout_marginTop="8dip"
-                    android:text="@string/wifi_ap_band_config" />
-
-               <RadioGroup android:id = "@+id/choose_channel"
-                       android:layout_width="fill_parent"
-                       android:layout_height="wrap_content"
-                       android:orientation="vertical">
-
-                   <RadioButton android:id="@+id/ap_2G_band"
-                           android:layout_width="match_parent"
-                           android:layout_height="wrap_content"
-                           android:text="@string/wifi_ap_choose_2G"
-                           android:layout_marginTop="8dip"/>
-
-                   <RadioButton android:id="@+id/ap_5G_band"
-                           android:layout_width="match_parent"
-                           android:layout_height="wrap_content"
-                           android:text="@string/wifi_ap_choose_5G"
-                           android:layout_marginTop="8dip"/>
-               </RadioGroup>
         </LinearLayout>
 
         <LinearLayout android:id="@+id/fields"
@@ -130,5 +106,26 @@
                     style="@style/wifi_item_content"
                     android:text="@string/wifi_show_password" />
         </LinearLayout>
+
+        <LinearLayout android:id="@+id/fields"
+                android:layout_width="match_parent"
+                android:layout_height="wrap_content"
+                style="@style/wifi_item"
+                android:orientation="vertical">
+
+                <TextView
+                    android:layout_width="match_parent"
+                    android:layout_height="wrap_content"
+                    style="@style/wifi_item_label"
+                    android:layout_marginTop="8dip"
+                    android:text="@string/wifi_ap_band_config" />
+
+                <Spinner android:id="@+id/choose_channel"
+                    android:layout_width="match_parent"
+                    android:layout_height="wrap_content"
+                    style="@style/wifi_item_content"
+                    android:prompt="@string/wifi_ap_band_config" />
+        </LinearLayout>
+
     </LinearLayout>
 </ScrollView>
diff --git a/res/values/arrays.xml b/res/values/arrays.xml
index c108a21..49a0037 100644
--- a/res/values/arrays.xml
+++ b/res/values/arrays.xml
@@ -324,6 +324,17 @@
         <item>AKA\'</item>
     </string-array>
 
+   <!-- Wi-Fi AP band settings.  Either 2.4GHz or 5GHz. -->
+   <!-- Note that adding/removing/moving the items will need wifi settings code change. -->
+    <string-array name="wifi_ap_band_config_full">
+        <item>@string/wifi_ap_choose_2G</item>
+        <item>@string/wifi_ap_choose_5G</item>
+    </string-array>
+
+    <string-array name="wifi_ap_band_config_2G_only">
+        <item>@string/wifi_ap_choose_2G</item>
+    </string-array>
+
    <!-- Wi-Fi WPS setup for p2p connections.  -->
    <!-- Note that adding/removing/moving the items will need wifi settings code change. -->
     <string-array name="wifi_p2p_wps_setup">
diff --git a/src/com/android/settings/wifi/WifiApDialog.java b/src/com/android/settings/wifi/WifiApDialog.java
index 3c4d912..d30457b 100644
--- a/src/com/android/settings/wifi/WifiApDialog.java
+++ b/src/com/android/settings/wifi/WifiApDialog.java
@@ -29,12 +29,11 @@
 import android.text.TextWatcher;
 import android.view.View;
 import android.widget.AdapterView;
+import android.widget.ArrayAdapter;
 import android.widget.CheckBox;
 import android.widget.EditText;
 import android.widget.Spinner;
 import android.widget.TextView;
-import android.widget.RadioGroup;
-import android.widget.RadioButton;
 
 import com.android.settings.R;
 
@@ -58,12 +57,11 @@
     private TextView mSsid;
     private int mSecurityTypeIndex = OPEN_INDEX;
     private EditText mPassword;
-    private RadioGroup mChannel;
-    private RadioButton mChannel2G;
-    private RadioButton mChannel5G;
+    private int mBandIndex = OPEN_INDEX;
 
     WifiConfiguration mWifiConfig;
     WifiManager mWifiManager;
+    private Context mContext;
 
     private static final String TAG = "WifiApDialog";
 
@@ -76,6 +74,7 @@
             mSecurityTypeIndex = getSecurityTypeIndex(wifiConfig);
         }
         mWifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
+        mContext =  context;
     }
 
     public static int getSecurityTypeIndex(WifiConfiguration wifiConfig) {
@@ -97,15 +96,7 @@
          */
         config.SSID = mSsid.getText().toString();
 
-        //obtain the band configure
-        if (mChannel2G.isChecked()) {
-            config.apBand = 0;
-        } else if(mChannel5G.isChecked()) {
-            config.apBand = 1;
-        } else {
-            Log.e("TAG", "AP band configure error!");
-            return null;
-        }
+        config.apBand = mBandIndex;
 
         switch (mSecurityTypeIndex) {
             case OPEN_INDEX:
@@ -126,9 +117,10 @@
 
     @Override
     protected void onCreate(Bundle savedInstanceState) {
-
+        boolean mInit = true;
         mView = getLayoutInflater().inflate(R.layout.wifi_ap_dialog, null);
         Spinner mSecurity = ((Spinner) mView.findViewById(R.id.security));
+        final Spinner mChannel = (Spinner) mView.findViewById(R.id.choose_channel);
 
         setView(mView);
         setInverseBackgroundForced(true);
@@ -140,20 +132,20 @@
         mSsid = (TextView) mView.findViewById(R.id.ssid);
         mPassword = (EditText) mView.findViewById(R.id.password);
 
-        mChannel = (RadioGroup) mView.findViewById(R.id.choose_channel);
-        mChannel2G = (RadioButton) mView.findViewById(R.id.ap_2G_band);
-        mChannel5G = (RadioButton) mView.findViewById(R.id.ap_5G_band);
-
+        ArrayAdapter <CharSequence> channelAdapter;
         String countryCode = mWifiManager.getCountryCode();
         if (!mWifiManager.is5GHzBandSupported() || countryCode == null) {
             //If no country code, 5GHz AP is forbidden
-            Log.e(TAG," NO country code, forbid 5GHz");
-            mChannel5G.setVisibility(View.INVISIBLE);
+            Log.i(TAG," NO country code, forbid 5GHz");
+            channelAdapter = ArrayAdapter.createFromResource(mContext,
+                    R.array.wifi_ap_band_config_2G_only, android.R.layout.simple_spinner_item);
             mWifiConfig.apBand = 0;
         } else {
-            mChannel5G.setVisibility(View.VISIBLE);
+            channelAdapter = ArrayAdapter.createFromResource(mContext,
+                    R.array.wifi_ap_band_config_full, android.R.layout.simple_spinner_item);
         }
 
+        channelAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
 
         setButton(BUTTON_SUBMIT, context.getString(R.string.wifi_save), mListener);
         setButton(DialogInterface.BUTTON_NEGATIVE,
@@ -162,9 +154,9 @@
         if (mWifiConfig != null) {
             mSsid.setText(mWifiConfig.SSID);
             if (mWifiConfig.apBand == 0) {
-                mChannel2G.setChecked(true);
+               mBandIndex = 0;
             } else {
-                mChannel5G.setChecked(true);
+               mBandIndex = 1;
             }
 
             mSecurity.setSelection(mSecurityTypeIndex);
@@ -173,6 +165,32 @@
             }
         }
 
+        mChannel.setAdapter(channelAdapter);
+        mChannel.setOnItemSelectedListener(
+                new AdapterView.OnItemSelectedListener() {
+                    boolean mInit = true;
+                    @Override
+                    public void onItemSelected(AdapterView<?> adapterView, View view, int position,
+                                               long id) {
+                        if (!mInit) {
+                            mBandIndex = position;
+                            mWifiConfig.apBand = mBandIndex;
+                            Log.i(TAG, "config on channelIndex : " + mBandIndex + " Band: " +
+                                    mWifiConfig.apBand);
+                        } else {
+                            mInit = false;
+                            mChannel.setSelection(mBandIndex);
+                        }
+
+                    }
+
+                    @Override
+                    public void onNothingSelected(AdapterView<?> adapterView) {
+
+                    }
+                }
+        );
+
         mSsid.addTextChangedListener(this);
         mPassword.addTextChangedListener(this);
         ((CheckBox) mView.findViewById(R.id.show_password)).setOnClickListener(this);