-
Notifications
You must be signed in to change notification settings - Fork 384
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added keylistner to KProgresshud #37
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -31,6 +31,8 @@ | |
import android.widget.FrameLayout; | ||
import android.widget.TextView; | ||
|
||
import org.jetbrains.annotations.Nullable; | ||
|
||
public class KProgressHUD { | ||
|
||
public enum Style { | ||
|
@@ -71,26 +73,28 @@ 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 | ||
*/ | ||
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); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just this is nice. You don't need to make any changes inside dialog class (I commented below). |
||
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) | ||
* | ||
* <p> | ||
* 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; | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think it not necessary to override this method, then save the reference which I don't see being call anywhere. |
||
|
||
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) { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using this type of annotation is generally good for the IDE to spot bugs and output some warnings.
But in this case I think it not so important to add a lib just for a single @nullable. Which IMHO, can be omitted without any problems.