From 372c5da8d09ff9928f937c4288b3f92351a576da Mon Sep 17 00:00:00 2001 From: Allan Wang Date: Wed, 21 Jun 2017 12:23:04 -0700 Subject: Add more configs in email builder --- .../kotlin/ca/allanwang/kau/email/EmailBuilder.kt | 25 +++++++++++++++++----- library/src/main/res/values/strings_commons.xml | 9 ++++++-- .../kotlin/ca/allanwang/kau/sample/MainActivity.kt | 2 ++ sample/src/main/res/menu/menu_main.xml | 7 +++++- sample/src/main/res/values/strings.xml | 2 ++ 5 files changed, 37 insertions(+), 8 deletions(-) diff --git a/library/src/main/kotlin/ca/allanwang/kau/email/EmailBuilder.kt b/library/src/main/kotlin/ca/allanwang/kau/email/EmailBuilder.kt index 1553757..ed3b928 100644 --- a/library/src/main/kotlin/ca/allanwang/kau/email/EmailBuilder.kt +++ b/library/src/main/kotlin/ca/allanwang/kau/email/EmailBuilder.kt @@ -1,11 +1,13 @@ package ca.allanwang.kau.email +import android.app.Activity import android.content.Context import android.content.Intent import android.content.pm.PackageManager import android.net.Uri import android.os.Build import android.support.annotation.StringRes +import android.util.DisplayMetrics import ca.allanwang.kau.R import ca.allanwang.kau.logging.KL import ca.allanwang.kau.utils.isAppInstalled @@ -20,10 +22,13 @@ class EmailBuilder(@StringRes val emailId: Int, @StringRes val subjectId: Int) { var deviceDetails: Boolean = true var appInfo: Boolean = true var footer: String? = null + private val pairs: MutableMap = mutableMapOf() private val packages: MutableList = mutableListOf() fun checkPackage(packageName: String, appName: String) = packages.add(Package(packageName, appName)) + fun addItem(key: String, value: String) = pairs.put(key, value) + data class Package(val packageName: String, val appName: String) fun execute(context: Context) { @@ -31,31 +36,41 @@ class EmailBuilder(@StringRes val emailId: Int, @StringRes val subjectId: Int) { intent.putExtra(Intent.EXTRA_SUBJECT, context.string(subjectId)) val emailBuilder = StringBuilder() emailBuilder.append(message).append("\n\n") - if (deviceDetails) + if (deviceDetails) { emailBuilder.append("\nOS Version: ").append(System.getProperty("os.version")).append("(").append(Build.VERSION.INCREMENTAL).append(")") .append("\nOS API Level: ").append(Build.VERSION.SDK_INT) .append("\nDevice: ").append(Build.DEVICE) .append("\nManufacturer: ").append(Build.MANUFACTURER) .append("\nModel (and Product): ").append(Build.MODEL).append(" (").append(Build.PRODUCT).append(")") - .append("\n") - + if (context is Activity) { + val metric = DisplayMetrics() + context.windowManager.defaultDisplay.getMetrics(metric) + emailBuilder.append("\nScreen Dimensions: ${metric.widthPixels} x ${metric.heightPixels}") + } + emailBuilder.append("\n") + } if (appInfo) { try { val appInfo = context.packageManager.getPackageInfo(context.packageName, 0) - emailBuilder.append("\nApp Version Name: ").append(appInfo.versionName) + emailBuilder.append("\nApp: ").append(context.packageName) + .append("\nApp Version Name: ").append(appInfo.versionName) .append("\nApp Version Code: ").append(appInfo.versionCode).append("\n") } catch (e: PackageManager.NameNotFoundException) { KL.e("EmailBuilder packageInfo not found") } } + if (packages.isNotEmpty()) emailBuilder.append("\n") packages.forEach { if (context.isAppInstalled(it.packageName)) emailBuilder.append(String.format("\n%s is installed", it.appName)) } + if (pairs.isNotEmpty()) emailBuilder.append("\n") + pairs.forEach { k, v -> emailBuilder.append("$k: $v\n") } + if (footer != null) - emailBuilder.append("\n\n").append(footer) + emailBuilder.append("\n").append(footer) intent.putExtra(Intent.EXTRA_TEXT, emailBuilder.toString()) context.startActivity(Intent.createChooser(intent, context.resources.getString(R.string.kau_send_via))) diff --git a/library/src/main/res/values/strings_commons.xml b/library/src/main/res/values/strings_commons.xml index 760d22e..2198564 100644 --- a/library/src/main/res/values/strings_commons.xml +++ b/library/src/main/res/values/strings_commons.xml @@ -4,21 +4,26 @@ Most resources are verbatim and x represents a formatted item --> + AMOLED Back Cancel Changelog Close Contact Us - Done + Custom + Dark + Default Do not show again + Done Error Exit Are you sure you want to exit? Are you sure you want to exit %s? Great + Light Login Logout - Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. + Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. Maybe No None diff --git a/sample/src/main/kotlin/ca/allanwang/kau/sample/MainActivity.kt b/sample/src/main/kotlin/ca/allanwang/kau/sample/MainActivity.kt index a03857a..8867a00 100644 --- a/sample/src/main/kotlin/ca/allanwang/kau/sample/MainActivity.kt +++ b/sample/src/main/kotlin/ca/allanwang/kau/sample/MainActivity.kt @@ -3,6 +3,7 @@ package ca.allanwang.kau.sample import android.os.Bundle import android.view.Menu import android.view.MenuItem +import ca.allanwang.kau.email.sendEmail import ca.allanwang.kau.kpref.KPrefActivity import ca.allanwang.kau.kpref.KPrefAdapterBuilder import ca.allanwang.kau.utils.* @@ -103,6 +104,7 @@ class MainActivity : KPrefActivity() { override fun onOptionsItemSelected(item: MenuItem): Boolean { when (item.itemId) { R.id.action_settings -> startActivity(AnimActivity::class.java, clearStack = true) + R.id.action_email -> sendEmail(R.string.your_email, R.string.your_subject) else -> return super.onOptionsItemSelected(item) } return true diff --git a/sample/src/main/res/menu/menu_main.xml b/sample/src/main/res/menu/menu_main.xml index 3725b18..caafd48 100644 --- a/sample/src/main/res/menu/menu_main.xml +++ b/sample/src/main/res/menu/menu_main.xml @@ -5,7 +5,12 @@ + diff --git a/sample/src/main/res/values/strings.xml b/sample/src/main/res/values/strings.xml index 7399593..049a395 100644 --- a/sample/src/main/res/values/strings.xml +++ b/sample/src/main/res/values/strings.xml @@ -15,4 +15,6 @@ This selector allows for custom colors with alpha values Text Pref Saves the text + your.email@here.com + Your subject -- cgit v1.2.3