This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
static class RetryInfo { | |
String md5; | |
String times; | |
RetryInfo(String md5, String times) { | |
this.md5 = md5; | |
this.times = times; | |
} | |
static RetryInfo readRetryProperty(File infoFile) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
AndroidSchedulers.mainThread().scheduleDirect(new Runnable() { | |
@Override public void run() { | |
onDispose(); | |
} | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | |
} |
NewerOlder