📘 AppUtilX Documentation

Examples: Gradle KTS, Gradle (Groovy), and Kotlin — (No Java examples)
<

🔹 Download & Setup (Gradle KTS & Groovy)

Add GitHub Packages repository and the AppUtilX dependency.
📦 Public package — no token required for usage.
Kotlin DSL (build.gradle.kts)

repositories {
    google()
    mavenCentral()
    maven {
       maven { url = uri("https://jitpack.io") }
    }
}

dependencies {
    implementation("com.github.mohamed-zaitoon:apputilx:1.0.3")
}
    

🔹 Initialize Utils (Kotlin)

Call from Application.onCreate and register lifecycle callbacks.

class MyApplication : Application() {
   
override fun onCreate() {
    super.onCreate()
    Utils.initialize(this)
    registerActivityLifecycleCallbacks(Utils.activityTracker)
}

} 

🔹 Toast (Kotlin)


Utils.showToast("Hello World")
Utils.showToast("Long Toast", long = true)
    

🔹 Connectivity (Kotlin)


val connected = Utils.isConnected
Utils.addConnectionListener { isOnline ->
    Utils.showToast("Network changed: $isOnline")
}
    

🔹 Clipboard (Kotlin)


Utils.copyText("Copied text")
val copied = Utils.getCopiedText()
    

🔹 Device Info (Kotlin)


val model = Utils.getDeviceModel()
val version = Utils.getAndroidVersion()
    

🔹 Permissions (Kotlin)


Utils.requestPermission(this, Manifest.permission.CAMERA, 1001)
    

🔹 Keyboard (Kotlin)


/* Hide keyboard (auto-detects Activity / Context) */
Utils.hideKeyboard()

/* Hide keyboard with Context */
Utils.hideKeyboard(this)

/* Hide keyboard from View */
Utils.hideKeyboard(editText)

/* Show keyboard for a View */
Utils.showKeyboard(editText)

/* Toggle keyboard state */
Utils.toggleKeyboard()

/* Check keyboard state */
if (Utils.isKeyboardOpen(editText)) {
    Utils.hideKeyboard(editText)
}
    

🔹 Sharing (Kotlin)


Utils.shareText(this, "Hello from Utils!")
    

🔹 Intent Utilities (Kotlin)

Common system intents like WhatsApp, dialer, email, and sharing.

/* Open WhatsApp chat */
Utils.openWhatsApp("201234567890", "Hello!")

/* Open phone dialer */
Utils.dial("201234567890")

/* Send email */
Utils.sendEmail(
    email = "test@example.com",
    subject = "Hello",
    body = "Message body"
)

/* Share text */
Utils.shareText("Shared from Utils")
    

🔹 Storage (Kotlin)

Internal storage and cache utilities.

val free = Utils.getFreeStorage()
val total = Utils.getTotalStorage()

val cacheSize = Utils.getCacheSize()
Utils.clearCache()
    

🔹 File Utilities (Kotlin)

Read and write text files in app internal storage.

Utils.writeFile("test.txt", "Hello World")

val text = Utils.readFile("test.txt")

val exists = Utils.fileExists("test.txt")

Utils.deleteFile("test.txt")
    

🔹 Encryption & Encoding (Kotlin)

Hashing and Base64 helpers.

val hash = Utils.sha256("password123")

val encoded = Utils.base64Encode("Hello")
val decoded = Utils.base64Decode(encoded)
    

🔹 App State (Kotlin)

Application and screen state helpers.

val isForeground = Utils.isAppInForeground()
val isScreenOn = Utils.isScreenOn()
    

🔹 Permission Helpers (Kotlin)

Check and request runtime permissions.

if (!Utils.isPermissionGranted(Manifest.permission.CAMERA)) {
    Utils.requestPermission(
        this,
        Manifest.permission.CAMERA,
        1001
    )
}
    

🔹 Vibration (Kotlin)


Utils.vibrate(300)
Utils.vibratePattern(longArrayOf(0,200,100,300), -1)
    

🔹 Open URL (Kotlin)


Utils.openUrl(this, "https://google.com")
    

🔹 Screen Capture (Kotlin)


Utils.blockCapture()
Utils.unblockCapture()
    

🔹 Notification (Kotlin)


val intent = Intent(this, ExampleActivity::class.java)
val pendingIntent = PendingIntent.getActivity(
    this,
    0,
    intent,
    PendingIntent.FLAG_UPDATE_CURRENT or PendingIntent.FLAG_IMMUTABLE
)Utils.showNotification( channelId = "default_channel", title = "Hello", text = "This is a notification", iconResId = R.drawable.ic_launcher, intent = pendingIntent ) 

🔹 App Signature (Kotlin)

Retrieve and validate application signing certificates.

val signatures = Utils.getAppSignatures()

val primarySha1 = Utils.getPrimarySignatureSHA1()

val valid = Utils.validateAppSignature("AA:BB:CC:DD")
    

🔹 Logger (AlertDialog + Logcat)

Display logs as an AlertDialog for easy debugging, while still logging to Logcat.

/* Normal log */
Utils.log("Main", "App started successfully")

/* Warning log */
Utils.logWarning("Network", "Internet connection is slow")

/* Error log */
Utils.logError("API", "Request failed")

/* Error log with Exception */
try {
    riskyCall()
} catch (e: Exception) {
    Utils.logError("Crash", "Unexpected error", e)
}
    
🔸 Logs are shown as a dialog only when an Activity is available. 🔸 Logs are always written to Logcat.

🔹 License

This license text is now copyable via the button.

Copyright (c) 2025 Mohamed Zaitoon