Skip to content

Instantly share code, notes, and snippets.

View raghunandankavi2010's full-sized avatar
🤵‍♂️
Android dev looking to learn new technologies and always open for a new job.

Raghunandan Kavi raghunandankavi2010

🤵‍♂️
Android dev looking to learn new technologies and always open for a new job.
View GitHub Profile
package com.backpackingmap.backpackingmap.ui.view
import androidx.compose.foundation.background
import androidx.compose.foundation.interaction.FocusInteraction
import androidx.compose.foundation.interaction.MutableInteractionSource
import androidx.compose.foundation.interaction.PressInteraction
import androidx.compose.foundation.layout.*
import androidx.compose.material.*
import androidx.compose.runtime.*
import androidx.compose.ui.Modifier
@vganin
vganin / FlexRow.kt
Last active September 1, 2024 19:19
[DEPRECATED, use official FlowRow instead] Jetpack Compose simple flex-wrap container
@Composable
fun FlowRow(
horizontalGap: Dp = 0.dp,
verticalGap: Dp = 0.dp,
alignment: Alignment.Horizontal = Alignment.Start,
content: @Composable () -> Unit,
) = Layout(content = content) { measurables, constraints ->
val horizontalGapPx = horizontalGap.toPx().roundToInt()
val verticalGapPx = verticalGap.toPx().roundToInt()
@zach-klippenstein
zach-klippenstein / SegmentedControl.kt
Last active December 26, 2024 23:13
iOS-style segmented control in Compose
import android.annotation.SuppressLint
import androidx.compose.animation.core.animateDpAsState
import androidx.compose.animation.core.animateFloatAsState
import androidx.compose.foundation.Canvas
import androidx.compose.foundation.background
import androidx.compose.foundation.gestures.awaitFirstDown
import androidx.compose.foundation.gestures.forEachGesture
import androidx.compose.foundation.gestures.horizontalDrag
import androidx.compose.foundation.layout.Arrangement.spacedBy
import androidx.compose.foundation.layout.Box
@agnostic-apollo
agnostic-apollo / hasFragileUserData.md
Last active November 10, 2024 16:56
Android hasFragileUserData AndroidManifest.xml flag

The hasFragileUserData flag can be added to the application node of AndroidManifest.xml. If its value is true, then when the user uninstalls the app, a prompt will be shown to the user asking him whether to keep the app's data.

<application
	...
    android:hasFragileUserData="true" tools:targetApi="q">
...
</application>
@Kshitij09
Kshitij09 / ComposeAutoCompleteTextField.kt
Last active April 3, 2023 10:06
AutoCompleteTextView implemented in Jetpack Compose.
@Composable
fun AutoCompleteTextField(
initialText: String,
itemList: List<String>,
onQuery: (String) -> Unit,
onClearResults: () -> Unit,
modifier: Modifier = Modifier
) {
val (field, changeField) = savedInstanceState(saver = TextFieldValue.Saver) { TextFieldValue(text = initialText) }
LaunchedEffect(subject = field.text) {
@Zhuinden
Zhuinden / MainActivity.kt
Last active December 30, 2022 09:40
Fragment multiple tabs without remove or replace
class MainActivity : AppCompatActivity() {
private lateinit var swipeFragment: SwipeFragment
private lateinit var favoritesFragment: FavoritesFragment
private lateinit var newsFragment: NewsFragment
private val fragments: Array<out Fragment> get() = arrayOf(swipeFragment, favoritesFragment, newsFragment)
private fun selectFragment(selectedFragment: Fragment) {
var transaction = supportFragmentManager.beginTransaction()
fragments.forEachIndexed { index, fragment ->
@cedrickring
cedrickring / ColoredShadow.kt
Last active September 5, 2024 21:56
Draw a colored shadow in Android Jetpack Compose
/*
Copyright 2020 Cedric Kring.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
@BhavyaRattan
BhavyaRattan / ScaleItemOnTouchListener.kt
Created September 26, 2020 14:21
Magic Touch Recycler
class ScaleItemOnTouchListener : RecyclerView.OnItemTouchListener {
private var previousX = 0f
private var previousY = 0f
private var previousMotionX = 0f
private var previousMotionY = 0f
private object Constants {
const val SCALE_DEFAULT = 1f
@antonshilov
antonshilov / TreeRenderer.kt
Last active July 1, 2024 18:49
Simple tree hierarchy rendering with Jetpack Compose
package com.example.myapplication
import androidx.compose.animation.AnimatedVisibility
import androidx.compose.animation.ExperimentalAnimationApi
import androidx.compose.foundation.Box
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.Spacer
@vidyesh95
vidyesh95 / MainActivity.java
Last active April 14, 2023 21:28
How to create carousel viewpager2 or infinite loop/endless scroll in android viewpager2
public class MainActivity extends AppCompatActivity {
ViewPager2 viewPager2;
private Handler headerHandler = new Handler();
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);