android: Add fragment that displays the IMC state
authorTobias Brunner <tobias@strongswan.org>
Fri, 17 May 2013 16:18:07 +0000 (18:18 +0200)
committerTobias Brunner <tobias@strongswan.org>
Mon, 8 Jul 2013 16:49:29 +0000 (18:49 +0200)
The fragment hides itself if the state is unknown or the assessment
succeeded.

src/frontends/android/res/layout/imc_state_fragment.xml [new file with mode: 0644]
src/frontends/android/res/layout/main.xml
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/colors.xml
src/frontends/android/res/values/strings.xml
src/frontends/android/src/org/strongswan/android/ui/ImcStateFragment.java [new file with mode: 0644]

diff --git a/src/frontends/android/res/layout/imc_state_fragment.xml b/src/frontends/android/res/layout/imc_state_fragment.xml
new file mode 100644 (file)
index 0000000..bdb3cd3
--- /dev/null
@@ -0,0 +1,54 @@
+<?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:background="@drawable/vpn_state_background"
+    android:orientation="vertical" >
+
+    <LinearLayout
+        android:layout_width="match_parent"
+        android:layout_height="wrap_content"
+        android:layout_marginLeft="20dp"
+        android:layout_marginRight="20dp"
+        android:layout_marginTop="10dp"
+        android:layout_marginBottom="10dp"
+        android:orientation="horizontal" >
+
+        <TextView
+            android:layout_width="wrap_content"
+            android:layout_height="wrap_content"
+            android:layout_marginRight="5dp"
+            android:text="@string/imc_state_label"
+            android:textColor="?android:textColorPrimary"
+            android:textSize="20sp" />
+
+        <TextView
+            android:id="@+id/imc_state"
+            android:layout_width="wrap_content"
+            android:layout_height="wrap_content"
+            android:text=""
+            android:textColor="?android:textColorSecondary"
+            android:textSize="20sp" />
+
+    </LinearLayout>
+
+    <View
+        android:layout_width="match_parent"
+        android:layout_height="2dp"
+        android:background="?android:attr/listDivider" />
+
+</LinearLayout>
index 1c7973e..ab03e72 100644 (file)
@@ -1,6 +1,6 @@
 <?xml version="1.0" encoding="utf-8"?>
 <!--
-    Copyright (C) 2012 Tobias Brunner
+    Copyright (C) 2012-2013 Tobias Brunner
     Hochschule fuer Technik Rapperswil
 
     This program is free software; you can redistribute it and/or modify it
             android:layout_height="wrap_content" />
 
     <fragment
+            class="org.strongswan.android.ui.ImcStateFragment"
+            android:id="@+id/imc_state_frag"
+            android:layout_width="match_parent"
+            android:layout_height="wrap_content" />
+
+    <fragment
             class="org.strongswan.android.ui.VpnProfileListFragment"
             android:id="@+id/profile_list_frag"
             android:layout_width="match_parent"
index 77bbbe7..97da97e 100644 (file)
@@ -1,6 +1,6 @@
 <?xml version="1.0" encoding="utf-8"?>
 <!--
-    Copyright (C) 2012 Tobias Brunner
+    Copyright (C) 2012-2013 Tobias Brunner
     Copyright (C) 2012 Giuliano Grassi
     Copyright (C) 2012 Ralf Sager
     Hochschule fuer Technik Rapperswil
     <string name="state_disabled">Kein aktives Profil</string>
     <string name="state_error">Fehler</string>
 
+    <!-- IMC state fragment -->
+    <string name="imc_state_label">Assessment:</string>
+    <string name="imc_state_isolate">Eingeschränkt</string>
+    <string name="imc_state_block">Fehlgeschlagen</string>
+
     <!-- Dialogs -->
     <string name="login_title">Passwort eingeben um zu verbinden</string>
     <string name="login_confirm">Verbinden</string>
index 9a54715..e3576d5 100644 (file)
@@ -1,7 +1,5 @@
 <?xml version="1.0" encoding="utf-8"?>
 <!--
-    Copyright (C) 2012 Giuliano Grassi
-    Copyright (C) 2012 Ralf Sager
     Copyright (C) 2012 Andreas Steffen
     HSR Hochschule fuer Technik Rapperswil
 
     <string name="state_disabled">Brak aktywnego VPN</string>
     <string name="state_error">Błąd</string>
 
+    <!-- IMC state fragment -->
+    <string name="imc_state_label">Assessment:</string>
+    <string name="imc_state_isolate">Restricted</string>
+    <string name="imc_state_block">Failed</string>
+
     <!-- Dialogs -->
     <string name="login_title">Wprowadż hasło</string>
     <string name="login_confirm">Połącz</string>
index 9ff1eff..f5f696a 100644 (file)
     <string name="state_disabled">Нет активных VPN</string>
     <string name="state_error">Ошибка</string>
 
+    <!-- IMC state fragment -->
+    <string name="imc_state_label">Assessment:</string>
+    <string name="imc_state_isolate">Restricted</string>
+    <string name="imc_state_block">Failed</string>
+
     <!-- Dialogs -->
     <string name="login_title">Введите пароль для соединения</string>
     <string name="login_confirm">Соединить</string>
