Skip to content

Commit

Permalink
add custom position programatically + saveState
Browse files Browse the repository at this point in the history
  • Loading branch information
abd3lraouf committed Jan 31, 2020
1 parent 6ba84b5 commit 49a7a76
Show file tree
Hide file tree
Showing 60 changed files with 34 additions and 6 deletions.
Empty file modified .gitignore
100644 → 100755
Empty file.
Empty file modified .idea/.name
100644 → 100755
Empty file.
Empty file modified .idea/codeStyles/Project.xml
100644 → 100755
Empty file.
Empty file modified .idea/codeStyles/codeStyleConfig.xml
100644 → 100755
Empty file.
Empty file modified .idea/gradle.xml
100644 → 100755
Empty file.
Empty file modified .idea/misc.xml
100644 → 100755
Empty file.
Empty file modified .idea/runConfigurations.xml
100644 → 100755
Empty file.
Empty file modified .idea/vcs.xml
100644 → 100755
Empty file.
Empty file modified README.md
100644 → 100755
Empty file.
Empty file modified app/.gitignore
100644 → 100755
Empty file.
Empty file modified app/build.gradle
100644 → 100755
Empty file.
Empty file modified app/proguard-rules.pro
100644 → 100755
Empty file.
Empty file.
Empty file modified app/src/main/AndroidManifest.xml
100644 → 100755
Empty file.
5 changes: 5 additions & 0 deletions app/src/main/java/io/abdelraoufsabri/learn/androidruler/MainActivity.kt
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,13 @@ class MainActivity : AppCompatActivity() {
value_text.text = myScrollingValuePicker.getReading(it).toString()
}, 250)




myScrollingValuePicker2.setOnScrollChangedListener({
value_text2.text = myScrollingValuePicker2.getReading(it).toString()
}, 250)

myScrollingValuePicker2.moveTo(150F)
}
}
Empty file modified app/src/main/res/drawable-v24/ic_launcher_foreground.xml
100644 → 100755
Empty file.
Empty file modified app/src/main/res/drawable/ic_launcher_background.xml
100644 → 100755
Empty file.
4 changes: 2 additions & 2 deletions app/src/main/res/layout/activity_main.xml
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@
android:layout_height="wrap_content"
app:rulerMinValue="15"
app:rulerMaxValue="108"
app:rulerSystem="imperial"
app:rulerDefaultPosition="107.75"
app:rulerSystem="imperial"
app:rulerPointerColor="#FF0000FF"
app:rulerNormalUnitBarColor="#FF0000FF"
app:rulerMiddleUnitBarColor="#00BCD4"
Expand Down Expand Up @@ -51,8 +51,8 @@
android:layout_height="wrap_content"
app:rulerMinValue="30"
app:rulerMaxValue="280"
app:rulerSystem="metric"
app:rulerDefaultPosition="279"
app:rulerSystem="metric"
app:rulerPointerColor="#FF0000FF"
app:rulerNormalUnitBarColor="#FF0000FF"
app:rulerMiddleUnitBarColor="#00BCD4"
Expand Down
Empty file modified app/src/main/res/layout/content_main.xml
100644 → 100755
Empty file.
Empty file modified app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml
100644 → 100755
Empty file.
Empty file modified app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml
100644 → 100755
Empty file.
Empty file modified app/src/main/res/mipmap-hdpi/ic_launcher.png
100644 → 100755
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Empty file modified app/src/main/res/mipmap-hdpi/ic_launcher_round.png
100644 → 100755
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Empty file modified app/src/main/res/mipmap-mdpi/ic_launcher.png
100644 → 100755
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Empty file modified app/src/main/res/mipmap-mdpi/ic_launcher_round.png
100644 → 100755
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Empty file modified app/src/main/res/mipmap-xhdpi/ic_launcher.png
100644 → 100755
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Empty file modified app/src/main/res/mipmap-xhdpi/ic_launcher_round.png
100644 → 100755
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Empty file modified app/src/main/res/mipmap-xxhdpi/ic_launcher.png
100644 → 100755
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Empty file modified app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png
100644 → 100755
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Empty file modified app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
100644 → 100755
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Empty file modified app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png
100644 → 100755
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Empty file modified app/src/main/res/values/colors.xml
100644 → 100755
Empty file.
Empty file modified app/src/main/res/values/dimens.xml
100644 → 100755
Empty file.
Empty file modified app/src/main/res/values/strings.xml
100644 → 100755
Empty file.
Empty file modified app/src/main/res/values/styles.xml
100644 → 100755
Empty file.
Empty file.
Empty file modified build.gradle
100644 → 100755
Empty file.
Empty file modified gradle.properties
100644 → 100755
Empty file.
Empty file modified gradle/wrapper/gradle-wrapper.jar
100644 → 100755
Empty file.
Empty file modified gradle/wrapper/gradle-wrapper.properties
100644 → 100755
Empty file.
Empty file modified gradlew.bat
100644 → 100755
Empty file.
Empty file modified ruler/.gitignore
100644 → 100755
Empty file.
5 changes: 2 additions & 3 deletions ruler/build.gradle
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ android {
defaultConfig {
minSdkVersion 16
targetSdkVersion 29
versionCode 7
versionName "1.3.0"
versionCode 8
versionName "1.3.1"

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
consumerProguardFiles 'consumer-rules.pro'
Expand All @@ -38,5 +38,4 @@ dependencies {
implementation 'io.reactivex.rxjava2:rxandroid:2.1.1'
implementation 'io.reactivex.rxjava2:rxjava:2.2.16'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'

}
Empty file modified ruler/consumer-rules.pro
100644 → 100755
Empty file.
Empty file modified ruler/proguard-rules.pro
100644 → 100755
Empty file.
Empty file modified ruler/src/main/AndroidManifest.xml
100644 → 100755
Empty file.
Empty file.
26 changes: 25 additions & 1 deletion ruler/src/main/java/io/abdelraoufsabri/learn/ruler/widget/FancyRuler.kt
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import android.animation.ObjectAnimator
import android.content.Context
import android.content.res.TypedArray
import android.graphics.drawable.GradientDrawable
import android.os.Bundle
import android.os.Parcelable
import android.util.AttributeSet
import android.util.Log
import android.view.Gravity
Expand All @@ -24,6 +26,7 @@ import kotlin.math.roundToInt


class FancyRuler : LinearLayout {
var value: Float = 0F

private var multiplier = 0

Expand Down Expand Up @@ -238,7 +241,7 @@ class FancyRuler : LinearLayout {
item.background = gradientDrawable
}

private fun customPosition() = ((defaultPosition - rulerMinValue) * step * multiplier) + step
private fun customPosition(newPosition: Float = defaultPosition) = ((newPosition - rulerMinValue) * step * multiplier) + step

private fun startPosition() = step.toFloat()

Expand Down Expand Up @@ -338,13 +341,34 @@ class FancyRuler : LinearLayout {
overScrolled(value) -> scrollTo(endPosition())
else -> scrollTo(correctedMark.toFloat())
}
this.value = value
return value
}

override fun onSaveInstanceState(): Parcelable? {
val bundle = Bundle()
bundle.putParcelable("SUPER_STATE", super.onSaveInstanceState())
bundle.putFloat("value", value)
return bundle
}

override fun onRestoreInstanceState(state: Parcelable?) {
if (state is Bundle) {
value = state.getFloat("value")
moveTo(value)
return super.onRestoreInstanceState(state.getParcelable<Parcelable>("SUPER_STATE"))
}
return super.onRestoreInstanceState(state)
}

private fun approachesNextStep(xValue: Int) = xValue % step > (step * .5)

private fun Float.dpAsPixels(): Int {
val scale = context.resources.displayMetrics.density
return (this * scale).toInt()
}

fun moveTo(newPosition: Float) {
scrollTo(customPosition(newPosition))
}
}
Empty file modified ruler/src/main/res/drawable/main_unit_bar.xml
100644 → 100755
Empty file.
Empty file modified ruler/src/main/res/drawable/middle_unit_bar.xml
100644 → 100755
Empty file.
Empty file modified ruler/src/main/res/drawable/normal_unit_bar.xml
100644 → 100755
Empty file.
Empty file modified ruler/src/main/res/drawable/pointer_line.xml
100644 → 100755
Empty file.
Empty file modified ruler/src/main/res/drawable/quarter_unit_bar.xml
100644 → 100755
Empty file.
Empty file modified ruler/src/main/res/drawable/three_quarters_unit_bar.xml
100644 → 100755
Empty file.
Empty file modified ruler/src/main/res/layout/units.xml
100644 → 100755
Empty file.
Empty file modified ruler/src/main/res/values/attrs.xml
100644 → 100755
Empty file.
Empty file modified ruler/src/main/res/values/colors.xml
100644 → 100755
Empty file.
Empty file modified ruler/src/main/res/values/dimens.xml
100644 → 100755
Empty file.
Empty file modified ruler/src/main/res/values/strings.xml
100644 → 100755
Empty file.
Empty file modified settings.gradle
100644 → 100755
Empty file.

0 comments on commit 49a7a76

Please sign in to comment.