Skip to content

Instantly share code, notes, and snippets.

@BCsl
BCsl / AndroidLogKotlin.xml
Created May 18, 2019 10:20 — forked from goodev/AndroidLogKotlin.xml
Android log live template for kotlin:
<templateSet group="AndroidLogKotlin">
<template name="logm" value="android.util.Log.d(TAG, $FORMAT$)" description="Log method name and its arguments" toReformat="true" toShortenFQNames="true">
<variable name="FORMAT" expression="groovyScript(&quot;def params = _2.collect {it + ' = [$' + it + ']'}.join(', '); return '\&quot;' + _1 + '() called' + (params.empty ? '' : ' with: ' + params) + '\&quot;'&quot;, kotlinFunctionName(), functionParameters())" defaultValue="" alwaysStopAt="false" />
<context>
<option name="KOTLIN_STATEMENT" value="true" />
</context>
</template>
<template name="logd" value="android.util.Log.d(TAG, &quot;$METHOD_NAME$: $content$&quot;)" description="Log.d(String)" toReformat="true" toShortenFQNames="true">
<variable name="METHOD_NAME" expression="kotlinFunctionName()" defaultValue="" alwaysStopAt="false" />
<variable name="content" expression="" defaultValue="" alwaysStopAt="true" />
Pick Audio file from Gallery:
//Use MediaStore.Audio.Media.EXTERNAL_CONTENT_URI
Intent intent = new Intent(Intent.ACTION_PICK, MediaStore.Audio.Media.EXTERNAL_CONTENT_URI);
Pick Video file from Gallery:
//Use MediaStore.Audio.Media.EXTERNAL_CONTENT_URI
Intent intent = new Intent(Intent.ACTION_PICK, MediaStore.Video.Media.EXTERNAL_CONTENT_URI);
Pick Image from gallery:
@BCsl
BCsl / DownloadManagerRx.java
Last active December 8, 2017 07:51
多线程断点下载
/**
* Created by chensuilun on 2017/12/08.
*/
public class DownloadManagerRx implements IDownloadListener {
private static final String TAG = "DownloadManagerRx";
private static DownloadManagerRx mInstance;
private HashMap<Object, Disposable> mRunningRequest;
private Map<Object, Float> mProgress;
private List<IDownloadListener> mIDownloadListeners;
@BCsl
BCsl / NTUSUtils.java
Last active September 17, 2022 12:13
NTP 网络时间
/**
* Created by chensuilun on 2017/7/4.
*/
public class NTUSUtils {
private static final String TAG = "NTUSUtils";
private static final String NTP_TRUSTED_TIME = "android.util.NtpTrustedTime";
private static final String GET_INSTANCE = "getInstance";//private NtpTrustedTime getInstance(Context context)
private static final String FORCE_REFRESH = "forceRefresh"; //public boolean forceRefresh()
private static final String GET_CACHED_NTP_TIME = "getCachedNtpTime";//public long getCachedNtpTime()
private static Context sContext = AppApplication.getContext();
@BCsl
BCsl / IMMLeaks.java
Created March 30, 2017 12:20 — forked from pyricau/IMMLeaks.java
"Fix" for InputMethodManager leaking the last focused view: https://code.google.com/p/android/issues/detail?id=171190
import android.app.Activity;
import android.app.Application;
import android.content.Context;
import android.content.ContextWrapper;
import android.os.Bundle;
import android.os.Looper;
import android.os.MessageQueue;
import android.util.Log;
import android.view.View;
import android.view.ViewTreeObserver;
package com.xinghui.notificationlistenerservicedemo;
import android.app.ActivityManager;
import android.app.Service;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.os.IBinder;
import android.os.Process;
/**
* 在内存重启的时候自动恢复可见状态的Fragment,避免重叠现象
* 但同时不要忘了在Activity中判断`savedInstanceState`为null的时候才操作Fragment
* Created by chensuilun on 16-8-9.
*/
public abstract class BaseRestoreFragment extends Fragment {
public static final String IS_SHOW = "is_show";
protected View mRootView;
@Override
public void onCreate(@Nullable Bundle savedInstanceState) {
@BCsl
BCsl / ColorUtil
Created December 29, 2016 11:10 — forked from martintreurnicht/ColorUtil
Lighten and darken colors in android
public static int lighten(int color, double fraction) {
int red = Color.red(color);
int green = Color.green(color);
int blue = Color.blue(color);
red = lightenColor(red, fraction);
green = lightenColor(green, fraction);
blue = lightenColor(blue, fraction);
int alpha = Color.alpha(color);
return Color.argb(alpha, red, green, blue);
}
@BCsl
BCsl / app-build.gradle
Created November 3, 2016 07:03
Gradle dependency
def supportLibraryVersion = '24.2.1'
ext.deps = [
supportCompat: "com.android.support:support-compat:$supportLibraryVersion",
]
@BCsl
BCsl / ColorStateGenerator.java
Last active November 1, 2016 10:17
Easy way to generate ColorStateList
class ColorStateGenerate{
// 灰度
public static int greyer(int color) {
int blue = (color & 0x000000FF) >> 0;
int green = (color & 0x0000FF00) >> 8;
int red = (color & 0x00FF0000) >> 16;
int grey = Math.round(red * 0.299f + green * 0.587f + blue * 0.114f);
return Color.argb(0xff, grey, grey, grey);
}