This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
previewView.afterMeasured { | |
val autoFocusPoint = SurfaceOrientedMeteringPointFactory(1f, 1f) | |
.createPoint(.5f, .5f) | |
try { | |
val autoFocusAction = FocusMeteringAction.Builder( | |
autoFocusPoint, | |
FocusMeteringAction.FLAG_AF | |
).apply { | |
//start auto-focusing after 2 seconds | |
setAutoCancelDuration(2, TimeUnit.SECONDS) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Create a listener with a callback invoked when a gesture event has occurred | |
val listener = object : ScaleGestureDetector.SimpleOnScaleGestureListener() { | |
override fun onScale(detector: ScaleGestureDetector): Boolean { | |
// Get the current camera zoom ratio | |
val currentZoomRatio: Float = cameraInfo.zoomRatio.value ?: 1F | |
// Get by how much the scale has changed due to the user's pinch gesture | |
val delta = detector.scaleFactor | |
// Update the camera's zoom ratio |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* Copyright 2012 Charles Harley | |
* | |
* 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, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import android.content.res.Resources | |
// Convert px to dp | |
val Int.dp: Int | |
get() = (this / Resources.getSystem().displayMetrics.density).toInt() | |
//Convert dp to px | |
val Int.px: Int | |
get() = (this * Resources.getSystem().displayMetrics.density).toInt() | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import android.view.View | |
fun View.gone() = run { visibility = View.GONE } | |
fun View.visible() = run { visibility = View.VISIBLE } | |
fun View.invisible() = run { visibility = View.INVISIBLE } | |
infix fun View.visibleIf(condition: Boolean) = | |
run { visibility = if (condition) View.VISIBLE else View.GONE } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import android.app.Activity | |
import android.widget.Toast | |
import androidx.annotation.StringRes | |
import androidx.fragment.app.Fragment | |
fun Fragment.toast(message: String) { | |
Toast.makeText(requireContext(), message, Toast.LENGTH_LONG).show() | |
} | |
fun Fragment.toast(@StringRes message: Int) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import android.app.Activity | |
import android.view.View | |
import android.view.inputmethod.InputMethodManager | |
import androidx.fragment.app.Fragment | |
fun Activity.hideKeyboard() { | |
val imm: InputMethodManager = | |
getSystemService(Activity.INPUT_METHOD_SERVICE) as InputMethodManager | |
val view = currentFocus ?: View(this) | |
imm.hideSoftInputFromWindow(view.windowToken, InputMethodManager.HIDE_NOT_ALWAYS) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.text.SimpleDateFormat | |
import java.util.* | |
fun String.toDate(format: String = "yyyy-MM-dd HH:mm:ss"): Date? { | |
val dateFormatter = SimpleDateFormat(format, Locale.getDefault()) | |
return dateFormatter.parse(this) | |
} | |
fun Date.toStringFormat(format: String = "yyyy-MM-dd HH:mm:ss"): String { | |
val dateFormatter = SimpleDateFormat(format, Locale.getDefault()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import android.util.Log | |
fun Any?.printToLog(tag: String = "DEBUG_LOG") { | |
Log.d(tag, toString()) | |
} |
NewerOlder