android: Move profile name field to the bottom and use server address as hint
[strongswan.git] / src / frontends / android / app / src / main / java / org / strongswan / android / ui / VpnProfileDetailActivity.java
index a8b3daa..9271191 100644 (file)
 
 package org.strongswan.android.ui;
 
-import java.security.cert.X509Certificate;
-
-import org.strongswan.android.R;
-import org.strongswan.android.data.VpnProfile;
-import org.strongswan.android.data.VpnProfileDataSource;
-import org.strongswan.android.data.VpnType;
-import org.strongswan.android.data.VpnType.VpnTypeFeature;
-import org.strongswan.android.logic.TrustedCertificateManager;
-import org.strongswan.android.security.TrustedCertificateEntry;
-
-import android.app.Activity;
-import android.app.AlertDialog;
 import android.app.Dialog;
-import android.app.DialogFragment;
 import android.content.Context;
 import android.content.DialogInterface;
 import android.content.Intent;
@@ -39,7 +26,13 @@ import android.os.Bundle;
 import android.security.KeyChain;
 import android.security.KeyChainAliasCallback;
 import android.security.KeyChainException;
+import android.support.v7.app.AlertDialog;
+import android.support.v7.app.AppCompatActivity;
+import android.support.v7.app.AppCompatDialogFragment;
+import android.text.Editable;
 import android.text.Html;
+import android.text.TextUtils;
+import android.text.TextWatcher;
 import android.util.Log;
 import android.view.Menu;
 import android.view.MenuInflater;
@@ -57,7 +50,17 @@ import android.widget.RelativeLayout;
 import android.widget.Spinner;
 import android.widget.TextView;
 
-public class VpnProfileDetailActivity extends Activity
+import org.strongswan.android.R;
+import org.strongswan.android.data.VpnProfile;
+import org.strongswan.android.data.VpnProfileDataSource;
+import org.strongswan.android.data.VpnType;
+import org.strongswan.android.data.VpnType.VpnTypeFeature;
+import org.strongswan.android.logic.TrustedCertificateManager;
+import org.strongswan.android.security.TrustedCertificateEntry;
+
+import java.security.cert.X509Certificate;
+
+public class VpnProfileDetailActivity extends AppCompatActivity
 {
        private static final int SELECT_TRUSTED_CERTIFICATE = 0;
        private static final int MTU_MIN = 1280;
@@ -94,7 +97,7 @@ public class VpnProfileDetailActivity extends Activity
                super.onCreate(savedInstanceState);
 
                /* the title is set when we load the profile, if any */
-               getActionBar().setDisplayHomeAsUpEnabled(true);
+               getSupportActionBar().setDisplayHomeAsUpEnabled(true);
 
                mDataSource = new VpnProfileDataSource(this);
                mDataSource.open();
@@ -124,6 +127,26 @@ public class VpnProfileDetailActivity extends Activity
                mBlockIPv4 = (CheckBox)findViewById(R.id.split_tunneling_v4);
                mBlockIPv6 = (CheckBox)findViewById(R.id.split_tunneling_v6);
 
+               mGateway.addTextChangedListener(new TextWatcher() {
+                       @Override
+                       public void beforeTextChanged(CharSequence s, int start, int count, int after) {}
+
+                       @Override
+                       public void onTextChanged(CharSequence s, int start, int before, int count) {}
+
+                       @Override
+                       public void afterTextChanged(Editable s) {
+                               if (TextUtils.isEmpty(mGateway.getText()))
+                               {
+                                       mName.setHint(R.string.profile_name_hint);
+                               }
+                               else
+                               {
+                                       mName.setHint("(" + mGateway.getText() + ")");
+                               }
+                       }
+               });
+
                mSelectVpnType.setOnItemSelectedListener(new OnItemSelectedListener() {
                        @Override
                        public void onItemSelected(AdapterView<?> parent, View view, int position, long id)
@@ -146,7 +169,7 @@ public class VpnProfileDetailActivity extends Activity
                        @Override
                        public void onClick(View v)
                        {
-                               new TncNoticeDialog().show(VpnProfileDetailActivity.this.getFragmentManager(), "TncNotice");
+                               new TncNoticeDialog().show(VpnProfileDetailActivity.this.getSupportFragmentManager(), "TncNotice");
                        }
                });
 
@@ -465,7 +488,7 @@ public class VpnProfileDetailActivity extends Activity
        {
                String useralias = null, alias = null;
 
-               getActionBar().setTitle(R.string.add_profile);
+               getSupportActionBar().setTitle(R.string.add_profile);
                if (mId != null && mId != 0)
                {
                        mProfile = mDataSource.getVpnProfile(mId);
@@ -482,7 +505,7 @@ public class VpnProfileDetailActivity extends Activity
                                mBlockIPv6.setChecked(mProfile.getSplitTunneling() != null ? (mProfile.getSplitTunneling() & VpnProfile.SPLIT_TUNNELING_BLOCK_IPV6) != 0 : false);
                                useralias = mProfile.getUserCertificateAlias();
                                alias = mProfile.getCertificateAlias();
-                               getActionBar().setTitle(mProfile.getName());
+                               getSupportActionBar().setTitle(mProfile.getName());
                        }
                        else
                        {
@@ -633,7 +656,7 @@ public class VpnProfileDetailActivity extends Activity
        /**
         * Dialog with notification message if EAP-TNC is used.
         */
-       public static class TncNoticeDialog extends DialogFragment
+       public static class TncNoticeDialog extends AppCompatDialogFragment
        {
                @Override
                public Dialog onCreateDialog(Bundle savedInstanceState)