1
0
Fork 0
mirror of https://github.com/ethauvin/android-about-box.git synced 2025-04-26 02:57:12 -07:00

Added AboutBox library source code. Implemented IAnalytic and IDialog interfaces for custom usage.

This commit is contained in:
Alex Dibrivnyi 2017-02-05 20:27:38 +02:00
parent 8a88eb2217
commit 8b28ebfb79
56 changed files with 1296 additions and 0 deletions

View file

@ -0,0 +1,49 @@
package com.eggheadgames.aboutbox;
import android.content.Context;
public class AboutConfig {
public enum BuildType {AMAZON, GOOGLE}
private static AboutConfig aboutConfig;
public static AboutConfig getInstance() {
if (aboutConfig == null) {
aboutConfig = new AboutConfig();
}
return aboutConfig;
}
// general info
public String appName;
public int appIcon;
public String version;
public String aboutLabelTitle;
public String logUiEventName;
public String facebookUserName;
public String twitterUserName;
public String webHomePage;
public String appPublisher;
public String companyHtmlPath;
public String privacyHtmlPath;
public String acknowledgmentHtmlPath;
public BuildType buildType;
public Context context;
// custom analytics and dialog
public IAnalytic analytics;
public IDialog dialog;
// email
public String emailAddress;
public String emailSubject;
public String emailBody;
// share
public String shareMessageTitle;
public String shareMessage;
public String sharingTitle;
}

View file

@ -0,0 +1,8 @@
package com.eggheadgames.aboutbox;
public interface IAnalytic {
void logUiEvent(String action, String label);
void logException(Exception e, boolean fatal);
}

View file

@ -0,0 +1,7 @@
package com.eggheadgames.aboutbox;
import android.support.v7.app.AppCompatActivity;
public interface IDialog {
void open(AppCompatActivity activity, String url, String tag);
}

View file

@ -0,0 +1,270 @@
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 com.danielstone.materialaboutlibrary.MaterialAboutActivity;
import com.danielstone.materialaboutlibrary.model.MaterialAboutActionItem;
import com.danielstone.materialaboutlibrary.model.MaterialAboutCard;
import com.danielstone.materialaboutlibrary.model.MaterialAboutList;
import com.danielstone.materialaboutlibrary.model.MaterialAboutTitleItem;
import com.eggheadgames.aboutbox.AboutConfig;
import com.eggheadgames.aboutbox.R;
import com.eggheadgames.aboutbox.share.EmailUtil;
import com.eggheadgames.aboutbox.share.ShareUtil;
public class AboutActivity extends MaterialAboutActivity {
public static void launch(Activity activity) {
Intent intent = new Intent(activity, AboutActivity.class);
activity.startActivity(intent);
}
@Override
protected MaterialAboutList getMaterialAboutList(Context context) {
final AboutConfig config = AboutConfig.getInstance();
MaterialAboutCard.Builder generalInfoCardBuilder = new MaterialAboutCard.Builder();
generalInfoCardBuilder.addItem(new MaterialAboutTitleItem.Builder()
.text(config.appName)
.icon(config.appIcon)
.build());
generalInfoCardBuilder.addItem(new MaterialAboutActionItem.Builder()
.text(R.string.version)
.subText(config.version)
.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() {
@Override
public void onClick() {
EmailUtil.contactUs(AboutActivity.this);
if (config.analytics != null) {
config.analytics.logUiEvent(config.logUiEventName, "Contact");
}
}
})
.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() {
@Override
public void onClick() {
openApp(config.context.getPackageName(), config.buildType == AboutConfig.BuildType.GOOGLE);
if (config.analytics != null) {
config.analytics.logUiEvent(config.logUiEventName, "Review");
}
}
})
.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, "Share");
}
}
})
.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, "Try Other Apps");
}
}
})
.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)));
} else {
config.dialog.open(AboutActivity.this, config.companyHtmlPath, config.aboutLabelTitle);
}
if (config.analytics != null) {
config.analytics.logUiEvent(config.logUiEventName, config.aboutLabelTitle);
}
}
})
.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, "Facebook");
}
}
})
.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, "Twitter");
}
}
})
.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, "Website");
}
}
})
.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));
}
if (config.analytics != null) {
config.analytics.logUiEvent(config.logUiEventName, "Privacy");
}
}
})
.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));
}
if (config.analytics != null) {
config.analytics.logUiEvent(config.logUiEventName, "Acknowlegement");
}
}
})
.build());
return new MaterialAboutList.Builder()
.addCard(generalInfoCardBuilder.build())
.addCard(supportCardBuilder.build())
.addCard(shareCardBuilder.build())
.addCard(aboutCardBuilder.build())
.addCard(socialNetworksCardBuilder.build())
.addCard(privacyCardBuilder.build())
.build();
}
@Override
protected CharSequence getActivityTitle() {
return getString(R.string.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, "You don't have any app that can open this link", 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, "You don't have any app that can open this link", Toast.LENGTH_SHORT).show();
}
}
}
}

View file

@ -0,0 +1,43 @@
package com.eggheadgames.aboutbox.share;
import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import com.eggheadgames.aboutbox.AboutConfig;
import com.eggheadgames.aboutbox.BuildConfig;
public final class EmailUtil {
private EmailUtil() {
// Utility class
}
public static void contactUs(Activity activity) {
AboutConfig config = AboutConfig.getInstance();
final Uri mailto = Uri.fromParts("mailto", config.emailAddress, null);
final String emailSubject;
if ("google".equals(BuildConfig.FLAVOR)) {
emailSubject = config.emailSubject + "G";
} else if ("amazon".equals(BuildConfig.FLAVOR)) {
emailSubject = config.emailSubject + "K";
} else {
emailSubject = config.emailSubject;
}
try {
Intent emailIntent = new Intent(Intent.ACTION_SENDTO, mailto);
emailIntent.putExtra(Intent.EXTRA_SUBJECT, emailSubject);
emailIntent.putExtra(Intent.EXTRA_TEXT, config.emailBody);
activity.startActivity(Intent.createChooser(emailIntent, "Send email..."));
} catch (Exception e) {
if (config.analytics != null) {
config.analytics.logException(e, false);
}
}
}
}

View file

@ -0,0 +1,66 @@
package com.eggheadgames.aboutbox.share;
import android.app.Activity;
import android.text.TextUtils;
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() {
// Utility class
}
public static void share(Activity activity) {
BranchUniversalObject branchUniversalObject = new BranchUniversalObject();
final 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);
branchUniversalObject.showShareSheet(activity,
new LinkProperties(), shareSheetStyle, new Branch.BranchLinkShareListener() {
@Override
public void onShareLinkDialogLaunched() {
//nothing
}
@Override
public void onShareLinkDialogDismissed() {
if (config.analytics != null) {
config.analytics.logUiEvent("Share", "Dismissed");
}
}
@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
}
});
}
}