Skip to content

Instantly share code, notes, and snippets.

View imandaliya's full-sized avatar
🐢

Rahul Mandaliya imandaliya

🐢
View GitHub Profile
// 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,
// 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));
original post : https://www.youtube.com/watch?v=FOibPikr0qc
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)
// 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 }
}
@imandaliya
imandaliya / colorUtils.kt
Created September 3, 2022 05:28 — forked from karangoel16/colorUtils.kt
ColorWithTransparency
fun String.toTransparentColor(num: Int): String {
return "#" + when (num) {
100 -> "FF"
99 -> "FC"
98 -> "FA"
97 -> "F7"
96 -> "F5"
95 -> "F2"
94 -> "F0"
// 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)
// 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
}
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) {
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()