Improve about dialog

This commit is contained in:
Jakob Nixdorf 2017-06-28 13:55:56 +02:00
parent 65f918c05f
commit f4affbb6fa
No known key found for this signature in database
GPG key ID: BE99BF86574A7DBC
7 changed files with 90 additions and 74 deletions

View file

@ -8,8 +8,8 @@ android {
applicationId "org.shadowice.flocke.andotp"
minSdkVersion 18
targetSdkVersion 25
versionCode 3
versionName "0.1.2"
versionCode 1
versionName "0.1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}

View file

@ -100,10 +100,10 @@ public class MainActivityTest extends ActivityInstrumentationTestCase2<MainActiv
onView(allOf(withText("About"), isDisplayed())).perform(click());
Thread.sleep(1000);
onView(withId(R.id.webViewAbout)).check(matches(isDisplayed()));
onView(withId(R.id.webViewAbout)).perform(pressBack());
onView(withId(R.id.about_layout)).check(matches(isDisplayed()));
onView(withId(R.id.about_layout)).perform(pressBack());
onView(withId(R.id.webViewAbout)).check(doesNotExist());
onView(withId(R.id.about_layout)).check(doesNotExist());
}

View file

@ -28,6 +28,7 @@ import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.os.Bundle;
import android.os.Handler;
@ -39,18 +40,17 @@ import android.support.v4.content.ContextCompat;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.ActionMode;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.WindowManager;
import android.view.animation.LinearInterpolator;
import android.webkit.WebView;
import android.widget.AdapterView;
import android.widget.EditText;
import android.widget.ListView;
import android.widget.ProgressBar;
import android.widget.TextView;
import com.google.zxing.client.android.Intents;
import com.google.zxing.integration.android.IntentIntegrator;
@ -84,6 +84,29 @@ public class MainActivity extends AppCompatActivity implements ActionMode.Callb
}
}
private void showAbout() {
// Inflate the dialog_about message contents
View messageView = getLayoutInflater().inflate(R.layout.dialog_about, null, 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);
builder.setIcon(R.mipmap.ic_launcher);
builder.setView(messageView);
builder.create();
builder.show();
}
@Override
public void onRequestPermissionsResult(int requestCode, @NonNull String permissions[], @NonNull int[] grantResults) {
if(requestCode == PERMISSIONS_REQUEST_CAMERA) {
@ -245,9 +268,7 @@ public class MainActivity extends AppCompatActivity implements ActionMode.Callb
int id = item.getItemId();
if(id == R.id.action_about){
WebView view = (WebView) LayoutInflater.from(this).inflate(R.layout.dialog_about, null);
view.loadUrl("file:///android_res/raw/about.html");
new AlertDialog.Builder(this).setView(view).show();
showAbout();
return true;
}

View file

@ -1,7 +1,55 @@
<?xml version="1.0" encoding="utf-8"?>
<WebView
xmlns:android="http://schemas.android.com/apk/res/android"
<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:id="@+id/webViewAbout"
/>
android:orientation="vertical"
android:padding="@dimen/activity_vertical_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:paddingLeft="@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:text="@string/about_credits" />
</LinearLayout>

View file

@ -1,27 +0,0 @@
<html>
<head>
<meta charset="utf-8"/>
<style>
* {
margin:5px;
color: #212121;
}
p { font-size:120%;}
body { font-family: sans-serif; }
pre { background-color: #eeeeee; padding: 1em; white-space: pre-wrap; }
a, a:visited, a:hover, a:active {
color: #727272;
}
</style>
</head>
<body>
<center>
<img width="72" src="file:///android_res/mipmap/ic_launcher.png">
<h2>OTP Authenticator 0.1.1</h2>
<p>© 2015 - Bruno Bierbaumer</p>
<p><a href="https://github.com/0xbb/otp-authenticator">Project Homepage</a></p>
<p><a href="file:///android_res/raw/opensource.html">Acknowledgments</a></p>
</center>
</body>
</html>

View file

@ -1,32 +0,0 @@
<html>
<head>
<meta charset="utf-8"/>
<style>
* {
margin:5px;
color: #212121;
}
body { font-family: sans-serif; }
pre { background-color: #eeeeee; padding: 1em; white-space: pre-wrap; }
a, a:visited, a:hover, a:active {
color: #727272;
}
ul {
padding-left:20px;
margin:0;
font-size:80%;
}
</style>
</head>
<body>
<div>
<h3>Acknowledgments:</h3>
<ul>
<li><a href="https://commons.apache.org/proper/commons-codec/">Apache Commons Code</a>
<li><a href="https://android.googlesource.com/platform/development/+/master/samples/Vault/src/com/example/android/vault">Code Parts from Google's Android Samples</a>
<li><a href="https://github.com/zxing/zxing">ZXing</a>
<li><a href="https://github.com/journeyapps/zxing-android-embedded">ZXing Android Embedded</a>
</ul>
</div>
</body>
</html>

View file

@ -17,4 +17,10 @@
<string name="alert_rename">Rename</string>
<string name="alert_remove">"Remove "</string>
<string name="msg_camera_permission">Camera permission not granted</string>
<!-- About dialog -->
<string name="about_description">An open-source two-factor authentication App for Android 4.3+</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</string>
</resources>