Skip to content

Instantly share code, notes, and snippets.

View Sagar0-0's full-sized avatar
πŸ›

Sagar Sagar0-0

πŸ›
View GitHub Profile
@Sagar0-0
Sagar0-0 / DragSelectionItemTouchListener
Created April 10, 2025 04:14
This Kotlin class implements a RecyclerView.OnItemTouchListener that enables drag-to-select behavior in a recyclerview grid. It tracks touch gestures, calculates item ranges, and triggers selection callbacks. Auto-scroll is supported when dragging near the top or bottom of the RecyclerView. Useful for enabling intuitive multi-item selection in p…
import android.content.Context
import android.content.res.Resources
import android.view.MotionEvent
import android.view.animation.LinearInterpolator
import android.widget.OverScroller
import androidx.recyclerview.widget.RecyclerView
class DragSelectionItemTouchListener : RecyclerView.OnItemTouchListener {
private var isActive = false
private var start = RecyclerView.NO_POSITION
@Sagar0-0
Sagar0-0 / PDFViewer.kt
Created June 4, 2024 15:39
Complete gist of the Custom Compose PDFViewer
import android.graphics.Bitmap
import android.graphics.pdf.PdfRenderer
import android.os.ParcelFileDescriptor
import android.util.Log
import androidx.compose.foundation.Image
import androidx.compose.foundation.background
import androidx.compose.foundation.border
import androidx.compose.foundation.gestures.rememberTransformableState
import androidx.compose.foundation.gestures.transformable
import androidx.compose.foundation.layout.Arrangement
@Sagar0-0
Sagar0-0 / AppPDFViewer.kt
Created June 4, 2024 15:04
Custom PDFViewer in Compose
import android.graphics.Bitmap
import android.graphics.pdf.PdfRenderer
import android.os.ParcelFileDescriptor
import android.util.Log
import androidx.compose.foundation.Image
import androidx.compose.foundation.background
import androidx.compose.foundation.border
import androidx.compose.foundation.gestures.rememberTransformableState
import androidx.compose.foundation.gestures.transformable
import androidx.compose.foundation.layout.Arrangement
@Sagar0-0
Sagar0-0 / MainActivity.kt
Created November 28, 2023 05:39
Detect Shake Event in Android
class MainActivity : ComponentActivity(), SensorEventListener {
private var sensorManager : SensorManager? = null
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
sensorManager = getSystemService(SENSOR_SERVICE)
as SensorManager
val sensor = sensorManager!!
@Sagar0-0
Sagar0-0 / WeatherContract.java
Created September 18, 2021 19:09 — forked from udacityandroid/WeatherContract.java
Contract class for a weather application called Sunshine
/*
* Copyright (C) 2014 The Android Open Source Project
*
* 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