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 OnSingleClickListener(private val clickListener: View.OnClickListener, private val intervalMs: Long = 1000L) : View.OnClickListener { | |
private var canClick = AtomicBoolean(true) | |
override fun onClick(v: View?) { | |
if (canClick.getAndSet(false)) { | |
v?.run { | |
postDelayed({ | |
canClick.set(true) | |
}, intervalMs) | |
clickListener.onClick(v) |
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
object ThemeHelper { | |
const val LIGHT_MODE = "light" | |
const val DARK_MODE = "dark" | |
const val DEFAULT_MODE = "default" | |
fun applyTheme(theme: String) { | |
when (theme) { | |
LIGHT_MODE -> { | |
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO) | |
} | |
DARK_MODE -> { |
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
1) Write the below command to restart adb in tcpip mode: | |
$ adb tcpip 5555 | |
2) Find out the IP address of the Android device: | |
Go to phone Settings -> About phone/tablet -> Status -> IP address | |
3) Step 5 Connect device to Computer: |
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
// After install mongo db. | |
// commmand to start mongodb service | |
mongo | |
// go to admin databse | |
use admin | |
// Create the root user | |
db.createUser({user:"admin", pwd:"password", roles:[{role:"root", db:"admin"}]}) |
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 parseGeoIntent(uri: Uri): Location? { | |
var schemeSpecific: String = uri.schemeSpecificPart ?: "" | |
if (uri.schemeSpecificPart.contains("%2B")) { | |
schemeSpecific = schemeSpecific.replace("+", "%2B") | |
} | |
var name: String? = null | |
val namePattern: Pattern = Pattern.compile("[\\+\\s]*\\((.*)\\)[\\+\\s]*$") | |
val nameMatcher: Matcher = namePattern.matcher(schemeSpecific) |
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
package com.websocket | |
import okhttp3.OkHttpClient | |
class Config private constructor() { | |
var client = OkHttpClient() | |
class Builder { | |
private val config: Config = Config() |
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
public static String getLocalIpAddress() { | |
try { | |
for (Enumeration<NetworkInterface> en = NetworkInterface.getNetworkInterfaces(); en.hasMoreElements(); ) { | |
NetworkInterface intf = en.nextElement(); | |
for (Enumeration<InetAddress> enumIpAddr = intf.getInetAddresses(); enumIpAddr.hasMoreElements(); ) { | |
InetAddress inetAddress = enumIpAddr.nextElement(); | |
if (!inetAddress.isLoopbackAddress() && inetAddress instanceof Inet4Address) { | |
return inetAddress.getHostAddress(); | |
} | |
} |
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
fun <T> Observable<T>.delayEach(interval: Long, timeUnit: TimeUnit): Observable<T> = Observable.zip(this, Observable.interval(interval, timeUnit), BiFunction { item, _ -> item }) |
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
fun Context.loadJSONFromAsserts(fileName: String): String { | |
return applicationContext.assets.open(fileName).bufferedReader().use { reader -> | |
reader.readText() | |
} | |
} |
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
Observable.fromIterable<Int>(Arrays.asList(1, 2, 3)) | |
.zipWith(Observable.interval(200, TimeUnit.MILLISECONDS), BiFunction { item:Int, _:Long -> item }) | |
.subscribe { integers: Int -> Log.d(TAG, "item $integers") } |
NewerOlder