diff --git a/library/src/androidTest/java/com/vorlonsoft/android/rate/UriHelperTest.java b/library/src/androidTest/java/com/vorlonsoft/android/rate/UriHelperTest.java index 65771d7..f6b5677 100644 --- a/library/src/androidTest/java/com/vorlonsoft/android/rate/UriHelperTest.java +++ b/library/src/androidTest/java/com/vorlonsoft/android/rate/UriHelperTest.java @@ -24,6 +24,7 @@ * @author Shintaro Katafuchi */ +@SuppressWarnings("unused") public class UriHelperTest { private static final String CHINESE_STORES = "market://details?id="; diff --git a/library/src/main/java/com/vorlonsoft/android/rate/AppCompatDialogManager.java b/library/src/main/java/com/vorlonsoft/android/rate/AppCompatDialogManager.java index 0208b13..903a305 100644 --- a/library/src/main/java/com/vorlonsoft/android/rate/AppCompatDialogManager.java +++ b/library/src/main/java/com/vorlonsoft/android/rate/AppCompatDialogManager.java @@ -37,6 +37,7 @@ */ public class AppCompatDialogManager extends DefaultDialogManager implements DialogManager { + /**

The WeakReference to the {@link AppCompatDialogManager} singleton object.

*/ private static volatile WeakReference singleton = null; @SuppressWarnings("WeakerAccess") diff --git a/library/src/main/java/com/vorlonsoft/android/rate/AppInformation.java b/library/src/main/java/com/vorlonsoft/android/rate/AppInformation.java index 219a990..ff61738 100644 --- a/library/src/main/java/com/vorlonsoft/android/rate/AppInformation.java +++ b/library/src/main/java/com/vorlonsoft/android/rate/AppInformation.java @@ -106,7 +106,7 @@ static AppInformation getInstance(@NonNull final Context context) { * @see #getAppVersionCodeMajor() * @see #getAppLongVersionCode() */ - @SuppressWarnings({"WeakerAccess", "JavadocReference"}) + @SuppressWarnings({"WeakerAccess", "JavadocReference", "unused"}) int getAppVersionCode() { return (int) (appLongVersionCode & 0b11111111111111111111111111111111L); } @@ -119,7 +119,7 @@ int getAppVersionCode() { * @see #getAppVersionCode() * @see #getAppLongVersionCode() */ - @SuppressWarnings({"WeakerAccess", "JavadocReference"}) + @SuppressWarnings({"WeakerAccess", "JavadocReference", "unused"}) int getAppVersionCodeMajor() { return (int) (appLongVersionCode >>> 32); } @@ -166,6 +166,7 @@ String getAppVersionName() { * @return the image of the icon, or the default application icon if it could not be found. * Returns null if the resources for the application could not be loaded. */ + @SuppressWarnings("unused") @Nullable Drawable getAppIcon() { return appIcon; diff --git a/library/src/main/java/com/vorlonsoft/android/rate/AppRate.java b/library/src/main/java/com/vorlonsoft/android/rate/AppRate.java index ac0ffd4..4c8a70c 100644 --- a/library/src/main/java/com/vorlonsoft/android/rate/AppRate.java +++ b/library/src/main/java/com/vorlonsoft/android/rate/AppRate.java @@ -177,7 +177,7 @@ public AppRate setLaunchTimes(@SuppressWarnings("SameParameterValue") byte appLa * @return the {@link AppRate} singleton object * @see #setTimeToWait(long, short) */ - @SuppressWarnings("WeakerAccess") + @SuppressWarnings({"WeakerAccess", "unused"}) public AppRate setInstallDays(byte installDate) { return setTimeToWait(Time.DAY, installDate); } @@ -208,6 +208,7 @@ public AppRate setTimeToWait(@Time.TimeUnits long timeUnit, short timeUnitsNumbe * @return the {@link AppRate} singleton object * @see #setRemindTimeToWait(long, short) */ + @SuppressWarnings({"WeakerAccess", "unused"}) public AppRate setRemindInterval(byte remindInterval) { return setRemindTimeToWait(Time.DAY, remindInterval); } diff --git a/library/src/main/java/com/vorlonsoft/android/rate/DefaultDialogManager.java b/library/src/main/java/com/vorlonsoft/android/rate/DefaultDialogManager.java index 085be39..88ce7d5 100644 --- a/library/src/main/java/com/vorlonsoft/android/rate/DefaultDialogManager.java +++ b/library/src/main/java/com/vorlonsoft/android/rate/DefaultDialogManager.java @@ -63,56 +63,50 @@ */ public class DefaultDialogManager implements DialogManager { + /**

The WeakReference to the {@link DefaultDialogManager} singleton object.

*/ private static volatile WeakReference singleton = null; private final StoreOptions storeOptions; private final OnClickButtonListener listener; @SuppressWarnings("WeakerAccess") protected final DialogOptions dialogOptions; + @SuppressWarnings({"WeakerAccess", "UnusedAssignment"}) protected Context context = null; @SuppressWarnings("WeakerAccess") - protected final DialogInterface.OnShowListener showListener = new DialogInterface.OnShowListener() { - @Override - public void onShow(DialogInterface dialog) { - if (getDialogFirstLaunchTime(context) == 0L) { - setDialogFirstLaunchTime(context); - } - increment365DayPeriodDialogLaunchTimes(context); - if (isLollipop()) { - try { - final Button positiveButton = ((AlertDialog) dialog).getButton(AlertDialog.BUTTON_POSITIVE); - if (positiveButton != null) { - final LinearLayout linearLayout = (LinearLayout) positiveButton.getParent(); - if ((linearLayout != null) && (positiveButton.getLeft() + positiveButton.getWidth() > linearLayout.getWidth())) { - final Button neutralButton = ((AlertDialog) dialog).getButton(AlertDialog.BUTTON_NEUTRAL); - final Button negativeButton = ((AlertDialog) dialog).getButton(AlertDialog.BUTTON_NEGATIVE); - linearLayout.setOrientation(LinearLayout.VERTICAL); - linearLayout.setGravity(Gravity.END); - if (neutralButton != null) { - linearLayout.removeView(neutralButton); - if (negativeButton != null) { - linearLayout.removeView(negativeButton); - linearLayout.addView(negativeButton); - } - linearLayout.addView(neutralButton); - } else if (negativeButton != null) { + protected final DialogInterface.OnShowListener showListener = dialog -> { + if (getDialogFirstLaunchTime(context) == 0L) { + setDialogFirstLaunchTime(context); + } + increment365DayPeriodDialogLaunchTimes(context); + if (isLollipop()) { + try { + final Button positiveButton = ((AlertDialog) dialog).getButton(AlertDialog.BUTTON_POSITIVE); + if (positiveButton != null) { + final LinearLayout linearLayout = (LinearLayout) positiveButton.getParent(); + if ((linearLayout != null) && (positiveButton.getLeft() + positiveButton.getWidth() > linearLayout.getWidth())) { + final Button neutralButton = ((AlertDialog) dialog).getButton(AlertDialog.BUTTON_NEUTRAL); + final Button negativeButton = ((AlertDialog) dialog).getButton(AlertDialog.BUTTON_NEGATIVE); + linearLayout.setOrientation(LinearLayout.VERTICAL); + linearLayout.setGravity(Gravity.END); + if (neutralButton != null) { + linearLayout.removeView(neutralButton); + if (negativeButton != null) { linearLayout.removeView(negativeButton); linearLayout.addView(negativeButton); } + linearLayout.addView(neutralButton); + } else if (negativeButton != null) { + linearLayout.removeView(negativeButton); + linearLayout.addView(negativeButton); } } - } catch (Exception e) { - Log.i(TAG, "Positive button may not fits in the window, can't change layout orientation to vertical"); } + } catch (Exception e) { + Log.i(TAG, "Positive button may not fits in the window, can't change layout orientation to vertical"); } } }; @SuppressWarnings("WeakerAccess") - protected final DialogInterface.OnDismissListener dismissListener = new DialogInterface.OnDismissListener() { - @Override - public void onDismiss(DialogInterface dialog) { - AppRate.with(context).clearRateDialog(); - } - }; + protected final DialogInterface.OnDismissListener dismissListener = dialog -> AppRate.with(context).clearRateDialog(); @SuppressWarnings("WeakerAccess") protected final DialogInterface.OnClickListener positiveListener = new DialogInterface.OnClickListener() { @Override @@ -228,6 +222,7 @@ protected DefaultDialogManager(final Context context, final DialogOptions dialog this.listener = dialogOptions.getListener(); } + @SuppressWarnings("WeakerAccess") protected void setContext(Context context){ this.context = context; } diff --git a/library/src/main/java/com/vorlonsoft/android/rate/DialogOptions.java b/library/src/main/java/com/vorlonsoft/android/rate/DialogOptions.java index 4ddca80..438bc60 100644 --- a/library/src/main/java/com/vorlonsoft/android/rate/DialogOptions.java +++ b/library/src/main/java/com/vorlonsoft/android/rate/DialogOptions.java @@ -61,6 +61,7 @@ public final class DialogOptions { DialogOptions() { } + @SuppressWarnings("WeakerAccess") public boolean shouldShowNeutralButton() { return showNeutralButton; } @@ -69,6 +70,7 @@ void setShowNeutralButton(boolean showNeutralButton) { this.showNeutralButton = showNeutralButton; } + @SuppressWarnings("WeakerAccess") public boolean shouldShowNegativeButton() { return showNegativeButton; } @@ -77,6 +79,7 @@ void setShowNegativeButton(boolean showNegativeButton) { this.showNegativeButton = showNegativeButton; } + @SuppressWarnings("WeakerAccess") public boolean shouldShowTitle() { return showTitle; } @@ -85,6 +88,7 @@ void setShowTitle(boolean showTitle) { this.showTitle = showTitle; } + @SuppressWarnings("WeakerAccess") public boolean getCancelable() { return cancelable; } @@ -155,6 +159,7 @@ void setListener(OnClickButtonListener listener) { this.listener = new SoftReference<>(listener); } + @SuppressWarnings("WeakerAccess") public String getTitleText(Context context) { if (titleText == null) { return context.getString(textTitleResId); @@ -166,6 +171,7 @@ void setTitleText(String titleText) { this.titleText = titleText; } + @SuppressWarnings("WeakerAccess") public String getMessageText(Context context) { if (messageText == null) { return context.getString(textMessageResId); @@ -177,6 +183,7 @@ void setMessageText(String messageText) { this.messageText = messageText; } + @SuppressWarnings("WeakerAccess") public String getPositiveText(Context context) { if (positiveText == null) { return context.getString(textPositiveResId); @@ -188,6 +195,7 @@ void setPositiveText(String positiveText) { this.positiveText = positiveText; } + @SuppressWarnings("WeakerAccess") public String getNeutralText(Context context) { if (neutralText == null) { return context.getString(textNeutralResId); @@ -199,6 +207,7 @@ void setNeutralText(String neutralText) { this.neutralText = neutralText; } + @SuppressWarnings("WeakerAccess") public String getNegativeText(Context context) { if (negativeText == null) { return context.getString(textNegativeResId); @@ -210,6 +219,7 @@ void setNegativeText(String negativeText) { this.negativeText = negativeText; } + @SuppressWarnings("WeakerAccess") public int getThemeResId() { return themeResId; } diff --git a/library/src/main/java/com/vorlonsoft/android/rate/DialogType.java b/library/src/main/java/com/vorlonsoft/android/rate/DialogType.java index b9141f2..27d0928 100644 --- a/library/src/main/java/com/vorlonsoft/android/rate/DialogType.java +++ b/library/src/main/java/com/vorlonsoft/android/rate/DialogType.java @@ -21,15 +21,13 @@ * @author Alexander Savin */ +@SuppressWarnings({"WeakerAccess", "unused"}) public class DialogType { /** Apple Rate Dialog */ - @SuppressWarnings("WeakerAccess") public static final int APPLE = 0; /** Classic Rate Dialog */ - @SuppressWarnings("WeakerAccess") public static final int CLASSIC = 1; /** Modern Rate Dialog */ - @SuppressWarnings("WeakerAccess") public static final int MODERN = 2; private DialogType() { @@ -41,7 +39,6 @@ private DialogType() { *

Annotated element, represents a logical type and its value should be one of the following * constants: APPLE, CLASSIC, MODERN.

*/ - @SuppressWarnings("WeakerAccess") @Documented @Retention(SOURCE) @IntDef({ diff --git a/library/src/main/java/com/vorlonsoft/android/rate/PreferenceHelper.java b/library/src/main/java/com/vorlonsoft/android/rate/PreferenceHelper.java index 6be3c7d..36ecc31 100644 --- a/library/src/main/java/com/vorlonsoft/android/rate/PreferenceHelper.java +++ b/library/src/main/java/com/vorlonsoft/android/rate/PreferenceHelper.java @@ -116,7 +116,7 @@ static void increment365DayPeriodDialogLaunchTimes(final Context context) { currentDay = (short) (currentDay % YEAR_IN_DAYS); } - if (currentDialogLaunchTimes.matches("(.*):" + currentDay + "y" + currentYear + "-[0-9][0-9]*:")) { + if (currentDialogLaunchTimes != null && currentDialogLaunchTimes.matches("(.*):" + currentDay + "y" + currentYear + "-[0-9][0-9]*:")) { final short length = (short) currentDialogLaunchTimes.length(); String currentDayCount = "" + currentDialogLaunchTimes.charAt(length - 2); for (short s = (short) (length - 3); s > 0; s--) { @@ -137,7 +137,7 @@ static short get365DayPeriodDialogLaunchTimes(final Context context) { final byte currentYear = (byte) (currentDay / YEAR_IN_DAYS); String dialogLaunchTimes = getPreferences(context).getString(PREF_KEY_365_DAY_PERIOD_DIALOG_LAUNCH_TIMES, ":0y0-0:"); - dialogLaunchTimes = dialogLaunchTimes.replaceAll(":[0-9][0-9]*" + "y" + currentYear + "-", ":"); + dialogLaunchTimes = dialogLaunchTimes != null ? dialogLaunchTimes.replaceAll(":[0-9][0-9]*" + "y" + currentYear + "-", ":") : ":0y0-0:"; if (currentYear > 0) { currentDay = (short) (currentDay % YEAR_IN_DAYS); for (short s = currentDay; s < YEAR_IN_DAYS; s++) { diff --git a/library/src/main/java/com/vorlonsoft/android/rate/StoreType.java b/library/src/main/java/com/vorlonsoft/android/rate/StoreType.java index 7fe5a35..12bb862 100644 --- a/library/src/main/java/com/vorlonsoft/android/rate/StoreType.java +++ b/library/src/main/java/com/vorlonsoft/android/rate/StoreType.java @@ -22,45 +22,33 @@ * @author Shintaro Katafuchi */ +@SuppressWarnings("WeakerAccess") public class StoreType { /** Amazon Appstore */ - @SuppressWarnings("WeakerAccess") public static final int AMAZON = 0; /** Apple App Store */ - @SuppressWarnings("WeakerAccess") public static final int APPLE = 1; /** Cafe Bazaar */ - @SuppressWarnings("WeakerAccess") public static final int BAZAAR = 2; /** BlackBerry World */ - @SuppressWarnings("WeakerAccess") public static final int BLACKBERRY = 3; /** 19 chinese app stores */ - @SuppressWarnings("WeakerAccess") public static final int CHINESESTORES = 4; /** Google Play */ - @SuppressWarnings("WeakerAccess") public static final int GOOGLEPLAY = 5; /** Mi Appstore (Xiaomi Market) */ - @SuppressWarnings("WeakerAccess") public static final int MI = 6; /** Samsung Galaxy Apps */ - @SuppressWarnings("WeakerAccess") public static final int SAMSUNG = 7; /** SlideME Marketplace */ - @SuppressWarnings("WeakerAccess") public static final int SLIDEME = 8; /** Tencent App Store */ - @SuppressWarnings("WeakerAccess") public static final int TENCENT = 9; /** Yandex.Store */ - @SuppressWarnings("WeakerAccess") public static final int YANDEX = 10; /** Any custom intents */ - @SuppressWarnings("WeakerAccess") public static final int INTENT = 11; /** Any other Store */ - @SuppressWarnings("WeakerAccess") public static final int OTHER = 12; private StoreType() { @@ -73,7 +61,6 @@ private StoreType() { * constants: AMAZON, BAZAAR, CHINESESTORES, GOOGLEPLAY, MI, SAMSUNG, SLIDEME, TENCENT, * YANDEX.

*/ - @SuppressWarnings("WeakerAccess") @Documented @Retention(SOURCE) @IntDef({ @@ -95,7 +82,6 @@ private StoreType() { *

Annotated element, represents a logical type and its value should be one of the following * constants: APPLE, BLACKBERRY.

*/ - @SuppressWarnings("WeakerAccess") @Documented @Retention(SOURCE) @IntDef({ @@ -111,7 +97,6 @@ private StoreType() { * constants: AMAZON, APPLE, BAZAAR, BLACKBERRY, CHINESESTORES, GOOGLEPLAY, INTENT, MI, OTHER, * SAMSUNG, SLIDEME, TENCENT, YANDEX.

*/ - @SuppressWarnings("WeakerAccess") @Documented @Retention(SOURCE) @IntDef({ diff --git a/sample/src/main/java/com/vorlonsoft/android/rate/sample/MainActivity.java b/sample/src/main/java/com/vorlonsoft/android/rate/sample/MainActivity.java index 5d356bd..1a56f96 100644 --- a/sample/src/main/java/com/vorlonsoft/android/rate/sample/MainActivity.java +++ b/sample/src/main/java/com/vorlonsoft/android/rate/sample/MainActivity.java @@ -60,27 +60,27 @@ protected void onCreate(Bundle savedInstanceState) { /* uncomment to test other locales - end */ /* comment if you don't want to test AppCompatDialogManager instead DefaultDialogManager */ - DialogManager.Factory appCompatDialogManagerFactory = new AppCompatDialogManager.Factory(); + @SuppressWarnings("unused") DialogManager.Factory appCompatDialogManagerFactory = new AppCompatDialogManager.Factory(); AppRate.with(this) - .setStoreType(StoreType.GOOGLEPLAY) /* default is GOOGLEPLAY (Google Play), other options are AMAZON (Amazon Appstore), BAZAAR (Cafe Bazaar), - * CHINESESTORES (19 chinese app stores), MI (Mi Appstore (Xiaomi Market)), SAMSUNG (Samsung Galaxy Apps), - * SLIDEME (SlideME Marketplace), TENCENT (Tencent App Store), YANDEX (Yandex.Store), - * setStoreType(BLACKBERRY, long) (BlackBerry World, long - your application ID), - * setStoreType(APPLE, long) (Apple App Store, long - your application ID), - * setStoreType(String...) (Any other store/stores, String... - an URI or array of URIs to your app) and - * setStoreType(Intent...) (Any custom intent/intents, Intent... - an intent or array of intents) */ - .setTimeToWait(Time.DAY, (short) 3) // default is 10 days, 0 means install millisecond, 10 means app is launched 10 or more time units later than installation - .setLaunchTimes((byte) 10) // default is 10, 3 means app is launched 3 or more times + .setStoreType(StoreType.GOOGLEPLAY) /* default is GOOGLEPLAY (Google Play), other options are AMAZON (Amazon Appstore), BAZAAR (Cafe Bazaar), + * CHINESESTORES (19 chinese app stores), MI (Mi Appstore (Xiaomi Market)), SAMSUNG (Samsung Galaxy Apps), + * SLIDEME (SlideME Marketplace), TENCENT (Tencent App Store), YANDEX (Yandex.Store), + * setStoreType(BLACKBERRY, long) (BlackBerry World, long - your application ID), + * setStoreType(APPLE, long) (Apple App Store, long - your application ID), + * setStoreType(String...) (Any other store/stores, String... - an URI or array of URIs to your app) and + * setStoreType(Intent...) (Any custom intent/intents, Intent... - an intent or array of intents) */ + .setTimeToWait(Time.DAY, (short) 3) // default is 10 days, 0 means install millisecond, 10 means app is launched 10 or more time units later than installation + .setLaunchTimes((byte) 10) // default is 10, 3 means app is launched 3 or more times .setRemindTimeToWait(Time.DAY, (short) 2) // default is 1 day, 1 means app is launched 1 or more time units after neutral button clicked - .setRemindLaunchesNumber((byte) 1) // default is 0, 1 means app is launched 1 or more times after neutral button clicked - .setSelectedAppLaunches((byte) 4) // default is 1, 1 means each launch, 2 means every 2nd launch, 3 means every 3rd launch, etc - .setShowLaterButton(true) // default is true, true means to show the Neutral button ("Remind me later"). + .setRemindLaunchesNumber((byte) 1) // default is 0, 1 means app is launched 1 or more times after neutral button clicked + .setSelectedAppLaunches((byte) 4) // default is 1, 1 means each launch, 2 means every 2nd launch, 3 means every 3rd launch, etc + .setShowLaterButton(true) // default is true, true means to show the Neutral button ("Remind me later"). .set365DayPeriodMaxNumberDialogLaunchTimes((short) 3) // default is unlimited, 3 means 3 or less occurrences of the display of the Rate Dialog within a 365-day period - .setVersionCodeCheck(true) // default is false, true means to re-enable the Rate Dialog if a new version of app with different version code is installed - .setVersionNameCheck(true) // default is false, true means to re-enable the Rate Dialog if a new version of app with different version name is installed - .setDebug(true) // default is false, true is for development only, true ensures that the Rate Dialog will be shown each time the app is launched - .setCancelable(false) // default false. + .setVersionCodeCheck(true) // default is false, true means to re-enable the Rate Dialog if a new version of app with different version code is installed + .setVersionNameCheck(true) // default is false, true means to re-enable the Rate Dialog if a new version of app with different version name is installed + .setDebug(true) // default is false, true is for development only, true ensures that the Rate Dialog will be shown each time the app is launched + .setCancelable(false) // default false. .setOnClickButtonListener(which -> Log.d(TAG, "RateButton: " + Byte.toString(which))) /* uncomment to test AppCompatDialogManager instead DefaultDialogManager */ //.setDialogManagerFactory(appCompatDialogManagerFactory) diff --git a/sample/src/main/java/com/vorlonsoft/android/rate/sample/SampleApplication.java b/sample/src/main/java/com/vorlonsoft/android/rate/sample/SampleApplication.java index 5464bb0..0650494 100644 --- a/sample/src/main/java/com/vorlonsoft/android/rate/sample/SampleApplication.java +++ b/sample/src/main/java/com/vorlonsoft/android/rate/sample/SampleApplication.java @@ -21,11 +21,13 @@ public SampleApplication() { @Override public void onCreate() { super.onCreate(); + //noinspection ConstantConditions if (LeakCanary.isInAnalyzerProcess(this)) { // This process is dedicated to LeakCanary for heap analysis. // You should not init your app in this process. return; } + //noinspection ResultOfMethodCallIgnored LeakCanary.install(this); // Normal app init code... }