From 8db345331662e4c96489aaa07d004e0d14027a74 Mon Sep 17 00:00:00 2001 From: Sundeep Date: Thu, 18 Jan 2018 15:39:51 +0100 Subject: [PATCH] https://github.com/rampo/UpdateChecker/issues/130 Gave option to change theme of UpdateChecker dialog --- .../rampo/updatechecker/UpdateChecker.java | 19 ++++++++++++++++++- .../rampo/updatechecker/notice/Dialog.java | 7 +++++-- 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/library/src/main/java/com/rampo/updatechecker/UpdateChecker.java b/library/src/main/java/com/rampo/updatechecker/UpdateChecker.java index 60b8668..73e00b8 100644 --- a/library/src/main/java/com/rampo/updatechecker/UpdateChecker.java +++ b/library/src/main/java/com/rampo/updatechecker/UpdateChecker.java @@ -39,6 +39,7 @@ public class UpdateChecker implements ASyncCheckResult, UpdateCheckerResult { static Store DEFAULT_STORE = Store.GOOGLE_PLAY; static int DEFAULT_SUCCESSFUL_CHECKS_REQUIRED = 5; static int DEFAULT_NOTICE_ICON_RES_ID = 0; + static int DEFAULT_DIALOG_STYLE_RES_ID = R.style.Theme_AppCompat_Dialog; static Notice DEFAULT_NOTICE = Notice.DIALOG; static Activity mActivity; @@ -46,6 +47,7 @@ public class UpdateChecker implements ASyncCheckResult, UpdateCheckerResult { static int mSuccessfulChecksRequired; static Notice mNotice; static int mNoticeIconResId; + static int mDialogStyleResId; static UpdateCheckerResult mLibraryResultCallaback; static ASyncCheckResult mCheckResultCallback; static boolean mCustomImplementation; @@ -56,6 +58,7 @@ public UpdateChecker(Activity activity) { mSuccessfulChecksRequired = DEFAULT_SUCCESSFUL_CHECKS_REQUIRED; mNotice = DEFAULT_NOTICE; mNoticeIconResId = DEFAULT_NOTICE_ICON_RES_ID; + mDialogStyleResId = DEFAULT_DIALOG_STYLE_RES_ID; mCheckResultCallback = this; mLibraryResultCallaback = this; mCustomImplementation = false; @@ -121,6 +124,20 @@ public static void setNoticeIcon(int noticeIconResId) { } } + /** + * Set the Dialog style. If you don't call this, the Dialog will have the default style. + * + * @param dialogStyleResId Res Id of the dialog style to be set. + * @see com.rampo.updatechecker.notice.Notification + * @see com.rampo.updatechecker.notice.Dialog + */ + public static void setDialogStyle(int dialogStyleResId) { + mDialogStyleResId = dialogStyleResId; + if (mCustomImplementation) { + throw new IllegalStateException("You can't set the notice Icon when you choose a custom implementation.\nThe Notice is controlled manually by you with the callbacks.\nTo call setNotice() use the UpdateChecker constructor with one argument."); + } + } + /** * Start the process */ @@ -286,7 +303,7 @@ private void saveNumberOfChecksForUpdatedVersion(String versionDownloadable, int * Show Dialog */ public void showDialog(String versionDownloadable) { - Dialog.show(mActivity, mStore, versionDownloadable, mNoticeIconResId); + Dialog.show(mActivity, mStore, versionDownloadable, mNoticeIconResId, mDialogStyleResId); } /** diff --git a/library/src/main/java/com/rampo/updatechecker/notice/Dialog.java b/library/src/main/java/com/rampo/updatechecker/notice/Dialog.java index 810552a..183b6b8 100644 --- a/library/src/main/java/com/rampo/updatechecker/notice/Dialog.java +++ b/library/src/main/java/com/rampo/updatechecker/notice/Dialog.java @@ -16,6 +16,7 @@ */ package com.rampo.updatechecker.notice; +import android.annotation.SuppressLint; import android.app.AlertDialog; import android.content.Context; import android.content.DialogInterface; @@ -23,6 +24,7 @@ import android.content.SharedPreferences; import android.content.pm.PackageManager; import android.net.Uri; +import android.support.v7.view.ContextThemeWrapper; import android.view.WindowManager; import com.rampo.updatechecker.R; @@ -38,7 +40,7 @@ */ public class Dialog { - public static void show(final Context context, final Store store, final String versionDownloadable, final int dialogIconResId) { + public static void show(final Context context, final Store store, final String versionDownloadable, final int dialogIconResId, final int dialogStyleResId) { try { String storeName = null; if (store == Store.GOOGLE_PLAY) { @@ -46,7 +48,8 @@ public static void show(final Context context, final Store store, final String v } else if (store == Store.AMAZON) { storeName = context.getString(R.string.amazonStore); } - AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(context); + @SuppressLint("RestrictedApi") + AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(new ContextThemeWrapper(context, dialogStyleResId)); String appName = null; try { appName = (String) context.getPackageManager().getApplicationLabel(context.getPackageManager().getApplicationInfo(context.getPackageName(), 0));