diff --git a/.gitignore b/.gitignore index f6b286c..81d4b50 100644 --- a/.gitignore +++ b/.gitignore @@ -34,7 +34,7 @@ captures/ # Intellij *.iml -.idea/workspace.xml +.idea/ # Keystore files *.jks diff --git a/.idea/compiler.xml b/.idea/compiler.xml deleted file mode 100644 index 96cc43e..0000000 --- a/.idea/compiler.xml +++ /dev/null @@ -1,22 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/.idea/copyright/profiles_settings.xml b/.idea/copyright/profiles_settings.xml deleted file mode 100644 index e7bedf3..0000000 --- a/.idea/copyright/profiles_settings.xml +++ /dev/null @@ -1,3 +0,0 @@ - - - \ No newline at end of file diff --git a/.idea/gradle.xml b/.idea/gradle.xml deleted file mode 100644 index 94946c6..0000000 --- a/.idea/gradle.xml +++ /dev/null @@ -1,18 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/.idea/libraries/animated_vector_drawable_25_1_0.xml b/.idea/libraries/animated_vector_drawable_25_1_0.xml deleted file mode 100644 index 04eaa82..0000000 --- a/.idea/libraries/animated_vector_drawable_25_1_0.xml +++ /dev/null @@ -1,12 +0,0 @@ - - - - - - - - - - - - \ No newline at end of file diff --git a/.idea/libraries/answers_shim_0_0_6.xml b/.idea/libraries/answers_shim_0_0_6.xml deleted file mode 100644 index ed4c218..0000000 --- a/.idea/libraries/answers_shim_0_0_6.xml +++ /dev/null @@ -1,10 +0,0 @@ - - - - - - - - - - \ No newline at end of file diff --git a/.idea/libraries/appcompat_v7_25_1_0.xml b/.idea/libraries/appcompat_v7_25_1_0.xml deleted file mode 100644 index 05f4b67..0000000 --- a/.idea/libraries/appcompat_v7_25_1_0.xml +++ /dev/null @@ -1,15 +0,0 @@ - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/.idea/libraries/cardview_v7_25_1_0.xml b/.idea/libraries/cardview_v7_25_1_0.xml deleted file mode 100644 index 58c989a..0000000 --- a/.idea/libraries/cardview_v7_25_1_0.xml +++ /dev/null @@ -1,12 +0,0 @@ - - - - - - - - - - - - \ No newline at end of file diff --git a/.idea/libraries/design_25_1_0.xml b/.idea/libraries/design_25_1_0.xml deleted file mode 100644 index 390d9cb..0000000 --- a/.idea/libraries/design_25_1_0.xml +++ /dev/null @@ -1,15 +0,0 @@ - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/.idea/libraries/library_2_5_7.xml b/.idea/libraries/library_2_5_7.xml deleted file mode 100644 index e27b642..0000000 --- a/.idea/libraries/library_2_5_7.xml +++ /dev/null @@ -1,15 +0,0 @@ - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/.idea/libraries/material_about_library_1_5_0.xml b/.idea/libraries/material_about_library_1_5_0.xml deleted file mode 100644 index c5467e8..0000000 --- a/.idea/libraries/material_about_library_1_5_0.xml +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - - - - - - - - \ No newline at end of file diff --git a/.idea/libraries/recyclerview_v7_25_1_0.xml b/.idea/libraries/recyclerview_v7_25_1_0.xml deleted file mode 100644 index f588474..0000000 --- a/.idea/libraries/recyclerview_v7_25_1_0.xml +++ /dev/null @@ -1,15 +0,0 @@ - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/.idea/libraries/support_annotations_25_1_0.xml b/.idea/libraries/support_annotations_25_1_0.xml deleted file mode 100644 index cbd775e..0000000 --- a/.idea/libraries/support_annotations_25_1_0.xml +++ /dev/null @@ -1,11 +0,0 @@ - - - - - - - - - - - \ No newline at end of file diff --git a/.idea/libraries/support_compat_25_1_0.xml b/.idea/libraries/support_compat_25_1_0.xml deleted file mode 100644 index cc9e2ac..0000000 --- a/.idea/libraries/support_compat_25_1_0.xml +++ /dev/null @@ -1,15 +0,0 @@ - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/.idea/libraries/support_core_ui_25_1_0.xml b/.idea/libraries/support_core_ui_25_1_0.xml deleted file mode 100644 index 8119b19..0000000 --- a/.idea/libraries/support_core_ui_25_1_0.xml +++ /dev/null @@ -1,15 +0,0 @@ - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/.idea/libraries/support_core_utils_25_1_0.xml b/.idea/libraries/support_core_utils_25_1_0.xml deleted file mode 100644 index 609ac4c..0000000 --- a/.idea/libraries/support_core_utils_25_1_0.xml +++ /dev/null @@ -1,15 +0,0 @@ - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/.idea/libraries/support_fragment_25_1_0.xml b/.idea/libraries/support_fragment_25_1_0.xml deleted file mode 100644 index 0d96f0b..0000000 --- a/.idea/libraries/support_fragment_25_1_0.xml +++ /dev/null @@ -1,15 +0,0 @@ - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/.idea/libraries/support_media_compat_25_1_0.xml b/.idea/libraries/support_media_compat_25_1_0.xml deleted file mode 100644 index 7724360..0000000 --- a/.idea/libraries/support_media_compat_25_1_0.xml +++ /dev/null @@ -1,15 +0,0 @@ - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/.idea/libraries/support_v4_25_1_0.xml b/.idea/libraries/support_v4_25_1_0.xml deleted file mode 100644 index 9652c57..0000000 --- a/.idea/libraries/support_v4_25_1_0.xml +++ /dev/null @@ -1,10 +0,0 @@ - - - - - - - - - - \ No newline at end of file diff --git a/.idea/libraries/support_vector_drawable_25_1_0.xml b/.idea/libraries/support_vector_drawable_25_1_0.xml deleted file mode 100644 index 860cf14..0000000 --- a/.idea/libraries/support_vector_drawable_25_1_0.xml +++ /dev/null @@ -1,12 +0,0 @@ - - - - - - - - - - - - \ No newline at end of file diff --git a/.idea/libraries/transition_25_1_0.xml b/.idea/libraries/transition_25_1_0.xml deleted file mode 100644 index 37e0254..0000000 --- a/.idea/libraries/transition_25_1_0.xml +++ /dev/null @@ -1,12 +0,0 @@ - - - - - - - - - - - - \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml deleted file mode 100644 index 519d433..0000000 --- a/.idea/misc.xml +++ /dev/null @@ -1,41 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml deleted file mode 100644 index 9601e1c..0000000 --- a/.idea/modules.xml +++ /dev/null @@ -1,9 +0,0 @@ - - - - - - - - - \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml deleted file mode 100644 index 35eb1dd..0000000 --- a/.idea/vcs.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/README.md b/README.md index 79ed307..24137eb 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,150 @@ -# android-about-box -Modern About Box for an Android App +[![Circle CI](https://circleci.com/gh/eggheadgames/android-about-box.svg?style=svg)](https://circleci.com/gh/eggheadgames/android-about-box) +[![Release](https://jitpack.io/v/eggheadgames/android-about-box.svg)](https://jitpack.io/#eggheadgames/android-about-box) +![Downloads](https://jitpack.io/v/eggheadgames/android-about-box/month.svg) +[![GitHub license](https://img.shields.io/badge/license-MIT-blue.svg)](https://github.com/eggheadgames/android-about-box/blob/develop/LICENSE) + +# About Box +A modern About Box for an Android App built on the [daniel-stoneuk/material-about-library](https://github.com/daniel-stoneuk/material-about-library). + +### Easily display the common items of an About Box in a modern Android friendly way + +## About + +Android About Box is configured with a set of (mostly) strings for the company name, twitter and Facebook accounts, website, and filenames to html files for help files, privacy policy etc. + +When triggered from a menu item, it will display the app name, icon and version, provide links to contact support, leave a review, share the app, go to other apps by the same company in the app store -- as well as links to Facebook etc. + +You can omit most features if they don't apply (e.g. like website), by not setting the values. + +## Installation Instructions + +Add the JitPack.io repository to your root `build.gradle`: + +```gradle +allprojects { + repositories { + maven { url "https://jitpack.io" } + } +} +``` + +Add a dependency to your application related `build.gradle` + +```gradle +dependencies { + compile 'com.github.eggheadgames:android-about-box:' +} +``` + +## Setup AboutBox + +Add AboutBox configuration to your Application class + +```java + AboutConfig aboutConfig = AboutConfig.getInstance(); + aboutConfig.appName = getString(R.string.app_name); + aboutConfig.appIcon = R.mipmap.ic_launcher; + aboutConfig.version = "1.0.0"; + aboutConfig.author = "Tolstoy"; + aboutConfig.aboutLabelTitle = "About App"; + aboutConfig.packageName = getApplicationContext().getPackageName(); + aboutConfig.buildType = google ? AboutConfig.BuildType.GOOGLE : AboutConfig.BuildType.AMAZON; + + aboutConfig.facebookUserName = FACEBOOK_USER_NAME; + aboutConfig.twitterUserName = TWITTER_USER_NAME; + aboutConfig.webHomePage = WEB_HOME_PAGE; + + // app publisher for "Try Other Apps" item + aboutConfig.appPublisher = APP_PUBLISHER; + + // if pages are stored locally, then you need to override aboutConfig.dialog to be able use custom WebView + aboutConfig.companyHtmlPath = COMPANY_HTML_PATH; + aboutConfig.privacyHtmlPath = PRIVACY_HTML_PATH; + aboutConfig.acknowledgmentHtmlPath = ACKNOWLEDGMENT_HTML_PATH; + + aboutConfig.dialog = new IDialog() { + @Override + public void open(AppCompatActivity appCompatActivity, String url, String tag) { + // handle custom implementations of WebView. It will be called when user click to web items. (Example: "Privacy", "Acknowledgments" and "About") + } + }; + + aboutConfig.analytics = new IAnalytic() { + @Override + public void logUiEvent(String s, String s1) { + // handle log events. + } + + @Override + public void logException(Exception e, boolean b) { + // handle exception events. + } + }; + // set it only if aboutConfig.analytics is defined. + aboutConfig.logUiEventName = "Log"; + + // Contact Support email details + aboutConfig.emailAddress = EMAIL_ADDRESS; + aboutConfig.emailSubject = EMAIL_SUBJECT; + aboutConfig.emailBody = EMAIL_BODY; + + +``` + +## Open the About Box from your app + +```java + AboutActivity.launch(activity); +``` + + + +## Sharing + +By default, the default Android share intent will be called with the values specified in `shareMessage` and `sharingTitle`. For example: +```java + aboutConfig.shareMessage = getString(R.string.share_message); + aboutConfig.sharingTitle = getString(R.string.sharing_title); +``` +The `share_message` string will have an app store URL appended to it (appropriately constructed for Google Play or Amazon). + +Alternatively, you can provide a custom sharing function (and omit `shareMessage` and `sharingTitle`): + ```java + aboutConfig.share = new IShare() { + @Override + public void share(Activity activity) { + // do custom sharing + } + }; +``` + +## Theme + +If you add the following to your AndroidManifest.xml file, the About Box will use these colours. This allows you to match your app colours: + +```xml + +``` + +Ensure that `AppTheme.MaterialAboutActivity` theme extends either of these themes, and apply primary & accent colours: +``` +Theme.Mal.Light.DarkActionBar +Theme.Mal.Light.LightActionBar +Theme.Mal.Dark.LightActionBar +Theme.Mal.Dark.DarkActionBar +``` + +```xml + +``` +## Screenshot + + + diff --git a/circle.yml b/circle.yml index e6a8356..a6eee0c 100644 --- a/circle.yml +++ b/circle.yml @@ -1,7 +1,7 @@ dependencies: pre: - - echo y | android update sdk --no-ui --all --filter tools,platform-tools,android-24 - - echo y | android update sdk --no-ui --all --filter build-tools-24.0.2 + - echo y | android update sdk --no-ui --all --filter tools,platform-tools,android-25 + - echo y | android update sdk --no-ui --all --filter build-tools-25.0.3 test: override: diff --git a/extras/example.png b/extras/example.png new file mode 100644 index 0000000..adb68b4 Binary files /dev/null and b/extras/example.png differ diff --git a/gradlew b/gradlew old mode 100644 new mode 100755 diff --git a/library/build.gradle b/library/build.gradle index 7e8dee8..d5d552d 100644 --- a/library/build.gradle +++ b/library/build.gradle @@ -5,15 +5,14 @@ apply plugin: 'com.github.dcendents.android-maven' group='com.github.eggheadgames' android { - compileSdkVersion 24 - buildToolsVersion "24.0.2" + compileSdkVersion 25 + buildToolsVersion "25.0.3" defaultConfig { minSdkVersion 15 targetSdkVersion 24 - versionCode 1 - versionName "1.0" - + versionCode 7 + versionName "1.3.1" } buildTypes { release { @@ -29,8 +28,5 @@ android { } dependencies { - compile 'com.github.daniel-stoneuk:material-about-library:1.5.0' - compile('io.branch.sdk.android:library:2.5.7') { - exclude module: 'answers.shim' - } + compile 'com.github.daniel-stoneuk:material-about-library:2.2.1' } diff --git a/library/src/main/AndroidManifest.xml b/library/src/main/AndroidManifest.xml index 3b15948..ef784a0 100644 --- a/library/src/main/AndroidManifest.xml +++ b/library/src/main/AndroidManifest.xml @@ -1,10 +1,10 @@ + package="com.eggheadgames.aboutbox"> - + + android:theme="@style/AppTheme.MaterialAboutActivity"/> diff --git a/library/src/main/java/com/eggheadgames/aboutbox/AboutBoxUtils.java b/library/src/main/java/com/eggheadgames/aboutbox/AboutBoxUtils.java new file mode 100644 index 0000000..32a3524 --- /dev/null +++ b/library/src/main/java/com/eggheadgames/aboutbox/AboutBoxUtils.java @@ -0,0 +1,109 @@ +package com.eggheadgames.aboutbox; + +import android.app.Activity; +import android.content.ActivityNotFoundException; +import android.content.Intent; +import android.net.Uri; +import android.widget.Toast; + +public final class AboutBoxUtils { + + public final static String playStoreAppURI = "https://play.google.com/store/apps/details?id="; + public final static String amznStoreAppURI = "https://www.amazon.com/gp/mas/dl/android?p="; + + private AboutBoxUtils() { + //nothing + } + + public static void getOpenFacebookIntent(Activity context, String name) { + try { + context.getPackageManager().getPackageInfo("com.facebook.katana", 0); + Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("fb://profile/" + name)); + context.startActivity(intent); + } catch (Exception e) { + try { + Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("https://www.facebook.com/" + name)); + context.startActivity(intent); + } catch (Exception e1) { + Toast.makeText(context, R.string.egab_can_not_open, Toast.LENGTH_SHORT).show(); + } + } + } + + public static void startTwitter(Activity context, String name) { + try { + context.getPackageManager().getPackageInfo("com.twitter.android", 0); + Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("twitter://user?screen_name=" + name)); + intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); + context.startActivity(intent); + } catch (Exception e) { + try { + Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("https://twitter.com/" + name)); + context.startActivity(intent); + } catch (Exception e1) { + Toast.makeText(context, R.string.egab_can_not_open, Toast.LENGTH_SHORT).show(); + } + } + } + + public static void openApp(Activity context, AboutConfig.BuildType buildType, String packageName) { + String appURI = null; + String webURI = null; + switch (buildType) { + case GOOGLE: + appURI = "market://details?id=" + packageName; + webURI = playStoreAppURI + packageName; + break; + case AMAZON: + appURI = "amzn://apps/android?p=" + packageName; + webURI = amznStoreAppURI + packageName; + break; + default: + //nothing + } + openApplication(context, appURI, webURI); + } + + public static void openPublisher(Activity context, AboutConfig.BuildType buildType, String publisher, String packageName) { + String appURI = null; + String webURI = null; + switch (buildType) { + case GOOGLE: + // see: + // https://developer.android.com/distribute/marketing-tools/linking-to-google-play.html#OpeningPublisher + // https://stackoverflow.com/questions/32029408/how-to-open-developer-page-on-google-play-store-market + // https://issuetracker.google.com/65244694 + if (publisher.matches("\\d+")) { + webURI = "https://play.google.com/store/apps/dev?id=" + publisher; + appURI = webURI; + } else { + appURI = "market://search?q=pub:" + publisher; + webURI = "https://play.google.com/store/search?q=pub:" + publisher; + } + break; + case AMAZON: + appURI = "amzn://apps/android?showAll=1&p=" + packageName; + webURI = "http://www.amazon.com/gp/mas/dl/android?showAll=1&p=" + packageName; + break; + default: + //nothing + } + openApplication(context, appURI, webURI); + } + + public static void openApplication(Activity context, String appURI, String webURI) { + try { + context.startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(appURI))); + } catch (ActivityNotFoundException e1) { + try { + openHTMLPage(context, webURI); + } catch (ActivityNotFoundException e2) { + Toast.makeText(context, R.string.egab_can_not_open, Toast.LENGTH_SHORT).show(); + } + } + } + + public static void openHTMLPage(Activity context, String htmlPath) { + context.startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(htmlPath))); + } +} diff --git a/library/src/main/java/com/eggheadgames/aboutbox/AboutConfig.java b/library/src/main/java/com/eggheadgames/aboutbox/AboutConfig.java index 490fc95..4929ab6 100644 --- a/library/src/main/java/com/eggheadgames/aboutbox/AboutConfig.java +++ b/library/src/main/java/com/eggheadgames/aboutbox/AboutConfig.java @@ -8,11 +8,15 @@ public class AboutConfig { public String appName; public int appIcon; public String version; + public String author; + public String extra; + public String extraTitle; public String aboutLabelTitle; public String logUiEventName; public String facebookUserName; public String twitterUserName; public String webHomePage; + public String guideHtmlPath; public String appPublisher; public String companyHtmlPath; public String privacyHtmlPath; @@ -20,9 +24,10 @@ public class AboutConfig { public BuildType buildType; public String packageName; - // custom analytics and dialog + // custom analytics, dialog and share public IAnalytic analytics; public IDialog dialog; + public IShare share; // email public String emailAddress; @@ -30,7 +35,6 @@ public class AboutConfig { public String emailBody; // share - public String shareMessageTitle; public String shareMessage; public String sharingTitle; diff --git a/library/src/main/java/com/eggheadgames/aboutbox/IShare.java b/library/src/main/java/com/eggheadgames/aboutbox/IShare.java new file mode 100644 index 0000000..b9b5520 --- /dev/null +++ b/library/src/main/java/com/eggheadgames/aboutbox/IShare.java @@ -0,0 +1,9 @@ +package com.eggheadgames.aboutbox; + + +import android.app.Activity; + +public interface IShare { + + void share(Activity activity); +} diff --git a/library/src/main/java/com/eggheadgames/aboutbox/activity/AboutActivity.java b/library/src/main/java/com/eggheadgames/aboutbox/activity/AboutActivity.java index d2b1b67..98555a1 100644 --- a/library/src/main/java/com/eggheadgames/aboutbox/activity/AboutActivity.java +++ b/library/src/main/java/com/eggheadgames/aboutbox/activity/AboutActivity.java @@ -1,18 +1,20 @@ package com.eggheadgames.aboutbox.activity; import android.app.Activity; -import android.content.ActivityNotFoundException; import android.content.Context; import android.content.Intent; -import android.net.Uri; -import android.widget.Toast; +import android.support.annotation.NonNull; +import android.text.TextUtils; import com.danielstone.materialaboutlibrary.MaterialAboutActivity; -import com.danielstone.materialaboutlibrary.model.MaterialAboutActionItem; +import com.danielstone.materialaboutlibrary.items.MaterialAboutActionItem; +import com.danielstone.materialaboutlibrary.items.MaterialAboutItemOnClickAction; +import com.danielstone.materialaboutlibrary.items.MaterialAboutTitleItem; import com.danielstone.materialaboutlibrary.model.MaterialAboutCard; import com.danielstone.materialaboutlibrary.model.MaterialAboutList; -import com.danielstone.materialaboutlibrary.model.MaterialAboutTitleItem; +import com.eggheadgames.aboutbox.AboutBoxUtils; import com.eggheadgames.aboutbox.AboutConfig; +import com.eggheadgames.aboutbox.IAnalytic; import com.eggheadgames.aboutbox.R; import com.eggheadgames.aboutbox.share.EmailUtil; import com.eggheadgames.aboutbox.share.ShareUtil; @@ -21,6 +23,7 @@ public class AboutActivity extends MaterialAboutActivity { public static void launch(Activity activity) { Intent intent = new Intent(activity, AboutActivity.class); + intent.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT); activity.startActivity(intent); } @@ -29,6 +32,18 @@ public class AboutActivity extends MaterialAboutActivity { final AboutConfig config = AboutConfig.getInstance(); + return new MaterialAboutList.Builder() + .addCard(buildGeneralInfoCard(config)) + .addCard(buildSupportCard(config)) + .addCard(buildShareCard(config)) + .addCard(buildAboutCard(config)) + .addCard(buildSocialNetworksCard(config)) + .addCard(buildPrivacyCard(config)) + .build(); + } + + @NonNull + private MaterialAboutCard buildGeneralInfoCard(AboutConfig config) { MaterialAboutCard.Builder generalInfoCardBuilder = new MaterialAboutCard.Builder(); generalInfoCardBuilder.addItem(new MaterialAboutTitleItem.Builder() @@ -37,234 +52,222 @@ public class AboutActivity extends MaterialAboutActivity { .build()); generalInfoCardBuilder.addItem(new MaterialAboutActionItem.Builder() - .text(R.string.version) + .text(R.string.egab_version) .subText(config.version) .build()); + if (!TextUtils.isEmpty(config.author)) { + generalInfoCardBuilder.addItem(new MaterialAboutActionItem.Builder() + .text(R.string.egab_author) + .subText(config.author) + .build()); + } - MaterialAboutCard.Builder supportCardBuilder = new MaterialAboutCard.Builder(); - supportCardBuilder.addItem(new MaterialAboutActionItem.Builder() - .text(R.string.contact_support) - .icon(R.drawable.ic_email_black) - .setOnClickListener(new MaterialAboutActionItem.OnClickListener() { + if (!TextUtils.isEmpty(config.extra) && !TextUtils.isEmpty(config.extraTitle)) { + generalInfoCardBuilder.addItem(new MaterialAboutActionItem.Builder() + .text(config.extraTitle) + .subTextHtml(config.extra) + .build()); + } + + return generalInfoCardBuilder.build(); + } + + @NonNull + private MaterialAboutCard buildSupportCard(final AboutConfig config) { + MaterialAboutCard.Builder card = new MaterialAboutCard.Builder(); + + if (!TextUtils.isEmpty(config.guideHtmlPath)) { + card.addItem(itemHelper(R.string.egab_guide, R.drawable.ic_help_green, + new MaterialAboutItemOnClickAction() { + @Override + public void onClick() { + if (config.dialog == null) { + AboutBoxUtils.openHTMLPage(AboutActivity.this, config.guideHtmlPath); + } else { + config.dialog.open(AboutActivity.this, config.guideHtmlPath, getString(R.string.egab_guide)); + } + logUIEventName(config.analytics, config.logUiEventName, getString(R.string.egab_guide)); + } + }) + ); + } + card.addItem(itemHelper(R.string.egab_contact_support, R.drawable.ic_email_black, + new MaterialAboutItemOnClickAction() { @Override public void onClick() { EmailUtil.contactUs(AboutActivity.this); - if (config.analytics != null) { - config.analytics.logUiEvent(config.logUiEventName, getString(R.string.contact_log_event)); - } + logUIEventName(config.analytics, config.logUiEventName, getString(R.string.egab_contact_log_event)); } - }) - .build()); + })); + return card.build(); + } - MaterialAboutCard.Builder shareCardBuilder = new MaterialAboutCard.Builder(); - shareCardBuilder.addItem(new MaterialAboutActionItem.Builder() - .text(R.string.leave_review) - .icon(R.drawable.ic_review) - .setOnClickListener(new MaterialAboutActionItem.OnClickListener() { + @NonNull + private MaterialAboutCard buildShareCard(final AboutConfig config) { + MaterialAboutCard.Builder card = new MaterialAboutCard.Builder(); + if (config.buildType != null && !TextUtils.isEmpty(config.packageName)) { + card.addItem(itemHelper(R.string.egab_leave_review, R.drawable.ic_review, + new MaterialAboutItemOnClickAction() { + @Override + public void onClick() { + AboutBoxUtils.openApp(AboutActivity.this, config.buildType, config.packageName); + logUIEventName(config.analytics, config.logUiEventName, getString(R.string.egab_review_log_event)); + } + })); + } + card.addItem(itemHelper(R.string.egab_share, R.drawable.ic_share_black, + new MaterialAboutItemOnClickAction() { @Override public void onClick() { - openApp(config.packageName, config.buildType == AboutConfig.BuildType.GOOGLE); - if (config.analytics != null) { - config.analytics.logUiEvent(config.logUiEventName, getString(R.string.review_log_event)); - } - } - }) - .build()); - shareCardBuilder.addItem(new MaterialAboutActionItem.Builder() - .text(R.string.share) - .icon(R.drawable.ic_share_black) - .setOnClickListener(new MaterialAboutActionItem.OnClickListener() { - @Override - public void onClick() { - ShareUtil.share(AboutActivity.this); - if (config.analytics != null) { - config.analytics.logUiEvent(config.logUiEventName, getString(R.string.share_log_event)); - } - } - }) - .build()); - - - MaterialAboutCard.Builder aboutCardBuilder = new MaterialAboutCard.Builder(); - aboutCardBuilder.addItem(new MaterialAboutActionItem.Builder() - .text(R.string.try_other_apps) - .icon(R.drawable.ic_try_other_apps) - .setOnClickListener(new MaterialAboutActionItem.OnClickListener() { - @Override - public void onClick() { - openPublisher(config.buildType == AboutConfig.BuildType.GOOGLE, config.appPublisher); - if (config.analytics != null) { - config.analytics.logUiEvent(config.logUiEventName, getString(R.string.try_other_app_log_event)); - } - } - }) - .build()); - aboutCardBuilder.addItem(new MaterialAboutActionItem.Builder() - .text(config.aboutLabelTitle) - .icon(R.drawable.ic_about_black) - .setOnClickListener(new MaterialAboutActionItem.OnClickListener() { - @Override - public void onClick() { - if (config.dialog == null) { - startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(config.companyHtmlPath))); + if (config.share == null) { + ShareUtil.share(AboutActivity.this); } else { - config.dialog.open(AboutActivity.this, config.companyHtmlPath, config.aboutLabelTitle); - } - - if (config.analytics != null) { - config.analytics.logUiEvent(config.logUiEventName, config.aboutLabelTitle); + config.share.share(AboutActivity.this); } + logUIEventName(config.analytics, config.logUiEventName, getString(R.string.egab_share_log_event)); } - }) - .build()); + })); + return card.build(); + } - - MaterialAboutCard.Builder socialNetworksCardBuilder = new MaterialAboutCard.Builder(); - socialNetworksCardBuilder.addItem(new MaterialAboutActionItem.Builder() - .text(R.string.facebook_label) - .subText(config.facebookUserName) - .icon(R.drawable.ic_facebook_24) - .setOnClickListener(new MaterialAboutActionItem.OnClickListener() { - @Override - public void onClick() { - getOpenFacebookIntent(AboutActivity.this, config.facebookUserName); - if (config.analytics != null) { - config.analytics.logUiEvent(config.logUiEventName, getString(R.string.facebook_log_event)); + @NonNull + private MaterialAboutCard buildAboutCard(final AboutConfig config) { + MaterialAboutCard.Builder card = new MaterialAboutCard.Builder(); + if (config.buildType != null && !TextUtils.isEmpty(config.appPublisher) && !TextUtils.isEmpty(config.packageName)) { + card.addItem(itemHelper(R.string.egab_try_other_apps, R.drawable.ic_try_other_apps, + new MaterialAboutItemOnClickAction() { + @Override + public void onClick() { + AboutBoxUtils.openPublisher(AboutActivity.this, config.buildType, + config.appPublisher, config.packageName); + logUIEventName(config.analytics, config.logUiEventName, getString(R.string.egab_try_other_app_log_event)); } - } - }) - .build()); - socialNetworksCardBuilder.addItem(new MaterialAboutActionItem.Builder() - .text(R.string.twitter_label) - .subText(config.twitterUserName) - .icon(R.drawable.ic_twitter_24dp) - .setOnClickListener(new MaterialAboutActionItem.OnClickListener() { - @Override - public void onClick() { - startTwitter(AboutActivity.this, config.twitterUserName); - if (config.analytics != null) { - config.analytics.logUiEvent(config.logUiEventName, getString(R.string.twitter_log_event)); + })); + } + if (!TextUtils.isEmpty(config.companyHtmlPath) && !TextUtils.isEmpty(config.aboutLabelTitle)) { + card.addItem(new MaterialAboutActionItem.Builder() + .text(config.aboutLabelTitle) + .icon(R.drawable.ic_about_black) + .setOnClickAction(new MaterialAboutItemOnClickAction() { + @Override + public void onClick() { + if (config.dialog == null) { + AboutBoxUtils.openHTMLPage(AboutActivity.this, config.companyHtmlPath); + } else { + config.dialog.open(AboutActivity.this, config.companyHtmlPath, config.aboutLabelTitle); + } + logUIEventName(config.analytics, config.logUiEventName, config.aboutLabelTitle); } - } - }) - .build()); + }) + .build()); + } + return card.build(); + } - socialNetworksCardBuilder.addItem(new MaterialAboutActionItem.Builder() - .text(R.string.web_label) - .subText(config.webHomePage.replace("https://", "").replace("http://", "").replace("/", "")) - .icon(R.drawable.ic_web_black_24dp) - .setOnClickListener(new MaterialAboutActionItem.OnClickListener() { - @Override - public void onClick() { - startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(config.webHomePage))); - if (config.analytics != null) { - config.analytics.logUiEvent(config.logUiEventName, getString(R.string.website_log_event)); + @NonNull + private MaterialAboutCard buildSocialNetworksCard(final AboutConfig config) { + MaterialAboutCard.Builder card = new MaterialAboutCard.Builder(); + if (!TextUtils.isEmpty(config.facebookUserName)) { + card.addItem(new MaterialAboutActionItem.Builder() + .text(R.string.egab_facebook_label) + .subText(config.facebookUserName) + .icon(R.drawable.ic_facebook_24) + .setOnClickAction(new MaterialAboutItemOnClickAction() { + @Override + public void onClick() { + AboutBoxUtils.getOpenFacebookIntent(AboutActivity.this, config.facebookUserName); + logUIEventName(config.analytics, config.logUiEventName, getString(R.string.egab_facebook_log_event)); } - } - }) - .build()); - - MaterialAboutCard.Builder privacyCardBuilder = new MaterialAboutCard.Builder(); - privacyCardBuilder.addItem(new MaterialAboutActionItem.Builder() - .text(R.string.privacy_policy) - .icon(R.drawable.ic_privacy) - .setOnClickListener(new MaterialAboutActionItem.OnClickListener() { - @Override - public void onClick() { - if (config.dialog == null) { - startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(config.privacyHtmlPath))); - } else { - config.dialog.open(AboutActivity.this, config.privacyHtmlPath, getString(R.string.privacy_policy)); + }) + .build()); + } + if (!TextUtils.isEmpty(config.twitterUserName)) { + card.addItem(new MaterialAboutActionItem.Builder() + .text(R.string.egab_twitter_label) + .subText(config.twitterUserName) + .icon(R.drawable.ic_twitter_24dp) + .setOnClickAction(new MaterialAboutItemOnClickAction() { + @Override + public void onClick() { + AboutBoxUtils.startTwitter(AboutActivity.this, config.twitterUserName); + logUIEventName(config.analytics, config.logUiEventName, getString(R.string.egab_twitter_log_event)); } - - if (config.analytics != null) { - config.analytics.logUiEvent(config.logUiEventName, getString(R.string.privacy_log_event)); + }) + .build()); + } + if (!TextUtils.isEmpty(config.webHomePage)) { + card.addItem(new MaterialAboutActionItem.Builder() + .text(R.string.egab_web_label) + .subText(config.webHomePage.replaceFirst("^https?://", "").replaceAll("/$", "")) + .icon(R.drawable.ic_web_black_24dp) + .setOnClickAction(new MaterialAboutItemOnClickAction() { + @Override + public void onClick() { + AboutBoxUtils.openHTMLPage(AboutActivity.this, config.webHomePage); + logUIEventName(config.analytics, config.logUiEventName, getString(R.string.egab_website_log_event)); } - } - }) - .build()); - privacyCardBuilder.addItem(new MaterialAboutActionItem.Builder() - .text(R.string.acknowledgment) - .icon(R.drawable.ic_acknowledgment) - .setOnClickListener(new MaterialAboutActionItem.OnClickListener() { - @Override - public void onClick() { - if (config.dialog == null) { - startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(config.acknowledgmentHtmlPath))); - } else { - config.dialog.open(AboutActivity.this, config.acknowledgmentHtmlPath, getString(R.string.acknowledgment)); + }) + .build()); + } + return card.build(); + } + + @NonNull + private MaterialAboutCard buildPrivacyCard(final AboutConfig config) { + MaterialAboutCard.Builder card = new MaterialAboutCard.Builder(); + if (!TextUtils.isEmpty(config.privacyHtmlPath)) { + card.addItem(itemHelper(R.string.egab_privacy_policy, R.drawable.ic_privacy, + new MaterialAboutItemOnClickAction() { + @Override + public void onClick() { + if (config.dialog == null) { + AboutBoxUtils.openHTMLPage(AboutActivity.this, config.privacyHtmlPath); + } else { + config.dialog.open(AboutActivity.this, config.privacyHtmlPath, getString(R.string.egab_privacy_policy)); + } + + logUIEventName(config.analytics, config.logUiEventName, getString(R.string.egab_privacy_log_event)); } - - if (config.analytics != null) { - config.analytics.logUiEvent(config.logUiEventName, getString(R.string.asknowledgment_log_event)); + }) + ); + } + if (!TextUtils.isEmpty(config.acknowledgmentHtmlPath)) { + card.addItem(itemHelper(R.string.egab_acknowledgements, R.drawable.ic_acknowledgements, + new MaterialAboutItemOnClickAction() { + @Override + public void onClick() { + if (config.dialog == null) { + AboutBoxUtils.openHTMLPage(AboutActivity.this, config.acknowledgmentHtmlPath); + } else { + config.dialog.open(AboutActivity.this, config.acknowledgmentHtmlPath, getString(R.string.egab_acknowledgements)); + } + logUIEventName(config.analytics, config.logUiEventName, getString(R.string.egab_acknowledgements_log_event)); } - } - }) - .build()); + }) + ); + } + return card.build(); + } - - return new MaterialAboutList.Builder() - .addCard(generalInfoCardBuilder.build()) - .addCard(supportCardBuilder.build()) - .addCard(shareCardBuilder.build()) - .addCard(aboutCardBuilder.build()) - .addCard(socialNetworksCardBuilder.build()) - .addCard(privacyCardBuilder.build()) + private MaterialAboutActionItem itemHelper(int name, int icon, MaterialAboutItemOnClickAction clickAction) { + return new MaterialAboutActionItem.Builder() + .text(name) + .icon(icon) + .setOnClickAction(clickAction) .build(); } + @Override protected CharSequence getActivityTitle() { - return getString(R.string.about_screen_title); + return getString(R.string.egab_about_screen_title); } - public static void getOpenFacebookIntent(Activity context, String name) { - Intent intent; - try { - context.getPackageManager().getPackageInfo("com.facebook.katana", 0); - intent = new Intent(Intent.ACTION_VIEW, Uri.parse("fb://profile/" + name)); - } catch (Exception e) { - intent = new Intent(Intent.ACTION_VIEW, Uri.parse("https://www.facebook.com/" + name)); - } - context.startActivity(intent); - } - - - public static void startTwitter(Activity context, String name) { - Intent intent; - try { - context.getPackageManager().getPackageInfo("com.twitter.android", 0); - intent = new Intent(Intent.ACTION_VIEW, Uri.parse("twitter://user?screen_name=" + name)); - intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); - } catch (Exception e) { - intent = new Intent(Intent.ACTION_VIEW, Uri.parse("https://twitter.com/" + name)); - } - context.startActivity(intent); - } - - public void openApp(String packageName, boolean googlePlay) {//true if Google Play, false if Amazon Store - try { - startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse((googlePlay ? "market://details?id=" : "amzn://apps/android?p=") + packageName))); - } catch (ActivityNotFoundException e1) { - try { - startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse((googlePlay ? "http://play.google.com/store/apps/details?id=" : "http://www.amazon.com/gp/mas/dl/android?p=") + packageName))); - } catch (ActivityNotFoundException e2) { - Toast.makeText(this, R.string.can_not_open, Toast.LENGTH_SHORT).show(); - } - } - } - - public void openPublisher(boolean googlePlay, String publisher) {//true if Google Play, false if Amazon Store - try { - startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse((googlePlay ? "market://search?q=pub:" : "amzn://apps/android?showAll=1&p=") + publisher))); - } catch (ActivityNotFoundException e1) { - try { - startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse((googlePlay ? "http://play.google.com/store/search?q=pub:" : "http://www.amazon.com/gp/mas/dl/android?showAll=1&p=") + publisher))); - } catch (ActivityNotFoundException e2) { - Toast.makeText(this, R.string.can_not_open, Toast.LENGTH_SHORT).show(); - } + private void logUIEventName(IAnalytic analytics, String eventType, String eventValue) { + if (analytics != null) { + analytics.logUiEvent(eventType, eventValue); } } } diff --git a/library/src/main/java/com/eggheadgames/aboutbox/share/EmailUtil.java b/library/src/main/java/com/eggheadgames/aboutbox/share/EmailUtil.java index a186245..438612a 100644 --- a/library/src/main/java/com/eggheadgames/aboutbox/share/EmailUtil.java +++ b/library/src/main/java/com/eggheadgames/aboutbox/share/EmailUtil.java @@ -3,9 +3,11 @@ package com.eggheadgames.aboutbox.share; import android.app.Activity; import android.content.Intent; import android.net.Uri; +import android.os.Build; +import android.text.TextUtils; import com.eggheadgames.aboutbox.AboutConfig; -import com.eggheadgames.aboutbox.BuildConfig; +import com.eggheadgames.aboutbox.R; public final class EmailUtil { @@ -18,26 +20,35 @@ public final class EmailUtil { final Uri mailto = Uri.fromParts("mailto", config.emailAddress, null); - final String emailSubject; + String emailBody = config.emailBody; + if (TextUtils.isEmpty(emailBody)) { + String deviceInfo = ""; + deviceInfo += "\n App version: " + config.version; + deviceInfo += "\n Android version: " + Build.VERSION.RELEASE + " (" + android.os.Build.VERSION.SDK_INT + ")"; + deviceInfo += "\n Device: " + android.os.Build.MODEL + " (" + android.os.Build.PRODUCT + ")"; + deviceInfo += "\n Platform: " + platformName(config.buildType); - if ("google".equals(BuildConfig.FLAVOR)) { - emailSubject = config.emailSubject + "G"; - } else if ("amazon".equals(BuildConfig.FLAVOR)) { - emailSubject = config.emailSubject + "K"; - } else { - emailSubject = config.emailSubject; + emailBody = activity.getString(R.string.egab_email_body_prompt) + "\n\n\n\n\n" + + "---------------------------" + deviceInfo; } try { Intent emailIntent = new Intent(Intent.ACTION_SENDTO, mailto); - emailIntent.putExtra(Intent.EXTRA_SUBJECT, emailSubject); - emailIntent.putExtra(Intent.EXTRA_TEXT, config.emailBody); + emailIntent.putExtra(Intent.EXTRA_SUBJECT, config.emailSubject); + emailIntent.putExtra(Intent.EXTRA_TEXT, emailBody); activity.startActivity(Intent.createChooser(emailIntent, "Send email...")); } catch (Exception e) { if (config.analytics != null) { config.analytics.logException(e, false); } } + } + private static String platformName(AboutConfig.BuildType buildType) { + switch (buildType) { + case GOOGLE: return "Google Play"; + case AMAZON: return "Amazon Kindle"; + default: return "Unknown"; + } } } diff --git a/library/src/main/java/com/eggheadgames/aboutbox/share/ShareUtil.java b/library/src/main/java/com/eggheadgames/aboutbox/share/ShareUtil.java index 364c9ab..95c59a9 100644 --- a/library/src/main/java/com/eggheadgames/aboutbox/share/ShareUtil.java +++ b/library/src/main/java/com/eggheadgames/aboutbox/share/ShareUtil.java @@ -1,17 +1,12 @@ package com.eggheadgames.aboutbox.share; import android.app.Activity; +import android.content.Intent; import android.text.TextUtils; +import com.eggheadgames.aboutbox.AboutBoxUtils; import com.eggheadgames.aboutbox.AboutConfig; -import io.branch.indexing.BranchUniversalObject; -import io.branch.referral.Branch; -import io.branch.referral.BranchError; -import io.branch.referral.SharingHelper; -import io.branch.referral.util.LinkProperties; -import io.branch.referral.util.ShareSheetStyle; - public final class ShareUtil { private ShareUtil() { @@ -19,48 +14,29 @@ public final class ShareUtil { } public static void share(Activity activity) { - BranchUniversalObject branchUniversalObject = new BranchUniversalObject(); - final AboutConfig config = AboutConfig.getInstance(); + AboutConfig config = AboutConfig.getInstance(); - ShareSheetStyle shareSheetStyle = new ShareSheetStyle(activity, config.shareMessageTitle, - config.shareMessage) - .setCopyUrlStyle(activity.getResources().getDrawable(android.R.drawable.ic_menu_send), - "Copy", "Added to clipboard") - .setMoreOptionStyle(activity.getResources().getDrawable(android.R.drawable.ic_menu_search), "Show more") - .addPreferredSharingOption(SharingHelper.SHARE_WITH.FACEBOOK) - .addPreferredSharingOption(SharingHelper.SHARE_WITH.EMAIL) - .setSharingTitle(config.sharingTitle); + Intent intent2 = new Intent(); + intent2.setAction(Intent.ACTION_SEND); + intent2.setType("text/plain"); - branchUniversalObject.showShareSheet(activity, - new LinkProperties(), shareSheetStyle, new Branch.BranchLinkShareListener() { - @Override - public void onShareLinkDialogLaunched() { - //nothing - } + String shareMessage = config.shareMessage; - @Override - public void onShareLinkDialogDismissed() { - if (config.analytics != null) { - config.analytics.logUiEvent("Share", "Dismissed"); - } - } + if (!TextUtils.isEmpty(config.packageName) && !TextUtils.isEmpty(shareMessage) && config.buildType != null) { + switch (config.buildType) { + case GOOGLE: + shareMessage = shareMessage + AboutBoxUtils.playStoreAppURI + config.packageName; + break; + case AMAZON: + shareMessage = shareMessage + AboutBoxUtils.amznStoreAppURI + config.packageName; + break; + default: + break; + } + } - @Override - public void onLinkShareResponse(String sharedLink, String sharedChannel, BranchError error) { - if (config.analytics != null) { - if (error == null || TextUtils.isEmpty(error.getMessage())) { - config.analytics.logUiEvent("Share", sharedChannel); - } else { - config.analytics.logUiEvent("Share Failure", error.getMessage()); - } - } - } - - @Override - public void onChannelSelected(String channelName) { - //nothing - } - }); + intent2.putExtra(Intent.EXTRA_TEXT, shareMessage); + activity.startActivity(Intent.createChooser(intent2, config.sharingTitle)); } } diff --git a/library/src/main/res/drawable/ic_acknowledgment.xml b/library/src/main/res/drawable/ic_acknowledgements.xml similarity index 100% rename from library/src/main/res/drawable/ic_acknowledgment.xml rename to library/src/main/res/drawable/ic_acknowledgements.xml diff --git a/library/src/main/res/drawable/ic_help_green.xml b/library/src/main/res/drawable/ic_help_green.xml new file mode 100644 index 0000000..e1e7ce0 --- /dev/null +++ b/library/src/main/res/drawable/ic_help_green.xml @@ -0,0 +1,11 @@ + + + + + \ No newline at end of file diff --git a/library/src/main/res/values-pt/strings.xml b/library/src/main/res/values-pt/strings.xml new file mode 100644 index 0000000..18a0b23 --- /dev/null +++ b/library/src/main/res/values-pt/strings.xml @@ -0,0 +1,26 @@ + + Avaliar + Contactar o Suporte + Experimentar outras aplicações + Versão + Autor + Facebook + Twitter + Web + Acknowledgements + Política de Privacidade + Sobre + Partilhar + Contactos + Avalie + Partilhar + Experimentar outras aplicações + Facebook + Twitter + Website + Privacicidade + Acknowledgements + Tu não tens nenhuma aplicação que possa abrir esta ligação + Digite sua pergunta aqui: + Guia + diff --git a/library/src/main/res/values/strings.xml b/library/src/main/res/values/strings.xml index b2eef7c..894f9ae 100644 --- a/library/src/main/res/values/strings.xml +++ b/library/src/main/res/values/strings.xml @@ -1,25 +1,27 @@ - AboutBox - Leave Review - Contact Support - Try Other Apps - Version - Facebook - Twitter - Web - Acknowledgment - Privacy Policy - About - Share - Contact - Review - Share - Try Other Apps - Facebook - Twitter - Website - Privacy - Acknowledgement - You don\'t have any app that can open this link + Leave Review + Contact Support + Try Other Apps + Version + Author + Facebook + Twitter + Web + Acknowledgements + Privacy Policy + About + Share + Contact + Review + Share + Try Other Apps + Facebook + Twitter + Website + Privacy + Acknowledgements + You don\'t have any app that can open this link + Please type your question here: + Guide diff --git a/library/src/main/res/values/styles.xml b/library/src/main/res/values/styles.xml index 41c850f..d0590ed 100644 --- a/library/src/main/res/values/styles.xml +++ b/library/src/main/res/values/styles.xml @@ -1,7 +1,7 @@ -