├── settings.gradle
├── exampleapp
├── ic_launcher-web.png
├── libs
│ └── android-support-v4.jar
├── res
│ ├── drawable-hdpi
│ │ ├── edinburgh.jpg
│ │ ├── ic_drawer.png
│ │ ├── ic_launcher.png
│ │ ├── operahuset.jpg
│ │ ├── holyroodpark.jpg
│ │ ├── blenheim_palace.jpg
│ │ ├── drawer_shadow.9.png
│ │ └── millennium_stadium.jpg
│ ├── drawable-mdpi
│ │ └── ic_launcher.png
│ ├── drawable-xhdpi
│ │ └── ic_launcher.png
│ ├── drawable-xxhdpi
│ │ └── ic_launcher.png
│ ├── values-sw600dp
│ │ └── dimens.xml
│ ├── values-sw720dp-land
│ │ └── dimens.xml
│ ├── values
│ │ ├── colors.xml
│ │ ├── dimens.xml
│ │ ├── strings.xml
│ │ └── styles.xml
│ └── layout
│ │ ├── lv_github.xml
│ │ ├── lv_colour_text.xml
│ │ ├── lv_style.xml
│ │ ├── lv_signer.xml
│ │ ├── activity_main.xml
│ │ ├── lv_header_layout.xml
│ │ ├── lv_image.xml
│ │ ├── lv_colour.xml
│ │ ├── lv_style_box.xml
│ │ ├── square_layout.xml
│ │ ├── customcolourdialog.xml
│ │ └── percentdialog.xml
├── project.properties
├── AndroidManifest.xml
├── build.gradle
└── src
│ └── ch
│ └── halcyon
│ └── squareprogressbar
│ └── example
│ ├── PreviewView.java
│ ├── dialogs
│ ├── CustomColourDialog.java
│ └── PercentDialog.java
│ ├── SquareFragment.java
│ └── MainActivity.java
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── squareprogressbar
├── res
│ ├── drawable-hdpi
│ │ └── ic_spb_empty.png
│ ├── values
│ │ └── strings.xml
│ ├── values-v11
│ │ └── styles.xml
│ ├── values-v14
│ │ └── styles.xml
│ └── layout
│ │ └── progressbarview.xml
├── src
│ └── ch
│ │ └── halcyon
│ │ └── squareprogressbar
│ │ ├── utils
│ │ ├── CalculationUtil.java
│ │ ├── ColourUtil.java
│ │ └── PercentStyle.java
│ │ ├── SquareProgressView.java
│ │ └── SquareProgressBar.java
├── AndroidManifest.xml
├── project.properties
└── build.gradle
├── .gitignore
├── android-square-progressbar.iml
├── gradlew.bat
├── README.md
└── gradlew
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':exampleapp'
2 | include ':squareprogressbar'
3 |
--------------------------------------------------------------------------------
/exampleapp/ic_launcher-web.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mrwonderman/android-square-progressbar/HEAD/exampleapp/ic_launcher-web.png
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mrwonderman/android-square-progressbar/HEAD/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/exampleapp/libs/android-support-v4.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mrwonderman/android-square-progressbar/HEAD/exampleapp/libs/android-support-v4.jar
--------------------------------------------------------------------------------
/exampleapp/res/drawable-hdpi/edinburgh.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mrwonderman/android-square-progressbar/HEAD/exampleapp/res/drawable-hdpi/edinburgh.jpg
--------------------------------------------------------------------------------
/exampleapp/res/drawable-hdpi/ic_drawer.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mrwonderman/android-square-progressbar/HEAD/exampleapp/res/drawable-hdpi/ic_drawer.png
--------------------------------------------------------------------------------
/exampleapp/res/drawable-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mrwonderman/android-square-progressbar/HEAD/exampleapp/res/drawable-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/exampleapp/res/drawable-hdpi/operahuset.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mrwonderman/android-square-progressbar/HEAD/exampleapp/res/drawable-hdpi/operahuset.jpg
--------------------------------------------------------------------------------
/exampleapp/res/drawable-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mrwonderman/android-square-progressbar/HEAD/exampleapp/res/drawable-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/exampleapp/res/drawable-hdpi/holyroodpark.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mrwonderman/android-square-progressbar/HEAD/exampleapp/res/drawable-hdpi/holyroodpark.jpg
--------------------------------------------------------------------------------
/exampleapp/res/drawable-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mrwonderman/android-square-progressbar/HEAD/exampleapp/res/drawable-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/exampleapp/res/drawable-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mrwonderman/android-square-progressbar/HEAD/exampleapp/res/drawable-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/exampleapp/res/drawable-hdpi/blenheim_palace.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mrwonderman/android-square-progressbar/HEAD/exampleapp/res/drawable-hdpi/blenheim_palace.jpg
--------------------------------------------------------------------------------
/exampleapp/res/drawable-hdpi/drawer_shadow.9.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mrwonderman/android-square-progressbar/HEAD/exampleapp/res/drawable-hdpi/drawer_shadow.9.png
--------------------------------------------------------------------------------
/exampleapp/res/drawable-hdpi/millennium_stadium.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mrwonderman/android-square-progressbar/HEAD/exampleapp/res/drawable-hdpi/millennium_stadium.jpg
--------------------------------------------------------------------------------
/squareprogressbar/res/drawable-hdpi/ic_spb_empty.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mrwonderman/android-square-progressbar/HEAD/squareprogressbar/res/drawable-hdpi/ic_spb_empty.png
--------------------------------------------------------------------------------
/squareprogressbar/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | android-square-progressbar
4 | That's the image to draw the progressbar around.
5 |
6 |
--------------------------------------------------------------------------------
/exampleapp/res/values-sw600dp/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
7 |
8 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Wed Mar 28 21:29:05 BST 2018
2 | distributionBase=GRADLE_USER_HOME
3 | distributionPath=wrapper/dists
4 | zipStoreBase=GRADLE_USER_HOME
5 | zipStorePath=wrapper/dists
6 | distributionUrl=https\://services.gradle.org/distributions/gradle-4.5-all.zip
7 |
--------------------------------------------------------------------------------
/exampleapp/res/values-sw720dp-land/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
7 | 128dp
8 |
9 |
--------------------------------------------------------------------------------
/exampleapp/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | #168686
5 | #333333
6 | #777777
7 | #168686
8 | #FFFFFF
9 |
10 |
--------------------------------------------------------------------------------
/squareprogressbar/res/values-v11/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
7 |
10 |
11 |
--------------------------------------------------------------------------------
/squareprogressbar/src/ch/halcyon/squareprogressbar/utils/CalculationUtil.java:
--------------------------------------------------------------------------------
1 | package ch.halcyon.squareprogressbar.utils;
2 |
3 | import android.content.Context;
4 | import android.util.TypedValue;
5 |
6 | public class CalculationUtil {
7 |
8 | public static int convertDpToPx(float dp, Context context) {
9 | return (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dp,
10 | context.getResources().getDisplayMetrics());
11 | }
12 | }
13 |
--------------------------------------------------------------------------------
/squareprogressbar/res/values-v14/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
8 |
11 |
12 |
--------------------------------------------------------------------------------
/squareprogressbar/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
5 |
6 |
9 |
10 |
13 |
14 |
15 |
--------------------------------------------------------------------------------
/squareprogressbar/project.properties:
--------------------------------------------------------------------------------
1 | # This file is automatically generated by Android Tools.
2 | # Do not modify this file -- YOUR CHANGES WILL BE ERASED!
3 | #
4 | # This file must be checked in Version Control Systems.
5 | #
6 | # To customize properties used by the Ant build system edit
7 | # "ant.properties", and override values to adapt the script to your
8 | # project structure.
9 | #
10 | # To enable ProGuard to shrink and obfuscate your code, uncomment this (available properties: sdk.dir, user.home):
11 | #proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt
12 |
13 | # Project target.
14 | target=android-17
15 | android.library=true
16 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | # built application files
2 | *.apk
3 | *.ap_
4 |
5 | # files for the dex VM
6 | *.dex
7 |
8 | # Java class files
9 | *.class
10 |
11 | # generated files
12 | bin/
13 | gen/
14 | out/
15 | build/
16 |
17 | # Local configuration file (sdk path, etc)
18 | local.properties
19 |
20 | # Eclipse project files
21 | .classpath
22 | .project
23 |
24 | # Windows thumbnail db
25 | .DS_Store
26 |
27 | # IDEA/Android Studio project files, because
28 | # the project can be imported from settings.gradle
29 | .idea
30 | *.iml
31 |
32 | # Old-style IDEA project files
33 | *.ipr
34 | *.iws
35 |
36 | # Local IDEA workspace
37 | .idea/workspace.xml
38 |
39 | # Gradle cache
40 | .gradle
--------------------------------------------------------------------------------
/exampleapp/project.properties:
--------------------------------------------------------------------------------
1 | # This file is automatically generated by Android Tools.
2 | # Do not modify this file -- YOUR CHANGES WILL BE ERASED!
3 | #
4 | # This file must be checked in Version Control Systems.
5 | #
6 | # To customize properties used by the Ant build system edit
7 | # "ant.properties", and override values to adapt the script to your
8 | # project structure.
9 | #
10 | # To enable ProGuard to shrink and obfuscate your code, uncomment this (available properties: sdk.dir, user.home):
11 | #proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt
12 |
13 | # Project target.
14 | target=android-17
15 | android.library.reference.1=../android-square-progressbar
16 |
--------------------------------------------------------------------------------
/squareprogressbar/src/ch/halcyon/squareprogressbar/utils/ColourUtil.java:
--------------------------------------------------------------------------------
1 | package ch.halcyon.squareprogressbar.utils;
2 |
3 | import java.util.ArrayList;
4 |
5 | import android.R.color;
6 |
7 | public class ColourUtil {
8 | static ArrayList colourArray = new ArrayList();
9 |
10 | public static ArrayList getColourArray() {
11 | colourArray.add(color.holo_blue_bright);
12 | colourArray.add(color.holo_blue_dark);
13 | colourArray.add(color.holo_blue_light);
14 | colourArray.add(color.holo_green_dark);
15 | colourArray.add(color.holo_green_light);
16 | colourArray.add(color.holo_orange_dark);
17 | colourArray.add(color.holo_orange_light);
18 | colourArray.add(color.holo_purple);
19 | colourArray.add(color.holo_red_dark);
20 | colourArray.add(color.holo_red_light);
21 | return colourArray;
22 | }
23 | }
24 |
--------------------------------------------------------------------------------
/android-square-progressbar.iml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
--------------------------------------------------------------------------------
/exampleapp/res/values/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | 16dp
5 | 16dp
6 |
7 | 18sp
8 | 14sp
9 | 65dp
10 | 14sp
11 | 6dp
12 | 1dp
13 | 8dp
14 | 2dp
15 | 6dp
16 | 8dp
17 | 1dp
18 | 5dp
19 |
20 |
--------------------------------------------------------------------------------
/exampleapp/res/layout/lv_github.xml:
--------------------------------------------------------------------------------
1 |
5 |
6 |
12 |
13 |
23 |
24 |
--------------------------------------------------------------------------------
/exampleapp/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
10 |
11 |
16 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
--------------------------------------------------------------------------------
/exampleapp/res/layout/lv_colour_text.xml:
--------------------------------------------------------------------------------
1 |
6 |
7 |
13 |
14 |
24 |
25 |
--------------------------------------------------------------------------------
/exampleapp/res/layout/lv_style.xml:
--------------------------------------------------------------------------------
1 |
6 |
7 |
14 |
15 |
25 |
26 |
--------------------------------------------------------------------------------
/squareprogressbar/res/layout/progressbarview.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 |
14 |
15 |
25 |
26 |
--------------------------------------------------------------------------------
/exampleapp/res/layout/lv_signer.xml:
--------------------------------------------------------------------------------
1 |
5 |
6 |
12 |
13 |
25 |
26 |
--------------------------------------------------------------------------------
/exampleapp/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
7 |
8 |
12 |
13 |
27 |
28 |
--------------------------------------------------------------------------------
/exampleapp/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 |
3 | dependencies {
4 | compile fileTree(dir: 'libs', include: '*.jar')
5 | compile project(':squareprogressbar')
6 | }
7 |
8 | android {
9 | compileSdkVersion 17
10 | buildToolsVersion '27.0.3'
11 |
12 | sourceSets {
13 | main {
14 | manifest.srcFile 'AndroidManifest.xml'
15 | java.srcDirs = ['src']
16 | resources.srcDirs = ['src']
17 | aidl.srcDirs = ['src']
18 | renderscript.srcDirs = ['src']
19 | res.srcDirs = ['res']
20 | assets.srcDirs = ['assets']
21 | }
22 |
23 | // Move the tests to tests/java, tests/res, etc...
24 | // instrumentTest.setRoot('tests')
25 |
26 | // Move the build types to build-types/
27 | // For instance, build-types/debug/java, build-types/debug/AndroidManifest.xml, ...
28 | // This moves them out of them default location under src//... which would
29 | // conflict with src/ being used by the main source set.
30 | // Adding new build types or product flavors should be accompanied
31 | // by a similar customization.
32 | debug.setRoot('build-types/debug')
33 | release.setRoot('build-types/release')
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/exampleapp/res/layout/lv_header_layout.xml:
--------------------------------------------------------------------------------
1 |
7 |
8 |
16 |
17 |
30 |
31 |
--------------------------------------------------------------------------------
/exampleapp/res/layout/lv_image.xml:
--------------------------------------------------------------------------------
1 |
5 |
6 |
12 |
13 |
22 |
23 |
33 |
34 |
--------------------------------------------------------------------------------
/exampleapp/res/layout/lv_colour.xml:
--------------------------------------------------------------------------------
1 |
6 |
7 |
13 |
14 |
23 |
24 |
34 |
35 |
--------------------------------------------------------------------------------
/exampleapp/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | android-square-progressbar-example
5 | Progress:
6 | Width:
7 | Opacity
8 |
9 |
10 | Open navigation drawer
11 | Close navigation drawer
12 |
13 |
14 | - Colour
15 | - Subitem One
16 | - Subitem Two
17 | - Style
18 | - Subitem Three
19 | - Title Three
20 | - Subitem Four
21 | - Subitem Five
22 |
23 |
24 |
25 | - Description One
26 | - Description Two
27 |
28 | - Description Three
29 |
30 | - Description Four
31 | - Description Five
32 |
33 |
34 | - CENTER
35 | - RIGHT
36 | - LEFT
37 |
38 |
39 | by Yannick Signer (halcyon.ch)
40 | main image of the progressbar
41 | (000,000,000)
42 | Green:
43 | Cancel
44 | Save
45 | Blue:
46 | RGB COLOUR:
47 | Red:
48 |
49 |
--------------------------------------------------------------------------------
/exampleapp/res/layout/lv_style_box.xml:
--------------------------------------------------------------------------------
1 |
6 |
7 |
14 |
15 |
25 |
26 |
36 |
37 |
45 |
46 |
--------------------------------------------------------------------------------
/squareprogressbar/src/ch/halcyon/squareprogressbar/utils/PercentStyle.java:
--------------------------------------------------------------------------------
1 | package ch.halcyon.squareprogressbar.utils;
2 |
3 | import android.graphics.Color;
4 | import android.graphics.Paint;
5 | import android.graphics.Paint.Align;
6 |
7 | public class PercentStyle {
8 | private Paint.Align align;
9 | private float textSize;
10 | private boolean percentSign;
11 | private String customText = "%";
12 | private int textColor = Color.BLACK;
13 |
14 | public PercentStyle() {
15 | // do nothing
16 | }
17 |
18 | public PercentStyle(Align align, float textSize, boolean percentSign) {
19 | super();
20 | this.align = align;
21 | this.textSize = textSize;
22 | this.percentSign = percentSign;
23 | }
24 |
25 | public Paint.Align getAlign() {
26 | return align;
27 | }
28 |
29 | public void setAlign(Paint.Align align) {
30 | this.align = align;
31 | }
32 |
33 | public float getTextSize() {
34 | return textSize;
35 | }
36 |
37 | public void setTextSize(float textSize) {
38 | this.textSize = textSize;
39 | }
40 |
41 | public boolean isPercentSign() {
42 | return percentSign;
43 | }
44 |
45 | public void setPercentSign(boolean percentSign) {
46 | this.percentSign = percentSign;
47 | }
48 |
49 | public String getCustomText() {
50 | return customText;
51 | }
52 |
53 | /**
54 | * With this you can set a custom text which should get displayed right
55 | * behind the number of the progress. Per default it displays a %.
56 | *
57 | * @param customText
58 | * The custom text you want to display.
59 | * @since 1.4.0
60 | */
61 | public void setCustomText(String customText) {
62 | this.customText = customText;
63 | }
64 |
65 | public int getTextColor() {
66 | return textColor;
67 | }
68 |
69 | /**
70 | * Set the color of the text that display the current progress. This will
71 | * also change the color of the text that normally represents a %.
72 | *
73 | * @param textColor
74 | * the color to set the text to.
75 | * @since 1.4.0
76 | */
77 | public void setTextColor(int textColor) {
78 | this.textColor = textColor;
79 | }
80 |
81 | }
--------------------------------------------------------------------------------
/exampleapp/src/ch/halcyon/squareprogressbar/example/PreviewView.java:
--------------------------------------------------------------------------------
1 | package ch.halcyon.squareprogressbar.example;
2 |
3 | import android.content.Context;
4 | import android.graphics.Canvas;
5 | import android.graphics.Paint;
6 | import android.graphics.Paint.Align;
7 | import android.graphics.Paint.Style;
8 | import android.graphics.Path;
9 | import android.util.AttributeSet;
10 | import android.view.View;
11 |
12 | public class PreviewView extends View {
13 |
14 | private final Paint paintPaint;
15 | private Align center = Align.CENTER;
16 | private float size = 150;
17 | private boolean b = true;
18 |
19 | public PreviewView(Context context) {
20 | super(context);
21 |
22 | paintPaint = new Paint();
23 | paintPaint.setColor(context.getResources().getColor(
24 | android.R.color.black));
25 | paintPaint.setAntiAlias(true);
26 | paintPaint.setStyle(Style.STROKE);
27 | }
28 |
29 | public PreviewView(Context context, AttributeSet attrs, int defStyle) {
30 | super(context, attrs, defStyle);
31 |
32 | paintPaint = new Paint();
33 | paintPaint.setColor(context.getResources().getColor(
34 | android.R.color.black));
35 | paintPaint.setAntiAlias(true);
36 | paintPaint.setStyle(Style.STROKE);
37 | }
38 |
39 | public PreviewView(Context context, AttributeSet attrs) {
40 | super(context, attrs);
41 |
42 | paintPaint = new Paint();
43 | paintPaint.setColor(context.getResources().getColor(
44 | android.R.color.black));
45 | paintPaint.setAntiAlias(true);
46 | paintPaint.setStyle(Style.STROKE);
47 | }
48 |
49 | @Override
50 | protected void onDraw(Canvas canvas) {
51 | super.onDraw(canvas);
52 | Path path = new Path();
53 | path.moveTo(0, 0);
54 | path.lineTo(0, canvas.getWidth());
55 | path.lineTo(canvas.getHeight(), canvas.getWidth());
56 | path.lineTo(canvas.getHeight(), 0);
57 | path.lineTo(0, 0);
58 | canvas.drawPath(path, paintPaint);
59 | paintPaint.setTextAlign(center);
60 | paintPaint.setTextSize(Float.valueOf(String.valueOf(size)));
61 | canvas.drawText(b ? "32%" : "32", canvas.getWidth() / 2, (int) ((canvas
62 | .getHeight() / 2) - ((paintPaint.descent() + paintPaint
63 | .ascent()) / 2)), paintPaint);
64 | }
65 |
66 | public void drawText(int size, Align center, boolean b) {
67 | this.size = size;
68 | this.center = center;
69 | this.b = b;
70 | this.invalidate();
71 | }
72 |
73 | }
74 |
--------------------------------------------------------------------------------
/gradlew.bat:
--------------------------------------------------------------------------------
1 | @if "%DEBUG%" == "" @echo off
2 | @rem ##########################################################################
3 | @rem
4 | @rem Gradle startup script for Windows
5 | @rem
6 | @rem ##########################################################################
7 |
8 | @rem Set local scope for the variables with windows NT shell
9 | if "%OS%"=="Windows_NT" setlocal
10 |
11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
12 | set DEFAULT_JVM_OPTS=
13 |
14 | set DIRNAME=%~dp0
15 | if "%DIRNAME%" == "" set DIRNAME=.
16 | set APP_BASE_NAME=%~n0
17 | set APP_HOME=%DIRNAME%
18 |
19 | @rem Find java.exe
20 | if defined JAVA_HOME goto findJavaFromJavaHome
21 |
22 | set JAVA_EXE=java.exe
23 | %JAVA_EXE% -version >NUL 2>&1
24 | if "%ERRORLEVEL%" == "0" goto init
25 |
26 | echo.
27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
28 | echo.
29 | echo Please set the JAVA_HOME variable in your environment to match the
30 | echo location of your Java installation.
31 |
32 | goto fail
33 |
34 | :findJavaFromJavaHome
35 | set JAVA_HOME=%JAVA_HOME:"=%
36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
37 |
38 | if exist "%JAVA_EXE%" goto init
39 |
40 | echo.
41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
42 | echo.
43 | echo Please set the JAVA_HOME variable in your environment to match the
44 | echo location of your Java installation.
45 |
46 | goto fail
47 |
48 | :init
49 | @rem Get command-line arguments, handling Windowz variants
50 |
51 | if not "%OS%" == "Windows_NT" goto win9xME_args
52 | if "%@eval[2+2]" == "4" goto 4NT_args
53 |
54 | :win9xME_args
55 | @rem Slurp the command line arguments.
56 | set CMD_LINE_ARGS=
57 | set _SKIP=2
58 |
59 | :win9xME_args_slurp
60 | if "x%~1" == "x" goto execute
61 |
62 | set CMD_LINE_ARGS=%*
63 | goto execute
64 |
65 | :4NT_args
66 | @rem Get arguments from the 4NT Shell from JP Software
67 | set CMD_LINE_ARGS=%$
68 |
69 | :execute
70 | @rem Setup the command line
71 |
72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
73 |
74 | @rem Execute Gradle
75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
76 |
77 | :end
78 | @rem End local scope for the variables with windows NT shell
79 | if "%ERRORLEVEL%"=="0" goto mainEnd
80 |
81 | :fail
82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
83 | rem the _cmd.exe /c_ return code!
84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
85 | exit /b 1
86 |
87 | :mainEnd
88 | if "%OS%"=="Windows_NT" endlocal
89 |
90 | :omega
91 |
--------------------------------------------------------------------------------
/exampleapp/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
8 |
9 |
14 |
15 |
19 |
20 |
27 |
28 |
35 |
62 |
63 |
--------------------------------------------------------------------------------
/exampleapp/res/layout/square_layout.xml:
--------------------------------------------------------------------------------
1 |
10 |
11 |
18 |
19 |
20 |
30 |
31 |
40 |
41 |
49 |
50 |
61 |
62 |
71 |
72 |
--------------------------------------------------------------------------------
/squareprogressbar/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.library'
2 | apply plugin: 'com.github.dcendents.android-maven'
3 | apply plugin: "com.jfrog.bintray"
4 |
5 | version = "1.6.4"
6 |
7 | android {
8 | compileSdkVersion 17
9 | buildToolsVersion '27.0.3'
10 |
11 | sourceSets {
12 | main {
13 | manifest.srcFile 'AndroidManifest.xml'
14 | java.srcDirs = ['src']
15 | resources.srcDirs = ['src']
16 | aidl.srcDirs = ['src']
17 | renderscript.srcDirs = ['src']
18 | res.srcDirs = ['res']
19 | assets.srcDirs = ['assets']
20 | }}
21 |
22 | defaultConfig {
23 | minSdkVersion 14
24 | targetSdkVersion 17
25 | versionCode 11
26 | versionName version
27 | }
28 |
29 | buildTypes {
30 | }
31 | }
32 |
33 | dependencies {
34 | }
35 |
36 | def siteUrl = 'https://github.com/mrwonderman/android-square-progressbar' // Homepage URL of the library
37 | def gitUrl = 'https://github.com/mrwonderman/android-square-progressbar.git' // Git repository URL
38 | group = "ch.halcyon" // Maven Group ID for the artifact
39 |
40 |
41 | install {
42 | repositories.mavenInstaller {
43 | // This generates POM.xml with proper parameters
44 | pom {
45 | project {
46 | packaging 'aar'
47 |
48 | // Add your description here
49 | name 'android-square-progressbar'
50 | //description = 'An android library to display a progressbar that goes around an image.'
51 | url siteUrl
52 |
53 | // Set your license
54 | licenses {
55 | license {
56 | name 'The Apache Software License, Version 2.0'
57 | url 'http://www.apache.org/licenses/LICENSE-2.0.txt'
58 | }
59 | }
60 | developers {
61 | developer {
62 | id 'yansigner'
63 | name 'Yannick Signer'
64 | email 'yannick@signer.pro'
65 | }
66 | }
67 | scm {
68 | connection gitUrl
69 | developerConnection gitUrl
70 | url siteUrl
71 |
72 | }
73 | }
74 | }
75 | }
76 | }
77 |
78 | task sourcesJar(type: Jar) {
79 | from android.sourceSets.main.java.srcDirs
80 | classifier = 'sources'
81 | }
82 |
83 | task javadoc(type: Javadoc) {
84 | source = android.sourceSets.main.java.srcDirs
85 | classpath += project.files(android.getBootClasspath().join(File.pathSeparator))
86 | }
87 |
88 | task javadocJar(type: Jar, dependsOn: javadoc) {
89 | classifier = 'javadoc'
90 | from javadoc.destinationDir
91 | }
92 | artifacts {
93 | archives javadocJar
94 | archives sourcesJar
95 | }
96 |
97 | Properties properties = new Properties()
98 | properties.load(project.rootProject.file('local.properties').newDataInputStream())
99 |
100 | bintray {
101 | user = properties.getProperty("bintray.user")
102 | key = properties.getProperty("bintray.apikey")
103 |
104 | configurations = ['archives']
105 | pkg {
106 | repo = "maven"
107 | // it is the name that appears in bintray when logged
108 | name = "squareprogressbar"
109 | websiteUrl = siteUrl
110 | vcsUrl = gitUrl
111 | licenses = ["Apache-2.0"]
112 | publish = true
113 | }
114 | }
--------------------------------------------------------------------------------
/exampleapp/src/ch/halcyon/squareprogressbar/example/dialogs/CustomColourDialog.java:
--------------------------------------------------------------------------------
1 | package ch.halcyon.squareprogressbar.example.dialogs;
2 |
3 | import ch.halcyon.squareprogressbar.example.R;
4 | import android.app.Dialog;
5 | import android.content.Context;
6 | import android.graphics.Color;
7 | import android.graphics.drawable.ColorDrawable;
8 | import android.view.View;
9 | import android.view.Window;
10 | import android.widget.Button;
11 | import android.widget.SeekBar;
12 | import android.widget.SeekBar.OnSeekBarChangeListener;
13 | import android.widget.TextView;
14 |
15 | /**
16 | * This gives the user the possibility to set a custom colour to the
17 | * SquareProgressBar by selecting a RGB-colour.
18 | *
19 | * @author yansigner
20 | * @since 1.4.0
21 | */
22 | public class CustomColourDialog extends Dialog {
23 |
24 | private final Button saveButton;
25 | private SeekBar rSeekBar;
26 | private SeekBar gSeekBar;
27 | private SeekBar bSeekBar;
28 | private int choosenRGB;
29 |
30 | public CustomColourDialog(final Context context) {
31 | super(context);
32 | requestWindowFeature(Window.FEATURE_NO_TITLE);
33 | this.setContentView(R.layout.customcolourdialog);
34 | this.setCancelable(false);
35 |
36 | Button closeButton = (Button) this
37 | .findViewById(R.id.returnColourDialog);
38 | closeButton.setOnClickListener(new View.OnClickListener() {
39 |
40 | @Override
41 | public void onClick(View v) {
42 | dismiss();
43 | }
44 | });
45 | saveButton = (Button) this.findViewById(R.id.shareColourDialog);
46 |
47 | rSeekBar = (SeekBar) findViewById(R.id.rSeekBar);
48 | rSeekBar.setMax(255);
49 | rSeekBar.setProgress(111);
50 | rSeekBar.setOnSeekBarChangeListener(rgbOnSeekBarListener());
51 |
52 | gSeekBar = (SeekBar) findViewById(R.id.gSeekBar);
53 | gSeekBar.setMax(255);
54 | gSeekBar.setProgress(111);
55 | gSeekBar.setOnSeekBarChangeListener(rgbOnSeekBarListener());
56 |
57 | bSeekBar = (SeekBar) findViewById(R.id.bSeekBar);
58 | bSeekBar.setMax(255);
59 | bSeekBar.setProgress(111);
60 | bSeekBar.setOnSeekBarChangeListener(rgbOnSeekBarListener());
61 |
62 | calculateRGB();
63 |
64 | }
65 |
66 | private OnSeekBarChangeListener rgbOnSeekBarListener() {
67 | return new OnSeekBarChangeListener() {
68 |
69 | @Override
70 | public void onStopTrackingTouch(SeekBar arg0) {
71 | // nothing to do =)
72 | }
73 |
74 | @Override
75 | public void onStartTrackingTouch(SeekBar arg0) {
76 | // nothing to do =)
77 |
78 | }
79 |
80 | @Override
81 | public void onProgressChanged(SeekBar arg0, int arg1, boolean arg2) {
82 | calculateRGB();
83 | }
84 | };
85 | }
86 |
87 | /**
88 | * Returns the save button of the dialog.
89 | *
90 | * @return the save {@link Button}.
91 | */
92 | public Button getSaveButton() {
93 | return saveButton;
94 | }
95 |
96 | /**
97 | * Calculates the current set RGB value according to the three
98 | * {@link SeekBar}s. This also changes the background of the Dialog.
99 | */
100 | private void calculateRGB() {
101 | int r = rSeekBar.getProgress();
102 | int g = gSeekBar.getProgress();
103 | int b = bSeekBar.getProgress();
104 | ((TextView) findViewById(R.id.rgbText)).setText("(" + r + "," + g + ","
105 | + b + ")");
106 | choosenRGB = Color.rgb(r, g, b);
107 | getWindow().setBackgroundDrawable(new ColorDrawable(choosenRGB));
108 | }
109 |
110 | /**
111 | * Returns the Color which was chosen in the Dialog.
112 | *
113 | * @return the chosen RGB-colour.
114 | */
115 | public int getChoosenRGB() {
116 | return choosenRGB;
117 | }
118 | }
119 |
--------------------------------------------------------------------------------
/exampleapp/src/ch/halcyon/squareprogressbar/example/SquareFragment.java:
--------------------------------------------------------------------------------
1 | package ch.halcyon.squareprogressbar.example;
2 |
3 | import ch.halcyon.squareprogressbar.SquareProgressBar;
4 |
5 | import android.app.Fragment;
6 | import android.os.Bundle;
7 | import android.view.LayoutInflater;
8 | import android.view.View;
9 | import android.view.ViewGroup;
10 | import android.widget.SeekBar;
11 | import android.widget.SeekBar.OnSeekBarChangeListener;
12 | import android.widget.TextView;
13 |
14 | import java.util.Random;
15 |
16 | public class SquareFragment extends Fragment {
17 | public SquareProgressBar squareProgressBar;
18 | private SeekBar progressSeekBar, widthSeekBar;
19 |
20 | @Override
21 | public View onCreateView(LayoutInflater inflater, ViewGroup container,
22 | Bundle savedInstanceState) {
23 | View view = inflater.inflate(ch.halcyon.squareprogressbar.example.R.layout.square_layout, container, false);
24 |
25 | final TextView progressView = (TextView) view
26 | .findViewById(ch.halcyon.squareprogressbar.example.R.id.progressDisplay);
27 | progressView.setText("32%");
28 |
29 | squareProgressBar = (SquareProgressBar) view.findViewById(ch.halcyon.squareprogressbar.example.R.id.subi2);
30 | squareProgressBar.setImage(ch.halcyon.squareprogressbar.example.R.drawable.blenheim_palace);
31 | squareProgressBar.setColor("#C9C9C9");
32 | squareProgressBar.setProgress(32);
33 | squareProgressBar.setWidth(8);
34 | squareProgressBar.setOnClickListener(new View.OnClickListener() {
35 | @Override
36 | public void onClick(View view) {
37 |
38 | Random random = new Random();
39 |
40 | // random progress
41 | setProgressBarProgress(random.nextInt(100), progressView);
42 |
43 | // random width
44 | int randWidth = random.nextInt(17) + 4;
45 | widthSeekBar.setProgress(randWidth);
46 | squareProgressBar.setWidth(randWidth);
47 |
48 | // random colour
49 | squareProgressBar.setColorRGB(random.nextInt(256), random.nextInt(256), random.nextInt(256));
50 | }
51 | });
52 |
53 | progressSeekBar = (SeekBar) view
54 | .findViewById(ch.halcyon.squareprogressbar.example.R.id.progressSeekBar);
55 | progressSeekBar
56 | .setOnSeekBarChangeListener(new OnSeekBarChangeListener() {
57 |
58 | @Override
59 | public void onStopTrackingTouch(SeekBar seekBar) {
60 | // nothing to do
61 | }
62 |
63 | @Override
64 | public void onStartTrackingTouch(SeekBar seekBar) {
65 | // nothing to do
66 | }
67 |
68 | @Override
69 | public void onProgressChanged(SeekBar seekBar,
70 | int progress, boolean fromUser) {
71 | setProgressBarProgress(progress, progressView);
72 | }
73 | });
74 |
75 | widthSeekBar = (SeekBar) view.findViewById(ch.halcyon.squareprogressbar.example.R.id.widthSeekBar);
76 | widthSeekBar.setOnSeekBarChangeListener(new OnSeekBarChangeListener() {
77 |
78 | @Override
79 | public void onStopTrackingTouch(SeekBar seekBar) {
80 | // nothing to do
81 | }
82 |
83 | @Override
84 | public void onStartTrackingTouch(SeekBar seekBar) {
85 | // nothing to do
86 | }
87 |
88 | @Override
89 | public void onProgressChanged(SeekBar seekBar, int progress,
90 | boolean fromUser) {
91 | squareProgressBar.setWidth(progress);
92 | }
93 | });
94 | return view;
95 | }
96 |
97 | private void setProgressBarProgress(int progress, TextView progressView) {
98 | squareProgressBar.setProgress(progress);
99 | progressView.setText(progress + "%");
100 | progressSeekBar.setProgress(progress);
101 | }
102 |
103 | }
104 |
--------------------------------------------------------------------------------
/exampleapp/res/layout/customcolourdialog.xml:
--------------------------------------------------------------------------------
1 |
2 |
10 |
11 |
23 |
24 |
30 |
31 |
40 |
41 |
47 |
48 |
54 |
55 |
64 |
65 |
75 |
76 |
86 |
87 |
95 |
96 |
103 |
104 |
111 |
112 |
113 |
--------------------------------------------------------------------------------
/exampleapp/res/layout/percentdialog.xml:
--------------------------------------------------------------------------------
1 |
2 |
10 |
11 |
22 |
23 |
30 |
31 |
41 |
42 |
51 |
52 |
59 |
60 |
67 |
68 |
69 |
76 |
77 |
89 |
90 |
96 |
97 |
110 |
111 |
118 |
119 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | android-square-progressbar[  ](https://bintray.com/mrwonderman/maven/squareprogressbar/_latestVersion)
2 | ==========================
3 | 
4 | ## First things first
5 |
6 | This library is setup to work with the Android Studio and Gradle. If you're using the Eclipse environment then check out the legacy repository here: [android-square-progressbar-legacy](https://github.com/mrwonderman/android-square-progressbar-legacy).
7 |
8 | You can find my blog post about the newest version here: [halcyon.ch - android-square-progressbar v.1.6.0](http://www.halcyon.ch/android-square-progressbar-v-1-6-0/), also check out the post about the previous major 1.5.0 version [here](http://www.halcyon.ch/android-square-progressbar-v-1-5-0/).
9 |
10 | The example application is available at the play store:
11 |
12 |
13 |
15 |
16 |
17 | [](https://gitter.im/mrwonderman/android-square-progressbar?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
18 |
19 | ## General idea
20 | Sometimes you don't have enough space in your layout to display a wide progressbar. So this library gives you a complete new possibility to display a progress. You can simply show a progressbar around an image. And this progressbar can be configured in a lot of different ways, like colour, outline, display of the percentage and so on.
21 |
22 | ### Examples
23 | Here are some examples of how these progressbars could look like:
24 |
25 | | normal / default | rounded corners | show percent | indeterminate|
26 | | ------------- | ------------- | ----- | ----- |
27 | || | | 
28 | | | `setRoundedCorners(true)` | `showProgress(true)` | `drawOutline(true)` |
29 | | | | `setOpacity(true)` | `setIndeterminate(true)` |
30 |
31 | There are some further examples available here (with code) : [Examples](https://github.com/mrwonderman/android-square-progressbar/wiki/Examples)
32 | ### How to use it? / How to install? / How to contribute?
33 | Check the wiki for more information about [how to use](https://github.com/mrwonderman/android-square-progressbar/wiki/Usage), [how to install](https://github.com/mrwonderman/android-square-progressbar/wiki/Use-with-an-Eclipse-Setup) or [how to contribute](https://github.com/mrwonderman/android-square-progressbar/wiki/How-To-Contribute).
34 |
35 | If you have questions about the code or if you need some help, you can try the [Gitter-Group](https://gitter.im/mrwonderman/android-square-progressbar).
36 |
37 | ## Usage
38 | ### Gradle
39 | This library now works with gradle and will soon be available on the central maven repository. For the moment its on jCenter at [Bintray](https://bintray.com/mrwonderman/maven/squareprogressbar/view). Just add the following repository to your root build.gradle:
40 |
41 | allprojects {
42 | repositories {
43 | jcenter()
44 | maven { url "https://jcenter.bintray.com" }
45 | }
46 | }
47 |
48 | Then in your app build.gradle:
49 |
50 | dependencies {
51 | // other repos ...
52 | implementation 'ch.halcyon:squareprogressbar:1.6.4'
53 | }
54 |
55 | ### Code
56 | After adding the gradle depedency from above you can go to your xml layout and add the following code for a squareprogressbar:
57 |
58 |
65 |
66 |
67 | To set some basic settings use the following java-code:
68 |
69 | SquareProgressBar squareProgressBar = findViewById(R.id.sprogressbar);
70 | squareProgressBar.setImage(R.drawable.example);
71 | squareProgressBar.setProgress(50.0);
72 |
73 | Now you can make the squareprogressbar as fancy as you like. Check the [usage page](https://github.com/mrwonderman/android-square-progressbar/wiki/Usage) for all the different possiblities.
74 |
--------------------------------------------------------------------------------
/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 |
3 | ##############################################################################
4 | ##
5 | ## Gradle start up script for UN*X
6 | ##
7 | ##############################################################################
8 |
9 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
10 | DEFAULT_JVM_OPTS=""
11 |
12 | APP_NAME="Gradle"
13 | APP_BASE_NAME=`basename "$0"`
14 |
15 | # Use the maximum available, or set MAX_FD != -1 to use that value.
16 | MAX_FD="maximum"
17 |
18 | warn ( ) {
19 | echo "$*"
20 | }
21 |
22 | die ( ) {
23 | echo
24 | echo "$*"
25 | echo
26 | exit 1
27 | }
28 |
29 | # OS specific support (must be 'true' or 'false').
30 | cygwin=false
31 | msys=false
32 | darwin=false
33 | case "`uname`" in
34 | CYGWIN* )
35 | cygwin=true
36 | ;;
37 | Darwin* )
38 | darwin=true
39 | ;;
40 | MINGW* )
41 | msys=true
42 | ;;
43 | esac
44 |
45 | # For Cygwin, ensure paths are in UNIX format before anything is touched.
46 | if $cygwin ; then
47 | [ -n "$JAVA_HOME" ] && JAVA_HOME=`cygpath --unix "$JAVA_HOME"`
48 | fi
49 |
50 | # Attempt to set APP_HOME
51 | # Resolve links: $0 may be a link
52 | PRG="$0"
53 | # Need this for relative symlinks.
54 | while [ -h "$PRG" ] ; do
55 | ls=`ls -ld "$PRG"`
56 | link=`expr "$ls" : '.*-> \(.*\)$'`
57 | if expr "$link" : '/.*' > /dev/null; then
58 | PRG="$link"
59 | else
60 | PRG=`dirname "$PRG"`"/$link"
61 | fi
62 | done
63 | SAVED="`pwd`"
64 | cd "`dirname \"$PRG\"`/" >&-
65 | APP_HOME="`pwd -P`"
66 | cd "$SAVED" >&-
67 |
68 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
69 |
70 | # Determine the Java command to use to start the JVM.
71 | if [ -n "$JAVA_HOME" ] ; then
72 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
73 | # IBM's JDK on AIX uses strange locations for the executables
74 | JAVACMD="$JAVA_HOME/jre/sh/java"
75 | else
76 | JAVACMD="$JAVA_HOME/bin/java"
77 | fi
78 | if [ ! -x "$JAVACMD" ] ; then
79 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
80 |
81 | Please set the JAVA_HOME variable in your environment to match the
82 | location of your Java installation."
83 | fi
84 | else
85 | JAVACMD="java"
86 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
87 |
88 | Please set the JAVA_HOME variable in your environment to match the
89 | location of your Java installation."
90 | fi
91 |
92 | # Increase the maximum file descriptors if we can.
93 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
94 | MAX_FD_LIMIT=`ulimit -H -n`
95 | if [ $? -eq 0 ] ; then
96 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
97 | MAX_FD="$MAX_FD_LIMIT"
98 | fi
99 | ulimit -n $MAX_FD
100 | if [ $? -ne 0 ] ; then
101 | warn "Could not set maximum file descriptor limit: $MAX_FD"
102 | fi
103 | else
104 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
105 | fi
106 | fi
107 |
108 | # For Darwin, add options to specify how the application appears in the dock
109 | if $darwin; then
110 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
111 | fi
112 |
113 | # For Cygwin, switch paths to Windows format before running java
114 | if $cygwin ; then
115 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
116 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
117 |
118 | # We build the pattern for arguments to be converted via cygpath
119 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
120 | SEP=""
121 | for dir in $ROOTDIRSRAW ; do
122 | ROOTDIRS="$ROOTDIRS$SEP$dir"
123 | SEP="|"
124 | done
125 | OURCYGPATTERN="(^($ROOTDIRS))"
126 | # Add a user-defined pattern to the cygpath arguments
127 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
128 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
129 | fi
130 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
131 | i=0
132 | for arg in "$@" ; do
133 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
134 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
135 |
136 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
137 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
138 | else
139 | eval `echo args$i`="\"$arg\""
140 | fi
141 | i=$((i+1))
142 | done
143 | case $i in
144 | (0) set -- ;;
145 | (1) set -- "$args0" ;;
146 | (2) set -- "$args0" "$args1" ;;
147 | (3) set -- "$args0" "$args1" "$args2" ;;
148 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
149 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
150 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
151 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
152 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
153 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
154 | esac
155 | fi
156 |
157 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
158 | function splitJvmOpts() {
159 | JVM_OPTS=("$@")
160 | }
161 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
162 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
163 |
164 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"
165 |
--------------------------------------------------------------------------------
/exampleapp/src/ch/halcyon/squareprogressbar/example/dialogs/PercentDialog.java:
--------------------------------------------------------------------------------
1 | package ch.halcyon.squareprogressbar.example.dialogs;
2 |
3 | import ch.halcyon.squareprogressbar.example.PreviewView;
4 | import ch.halcyon.squareprogressbar.utils.PercentStyle;
5 | import ch.halcyon.squareprogressbar.example.R;
6 |
7 | import android.app.Dialog;
8 | import android.content.Context;
9 | import android.graphics.Paint.Align;
10 | import android.view.View;
11 | import android.view.Window;
12 | import android.widget.AdapterView;
13 | import android.widget.AdapterView.OnItemSelectedListener;
14 | import android.widget.ArrayAdapter;
15 | import android.widget.Button;
16 | import android.widget.CheckBox;
17 | import android.widget.CompoundButton;
18 | import android.widget.CompoundButton.OnCheckedChangeListener;
19 | import android.widget.SeekBar;
20 | import android.widget.SeekBar.OnSeekBarChangeListener;
21 | import android.widget.Spinner;
22 | import android.widget.TextView;
23 |
24 | /**
25 | * THe dialog to set some example values for the percent text.
26 | *
27 | * @author ysigner
28 | * @since 1.3.0
29 | */
30 | public class PercentDialog extends Dialog {
31 |
32 | private final Spinner spinner;
33 | private final CheckBox box;
34 | private final Button saveButton;
35 | private final SeekBar bar;
36 | private int size;
37 | private final PreviewView previewView;
38 |
39 | /**
40 | * The {@link PercentDialog} to set custom settings for the style of the
41 | * percent text.
42 | *
43 | * @param context
44 | * the context.
45 | */
46 | public PercentDialog(final Context context) {
47 | super(context);
48 | requestWindowFeature(Window.FEATURE_NO_TITLE);
49 | this.setContentView(R.layout.percentdialog);
50 | this.setCancelable(false);
51 | spinner = (Spinner) this.findViewById(R.id.spinner1);
52 | ArrayAdapter adapter = ArrayAdapter.createFromResource(
53 | context, R.array.alignstyle,
54 | android.R.layout.simple_spinner_item);
55 | adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
56 | spinner.setAdapter(adapter);
57 |
58 | previewView = (PreviewView) findViewById(R.id.previewView1);
59 | spinner.setOnItemSelectedListener(new OnItemSelectedListener() {
60 |
61 | @Override
62 | public void onItemSelected(AdapterView> arg0, View arg1,
63 | int arg2, long arg3) {
64 | redrawPreview();
65 | }
66 |
67 | @Override
68 | public void onNothingSelected(AdapterView> arg0) {
69 | // nothing to do =)
70 | }
71 | });
72 |
73 | Button closeButton = (Button) this.findViewById(R.id.returnDialog);
74 | closeButton.setOnClickListener(new View.OnClickListener() {
75 |
76 | @Override
77 | public void onClick(View v) {
78 | dismiss();
79 |
80 | }
81 | });
82 | saveButton = (Button) this.findViewById(R.id.shareDialog);
83 |
84 | final TextView progress = (TextView) findViewById(R.id.textView3);
85 |
86 | bar = (SeekBar) findViewById(R.id.textSize);
87 | bar.setMax(400);
88 | bar.setProgress(125);
89 | bar.setOnSeekBarChangeListener(new OnSeekBarChangeListener() {
90 |
91 | @Override
92 | public void onStopTrackingTouch(SeekBar arg0) {
93 | // nothing to do =)
94 | }
95 |
96 | @Override
97 | public void onStartTrackingTouch(SeekBar arg0) {
98 | // nothing to do =)
99 |
100 | }
101 |
102 | @Override
103 | public void onProgressChanged(SeekBar arg0, int arg1, boolean arg2) {
104 | size = arg1;
105 | progress.setText(arg1 + " dp");
106 | redrawPreview();
107 | }
108 | });
109 |
110 | box = (CheckBox) this.findViewById(R.id.checkBox1);
111 | box.setOnCheckedChangeListener(new OnCheckedChangeListener() {
112 |
113 | @Override
114 | public void onCheckedChanged(CompoundButton buttonView,
115 | boolean isChecked) {
116 | redrawPreview();
117 | }
118 | });
119 |
120 | }
121 |
122 | /**
123 | * Returns the {@link PercentStyle} of the current settings.
124 | *
125 | * @return a new {@link PercentStyle}.
126 | */
127 | public PercentStyle getSettings() {
128 | return new PercentStyle(Align.valueOf((String) spinner
129 | .getSelectedItem()), Float.valueOf(bar.getProgress()),
130 | box.isChecked());
131 | }
132 |
133 | /**
134 | * Returns the save button of the dialog.
135 | *
136 | * @return the save {@link Button}.
137 | */
138 | public Button getSaveButton() {
139 | return saveButton;
140 | }
141 |
142 | /**
143 | * Returns the {@link Align} according to the position in the dropdown.
144 | *
145 | * @param position
146 | * the position in the dropdown.
147 | * @return the according {@link Align}.
148 | */
149 | private Align returnAlign(int position) {
150 | switch (position) {
151 | case 0:
152 | return Align.CENTER;
153 | case 1:
154 | return Align.RIGHT;
155 | case 2:
156 | return Align.LEFT;
157 | default:
158 | return Align.CENTER;
159 | }
160 | }
161 |
162 | /**
163 | * Redraws the preview canvas.
164 | */
165 | private void redrawPreview() {
166 | previewView
167 | .drawText(size, returnAlign(spinner.getSelectedItemPosition()),
168 | box.isChecked());
169 | }
170 |
171 | /**
172 | * Sets the {@link PercentStyle} to the settings in the dialog.
173 | *
174 | * @param settings
175 | * The {@link PercentStyle}, this is most likely the default
176 | * settings.
177 | */
178 | public void setPercentStyle(PercentStyle settings) {
179 | switch (settings.getAlign()) {
180 | case CENTER:
181 | spinner.setSelection(0);
182 | break;
183 | case RIGHT:
184 | spinner.setSelection(1);
185 | break;
186 | case LEFT:
187 | spinner.setSelection(2);
188 | break;
189 | default:
190 | spinner.setSelection(0);
191 | break;
192 | }
193 |
194 | bar.setProgress(Math.round(settings.getTextSize()));
195 | box.setChecked(settings.isPercentSign());
196 | }
197 | }
198 |
--------------------------------------------------------------------------------
/squareprogressbar/src/ch/halcyon/squareprogressbar/SquareProgressView.java:
--------------------------------------------------------------------------------
1 | package ch.halcyon.squareprogressbar;
2 |
3 | import android.content.Context;
4 | import android.graphics.Canvas;
5 | import android.graphics.CornerPathEffect;
6 | import android.graphics.Paint;
7 | import android.graphics.Paint.Align;
8 | import android.graphics.Paint.Style;
9 | import android.graphics.Path;
10 | import android.util.AttributeSet;
11 | import android.view.View;
12 |
13 | import java.text.DecimalFormat;
14 |
15 | import ch.halcyon.squareprogressbar.utils.CalculationUtil;
16 | import ch.halcyon.squareprogressbar.utils.PercentStyle;
17 |
18 | public class SquareProgressView extends View {
19 |
20 | private double progress;
21 | private Paint progressBarPaint;
22 | private Paint outlinePaint;
23 | private Paint textPaint;
24 |
25 | private float widthInDp = 10;
26 | private float strokewidth = 0;
27 | private Canvas canvas;
28 |
29 | private boolean outline = false;
30 | private boolean startline = false;
31 | private boolean showProgress = false;
32 | private boolean centerline = false;
33 |
34 | private boolean roundedCorners = false;
35 | private float roundedCornersRadius = 10;
36 |
37 | private PercentStyle percentSettings = new PercentStyle(Align.CENTER, 150,
38 | true);
39 | private boolean clearOnHundred = false;
40 | private boolean isIndeterminate = false;
41 | private int indeterminate_count = 1;
42 |
43 | private float indeterminate_width = 20.0f;
44 |
45 | public SquareProgressView(Context context) {
46 | super(context);
47 | initializePaints(context);
48 | }
49 |
50 | public SquareProgressView(Context context, AttributeSet attrs, int defStyle) {
51 | super(context, attrs, defStyle);
52 | initializePaints(context);
53 | }
54 |
55 | public SquareProgressView(Context context, AttributeSet attrs) {
56 | super(context, attrs);
57 | initializePaints(context);
58 | }
59 |
60 | private void initializePaints(Context context) {
61 | progressBarPaint = new Paint();
62 | progressBarPaint.setColor(context.getResources().getColor(
63 | android.R.color.holo_green_dark));
64 | progressBarPaint.setStrokeWidth(CalculationUtil.convertDpToPx(
65 | widthInDp, getContext()));
66 | progressBarPaint.setAntiAlias(true);
67 | progressBarPaint.setStyle(Style.STROKE);
68 |
69 | outlinePaint = new Paint();
70 | outlinePaint.setColor(context.getResources().getColor(
71 | android.R.color.black));
72 | outlinePaint.setStrokeWidth(1);
73 | outlinePaint.setAntiAlias(true);
74 | outlinePaint.setStyle(Style.STROKE);
75 |
76 | textPaint = new Paint();
77 | textPaint.setColor(context.getResources().getColor(
78 | android.R.color.black));
79 | textPaint.setAntiAlias(true);
80 | textPaint.setStyle(Style.STROKE);
81 | }
82 |
83 | @Override
84 | protected void onDraw(Canvas canvas) {
85 | this.canvas = canvas;
86 | super.onDraw(canvas);
87 | strokewidth = CalculationUtil.convertDpToPx(widthInDp, getContext());
88 | int cW = canvas.getWidth();
89 | int cH = canvas.getHeight();
90 | float scope = (2 * cW) + (2 * cH) - (4 * strokewidth);
91 | float hSw = strokewidth / 2;
92 |
93 | if (isOutline()) {
94 | drawOutline();
95 | }
96 |
97 | if (isStartline()) {
98 | drawStartline();
99 | }
100 |
101 | if (isShowProgress()) {
102 | drawPercent(percentSettings);
103 | }
104 |
105 | if (isCenterline()) {
106 | drawCenterline(strokewidth);
107 | }
108 |
109 | if ((isClearOnHundred() && progress == 100.0) || (progress <= 0.0)) {
110 | return;
111 | }
112 |
113 | if (isIndeterminate()) {
114 | Path path = new Path();
115 | DrawStop drawEnd = getDrawEnd((scope / 100) * Float.valueOf(String.valueOf(indeterminate_count)), canvas);
116 |
117 | if (drawEnd.place == Place.TOP) {
118 | path.moveTo(drawEnd.location - indeterminate_width - strokewidth, hSw);
119 | path.lineTo(drawEnd.location, hSw);
120 | canvas.drawPath(path, progressBarPaint);
121 | }
122 |
123 | if (drawEnd.place == Place.RIGHT) {
124 | path.moveTo(cW - hSw, drawEnd.location - indeterminate_width);
125 | path.lineTo(cW - hSw, strokewidth
126 | + drawEnd.location);
127 | canvas.drawPath(path, progressBarPaint);
128 | }
129 |
130 | if (drawEnd.place == Place.BOTTOM) {
131 | path.moveTo(drawEnd.location - indeterminate_width - strokewidth,
132 | cH - hSw);
133 | path.lineTo(drawEnd.location, cH
134 | - hSw);
135 | canvas.drawPath(path, progressBarPaint);
136 | }
137 |
138 | if (drawEnd.place == Place.LEFT) {
139 | path.moveTo(hSw, drawEnd.location - indeterminate_width
140 | - strokewidth);
141 | path.lineTo(hSw, drawEnd.location);
142 | canvas.drawPath(path, progressBarPaint);
143 | }
144 |
145 | indeterminate_count++;
146 | if (indeterminate_count > 100) {
147 | indeterminate_count = 0;
148 | }
149 | invalidate();
150 | } else {
151 | Path path = new Path();
152 | DrawStop drawEnd = getDrawEnd((scope / 100) * Float.valueOf(String.valueOf(progress)), canvas);
153 |
154 | if (drawEnd.place == Place.TOP) {
155 | if (drawEnd.location > (cW / 2) && progress < 100.0) {
156 | path.moveTo(cW / 2, hSw);
157 | path.lineTo(drawEnd.location, hSw);
158 | } else {
159 | path.moveTo(cW / 2, hSw);
160 | path.lineTo(cW - hSw, hSw);
161 | path.lineTo(cW - hSw, cH - hSw);
162 | path.lineTo(hSw, cH - hSw);
163 | path.lineTo(hSw, hSw);
164 | path.lineTo(strokewidth, hSw);
165 | path.lineTo(drawEnd.location, hSw);
166 | }
167 | canvas.drawPath(path, progressBarPaint);
168 | }
169 |
170 | if (drawEnd.place == Place.RIGHT) {
171 | path.moveTo(cW / 2, hSw);
172 | path.lineTo(cW - hSw, hSw);
173 | path.lineTo(cW - hSw, 0
174 | + drawEnd.location);
175 | canvas.drawPath(path, progressBarPaint);
176 | }
177 |
178 | if (drawEnd.place == Place.BOTTOM) {
179 | path.moveTo(cW / 2, hSw);
180 | path.lineTo(cW - hSw, hSw);
181 | path.lineTo(cW - hSw, cH - hSw);
182 | path.lineTo(cW - strokewidth, cH - hSw);
183 | path.lineTo(drawEnd.location, cH - hSw);
184 | canvas.drawPath(path, progressBarPaint);
185 | }
186 |
187 | if (drawEnd.place == Place.LEFT) {
188 | path.moveTo(cW / 2, hSw);
189 | path.lineTo(cW - hSw, hSw);
190 | path.lineTo(cW - hSw, cH - hSw);
191 | path.lineTo(hSw, cH - hSw);
192 | path.lineTo(hSw, cH - strokewidth);
193 | path.lineTo(hSw, drawEnd.location);
194 | canvas.drawPath(path, progressBarPaint);
195 | }
196 | }
197 | }
198 |
199 | private void drawStartline() {
200 | Path outlinePath = new Path();
201 | outlinePath.moveTo(canvas.getWidth() / 2, 0);
202 | outlinePath.lineTo(canvas.getWidth() / 2, strokewidth);
203 | canvas.drawPath(outlinePath, outlinePaint);
204 | }
205 |
206 | private void drawOutline() {
207 | Path outlinePath = new Path();
208 | outlinePath.moveTo(0, 0);
209 | outlinePath.lineTo(canvas.getWidth(), 0);
210 | outlinePath.lineTo(canvas.getWidth(), canvas.getHeight());
211 | outlinePath.lineTo(0, canvas.getHeight());
212 | outlinePath.lineTo(0, 0);
213 | canvas.drawPath(outlinePath, outlinePaint);
214 | }
215 |
216 | public double getProgress() {
217 | return progress;
218 | }
219 |
220 | public void setProgress(double progress) {
221 | this.progress = progress;
222 | this.invalidate();
223 | }
224 |
225 | public void setColor(int color) {
226 | progressBarPaint.setColor(color);
227 | this.invalidate();
228 | }
229 |
230 | public void setWidthInDp(int width) {
231 | this.widthInDp = width;
232 | progressBarPaint.setStrokeWidth(CalculationUtil.convertDpToPx(
233 | widthInDp, getContext()));
234 | this.invalidate();
235 | }
236 |
237 | public boolean isOutline() {
238 | return outline;
239 | }
240 |
241 | public void setOutline(boolean outline) {
242 | this.outline = outline;
243 | this.invalidate();
244 | }
245 |
246 | public boolean isStartline() {
247 | return startline;
248 | }
249 |
250 | public void setStartline(boolean startline) {
251 | this.startline = startline;
252 | this.invalidate();
253 | }
254 |
255 | private void drawPercent(PercentStyle setting) {
256 | textPaint.setTextAlign(setting.getAlign());
257 | if (setting.getTextSize() == 0) {
258 | textPaint.setTextSize((canvas.getHeight() / 10) * 4);
259 | } else {
260 | textPaint.setTextSize(setting.getTextSize());
261 | }
262 |
263 | String percentString = new DecimalFormat("###").format(getProgress());
264 | if (setting.isPercentSign()) {
265 | percentString = percentString + percentSettings.getCustomText();
266 | }
267 |
268 | textPaint.setColor(percentSettings.getTextColor());
269 |
270 | canvas.drawText(
271 | percentString,
272 | canvas.getWidth() / 2,
273 | (int) ((canvas.getHeight() / 2) - ((textPaint.descent() + textPaint
274 | .ascent()) / 2)), textPaint);
275 | }
276 |
277 | public boolean isShowProgress() {
278 | return showProgress;
279 | }
280 |
281 | public void setShowProgress(boolean showProgress) {
282 | this.showProgress = showProgress;
283 | this.invalidate();
284 | }
285 |
286 | public void setPercentStyle(PercentStyle percentSettings) {
287 | this.percentSettings = percentSettings;
288 | this.invalidate();
289 | }
290 |
291 | public PercentStyle getPercentStyle() {
292 | return percentSettings;
293 | }
294 |
295 | public void setClearOnHundred(boolean clearOnHundred) {
296 | this.clearOnHundred = clearOnHundred;
297 | this.invalidate();
298 | }
299 |
300 | public boolean isClearOnHundred() {
301 | return clearOnHundred;
302 | }
303 |
304 | private void drawCenterline(float strokewidth) {
305 | float centerOfStrokeWidth = strokewidth / 2;
306 | Path centerlinePath = new Path();
307 | centerlinePath.moveTo(centerOfStrokeWidth, centerOfStrokeWidth);
308 | centerlinePath.lineTo(canvas.getWidth() - centerOfStrokeWidth, centerOfStrokeWidth);
309 | centerlinePath.lineTo(canvas.getWidth() - centerOfStrokeWidth, canvas.getHeight() - centerOfStrokeWidth);
310 | centerlinePath.lineTo(centerOfStrokeWidth, canvas.getHeight() - centerOfStrokeWidth);
311 | centerlinePath.lineTo(centerOfStrokeWidth, centerOfStrokeWidth);
312 | canvas.drawPath(centerlinePath, outlinePaint);
313 | }
314 |
315 | public boolean isCenterline() {
316 | return centerline;
317 | }
318 |
319 | public void setCenterline(boolean centerline) {
320 | this.centerline = centerline;
321 | this.invalidate();
322 | }
323 |
324 | public boolean isIndeterminate() {
325 | return isIndeterminate;
326 | }
327 |
328 | public void setIndeterminate(boolean indeterminate) {
329 | isIndeterminate = indeterminate;
330 | this.invalidate();
331 | }
332 |
333 | public DrawStop getDrawEnd(float percent, Canvas canvas) {
334 | DrawStop drawStop = new DrawStop();
335 | strokewidth = CalculationUtil.convertDpToPx(widthInDp, getContext());
336 | float halfOfTheImage = canvas.getWidth() / 2;
337 |
338 | // top right
339 | if (percent > halfOfTheImage) {
340 | float second = percent - (halfOfTheImage);
341 |
342 | // right
343 | if (second > (canvas.getHeight() - strokewidth)) {
344 | float third = second - (canvas.getHeight() - strokewidth);
345 |
346 | // bottom
347 | if (third > (canvas.getWidth() - strokewidth)) {
348 | float forth = third - (canvas.getWidth() - strokewidth);
349 |
350 | // left
351 | if (forth > (canvas.getHeight() - strokewidth)) {
352 | float fifth = forth - (canvas.getHeight() - strokewidth);
353 |
354 | // top left
355 | if (fifth == halfOfTheImage) {
356 | drawStop.place = Place.TOP;
357 | drawStop.location = halfOfTheImage;
358 | } else {
359 | drawStop.place = Place.TOP;
360 | drawStop.location = strokewidth + fifth;
361 | }
362 | } else {
363 | drawStop.place = Place.LEFT;
364 | drawStop.location = canvas.getHeight() - strokewidth - forth;
365 | }
366 |
367 | } else {
368 | drawStop.place = Place.BOTTOM;
369 | drawStop.location = canvas.getWidth() - strokewidth - third;
370 | }
371 | } else {
372 | drawStop.place = Place.RIGHT;
373 | drawStop.location = strokewidth + second;
374 | }
375 |
376 | } else {
377 | drawStop.place = Place.TOP;
378 | drawStop.location = halfOfTheImage + percent;
379 | }
380 |
381 | return drawStop;
382 | }
383 |
384 | public void setRoundedCorners(boolean roundedCorners, float radius) {
385 | this.roundedCorners = roundedCorners;
386 | this.roundedCornersRadius = radius;
387 | if (roundedCorners) {
388 | progressBarPaint.setPathEffect(new CornerPathEffect(roundedCornersRadius));
389 | } else {
390 | progressBarPaint.setPathEffect(null);
391 | }
392 | this.invalidate();
393 | }
394 |
395 | public boolean isRoundedCorners() {
396 | return roundedCorners;
397 | }
398 |
399 | private class DrawStop {
400 |
401 | private Place place;
402 | private float location;
403 |
404 | public DrawStop() {
405 |
406 | }
407 | }
408 |
409 | public enum Place {
410 | TOP, RIGHT, BOTTOM, LEFT
411 | }
412 | }
413 |
--------------------------------------------------------------------------------
/squareprogressbar/src/ch/halcyon/squareprogressbar/SquareProgressBar.java:
--------------------------------------------------------------------------------
1 | package ch.halcyon.squareprogressbar;
2 |
3 | import ch.halcyon.squareprogressbar.utils.CalculationUtil;
4 | import ch.halcyon.squareprogressbar.utils.PercentStyle;
5 |
6 | import android.content.Context;
7 | import android.graphics.Bitmap;
8 | import android.graphics.Color;
9 | import android.graphics.ColorMatrix;
10 | import android.graphics.ColorMatrixColorFilter;
11 | import android.graphics.drawable.Drawable;
12 | import android.util.AttributeSet;
13 | import android.view.LayoutInflater;
14 | import android.widget.ImageView;
15 | import android.widget.ImageView.ScaleType;
16 | import android.widget.RelativeLayout;
17 |
18 | /**
19 | * The basic {@link SquareProgressBar}. This class includes all the methods you
20 | * need to modify your {@link SquareProgressBar}.
21 | *
22 | * @author ysigner
23 | * @since 1.0.0
24 | */
25 | public class SquareProgressBar extends RelativeLayout {
26 |
27 | private ImageView imageView;
28 | private final SquareProgressView bar;
29 | private boolean opacity = false;
30 | private boolean greyscale;
31 | private boolean isFadingOnProgress = false;
32 | private boolean roundedCorners = false;
33 |
34 | /**
35 | * New SquareProgressBar.
36 | *
37 | * @param context
38 | * the {@link Context}
39 | * @param attrs
40 | * an {@link AttributeSet}
41 | * @param defStyle
42 | * a defined style.
43 | * @since 1.0.0
44 | */
45 | public SquareProgressBar(Context context, AttributeSet attrs, int defStyle) {
46 | super(context, attrs, defStyle);
47 | LayoutInflater mInflater = (LayoutInflater) context
48 | .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
49 | mInflater.inflate(R.layout.progressbarview, this, true);
50 | bar = (SquareProgressView) findViewById(R.id.squareProgressBar1);
51 | imageView = (ImageView) findViewById(R.id.imageView1);
52 | bar.bringToFront();
53 | }
54 |
55 | /**
56 | * New SquareProgressBar.
57 | *
58 | * @param context
59 | * the {@link Context}
60 | * @param attrs
61 | * an {@link AttributeSet}
62 | * @since 1.0.0
63 | */
64 | public SquareProgressBar(Context context, AttributeSet attrs) {
65 | super(context, attrs);
66 | LayoutInflater mInflater = (LayoutInflater) context
67 | .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
68 | mInflater.inflate(R.layout.progressbarview, this, true);
69 | bar = (SquareProgressView) findViewById(R.id.squareProgressBar1);
70 | imageView = (ImageView) findViewById(R.id.imageView1);
71 | bar.bringToFront();
72 | }
73 |
74 | /**
75 | * New SquareProgressBar.
76 | *
77 | * @param context the context
78 | * @since 1.0.0
79 | */
80 | public SquareProgressBar(Context context) {
81 | super(context);
82 | LayoutInflater mInflater = (LayoutInflater) context
83 | .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
84 | mInflater.inflate(R.layout.progressbarview, this, true);
85 | bar = (SquareProgressView) findViewById(R.id.squareProgressBar1);
86 | imageView = (ImageView) findViewById(R.id.imageView1);
87 | bar.bringToFront();
88 | }
89 |
90 | /**
91 | * Sets the image of the {@link SquareProgressBar}. Must be a valid
92 | * ressourceId.
93 | *
94 | * @param image
95 | * the image as a ressourceId
96 | * @since 1.0
97 | */
98 | public void setImage(int image) {
99 | imageView.setImageResource(image);
100 |
101 | }
102 |
103 | /**
104 | * Sets the image of the {@link SquareProgressBar}. Must be a valid
105 | * Drawable.
106 | *
107 | * @param imageDrawable the image as a Drawable
108 | * @since 1.6.1
109 | * @author erikswed
110 | */
111 | public void setImageDrawable(Drawable imageDrawable) {
112 | imageView.setImageDrawable(imageDrawable);
113 | }
114 |
115 |
116 | /**
117 | * Sets the image scale type according to {@link ScaleType}.
118 | *
119 | * @param scale
120 | * the image ScaleType
121 | * @since 1.3.0
122 | * @author thiagokimo
123 | */
124 | public void setImageScaleType(ScaleType scale) {
125 | imageView.setScaleType(scale);
126 | }
127 |
128 | /**
129 | * Sets the progress of the {@link SquareProgressBar}. If opacity is
130 | * selected then here it sets it. See {@link #setOpacity(boolean)} for more
131 | * information.
132 | *
133 | * @param progress
134 | * the progress
135 | * @since 1.0.0
136 | */
137 | public void setProgress(double progress) {
138 | bar.setProgress(progress);
139 | if (opacity) {
140 | if (isFadingOnProgress) {
141 | setOpacity(100 - (int) progress);
142 | } else {
143 | setOpacity((int) progress);
144 | }
145 | } else {
146 | setOpacity(100);
147 | }
148 | }
149 |
150 | /**
151 | * Sets the colour of the {@link SquareProgressBar} to a predefined android
152 | * holo color.
153 | * Examples:
154 | *
155 | * - holo_blue_bright
156 | * - holo_blue_dark
157 | * - holo_blue_light
158 | * - holo_green_dark
159 | * - holo_green_light
160 | * - holo_orange_dark
161 | * - holo_orange_light
162 | * - holo_purple
163 | * - holo_red_dark
164 | * - holo_red_light
165 | *
166 | *
167 | * @param androidHoloColor holo color value
168 | * @since 1.0.0
169 | */
170 | public void setHoloColor(int androidHoloColor) {
171 | bar.setColor(getContext().getResources().getColor(androidHoloColor));
172 | }
173 |
174 | /**
175 | * Sets the colour of the {@link SquareProgressBar}. YOu can give it a
176 | * hex-color string like #C9C9C9.
177 | *
178 | * @param colorString
179 | * the colour of the {@link SquareProgressBar}
180 | * @since 1.1.0
181 | */
182 | public void setColor(String colorString) {
183 | bar.setColor(Color.parseColor(colorString));
184 | }
185 |
186 | /**
187 | * This sets the colour of the {@link SquareProgressBar} with a RGB colour.
188 | *
189 | * @param r
190 | * red
191 | * @param g
192 | * green
193 | * @param b
194 | * blue
195 | * @since 1.1.0
196 | */
197 | public void setColorRGB(int r, int g, int b) {
198 | bar.setColor(Color.rgb(r, g, b));
199 | }
200 |
201 | /**
202 | * This sets the colour of the {@link SquareProgressBar} with a RGB colour.
203 | * Works when used with
204 | * android.graphics.Color.rgb(int)
205 | *
206 | * @param rgb the rgb color
207 | * @since 1.4.0
208 | */
209 | public void setColorRGB(int rgb) {
210 | bar.setColor(rgb);
211 | }
212 |
213 | /**
214 | * This sets the width of the {@link SquareProgressBar}.
215 | *
216 | * @param width
217 | * in Dp
218 | * @since 1.1.0
219 | */
220 | public void setWidth(int width) {
221 | int padding = CalculationUtil.convertDpToPx(width, getContext());
222 | imageView.setPadding(padding, padding, padding, padding);
223 | bar.setWidthInDp(width);
224 | }
225 |
226 | /**
227 | * This sets the alpha of the image in the view. Actually I need to use the
228 | * deprecated method here as the new one is only available for the API-level
229 | * 16. And the min API level of this library is 14.
230 | *
231 | * Use this only as private method.
232 | *
233 | * @param progress
234 | * the progress
235 | */
236 | private void setOpacity(int progress) {
237 | imageView.setAlpha((int) (2.55 * progress));
238 | }
239 |
240 | /**
241 | * Switches the opacity state of the image. This forces the
242 | * SquareProgressBar to redraw with the current progress. As bigger the
243 | * progress is, then more of the image comes to view. If the progress is 0,
244 | * then you can't see the image at all. If the progress is 100, the image is
245 | * shown full.
246 | *
247 | * @param opacity
248 | * true if opacity should be enabled.
249 | * @since 1.2.0
250 | */
251 | public void setOpacity(boolean opacity) {
252 | this.opacity = opacity;
253 | setProgress(bar.getProgress());
254 | }
255 |
256 | /**
257 | * Switches the opacity state of the image. This forces the
258 | * SquareProgressBar to redraw with the current progress. As bigger the
259 | * progress is, then more of the image comes to view. If the progress is 0,
260 | * then you can't see the image at all. If the progress is 100, the image is
261 | * shown full.
262 | *
263 | * You can also set the flag if the fading should get inverted so the image
264 | * disappears when the progress increases.
265 | *
266 | * @param opacity
267 | * true if opacity should be enabled.
268 | * @param isFadingOnProgress
269 | * default false. This changes the behavior the opacity works. If
270 | * the progress increases then the images fades. When the
271 | * progress reaches 100, then the image disappears.
272 | * @since 1.4.0
273 | */
274 | public void setOpacity(boolean opacity, boolean isFadingOnProgress) {
275 | this.opacity = opacity;
276 | this.isFadingOnProgress = isFadingOnProgress;
277 | setProgress(bar.getProgress());
278 | }
279 |
280 | /**
281 | * You can set the image to b/w with this method. Works fine with the
282 | * opacity.
283 | *
284 | * @param greyscale
285 | * true if the grayscale should be activated.
286 | * @since 1.2.0
287 | */
288 | public void setImageGrayscale(boolean greyscale) {
289 | this.greyscale = greyscale;
290 | if (greyscale) {
291 | ColorMatrix matrix = new ColorMatrix();
292 | matrix.setSaturation(0);
293 | imageView.setColorFilter(new ColorMatrixColorFilter(matrix));
294 | } else {
295 | imageView.setColorFilter(null);
296 | }
297 | }
298 |
299 | /**
300 | * If opacity is enabled.
301 | *
302 | * @return true if opacity is enabled.
303 | */
304 | public boolean isOpacity() {
305 | return opacity;
306 | }
307 |
308 | /**
309 | * If greyscale is enabled.
310 | *
311 | * @return true if greyscale is enabled.
312 | */
313 | public boolean isGreyscale() {
314 | return greyscale;
315 | }
316 |
317 | /**
318 | * Draws an outline of the progressbar. Looks quite cool in some situations.
319 | *
320 | * @param drawOutline
321 | * true if it should or not.
322 | * @since 1.3.0
323 | */
324 | public void drawOutline(boolean drawOutline) {
325 | bar.setOutline(drawOutline);
326 | }
327 |
328 | /**
329 | * If outline is enabled or not.
330 | *
331 | * @return true if outline is enabled.
332 | */
333 | public boolean isOutline() {
334 | return bar.isOutline();
335 | }
336 |
337 | /**
338 | * Draws the startline. this is the line where the progressbar starts the
339 | * drawing around the image.
340 | *
341 | * @param drawStartline
342 | * true if it should or not.
343 | * @since 1.3.0
344 | */
345 | public void drawStartline(boolean drawStartline) {
346 | bar.setStartline(drawStartline);
347 | }
348 |
349 | /**
350 | * If the startline is enabled.
351 | *
352 | * @return true if startline is enabled or not.
353 | */
354 | public boolean isStartline() {
355 | return bar.isStartline();
356 | }
357 |
358 | /**
359 | * Defines if the percent text should be shown or not. To modify the text
360 | * checkout {@link #setPercentStyle(ch.halcyon.squareprogressbar.utils.PercentStyle)}.
361 | *
362 | * @param showProgress
363 | * true if it should or not.
364 | * @since 1.3.0
365 | */
366 | public void showProgress(boolean showProgress) {
367 | bar.setShowProgress(showProgress);
368 | }
369 |
370 | /**
371 | * If the progress text inside of the image is enabled.
372 | *
373 | * @return true if it is or not.
374 | */
375 | public boolean isShowProgress() {
376 | return bar.isShowProgress();
377 | }
378 |
379 | /**
380 | * Sets a custom percent style to the text inside the image. Make sure you
381 | * set {@link #showProgress(boolean)} to true. Otherwise it doesn't shows.
382 | * The default settings are:
383 | * Text align: CENTER
384 | * Text size: 150 [dp]
385 | * Display percentsign: true
386 | * Custom text: %
387 | *
388 | * @param percentStyle the percent style
389 | */
390 | public void setPercentStyle(PercentStyle percentStyle) {
391 | bar.setPercentStyle(percentStyle);
392 | }
393 |
394 | /**
395 | * Returns the {@link PercentStyle} of the percent text. Maybe returns the
396 | * default value, check {@link #setPercentStyle(PercentStyle)} fo that.
397 | *
398 | * @return the percent style of the moment.
399 | */
400 | public PercentStyle getPercentStyle() {
401 | return bar.getPercentStyle();
402 | }
403 |
404 | /**
405 | * If the progress hits 100% then the progressbar disappears if this flag is
406 | * set to true. The default is set to false.
407 | *
408 | * @param clearOnHundred
409 | * if it should disappear or not.
410 | * @since 1.4.0
411 | */
412 | public void setClearOnHundred(boolean clearOnHundred) {
413 | bar.setClearOnHundred(clearOnHundred);
414 | }
415 |
416 | /**
417 | * If the progressbar disappears when the progress reaches 100%.
418 | *
419 | * @since 1.4.0
420 | *
421 | * @return if "clearOnHundred" is enabled or not
422 | */
423 | public boolean isClearOnHundred() {
424 | return bar.isClearOnHundred();
425 | }
426 |
427 |
428 | /**
429 | * Set an image resource directly to the ImageView.
430 | *
431 | * @param bitmap the {@link android.graphics.Bitmap} to set.
432 | */
433 | public void setImageBitmap(Bitmap bitmap){
434 | imageView.setImageBitmap(bitmap);
435 | }
436 |
437 | /**
438 | * Set the status of the indeterminate mode. The default is false. You can
439 | * still configure colour, width and so on.
440 | *
441 | * @param indeterminate true to enable the indeterminate mode (default true)
442 | * @since 1.6.0
443 | */
444 | public void setIndeterminate(boolean indeterminate) {
445 | bar.setIndeterminate(indeterminate);
446 | }
447 |
448 | /**
449 | * Returns the status of the indeterminate mode. The default status is false.
450 | *
451 | * @since 1.6.0
452 | *
453 | * @return if "indeterminate" is enabled or not
454 | */
455 | public boolean isIndeterminate() {
456 | return bar.isIndeterminate();
457 | }
458 |
459 | /**
460 | * Draws a line in the center of the way the progressbar has to go.
461 | *
462 | * @param drawCenterline
463 | * true if it should or not.
464 | * @since 1.6.0
465 | */
466 | public void drawCenterline(boolean drawCenterline) {
467 | bar.setCenterline(drawCenterline);
468 | }
469 |
470 | /**
471 | * If the centerline is enabled or not.
472 | *
473 | * @return true if centerline is enabled.
474 | * @since 1.6.0
475 | */
476 | public boolean isCenterline() {
477 | return bar.isCenterline();
478 | }
479 |
480 | /**
481 | * Returns the {@link ImageView} that the progress gets drawn around.
482 | *
483 | * @return the main ImageView
484 | * @since 1.6.0
485 | */
486 | public ImageView getImageView(){
487 | return imageView;
488 | }
489 |
490 | /**
491 | * Returns the progress of the progressbar as a double.
492 | *
493 | * @return the current progress as double.
494 | * @since 1.6.2
495 | */
496 | public double getProgress() {
497 | return bar.getProgress();
498 | }
499 |
500 | /**
501 | * Sets the progress as an integer value. This is mainly used for animations.
502 | *
503 | * @param progress as an integer value.
504 | * @since 1.6.2
505 | */
506 | public void setProgress(int progress){
507 | setProgress((double) progress);
508 | }
509 |
510 | /**
511 | * Activates the drawing of rounded corners.
512 | *
513 | * @since 1.6.2
514 | */
515 | public void setRoundedCorners(boolean useRoundedCorners){
516 | bar.setRoundedCorners(useRoundedCorners, 10);
517 | }
518 |
519 | /**
520 | * Activates the drawing of rounded corners with a given radius.
521 | *
522 | * @since 1.6.2
523 | */
524 | public void setRoundedCorners(boolean useRoundedCorners, float radius){
525 | bar.setRoundedCorners(useRoundedCorners, radius);
526 | }
527 |
528 | /**
529 | * Returns a boolean if rounded corners is active or not.
530 | *
531 | * @return true if rounded corners is active.
532 | * @since 1.6.2
533 | */
534 | public boolean isRoundedCorners(){
535 | return bar.isRoundedCorners();
536 | }
537 | }
538 |
--------------------------------------------------------------------------------
/exampleapp/src/ch/halcyon/squareprogressbar/example/MainActivity.java:
--------------------------------------------------------------------------------
1 | package ch.halcyon.squareprogressbar.example;
2 |
3 | import android.app.Activity;
4 | import android.app.FragmentManager;
5 | import android.content.Context;
6 | import android.content.Intent;
7 | import android.content.res.Configuration;
8 | import android.net.Uri;
9 | import android.os.Bundle;
10 | import android.support.v4.app.ActionBarDrawerToggle;
11 | import android.support.v4.view.GravityCompat;
12 | import android.support.v4.widget.DrawerLayout;
13 | import android.text.Html;
14 | import android.view.LayoutInflater;
15 | import android.view.Menu;
16 | import android.view.MenuItem;
17 | import android.view.View;
18 | import android.view.View.OnClickListener;
19 | import android.view.ViewGroup;
20 | import android.widget.AdapterView;
21 | import android.widget.BaseAdapter;
22 | import android.widget.CheckBox;
23 | import android.widget.CompoundButton;
24 | import android.widget.CompoundButton.OnCheckedChangeListener;
25 | import android.widget.ImageView;
26 | import android.widget.ListView;
27 | import android.widget.TextView;
28 |
29 | import java.util.ArrayList;
30 |
31 | import ch.halcyon.squareprogressbar.example.dialogs.CustomColourDialog;
32 | import ch.halcyon.squareprogressbar.example.dialogs.PercentDialog;
33 | import ch.halcyon.squareprogressbar.utils.ColourUtil;
34 |
35 | public class MainActivity extends Activity {
36 | private DrawerLayout drawerLayout;
37 | private ListView drawerListView;
38 | private ActionBarDrawerToggle drawerToggle;
39 |
40 | private CharSequence drawerTitle;
41 | private CharSequence title;
42 | public static String[] partTitle, descriptions;
43 | private SquareFragment squareFragment;
44 |
45 | private int lastPosition;
46 |
47 | @Override
48 | protected void onCreate(Bundle savedInstanceState) {
49 | super.onCreate(savedInstanceState);
50 | FragmentManager fragmentManager = getFragmentManager();
51 | squareFragment = new SquareFragment();
52 | fragmentManager.beginTransaction()
53 | .replace(ch.halcyon.squareprogressbar.example.R.id.content_frame, squareFragment).commit();
54 | setContentView(ch.halcyon.squareprogressbar.example.R.layout.activity_main);
55 |
56 | title = drawerTitle = getTitle();
57 | partTitle = getResources().getStringArray(ch.halcyon.squareprogressbar.example.R.array.drawer_titel);
58 | descriptions = getResources().getStringArray(
59 | ch.halcyon.squareprogressbar.example.R.array.drawer_descriptions);
60 | drawerLayout = (DrawerLayout) findViewById(ch.halcyon.squareprogressbar.example.R.id.drawer_layout);
61 | drawerListView = (ListView) findViewById(ch.halcyon.squareprogressbar.example.R.id.left_drawer);
62 |
63 | drawerLayout.setDrawerShadow(ch.halcyon.squareprogressbar.example.R.drawable.drawer_shadow,
64 | GravityCompat.START);
65 | BaseAdapter adapter = new BaseAdapter() {
66 |
67 | @Override
68 | public View getView(final int position, View convertView,
69 | ViewGroup parent) {
70 | View item = convertView;
71 |
72 | // Header Item
73 | View headerItem = LayoutInflater.from(getApplicationContext())
74 | .inflate(ch.halcyon.squareprogressbar.example.R.layout.lv_header_layout, parent, false);
75 | TextView title = (TextView) headerItem
76 | .findViewById(ch.halcyon.squareprogressbar.example.R.id.lv_list_hdr);
77 |
78 | // Custom Style Item
79 | View styleItem = LayoutInflater.from(getApplicationContext())
80 | .inflate(ch.halcyon.squareprogressbar.example.R.layout.lv_style, parent, false);
81 | CheckBox box = (CheckBox) styleItem
82 | .findViewById(ch.halcyon.squareprogressbar.example.R.id.checkBox1);
83 |
84 | // Custom Style Item
85 | View styleBoxItem = LayoutInflater
86 | .from(getApplicationContext()).inflate(
87 | ch.halcyon.squareprogressbar.example.R.layout.lv_style_box, parent, false);
88 | final CheckBox styleBox = (CheckBox) styleBoxItem
89 | .findViewById(ch.halcyon.squareprogressbar.example.R.id.checkBox11);
90 | ImageView styleImage = (ImageView) styleBoxItem
91 | .findViewById(ch.halcyon.squareprogressbar.example.R.id.imageView1);
92 |
93 | // Link to Github Item
94 | View githubItem = LayoutInflater.from(getApplicationContext())
95 | .inflate(ch.halcyon.squareprogressbar.example.R.layout.lv_github, parent, false);
96 | TextView githublink = (TextView) githubItem
97 | .findViewById(ch.halcyon.squareprogressbar.example.R.id.textView1);
98 |
99 | // Link to homepage Item
100 | View signerItem = LayoutInflater.from(getApplicationContext())
101 | .inflate(ch.halcyon.squareprogressbar.example.R.layout.lv_signer, parent, false);
102 |
103 | // Link to Image Item
104 | View imageItem = LayoutInflater.from(getApplicationContext())
105 | .inflate(ch.halcyon.squareprogressbar.example.R.layout.lv_image, parent, false);
106 | ImageView imagePreview = (ImageView) imageItem
107 | .findViewById(ch.halcyon.squareprogressbar.example.R.id.imageView1);
108 | TextView imageDesc = (TextView) imageItem
109 | .findViewById(ch.halcyon.squareprogressbar.example.R.id.imagetag);
110 |
111 | switch (position) {
112 | case 0:
113 | title.setText("Colour");
114 | return headerItem;
115 | case 11:
116 | Context context = getApplicationContext();
117 | item = LayoutInflater.from(context).inflate(
118 | ch.halcyon.squareprogressbar.example.R.layout.lv_colour_text, parent, false);
119 | item.setOnClickListener(new OnClickListener() {
120 |
121 | @Override
122 | public void onClick(View arg0) {
123 | final CustomColourDialog customColourDialog = new CustomColourDialog(
124 | MainActivity.this);
125 | customColourDialog.show();
126 | customColourDialog.getSaveButton()
127 | .setOnClickListener(new OnClickListener() {
128 |
129 | @Override
130 | public void onClick(View v) {
131 | squareFragment.squareProgressBar
132 | .setColorRGB(customColourDialog
133 | .getChoosenRGB());
134 | customColourDialog.dismiss();
135 |
136 | }
137 | });
138 | selectItem(position);
139 | lastPosition = position;
140 | }
141 | });
142 | TextView textView = (TextView) item
143 | .findViewById(ch.halcyon.squareprogressbar.example.R.id.colour_name_center);
144 | textView.setText("choose RGB colour");
145 | return item;
146 | case 12:
147 | title.setText("Style");
148 | return headerItem;
149 |
150 | case 13:
151 | box.setText(ch.halcyon.squareprogressbar.example.R.string.opacity);
152 | box.setChecked(squareFragment.squareProgressBar.isOpacity());
153 | box.setOnCheckedChangeListener(new OnCheckedChangeListener() {
154 | @Override
155 | public void onCheckedChanged(CompoundButton buttonView,
156 | boolean isChecked) {
157 | squareFragment.squareProgressBar
158 | .setOpacity(isChecked);
159 | }
160 | });
161 | return styleItem;
162 |
163 | case 14:
164 | box.setText("Outline");
165 | box.setChecked(squareFragment.squareProgressBar.isOutline());
166 | box.setOnCheckedChangeListener(new OnCheckedChangeListener() {
167 | @Override
168 | public void onCheckedChanged(CompoundButton buttonView,
169 | boolean isChecked) {
170 | squareFragment.squareProgressBar
171 | .drawOutline(isChecked);
172 | }
173 | });
174 | return styleItem;
175 |
176 | case 15:
177 | box.setText("Startline");
178 | box.setChecked(squareFragment.squareProgressBar
179 | .isStartline());
180 | box.setOnCheckedChangeListener(new OnCheckedChangeListener() {
181 | @Override
182 | public void onCheckedChanged(CompoundButton buttonView,
183 | boolean isChecked) {
184 | squareFragment.squareProgressBar
185 | .drawStartline(isChecked);
186 | }
187 | });
188 | return styleItem;
189 |
190 | case 16:
191 | box.setText("Centerline");
192 | box.setChecked(squareFragment.squareProgressBar
193 | .isCenterline());
194 | box.setOnCheckedChangeListener(new OnCheckedChangeListener() {
195 | @Override
196 | public void onCheckedChanged(CompoundButton buttonView,
197 | boolean isChecked) {
198 | squareFragment.squareProgressBar
199 | .drawCenterline(isChecked);
200 | }
201 | });
202 | return styleItem;
203 |
204 | case 17:
205 | styleBox.setText("Show percent");
206 | styleBox.setChecked(squareFragment.squareProgressBar
207 | .isShowProgress());
208 | styleBox.setOnCheckedChangeListener(new OnCheckedChangeListener() {
209 | @Override
210 | public void onCheckedChanged(CompoundButton buttonView,
211 | boolean isChecked) {
212 | squareFragment.squareProgressBar
213 | .showProgress(isChecked);
214 | }
215 | });
216 | styleImage.setOnClickListener(new OnClickListener() {
217 |
218 | @Override
219 | public void onClick(View arg0) {
220 | final PercentDialog percentDialog = new PercentDialog(
221 | MainActivity.this);
222 | percentDialog.show();
223 | percentDialog
224 | .setPercentStyle(squareFragment.squareProgressBar
225 | .getPercentStyle());
226 | percentDialog.getSaveButton().setOnClickListener(
227 | new OnClickListener() {
228 |
229 | @Override
230 | public void onClick(View v) {
231 | squareFragment.squareProgressBar
232 | .setPercentStyle(percentDialog
233 | .getSettings());
234 | percentDialog.dismiss();
235 | styleBox.setChecked(true);
236 | drawerLayout.closeDrawers();
237 | }
238 | });
239 | }
240 | });
241 | return styleBoxItem;
242 |
243 | case 18:
244 | box.setText("Grayscale");
245 | box.setChecked(squareFragment.squareProgressBar
246 | .isGreyscale());
247 | box.setOnCheckedChangeListener(new OnCheckedChangeListener() {
248 | @Override
249 | public void onCheckedChanged(CompoundButton buttonView,
250 | boolean isChecked) {
251 | squareFragment.squareProgressBar
252 | .setImageGrayscale(isChecked);
253 | }
254 | });
255 | return styleItem;
256 | case 19:
257 | box.setText("Clear at 100%");
258 | box.setChecked(squareFragment.squareProgressBar
259 | .isClearOnHundred());
260 | box.setOnCheckedChangeListener(new OnCheckedChangeListener() {
261 | @Override
262 | public void onCheckedChanged(CompoundButton buttonView,
263 | boolean isChecked) {
264 | squareFragment.squareProgressBar
265 | .setClearOnHundred(isChecked);
266 | }
267 | });
268 | return styleItem;
269 |
270 | case 20:
271 | box.setText("Indeterminate");
272 | box.setChecked(squareFragment.squareProgressBar
273 | .isIndeterminate());
274 | box.setOnCheckedChangeListener(new OnCheckedChangeListener() {
275 | @Override
276 | public void onCheckedChanged(CompoundButton buttonView,
277 | boolean isChecked) {
278 | squareFragment.squareProgressBar
279 | .setIndeterminate(isChecked);
280 | }
281 | });
282 | return styleItem;
283 |
284 | case 21:
285 | box.setText("Rounded corners");
286 | box.setChecked(squareFragment.squareProgressBar.isRoundedCorners());
287 | box.setOnCheckedChangeListener(new OnCheckedChangeListener() {
288 | @Override
289 | public void onCheckedChanged(CompoundButton buttonView,
290 | boolean isChecked) {
291 | squareFragment.squareProgressBar.setRoundedCorners(isChecked);
292 | }
293 | });
294 | return styleItem;
295 |
296 | case 22:
297 | title.setText("Image");
298 | return headerItem;
299 | case 23:
300 | imagePreview.setImageResource(ch.halcyon.squareprogressbar.example.R.drawable.blenheim_palace);
301 | imageDesc.setText("blenheim palace");
302 | imageItem.setOnClickListener(new OnClickListener() {
303 |
304 | @Override
305 | public void onClick(View v) {
306 | squareFragment.squareProgressBar
307 | .setImage(ch.halcyon.squareprogressbar.example.R.drawable.blenheim_palace);
308 | }
309 | });
310 | return imageItem;
311 | case 24:
312 | imagePreview
313 | .setImageResource(ch.halcyon.squareprogressbar.example.R.drawable.millennium_stadium);
314 | imageDesc.setText("the millennium stadium");
315 | imageItem.setOnClickListener(new OnClickListener() {
316 |
317 | @Override
318 | public void onClick(View v) {
319 | squareFragment.squareProgressBar
320 | .setImage(ch.halcyon.squareprogressbar.example.R.drawable.millennium_stadium);
321 | }
322 | });
323 | return imageItem;
324 | case 25:
325 | imagePreview.setImageResource(ch.halcyon.squareprogressbar.example.R.drawable.edinburgh);
326 | imageDesc.setText("carlton hill");
327 | imageItem.setOnClickListener(new OnClickListener() {
328 |
329 | @Override
330 | public void onClick(View v) {
331 | squareFragment.squareProgressBar
332 | .setImage(ch.halcyon.squareprogressbar.example.R.drawable.edinburgh);
333 | }
334 | });
335 | return imageItem;
336 | case 26:
337 | imagePreview.setImageResource(ch.halcyon.squareprogressbar.example.R.drawable.holyroodpark);
338 | imageDesc.setText("holyrood park");
339 | imageItem.setOnClickListener(new OnClickListener() {
340 |
341 | @Override
342 | public void onClick(View v) {
343 | squareFragment.squareProgressBar
344 | .setImage(ch.halcyon.squareprogressbar.example.R.drawable.holyroodpark);
345 | }
346 | });
347 | return imageItem;
348 | case 27:
349 | imagePreview.setImageResource(ch.halcyon.squareprogressbar.example.R.drawable.operahuset);
350 | imageDesc.setText("operahuset oslo");
351 | imageItem.setOnClickListener(new OnClickListener() {
352 |
353 | @Override
354 | public void onClick(View v) {
355 | squareFragment.squareProgressBar
356 | .setImage(ch.halcyon.squareprogressbar.example.R.drawable.operahuset);
357 | }
358 | });
359 | return imageItem;
360 | case 28:
361 | title.setText("Source");
362 | return headerItem;
363 | case 29:
364 | String text = "mrwonderman/android-square-progressbar (v. 1.6.4)";
365 | githublink.setText(Html.fromHtml(text));
366 | githubItem.setOnClickListener(new OnClickListener() {
367 |
368 | @Override
369 | public void onClick(View arg0) {
370 | Intent browserIntent = new Intent(
371 | Intent.ACTION_VIEW,
372 | Uri.parse("https://github.com/mrwonderman/android-square-progressbar"));
373 | startActivity(browserIntent);
374 | }
375 | });
376 | return githubItem;
377 | case 30:
378 | signerItem.setOnClickListener(new OnClickListener() {
379 |
380 | @Override
381 | public void onClick(View arg0) {
382 | Intent browserIntent = new Intent(
383 | Intent.ACTION_VIEW, Uri
384 | .parse("http://www.halcyon.ch/"));
385 | startActivity(browserIntent);
386 | }
387 | });
388 | return signerItem;
389 | default:
390 | break;
391 | }
392 |
393 | ArrayList colourArray = ColourUtil.getColourArray();
394 |
395 | if (position <= 10) {
396 | Context context = getApplicationContext();
397 | item = LayoutInflater.from(context).inflate(
398 | ch.halcyon.squareprogressbar.example.R.layout.lv_colour, parent, false);
399 | View colourView = item.findViewById(ch.halcyon.squareprogressbar.example.R.id.colour_preview);
400 | final Integer integer = colourArray.get(position - 1);
401 | colourView.setBackgroundColor(context.getResources()
402 | .getColor(integer));
403 | item.setOnClickListener(new OnClickListener() {
404 |
405 | @Override
406 | public void onClick(View arg0) {
407 | squareFragment.squareProgressBar
408 | .setHoloColor(integer);
409 | selectItem(position);
410 | lastPosition = position;
411 | }
412 | });
413 | TextView textView = (TextView) item
414 | .findViewById(ch.halcyon.squareprogressbar.example.R.id.colour_name);
415 | textView.setText(getName(position - 1));
416 | }
417 | return item;
418 | }
419 |
420 | @Override
421 | public long getItemId(int position) {
422 | return position;
423 | }
424 |
425 | @Override
426 | public Object getItem(int position) {
427 | return position;
428 | }
429 |
430 | @Override
431 | public int getCount() {
432 | return 31;
433 | }
434 | };
435 | drawerListView.setAdapter(adapter);
436 | drawerListView.setOnItemClickListener(new DrawerItemClickListener());
437 |
438 | getActionBar().setDisplayHomeAsUpEnabled(true);
439 | getActionBar().setHomeButtonEnabled(true);
440 |
441 | drawerToggle = new ActionBarDrawerToggle(this, drawerLayout,
442 | ch.halcyon.squareprogressbar.example.R.drawable.ic_drawer, ch.halcyon.squareprogressbar.example.R.string.drawer_open,
443 | ch.halcyon.squareprogressbar.example.R.string.drawer_close) {
444 | @Override
445 | public void onDrawerClosed(View view) {
446 | getActionBar().setTitle(title);
447 | invalidateOptionsMenu();
448 | }
449 |
450 | @Override
451 | public void onDrawerOpened(View drawerView) {
452 | getActionBar().setTitle(drawerTitle);
453 | invalidateOptionsMenu();
454 | }
455 | };
456 | drawerLayout.setDrawerListener(drawerToggle);
457 | }
458 |
459 | @Override
460 | public boolean onOptionsItemSelected(MenuItem item) {
461 | if (drawerToggle.onOptionsItemSelected(item)) {
462 | return true;
463 | }
464 | return true;
465 | }
466 |
467 | @Override
468 | public boolean onPrepareOptionsMenu(Menu menu) {
469 | return super.onPrepareOptionsMenu(menu);
470 | }
471 |
472 | @Override
473 | public void setTitle(CharSequence title) {
474 | this.title = title;
475 | getActionBar().setTitle(title);
476 | }
477 |
478 | @Override
479 | protected void onPostCreate(Bundle savedInstanceState) {
480 | super.onPostCreate(savedInstanceState);
481 | drawerToggle.syncState();
482 | }
483 |
484 | @Override
485 | public void onConfigurationChanged(Configuration newConfig) {
486 | super.onConfigurationChanged(newConfig);
487 | drawerToggle.onConfigurationChanged(newConfig);
488 | }
489 |
490 | private CharSequence getName(int position) {
491 | switch (position) {
492 | case 0:
493 | return "holo_blue_bright";
494 | case 1:
495 | return "holo_blue_dark";
496 | case 2:
497 | return "holo_blue_light";
498 | case 3:
499 | return "holo_green_dark";
500 | case 4:
501 | return "holo_green_light";
502 | case 5:
503 | return "holo_orange_dark";
504 | case 6:
505 | return "holo_orange_light";
506 | case 7:
507 | return "holo_purple";
508 | case 8:
509 | return "holo_red_dark";
510 | case 9:
511 | return "holo_red_light";
512 |
513 | default:
514 | break;
515 | }
516 | return "";
517 | }
518 |
519 | private void selectItem(int position) {
520 | drawerListView.setItemChecked(position, true);
521 | }
522 |
523 | private class DrawerItemClickListener implements
524 | ListView.OnItemClickListener {
525 | @Override
526 | public void onItemClick(AdapterView> parent, View view, int position,
527 | long id) {
528 | if ((position != 0) && (position != 12) && (position != 22)
529 | && (position != 28)) {
530 | selectItem(position);
531 | } else {
532 | selectItem(lastPosition);
533 | }
534 | }
535 | }
536 | }
--------------------------------------------------------------------------------