Skip to content

Instantly share code, notes, and snippets.

View ktvipin27's full-sized avatar
🏠
Working from home

Vipin K T ktvipin27

🏠
Working from home
View GitHub Profile
@ktvipin27
ktvipin27 / ControlView.kt
Created June 24, 2020 10:49
Code for toggling the flash mode in cameraX sample application
private fun toggleFlash() {
when (flashMode) {
FlashMode.FLASH_MODE_AUTO -> {
flashMode =
FlashMode.FLASH_MODE_OFF
ivFlash.setImageResource(R.drawable.ic_baseline_flash_off_24)
}
FlashMode.FLASH_MODE_ON -> {
flashMode =
FlashMode.FLASH_MODE_AUTO
@ktvipin27
ktvipin27 / ControlView.FlashMode.kt
Last active June 24, 2020 10:40
Enum class for maintaining flash mode in cameraX sample application
enum class FlashMode {
FLASH_MODE_AUTO,
FLASH_MODE_ON,
FLASH_MODE_OFF
}
@ktvipin27
ktvipin27 / ControlView.Listener.kt
Created June 23, 2020 05:43
Listener for camera controls
interface Listener {
fun toggleCamera()
fun toggleFlash(flashMode: FlashMode)
fun capturePhoto()
fun startVideoCapturing()
fun stopVideoCapturing()
}
@ktvipin27
ktvipin27 / ControlView.kt
Last active June 26, 2020 15:58
A custom view for controlling camera
class ControlView : LinearLayout {
private var isLongPressed: Boolean = false
private var flashMode: FlashMode = FlashMode.FLASH_MODE_OFF
private var listener: Listener? = null
private val timerView = TimerView(context)
.apply {
layoutParams = LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT)
visibility = View.INVISIBLE
@ktvipin27
ktvipin27 / TimerView.kt
Created June 23, 2020 05:09
A custom view for displaying timer while recording video
class TimerView : LinearLayout {
private var startTime = 0L
private var timerHandler = Handler()
private val timerThread = object : Runnable {
override fun run() {
tvTimer.text = (SystemClock.uptimeMillis() - startTime).toDuration()
timerHandler.postDelayed(this, 0)
}
}
@ktvipin27
ktvipin27 / TimberFirestoreTree.kt
Created June 16, 2020 14:11
RemoteLog class for Timber configuration for pushing logs to Firebase firestore.
class TimberFirestoreTree(private val deviceDetails: DeviceDetails) : Timber.DebugTree() {
private val dateFormat = SimpleDateFormat("dd-MM-yyyy", Locale.getDefault())
private val timeFormat = SimpleDateFormat("yyyy-MM-dd hh:mm:ss.SSS a zzz", Locale.getDefault())
private val date = dateFormat.format(Date(System.currentTimeMillis()))
private val logRef = Firebase.firestore.collection("logs/10-06-2020/${deviceDetails.deviceId}")
override fun log(priority: Int, tag: String?, message: String, t: Throwable?) {
if (BuildConfig.REMOTE_LOG_ENABLED) {
@ktvipin27
ktvipin27 / build.gradle
Created June 12, 2020 02:51
App-level build.gradle file for Firebase realtime database configuration.
apply plugin: 'com.android.application'
// Add this line
apply plugin: 'com.google.gms.google-services'
dependencies {
// add SDKs for desired Firebase products
implementation 'com.google.firebase:firebase-database-ktx:19.3.0'
}
@ktvipin27
ktvipin27 / build.gradle
Created June 12, 2020 02:50
Project-level build.gradle file for Firebase realtime database configuration.
buildscript {
repositories {
// Check that you have the following line (if not, add it):
google() // Google's Maven repository
}
dependencies {
...
// Add this line
classpath 'com.google.gms:google-services:4.3.3'
}
@ktvipin27
ktvipin27 / RemoteLog.kt
Created June 11, 2020 15:01
RemoteLog class for Timber configuration for pushing logs to Firebase realtime database.
data class RemoteLog(
var priority: String,
var tag: String?,
var message: String,
var throwable: String?,
val time : String
)
@ktvipin27
ktvipin27 / DeviceDetails.kt
Created June 11, 2020 15:00
DeviceDetails class for Timber configuration for pushing logs to Firebase realtime database.
data class DeviceDetails(
val deviceId: String,
val osVersion: String = Build.VERSION.RELEASE,
val manufacturer: String = Build.MANUFACTURER,
val brand: String = Build.BRAND,
val device: String = Build.DEVICE,
val model: String = Build.MODEL,
val appVersionName: String = BuildConfig.VERSION_NAME,
val appVersionCode: Int = BuildConfig.VERSION_CODE
)