From adb3e1e57105d5368be4b3d9467148ec38e1cc13 Mon Sep 17 00:00:00 2001 From: Upendra Shah Date: Mon, 8 Jan 2018 18:41:09 +0530 Subject: [PATCH] Added keylistner to kprogresshud --- kprogresshud/build.gradle | 1 + .../com/kaopiz/kprogresshud/KProgressHUD.java | 65 ++++++++++++++----- 2 files changed, 51 insertions(+), 15 deletions(-) diff --git a/kprogresshud/build.gradle b/kprogresshud/build.gradle index f3cd726..5fad552 100644 --- a/kprogresshud/build.gradle +++ b/kprogresshud/build.gradle @@ -37,6 +37,7 @@ android { dependencies { compile fileTree(dir: 'libs', include: ['*.jar']) testCompile 'junit:junit:4.12' + compile 'org.jetbrains:annotations-java5:15.0' } diff --git a/kprogresshud/src/main/java/com/kaopiz/kprogresshud/KProgressHUD.java b/kprogresshud/src/main/java/com/kaopiz/kprogresshud/KProgressHUD.java index 93e1d1c..a177249 100644 --- a/kprogresshud/src/main/java/com/kaopiz/kprogresshud/KProgressHUD.java +++ b/kprogresshud/src/main/java/com/kaopiz/kprogresshud/KProgressHUD.java @@ -31,6 +31,8 @@ import android.widget.FrameLayout; import android.widget.TextView; +import org.jetbrains.annotations.Nullable; + public class KProgressHUD { public enum Style { @@ -71,6 +73,7 @@ public KProgressHUD(Context context) { /** * Create a new HUD. Have the same effect as the constructor. * For convenient only. + * * @param context Activity context that the HUD bound to * @return An unique HUD instance */ @@ -78,19 +81,20 @@ public static KProgressHUD create(Context context) { return new KProgressHUD(context); } - /** - * Create a new HUD. specify the HUD style (if you use a custom view, you need {@code KProgressHUD.create(Context context)}). - * - * @param context Activity context that the HUD bound to - * @param style One of the KProgressHUD.Style values - * @return An unique HUD instance - */ + /** + * Create a new HUD. specify the HUD style (if you use a custom view, you need {@code KProgressHUD.create(Context context)}). + * + * @param context Activity context that the HUD bound to + * @param style One of the KProgressHUD.Style values + * @return An unique HUD instance + */ public static KProgressHUD create(Context context, Style style) { return new KProgressHUD(context).setStyle(style); } /** * Specify the HUD style (not needed if you use a custom view) + * * @param style One of the KProgressHUD.Style values * @return Current HUD */ @@ -117,6 +121,7 @@ public KProgressHUD setStyle(Style style) { /** * Specify the dim area around the HUD, like in Dialog + * * @param dimAmount May take value from 0 to 1. Default to 0 (no dimming) * @return Current HUD */ @@ -129,7 +134,8 @@ public KProgressHUD setDimAmount(float dimAmount) { /** * Set HUD size. If not the HUD view will use WRAP_CONTENT instead - * @param width in dp + * + * @param width in dp * @param height in dp * @return Current HUD */ @@ -139,9 +145,9 @@ public KProgressHUD setSize(int width, int height) { } /** - * @deprecated As of release 1.1.0, replaced by {@link #setBackgroundColor(int)} * @param color ARGB color * @return Current HUD + * @deprecated As of release 1.1.0, replaced by {@link #setBackgroundColor(int)} */ @Deprecated public KProgressHUD setWindowColor(int color) { @@ -151,6 +157,7 @@ public KProgressHUD setWindowColor(int color) { /** * Specify the HUD background color + * * @param color ARGB color * @return Current HUD */ @@ -159,8 +166,20 @@ public KProgressHUD setBackgroundColor(int color) { return this; } + /** + * Specify the HUD background color + * + * @param onKeyListener KeyListener + * @return Current HUD + */ + public KProgressHUD setOnKeyListener(@Nullable DialogInterface.OnKeyListener onKeyListener) { + this.mProgressDialog.setOnKeyListener(onKeyListener); + return this; + } + /** * Specify corner radius of the HUD (default is 10) + * * @param radius Corner radius in dp * @return Current HUD */ @@ -171,6 +190,7 @@ public KProgressHUD setCornerRadius(float radius) { /** * Change animation speed relative to default. Used with indeterminate style + * * @param scale Default is 1. If you want double the speed, set the param at 2. * @return Current HUD */ @@ -181,6 +201,7 @@ public KProgressHUD setAnimationSpeed(int scale) { /** * Optional label to be displayed. + * * @return Current HUD */ public KProgressHUD setLabel(String label) { @@ -190,6 +211,7 @@ public KProgressHUD setLabel(String label) { /** * Optional label to be displayed + * * @return Current HUD */ public KProgressHUD setLabel(String label, int color) { @@ -199,6 +221,7 @@ public KProgressHUD setLabel(String label, int color) { /** * Optional detail description to be displayed on the HUD + * * @return Current HUD */ public KProgressHUD setDetailsLabel(String detailsLabel) { @@ -208,6 +231,7 @@ public KProgressHUD setDetailsLabel(String detailsLabel) { /** * Optional detail description to be displayed + * * @return Current HUD */ public KProgressHUD setDetailsLabel(String detailsLabel, int color) { @@ -217,6 +241,7 @@ public KProgressHUD setDetailsLabel(String detailsLabel, int color) { /** * Max value for use in one of the determinate styles + * * @return Current HUD */ public KProgressHUD setMaxProgress(int maxProgress) { @@ -234,6 +259,7 @@ public void setProgress(int progress) { /** * Provide a custom view to be displayed. + * * @param view Must not be null * @return Current HUD */ @@ -248,7 +274,7 @@ public KProgressHUD setCustomView(View view) { /** * Specify whether this HUD can be cancelled by using back button (default is false) - * + *

* Setting a cancelable to true with this method will set a null callback, * clearing any callback previously set with * {@link #setCancellable(DialogInterface.OnCancelListener)} @@ -265,9 +291,8 @@ public KProgressHUD setCancellable(boolean isCancellable) { * Specify a callback to run when using the back button (default is null) * * @param listener The code that will run if the user presses the back - * button. If you pass null, the dialog won't be cancellable, just like - * if you had called {@link #setCancellable(boolean)} passing false. - * + * button. If you pass null, the dialog won't be cancellable, just like + * if you had called {@link #setCancellable(boolean)} passing false. * @return Current HUD */ public KProgressHUD setCancellable(DialogInterface.OnCancelListener listener) { @@ -278,6 +303,7 @@ public KProgressHUD setCancellable(DialogInterface.OnCancelListener listener) { /** * Specify whether this HUD closes itself if progress reaches max. Default is true. + * * @return Current HUD */ public KProgressHUD setAutoDismiss(boolean isAutoDismiss) { @@ -291,6 +317,7 @@ public KProgressHUD setAutoDismiss(boolean isAutoDismiss) { * not be shown at all. * This may be used to prevent HUD display for very short tasks. * Defaults to 0 (no grace time). + * * @param graceTimeMs Grace time in milliseconds * @return Current HUD */ @@ -339,16 +366,17 @@ private class ProgressDialog extends Dialog { private Determinate mDeterminateView; private Indeterminate mIndeterminateView; private View mView; - private TextView mLabelText; + private TextView mLabelText; private TextView mDetailsText; private String mLabel; private String mDetailsLabel; private FrameLayout mCustomViewContainer; private BackgroundLayout mBackgroundLayout; + private OnKeyListener mOnKeyListener; private int mWidth, mHeight; private int mLabelColor = Color.WHITE; private int mDetailColor = Color.WHITE; - + public ProgressDialog(Context context) { super(context); } @@ -372,6 +400,12 @@ protected void onCreate(Bundle savedInstanceState) { initViews(); } + @Override + public void setOnKeyListener(OnKeyListener onKeyListener) { + super.setOnKeyListener(onKeyListener); + mOnKeyListener = onKeyListener; + } + private void initViews() { mBackgroundLayout = (BackgroundLayout) findViewById(R.id.background); mBackgroundLayout.setBaseColor(mWindowColor); @@ -394,6 +428,7 @@ private void initViews() { setLabel(mLabel, mLabelColor); mDetailsText = (TextView) findViewById(com.kaopiz.kprogresshud.R.id.details_label); setDetailsLabel(mDetailsLabel, mDetailColor); + setOnKeyListener(mOnKeyListener); } private void addViewToFrame(View view) {