Skip to content

Instantly share code, notes, and snippets.

class ZoomableTextureView : TextureRenderView {
private var minScale = 1f
private var maxScale = 5f
private var saveScale = 1f
fun setMinScale(scale: Float) {
minScale =
if (scale < 1.0f || scale > maxScale) throw RuntimeException("minScale can't be lower than 1 or larger than maxScale($maxScale)") else scale
}
taskObservable.subscribe(new Observer<Task>() {
@Override
public void onSubscribe(Disposable d) {
}
@Override
public void onNext(Task task) { // run on main thread
Log.d(TAG, "onNext: : " + task.getDescription());
}
Observable<Task> taskObservable = Observable // create a new Observable object
.fromIterable(DataSource.createTasksList()) // apply 'fromIterable' operator
.subscribeOn(Schedulers.io()) // designate worker thread (background)
.observeOn(AndroidSchedulers.mainThread()); // designate observer thread (main thread)
@sagarpatel288
sagarpatel288 / CallingVarInClass.java
Created June 24, 2020 05:57
Showing how to access a kotlin "public final" class members from Java (Java interop)
/**
* 6/24/2020
* A java class accessing {@code var} and its variants defined in a kotlin {@code public final} class.
*
* @author srdpatel
* @since 1.0
*/
public class CallingVarInClass {
public static void main(String[] args) {
@sagarpatel288
sagarpatel288 / CallingVarInClass.kt
Created June 24, 2020 05:48
Showing access to a kotlin "public final" class from outside the class
/**
* 6/23/2020
* Examining access to a `public final` class for `var` from outside the class.
*
* @author srdpatel
* @since 1.0
*/
fun main() {
/**
@sagarpatel288
sagarpatel288 / VarAtTopLevel.kt
Created June 22, 2020 12:52
"var" at top-level
/**
* 6/22/2020
* Assigns a compile time value to the top-level variable: [varTopLevelCompileTime]
* <p>
* `var` is used to assign the runtime or compile time value to the variable that can be reassigned.
* <p>
* Behind the scene of top-level `var`:
* <p>
* The compiler will generate a `public final` class with `Kt` suffix
* for the top-level members.
@sagarpatel288
sagarpatel288 / VarInClassByteCode.java
Created June 22, 2020 11:54
Kotlin Bytecode for VarInClass.kt showing java equivalent for "var" in a kotlin class
/**
* 6/22/2020
* Unlike kotlin, we have to write {@code public} keyword in Java.
* In kotlin, classes are {@code public} by default. We don't have to write.
* Unlike kotlin, we have to write {@code final} keyword in Java to save the class from inheritance.
* In kotlin, classes are {@code final} by default. They can't be inherited unless we mark it as {@code open}.
*
* @author srdpatel
* @see <a href="https://kotlinlang.org/docs/reference/classes.html">Classes and Inheritance</a>
@sagarpatel288
sagarpatel288 / VarInClass.kt
Last active June 24, 2020 04:29
Var in a class and in a function
/**
* 6/22/2020
* <p>
* A java `public final` like class examining `var` variants.
* In kotlin, all classes are by default like java `public final`.
* They can't be inherited unless we mark it as `open`.
* <p>
* Being a `public` class, all the `public` members of this class are accessible from anywhere.
* <p>
* Introduction of `var`:
@sagarpatel288
sagarpatel288 / FinalValInClassJava.java
Created June 19, 2020 03:11
Java equivalent class for a class of kotlin having few val members
class FinalValInClassJava {
/**
* 6/19/2020
* This is kotlin bytecode equivalent of the variable defined inside of a kotlin class as below:
* ```
* {@code @JvmField val jvmFieldFinalExample = someFunction()}
* ```
* We can see that the kotlin bytecode has made it public due to {@code JvmField} annotation.
@sagarpatel288
sagarpatel288 / callTopLevelMembersOfKotlin.java
Created June 19, 2020 00:42
Showing how to access kotlin top-level members from Java
/**
* 6/18/2020
* Accessing java {@code public static final} like kotlin top-level members.
* We can access top-level members even those without having {@code @JvmField} annotation.
*
* @author srdpatel
* @since 1.0
*/
private void accessVal() {