Java Code Examples for android.os.Handler.obtainMessage()

The following are Jave code examples for showing how to use obtainMessage() of the android.os.Handler class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
Example 1
Project: WearTools   File: WTBothway.java   Source Code and License Vote up 6 votes
/**
 * 注册监听响应的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);
}
 
Example 2
Project: WearTools   File: WTBothway.java   Source Code and License Vote up 6 votes
/**
 * 注册监听响应的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);
}
 
Example 3
Project: CodeScaner   File: PreviewCallback.java   Source Code and License Vote up 6 votes
@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");
    }
  }
 
Example 4
Project: appinventor-extensions   File: PreviewCallback.java   Source Code and License Vote up 5 votes
@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");
  }
}
 
Example 5
Project: keepass2android   File: PreviewCallback.java   Source Code and License Vote up 5 votes
@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");
  }
}
 
Example 6
Project: android-mrz-reader   File: PreviewCallback.java   Source Code and License Vote up 5 votes
@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");
  }
}
 
Example 7
Project: CXJPadProject   File: SobotBaseActivity.java   Source Code and License Vote up 5 votes
/**
 * 发送声音的定时的任务
 * 
 * @param handler
 */
public void sendVoiceTimeTask(Handler handler) {
	Message message = handler.obtainMessage();
	message.what = ZhiChiConstant.voiceIsRecoding;
	voiceTimerLong = voiceTimerLong + 500;
	message.obj = voiceTimerLong;
	handler.sendMessage(message);
}
 
Example 8
Project: tvConnect_android   File: PreviewCallback.java   Source Code and License Vote up 5 votes
@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");
  }
}
 
Example 9
Project: weex-3d-map   File: PreviewCallback.java   Source Code and License Vote up 5 votes
@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");
  }
}
 
Example 10
Project: android_viewtracker   File: TrackerManager.java   Source Code and License Vote up 5 votes
/**
 * 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");
}
 
Example 11
Project: LifeHelper   File: PreviewCallback.java   Source Code and License Vote up 5 votes
@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");
    }
}
 
Example 12
Project: QRScanner   File: PreviewCallback.java   Source Code and License Vote up 5 votes
@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");
    }
}
 
Example 13
Project: anyRTC-RTCP-Android   File: PreviewCallback.java   Source Code and License Vote up 5 votes
@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");
	}
}
 
Example 14
Project: Zxing-Custom   File: PreviewCallback.java   Source Code and License Vote up 5 votes
@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");
  }
}
 
Example 15
Project: xlight_android_native   File: xltDevice.java   Source Code and License Vote up 5 votes
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);
            }
        }
    }
}
 
Example 16
Project: xlight_android_native   File: xltDevice.java   Source Code and License Vote up 5 votes
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);
            }
        }
    }
}
 
Example 17
Project: androidscan   File: PreviewCallback.java   Source Code and License Vote up 5 votes
@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");
    }
}
 
Example 18
Project: RLibrary   File: PreviewCallback.java   Source Code and License Vote up 5 votes
@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");
    }
}
 
Example 19
Project: PictureShow   File: AlbumSetPage.java   Source Code and License Vote up 5 votes
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;
            }
        }

    };

}
 
Example 20
Project: PictureShow   File: AlbumPage.java   Source Code and License Vote up 4 votes
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;
            }
        }

    };

}