packages/apps/Settings
Revision | e8be961a4f52c50ccc3df610fe4c662d2cc7ef00 (tree) |
---|---|
Time | 2011-08-05 15:37:51 |
Author | Nicu Pavel <npavel@mini...> |
Commiter | Chih-Wei Huang |
Added Ethernet Settings based on Yi Sun's patch from android-x86.org
Change-Id: I6da2c35d6609bdd980a02de9794d7dec43b640dd
@@ -71,6 +71,41 @@ | ||
71 | 71 | </intent-filter> |
72 | 72 | </activity> |
73 | 73 | |
74 | + <!-- Ethernet controls --> | |
75 | + <activity android:name="EthernetSettings" | |
76 | + android:label="@string/eth_radio_ctrl_title" | |
77 | + > | |
78 | + <intent-filter> | |
79 | + <action android:name="android.intent.action.MAIN" /> | |
80 | + <action android:name="android.settings.ETHERNET_SETTINGS" /> | |
81 | + <category android:name="android.intent.category.DEFAULT" /> | |
82 | + <category android:name="android.intent.category.VOICE_LAUNCH" /> | |
83 | + </intent-filter> | |
84 | + </activity> | |
85 | + | |
86 | + <activity android:name=".ethernet.EthernetEnabler" android:label="@string/eth_setting" | |
87 | + android:clearTaskOnLaunch="true" | |
88 | + > | |
89 | + <intent-filter> | |
90 | + <action android:name="android.intent.action.MAIN" /> | |
91 | + <action android:name="android.settings.ETHERNET_SETTINGS" /> | |
92 | + <category android:name="android.intent.category.DEFAULT" /> | |
93 | + <category android:name="android.intent.category.VOICE_LAUNCH" /> | |
94 | + <category android:name="com.android.settings.SHORTCUT" /> | |
95 | + </intent-filter> | |
96 | + </activity> | |
97 | + <activity android:name=".ethernet.EthernetConfigure" android:label="@string/eth_conf_perf_title" | |
98 | + android:clearTaskOnLaunch="true" | |
99 | + > | |
100 | + <intent-filter> | |
101 | + <action android:name="android.intent.action.MAIN" /> | |
102 | + <action android:name="android.settings.ETHERNET_SETTINGS" /> | |
103 | + <category android:name="android.intent.category.DEFAULT" /> | |
104 | + <category android:name="android.intent.category.VOICE_LAUNCH" /> | |
105 | + <category android:name="com.android.settings.SHORTCUT" /> | |
106 | + </intent-filter> | |
107 | + </activity> | |
108 | + | |
74 | 109 | <!-- Wireless Controls --> |
75 | 110 | |
76 | 111 | <activity android:name="WirelessSettings" |
@@ -0,0 +1,112 @@ | ||
1 | +<?xml version="1.0" encoding="utf-8"?> | |
2 | +<ScrollView xmlns:android="http://schemas.android.com/apk/res/android" | |
3 | + android:layout_width="fill_parent" | |
4 | + android:layout_height="wrap_content"> | |
5 | + | |
6 | + <LinearLayout | |
7 | + android:layout_width="fill_parent" | |
8 | + android:layout_height="wrap_content" | |
9 | + android:padding="8dip" | |
10 | + android:orientation="vertical"> | |
11 | + | |
12 | + <LinearLayout | |
13 | + android:id="@+id/table" | |
14 | + android:layout_width="fill_parent" | |
15 | + android:layout_height="fill_parent" | |
16 | + android:orientation="vertical"> | |
17 | + </LinearLayout> | |
18 | + | |
19 | + <!-- Device list --> | |
20 | + | |
21 | + <TextView android:id="@+id/eth_dev_list_text" | |
22 | + style="?android:attr/textAppearanceSmallInverse" | |
23 | + android:layout_width="fill_parent" | |
24 | + android:layout_height="wrap_content" | |
25 | + android:layout_marginTop="8dip" | |
26 | + android:text="@string/eth_dev_list" /> | |
27 | + | |
28 | + <!-- The entries will be set programmatically --> | |
29 | + <Spinner android:id="@+id/eth_dev_spinner" | |
30 | + android:layout_width="fill_parent" | |
31 | + android:layout_height="wrap_content" /> | |
32 | + | |
33 | + <!-- Connection type --> | |
34 | + <TextView android:id="@+id/eth_con_type" | |
35 | + style="?android:attr/textAppearanceSmallInverse" | |
36 | + android:layout_width="fill_parent" | |
37 | + android:layout_height="wrap_content" | |
38 | + android:layout_marginTop="8dip" | |
39 | + android:text="@string/eth_con_type" /> | |
40 | + <RadioGroup android:id="@+id/con_type" | |
41 | + android:layout_width="fill_parent" | |
42 | + android:layout_height="wrap_content" | |
43 | + > | |
44 | + <RadioButton android:id="@+id/dhcp_radio" | |
45 | + style="?android:attr/textAppearanceSmallInverse" | |
46 | + android:layout_width="fill_parent" | |
47 | + android:layout_height="wrap_content" | |
48 | + android:text="@string/eth_con_type_dhcp" | |
49 | + ></RadioButton> | |
50 | + <RadioButton android:id="@+id/manual_radio" | |
51 | + style="?android:attr/textAppearanceSmallInverse" | |
52 | + android:layout_width="fill_parent" | |
53 | + android:layout_height="wrap_content" | |
54 | + android:text="@string/eth_con_type_manual" | |
55 | + ></RadioButton> | |
56 | + </RadioGroup> | |
57 | + | |
58 | + <!-- IP address --> | |
59 | + <LinearLayout android:id="@+id/enterprise_wrapper" | |
60 | + android:layout_width="fill_parent" | |
61 | + android:layout_height="wrap_content" | |
62 | + android:padding="0dip" | |
63 | + android:orientation="vertical"> | |
64 | + <TextView android:id="@+id/ipaddr_text" | |
65 | + style="?android:attr/textAppearanceSmallInverse" | |
66 | + android:layout_width="fill_parent" | |
67 | + android:layout_height="wrap_content" | |
68 | + android:layout_marginTop="8dip" | |
69 | + android:text="@string/eth_ipaddr" /> | |
70 | + <EditText android:id="@+id/ipaddr_edit" | |
71 | + android:layout_width="fill_parent" | |
72 | + android:layout_height="wrap_content" | |
73 | + android:layout_marginTop="2dip" | |
74 | + android:singleLine="true" /> | |
75 | + <TextView android:id="@+id/netmask_text" | |
76 | + style="?android:attr/textAppearanceSmallInverse" | |
77 | + android:layout_width="fill_parent" | |
78 | + android:layout_height="wrap_content" | |
79 | + android:layout_marginTop="8dip" | |
80 | + android:text="@string/eth_mask" /> | |
81 | + <EditText android:id="@+id/netmask_edit" | |
82 | + android:layout_width="fill_parent" | |
83 | + android:layout_height="wrap_content" | |
84 | + android:layout_marginTop="2dip" | |
85 | + android:singleLine="true" /> | |
86 | + <TextView android:id="@+id/dns_text" | |
87 | + style="?android:attr/textAppearanceSmallInverse" | |
88 | + android:layout_width="fill_parent" | |
89 | + android:layout_height="wrap_content" | |
90 | + android:layout_marginTop="8dip" | |
91 | + android:text="@string/eth_dns" /> | |
92 | + <EditText android:id="@+id/eth_dns_edit" | |
93 | + android:layout_width="fill_parent" | |
94 | + android:layout_height="wrap_content" | |
95 | + android:layout_marginTop="2dip" | |
96 | + android:singleLine="true" /> | |
97 | + <TextView android:id="@+id/gw_text" | |
98 | + style="?android:attr/textAppearanceSmallInverse" | |
99 | + android:layout_width="fill_parent" | |
100 | + android:layout_height="wrap_content" | |
101 | + android:layout_marginTop="8dip" | |
102 | + android:text="@string/eth_gw" /> | |
103 | + <EditText android:id="@+id/eth_gw_edit" | |
104 | + android:layout_width="fill_parent" | |
105 | + android:layout_height="wrap_content" | |
106 | + android:layout_marginTop="2dip" | |
107 | + android:singleLine="true" /> | |
108 | + </LinearLayout> | |
109 | + | |
110 | + </LinearLayout> | |
111 | + | |
112 | +</ScrollView> |
@@ -797,6 +797,25 @@ | ||
797 | 797 | <string name="nfc_quick_toggle_summary">Use Near Field Communication to read and exchange tags</string> |
798 | 798 | <string name="nfc_toggle_error" msgid="8998642457947607263">An error occurred.</string> |
799 | 799 | |
800 | + <!-- Ethernet configuration dialog --> | |
801 | + <string name="eth_config_title">Configure Ethernet device</string> | |
802 | + <string name="eth_setting">Ethernet setting</string> | |
803 | + <string name="eth_dev_list">Ethernet Devices:</string> | |
804 | + <string name="eth_con_type">Connection Type</string> | |
805 | + <string name="eth_con_type_dhcp">DHCP</string> | |
806 | + <string name="eth_con_type_manual">Static IP</string> | |
807 | + <string name="eth_dns">DNS address</string> | |
808 | + <string name="eth_gw">Gateway address</string> | |
809 | + <string name="eth_ipaddr">IP address</string> | |
810 | + <string name="eth_quick_toggle_title">Ethernet</string> | |
811 | + <string name="eth_quick_toggle_summary">Turn on Ethernet</string> | |
812 | + <string name="eth_radio_ctrl_title">Ethernet configuration</string> | |
813 | + <string name="eth_conf_perf_title">Ethernet configuration</string> | |
814 | + <string name="eth_conf_summary">Configure Ethernet devices</string> | |
815 | + <string name="eth_mask">Netmask</string> | |
816 | + <string name="eth_toggle_summary_off">Turn off Ethernet</string> | |
817 | + <string name="eth_toggle_summary_on">Turn on Ethernet</string> | |
818 | + | |
800 | 819 | <!-- Wi-Fi Settings --> <skip /> |
801 | 820 | <!-- Used in the 1st-level settings screen to turn on Wi-Fi --> |
802 | 821 | <string name="wifi_quick_toggle_title">Wi-Fi</string> |
@@ -0,0 +1,31 @@ | ||
1 | +<?xml version="1.0" encoding="utf-8"?> | |
2 | +<!-- Copyright (C) 2008 The Android Open Source Project | |
3 | + | |
4 | + Licensed under the Apache License, Version 2.0 (the "License"); | |
5 | + you may not use this file except in compliance with the License. | |
6 | + You may obtain a copy of the License at | |
7 | + | |
8 | + http://www.apache.org/licenses/LICENSE-2.0 | |
9 | + | |
10 | + Unless required by applicable law or agreed to in writing, software | |
11 | + distributed under the License is distributed on an "AS IS" BASIS, | |
12 | + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
13 | + See the License for the specific language governing permissions and | |
14 | + limitations under the License. | |
15 | +--> | |
16 | + | |
17 | +<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android" | |
18 | + android:title="@string/eth_radio_ctrl_title"> | |
19 | + <!-- Programmatically will have dynamic summary, but we provide the fallback summary. --> | |
20 | + <CheckBoxPreference | |
21 | + android:key="toggle_eth" | |
22 | + android:title="@string/eth_quick_toggle_title" | |
23 | + android:summaryOn="@string/eth_toggle_summary_off" | |
24 | + android:summaryOff="@string/eth_toggle_summary_on" | |
25 | + android:persistent="false" /> | |
26 | + <Preference | |
27 | + android:title="@string/eth_conf_perf_title" | |
28 | + android:summary="@string/eth_conf_summary" | |
29 | + android:key="ETHERNET_config" | |
30 | + android:persistent="false" /> | |
31 | +</PreferenceScreen> |
@@ -30,6 +30,15 @@ | ||
30 | 30 | </com.android.settings.IconPreferenceScreen> |
31 | 31 | |
32 | 32 | <com.android.settings.IconPreferenceScreen |
33 | + android:title="@string/eth_radio_ctrl_title" | |
34 | + settings:icon="@drawable/ic_settings_ethernet"> | |
35 | + <intent | |
36 | + android:action="android.intent.action.MAIN" | |
37 | + android:targetPackage="com.android.settings" | |
38 | + android:targetClass="com.android.settings.EthernetSettings" /> | |
39 | + </com.android.settings.IconPreferenceScreen> | |
40 | + | |
41 | + <com.android.settings.IconPreferenceScreen | |
33 | 42 | android:key="call_settings" |
34 | 43 | settings:icon="@drawable/ic_settings_call" |
35 | 44 | android:title="@string/call_settings_title"> |
@@ -0,0 +1,83 @@ | ||
1 | +/* | |
2 | + * Copyright (C) 2010 The Android-x86 Open Source Project | |
3 | + * | |
4 | + * Licensed under the Apache License, Version 2.0 (the "License"); | |
5 | + * you may not use this file except in compliance with the License. | |
6 | + * You may obtain a copy of the License at | |
7 | + * | |
8 | + * http://www.apache.org/licenses/LICENSE-2.0 | |
9 | + * | |
10 | + * Unless required by applicable law or agreed to in writing, software | |
11 | + * distributed under the License is distributed on an "AS IS" BASIS, | |
12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
13 | + * See the License for the specific language governing permissions and | |
14 | + * limitations under the License. | |
15 | + * | |
16 | + * Author: Yi Sun <beyounn@gmail.com> | |
17 | + */ | |
18 | + | |
19 | +package com.android.settings; | |
20 | + | |
21 | +import com.android.settings.R; | |
22 | +import com.android.settings.ethernet.EthernetConfigDialog; | |
23 | +import com.android.settings.ethernet.EthernetEnabler; | |
24 | + | |
25 | +import android.net.ethernet.EthernetManager; | |
26 | +import android.os.Bundle; | |
27 | +import android.preference.CheckBoxPreference; | |
28 | +import android.preference.Preference; | |
29 | +import android.preference.PreferenceActivity; | |
30 | +import android.preference.PreferenceScreen; | |
31 | + | |
32 | +public class EthernetSettings extends PreferenceActivity { | |
33 | + private static final String KEY_TOGGLE_ETH = "toggle_eth"; | |
34 | + private static final String KEY_CONF_ETH = "ETHERNET_config"; | |
35 | + private EthernetEnabler mEthEnabler; | |
36 | + private EthernetConfigDialog mEthConfigDialog; | |
37 | + private Preference mEthConfigPref; | |
38 | + | |
39 | + @Override | |
40 | + public boolean onPreferenceTreeClick(PreferenceScreen preferenceScreen, Preference preference) { | |
41 | + super.onPreferenceTreeClick(preferenceScreen, preference); | |
42 | + | |
43 | + if (preference == mEthConfigPref) { | |
44 | + mEthConfigDialog.show(); | |
45 | + } | |
46 | + return false; | |
47 | + } | |
48 | + | |
49 | + @Override | |
50 | + protected void onCreate(Bundle savedInstanceState) { | |
51 | + super.onCreate(savedInstanceState); | |
52 | + | |
53 | + addPreferencesFromResource(R.xml.ethernet_settings); | |
54 | + final PreferenceScreen preferenceScreen = getPreferenceScreen(); | |
55 | + mEthConfigPref = preferenceScreen.findPreference(KEY_CONF_ETH); | |
56 | + /* | |
57 | + * TO DO: | |
58 | + * Add new perference screen for Etherenet Configuration | |
59 | + */ | |
60 | + | |
61 | + initToggles(); | |
62 | + } | |
63 | + | |
64 | + @Override | |
65 | + protected void onResume() { | |
66 | + super.onResume(); | |
67 | + mEthEnabler.resume(); | |
68 | + } | |
69 | + | |
70 | + @Override | |
71 | + protected void onPause() { | |
72 | + super.onPause(); | |
73 | + mEthEnabler.pause(); | |
74 | + } | |
75 | + | |
76 | + private void initToggles() { | |
77 | + mEthEnabler = new EthernetEnabler(this, | |
78 | + (EthernetManager) getSystemService(ETHERNET_SERVICE), | |
79 | + (CheckBoxPreference) findPreference(KEY_TOGGLE_ETH)); | |
80 | + mEthConfigDialog = new EthernetConfigDialog(this, mEthEnabler); | |
81 | + mEthEnabler.setConfigDialog(mEthConfigDialog); | |
82 | + } | |
83 | +} |
@@ -0,0 +1,214 @@ | ||
1 | +/* | |
2 | + * Copyright (C) 2010 The Android-x86 Open Source Project | |
3 | + * | |
4 | + * Licensed under the Apache License, Version 2.0 (the "License"); | |
5 | + * you may not use this file except in compliance with the License. | |
6 | + * You may obtain a copy of the License at | |
7 | + * | |
8 | + * http://www.apache.org/licenses/LICENSE-2.0 | |
9 | + * | |
10 | + * Unless required by applicable law or agreed to in writing, software | |
11 | + * distributed under the License is distributed on an "AS IS" BASIS, | |
12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
13 | + * See the License for the specific language governing permissions and | |
14 | + * limitations under the License. | |
15 | + * | |
16 | + * Author: Yi Sun <beyounn@gmail.com> | |
17 | + */ | |
18 | + | |
19 | +package com.android.settings.ethernet; | |
20 | + | |
21 | + | |
22 | +import java.util.List; | |
23 | + | |
24 | +import com.android.settings.R; | |
25 | + | |
26 | +import android.app.AlertDialog; | |
27 | +import android.content.BroadcastReceiver; | |
28 | +import android.content.Context; | |
29 | +import android.content.DialogInterface; | |
30 | +import android.content.Intent; | |
31 | +import android.net.NetworkInfo; | |
32 | +import android.net.ethernet.EthernetManager; | |
33 | +import android.net.ethernet.EthernetDevInfo; | |
34 | +import android.os.Bundle; | |
35 | +import android.view.View; | |
36 | +import android.view.ViewGroup; | |
37 | +import android.widget.AdapterView; | |
38 | +import android.widget.ArrayAdapter; | |
39 | +import android.widget.CheckBox; | |
40 | +import android.widget.EditText; | |
41 | +import android.widget.RadioButton; | |
42 | +import android.widget.RadioGroup; | |
43 | +import android.widget.Spinner; | |
44 | +import android.widget.TextView; | |
45 | +import android.util.Slog; | |
46 | + | |
47 | +public class EthernetConfigDialog extends AlertDialog implements | |
48 | + DialogInterface.OnClickListener, AdapterView.OnItemSelectedListener, View.OnClickListener { | |
49 | + private final String TAG = "EtherenetSettings"; | |
50 | + private static final boolean localLOGV = false; | |
51 | + | |
52 | + private EthernetEnabler mEthEnabler; | |
53 | + private View mView; | |
54 | + private Spinner mDevList; | |
55 | + private TextView mDevs; | |
56 | + private RadioButton mConTypeDhcp; | |
57 | + private RadioButton mConTypeManual; | |
58 | + private EditText mIpaddr; | |
59 | + private EditText mDns; | |
60 | + private EditText mGw; | |
61 | + private EditText mMask; | |
62 | + | |
63 | + private EthernetLayer mEthLayer; | |
64 | + private EthernetManager mEthManager; | |
65 | + private EthernetDevInfo mEthInfo; | |
66 | + private boolean mEnablePending; | |
67 | + | |
68 | + public EthernetConfigDialog(Context context, EthernetEnabler Enabler) { | |
69 | + super(context); | |
70 | + mEthLayer = new EthernetLayer(this); | |
71 | + mEthEnabler = Enabler; | |
72 | + mEthManager=Enabler.getManager(); | |
73 | + buildDialogContent(context); | |
74 | + } | |
75 | + | |
76 | + public int buildDialogContent(Context context) { | |
77 | + this.setTitle(R.string.eth_config_title); | |
78 | + this.setView(mView = getLayoutInflater().inflate(R.layout.eth_configure, null)); | |
79 | + mDevs = (TextView) mView.findViewById(R.id.eth_dev_list_text); | |
80 | + mDevList = (Spinner) mView.findViewById(R.id.eth_dev_spinner); | |
81 | + mConTypeDhcp = (RadioButton) mView.findViewById(R.id.dhcp_radio); | |
82 | + mConTypeManual = (RadioButton) mView.findViewById(R.id.manual_radio); | |
83 | + mIpaddr = (EditText)mView.findViewById(R.id.ipaddr_edit); | |
84 | + mMask = (EditText)mView.findViewById(R.id.netmask_edit); | |
85 | + mDns = (EditText)mView.findViewById(R.id.eth_dns_edit); | |
86 | + mGw = (EditText)mView.findViewById(R.id.eth_gw_edit); | |
87 | + | |
88 | + mConTypeDhcp.setChecked(true); | |
89 | + mConTypeManual.setChecked(false); | |
90 | + mIpaddr.setEnabled(false); | |
91 | + mMask.setEnabled(false); | |
92 | + mDns.setEnabled(false); | |
93 | + mGw.setEnabled(false); | |
94 | + mConTypeManual.setOnClickListener(new RadioButton.OnClickListener() { | |
95 | + public void onClick(View v) { | |
96 | + mIpaddr.setEnabled(true); | |
97 | + mDns.setEnabled(true); | |
98 | + mGw.setEnabled(true); | |
99 | + mMask.setEnabled(true); | |
100 | + } | |
101 | + }); | |
102 | + | |
103 | + mConTypeDhcp.setOnClickListener(new RadioButton.OnClickListener() { | |
104 | + public void onClick(View v) { | |
105 | + mIpaddr.setEnabled(false); | |
106 | + mDns.setEnabled(false); | |
107 | + mGw.setEnabled(false); | |
108 | + mMask.setEnabled(false); | |
109 | + } | |
110 | + }); | |
111 | + | |
112 | + this.setInverseBackgroundForced(true); | |
113 | + this.setButton(BUTTON_POSITIVE, context.getText(R.string.menu_save), this); | |
114 | + this.setButton(BUTTON_NEGATIVE, context.getText(R.string.menu_cancel), this); | |
115 | + String[] Devs = mEthEnabler.getManager().getDeviceNameList(); | |
116 | + if (Devs != null) { | |
117 | + if (localLOGV) | |
118 | + Slog.v(TAG, "found device: " + Devs[0]); | |
119 | + updateDevNameList(Devs); | |
120 | + if (mEthManager.isConfigured()) { | |
121 | + mEthInfo = mEthManager.getSavedConfig(); | |
122 | + for (int i = 0 ; i < Devs.length; i++) { | |
123 | + if (Devs[i].equals(mEthInfo.getIfName())) { | |
124 | + mDevList.setSelection(i); | |
125 | + break; | |
126 | + } | |
127 | + } | |
128 | + mIpaddr.setText(mEthInfo.getIpAddress()); | |
129 | + mGw.setText(mEthInfo.getRouteAddr()); | |
130 | + mDns.setText(mEthInfo.getDnsAddr()); | |
131 | + mMask.setText(mEthInfo.getNetMask()); | |
132 | + if (mEthInfo.getConnectMode().equals(EthernetDevInfo.ETHERNET_CONN_MODE_DHCP)) { | |
133 | + mIpaddr.setEnabled(false); | |
134 | + mDns.setEnabled(false); | |
135 | + mGw.setEnabled(false); | |
136 | + mMask.setEnabled(false); | |
137 | + } else { | |
138 | + mConTypeDhcp.setChecked(false); | |
139 | + mConTypeManual.setChecked(true); | |
140 | + mIpaddr.setEnabled(true); | |
141 | + mDns.setEnabled(true); | |
142 | + mGw.setEnabled(true); | |
143 | + mMask.setEnabled(true); | |
144 | + } | |
145 | + } | |
146 | + } | |
147 | + return 0; | |
148 | + } | |
149 | + | |
150 | + private void handle_saveconf() { | |
151 | + EthernetDevInfo info = new EthernetDevInfo(); | |
152 | + info.setIfName(mDevList.getSelectedItem().toString()); | |
153 | + if (localLOGV) | |
154 | + Slog.v(TAG, "Config device for " + mDevList.getSelectedItem().toString()); | |
155 | + if (mConTypeDhcp.isChecked()) { | |
156 | + info.setConnectMode(EthernetDevInfo.ETHERNET_CONN_MODE_DHCP); | |
157 | + info.setIpAddress(null); | |
158 | + info.setRouteAddr(null); | |
159 | + info.setDnsAddr(null); | |
160 | + info.setNetMask(null); | |
161 | + } else { | |
162 | + info.setConnectMode(EthernetDevInfo.ETHERNET_CONN_MODE_MANUAL); | |
163 | + info.setIpAddress(mIpaddr.getText().toString()); | |
164 | + info.setRouteAddr(mGw.getText().toString()); | |
165 | + info.setDnsAddr(mDns.getText().toString()); | |
166 | + info.setNetMask(mMask.getText().toString()); | |
167 | + } | |
168 | + mEthManager.updateDevInfo(info); | |
169 | + if (mEnablePending) { | |
170 | + mEthManager.setEnabled(true); | |
171 | + mEnablePending = false; | |
172 | + } | |
173 | + } | |
174 | + | |
175 | + public void onClick(DialogInterface dialog, int which) { | |
176 | + switch (which) { | |
177 | + case BUTTON_POSITIVE: | |
178 | + handle_saveconf(); | |
179 | + break; | |
180 | + case BUTTON_NEGATIVE: | |
181 | + //Don't need to do anything | |
182 | + break; | |
183 | + default: | |
184 | + Slog.e(TAG,"Unknow button"); | |
185 | + } | |
186 | + } | |
187 | + | |
188 | + public void onItemSelected(AdapterView<?> parent, View view, int position, long id) { | |
189 | + | |
190 | + } | |
191 | + | |
192 | + public void onNothingSelected(AdapterView<?> parent) { | |
193 | + | |
194 | + } | |
195 | + | |
196 | + public void onClick(View v) { | |
197 | + | |
198 | + } | |
199 | + | |
200 | + public void updateDevNameList(String[] DevList) { | |
201 | + if (DevList != null) { | |
202 | + ArrayAdapter<CharSequence> adapter = new ArrayAdapter<CharSequence>( | |
203 | + getContext(), android.R.layout.simple_spinner_item, DevList); | |
204 | + adapter.setDropDownViewResource( | |
205 | + android.R.layout.simple_spinner_dropdown_item); | |
206 | + mDevList.setAdapter(adapter); | |
207 | + } | |
208 | + | |
209 | + } | |
210 | + | |
211 | + public void enableAfterConfig() { | |
212 | + mEnablePending = true; | |
213 | + } | |
214 | +} |
@@ -0,0 +1,170 @@ | ||
1 | +/* | |
2 | + * Copyright (C) 2010 The Android-x86 Open Source Project | |
3 | + * | |
4 | + * Licensed under the Apache License, Version 2.0 (the "License"); | |
5 | + * you may not use this file except in compliance with the License. | |
6 | + * You may obtain a copy of the License at | |
7 | + * | |
8 | + * http://www.apache.org/licenses/LICENSE-2.0 | |
9 | + * | |
10 | + * Unless required by applicable law or agreed to in writing, software | |
11 | + * distributed under the License is distributed on an "AS IS" BASIS, | |
12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
13 | + * See the License for the specific language governing permissions and | |
14 | + * limitations under the License. | |
15 | + * | |
16 | + * Author: Yi Sun <beyounn@gmail.com> | |
17 | + */ | |
18 | + | |
19 | +package com.android.settings.ethernet; | |
20 | + | |
21 | + | |
22 | +import static android.net.ethernet.EthernetManager.ETHERNET_STATE_DISABLED; | |
23 | +import static android.net.ethernet.EthernetManager.ETHERNET_STATE_ENABLED; | |
24 | +import static android.net.ethernet.EthernetManager.ETHERNET_STATE_UNKNOWN; | |
25 | + | |
26 | +import com.android.settings.R; | |
27 | + | |
28 | +import android.content.BroadcastReceiver; | |
29 | +import android.content.Context; | |
30 | +import android.content.Intent; | |
31 | +import android.content.IntentFilter; | |
32 | +import android.net.NetworkInfo; | |
33 | +import android.net.ethernet.EthernetManager; | |
34 | +import android.preference.Preference; | |
35 | +import android.preference.CheckBoxPreference; | |
36 | +import android.text.TextUtils; | |
37 | +import android.util.Config; | |
38 | +import android.util.Slog; | |
39 | + | |
40 | +public class EthernetEnabler implements Preference.OnPreferenceChangeListener { | |
41 | + private static final boolean LOCAL_LOGD = true; | |
42 | + private static final String TAG = "SettingsEthEnabler"; | |
43 | + //private final IntentFilter mEthStateFilter; | |
44 | + private Context mContext; | |
45 | + private EthernetManager mEthManager; | |
46 | + private CheckBoxPreference mEthCheckBoxPref; | |
47 | + private final CharSequence mOriginalSummary; | |
48 | + private EthernetConfigDialog mEthConfigDialog; | |
49 | + | |
50 | + private final BroadcastReceiver mEthStateReceiver = new BroadcastReceiver() { | |
51 | + @Override | |
52 | + public void onReceive(Context context, Intent intent) { | |
53 | + if (intent.getAction().equals(EthernetManager.ETHERNET_STATE_CHANGED_ACTION)) { | |
54 | + handleEthStateChanged( | |
55 | + intent.getIntExtra(EthernetManager.EXTRA_ETHERNET_STATE, | |
56 | + EthernetManager.ETHERNET_STATE_UNKNOWN), | |
57 | + intent.getIntExtra(EthernetManager.EXTRA_PREVIOUS_ETHERNET_STATE, | |
58 | + EthernetManager.ETHERNET_STATE_UNKNOWN)); | |
59 | + } else if (intent.getAction().equals(EthernetManager.NETWORK_STATE_CHANGED_ACTION)) { | |
60 | + handleNetworkStateChanged( | |
61 | + (NetworkInfo) intent.getParcelableExtra(EthernetManager.EXTRA_NETWORK_INFO)); | |
62 | + } | |
63 | + } | |
64 | + }; | |
65 | + | |
66 | + public void setConfigDialog (EthernetConfigDialog Dialog) { | |
67 | + mEthConfigDialog = Dialog; | |
68 | + } | |
69 | + | |
70 | + public EthernetEnabler(Context context, EthernetManager ethernetManager, CheckBoxPreference ethernetCheckBoxPreference) { | |
71 | + mContext = context; | |
72 | + mEthCheckBoxPref = ethernetCheckBoxPreference; | |
73 | + mEthManager = ethernetManager; | |
74 | + | |
75 | + mOriginalSummary = ethernetCheckBoxPreference.getSummary(); | |
76 | + ethernetCheckBoxPreference.setPersistent(false); | |
77 | + if (mEthManager.getState() == ETHERNET_STATE_ENABLED) { | |
78 | + mEthCheckBoxPref.setChecked(true); | |
79 | + } | |
80 | + | |
81 | + /* | |
82 | + mEthStateFilter = new IntentFilter(EthernetManager.ETHERNET_STATE_CHANGED_ACTION); | |
83 | + mEthStateFilter.addAction(EthernetManager.NETWORK_STATE_CHANGED_ACTION); | |
84 | + */ | |
85 | + } | |
86 | + | |
87 | + public EthernetManager getManager() { | |
88 | + return mEthManager; | |
89 | + } | |
90 | + | |
91 | + public void resume() { | |
92 | + mEthCheckBoxPref.setOnPreferenceChangeListener(this); | |
93 | + } | |
94 | + | |
95 | + public void pause() { | |
96 | + // mContext.unregisterReceiver(mEthStateReceiver); | |
97 | + mEthCheckBoxPref.setOnPreferenceChangeListener(null); | |
98 | + } | |
99 | + | |
100 | + public boolean onPreferenceChange(Preference preference, Object newValue) { | |
101 | + setEthEnabled((Boolean)newValue); | |
102 | + return false; | |
103 | + } | |
104 | + | |
105 | + private void setEthEnabled(final boolean enable) { | |
106 | + | |
107 | + int state = mEthManager.getState(); | |
108 | + | |
109 | + Slog.i(TAG,"Show configuration dialog " + enable); | |
110 | + // Disable button | |
111 | + mEthCheckBoxPref.setEnabled(false); | |
112 | + | |
113 | + if (state != ETHERNET_STATE_ENABLED && enable) { | |
114 | + if (mEthManager.isConfigured() != true) { | |
115 | + // Now, kick off the setting dialog to get the configurations | |
116 | + mEthConfigDialog.enableAfterConfig(); | |
117 | + mEthConfigDialog.show(); | |
118 | + } else { | |
119 | + mEthManager.setEnabled(enable); | |
120 | + } | |
121 | + } else { | |
122 | + mEthManager.setEnabled(enable); | |
123 | + } | |
124 | + | |
125 | + mEthCheckBoxPref.setChecked(enable); | |
126 | + // Disable button | |
127 | + mEthCheckBoxPref.setEnabled(true); | |
128 | + } | |
129 | + | |
130 | + private void handleEthStateChanged(int ethState, int previousEthState) { | |
131 | + | |
132 | + } | |
133 | + | |
134 | + private void handleNetworkStateChanged(NetworkInfo networkInfo) { | |
135 | + if (LOCAL_LOGD) { | |
136 | + Slog.d(TAG, "Received network state changed to " + networkInfo); | |
137 | + } | |
138 | + } | |
139 | + | |
140 | + private boolean isEnabledByDependency() { | |
141 | + Preference dep = getDependencyPreference(); | |
142 | + if (dep == null) { | |
143 | + return true; | |
144 | + } | |
145 | + | |
146 | + return !dep.shouldDisableDependents(); | |
147 | + } | |
148 | + | |
149 | + private Preference getDependencyPreference() { | |
150 | + String depKey = mEthCheckBoxPref.getDependency(); | |
151 | + if (TextUtils.isEmpty(depKey)) { | |
152 | + return null; | |
153 | + } | |
154 | + | |
155 | + return mEthCheckBoxPref.getPreferenceManager().findPreference(depKey); | |
156 | + } | |
157 | + | |
158 | + private static String getHumanReadableEthState(int wifiState) { | |
159 | + switch (wifiState) { | |
160 | + case ETHERNET_STATE_DISABLED: | |
161 | + return "Disabled"; | |
162 | + case ETHERNET_STATE_ENABLED: | |
163 | + return "Enabled"; | |
164 | + case ETHERNET_STATE_UNKNOWN: | |
165 | + return "Unknown"; | |
166 | + default: | |
167 | + return "Some other state!"; | |
168 | + } | |
169 | + } | |
170 | +} |
@@ -0,0 +1,68 @@ | ||
1 | +/* | |
2 | + * Copyright (C) 2010 The Android-x86 Open Source Project | |
3 | + * | |
4 | + * Licensed under the Apache License, Version 2.0 (the "License"); | |
5 | + * you may not use this file except in compliance with the License. | |
6 | + * You may obtain a copy of the License at | |
7 | + * | |
8 | + * http://www.apache.org/licenses/LICENSE-2.0 | |
9 | + * | |
10 | + * Unless required by applicable law or agreed to in writing, software | |
11 | + * distributed under the License is distributed on an "AS IS" BASIS, | |
12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
13 | + * See the License for the specific language governing permissions and | |
14 | + * limitations under the License. | |
15 | + * | |
16 | + * Author: Yi Sun <beyounn@gmail.com> | |
17 | + */ | |
18 | + | |
19 | +package com.android.settings.ethernet; | |
20 | + | |
21 | +import static android.net.ethernet.EthernetManager.ETHERNET_DEVICE_SCAN_RESULT_READY; | |
22 | + | |
23 | +import com.android.settings.R; | |
24 | +import android.content.BroadcastReceiver; | |
25 | +import android.content.Context; | |
26 | +import android.content.Intent; | |
27 | +import android.content.IntentFilter; | |
28 | +import android.net.NetworkInfo; | |
29 | +import android.net.NetworkInfo.DetailedState; | |
30 | +import android.net.NetworkInfo.State; | |
31 | +import android.net.ethernet.EthernetManager; | |
32 | +import android.os.Handler; | |
33 | +import android.os.Message; | |
34 | +import android.provider.Settings; | |
35 | +import android.text.TextUtils; | |
36 | +import android.util.Config; | |
37 | + | |
38 | +import java.util.ArrayList; | |
39 | +import java.util.Collections; | |
40 | +import java.util.Comparator; | |
41 | +import java.util.List; | |
42 | + | |
43 | +public class EthernetLayer { | |
44 | + private static final String TAG = "EthernetLayer"; | |
45 | + | |
46 | + private EthernetManager mEthManager; | |
47 | + private String[] mDevList; | |
48 | + private EthernetConfigDialog mDialog; | |
49 | + | |
50 | + EthernetLayer (EthernetConfigDialog configdialog) { | |
51 | + mDialog = configdialog; | |
52 | + } | |
53 | + | |
54 | + private BroadcastReceiver mReceiver = new BroadcastReceiver() { | |
55 | + @Override | |
56 | + public void onReceive(Context context, Intent intent) { | |
57 | + final String action = intent.getAction(); | |
58 | + if (action.equals(EthernetManager.ETHERNET_DEVICE_SCAN_RESULT_READY)) { | |
59 | + handleDevListChanges(); | |
60 | + } | |
61 | + } | |
62 | + }; | |
63 | + | |
64 | + private void handleDevListChanges() { | |
65 | + mDevList = mEthManager.getDeviceNameList(); | |
66 | + mDialog.updateDevNameList(mDevList); | |
67 | + } | |
68 | +} |