Skip to content
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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions kprogresshud/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ android {
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'org.jetbrains:annotations-java5:15.0'
Copy link
Contributor

@tuanna-hsp tuanna-hsp Apr 20, 2018

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.

}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@
import android.widget.FrameLayout;
import android.widget.TextView;

import org.jetbrains.annotations.Nullable;

public class KProgressHUD {

public enum Style {
Expand Down Expand Up @@ -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
*/
Expand All @@ -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
*/
Expand All @@ -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
*/
Expand All @@ -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) {
Expand All @@ -151,6 +157,7 @@ public KProgressHUD setWindowColor(int color) {

/**
* Specify the HUD background color
*
* @param color ARGB color
* @return Current HUD
*/
Expand All @@ -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);
Copy link
Contributor

Choose a reason for hiding this comment

The 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
*/
Expand All @@ -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
*/
Expand All @@ -181,6 +201,7 @@ public KProgressHUD setAnimationSpeed(int scale) {

/**
* Optional label to be displayed.
*
* @return Current HUD
*/
public KProgressHUD setLabel(String label) {
Expand All @@ -190,6 +211,7 @@ public KProgressHUD setLabel(String label) {

/**
* Optional label to be displayed
*
* @return Current HUD
*/
public KProgressHUD setLabel(String label, int color) {
Expand All @@ -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) {
Expand All @@ -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) {
Expand All @@ -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) {
Expand All @@ -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
*/
Expand All @@ -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)}
Expand All @@ -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) {
Expand All @@ -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) {
Expand All @@ -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
*/
Expand Down Expand Up @@ -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);
}
Expand All @@ -372,6 +400,12 @@ protected void onCreate(Bundle savedInstanceState) {
initViews();
}

@Override
public void setOnKeyListener(OnKeyListener onKeyListener) {
super.setOnKeyListener(onKeyListener);
mOnKeyListener = onKeyListener;
}
Copy link
Contributor

Choose a reason for hiding this comment

The 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);
Expand All @@ -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) {
Expand Down