├── .gitignore ├── .settings └── org.eclipse.jdt.core.prefs ├── AndroidManifest.xml ├── LICENSE ├── README.md ├── libs └── android-support-v4.jar ├── proguard-project.txt ├── project.properties ├── res ├── drawable-hdpi │ └── ic_launcher.png ├── drawable-mdpi │ └── ic_launcher.png ├── drawable-xhdpi │ └── ic_launcher.png ├── layout │ ├── activity_main.xml │ └── wheel_progress_dialog.xml ├── menu │ └── main.xml ├── values-sw600dp │ └── dimens.xml ├── values-sw720dp-land │ └── dimens.xml ├── values-v11 │ └── styles.xml ├── values-v14 │ └── styles.xml └── values │ ├── attrs.xml │ ├── dimens.xml │ ├── strings.xml │ └── styles.xml ├── sample.gif └── src └── com ├── github └── tcking │ └── wheelprogress │ ├── MainActivity.java │ └── WheelProgressDialog.java └── todddavies └── components └── progressbar └── ProgressWheel.java /.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 | 15 | # Local configuration file (sdk path, etc) 16 | local.properties 17 | 18 | # Eclipse project files 19 | .classpath 20 | .project 21 | 22 | # Proguard folder generated by Eclipse 23 | proguard/ 24 | 25 | # Intellij project files 26 | *.iml 27 | *.ipr 28 | *.iws 29 | .idea/ 30 | -------------------------------------------------------------------------------- /.settings/org.eclipse.jdt.core.prefs: -------------------------------------------------------------------------------- 1 | eclipse.preferences.version=1 2 | org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6 3 | org.eclipse.jdt.core.compiler.compliance=1.6 4 | org.eclipse.jdt.core.compiler.source=1.6 5 | -------------------------------------------------------------------------------- /AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 10 | 11 | 16 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2014 tcking 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | WheelProgressDialog 2 | =================== 3 | 4 | progress dailog using wheel style in android 5 | 6 | ![Sample Image](https://github.com/tcking/WheelProgressDialog/raw/master/sample.gif "An example implementation") 7 | 8 | 9 | usage: 10 | 11 | ``` 12 | wheelProgressDialog=new WheelProgressDialog(this); 13 | wheelProgressDialog.message("game on !").show(); 14 | 15 | ... 16 | 17 | wheelProgressDialog.progress(i++).message("processing:"+i+"%"); 18 | 19 | ... 20 | 21 | wheelProgressDialog.dismiss(); 22 | 23 | ``` 24 | 25 | this is a dialog wrapper for [ProgressWheel](https://github.com/Todd-Davies/ProgressWheel) 26 | -------------------------------------------------------------------------------- /libs/android-support-v4.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tcking/WheelProgressDialog/a608e1db07970e003e0393349fd107c7171a5bf3/libs/android-support-v4.jar -------------------------------------------------------------------------------- /proguard-project.txt: -------------------------------------------------------------------------------- 1 | # To enable ProGuard in your project, edit project.properties 2 | # to define the proguard.config property as described in that file. 3 | # 4 | # Add project specific ProGuard rules here. 5 | # By default, the flags in this file are appended to flags specified 6 | # in ${sdk.dir}/tools/proguard/proguard-android.txt 7 | # You can edit the include path and order by changing the ProGuard 8 | # include property in project.properties. 9 | # 10 | # For more details, see 11 | # http://developer.android.com/guide/developing/tools/proguard.html 12 | 13 | # Add any project specific keep options here: 14 | 15 | # If your project uses WebView with JS, uncomment the following 16 | # and specify the fully qualified class name to the JavaScript interface 17 | # class: 18 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 19 | # public *; 20 | #} 21 | -------------------------------------------------------------------------------- /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-19 15 | -------------------------------------------------------------------------------- /res/drawable-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tcking/WheelProgressDialog/a608e1db07970e003e0393349fd107c7171a5bf3/res/drawable-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /res/drawable-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tcking/WheelProgressDialog/a608e1db07970e003e0393349fd107c7171a5bf3/res/drawable-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /res/drawable-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tcking/WheelProgressDialog/a608e1db07970e003e0393349fd107c7171a5bf3/res/drawable-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 10 | 11 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /res/layout/wheel_progress_dialog.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 16 | 17 | 30 | 31 | 37 | 38 | 39 | -------------------------------------------------------------------------------- /res/menu/main.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /res/values-sw600dp/dimens.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /res/values-sw720dp-land/dimens.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 7 | 128dp 8 | 9 | 10 | -------------------------------------------------------------------------------- /res/values-v11/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 7 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /res/values-v14/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 8 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /res/values/attrs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /res/values/dimens.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 16dp 5 | 16dp 6 | 7 | 8 | -------------------------------------------------------------------------------- /res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | WheelProgressDialog 5 | Settings 6 | Hello world! 7 | 8 | 9 | -------------------------------------------------------------------------------- /res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 7 | 14 | 15 | 16 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /sample.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tcking/WheelProgressDialog/a608e1db07970e003e0393349fd107c7171a5bf3/sample.gif -------------------------------------------------------------------------------- /src/com/github/tcking/wheelprogress/MainActivity.java: -------------------------------------------------------------------------------- 1 | package com.github.tcking.wheelprogress; 2 | 3 | import android.os.Bundle; 4 | import android.os.Handler; 5 | import android.app.Activity; 6 | import android.view.Menu; 7 | 8 | public class MainActivity extends Activity { 9 | 10 | private Handler handler; 11 | private WheelProgressDialog wheelProgressDialog; 12 | int progress=0; 13 | @Override 14 | protected void onCreate(Bundle savedInstanceState) { 15 | super.onCreate(savedInstanceState); 16 | setContentView(R.layout.activity_main); 17 | handler=new Handler(); 18 | wheelProgressDialog=new WheelProgressDialog(this); 19 | wheelProgressDialog.message("game on !").show(); 20 | test(); 21 | } 22 | 23 | private void test(){ 24 | handler.postDelayed(new Runnable() { 25 | @Override 26 | public void run() { 27 | // TODO Auto-generated method stub 28 | wheelProgressDialog.progress(++progress).message(progress>=100?"mission complete":"processing:"+progress); 29 | if(progress<=100){ 30 | test(); 31 | } 32 | } 33 | }, 100); 34 | } 35 | 36 | @Override 37 | public boolean onCreateOptionsMenu(Menu menu) { 38 | // Inflate the menu; this adds items to the action bar if it is present. 39 | getMenuInflater().inflate(R.menu.main, menu); 40 | return true; 41 | } 42 | 43 | } 44 | -------------------------------------------------------------------------------- /src/com/github/tcking/wheelprogress/WheelProgressDialog.java: -------------------------------------------------------------------------------- 1 | package com.github.tcking.wheelprogress; 2 | 3 | import android.app.AlertDialog; 4 | import android.content.Context; 5 | import android.os.Bundle; 6 | import android.view.LayoutInflater; 7 | import android.view.View; 8 | import android.widget.TextView; 9 | 10 | import com.todddavies.components.progressbar.ProgressWheel; 11 | 12 | public class WheelProgressDialog extends AlertDialog{ 13 | private ProgressWheel mWheelView; 14 | private TextView mMessageView; 15 | private String message; 16 | private int progress; 17 | 18 | public WheelProgressDialog(Context context) { 19 | super(context); 20 | } 21 | 22 | public WheelProgressDialog(Context context,int theme) { 23 | super(context,theme); 24 | } 25 | 26 | @Override 27 | protected void onCreate(Bundle savedInstanceState) { 28 | LayoutInflater inflater = LayoutInflater.from(getContext()); 29 | View v = inflater.inflate(R.layout.wheel_progress_dialog, null); 30 | mWheelView=(ProgressWheel) v.findViewById(R.id.progress); 31 | mMessageView=(TextView)v.findViewById(R.id.message); 32 | setView(v); 33 | mWheelView.setText("0%"); 34 | super.onCreate(savedInstanceState); 35 | } 36 | 37 | 38 | public int getProgress(){ 39 | return progress; 40 | } 41 | 42 | 43 | public WheelProgressDialog message(String message){ 44 | this.message=message; 45 | if(mMessageView!=null){ 46 | mMessageView.setText(message); 47 | } 48 | return this; 49 | } 50 | 51 | public WheelProgressDialog title(String title){ 52 | setTitle(title); 53 | return this; 54 | } 55 | 56 | @Override 57 | public void show() { 58 | super.show(); 59 | mWheelView.setProgress(progress); 60 | mMessageView.setText(message); 61 | } 62 | 63 | public WheelProgressDialog progress(int value) { 64 | if(value<0){ 65 | value=0; 66 | } 67 | if(value>100){ 68 | value=100; 69 | } 70 | this.progress=value*360/100; 71 | if(mWheelView!=null){ 72 | mWheelView.setProgress(progress); 73 | mWheelView.setText(value+"%"); 74 | } 75 | return this; 76 | } 77 | 78 | 79 | 80 | } 81 | -------------------------------------------------------------------------------- /src/com/todddavies/components/progressbar/ProgressWheel.java: -------------------------------------------------------------------------------- 1 | package com.todddavies.components.progressbar; 2 | 3 | import android.content.Context; 4 | import android.content.res.TypedArray; 5 | import android.graphics.Canvas; 6 | import android.graphics.Paint; 7 | import android.graphics.Paint.Style; 8 | import android.graphics.RectF; 9 | import android.graphics.Shader; 10 | import android.os.Handler; 11 | import android.os.Message; 12 | import android.util.AttributeSet; 13 | import android.view.View; 14 | 15 | import com.github.tcking.wheelprogress.R; 16 | 17 | 18 | /** 19 | * An indicator of progress, similar to Android's ProgressBar. 20 | * Can be used in 'spin mode' or 'increment mode' 21 | * 22 | * @author Todd Davies 23 | *

