android: Add activity that displays a list of remediation instructions
authorTobias Brunner <tobias@strongswan.org>
Thu, 30 May 2013 09:55:44 +0000 (11:55 +0200)
committerTobias Brunner <tobias@strongswan.org>
Mon, 8 Jul 2013 16:49:29 +0000 (18:49 +0200)
On large displays a two-pane layout is used that displays the list next
to the actual instructions.

src/frontends/android/AndroidManifest.xml
src/frontends/android/res/drawable/remediation_instruction_background_large.xml [new file with mode: 0644]
src/frontends/android/res/layout-large/remediation_instructions.xml [new file with mode: 0644]
src/frontends/android/res/layout/remediation_instructions.xml [new file with mode: 0644]
src/frontends/android/res/values-de/strings.xml
src/frontends/android/res/values-pl/strings.xml
src/frontends/android/res/values-ru/strings.xml
src/frontends/android/res/values-ua/strings.xml
src/frontends/android/res/values/strings.xml
src/frontends/android/src/org/strongswan/android/ui/RemediationInstructionsActivity.java [new file with mode: 0644]
src/frontends/android/src/org/strongswan/android/ui/RemediationInstructionsFragment.java

index 4d76ac0..dd03cf2 100644 (file)
             android:label="@string/log_title" >
         </activity>
         <activity
+            android:name=".ui.RemediationInstructionsActivity"
+            android:label="@string/remediation_instructions_title" >
+        </activity>
+        <activity
             android:name=".ui.VpnProfileSelectActivity"
             android:label="@string/strongswan_shortcut" >
             <intent-filter>
diff --git a/src/frontends/android/res/drawable/remediation_instruction_background_large.xml b/src/frontends/android/res/drawable/remediation_instruction_background_large.xml
new file mode 100644 (file)
index 0000000..470fecb
--- /dev/null
@@ -0,0 +1,32 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+    Copyright (C) 2013 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.
+-->
+<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
+
+    <item>
+        <shape>
+            <solid
+                android:color="@color/panel_separator" />
+        </shape>
+    </item>
+
+    <item android:left="2dp">
+        <shape>
+            <solid
+                android:color="@color/panel_background" />
+        </shape>
+    </item>
+
+</layer-list>
diff --git a/src/frontends/android/res/layout-large/remediation_instructions.xml b/src/frontends/android/res/layout-large/remediation_instructions.xml
new file mode 100644 (file)
index 0000000..5a28dd6
--- /dev/null
@@ -0,0 +1,44 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+    Copyright (C) 2013 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.
+-->
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+    android:layout_width="match_parent"
+    android:layout_height="match_parent"
+    android:orientation="horizontal"
+    android:baselineAligned="false" >
+
+    <fragment
+        class="org.strongswan.android.ui.RemediationInstructionsFragment"
+        android:id="@+id/remediation_instructions_fragment"
+        android:layout_height="match_parent"
+        android:layout_weight="1"
+        android:layout_width="0dp" />
+
+    <FrameLayout
+        android:layout_height="match_parent"
+        android:layout_weight="2"
+        android:layout_width="0dp"
+        android:background="@drawable/remediation_instruction_background_large"
+        android:padding="5dp" >
+
+        <fragment
+            class="org.strongswan.android.ui.RemediationInstructionFragment"
+            android:id="@+id/remediation_instruction_fragment"
+            android:layout_height="match_parent"
+            android:layout_width="match_parent" />
+
+    </FrameLayout>
+
+</LinearLayout>
diff --git a/src/frontends/android/res/layout/remediation_instructions.xml b/src/frontends/android/res/layout/remediation_instructions.xml
new file mode 100644 (file)
index 0000000..84143b5
--- /dev/null
@@ -0,0 +1,21 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+    Copyright (C) 2013 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"
+    android:id="@+id/fragment_container">
+
+</FrameLayout>
\ No newline at end of file
index 97da97e..6414f11 100644 (file)
@@ -91,6 +91,9 @@
     <string name="imc_state_isolate">Eingeschränkt</string>
     <string name="imc_state_block">Fehlgeschlagen</string>
 
+    <!-- Remediation instructions -->
+    <string name="remediation_instructions_title">Korrekturanweisungen</string>
+
     <!-- Dialogs -->
     <string name="login_title">Passwort eingeben um zu verbinden</string>
     <string name="login_confirm">Verbinden</string>
index e3576d5..722bc10 100644 (file)
@@ -91,6 +91,9 @@
     <string name="imc_state_isolate">Restricted</string>
     <string name="imc_state_block">Failed</string>
 
+    <!-- Remediation instructions -->
+    <string name="remediation_instructions_title">Remediation instructions</string>
+
     <!-- Dialogs -->
     <string name="login_title">Wprowadż hasło</string>
     <string name="login_confirm">Połącz</string>
index f5f696a..c82350b 100644 (file)
@@ -88,6 +88,9 @@
     <string name="imc_state_isolate">Restricted</string>
     <string name="imc_state_block">Failed</string>
 
+    <!-- Remediation instructions -->
+    <string name="remediation_instructions_title">Remediation instructions</string>
+
     <!-- Dialogs -->
     <string name="login_title">Введите пароль для соединения</string>
     <string name="login_confirm">Соединить</string>
