Skip to content

Instantly share code, notes, and snippets.

View virendersran01's full-sized avatar
💻
Working from home

Virender Srxn virendersran01

💻
Working from home
  • India
View GitHub Profile
@ImaginativeShohag
ImaginativeShohag / ExtNavController.kt
Last active June 23, 2024 14:41
"MainActivity.kt" example indicates that calling `navigateUp()` multiple times will recreate the `Activity`. To solve the black issue 2 extension function given in "ExtNavController.kt" file.
import android.app.Activity
import android.content.Context
import androidx.lifecycle.Lifecycle
import androidx.navigation.NavController
/**
* Attempts to pop the controller's back stack.
* If the back stack is empty, it will finish the activity.
*
* @param context Activity context.
@ardakazanci
ardakazanci / AnimatedTextSwitcher.kt
Created June 11, 2024 17:02
Animated Text in Jetpack Compose
@Composable
fun AnimatedTextSwitcher() {
var isYellowBoxVisibility by remember { mutableStateOf(true) }
LaunchedEffect(Unit) {
while (true) {
delay(3000)
isYellowBoxVisibility = !isYellowBoxVisibility
}
}
@saurabharora90
saurabharora90 / Speedometer.kt
Created October 15, 2023 11:36
Speedometer in Jetpack Compose
import androidx.annotation.FloatRange
import androidx.compose.animation.core.Animatable
import androidx.compose.animation.core.LinearOutSlowInEasing
import androidx.compose.animation.core.tween
import androidx.compose.foundation.Canvas
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.requiredSize
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Slider
Apache License
Version 2.0, January 2004
http://www.apache.org/licenses/
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
1. Definitions.
"License" shall mean the terms and conditions for use, reproduction,
and distribution as defined by Sections 1 through 9 of this document.
@whytarun
whytarun / CertificateHelper.kt
Created October 3, 2023 06:46
SSL Support
class CertificateHelper @Inject constructor(@ApplicationContext context: Context) {
private val applicationContext = context
fun createTrustManagers(): Array<TrustManager> {
val certificateInputStream = applicationContext.resources.openRawResource(
R.raw.test)
val certificateFactory = CertificateFactory.getInstance("X.509")
val certificate = certificateFactory.generateCertificate(certificateInputStream)
val trustManagerFactory = TrustManagerFactory.getInstance(
TrustManagerFactory.getDefaultAlgorithm())
val keyStore = KeyStore.getInstance(KeyStore.getDefaultType())
@whytarun
whytarun / NetworkModule.kt
Last active October 8, 2023 13:52
Including support for TLS/SSL
@Singleton
@Provides
fun provideOkhttpClient(authInterceptor: AuthInterceptor,
certificateHelper: CertificateHelper
) :OkHttpClient{
val trustManagers = certificateHelper.createTrustManagers()
val sslContext = SSLContext.getInstance("TLS")
sslContext.init(null, trustManagers, null)
return OkHttpClient().newBuilder()
.readTimeout(2, TimeUnit.MINUTES)
@HasibPrince
HasibPrince / FileUtils.kt
Created September 24, 2023 20:45
Usage of old storage api
val filename = "myFile.txt"
val content = "Hello, World!"
val documentsDir = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOCUMENTS)
val file = File(documentsDir, filename)
file.outputStream().use { outputStream ->
outputStream.write(content.toByteArray())
}
@HasibPrince
HasibPrince / FileUtils.kt
Created September 24, 2023 20:41
Usage of MediaStore API
val contentResolver = this.contentResolver
val contentValues = ContentValues().apply {
put(MediaStore.MediaColumns.DISPLAY_NAME, "applounge")
put(MediaStore.MediaColumns.MIME_TYPE, "text/plain")
put(MediaStore.MediaColumns.RELATIVE_PATH, Environment.DIRECTORY_DOCUMENTS)
}
val uri = contentResolver.insert(MediaStore.Files.getContentUri("external"), contentValues)
uri?.let {
contentResolver.openOutputStream(it)?.use { outputStream ->
@nirbhayph
nirbhayph / Circles.kt
Last active December 11, 2023 21:06
Google Maps and Jetpack Compose
@Composable
fun CircleMap() {
// Define the coordinates for circle centers and their associated information
val circleData = listOf(
CircleInfo("Park A", LatLng(37.7749, -122.4194), "This is Park A"),
CircleInfo("Park B", LatLng(36.7783, -119.4179), "This is Park B"),
CircleInfo("Park C", LatLng(34.0522, -118.2437), "This is Park C")
)
// Create a mutable state to track the selected circle
@stevdza-san
stevdza-san / AnimatedBorderCard.kt
Last active April 3, 2024 14:01
Card with Animated Border built with Jetpack Compose.
@Composable
fun AnimatedBorderCard(
modifier: Modifier = Modifier,
shape: Shape = RoundedCornerShape(size = 0.dp),
borderWidth: Dp = 2.dp,
gradient: Brush = Brush.sweepGradient(listOf(Color.Gray, Color.White)),
animationDuration: Int = 10000,
onCardClick: () -> Unit = {},
content: @Composable () -> Unit
) {