]> git.ipfire.org Git - thirdparty/strongswan.git/blob - src/frontends/android/app/src/main/java/org/strongswan/android/ui/LogActivity.java
android: Migrate to the Gradle build system
[thirdparty/strongswan.git] / src / frontends / android / app / src / main / java / org / strongswan / android / ui / LogActivity.java
1 /*
2 * Copyright (C) 2012 Tobias Brunner
3 * Hochschule fuer Technik Rapperswil
4 *
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License as published by the
7 * Free Software Foundation; either version 2 of the License, or (at your
8 * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
9 *
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
12 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
13 * for more details.
14 */
15
16 package org.strongswan.android.ui;
17
18 import java.io.File;
19
20 import org.strongswan.android.R;
21 import org.strongswan.android.data.LogContentProvider;
22 import org.strongswan.android.logic.CharonVpnService;
23
24 import android.app.Activity;
25 import android.content.Intent;
26 import android.content.pm.PackageManager.NameNotFoundException;
27 import android.os.Bundle;
28 import android.view.Menu;
29 import android.view.MenuItem;
30 import android.widget.Toast;
31
32 public class LogActivity extends Activity
33 {
34 @Override
35 public void onCreate(Bundle savedInstanceState)
36 {
37 super.onCreate(savedInstanceState);
38 setContentView(R.layout.log_activity);
39
40 getActionBar().setDisplayHomeAsUpEnabled(true);
41 }
42
43 @Override
44 public boolean onCreateOptionsMenu(Menu menu)
45 {
46 getMenuInflater().inflate(R.menu.log, menu);
47 return true;
48 }
49
50 @Override
51 public boolean onOptionsItemSelected(MenuItem item)
52 {
53 switch (item.getItemId())
54 {
55 case android.R.id.home:
56 finish();
57 return true;
58 case R.id.menu_send_log:
59 File logfile = new File(getFilesDir(), CharonVpnService.LOG_FILE);
60 if (!logfile.exists() || logfile.length() == 0)
61 {
62 Toast.makeText(this, getString(R.string.empty_log), Toast.LENGTH_SHORT).show();
63 return true;
64 }
65
66 String version = "";
67 try
68 {
69 version = getPackageManager().getPackageInfo(getPackageName(), 0).versionName;
70 }
71 catch (NameNotFoundException e)
72 {
73 e.printStackTrace();
74 }
75
76 Intent intent = new Intent(Intent.ACTION_SEND);
77 intent.putExtra(Intent.EXTRA_EMAIL, new String[] { MainActivity.CONTACT_EMAIL });
78 intent.putExtra(Intent.EXTRA_SUBJECT, String.format(getString(R.string.log_mail_subject), version));
79 intent.setType("text/plain");
80 intent.putExtra(Intent.EXTRA_STREAM, LogContentProvider.createContentUri());
81 startActivity(Intent.createChooser(intent, getString(R.string.send_log)));
82 return true;
83 }
84 return super.onOptionsItemSelected(item);
85 }
86 }