Menu option added that allows users to send the log file
authorTobias Brunner <tobias@strongswan.org>
Fri, 10 Aug 2012 14:37:39 +0000 (16:37 +0200)
committerTobias Brunner <tobias@strongswan.org>
Mon, 13 Aug 2012 09:22:21 +0000 (11:22 +0200)
src/frontends/android/res/menu/log.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/LogActivity.java
src/frontends/android/src/org/strongswan/android/ui/MainActivity.java

diff --git a/src/frontends/android/res/menu/log.xml b/src/frontends/android/res/menu/log.xml
new file mode 100644 (file)
index 0000000..1af5bd3
--- /dev/null
@@ -0,0 +1,23 @@
+<?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.
+-->
+<menu xmlns:android="http://schemas.android.com/apk/res/android">
+
+    <item
+        android:id="@+id/menu_send_log"
+        android:title="@string/send_log"
+        android:showAsAction="ifRoom|withText" />
+
+</menu>
index 7f7288d..0e0ddd5 100644 (file)
@@ -25,6 +25,9 @@
 
     <!-- Log view -->
     <string name="log_title">Log</string>
+    <string name="send_log">Logdatei senden</string>
+    <string name="empty_log">Logdatei ist leer</string>
+    <string name="log_mail_subject">strongSwan %1$s Logdatei</string>
 
     <!-- VPN profile list -->
     <string name="no_profiles">Keine VPN Profile vorhanden.</string>
index 762273f..a83e219 100644 (file)
@@ -25,6 +25,9 @@
 
     <!-- Log view -->
     <string name="log_title">Log</string>
+    <string name="send_log">Send log file</string>
+    <string name="empty_log">Log file is empty</string>
+    <string name="log_mail_subject">strongSwan %1$s Log File</string>
 
     <!-- VPN profile list -->
     <string name="no_profiles">No VPN profiles.</string>
index 84bb458..a5efecc 100644 (file)
 
 package org.strongswan.android.ui;
 
+import java.io.File;
+
 import org.strongswan.android.R;
+import org.strongswan.android.data.LogContentProvider;
+import org.strongswan.android.logic.CharonVpnService;
 
 import android.app.Activity;
+import android.content.Intent;
+import android.content.pm.PackageManager.NameNotFoundException;
 import android.os.Bundle;
+import android.view.Menu;
 import android.view.MenuItem;
+import android.widget.Toast;
 
 public class LogActivity extends Activity
 {
@@ -33,6 +41,13 @@ public class LogActivity extends Activity
        }
 
        @Override
+       public boolean onCreateOptionsMenu(Menu menu)
+       {
+               getMenuInflater().inflate(R.menu.log, menu);
+               return true;
+       }
+
+       @Override
        public boolean onOptionsItemSelected(MenuItem item)
        {
                switch (item.getItemId())
@@ -40,6 +55,31 @@ public class LogActivity extends Activity
                        case android.R.id.home:
                                finish();
                                return true;
+                       case R.id.menu_send_log:
+                               File logfile = new File(getFilesDir(), CharonVpnService.LOG_FILE);
+                               if (!logfile.exists() || logfile.length() == 0)
+                               {
+                                       Toast.makeText(this, getString(R.string.empty_log), Toast.LENGTH_SHORT).show();
+                                       return true;
+                               }
+
+                               String version = "";
+                               try
+                               {
+                                       version = getPackageManager().getPackageInfo(getPackageName(), 0).versionName;
+                               }
+                               catch (NameNotFoundException e)
+                               {
+                                       e.printStackTrace();
+                               }
+
+                               Intent intent = new Intent(Intent.ACTION_SEND);
+                               intent.putExtra(Intent.EXTRA_EMAIL, new String[] { MainActivity.CONTACT_EMAIL });
+                               intent.putExtra(Intent.EXTRA_SUBJECT, String.format(getString(R.string.log_mail_subject), version));
+                               intent.setType("text/plain");
+                               intent.putExtra(Intent.EXTRA_STREAM, LogContentProvider.createContentUri());
+                               startActivity(Intent.createChooser(intent, getString(R.string.send_log)));
+                               return true;
                }
                return super.onOptionsItemSelected(item);
        }
index f9d6c17..80f1a27 100644 (file)
@@ -45,6 +45,7 @@ import android.widget.EditText;
 
 public class MainActivity extends Activity implements OnVpnProfileSelectedListener
 {
+       public static final String CONTACT_EMAIL = "android@strongswan.org";
        private static final int PREPARE_VPN_SERVICE = 0;
        private VpnProfile activeProfile;