Skip to content

Commit

Permalink
Initial Commit
Browse files Browse the repository at this point in the history
  • Loading branch information
salmaanahmed committed Sep 3, 2018
1 parent 67dde45 commit 53d47b3
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 25 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.

Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ import android.graphics.Color
import android.os.Bundle
import android.support.v7.app.AppCompatActivity
import kotlinx.android.synthetic.main.activity_main.*
import sasliderdemo.salmaan.ahmsal.com.saslider.CustomSlider
import sasliderdemo.salmaan.ahmsal.com.R
import sasliderdemo.salmaan.ahmsal.com.saslider.SASlider

class MainActivity : AppCompatActivity() {

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


val slider = CustomSlider(this@MainActivity)
val slider = SASlider(this@MainActivity)
slider.sliderColor = Color.BLUE
slider.criticalColor = Color.BLACK
slider.min = 0.0
Expand Down
4 changes: 2 additions & 2 deletions app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:color/white"
tools:context="sasliderdemo.salmaan.ahmsal.com.sasliderdemo.salmaan.ahmsal.com.MainActivity">
tools:context="sasliderdemo.salmaan.ahmsal.com.MainActivity">

<LinearLayout
android:id="@+id/linearLayout"
Expand All @@ -20,7 +20,7 @@
android:text="Slider below is added via xml"
android:textSize="20sp" />

<sasliderdemo.salmaan.ahmsal.com.saslider.CustomSlider
<sasliderdemo.salmaan.ahmsal.com.saslider.SASlider
android:layout_width="match_parent"
android:layout_height="100dp"
android:layout_marginBottom="50dp"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,15 @@ import android.widget.LinearLayout
import android.widget.TextView
import com.wisemani.customview.CircleView
import com.wisemani.patienttouch.customview.TriangleShapeView
import kotlinx.android.synthetic.main.custom_slider.view.*
import kotlinx.android.synthetic.main.sa_slider.view.*
import java.math.RoundingMode
import java.text.DecimalFormat
import kotlin.math.roundToInt

/**
* Created by salmaanahmed on 20/07/2018.
*/
class CustomSlider @JvmOverloads constructor(
class SASlider @JvmOverloads constructor(
context: Context, attrs: AttributeSet? = null, defStyleAttr: Int = 0
) : LinearLayout(context, attrs, defStyleAttr), ViewTreeObserver.OnScrollChangedListener {

Expand Down Expand Up @@ -95,25 +95,25 @@ class CustomSlider @JvmOverloads constructor(
}

init {
LayoutInflater.from(context).inflate(R.layout.custom_slider, this, true)

val typedArray = context.obtainStyledAttributes(attrs, R.styleable.CustomSlider, 0, 0)
sliderColor = typedArray.getColor(R.styleable.CustomSlider_sliderColor, Color.BLUE) // Set value from XML attributes or set default slider color
circleColor = typedArray.getColor(R.styleable.CustomSlider_circleColor, Color.GRAY) // Set value from XML attributes or set default circle/text color
criticalColor = typedArray.getColor(R.styleable.CustomSlider_criticalColor, Color.RED) // Set value from XML attributes or set default circle/text color
editTextColor = typedArray.getColor(R.styleable.CustomSlider_editTextBorderColor, Color.LTGRAY) // Set value from XML attributes or set default edit text color
circleWidth = typedArray.getDimensionPixelSize(R.styleable.CustomSlider_circleSize, resources.getDimension(R.dimen.circleSize).toInt()) // Set value from XML attributes or set default size of circle
LayoutInflater.from(context).inflate(R.layout.sa_slider, this, true)

val typedArray = context.obtainStyledAttributes(attrs, R.styleable.SASlider, 0, 0)
sliderColor = typedArray.getColor(R.styleable.SASlider_sliderColor, Color.BLUE) // Set value from XML attributes or set default slider color
circleColor = typedArray.getColor(R.styleable.SASlider_circleColor, Color.GRAY) // Set value from XML attributes or set default circle/text color
criticalColor = typedArray.getColor(R.styleable.SASlider_criticalColor, Color.RED) // Set value from XML attributes or set default circle/text color
editTextColor = typedArray.getColor(R.styleable.SASlider_editTextBorderColor, Color.LTGRAY) // Set value from XML attributes or set default edit text color
circleWidth = typedArray.getDimensionPixelSize(R.styleable.SASlider_circleSize, resources.getDimension(R.dimen.circleSize).toInt()) // Set value from XML attributes or set default size of circle
bigCircleWidth = circleWidth * 2 // Big circle is twice the size of small circle
thumbWidth = (bigCircleWidth * 3) // Thumb should be large enough to be seen
spaceSize = bigCircleWidth * 2 // Space is twice the size of big circle
textViewSize = (spaceSize * 5) + (bigCircleWidth * 5) // Text View is size of 5 circles and 5 spaces as text is displayed at every 5th circle
spaceBetweenCircles = bigCircleWidth + spaceSize // Space between center point is equal to two half big circles i.e. one big circle and size of space
isDecimal = typedArray.getBoolean(R.styleable.CustomSlider_isDecimal, false) // Set value from XML attributes or set default slider type
min = typedArray.getFloat(R.styleable.CustomSlider_minValue, 1.0f).toDouble().roundToOneDecimal() // Set value from XML attributes or set default min value
max = typedArray.getFloat(R.styleable.CustomSlider_maxValue, 10.0f).toDouble().roundToOneDecimal() // Set value from XML attributes or set default max value
upperThreshold = typedArray.getFloat(R.styleable.CustomSlider_upperThreshold, max.toFloat()).toDouble().roundToOneDecimal() // Set value from XML attributes or set default threshold value
lowerThreshold = typedArray.getFloat(R.styleable.CustomSlider_lowerThreshold, min.toFloat()).toDouble().roundToOneDecimal() // Set value from XML attributes or set default threshold value
default = typedArray.getFloat(R.styleable.CustomSlider_defaultValue, min.toFloat()).toDouble().roundToOneDecimal() // Set value from XML attributes or set default value
isDecimal = typedArray.getBoolean(R.styleable.SASlider_isDecimal, false) // Set value from XML attributes or set default slider type
min = typedArray.getFloat(R.styleable.SASlider_minValue, 1.0f).toDouble().roundToOneDecimal() // Set value from XML attributes or set default min value
max = typedArray.getFloat(R.styleable.SASlider_maxValue, 10.0f).toDouble().roundToOneDecimal() // Set value from XML attributes or set default max value
upperThreshold = typedArray.getFloat(R.styleable.SASlider_upperThreshold, max.toFloat()).toDouble().roundToOneDecimal() // Set value from XML attributes or set default threshold value
lowerThreshold = typedArray.getFloat(R.styleable.SASlider_lowerThreshold, min.toFloat()).toDouble().roundToOneDecimal() // Set value from XML attributes or set default threshold value
default = typedArray.getFloat(R.styleable.SASlider_defaultValue, min.toFloat()).toDouble().roundToOneDecimal() // Set value from XML attributes or set default value
}


Expand Down Expand Up @@ -257,7 +257,7 @@ class CustomSlider @JvmOverloads constructor(

frameEditText.setBackgroundColor(editTextColor)

var triangle = TriangleShapeView(context, editTextColor)
val triangle = TriangleShapeView(context, editTextColor)
trLayout.addView(triangle)
triangle.layoutParams.width = (bigCircleWidth * 1.25).toInt()
triangle.layoutParams.height = (bigCircleWidth * 1.25).toInt()
Expand Down Expand Up @@ -360,15 +360,15 @@ class CustomSlider @JvmOverloads constructor(
* Setup scroll listener
*/
private fun setScrollListener() {
scrollView.viewTreeObserver.addOnScrollChangedListener(this@CustomSlider)
scrollView.viewTreeObserver.addOnScrollChangedListener(this@SASlider)
}

/**
* Scroll changed listener
* Update edit text
*/
override fun onScrollChanged() {
var value = getNumberFromPixel(scrollView.scrollX)
val value = getNumberFromPixel(scrollView.scrollX)
if (isDecimal) editText.setTextProgrammatically((value).toString())
else editText.setTextProgrammatically((value).roundToInt().toString())
editText.setSelection(editText.text.count())
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion saslider/src/main/res/values/attrs.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<declare-styleable name="CustomSlider">
<declare-styleable name="SASlider">
<attr name="circleSize" format="dimension" />
<attr name="minValue" format="float" />
<attr name="maxValue" format="float" />
Expand Down

0 comments on commit 53d47b3

Please sign in to comment.