Skip to content

Instantly share code, notes, and snippets.

View wutianlong's full-sized avatar

Superman wutianlong

View GitHub Profile
@wutianlong
wutianlong / TextEllipse.java
Last active February 1, 2016 02:59
设置TextView最多显示多少行string
public static void makeEllipseEnd(TextView textView, String str, int maxLine) {
textView.setText(str);
textView.getViewTreeObserver().addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener() {
@Override
public boolean onPreDraw() {
textView.getViewTreeObserver().removeOnPreDrawListener(this);
if (textView.getLineCount() > maxLine) {
int offset = textView.getLayout().getLineEnd(maxLine - 1);
String text = textView.getText().subSequence(0, offset).toString();
if (text.endsWith("\n")) {
@wutianlong
wutianlong / android studio .gitignore
Last active February 1, 2016 02:58
AndroidStudio 注释内容
# AS中注释掉内容
*.gradle
gradle*
build
.idea
*.iml
local.properties
@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 / 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 / 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 / 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 / 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 / 优化后的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) {
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 / 获取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 {