]> git.ipfire.org Git - thirdparty/strongswan.git/commitdiff
android: Hide previous dialogs when handling a new connection attempt
authorTobias Brunner <tobias@strongswan.org>
Tue, 20 Nov 2012 14:47:54 +0000 (15:47 +0100)
committerTobias Brunner <tobias@strongswan.org>
Wed, 21 Nov 2012 17:57:41 +0000 (18:57 +0100)
src/frontends/android/src/org/strongswan/android/ui/MainActivity.java

index 2fd00efc94822713fdc12f2b507459a4587194ca..50f83b2b4cec301b0117e2d177f5bc51f2ee1631 100644 (file)
@@ -32,6 +32,9 @@ import android.app.AlertDialog;
 import android.app.AlertDialog.Builder;
 import android.app.Dialog;
 import android.app.DialogFragment;
+import android.app.Fragment;
+import android.app.FragmentManager;
+import android.app.FragmentTransaction;
 import android.app.Service;
 import android.content.ActivityNotFoundException;
 import android.content.ComponentName;
@@ -215,6 +218,10 @@ public class MainActivity extends Activity implements OnVpnProfileSelectedListen
                profileInfo.putBoolean(PROFILE_REQUIRES_PASSWORD, profile.getVpnType().getRequiresUsernamePassword());
                profileInfo.putString(PROFILE_NAME, profile.getName());
 
+               removeFragmentByTag("ConfirmationDialog");
+               removeFragmentByTag("LoginDialog");
+               removeFragmentByTag("ErrorDialog");
+
                if (mService != null && mService.getState() == State.CONNECTED)
                {
                        profileInfo.putBoolean(PROFILE_RECONNECT, mService.getProfile().getId() == profile.getId());
@@ -297,6 +304,21 @@ public class MainActivity extends Activity implements OnVpnProfileSelectedListen
                }
        }
 
+       /**
+        * Dismiss dialog if shown
+        */
+       public void removeFragmentByTag(String tag)
+       {
+               FragmentManager fm = getFragmentManager();
+               Fragment login = fm.findFragmentByTag(tag);
+               if (login != null)
+               {
+                       FragmentTransaction ft = fm.beginTransaction();
+                       ft.remove(login);
+                       ft.commit();
+               }
+       }
+
        /**
         * Class that displays a confirmation dialog if a VPN profile is already connected
         * and then initiates the selected VPN profile if the user confirms the dialog.