Skip to content

Instantly share code, notes, and snippets.

View sushant-droid's full-sized avatar

Sushant sushant-droid

  • Sydney
View GitHub Profile
@sushant-droid
sushant-droid / gist:4594f502111753bbd0922faecc817986
Created October 20, 2022 06:35
Imageview, bitmap, canvas drawing
{
// Get display metrics.
metrics = getWindowManager().getDefaultDisplay();
// Get watcher text as String.
String text = s.toString();
// Reverse text and add to TextView.
String inversedText = new StringBuilder(s).reverse().toString();
reverseTextView.setText(inversedText);
inline fun waitUntilLoaded(crossinline recyclerProvider: () -> RecyclerView) {
Espresso.onIdle()
lateinit var recycler: RecyclerView
InstrumentationRegistry.getInstrumentation().runOnMainSync {
recycler = recyclerProvider()
}
while (recycler.hasPendingAdapterUpdates()) {
@sushant-droid
sushant-droid / gist:a3b673f513717b43550950cbcc1307cb
Created February 4, 2022 03:41
Gson type adapter for post processing
internal class RequiredFieldsTypeAdpaterFactory : TypeAdapterFactory {
override fun <T : Any> create(gson: Gson, type: TypeToken<T>): TypeAdapter<T>? {
val delegate = gson.getDelegateAdapter(this, type)
val objectValidator = type.rawType.getAnnotation(EmptyObjectValidator::class.java) ?: return null
return object: TypeAdapter<T>() {
override fun write(out: JsonWriter?, value: T) {
delegate.write(out, value)
}
@sushant-droid
sushant-droid / NullableTypAdapterFactory
Created January 31, 2022 03:10
GSON null type adpater factory
import com.google.gson.*
import com.google.gson.reflect.TypeToken
import com.google.gson.stream.JsonReader
import com.google.gson.stream.JsonWriter
import kotlin.jvm.internal.Reflection
import kotlin.reflect.KClass
import kotlin.reflect.full.memberProperties
class NullableTypAdapterFactory : TypeAdapterFactory {
override fun <T : Any> create(gson: Gson, type: TypeToken<T>): TypeAdapter<T>? {