Fragmentize TetherSettings and WifiApSettings.

PreferenceScreen for BT tethering isn't fragmentized yet.
We'll need to do so in the near future.

Change-Id: I5a84fecaf84d55b59b6efa8151f2549ad37ca5db
This commit is contained in:
Daisuke Miyakawa
2010-09-10 12:04:37 -07:00
parent 71cc548f7e
commit 9c602c4789
5 changed files with 70 additions and 68 deletions

View File

@@ -147,13 +147,14 @@
</intent-filter> </intent-filter>
</activity> </activity>
<activity android:name=".wifi.WifiApSettings"> <activity-alias android:name=".wifi.WifiApSettings"
android:targetActivity="Settings">
<intent-filter> <intent-filter>
<action android:name="android.intent.action.MAIN" /> <action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.DEFAULT" /> <category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.VOICE_LAUNCH" /> <category android:name="android.intent.category.VOICE_LAUNCH" />
</intent-filter> </intent-filter>
</activity> </activity-alias>
<activity android:name="ApnSettings" android:label="@string/apn_settings" <activity android:name="ApnSettings" android:label="@string/apn_settings"
android:configChanges="orientation|keyboardHidden" android:configChanges="orientation|keyboardHidden"
@@ -184,14 +185,15 @@
</intent-filter> </intent-filter>
</activity> </activity>
<activity android:name=".TetherSettings" <activity-alias android:name=".TetherSettings"
android:clearTaskOnLaunch="true"> android:clearTaskOnLaunch="true"
android:targetActivity="Settings">
<intent-filter> <intent-filter>
<action android:name="android.intent.action.MAIN" /> <action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.DEFAULT" /> <category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.VOICE_LAUNCH" /> <category android:name="android.intent.category.VOICE_LAUNCH" />
</intent-filter> </intent-filter>
</activity> </activity-alias>
<activity android:name=".vpn.VpnSettings" <activity android:name=".vpn.VpnSettings"
android:configChanges="orientation|keyboardHidden" android:configChanges="orientation|keyboardHidden"

View File

@@ -27,13 +27,10 @@
android:persistent="false" /> android:persistent="false" />
<PreferenceScreen <PreferenceScreen
android:fragment="com.android.settings.wifi.WifiApSettings"
android:key="wifi_ap_settings" android:key="wifi_ap_settings"
android:title="@string/wifi_tether_settings_text" android:title="@string/wifi_tether_settings_text"
android:summary="@string/wifi_tether_settings_subtext" > android:summary="@string/wifi_tether_settings_subtext" >
<intent
android:action="android.intent.action.MAIN"
android:targetPackage="com.android.settings"
android:targetClass="com.android.settings.wifi.WifiApSettings" />
</PreferenceScreen> </PreferenceScreen>
<CheckBoxPreference <CheckBoxPreference

View File

@@ -55,13 +55,10 @@
</PreferenceScreen> </PreferenceScreen>
<PreferenceScreen <PreferenceScreen
android:fragment="com.android.settings.TetherSettings"
android:key="tether_settings" android:key="tether_settings"
android:title="@string/tether_settings_title_all" android:title="@string/tether_settings_title_all"
android:summary="@string/tether_settings_summary_all"> android:summary="@string/tether_settings_summary_all">
<intent
android:action="android.intent.action.MAIN"
android:targetPackage="com.android.settings"
android:targetClass="com.android.settings.TetherSettings" />
</PreferenceScreen> </PreferenceScreen>
<PreferenceScreen <PreferenceScreen

View File