24 | * Licensed under the Creative Commons Attribution 3.0 license see: 25 | * http://creativecommons.org/licenses/by/3.0/ 26 | */ 27 | public class ProgressWheel extends View { 28 | 29 | //Sizes (with defaults) 30 | private int layout_height = 0; 31 | private int layout_width = 0; 32 | private int fullRadius = 100; 33 | private int circleRadius = 80; 34 | private int barLength = 60; 35 | private int barWidth = 20; 36 | private int rimWidth = 20; 37 | private int textSize = 20; 38 | private float contourSize = 0; 39 | 40 | //Padding (with defaults) 41 | private int paddingTop = 5; 42 | private int paddingBottom = 5; 43 | private int paddingLeft = 5; 44 | private int paddingRight = 5; 45 | 46 | //Colors (with defaults) 47 | private int barColor = 0xAA000000; 48 | private int contourColor = 0xAA000000; 49 | private int circleColor = 0x00000000; 50 | private int rimColor = 0xAADDDDDD; 51 | private int textColor = 0xFF000000; 52 | 53 | //Paints 54 | private Paint barPaint = new Paint(); 55 | private Paint circlePaint = new Paint(); 56 | private Paint rimPaint = new Paint(); 57 | private Paint textPaint = new Paint(); 58 | private Paint contourPaint = new Paint(); 59 | 60 | //Rectangles 61 | @SuppressWarnings("unused") 62 | private RectF rectBounds = new RectF(); 63 | private RectF circleBounds = new RectF(); 64 | private RectF circleOuterContour = new RectF(); 65 | private RectF circleInnerContour = new RectF(); 66 | 67 | //Animation 68 | //The amount of pixels to move the bar by on each draw 69 | private int spinSpeed = 2; 70 | //The number of milliseconds to wait inbetween each draw 71 | private int delayMillis = 0; 72 | private Handler spinHandler = new Handler() { 73 | /** 74 | * This is the code that will increment the progress variable 75 | * and so spin the wheel 76 | */ 77 | @Override 78 | public void handleMessage(Message msg) { 79 | invalidate(); 80 | if (isSpinning) { 81 | progress += spinSpeed; 82 | if (progress > 360) { 83 | progress = 0; 84 | } 85 | spinHandler.sendEmptyMessageDelayed(0, delayMillis); 86 | } 87 | //super.handleMessage(msg); 88 | } 89 | }; 90 | int progress = 0; 91 | boolean isSpinning = false; 92 | 93 | //Other 94 | private String text = ""; 95 | private String[] splitText = {}; 96 | 97 | /** 98 | * The constructor for the ProgressWheel 99 | * 100 | * @param context 101 | * @param attrs 102 | */ 103 | public ProgressWheel(Context context, AttributeSet attrs) { 104 | super(context, attrs); 105 | 106 | parseAttributes(context.obtainStyledAttributes(attrs, 107 | R.styleable.ProgressWheel)); 108 | } 109 | 110 | //---------------------------------- 111 | //Setting up stuff 112 | //---------------------------------- 113 | 114 | /** 115 | * Use onSizeChanged instead of onAttachedToWindow to get the dimensions of the view, 116 | * because this method is called after measuring the dimensions of MATCH_PARENT & WRAP_CONTENT. 117 | * Use this dimensions to setup the bounds and paints. 118 | */ 119 | @Override 120 | protected void onSizeChanged(int w, int h, int oldw, int oldh) { 121 | super.onSizeChanged(w, h, oldw, oldh); 122 | 123 | // Share the dimensions 124 | layout_width = w; 125 | layout_height = h; 126 | 127 | setupBounds(); 128 | setupPaints(); 129 | invalidate(); 130 | } 131 | 132 | /** 133 | * Set the properties of the paints we're using to 134 | * draw the progress wheel 135 | */ 136 | private void setupPaints() { 137 | barPaint.setColor(barColor); 138 | barPaint.setAntiAlias(true); 139 | barPaint.setStyle(Style.STROKE); 140 | barPaint.setStrokeWidth(barWidth); 141 | 142 | rimPaint.setColor(rimColor); 143 | rimPaint.setAntiAlias(true); 144 | rimPaint.setStyle(Style.STROKE); 145 | rimPaint.setStrokeWidth(rimWidth); 146 | 147 | circlePaint.setColor(circleColor); 148 | circlePaint.setAntiAlias(true); 149 | circlePaint.setStyle(Style.FILL); 150 | 151 | textPaint.setColor(textColor); 152 | textPaint.setStyle(Style.FILL); 153 | textPaint.setAntiAlias(true); 154 | textPaint.setTextSize(textSize); 155 | 156 | contourPaint.setColor(contourColor); 157 | contourPaint.setAntiAlias(true); 158 | contourPaint.setStyle(Style.STROKE); 159 | contourPaint.setStrokeWidth(contourSize); 160 | } 161 | 162 | /** 163 | * Set the bounds of the component 164 | */ 165 | private void setupBounds() { 166 | // Width should equal to Height, find the min value to steup the circle 167 | int minValue = Math.min(layout_width, layout_height); 168 | 169 | // Calc the Offset if needed 170 | int xOffset = layout_width - minValue; 171 | int yOffset = layout_height - minValue; 172 | 173 | // Add the offset 174 | paddingTop = this.getPaddingTop() + (yOffset / 2); 175 | paddingBottom = this.getPaddingBottom() + (yOffset / 2); 176 | paddingLeft = this.getPaddingLeft() + (xOffset / 2); 177 | paddingRight = this.getPaddingRight() + (xOffset / 2); 178 | 179 | rectBounds = new RectF(paddingLeft, 180 | paddingTop, 181 | this.getLayoutParams().width - paddingRight, 182 | this.getLayoutParams().height - paddingBottom); 183 | 184 | circleBounds = new RectF(paddingLeft + barWidth, 185 | paddingTop + barWidth, 186 | this.getLayoutParams().width - paddingRight - barWidth, 187 | this.getLayoutParams().height - paddingBottom - barWidth); 188 | circleInnerContour = new RectF(circleBounds.left + (rimWidth / 2.0f) + (contourSize / 2.0f), circleBounds.top + (rimWidth / 2.0f) + (contourSize / 2.0f), circleBounds.right - (rimWidth / 2.0f) - (contourSize / 2.0f), circleBounds.bottom - (rimWidth / 2.0f) - (contourSize / 2.0f)); 189 | circleOuterContour = new RectF(circleBounds.left - (rimWidth / 2.0f) - (contourSize / 2.0f), circleBounds.top - (rimWidth / 2.0f) - (contourSize / 2.0f), circleBounds.right + (rimWidth / 2.0f) + (contourSize / 2.0f), circleBounds.bottom + (rimWidth / 2.0f) + (contourSize / 2.0f)); 190 | 191 | fullRadius = (this.getLayoutParams().width - paddingRight - barWidth) / 2; 192 | circleRadius = (fullRadius - barWidth) + 1; 193 | } 194 | 195 | /** 196 | * Parse the attributes passed to the view from the XML 197 | * 198 | * @param a the attributes to parse 199 | */ 200 | private void parseAttributes(TypedArray a) { 201 | barWidth = (int) a.getDimension(R.styleable.ProgressWheel_barWidth, 202 | barWidth); 203 | 204 | rimWidth = (int) a.getDimension(R.styleable.ProgressWheel_rimWidth, 205 | rimWidth); 206 | 207 | spinSpeed = (int) a.getDimension(R.styleable.ProgressWheel_spinSpeed, 208 | spinSpeed); 209 | 210 | delayMillis = a.getInteger(R.styleable.ProgressWheel_delayMillis, 211 | delayMillis); 212 | if (delayMillis < 0) { 213 | delayMillis = 0; 214 | } 215 | 216 | barColor = a.getColor(R.styleable.ProgressWheel_barColor, barColor); 217 | 218 | barLength = (int) a.getDimension(R.styleable.ProgressWheel_barLength, 219 | barLength); 220 | 221 | textSize = (int) a.getDimension(R.styleable.ProgressWheel_textSize, 222 | textSize); 223 | 224 | textColor = (int) a.getColor(R.styleable.ProgressWheel_textColor, 225 | textColor); 226 | 227 | //if the text is empty , so ignore it 228 | if (a.hasValue(R.styleable.ProgressWheel_text)) { 229 | setText(a.getString(R.styleable.ProgressWheel_text)); 230 | } 231 | 232 | rimColor = (int) a.getColor(R.styleable.ProgressWheel_rimColor, 233 | rimColor); 234 | 235 | circleColor = (int) a.getColor(R.styleable.ProgressWheel_circleColor, 236 | circleColor); 237 | 238 | contourColor = a.getColor(R.styleable.ProgressWheel_contourColor, contourColor); 239 | contourSize = a.getDimension(R.styleable.ProgressWheel_contourSize, contourSize); 240 | 241 | 242 | // Recycle 243 | a.recycle(); 244 | } 245 | 246 | //---------------------------------- 247 | //Animation stuff 248 | //---------------------------------- 249 | 250 | protected void onDraw(Canvas canvas) { 251 | super.onDraw(canvas); 252 | //Draw the rim 253 | canvas.drawArc(circleBounds, 360, 360, false, rimPaint); 254 | canvas.drawArc(circleOuterContour, 360, 360, false, contourPaint); 255 | canvas.drawArc(circleInnerContour, 360, 360, false, contourPaint); 256 | //Draw the bar 257 | if (isSpinning) { 258 | canvas.drawArc(circleBounds, progress - 90, barLength, false, 259 | barPaint); 260 | } else { 261 | canvas.drawArc(circleBounds, -90, progress, false, barPaint); 262 | } 263 | //Draw the inner circle 264 | canvas.drawCircle((circleBounds.width() / 2) + rimWidth + paddingLeft, 265 | (circleBounds.height() / 2) + rimWidth + paddingTop, 266 | circleRadius, 267 | circlePaint); 268 | //Draw the text (attempts to center it horizontally and vertically) 269 | float textHeight = textPaint.descent() - textPaint.ascent(); 270 | float verticalTextOffset = (textHeight / 2) - textPaint.descent(); 271 | 272 | for (String s : splitText) { 273 | float horizontalTextOffset = textPaint.measureText(s) / 2; 274 | canvas.drawText(s, this.getWidth() / 2 - horizontalTextOffset, 275 | this.getHeight() / 2 + verticalTextOffset, textPaint); 276 | } 277 | } 278 | 279 | /** 280 | * Check if the wheel is currently spinning 281 | */ 282 | 283 | public boolean isSpinning() { 284 | if(isSpinning){ 285 | return true; 286 | } else { 287 | return false; 288 | } 289 | } 290 | 291 | /** 292 | * Reset the count (in increment mode) 293 | */ 294 | public void resetCount() { 295 | progress = 0; 296 | setText("0%"); 297 | invalidate(); 298 | } 299 | 300 | /** 301 | * Turn off spin mode 302 | */ 303 | public void stopSpinning() { 304 | isSpinning = false; 305 | progress = 0; 306 | spinHandler.removeMessages(0); 307 | } 308 | 309 | 310 | /** 311 | * Puts the view on spin mode 312 | */ 313 | public void spin() { 314 | isSpinning = true; 315 | spinHandler.sendEmptyMessage(0); 316 | } 317 | 318 | /** 319 | * Increment the progress by 1 (of 360) 320 | */ 321 | public void incrementProgress() { 322 | isSpinning = false; 323 | progress++; 324 | if (progress > 360) 325 | progress = 0; 326 | // setText(Math.round(((float) progress / 360) * 100) + "%"); 327 | spinHandler.sendEmptyMessage(0); 328 | } 329 | 330 | 331 | /** 332 | * Set the progress to a specific value 333 | */ 334 | public void setProgress(int i) { 335 | isSpinning = false; 336 | progress = i; 337 | spinHandler.sendEmptyMessage(0); 338 | } 339 | 340 | //---------------------------------- 341 | //Getters + setters 342 | //---------------------------------- 343 | 344 | /** 345 | * Set the text in the progress bar 346 | * Doesn't invalidate the view 347 | * 348 | * @param text the text to show ('\n' constitutes a new line) 349 | */ 350 | public void setText(String text) { 351 | this.text = text; 352 | splitText = this.text.split("\n"); 353 | } 354 | 355 | public int getCircleRadius() { 356 | return circleRadius; 357 | } 358 | 359 | public void setCircleRadius(int circleRadius) { 360 | this.circleRadius = circleRadius; 361 | } 362 | 363 | public int getBarLength() { 364 | return barLength; 365 | } 366 | 367 | public void setBarLength(int barLength) { 368 | this.barLength = barLength; 369 | } 370 | 371 | public int getBarWidth() { 372 | return barWidth; 373 | } 374 | 375 | public void setBarWidth(int barWidth) { 376 | this.barWidth = barWidth; 377 | } 378 | 379 | public int getTextSize() { 380 | return textSize; 381 | } 382 | 383 | public void setTextSize(int textSize) { 384 | this.textSize = textSize; 385 | } 386 | 387 | public int getPaddingTop() { 388 | return paddingTop; 389 | } 390 | 391 | public void setPaddingTop(int paddingTop) { 392 | this.paddingTop = paddingTop; 393 | } 394 | 395 | public int getPaddingBottom() { 396 | return paddingBottom; 397 | } 398 | 399 | public void setPaddingBottom(int paddingBottom) { 400 | this.paddingBottom = paddingBottom; 401 | } 402 | 403 | public int getPaddingLeft() { 404 | return paddingLeft; 405 | } 406 | 407 | public void setPaddingLeft(int paddingLeft) { 408 | this.paddingLeft = paddingLeft; 409 | } 410 | 411 | public int getPaddingRight() { 412 | return paddingRight; 413 | } 414 | 415 | public void setPaddingRight(int paddingRight) { 416 | this.paddingRight = paddingRight; 417 | } 418 | 419 | public int getBarColor() { 420 | return barColor; 421 | } 422 | 423 | public void setBarColor(int barColor) { 424 | this.barColor = barColor; 425 | } 426 | 427 | public int getCircleColor() { 428 | return circleColor; 429 | } 430 | 431 | public void setCircleColor(int circleColor) { 432 | this.circleColor = circleColor; 433 | } 434 | 435 | public int getRimColor() { 436 | return rimColor; 437 | } 438 | 439 | public void setRimColor(int rimColor) { 440 | this.rimColor = rimColor; 441 | } 442 | 443 | 444 | public Shader getRimShader() { 445 | return rimPaint.getShader(); 446 | } 447 | 448 | public void setRimShader(Shader shader) { 449 | this.rimPaint.setShader(shader); 450 | } 451 | 452 | public int getTextColor() { 453 | return textColor; 454 | } 455 | 456 | public void setTextColor(int textColor) { 457 | this.textColor = textColor; 458 | } 459 | 460 | public int getSpinSpeed() { 461 | return spinSpeed; 462 | } 463 | 464 | public void setSpinSpeed(int spinSpeed) { 465 | this.spinSpeed = spinSpeed; 466 | } 467 | 468 | public int getRimWidth() { 469 | return rimWidth; 470 | } 471 | 472 | public void setRimWidth(int rimWidth) { 473 | this.rimWidth = rimWidth; 474 | } 475 | 476 | public int getDelayMillis() { 477 | return delayMillis; 478 | } 479 | 480 | public void setDelayMillis(int delayMillis) { 481 | this.delayMillis = delayMillis; 482 | } 483 | } 484 | --------------------------------------------------------------------------------