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
// how to get material color/colour programatically | |
// material color using code | |
import android.view.View | |
import androidx.core.content.ContextCompat | |
import com.google.android.material.color.MaterialColors | |
fun View.colorPrimary() = MaterialColors.getColor( | |
this, |
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
// compare two strings on java with neglating localization | |
public static boolean containsIgnoreCase(String src, String what) { | |
final int length = what.length(); | |
if (length == 0) | |
return true; // Empty string is contained | |
final char firstLo = Character.toLowerCase(what.charAt(0)); | |
final char firstUp = Character.toUpperCase(what.charAt(0)); |
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
original post : https://www.youtube.com/watch?v=FOibPikr0qc | |
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
thanks to link : https://stackoverflow.com/a/45459675 | |
var repeatDays = ArrayList<String>() | |
for read : | |
repeatDays = arrayListOf<String>().apply { | |
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) { | |
parcel.readList(this, String::class.java.classLoader, String::class.java) |
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
// Reference : https://blog.kiprosh.com/how-to-avoid-double-splash-screens-in-android-12/ | |
class SplashActivity : AppCompatActivity() { | |
override fun onCreate(savedInstanceState: Bundle?) { | |
super.onCreate(savedInstanceState) | |
setContentView(R.layout.activity_splash) | |
val content = findViewById<View>(android.R.id.content) | |
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) { | |
content.viewTreeObserver.addOnDrawListener { false } | |
} |
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 String.toTransparentColor(num: Int): String { | |
return "#" + when (num) { | |
100 -> "FF" | |
99 -> "FC" | |
98 -> "FA" | |
97 -> "F7" | |
96 -> "F5" | |
95 -> "F2" | |
94 -> "F0" |
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
// packageName = your application package name | |
fun Context.openInPlayStore() { | |
val playStoreApp = String.format("market://details?id=%", packageName) | |
val playStoreUrl = String.format("https://play.google.com/store/apps/details?id=%", packageName) | |
val playStoragePackage = "com.android.vending" | |
try { | |
if (appInstalledOrNot(playStoragePackage)) { | |
packageManager.getLaunchIntentForPackage(playStoragePackage)?.let { intent -> | |
intent.action = Intent.ACTION_VIEW | |
intent.data = Uri.parse(playStoreApp) |
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
// Add debugSymbolLevel line in your main app project gradle.build | |
debug { | |
ndk.debugSymbolLevel = "FULL" // /build/intermediates/merged_native_libs path of the native debug build files | |
} | |
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 Uri.calculateFileSizeInMB(context: Context): String? { | |
val cursor: Cursor? = context.contentResolver.query(this, null, null, null, null) | |
if (cursor != null) { | |
cursor.moveToFirst() | |
val sizeIndex: Int = cursor.getColumnIndex(OpenableColumns.SIZE) | |
val imageSize: Float = cursor.getLong(sizeIndex).toFloat() | |
cursor.close() | |
if (imageSize < 1024) { |
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 Uri.calculateImageDimens(context: Context): String? { | |
try { | |
context.contentResolver.openInputStream(this)?.let { | |
val exif = ExifInterface(it) | |
val width = exif.getAttributeInt(ExifInterface.TAG_IMAGE_WIDTH, -1) | |
if (width > 0) return "$width x $width" | |
} | |
context.contentResolver.openFileDescriptor(this, "r")?.let { fd -> | |
val options: BitmapFactory.Options = BitmapFactory.Options() |