@@ -18,27 +18,22 @@ package com.android.settings;
import com.android.settings.wifi.WifiApEnabler; import com.android.settings.wifi.WifiApEnabler;
import android.app.Activity;
import android.app.AlertDialog; import android.app.AlertDialog;
import android.app.Dialog; import android.app.Dialog;
import android.bluetooth.BluetoothAdapter; import android.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothPan; import android.bluetooth.BluetoothPan;
import android.bluetooth.IBluetooth;
import android.os.Bundle;
import android.os.IBinder;
import android.os.RemoteException;
import android.os.ServiceManager;
import android.content.BroadcastReceiver; import android.content.BroadcastReceiver;
import android.content.Context; import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.content.IntentFilter; import android.content.IntentFilter;
import android.content.res.AssetManager; import android.content.res.AssetManager;
import android.net.ConnectivityManager; import android.net.ConnectivityManager;
import android.os.Bundle;
import android.os.Environment; import android.os.Environment;
import android.preference.CheckBoxPreference; import android.preference.CheckBoxPreference;
import android.preference.Preference; import android.preference.Preference;
import android.preference.PreferenceActivity;
import android.preference.PreferenceScreen; import android.preference.PreferenceScreen;
import android.util.Log;
import android.webkit.WebView; import android.webkit.WebView;
import java.io.InputStream; import java.io.InputStream;
@@ -48,7 +43,7 @@ import java.util.Locale;
/* /*
* Displays preferences for Tethering. * Displays preferences for Tethering.
*/ */
public class TetherSettings extends PreferenceActivity { public class TetherSettings extends SettingsPreferenceFragment {
private static final String TAG = "TetheringSettings"; private static final String TAG = "TetheringSettings";
private static final String USB_TETHER_SETTINGS = "usb_tether_settings"; private static final String USB_TETHER_SETTINGS = "usb_tether_settings";
@@ -86,11 +81,16 @@ public class TetherSettings extends PreferenceActivity {
private BluetoothPan mBluetoothPan; private BluetoothPan mBluetoothPan;
@Override @Override
protected void onCreate(Bundle icicle) { public void onCreate(Bundle icicle) {
super.onCreate(icicle); super.onCreate(icicle);
mBluetoothPan = new BluetoothPan(this);
addPreferencesFromResource(R.xml.tether_prefs); addPreferencesFromResource(R.xml.tether_prefs);
}
@Override
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
final Activity activity = getActivity();
mBluetoothPan = new BluetoothPan(activity);
mEnableWifiAp = (CheckBoxPreference) findPreference(ENABLE_WIFI_AP); mEnableWifiAp = (CheckBoxPreference) findPreference(ENABLE_WIFI_AP);
mWifiApSettings = (PreferenceScreen) findPreference(WIFI_AP_SETTINGS); mWifiApSettings = (PreferenceScreen) findPreference(WIFI_AP_SETTINGS);
@@ -131,31 +131,31 @@ public class TetherSettings extends PreferenceActivity {
} }
} }
if (wifiAvailable && usbAvailable && bluetoothAvailable){ if (wifiAvailable && usbAvailable && bluetoothAvailable){
setTitle(R.string.tether_settings_title_all); activity.setTitle(R.string.tether_settings_title_all);
} else if (wifiAvailable && usbAvailable){ } else if (wifiAvailable && usbAvailable){
setTitle(R.string.tether_settings_title_all); activity.setTitle(R.string.tether_settings_title_all);
} else if (wifiAvailable && bluetoothAvailable){ } else if (wifiAvailable && bluetoothAvailable){
setTitle(R.string.tether_settings_title_all); activity.setTitle(R.string.tether_settings_title_all);
} else if (wifiAvailable) { } else if (wifiAvailable) {
setTitle(R.string.tether_settings_title_wifi); activity.setTitle(R.string.tether_settings_title_wifi);
} else if (usbAvailable && bluetoothAvailable) { } else if (usbAvailable && bluetoothAvailable) {
setTitle(R.string.tether_settings_title_usb_bluetooth); activity.setTitle(R.string.tether_settings_title_usb_bluetooth);
} else if (usbAvailable) { } else if (usbAvailable) {
setTitle(R.string.tether_settings_title_usb); activity.setTitle(R.string.tether_settings_title_usb);
} else { } else {
setTitle(R.string.tether_settings_title_bluetooth); activity.setTitle(R.string.tether_settings_title_bluetooth);
} }
mWifiApEnabler = new WifiApEnabler(this, mEnableWifiAp); mWifiApEnabler = new WifiApEnabler(activity, mEnableWifiAp);
mView = new WebView(this); mView = new WebView(activity);
} }
@Override @Override
protected Dialog onCreateDialog(int id) { public Dialog onCreateDialog(int id) {
if (id == DIALOG_TETHER_HELP) { if (id == DIALOG_TETHER_HELP) {
Locale locale = Locale.getDefault(); Locale locale = Locale.getDefault();
// check for the full language + country resource, if not there, try just language // check for the full language + country resource, if not there, try just language
AssetManager am = getAssets(); final AssetManager am = getActivity().getAssets();
String path = HELP_PATH.replace("%y", locale.getLanguage().toLowerCase()); String path = HELP_PATH.replace("%y", locale.getLanguage().toLowerCase());
path = path.replace("%z", "_"+locale.getCountry().toLowerCase()); path = path.replace("%z", "_"+locale.getCountry().toLowerCase());
boolean useCountry = true; boolean useCountry = true;
@@ -185,7 +185,7 @@ public class TetherSettings extends PreferenceActivity {
mView.loadUrl(url); mView.loadUrl(url);
return new AlertDialog.Builder(this) return new AlertDialog.Builder(getActivity())
.setCancelable(true) .setCancelable(true)
.setTitle(R.string.tethering_help_button_text) .setTitle(R.string.tethering_help_button_text)
.setView(mView) .setView(mView)
@@ -218,31 +218,33 @@ public class TetherSettings extends PreferenceActivity {
} }
@Override @Override
protected void onResume() { public void onResume() {
super.onResume(); super.onResume();
final Activity activity = getActivity();
mTetherChangeReceiver = new TetherChangeReceiver(); mTetherChangeReceiver = new TetherChangeReceiver();
IntentFilter filter = new IntentFilter(ConnectivityManager.ACTION_TETHER_STATE_CHANGED); IntentFilter filter = new IntentFilter(ConnectivityManager.ACTION_TETHER_STATE_CHANGED);
Intent intent = registerReceiver(mTetherChangeReceiver, filter); Intent intent = activity.registerReceiver(mTetherChangeReceiver, filter);
filter = new IntentFilter(); filter = new IntentFilter();
filter.addAction(Intent.ACTION_MEDIA_SHARED); filter.addAction(Intent.ACTION_MEDIA_SHARED);
filter.addAction(Intent.ACTION_MEDIA_UNSHARED); filter.addAction(Intent.ACTION_MEDIA_UNSHARED);
filter.addDataScheme("file"); filter.addDataScheme("file");
registerReceiver(mTetherChangeReceiver, filter); activity.registerReceiver(mTetherChangeReceiver, filter);
filter = new IntentFilter(); filter = new IntentFilter();
filter.addAction(BluetoothAdapter.ACTION_STATE_CHANGED); filter.addAction(BluetoothAdapter.ACTION_STATE_CHANGED);
registerReceiver(mTetherChangeReceiver, filter); activity.registerReceiver(mTetherChangeReceiver, filter);
if (intent != null) mTetherChangeReceiver.onReceive(this, intent); if (intent != null) mTetherChangeReceiver.onReceive(activity, intent);
mWifiApEnabler.resume(); mWifiApEnabler.resume();
} }
@Override @Override
protected void onPause() { public void onPause() {
super.onPause(); super.onPause();
unregisterReceiver(mTetherChangeReceiver); getActivity().unregisterReceiver(mTetherChangeReceiver);
mTetherChangeReceiver = null; mTetherChangeReceiver = null;
mWifiApEnabler.pause(); mWifiApEnabler.pause();
} }
@@ -458,7 +460,8 @@ public class TetherSettings extends PreferenceActivity {
} else if (preference == mTetherHelp) { } else if (preference == mTetherHelp) {
showDialog(DIALOG_TETHER_HELP); showDialog(DIALOG_TETHER_HELP);
} }
return false;
return super.onPreferenceTreeClick(preferenceScreen, preference);
} }
private String findIface(String[] ifaces, String[] regexes) { private String findIface(String[] ifaces, String[] regexes) {

View File

@@ -17,29 +17,24 @@
package com.android.settings.wifi; package com.android.settings.wifi;
import com.android.settings.R; import com.android.settings.R;
import com.android.settings.SettingsPreferenceFragment;
import android.app.Activity;
import android.app.Dialog; import android.app.Dialog;
import android.content.BroadcastReceiver;
import android.content.Context; import android.content.Context;
import android.content.DialogInterface; import android.content.DialogInterface;
import android.content.Intent;
import android.content.IntentFilter;
import android.preference.ListPreference;
import android.preference.Preference;
import android.preference.PreferenceActivity;
import android.preference.PreferenceScreen;
import android.preference.CheckBoxPreference;
import android.provider.Settings;
import android.util.Log;
import android.net.wifi.WifiConfiguration; import android.net.wifi.WifiConfiguration;
import android.net.wifi.WifiConfiguration.AuthAlgorithm;
import android.net.wifi.WifiConfiguration.KeyMgmt; import android.net.wifi.WifiConfiguration.KeyMgmt;
import android.net.wifi.WifiManager; import android.net.wifi.WifiManager;
import android.os.Bundle; import android.os.Bundle;
import android.preference.CheckBoxPreference;
import android.preference.Preference;
import android.preference.PreferenceScreen;
/* /*
* Displays preferences for Tethering. * Displays preferences for Tethering.
*/ */
public class WifiApSettings extends PreferenceActivity public class WifiApSettings extends SettingsPreferenceFragment
implements DialogInterface.OnClickListener { implements DialogInterface.OnClickListener {
private static final String WIFI_AP_SSID_AND_SECURITY = "wifi_ap_ssid_and_security"; private static final String WIFI_AP_SSID_AND_SECURITY = "wifi_ap_ssid_and_security";
@@ -61,26 +56,34 @@ public class WifiApSettings extends PreferenceActivity
private WifiConfiguration mWifiConfig = null; private WifiConfiguration mWifiConfig = null;
@Override @Override
protected void onCreate(Bundle savedInstanceState) { public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
addPreferencesFromResource(R.xml.wifi_ap_settings);
}
@Override
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
final Activity activity = getActivity();
mWifiManager = (WifiManager) getSystemService(Context.WIFI_SERVICE); mWifiManager = (WifiManager) getSystemService(Context.WIFI_SERVICE);
mWifiConfig = mWifiManager.getWifiApConfiguration(); mWifiConfig = mWifiManager.getWifiApConfiguration();
mSecurityType = getResources().getStringArray(R.array.wifi_ap_security); mSecurityType = getResources().getStringArray(R.array.wifi_ap_security);
addPreferencesFromResource(R.xml.wifi_ap_settings);
mCreateNetwork = findPreference(WIFI_AP_SSID_AND_SECURITY); mCreateNetwork = findPreference(WIFI_AP_SSID_AND_SECURITY);
mEnableWifiAp = (CheckBoxPreference) findPreference(ENABLE_WIFI_AP); mEnableWifiAp = (CheckBoxPreference) findPreference(ENABLE_WIFI_AP);
mWifiApEnabler = new WifiApEnabler(this, mEnableWifiAp); mWifiApEnabler = new WifiApEnabler(activity, mEnableWifiAp);
if(mWifiConfig == null) { if(mWifiConfig == null) {
String s = getString(com.android.internal.R.string.wifi_tether_configure_ssid_default); final String s = activity.getString(
mCreateNetwork.setSummary(String.format(getString(CONFIG_SUBTEXT), com.android.internal.R.string.wifi_tether_configure_ssid_default);
mCreateNetwork.setSummary(String.format(activity.getString(CONFIG_SUBTEXT),
s, mSecurityType[OPEN_INDEX])); s, mSecurityType[OPEN_INDEX]));
} else { } else {
mCreateNetwork.setSummary(String.format(getString(CONFIG_SUBTEXT), mCreateNetwork.setSummary(String.format(activity.getString(CONFIG_SUBTEXT),
mWifiConfig.SSID, mWifiConfig.SSID,
mWifiConfig.allowedKeyManagement.get(KeyMgmt.WPA_PSK) ? mWifiConfig.allowedKeyManagement.get(KeyMgmt.WPA_PSK) ?
mSecurityType[WPA_INDEX] : mSecurityType[OPEN_INDEX])); mSecurityType[WPA_INDEX] : mSecurityType[OPEN_INDEX]));
@@ -88,22 +91,23 @@ public class WifiApSettings extends PreferenceActivity
} }
@Override @Override
protected Dialog onCreateDialog(int id) { public Dialog onCreateDialog(int id) {
if (id == DIALOG_AP_SETTINGS) { if (id == DIALOG_AP_SETTINGS) {
mDialog = new WifiApDialog(this, this, mWifiConfig); final Activity activity = getActivity();
mDialog = new WifiApDialog(activity, this, mWifiConfig);
return mDialog; return mDialog;
} }
return null; return null;
} }
@Override @Override
protected void onResume() { public void onResume() {
super.onResume(); super.onResume();
mWifiApEnabler.resume(); mWifiApEnabler.resume();
} }
@Override @Override
protected void onPause() { public void onPause() {
super.onPause(); super.onPause();
mWifiApEnabler.pause(); mWifiApEnabler.pause();
} }
@@ -117,7 +121,6 @@ public class WifiApSettings extends PreferenceActivity
} }
public void onClick(DialogInterface dialogInterface, int button) { public void onClick(DialogInterface dialogInterface, int button) {
if (button == DialogInterface.BUTTON_POSITIVE) { if (button == DialogInterface.BUTTON_POSITIVE) {
mWifiConfig = mDialog.getConfig(); mWifiConfig = mDialog.getConfig();
if (mWifiConfig != null) { if (mWifiConfig != null) {
@@ -135,7 +138,7 @@ public class WifiApSettings extends PreferenceActivity
} else { } else {
mWifiManager.setWifiApConfiguration(mWifiConfig); mWifiManager.setWifiApConfiguration(mWifiConfig);
} }
mCreateNetwork.setSummary(String.format(getString(CONFIG_SUBTEXT), mCreateNetwork.setSummary(String.format(getActivity().getString(CONFIG_SUBTEXT),
mWifiConfig.SSID, mWifiConfig.SSID,
mWifiConfig.allowedKeyManagement.get(KeyMgmt.WPA_PSK) ? mWifiConfig.allowedKeyManagement.get(KeyMgmt.WPA_PSK) ?
mSecurityType[WPA_INDEX] : mSecurityType[OPEN_INDEX])); mSecurityType[WPA_INDEX] : mSecurityType[OPEN_INDEX]));