aboutsummaryrefslogtreecommitdiff
path: root/aboutit
diff options
context:
space:
mode:
authorVictor Häggqvist <[email protected]>2015-01-01 16:28:17 +0100
committerVictor Häggqvist <[email protected]>2015-01-01 16:28:17 +0100
commit5d2f7b4c8f76a1fb7cb8d3d0ad9ca7e6fcc6274a (patch)
tree5c5ed9ccd86d39201c64526c4557ab6c48d69a56 /aboutit
init
Diffstat (limited to 'aboutit')
-rw-r--r--aboutit/.gitignore1
-rw-r--r--aboutit/build.gradle24
-rw-r--r--aboutit/proguard-rules.pro17
-rw-r--r--aboutit/src/androidTest/java/com/snilius/aboutit/ApplicationTest.java13
-rw-r--r--aboutit/src/main/AndroidManifest.xml8
-rw-r--r--aboutit/src/main/java/com/snilius/aboutit/AboutIt.java232
-rw-r--r--aboutit/src/main/java/com/snilius/aboutit/L.java24
-rw-r--r--aboutit/src/main/res/drawable-hdpi/ic_launcher.pngbin0 -> 9397 bytes
-rw-r--r--aboutit/src/main/res/drawable-mdpi/ic_launcher.pngbin0 -> 5237 bytes
-rw-r--r--aboutit/src/main/res/drawable-xhdpi/ic_launcher.pngbin0 -> 14383 bytes
-rw-r--r--aboutit/src/main/res/drawable-xxhdpi/ic_launcher.pngbin0 -> 19388 bytes
-rw-r--r--aboutit/src/main/res/values/strings.xml3
12 files changed, 322 insertions, 0 deletions
diff --git a/aboutit/.gitignore b/aboutit/.gitignore
new file mode 100644
index 0000000..796b96d
--- /dev/null
+++ b/aboutit/.gitignore
@@ -0,0 +1 @@
+/build
diff --git a/aboutit/build.gradle b/aboutit/build.gradle
new file mode 100644
index 0000000..db556e0
--- /dev/null
+++ b/aboutit/build.gradle
@@ -0,0 +1,24 @@
+apply plugin: 'com.android.library'
+
+android {
+ compileSdkVersion 21
+ buildToolsVersion "21.1.2"
+
+ defaultConfig {
+ minSdkVersion 14
+ targetSdkVersion 21
+ versionCode 1
+ versionName "1.0"
+ }
+ buildTypes {
+ release {
+ minifyEnabled false
+ proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
+ }
+ }
+}
+
+dependencies {
+ compile fileTree(dir: 'libs', include: ['*.jar'])
+ compile 'com.android.support:appcompat-v7:21.0.3'
+}
diff --git a/aboutit/proguard-rules.pro b/aboutit/proguard-rules.pro
new file mode 100644
index 0000000..7873ee5
--- /dev/null
+++ b/aboutit/proguard-rules.pro
@@ -0,0 +1,17 @@
+# Add project specific ProGuard rules here.
+# By default, the flags in this file are appended to flags specified
+# in /opt/android-sdk-linux/tools/proguard/proguard-android.txt
+# You can edit the include path and order by changing the proguardFiles
+# directive in build.gradle.
+#
+# For more details, see
+# http://developer.android.com/guide/developing/tools/proguard.html
+
+# Add any project specific keep options here:
+
+# If your project uses WebView with JS, uncomment the following
+# and specify the fully qualified class name to the JavaScript interface
+# class:
+#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
+# public *;
+#}
diff --git a/aboutit/src/androidTest/java/com/snilius/aboutit/ApplicationTest.java b/aboutit/src/androidTest/java/com/snilius/aboutit/ApplicationTest.java
new file mode 100644
index 0000000..c6f81f4
--- /dev/null
+++ b/aboutit/src/androidTest/java/com/snilius/aboutit/ApplicationTest.java
@@ -0,0 +1,13 @@
+package com.snilius.aboutit;
+
+import android.app.Application;
+import android.test.ApplicationTestCase;
+
+/**
+ * <a href="http://d.android.com/tools/testing/testing_android.html">Testing Fundamentals</a>
+ */
+public class ApplicationTest extends ApplicationTestCase<Application> {
+ public ApplicationTest() {
+ super(Application.class);
+ }
+} \ No newline at end of file
diff --git a/aboutit/src/main/AndroidManifest.xml b/aboutit/src/main/AndroidManifest.xml
new file mode 100644
index 0000000..aa76a22
--- /dev/null
+++ b/aboutit/src/main/AndroidManifest.xml
@@ -0,0 +1,8 @@
+<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.snilius.aboutit">
+
+ <application android:allowBackup="true" android:label="@string/app_name"
+ android:icon="@drawable/ic_launcher">
+
+ </application>
+
+</manifest>
diff --git a/aboutit/src/main/java/com/snilius/aboutit/AboutIt.java b/aboutit/src/main/java/com/snilius/aboutit/AboutIt.java
new file mode 100644
index 0000000..7d52191
--- /dev/null
+++ b/aboutit/src/main/java/com/snilius/aboutit/AboutIt.java
@@ -0,0 +1,232 @@
+package com.snilius.aboutit;
+
+import android.app.Activity;
+import android.text.util.Linkify;
+import android.widget.TextView;
+
+import java.util.ArrayList;
+import java.util.Calendar;
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.List;
+
+/**
+ * <h1>AboutIt</h1>
+ * A About-page creator
+ *
+ * <pre>
+ * {@code
+ * new AboutIt(this).app(R.string.app_name)
+ * .buildInfo(BuildConfig.DEBUG, BuildConfig.VERSION_CODE, BuildConfig.VERSION_NAME)
+ * .copyright("Example Business")
+ * .libLicense("AboutIt", "Victor Häggqvist", L.AP2, "https://github.com/victorhaggqvist/aboutit")
+ * .toTextView(R.id.about_text);
+ * }
+ * </pre>
+ *
+ * @author Victor Häggqvist
+ * @since 12/29/14
+ * @version 1.0
+ */
+public class AboutIt {
+
+ private String copyright = null;
+ private int year = 0;
+ private int endYear = 0;
+ private List<Lib> libs = new ArrayList<>();
+ private Activity activity;
+ private String appName = null;
+ private boolean debug;
+ private int versionCode;
+ private String versionName;
+ private String releaseName = null;
+ private String description = null;
+
+ /**
+ * Create a page generator
+ * @param activity The aboutpage activity
+ */
+ public AboutIt(Activity activity) {
+
+ this.activity = activity;
+ }
+
+ /**
+ * Generate text and put in @ref{about_text}
+ * @param about_text Resource it of destination TextView
+ */
+ @SuppressWarnings("StringConcatenationInsideStringBufferAppend")
+ public void toTextView(int about_text) {
+ TextView out = (TextView) activity.findViewById(about_text);
+ out.setAutoLinkMask(Linkify.WEB_URLS);
+
+ releaseName = "-"+(releaseName != null?releaseName:(debug?"debug":""));
+ endYear = endYear();
+
+ StringBuilder sb = new StringBuilder();
+ if (appName != null)
+ sb.append(appName+" v"+versionName+" ("+versionCode+releaseName+")\n");
+
+ if (copyright != null) {
+ sb.append("Copyright (c) ");
+ if (year != 0)
+ sb.append(year + (endYear != 0 ? " - " + endYear : "") + " ");
+ sb.append(copyright + "\n\n");
+ }
+
+ if (description != null)
+ sb.append(description+"\n\n");
+
+ // Sort library list alphabeticly by name
+ Collections.sort(libs, new Comparator<Lib>() {
+ @Override
+ public int compare(Lib lhs, Lib rhs) {
+ return lhs.name.compareTo(rhs.name);
+ }
+ });
+
+ for(Lib l:libs){
+ sb.append(l.name + " by " + l.author + " under " + l.license.display() + ", " + l.url + "\n");
+ }
+
+ out.setText(sb.toString());
+ }
+
+ /**
+ * Demiter what endyear to show
+ * @return year to show
+ */
+ private int endYear() {
+ if (endYear != 0) {
+ return endYear;
+ } else {
+ Calendar now = Calendar.getInstance();
+ int yearNow = now.get(Calendar.YEAR);
+ if (year == yearNow)
+ return 0;
+ else
+ return yearNow;
+ }
+ }
+
+ /**
+ * Get String by id
+ * @param stringid String id
+ * @return String
+ */
+ private String s(int stringid) {
+ return activity.getString(stringid);
+ }
+
+ /**
+ * Copyright name
+ * @param copyright Name
+ */
+ public AboutIt copyright(String copyright){
+ this.copyright = copyright;
+ return this;
+ }
+
+ /**
+ * Start copyright year.
+ * If there is no start year no year will be displayed at all.
+ * @param year Year
+ */
+ public AboutIt year(int year) {
+ this.year = year;
+ return this;
+ }
+
+ /**
+ * Add a library to the list
+ * @param name Name of Library
+ * @param author Author of library
+ * @param license Library licanse, defined by L
+ * @param url Url to or otherwise referense to library
+ * @see L
+ */
+ public AboutIt libLicense(String name, String author, L license, String url) {
+ libs.add(new Lib(name, author, license, url));
+ return this;
+ }
+
+ /**
+ * Appname to display
+ * @param stringresource A string resource id
+ */
+ public AboutIt app(int stringresource) {
+ this.appName = s(stringresource);
+ return this;
+ }
+
+ /**
+ * Appname to display
+ * @see #app(int)
+ */
+ public AboutIt app(String appName) {
+ this.appName = appName;
+ return this;
+ }
+
+ /**
+ * Set a custom release name. Override the default name eg. beta
+ * @param releaseName The release name
+ */
+ public AboutIt release(String releaseName){
+ this.releaseName = releaseName;
+ return this;
+ }
+
+ /**
+ * App build info. To be used in conjunktion with the BuildConfig class
+ * {@code .buildInfo(BuildConfig.DEBUG, BuildConfig.VERSION_CODE, BuildConfig.VERSION_NAME)}
+ *
+ * @param debug If is debug build
+ * @param versionCode Version code
+ * @param versionName Version name
+ */
+ public AboutIt buildInfo(boolean debug, int versionCode, String versionName) {
+ this.debug = debug;
+ this.versionCode = versionCode;
+ this.versionName = versionName;
+ return this;
+ }
+
+ /**
+ * A longer description
+ * @param stringresource A string resource id
+ */
+ public AboutIt description(int stringresource) {
+ description = s(stringresource);
+ return this;
+ }
+
+ /**
+ * A longer description
+ * @param description The description
+ * @see #description(int)
+ */
+ public AboutIt description(String description) {
+ this.description = description;
+ return this;
+ }
+
+ /**
+ * Holder for libraries
+ */
+ private class Lib {
+
+ final String name;
+ final String author;
+ final L license;
+ final String url;
+
+ public Lib(String name, String author, L license, String url) {
+
+ this.name = name;
+ this.author = author;
+ this.license = license;
+ this.url = url;
+ }
+ }
+}
diff --git a/aboutit/src/main/java/com/snilius/aboutit/L.java b/aboutit/src/main/java/com/snilius/aboutit/L.java
new file mode 100644
index 0000000..a66726b
--- /dev/null
+++ b/aboutit/src/main/java/com/snilius/aboutit/L.java
@@ -0,0 +1,24 @@
+package com.snilius.aboutit;
+
+/**
+ * License Definitions
+ * @author Victor Häggqvist
+ * @since 12/29/14
+ */
+public enum L {
+ AP2("Apache License, Version 2.0"), MIT("MIT"), GPL2("GPLv2"), GPL3("GPLv3");
+
+ private String mDisplayname;
+
+ L(String displayname) {
+ mDisplayname = displayname;
+ }
+
+ /**
+ * Get diaplayname for license
+ * @return displaname
+ */
+ public String display() {
+ return mDisplayname;
+ }
+}
diff --git a/aboutit/src/main/res/drawable-hdpi/ic_launcher.png b/aboutit/src/main/res/drawable-hdpi/ic_launcher.png
new file mode 100644
index 0000000..96a442e
--- /dev/null
+++ b/aboutit/src/main/res/drawable-hdpi/ic_launcher.png
Binary files differ
diff --git a/aboutit/src/main/res/drawable-mdpi/ic_launcher.png b/aboutit/src/main/res/drawable-mdpi/ic_launcher.png
new file mode 100644
index 0000000..359047d
--- /dev/null
+++ b/aboutit/src/main/res/drawable-mdpi/ic_launcher.png
Binary files differ
diff --git a/aboutit/src/main/res/drawable-xhdpi/ic_launcher.png b/aboutit/src/main/res/drawable-xhdpi/ic_launcher.png
new file mode 100644
index 0000000..71c6d76
--- /dev/null
+++ b/aboutit/src/main/res/drawable-xhdpi/ic_launcher.png
Binary files differ
diff --git a/aboutit/src/main/res/drawable-xxhdpi/ic_launcher.png b/aboutit/src/main/res/drawable-xxhdpi/ic_launcher.png
new file mode 100644
index 0000000..4df1894
--- /dev/null
+++ b/aboutit/src/main/res/drawable-xxhdpi/ic_launcher.png
Binary files differ
diff --git a/aboutit/src/main/res/values/strings.xml b/aboutit/src/main/res/values/strings.xml
new file mode 100644
index 0000000..9b430f7
--- /dev/null
+++ b/aboutit/src/main/res/values/strings.xml
@@ -0,0 +1,3 @@
+<resources>
+ <string name="app_name">AboutIt</string>
+</resources>