Skip to content

Instantly share code, notes, and snippets.

@pablisco
pablisco / ContextExtensions.kt
Created September 14, 2017 14:45
Fluent Intents
import android.app.Activity
import android.app.Service
import android.content.ComponentName
import android.content.Context
import android.content.Intent
import android.content.Intent.EXTRA_SUBJECT
import android.content.Intent.EXTRA_TEXT
import android.net.Uri
import kotlin.properties.ReadWriteProperty
import kotlin.reflect.KClass
@pablisco
pablisco / gist:da25563d57559dd1d18f165272269b57
Last active April 15, 2022 03:23
ResourcesExceptions.kt
import android.content.Context
import android.content.res.Resources
import android.graphics.drawable.Drawable
import android.support.annotation.AnyRes
import android.support.v4.app.Fragment
import android.support.v4.content.res.ResourcesCompat.*
import android.view.View
val Context.animations
get() = ResourceMapper { resources.getAnimation(it) }
@Nikaoto
Nikaoto / CopyBytes.kt
Last active July 27, 2020 09:31
A function that copies data from input to output (in Kotlin and Java)
//A Kotlin object (singleton) that handles the copying with mulitple different arguments
object CopyBytes {
@Throws(IOException::class)
fun copy(input: InputStream, output: OutputStream) {
//Creating byte array
val buffer = ByteArray(1024)
var length = input.read(buffer)
//Transferring data
@D-clock
D-clock / HanziToPinyin.java
Last active September 20, 2023 06:41
从Android4.2.2原生系统中提取出来的汉字转换成拼音的方案,同时兼容国产ROM
/*
* Copyright (C) 2009 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
@nickbutcher
nickbutcher / MainActivity.java
Last active August 20, 2021 16:15
A quick sample of the new physics-based animation library added in Support Library 25.3.0 docs: https://developer.android.com/reference/android/support/animation/package-summary.html output: https://twitter.com/crafty/status/842055117323026432
/*
* Copyright 2017 Google Inc.
*
* 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
@xingstarx
xingstarx / README.md
Last active December 13, 2016 05:58 — forked from polbins/README.md
Simple RecyclerView Divider

Simple RecyclerView Divider

Simple Horizontal Divider Item Decoration for RecyclerView

    mRecyclerView.addItemDecoration(new SimpleDividerItemDecoration(
            getApplicationContext()
    	));

NOTE: Add item decoration prior to setting the adapter

@AKiniyalocts
AKiniyalocts / EdgeDecorator.java
Created December 8, 2016 21:00
Quick way to add padding to first and last item in recyclerview via decorators
package com.batterii.mobile.ui.component.decorators;
import android.graphics.Rect;
import android.support.v7.widget.RecyclerView;
import android.view.View;
/**
* Created by anthonykiniyalocts on 12/8/16.
*
* Quick way to add padding to first and last item in recyclerview via decorators
@jemshit
jemshit / proguard-rules.pro
Last active February 18, 2025 12:50
Proguard Rules for Android libraries
# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
-keepclassmembers class fqcn.of.javascript.interface.for.webview {
public *;
}
### RxJava, RxAndroid (https://gist.github.com/kosiara/487868792fbd3214f9c9)
-keep class rx.schedulers.Schedulers {
public static <methods>;
@xingstarx
xingstarx / CustomeLinkMovementMethod.java
Last active November 10, 2016 05:18
自定义LinkMovementMethod处理textview的链接点击事件
private final RectF touchedLineBounds = new RectF();
@Override
public boolean onTouchEvent(TextView widget, Spannable buffer,
MotionEvent event) {
int action = event.getAction();
if (action == MotionEvent.ACTION_UP ||
action == MotionEvent.ACTION_DOWN) {
int x = (int) event.getX();
@orange1988
orange1988 / Android 命名规范.md
Last active December 19, 2022 03:43
Android 命名规范

在讲解命名规范前,先初略介绍下当前主要的标识符命名法和英文缩写规则。

标识符命名法

标识符命名法最要有四种:

  1. 驼峰(Camel)命名法:又称小驼峰命名法,除首单词外,其余所有单词的第一个字母大写。
  2. 帕斯卡(pascal)命名法:又称大驼峰命名法,所有单词的第一个字母大写
  3. 下划线命名法:单词与单词间用下划线做间隔。
  4. 匈牙利命名法:广泛应用于微软编程环境中,在以Pascal命名法的变量前附加小写序列说明该变量的类型。 量的取名方式为:<scope_> + <prefix_> + 范围前缀,类型前缀,限定词。