index e420a35..39d67ea 100644 (file)
@@ -1,7 +1,7 @@
 <?xml version="1.0" encoding="utf-8"?>
 <!--
-    Copyright (C) 2012 Dmitry Korzhevin
     Copyright (C) 2013 Pavel Kopchyk
+    Copyright (C) 2012 Dmitry Korzhevin
 
     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
     <string name="state_disabled">Немає активних VPN</string>
     <string name="state_error">Помилка</string>
 
+    <!-- IMC state fragment -->
+    <string name="imc_state_label">Assessment:</string>
+    <string name="imc_state_isolate">Restricted</string>
+    <string name="imc_state_block">Failed</string>
+
     <!-- Dialogs -->
     <string name="login_title">Введіть пароль для з\'єднання</string>
     <string name="login_confirm">Підключити</string>
index be64d5d..ee8d724 100644 (file)
@@ -1,6 +1,6 @@
 <?xml version="1.0" encoding="utf-8"?>
 <!--
-    Copyright (C) 2012 Tobias Brunner
+    Copyright (C) 2012-2013 Tobias Brunner
     Hochschule fuer Technik Rapperswil
 
     This program is free software; you can redistribute it and/or modify it
@@ -19,6 +19,9 @@
         name="error_text">#D9192C</color>
 
     <color
+        name="warning_text">#FF9909</color>
+
+    <color
         name="success_text">#99CC00</color>
 
 </resources>
index e7b7fb6..78475df 100644 (file)
@@ -1,6 +1,6 @@
 <?xml version="1.0" encoding="utf-8"?>
 <!--
-    Copyright (C) 2012 Tobias Brunner
+    Copyright (C) 2012-2013 Tobias Brunner
     Copyright (C) 2012 Giuliano Grassi
     Copyright (C) 2012 Ralf Sager
     Hochschule fuer Technik Rapperswil
     <string name="state_disabled">No active VPN</string>
     <string name="state_error">Error</string>
 
+    <!-- IMC state fragment -->
+    <string name="imc_state_label">Assessment:</string>
+    <string name="imc_state_isolate">Restricted</string>
+    <string name="imc_state_block">Failed</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/ImcStateFragment.java b/src/frontends/android/src/org/strongswan/android/ui/ImcStateFragment.java
new file mode 100644 (file)
index 0000000..4736113
--- /dev/null
@@ -0,0 +1,117 @@
+/*
+ * 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 org.strongswan.android.R;
+import org.strongswan.android.logic.VpnStateService;
+import org.strongswan.android.logic.VpnStateService.VpnStateListener;
+
+import android.app.Fragment;
+import android.app.FragmentTransaction;
+import android.app.Service;
+import android.content.ComponentName;
+import android.content.Context;
+import android.content.Intent;
+import android.content.ServiceConnection;
+import android.os.Bundle;
+import android.os.IBinder;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.view.ViewGroup;
+import android.widget.TextView;
+
+public class ImcStateFragment extends Fragment implements VpnStateListener
+{
+       private TextView mStateView;
+       private VpnStateService mService;
+       private final ServiceConnection mServiceConnection = new ServiceConnection() {
+               @Override
+               public void onServiceDisconnected(ComponentName name)
+               {
+                       mService = null;
+               }
+
+               @Override
+               public void onServiceConnected(ComponentName name, IBinder service)
+               {
+                       mService = ((VpnStateService.LocalBinder)service).getService();
+                       mService.registerListener(ImcStateFragment.this);
+                       updateView();
+               }
+       };
+
+       @Override
+       public void onCreate(Bundle savedInstanceState)
+       {
+               super.onCreate(savedInstanceState);
+
+               /* bind to the service only seems to work from the ApplicationContext */
+               Context context = getActivity().getApplicationContext();
+               context.bindService(new Intent(context, VpnStateService.class),
+                                                       mServiceConnection, Service.BIND_AUTO_CREATE);
+       }
+
+       @Override
+       public View onCreateView(LayoutInflater inflater, ViewGroup container,
+                                                        Bundle savedInstanceState)
+       {
+               View view = inflater.inflate(R.layout.imc_state_fragment, null);
+
+               mStateView = (TextView)view.findViewById(R.id.imc_state);
+
+               return view;
+       }
+
+       @Override
+       public void onDestroy()
+       {
+               super.onDestroy();
+               if (mService != null)
+               {
+                       mService.unregisterListener(this);
+                       getActivity().getApplicationContext().unbindService(mServiceConnection);
+               }
+       }
+
+       @Override
+       public void stateChanged()
+       {
+               updateView();
+       }
+
+       public void updateView()
+       {
+               FragmentTransaction ft = getFragmentManager().beginTransaction();
+               ft.show(this);
+
+               switch (mService.getImcState())
+               {
+                       case UNKNOWN:
+                       case ALLOW:
+                               ft.hide(this);
+                               break;
+                       case ISOLATE:
+                               mStateView.setText(R.string.imc_state_isolate);
+                               mStateView.setTextColor(getResources().getColor(R.color.warning_text));
+                               break;
+                       case BLOCK:
+                               mStateView.setText(R.string.imc_state_block);
+                               mStateView.setTextColor(getResources().getColor(R.color.error_text));
+                               break;
+               }
+               ft.commit();
+       }
+}