From 5d2f7b4c8f76a1fb7cb8d3d0ad9ca7e6fcc6274a Mon Sep 17 00:00:00 2001 From: Victor Häggqvist Date: Thu, 1 Jan 2015 16:28:17 +0100 Subject: init --- aboutit/.gitignore | 1 + aboutit/build.gradle | 24 +++ aboutit/proguard-rules.pro | 17 ++ .../java/com/snilius/aboutit/ApplicationTest.java | 13 ++ aboutit/src/main/AndroidManifest.xml | 8 + .../src/main/java/com/snilius/aboutit/AboutIt.java | 232 +++++++++++++++++++++ aboutit/src/main/java/com/snilius/aboutit/L.java | 24 +++ aboutit/src/main/res/drawable-hdpi/ic_launcher.png | Bin 0 -> 9397 bytes aboutit/src/main/res/drawable-mdpi/ic_launcher.png | Bin 0 -> 5237 bytes .../src/main/res/drawable-xhdpi/ic_launcher.png | Bin 0 -> 14383 bytes .../src/main/res/drawable-xxhdpi/ic_launcher.png | Bin 0 -> 19388 bytes aboutit/src/main/res/values/strings.xml | 3 + 12 files changed, 322 insertions(+) create mode 100644 aboutit/.gitignore create mode 100644 aboutit/build.gradle create mode 100644 aboutit/proguard-rules.pro create mode 100644 aboutit/src/androidTest/java/com/snilius/aboutit/ApplicationTest.java create mode 100644 aboutit/src/main/AndroidManifest.xml create mode 100644 aboutit/src/main/java/com/snilius/aboutit/AboutIt.java create mode 100644 aboutit/src/main/java/com/snilius/aboutit/L.java create mode 100644 aboutit/src/main/res/drawable-hdpi/ic_launcher.png create mode 100644 aboutit/src/main/res/drawable-mdpi/ic_launcher.png create mode 100644 aboutit/src/main/res/drawable-xhdpi/ic_launcher.png create mode 100644 aboutit/src/main/res/drawable-xxhdpi/ic_launcher.png create mode 100644 aboutit/src/main/res/values/strings.xml (limited to 'aboutit') 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; + +/** + * Testing Fundamentals + */ +public class ApplicationTest extends ApplicationTestCase { + 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 @@ + + + + + + + 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; + +/** + *

AboutIt

+ * A About-page creator + * + *
+ * {@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);
+ * }
+ * 
+ * + * @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 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() { + @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 Binary files /dev/null and b/aboutit/src/main/res/drawable-hdpi/ic_launcher.png 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 Binary files /dev/null and b/aboutit/src/main/res/drawable-mdpi/ic_launcher.png 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 Binary files /dev/null and b/aboutit/src/main/res/drawable-xhdpi/ic_launcher.png 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 Binary files /dev/null and b/aboutit/src/main/res/drawable-xxhdpi/ic_launcher.png 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 @@ + + AboutIt + -- cgit v1.2.3