Skip to content

Commit

Permalink
refresh code
Browse files Browse the repository at this point in the history
  • Loading branch information
fairytale2016 committed Sep 29, 2019
1 parent cece116 commit 1f1c17b
Show file tree
Hide file tree
Showing 15 changed files with 21 additions and 151 deletions.
6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 3 additions & 6 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,8 @@ android {
applicationId "tech.nicesky.balloonpicker"
minSdkVersion 21
targetSdkVersion 29
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
versionCode 2
versionName "1.0.1"
}
buildTypes {
release {
Expand All @@ -27,11 +26,9 @@ dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation"org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'androidx.core:core-ktx:1.0.2'
implementation 'androidx.core:core-ktx:1.1.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test:runner:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1'

implementation project(':balloonpicker')
}
Binary file modified app/release/app-release.apk
Binary file not shown.
1 change: 1 addition & 0 deletions app/release/output.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[{"outputType":{"type":"APK"},"apkData":{"type":"MAIN","splits":[],"versionCode":2,"versionName":"1.0.1","enabled":true,"outputFile":"app-release.apk","fullName":"release","baseName":"release"},"path":"app-release.apk","properties":{}}]
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,14 @@ import android.os.Handler
import android.util.Log
import androidx.core.graphics.toColorInt
import kotlinx.android.synthetic.main.activity_main.*
import tech.nicesky.balloonpicker.BalloonPickerListener

class MainActivity : AppCompatActivity() {

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)

balloon_picker.layerValues(10, 50, 5)
balloon_picker.setColorFoThumb("#FFFFFF".toColorInt(), "#512DA8".toColorInt())
balloon_picker.setColorForLayer("#512DA8".toColorInt(), "#BDBDBD".toColorInt())
Expand All @@ -20,7 +22,7 @@ class MainActivity : AppCompatActivity() {
balloon_picker.colorOfDesc = "#000000".toColorInt()
balloon_picker.colorOfValue = "#000000".toColorInt()
balloon_picker.desc = "Quantity"
balloon_picker.valueListener = object : BalloonPickerListener{
balloon_picker.valueListener = object : BalloonPickerListener {
override fun changed(value: Long) {
Log.w("MainActivity","value: $value")
}
Expand All @@ -29,6 +31,6 @@ class MainActivity : AppCompatActivity() {
Handler().postDelayed({
balloon_picker.defaultValue(30)
},3000)
val valueSelected = balloon_picker.getValue()
//val valueSelected = balloon_picker.getValue()
}
}
10 changes: 1 addition & 9 deletions app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,10 @@
android:layout_height="match_parent"
tools:context=".MainActivity">

<androidx.appcompat.widget.AppCompatImageView
android:id="@+id/btn_back"
android:layout_width="wrap_content"
android:src="@drawable/ic_keyboard_arrow_left_black_24dp"
android:layout_margin="15dp"
android:layout_height="50dp"/>

<androidx.appcompat.widget.AppCompatTextView
android:layout_below="@+id/btn_back"
android:id="@+id/txt_value"
android:layout_width="wrap_content"
android:layout_marginTop="20sp"
android:layout_marginTop="80sp"
android:layout_marginStart="30dp"
android:layout_marginEnd="30dp"
android:layout_height="wrap_content"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class BalloonAnimSet{
val scale = if (show) loadAnimation(context, R.anim.balloon_scale_enter) else loadAnimation(context, R.anim.balloon_scale_exit)

val alpha = if (show) AlphaAnimation(0F,1F) else AlphaAnimation(0.8F,0F)

alpha.duration = 200
animSet.addAnimation(alpha)
animSet.addAnimation(scale)
animSet.addAnimation(trans)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package tech.nicesky.balloonpickerdemo
package tech.nicesky.balloonpicker

interface BalloonPickerListener {
fun changed(value : Long)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import android.view.animation.Animation.AnimationListener
import androidx.core.animation.doOnEnd
import androidx.core.graphics.toColorInt
import androidx.core.text.TextUtilsCompat
import tech.nicesky.balloonpickerdemo.BalloonPickerListener
import tech.nicesky.balloonpicker.BalloonPickerListener
import kotlin.math.*
import android.graphics.Typeface
import android.icu.lang.UCharacter.GraphemeClusterBreak.T
Expand Down Expand Up @@ -144,11 +144,6 @@ class BalloonPickerView : ViewGroup, TrackLayerListener, ValueAnimator.AnimatorU
}

private fun initAnimation(anim: ValueAnimator){
// if (balloonAnim != null){
// if(balloonAnim.isRunning)
// balloonAnim.cancel()
// balloonAnim = null
// }
balloonAnim = anim
balloonAnim.interpolator = LinearInterpolator()
balloonAnim.repeatCount = 0
Expand All @@ -162,8 +157,6 @@ class BalloonPickerView : ViewGroup, TrackLayerListener, ValueAnimator.AnimatorU

private fun moveBalloon() {
val b = pointThumb.x - centerOfBalloon.x
// if (b == 0F && balloonAnim != null && balloonAnim.isRunning)
// balloonAnim.cancel()
moveBalloonWithAnim()
}

Expand All @@ -187,7 +180,6 @@ class BalloonPickerView : ViewGroup, TrackLayerListener, ValueAnimator.AnimatorU
val b = pointThumb.x - centerOfBalloon.x
val angleRoTan = -atan(b/distanceVerticalBetweenBalloonAndTrackLayer) / PI * 180F
balloon?.rotation = angleRoTan.toFloat()

}

override fun onMeasure(widthMeasureSpec: Int, heightMeasureSpec: Int) {
Expand Down Expand Up @@ -246,18 +238,6 @@ class BalloonPickerView : ViewGroup, TrackLayerListener, ValueAnimator.AnimatorU

override fun layerTouchedMoving(value: Long, pointAtLayer: PointF) {
pointThumb.set(pointAtLayer.x, height.toFloat() - trackLayer?.getPadding()!!)
val b = pointThumb.x.toInt() - centerOfBalloon.x.toInt()
// if (abs(b) > distanceVerticalBetweenBalloonAndTrackLayer.toInt()){
// initAnimation(ValueAnimator.ofInt(centerOfBalloon.x.toInt(), pointThumb.x.toInt()))
// val valueAtBalloon =trackLayer?.minValue()!! + (trackLayer?.maxValue()!! - trackLayer?.minValue()!!) * centerOfBalloon.x/measuredWidth
// val disScaleHeight =maxScale * balloonHeightDefault * (valueAtBalloon - trackLayer?.minValue()!!) / (trackLayer?.maxValue()!! - trackLayer?.minValue()!!)
// val disScaleWidth = maxScale * balloonWidthDefault/2 * (valueAtBalloon - trackLayer?.minValue()!!) / (trackLayer?.maxValue()!! - trackLayer?.minValue()!!)
// val xOfBalloon = (centerOfBalloon.x - balloonWidthDefault / 2 - disScaleWidth.toInt() + if (b > 0) b-distanceVerticalBetweenBalloonAndTrackLayer else b + distanceVerticalBetweenBalloonAndTrackLayer).toInt()
//
// balloon?.layout( xOfBalloon , balloonDefaultY.toInt() - disScaleHeight.toInt(), xOfBalloon + balloonWidthDefault.toInt() + disScaleWidth.toInt() * 2, (balloonDefaultY + balloonHeightDefault).toInt())
// centerOfBalloon.set(xOfBalloon + disScaleWidth + balloonWidthDefault / 2F, balloonDefaultY + balloonHeightDefault/2 - disScaleHeight/2 )
// rotateBalloon()
// }
moveBalloon()
balloon?.valueOfBalloon = value
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,5 +122,4 @@ class BalloonView : View {
drawable?.draw(canvas)
return bitmap
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -24,25 +24,18 @@ class TrackLayerView : View {
private var paintOfTrackLayerUnSelected= Paint()
private var paintOfThumb = Paint()
private var paintOfThumbStroke = Paint()

/**当前位置*/
private var pointOfThumb = PointF(-1F,-1F)
/**出师位置*/
private var pointOfThumbDefault = PointF(-1F, -1F)
private var pointOfThumbTemp = PointF(0F,0F)

private var pointOfTouchDown= PointF(0F,0F)

private var thumbOuterCircleRadiusMax : Float = DpUtil.dp2px(25.toFloat())
private var thumbOuterCircleRadiusDefault : Float = DpUtil.dp2px(15.toFloat())
private var thumbOuterCircleRadius : Float = thumbOuterCircleRadiusDefault
private var thumbOuterCircleRadiusTemp : Float = thumbOuterCircleRadius

private var thumbInnerCircleRadiusDefault : Float = DpUtil.dp2px(7.5.toFloat())
private var thumbInnerCircleRadiusMax : Float = thumbOuterCircleRadiusMax - DpUtil.dp2px(0.8F)
private var thumbInnerCircleRadius : Float = thumbInnerCircleRadiusDefault
private var thumbInnerCircleRadiusTemp : Float = thumbInnerCircleRadius

private var yOfTrackLayer : Float = 0F
private var padding : Float = DpUtil.dp2px(5F)
private var widthOfView : Float = DpUtil.dp2px(10F)
Expand All @@ -51,18 +44,18 @@ class TrackLayerView : View {
private var xOfTrackLayerEnd = 0F
private var xOfValue = 0F
private var yOfValue = 0F

private var anim : ValueAnimator = ValueAnimator.ofInt(0,1)

private val duration = 200L
private val duration = 300L
internal var increase : Boolean = false
private var touchWithinRange : Boolean = false

internal var colorOFThumb = "#FFFFFF".toColorInt()
set(value) {
field = value
paintOfThumb.color = colorOFThumb
postInvalidate()
}

internal var colorOFThumbStroke = "#512DA8".toColorInt()
set(value) {
field = value
Expand Down Expand Up @@ -159,17 +152,14 @@ class TrackLayerView : View {

override fun onMeasure(widthMeasureSpec: Int, heightMeasureSpec: Int) {
super.onMeasure(widthMeasureSpec, heightMeasureSpec)
Log.w(TAG, "onMeasure")
}

override fun onSizeChanged(w: Int, h: Int, oldw: Int, oldh: Int) {
super.onSizeChanged(w, h, oldw, oldh)
// Log.w(TAG, "onSizeChanged")
}

override fun onLayout(changed: Boolean, left: Int, top: Int, right: Int, bottom: Int) {
super.onLayout(changed, left, top, right, bottom)
Log.w(TAG, "onLayout")
widthOfView = width.toFloat()
heightOfView = height.toFloat()

Expand All @@ -181,7 +171,6 @@ class TrackLayerView : View {
pointOfThumbDefault.set(if (xNew < (xOfTrackLayerStart)) xOfTrackLayerStart else xNew, yOfTrackLayer)
pointOfThumb = pointOfThumbDefault
pointOfThumbTemp = pointOfThumb

}

override fun onFinishInflate() {
Expand All @@ -190,7 +179,6 @@ class TrackLayerView : View {

override fun onDraw(canvas: Canvas?) {
super.onDraw(canvas)

canvas?.drawLine(xOfTrackLayerStart, yOfTrackLayer ,pointOfThumb.x, yOfTrackLayer, paintOfTrackLayerSelected)
canvas?.drawLine(pointOfThumb.x, yOfTrackLayer ,xOfTrackLayerEnd, yOfTrackLayer, paintOfTrackLayerUnSelected)
canvas?.drawCircle(pointOfThumb.x, pointOfThumb.y, thumbOuterCircleRadius, paintOfThumbStroke)
Expand All @@ -203,7 +191,6 @@ class TrackLayerView : View {
if (event.x < pointOfThumb.x + DpUtil.dp2px(50F) && event.x > pointOfThumb.x - DpUtil.dp2px(50F)
&& event.y < pointOfThumb.y + DpUtil.dp2px(50F) && event.y > pointOfThumb.y - DpUtil.dp2px(50F)
){
// Log.w(TAG, "in side")
//动画变大内圆paintOfThumb 的 radius半径
touchWithinRange = true
pointOfTouchDown = PointF(event.x, event.y)
Expand All @@ -216,9 +203,6 @@ class TrackLayerView : View {
true
}
MotionEvent.ACTION_UP ->{
//Log.d("onTouchEvent", "UP")
//动画变大内圆paintOfThumb 的 radius半径

xOfValue = xOfTrackLayerEnd - selectedValue.toString().length.toFloat() * paintOfValueSelected.textSize
yOfValue = yOfTrackLayer - thumbOuterCircleRadiusMax - padding
scalingInnerCircleRadius(false)
Expand All @@ -228,8 +212,6 @@ class TrackLayerView : View {
true
}
MotionEvent.ACTION_MOVE->{
//Log.d("onTouchEvent", "MOVE")

//TODO Refining logic
if (touchWithinRange){
val x = pointOfThumbTemp.x + event.x - pointOfTouchDown.x
Expand All @@ -255,7 +237,6 @@ class TrackLayerView : View {
this.increase -> (duration* (thumbInnerCircleRadiusMax - thumbInnerCircleRadiusTemp)/(thumbInnerCircleRadiusMax - thumbInnerCircleRadiusDefault)).toLong()
else -> (duration* (thumbInnerCircleRadiusTemp - thumbInnerCircleRadiusDefault)/(thumbInnerCircleRadiusMax - thumbInnerCircleRadiusDefault)).toLong()
}
//Log.w(TAG, "Last time is $remainingTime")
anim.duration = if (remainingTime < 0) 5 else remainingTime
}
anim.duration = duration
Expand All @@ -276,7 +257,6 @@ class TrackLayerView : View {
this.minValue = minValue
this.maxValue = maxValue
this.selectedValue = defaultValue

refreshView()
}

Expand Down Expand Up @@ -309,5 +289,4 @@ class TrackLayerView : View {
fun selectedValue(): Long{
return selectedValue
}

}
79 changes: 0 additions & 79 deletions balloonpicker/src/main/java/tech/nicesky/balloonpicker/sss.java

This file was deleted.

This file was deleted.

1 change: 0 additions & 1 deletion balloonpicker/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
<resources>
<string name="app_name">BalloonPicker</string>
</resources>
Binary file added blogpost/key/release.jks
Binary file not shown.

0 comments on commit 1f1c17b

Please sign in to comment.