WEB开发网
开发学院手机开发Android 开发 Android 用代理模式处理海量高频数据更新 阅读

Android 用代理模式处理海量高频数据更新

 2010-12-18 08:04:10 来源:WEB开发网   
核心提示:**/public class ColorRefreshTask extends TimerTask {private RefreshHandlerInterface refreshHandler;private final static int DELAY_ONCE =200;private final static

*

*/

public class ColorRefreshTask extends TimerTask {

private RefreshHandlerInterface refreshHandler;

private final static int DELAY_ONCE =200;

private final static int TOTAL_RUNTIME = 1500;

private final static int POWER_16_16 = 16 * 16* 16 * 16 * 16 * 16;

private final static int INCREASE_ONCE = 0xff / (TOTAL_RUNTIME / DELAY_ONCE);

private int color;

private Object id;

private int startTime;

private int alphaChannel;

/**

*

* @param color ( current background color)

* @param id id of the updated view

*/

public ColorRefreshTask(RefreshHandlerInterface refreshHandler, int color, Object id) {

super();

Log.d("color", "ready to set color!");

this.color = color;

this.id = id;

this.startTime = 0;

this.alphaChannel = 0;

this.refreshHandler = refreshHandler;

}

public void run(){

int colorComm = color - 0xff000000; //RGB color value;

int currColor = 0;

if(startTime < TOTAL_RUNTIME) {

startTime += DELAY_ONCE;

alphaChannel += INCREASE_ONCE;

currColor = POWER_16_16 * alphaChannel + colorComm;

//Log.d("color", Integer.toHexString(currColor));

sendMsg(currColor);

refreshHandler.getHandler().postDelayed(this,DELAY_ONCE);

}

else {

sendMsg(currColor <= color ? color : 0 );

cancel();

}

}

public void startTimer(){

refreshHandler.getHandler().postDelayed(this,DELAY_ONCE);

}

private void sendMsg(final int currColor){

final Runnable myUpdateResults = new Runnable() {

public void run() {

refreshHandler.updateBackground( id, currColor);


  点击下载:php?id=1364" rel="nofollow">源码下载

上一页  1 2 3 4 5 6  下一页

Tags:Android 代理 模式

编辑录入:爽爽 [复制链接] [打 印]
赞助商链接