Skip to content

Instantly share code, notes, and snippets.

private fun getApplicationOrientation(): Int {
val windowManager = getSystemService(Context.WINDOW_SERVICE) as WindowManager
val rotation = windowManager.defaultDisplay.rotation
return when (rotation) {
Surface.ROTATION_0 -> 0
Surface.ROTATION_90 -> 90
Surface.ROTATION_180 -> 180
Surface.ROTATION_270 -> 270
else -> throw IllegalStateException()
}
private val cameraManager: CameraManager by lazy {
getSystemService(Context.CAMERA_SERVICE) as CameraManager
}
private fun getCameraOrientation(cameraId: String): Int {
val characteristic = cameraManager.getCameraCharacteristics(cameraId)
return characteristic.get(CameraCharacteristics.SENSOR_ORIENTATION) ?: 0
}
private var captureSession: CameraCaptureSession? = null
private fun createCameraPreviewSession() {
if (cameraDevice == null) {
return
}
val texture = textureView.surfaceTexture
texture.setDefaultBufferSize(640, 480)
val surface = Surface(texture)
private var cameraDevice: CameraDevice? = null
private val cameraManager: CameraManager by lazy {
getSystemService(Context.CAMERA_SERVICE) as CameraManager
}
private fun openCamera() {
cameraManager.openCamera("0", object: CameraDevice.StateCallback() {
override fun onOpened(camera: CameraDevice) {
cameraDevice = camera
private val textureView: TextureView by lazy {
findViewById<TextureView>(R.id.texture_view)
}
override fun onResume() {
super.onResume()
if (textureView.isAvailable) {
openCamera()
} else {
<?xml version="1.0" encoding="utf-8"?>
<TextureView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/texture_view"
android:layout_width="match_parent"
android:layout_height="match_parent" />
@itome
itome / Colorful-Transceivers.py
Created May 13, 2018 04:45
AtCoder Beginner Contest 097
a, b, c, d = map(int, input().split())
if abs(a - c) <= d or abs(a - b) <= d and abs(b - c) <= d:
print("Yes")
else:
print("No")