From 38da532f3935949afe4f5e14ca72038b0056f774 Mon Sep 17 00:00:00 2001 From: Shintaro Katafuchi Date: Sun, 28 Jun 2015 19:03:27 +0900 Subject: [PATCH] Fix the bug that button text overflow when the device is over lollipop. --- .../hotchemi/android/rate/DialogManager.java | 16 ++++----- .../java/hotchemi/android/rate/Utils.java | 34 +++++++++++++++++++ library/src/main/res/values-v21/themes.xml | 26 ++++++++++++++ 3 files changed, 67 insertions(+), 9 deletions(-) create mode 100644 library/src/main/java/hotchemi/android/rate/Utils.java create mode 100644 library/src/main/res/values-v21/themes.xml diff --git a/library/src/main/java/hotchemi/android/rate/DialogManager.java b/library/src/main/java/hotchemi/android/rate/DialogManager.java index 98e4a62..6999e09 100644 --- a/library/src/main/java/hotchemi/android/rate/DialogManager.java +++ b/library/src/main/java/hotchemi/android/rate/DialogManager.java @@ -1,25 +1,29 @@ package hotchemi.android.rate; +import android.annotation.TargetApi; import android.app.AlertDialog; import android.app.Dialog; import android.content.Context; import android.content.DialogInterface; +import android.os.Build; import android.view.View; -import android.view.Window; import static hotchemi.android.rate.IntentHelper.createIntentForGooglePlay; import static hotchemi.android.rate.PreferenceHelper.setAgreeShowDialog; import static hotchemi.android.rate.PreferenceHelper.setRemindInterval; +import static hotchemi.android.rate.Utils.getDialogBuilder; final class DialogManager { private DialogManager() { } + @TargetApi(Build.VERSION_CODES.HONEYCOMB) static Dialog create(final Context context, boolean isShowNeutralButton, boolean isShowTitle, final OnClickButtonListener listener, View view) { - AlertDialog.Builder builder = new AlertDialog.Builder(context); + AlertDialog.Builder builder = getDialogBuilder(context); builder.setMessage(R.string.rate_dialog_message); + if (isShowTitle) builder.setTitle(R.string.rate_dialog_title); if (view != null) builder.setView(view); builder.setPositiveButton(R.string.rate_dialog_ok, new DialogInterface.OnClickListener() { @Override @@ -45,13 +49,7 @@ public void onClick(DialogInterface dialog, int which) { if (listener != null) listener.onClickButton(which); } }); - AlertDialog dialog = builder.create(); - if (!isShowTitle) { - dialog.requestWindowFeature(Window.FEATURE_NO_TITLE); - } else { - dialog.setTitle(R.string.rate_dialog_title); - } - return dialog; + return builder.create(); } } \ No newline at end of file diff --git a/library/src/main/java/hotchemi/android/rate/Utils.java b/library/src/main/java/hotchemi/android/rate/Utils.java new file mode 100644 index 0000000..7b9ce94 --- /dev/null +++ b/library/src/main/java/hotchemi/android/rate/Utils.java @@ -0,0 +1,34 @@ +package hotchemi.android.rate; + +import android.annotation.SuppressLint; +import android.app.AlertDialog; +import android.content.Context; +import android.os.Build; + +final class Utils { + + private Utils() { + } + + static boolean underHoneyComb() { + return Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB; + } + + static boolean overLollipop() { + return Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP; + } + + static int getDialogTheme() { + return overLollipop() ? R.style.CustomLollipopDialogStyle : 0; + } + + @SuppressLint("NewApi") + static AlertDialog.Builder getDialogBuilder(Context context) { + if (underHoneyComb()) { + return new AlertDialog.Builder(context); + } else { + return new AlertDialog.Builder(context, getDialogTheme()); + } + } + +} diff --git a/library/src/main/res/values-v21/themes.xml b/library/src/main/res/values-v21/themes.xml new file mode 100644 index 0000000..d7d103f --- /dev/null +++ b/library/src/main/res/values-v21/themes.xml @@ -0,0 +1,26 @@ + + + + + + + + + + \ No newline at end of file