Skip to content

Instantly share code, notes, and snippets.

Avatar

Nonthawit Doungsodsri TheKhaeng

View GitHub Profile
@TheKhaeng
TheKhaeng / settings.json
Created Aug 11, 2018
VScode vim setting
View settings.json
// ============ vim ============ //
"vim.easymotion": true,
"vim.incsearch": true,
"vim.useSystemClipboard": true,
"vim.useCtrlKeys": true,
"vim.hlsearch": true,
"vim.otherModesKeyBindingsNonRecursive": [
{
"before": [
"L"
View ValidateConstantNew.kt
//common validate = 1
const val VALIDATE = 0x000000000000101
const val INVALIDATE = 0x000000000000102
//common string = 2
const val INVALIDATE_EMPTY = 0x000000000000201 or INVALIDATE
//email validate = 3
const val INVALIDATE_EMAIL = 0x000000000000301 or INVALIDATE
const val INVALIDATE_EMAIL_FORMAT = 0x000000000000302 or INVALIDATE_EMAIL
View ValidateConstant.kt
fun @receiver:ValidateString Int.isValidate(): Boolean = this and VALIDATE == VALIDATE
fun @receiver:ValidateString Int.isInvalidate(): Boolean = this and INVALIDATE == INVALIDATE
fun String?.validateCommon(): Int {
if (this.isNullOrEmpty()) return INVALIDATE_EMPTY
return VALIDATE
}
fun @receiver:ValidateString Int.isInvalidateEmail(): Boolean = this and INVALIDATE_EMAIL == INVALIDATE_EMAIL
fun String?.validateEmail(): Int {
if (this.validateCommon().isInvalidate()) return this.validateCommon()
@TheKhaeng
TheKhaeng / ValidateConstant.kt
Last active Jul 30, 2018
ValidateConstant.kt
View ValidateConstant.kt
//common validate at index 0
const val VALIDATE = 0x0001
const val INVALIDATE = 0x0002
//common string validate at index 1
const val INVALIDATE_EMPTY = 0x0010 or INVALIDATE
//email validate at index 2
const val INVALIDATE_EMAIL = 0x0100 or INVALIDATE
const val INVALIDATE_EMAIL_FORMAT = 0x0200 or INVALIDATE_EMAIL
View Validate.kt
import android.support.annotation.IntDef
import java.util.regex.Pattern
/**
* Created by「 The Khaeng 」on 27 Mar 2018 :)
*/
//common validate at index 0
const val VALIDATE = 0x0001
const val INVALIDATE = 0x0002
View SystemUISpaceView.kt
package com.thekhaeng.systemui.view
import android.content.Context
import android.graphics.Rect
import android.os.Build
import android.support.annotation.RequiresApi
import android.util.AttributeSet
import android.view.View
import android.view.WindowInsets
import com.thekhaeng.systemui.R
View get_statusbar_height.kt
var statusBarHeight: Int = 0
ViewCompat.setOnApplyWindowInsetsListener(rootView) { view, windowInsets ->
statusBarHeight = windowInsets.systemWindowInsetTop
return windowInsets //pass insets down to child view
}
View CustomLayout.kt
class CustomLayout : LinearLayout {
...
@Suppress("OverridingDeprecatedMember")
override
fun fitSystemWindows(insets: Rect): Boolean {
// Pre API 20: do something with insets
return true //consume inset: not pass insets down
@TheKhaeng
TheKhaeng / setOnApplyWindowInsetsListener.kt
Last active Jun 2, 2018
setOnApplyWindowInsetsListener.kt
View setOnApplyWindowInsetsListener.kt
ViewCompat.setOnApplyWindowInsetsListener(rootView) { view, windowInsets ->
// do something with insets
return windowInsets.consumeSystemWindowInsets() //consume inset: not pass insets down
//or
return windowInsets //pass insets down to child view
}
View CoordinatorLayout.xml
<android.support.design.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true">
<android.support.design.widget.AppBarLayout
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"