Skip to content

Instantly share code, notes, and snippets.

View thoinv's full-sized avatar
🎯
Focusing

Thoi Nguyen thoinv

🎯
Focusing
View GitHub Profile
@thoinv
thoinv / webviewerror.java
Created February 10, 2023 01:12
[WebView multi process error Solution] Android 9 prohibit sharing WebView data directory among multiple processes add below code in your main #webview #solution #android
public void onCreate() {
...
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
String processName = getProcessName(this);
String packageName = this.getPackageName();
if (!packageName.equals(processName)) {
WebView.setDataDirectorySuffix(processName);
}
}
}
@thoinv
thoinv / sqliteleaks.java
Created February 9, 2023 04:14
[Detect Leaked Object SQL Lite debug] #database #sqlite
private void initSQLiteDetectLeakedObjects() {
StrictMode.setVmPolicy(new StrictMode.VmPolicy.Builder()
.detectLeakedSqlLiteObjects()
.detectLeakedClosableObjects()
.penaltyLog()
.penaltyDeath()
.build());
}
@thoinv
thoinv / scroll_down_hidden_toolbar.xml
Last active July 25, 2022 07:33
[Scroll Down hidden Toolbar] #android #ui
<androidx.coordinatorlayout.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/main_content"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:id="@+id/mylin"
android:layout_width="match_parent"
android:layout_height="50dp"
@thoinv
thoinv / Singleton.kt
Last active July 19, 2022 10:04
[Singleton Kotlin] #kotlin
companion object {
private var INSTANCE: Repository? = null
val instance: Repository?
get() {
if (INSTANCE == null) {
synchronized(Repository::class.java) {
if (INSTANCE == null) {
INSTANCE =
Repository()
}
@thoinv
thoinv / PopupMenu.java
Created July 4, 2022 02:45
[Show Popup Menu] #android #popupmenu
PopupMenu popupMenu = new PopupMenu(MainActivity.this, button);
// Inflating popup menu from popup_menu.xml file
popupMenu.getMenuInflater().inflate(R.menu.popup_menu, popupMenu.getMenu());
popupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem menuItem) {
// Toast message on menu item clicked
Toast.makeText(MainActivity.this, "You Clicked " + menuItem.getTitle(), Toast.LENGTH_SHORT).show();
return true;
@thoinv
thoinv / modDs.sh
Created May 25, 2021 04:05
[Keep only drawable folders in app resource] #macos #mod
DIR="$( cd "$( dirname "$0" )" && pwd )"
for entry in "$DIR"/*
do
if [[ "$entry" != *"/drawable"* ]] && [[ "$entry" == *"/resource-designer/res/"* ]]
then
#remove all folder != drawable*
rm -rf "$entry"
else
# remove all file xml
@thoinv
thoinv / note.txt
Last active May 24, 2021 10:11
[Install adb in MacOS] #macos #adb
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"
brew install android-platform-tools
https://stackoverflow.com/questions/17901692/set-up-adb-on-mac-os-x
@thoinv
thoinv / sample.xml
Created May 16, 2021 16:26
[How can you use tools in android layout to replace a merge item for designer] #android #ui
<merge xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
tools:parentTag="androidx.constraintlayout.widget.ConstraintLayout"
tools:showIn="@layout/fragment_layout">
...
</merge>
https://stackoverflow.com/questions/57070747/how-can-you-use-tools-in-android-layout-to-replace-a-merge-item-for-designer
@thoinv
thoinv / proguard-rules.pro
Last active May 13, 2021 08:40
[Proguard Template] #apkprotect #android
-repackageclasses ''
#Optimization Option
-optimizations !code/simplification/arithmetic,!code/simplification/cast,!field/*,!class/merging/*
-optimizationpasses 5
#Annotation
-keepattributes *Annotation*
-keep @interface com.google.gson.annotations.*
@thoinv
thoinv / build.gradle
Created May 6, 2021 03:42
[Auto Increment Version in Gralde] #gradle #tip
productFlavors{
vDevelop_Auto_Increment_Version {
buildConfigField "long", "BUILD_DATE", System.currentTimeMillis() + "L"
buildConfigField "boolean", "DEBUG_MODE", "true"
buildConfigField "boolean", "ENABLE_FORCE_UPDATE", "false"
dimension "dimen"
versionName "develop"
def versionPropsFile = file('version.properties')