Repository: liangchengcheng/android-loading-dialog
Branch: master
Commit: 0c49f8294ba6
Files: 40
Total size: 70.3 KB
Directory structure:
gitextract__b8dyl2m/
├── .gitignore
├── LICENSE
├── README.md
├── build.gradle
├── demo/
│ ├── .gitignore
│ ├── build.gradle
│ ├── proguard-rules.pro
│ └── src/
│ ├── androidTest/
│ │ └── java/
│ │ └── com/
│ │ └── kaopiz/
│ │ └── progresshud/
│ │ └── demo/
│ │ └── ApplicationTest.java
│ ├── main/
│ │ ├── AndroidManifest.xml
│ │ ├── java/
│ │ │ └── com/
│ │ │ └── kaopiz/
│ │ │ └── progresshud/
│ │ │ └── demo/
│ │ │ └── MainActivity.java
│ │ └── res/
│ │ ├── layout/
│ │ │ └── activity_main.xml
│ │ ├── values/
│ │ │ ├── colors.xml
│ │ │ ├── dimens.xml
│ │ │ ├── strings.xml
│ │ │ └── styles.xml
│ │ └── values-w820dp/
│ │ └── dimens.xml
│ └── test/
│ └── java/
│ └── com/
│ └── kaopiz/
│ └── progresshud/
│ └── ExampleUnitTest.java
├── gradle/
│ └── wrapper/
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── gradle.properties
├── gradlew
├── gradlew.bat
├── kprogresshud/
│ ├── .gitignore
│ ├── build.gradle
│ ├── proguard-rules.pro
│ └── src/
│ ├── androidTest/
│ │ └── java/
│ │ └── com/
│ │ └── kaopiz/
│ │ └── kprogresshud/
│ │ └── ApplicationTest.java
│ ├── main/
│ │ ├── AndroidManifest.xml
│ │ ├── java/
│ │ │ └── com/
│ │ │ └── kaopiz/
│ │ │ └── kprogresshud/
│ │ │ ├── AnnularView.java
│ │ │ ├── BackgroundLayout.java
│ │ │ ├── BarView.java
│ │ │ ├── Determinate.java
│ │ │ ├── Helper.java
│ │ │ ├── Indeterminate.java
│ │ │ ├── KProgressHUD.java
│ │ │ ├── PieView.java
│ │ │ └── SpinView.java
│ │ └── res/
│ │ ├── layout/
│ │ │ └── kprogresshud_hud.xml
│ │ └── values/
│ │ └── colors.xml
│ └── test/
│ └── java/
│ └── com/
│ └── kaopiz/
│ └── kprogresshud/
│ └── ExampleUnitTest.java
└── settings.gradle
================================================
FILE CONTENTS
================================================
================================================
FILE: .gitignore
================================================
*.iml
.gradle
/local.properties
/.idea
.DS_Store
/build
/captures
================================================
FILE: LICENSE
================================================
Apache License
Version 2.0, January 2004
http://www.apache.org/licenses/
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
1. Definitions.
"License" shall mean the terms and conditions for use, reproduction,
and distribution as defined by Sections 1 through 9 of this document.
"Licensor" shall mean the copyright owner or entity authorized by
the copyright owner that is granting the License.
"Legal Entity" shall mean the union of the acting entity and all
other entities that control, are controlled by, or are under common
control with that entity. For the purposes of this definition,
"control" means (i) the power, direct or indirect, to cause the
direction or management of such entity, whether by contract or
otherwise, or (ii) ownership of fifty percent (50%) or more of the
outstanding shares, or (iii) beneficial ownership of such entity.
"You" (or "Your") shall mean an individual or Legal Entity
exercising permissions granted by this License.
"Source" form shall mean the preferred form for making modifications,
including but not limited to software source code, documentation
source, and configuration files.
"Object" form shall mean any form resulting from mechanical
transformation or translation of a Source form, including but
not limited to compiled object code, generated documentation,
and conversions to other media types.
"Work" shall mean the work of authorship, whether in Source or
Object form, made available under the License, as indicated by a
copyright notice that is included in or attached to the work
(an example is provided in the Appendix below).
"Derivative Works" shall mean any work, whether in Source or Object
form, that is based on (or derived from) the Work and for which the
editorial revisions, annotations, elaborations, or other modifications
represent, as a whole, an original work of authorship. For the purposes
of this License, Derivative Works shall not include works that remain
separable from, or merely link (or bind by name) to the interfaces of,
the Work and Derivative Works thereof.
"Contribution" shall mean any work of authorship, including
the original version of the Work and any modifications or additions
to that Work or Derivative Works thereof, that is intentionally
submitted to Licensor for inclusion in the Work by the copyright owner
or by an individual or Legal Entity authorized to submit on behalf of
the copyright owner. For the purposes of this definition, "submitted"
means any form of electronic, verbal, or written communication sent
to the Licensor or its representatives, including but not limited to
communication on electronic mailing lists, source code control systems,
and issue tracking systems that are managed by, or on behalf of, the
Licensor for the purpose of discussing and improving the Work, but
excluding communication that is conspicuously marked or otherwise
designated in writing by the copyright owner as "Not a Contribution."
"Contributor" shall mean Licensor and any individual or Legal Entity
on behalf of whom a Contribution has been received by Licensor and
subsequently incorporated within the Work.
2. Grant of Copyright License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
copyright license to reproduce, prepare Derivative Works of,
publicly display, publicly perform, sublicense, and distribute the
Work and such Derivative Works in Source or Object form.
3. Grant of Patent License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
(except as stated in this section) patent license to make, have made,
use, offer to sell, sell, import, and otherwise transfer the Work,
where such license applies only to those patent claims licensable
by such Contributor that are necessarily infringed by their
Contribution(s) alone or by combination of their Contribution(s)
with the Work to which such Contribution(s) was submitted. If You
institute patent litigation against any entity (including a
cross-claim or counterclaim in a lawsuit) alleging that the Work
or a Contribution incorporated within the Work constitutes direct
or contributory patent infringement, then any patent licenses
granted to You under this License for that Work shall terminate
as of the date such litigation is filed.
4. Redistribution. You may reproduce and distribute copies of the
Work or Derivative Works thereof in any medium, with or without
modifications, and in Source or Object form, provided that You
meet the following conditions:
(a) You must give any other recipients of the Work or
Derivative Works a copy of this License; and
(b) You must cause any modified files to carry prominent notices
stating that You changed the files; and
(c) You must retain, in the Source form of any Derivative Works
that You distribute, all copyright, patent, trademark, and
attribution notices from the Source form of the Work,
excluding those notices that do not pertain to any part of
the Derivative Works; and
(d) If the Work includes a "NOTICE" text file as part of its
distribution, then any Derivative Works that You distribute must
include a readable copy of the attribution notices contained
within such NOTICE file, excluding those notices that do not
pertain to any part of the Derivative Works, in at least one
of the following places: within a NOTICE text file distributed
as part of the Derivative Works; within the Source form or
documentation, if provided along with the Derivative Works; or,
within a display generated by the Derivative Works, if and
wherever such third-party notices normally appear. The contents
of the NOTICE file are for informational purposes only and
do not modify the License. You may add Your own attribution
notices within Derivative Works that You distribute, alongside
or as an addendum to the NOTICE text from the Work, provided
that such additional attribution notices cannot be construed
as modifying the License.
You may add Your own copyright statement to Your modifications and
may provide additional or different license terms and conditions
for use, reproduction, or distribution of Your modifications, or
for any such Derivative Works as a whole, provided Your use,
reproduction, and distribution of the Work otherwise complies with
the conditions stated in this License.
5. Submission of Contributions. Unless You explicitly state otherwise,
any Contribution intentionally submitted for inclusion in the Work
by You to the Licensor shall be under the terms and conditions of
this License, without any additional terms or conditions.
Notwithstanding the above, nothing herein shall supersede or modify
the terms of any separate license agreement you may have executed
with Licensor regarding such Contributions.
6. Trademarks. This License does not grant permission to use the trade
names, trademarks, service marks, or product names of the Licensor,
except as required for reasonable and customary use in describing the
origin of the Work and reproducing the content of the NOTICE file.
7. Disclaimer of Warranty. Unless required by applicable law or
agreed to in writing, Licensor provides the Work (and each
Contributor provides its Contributions) on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
implied, including, without limitation, any warranties or conditions
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
PARTICULAR PURPOSE. You are solely responsible for determining the
appropriateness of using or redistributing the Work and assume any
risks associated with Your exercise of permissions under this License.
8. Limitation of Liability. In no event and under no legal theory,
whether in tort (including negligence), contract, or otherwise,
unless required by applicable law (such as deliberate and grossly
negligent acts) or agreed to in writing, shall any Contributor be
liable to You for damages, including any direct, indirect, special,
incidental, or consequential damages of any character arising as a
result of this License or out of the use or inability to use the
Work (including but not limited to damages for loss of goodwill,
work stoppage, computer failure or malfunction, or any and all
other commercial damages or losses), even if such Contributor
has been advised of the possibility of such damages.
9. Accepting Warranty or Additional Liability. While redistributing
the Work or Derivative Works thereof, You may choose to offer,
and charge a fee for, acceptance of support, warranty, indemnity,
or other liability obligations and/or rights consistent with this
License. However, in accepting such obligations, You may act only
on Your own behalf and on Your sole responsibility, not on behalf
of any other Contributor, and only if You agree to indemnify,
defend, and hold each Contributor harmless for any liability
incurred by, or claims asserted against, such Contributor by reason
of your accepting any such warranty or additional liability.
END OF TERMS AND CONDITIONS
APPENDIX: How to apply the Apache License to your work.
To apply the Apache License to your work, attach the following
boilerplate notice, with the fields enclosed by brackets "{}"
replaced with your own identifying information. (Don't include
the brackets!) The text should be enclosed in the appropriate
comment syntax for the file format. We also recommend that a
file or class name and description of purpose be included on the
same "printed page" as the copyright notice for easier
identification within third-party archives.
Copyright 2015 Kaopiz Software Co., Ltd.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
================================================
FILE: README.md
================================================
# KProgressHUD
[](http://opensource.org/licenses/Apache-2.0)
[  ](https://bintray.com/kaopiz/KProgressHUD/KProgressHUD/_latestVersion)
[](https://android-arsenal.com/details/1/2975)
An implement of ProgressHUD for Android, similar to MBProgressHUD, SVProgressHUD.
Inspired by [MBProgressHUD](https://github.com/jdg/MBProgressHUD) for iOS.

## Compatibility
Android 2.3 and later
## Adding KProgressHUD to your project
### Gradle
Include this in your module `build.gradle`
```
dependencies {
// Other dependencies
compile 'com.kaopiz:kprogresshud:1.0.2'
}
```
### Source code
You can download and import the `kprogresshud` folder as module to your project.
## Usage
The usage of KProgressHUD is pretty straight forward. You create the HUD, customize its style and show it on the UI thread. Then fire a background thread to work on long-running tasks. When done, call `dismiss()` to close it (if you use a determinate style, the HUD will automatically dismiss if progress reach its max).
Indeterminate HUD
```java
KProgressHUD.create(MainActivity.this)
.setStyle(KProgressHUD.Style.SPIN_INDETERMINATE)
.setLabel("Please wait")
.setDetailsLabel("Downloading data");
.setCancellable(true)
.setAnimationSpeed(2)
.setDimAmount(0.5f)
.show();
```
Determinate HUD
```java
KProgressHUD hud = KProgressHUD.create(MainActivity.this)
.setStyle(KProgressHUD.Style.ANNULAR_DETERMINATE)
.setLabel("Please wait")
.setMaxProgress(100)
.show();
hud.setProgress(90);
```
Alternatively, you can create a custom view and pass to the HUD to display it.
```java
ImageView imageView = new ImageView(this);
imageView.setImageResource(R.mipmap.ic_launcher);
KProgressHUD.create(MainActivity.this)
.setCustomView(imageView)
.setLabel("This is a custom view")
.show();
```
The custom view can implement `Determinate` or `Indeterminate`, which make the HUD treats this view like the default determinate or indeterminate implementations, not required.
See [**Javadocs**](http://kaopiz.github.io/KProgressHUD/) or [**sample app**](https://github.com/Kaopiz/KProgressHUD/tree/master/demo/src/main) for more information.
## Contributing
1. Fork it ( https://github.com/Kaopiz/KProgressHUD/fork )
2. Create your feature branch (`git checkout -b my-new-feature`)
3. Commit your changes (`git commit -am 'Add some feature'`)
4. Push to the branch (`git push origin my-new-feature`)
5. Create new Pull Request
## Contributor
* [tuanna-hsp](https://github.com/tuanna-hsp)
* [nafuto](https://github.com/nafuto)
## License
```
Copyright 2015 Kaopiz Software Co., Ltd.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
```
================================================
FILE: build.gradle
================================================
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.5.0'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
================================================
FILE: demo/.gitignore
================================================
/build
================================================
FILE: demo/build.gradle
================================================
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion "23.0.2"
defaultConfig {
applicationId "com.kaopiz.progresshud"
minSdkVersion 8
targetSdkVersion 23
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.1.1'
compile project(':kprogresshud')
}
================================================
FILE: demo/proguard-rules.pro
================================================
# Add project specific ProGuard rules here.
# By default, the flags in this file are appended to flags specified
# in E:\Android\sdk/tools/proguard/proguard-android.txt
# You can edit the include path and order by changing the proguardFiles
# directive in build.gradle.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html
# Add any project specific keep options here:
# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}
================================================
FILE: demo/src/androidTest/java/com/kaopiz/progresshud/demo/ApplicationTest.java
================================================
package com.kaopiz.progresshud.demo;
import android.app.Application;
import android.test.ApplicationTestCase;
/**
* Testing Fundamentals
*/
public class ApplicationTest extends ApplicationTestCase {
public ApplicationTest() {
super(Application.class);
}
}
================================================
FILE: demo/src/main/AndroidManifest.xml
================================================
================================================
FILE: demo/src/main/java/com/kaopiz/progresshud/demo/MainActivity.java
================================================
/*
* Copyright (c) 2015 Kaopiz Software Co., Ltd
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package com.kaopiz.progresshud.demo;
import android.os.Bundle;
import android.os.Handler;
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;
public class MainActivity extends AppCompatActivity implements View.OnClickListener {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button indeterminate = (Button) findViewById(R.id.indeterminate);
indeterminate.setOnClickListener(this);
Button labelIndeterminate = (Button) findViewById(R.id.label_indeterminate);
labelIndeterminate.setOnClickListener(this);
Button detailIndeterminate = (Button) findViewById(R.id.detail_indeterminate);
detailIndeterminate.setOnClickListener(this);
Button determinate = (Button) findViewById(R.id.determinate);
determinate.setOnClickListener(this);
Button annularDeterminate = (Button) findViewById(R.id.annular_determinate);
annularDeterminate.setOnClickListener(this);
Button barDeterminate = (Button) findViewById(R.id.bar_determinate);
barDeterminate.setOnClickListener(this);
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);
}
private KProgressHUD hud;
@Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.indeterminate:
hud = KProgressHUD.create(this)
.setStyle(KProgressHUD.Style.SPIN_INDETERMINATE);
scheduleDismiss();
break;
case R.id.label_indeterminate:
hud = KProgressHUD.create(this)
.setStyle(KProgressHUD.Style.SPIN_INDETERMINATE)
.setLabel("Please wait")
.setCancellable(true);
scheduleDismiss();
break;
case R.id.detail_indeterminate:
hud = KProgressHUD.create(this)
.setStyle(KProgressHUD.Style.SPIN_INDETERMINATE)
.setLabel("Please wait")
.setDetailsLabel("Downloading data");
scheduleDismiss();
break;
case R.id.determinate:
hud = KProgressHUD.create(MainActivity.this)
.setStyle(KProgressHUD.Style.PIE_DETERMINATE)
.setLabel("Please wait");
simulateProgressUpdate();
break;
case R.id.annular_determinate:
hud = KProgressHUD.create(MainActivity.this)
.setStyle(KProgressHUD.Style.ANNULAR_DETERMINATE)
.setLabel("Please wait");
simulateProgressUpdate();
break;
case R.id.bar_determinate:
hud = KProgressHUD.create(MainActivity.this)
.setStyle(KProgressHUD.Style.BAR_DETERMINATE)
.setLabel("Please wait");
simulateProgressUpdate();
break;
case R.id.custom_view:
ImageView imageView = new ImageView(this);
imageView.setImageResource(R.mipmap.ic_launcher);
hud = KProgressHUD.create(this)
.setCustomView(imageView)
.setLabel("This is a custom view");
scheduleDismiss();
break;
case R.id.dim_background:
hud = KProgressHUD.create(this)
.setStyle(KProgressHUD.Style.SPIN_INDETERMINATE)
.setDimAmount(0.5f);
scheduleDismiss();
break;
case R.id.custom_color_animate:
//noinspection deprecation
hud = KProgressHUD.create(this)
.setStyle(KProgressHUD.Style.SPIN_INDETERMINATE)
.setWindowColor(getResources().getColor(R.color.colorPrimary))
.setAnimationSpeed(2);
scheduleDismiss();
break;
}
hud.show();
}
private void simulateProgressUpdate() {
hud.setMaxProgress(100);
final Handler handler = new Handler();
handler.postDelayed(new Runnable() {
int currentProgress;
@Override
public void run() {
currentProgress += 1;
hud.setProgress(currentProgress);
if (currentProgress < 100) {
handler.postDelayed(this, 50);
}
}
}, 100);
}
private void scheduleDismiss() {
Handler handler = new Handler();
handler.postDelayed(new Runnable() {
@Override
public void run() {
hud.dismiss();
}
}, 2000);
}
}
================================================
FILE: demo/src/main/res/layout/activity_main.xml
================================================
================================================
FILE: demo/src/main/res/values/colors.xml
================================================
#3F51B5#303F9F#FF4081
================================================
FILE: demo/src/main/res/values/dimens.xml
================================================
16dp16dp
================================================
FILE: demo/src/main/res/values/strings.xml
================================================
KProgressHUD
================================================
FILE: demo/src/main/res/values/styles.xml
================================================
================================================
FILE: demo/src/main/res/values-w820dp/dimens.xml
================================================
64dp
================================================
FILE: demo/src/test/java/com/kaopiz/progresshud/ExampleUnitTest.java
================================================
package com.kaopiz.progresshud;
import org.junit.Test;
import static org.junit.Assert.*;
/**
* To work on unit tests, switch the Test Artifact in the Build Variants view.
*/
public class ExampleUnitTest {
@Test
public void addition_isCorrect() throws Exception {
assertEquals(4, 2 + 2);
}
}
================================================
FILE: gradle/wrapper/gradle-wrapper.properties
================================================
#Wed Oct 21 11:34:03 PDT 2015
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-2.8-all.zip
================================================
FILE: gradle.properties
================================================
# Project-wide Gradle settings.
# IDE (e.g. Android Studio) users:
# Gradle settings configured through the IDE *will override*
# any settings specified in this file.
# For more details on how to configure your build environment visit
# http://www.gradle.org/docs/current/userguide/build_environment.html
# Specifies the JVM arguments used for the daemon process.
# The setting is particularly useful for tweaking memory settings.
# Default value: -Xmx10248m -XX:MaxPermSize=256m
# org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
# When configured, Gradle will run in incubating parallel mode.
# This option should only be used with decoupled projects. More details, visit
# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
# org.gradle.parallel=true
================================================
FILE: gradlew
================================================
#!/usr/bin/env bash
##############################################################################
##
## Gradle start up script for UN*X
##
##############################################################################
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
DEFAULT_JVM_OPTS=""
APP_NAME="Gradle"
APP_BASE_NAME=`basename "$0"`
# Use the maximum available, or set MAX_FD != -1 to use that value.
MAX_FD="maximum"
warn ( ) {
echo "$*"
}
die ( ) {
echo
echo "$*"
echo
exit 1
}
# OS specific support (must be 'true' or 'false').
cygwin=false
msys=false
darwin=false
case "`uname`" in
CYGWIN* )
cygwin=true
;;
Darwin* )
darwin=true
;;
MINGW* )
msys=true
;;
esac
# Attempt to set APP_HOME
# Resolve links: $0 may be a link
PRG="$0"
# Need this for relative symlinks.
while [ -h "$PRG" ] ; do
ls=`ls -ld "$PRG"`
link=`expr "$ls" : '.*-> \(.*\)$'`
if expr "$link" : '/.*' > /dev/null; then
PRG="$link"
else
PRG=`dirname "$PRG"`"/$link"
fi
done
SAVED="`pwd`"
cd "`dirname \"$PRG\"`/" >/dev/null
APP_HOME="`pwd -P`"
cd "$SAVED" >/dev/null
CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
# Determine the Java command to use to start the JVM.
if [ -n "$JAVA_HOME" ] ; then
if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
# IBM's JDK on AIX uses strange locations for the executables
JAVACMD="$JAVA_HOME/jre/sh/java"
else
JAVACMD="$JAVA_HOME/bin/java"
fi
if [ ! -x "$JAVACMD" ] ; then
die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
Please set the JAVA_HOME variable in your environment to match the
location of your Java installation."
fi
else
JAVACMD="java"
which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
Please set the JAVA_HOME variable in your environment to match the
location of your Java installation."
fi
# Increase the maximum file descriptors if we can.
if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
MAX_FD_LIMIT=`ulimit -H -n`
if [ $? -eq 0 ] ; then
if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
MAX_FD="$MAX_FD_LIMIT"
fi
ulimit -n $MAX_FD
if [ $? -ne 0 ] ; then
warn "Could not set maximum file descriptor limit: $MAX_FD"
fi
else
warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
fi
fi
# For Darwin, add options to specify how the application appears in the dock
if $darwin; then
GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
fi
# For Cygwin, switch paths to Windows format before running java
if $cygwin ; then
APP_HOME=`cygpath --path --mixed "$APP_HOME"`
CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
JAVACMD=`cygpath --unix "$JAVACMD"`
# We build the pattern for arguments to be converted via cygpath
ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
SEP=""
for dir in $ROOTDIRSRAW ; do
ROOTDIRS="$ROOTDIRS$SEP$dir"
SEP="|"
done
OURCYGPATTERN="(^($ROOTDIRS))"
# Add a user-defined pattern to the cygpath arguments
if [ "$GRADLE_CYGPATTERN" != "" ] ; then
OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
fi
# Now convert the arguments - kludge to limit ourselves to /bin/sh
i=0
for arg in "$@" ; do
CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
else
eval `echo args$i`="\"$arg\""
fi
i=$((i+1))
done
case $i in
(0) set -- ;;
(1) set -- "$args0" ;;
(2) set -- "$args0" "$args1" ;;
(3) set -- "$args0" "$args1" "$args2" ;;
(4) set -- "$args0" "$args1" "$args2" "$args3" ;;
(5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
(6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
(7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
(8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
(9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
esac
fi
# Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
function splitJvmOpts() {
JVM_OPTS=("$@")
}
eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"
================================================
FILE: gradlew.bat
================================================
@if "%DEBUG%" == "" @echo off
@rem ##########################################################################
@rem
@rem Gradle startup script for Windows
@rem
@rem ##########################################################################
@rem Set local scope for the variables with windows NT shell
if "%OS%"=="Windows_NT" setlocal
@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
set DEFAULT_JVM_OPTS=
set DIRNAME=%~dp0
if "%DIRNAME%" == "" set DIRNAME=.
set APP_BASE_NAME=%~n0
set APP_HOME=%DIRNAME%
@rem Find java.exe
if defined JAVA_HOME goto findJavaFromJavaHome
set JAVA_EXE=java.exe
%JAVA_EXE% -version >NUL 2>&1
if "%ERRORLEVEL%" == "0" goto init
echo.
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
echo.
echo Please set the JAVA_HOME variable in your environment to match the
echo location of your Java installation.
goto fail
:findJavaFromJavaHome
set JAVA_HOME=%JAVA_HOME:"=%
set JAVA_EXE=%JAVA_HOME%/bin/java.exe
if exist "%JAVA_EXE%" goto init
echo.
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
echo.
echo Please set the JAVA_HOME variable in your environment to match the
echo location of your Java installation.
goto fail
:init
@rem Get command-line arguments, handling Windowz variants
if not "%OS%" == "Windows_NT" goto win9xME_args
if "%@eval[2+2]" == "4" goto 4NT_args
:win9xME_args
@rem Slurp the command line arguments.
set CMD_LINE_ARGS=
set _SKIP=2
:win9xME_args_slurp
if "x%~1" == "x" goto execute
set CMD_LINE_ARGS=%*
goto execute
:4NT_args
@rem Get arguments from the 4NT Shell from JP Software
set CMD_LINE_ARGS=%$
:execute
@rem Setup the command line
set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
@rem Execute Gradle
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
:end
@rem End local scope for the variables with windows NT shell
if "%ERRORLEVEL%"=="0" goto mainEnd
:fail
rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
rem the _cmd.exe /c_ return code!
if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
exit /b 1
:mainEnd
if "%OS%"=="Windows_NT" endlocal
:omega
================================================
FILE: kprogresshud/.gitignore
================================================
/build
================================================
FILE: kprogresshud/build.gradle
================================================
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.4'
classpath 'com.github.dcendents:android-maven-gradle-plugin:1.3'
}
}
apply plugin: 'com.android.library'
project.archivesBaseName = 'kprogresshud'
android {
compileSdkVersion 23
buildToolsVersion "23.0.2"
defaultConfig {
minSdkVersion 8
targetSdkVersion 23
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
}
apply plugin: 'com.github.dcendents.android-maven'
apply plugin: 'com.jfrog.bintray'
ext {
bintrayRepo = 'KProgressHUD'
bintrayName = 'KProgressHUD'
publishedGroupId = 'com.kaopiz'
libraryName = 'kprogresshud'
artifact = 'kprogresshud'
libraryDescription = 'A customizable ProgressHUD for Android'
siteUrl = 'http://kaopiz.github.io/KProgressHUD/'
gitUrl = 'https://github.com/Kaopiz/KProgressHUD'
libraryVersion = '1.0.2'
developerId = 'kaopiz'
developerName = 'Kaopiz Software Co., Ltd.'
developerEmail = 'contact@kaopiz.com'
licenseName = 'The Apache Software License, Version 2.0'
licenseUrl = 'http://www.apache.org/licenses/LICENSE-2.0.txt'
allLicenses = ["Apache-2.0"]
}
group = publishedGroupId
version = libraryVersion
task sourcesJar(type: Jar) {
from android.sourceSets.main.java.srcDirs
classifier = 'sources'
}
task javadoc(type: Javadoc) {
source = android.sourceSets.main.java.srcDirs
classpath += project.files(android.getBootClasspath().join(File.pathSeparator))
}
task javadocJar(type: Jar, dependsOn: javadoc) {
classifier = 'javadoc'
from javadoc.destinationDir
}
artifacts {
archives javadocJar
archives sourcesJar
}
// Bintray
Properties properties = new Properties()
properties.load(project.rootProject.file('local.properties').newDataInputStream())
bintray {
user = properties.getProperty("bintray.user")
key = properties.getProperty("bintray.apikey")
configurations = ['archives']
pkg {
repo = bintrayRepo
name = bintrayName
userOrg = 'kaopiz'
desc = libraryDescription
websiteUrl = siteUrl
vcsUrl = gitUrl
licenses = allLicenses
publish = true
publicDownloadNumbers = true
version {
desc = libraryDescription
gpg {
sign = true //Determines whether to GPG sign the files. The default is false
passphrase = properties.getProperty("bintray.gpg.password")
//Optional. The passphrase for GPG signing'
}
}
}
}
install {
repositories.mavenInstaller {
// This generates POM.xml with proper parameters
pom {
project {
packaging 'aar'
groupId 'com.kaopiz'
artifactId 'kprogresshud'
// Add your description here
name libraryName
description libraryDescription
url siteUrl
// Set your license
licenses {
license {
name licenseName
url licenseUrl
}
}
developers {
developer {
id developerId
name developerName
email developerEmail
}
}
scm {
connection gitUrl
developerConnection gitUrl
url siteUrl
}
}
}
}
}
================================================
FILE: kprogresshud/proguard-rules.pro
================================================
# Add project specific ProGuard rules here.
# By default, the flags in this file are appended to flags specified
# in E:\Android\sdk/tools/proguard/proguard-android.txt
# You can edit the include path and order by changing the proguardFiles
# directive in build.gradle.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html
# Add any project specific keep options here:
# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}
================================================
FILE: kprogresshud/src/androidTest/java/com/kaopiz/kprogresshud/ApplicationTest.java
================================================
package com.kaopiz.kprogresshud;
import android.app.Application;
import android.test.ApplicationTestCase;
/**
* Testing Fundamentals
*/
public class ApplicationTest extends ApplicationTestCase {
public ApplicationTest() {
super(Application.class);
}
}
================================================
FILE: kprogresshud/src/main/AndroidManifest.xml
================================================
================================================
FILE: kprogresshud/src/main/java/com/kaopiz/kprogresshud/AnnularView.java
================================================
/*
* Copyright 2015 Kaopiz Software Co., Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.kaopiz.kprogresshud;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.RectF;
import android.util.AttributeSet;
import android.view.View;
class AnnularView extends View implements Determinate {
private Paint mWhitePaint;
private Paint mGreyPaint;
private RectF mBound;
private int mMax = 100;
private int mProgress = 0;
public AnnularView(Context context) {
super(context);
init(context);
}
public AnnularView(Context context, AttributeSet attrs) {
super(context, attrs);
init(context);
}
public AnnularView(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
init(context);
}
private void init(Context context){
mWhitePaint = new Paint(Paint.ANTI_ALIAS_FLAG);
mWhitePaint.setStyle(Paint.Style.STROKE);
mWhitePaint.setStrokeWidth(Helper.dpToPixel(3, getContext()));
mWhitePaint.setColor(Color.WHITE);
mGreyPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
mGreyPaint.setStyle(Paint.Style.STROKE);
mGreyPaint.setStrokeWidth(Helper.dpToPixel(3, getContext()));
mGreyPaint.setColor(context.getResources().getColor(R.color.kprogresshud_grey_color));
mBound = new RectF();
}
@Override
protected void onSizeChanged(int w, int h, int oldw, int oldh) {
super.onSizeChanged(w, h, oldw, oldh);
int padding = Helper.dpToPixel(4, getContext());
mBound.set(padding, padding, w - padding, h - padding);
}
@Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
float mAngle = mProgress * 360f / mMax;
canvas.drawArc(mBound, 270, mAngle, false, mWhitePaint);
canvas.drawArc(mBound, 270 + mAngle, 360 - mAngle, false, mGreyPaint);
}
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
int dimension = Helper.dpToPixel(40, getContext());
setMeasuredDimension(dimension, dimension);
}
@Override
public void setMax(int max) {
this.mMax = max;
}
@Override
public void setProgress(int progress) {
mProgress = progress;
invalidate();
}
}
================================================
FILE: kprogresshud/src/main/java/com/kaopiz/kprogresshud/BackgroundLayout.java
================================================
/*
* Copyright 2015 Kaopiz Software Co., Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.kaopiz.kprogresshud;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.RectF;
import android.util.AttributeSet;
import android.widget.FrameLayout;
class BackgroundLayout extends FrameLayout {
private float mCornerRadius;
private Paint mPaint;
private RectF mRect;
public BackgroundLayout(Context context) {
super(context);
init();
}
public BackgroundLayout(Context context, AttributeSet attrs) {
super(context, attrs);
init();
}
public BackgroundLayout(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
init();
}
@SuppressWarnings("deprecation")
private void init() {
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));
}
public void setCornerRadius(float radius) {
mCornerRadius = Helper.dpToPixel(radius, getContext());
}
public void setBaseColor(int color) {
mPaint = new Paint();
//noinspection deprecation
mPaint.setColor(color);
mPaint.setStyle(Paint.Style.FILL);
}
@Override
protected void onSizeChanged(int w, int h, int oldw, int oldh) {
super.onSizeChanged(w, h, oldw, oldh);
mRect = new RectF(0, 0, w, h);
}
@Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
canvas.drawRoundRect(mRect, mCornerRadius, mCornerRadius, mPaint);
}
}
================================================
FILE: kprogresshud/src/main/java/com/kaopiz/kprogresshud/BarView.java
================================================
/*
* Copyright 2015 Kaopiz Software Co., Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.kaopiz.kprogresshud;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.RectF;
import android.util.AttributeSet;
import android.view.View;
class BarView extends View implements Determinate {
private Paint mOuterPaint;
private Paint mInnerPaint;
private RectF mBound;
private RectF mInBound;
private int mMax = 100;
private int mProgress = 0;
private float mRadius;
private float mBoundGap;
public BarView(Context context) {
super(context);
init();
}
public BarView(Context context, AttributeSet attrs) {
super(context, attrs);
init();
}
public BarView(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
init();
}
private void init() {
mOuterPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
mOuterPaint.setStyle(Paint.Style.STROKE);
mOuterPaint.setStrokeWidth(Helper.dpToPixel(2, getContext()));
mOuterPaint.setColor(Color.WHITE);
mInnerPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
mInnerPaint.setStyle(Paint.Style.FILL);
mInnerPaint.setColor(Color.WHITE);
mBoundGap = Helper.dpToPixel(5, getContext());
mInBound = new RectF(mBoundGap, mBoundGap,
(getWidth() - mBoundGap) * mProgress / mMax, getHeight() - mBoundGap);
mRadius = Helper.dpToPixel(10, getContext());
mBound = new RectF();
}
@Override
protected void onSizeChanged(int w, int h, int oldw, int oldh) {
super.onSizeChanged(w, h, oldw, oldh);
int padding = Helper.dpToPixel(2, getContext());
mBound.set(padding, padding, w - padding, h - padding);
}
@Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
canvas.drawRoundRect(mBound, mRadius, mRadius, mOuterPaint);
canvas.drawRoundRect(mInBound, mRadius, mRadius, mInnerPaint);
}
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
int widthDimension = Helper.dpToPixel(100, getContext());
int heightDimension = Helper.dpToPixel(20, getContext());
setMeasuredDimension(widthDimension, heightDimension);
}
@Override
public void setMax(int max) {
this.mMax = max;
}
@Override
public void setProgress(int progress) {
this.mProgress = progress;
mInBound.set(mBoundGap, mBoundGap,
(getWidth() - mBoundGap) * mProgress / mMax, getHeight() - mBoundGap);
invalidate();
}
}
================================================
FILE: kprogresshud/src/main/java/com/kaopiz/kprogresshud/Determinate.java
================================================
/*
* Copyright 2015 Kaopiz Software Co., Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.kaopiz.kprogresshud;
/**
* If a view implements this interface passed to the HUD as a custom view, its progress
* can be updated by calling setMax() and setProgress() on the HUD.
* This interface only provides convenience, how progress work depends on the view implementation.
*/
public interface Determinate {
void setMax(int max);
void setProgress(int progress);
}
================================================
FILE: kprogresshud/src/main/java/com/kaopiz/kprogresshud/Helper.java
================================================
/*
* Copyright 2015 Kaopiz Software Co., Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.kaopiz.kprogresshud;
import android.content.Context;
class Helper {
private static float scale;
public static int dpToPixel(float dp, Context context) {
if (scale == 0) {
scale = context.getResources().getDisplayMetrics().density;
}
return (int) (dp * scale);
}
}
================================================
FILE: kprogresshud/src/main/java/com/kaopiz/kprogresshud/Indeterminate.java
================================================
/*
* Copyright 2015 Kaopiz Software Co., Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.kaopiz.kprogresshud;
/**
* If a view implements this interface passed to the HUD as a custom view, its animation
* speed can be change by calling setAnimationSpeed() on the HUD.
* This interface only provides convenience, how animation speed work depends on the view implementation.
*/
public interface Indeterminate {
void setAnimationSpeed(float scale);
}
================================================
FILE: kprogresshud/src/main/java/com/kaopiz/kprogresshud/KProgressHUD.java
================================================
/*
* Copyright 2015 Kaopiz Software Co., Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.kaopiz.kprogresshud;
import android.app.Dialog;
import android.content.Context;
import android.graphics.drawable.ColorDrawable;
import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.view.WindowManager;
import android.widget.FrameLayout;
import android.widget.TextView;
public class KProgressHUD {
public enum Style {
SPIN_INDETERMINATE, PIE_DETERMINATE, ANNULAR_DETERMINATE, BAR_DETERMINATE
}
// To avoid redundant APIs, all HUD functions will be forward to
// a custom dialog
private ProgressDialog mProgressDialog;
private float mDimAmount;
private int mWindowColor;
private float mCornerRadius;
private boolean mCancellable;
private Context mContext;
private int mAnimateSpeed;
private String mLabel;
private String mDetailsLabel;
private int mMaxProgress;
private boolean mIsAutoDismiss;
public KProgressHUD(Context context) {
mContext = context;
mProgressDialog = new ProgressDialog(context);
mDimAmount = 0;
//noinspection deprecation
mWindowColor = context.getResources().getColor(R.color.kprogresshud_default_color);
mAnimateSpeed = 1;
mCornerRadius = 10;
mIsAutoDismiss = true;
setStyle(Style.SPIN_INDETERMINATE);
}
/**
* 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);
}
/**
* Specify the HUD style (not needed if you use a custom view)
* @param style One of the KProgressHUD.Style values
* @return Current HUD
*/
public KProgressHUD setStyle(Style style) {
View view = null;
switch (style) {
case SPIN_INDETERMINATE:
view = new SpinView(mContext);
break;
case PIE_DETERMINATE:
view = new PieView(mContext);
break;
case ANNULAR_DETERMINATE:
view = new AnnularView(mContext);
break;
case BAR_DETERMINATE:
view = new BarView(mContext);
break;
// No custom view style here, because view will be added later
}
mProgressDialog.setView(view);
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;
}
/**
* Specify corner radius of the HUD (default is 10)
* @param radius Corner radius in dp
* @return Current HUD
*/
public KProgressHUD setCornerRadius(float radius) {
mCornerRadius = radius;
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 setAnimationSpeed(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;
}
/**
* Set current progress. Only have effect when use with a determinate style, or a custom
* view which implements Determinate interface.
*/
public void setProgress(int progress) {
mProgressDialog.setProgress(progress);
}
/**
* Provide a custom view to be displayed.
* @param view Must not be null
* @return Current HUD
*/
public KProgressHUD setCustomView(View view) {
if (view != null) {
mProgressDialog.setView(view);
} else {
throw new RuntimeException("Custom view must not be null!");
}
return this;
}
/**
* Specify whether this HUD can be cancelled by using back button (default is false)
* @return Current HUD
*/
public KProgressHUD setCancellable(boolean isCancellable) {
mCancellable = isCancellable;
return this;
}
/**
* Specify whether this HUD closes itself if progress reaches max. Default is true.
* @return Current HUD
*/
public KProgressHUD setAutoDismiss(boolean isAutoDismiss) {
mIsAutoDismiss = isAutoDismiss;
return this;
}
public KProgressHUD show() {
if (!isShowing()) {
mProgressDialog.show();
}
return this;
}
public boolean isShowing() {
return mProgressDialog != null && mProgressDialog.isShowing();
}
public void dismiss() {
if (mProgressDialog != null && mProgressDialog.isShowing()) {
mProgressDialog.dismiss();
}
}
private class ProgressDialog extends Dialog {
private Determinate mDeterminateView;
private Indeterminate mIndeterminateView;
private View mView;
public ProgressDialog(Context context) {
super(context);
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.kprogresshud_hud);
Window window = getWindow();
window.setBackgroundDrawable(new ColorDrawable(0));
window.addFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND);
WindowManager.LayoutParams layoutParams = window.getAttributes();
layoutParams.dimAmount = mDimAmount;
window.setAttributes(layoutParams);
setCanceledOnTouchOutside(false);
setCancelable(mCancellable);
initViews();
}
private void initViews() {
BackgroundLayout background = (BackgroundLayout) findViewById(R.id.background);
background.setBaseColor(mWindowColor);
background.setCornerRadius(mCornerRadius);
FrameLayout containerFrame = (FrameLayout) findViewById(R.id.container);
int wrapParam = ViewGroup.LayoutParams.WRAP_CONTENT;
ViewGroup.LayoutParams params = new ViewGroup.LayoutParams(wrapParam, wrapParam);
containerFrame.addView(mView, params);
if (mDeterminateView != null) {
mDeterminateView.setMax(mMaxProgress);
}
if (mIndeterminateView != null) {
mIndeterminateView.setAnimationSpeed(mAnimateSpeed);
}
if (mLabel != null) {
TextView labelText = (TextView) findViewById(R.id.label);
labelText.setText(mLabel);
labelText.setVisibility(View.VISIBLE);
}
if (mDetailsLabel != null) {
TextView detailsText = (TextView) findViewById(R.id.details_label);
detailsText.setText(mDetailsLabel);
detailsText.setVisibility(View.VISIBLE);
}
}
public void setProgress(int progress) {
if (mDeterminateView != null) {
mDeterminateView.setProgress(progress);
if (mIsAutoDismiss && progress >= mMaxProgress) {
dismiss();
}
}
}
public void setView(View view) {
if (view != null) {
if (view instanceof Determinate) {
mDeterminateView = (Determinate) view;
}
if (view instanceof Indeterminate) {
mIndeterminateView = (Indeterminate) view;
}
mView = view;
}
}
}
}
================================================
FILE: kprogresshud/src/main/java/com/kaopiz/kprogresshud/PieView.java
================================================
/*
* Copyright 2015 Kaopiz Software Co., Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.kaopiz.kprogresshud;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.RectF;
import android.util.AttributeSet;
import android.view.View;
class PieView extends View implements Determinate {
private Paint mWhitePaint;
private Paint mGreyPaint;
private RectF mBound;
private int mMax = 100;
private int mProgress = 0;
public PieView(Context context) {
super(context);
init();
}
public PieView(Context context, AttributeSet attrs) {
super(context, attrs);
init();
}
public PieView(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
init();
}
private void init(){
mWhitePaint = new Paint(Paint.ANTI_ALIAS_FLAG);
mWhitePaint.setStyle(Paint.Style.FILL_AND_STROKE);
mWhitePaint.setStrokeWidth(Helper.dpToPixel(0.1f, getContext()));
mWhitePaint.setColor(Color.WHITE);
mGreyPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
mGreyPaint.setStyle(Paint.Style.STROKE);
mGreyPaint.setStrokeWidth(Helper.dpToPixel(2, getContext()));
mGreyPaint.setColor(Color.WHITE);
mBound = new RectF();
}
@Override
protected void onSizeChanged(int w, int h, int oldw, int oldh) {
super.onSizeChanged(w, h, oldw, oldh);
int padding = Helper.dpToPixel(4, getContext());
mBound.set(padding, padding, w - padding, h - padding);
}
@Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
float mAngle = mProgress * 360f / mMax;
canvas.drawArc(mBound, 270, mAngle, true, mWhitePaint);
int padding = Helper.dpToPixel(4, getContext());
canvas.drawCircle(getWidth()/2, getHeight()/2, getWidth()/2-padding, mGreyPaint);
}
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
int dimension = Helper.dpToPixel(40, getContext());
setMeasuredDimension(dimension, dimension);
}
@Override
public void setMax(int max) {
this.mMax = max;
}
@Override
public void setProgress(int progress) {
this.mProgress = progress;
invalidate();
}
}
================================================
FILE: kprogresshud/src/main/java/com/kaopiz/kprogresshud/SpinView.java
================================================
/*
* Copyright 2015 Kaopiz Software Co., Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.kaopiz.kprogresshud;
import android.content.Context;
import android.graphics.Canvas;
import android.util.AttributeSet;
import android.widget.ImageView;
class SpinView extends ImageView implements Indeterminate {
private float mRotateDegrees;
private int mFrameTime;
private boolean mNeedToUpdateView;
private Runnable mUpdateViewRunnable;
public SpinView(Context context) {
super(context);
init();
}
public SpinView(Context context, AttributeSet attrs) {
super(context, attrs);
init();
}
private void init() {
setImageResource(R.drawable.kprogresshud_spinner);
mFrameTime = 1000 / 12;
mUpdateViewRunnable = new Runnable() {
@Override
public void run() {
mRotateDegrees += 30;
mRotateDegrees = mRotateDegrees < 360 ? mRotateDegrees : mRotateDegrees - 360;
invalidate();
if (mNeedToUpdateView) {
postDelayed(this, mFrameTime);
}
}
};
}
@Override
public void setAnimationSpeed(float scale) {
mFrameTime = (int) (1000 / 12 / scale);
}
@Override
protected void onDraw(Canvas canvas) {
canvas.rotate(mRotateDegrees, getWidth() / 2, getHeight() / 2);
super.onDraw(canvas);
}
@Override
protected void onAttachedToWindow() {
super.onAttachedToWindow();
mNeedToUpdateView = true;
post(mUpdateViewRunnable);
}
@Override
protected void onDetachedFromWindow() {
mNeedToUpdateView = false;
super.onDetachedFromWindow();
}
}
================================================
FILE: kprogresshud/src/main/res/layout/kprogresshud_hud.xml
================================================
================================================
FILE: kprogresshud/src/main/res/values/colors.xml
================================================
#b1000000#449E9E9E
================================================
FILE: kprogresshud/src/test/java/com/kaopiz/kprogresshud/ExampleUnitTest.java
================================================
package com.kaopiz.kprogresshud;
import org.junit.Test;
import static org.junit.Assert.*;
/**
* To work on unit tests, switch the Test Artifact in the Build Variants view.
*/
public class ExampleUnitTest {
@Test
public void addition_isCorrect() throws Exception {
assertEquals(4, 2 + 2);
}
}
================================================
FILE: settings.gradle
================================================
include ':demo', ':kprogresshud'