Skip to content

Instantly share code, notes, and snippets.

View libliboom's full-sized avatar
🎯
Focusing

Eric Lee libliboom

🎯
Focusing
View GitHub Profile
fun Context.createNotificationSettingsIntent() =
when {
Build.VERSION.SDK_INT >= Build.VERSION_CODES.O -> {
Intent(Settings.ACTION_APP_NOTIFICATION_SETTINGS).apply {
putExtra(Settings.EXTRA_APP_PACKAGE, packageName)
}
}
Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP -> {
Intent().apply {
action = "android.settings.APP_NOTIFICATION_SETTINGS"
inline class Dp(val dp: Int) {
fun toPx() = TypedValue.applyDimension(
TypedValue.COMPLEX_UNIT_DIP, dp.toFloat(), Resources.getSystem().displayMetrics
).toInt()
}
inline val Int.dp
get() = Dp(this).toPx()
import junit.framework.TestCase.assertEquals
import kotlinx.coroutines.*
import kotlinx.coroutines.test.TestCoroutineDispatcher
import org.junit.Rule
import org.junit.Test
/**
* Check the official example for ScopeBuilder with the following url.
* https://kotlinlang.org/docs/reference/coroutines/basics.html#scope-builder
* **/
// before
setOuterBounds(x, y, width, height);
setInnerBounds(x + 2, y + 2, width - 4, height - 4);
// after
setOuterBounds(bounds);
setInnerBounds(bounds.expand(-2));
// 반환 결과값이 단순한 경우
int size() {
int result = 1;
for (Node each : getChildren())
result += each.size();
return result;
}
// 파라미터를 전달해서 결과를 수집하는 직관적인 경우
asList() {
// 가변 상태를 키로하고 값을 데이터로 하는 맵의 예제
class FlexibleObject {
/*package*/ Map<String, Object> properties = new HashMap<String, Object>();
/*package*/ Object getProperty(String key) {
return properties.get(key);
}
/*package*/ void setProperty(String key, Objecct value) {
properties.set(key, value);
// 의존관계가 있는 경우
Rectangle void setWidth(int width) {
this.width = width;
area = width * height;
}
// 의존관계가 있으나 명확하지 않은 경우
Widget void setBorder(int width) {
this.width = width;
notifyListener
class GraphicEditor {
...
public void mouseDown() {
tool.mouseDown(this);
}
...
}
class RectangleTool {
...
class GraphicEditor {
...
public void mouseDown() {
tool.mouseDown();
}
...
}
class RectangleTool {
private GraphicEditor editor;
class ExchangeRate {
private int CountryCode;
public void b() {
Info info = new Info();
int d = info.day;
int m = info.month;
int y = info.year;
}