本文整理匯總了Java中android.os.Handler.obtainMessage方法的典型用法代碼示例。如果您正苦於以下問題:Java Handler.obtainMessage方法的具體用法?Java Handler.obtainMessage怎麽用?Java Handler.obtainMessage使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類android.os.Handler
的用法示例。
在下文中一共展示了Handler.obtainMessage方法的14個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: regResponseDataListener
import android.os.Handler; //導入方法依賴的package包/類
/**
* 注冊監聽響應的DataMap.
*
* @param context c
* @param dataListenerKey listerId 用於在map中標識監聽器
* @param handler 用於回傳響應的數據
* @param sendBothwayId 發送時的BothwayId.
*/
private static void regResponseDataListener(
final Context context, final long dataListenerKey,
@NonNull final Handler handler, @NonNull final byte[] sendBothwayId) {
WTResponseDataListener listener = new WTResponseDataListener() {
@Override
public void onResponseDataChanged(byte[] bothwayId, String path, DataMap dataMap) {
//判斷與發送時的path是否對應,避免同時發送2個請求時響應混亂。
if (!Arrays.equals(sendBothwayId, bothwayId)) return;
//雙向通訊響應path格式為:/RE/WTBothway/{nanoTime}/xxx
Message msg = handler.obtainMessage(HANDLER_RECEIVE_RESPONSE);
msg.obj = new ResponseDataBean(dataMap, path);
handler.sendMessage(msg);
if (dataListenerMap.get(dataListenerKey) != null) {
WTRegister.removeDataListener(context, dataListenerMap.get(dataListenerKey));
dataListenerMap.remove(dataListenerKey);
}
}
};
dataListenerMap.put(dataListenerKey, listener);
WTRegister.addDataListener(context, listener);
}
示例2: onPreviewFrame
import android.os.Handler; //導入方法依賴的package包/類
@Override
public void onPreviewFrame(byte[] data, Camera camera) {
Point cameraResolution = configManager.getCameraResolution();
Handler thePreviewHandler = previewHandler;
if (cameraResolution != null && thePreviewHandler != null) {
// Message message = thePreviewHandler.obtainMessage(previewMessage, cameraResolution.x,
// cameraResolution.y, data);
Point screenResolution = configManager.getScreenResolution();
Message message;
if (screenResolution.x < screenResolution.y){
// portrait
message = thePreviewHandler.obtainMessage(previewMessage, cameraResolution.y,
cameraResolution.x, data);
} else {
// landscape
message = thePreviewHandler.obtainMessage(previewMessage, cameraResolution.x,
cameraResolution.y, data);
}
message.sendToTarget();
previewHandler = null;
} else {
Log.d(TAG, "Got preview callback, but no handler or resolution available");
}
}
示例3: regResponseMsgListener
import android.os.Handler; //導入方法依賴的package包/類
/**
* 注冊監聽響應的msg.
*
* @param context c
* @param msgListenerKey listerId 用於在map中標識監聽器
* @param handler 用於回傳響應的數據
* @param sendBothwayId 發送時的BothwayId.
*/
private static void regResponseMsgListener(
final Context context, final long msgListenerKey,
@NonNull final Handler handler, @NonNull final byte[] sendBothwayId) {
WTResponseMsgListener listener = new WTResponseMsgListener() {
@Override
public void onResponseMsgReceived(String path, byte[] data, byte[] bothwayId) {
//判斷與發送時的path是否對應,避免同時發送2個請求時響應混亂。
if (!Arrays.equals(sendBothwayId, bothwayId)) return;
//雙向通訊響應path格式為:/RE/WTBothway/{nanoTime}/xxx
Message msg = handler.obtainMessage(HANDLER_RECEIVE_RESPONSE);
Bundle bundle = new Bundle();
bundle.putByteArray("data", data);
bundle.putString("path", path);
msg.setData(bundle);
handler.sendMessage(msg);
if (msgListenerMap.get(msgListenerKey) != null) {
WTLog.v(TAG, "Remove response msg listener.");
WTRegister.removeMessageListener(context, msgListenerMap.get(msgListenerKey));
msgListenerMap.remove(msgListenerKey);
}
}
};
WTLog.v(TAG, "Register response msg listener.");
msgListenerMap.put(msgListenerKey, listener);
WTRegister.addMessageListener(context, listener);
}
示例4: onPreviewFrame
import android.os.Handler; //導入方法依賴的package包/類
@Override
public void onPreviewFrame(byte[] data, Camera camera) {
Point cameraResolution = configManager.getCameraResolution();
Handler thePreviewHandler = previewHandler;
if (cameraResolution != null && thePreviewHandler != null) {
Message message = thePreviewHandler.obtainMessage(previewMessage, cameraResolution.x,
cameraResolution.y, data);
message.sendToTarget();
previewHandler = null;
} else {
Log.d(TAG, "Got preview callback, but no handler or resolution available");
}
}
示例5: sendVoiceTimeTask
import android.os.Handler; //導入方法依賴的package包/類
/**
* 發送聲音的定時的任務
*
* @param handler
*/
public void sendVoiceTimeTask(Handler handler) {
Message message = handler.obtainMessage();
message.what = ZhiChiConstant.voiceIsRecoding;
voiceTimerLong = voiceTimerLong + 500;
message.obj = voiceTimerLong;
handler.sendMessage(message);
}
示例6: batchReport
import android.os.Handler; //導入方法依賴的package包/類
/**
* commit the data for exposure event in batch
*/
private void batchReport() {
long time = System.currentTimeMillis();
Handler handler = ExposureManager.getInstance().getExposureHandler();
Message message = handler.obtainMessage();
message.what = ExposureManager.BATCH_COMMIT_EXPOSURE;
handler.sendMessage(message);
TrackerLog.v("batch report exposure views " + (System.currentTimeMillis() - time) + "ms");
}
示例7: onPreviewFrame
import android.os.Handler; //導入方法依賴的package包/類
@Override
public void onPreviewFrame(byte[] data, Camera camera) {
Point cameraResolution = configManager.getCameraResolution();
Handler thePreviewHandler = previewHandler;
if (cameraResolution != null && thePreviewHandler != null) {
Message message = thePreviewHandler.obtainMessage(previewMessage, cameraResolution.x,
cameraResolution.y, data);
message.sendToTarget();
previewHandler = null;
} else {
Log.d(TAG, "Got preview callback, but no handler or resolution available");
}
}
示例8: onPreviewFrame
import android.os.Handler; //導入方法依賴的package包/類
@Override
public void onPreviewFrame(byte[] data, Camera camera) {
Camera.Size cameraResolution = configManager.getCameraResolution();
Handler thePreviewHandler = previewHandler;
if (cameraResolution != null && thePreviewHandler != null) {
Message message = thePreviewHandler.obtainMessage(previewMessage, cameraResolution.width,
cameraResolution.height, data);
message.sendToTarget();
previewHandler = null;
} else {
Log.d(TAG, "Got preview callback, but no handler or resolution available");
}
}
示例9: onPreviewFrame
import android.os.Handler; //導入方法依賴的package包/類
@Override
public void onPreviewFrame(byte[] data, Camera camera) {
Point cameraResolution = configManager.getCameraResolution();
Handler thePreviewHandler = previewHandler;
if (cameraResolution != null && thePreviewHandler != null) {
Message message = thePreviewHandler.obtainMessage(previewMessage, cameraResolution.x, cameraResolution.y, data);
message.sendToTarget();
previewHandler = null;
} else {
Log.d(TAG, "Got preview callback, but no handler or resolution available");
}
}
示例10: onPreviewFrame
import android.os.Handler; //導入方法依賴的package包/類
@Override
public void onPreviewFrame(byte[] data, Camera camera) {
Point cameraResolution = configManager.getCameraResolution();
Handler thePreviewHandler = previewHandler;
if (cameraResolution != null && thePreviewHandler != null) {
Message message = thePreviewHandler.obtainMessage(previewMessage, cameraResolution.x,
cameraResolution.y, data);
message.sendToTarget();
previewHandler = null;
} else {
Log.d(TAG, "Got preview callback, but no handler or resolution available");
}
}
示例11: sendDeviceStatusMessage
import android.os.Handler; //導入方法依賴的package包/類
public void sendDeviceStatusMessage(final Bundle data) {
Handler handler;
Message msg;
for (int i = 0; i < m_lstEH_DevST.size(); i++) {
handler = m_lstEH_DevST.get(i);
if (handler != null) {
msg = handler.obtainMessage();
if (msg != null) {
msg.setData(data);
handler.sendMessage(msg);
}
}
}
}
示例12: sendSensorDataMessage
import android.os.Handler; //導入方法依賴的package包/類
public void sendSensorDataMessage(final Bundle data) {
Handler handler;
Message msg;
for (int i = 0; i < m_lstEH_SenDT.size(); i++) {
handler = m_lstEH_SenDT.get(i);
if (handler != null) {
msg = handler.obtainMessage();
if (msg != null) {
msg.setData(data);
handler.sendMessage(msg);
}
}
}
}
示例13: init
import android.os.Handler; //導入方法依賴的package包/類
private void init() {
decodeBitmapWidth = PicShowUtils.getAlbumImageWidth(getContext());
LogPrinter.i(TAG,"decodeBitmapWidth:" + decodeBitmapWidth);
myLoadListener = new LoadListener() {
@Override
public void startLoad() {
}
@Override
public void finishLoad(Object[] items) {
Message msg = mainHandler.obtainMessage();
msg.what = UPDATE;
msg.obj = items;
mainHandler.sendMessage(msg);
}
};
dataLoader = new AlbumSetDataLoader(getActivity().getApplication(), myLoadListener);
mainHandler = new Handler() {
@Override
public void handleMessage(Message msg) {
switch (msg.what) {
case UPDATE:
if(gridAdapter != null) {
gridAdapter.setData((Album[]) msg.obj);
}
break;
default:
break;
}
}
};
}
示例14: init
import android.os.Handler; //導入方法依賴的package包/類
private void init() {
decodeBitmapWidth = PicShowUtils.getImageWidth(getApplicationContext());
myLoadListener = new LoadListener() {
@Override
public void startLoad() {
LogPrinter.i(TAG,"startLoad");
}
@Override
public void finishLoad(Object[] items) {
LogPrinter.i(TAG,"finishLoad:" + mAdapter);
Message msg = mainHandler.obtainMessage();
msg.what = UPDATE;
msg.obj = items;
mainHandler.sendMessage(msg);
}
};
bucketID = getIntent().getIntExtra(MediaSetUtils.BUCKET, MediaSetUtils.CAMERA_BUCKET_ID);
albumDataLoader = new AlbumDataLoader(getApplication(), myLoadListener, bucketID);
mainHandler = new Handler() {
@Override
public void handleMessage(Message msg) {
switch (msg.what) {
case UPDATE:
if(mAdapter != null) {
mAdapter.setData((PhotoItem[]) msg.obj);
}
break;
default:
break;
}
}
};
}