Skip to content

Commit 53d47b3

Browse files
committed
Initial Commit
1 parent 67dde45 commit 53d47b3

File tree

6 files changed

+30
-25
lines changed

6 files changed

+30
-25
lines changed

.idea/vcs.xml

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

app/src/main/java/sasliderdemo/salmaan/ahmsal/com/MainActivity.kt

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@ import android.graphics.Color
44
import android.os.Bundle
55
import android.support.v7.app.AppCompatActivity
66
import kotlinx.android.synthetic.main.activity_main.*
7-
import sasliderdemo.salmaan.ahmsal.com.saslider.CustomSlider
8-
import sasliderdemo.salmaan.ahmsal.com.R
7+
import sasliderdemo.salmaan.ahmsal.com.saslider.SASlider
98

109
class MainActivity : AppCompatActivity() {
1110

@@ -14,7 +13,7 @@ class MainActivity : AppCompatActivity() {
1413
setContentView(R.layout.activity_main)
1514

1615

17-
val slider = CustomSlider(this@MainActivity)
16+
val slider = SASlider(this@MainActivity)
1817
slider.sliderColor = Color.BLUE
1918
slider.criticalColor = Color.BLACK
2019
slider.min = 0.0

app/src/main/res/layout/activity_main.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
android:layout_width="match_parent"
66
android:layout_height="match_parent"
77
android:background="@android:color/white"
8-
tools:context="sasliderdemo.salmaan.ahmsal.com.sasliderdemo.salmaan.ahmsal.com.MainActivity">
8+
tools:context="sasliderdemo.salmaan.ahmsal.com.MainActivity">
99

1010
<LinearLayout
1111
android:id="@+id/linearLayout"
@@ -20,7 +20,7 @@
2020
android:text="Slider below is added via xml"
2121
android:textSize="20sp" />
2222

23-
<sasliderdemo.salmaan.ahmsal.com.saslider.CustomSlider
23+
<sasliderdemo.salmaan.ahmsal.com.saslider.SASlider
2424
android:layout_width="match_parent"
2525
android:layout_height="100dp"
2626
android:layout_marginBottom="50dp"

saslider/src/main/java/sasliderdemo/salmaan/ahmsal/com/saslider/CustomSlider.kt renamed to saslider/src/main/java/sasliderdemo/salmaan/ahmsal/com/saslider/SASlider.kt

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,15 @@ import android.widget.LinearLayout
2020
import android.widget.TextView
2121
import com.wisemani.customview.CircleView
2222
import com.wisemani.patienttouch.customview.TriangleShapeView
23-
import kotlinx.android.synthetic.main.custom_slider.view.*
23+
import kotlinx.android.synthetic.main.sa_slider.view.*
2424
import java.math.RoundingMode
2525
import java.text.DecimalFormat
2626
import kotlin.math.roundToInt
2727

2828
/**
2929
* Created by salmaanahmed on 20/07/2018.
3030
*/
31-
class CustomSlider @JvmOverloads constructor(
31+
class SASlider @JvmOverloads constructor(
3232
context: Context, attrs: AttributeSet? = null, defStyleAttr: Int = 0
3333
) : LinearLayout(context, attrs, defStyleAttr), ViewTreeObserver.OnScrollChangedListener {
3434

@@ -95,25 +95,25 @@ class CustomSlider @JvmOverloads constructor(
9595
}
9696

9797
init {
98-
LayoutInflater.from(context).inflate(R.layout.custom_slider, this, true)
99-
100-
val typedArray = context.obtainStyledAttributes(attrs, R.styleable.CustomSlider, 0, 0)
101-
sliderColor = typedArray.getColor(R.styleable.CustomSlider_sliderColor, Color.BLUE) // Set value from XML attributes or set default slider color
102-
circleColor = typedArray.getColor(R.styleable.CustomSlider_circleColor, Color.GRAY) // Set value from XML attributes or set default circle/text color
103-
criticalColor = typedArray.getColor(R.styleable.CustomSlider_criticalColor, Color.RED) // Set value from XML attributes or set default circle/text color
104-
editTextColor = typedArray.getColor(R.styleable.CustomSlider_editTextBorderColor, Color.LTGRAY) // Set value from XML attributes or set default edit text color
105-
circleWidth = typedArray.getDimensionPixelSize(R.styleable.CustomSlider_circleSize, resources.getDimension(R.dimen.circleSize).toInt()) // Set value from XML attributes or set default size of circle
98+
LayoutInflater.from(context).inflate(R.layout.sa_slider, this, true)
99+
100+
val typedArray = context.obtainStyledAttributes(attrs, R.styleable.SASlider, 0, 0)
101+
sliderColor = typedArray.getColor(R.styleable.SASlider_sliderColor, Color.BLUE) // Set value from XML attributes or set default slider color
102+
circleColor = typedArray.getColor(R.styleable.SASlider_circleColor, Color.GRAY) // Set value from XML attributes or set default circle/text color
103+
criticalColor = typedArray.getColor(R.styleable.SASlider_criticalColor, Color.RED) // Set value from XML attributes or set default circle/text color
104+
editTextColor = typedArray.getColor(R.styleable.SASlider_editTextBorderColor, Color.LTGRAY) // Set value from XML attributes or set default edit text color
105+
circleWidth = typedArray.getDimensionPixelSize(R.styleable.SASlider_circleSize, resources.getDimension(R.dimen.circleSize).toInt()) // Set value from XML attributes or set default size of circle
106106
bigCircleWidth = circleWidth * 2 // Big circle is twice the size of small circle
107107
thumbWidth = (bigCircleWidth * 3) // Thumb should be large enough to be seen
108108
spaceSize = bigCircleWidth * 2 // Space is twice the size of big circle
109109
textViewSize = (spaceSize * 5) + (bigCircleWidth * 5) // Text View is size of 5 circles and 5 spaces as text is displayed at every 5th circle
110110
spaceBetweenCircles = bigCircleWidth + spaceSize // Space between center point is equal to two half big circles i.e. one big circle and size of space
111-
isDecimal = typedArray.getBoolean(R.styleable.CustomSlider_isDecimal, false) // Set value from XML attributes or set default slider type
112-
min = typedArray.getFloat(R.styleable.CustomSlider_minValue, 1.0f).toDouble().roundToOneDecimal() // Set value from XML attributes or set default min value
113-
max = typedArray.getFloat(R.styleable.CustomSlider_maxValue, 10.0f).toDouble().roundToOneDecimal() // Set value from XML attributes or set default max value
114-
upperThreshold = typedArray.getFloat(R.styleable.CustomSlider_upperThreshold, max.toFloat()).toDouble().roundToOneDecimal() // Set value from XML attributes or set default threshold value
115-
lowerThreshold = typedArray.getFloat(R.styleable.CustomSlider_lowerThreshold, min.toFloat()).toDouble().roundToOneDecimal() // Set value from XML attributes or set default threshold value
116-
default = typedArray.getFloat(R.styleable.CustomSlider_defaultValue, min.toFloat()).toDouble().roundToOneDecimal() // Set value from XML attributes or set default value
111+
isDecimal = typedArray.getBoolean(R.styleable.SASlider_isDecimal, false) // Set value from XML attributes or set default slider type
112+
min = typedArray.getFloat(R.styleable.SASlider_minValue, 1.0f).toDouble().roundToOneDecimal() // Set value from XML attributes or set default min value
113+
max = typedArray.getFloat(R.styleable.SASlider_maxValue, 10.0f).toDouble().roundToOneDecimal() // Set value from XML attributes or set default max value
114+
upperThreshold = typedArray.getFloat(R.styleable.SASlider_upperThreshold, max.toFloat()).toDouble().roundToOneDecimal() // Set value from XML attributes or set default threshold value
115+
lowerThreshold = typedArray.getFloat(R.styleable.SASlider_lowerThreshold, min.toFloat()).toDouble().roundToOneDecimal() // Set value from XML attributes or set default threshold value
116+
default = typedArray.getFloat(R.styleable.SASlider_defaultValue, min.toFloat()).toDouble().roundToOneDecimal() // Set value from XML attributes or set default value
117117
}
118118

119119

@@ -257,7 +257,7 @@ class CustomSlider @JvmOverloads constructor(
257257

258258
frameEditText.setBackgroundColor(editTextColor)
259259

260-
var triangle = TriangleShapeView(context, editTextColor)
260+
val triangle = TriangleShapeView(context, editTextColor)
261261
trLayout.addView(triangle)
262262
triangle.layoutParams.width = (bigCircleWidth * 1.25).toInt()
263263
triangle.layoutParams.height = (bigCircleWidth * 1.25).toInt()
@@ -360,15 +360,15 @@ class CustomSlider @JvmOverloads constructor(
360360
* Setup scroll listener
361361
*/
362362
private fun setScrollListener() {
363-
scrollView.viewTreeObserver.addOnScrollChangedListener(this@CustomSlider)
363+
scrollView.viewTreeObserver.addOnScrollChangedListener(this@SASlider)
364364
}
365365

366366
/**
367367
* Scroll changed listener
368368
* Update edit text
369369
*/
370370
override fun onScrollChanged() {
371-
var value = getNumberFromPixel(scrollView.scrollX)
371+
val value = getNumberFromPixel(scrollView.scrollX)
372372
if (isDecimal) editText.setTextProgrammatically((value).toString())
373373
else editText.setTextProgrammatically((value).roundToInt().toString())
374374
editText.setSelection(editText.text.count())

saslider/src/main/res/values/attrs.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<resources>
3-
<declare-styleable name="CustomSlider">
3+
<declare-styleable name="SASlider">
44
<attr name="circleSize" format="dimension" />
55
<attr name="minValue" format="float" />
66
<attr name="maxValue" format="float" />

0 commit comments

Comments
 (0)