Skip to content

Instantly share code, notes, and snippets.

View alvindizon's full-sized avatar
🎯
Focusing

alvindizon

🎯
Focusing
View GitHub Profile
@alvindizon
alvindizon / OTPEditText.kt
Last active March 29, 2022 03:09 — forked from ShivamPokhriyal/OTPEditText.java
A custom view to handle otp input in multiple edittexts. It will move focus to next edittext, if available, when user enters otp and it will move focus to the previous edittext, if available, when user deletes otp. It will also delegate the paste option, if user long presses and pastes a string into the otp input.
package com.yourapp.ui
import android.content.ClipboardManager
import android.content.Context
import android.graphics.Rect
import android.util.AttributeSet
import android.view.KeyEvent
import android.view.View
import androidx.appcompat.widget.AppCompatEditText
import androidx.core.widget.doAfterTextChanged
@alvindizon
alvindizon / CoroutineExtension.kt
Last active August 30, 2022 01:08
JUnit extensions for LiveData(InstantExecutor), RxJava2, and Coroutines
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.test.TestCoroutineDispatcher
import kotlinx.coroutines.test.TestCoroutineScope
import kotlinx.coroutines.test.resetMain
import kotlinx.coroutines.test.setMain
import org.junit.jupiter.api.extension.AfterEachCallback
import org.junit.jupiter.api.extension.BeforeEachCallback
import org.junit.jupiter.api.extension.ExtensionContext
### Keybase proof
I hereby claim:
* I am alvindizon on github.
* I am admdizon (https://keybase.io/admdizon) on keybase.
* I have a public key ASDGH9f1Dlyjd5ca8lSGN1qEZTRMN14md_MdfUeYyI5FuAo
To claim this, I am signing this object:
@alvindizon
alvindizon / vector.xml
Last active August 17, 2020 08:51
day/night mode drawable notes
<!-- If you are using a drawable on an imageview on a layout, -->
<!-- in order for the night color values to take effect, use/reference color attributes in this manner: -->
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24">
<path
android:fillColor="?attr/colorOnSurface"
@alvindizon
alvindizon / build.gradle
Last active August 13, 2020 00:44
Android flavors
defaultConfig {
applicationId "com.internal.app"
...
}
buildTypes {
debug{
...
}
release {
...
@alvindizon
alvindizon / ThreadPoolConfig.java
Created May 30, 2020 06:05
sample custom thread pool config (from Vasiliy Zukanov)
new ThreadPoolExecutor(
3,
Integer.MAX_VALUE,
60,
TimeUnit.SECONDS,
new SynchronousQueue<Runnable>()
);
@alvindizon
alvindizon / Test.java
Last active May 12, 2020 08:40
copy file in java using NIO
try(FileChannel in = new FileInputStream(src).getChannel();
FileChannel out = new FileOutputStream(dest).getChannel() ) {
in.transferTo(0, in.size(), out);
} catch (IOException e) {
e.printStackTrace();
}
@alvindizon
alvindizon / Test.java
Last active May 12, 2020 08:39
write text file to sdcard folder in android
new Thread(() -> {
String errorPath = Environment.getExternalStorageDirectory().getPath() +
File.separator + Const.TEST_FILE_FOLDER;
File exceptionFolder = new File(errorPath);
if(!exceptionFolder.exists()) {
exceptionFolder.mkdir();
}
File errFile = new File(errorPath + File.separator + Const.TEST_FILE);
if(!errFile.exists()) {
try {
@alvindizon
alvindizon / UDPclient.java
Created October 10, 2019 05:22
safe lazy initialization example
public class UDPClient {
private static final String TAG = UDPClient.class.getSimpleName();
private static class Holder{
public static UDPClient udpClient = new UDPClient();
}
public static UDPClient getUdpClient() {
return Holder.udpClient;
}