Skip to content

Instantly share code, notes, and snippets.

@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 / DragLinearLayout.java
Created September 7, 2016 03:17
DragLinearLayout
/**
* copy from github:https://github.com/justasm/DragLinearLayout
* <p/>
* Edited by @author chensuilun
* add support for HORIZONTAL , simplify code , some useful callback ,add OverScroll constrain , long click to drag support
*/
public class DragLinearLayout extends LinearLayout {
private static final String TAG = DragLinearLayout.class.getSimpleName();
private static final long NOMINAL_SWITCH_DURATION = 150;
private static final long MIN_SWITCH_DURATION = NOMINAL_SWITCH_DURATION;
@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" />
@BCsl
BCsl / StatusBarCompat.java
Last active April 13, 2018 11:01
状态栏着色工具类,不需要再繁琐的配style
/**
* https://github.com/niorgai/StatusBarCompat
* */
public class StatusBarCompat {
private static final int COLOR_TRANSLUCENT = Color.parseColor("#00000000");
public static final int DEFAULT_COLOR_ALPHA = 112;
/**
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 / 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;
@BCsl
BCsl / BaseFragment.java
Last active March 27, 2017 07:32
在内存重启的时候自动恢复可见状态的Fragment,避免重叠现象,懒加载的Fragment
public abstract class BaseFragment extends Fragment {
public static final String IS_SHOW = "is_show";
protected View mRootView;
@Override
public void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (BuildConfig.DEBUG) {
Log.d(getClass().getSimpleName(), "onCreate:");
}
/**
* 在内存重启的时候自动恢复可见状态的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) {
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;