Skip to content

Instantly share code, notes, and snippets.

View duanhong169's full-sized avatar
💭
I may be slow to respond.

Hong Duan duanhong169

💭
I may be slow to respond.
View GitHub Profile
/**
* 该Drawable能够为与之绑定的ImageView保持一个BitmapWorkerTask(AsyncTask)的引用,使得
* BitmapWorkerTask能够在需要的时候被取消,并且保证只有最后与ImageView绑定的BitmapWorkerTask
* 才能够更新ImageView
*/
private static class AsyncDrawable extends BitmapDrawable {
private final WeakReference<BitmapWorkerTask> bitmapWorkerTaskReference;
/**
* bitmap参数是占位图片(placeholder),代表图片正在加载中
public static int calculateInSampleSize(BitmapFactory.Options options,
int reqWidth, int reqHeight) {
// 从BitmapFactory.Options中获取图片的原始高度和宽度
final int height = options.outHeight;
final int width = options.outWidth;
int inSampleSize = 1;
if (height > reqHeight || width > reqWidth) {
// 计算原始尺寸与显示尺寸的比例
public static Bitmap decodeSampledBitmapFromDescriptor(
FileDescriptor fileDescriptor, int reqWidth,
int reqHeight, ImageCache cache) {
// 设置inJustDecodeBounds=true来获取图片的尺寸
final BitmapFactory.Options options = new BitmapFactory.Options();
options.inJustDecodeBounds = true;
BitmapFactory.decodeFileDescriptor(fileDescriptor, null, options);
// 计算采样率
//设置状态
private void setPresence(int code){
if(connection == null) return;
Presence presence;
switch(code){
case 0:
presence = new Presence(Presence.Type.available);
connection.sendPacket(presence);
Log.v(TAG, "设置在线");
break;
@duanhong169
duanhong169 / LICENSE.txt
Created February 20, 2012 14:59 — forked from aemkei/LICENSE.txt
Binary Tetris - 140byt.es
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
Version 2, December 2004
Copyright (C) 2011 YOUR_NAME_HERE <YOUR_URL_HERE>
Everyone is permitted to copy and distribute verbatim or modified
copies of this license document, and changing it is allowed as long
as the name is changed.
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE