am 27682b0a
: Merge "Clear mDialogFragment when it\'s detached" into honeycomb
* commit '27682b0aff076e9d4ef6c4651effc9ce47ff6fb6': Clear mDialogFragment when it's detached
This commit is contained in:
@@ -278,7 +278,6 @@
|
|||||||
<activity android:name="Settings$VpnSettingsActivity"
|
<activity android:name="Settings$VpnSettingsActivity"
|
||||||
android:theme="@android:style/Theme.Holo"
|
android:theme="@android:style/Theme.Holo"
|
||||||
android:label="@string/vpn_settings_activity_title"
|
android:label="@string/vpn_settings_activity_title"
|
||||||
android:configChanges="orientation|keyboardHidden"
|
|
||||||
android:clearTaskOnLaunch="true">
|
android:clearTaskOnLaunch="true">
|
||||||
<intent-filter>
|
<intent-filter>
|
||||||
<action android:name="android.intent.action.MAIN" />
|
<action android:name="android.intent.action.MAIN" />
|
||||||
|
@@ -182,6 +182,8 @@ public class SettingsPreferenceFragment extends PreferenceFragment
|
|||||||
+ DialogCreatable.class.getName());
|
+ DialogCreatable.class.getName());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// restore mDialogFragment in mParentFragment
|
||||||
|
((SettingsPreferenceFragment) mParentFragment).mDialogFragment = this;
|
||||||
}
|
}
|
||||||
return ((DialogCreatable) mParentFragment).onCreateDialog(mDialogId);
|
return ((DialogCreatable) mParentFragment).onCreateDialog(mDialogId);
|
||||||
}
|
}
|
||||||
@@ -204,6 +206,16 @@ public class SettingsPreferenceFragment extends PreferenceFragment
|
|||||||
public int getDialogId() {
|
public int getDialogId() {
|
||||||
return mDialogId;
|
return mDialogId;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onDetach() {
|
||||||
|
super.onDetach();
|
||||||
|
|
||||||
|
// in case the dialog is not explicitly removed by removeDialog()
|
||||||
|
if (((SettingsPreferenceFragment) mParentFragment).mDialogFragment == this) {
|
||||||
|
((SettingsPreferenceFragment) mParentFragment).mDialogFragment = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected boolean hasNextButton() {
|
protected boolean hasNextButton() {
|
||||||
|
@@ -86,6 +86,7 @@ public class VpnSettings extends SettingsPreferenceFragment
|
|||||||
|
|
||||||
private static final String KEY_ACTIVE_PROFILE = "ActiveProfile";
|
private static final String KEY_ACTIVE_PROFILE = "ActiveProfile";
|
||||||
private static final String KEY_PROFILE_CONNECTING = "ProfileConnecting";
|
private static final String KEY_PROFILE_CONNECTING = "ProfileConnecting";
|
||||||
|
private static final String KEY_CONNECT_DIALOG_SHOWING = "ConnectDialogShowing";
|
||||||
|
|
||||||
private static final int REQUEST_ADD_OR_EDIT_PROFILE = 1;
|
private static final int REQUEST_ADD_OR_EDIT_PROFILE = 1;
|
||||||
static final int REQUEST_SELECT_VPN_TYPE = 2;
|
static final int REQUEST_SELECT_VPN_TYPE = 2;
|
||||||
@@ -140,33 +141,6 @@ public class VpnSettings extends SettingsPreferenceFragment
|
|||||||
public void onCreate(Bundle savedInstanceState) {
|
public void onCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
addPreferencesFromResource(R.xml.vpn_settings);
|
addPreferencesFromResource(R.xml.vpn_settings);
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onSaveInstanceState(Bundle savedInstanceState) {
|
|
||||||
if (mActiveProfile != null) {
|
|
||||||
savedInstanceState.putString(KEY_ACTIVE_PROFILE,
|
|
||||||
mActiveProfile.getId());
|
|
||||||
savedInstanceState.putBoolean(KEY_PROFILE_CONNECTING,
|
|
||||||
(mConnectingActor != null));
|
|
||||||
}
|
|
||||||
super.onSaveInstanceState(savedInstanceState);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void restoreInstanceState(Bundle savedInstanceState) {
|
|
||||||
if (savedInstanceState == null) return;
|
|
||||||
String profileId = savedInstanceState.getString(KEY_ACTIVE_PROFILE);
|
|
||||||
if (profileId != null) {
|
|
||||||
mActiveProfile = getProfile(getProfileIndexFromId(profileId));
|
|
||||||
if (savedInstanceState.getBoolean(KEY_PROFILE_CONNECTING)) {
|
|
||||||
mConnectingActor = getActor(mActiveProfile);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onActivityCreated(Bundle savedInstanceState) {
|
|
||||||
super.onActivityCreated(savedInstanceState);
|
|
||||||
|
|
||||||
mVpnManager = new VpnManager(getActivity());
|
mVpnManager = new VpnManager(getActivity());
|
||||||
// restore VpnProfile list and construct VpnPreference map
|
// restore VpnProfile list and construct VpnPreference map
|
||||||
@@ -182,13 +156,43 @@ public class VpnSettings extends SettingsPreferenceFragment
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// for long-press gesture on a profile preference
|
|
||||||
registerForContextMenu(getListView());
|
|
||||||
|
|
||||||
retrieveVpnListFromStorage();
|
retrieveVpnListFromStorage();
|
||||||
restoreInstanceState(savedInstanceState);
|
restoreInstanceState(savedInstanceState);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onSaveInstanceState(Bundle savedInstanceState) {
|
||||||
|
if (mActiveProfile != null) {
|
||||||
|
savedInstanceState.putString(KEY_ACTIVE_PROFILE,
|
||||||
|
mActiveProfile.getId());
|
||||||
|
savedInstanceState.putBoolean(KEY_PROFILE_CONNECTING,
|
||||||
|
(mConnectingActor != null));
|
||||||
|
savedInstanceState.putBoolean(KEY_CONNECT_DIALOG_SHOWING,
|
||||||
|
mConnectDialogShowing);
|
||||||
|
}
|
||||||
|
super.onSaveInstanceState(savedInstanceState);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void restoreInstanceState(Bundle savedInstanceState) {
|
||||||
|
if (savedInstanceState == null) return;
|
||||||
|
String profileId = savedInstanceState.getString(KEY_ACTIVE_PROFILE);
|
||||||
|
if (profileId != null) {
|
||||||
|
mActiveProfile = getProfile(getProfileIndexFromId(profileId));
|
||||||
|
if (savedInstanceState.getBoolean(KEY_PROFILE_CONNECTING)) {
|
||||||
|
mConnectingActor = getActor(mActiveProfile);
|
||||||
|
}
|
||||||
|
mConnectDialogShowing = savedInstanceState.getBoolean(KEY_CONNECT_DIALOG_SHOWING);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onActivityCreated(Bundle savedInstanceState) {
|
||||||
|
super.onActivityCreated(savedInstanceState);
|
||||||
|
|
||||||
|
// for long-press gesture on a profile preference
|
||||||
|
registerForContextMenu(getListView());
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onPause() {
|
public void onPause() {
|
||||||
// ignore vpn connectivity event
|
// ignore vpn connectivity event
|
||||||
@@ -205,8 +209,7 @@ public class VpnSettings extends SettingsPreferenceFragment
|
|||||||
super.onResume();
|
super.onResume();
|
||||||
updatePreferenceMap();
|
updatePreferenceMap();
|
||||||
|
|
||||||
if (DEBUG)
|
if (DEBUG) Log.d(TAG, "onResume");
|
||||||
Log.d(TAG, "onResume");
|
|
||||||
|
|
||||||
// listen to vpn connectivity event
|
// listen to vpn connectivity event
|
||||||
mVpnManager.registerConnectivityReceiver(mConnectivityReceiver);
|
mVpnManager.registerConnectivityReceiver(mConnectivityReceiver);
|
||||||
@@ -249,17 +252,7 @@ public class VpnSettings extends SettingsPreferenceFragment
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void showDialog(int dialogId) {
|
public Dialog onCreateDialog (int id) {
|
||||||
super.showDialog(dialogId);
|
|
||||||
|
|
||||||
if (dialogId == DIALOG_CONNECT) {
|
|
||||||
mConnectDialogShowing = true;
|
|
||||||
setOnDismissListener(new DialogInterface.OnDismissListener() {
|
|
||||||
public void onDismiss(DialogInterface dialog) {
|
|
||||||
mConnectDialogShowing = false;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
setOnCancelListener(new DialogInterface.OnCancelListener() {
|
setOnCancelListener(new DialogInterface.OnCancelListener() {
|
||||||
public void onCancel(DialogInterface dialog) {
|
public void onCancel(DialogInterface dialog) {
|
||||||
if (mActiveProfile != null) {
|
if (mActiveProfile != null) {
|
||||||
@@ -272,12 +265,15 @@ public class VpnSettings extends SettingsPreferenceFragment
|
|||||||
onIdle();
|
onIdle();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Dialog onCreateDialog (int id) {
|
|
||||||
switch (id) {
|
switch (id) {
|
||||||
case DIALOG_CONNECT:
|
case DIALOG_CONNECT:
|
||||||
|
mConnectDialogShowing = true;
|
||||||
|
setOnDismissListener(new DialogInterface.OnDismissListener() {
|
||||||
|
public void onDismiss(DialogInterface dialog) {
|
||||||
|
mConnectDialogShowing = false;
|
||||||
|
}
|
||||||
|
});
|
||||||
return createConnectDialog();
|
return createConnectDialog();
|
||||||
|
|
||||||
case DIALOG_SECRET_NOT_SET:
|
case DIALOG_SECRET_NOT_SET:
|
||||||
@@ -524,7 +520,6 @@ public class VpnSettings extends SettingsPreferenceFragment
|
|||||||
String error = mConnectingActor.validateInputs(d);
|
String error = mConnectingActor.validateInputs(d);
|
||||||
if (error == null) {
|
if (error == null) {
|
||||||
mConnectingActor.connect(d);
|
mConnectingActor.connect(d);
|
||||||
return;
|
|
||||||
} else {
|
} else {
|
||||||
// show error dialog
|
// show error dialog
|
||||||
final Activity activity = getActivity();
|
final Activity activity = getActivity();
|
||||||
@@ -795,7 +790,6 @@ public class VpnSettings extends SettingsPreferenceFragment
|
|||||||
|
|
||||||
private void changeState(VpnProfile p, VpnState state) {
|
private void changeState(VpnProfile p, VpnState state) {
|
||||||
VpnState oldState = p.getState();
|
VpnState oldState = p.getState();
|
||||||
if (oldState == state) return;
|
|
||||||
p.setState(state);
|
p.setState(state);
|
||||||
mVpnPreferenceMap.get(p.getName()).setSummary(
|
mVpnPreferenceMap.get(p.getName()).setSummary(
|
||||||
getProfileSummaryString(p));
|
getProfileSummaryString(p));
|
||||||
@@ -808,7 +802,9 @@ public class VpnSettings extends SettingsPreferenceFragment
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case CONNECTING:
|
case CONNECTING:
|
||||||
|
if (mConnectingActor == null) {
|
||||||
mConnectingActor = getActor(p);
|
mConnectingActor = getActor(p);
|
||||||
|
}
|
||||||
// $FALL-THROUGH$
|
// $FALL-THROUGH$
|
||||||
case DISCONNECTING:
|
case DISCONNECTING:
|
||||||
mActiveProfile = p;
|
mActiveProfile = p;
|
||||||
@@ -883,12 +879,12 @@ public class VpnSettings extends SettingsPreferenceFragment
|
|||||||
mVpnPreferenceMap = new LinkedHashMap<String, VpnPreference>();
|
mVpnPreferenceMap = new LinkedHashMap<String, VpnPreference>();
|
||||||
mVpnListContainer.removeAll();
|
mVpnListContainer.removeAll();
|
||||||
for (VpnProfile p : sVpnProfileList) {
|
for (VpnProfile p : sVpnProfileList) {
|
||||||
addPreferenceFor(p, false);
|
addPreferenceFor(p, true);
|
||||||
}
|
}
|
||||||
// reset the mActiveProfile if the profile has been removed from the
|
// reset the mActiveProfile if the profile has been removed from the
|
||||||
// other instance.
|
// other instance.
|
||||||
if ((mActiveProfile != null)
|
if ((mActiveProfile != null)
|
||||||
&& mVpnPreferenceMap.containsKey(mActiveProfile.getName())) {
|
&& !mVpnPreferenceMap.containsKey(mActiveProfile.getName())) {
|
||||||
onIdle();
|
onIdle();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -924,11 +920,6 @@ public class VpnSettings extends SettingsPreferenceFragment
|
|||||||
for (VpnProfile p : sVpnProfileList) {
|
for (VpnProfile p : sVpnProfileList) {
|
||||||
changeState(p, mVpnManager.getState(p));
|
changeState(p, mVpnManager.getState(p));
|
||||||
}
|
}
|
||||||
// make preferences appear
|
|
||||||
for (VpnProfile p : sVpnProfileList) {
|
|
||||||
VpnPreference pref = mVpnPreferenceMap.get(p.getName());
|
|
||||||
mVpnListContainer.addPreference(pref);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// A sanity check. Returns true if the profile directory name and profile ID
|
// A sanity check. Returns true if the profile directory name and profile ID
|
||||||
|
Reference in New Issue
Block a user