mirror of
https://github.com/ethauvin/android-about-box.git
synced 2025-04-25 02:37:11 -07:00
Tried to fix GOD class pmd fail
This commit is contained in:
parent
11f7abc55f
commit
a3ea5e4d90
2 changed files with 108 additions and 95 deletions
|
@ -0,0 +1,97 @@
|
||||||
|
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 {
|
||||||
|
|
||||||
|
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 = "http://play.google.com/store/apps/details?id=" + packageName;
|
||||||
|
break;
|
||||||
|
case AMAZON:
|
||||||
|
appURI = "amzn://apps/android?p=" + packageName;
|
||||||
|
webURI = "http://www.amazon.com/gp/mas/dl/android?p=" + 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:
|
||||||
|
appURI = "market://search?q=pub:" + publisher;
|
||||||
|
webURI = "http://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)));
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,13 +1,10 @@
|
||||||
package com.eggheadgames.aboutbox.activity;
|
package com.eggheadgames.aboutbox.activity;
|
||||||
|
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
import android.content.ActivityNotFoundException;
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.net.Uri;
|
|
||||||
import android.support.annotation.NonNull;
|
import android.support.annotation.NonNull;
|
||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
import android.widget.Toast;
|
|
||||||
|
|
||||||
import com.danielstone.materialaboutlibrary.MaterialAboutActivity;
|
import com.danielstone.materialaboutlibrary.MaterialAboutActivity;
|
||||||
import com.danielstone.materialaboutlibrary.items.MaterialAboutActionItem;
|
import com.danielstone.materialaboutlibrary.items.MaterialAboutActionItem;
|
||||||
|
@ -15,6 +12,7 @@ import com.danielstone.materialaboutlibrary.items.MaterialAboutItemOnClickListen
|
||||||
import com.danielstone.materialaboutlibrary.items.MaterialAboutTitleItem;
|
import com.danielstone.materialaboutlibrary.items.MaterialAboutTitleItem;
|
||||||
import com.danielstone.materialaboutlibrary.model.MaterialAboutCard;
|
import com.danielstone.materialaboutlibrary.model.MaterialAboutCard;
|
||||||
import com.danielstone.materialaboutlibrary.model.MaterialAboutList;
|
import com.danielstone.materialaboutlibrary.model.MaterialAboutList;
|
||||||
|
import com.eggheadgames.aboutbox.AboutBoxUtils;
|
||||||
import com.eggheadgames.aboutbox.AboutConfig;
|
import com.eggheadgames.aboutbox.AboutConfig;
|
||||||
import com.eggheadgames.aboutbox.IAnalytic;
|
import com.eggheadgames.aboutbox.IAnalytic;
|
||||||
import com.eggheadgames.aboutbox.R;
|
import com.eggheadgames.aboutbox.R;
|
||||||
|
@ -69,7 +67,7 @@ public class AboutActivity extends MaterialAboutActivity {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(boolean b) {
|
public void onClick(boolean b) {
|
||||||
if (config.dialog == null) {
|
if (config.dialog == null) {
|
||||||
openHTMLPage(config.guideHtmlPath);
|
AboutBoxUtils.openHTMLPage(AboutActivity.this, config.guideHtmlPath);
|
||||||
} else {
|
} else {
|
||||||
config.dialog.open(AboutActivity.this, config.guideHtmlPath, getString(R.string.egab_guide));
|
config.dialog.open(AboutActivity.this, config.guideHtmlPath, getString(R.string.egab_guide));
|
||||||
}
|
}
|
||||||
|
@ -98,7 +96,7 @@ public class AboutActivity extends MaterialAboutActivity {
|
||||||
new MaterialAboutItemOnClickListener() {
|
new MaterialAboutItemOnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(boolean b) {
|
public void onClick(boolean b) {
|
||||||
openApp(config.buildType, config.packageName);
|
AboutBoxUtils.openApp(AboutActivity.this, config.buildType, config.packageName);
|
||||||
logUIEventName(config.analytics, config.logUiEventName, getString(R.string.egab_review_log_event));
|
logUIEventName(config.analytics, config.logUiEventName, getString(R.string.egab_review_log_event));
|
||||||
}
|
}
|
||||||
}));
|
}));
|
||||||
|
@ -123,7 +121,8 @@ public class AboutActivity extends MaterialAboutActivity {
|
||||||
new MaterialAboutItemOnClickListener() {
|
new MaterialAboutItemOnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(boolean b) {
|
public void onClick(boolean b) {
|
||||||
openPublisher(config.buildType, config.appPublisher, config.packageName);
|
AboutBoxUtils.openPublisher(AboutActivity.this, config.buildType,
|
||||||
|
config.appPublisher, config.packageName);
|
||||||
logUIEventName(config.analytics, config.logUiEventName, getString(R.string.egab_try_other_app_log_event));
|
logUIEventName(config.analytics, config.logUiEventName, getString(R.string.egab_try_other_app_log_event));
|
||||||
}
|
}
|
||||||
}));
|
}));
|
||||||
|
@ -136,7 +135,7 @@ public class AboutActivity extends MaterialAboutActivity {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(boolean b) {
|
public void onClick(boolean b) {
|
||||||
if (config.dialog == null) {
|
if (config.dialog == null) {
|
||||||
openHTMLPage(config.companyHtmlPath);
|
AboutBoxUtils.openHTMLPage(AboutActivity.this, config.companyHtmlPath);
|
||||||
} else {
|
} else {
|
||||||
config.dialog.open(AboutActivity.this, config.companyHtmlPath, config.aboutLabelTitle);
|
config.dialog.open(AboutActivity.this, config.companyHtmlPath, config.aboutLabelTitle);
|
||||||
}
|
}
|
||||||
|
@ -159,7 +158,7 @@ public class AboutActivity extends MaterialAboutActivity {
|
||||||
.setOnClickListener(new MaterialAboutItemOnClickListener() {
|
.setOnClickListener(new MaterialAboutItemOnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(boolean b) {
|
public void onClick(boolean b) {
|
||||||
getOpenFacebookIntent(AboutActivity.this, config.facebookUserName);
|
AboutBoxUtils.getOpenFacebookIntent(AboutActivity.this, config.facebookUserName);
|
||||||
logUIEventName(config.analytics, config.logUiEventName, getString(R.string.egab_facebook_log_event));
|
logUIEventName(config.analytics, config.logUiEventName, getString(R.string.egab_facebook_log_event));
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
@ -173,7 +172,7 @@ public class AboutActivity extends MaterialAboutActivity {
|
||||||
.setOnClickListener(new MaterialAboutItemOnClickListener() {
|
.setOnClickListener(new MaterialAboutItemOnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(boolean b) {
|
public void onClick(boolean b) {
|
||||||
startTwitter(AboutActivity.this, config.twitterUserName);
|
AboutBoxUtils.startTwitter(AboutActivity.this, config.twitterUserName);
|
||||||
logUIEventName(config.analytics, config.logUiEventName, getString(R.string.egab_twitter_log_event));
|
logUIEventName(config.analytics, config.logUiEventName, getString(R.string.egab_twitter_log_event));
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
@ -187,7 +186,7 @@ public class AboutActivity extends MaterialAboutActivity {
|
||||||
.setOnClickListener(new MaterialAboutItemOnClickListener() {
|
.setOnClickListener(new MaterialAboutItemOnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(boolean b) {
|
public void onClick(boolean b) {
|
||||||
openHTMLPage(config.webHomePage);
|
AboutBoxUtils.openHTMLPage(AboutActivity.this, config.webHomePage);
|
||||||
logUIEventName(config.analytics, config.logUiEventName, getString(R.string.egab_website_log_event));
|
logUIEventName(config.analytics, config.logUiEventName, getString(R.string.egab_website_log_event));
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
@ -205,7 +204,7 @@ public class AboutActivity extends MaterialAboutActivity {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(boolean b) {
|
public void onClick(boolean b) {
|
||||||
if (config.dialog == null) {
|
if (config.dialog == null) {
|
||||||
openHTMLPage(config.privacyHtmlPath);
|
AboutBoxUtils.openHTMLPage(AboutActivity.this, config.privacyHtmlPath);
|
||||||
} else {
|
} else {
|
||||||
config.dialog.open(AboutActivity.this, config.privacyHtmlPath, getString(R.string.egab_privacy_policy));
|
config.dialog.open(AboutActivity.this, config.privacyHtmlPath, getString(R.string.egab_privacy_policy));
|
||||||
}
|
}
|
||||||
|
@ -221,7 +220,7 @@ public class AboutActivity extends MaterialAboutActivity {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(boolean b) {
|
public void onClick(boolean b) {
|
||||||
if (config.dialog == null) {
|
if (config.dialog == null) {
|
||||||
openHTMLPage(config.acknowledgmentHtmlPath);
|
AboutBoxUtils.openHTMLPage(AboutActivity.this, config.acknowledgmentHtmlPath);
|
||||||
} else {
|
} else {
|
||||||
config.dialog.open(AboutActivity.this, config.acknowledgmentHtmlPath, getString(R.string.egab_acknowledgements));
|
config.dialog.open(AboutActivity.this, config.acknowledgmentHtmlPath, getString(R.string.egab_acknowledgements));
|
||||||
}
|
}
|
||||||
|
@ -247,89 +246,6 @@ public class AboutActivity extends MaterialAboutActivity {
|
||||||
return getString(R.string.egab_about_screen_title);
|
return getString(R.string.egab_about_screen_title);
|
||||||
}
|
}
|
||||||
|
|
||||||
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 void openApp(AboutConfig.BuildType buildType, String packageName) {
|
|
||||||
String appURI = null;
|
|
||||||
String webURI = null;
|
|
||||||
switch (buildType) {
|
|
||||||
case GOOGLE:
|
|
||||||
appURI = "market://details?id=" + packageName;
|
|
||||||
webURI = "http://play.google.com/store/apps/details?id=" + packageName;
|
|
||||||
break;
|
|
||||||
case AMAZON:
|
|
||||||
appURI = "amzn://apps/android?p=" + packageName;
|
|
||||||
webURI = "http://www.amazon.com/gp/mas/dl/android?p=" + packageName;
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
//nothing
|
|
||||||
}
|
|
||||||
openApplication(appURI, webURI);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void openPublisher(AboutConfig.BuildType buildType, String publisher, String packageName) {
|
|
||||||
String appURI = null;
|
|
||||||
String webURI = null;
|
|
||||||
switch (buildType) {
|
|
||||||
case GOOGLE:
|
|
||||||
appURI = "market://search?q=pub:" + publisher;
|
|
||||||
webURI = "http://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(appURI, webURI);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void openApplication(String appURI, String webURI) {
|
|
||||||
try {
|
|
||||||
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(appURI)));
|
|
||||||
} catch (ActivityNotFoundException e1) {
|
|
||||||
try {
|
|
||||||
openHTMLPage(webURI);
|
|
||||||
} catch (ActivityNotFoundException e2) {
|
|
||||||
Toast.makeText(this, R.string.egab_can_not_open, Toast.LENGTH_SHORT).show();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void openHTMLPage(String htmlPath) {
|
|
||||||
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(htmlPath)));
|
|
||||||
}
|
|
||||||
|
|
||||||
private void logUIEventName(IAnalytic analytics, String eventType, String eventValue) {
|
private void logUIEventName(IAnalytic analytics, String eventType, String eventValue) {
|
||||||
if (analytics != null) {
|
if (analytics != null) {
|
||||||
analytics.logUiEvent(eventType, eventValue);
|
analytics.logUiEvent(eventType, eventValue);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue