Ruler (Android)

Library for distance measurments.

License

License

GroupId

GroupId

io.mehow.ruler
ArtifactId

ArtifactId

android
Last Version

Last Version

0.5.3
Release Date

Release Date

Type

Type

aar
Description

Description

Ruler (Android)
Library for distance measurments.
Project URL

Project URL

https://github.com/MiSikora/Ruler
Source Code Management

Source Code Management

https://github.com/MiSikora/Ruler

Download android

How to add to project

<!-- https://jarcasting.com/artifacts/io.mehow.ruler/android/ -->
<dependency>
    <groupId>io.mehow.ruler</groupId>
    <artifactId>android</artifactId>
    <version>0.5.3</version>
    <type>aar</type>
</dependency>
// https://jarcasting.com/artifacts/io.mehow.ruler/android/
implementation 'io.mehow.ruler:android:0.5.3'
// https://jarcasting.com/artifacts/io.mehow.ruler/android/
implementation ("io.mehow.ruler:android:0.5.3")
'io.mehow.ruler:android:aar:0.5.3'
<dependency org="io.mehow.ruler" name="android" rev="0.5.3">
  <artifact name="android" type="aar" />
</dependency>
@Grapes(
@Grab(group='io.mehow.ruler', module='android', version='0.5.3')
)
libraryDependencies += "io.mehow.ruler" % "android" % "0.5.3"
[io.mehow.ruler/android "0.5.3"]

Dependencies

compile (1)

Group / Artifact Type Version
io.mehow.ruler : ruler jar 0.5.3

runtime (1)

Group / Artifact Type Version
org.jetbrains.kotlin : kotlin-stdlib-jdk7 jar 1.3.72

Project Modules

There are no modules declared in this project.

Ruler 📐

Quality Check CI Snapshot CI GitHub License

Distance measurements library for Kotlin and Android.

Please visit project website for the full documentation and the changelog.

TLDR

Add Laboratory dependency to your project.

repositories {
  mavenCentral()
}

dependencies {
  implementation "io.mehow.ruler:ruler-android:0.6.0"
}

Enable Java 8 support.

android {
  compileOptions {
    sourceCompatibility JavaVersion.VERSION_1_8
    targetCompatibility JavaVersion.VERSION_1_8
  }

  kotlinOptions {
    jvmTarget = "1.8"
    freeCompilerArgs += "-Xjvm-default=enable"
  }
}

Define a distance and manipulate it.

// Distance is dimensionless.
val distanceFromMeters: Distance = Distance.ofMeters(100)
val distanceFromYards: Distance = Distance.ofYards(50)

// Length has a unit attached to it
val metersLength: Length<SiLengthUnit.Meter> = distanceFromMeters.toLength(SiLengthUnit.Meter)
val inchesLength: Length<ImperialLengthUnit.Inch> = distanceFromMeters.toLength(ImperialLengthUnit.Inch)

// metersLength and inchesLength represent the same distance but with a different units attached to them
check(metersLength - inchesLength == Length.ofMeters(0))

Print distances and lengths in a human-readable way based on Locale.

fun main(context: Context) {
  val distance = Distance.ofMeters(100)
  val length = distance.toLength(Meter)

  // Assumes en_US Locale on a device.

  // Prints "109yd 1ft 1in"
  val humanReadableDistance: String = distance.format(context)

  // Prints "109yd 1ft 1in"
  val humanReadableLength: String = length.format(context)
}

License

Copyright 2020 Michał Sikora

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

   http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

Versions

Version
0.5.3
0.5.2
0.5.1
0.5.0
0.4.1
0.4.0
0.3.2
0.3.1
0.3.0
0.2.0
0.1.0