├── README.md ├── ScaleView.iml ├── app ├── .gitignore ├── app.iml ├── build.gradle ├── proguard-rules.pro └── src │ ├── androidTest │ └── java │ │ └── xyy │ │ └── scaleview │ │ └── ExampleInstrumentedTest.java │ ├── main │ ├── AndroidManifest.xml │ ├── java │ │ └── xyy │ │ │ └── scaleview │ │ │ ├── MainActivity.java │ │ │ └── scaleview │ │ │ ├── HorizontalScaleView.java │ │ │ ├── OnValueChangeListener.java │ │ │ └── VerticalScaleView.java │ └── res │ │ ├── drawable │ │ └── button_round_corner.xml │ │ ├── layout │ │ └── activity_main.xml │ │ ├── mipmap-hdpi │ │ └── ic_launcher.png │ │ ├── mipmap-mdpi │ │ └── ic_launcher.png │ │ ├── mipmap-xhdpi │ │ └── ic_launcher.png │ │ ├── mipmap-xxhdpi │ │ └── ic_launcher.png │ │ ├── mipmap-xxxhdpi │ │ └── ic_launcher.png │ │ ├── values-w820dp │ │ └── dimens.xml │ │ └── values │ │ ├── colors.xml │ │ ├── dimens.xml │ │ ├── strings.xml │ │ └── styles.xml │ └── test │ └── java │ └── xyy │ └── scaleview │ └── ExampleUnitTest.java ├── build.gradle ├── build ├── generated │ └── mockable-android-25.jar └── intermediates │ └── dex-cache │ └── cache.xml ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── local.properties ├── screenshot ├── HorizontalScaleView.png └── VerticalScaleView.png └── settings.gradle /README.md: -------------------------------------------------------------------------------- 1 | # ScaleView 2 | Android横向和纵向滑动刻度尺 3 | 4 | ![HorizontalScaleView](https://github.com/GITbiubiubiu/ScaleView/raw/master/screenshot/HorizontalScaleView.png) 5 | 6 | ![VerticalScaleView](https://github.com/GITbiubiubiu/ScaleView/raw/master/screenshot/VerticalScaleView.png) 7 | -------------------------------------------------------------------------------- /ScaleView.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /app/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /app/app.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 8 | 9 | 10 | 11 | 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 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | 134 | 135 | 136 | 137 | 138 | 139 | 140 | 141 | 142 | -------------------------------------------------------------------------------- /app/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | 3 | android { 4 | compileSdkVersion 25 5 | buildToolsVersion "25.0.0" 6 | defaultConfig { 7 | applicationId "xyy.scaleview" 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.0.0' 28 | testCompile 'junit:junit:4.12' 29 | } 30 | -------------------------------------------------------------------------------- /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 F:\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/xyy/scaleview/ExampleInstrumentedTest.java: -------------------------------------------------------------------------------- 1 | package xyy.scaleview; 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("xyy.scaleview", appContext.getPackageName()); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /app/src/main/java/xyy/scaleview/MainActivity.java: -------------------------------------------------------------------------------- 1 | package xyy.scaleview; 2 | 3 | import android.app.Activity; 4 | import android.support.annotation.Nullable; 5 | import android.support.v7.app.AppCompatActivity; 6 | import android.os.Bundle; 7 | import android.view.View; 8 | import android.view.Window; 9 | import android.widget.TextView; 10 | 11 | import xyy.scaleview.scaleview.HorizontalScaleView; 12 | import xyy.scaleview.scaleview.OnValueChangeListener; 13 | import xyy.scaleview.scaleview.VerticalScaleView; 14 | 15 | public class MainActivity extends Activity implements View.OnClickListener { 16 | 17 | private VerticalScaleView verticalScaleView; 18 | private HorizontalScaleView horizontalScaleView; 19 | private TextView heightTv; 20 | private TextView weightTv; 21 | 22 | @Override 23 | protected void onCreate(Bundle savedInstanceState) { 24 | super.onCreate(savedInstanceState); 25 | setContentView(R.layout.activity_main); 26 | verticalScaleView = (VerticalScaleView) findViewById(R.id.vertical_scale); 27 | horizontalScaleView = (HorizontalScaleView) findViewById(R.id 28 | .horizontal_scale); 29 | heightTv = (TextView) findViewById(R.id.height); 30 | weightTv = (TextView) findViewById(R.id.weight); 31 | heightTv.setOnClickListener(this); 32 | weightTv.setOnClickListener(this); 33 | 34 | verticalScaleView.setRange(100, 200); 35 | horizontalScaleView.setRange(40, 100); 36 | 37 | verticalScaleView.setOnValueChangeListener(new OnValueChangeListener() { 38 | @Override 39 | public void onValueChanged(float value) { 40 | heightTv.setText(String.valueOf(value)); 41 | heightTv.setTextColor(getResources().getColor(R.color.main_color)); 42 | } 43 | }); 44 | horizontalScaleView.setOnValueChangeListener(new OnValueChangeListener() { 45 | @Override 46 | public void onValueChanged(float value) { 47 | weightTv.setText(String.valueOf(value)); 48 | weightTv.setTextColor(getResources().getColor(R.color.main_color)); 49 | } 50 | }); 51 | } 52 | 53 | @Override 54 | public void onClick(View v) { 55 | switch (v.getId()) { 56 | case R.id.height: 57 | verticalScaleView.setVisibility(View.VISIBLE); 58 | horizontalScaleView.setVisibility(View.GONE); 59 | break; 60 | case R.id.weight: 61 | verticalScaleView.setVisibility(View.GONE); 62 | horizontalScaleView.setVisibility(View.VISIBLE); 63 | break; 64 | default: 65 | break; 66 | } 67 | } 68 | } -------------------------------------------------------------------------------- /app/src/main/java/xyy/scaleview/scaleview/HorizontalScaleView.java: -------------------------------------------------------------------------------- 1 | package xyy.scaleview.scaleview; 2 | 3 | import java.math.BigDecimal; 4 | 5 | import android.content.Context; 6 | import android.graphics.Canvas; 7 | import android.graphics.Paint; 8 | import android.graphics.Path; 9 | import android.graphics.Rect; 10 | import android.graphics.RectF; 11 | import android.os.Handler; 12 | import android.os.Message; 13 | import android.util.AttributeSet; 14 | import android.view.MotionEvent; 15 | import android.view.VelocityTracker; 16 | import android.view.View; 17 | import android.view.ViewConfiguration; 18 | 19 | import xyy.scaleview.R; 20 | 21 | /** 22 | * Copyright (c) 2017, Bongmi 23 | * All rights reserved 24 | * Author: xuyuanyi@bongmi.com 25 | */ 26 | 27 | public class HorizontalScaleView extends View { 28 | 29 | private final int SCALE_WIDTH_BIG = 4;//大刻度线宽度 30 | private final int SCALE_WIDTH_SMALL = 2;//小刻度线宽度 31 | private final int LINE_WIDTH = 6;//指针线宽度 32 | 33 | private int rectPadding = 40;//圆角矩形间距 34 | private int rectWidth;//圆角矩形宽 35 | private int rectHeight;//圆角矩形高 36 | 37 | private int maxScaleLength;//大刻度长度 38 | private int midScaleLength;//中刻度长度 39 | private int minScaleLength;//小刻度长度 40 | private int scaleSpace;//刻度间距 41 | private int scaleSpaceUnit;//每大格刻度间距 42 | private int height, width;//view高宽 43 | private int ruleHeight;//刻度尺高 44 | 45 | private int max;//最大刻度 46 | private int min;//最小刻度 47 | private int borderLeft, borderRight;//左右边界值坐标 48 | private float midX;//当前中心刻度x坐标 49 | private float originMidX;//初始中心刻度x坐标 50 | private float minX;//最小刻度x坐标,从最小刻度开始画刻度 51 | 52 | private float lastX; 53 | 54 | private float originValue;//初始刻度对应的值 55 | private float currentValue;//当前刻度对应的值 56 | 57 | private Paint paint;//画笔 58 | 59 | private Context context; 60 | 61 | private String descri = "体重";//描述 62 | private String unit = "kg";//刻度单位 63 | 64 | private VelocityTracker velocityTracker;//速度监测 65 | private float velocity;//当前滑动速度 66 | private float a = 1000000;//加速度 67 | private boolean continueScroll;//是否继续滑动 68 | 69 | private boolean isMeasured; 70 | 71 | private OnValueChangeListener onValueChangeListener; 72 | 73 | private Handler mHandler = new Handler() { 74 | @Override 75 | public void handleMessage(Message msg) { 76 | if (null != onValueChangeListener) { 77 | float v = (float) (Math.round(currentValue * 10)) / 10;//保留一位小数 78 | onValueChangeListener.onValueChanged(v); 79 | } 80 | } 81 | }; 82 | 83 | public HorizontalScaleView(Context context) { 84 | super(context); 85 | this.context = context; 86 | init(); 87 | } 88 | 89 | public HorizontalScaleView(Context context, AttributeSet attrs) { 90 | super(context, attrs); 91 | this.context = context; 92 | init(); 93 | } 94 | 95 | public HorizontalScaleView(Context context, AttributeSet attrs, int defStyleAttr) { 96 | super(context, attrs, defStyleAttr); 97 | this.context = context; 98 | init(); 99 | } 100 | 101 | private void init() { 102 | //初始化画笔 103 | paint = new Paint(); 104 | paint.setAntiAlias(true); 105 | paint.setDither(true); 106 | 107 | } 108 | 109 | //设置刻度范围 110 | public void setRange(int min, int max) { 111 | this.min = min; 112 | this.max = max; 113 | originValue = (max + min) / 2; 114 | currentValue = originValue; 115 | } 116 | 117 | //设置刻度单位 118 | public void setUnit(String unit) { 119 | this.unit = unit; 120 | } 121 | 122 | //设置刻度描述 123 | public void setDescri(String descri) { 124 | this.descri = descri; 125 | } 126 | 127 | //设置value变化监听 128 | public void setOnValueChangeListener(OnValueChangeListener onValueChangeListener) { 129 | this.onValueChangeListener = onValueChangeListener; 130 | } 131 | 132 | @Override 133 | protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { 134 | super.onMeasure(widthMeasureSpec, heightMeasureSpec); 135 | if (!isMeasured) { 136 | width = getMeasuredWidth(); 137 | height = getMeasuredHeight(); 138 | ruleHeight = height * 2 / 3; 139 | maxScaleLength = height / 10; 140 | midScaleLength = height / 12; 141 | minScaleLength = maxScaleLength / 2; 142 | scaleSpace = height / 60 > 8 ? height / 60 : 8; 143 | scaleSpaceUnit = scaleSpace * 10 + SCALE_WIDTH_BIG + SCALE_WIDTH_SMALL * 9; 144 | rectWidth = scaleSpaceUnit; 145 | rectHeight = scaleSpaceUnit / 2; 146 | 147 | borderLeft = width / 2 - ((min + max) / 2 - min) * scaleSpaceUnit; 148 | borderRight = width / 2 + ((min + max) / 2 - min) * scaleSpaceUnit; 149 | midX = (borderLeft + borderRight) / 2; 150 | originMidX = midX; 151 | minX = borderLeft; 152 | isMeasured = true; 153 | } 154 | 155 | } 156 | 157 | @Override 158 | protected void onDraw(Canvas canvas) { 159 | super.onDraw(canvas); 160 | 161 | //画刻度线 162 | for (int i = min; i <= max; i++) { 163 | //画刻度数字 164 | Rect rect = new Rect(); 165 | String str = String.valueOf(i); 166 | paint.setColor(getResources().getColor(R.color.black)); 167 | paint.setTextSize(40); 168 | paint.getTextBounds(str, 0, str.length(), rect); 169 | int w = rect.width(); 170 | int h = rect.height(); 171 | canvas.drawText(str, minX + (i - min) * scaleSpaceUnit - w / 2 - SCALE_WIDTH_BIG / 2, ruleHeight - maxScaleLength - h - minScaleLength / 2, paint); 172 | //画大刻度线 173 | paint.setStrokeWidth(SCALE_WIDTH_BIG); 174 | canvas.drawLine(minX + (i - min) * scaleSpaceUnit, ruleHeight - maxScaleLength, minX + (i - min) * scaleSpaceUnit, ruleHeight, paint); 175 | 176 | if (i == max) { 177 | continue;//最后一条不画中小刻度线 178 | } 179 | //画中刻度线 180 | paint.setStrokeWidth(SCALE_WIDTH_SMALL); 181 | canvas.drawLine(minX + (i - min) * scaleSpaceUnit + scaleSpaceUnit / 2, ruleHeight, minX + (i - min) * scaleSpaceUnit + scaleSpaceUnit / 2, ruleHeight - midScaleLength, paint); 182 | //画小刻度线 183 | for (int j = 1; j < 10; j++) { 184 | if (j == 5) { 185 | continue; 186 | } 187 | canvas.drawLine(minX + (i - min) * scaleSpaceUnit + (SCALE_WIDTH_SMALL + scaleSpace) * j, ruleHeight, minX + (i - min) * scaleSpaceUnit + (SCALE_WIDTH_SMALL + scaleSpace) * j, ruleHeight - minScaleLength, paint); 188 | } 189 | 190 | } 191 | 192 | //画竖线 193 | paint.setStrokeWidth(LINE_WIDTH); 194 | paint.setColor(getResources().getColor(R.color.gray)); 195 | canvas.drawLine(minX + SCALE_WIDTH_BIG / 2, ruleHeight + LINE_WIDTH / 2, minX + (max - min) * scaleSpaceUnit - SCALE_WIDTH_BIG / 2, ruleHeight + LINE_WIDTH / 2, paint); 196 | //画指针线 197 | paint.setColor(getResources().getColor(R.color.colorPrimaryDark)); 198 | canvas.drawLine(width / 2, 0, width / 2, ruleHeight, paint); 199 | //画圆角矩形 200 | paint.setStyle(Paint.Style.FILL); 201 | RectF r = new RectF(); 202 | r.left = width / 2 - rectWidth / 2; 203 | r.top = ruleHeight + rectPadding; 204 | r.right = width / 2 + rectWidth / 2; 205 | r.bottom = ruleHeight + rectPadding + rectHeight; 206 | canvas.drawRoundRect(r, 10, 10, paint); 207 | //画小三角形指针 208 | Path path = new Path(); 209 | path.moveTo(width / 2 - scaleSpace * 2, ruleHeight + rectPadding); 210 | path.lineTo(width / 2, ruleHeight + rectPadding - 10); 211 | path.lineTo(width / 2 + scaleSpace * 2, ruleHeight + rectPadding); 212 | path.close(); 213 | canvas.drawPath(path, paint); 214 | //绘制文字 215 | paint.setColor(getResources().getColor(R.color.black)); 216 | Rect rect1 = new Rect(); 217 | paint.getTextBounds(descri, 0, descri.length(), rect1); 218 | int w1 = rect1.width(); 219 | int h1 = rect1.height(); 220 | canvas.drawText(descri, width / 2 - w1 / 2, ruleHeight + rectPadding + rectHeight + h1 + 10, paint); 221 | //绘制当前刻度值数字 222 | paint.setColor(getResources().getColor(R.color.white)); 223 | float v = (float) (Math.round(currentValue * 10)) / 10;//保留一位小数 224 | String value = String.valueOf(v) + unit; 225 | Rect rect2 = new Rect(); 226 | paint.getTextBounds(value, 0, value.length(), rect2); 227 | int w2 = rect2.width(); 228 | int h2 = rect2.height(); 229 | canvas.drawText(value, width / 2 - w2 / 2, ruleHeight + rectPadding + rectHeight / 2 + h2 / 2, paint); 230 | } 231 | 232 | @Override 233 | public boolean onTouchEvent(MotionEvent event) { 234 | float x = event.getX(); 235 | switch (event.getAction()) { 236 | case MotionEvent.ACTION_DOWN: 237 | lastX = x; 238 | continueScroll = false; 239 | //初始化速度追踪 240 | if (velocityTracker == null) { 241 | velocityTracker = VelocityTracker.obtain(); 242 | } else { 243 | velocityTracker.clear(); 244 | } 245 | break; 246 | case MotionEvent.ACTION_MOVE: 247 | velocityTracker.addMovement(event); 248 | int offsetX = (int) (lastX - x); 249 | minX -= offsetX; 250 | midX -= offsetX; 251 | calculateCurrentScale(); 252 | invalidate(); 253 | lastX = x; 254 | break; 255 | case MotionEvent.ACTION_UP: 256 | confirmBorder(); 257 | //当前滑动速度 258 | velocityTracker.computeCurrentVelocity(1000); 259 | velocity = velocityTracker.getXVelocity(); 260 | float minVelocity = ViewConfiguration.get(context).getScaledMinimumFlingVelocity(); 261 | if (Math.abs(velocity) > minVelocity) { 262 | continueScroll = true; 263 | continueScroll(); 264 | } else { 265 | velocityTracker.recycle(); 266 | velocityTracker = null; 267 | } 268 | break; 269 | case MotionEvent.ACTION_CANCEL: 270 | velocityTracker.recycle(); 271 | velocityTracker = null; 272 | break; 273 | } 274 | return true; 275 | } 276 | 277 | //计算当前刻度 278 | private void calculateCurrentScale() { 279 | float offsetTotal = midX - originMidX; 280 | int offsetBig = (int) (offsetTotal / scaleSpaceUnit);//移动的大刻度数 281 | float offsetS = offsetTotal % scaleSpaceUnit; 282 | int offsetSmall = (new BigDecimal(offsetS / (scaleSpace + SCALE_WIDTH_SMALL)).setScale(0, BigDecimal.ROUND_HALF_UP)).intValue();//移动的小刻度数 四舍五入取整 283 | float offset = offsetBig + offsetSmall * 0.1f; 284 | if (originValue - offset > max) { 285 | currentValue = max; 286 | } else if (originValue - offset < min) { 287 | currentValue = min; 288 | } else { 289 | currentValue = originValue - offset; 290 | } 291 | mHandler.sendEmptyMessage(0); 292 | } 293 | 294 | //指针线超出范围时 重置回边界处 295 | private void confirmBorder() { 296 | if (midX < borderLeft) { 297 | midX = borderLeft; 298 | minX = borderLeft - (borderRight - borderLeft) / 2; 299 | postInvalidate(); 300 | } else if (midX > borderRight) { 301 | midX = borderRight; 302 | minX = borderLeft + (borderRight - borderLeft) / 2; 303 | postInvalidate(); 304 | } 305 | } 306 | 307 | //手指抬起后继续惯性滑动 308 | private void continueScroll() { 309 | new Thread(new Runnable() { 310 | @Override 311 | public void run() { 312 | float velocityAbs = 0;//速度绝对值 313 | if (velocity > 0 && continueScroll) { 314 | velocity -= 50; 315 | minX += velocity * velocity / a; 316 | midX += velocity * velocity / a; 317 | velocityAbs = velocity; 318 | } else if (velocity < 0 && continueScroll) { 319 | velocity += 50; 320 | minX -= velocity * velocity / a; 321 | midX -= velocity * velocity / a; 322 | velocityAbs = -velocity; 323 | } 324 | calculateCurrentScale(); 325 | confirmBorder(); 326 | postInvalidate(); 327 | if (continueScroll && velocityAbs > 0) { 328 | post(this); 329 | } else { 330 | continueScroll = false; 331 | } 332 | } 333 | }).start(); 334 | } 335 | } 336 | -------------------------------------------------------------------------------- /app/src/main/java/xyy/scaleview/scaleview/OnValueChangeListener.java: -------------------------------------------------------------------------------- 1 | package xyy.scaleview.scaleview; 2 | 3 | /** 4 | * Copyright (c) 2017, Bongmi 5 | * All rights reserved 6 | * Author: xuyuanyi@bongmi.com 7 | */ 8 | 9 | public interface OnValueChangeListener { 10 | void onValueChanged(float value); 11 | } 12 | -------------------------------------------------------------------------------- /app/src/main/java/xyy/scaleview/scaleview/VerticalScaleView.java: -------------------------------------------------------------------------------- 1 | package xyy.scaleview.scaleview; 2 | 3 | import java.math.BigDecimal; 4 | 5 | import android.content.Context; 6 | import android.graphics.Canvas; 7 | import android.graphics.Paint; 8 | import android.graphics.Path; 9 | import android.graphics.Rect; 10 | import android.graphics.RectF; 11 | import android.os.Handler; 12 | import android.os.Message; 13 | import android.util.AttributeSet; 14 | import android.util.Log; 15 | import android.view.MotionEvent; 16 | import android.view.VelocityTracker; 17 | import android.view.View; 18 | import android.view.ViewConfiguration; 19 | 20 | import xyy.scaleview.R; 21 | 22 | /** 23 | * Copyright (c) 2017, Bongmi 24 | * All rights reserved 25 | * Author: xuyuanyi@bongmi.com 26 | */ 27 | 28 | public class VerticalScaleView extends View { 29 | 30 | private final int SCALE_WIDTH_BIG = 4;//大刻度线宽度 31 | private final int SCALE_WIDTH_SMALL = 2;//小刻度线宽度 32 | private final int LINE_WIDTH = 6;//指针线宽度 33 | 34 | private int rectPadding = 20;//圆角矩形间距 35 | private int rectHeight;//圆角矩形高 36 | 37 | private int maxScaleLength;//大刻度长度 38 | private int midScaleLength;//中刻度长度 39 | private int minScaleLength;//小刻度长度 40 | private int scaleSpace;//刻度间距 41 | private int scaleSpaceUnit;//每大格刻度间距 42 | private int height, width;//view高宽 43 | private int ruleWidth;//刻度尺宽 44 | 45 | private int max;//最大刻度 46 | private int min;//最小刻度 47 | private int borderUp, borderDown;//上下边界值坐标 48 | private float midY;//当前中心刻度y坐标 49 | private float originMidY;//初始中心刻度y坐标 50 | private float minY;//最小刻度y坐标,从最小刻度开始画刻度 51 | 52 | private float lastY; 53 | 54 | private float originValue;//初始刻度对应的值 55 | private float currentValue;//当前刻度对应的值 56 | 57 | private Paint paint;//画笔 58 | 59 | private Context context; 60 | 61 | private String descri = "身高";//描述 62 | private String unit = "cm";//刻度单位 63 | 64 | private VelocityTracker velocityTracker;//速度监测 65 | private float velocity;//当前滑动速度 66 | private float a = 1000000;//加速度 67 | private boolean continueScroll;//是否继续滑动 68 | 69 | private boolean isMeasured; 70 | 71 | private OnValueChangeListener onValueChangeListener; 72 | 73 | private Handler mHandler = new Handler() { 74 | @Override 75 | public void handleMessage(Message msg) { 76 | if (null != onValueChangeListener) { 77 | float v = (float) (Math.round(currentValue * 10)) / 10;//保留一位小数 78 | onValueChangeListener.onValueChanged(v); 79 | } 80 | } 81 | }; 82 | 83 | public VerticalScaleView(Context context) { 84 | super(context); 85 | this.context = context; 86 | init(); 87 | } 88 | 89 | public VerticalScaleView(Context context, AttributeSet attrs) { 90 | super(context, attrs); 91 | this.context = context; 92 | init(); 93 | } 94 | 95 | public VerticalScaleView(Context context, AttributeSet attrs, int defStyleAttr) { 96 | super(context, attrs, defStyleAttr); 97 | this.context = context; 98 | init(); 99 | } 100 | 101 | private void init() { 102 | //初始化画笔 103 | paint = new Paint(); 104 | paint.setAntiAlias(true); 105 | paint.setDither(true); 106 | 107 | } 108 | 109 | //设置刻度范围 110 | public void setRange(int min, int max) { 111 | this.min = min; 112 | this.max = max; 113 | originValue = (max + min) / 2; 114 | currentValue = originValue; 115 | } 116 | 117 | //设置刻度单位 118 | public void setUnit(String unit) { 119 | this.unit = unit; 120 | } 121 | 122 | //设置刻度描述 123 | public void setDescri(String descri) { 124 | this.descri = descri; 125 | } 126 | 127 | //设置value变化监听 128 | public void setOnValueChangeListener(OnValueChangeListener onValueChangeListener) { 129 | this.onValueChangeListener = onValueChangeListener; 130 | } 131 | 132 | @Override 133 | protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { 134 | super.onMeasure(widthMeasureSpec, heightMeasureSpec); 135 | if (!isMeasured) { 136 | width = getMeasuredWidth(); 137 | height = getMeasuredHeight(); 138 | ruleWidth = width * 2 / 3; 139 | maxScaleLength = width / 5; 140 | midScaleLength = width / 6; 141 | minScaleLength = maxScaleLength / 2; 142 | scaleSpace = height / 80 > 8 ? height / 80 : 8; 143 | scaleSpaceUnit = scaleSpace * 10 + SCALE_WIDTH_BIG + SCALE_WIDTH_SMALL * 9; 144 | rectHeight = scaleSpaceUnit / 2; 145 | 146 | borderUp = height / 2 - ((min + max) / 2 - min) * scaleSpaceUnit; 147 | borderDown = height / 2 + ((min + max) / 2 - min) * scaleSpaceUnit; 148 | midY = (borderUp + borderDown) / 2; 149 | originMidY = midY; 150 | minY = borderDown; 151 | isMeasured = true; 152 | } 153 | 154 | } 155 | 156 | @Override 157 | protected void onDraw(Canvas canvas) { 158 | super.onDraw(canvas); 159 | 160 | //画刻度线 161 | for (int i = min; i <= max; i++) { 162 | //画刻度数字 163 | canvas.rotate(90); 164 | Rect rect = new Rect(); 165 | String str = String.valueOf(i); 166 | paint.setColor(getResources().getColor(R.color.black)); 167 | paint.setTextSize(40); 168 | paint.getTextBounds(str, 0, str.length(), rect); 169 | int w = rect.width(); 170 | int h = rect.height(); 171 | canvas.drawText(str, minY - (i - min) * scaleSpaceUnit - w / 2 - SCALE_WIDTH_BIG / 2, -(ruleWidth - maxScaleLength - h - minScaleLength / 2), paint); 172 | canvas.rotate(-90); 173 | //画大刻度线 174 | paint.setStrokeWidth(SCALE_WIDTH_BIG); 175 | canvas.drawLine(ruleWidth, minY - (i - min) * scaleSpaceUnit, ruleWidth - maxScaleLength, minY - (i - min) * scaleSpaceUnit, paint); 176 | 177 | if (i == min) { 178 | continue;//最后一条不画中小刻度线 179 | } 180 | //画中刻度线 181 | paint.setStrokeWidth(SCALE_WIDTH_SMALL); 182 | canvas.drawLine(ruleWidth, minY - (i - min) * scaleSpaceUnit + scaleSpaceUnit / 2, ruleWidth - midScaleLength, minY - (i - min) * scaleSpaceUnit + scaleSpaceUnit / 2, paint); 183 | //画小刻度线 184 | for (int j = 1; j < 10; j++) { 185 | if (j == 5) { 186 | continue; 187 | } 188 | canvas.drawLine(ruleWidth, minY - (i - min) * scaleSpaceUnit + (SCALE_WIDTH_SMALL + scaleSpace) * j, ruleWidth - minScaleLength, minY - (i - min) * scaleSpaceUnit + (SCALE_WIDTH_SMALL + scaleSpace) * j, paint); 189 | } 190 | 191 | } 192 | 193 | //画竖线 194 | paint.setStrokeWidth(LINE_WIDTH); 195 | paint.setColor(getResources().getColor(R.color.gray)); 196 | canvas.drawLine(ruleWidth + LINE_WIDTH / 2, minY + SCALE_WIDTH_BIG / 2, ruleWidth + LINE_WIDTH / 2, minY - (max - min) * scaleSpaceUnit - SCALE_WIDTH_BIG / 2, paint); 197 | //画指针线 198 | paint.setColor(getResources().getColor(R.color.colorPrimaryDark)); 199 | canvas.drawLine(0, height / 2, ruleWidth, height / 2, paint); 200 | //画圆角矩形 201 | paint.setStyle(Paint.Style.FILL); 202 | RectF r = new RectF(); 203 | r.left = ruleWidth + rectPadding; 204 | r.top = height / 2 - rectHeight / 2; 205 | r.right = width; 206 | r.bottom = height / 2 + rectHeight / 2; 207 | canvas.drawRoundRect(r, 10, 10, paint); 208 | //画小三角形指针 209 | Path path = new Path(); 210 | path.moveTo(ruleWidth + rectPadding, height / 2 - scaleSpace); 211 | path.lineTo(ruleWidth + rectPadding - 8, height / 2); 212 | path.lineTo(ruleWidth + rectPadding, height / 2 + scaleSpace); 213 | path.close(); 214 | canvas.drawPath(path, paint); 215 | //绘制文字 216 | paint.setColor(getResources().getColor(R.color.black)); 217 | Rect rect1 = new Rect(); 218 | paint.getTextBounds(descri, 0, descri.length(), rect1); 219 | int w1 = rect1.width(); 220 | canvas.drawText(descri, width - (width - ruleWidth - 20) / 2 - w1 / 2, height / 2 - rectHeight / 2 - 10, paint); 221 | //绘制当前刻度值数字 222 | paint.setColor(getResources().getColor(R.color.white)); 223 | float v = (float) (Math.round(currentValue * 10)) / 10;//保留一位小数 224 | String value = String.valueOf(v) + unit; 225 | Rect rect2 = new Rect(); 226 | paint.getTextBounds(value, 0, value.length(), rect2); 227 | int w2 = rect2.width(); 228 | int h2 = rect2.height(); 229 | canvas.drawText(value, width - (width - ruleWidth - 20) / 2 - w2 / 2, height / 2 + h2 / 2, paint); 230 | } 231 | 232 | @Override 233 | public boolean onTouchEvent(MotionEvent event) { 234 | float y = event.getY(); 235 | switch (event.getAction()) { 236 | case MotionEvent.ACTION_DOWN: 237 | lastY = y; 238 | continueScroll = false; 239 | //初始化速度追踪 240 | if (velocityTracker == null) { 241 | velocityTracker = VelocityTracker.obtain(); 242 | } else { 243 | velocityTracker.clear(); 244 | } 245 | break; 246 | case MotionEvent.ACTION_MOVE: 247 | velocityTracker.addMovement(event); 248 | int offsetY = (int) (lastY - y); 249 | minY -= offsetY; 250 | midY -= offsetY; 251 | calculateCurrentScale(); 252 | invalidate(); 253 | lastY = y; 254 | break; 255 | case MotionEvent.ACTION_UP: 256 | confirmBorder(); 257 | //当前滑动速度 258 | velocityTracker.computeCurrentVelocity(1000); 259 | velocity = velocityTracker.getYVelocity(); 260 | float minVelocity = ViewConfiguration.get(context).getScaledMinimumFlingVelocity(); 261 | if (Math.abs(velocity) > minVelocity) { 262 | continueScroll = true; 263 | continueScroll(); 264 | } else { 265 | velocityTracker.recycle(); 266 | velocityTracker = null; 267 | } 268 | break; 269 | case MotionEvent.ACTION_CANCEL: 270 | velocityTracker.recycle(); 271 | velocityTracker = null; 272 | break; 273 | } 274 | return true; 275 | } 276 | 277 | //计算当前刻度 278 | private void calculateCurrentScale() { 279 | float offsetTotal = originMidY - midY; 280 | int offsetBig = (int) (offsetTotal / scaleSpaceUnit);//移动的大刻度数 281 | float offsetS = offsetTotal % scaleSpaceUnit; 282 | int offsetSmall = (new BigDecimal(offsetS / (scaleSpace + SCALE_WIDTH_SMALL)).setScale(0, BigDecimal.ROUND_HALF_UP)).intValue();//移动的小刻度数 四舍五入取整 283 | float offset = offsetBig + offsetSmall * 0.1f; 284 | if (originValue - offset > max) { 285 | currentValue = max; 286 | } else if (originValue - offset < min) { 287 | currentValue = min; 288 | } else { 289 | currentValue = originValue - offset; 290 | } 291 | mHandler.sendEmptyMessage(0); 292 | } 293 | 294 | //指针线超出范围时 重置回边界处 295 | private void confirmBorder() { 296 | if (midY < borderUp) { 297 | midY = borderUp; 298 | minY = borderDown + (borderUp - borderDown) / 2; 299 | postInvalidate(); 300 | } else if (midY > borderDown) { 301 | midY = borderDown; 302 | minY = borderDown - (borderUp - borderDown) / 2; 303 | postInvalidate(); 304 | } 305 | } 306 | 307 | //手指抬起后继续惯性滑动 308 | private void continueScroll() { 309 | new Thread(new Runnable() { 310 | @Override 311 | public void run() { 312 | float velocityAbs = 0;//速度绝对值 313 | if (velocity > 0 && continueScroll) { 314 | velocity -= 50; 315 | minY += velocity * velocity / a; 316 | midY += velocity * velocity / a; 317 | velocityAbs = velocity; 318 | } else if (velocity < 0 && continueScroll) { 319 | velocity += 50; 320 | minY -= velocity * velocity / a; 321 | midY -= velocity * velocity / a; 322 | velocityAbs = -velocity; 323 | } 324 | calculateCurrentScale(); 325 | confirmBorder(); 326 | postInvalidate(); 327 | if (continueScroll && velocityAbs > 0) { 328 | post(this); 329 | } else { 330 | continueScroll = false; 331 | } 332 | } 333 | }).start(); 334 | } 335 | } 336 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/button_round_corner.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 12 | 13 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 13 | 14 | 20 | 21 | 28 | 29 | 40 | 41 | 42 | 48 | 49 | 56 | 57 | 68 | 69 | 70 | 71 | 75 | 76 | 81 | -------------------------------------------------------------------------------- /app/src/main/res/mipmap-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GITbiubiubiu/ScaleView/196c9c837281bb3417b99cba55a8718f11132e9c/app/src/main/res/mipmap-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GITbiubiubiu/ScaleView/196c9c837281bb3417b99cba55a8718f11132e9c/app/src/main/res/mipmap-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GITbiubiubiu/ScaleView/196c9c837281bb3417b99cba55a8718f11132e9c/app/src/main/res/mipmap-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GITbiubiubiu/ScaleView/196c9c837281bb3417b99cba55a8718f11132e9c/app/src/main/res/mipmap-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GITbiubiubiu/ScaleView/196c9c837281bb3417b99cba55a8718f11132e9c/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/values-w820dp/dimens.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 64dp 6 | 7 | -------------------------------------------------------------------------------- /app/src/main/res/values/colors.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | #3F51B5 4 | #303F9F 5 | #FF4081 6 | #00C7BA 7 | #000000 8 | #FFCCCCCC 9 | #FFFFFFFF 10 | 11 | -------------------------------------------------------------------------------- /app/src/main/res/values/dimens.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 16dp 4 | 16dp 5 | 6 | -------------------------------------------------------------------------------- /app/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | ScaleViewTest 3 | 4 | -------------------------------------------------------------------------------- /app/src/main/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /app/src/test/java/xyy/scaleview/ExampleUnitTest.java: -------------------------------------------------------------------------------- 1 | package xyy.scaleview; 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.2.2' 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 | -------------------------------------------------------------------------------- /build/generated/mockable-android-25.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GITbiubiubiu/ScaleView/196c9c837281bb3417b99cba55a8718f11132e9c/build/generated/mockable-android-25.jar -------------------------------------------------------------------------------- /build/intermediates/dex-cache/cache.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 11 | 12 | 13 | 20 | 21 | 22 | 29 | 30 | 31 | 38 | 39 | 40 | 47 | 48 | 49 | 56 | 57 | 58 | 65 | 66 | 67 | 74 | 75 | 76 | 83 | 84 | 85 | 92 | 93 | 94 | 101 | 102 | 103 | 110 | 111 | 112 | 119 | 120 | 121 | 128 | 129 | 130 | 137 | 138 | 139 | 140 | 141 | -------------------------------------------------------------------------------- /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/GITbiubiubiu/ScaleView/196c9c837281bb3417b99cba55a8718f11132e9c/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Mon Dec 28 10:00:20 PST 2015 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.14.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 | # 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 | -------------------------------------------------------------------------------- /local.properties: -------------------------------------------------------------------------------- 1 | ## This file is automatically generated by Android Studio. 2 | # Do not modify this file -- YOUR CHANGES WILL BE ERASED! 3 | # 4 | # This file must *NOT* be checked into Version Control Systems, 5 | # as it contains information specific to your local configuration. 6 | # 7 | # Location of the SDK. This is only used by Gradle. 8 | # For customization when using a Version Control System, please read the 9 | # header note. 10 | #Tue Feb 27 15:22:06 CST 2018 11 | sdk.dir=/home/bongmi/Android/Sdk 12 | -------------------------------------------------------------------------------- /screenshot/HorizontalScaleView.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GITbiubiubiu/ScaleView/196c9c837281bb3417b99cba55a8718f11132e9c/screenshot/HorizontalScaleView.png -------------------------------------------------------------------------------- /screenshot/VerticalScaleView.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GITbiubiubiu/ScaleView/196c9c837281bb3417b99cba55a8718f11132e9c/screenshot/VerticalScaleView.png -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | include ':app' 2 | --------------------------------------------------------------------------------