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
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") |
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
<?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" /> |
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
private val textureView: TextureView by lazy { | |
findViewById<TextureView>(R.id.texture_view) | |
} | |
override fun onResume() { | |
super.onResume() | |
if (textureView.isAvailable) { | |
openCamera() | |
} else { |
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
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 |
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
private var captureSession: CameraCaptureSession? = null | |
private fun createCameraPreviewSession() { | |
if (cameraDevice == null) { | |
return | |
} | |
val texture = textureView.surfaceTexture | |
texture.setDefaultBufferSize(640, 480) | |
val surface = Surface(texture) |
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
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 | |
} |
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
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() | |
} |
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
private fun rotateTextureView() { | |
val orientation = getApplicationOrientation() | |
val viewWidth = textureView.width | |
val viewHeight = textureView.height | |
val matrix = Matrix() | |
matrix.postRotate(- orientation.toFloat(), viewWidth * 0.5F, viewHeight * 0.5F) | |
textureView.setTransform(matrix) | |
} |
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
sealed class CounterIntent : Intent { | |
object IncrementIntent : CounterIntent() | |
object DecrementIntent : CounterIntent() | |
} | |
sealed class CounterAction : Action { | |
data class UpdateCountAction(val count: Int) : CounterAction() | |
} | |
data class CounterState(val count: Int = 0) : State |
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
class CounterProcessor : Processor<CounterAction>() { | |
private fun processIncrementAction(action: DelayedIncrementAction) = launch { | |
delay(1000) | |
put(UpdateCountAction(action.count - 1)) | |
} | |
override fun processAction(action: CounterAction) { | |
when (action) { | |
is IncrementAction -> processIncrementAction(action) |
OlderNewer