├── .gitignore ├── LICENSE ├── README.md ├── app ├── .gitignore ├── build.gradle ├── proguard-rules.pro └── src │ ├── androidTest │ └── java │ │ └── io │ │ └── sule │ │ └── gaugeview │ │ └── ApplicationTest.java │ └── main │ ├── AndroidManifest.xml │ ├── java │ └── io │ │ └── sule │ │ └── gaugeview │ │ └── GaugeActivity.java │ └── res │ ├── layout │ └── activity_gauge.xml │ ├── menu │ └── menu_gauge.xml │ ├── mipmap-hdpi │ └── ic_launcher.png │ ├── mipmap-mdpi │ └── ic_launcher.png │ ├── mipmap-xhdpi │ └── ic_launcher.png │ ├── mipmap-xxhdpi │ └── ic_launcher.png │ ├── values-v21 │ └── styles.xml │ ├── values-w820dp │ └── dimens.xml │ └── values │ ├── attrs.xml │ ├── dimens.xml │ ├── strings.xml │ └── styles.xml ├── build.gradle ├── build └── intermediates │ └── dex-cache │ └── cache.xml ├── gaugelibrary ├── .gitignore ├── build.gradle ├── proguard-rules.pro └── src │ ├── androidTest │ └── java │ │ └── io │ │ └── sule │ │ └── gaugelibrary │ │ └── ApplicationTest.java │ └── main │ ├── AndroidManifest.xml │ ├── java │ └── io │ │ └── sule │ │ └── gaugelibrary │ │ └── GaugeView.java │ └── res │ ├── drawable │ ├── brushed_alu.png │ ├── brushed_alu2.png │ ├── carbon_fibre.png │ └── light_alu.png │ └── values │ ├── arrays.xml │ ├── attrs.xml │ └── strings.xml ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat └── settings.gradle /.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 | target/ 16 | 17 | # Local configuration file (sdk path, etc) 18 | local.properties 19 | 20 | # Eclipse files 21 | .properties 22 | .settings 23 | .classpath 24 | .project 25 | 26 | # IntelliJ files 27 | .idea 28 | *.iml 29 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | 2 | Apache License 3 | Version 2.0, January 2004 4 | http://www.apache.org/licenses/ 5 | 6 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 7 | 8 | 1. Definitions. 9 | 10 | "License" shall mean the terms and conditions for use, reproduction, 11 | and distribution as defined by Sections 1 through 9 of this document. 12 | 13 | "Licensor" shall mean the copyright owner or entity authorized by 14 | the copyright owner that is granting the License. 15 | 16 | "Legal Entity" shall mean the union of the acting entity and all 17 | other entities that control, are controlled by, or are under common 18 | control with that entity. For the purposes of this definition, 19 | "control" means (i) the power, direct or indirect, to cause the 20 | direction or management of such entity, whether by contract or 21 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 22 | outstanding shares, or (iii) beneficial ownership of such entity. 23 | 24 | "You" (or "Your") shall mean an individual or Legal Entity 25 | exercising permissions granted by this License. 26 | 27 | "Source" form shall mean the preferred form for making modifications, 28 | including but not limited to software source code, documentation 29 | source, and configuration files. 30 | 31 | "Object" form shall mean any form resulting from mechanical 32 | transformation or translation of a Source form, including but 33 | not limited to compiled object code, generated documentation, 34 | and conversions to other media types. 35 | 36 | "Work" shall mean the work of authorship, whether in Source or 37 | Object form, made available under the License, as indicated by a 38 | copyright notice that is included in or attached to the work 39 | (an example is provided in the Appendix below). 40 | 41 | "Derivative Works" shall mean any work, whether in Source or Object 42 | form, that is based on (or derived from) the Work and for which the 43 | editorial revisions, annotations, elaborations, or other modifications 44 | represent, as a whole, an original work of authorship. For the purposes 45 | of this License, Derivative Works shall not include works that remain 46 | separable from, or merely link (or bind by name) to the interfaces of, 47 | the Work and Derivative Works thereof. 48 | 49 | "Contribution" shall mean any work of authorship, including 50 | the original version of the Work and any modifications or additions 51 | to that Work or Derivative Works thereof, that is intentionally 52 | submitted to Licensor for inclusion in the Work by the copyright owner 53 | or by an individual or Legal Entity authorized to submit on behalf of 54 | the copyright owner. For the purposes of this definition, "submitted" 55 | means any form of electronic, verbal, or written communication sent 56 | to the Licensor or its representatives, including but not limited to 57 | communication on electronic mailing lists, source code control systems, 58 | and issue tracking systems that are managed by, or on behalf of, the 59 | Licensor for the purpose of discussing and improving the Work, but 60 | excluding communication that is conspicuously marked or otherwise 61 | designated in writing by the copyright owner as "Not a Contribution." 62 | 63 | "Contributor" shall mean Licensor and any individual or Legal Entity 64 | on behalf of whom a Contribution has been received by Licensor and 65 | subsequently incorporated within the Work. 66 | 67 | 2. Grant of Copyright License. Subject to the terms and conditions of 68 | this License, each Contributor hereby grants to You a perpetual, 69 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 70 | copyright license to reproduce, prepare Derivative Works of, 71 | publicly display, publicly perform, sublicense, and distribute the 72 | Work and such Derivative Works in Source or Object form. 73 | 74 | 3. Grant of Patent License. Subject to the terms and conditions of 75 | this License, each Contributor hereby grants to You a perpetual, 76 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 77 | (except as stated in this section) patent license to make, have made, 78 | use, offer to sell, sell, import, and otherwise transfer the Work, 79 | where such license applies only to those patent claims licensable 80 | by such Contributor that are necessarily infringed by their 81 | Contribution(s) alone or by combination of their Contribution(s) 82 | with the Work to which such Contribution(s) was submitted. If You 83 | institute patent litigation against any entity (including a 84 | cross-claim or counterclaim in a lawsuit) alleging that the Work 85 | or a Contribution incorporated within the Work constitutes direct 86 | or contributory patent infringement, then any patent licenses 87 | granted to You under this License for that Work shall terminate 88 | as of the date such litigation is filed. 89 | 90 | 4. Redistribution. You may reproduce and distribute copies of the 91 | Work or Derivative Works thereof in any medium, with or without 92 | modifications, and in Source or Object form, provided that You 93 | meet the following conditions: 94 | 95 | (a) You must give any other recipients of the Work or 96 | Derivative Works a copy of this License; and 97 | 98 | (b) You must cause any modified files to carry prominent notices 99 | stating that You changed the files; and 100 | 101 | (c) You must retain, in the Source form of any Derivative Works 102 | that You distribute, all copyright, patent, trademark, and 103 | attribution notices from the Source form of the Work, 104 | excluding those notices that do not pertain to any part of 105 | the Derivative Works; and 106 | 107 | (d) If the Work includes a "NOTICE" text file as part of its 108 | distribution, then any Derivative Works that You distribute must 109 | include a readable copy of the attribution notices contained 110 | within such NOTICE file, excluding those notices that do not 111 | pertain to any part of the Derivative Works, in at least one 112 | of the following places: within a NOTICE text file distributed 113 | as part of the Derivative Works; within the Source form or 114 | documentation, if provided along with the Derivative Works; or, 115 | within a display generated by the Derivative Works, if and 116 | wherever such third-party notices normally appear. The contents 117 | of the NOTICE file are for informational purposes only and 118 | do not modify the License. You may add Your own attribution 119 | notices within Derivative Works that You distribute, alongside 120 | or as an addendum to the NOTICE text from the Work, provided 121 | that such additional attribution notices cannot be construed 122 | as modifying the License. 123 | 124 | You may add Your own copyright statement to Your modifications and 125 | may provide additional or different license terms and conditions 126 | for use, reproduction, or distribution of Your modifications, or 127 | for any such Derivative Works as a whole, provided Your use, 128 | reproduction, and distribution of the Work otherwise complies with 129 | the conditions stated in this License. 130 | 131 | 5. Submission of Contributions. Unless You explicitly state otherwise, 132 | any Contribution intentionally submitted for inclusion in the Work 133 | by You to the Licensor shall be under the terms and conditions of 134 | this License, without any additional terms or conditions. 135 | Notwithstanding the above, nothing herein shall supersede or modify 136 | the terms of any separate license agreement you may have executed 137 | with Licensor regarding such Contributions. 138 | 139 | 6. Trademarks. This License does not grant permission to use the trade 140 | names, trademarks, service marks, or product names of the Licensor, 141 | except as required for reasonable and customary use in describing the 142 | origin of the Work and reproducing the content of the NOTICE file. 143 | 144 | 7. Disclaimer of Warranty. Unless required by applicable law or 145 | agreed to in writing, Licensor provides the Work (and each 146 | Contributor provides its Contributions) on an "AS IS" BASIS, 147 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 148 | implied, including, without limitation, any warranties or conditions 149 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 150 | PARTICULAR PURPOSE. You are solely responsible for determining the 151 | appropriateness of using or redistributing the Work and assume any 152 | risks associated with Your exercise of permissions under this License. 153 | 154 | 8. Limitation of Liability. In no event and under no legal theory, 155 | whether in tort (including negligence), contract, or otherwise, 156 | unless required by applicable law (such as deliberate and grossly 157 | negligent acts) or agreed to in writing, shall any Contributor be 158 | liable to You for damages, including any direct, indirect, special, 159 | incidental, or consequential damages of any character arising as a 160 | result of this License or out of the use or inability to use the 161 | Work (including but not limited to damages for loss of goodwill, 162 | work stoppage, computer failure or malfunction, or any and all 163 | other commercial damages or losses), even if such Contributor 164 | has been advised of the possibility of such damages. 165 | 166 | 9. Accepting Warranty or Additional Liability. While redistributing 167 | the Work or Derivative Works thereof, You may choose to offer, 168 | and charge a fee for, acceptance of support, warranty, indemnity, 169 | or other liability obligations and/or rights consistent with this 170 | License. However, in accepting such obligations, You may act only 171 | on Your own behalf and on Your sole responsibility, not on behalf 172 | of any other Contributor, and only if You agree to indemnify, 173 | defend, and hold each Contributor harmless for any liability 174 | incurred by, or claims asserted against, such Contributor by reason 175 | of your accepting any such warranty or additional liability. 176 | 177 | END OF TERMS AND CONDITIONS 178 | 179 | APPENDIX: How to apply the Apache License to your work. 180 | 181 | To apply the Apache License to your work, attach the following 182 | boilerplate notice, with the fields enclosed by brackets "[]" 183 | replaced with your own identifying information. (Don't include 184 | the brackets!) The text should be enclosed in the appropriate 185 | comment syntax for the file format. We also recommend that a 186 | file or class name and description of purpose be included on the 187 | same "printed page" as the copyright notice for easier 188 | identification within third-party archives. 189 | 190 | Copyright 2012 readyState Software Ltd 191 | 192 | Licensed under the Apache License, Version 2.0 (the "License"); 193 | you may not use this file except in compliance with the License. 194 | You may obtain a copy of the License at 195 | 196 | http://www.apache.org/licenses/LICENSE-2.0 197 | 198 | Unless required by applicable law or agreed to in writing, software 199 | distributed under the License is distributed on an "AS IS" BASIS, 200 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 201 | See the License for the specific language governing permissions and 202 | limitations under the License. 203 | 204 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | GaugeView 2 | ========= 3 | 4 | An Android library for drawing gauges on Canvas. 5 | 6 | For instructions how to use this library see this link: 7 | http://www.sule.io/?p=25 8 | 9 | 10 | ![screen shot 2015-04-12 at 06 03 58](https://cloud.githubusercontent.com/assets/3107367/7104368/098ac554-e0db-11e4-9e79-5c9c0e2085cf.png) 11 | 12 | 13 | TODO (coming soon) 14 | ------------------ 15 | 16 | Add wearables support. 17 | 18 | Document the main features. 19 | 20 | -------------------------------------------------------------------------------- /app/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /app/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | 3 | android { 4 | compileSdkVersion 22 5 | buildToolsVersion "22.0.1" 6 | 7 | defaultConfig { 8 | applicationId "io.sule.gaugeview" 9 | minSdkVersion 8 10 | targetSdkVersion 22 11 | versionCode 1 12 | versionName "1.0" 13 | } 14 | buildTypes { 15 | release { 16 | minifyEnabled false 17 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 18 | } 19 | } 20 | } 21 | 22 | dependencies { 23 | compile fileTree(dir: 'libs', include: ['*.jar']) 24 | compile project (":gaugelibrary") 25 | } 26 | -------------------------------------------------------------------------------- /app/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # By default, the flags in this file are appended to flags specified 3 | # in /Users/sulejman/Library/Android/sdk/tools/proguard/proguard-android.txt 4 | # You can edit the include path and order by changing the proguardFiles 5 | # directive in build.gradle. 6 | # 7 | # For more details, see 8 | # http://developer.android.com/guide/developing/tools/proguard.html 9 | 10 | # Add any project specific keep options here: 11 | 12 | # If your project uses WebView with JS, uncomment the following 13 | # and specify the fully qualified class name to the JavaScript interface 14 | # class: 15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 16 | # public *; 17 | #} 18 | -------------------------------------------------------------------------------- /app/src/androidTest/java/io/sule/gaugeview/ApplicationTest.java: -------------------------------------------------------------------------------- 1 | package io.sule.gaugeview; 2 | 3 | import android.app.Application; 4 | import android.test.ApplicationTestCase; 5 | 6 | /** 7 | * Testing Fundamentals 8 | */ 9 | public class ApplicationTest extends ApplicationTestCase { 10 | public ApplicationTest() { 11 | super(Application.class); 12 | } 13 | } -------------------------------------------------------------------------------- /app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 10 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /app/src/main/java/io/sule/gaugeview/GaugeActivity.java: -------------------------------------------------------------------------------- 1 | package io.sule.gaugeview; 2 | 3 | import android.app.Activity; 4 | import android.os.Bundle; 5 | import android.os.CountDownTimer; 6 | 7 | 8 | import java.util.Random; 9 | import io.sule.gaugelibrary.GaugeView; 10 | 11 | 12 | public class GaugeActivity extends Activity{ 13 | 14 | private GaugeView mGaugeView; 15 | private final Random RAND = new Random(); 16 | 17 | @Override 18 | protected void onCreate(Bundle savedInstanceState) { 19 | super.onCreate(savedInstanceState); 20 | setContentView(R.layout.activity_gauge); 21 | 22 | mGaugeView = (GaugeView) findViewById(R.id.gauge_view); 23 | mTimer.start(); 24 | 25 | } 26 | 27 | private final CountDownTimer mTimer = new CountDownTimer(30000, 1000) { 28 | 29 | @Override 30 | public void onTick(final long millisUntilFinished) { 31 | mGaugeView.setTargetValue(RAND.nextInt(101)); 32 | } 33 | 34 | @Override 35 | public void onFinish() {} 36 | }; 37 | 38 | 39 | } -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_gauge.xml: -------------------------------------------------------------------------------- 1 | 12 | 13 | 27 | 28 | 29 | -------------------------------------------------------------------------------- /app/src/main/res/menu/menu_gauge.xml: -------------------------------------------------------------------------------- 1 | 3 | 5 | 6 | -------------------------------------------------------------------------------- /app/src/main/res/mipmap-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Sulejman/GaugeView/e2570476718afb8126d8d63e35c9a883adcf97ac/app/src/main/res/mipmap-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Sulejman/GaugeView/e2570476718afb8126d8d63e35c9a883adcf97ac/app/src/main/res/mipmap-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Sulejman/GaugeView/e2570476718afb8126d8d63e35c9a883adcf97ac/app/src/main/res/mipmap-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Sulejman/GaugeView/e2570476718afb8126d8d63e35c9a883adcf97ac/app/src/main/res/mipmap-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/values-v21/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 5 | 6 | -------------------------------------------------------------------------------- /app/src/main/res/values-w820dp/dimens.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 64dp 6 | 7 | -------------------------------------------------------------------------------- /app/src/main/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 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | -------------------------------------------------------------------------------- /app/src/main/res/values/dimens.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 16dp 4 | 16dp 5 | 6 | -------------------------------------------------------------------------------- /app/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | Gauge View 3 | 4 | Hello world! 5 | Settings 6 | 7 | -------------------------------------------------------------------------------- /app/src/main/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /build.gradle: -------------------------------------------------------------------------------- 1 | // Top-level build file where you can add configuration options common to all sub-projects/modules. 2 | 3 | buildscript { 4 | repositories { 5 | jcenter() 6 | } 7 | dependencies { 8 | classpath 'com.android.tools.build:gradle:1.1.0' 9 | 10 | // NOTE: Do not place your application dependencies here; they belong 11 | // in the individual module build.gradle files 12 | } 13 | } 14 | 15 | allprojects { 16 | repositories { 17 | jcenter() 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /build/intermediates/dex-cache/cache.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /gaugelibrary/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /gaugelibrary/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.library' 2 | 3 | android { 4 | compileSdkVersion 22 5 | buildToolsVersion "22.0.1" 6 | 7 | defaultConfig { 8 | minSdkVersion 21 9 | targetSdkVersion 22 10 | versionCode 1 11 | versionName "1.0" 12 | } 13 | buildTypes { 14 | release { 15 | minifyEnabled false 16 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 17 | } 18 | } 19 | } 20 | 21 | dependencies { 22 | compile fileTree(dir: 'libs', include: ['*.jar']) 23 | } 24 | -------------------------------------------------------------------------------- /gaugelibrary/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # By default, the flags in this file are appended to flags specified 3 | # in /Users/sulejman/Library/Android/sdk/tools/proguard/proguard-android.txt 4 | # You can edit the include path and order by changing the proguardFiles 5 | # directive in build.gradle. 6 | # 7 | # For more details, see 8 | # http://developer.android.com/guide/developing/tools/proguard.html 9 | 10 | # Add any project specific keep options here: 11 | 12 | # If your project uses WebView with JS, uncomment the following 13 | # and specify the fully qualified class name to the JavaScript interface 14 | # class: 15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 16 | # public *; 17 | #} 18 | -------------------------------------------------------------------------------- /gaugelibrary/src/androidTest/java/io/sule/gaugelibrary/ApplicationTest.java: -------------------------------------------------------------------------------- 1 | package io.sule.gaugelibrary; 2 | 3 | import android.app.Application; 4 | import android.test.ApplicationTestCase; 5 | 6 | /** 7 | * Testing Fundamentals 8 | */ 9 | public class ApplicationTest extends ApplicationTestCase { 10 | public ApplicationTest() { 11 | super(Application.class); 12 | } 13 | } -------------------------------------------------------------------------------- /gaugelibrary/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /gaugelibrary/src/main/java/io/sule/gaugelibrary/GaugeView.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2015 Sulejman Sarajlija 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 7 | *******************************************************************************/ 8 | package io.sule.gaugelibrary; 9 | 10 | import android.annotation.TargetApi; 11 | import android.content.Context; 12 | import android.content.res.Resources; 13 | import android.content.res.TypedArray; 14 | import android.graphics.Bitmap; 15 | import android.graphics.BitmapFactory; 16 | import android.graphics.BitmapShader; 17 | import android.graphics.Canvas; 18 | import android.graphics.Color; 19 | import android.graphics.ComposeShader; 20 | import android.graphics.LinearGradient; 21 | import android.graphics.Matrix; 22 | import android.graphics.Paint; 23 | import android.graphics.Paint.Align; 24 | import android.graphics.Path; 25 | import android.graphics.PorterDuff; 26 | import android.graphics.RadialGradient; 27 | import android.graphics.RectF; 28 | import android.graphics.Shader.TileMode; 29 | import android.graphics.Typeface; 30 | import android.os.Build; 31 | import android.os.Bundle; 32 | import android.os.Parcelable; 33 | import android.text.TextUtils; 34 | import android.util.AttributeSet; 35 | import android.util.Log; 36 | import android.view.View; 37 | import android.widget.TextView; 38 | 39 | public class GaugeView extends View { 40 | 41 | public static final int SIZE = 300; 42 | public static final float TOP = 0.0f; 43 | public static final float LEFT = 0.0f; 44 | public static final float RIGHT = 1.0f; 45 | public static final float BOTTOM = 1.0f; 46 | public static final float CENTER = 0.5f; 47 | public static final boolean SHOW_OUTER_SHADOW = true; 48 | public static final boolean SHOW_OUTER_BORDER = true; 49 | public static final boolean SHOW_OUTER_RIM = true; 50 | public static final boolean SHOW_INNER_RIM = true; 51 | public static final boolean SHOW_NEEDLE = true; 52 | public static final boolean SHOW_SCALE = false; 53 | public static final boolean SHOW_RANGES = true; 54 | public static final boolean SHOW_TEXT = false; 55 | 56 | public static final float OUTER_SHADOW_WIDTH = 0.03f; 57 | public static final float OUTER_BORDER_WIDTH = 0.04f; 58 | public static final float OUTER_RIM_WIDTH = 0.05f; 59 | public static final float INNER_RIM_WIDTH = 0.06f; 60 | public static final float INNER_RIM_BORDER_WIDTH = 0.005f; 61 | 62 | public static final float NEEDLE_WIDTH = 0.025f; 63 | public static final float NEEDLE_HEIGHT = 0.32f; 64 | public static final int INNER_CIRCLE_COLOR = Color.rgb(190, 215, 123); 65 | public static final int OUTER_CIRCLE_COLOR = Color.rgb(205, 231, 132); 66 | 67 | 68 | public static final float SCALE_POSITION = 0.015f; 69 | public static final float SCALE_START_VALUE = 0.0f; 70 | public static final float SCALE_END_VALUE = 100.0f; 71 | public static final float SCALE_START_ANGLE = 60.0f; 72 | public static final int SCALE_DIVISIONS = 10; 73 | public static final int SCALE_SUBDIVISIONS = 5; 74 | 75 | public static final int[] OUTER_SHADOW_COLORS = {Color.argb(40, 255, 254, 187), Color.argb(20, 255, 247, 219), 76 | Color.argb(5, 255, 255, 255)}; 77 | public static final float[] OUTER_SHADOW_POS = {0.90f, 0.95f, 0.99f}; 78 | 79 | public static final float[] RANGE_VALUES = {16.0f, 25.0f, 40.0f, 100.0f}; 80 | public static final int[] RANGE_COLORS = {Color.rgb(0, 0, 0), Color.rgb(0, 0, 0), Color.rgb(0, 0, 0), 81 | Color.rgb(0, 0, 0)}; 82 | 83 | public static final int TEXT_SHADOW_COLOR = Color.argb(100, 0, 0, 0); 84 | public static final int TEXT_VALUE_COLOR = Color.WHITE; 85 | public static final int TEXT_UNIT_COLOR = Color.WHITE; 86 | public static final float TEXT_VALUE_SIZE = 0.3f; 87 | public static final float TEXT_UNIT_SIZE = 0.1f; 88 | 89 | 90 | // *--------------------------------------------------------------------- *// 91 | // Customizable properties 92 | // *--------------------------------------------------------------------- *// 93 | 94 | private boolean mShowOuterShadow; 95 | private boolean mShowOuterBorder; 96 | private boolean mShowOuterRim; 97 | private boolean mShowInnerRim; 98 | private boolean mShowScale; 99 | private boolean mShowRanges; 100 | private boolean mShowNeedle; 101 | private boolean mShowText; 102 | 103 | private float mOuterShadowWidth; 104 | private float mOuterBorderWidth; 105 | private float mOuterRimWidth; 106 | private float mInnerRimWidth; 107 | private float mInnerRimBorderWidth; 108 | private float mNeedleWidth; 109 | private float mNeedleHeight; 110 | private int mInnerCircleColor; 111 | private int mOuterCircleColor; 112 | 113 | private float mScalePosition; 114 | private float mScaleStartValue; 115 | private float mScaleEndValue; 116 | private float mScaleStartAngle; 117 | private float[] mRangeValues; 118 | 119 | private int[] mRangeColors; 120 | private int mDivisions; 121 | private int mSubdivisions; 122 | 123 | private RectF mOuterShadowRect; 124 | private RectF mOuterBorderRect; 125 | private RectF mOuterRimRect; 126 | private RectF mInnerRimRect; 127 | private RectF mInnerRimBorderRect; 128 | private RectF mFaceRect; 129 | private RectF mScaleRect; 130 | 131 | private Bitmap mBackground; 132 | private Paint mBackgroundPaint; 133 | private Paint mOuterShadowPaint; 134 | private Paint mOuterBorderPaint; 135 | private Paint mOuterRimPaint; 136 | private Paint mInnerRimPaint; 137 | private Paint mInnerRimBorderLightPaint; 138 | private Paint mInnerRimBorderDarkPaint; 139 | private Paint mFacePaint; 140 | private Paint mFaceBorderPaint; 141 | private Paint mFaceShadowPaint; 142 | private Paint[] mRangePaints; 143 | private Paint mNeedleRightPaint; 144 | private Paint mNeedleLeftPaint; 145 | private Paint mNeedleScrewPaint; 146 | private Paint mNeedleScrewBorderPaint; 147 | private Paint mTextValuePaint; 148 | private Paint mTextUnitPaint; 149 | 150 | private String mTextValue; 151 | private String mTextUnit; 152 | private int mTextValueColor; 153 | private int mTextUnitColor; 154 | private int mTextShadowColor; 155 | private float mTextValueSize; 156 | private float mTextUnitSize; 157 | 158 | private Path mNeedleRightPath; 159 | private Path mNeedleLeftPath; 160 | 161 | // *--------------------------------------------------------------------- *// 162 | 163 | private float mScaleRotation; 164 | private float mDivisionValue; 165 | private float mSubdivisionValue; 166 | private float mSubdivisionAngle; 167 | 168 | private float mTargetValue; 169 | private float mCurrentValue; 170 | 171 | private float mNeedleVelocity; 172 | private float mNeedleAcceleration; 173 | private long mNeedleLastMoved = -1; 174 | private boolean mNeedleInitialized; 175 | 176 | public GaugeView(final Context context, final AttributeSet attrs, final int defStyle) { 177 | super(context, attrs, defStyle); 178 | readAttrs(context, attrs, defStyle); 179 | init(); 180 | } 181 | 182 | public GaugeView(final Context context, final AttributeSet attrs) { 183 | this(context, attrs, 0); 184 | } 185 | 186 | public GaugeView(final Context context) { 187 | this(context, null, 0); 188 | } 189 | 190 | private void readAttrs(final Context context, final AttributeSet attrs, final int defStyle) { 191 | final TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.GaugeView, defStyle, 0); 192 | mShowOuterShadow = a.getBoolean(R.styleable.GaugeView_showOuterShadow, SHOW_OUTER_SHADOW); 193 | mShowOuterBorder = a.getBoolean(R.styleable.GaugeView_showOuterBorder, SHOW_OUTER_BORDER); 194 | mShowOuterRim = a.getBoolean(R.styleable.GaugeView_showOuterRim, SHOW_OUTER_RIM); 195 | mShowInnerRim = a.getBoolean(R.styleable.GaugeView_showInnerRim, SHOW_INNER_RIM); 196 | mShowNeedle = a.getBoolean(R.styleable.GaugeView_showNeedle, SHOW_NEEDLE); 197 | mShowScale = a.getBoolean(R.styleable.GaugeView_showScale, SHOW_SCALE); 198 | mShowRanges = a.getBoolean(R.styleable.GaugeView_showRanges, SHOW_RANGES); 199 | mShowText = a.getBoolean(R.styleable.GaugeView_showText, SHOW_TEXT); 200 | 201 | mOuterShadowWidth = mShowOuterShadow ? a.getFloat(R.styleable.GaugeView_outerShadowWidth, OUTER_SHADOW_WIDTH) : 0.0f; 202 | mOuterBorderWidth = mShowOuterBorder ? a.getFloat(R.styleable.GaugeView_outerBorderWidth, OUTER_BORDER_WIDTH) : 0.0f; 203 | mOuterRimWidth = mShowOuterRim ? a.getFloat(R.styleable.GaugeView_outerRimWidth, OUTER_RIM_WIDTH) : 0.0f; 204 | mInnerRimWidth = mShowInnerRim ? a.getFloat(R.styleable.GaugeView_innerRimWidth, INNER_RIM_WIDTH) : 0.0f; 205 | mInnerRimBorderWidth = mShowInnerRim ? a.getFloat(R.styleable.GaugeView_innerRimBorderWidth, INNER_RIM_BORDER_WIDTH) : 0.0f; 206 | 207 | mNeedleWidth = a.getFloat(R.styleable.GaugeView_needleWidth, NEEDLE_WIDTH); 208 | mNeedleHeight = a.getFloat(R.styleable.GaugeView_needleHeight, NEEDLE_HEIGHT); 209 | mInnerCircleColor = a.getColor(R.styleable.GaugeView_innerCircleColor, INNER_CIRCLE_COLOR); 210 | mOuterCircleColor = a.getColor(R.styleable.GaugeView_outerCircleColor, OUTER_CIRCLE_COLOR); 211 | 212 | 213 | mScalePosition = (mShowScale || mShowRanges) ? a.getFloat(R.styleable.GaugeView_scalePosition, SCALE_POSITION) : 0.0f; 214 | mScaleStartValue = a.getFloat(R.styleable.GaugeView_scaleStartValue, SCALE_START_VALUE); 215 | mScaleEndValue = a.getFloat(R.styleable.GaugeView_scaleEndValue, SCALE_END_VALUE); 216 | mScaleStartAngle = a.getFloat(R.styleable.GaugeView_scaleStartAngle, SCALE_START_ANGLE); 217 | 218 | mDivisions = a.getInteger(R.styleable.GaugeView_divisions, SCALE_DIVISIONS); 219 | mSubdivisions = a.getInteger(R.styleable.GaugeView_subdivisions, SCALE_SUBDIVISIONS); 220 | 221 | if (mShowRanges) { 222 | mTextShadowColor = a.getColor(R.styleable.GaugeView_textShadowColor, TEXT_SHADOW_COLOR); 223 | final int rangesId = a.getResourceId(R.styleable.GaugeView_rangeValues, 0); 224 | final int colorsId = a.getResourceId(R.styleable.GaugeView_rangeColors, 0); 225 | readRanges(context.getResources(), rangesId, colorsId); 226 | } 227 | 228 | if (mShowText) { 229 | final int textValueId = a.getResourceId(R.styleable.GaugeView_textValue, 0); 230 | final String textValue = a.getString(R.styleable.GaugeView_textValue); 231 | mTextValue = (0 < textValueId) ? context.getString(textValueId) : (null != textValue) ? textValue : ""; 232 | 233 | final int textUnitId = a.getResourceId(R.styleable.GaugeView_textUnit, 0); 234 | final String textUnit = a.getString(R.styleable.GaugeView_textUnit); 235 | mTextUnit = (0 < textUnitId) ? context.getString(textUnitId) : (null != textUnit) ? textUnit : ""; 236 | mTextValueColor = a.getColor(R.styleable.GaugeView_textValueColor, TEXT_VALUE_COLOR); 237 | mTextUnitColor = a.getColor(R.styleable.GaugeView_textUnitColor, TEXT_UNIT_COLOR); 238 | mTextShadowColor = a.getColor(R.styleable.GaugeView_textShadowColor, TEXT_SHADOW_COLOR); 239 | 240 | mTextValueSize = a.getFloat(R.styleable.GaugeView_textValueSize, TEXT_VALUE_SIZE); 241 | mTextUnitSize = a.getFloat(R.styleable.GaugeView_textUnitSize, TEXT_UNIT_SIZE); 242 | } 243 | 244 | a.recycle(); 245 | } 246 | 247 | private void readRanges(final Resources res, final int rangesId, final int colorsId) { 248 | if (rangesId > 0 && colorsId > 0) { 249 | final String[] ranges = res.getStringArray(R.array.ranges); 250 | final String[] colors = res.getStringArray(R.array.rangeColors); 251 | if (ranges.length != colors.length) { 252 | throw new IllegalArgumentException( 253 | "The ranges and colors arrays must have the same length."); 254 | } 255 | 256 | final int length = ranges.length; 257 | mRangeValues = new float[length]; 258 | mRangeColors = new int[length]; 259 | for (int i = 0; i < length; i++) { 260 | mRangeValues[i] = Float.parseFloat(ranges[i]); 261 | mRangeColors[i] = Color.parseColor(colors[i]); 262 | } 263 | } else { 264 | mRangeValues = RANGE_VALUES; 265 | mRangeColors = RANGE_COLORS; 266 | } 267 | } 268 | 269 | @TargetApi(11) 270 | private void init() { 271 | // TODO Why isn't this working with HA layer? 272 | // The needle is not displayed although the onDraw() is being triggered by invalidate() 273 | // calls. 274 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) { 275 | setLayerType(View.LAYER_TYPE_SOFTWARE, null); 276 | } 277 | 278 | initDrawingRects(); 279 | initDrawingTools(); 280 | 281 | // Compute the scale properties 282 | if (mShowRanges) { 283 | initScale(); 284 | } 285 | } 286 | 287 | public void initDrawingRects() { 288 | // The drawing area is a rectangle of width 1 and height 1, 289 | // where (0,0) is the top left corner of the canvas. 290 | // Note that on Canvas X axis points to right, while the Y axis points downwards. 291 | mOuterShadowRect = new RectF(LEFT, TOP, RIGHT, BOTTOM); 292 | 293 | mOuterBorderRect = new RectF(mOuterShadowRect.left + mOuterShadowWidth, mOuterShadowRect.top + mOuterShadowWidth, 294 | mOuterShadowRect.right - mOuterShadowWidth, mOuterShadowRect.bottom - mOuterShadowWidth); 295 | 296 | mOuterRimRect = new RectF(mOuterBorderRect.left + mOuterBorderWidth, mOuterBorderRect.top + mOuterBorderWidth, 297 | mOuterBorderRect.right - mOuterBorderWidth, mOuterBorderRect.bottom - mOuterBorderWidth); 298 | 299 | mInnerRimRect = new RectF(mOuterRimRect.left + mOuterRimWidth, mOuterRimRect.top + mOuterRimWidth, mOuterRimRect.right 300 | - mOuterRimWidth, mOuterRimRect.bottom - mOuterRimWidth); 301 | 302 | mInnerRimBorderRect = new RectF(mInnerRimRect.left + mInnerRimBorderWidth, mInnerRimRect.top + mInnerRimBorderWidth, 303 | mInnerRimRect.right - mInnerRimBorderWidth, mInnerRimRect.bottom - mInnerRimBorderWidth); 304 | 305 | mFaceRect = new RectF(mInnerRimRect.left + mInnerRimWidth, mInnerRimRect.top + mInnerRimWidth, 306 | mInnerRimRect.right - mInnerRimWidth, mInnerRimRect.bottom - mInnerRimWidth); 307 | 308 | mScaleRect = new RectF(mFaceRect.left + mScalePosition, mFaceRect.top + mScalePosition, mFaceRect.right - mScalePosition, 309 | mFaceRect.bottom - mScalePosition); 310 | } 311 | 312 | private void initDrawingTools() { 313 | mBackgroundPaint = new Paint(); 314 | mBackgroundPaint.setFilterBitmap(true); 315 | 316 | if (mShowOuterShadow) { 317 | mOuterShadowPaint = getDefaultOuterShadowPaint(); 318 | } 319 | if (mShowOuterBorder) { 320 | mOuterBorderPaint = getDefaultOuterBorderPaint(); 321 | } 322 | if (mShowOuterRim) { 323 | mOuterRimPaint = getDefaultOuterRimPaint(); 324 | } 325 | if (mShowInnerRim) { 326 | mInnerRimPaint = getDefaultInnerRimPaint(); 327 | mInnerRimBorderLightPaint = getDefaultInnerRimBorderLightPaint(); 328 | mInnerRimBorderDarkPaint = getDefaultInnerRimBorderDarkPaint(); 329 | } 330 | if (mShowRanges) { 331 | setDefaultScaleRangePaints(); 332 | } 333 | if (mShowNeedle) { 334 | setDefaultNeedlePaths(); 335 | mNeedleLeftPaint = getDefaultNeedleLeftPaint(); 336 | mNeedleRightPaint = getDefaultNeedleRightPaint(); 337 | mNeedleScrewPaint = getDefaultNeedleScrewPaint(); 338 | mNeedleScrewBorderPaint = getDefaultNeedleScrewBorderPaint(); 339 | } 340 | if (mShowText) { 341 | mTextValuePaint = getDefaultTextValuePaint(); 342 | mTextUnitPaint = getDefaultTextUnitPaint(); 343 | } 344 | 345 | mFacePaint = getDefaultFacePaint(); 346 | mFaceBorderPaint = getDefaultFaceBorderPaint(); 347 | mFaceShadowPaint = getDefaultFaceShadowPaint(); 348 | } 349 | 350 | public Paint getDefaultOuterShadowPaint() { 351 | final Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG); 352 | paint.setStyle(Paint.Style.FILL); 353 | paint.setShader(new RadialGradient(CENTER, CENTER, mOuterShadowRect.width() / 2.0f, OUTER_SHADOW_COLORS, OUTER_SHADOW_POS, 354 | TileMode.MIRROR)); 355 | return paint; 356 | } 357 | 358 | private Paint getDefaultOuterBorderPaint() { 359 | final Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG); 360 | paint.setStyle(Paint.Style.FILL); 361 | paint.setColor(Color.argb(245, 0, 0, 0)); 362 | return paint; 363 | } 364 | 365 | public Paint getDefaultOuterRimPaint() { 366 | // Use a linear gradient to create the 3D effect 367 | final LinearGradient verticalGradient = new LinearGradient(mOuterRimRect.left, mOuterRimRect.top, mOuterRimRect.left, 368 | mOuterRimRect.bottom, Color.rgb(255, 255, 255), Color.rgb(84, 90, 100), TileMode.REPEAT); 369 | 370 | // Use a Bitmap shader for the metallic style 371 | final Bitmap bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.light_alu); 372 | final BitmapShader aluminiumTile = new BitmapShader(bitmap, TileMode.REPEAT, TileMode.REPEAT); 373 | final Matrix matrix = new Matrix(); 374 | matrix.setScale(1.0f / bitmap.getWidth(), 1.0f / bitmap.getHeight()); 375 | aluminiumTile.setLocalMatrix(matrix); 376 | 377 | final Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG); 378 | paint.setShader(new ComposeShader(verticalGradient, aluminiumTile, PorterDuff.Mode.MULTIPLY)); 379 | paint.setFilterBitmap(true); 380 | return paint; 381 | } 382 | 383 | private Paint getDefaultInnerRimPaint() { 384 | final Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG); 385 | paint.setShader(new LinearGradient(mInnerRimRect.left, mInnerRimRect.top, mInnerRimRect.left, mInnerRimRect.bottom, new int[]{ 386 | Color.argb(255, 68, 73, 80), Color.argb(255, 91, 97, 105), Color.argb(255, 178, 180, 183), Color.argb(255, 188, 188, 190), 387 | Color.argb(255, 84, 90, 100), Color.argb(255, 137, 137, 137)}, new float[]{0, 0.1f, 0.2f, 0.4f, 0.8f, 1}, 388 | TileMode.CLAMP)); 389 | return paint; 390 | } 391 | 392 | private Paint getDefaultInnerRimBorderLightPaint() { 393 | final Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG); 394 | paint.setStyle(Paint.Style.STROKE); 395 | paint.setColor(Color.argb(100, 255, 255, 255)); 396 | paint.setStrokeWidth(0.005f); 397 | return paint; 398 | } 399 | 400 | private Paint getDefaultInnerRimBorderDarkPaint() { 401 | final Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG); 402 | paint.setStyle(Paint.Style.STROKE); 403 | paint.setColor(Color.argb(100, 81, 84, 89)); 404 | paint.setStrokeWidth(0.005f); 405 | return paint; 406 | } 407 | 408 | public Paint getDefaultFacePaint() { 409 | final Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG); 410 | paint.setColor(Color.rgb(255, 255, 255)); 411 | return paint; 412 | } 413 | 414 | public Paint getDefaultFaceBorderPaint() { 415 | final Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG); 416 | paint.setStyle(Paint.Style.STROKE); 417 | paint.setColor(Color.rgb(255, 255, 255)); 418 | paint.setStrokeWidth(0f); 419 | return paint; 420 | } 421 | 422 | public Paint getDefaultFaceShadowPaint() { 423 | final Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG); 424 | paint.setShader(new RadialGradient(0.5f, 0.5f, mFaceRect.width() / 2.0f, new int[]{Color.argb(60, 40, 96, 170), 425 | Color.argb(80, 15, 34, 98), Color.argb(120, 0, 0, 0), Color.argb(140, 0, 0, 0)}, 426 | new float[]{0.60f, 0.85f, 0.96f, 0.99f}, TileMode.MIRROR)); 427 | return paint; 428 | } 429 | 430 | public void setDefaultNeedlePaths() { 431 | final float x = 0.5f, y = 0.5f; 432 | mNeedleLeftPath = new Path(); 433 | mNeedleLeftPath.moveTo(x, y); 434 | mNeedleLeftPath.lineTo(x - mNeedleWidth, y); 435 | mNeedleLeftPath.lineTo(x, y - mNeedleHeight); 436 | mNeedleLeftPath.lineTo(x, y); 437 | mNeedleLeftPath.lineTo(x - mNeedleWidth, y); 438 | 439 | mNeedleRightPath = new Path(); 440 | mNeedleRightPath.moveTo(x, y); 441 | mNeedleRightPath.lineTo(x + mNeedleWidth, y); 442 | mNeedleRightPath.lineTo(x, y - mNeedleHeight); 443 | mNeedleRightPath.lineTo(x, y); 444 | mNeedleRightPath.lineTo(x + mNeedleWidth, y); 445 | } 446 | 447 | public Paint getDefaultNeedleLeftPaint() { 448 | final Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG); 449 | paint.setColor(Color.rgb(0, 0, 0)); 450 | return paint; 451 | } 452 | 453 | public Paint getDefaultNeedleRightPaint() { 454 | final Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG); 455 | paint.setColor(Color.rgb(0, 0, 0)); 456 | //paint.setShadowLayer(0.01f, 0.005f, -0.005f, Color.argb(127, 0, 0, 0)); 457 | return paint; 458 | } 459 | 460 | public Paint getDefaultNeedleScrewPaint() { 461 | final Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG); 462 | //paint.setShader(new RadialGradient(0.5f, 0.5f, 0.07f, new int[]{Color.rgb(171, 171, 171), Color.WHITE}, new float[]{0.05f, 463 | // 0.9f}, TileMode.MIRROR)); 464 | paint.setColor(Color.rgb(0, 0, 0)); 465 | return paint; 466 | } 467 | 468 | public Paint getDefaultNeedleScrewBorderPaint() { 469 | final Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG); 470 | paint.setStyle(Paint.Style.STROKE); 471 | paint.setColor(Color.argb(100, 81, 84, 89)); 472 | paint.setStrokeWidth(0.005f); 473 | return paint; 474 | } 475 | 476 | public void setDefaultRanges() { 477 | mRangeValues = new float[]{16, 25, 40, 100}; 478 | mRangeColors = new int[]{Color.rgb(231, 32, 43), Color.rgb(232, 111, 33), Color.rgb(232, 231, 33), Color.rgb(27, 202, 33)}; 479 | } 480 | 481 | public void setDefaultScaleRangePaints() { 482 | final int length = mRangeValues.length; 483 | mRangePaints = new Paint[length]; 484 | for (int i = 0; i < length; i++) { 485 | mRangePaints[i] = new Paint(Paint.LINEAR_TEXT_FLAG | Paint.ANTI_ALIAS_FLAG); 486 | mRangePaints[i].setColor(mRangeColors[i]); 487 | mRangePaints[i].setStyle(Paint.Style.STROKE); 488 | mRangePaints[i].setStrokeWidth(0.005f); 489 | mRangePaints[i].setTextSize(0.05f); 490 | mRangePaints[i].setTypeface(Typeface.SANS_SERIF); 491 | mRangePaints[i].setTextAlign(Align.CENTER); 492 | mRangePaints[i].setShadowLayer(0.005f, 0.002f, 0.002f, mTextShadowColor); 493 | } 494 | } 495 | 496 | public Paint getDefaultTextValuePaint() { 497 | final Paint paint = new Paint(Paint.LINEAR_TEXT_FLAG | Paint.ANTI_ALIAS_FLAG); 498 | paint.setColor(mTextValueColor); 499 | paint.setStyle(Paint.Style.FILL_AND_STROKE); 500 | paint.setStrokeWidth(0.005f); 501 | paint.setTextSize(mTextValueSize); 502 | paint.setTextAlign(Align.CENTER); 503 | paint.setTypeface(Typeface.SANS_SERIF); 504 | paint.setShadowLayer(0.01f, 0.002f, 0.002f, mTextShadowColor); 505 | return paint; 506 | } 507 | 508 | public Paint getDefaultTextUnitPaint() { 509 | final Paint paint = new Paint(Paint.LINEAR_TEXT_FLAG | Paint.ANTI_ALIAS_FLAG); 510 | paint.setColor(mTextUnitColor); 511 | paint.setStyle(Paint.Style.FILL_AND_STROKE); 512 | paint.setStrokeWidth(0.005f); 513 | paint.setTextSize(mTextUnitSize); 514 | paint.setTextAlign(Align.CENTER); 515 | paint.setShadowLayer(0.01f, 0.002f, 0.002f, mTextShadowColor); 516 | return paint; 517 | } 518 | 519 | @Override 520 | protected void onRestoreInstanceState(final Parcelable state) { 521 | final Bundle bundle = (Bundle) state; 522 | final Parcelable superState = bundle.getParcelable("superState"); 523 | super.onRestoreInstanceState(superState); 524 | 525 | mNeedleInitialized = bundle.getBoolean("needleInitialized"); 526 | mNeedleVelocity = bundle.getFloat("needleVelocity"); 527 | mNeedleAcceleration = bundle.getFloat("needleAcceleration"); 528 | mNeedleLastMoved = bundle.getLong("needleLastMoved"); 529 | mCurrentValue = bundle.getFloat("currentValue"); 530 | mTargetValue = bundle.getFloat("targetValue"); 531 | } 532 | 533 | private void initScale() { 534 | mScaleRotation = (mScaleStartAngle + 180) % 360; 535 | mDivisionValue = (mScaleEndValue - mScaleStartValue) / mDivisions; 536 | Log.d("mDivisionValue:", String.valueOf(mDivisionValue)); 537 | mSubdivisionValue = mDivisionValue / mSubdivisions; 538 | mSubdivisionAngle = (360 - 2 * mScaleStartAngle) / (mDivisions * mSubdivisions); 539 | } 540 | 541 | @Override 542 | protected Parcelable onSaveInstanceState() { 543 | final Parcelable superState = super.onSaveInstanceState(); 544 | 545 | final Bundle state = new Bundle(); 546 | state.putParcelable("superState", superState); 547 | state.putBoolean("needleInitialized", mNeedleInitialized); 548 | state.putFloat("needleVelocity", mNeedleVelocity); 549 | state.putFloat("needleAcceleration", mNeedleAcceleration); 550 | state.putLong("needleLastMoved", mNeedleLastMoved); 551 | state.putFloat("currentValue", mCurrentValue); 552 | state.putFloat("targetValue", mTargetValue); 553 | return state; 554 | } 555 | 556 | @Override 557 | protected void onMeasure(final int widthMeasureSpec, final int heightMeasureSpec) { 558 | // Loggable.log.debug(String.format("widthMeasureSpec=%s, heightMeasureSpec=%s", 559 | // View.MeasureSpec.toString(widthMeasureSpec), 560 | // View.MeasureSpec.toString(heightMeasureSpec))); 561 | 562 | final int widthMode = MeasureSpec.getMode(widthMeasureSpec); 563 | final int heightMode = MeasureSpec.getMode(heightMeasureSpec); 564 | final int widthSize = MeasureSpec.getSize(widthMeasureSpec); 565 | final int heightSize = MeasureSpec.getSize(heightMeasureSpec); 566 | 567 | final int chosenWidth = chooseDimension(widthMode, widthSize); 568 | final int chosenHeight = chooseDimension(heightMode, heightSize); 569 | setMeasuredDimension(chosenWidth, chosenHeight); 570 | } 571 | 572 | private int chooseDimension(final int mode, final int size) { 573 | switch (mode) { 574 | case View.MeasureSpec.AT_MOST: 575 | case View.MeasureSpec.EXACTLY: 576 | return size; 577 | case View.MeasureSpec.UNSPECIFIED: 578 | default: 579 | return getDefaultDimension(); 580 | } 581 | } 582 | 583 | private int getDefaultDimension() { 584 | return SIZE; 585 | } 586 | 587 | @Override 588 | protected void onSizeChanged(final int w, final int h, final int oldw, final int oldh) { 589 | drawGauge(); 590 | } 591 | 592 | private void drawGauge() { 593 | if (null != mBackground) { 594 | // Let go of the old background 595 | mBackground.recycle(); 596 | } 597 | // Create a new background according to the new width and height 598 | mBackground = Bitmap.createBitmap(getWidth(), getHeight(), Bitmap.Config.ARGB_8888); 599 | final Canvas canvas = new Canvas(mBackground); 600 | final float scale = Math.min(getWidth(), getHeight()); 601 | canvas.scale(scale, scale); 602 | canvas.translate((scale == getHeight()) ? ((getWidth() - scale) / 2) / scale : 0 603 | , (scale == getWidth()) ? ((getHeight() - scale) / 2) / scale : 0); 604 | 605 | //drawRim(canvas); 606 | //drawFace(canvas); 607 | 608 | if (mShowRanges) { 609 | drawScale(canvas); 610 | } 611 | } 612 | 613 | @Override 614 | protected void onDraw(final Canvas canvas) { 615 | drawBackground(canvas); 616 | 617 | final float scale = Math.min(getWidth(), getHeight()); 618 | canvas.scale(scale, scale); 619 | canvas.translate((scale == getHeight()) ? ((getWidth() - scale) / 2) / scale : 0 620 | , (scale == getWidth()) ? ((getHeight() - scale) / 2) / scale : 0); 621 | 622 | if (mShowNeedle) { 623 | drawNeedle(canvas); 624 | } 625 | 626 | if (mShowText) { 627 | drawText(canvas); 628 | } 629 | 630 | computeCurrentValue(); 631 | } 632 | 633 | private void drawBackground(final Canvas canvas) { 634 | if (null != mBackground) { 635 | canvas.drawBitmap(mBackground, 0, 0, mBackgroundPaint); 636 | } 637 | } 638 | 639 | private void drawRim(final Canvas canvas) { 640 | if (mShowOuterShadow) { 641 | canvas.drawOval(mOuterShadowRect, mOuterShadowPaint); 642 | } 643 | if (mShowOuterBorder) { 644 | canvas.drawOval(mOuterBorderRect, mOuterBorderPaint); 645 | } 646 | if (mShowOuterRim) { 647 | canvas.drawOval(mOuterRimRect, mOuterRimPaint); 648 | } 649 | if (mShowInnerRim) { 650 | canvas.drawOval(mInnerRimRect, mInnerRimPaint); 651 | canvas.drawOval(mInnerRimRect, mInnerRimBorderLightPaint); 652 | canvas.drawOval(mInnerRimBorderRect, mInnerRimBorderDarkPaint); 653 | } 654 | } 655 | 656 | private void drawFace(final Canvas canvas) { 657 | // Draw the face gradient 658 | canvas.drawOval(mFaceRect, mFacePaint); 659 | // Draw the face border 660 | //canvas.drawOval(mFaceRect, mFaceBorderPaint); 661 | // Draw the inner face shadow 662 | //canvas.drawOval(mFaceRect, mFaceShadowPaint); 663 | } 664 | 665 | private void drawText(final Canvas canvas) { 666 | final String textValue = !TextUtils.isEmpty(mTextValue) ? mTextValue : valueString(mCurrentValue); 667 | final float textValueWidth = mTextValuePaint.measureText(textValue); 668 | final float textUnitWidth = !TextUtils.isEmpty(mTextUnit) ? mTextUnitPaint.measureText(mTextUnit) : 0; 669 | 670 | final float startX = CENTER - textUnitWidth / 2; 671 | final float startY = CENTER + 0.1f; 672 | 673 | drawText(canvas,textValue, startX, startY, mTextValuePaint); 674 | 675 | if (!TextUtils.isEmpty(mTextUnit)) { 676 | canvas.drawText(mTextUnit, CENTER + textValueWidth / 2 + 0.03f, CENTER, mTextUnitPaint); 677 | } 678 | } 679 | 680 | private void drawScale(final Canvas canvas) { 681 | canvas.save(Canvas.MATRIX_SAVE_FLAG); 682 | // On canvas, North is 0 degrees, East is 90 degrees, South is 180 etc. 683 | // We start the scale somewhere South-West so we need to first rotate the canvas. 684 | canvas.rotate(mScaleRotation, 0.5f, 0.5f); 685 | Log.d("mScaleRotation: ", String.valueOf(mScaleRotation)); 686 | 687 | final int totalTicks = mDivisions * mSubdivisions + 1; 688 | for (int i = 0; i < totalTicks; i++) { 689 | final float y1 = mScaleRect.top; 690 | Log.d("mScaleRect.top: ", String.valueOf(mScaleRect.top)); 691 | 692 | final float y2 = y1 + 0.045f; // height of division 693 | final float y3 = y1 + 0.090f; // height of subdivision 694 | 695 | final float value = getValueForTick(i); 696 | final Paint paint = getRangePaint(value); 697 | 698 | float div = mScaleEndValue / (float) mDivisions; 699 | float mod = value % div; 700 | if ((Math.abs(mod - 0) < 0.001) || (Math.abs(mod - div) < 0.001)) { 701 | // Draw a division tick 702 | paint.setStrokeWidth(0.01f); 703 | paint.setColor(Color.rgb(87,97,114)); 704 | canvas.drawLine(0.5f, y1 - 0.015f, 0.5f, y3 - 0.03f, paint); 705 | // Draw the text 0.15 away from the division tick 706 | //paint.setTextSize(1F); 707 | paint.setStyle(Paint.Style.FILL); 708 | //canvas.drawText(valueString(value), 0.49f, y3 + 0.05f, paint); 709 | drawText(canvas, valueString(value), 0.5f, y3 + 0.05f, paint); 710 | Log.d("TEXT:",valueString(value)); 711 | } else { 712 | // Draw a subdivision tick 713 | paint.setStrokeWidth(0.002f); 714 | paint.setColor(Color.rgb(209,209,209)); 715 | canvas.drawLine(0.5f, y1, 0.5f, y2, paint); 716 | } 717 | canvas.rotate(mSubdivisionAngle, 0.5f, 0.5f); 718 | Log.d("mSubdivisionAngle: ", String.valueOf(mSubdivisionAngle)); 719 | } 720 | canvas.restore(); 721 | } 722 | 723 | private void drawText(Canvas canvas, String value, float x, float y, Paint paint) 724 | { 725 | //Save original font size 726 | float originalTextSize = paint.getTextSize(); 727 | 728 | // set a magnification factor 729 | final float magnifier = 100f; 730 | 731 | // Scale the canvas 732 | canvas.save(); 733 | canvas.scale(1f / magnifier, 1f / magnifier); 734 | 735 | // increase the font size 736 | paint.setTextSize(originalTextSize * magnifier); 737 | 738 | canvas.drawText(value, x*magnifier, y*magnifier,paint); 739 | 740 | //canvas.drawTextOnPath(value, textPath, 0.0f, 0.0f, paint); 741 | 742 | // bring everything back to normal 743 | canvas.restore(); 744 | paint.setTextSize(originalTextSize); 745 | } 746 | 747 | /** 748 | * Draws a text in the canvas with spacing between each letter. 749 | * Basically what this method does is it split's the given text into individual letters 750 | * and draws each letter independently using Canvas.drawText with a separation of 751 | * {@code spacingX} between each letter. 752 | * @param canvas the canvas where the text will be drawn 753 | * @param text the text what will be drawn 754 | * @param left the left position of the text 755 | * @param top the top position of the text 756 | * @param paint holds styling information for the text 757 | * @param spacingPx the number of pixels between each letter that will be drawn 758 | */ 759 | public static void drawSpacedText(Canvas canvas, String text, float left, float top, Paint paint, float spacingPx){ 760 | 761 | float currentLeft = left; 762 | 763 | for (int i = 0; i < text.length(); i++) { 764 | String c = text.charAt(i)+""; 765 | canvas.drawText(c, currentLeft, top, paint); 766 | currentLeft += spacingPx; 767 | currentLeft += paint.measureText(c); 768 | } 769 | } 770 | 771 | /** 772 | * returns the width of a text drawn by drawSpacedText 773 | */ 774 | public static float getSpacedTextWidth(Paint paint, String text, float spacingX){ 775 | return paint.measureText(text) + spacingX * ( text.length() - 1 ); 776 | } 777 | 778 | private String valueString(final float value) { 779 | return String.format("%d", (int) value); 780 | } 781 | 782 | private float getValueForTick(final int tick) { 783 | return tick * (mDivisionValue / mSubdivisions); 784 | } 785 | 786 | private Paint getRangePaint(final float value) { 787 | final int length = mRangeValues.length; 788 | for (int i = 0; i < length - 1; i++) { 789 | if (value < mRangeValues[i]) return mRangePaints[i]; 790 | } 791 | if (value <= mRangeValues[length - 1]) return mRangePaints[length - 1]; 792 | throw new IllegalArgumentException("Value " + value + " out of range!"); 793 | } 794 | 795 | private void drawNeedle(final Canvas canvas) { 796 | if (mNeedleInitialized) { 797 | final float angle = getAngleForValue(mCurrentValue); 798 | // Logger.log.info(String.format("value=%f -> angle=%f", mCurrentValue, angle)); 799 | 800 | canvas.save(Canvas.MATRIX_SAVE_FLAG); 801 | canvas.rotate(angle, 0.5f, 0.5f); 802 | 803 | Paint outerCircle = new Paint(); 804 | outerCircle.setColor(mOuterCircleColor); 805 | outerCircle.setStyle(Paint.Style.FILL); 806 | canvas.drawCircle(0.5f, 0.5f, 0.23f, outerCircle); 807 | 808 | Paint innerCircle = new Paint(); 809 | innerCircle.setColor(mInnerCircleColor); 810 | canvas.drawCircle(0.5f, 0.5f, 0.1f, innerCircle); 811 | 812 | setNeedleShadowPosition(angle); 813 | canvas.drawPath(mNeedleLeftPath, mNeedleLeftPaint); 814 | canvas.drawPath(mNeedleRightPath, mNeedleRightPaint); 815 | 816 | canvas.restore(); 817 | 818 | // Draw the needle screw and its border 819 | 820 | 821 | canvas.drawCircle(0.5f, 0.5f, 0.04f, mNeedleScrewPaint); 822 | 823 | Log.d("NEEDLE", "Needle drawn :/"); 824 | //canvas.drawCircle(0.5f, 0.5f, 0.04f, mNeedleScrewBorderPaint); 825 | } 826 | } 827 | 828 | private void setNeedleShadowPosition(final float angle) { 829 | if (angle > 180 && angle < 360) { 830 | // Move shadow from right to left 831 | mNeedleRightPaint.setShadowLayer(0, 0, 0, Color.BLACK); 832 | mNeedleLeftPaint.setShadowLayer(0.01f, -0.005f, 0.005f, Color.argb(127, 0, 0, 0)); 833 | } else { 834 | // Move shadow from left to right 835 | mNeedleLeftPaint.setShadowLayer(0, 0, 0, Color.BLACK); 836 | mNeedleRightPaint.setShadowLayer(0.01f, 0.005f, -0.005f, Color.argb(127, 0, 0, 0)); 837 | } 838 | } 839 | 840 | private float getAngleForValue(final float value) { 841 | return (mScaleRotation + (value / mSubdivisionValue) * mSubdivisionAngle) % 360; 842 | } 843 | 844 | private void computeCurrentValue() { 845 | // Logger.log.warn(String.format("velocity=%f, acceleration=%f", mNeedleVelocity, 846 | // mNeedleAcceleration)); 847 | 848 | if (!(Math.abs(mCurrentValue - mTargetValue) > 0.01f)) { 849 | return; 850 | } 851 | 852 | if (-1 != mNeedleLastMoved) { 853 | final float time = (System.currentTimeMillis() - mNeedleLastMoved) / 1000.0f; 854 | final float direction = Math.signum(mNeedleVelocity); 855 | if (Math.abs(mNeedleVelocity) < 90.0f) { 856 | mNeedleAcceleration = 5.0f * (mTargetValue - mCurrentValue); 857 | } else { 858 | mNeedleAcceleration = 0.0f; 859 | } 860 | 861 | mNeedleAcceleration = 5.0f * (mTargetValue - mCurrentValue); 862 | mCurrentValue += mNeedleVelocity * time; 863 | mNeedleVelocity += mNeedleAcceleration * time; 864 | 865 | if ((mTargetValue - mCurrentValue) * direction < 0.01f * direction) { 866 | mCurrentValue = mTargetValue; 867 | mNeedleVelocity = 0.0f; 868 | mNeedleAcceleration = 0.0f; 869 | mNeedleLastMoved = -1L; 870 | } else { 871 | mNeedleLastMoved = System.currentTimeMillis(); 872 | } 873 | 874 | invalidate(); 875 | 876 | } else { 877 | mNeedleLastMoved = System.currentTimeMillis(); 878 | computeCurrentValue(); 879 | } 880 | } 881 | 882 | public void setTargetValue(final float value) { 883 | if (mShowScale || mShowRanges) { 884 | if (value < mScaleStartValue) { 885 | mTargetValue = mScaleStartValue; 886 | } else if (value > mScaleEndValue) { 887 | mTargetValue = mScaleEndValue; 888 | } else { 889 | mTargetValue = value; 890 | } 891 | } else { 892 | mTargetValue = value; 893 | } 894 | mNeedleInitialized = true; 895 | invalidate(); 896 | } 897 | 898 | } 899 | 900 | 901 | -------------------------------------------------------------------------------- /gaugelibrary/src/main/res/drawable/brushed_alu.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Sulejman/GaugeView/e2570476718afb8126d8d63e35c9a883adcf97ac/gaugelibrary/src/main/res/drawable/brushed_alu.png -------------------------------------------------------------------------------- /gaugelibrary/src/main/res/drawable/brushed_alu2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Sulejman/GaugeView/e2570476718afb8126d8d63e35c9a883adcf97ac/gaugelibrary/src/main/res/drawable/brushed_alu2.png -------------------------------------------------------------------------------- /gaugelibrary/src/main/res/drawable/carbon_fibre.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Sulejman/GaugeView/e2570476718afb8126d8d63e35c9a883adcf97ac/gaugelibrary/src/main/res/drawable/carbon_fibre.png -------------------------------------------------------------------------------- /gaugelibrary/src/main/res/drawable/light_alu.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Sulejman/GaugeView/e2570476718afb8126d8d63e35c9a883adcf97ac/gaugelibrary/src/main/res/drawable/light_alu.png -------------------------------------------------------------------------------- /gaugelibrary/src/main/res/values/arrays.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 16 5 | 25 6 | 40 7 | 100 8 | 9 | 10 | 11 | #E7202B 12 | #E86F21 13 | #E8E721 14 | #1BCA21 15 | 16 | 17 | -------------------------------------------------------------------------------- /gaugelibrary/src/main/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 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | -------------------------------------------------------------------------------- /gaugelibrary/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | GaugeLibrary 3 | 4 | -------------------------------------------------------------------------------- /gradle.properties: -------------------------------------------------------------------------------- 1 | # Project-wide Gradle settings. 2 | 3 | # IDE (e.g. Android Studio) users: 4 | # Gradle settings configured through the IDE *will override* 5 | # any settings specified in this file. 6 | 7 | # For more details on how to configure your build environment visit 8 | # http://www.gradle.org/docs/current/userguide/build_environment.html 9 | 10 | # Specifies the JVM arguments used for the daemon process. 11 | # The setting is particularly useful for tweaking memory settings. 12 | # Default value: -Xmx10248m -XX:MaxPermSize=256m 13 | # org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8 14 | 15 | # When configured, Gradle will run in incubating parallel mode. 16 | # This option should only be used with decoupled projects. More details, visit 17 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects 18 | # org.gradle.parallel=true -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Sulejman/GaugeView/e2570476718afb8126d8d63e35c9a883adcf97ac/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Wed Apr 10 15:27:10 PDT 2013 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-2.2.1-all.zip 7 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | include ':app', ':gaugelibrary' 2 | --------------------------------------------------------------------------------