Skip to content

Instantly share code, notes, and snippets.

View Orange168's full-sized avatar
😃

Quentin Marvin Orange168

😃
View GitHub Profile
@Orange168
Orange168 / SocketIntterruptHandler.java
Created March 2, 2019 14:58
[多线程]java不支持中断的多线程处理#多线程#中断
import java.io.IOException;
import java.io.InputStream;
import java.net.Socket;
public class Test32 extends Thread {
public static final int BUF_SIZE = 512;
Socket socket;
InputStream in;
@Orange168
Orange168 / RetryInfo.java
Created October 16, 2018 07:30
[Java 读取写入文件M5等额外信息] #Java#md5#
static class RetryInfo {
String md5;
String times;
RetryInfo(String md5, String times) {
this.md5 = md5;
this.times = times;
}
static RetryInfo readRetryProperty(File infoFile) {
@Orange168
Orange168 / ChangeTextBehaviorTest.java
Created October 7, 2018 15:46
[UIAutomator] UIAutomator #test #android
/*
* Copyright 2015, The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
@Orange168
Orange168 / TypedArray.java
Created September 9, 2018 15:29
[获取xml属性值] #UI#Android
final TypedArray a = context.obtainStyledAttributes(attrs,
R.styleable.DialogPreference, defStyleAttr, defStyleRes);
mDialogTitle = TypedArrayUtils.getString(a, R.styleable.DialogPreference_dialogTitle,
R.styleable.DialogPreference_android_dialogTitle);
mDialogIcon = TypedArrayUtils.getDrawable(a, R.styleable.DialogPreference_dialogIcon,
R.styleable.DialogPreference_android_dialogIcon);
mDialogLayoutResId = TypedArrayUtils.getResourceId(a,
R.styleable.DialogPreference_dialogLayout,
R.styleable.DialogPreference_android_dialogLayout, 0);
@Orange168
Orange168 / Drawable.java
Last active September 9, 2018 15:25
[获取Preference.xml中的icon] #UI #Android #Bitmap
final Drawable icon = mPreference.getDialogIcon();
if (icon == null || icon instanceof BitmapDrawable) {
mDialogIcon = (BitmapDrawable) icon;
} else {
final Bitmap bitmap = Bitmap.createBitmap(icon.getIntrinsicWidth(),
icon.getIntrinsicHeight(), Bitmap.Config.ARGB_8888);
final Canvas canvas = new Canvas(bitmap);
icon.setBounds(0, 0, canvas.getWidth(), canvas.getHeight());
icon.draw(canvas);
mDialogIcon = new BitmapDrawable(getResources(), bitmap);
@Orange168
Orange168 / MainThreadDisposable.java
Created September 3, 2018 13:09
[主线程运行] #RxJava
public abstract class MainThreadDisposable implements Disposable {
/**
* Verify that the calling thread is the Android main thread.
* <p>
* Calls to this method are usually preconditions for subscription behavior which instances of
* this class later undo. See the class documentation for an example.
*
* @throws IllegalStateException when called from any other thread.
*/
public static void verifyMainThread() {
@Orange168
Orange168 / checkMainThread.java
Created September 3, 2018 12:34
[Observer 返回空] #RxJava
public static boolean checkMainThread(Observer<?> observer) {
if (Looper.myLooper() != Looper.getMainLooper()) {
observer.onSubscribe(Disposables.empty());
observer.onError(new IllegalStateException(
"Expected to be called on the main thread but was " + Thread.currentThread().getName()));
return false;
}
return true;
}
@Orange168
Orange168 / AndroidSchedulers.mainThread.java
Last active September 7, 2018 08:43
[RxJava 主线程运行] 任何时候都在主线程运行 #RxJava
AndroidSchedulers.mainThread().scheduleDirect(new Runnable() {
@Override public void run() {
onDispose();
}
});
@Orange168
Orange168 / OKHttp.java
Created August 19, 2018 09:41
[OKHttp] OKhttp使用
//1. 同步请求
OkHttpClient client = new OkHttpClient();//创建OkHttpClient对象
Request request = new Request.Builder()
.url("http://www.baidu.com")//请求接口。如果需要传参拼接到接口后面。
.build();//创建Request 对象
Response response = null;
response = client.newCall(request).execute();//得到Response 对象
//2. 异步
OkHttpClient client = new OkHttpClient();
Request request = new Request.Builder()
@Orange168
Orange168 / ArrayCopy.java
Created July 14, 2018 02:24
[不同类型数组复制] 数组复制#不同类型数组复制#Java#Array
public static Object goodCopyOf(Object a, int newLength)
{
Class cl = a.getClass();
if (!cl.isArray()) return null;
Class componentType = cl.getComponentType();
int length = Array.getLength(a);
Object newArray = Array.newInstance(componentType, newLength);
System.arraycopy(a, 0, newArray, 0, Math.min(length, newLength));
return newArray;
}