Skip to content

Instantly share code, notes, and snippets.

View ChuuMong's full-sized avatar
✈️

JongHun Lee ChuuMong

✈️
View GitHub Profile
@ChuuMong
ChuuMong / MainActivity.kt
Created March 16, 2023 03:21
Webview Disable Horizontal Scroll
webview.setOnTouchListener(object: View.OnTouchListener {
private var touchDownX: Float = -1f
override fun onTouch(v: View, event: MotionEvent): Boolean {
if (event.pointerCount > 1) {
return true
}
when (event.action) {
@ChuuMong
ChuuMong / select_image_position.java
Created December 20, 2022 05:57
select_image_position.java
Cursor c = null;
SubwayDatabaseHelper myDbHelper = new SubwayDatabaseHelper(MainActivity.this); // Reading SQLite database.
try {
myDbHelper.createDataBase();
} catch (IOException ioe) {
throw new Error("Unable to create database");
}
try {
myDbHelper.openDataBase();
} catch (SQLException sqle) {
abstract class PaginationScrollListener(private val layoutManager: LinearLayoutManager) :
RecyclerView.OnScrollListener() {
override fun onScrolled(recyclerView: RecyclerView, dx: Int, dy: Int) {
super.onScrolled(recyclerView, dx, dy)
val visibleItemCount: Int = layoutManager.childCount
val totalItemCount: Int = layoutManager.itemCount
val firstVisibleItemPosition: Int = layoutManager.findFirstVisibleItemPosition()
if (!isLoading() && !isLastPage()) {
if (visibleItemCount + firstVisibleItemPosition >= totalItemCount
@ChuuMong
ChuuMong / printing_directory_tree.kt
Created March 30, 2022 07:49
printing directory tree
private fun printDirectoryTree(folder: File): String {
if (!folder.isDirectory) {
return String.empty()
}
val indent = 0
val sb = StringBuilder()
printDirectoryTree(folder, indent, sb)
return sb.toString()
}
@ChuuMong
ChuuMong / EventBus.kt
Last active October 15, 2021 00:08
Flow EventBus
/**
* ```
* // To post an event:
* EventBus.send(SomeEvent())
*
* // To subscribe to an event:
* EventBus.register(this, SomeEvent::class) { event ->
* }
*
* // To cancel a subscriber:
@ChuuMong
ChuuMong / layout_test.xml
Last active October 7, 2021 04:28
ConstraintLayout 중앙 TextView 가변 제약 처리
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:id="@+id/tv_label_1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Label 1"
app:layout_constraintStart_toStartOf="parent"
@ChuuMong
ChuuMong / EditTextEnglishKoreanFilter.kt
Created June 17, 2020 04:34
EditText 영문, 한글(천지인 키보드 대응) 필터
et_name.filters = arrayOf(InputFilter { source, start, end, dest, dstart, dend ->
val pattern = Pattern.compile("^[a-zA-Zㄱ-ㅎ가-힣ㅏ-ㅣ\\u318D\\u119E\\u11A2\\u2022\\u2025a\\u00B7\\uFE55]+$")
if (pattern.matcher(source).matches()) {
source
} else {
""
}
})
@ChuuMong
ChuuMong / EventBus.kt
Last active January 6, 2021 14:16
Coroutine based event bus
/**
* ```
* // To post an event:
* EventBus.send(SomeEvent())
*
* // To subscribe to an event:
* EventBus.register(this, Dispatchers.Main, SomeEvent::class) { event ->
* }
*
@ChuuMong
ChuuMong / CustomFragment.kt
Created April 13, 2020 07:13
BackPress handling in Android Fragments
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
activity?.onBackPressedDispatcher?.addCallback(this, object : OnBackPressedCallback(true) {
override fun handleOnBackPressed() {
// in here you can do logic when backPress is clicked
}
})
}
import com.gargoylesoftware.htmlunit.WebClient
import com.gargoylesoftware.htmlunit.html.HtmlDivision
import com.gargoylesoftware.htmlunit.html.HtmlPage
import org.jsoup.Jsoup
import kotlin.system.measureTimeMillis
data class Currency(val code: String, val engName: String)
fun main() {
val currencies = mutableListOf<Currency>()