Skip to content

Instantly share code, notes, and snippets.

@togramago
togramago / Gallery Backend Schema
Created April 28, 2020 13:05
Gallery Backend Schema
object MatchesDependencies {
internal lateinit var matchMakingService: MatchMakingService
private set
fun init(networkingModule: NetworkingModule) {
matchMakingService =
networkingModule.createSecureServiceEndpoint(MatchMakingService::class.java)
}
internal lateinit var matchesBehavior: MatchesBehavior
@togramago
togramago / TestExample.kt
Created March 29, 2019 15:28
Mocking dependencies in tests
@Test
internal fun presenceService_askedForFrequency() {
val heartbeat = PublishSubject.create<Presence>()
val mockPresenceService = mock<PresenceService> {
on { sendHeartbeat() } doReturn heartbeat
}
val mockNetworkingModule = mock<NetworkingModule> {
on { createSecureServiceEndpoint(PresenceService::class.java) }
.doReturn(mockPresenceService)
}
@togramago
togramago / ApplicationModule.kt
Created March 29, 2019 15:27
Injecting dependency in the main app module
@Provides
@Singleton
open fun providePresenceMaintainer(networkingModule: NetworkingModule) = PresenceMaintainer(networkingModule)
open class PresenceMaintainer(
networkingModule: NetworkingModule,
) : Application.ActivityLifecycleCallbacks {
internal val presenceService =
networkingModule.createSecureServiceEndpoint(PresenceService::class.java)
private val foregroundSubject = PublishSubject.create<Boolean>()
private val polling = presenceService.sendHeartbeat()
.subscribeOn(Schedulers.io())
private var connected by Delegates.observable(false) { … }
@togramago
togramago / ExtendedNumberPicker.java
Last active May 8, 2019 07:35
NumberPicker with transparent selection dividers via Reflection
package com.runup.myapplication2.app;
import android.content.Context;
import android.content.res.Resources;
import android.util.AttributeSet;
import android.widget.NumberPicker;
import java.lang.reflect.Field;
/**
@togramago
togramago / ClearTextView.java
Created June 2, 2014 15:33
TextView with background and transparent (carved through background) text
package com.runup.myapplication2.app;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.PorterDuff;
import android.graphics.PorterDuffXfermode;
import android.graphics.drawable.BitmapDrawable;
/**
* Manages dimensions (px) via etalon (STANDARD is for Nexus7).
* Use for texts, not for pictures
* (as this one has two scale coefficients: one for width and one for height).
*/
@SuppressLint("UseValueOf")
public class DimenManager {
private static final Point STANDARD = new Point(1200, 1776);