├── .gitignore ├── .idea ├── compiler.xml ├── copyright │ └── profiles_settings.xml ├── gradle.xml ├── misc.xml ├── modules.xml └── runConfigurations.xml ├── README.md ├── ScreenShots ├── device143641.png ├── device143747.png └── u8y76ghj.gif ├── app ├── .gitignore ├── build.gradle ├── proguard-rules.pro └── src │ ├── androidTest │ └── java │ │ └── com │ │ └── excellent_tank │ │ └── customchart │ │ └── ExampleInstrumentedTest.java │ ├── main │ ├── AndroidManifest.xml │ ├── java │ │ └── com │ │ │ └── excellent_tank │ │ │ └── customchart │ │ │ ├── activity │ │ │ └── MainActivity.java │ │ │ └── chart │ │ │ ├── HistogramChart.java │ │ │ └── HorizontalChart.java │ └── res │ │ ├── layout │ │ └── activity_main.xml │ │ ├── mipmap-hdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ ├── mipmap-mdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ ├── mipmap-xhdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ ├── mipmap-xxhdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ ├── mipmap-xxxhdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ └── values │ │ ├── colors.xml │ │ ├── dimens.xml │ │ ├── strings.xml │ │ └── styles.xml │ └── test │ └── java │ └── com │ └── excellent_tank │ └── customchart │ └── ExampleUnitTest.java ├── build.gradle ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat └── settings.gradle /.gitignore: -------------------------------------------------------------------------------- 1 | *.iml 2 | .gradle 3 | /local.properties 4 | /.idea/workspace.xml 5 | /.idea/libraries 6 | .DS_Store 7 | /build 8 | /captures 9 | .externalNativeBuild 10 | -------------------------------------------------------------------------------- /.idea/compiler.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /.idea/copyright/profiles_settings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | -------------------------------------------------------------------------------- /.idea/gradle.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 17 | 18 | -------------------------------------------------------------------------------- /.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 19 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 46 | 47 | C:\Users\Administrator\AppData\Roaming\Subversion 48 | 49 | 50 | 51 | 52 | 53 | 1.8 54 | 55 | 60 | 61 | 62 | 63 | 64 | 65 | -------------------------------------------------------------------------------- /.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /.idea/runConfigurations.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 11 | 12 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | #效果图 2 | ![](https://github.com/excellenttank/CustomChart/blob/master/ScreenShots/device143641.png) 3 | ![](https://github.com/excellenttank/CustomChart/blob/master/ScreenShots/device143747.png) 4 | ![](https://github.com/excellenttank/CustomChart/blob/master/ScreenShots/u8y76ghj.gif) -------------------------------------------------------------------------------- /ScreenShots/device143641.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/excellenttank/CustomChart/d3c9b8d3f1d2e9afc52e54f1911b73091b64f762/ScreenShots/device143641.png -------------------------------------------------------------------------------- /ScreenShots/device143747.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/excellenttank/CustomChart/d3c9b8d3f1d2e9afc52e54f1911b73091b64f762/ScreenShots/device143747.png -------------------------------------------------------------------------------- /ScreenShots/u8y76ghj.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/excellenttank/CustomChart/d3c9b8d3f1d2e9afc52e54f1911b73091b64f762/ScreenShots/u8y76ghj.gif -------------------------------------------------------------------------------- /app/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /app/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | 3 | android { 4 | compileSdkVersion 25 5 | buildToolsVersion "25.0.3" 6 | defaultConfig { 7 | applicationId "com.excellent_tank.customchart" 8 | minSdkVersion 15 9 | targetSdkVersion 25 10 | versionCode 1 11 | versionName "1.0" 12 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" 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 | androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', { 25 | exclude group: 'com.android.support', module: 'support-annotations' 26 | }) 27 | compile 'com.android.support:appcompat-v7:25.3.1' 28 | compile 'com.android.support.constraint:constraint-layout:1.0.2' 29 | testCompile 'junit:junit:4.12' 30 | compile 'com.jakewharton:butterknife:8.8.1' 31 | annotationProcessor 'com.jakewharton:butterknife-compiler:8.8.1' 32 | } 33 | -------------------------------------------------------------------------------- /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 D:\AndroidSdk/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 | 19 | # Uncomment this to preserve the line number information for 20 | # debugging stack traces. 21 | #-keepattributes SourceFile,LineNumberTable 22 | 23 | # If you keep the line number information, uncomment this to 24 | # hide the original source file name. 25 | #-renamesourcefileattribute SourceFile 26 | -------------------------------------------------------------------------------- /app/src/androidTest/java/com/excellent_tank/customchart/ExampleInstrumentedTest.java: -------------------------------------------------------------------------------- 1 | package com.excellent_tank.customchart; 2 | 3 | import android.content.Context; 4 | import android.support.test.InstrumentationRegistry; 5 | import android.support.test.runner.AndroidJUnit4; 6 | 7 | import org.junit.Test; 8 | import org.junit.runner.RunWith; 9 | 10 | import static org.junit.Assert.*; 11 | 12 | /** 13 | * Instrumentation test, which will execute on an Android device. 14 | * 15 | * @see Testing documentation 16 | */ 17 | @RunWith(AndroidJUnit4.class) 18 | public class ExampleInstrumentedTest { 19 | @Test 20 | public void useAppContext() throws Exception { 21 | // Context of the app under test. 22 | Context appContext = InstrumentationRegistry.getTargetContext(); 23 | 24 | assertEquals("com.excellent_tank.customchart", appContext.getPackageName()); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 12 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /app/src/main/java/com/excellent_tank/customchart/activity/MainActivity.java: -------------------------------------------------------------------------------- 1 | package com.excellent_tank.customchart.activity; 2 | 3 | import android.os.Bundle; 4 | import android.support.v7.app.AppCompatActivity; 5 | import android.widget.LinearLayout; 6 | 7 | import com.excellent_tank.customchart.R; 8 | import com.excellent_tank.customchart.chart.HorizontalChart; 9 | 10 | import java.util.ArrayList; 11 | import java.util.HashMap; 12 | import java.util.Random; 13 | 14 | 15 | public class MainActivity extends AppCompatActivity { 16 | 17 | private Random random = new Random(); 18 | private ArrayList> pileNoDateList = new ArrayList<>(); 19 | private ArrayList monthCountList = new ArrayList(); 20 | private LinearLayout histogram_text_whole_ll; 21 | private LinearLayout histogram_text_ll; 22 | private com.excellent_tank.customchart.chart.HistogramChart histogram_chart_view; 23 | private HorizontalChart horizontalChart; 24 | 25 | 26 | @Override 27 | protected void onCreate(Bundle savedInstanceState) { 28 | super.onCreate(savedInstanceState); 29 | setContentView(R.layout.activity_main); 30 | bindViews(); 31 | initView(); 32 | } 33 | 34 | private void bindViews() { 35 | histogram_text_whole_ll = (LinearLayout) findViewById(R.id.histogram_text_whole_ll); 36 | histogram_text_ll = (LinearLayout) findViewById(R.id.histogram_text_ll); 37 | histogram_chart_view = (com.excellent_tank.customchart.chart.HistogramChart) findViewById(R.id.histogram_chart_view); 38 | horizontalChart = (HorizontalChart) findViewById(R.id.horizontal_chart); 39 | } 40 | 41 | private void initView() { 42 | initData(); 43 | histogram_chart_view.setRefresh(true); 44 | histogram_chart_view.setData(pileNoDateList, histogram_text_ll, histogram_text_whole_ll); 45 | histogram_chart_view.invalidate(); 46 | histogram_chart_view.requestLayout(); 47 | 48 | horizontalChart.setRefresh(true); 49 | horizontalChart.SetDate(monthCountList); 50 | horizontalChart.invalidate(); 51 | horizontalChart.requestLayout(); 52 | } 53 | 54 | private void initData() { 55 | pileNoDateList.clear(); 56 | for (int i = 0; i < 50; i++) { 57 | HashMap data = new HashMap<>(); 58 | data.put("startPileNo", i); 59 | data.put("upCount", random.nextInt(200)); 60 | data.put("downCount", random.nextInt(200)); 61 | pileNoDateList.add(data); 62 | } 63 | 64 | monthCountList.clear(); 65 | monthCountList.add(10f); 66 | monthCountList.add(30f); 67 | monthCountList.add(20f); 68 | monthCountList.add(60f); 69 | monthCountList.add(45f); 70 | 71 | } 72 | 73 | 74 | } 75 | -------------------------------------------------------------------------------- /app/src/main/java/com/excellent_tank/customchart/chart/HistogramChart.java: -------------------------------------------------------------------------------- 1 | package com.excellent_tank.customchart.chart; 2 | 3 | import android.content.Context; 4 | import android.content.res.Resources; 5 | import android.graphics.Canvas; 6 | import android.graphics.Color; 7 | import android.graphics.DashPathEffect; 8 | import android.graphics.Paint; 9 | import android.graphics.Paint.Align; 10 | import android.graphics.Paint.Style; 11 | import android.graphics.Path; 12 | import android.util.AttributeSet; 13 | import android.util.DisplayMetrics; 14 | import android.view.Gravity; 15 | import android.view.View; 16 | import android.widget.LinearLayout; 17 | import android.widget.LinearLayout.LayoutParams; 18 | import android.widget.TextView; 19 | 20 | import com.excellent_tank.customchart.R; 21 | 22 | import java.util.ArrayList; 23 | import java.util.HashMap; 24 | import java.util.List; 25 | 26 | /** 27 | * 各路段事故数量统计 28 | * 29 | * @author wbb 30 | */ 31 | public class HistogramChart extends View { 32 | 33 | private String[] pileNo; 34 | private Resources resources; 35 | List> pileNoDateList = new ArrayList>(); 36 | 37 | private List> accident_data = new ArrayList>(); 38 | 39 | private int[] accident_count; 40 | 41 | private int maxValue; 42 | 43 | private int addValue; 44 | 45 | private DashPathEffect dashPathEffect; 46 | 47 | /** 48 | * 用于放置Y轴刻度值 49 | */ 50 | private LinearLayout histogram_text_ll; 51 | 52 | private boolean drawYDegree = false; 53 | 54 | private LinearLayout histogram_text_whole_ll; 55 | 56 | private Paint paintCommon = new Paint(); 57 | 58 | private Path path = new Path(); 59 | 60 | private boolean isRefresh = false; 61 | 62 | private int screenWidth = 0; 63 | 64 | public boolean isRefresh() { 65 | return isRefresh; 66 | } 67 | 68 | public void setRefresh(boolean isRefresh) { 69 | this.isRefresh = isRefresh; 70 | } 71 | 72 | private void init() { 73 | resources = this.getContext().getResources(); 74 | DisplayMetrics metric = getResources().getDisplayMetrics(); 75 | screenWidth = metric.widthPixels; // 屏幕宽度(像素) 76 | dashPathEffect = new DashPathEffect(new float[]{resources.getDimension(R.dimen.accidentDashDistance), resources.getDimension(R.dimen.accidentDashDistance), resources.getDimension(R.dimen.accidentDashDistance), resources.getDimension(R.dimen.accidentDashDistance)}, 1); 77 | } 78 | 79 | public HistogramChart(Context context) { 80 | super(context); 81 | init(); 82 | } 83 | 84 | public HistogramChart(Context context, AttributeSet attrs) { 85 | super(context, attrs); 86 | init(); 87 | } 88 | 89 | public HistogramChart(Context context, AttributeSet attrs, int defStyle) { 90 | super(context, attrs, defStyle); 91 | init(); 92 | } 93 | 94 | protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { 95 | super.onMeasure(widthMeasureSpec, heightMeasureSpec); 96 | int width = measureWidth(); 97 | int height = (int) resources.getDimension(R.dimen.accident_grid_height); 98 | setMeasuredDimension(width, height); 99 | } 100 | 101 | private int measureWidth() { 102 | int result = 0; // 结果 103 | int myWidth = 0; 104 | if (null != pileNo && pileNo.length > 0) { 105 | myWidth = (int) resources.getDimension(R.dimen.accident_begin_x) + (int) (pileNo.length * resources.getDimension(R.dimen.accident_y_space) + resources.getDimension(R.dimen.accident_begin_y) * 2); 106 | } 107 | 108 | int screenWidth = getResources().getDisplayMetrics().widthPixels; 109 | 110 | if (myWidth < screenWidth) { 111 | result = screenWidth - (int) (2 * resources.getDimension(R.dimen.cb_padding_right)); 112 | drawYDegree = true; 113 | } else { 114 | result = myWidth - (int) (3 * resources.getDimension(R.dimen.cb_padding_right)); 115 | } 116 | 117 | return result; 118 | } 119 | 120 | public void setData(List> pileNoDateList, LinearLayout histogram_text_ll, LinearLayout histogram_text_whole_ll) { 121 | 122 | accident_count = new int[]{0, 5, 10, 15, 20, 25}; 123 | maxValue = 0; 124 | accident_data.clear(); 125 | 126 | this.histogram_text_whole_ll = histogram_text_whole_ll; 127 | 128 | this.histogram_text_ll = histogram_text_ll; 129 | 130 | this.pileNoDateList.clear(); 131 | this.pileNoDateList.addAll(pileNoDateList); 132 | 133 | pileNo = new String[pileNoDateList.size()]; 134 | 135 | for (int i = 0; i < pileNoDateList.size(); i++) { 136 | HashMap hm = new HashMap(); 137 | int pileNoCache = (int) Float.parseFloat(pileNoDateList.get(i).get("startPileNo").toString()); 138 | pileNo[i] = String.valueOf(pileNoCache); 139 | 140 | int downCount = (int) Float.parseFloat(pileNoDateList.get(i).get("downCount").toString()); 141 | 142 | int upCount = (int) Float.parseFloat(pileNoDateList.get(i).get("upCount").toString()); 143 | 144 | if (maxValue < downCount) { 145 | maxValue = downCount; 146 | } 147 | 148 | if (maxValue < upCount) { 149 | maxValue = upCount; 150 | } 151 | 152 | hm.put("left", (int) Float.parseFloat(pileNoDateList.get(i).get("upCount").toString())); 153 | hm.put("right", (int) Float.parseFloat(pileNoDateList.get(i).get("downCount").toString())); 154 | 155 | accident_data.add(hm); 156 | 157 | } 158 | 159 | if (maxValue > 25) { 160 | addValue = (int) ((maxValue / 5f) + 1f); 161 | for (int i = 1; i < accident_count.length; i++) { 162 | accident_count[i] = i * addValue; 163 | } 164 | } else { 165 | addValue = 5; 166 | } 167 | } 168 | 169 | @Override 170 | protected void onDetachedFromWindow() { 171 | super.onDetachedFromWindow(); 172 | resources = null; 173 | pileNoDateList.clear(); 174 | pileNoDateList = null; 175 | accident_data.clear(); 176 | accident_data = null; 177 | paintCommon = null; 178 | path = null; 179 | } 180 | 181 | @Override 182 | protected void onDraw(Canvas canvas) { 183 | super.onDraw(canvas); 184 | if (!isRefresh) 185 | return; 186 | 187 | float gridX = resources.getDimension(R.dimen.accident_begin_x); 188 | 189 | float gridY = resources.getDimension(R.dimen.accident_begin_y); 190 | 191 | float x_space = resources.getDimension(R.dimen.accident_y_space); 192 | 193 | int lineCount = 11; 194 | 195 | float y_space = (getHeight() - resources.getDimension(R.dimen.bottom_subtractor) - gridY - 2 * resources.getDimension(R.dimen.y_padding)) / (lineCount - 1); 196 | 197 | float y_single_height = (getHeight() - resources.getDimension(R.dimen.bottom_subtractor) - gridY - 2 * resources.getDimension(R.dimen.y_padding)) / (accident_count[accident_count.length - 1] * 2); 198 | 199 | float gridMiddlePosition = (getHeight() - resources.getDimension(R.dimen.bottom_subtractor) - gridY) / 2f; 200 | 201 | path.reset(); 202 | 203 | if (null != pileNo && pileNo.length > 0) { 204 | float chart_width = x_space * pileNo.length; 205 | if (chart_width < screenWidth) { 206 | 207 | gridX = (screenWidth / 2f) - (chart_width / 2f); 208 | 209 | } 210 | 211 | paintCommon.reset(); 212 | paintCommon.setAntiAlias(true);// 抗锯齿 213 | paintCommon.setColor(Color.parseColor("#E4E4E4")); 214 | paintCommon.setAlpha(50); 215 | 216 | // 绘制背景矩形 217 | canvas.drawRect(gridX, // 218 | gridY - resources.getDimension(R.dimen.line_space), // 219 | gridX + x_space * pileNo.length, // 220 | gridY + resources.getDimension(R.dimen.line_space) + y_space * (lineCount - 1) + 2 * resources.getDimension(R.dimen.y_padding), paintCommon); 221 | 222 | paintCommon.reset(); 223 | paintCommon.setAntiAlias(true);// 抗锯齿 224 | paintCommon.setColor(Color.parseColor("#E4E4E4")); 225 | paintCommon.setStrokeWidth(resources.getDimension(R.dimen.accidentXYLineWidth)); 226 | // 最上方的横线 227 | canvas.drawLine(gridX, // 228 | gridY - resources.getDimension(R.dimen.line_space), // 229 | gridX + x_space * pileNo.length, // 230 | gridY - resources.getDimension(R.dimen.line_space), // 231 | paintCommon); 232 | // 最下方的横线 233 | canvas.drawLine(gridX, // 234 | gridY + resources.getDimension(R.dimen.line_space) + y_space * (lineCount - 1) + 2 * resources.getDimension(R.dimen.y_padding), // 235 | gridX + x_space * pileNo.length, // 236 | gridY + resources.getDimension(R.dimen.line_space) + y_space * (lineCount - 1) + 2 * resources.getDimension(R.dimen.y_padding), // 237 | paintCommon); 238 | // 最右方的竖线 239 | canvas.drawLine(gridX + x_space * pileNo.length - resources.getDimension(R.dimen.line_space), // 240 | gridY, // 241 | gridX + x_space * pileNo.length - resources.getDimension(R.dimen.line_space), // 242 | gridY + y_space * (lineCount - 1) + 2 * resources.getDimension(R.dimen.y_padding), // 243 | paintCommon); 244 | // 绘制纵向线 245 | for (int i = 1; i < pileNo.length; i++) { 246 | canvas.drawLine(gridX + x_space * i, // 247 | gridY + y_space * (lineCount - 1) + 2 * resources.getDimension(R.dimen.y_padding), // 248 | gridX + x_space * i, // 249 | gridY + y_space * (lineCount - 1) + resources.getDimension(R.dimen.lenged_length) + 2 * resources.getDimension(R.dimen.y_padding), // 250 | paintCommon); 251 | 252 | } 253 | // 绘制内部框线 254 | paintCommon.reset(); 255 | paintCommon.setStyle(Style.STROKE); 256 | paintCommon.setAntiAlias(true);// 抗锯齿 257 | paintCommon.setStrokeWidth(1f); 258 | paintCommon.setColor(Color.parseColor("#E4E4E4")); 259 | paintCommon.setPathEffect(dashPathEffect);// 虚线设置 260 | 261 | path.reset(); 262 | 263 | // 绘制横向内部虚线 264 | float xx = x_space * pileNo.length; 265 | 266 | for (int i = 0; i < lineCount; i++) { 267 | 268 | int xC = (int) xx / screenWidth; 269 | float moveToY = gridY + resources.getDimension(R.dimen.y_padding) + y_space * i; 270 | float lineToY = gridY + resources.getDimension(R.dimen.y_padding) + y_space * i; 271 | if (xC <= 0) { 272 | float moveToX = gridX; 273 | float lineToX = gridX + xx; 274 | path.reset(); 275 | path.moveTo(moveToX, moveToY); 276 | path.lineTo(lineToX, lineToY); 277 | canvas.drawPath(path, paintCommon); 278 | 279 | } else { 280 | xC += 1; 281 | for (int m = 0; m < xC; m++) { 282 | float moveToX = gridX + screenWidth * m; 283 | float lineToX = gridX + screenWidth * (m + 1); 284 | path.reset(); 285 | path.moveTo(moveToX, moveToY); 286 | path.lineTo(lineToX, lineToY); 287 | canvas.drawPath(path, paintCommon); 288 | 289 | } 290 | 291 | } 292 | 293 | } 294 | // path.reset(); 295 | // for (int i = 0; i < lineCount; i++) { 296 | // 297 | // float moveToX = gridX; 298 | // float moveToY = gridY + resources.getDimension(R.dimen.y_padding) + y_space * i; 299 | // float lineToX = gridX + x_space * pileNo.length; 300 | // float lineToY = gridY + resources.getDimension(R.dimen.y_padding) + y_space * i; 301 | // 302 | // path.moveTo(moveToX,moveToY ); 303 | // path.lineTo(lineToX/2f,lineToY ); 304 | // canvas.drawPath(path, paintCommon); 305 | // } 306 | // path.reset(); 307 | // for (int i = 0; i < lineCount; i++) { 308 | // 309 | // float moveToX = gridX; 310 | // float moveToY = gridY + resources.getDimension(R.dimen.y_padding) + y_space * i; 311 | // float lineToX = gridX + x_space * pileNo.length; 312 | // float lineToY = gridY + resources.getDimension(R.dimen.y_padding) + y_space * i; 313 | // 314 | // path.moveTo(lineToX/2f+50,moveToY ); 315 | // path.lineTo(lineToX,lineToY ); 316 | // canvas.drawPath(path, paintCommon); 317 | // } 318 | 319 | // 绘制X周刻度 320 | paintCommon.reset(); 321 | paintCommon.setAntiAlias(true);// 抗锯齿 322 | paintCommon.setColor(Color.parseColor("#7E7E7E")); 323 | paintCommon.setTextSize(resources.getDimension(R.dimen.pile_no_textsize)); 324 | paintCommon.setTextAlign(Align.CENTER); 325 | // 绘制桩号 326 | for (int i = 0; i < pileNo.length; i++) { 327 | canvas.drawText(pileNo[i], gridX + x_space / 2 + x_space * i, getHeight() - resources.getDimension(R.dimen.bottom_text_subtractor), paintCommon); 328 | } 329 | // 绘制圆角矩形 330 | float start_space = x_space / 2f - resources.getDimension(R.dimen.histogram_width) / 2f; 331 | 332 | int accident_data_count = accident_data.size(); 333 | 334 | if (accident_data_count > 0) { 335 | for (int i = 0; i < accident_data_count; i++) { 336 | 337 | int leftSize = accident_data.get(i).get("left"); 338 | int rightSize = accident_data.get(i).get("right"); 339 | 340 | int leftEnd = leftSize; 341 | 342 | int rightEnd = rightSize; 343 | // 左方向 344 | paintCommon.reset(); 345 | paintCommon.setAntiAlias(true);// 抗锯齿 346 | paintCommon.setTextSize(resources.getDimension(R.dimen.pile_no_textsize)); 347 | paintCommon.setColor(Color.parseColor("#00CCFF")); 348 | canvas.drawRect(gridX + x_space * i + start_space,// 349 | gridY + gridMiddlePosition - leftEnd * y_single_height,// 350 | gridX + x_space * i + start_space + resources.getDimension(R.dimen.histogram_width),// 351 | gridY + gridMiddlePosition, paintCommon); 352 | 353 | // 绘制左方向的数值 354 | if (leftSize > 0) { 355 | paintCommon.reset(); 356 | paintCommon.setAntiAlias(true);// 抗锯齿 357 | paintCommon.setTextSize(resources.getDimension(R.dimen.left_right_text_size)); 358 | paintCommon.setTextAlign(Align.CENTER); 359 | paintCommon.setColor(Color.parseColor("#00CCFF")); 360 | canvas.drawText(String.valueOf(leftSize), // 361 | gridX + x_space / 2 + x_space * i, // 362 | gridY + gridMiddlePosition - leftEnd * y_single_height - resources.getDimension(R.dimen.left_count_y_offset), // 363 | paintCommon);// 364 | } 365 | 366 | paintCommon.reset(); 367 | paintCommon.setAntiAlias(true);// 抗锯齿 368 | paintCommon.setTextSize(resources.getDimension(R.dimen.pile_no_textsize)); 369 | paintCommon.setColor(Color.parseColor("#4FA975")); 370 | canvas.drawRect(gridX + x_space * i + start_space,// 371 | gridY + gridMiddlePosition,// 372 | gridX + x_space * i + start_space + resources.getDimension(R.dimen.histogram_width),// 373 | gridY + gridMiddlePosition + rightEnd * y_single_height, paintCommon); 374 | 375 | // 绘制右方向的数值 376 | if (rightSize > 0) { 377 | paintCommon.reset(); 378 | paintCommon.setAntiAlias(true);// 抗锯齿 379 | paintCommon.setTextSize(resources.getDimension(R.dimen.left_right_text_size)); 380 | paintCommon.setTextAlign(Align.CENTER); 381 | paintCommon.setColor(Color.parseColor("#4FA975")); 382 | canvas.drawText(String.valueOf(rightSize), // 383 | gridX + x_space / 2 + x_space * i, // 384 | gridY + gridMiddlePosition + rightEnd * y_single_height + resources.getDimension(R.dimen.right_count_y_offset), // 385 | paintCommon); 386 | } 387 | 388 | } 389 | 390 | if (drawYDegree) { 391 | histogram_text_whole_ll.setVisibility(View.GONE); 392 | paintCommon.reset(); 393 | paintCommon.setAntiAlias(true);// 抗锯齿 394 | paintCommon.setColor(Color.parseColor("#E4E4E4")); 395 | paintCommon.setStrokeWidth(resources.getDimension(R.dimen.accidentXYLineWidth)); 396 | canvas.drawLine(gridX - resources.getDimension(R.dimen.line_space), // 397 | gridY, // 398 | gridX - resources.getDimension(R.dimen.line_space), // 399 | gridY + y_space * (lineCount - 1) + 2 * resources.getDimension(R.dimen.y_padding), // 400 | paintCommon);// 最左方的竖线 401 | // 绘制Y轴刻度 402 | paintCommon.reset(); 403 | paintCommon.setAntiAlias(true);// 抗锯齿 404 | paintCommon.setColor(Color.parseColor("#D5D5D5")); 405 | paintCommon.setTextSize(resources.getDimension(R.dimen.pile_no_textsize)); 406 | paintCommon.setTextAlign(Align.RIGHT); 407 | // 绘制Y轴刻度 408 | for (int i = 0; i < lineCount; i++) { 409 | 410 | int acc_index; 411 | 412 | if (i < 6) { 413 | acc_index = 5 - i; 414 | } else { 415 | acc_index = i - 5; 416 | } 417 | 418 | canvas.drawText(String.valueOf(accident_count[acc_index]), gridX - resources.getDimension(R.dimen.accidentYTextXOffset), gridY + y_space * i + resources.getDimension(R.dimen.accidentYTextYOffset) + resources.getDimension(R.dimen.y_padding), paintCommon); 419 | 420 | } 421 | 422 | } else { 423 | histogram_text_whole_ll.setVisibility(View.VISIBLE); 424 | 425 | LayoutParams lp = new LayoutParams(LayoutParams.WRAP_CONTENT, (int) (y_space * (lineCount - 1) + 2 * resources.getDimension(R.dimen.y_padding))); 426 | histogram_text_ll.setLayoutParams(lp); 427 | 428 | LayoutParams lp_text_legend = new LayoutParams(LayoutParams.WRAP_CONTENT, (int) (y_space)); 429 | lp_text_legend.gravity = Gravity.RIGHT; 430 | 431 | LayoutParams lp_text_legend0 = new LayoutParams(LayoutParams.WRAP_CONTENT, (int) (resources.getDimension(R.dimen.y_padding) + 2 * resources.getDimension(R.dimen.line_space))); 432 | lp_text_legend0.gravity = Gravity.RIGHT; 433 | 434 | histogram_text_ll.removeAllViews(); 435 | 436 | // 绘制Y轴刻度 437 | for (int i = 0; i < lineCount; i++) { 438 | int acc_index; 439 | 440 | if (i < 6) { 441 | acc_index = 5 - i; 442 | } else { 443 | acc_index = i - 5; 444 | } 445 | 446 | TextView tv = new TextView(this.getContext()); 447 | tv.setText(String.valueOf(accident_count[acc_index])); 448 | tv.setTextColor(Color.parseColor("#D5D5D5")); 449 | tv.setTextSize(resources.getDimension(R.dimen.time_accident_y_textsize)); 450 | tv.setSingleLine(true); 451 | tv.setGravity(Gravity.BOTTOM | Gravity.RIGHT); 452 | if (i == 0) { 453 | tv.setLayoutParams(lp_text_legend0); 454 | } else { 455 | tv.setLayoutParams(lp_text_legend); 456 | } 457 | 458 | histogram_text_ll.addView(tv); 459 | 460 | } 461 | 462 | } 463 | 464 | } 465 | } 466 | isRefresh = false; 467 | } 468 | } 469 | -------------------------------------------------------------------------------- /app/src/main/java/com/excellent_tank/customchart/chart/HorizontalChart.java: -------------------------------------------------------------------------------- 1 | package com.excellent_tank.customchart.chart; 2 | 3 | import android.content.Context; 4 | import android.content.res.Resources; 5 | import android.graphics.Canvas; 6 | import android.graphics.Color; 7 | import android.graphics.Paint; 8 | import android.graphics.Paint.Align; 9 | import android.graphics.RectF; 10 | import android.util.AttributeSet; 11 | import android.view.View; 12 | 13 | import com.excellent_tank.customchart.R; 14 | 15 | import java.util.ArrayList; 16 | import java.util.List; 17 | 18 | public class HorizontalChart extends View { 19 | 20 | private Resources resources; 21 | 22 | private String[] eventText = new String[]{"统计1", "统计2", "统计3", "统计4", "统计5"}; 23 | 24 | private ArrayList monthCountList = new ArrayList(); 25 | 26 | private int max = 0; 27 | 28 | private Paint paintCommon = new Paint(); 29 | 30 | private RectF rectCommon = new RectF(); 31 | private boolean isRefresh = false; 32 | 33 | @Override 34 | protected void onDetachedFromWindow() { 35 | super.onDetachedFromWindow(); 36 | 37 | eventText = null; 38 | monthCountList.clear(); 39 | monthCountList = null; 40 | paintCommon = null; 41 | rectCommon = null; 42 | resources = null; 43 | 44 | } 45 | 46 | public boolean isRefresh() { 47 | return isRefresh; 48 | } 49 | 50 | public void setRefresh(boolean isRefresh) { 51 | this.isRefresh = isRefresh; 52 | } 53 | 54 | public HorizontalChart(Context context) { 55 | super(context); 56 | init(); 57 | } 58 | 59 | public HorizontalChart(Context context, AttributeSet attrs) { 60 | super(context, attrs); 61 | init(); 62 | } 63 | 64 | public HorizontalChart(Context context, AttributeSet attrs, int defStyle) { 65 | super(context, attrs, defStyle); 66 | init(); 67 | } 68 | 69 | private void init() { 70 | resources = this.getContext().getResources(); 71 | } 72 | 73 | protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { 74 | super.onMeasure(widthMeasureSpec, heightMeasureSpec); 75 | setMeasuredDimension(measureHeight(widthMeasureSpec), measureHeight(heightMeasureSpec)); 76 | } 77 | 78 | private int measureHeight(int heightMeasureSpec) { 79 | int result = 0; 80 | int specMode = MeasureSpec.getMode(heightMeasureSpec); 81 | int specSize = MeasureSpec.getSize(heightMeasureSpec); 82 | switch (specMode) { 83 | case MeasureSpec.AT_MOST: 84 | result = specSize; 85 | break; 86 | case MeasureSpec.EXACTLY: 87 | result = specSize; 88 | break; 89 | case MeasureSpec.UNSPECIFIED: 90 | result = getHeight(); 91 | break; 92 | default: 93 | break; 94 | } 95 | return result; 96 | } 97 | 98 | public void SetDate(List monthCountList) { 99 | this.monthCountList.clear(); 100 | this.monthCountList.addAll(monthCountList); 101 | max = 0; 102 | for (Float ft : this.monthCountList) { 103 | if (max < ft.intValue()) { 104 | max = ft.intValue(); 105 | } 106 | } 107 | 108 | // max = max + 10; 109 | 110 | } 111 | 112 | @Override 113 | protected void onDraw(Canvas canvas) { 114 | super.onDraw(canvas); 115 | if (!isRefresh) 116 | return; 117 | float beginX = resources.getDimension(R.dimen.chart_begin_x); 118 | float spaceY = (getHeight() - (resources.getDimension(R.dimen.chart_begin_y) * 2)) / 5f; 119 | float beginY = resources.getDimension(R.dimen.chart_begin_y); 120 | float vertical_line_X = resources.getDimension(R.dimen.vertical_line_x); 121 | 122 | float reckTotalLength = getWidth() - resources.getDimension(R.dimen.vertical_line_x) - resources.getDimension(R.dimen.chart_right_pading); 123 | float reckRealTotalLength = getWidth() - resources.getDimension(R.dimen.vertical_line_x) - resources.getDimension(R.dimen.chart_right_real_pading); 124 | 125 | // 根据不同的id设置不同的绘制颜色 126 | for (int i = 0; i < eventText.length; i++) { 127 | 128 | // 绘制事件名称 129 | // 绘制事件文字的画笔 130 | paintCommon.reset(); 131 | paintCommon.setAntiAlias(true); 132 | paintCommon.setColor(Color.parseColor("#4C4C4C")); 133 | paintCommon.setTextSize(resources.getDimension(R.dimen.road_state_text_size)); 134 | paintCommon.setTextAlign(Align.LEFT); 135 | canvas.drawText(eventText[i], beginX, beginY + (spaceY / 2f) + resources.getDimension(R.dimen.center_offset) + spaceY * i, paintCommon); 136 | 137 | if (monthCountList.size() > 0) { 138 | 139 | // 生成矩形边界 140 | rectCommon.left = vertical_line_X + resources.getDimension(R.dimen.line_space); 141 | rectCommon.top = beginY + (spaceY / 2f) + resources.getDimension(R.dimen.center_offset) + spaceY * i - resources.getDimension(R.dimen.reck_subtractor); 142 | rectCommon.right = vertical_line_X + reckTotalLength; 143 | rectCommon.bottom = beginY + (spaceY / 2f) + resources.getDimension(R.dimen.center_offset) + spaceY * i - resources.getDimension(R.dimen.reck_subtractor) + resources.getDimension(R.dimen.reck_height); 144 | // 绘制圆角矩形 145 | // 绘制矩形条的画笔,每个条目的背景 146 | paintCommon.reset(); 147 | paintCommon.setAntiAlias(true); 148 | paintCommon.setColor(Color.parseColor("#BFC6E8")); 149 | paintCommon.setAlpha(30); 150 | paintCommon.setStyle(Paint.Style.FILL); 151 | canvas.drawRoundRect(rectCommon, 15, 15, paintCommon); 152 | 153 | if (max > 0) { 154 | 155 | // 生成矩形边界 156 | rectCommon.left = vertical_line_X + resources.getDimension(R.dimen.line_space); 157 | rectCommon.top = beginY + (spaceY / 2f) + resources.getDimension(R.dimen.center_offset) + spaceY * i - resources.getDimension(R.dimen.reck_subtractor); 158 | rectCommon.right = vertical_line_X + monthCountList.get(i) / (float) max * reckRealTotalLength; 159 | rectCommon.bottom = beginY + (spaceY / 2f) + resources.getDimension(R.dimen.center_offset) + spaceY * i - resources.getDimension(R.dimen.reck_subtractor) + resources.getDimension(R.dimen.reck_height); 160 | // 绘制圆角矩形 161 | // 绘制矩形条的画笔 162 | paintCommon.reset(); 163 | paintCommon.setAntiAlias(true); 164 | paintCommon.setStyle(Paint.Style.FILL); 165 | if (i == 0) { 166 | paintCommon.setColor(Color.parseColor("#E31470")); 167 | } 168 | if (i == 1) { 169 | paintCommon.setColor(Color.parseColor("#FD4949")); 170 | } 171 | if (i == 2) { 172 | paintCommon.setColor(Color.parseColor("#FD8708")); 173 | } 174 | if (i == 3) { 175 | paintCommon.setColor(Color.parseColor("#F7BF12")); 176 | } 177 | if (i == 4) { 178 | paintCommon.setColor(Color.parseColor("#8DC734")); 179 | } 180 | canvas.drawRoundRect(rectCommon, 15, 15, paintCommon); 181 | // 绘制数量值 182 | if (monthCountList.get(i).intValue() > 0) { 183 | // 绘制事件数量文字的画笔 184 | paintCommon.reset(); 185 | paintCommon.setAntiAlias(true); 186 | paintCommon.setColor(Color.parseColor("#000000")); 187 | paintCommon.setTextSize(resources.getDimension(R.dimen.count_text_size)); 188 | paintCommon.setTextAlign(Align.LEFT); 189 | canvas.drawText(String.valueOf(monthCountList.get(i).intValue()), vertical_line_X + monthCountList.get(i) / (float) max * reckRealTotalLength + resources.getDimension(R.dimen.count_text_offset), beginY + (spaceY / 2f) + resources.getDimension(R.dimen.center_offset) + spaceY * i, paintCommon); 190 | } 191 | 192 | } 193 | } 194 | } 195 | isRefresh = false; 196 | } 197 | } 198 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | 14 | 15 | 22 | 23 | 27 | 28 | 33 | 34 | 35 | 40 | 41 | 42 | 49 | 50 | 54 | 55 | 56 | 57 | 58 | 59 | 64 | 65 | 66 | -------------------------------------------------------------------------------- /app/src/main/res/mipmap-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/excellenttank/CustomChart/d3c9b8d3f1d2e9afc52e54f1911b73091b64f762/app/src/main/res/mipmap-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-hdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/excellenttank/CustomChart/d3c9b8d3f1d2e9afc52e54f1911b73091b64f762/app/src/main/res/mipmap-hdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/excellenttank/CustomChart/d3c9b8d3f1d2e9afc52e54f1911b73091b64f762/app/src/main/res/mipmap-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-mdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/excellenttank/CustomChart/d3c9b8d3f1d2e9afc52e54f1911b73091b64f762/app/src/main/res/mipmap-mdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/excellenttank/CustomChart/d3c9b8d3f1d2e9afc52e54f1911b73091b64f762/app/src/main/res/mipmap-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/excellenttank/CustomChart/d3c9b8d3f1d2e9afc52e54f1911b73091b64f762/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/excellenttank/CustomChart/d3c9b8d3f1d2e9afc52e54f1911b73091b64f762/app/src/main/res/mipmap-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/excellenttank/CustomChart/d3c9b8d3f1d2e9afc52e54f1911b73091b64f762/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/excellenttank/CustomChart/d3c9b8d3f1d2e9afc52e54f1911b73091b64f762/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/excellenttank/CustomChart/d3c9b8d3f1d2e9afc52e54f1911b73091b64f762/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/values/colors.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | #3F51B5 4 | #303F9F 5 | #FF4081 6 | 7 | -------------------------------------------------------------------------------- /app/src/main/res/values/dimens.xml: -------------------------------------------------------------------------------- 1 | 2 | 700dp 3 | 240dp 4 | 0dp 5 | 10dp 6 | 30dp 7 | 1dp 8 | 5dp 9 | 20dp 10 | 2dp 11 | 1dp 12 | 30dp 13 | 10dp 14 | 1dp 15 | 10sp 16 | 15dp 17 | 6dp 18 | 4dp 19 | 3dp 20 | 9sp 21 | 3sp 22 | 1dp 23 | 20dp 24 | 10dp 25 | 20dp 26 | 17dp 27 | 9dp 28 | 5dp 29 | 62dp 30 | 30dp 31 | 2dp 32 | 8dp 33 | 10dp 34 | 10dp 35 | 7dp 36 | 37 | 20dp 38 | 5dp 39 | 20dp 40 | 45dp 41 | 14sp 42 | 12sp 43 | 80dp 44 | 12dp 45 | 15dp 46 | 2dp 47 | 5dp 48 | 49 | -------------------------------------------------------------------------------- /app/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | CustomChart 3 | 4 | -------------------------------------------------------------------------------- /app/src/main/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /app/src/test/java/com/excellent_tank/customchart/ExampleUnitTest.java: -------------------------------------------------------------------------------- 1 | package com.excellent_tank.customchart; 2 | 3 | import org.junit.Test; 4 | 5 | import static org.junit.Assert.*; 6 | 7 | /** 8 | * Example local unit test, which will execute on the development machine (host). 9 | * 10 | * @see Testing documentation 11 | */ 12 | public class ExampleUnitTest { 13 | @Test 14 | public void addition_isCorrect() throws Exception { 15 | assertEquals(4, 2 + 2); 16 | } 17 | } -------------------------------------------------------------------------------- /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:2.3.3' 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 | 21 | task clean(type: Delete) { 22 | delete rootProject.buildDir 23 | } 24 | -------------------------------------------------------------------------------- /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 | org.gradle.jvmargs=-Xmx1536m 13 | 14 | # When configured, Gradle will run in incubating parallel mode. 15 | # This option should only be used with decoupled projects. More details, visit 16 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects 17 | # org.gradle.parallel=true 18 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/excellenttank/CustomChart/d3c9b8d3f1d2e9afc52e54f1911b73091b64f762/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Mon Aug 28 10:12:34 CST 2017 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-3.3-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 | # Attempt to set APP_HOME 46 | # Resolve links: $0 may be a link 47 | PRG="$0" 48 | # Need this for relative symlinks. 49 | while [ -h "$PRG" ] ; do 50 | ls=`ls -ld "$PRG"` 51 | link=`expr "$ls" : '.*-> \(.*\)$'` 52 | if expr "$link" : '/.*' > /dev/null; then 53 | PRG="$link" 54 | else 55 | PRG=`dirname "$PRG"`"/$link" 56 | fi 57 | done 58 | SAVED="`pwd`" 59 | cd "`dirname \"$PRG\"`/" >/dev/null 60 | APP_HOME="`pwd -P`" 61 | cd "$SAVED" >/dev/null 62 | 63 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 64 | 65 | # Determine the Java command to use to start the JVM. 66 | if [ -n "$JAVA_HOME" ] ; then 67 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 68 | # IBM's JDK on AIX uses strange locations for the executables 69 | JAVACMD="$JAVA_HOME/jre/sh/java" 70 | else 71 | JAVACMD="$JAVA_HOME/bin/java" 72 | fi 73 | if [ ! -x "$JAVACMD" ] ; then 74 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 75 | 76 | Please set the JAVA_HOME variable in your environment to match the 77 | location of your Java installation." 78 | fi 79 | else 80 | JAVACMD="java" 81 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 82 | 83 | Please set the JAVA_HOME variable in your environment to match the 84 | location of your Java installation." 85 | fi 86 | 87 | # Increase the maximum file descriptors if we can. 88 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then 89 | MAX_FD_LIMIT=`ulimit -H -n` 90 | if [ $? -eq 0 ] ; then 91 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then 92 | MAX_FD="$MAX_FD_LIMIT" 93 | fi 94 | ulimit -n $MAX_FD 95 | if [ $? -ne 0 ] ; then 96 | warn "Could not set maximum file descriptor limit: $MAX_FD" 97 | fi 98 | else 99 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" 100 | fi 101 | fi 102 | 103 | # For Darwin, add options to specify how the application appears in the dock 104 | if $darwin; then 105 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" 106 | fi 107 | 108 | # For Cygwin, switch paths to Windows format before running java 109 | if $cygwin ; then 110 | APP_HOME=`cygpath --path --mixed "$APP_HOME"` 111 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` 112 | JAVACMD=`cygpath --unix "$JAVACMD"` 113 | 114 | # We build the pattern for arguments to be converted via cygpath 115 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` 116 | SEP="" 117 | for dir in $ROOTDIRSRAW ; do 118 | ROOTDIRS="$ROOTDIRS$SEP$dir" 119 | SEP="|" 120 | done 121 | OURCYGPATTERN="(^($ROOTDIRS))" 122 | # Add a user-defined pattern to the cygpath arguments 123 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then 124 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" 125 | fi 126 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 127 | i=0 128 | for arg in "$@" ; do 129 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` 130 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option 131 | 132 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition 133 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` 134 | else 135 | eval `echo args$i`="\"$arg\"" 136 | fi 137 | i=$((i+1)) 138 | done 139 | case $i in 140 | (0) set -- ;; 141 | (1) set -- "$args0" ;; 142 | (2) set -- "$args0" "$args1" ;; 143 | (3) set -- "$args0" "$args1" "$args2" ;; 144 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;; 145 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; 146 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; 147 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; 148 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; 149 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; 150 | esac 151 | fi 152 | 153 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules 154 | function splitJvmOpts() { 155 | JVM_OPTS=("$@") 156 | } 157 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS 158 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME" 159 | 160 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@" 161 | -------------------------------------------------------------------------------- /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' 2 | --------------------------------------------------------------------------------