Skip to content

Commit

Permalink
Merge pull request #6 from lhoyong/dev
Browse files Browse the repository at this point in the history
Add: thumb click type
  • Loading branch information
lhoyong authored Apr 8, 2018
2 parents 94a025c + a0ff25b commit 8d76ae2
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,13 @@ package com.github.lhoyong.transparencyseekbar

import android.os.Bundle
import android.support.v7.app.AppCompatActivity
import kotlinx.android.synthetic.main.activity_main.*

class MainActivity : AppCompatActivity() {



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

var p = 120

tran.progress = p
tran.maxProgress = 240
}

override fun onStop() {
Expand Down
36 changes: 34 additions & 2 deletions app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,44 @@
tools:context="com.github.lhoyong.transparencyseekbar.MainActivity">


<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="50dp"
android:gravity="center"
android:text="Default Style"
android:textColor="#000000"
android:textSize="20sp" />

<com.github.lhoyong.transparencyseekbar.TransParencySeekBar
android:id="@+id/defStyle"
android:layout_width="match_parent"
android:layout_height="60dp"
android:layout_marginTop="10dp"
app:backgroundColor="#44000000"
app:maxProgress="300"
app:progress="150"
app:progressColor="#66000000"
app:thumbClickable="false" />

<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="50dp"
android:gravity="center"
android:text="Clickable Style"
android:textColor="#000000"
android:textSize="20sp" />

<com.github.lhoyong.transparencyseekbar.TransParencySeekBar
android:id="@+id/tran"
android:id="@+id/clickableStyle"
android:layout_width="match_parent"
android:layout_height="60dp"
android:layout_marginTop="10dp"
app:backgroundColor="#44000000"
app:progressColor="#66000000" />
app:maxProgress="300"
app:progress="150"
app:progressColor="#66000000"
app:thumbClickable="true" />

</LinearLayout>
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import android.graphics.Canvas
import android.graphics.Paint
import android.graphics.drawable.Drawable
import android.util.AttributeSet
import android.util.Log
import android.view.MotionEvent
import android.view.View

Expand All @@ -20,7 +19,9 @@ class TransParencySeekBar @JvmOverloads constructor(
// attr
private val a = attrs.let { context.obtainStyledAttributes(attrs, R.styleable.TransParencySeekBar, defStyleAttr, defStyleAttr) }

// thumb & touch X Position
private var thumbX: Float = 0F
private var touchX: Float = 0F

val thumb: Drawable = a.getDrawable(R.styleable.TransParencySeekBar_thumb)
?: resources.getDrawable(R.drawable.thumb)
Expand All @@ -33,14 +34,13 @@ class TransParencySeekBar @JvmOverloads constructor(

var progress: Int = a.getInteger(R.styleable.TransParencySeekBar_progress, 0)

// Use thumb
/* true: use Thumb */
var mEnabled: Boolean = a.getBoolean(R.styleable.TransParencySeekBar_enable, true)


/* test value */
var touchX: Float = 0F

/* ---- test value --- */
/*thumb Click
* true : MotionEvent Pressed thumb Visible
* false : thumb Always Visible */
var thumbClickable: Boolean = a.getBoolean(R.styleable.TransParencySeekBar_thumbClickable, false)

init {
a?.recycle()
Expand Down Expand Up @@ -76,7 +76,10 @@ class TransParencySeekBar @JvmOverloads constructor(

drawBackground(canvas)
drawProgress(canvas)
if (mEnabled) drawThumb(canvas)
if (mEnabled) {
if(!thumbClickable) drawThumb(canvas)
else if(thumbClickable&& isPressed) drawThumb(canvas)
}
}

override fun drawableStateChanged() {
Expand Down Expand Up @@ -137,4 +140,5 @@ class TransParencySeekBar @JvmOverloads constructor(

invalidate()
}

}
1 change: 1 addition & 0 deletions lib/src/main/res/values/attrs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@
<attr name="maxProgress" format="integer"/>
<attr name="thumb" format="reference"/>
<attr name="progress" format="integer"/>
<attr name="thumbClickable" format="boolean"/>
</declare-styleable>
</resources>

0 comments on commit 8d76ae2

Please sign in to comment.