Skip to content

Commit

Permalink
Update demo; add Java docs
Browse files Browse the repository at this point in the history
  • Loading branch information
tuanna-hsp committed Dec 25, 2015
1 parent 94df233 commit 8165e78
Show file tree
Hide file tree
Showing 10 changed files with 110 additions and 36 deletions.
34 changes: 30 additions & 4 deletions demo/src/main/java/com/kaopiz/progresshud/demo/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;

import com.kaopiz.kprogresshud.KProgressHUD;
import com.kaopiz.progresshud.R;
Expand Down Expand Up @@ -36,23 +37,30 @@ protected void onCreate(Bundle savedInstanceState) {

Button customView = (Button) findViewById(R.id.custom_view);
customView.setOnClickListener(this);

Button dimBackground = (Button) findViewById(R.id.dim_background);
dimBackground.setOnClickListener(this);

Button customColor = (Button) findViewById(R.id.custom_color_animate);
customColor.setOnClickListener(this);
}

@Override
public void onClick(View v) {
KProgressHUD hud = null;
switch (v.getId()) {
case R.id.indeterminate:
hud = KProgressHUD.create(MainActivity.this)
hud = KProgressHUD.create(this)
.setStyle(KProgressHUD.Style.INDETERMINATE);
break;
case R.id.label_indeterminate:
hud = KProgressHUD.create(MainActivity.this)
hud = KProgressHUD.create(this)
.setStyle(KProgressHUD.Style.INDETERMINATE)
.setLabel("Please wait");
.setLabel("Please wait")
.setCancellable(true);
break;
case R.id.detail_indeterminate:
hud = KProgressHUD.create(MainActivity.this)
hud = KProgressHUD.create(this)
.setStyle(KProgressHUD.Style.INDETERMINATE)
.setLabel("Please wait")
.setDetailsLabel("Downloading data");
Expand All @@ -64,6 +72,24 @@ public void onClick(View v) {
case R.id.bar_determinate:
break;
case R.id.custom_view:
ImageView imageView = new ImageView(this);
imageView.setImageResource(R.mipmap.ic_launcher);
hud = KProgressHUD.create(this)
.setStyle(KProgressHUD.Style.CUSTOM_VIEW)
.setCustomView(imageView)
.setLabel("This is a custom view");
break;
case R.id.dim_background:
hud = KProgressHUD.create(this)
.setStyle(KProgressHUD.Style.INDETERMINATE)
.setDimAmount(0.6f);
break;
case R.id.custom_color_animate:
//noinspection deprecation
hud = KProgressHUD.create(this)
.setStyle(KProgressHUD.Style.INDETERMINATE)
.setWindowColor(getResources().getColor(R.color.colorPrimary))
.setAnimateSpeed(2);
break;
}
if (hud != null) {
Expand Down
14 changes: 13 additions & 1 deletion demo/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
android:id="@+id/label_indeterminate"
android:layout_width="match_parent"
android:layout_height="60dp"
android:text="With label"/>
android:text="With label and cancellable"/>

<Button
android:id="@+id/detail_indeterminate"
Expand Down Expand Up @@ -56,6 +56,18 @@
android:layout_width="match_parent"
android:layout_height="60dp"
android:text="Custom view"/>

<Button
android:id="@+id/dim_background"
android:layout_width="match_parent"
android:layout_height="60dp"
android:text="Dim background"/>

<Button
android:id="@+id/custom_color_animate"
android:layout_width="match_parent"
android:layout_height="60dp"
android:text="Custom color and speed"/>
</LinearLayout>
</ScrollView>

8 changes: 2 additions & 6 deletions library/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,6 @@

<application
android:allowBackup="true"
android:label="@string/app_name"
android:supportsRtl="true"
>

</application>

android:label="@string/kprogresshud_app_name"
android:supportsRtl="true" />
</manifest>
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public BackgroundLayout(Context context, AttributeSet attrs, int defStyleAttr) {

@SuppressWarnings("deprecation")
private void init() {
setBaseColor(getContext().getResources().getColor(R.color.default_window_color));
setBaseColor(getContext().getResources().getColor(R.color.kprogresshud_default_color));
// Remove background, we will drawing background using base color
setBackgroundColor(getContext().getResources().getColor(android.R.color.transparent));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public IndeterminateView(Context context, AttributeSet attrs) {
}

private void init() {
setImageResource(R.drawable.spinner);
setImageResource(R.drawable.kprogresshud_spinner);
mFrameTime = 1000 / 12;
mUpdateViewRunnable = new Runnable() {
@Override
Expand Down
82 changes: 61 additions & 21 deletions library/src/main/java/com/kaopiz/kprogresshud/KProgressHUD.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.kaopiz.kprogresshud;

import android.app.Activity;
import android.app.Dialog;
import android.content.Context;
import android.graphics.drawable.ColorDrawable;
Expand All @@ -23,7 +22,7 @@ public enum Style {
private float mDimAmount;
private int mWindowColor;
private float mCornerRadius;
private boolean mIsActivityHandleBackPress;
private boolean mCancellable;

private int mAnimateSpeed;
private String mLabel;
Expand All @@ -39,60 +38,102 @@ public KProgressHUD(Context context) {
mStyle = Style.INDETERMINATE;
mDimAmount = 0;
//noinspection deprecation
mWindowColor = context.getResources().getColor(R.color.default_window_color);
mWindowColor = context.getResources().getColor(R.color.kprogresshud_default_color);
mAnimateSpeed = 1;
mCornerRadius = 15;
}

/**
* Create a new HUD with default indeterminate style.
* @param context Activity context that the HUD bound to
* @return An unique HUD instance
*/
public static KProgressHUD create(Context context) {
return new KProgressHUD(context);
}

/*
* Methods for HUD customizing
/**
* Specify the HUD style
* @param style One of the following KProgressHUD.Style values:
* INDETERMINATE, DETERMINATE, ANNULAR_DETERMINATE, BAR_DETERMINATE, CUSTOM_VIEW
* @return Current HUD
*/

public KProgressHUD setStyle(Style style) {
mStyle = style;
return this;
}

/**
* Specify the dim area around the HUD, like in Dialog
* @param dimAmount May take value from 0 to 1.
* 0 means no dimming, 1 mean darkness
* @return Current HUD
*/
public KProgressHUD setDimAmount(float dimAmount) {
if (dimAmount >= 0 && dimAmount <= 1) {
mDimAmount = dimAmount;
}
return this;
}

/**
* Specify the HUD background color
* @param color ARGB color
* @return Current HUD
*/
public KProgressHUD setWindowColor(int color) {
mWindowColor = color;
return this;
}

/**
* Change animate speed relative to default. Only have effect when use with indeterminate style
* @param scale 1 is default, 2 means double speed, 0.5 means half speed..etc.
* @return Current HUD
*/
public KProgressHUD setAnimateSpeed(int scale) {
mAnimateSpeed = scale;
return this;
}

/**
* Optional label to be displayed on the HUD
* @return Current HUD
*/
public KProgressHUD setLabel(String label) {
mLabel = label;
return this;
}

/**
* Optional detail description to be displayed on the HUD
* @return Current HUD
*/
public KProgressHUD setDetailsLabel(String detailsLabel) {
mDetailsLabel = detailsLabel;
return this;
}

/**
* Max value for use in one of the determinate styles
* @return Current HUD
*/
public KProgressHUD setMaxProgress(int maxProgress) {
mMaxProgress = maxProgress;
return this;
}

public KProgressHUD setProgress(int progress) {
return this;
/**
* Set current progress. Only have effect when use with a determinate style
*/
public void setProgress(int progress) {
}

/**
* Provide a custom view to be displayed. Only have effect with the CUSTOM_VIEW style.
* @param view Must not be null
* @return Current HUD
*/
public KProgressHUD setCustomView(View view) {
if (view != null) {
mCustomView = view;
Expand All @@ -102,20 +143,26 @@ public KProgressHUD setCustomView(View view) {
return this;
}

public KProgressHUD letActivityHandleBackPress(boolean isAllow) {
mIsActivityHandleBackPress = isAllow;
/**
* Specify whether this HUD can be cancelled by using back button.
* @return Current HUD
*/
public KProgressHUD setCancellable(boolean isCancellable) {
mCancellable = isCancellable;
return this;
}

public KProgressHUD show() {
if (!mProgressDialog.isShowing()) {
if (mProgressDialog != null && !mProgressDialog.isShowing()) {
mProgressDialog.show();
}
return this;
}

public void dismiss() {
mProgressDialog.dismiss();
if (mProgressDialog != null && mProgressDialog.isShowing()) {
mProgressDialog.dismiss();
}
}

private class ProgressDialog extends Dialog {
Expand All @@ -128,7 +175,7 @@ public ProgressDialog(Context context) {
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.hud);
setContentView(R.layout.kprogresshud_hud);

Window window = getWindow();
window.setBackgroundDrawable(new ColorDrawable(0));
Expand All @@ -138,18 +185,11 @@ protected void onCreate(Bundle savedInstanceState) {
window.setAttributes(layoutParams);

setCanceledOnTouchOutside(false);
setCancelable(mCancellable);

initViews();
}

@Override
public void onBackPressed() {
if (mIsActivityHandleBackPress) {
dismiss();
((Activity) getContext()).onBackPressed();
}
}

private void initViews() {
BackgroundLayout background = (BackgroundLayout) findViewById(R.id.background);
background.setBaseColor(mWindowColor);
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion library/src/main/res/values/colors.xml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="default_window_color">#d8000000</color>
<color name="kprogresshud_default_color">#d8000000</color>
</resources>
2 changes: 1 addition & 1 deletion library/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
<resources>
<string name="app_name">KProgressHUD</string>
<string name="kprogresshud_app_name">KProgressHUD</string>
</resources>

0 comments on commit 8165e78

Please sign in to comment.