Skip to content

Instantly share code, notes, and snippets.

View RahulSDeshpande's full-sized avatar
☑️
Code • Jam • Shoot | Repeat

Rahul RahulSDeshpande

☑️
Code • Jam • Shoot | Repeat
View GitHub Profile
@orwir
orwir / SharedPreferencesExtensions.kt
Last active March 12, 2024 09:27
Kotlin extensions for shared preferences
import android.content.Context
import android.content.SharedPreferences
import kotlin.reflect.KProperty
/**
* Creates delegate for property from [prefs] with the key presented as className+propertyName.
* @param T type of the property
* @param defaultValue is used if property not set
* @return wrapper for property accessors
*/
@abhaysood
abhaysood / medium_rider_redesign_blog_example.kt
Created March 18, 2018 20:04
A simple component which is created when user clicks the cancel order button in the app. It is responsible for showing a confirmation dialog and actually cancelling the order by making an API call.
class OrderCancellationComponent(private val context: Context,
private val api: Api,
private val orderNumber: String) {
interface Callbacks {
fun onOrderCancelledSuccessfully()
fun onOrderCancellationFailed()
}
var callbacks: Callbacks? = null // Callbacks for communication with the parent component
import android.os.Bundle
import android.support.v7.app.AppCompatActivity
class SplashActivity: AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
// Make sure this is before calling super.onCreate
setTheme(R.style.AppTheme)
super.onCreate(savedInstanceState)
@oakkub
oakkub / DialogExtensions.kt
Last active December 27, 2023 04:32
Kotlin extension functions for creating AlertDialog in a DSL way
import android.annotation.SuppressLint
import android.app.Activity
import android.app.AlertDialog
import android.content.Context
import android.support.annotation.StringRes
import android.support.v4.app.Fragment
import android.view.LayoutInflater
import android.view.View
import android.widget.Button
import android.widget.TextView
@ryneli
ryneli / gist:bc4ea5b679a75b940a44d4bc967e2f54
Created May 2, 2017 17:54
android elevation translationz on ImageView
v.setOutlineProvider(ViewOutlineProvider.BOUNDS);
v.setElevation(10.0);
v.setTranslationZ(10.0);
@kmerrell42
kmerrell42 / gist:b4ff31733c562a3262ee9a42f5704a89
Created February 23, 2017 22:08
Using headers from a WebView.load(...) response. Kinda ugly implementation since it requires exposing the networking implementation at the "view" level.
package io.mercury.monkeybutt.webviewintercept;
import android.annotation.TargetApi;
import android.os.Build;
import android.support.annotation.NonNull;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.webkit.WebResourceRequest;
import android.webkit.WebResourceResponse;
import android.webkit.WebView;
@faruktoptas
faruktoptas / KeyboardSensitiveRelativeLayout.java
Last active November 3, 2023 17:50
A layout that detects Soft Keyboard is visible or not.
public class KeyboardSensitiveRelativeLayout extends RelativeLayout {
private OnKeyboardShowHideListener listener;
public KeyboardSensitiveRelativeLayout(Context context) {
super(context);
}
public KeyboardSensitiveRelativeLayout(Context context, AttributeSet attrs) {
super(context, attrs);
@bpr10
bpr10 / ImageDownloadManager.java
Last active November 29, 2021 10:26
This is a simple ImageDownloader which uses Picasso do download images and write them to a folder.
import android.content.Context;
import android.graphics.Bitmap;
import android.net.Uri;
import android.os.Handler;
import android.os.Looper;
import android.util.Log;
import com.squareup.picasso.MemoryPolicy;
import com.squareup.picasso.Picasso;
import com.squareup.picasso.RequestCreator;
@SeanJM
SeanJM / generateId.ts
Last active September 20, 2017 14:39
A TypeScript function to generate a random ID
interface ILib {
alpha: string[],
number: string[],
symbols: string[]
}
type Key = keyof ILib;
const lib : ILib = {
alpha: [