Add about view and share app

This commit is contained in:
emanuele-f 2021-03-04 23:14:30 +01:00
parent fc31bf6e7c
commit e8a56aa669
8 changed files with 185 additions and 19 deletions

View File

@ -52,6 +52,11 @@
android:label="@string/title_activity_settings"
android:launchMode="singleTop"
android:parentActivityName=".activities.MainActivity" />
<activity
android:name=".activities.AboutActivity"
android:label="@string/about"
android:launchMode="singleTop"
android:parentActivityName=".activities.MainActivity" />
<service
android:name=".CaptureService"

View File

@ -24,6 +24,8 @@ import android.app.Dialog;
import android.app.Service;
import android.app.UiModeManager;
import android.content.Context;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.content.res.Configuration;
import android.content.res.Resources;
import android.graphics.Bitmap;
@ -364,4 +366,21 @@ public class Utils {
return false;
}
public static String getAppVersion(Context context) {
String appver;
try {
PackageInfo pInfo = context.getPackageManager().getPackageInfo(context.getPackageName(), 0);
String version = pInfo.versionName;
boolean isRelease = version.contains(".");
appver = isRelease ? ("v" + version) : version;
} catch (PackageManager.NameNotFoundException e) {
Log.e("Utils", "Could not retrieve package version");
appver = "";
}
return appver;
}
}

View File

@ -0,0 +1,48 @@
/*
* This file is part of PCAPdroid.
*
* PCAPdroid 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 3 of the License, or
* (at your option) any later version.
*
* PCAPdroid 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.
*
* You should have received a copy of the GNU General Public License
* along with PCAPdroid. If not, see <http://www.gnu.org/licenses/>.
*
* Copyright 2020-21 - Emanuele Faranda
*/
package com.emanuelef.remote_capture.activities;
import android.os.Bundle;
import android.text.Html;
import android.text.method.LinkMovementMethod;
import android.widget.TextView;
import androidx.appcompat.app.AppCompatActivity;
import com.emanuelef.remote_capture.R;
import com.emanuelef.remote_capture.Utils;
public class AboutActivity extends AppCompatActivity {
private static final String TAG = "AboutActivity";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.about_activity);
TextView appVersion = findViewById(R.id.app_version);
appVersion.setText(getString(R.string.app_name) + " " + Utils.getAppVersion(this));
TextView gplLicense = findViewById(R.id.app_license_link);
String localized = gplLicense.getText().toString();
gplLicense.setText(Html.fromHtml("<a href='https://www.gnu.org/licenses/gpl-3.0-standalone.html'>" + localized + "</a>"));
gplLicense.setMovementMethod(LinkMovementMethod.getInstance());
}
}

View File

@ -24,8 +24,6 @@ import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.SharedPreferences;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.database.Cursor;
import android.net.Uri;
import android.net.VpnService;
@ -188,21 +186,13 @@ public class MainActivity extends AppCompatActivity implements NavigationView.On
navView.setNavigationItemSelectedListener(this);
View header = navView.getHeaderView(0);
try {
PackageInfo pInfo = getPackageManager().getPackageInfo(getPackageName(), 0);
String version = pInfo.versionName;
boolean isRelease = version.contains(".");
final String verStr = isRelease ? ("v" + version) : version;
TextView appVer = header.findViewById(R.id.app_version);
appVer.setText(verStr);
appVer.setOnClickListener((ev) -> {
Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(GITHUB_PROJECT_URL + "/tree/" + verStr));
startActivity(browserIntent);
});
} catch (PackageManager.NameNotFoundException e) {
Log.e(TAG, "Could not retrieve package version");
}
TextView appVer = header.findViewById(R.id.app_version);
String verStr = Utils.getAppVersion(this);
appVer.setText(verStr);
appVer.setOnClickListener((ev) -> {
Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(GITHUB_PROJECT_URL + "/tree/" + verStr));
startActivity(browserIntent);
});
}
@Override
@ -327,6 +317,19 @@ public class MainActivity extends AppCompatActivity implements NavigationView.On
startActivity(intent);
} else
Utils.showToast(this, R.string.capture_not_started);
} else if (id == R.id.action_about) {
Intent intent = new Intent(MainActivity.this, AboutActivity.class);
startActivity(intent);
} else if (id == R.id.action_share_app) {
String description = getString(R.string.about_text);
String getApp = getString(R.string.get_app);
String url = "http://play.google.com/store/apps/details?id=" + this.getPackageName();
Intent intent = new Intent(android.content.Intent.ACTION_SEND);
intent.setType("text/plain");
intent.putExtra(android.content.Intent.EXTRA_TEXT, description + "\n" + getApp + "\n" + url);
startActivity(Intent.createChooser(intent, getResources().getString(R.string.share)));
}
return false;

