Added an activity that shows lists of CA certificates in two tabs
authorTobias Brunner <tobias@strongswan.org>
Tue, 14 Aug 2012 08:10:52 +0000 (10:10 +0200)
committerTobias Brunner <tobias@strongswan.org>
Tue, 14 Aug 2012 10:01:41 +0000 (12:01 +0200)
src/frontends/android/AndroidManifest.xml
src/frontends/android/res/layout/trusted_certificates_activity.xml [new file with mode: 0644]
src/frontends/android/res/values-de/strings.xml
src/frontends/android/res/values/strings.xml
src/frontends/android/src/org/strongswan/android/ui/TrustedCertificatesActivity.java [new file with mode: 0644]

index 747fe1d..59e8679 100644 (file)
             android:name=".ui.VpnProfileDetailActivity" >
         </activity>
         <activity
+            android:name=".ui.TrustedCertificatesActivity"
+            android:label="@string/trusted_certs_title" >
+        </activity>
+        <activity
             android:name=".ui.LogActivity"
             android:label="@string/log_title" >
         </activity>
diff --git a/src/frontends/android/res/layout/trusted_certificates_activity.xml b/src/frontends/android/res/layout/trusted_certificates_activity.xml
new file mode 100644 (file)
index 0000000..966ecf2
--- /dev/null
@@ -0,0 +1,20 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+    Copyright (C) 2012 Tobias Brunner
+    Hochschule fuer Technik Rapperswil
+
+    This program is free software; you can redistribute it and/or modify it
+    under the terms of the GNU General Public License as published by the
+    Free Software Foundation; either version 2 of the License, or (at your
+    option) any later version.  See <http://www.fsf.org/copyleft/gpl.txt>.
+
+    This program is distributed in the hope that it will be useful, but
+    WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+    or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+    for more details.
+-->
+<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
+    android:layout_width="match_parent"
+    android:layout_height="match_parent" >
+
+</FrameLayout>
index ce5cb6a..bbbea55 100644 (file)
     <string name="alert_text_nocertfound">Bitte wählen Sie eines aus oder aktivieren Sie <i>Automatisch wählen</i></string>
 
     <!-- Trusted certificate selection -->
+    <string name="trusted_certs_title">CA-Zertifikate</string>
     <string name="no_certificates">Keine Zertifikate</string>
+    <string name="system_tab">System</string>
+    <string name="user_tab">Benutzer</string>
 
     <!-- VPN state fragment -->
     <string name="state_label">Status:</string>
index 591bfff..823399a 100644 (file)
     <string name="alert_text_nocertfound">Please select one or activate <i>Select automatically</i></string>
 
     <!-- Trusted certificate selection -->
+    <string name="trusted_certs_title">CA certificates</string>
     <string name="no_certificates">No certificates</string>
+    <string name="system_tab">System</string>
+    <string name="user_tab">User</string>
 
     <!-- VPN state fragment -->
     <string name="state_label">Status:</string>
diff --git a/src/frontends/android/src/org/strongswan/android/ui/TrustedCertificatesActivity.java b/src/frontends/android/src/org/strongswan/android/ui/TrustedCertificatesActivity.java
new file mode 100644 (file)
index 0000000..e4a9f33
--- /dev/null
@@ -0,0 +1,129 @@
+/*
+ * Copyright (C) 2012 Tobias Brunner
+ * Hochschule fuer Technik Rapperswil
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the
+ * Free Software Foundation; either version 2 of the License, or (at your
+ * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * for more details.
+ */
+
+package org.strongswan.android.ui;
+
+import org.strongswan.android.R;
+
+import android.app.ActionBar;
+import android.app.ActionBar.Tab;
+import android.app.Activity;
+import android.app.Fragment;
+import android.app.FragmentTransaction;
+import android.os.Bundle;
+import android.view.MenuItem;
+
+public class TrustedCertificatesActivity extends Activity
+{
+       @Override
+       public void onCreate(Bundle savedInstanceState)
+       {
+               super.onCreate(savedInstanceState);
+               setContentView(R.layout.trusted_certificates_activity);
+
+               ActionBar actionBar = getActionBar();
+               actionBar.setDisplayHomeAsUpEnabled(true);
+               actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
+
+               actionBar.addTab(actionBar
+                       .newTab()
+                       .setText(R.string.system_tab)
+                       .setTabListener(new TrustedCertificatesTabListener(this, "system", false)));
+               actionBar.addTab(actionBar
+                       .newTab()
+                       .setText(R.string.user_tab)
+                       .setTabListener(new TrustedCertificatesTabListener(this, "user", true)));
+
+               if (savedInstanceState != null)
+               {
+                       actionBar.setSelectedNavigationItem(savedInstanceState.getInt("tab", 0));
+               }
+       }
+
+       @Override
+       protected void onSaveInstanceState(Bundle outState)
+       {
+               super.onSaveInstanceState(outState);
+               outState.putInt("tab", getActionBar().getSelectedNavigationIndex());
+       }
+
+       @Override
+       public boolean onOptionsItemSelected(MenuItem item)
+       {
+               switch (item.getItemId())
+               {
+                       case android.R.id.home:
+                               finish();
+                               return true;
+               }
+               return super.onOptionsItemSelected(item);
+       }
+
+       public static class TrustedCertificatesTabListener implements ActionBar.TabListener
+       {
+               private final String mTag;
+               private final boolean mUser;
+               private Fragment mFragment;
+
+               public TrustedCertificatesTabListener(Activity activity, String tag, boolean user)
+               {
+                       mTag = tag;
+                       mUser = user;
+                       /* check to see if we already have a fragment for this tab, probably
+                        * from a previously saved state. if so, deactivate it, because the
+                        * initial state is that no tab is shown */
+                       mFragment = activity.getFragmentManager().findFragmentByTag(mTag);
+                       if (mFragment != null && !mFragment.isDetached())
+                       {
+                               FragmentTransaction ft = activity.getFragmentManager().beginTransaction();
+                               ft.detach(mFragment);
+                               ft.commit();
+                       }
+               }
+
+               @Override
+               public void onTabSelected(Tab tab, FragmentTransaction ft)
+               {
+                       if (mFragment == null)
+                       {
+                               mFragment = new TrustedCertificateListFragment();
+                               if (mUser)
+                               {       /* use non empty arguments to indicate this */
+                                       mFragment.setArguments(new Bundle());
+                               }
+                               ft.add(android.R.id.content, mFragment, mTag);
+                       }
+                       else
+                       {
+                               ft.attach(mFragment);
+                       }
+               }
+
+               @Override
+               public void onTabUnselected(Tab tab, FragmentTransaction ft)
+               {
+                       if (mFragment != null)
+                       {
+                               ft.detach(mFragment);
+                       }
+               }
+
+               @Override
+               public void onTabReselected(Tab tab, FragmentTransaction ft)
+               {
+                       /* nothing to be done */
+               }
+       }
+}