Move the about dialog to a new activity

This commit is contained in:
Jakob Nixdorf 2017-07-13 12:15:54 +02:00
parent d693d331ae
commit b5dcd2b337
No known key found for this signature in database
GPG key ID: BE99BF86574A7DBC
16 changed files with 433 additions and 103 deletions

View file

@ -1,13 +1,16 @@
Copyright (C) 2017 Jakob Nixdorf <flocke@shadowice.org>
Copyright (C) 2015 Bruno Bierbaumer
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in the
Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE

View file

@ -44,6 +44,7 @@ goes to Bruno.
#### Open-source components used:
* [Apache Commons Codec](https://commons.apache.org/proper/commons-codec/)
* [LicensesDialog](https://github.com/PSDev/LicensesDialog)
* [MaterialProgressBar](https://github.com/DreaminginCodeZH/MaterialProgressBar)
* [ZXing Android Embedded](https://github.com/journeyapps/zxing-android-embedded)

View file

@ -30,6 +30,7 @@ android {
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile ('de.psdev.licensesdialog:licensesdialog:1.8.2') {exclude module: 'jsr305'}
compile 'com.android.support:appcompat-v7:25.3.1'
compile 'com.android.support:design:25.3.1'
compile 'com.android.support:recyclerview-v7:25.3.1'

View file

@ -23,6 +23,10 @@
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".AboutActivity"
android:parentActivityName=".MainActivity"
android:theme="@style/AppTheme.NoActionBar" />
<activity
android:name=".BackupActivity"
android:parentActivityName=".MainActivity"

View file

@ -0,0 +1,107 @@
package org.shadowice.flocke.andotp;
import android.content.Intent;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.net.Uri;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.View;
import android.view.ViewStub;
import android.widget.LinearLayout;
import android.widget.TextView;
import de.psdev.licensesdialog.LicensesDialog;
public class AboutActivity extends AppCompatActivity {
private static final String GITHUB_URI = "https://github.com/flocke/andOTP";
private static final String CHANGELOG_URI = GITHUB_URI + "/blob/master/CHANGELOG.md";
private static final String MIT_URI = GITHUB_URI + "/blob/master/LICENSE.txt";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setTitle(R.string.about_activity_title);
setContentView(R.layout.activity_container);
Toolbar toolbar = (Toolbar) findViewById(R.id.container_toolbar);
setSupportActionBar(toolbar);
ViewStub stub = (ViewStub) findViewById(R.id.container_stub);
stub.setLayoutResource(R.layout.content_about);
View v = stub.inflate();
String versionName = "";
try {
PackageInfo packageInfo = getPackageManager().getPackageInfo(getPackageName(), 0);
versionName = packageInfo.versionName;
} catch (PackageManager.NameNotFoundException e) {
e.printStackTrace();
}
TextView version = (TextView) v.findViewById(R.id.about_text_version);
version.setText(versionName);
LinearLayout license = (LinearLayout) v.findViewById(R.id.about_layout_license);
license.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
openURI(MIT_URI);
}
});
LinearLayout changelog = (LinearLayout) v.findViewById(R.id.about_layout_changelog);
changelog.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
openURI(CHANGELOG_URI);
}
});
LinearLayout source = (LinearLayout) v.findViewById(R.id.about_layout_source);
source.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
openURI(GITHUB_URI);
}
});
LinearLayout licenses = (LinearLayout) v.findViewById(R.id.about_layout_licenses);
licenses.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
showLicenses();
}
});
}
// Go back to the main activity
@Override
public boolean onSupportNavigateUp() {
finish();
return true;
}
@Override
public void onBackPressed() {
finish();
super.onBackPressed();
}
public void openURI(String uri) {
Intent openURI = new Intent(Intent.ACTION_VIEW);
openURI.setData(Uri.parse(uri));
startActivity(openURI);
}
public void showLicenses() {
new LicensesDialog.Builder(this)
.setNotices(R.raw.licenses)
.setIncludeOwnLicense(true)
.setTitle(R.string.about_label_licenses)
.build()
.show();
}
}

View file