View File

@ -0,0 +1,5 @@
<vector android:height="24dp" android:tint="#FFFFFF"
android:viewportHeight="24" android:viewportWidth="24"
android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
<path android:fillColor="@android:color/white" android:pathData="M11.88,9.14c1.28,0.06 1.61,1.15 1.63,1.66h1.79c-0.08,-1.98 -1.49,-3.19 -3.45,-3.19C9.64,7.61 8,9 8,12.14c0,1.94 0.93,4.24 3.84,4.24c2.22,0 3.41,-1.65 3.44,-2.95h-1.79c-0.03,0.59 -0.45,1.38 -1.63,1.44C10.55,14.83 10,13.81 10,12.14C10,9.25 11.28,9.16 11.88,9.14zM12,2C6.48,2 2,6.48 2,12s4.48,10 10,10s10,-4.48 10,-10S17.52,2 12,2zM12,20c-4.41,0 -8,-3.59 -8,-8s3.59,-8 8,-8s8,3.59 8,8S16.41,20 12,20z"/>
</vector>

View File

@ -0,0 +1,72 @@
<?xml version="1.0" encoding="utf-8"?>
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="15dp">
<ImageView
android:id="@+id/logo"
android:layout_width="90dp"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="30dp"
android:src="@mipmap/ic_launcher"
android:adjustViewBounds="true" />
<TextView
android:id="@+id/app_version"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/logo"
android:layout_centerHorizontal="true"
android:layout_marginTop="20dp"
android:textSize="20sp"
android:textStyle="bold"
tools:text="PCAPdroid vx.y.z"/>
<TextView
android:id="@+id/app_description"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/app_version"
android:layout_alignParentStart="true"
android:layout_marginTop="50dp"
android:text="@string/about_text"/>
<TextView
android:id="@+id/app_copyright"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/app_description"
android:layout_alignParentStart="true"
android:layout_marginTop="20dp"
android:autoLink="email"
android:text="@string/about_copyright"/>
<TextView
android:id="@+id/app_no_warranty"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/app_copyright"
android:layout_alignParentStart="true"
android:layout_marginTop="20dp"
android:text="@string/app_no_warranty"/>
<TextView
android:id="@+id/app_license_link"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/app_no_warranty"
android:layout_alignParentStart="true"
android:layout_marginTop="20dp"
android:text="@string/gpl_license_link"/>
</RelativeLayout>
</ScrollView>

View File

@ -19,6 +19,10 @@
android:id="@+id/action_rate_app"
android:title="@string/rate_app"
android:icon="@drawable/ic_star" />
<item
android:id="@+id/action_share_app"
android:title="@string/share"
android:icon="@drawable/ic_share" />
<item
android:id="@+id/action_open_telegram"
android:title="@string/open_telegram_group"
@ -27,5 +31,10 @@
android:id="@+id/action_open_github"
android:title="@string/open_github"
android:icon="@drawable/ic_github" />
<item
android:id="@+id/action_about"
android:title="@string/about"
android:icon="@drawable/ic_copyright" />
</group>
</menu>

View File

@ -1,5 +1,6 @@
<resources>
<string name="app_name" translatable="false">PCAPdroid</string>
<string name="about_copyright" translatable="false">Copyright (C) 2020-21 - Emanuele Faranda black.silver@hotmail.it</string>
<string name="start_button">Start</string>
<string name="stop_button">Stop</string>
<string name="title_activity_settings">Settings</string>
@ -59,9 +60,9 @@
<string name="pcap_dump">PCAP Dump</string>
<string name="tls_decryption">TLS Decryption</string>
<string name="user_guide">User Guide</string>
<string name="rate_app">Rate App</string>
<string name="rate_app">Rate</string>
<string name="open_telegram_group">Telegram Group</string>
<string name="open_github">Github Project</string>
<string name="open_github">Source Code</string>
<string name="yes">YES</string>
<string name="no">NO</string>
<string name="existing_vpn_confirm">The currently active VPN app will be disconnected. Do you want to proceed?</string>
@ -112,5 +113,9 @@
<string name="save_to_file">Save to file</string>
<string name="file_saved">File successfully saved</string>
<string name="older_connections_notice">%1$d older connections not shown</string>
<string name="about_text">PCAPdroid is an open source network capture and monitoring tool which works without root privileges.</string>
<string name="app_no_warranty">PCAPdroid 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.</string>
<string name="gpl_license_link">GPLv3 License</string>
<string name="get_app">Get it:</string>
</resources>