Skip to content

Instantly share code, notes, and snippets.

HelloCsl BCsl

Block or report user

Report or block BCsl

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@BCsl
BCsl / AndroidLogKotlin.xml
Created May 18, 2019 — forked from goodev/AndroidLogKotlin.xml
Android log live template for kotlin:
View AndroidLogKotlin.xml
<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" />
View SELECT MEDIA IMAGE or VIDEO - ANDROID
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 Dec 8, 2017
多线程断点下载
View DownloadManagerRx.java
/**
* 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 Nov 26, 2018
NTP 网络时间
View NTUSUtils.java
/**
* 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 Mar 30, 2017 — forked from pyricau/IMMLeaks.java
"Fix" for InputMethodManager leaking the last focused view: https://code.google.com/p/android/issues/detail?id=171190
View IMMLeaks.java
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;
View NotificationCollectorMonitorService.java
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;
View BaseRestoreFragment.java
/**
* 在内存重启的时候自动恢复可见状态的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 Dec 29, 2016 — forked from martintreurnicht/ColorUtil
Lighten and darken colors in android
View ColorUtil
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);
}
View app-build.gradle
def supportLibraryVersion = '24.2.1'
ext.deps = [
supportCompat: "com.android.support:support-compat:$supportLibraryVersion",
]
@BCsl
BCsl / ColorStateGenerator.java
Last active Nov 1, 2016
Easy way to generate ColorStateList
View ColorStateGenerator.java
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);
}
You can’t perform that action at this time.