This file contains hidden or 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
| package com.bacancy.dispenserhmi.utils | |
| import android.app.DownloadManager | |
| import android.content.BroadcastReceiver | |
| import android.content.Context | |
| import android.content.Intent | |
| import android.content.IntentFilter | |
| import android.net.Uri | |
| import android.os.Build | |
| import android.os.Environment |
This file contains hidden or 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
| private suspend fun fetchDataParallel() { | |
| try { | |
| Log.d(TAG, "fetchDataParallel: Started") | |
| val deferredData1 = lifecycleScope.async { | |
| delay(3000) | |
| "Hello" | |
| } | |
| val deferredData2 = lifecycleScope.async { | |
| delay(5000) | |
| "World" |
This file contains hidden or 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
| private fun loadImage() { | |
| //val picturesDirectory = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOCUMENTS) | |
| // /storage/emulated/0/Android/data/com.bacancy.ccs2androidhmi/files/ | |
| val picturesDirectory = getExternalFilesDir(null) ?: return | |
| // Create a File object representing the desired directory | |
| val directory = File(picturesDirectory.absolutePath) | |
| // Check if the directory exists | |
| if (directory.exists()) { |
This file contains hidden or 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 createFolderInAppDirectory() { | |
| val folderName = FOLDER_NAME | |
| val appDirectory = getExternalFilesDir(null) ?: return | |
| val folder = File(appDirectory, folderName) | |
| if (!folder.exists()) { | |
| if (folder.mkdir()) { | |
| Log.d("MyApp", "Folder created successfully!") | |
| loadImage() | |
| } else { | |
| Log.e("MyApp", "Failed to create folder") |
This file contains hidden or 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
| private fun loadImage() { | |
| // Specify the directory path for Pictures | |
| val picturesDirectory = | |
| Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES) | |
| // Create a File object representing the desired directory | |
| val directory = File(picturesDirectory.absolutePath) | |
| // Check if the directory exists | |
| if (directory.exists()) { |
This file contains hidden or 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
| package com.bacancy.ccs2androidhmi.util | |
| import android.content.Context | |
| import android.os.Environment | |
| import android.util.Log | |
| import com.bacancy.ccs2androidhmi.db.entity.TbChargingHistory | |
| import java.io.File | |
| import java.io.FileWriter | |
| import java.io.IOException |
This file contains hidden or 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
| //Encryption using Android Keystore: | |
| private fun encryptUrl(context: Context, url: String): String { | |
| val keystore = KeyStore.getInstance(ANDROID_KEYSTORE) | |
| keystore.load(null) | |
| val key = keystore.getKey(KEY_ALIAS, null) as SecretKey | |
| val cipher = Cipher.getInstance(AES_MODE) | |
| cipher.init(Cipher.ENCRYPT_MODE, key) | |
| val encryptedBytes = cipher.doFinal(url.toByteArray()) | |
| return Base64.encodeToString(encryptedBytes, Base64.DEFAULT) | |
| } |
This file contains hidden or 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
| /** | |
| * Kotlin Extensions for simpler, easier and funw way | |
| * of launching of Activities | |
| */ | |
| inline fun <reified T : Any> Activity.launchActivity ( | |
| requestCode: Int = -1, | |
| options: Bundle? = null, | |
| noinline init: Intent.() -> Unit = {}) | |
| { |
This file contains hidden or 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
| <?xml version="1.0" encoding="utf-8"?> | |
| <androidx.coordinatorlayout.widget.CoordinatorLayout 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" | |
| android:layout_width="match_parent" | |
| android:layout_height="match_parent"> | |
| <com.google.android.material.appbar.AppBarLayout | |
| android:layout_width="match_parent" | |
| android:layout_height="wrap_content"> |
NewerOlder