index 39d67ea..3d82008 100644 (file)
@@ -89,6 +89,9 @@
     <string name="imc_state_isolate">Restricted</string>
     <string name="imc_state_block">Failed</string>
 
+    <!-- Remediation instructions -->
+    <string name="remediation_instructions_title">Remediation instructions</string>
+
     <!-- Dialogs -->
     <string name="login_title">Введіть пароль для з\'єднання</string>
     <string name="login_confirm">Підключити</string>
index 78475df..b275cd5 100644 (file)
@@ -91,6 +91,9 @@
     <string name="imc_state_isolate">Restricted</string>
     <string name="imc_state_block">Failed</string>
 
+    <!-- Remediation instructions -->
+    <string name="remediation_instructions_title">Remediation instructions</string>
+
     <!-- Dialogs -->
     <string name="login_title">Enter password to connect</string>
     <string name="login_confirm">Connect</string>
diff --git a/src/frontends/android/src/org/strongswan/android/ui/RemediationInstructionsActivity.java b/src/frontends/android/src/org/strongswan/android/ui/RemediationInstructionsActivity.java
new file mode 100644 (file)
index 0000000..66d0de2
--- /dev/null
@@ -0,0 +1,94 @@
+/*
+ * Copyright (C) 2013 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 java.util.ArrayList;
+
+import org.strongswan.android.R;
+import org.strongswan.android.logic.imc.RemediationInstruction;
+import org.strongswan.android.ui.RemediationInstructionsFragment.OnRemediationInstructionSelectedListener;
+
+import android.app.Activity;
+import android.os.Bundle;
+import android.view.MenuItem;
+
+public class RemediationInstructionsActivity extends Activity implements OnRemediationInstructionSelectedListener
+{
+       @Override
+       protected void onCreate(Bundle savedInstanceState)
+       {
+               super.onCreate(savedInstanceState);
+               setContentView(R.layout.remediation_instructions);
+               getActionBar().setDisplayHomeAsUpEnabled(true);
+
+               if (savedInstanceState != null)
+               {       /* only update if we're not restoring */
+                       return;
+               }
+               RemediationInstructionsFragment frag = (RemediationInstructionsFragment)getFragmentManager().findFragmentById(R.id.remediation_instructions_fragment);
+               if (frag != null)
+               {       /* two-pane layout, update fragment */
+                       Bundle extras = getIntent().getExtras();
+                       ArrayList<RemediationInstruction> list = extras.getParcelableArrayList(RemediationInstructionsFragment.EXTRA_REMEDIATION_INSTRUCTIONS);
+                       frag.updateView(list);
+               }
+               else
+               {       /* one-pane layout, create fragment */
+                       frag = new RemediationInstructionsFragment();
+                       frag.setArguments(getIntent().getExtras());
+                       getFragmentManager().beginTransaction().add(R.id.fragment_container, frag).commit();
+               }
+       }
+
+       @Override
+       public boolean onOptionsItemSelected(MenuItem item)
+       {
+               switch (item.getItemId())
+               {
+                       case android.R.id.home:
+                               /* one-pane layout, pop possible fragment from stack, finish otherwise */
+                               if (!getFragmentManager().popBackStackImmediate())
+                               {
+                                       finish();
+                               }
+                               getActionBar().setTitle(getTitle());
+                               return true;
+                       default:
+                               return super.onOptionsItemSelected(item);
+               }
+       }
+
+       @Override
+       public void onRemediationInstructionSelected(RemediationInstruction instruction)
+       {
+               RemediationInstructionFragment frag = (RemediationInstructionFragment)getFragmentManager().findFragmentById(R.id.remediation_instruction_fragment);
+
+               if (frag != null)
+               {       /* two-pane layout, update directly */
+                       frag.updateView(instruction);
+               }
+               else
+               {       /* one-pane layout, replace fragment */
+                       frag = new RemediationInstructionFragment();
+                       Bundle args = new Bundle();
+                       args.putParcelable(RemediationInstructionFragment.ARG_REMEDIATION_INSTRUCTION, instruction);
+                       frag.setArguments(args);
+
+                       getFragmentManager().beginTransaction().replace(R.id.fragment_container, frag).addToBackStack(null).commit();
+                       getActionBar().setTitle(instruction.getTitle());
+               }
+       }
+}
index 9aa7ea1..86467dc 100644 (file)
@@ -17,6 +17,7 @@ package org.strongswan.android.ui;
 
 import java.util.ArrayList;
 
+import org.strongswan.android.R;
 import org.strongswan.android.logic.imc.RemediationInstruction;
 import org.strongswan.android.ui.adapter.RemediationInstructionAdapter;
 
@@ -79,7 +80,7 @@ public class RemediationInstructionsFragment extends ListFragment
        {
                super.onStart();
 
-               boolean two_pane = false;
+               boolean two_pane = getFragmentManager().findFragmentById(R.id.remediation_instruction_fragment) != null;
                if (two_pane)
                {       /* two-pane layout, make list items selectable */
                        getListView().setChoiceMode(ListView.CHOICE_MODE_SINGLE);