Skip to content

Commit 93ccf01

Browse files
committed
docs: improve documentation
1 parent 3b271ec commit 93ccf01

File tree

19 files changed

+551
-79
lines changed

19 files changed

+551
-79
lines changed

virtualjoystick/src/main/java/com/yoimerdr/android/virtualjoystick/api/drawable/DrawableBitCache.kt

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,21 @@ import android.graphics.drawable.Drawable
55
import androidx.core.graphics.drawable.toBitmap
66
import com.yoimerdr.android.virtualjoystick.geometry.size.Size
77

8+
/**
9+
* Cache a [Drawable] as a [Bitmap] to improve performance when drawing it multiple times.
10+
*
11+
* @param drawable The [Drawable] to cache.
12+
* @param size The desired size of the [Bitmap]. If null, the intrinsic size of the [Drawable] will be used.
13+
*
14+
*/
815
class DrawableBitCache @JvmOverloads constructor(
916
drawable: Drawable,
1017
size: Size? = null,
1118
) {
1219

20+
/**
21+
* The desired size of the bitmap.
22+
* */
1323
var size = size
1424
set(value) {
1525
if (field != value) {
@@ -18,6 +28,9 @@ class DrawableBitCache @JvmOverloads constructor(
1828
}
1929
}
2030

31+
/**
32+
* The drawable to be cached as a bitmap.
33+
* */
2134
var drawable = drawable
2235
set(value) {
2336
if (field != value) {
@@ -26,6 +39,11 @@ class DrawableBitCache @JvmOverloads constructor(
2639
}
2740
}
2841

42+
/**
43+
* The width of the bitmap.
44+
*
45+
* If [size] is null, it's the intrinsic width of the [drawable].
46+
* */
2947
var width: Int
3048
get() = size?.width ?: drawable.intrinsicWidth
3149
set(value) {
@@ -38,6 +56,11 @@ class DrawableBitCache @JvmOverloads constructor(
3856
}
3957
}
4058

59+
/**
60+
* The height of the bitmap.
61+
*
62+
* If [size] is null, it's the intrinsic height of the [drawable].
63+
* */
4164
var height: Int
4265
get() = size?.height ?: drawable.intrinsicHeight
4366
set(value) {
@@ -52,6 +75,9 @@ class DrawableBitCache @JvmOverloads constructor(
5275

5376
private var mBitmap: Bitmap? = null
5477

78+
/**
79+
* The cached bitmap of the [drawable].
80+
* */
5581
val bitmap: Bitmap
5682
get() {
5783
if (mBitmap == null)
@@ -63,6 +89,9 @@ class DrawableBitCache @JvmOverloads constructor(
6389
return mBitmap!!
6490
}
6591

92+
/**
93+
* Recycles the cached bitmap.
94+
* */
6695
fun recycle() {
6796
mBitmap?.recycle()
6897
mBitmap = null
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,20 @@
11
package com.yoimerdr.android.virtualjoystick.api.log
22

3+
/**
4+
* A simple logging interface
5+
* */
36
interface Logger {
7+
/**
8+
* Log a message with info level.
9+
* */
410
fun log(message: Any, vararg others: Any)
11+
12+
/**
13+
* Log a message with warn level.
14+
* */
515
fun warn(message: Any, vararg others: Any)
16+
/**
17+
* Log a message with error level.
18+
* */
619
fun error(message: Any, vararg others: Any)
720
}

virtualjoystick/src/main/java/com/yoimerdr/android/virtualjoystick/api/log/LoggerSupplier.kt

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,34 @@ import android.util.Log
44
import kotlin.reflect.KClass
55

66
object LoggerSupplier {
7+
/**
8+
* Calls the specified function [block] with the [DefaultLogger] as its receiver.
9+
* */
710
fun withLogger(block: Logger.() -> Unit) {
811
DefaultLogger.block()
912
}
1013

14+
/**
15+
* Calls the specified function [block] with a [LabeledLogger] as its receiver.
16+
*
17+
* The label is derived from the simple name of the provided [clazz].
18+
* */
1119
fun withLogger(clazz: KClass<*>, block: Logger.() -> Unit) {
1220
withLogger(clazz.simpleName ?: "LOGGER", block)
1321
}
1422

23+
/**
24+
* Calls the specified function [block] with a [LabeledLogger] as its receiver.
25+
*
26+
* The label is derived from the simple name of the provided [clazz].
27+
* */
1528
fun withLogger(clazz: Class<*>, block: Logger.() -> Unit) {
1629
withLogger(clazz.simpleName ?: "LOGGER", block)
1730
}
1831

32+
/**
33+
* Calls the specified function [block] with a [LabeledLogger] as its receiver.
34+
* */
1935
fun withLogger(label: String, block: Logger.() -> Unit) {
2036
LabeledLogger(label)
2137
.block()
@@ -25,6 +41,13 @@ object LoggerSupplier {
2541
return "$message\n${others.joinToString("\n") { it.toString() }}"
2642
}
2743

44+
/**
45+
* The default logger implementation that logs to Logcat with the tag "LOG", "WARN", and "ERROR".
46+
*
47+
* @see [Log.d]
48+
* @see [Log.w]
49+
* @see [Log.e]
50+
* */
2851
object DefaultLogger : Logger {
2952
override fun log(message: Any, vararg others: Any) {
3053
Log.d("LOG", createMessage(message, others))
@@ -39,6 +62,15 @@ object LoggerSupplier {
3962
}
4063
}
4164

65+
/**
66+
* A logger implementation that logs to Logcat with a custom label.
67+
*
68+
* @param label The label to use for logging.
69+
*
70+
* @see [Log.d]
71+
* @see [Log.w]
72+
* @see [Log.e]
73+
* */
4274
class LabeledLogger(private val label: String) : Logger {
4375
override fun log(message: Any, vararg others: Any) {
4476
Log.d(label, createMessage(message, others))

virtualjoystick/src/main/java/com/yoimerdr/android/virtualjoystick/control/ArcControl.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import com.yoimerdr.android.virtualjoystick.drawer.shapes.arc.ArcDrawer
44
import com.yoimerdr.android.virtualjoystick.theme.ColorsScheme
55

66
/**
7-
* [Control] that uses by default by the [ArcDrawer].
7+
* [Control] that uses by default the [ArcDrawer] as drawer.
88
*/
99
open class ArcControl(
1010
colors: ColorsScheme,

virtualjoystick/src/main/java/com/yoimerdr/android/virtualjoystick/control/CircleArcControl.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import com.yoimerdr.android.virtualjoystick.drawer.shapes.arc.CircleArcDrawer
44
import com.yoimerdr.android.virtualjoystick.theme.ColorsScheme
55

66
/**
7-
* [Control] that uses by default by the [CircleArcDrawer.withRatio].
7+
* [Control] that uses by default the [CircleArcDrawer.withRatio] as drawer.
88
*/
99
open class CircleArcControl(
1010
colors: ColorsScheme,

virtualjoystick/src/main/java/com/yoimerdr/android/virtualjoystick/control/CircleControl.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import com.yoimerdr.android.virtualjoystick.drawer.shapes.circle.CircleDrawer
44
import com.yoimerdr.android.virtualjoystick.theme.ColorsScheme
55

66
/**
7-
* [Control] that uses by default by the [CircleDrawer] with [CircleDrawer.withRatio].
7+
* [Control] that uses by default the [CircleDrawer.withRatio] as drawer.
88
*/
99
open class CircleControl(
1010
colors: ColorsScheme,

0 commit comments

Comments
 (0)