Skip to content

Instantly share code, notes, and snippets.

View wutianlong's full-sized avatar

Superman wutianlong

View GitHub Profile
请注意:这种继承Binder类的方式仅适用于Service与绑定的组件处于同一应用程序或进程的情况,当然这也是最普遍的情况。举例来说,在播放音乐应用程序中,可以使用这种方式将一个Activity与Service绑定,而Service用于在后台播放音乐。
参考文章 http://mp.weixin.qq.com/s?__biz=MzA5MzI3NjE2MA==&mid=2650236008&idx=1&sn=c7a1f1de9ee92e6d7a2d00f04821a8c3&scene=0#wechat_redirect
1. Service 类代码==============
public class LocalService extends Service
// Binder given to clients
private final IBinder mBinder = new LocalBinder();
@wutianlong
wutianlong / 获取h5中数据
Last active June 2, 2016 09:13
android webview 获取h5中数据,然后回调给android
内部类不能被混淆,否则h5页面内找不到android中类
-keep class com.sohu.tv.activity.IndividualH5Activity$*{*;}
webView.addJavascriptInterface(new HTMLHandler(), "handler");
webView.loadUrl(getJsOfFetchMeta());
class HTMLHandler {
public void doubleClickDetect(View view){
Observable<Void> observable = RxView.clicks(view).share();
observable.buffer(observable.debounce(200, TimeUnit.MILLISECONDS))
.observeOn(AndroidSchedulers.mainThread())
.subscribe(new Action1<List<Void>>() {
@Override
public void call(List<Void> voids) {
if(voids.size() >= 2){
//double click detected
}
@wutianlong
wutianlong / 优化后的Handler
Last active June 2, 2016 09:13
Handler-Optimized
private WeakReference<ClassName> mActivityWeakReference = new WeakReference<ClassName>(this);
private final Handler mHandler = new InnerHandler(mActivityWeakReference);
private static class InnerHandler extends Handler {
WeakReference<ClassName> activityWeakReference;
InnerHandler(WeakReference<ClassName> activityWeakReference) {
this.activityWeakReference = activityWeakReference;
}
public void handleMessage(android.os.Message msg) {
@wutianlong
wutianlong / HashMap最佳移除元素方案
Last active June 2, 2016 09:14
HashMap 遍历最佳方案,移除元素避免异常
遍历HashMap中元素的最佳方法是什么?
解决方案
这样遍历entrySet:
public static void printMap(Map mp) {
Iterator it = mp.entrySet().iterator();
while (it.hasNext()) {
Map.Entry pair = (Map.Entry)it.next();
@wutianlong
wutianlong / random.txt
Last active February 1, 2016 02:55
高效率生成随机数字
我试着使用Java生成一个随机整数,但是随机被指定在一个范围里。例如,整数范围是5~10,就是说5是最小的随机值,10是最大的。5到10之间的书也可以是生成的随机数。
解决方案
标准的解决方式(Java1.7 之前)如下:
import java.util.Random;
public static int randInt(int min, int max) {
@wutianlong
wutianlong / recompress-apk
Last active February 1, 2016 02:56
压缩apk 文件脚本
#!/bin/bash
function zip_align()
{
TEMP="${1}"
DEST="${2}"
if [ ! -f "${TEMP}" ]; then
echo "${TEMP} is NOT a file"
return
@wutianlong
wutianlong / adb+
Last active February 1, 2016 02:56 — forked from race604/adb+
同时为多台设备安装apk文件
#!/bin/bash
# Script adb+
# Run any command adb provides on all your currently connected devices,
# Or prompt to select one device
showHelp() {
echo "Usage: adb+ [-a] <command>"
echo " -h: show help"
echo " -a: run command on all device"
echo " command: normal adb commands"
@wutianlong
wutianlong / gist:7412f7334afd1eae4c67
Last active February 1, 2016 02:57 — forked from kyze8439690/gist:5bafc99a65a0f4298db3
发布apk之前需要做的事情
1.debug false
2.sign true
3.test proguard
4.change version code
5.upload new apk to umeng and test update works
6.merge master to release branch
7.upload new apk to appstores
@wutianlong
wutianlong / android studio .gitignore
Last active February 1, 2016 02:58
AndroidStudio 注释内容
# AS中注释掉内容
*.gradle
gradle*
build
.idea
*.iml
local.properties