@ -29,8 +29,6 @@ import android.app.KeyguardManager;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.os.Bundle;
import android.os.Handler;
import android.preference.PreferenceManager;
@ -53,7 +51,6 @@ import android.widget.ArrayAdapter;
import android.widget.EditText;
import android.widget.ProgressBar;
import android.widget.Spinner;
import android.widget.TextView;
import android.widget.Toast;
import com.google.zxing.integration.android.IntentIntegrator;
@ -123,34 +120,6 @@ public class MainActivity extends AppCompatActivity {
.show();
}
// About dialog
private void showAbout() {
ViewGroup container = (ViewGroup) findViewById(R.id.main_content);
View messageView = getLayoutInflater().inflate(R.layout.dialog_about, container, false);
String versionName = "";
try {
PackageInfo packageInfo = getPackageManager().getPackageInfo(getPackageName(), 0);
versionName = packageInfo.versionName;
} catch (PackageManager.NameNotFoundException e) {
e.printStackTrace();
}
TextView versionText = (TextView) messageView.findViewById(R.id.about_version);
versionText.setText(versionName);
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle(R.string.app_name)
.setIcon(R.mipmap.ic_launcher)
.setView(messageView)
.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {}
})
.create()
.show();
}
// Initialize the main application
@Override
protected void onCreate(Bundle savedInstanceState) {
@ -338,13 +307,14 @@ public class MainActivity extends AppCompatActivity {
int id = item.getItemId();
if (id == R.id.action_backup) {
Intent intent = new Intent(this, BackupActivity.class);
startActivityForResult(intent, INTENT_INTERNAL_BACKUP);
Intent backupIntent = new Intent(this, BackupActivity.class);
startActivityForResult(backupIntent, INTENT_INTERNAL_BACKUP);
} else if (id == R.id.action_settings) {
Intent intent = new Intent(this, SettingsActivity.class);
startActivityForResult(intent, INTENT_INTERNAL_SETTINGS);
Intent settingsIntent = new Intent(this, SettingsActivity.class);
startActivityForResult(settingsIntent, INTENT_INTERNAL_SETTINGS);
} else if (id == R.id.action_about){
showAbout();
Intent aboutIntent = new Intent(this, AboutActivity.class);
startActivity(aboutIntent);
return true;
}
return super.onOptionsItemSelected(item);

View file

@ -0,0 +1,9 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24.0"
android:viewportHeight="24.0">
<path
android:fillColor="#FF727272"
android:pathData="M9.4,16.6L4.8,12l4.6,-4.6L8,6l-6,6 6,6 1.4,-1.4zM14.6,16.6l4.6,-4.6 -4.6,-4.6L16,6l6,6 -6,6 -1.4,-1.4z"/>
</vector>

View file

@ -0,0 +1,9 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24.0"
android:viewportHeight="24.0">
<path
android:fillColor="#FF727272"
android:pathData="M10.08,10.86c0.05,-0.33 0.16,-0.62 0.3,-0.87s0.34,-0.46 0.59,-0.62c0.24,-0.15 0.54,-0.22 0.91,-0.23 0.23,0.01 0.44,0.05 0.63,0.13 0.2,0.09 0.38,0.21 0.52,0.36s0.25,0.33 0.34,0.53 0.13,0.42 0.14,0.64h1.79c-0.02,-0.47 -0.11,-0.9 -0.28,-1.29s-0.4,-0.73 -0.7,-1.01 -0.66,-0.5 -1.08,-0.66 -0.88,-0.23 -1.39,-0.23c-0.65,0 -1.22,0.11 -1.7,0.34s-0.88,0.53 -1.2,0.92 -0.56,0.84 -0.71,1.36S8,11.29 8,11.87v0.27c0,0.58 0.08,1.12 0.23,1.64s0.39,0.97 0.71,1.35 0.72,0.69 1.2,0.91 1.05,0.34 1.7,0.34c0.47,0 0.91,-0.08 1.32,-0.23s0.77,-0.36 1.08,-0.63 0.56,-0.58 0.74,-0.94 0.29,-0.74 0.3,-1.15h-1.79c-0.01,0.21 -0.06,0.4 -0.15,0.58s-0.21,0.33 -0.36,0.46 -0.32,0.23 -0.52,0.3c-0.19,0.07 -0.39,0.09 -0.6,0.1 -0.36,-0.01 -0.66,-0.08 -0.89,-0.23 -0.25,-0.16 -0.45,-0.37 -0.59,-0.62s-0.25,-0.55 -0.3,-0.88 -0.08,-0.67 -0.08,-1v-0.27c0,-0.35 0.03,-0.68 0.08,-1.01zM12,2C6.48,2 2,6.48 2,12s4.48,10 10,10 10,-4.48 10,-10S17.52,2 12,2zM12,20c-4.41,0 -8,-3.59 -8,-8s3.59,-8 8,-8 8,3.59 8,8 -3.59,8 -8,8z"/>
</vector>

View file

@ -0,0 +1,9 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24.0"
android:viewportHeight="24.0">
<path
android:fillColor="#FF727272"
android:pathData="M13,3c-4.97,0 -9,4.03 -9,9L1,12l3.89,3.89 0.07,0.14L9,12L6,12c0,-3.87 3.13,-7 7,-7s7,3.13 7,7 -3.13,7 -7,7c-1.93,0 -3.68,-0.79 -4.94,-2.06l-1.42,1.42C8.27,19.99 10.51,21 13,21c4.97,0 9,-4.03 9,-9s-4.03,-9 -9,-9zM12,8v5l4.28,2.54 0.72,-1.21 -3.5,-2.08L13.5,8L12,8z"/>
</vector>

View file

@ -0,0 +1,9 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24.0"
android:viewportHeight="24.0">
<path
android:fillColor="#FF727272"
android:pathData="M11,17h2v-6h-2v6zM12,2C6.48,2 2,6.48 2,12s4.48,10 10,10 10,-4.48 10,-10S17.52,2 12,2zM12,20c-4.41,0 -8,-3.59 -8,-8s3.59,-8 8,-8 8,3.59 8,8 -3.59,8 -8,8zM11,9h2L13,7h-2v2z"/>
</vector>

View file

@ -0,0 +1,238 @@
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.NestedScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/scroll_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:overScrollMode="never"
app:layout_behavior="@string/appbar_scrolling_view_behavior" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="@dimen/activity_margin"
app:cardElevation="@dimen/card_elevation" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:paddingTop="@dimen/activity_margin"
android:paddingBottom="@dimen/activity_margin" >
<!-- version -->
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="?android:attr/listPreferredItemHeight"
android:padding="@dimen/activity_margin_small"
android:background="?android:attr/selectableItemBackground"
android:gravity="center_vertical" >
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="@dimen/activity_margin"
android:layout_marginEnd="@dimen/activity_margin_large"
android:src="@mipmap/ic_launcher"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textStyle="bold"
android:text="@string/app_name"/>
</LinearLayout>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="@dimen/activity_margin_large"
android:layout_marginEnd="@dimen/activity_margin_large"
android:textAlignment="center"
android:textStyle="bold"
android:text="@string/about_description" />
</LinearLayout>
</android.support.v7.widget.CardView>
<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="@dimen/activity_margin"
app:cardElevation="@dimen/card_elevation" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:paddingTop="@dimen/activity_margin"
android:paddingBottom="@dimen/activity_margin" >
<!-- version -->
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="?android:attr/listPreferredItemHeight"
android:padding="@dimen/activity_margin_small"
android:background="?android:attr/selectableItemBackground"
android:gravity="center_vertical" >
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="@dimen/activity_margin"
android:layout_marginEnd="@dimen/activity_margin_large"
android:src="@drawable/ic_info_outline_gray" />
<LinearLayout
android:orientation="vertical"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:gravity="center_vertical" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/about_label_version"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textStyle="bold" />
<TextView
android:id="@+id/about_text_version"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall" />
</LinearLayout>
</LinearLayout>
<!-- license -->
<LinearLayout
android:id="@+id/about_layout_license"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="?android:attr/listPreferredItemHeight"
android:padding="@dimen/activity_margin_small"
android:background="?android:attr/selectableItemBackground"
android:gravity="center_vertical" >
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="@dimen/activity_margin"
android:layout_marginEnd="@dimen/activity_margin_large"
android:src="@drawable/ic_copyright_gray" />
<LinearLayout
android:orientation="vertical"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:gravity="center_vertical" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textStyle="bold"
android:text="@string/about_label_license" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:text="@string/about_label_MIT" />
</LinearLayout>
</LinearLayout>
<!-- changelog -->
<LinearLayout
android:id="@+id/about_layout_changelog"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="?android:attr/listPreferredItemHeight"
android:padding="@dimen/activity_margin_small"
android:background="?android:attr/selectableItemBackground"
android:gravity="center_vertical" >
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="@dimen/activity_margin"
android:layout_marginEnd="@dimen/activity_margin_large"
android:src="@drawable/ic_history_gray" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/about_label_changelog"
android:textStyle="bold"
android:textAppearance="?android:attr/textAppearanceMedium" />
</LinearLayout>
<!-- source -->
<LinearLayout
android:id="@+id/about_layout_source"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="?android:attr/listPreferredItemHeight"
android:padding="@dimen/activity_margin_small"
android:background="?android:attr/selectableItemBackground"
android:gravity="center_vertical" >
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="@dimen/activity_margin"
android:layout_marginEnd="@dimen/activity_margin_large"
android:src="@drawable/ic_code_gray" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/about_label_source"
android:textStyle="bold"
android:textAppearance="?android:attr/textAppearanceMedium" />
</LinearLayout>
<!-- licenses -->
<LinearLayout
android:id="@+id/about_layout_licenses"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="?android:attr/listPreferredItemHeight"
android:padding="@dimen/activity_margin_small"
android:background="?android:attr/selectableItemBackground"
android:gravity="center_vertical" >
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="@dimen/activity_margin"
android:layout_marginEnd="@dimen/activity_margin_large"
android:src="@drawable/ic_copyright_gray" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/about_label_licenses"
android:textStyle="bold"
android:textAppearance="?android:attr/textAppearanceMedium" />
</LinearLayout>
</LinearLayout>
</android.support.v7.widget.CardView>
</LinearLayout>
</android.support.v4.widget.NestedScrollView>

View file

@ -1,56 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/about_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:padding="@dimen/activity_margin" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginBottom="@dimen/activity_vertical_margin"
android:textAlignment="center"
android:textStyle="bold"
android:text="@string/about_description" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginBottom="@dimen/activity_vertical_margin"
android:orientation="horizontal" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="16sp"
android:text="@string/about_version_hint" />
<TextView
android:id="@+id/about_version"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingStart="@dimen/activity_horizontal_margin"
android:textStyle="bold" />
</LinearLayout>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:autoLink="web"
android:layout_marginBottom="@dimen/activity_vertical_margin"
android:text="@string/about_homepage_link" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:textSize="16sp"
android:textAlignment="center"
android:text="@string/about_credits" />
</LinearLayout>

View file

@ -0,0 +1,21 @@
<?xml version="1.0" encoding="utf-8"?>
<notices>
<notice>
<name>Apache Commons Codec</name>
<url>https://commons.apache.org/proper/commons-codec</url>
<copyright>Copyright 2002-2014 The Apache Software Foundation</copyright>
<license>Apache Software License 2.0</license>
</notice>
<notice>
<name>MaterialProgressBar</name>
<url>https://github.com/DreaminginCodeZH/MaterialProgressBar</url>
<copyright>Copyright 2015 Zhang Hai</copyright>
<license>Apache Software License 2.0</license>
</notice>
<notice>
<name>ZXing Android Embedded</name>
<url>https://github.com/journeyapps/zxing-android-embedded</url>
<copyright>Copyright (C) 2012-2017 ZXing authors, Journey Mobile</copyright>
<license>Apache Software License 2.0</license>
</notice>
</notices>

View file

@ -7,6 +7,7 @@
<dimen name="activity_vertical_margin">16dp</dimen>
<dimen name="card_corner_radius">0dp</dimen>
<dimen name="card_elevation">4dp</dimen>
<!-- FAB Menu -->
<dimen name="fab_small_elevation">2dp</dimen>

View file

@ -0,0 +1,15 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="about_activity_title">About</string>
<string name="about_description">
An open-source two-factor authentication App for Android 4.4+.
</string>
<string name="about_label_changelog">Changelog</string>
<string name="about_label_license">License</string>
<string name="about_label_licenses">Open source licenses</string>
<string name="about_label_MIT">MIT License</string>
<string name="about_label_source">Source code</string>
<string name="about_label_version">Version</string>
</resources>

View file

@ -46,15 +46,4 @@
<string name="dialog_msg_auth">Enter your device credentials to start andOTP.</string>
<string name="dialog_msg_confirm_delete">Are you sure you want do remove this account?</string>
<!-- About dialog -->
<string name="about_description">
An open-source two-factor authentication App for Android 4.4+.
</string>
<string name="about_version_hint">Version</string>
<string name="about_homepage_link" translatable="false">https://github.com/flocke/andOTP</string>
<string name="about_credits" translatable="false">
Copyright © 2017 Jakob Nixdorf\n
Copyright © 2015 Bruno Bierbaumer
</string>
</resources>