@Override public void handleMessage(Message msg) { switch (msg.what) { // It is time to bump the value! case REPORT_MSG: { // Up it goes. int value = ++mValue; // Broadcast to all clients the new value. final int N = mCallbacks.beginBroadcast(); for (int i = 0; i < N; i++) { try { mCallbacks.getBroadcastItem(i).valueChanged(value); } catch (RemoteException e) { // The RemoteCallbackList will take care of removing // the dead object for us. } } mCallbacks.finishBroadcast(); // Repeat every 1 second. sendMessageDelayed(obtainMessage(REPORT_MSG), 1 * 1000); } break; default: super.handleMessage(msg); } }
/** * Receive a new geoloc sharing invitation * * @param session Geoloc sharing session */ public void receiveGeolocSharingInvitation(GeolocTransferSession session) { if (logger.isActivated()) { logger.info("Receive geoloc sharing invitation from " + session.getRemoteContact()); } // Extract number from contact String number = PhoneUtils.extractNumberFromUri(session.getRemoteContact()); // Add session in the list GeolocSharingImpl sessionApi = new GeolocSharingImpl(session); GeolocSharingServiceImpl.addGeolocSharingSession(sessionApi); // Broadcast intent related to the received invitation Intent intent = new Intent(GeolocSharingIntent.ACTION_NEW_INVITATION); intent.addFlags(Intent.FLAG_EXCLUDE_STOPPED_PACKAGES); intent.putExtra(GeolocSharingIntent.EXTRA_CONTACT, number); intent.putExtra(GeolocSharingIntent.EXTRA_DISPLAY_NAME, session.getRemoteDisplayName()); intent.putExtra(GeolocSharingIntent.EXTRA_SHARING_ID, session.getSessionID()); AndroidFactory.getApplicationContext().sendBroadcast(intent); // Notify geoloc sharing invitation listeners synchronized (lock) { final int N = listeners.beginBroadcast(); for (int i = 0; i < N; i++) { try { listeners.getBroadcastItem(i).onNewGeolocSharing(session.getSessionID()); } catch (Exception e) { if (logger.isActivated()) { logger.error("Can't notify listener", e); } } } listeners.finishBroadcast(); } }
@Override public void handleMessage(Message msg) { switch (msg.what) { case 1: { // Broadcast to all clients the new value. final int N = mCallbacks.beginBroadcast(); for (int i = 0; i < N; i++) { try { final Location loc = (Location) msg.obj; Ut.dd("mCallbacks.getBroadcastItem(i).newPointWrited"); mCallbacks .getBroadcastItem(i) .newPointWrited(loc.getLatitude(), loc.getLongitude()); } catch (RemoteException e) { // The RemoteCallbackList will take care of removing // the dead object for us. Ut.dd("RemoteException: The RemoteCallbackList will take care of removing"); } } mCallbacks.finishBroadcast(); // sendMessageDelayed(obtainMessage(1), 1*1000); } break; default: super.handleMessage(msg); } }
/** * Receive registration event * * @param state Registration state */ public void notifyRegistrationEvent(boolean state) { // Notify listeners synchronized (lock) { final int N = serviceListeners.beginBroadcast(); for (int i = 0; i < N; i++) { try { if (state) { serviceListeners.getBroadcastItem(i).onServiceRegistered(); } else { serviceListeners.getBroadcastItem(i).onServiceUnregistered(); } } catch (Exception e) { if (logger.isActivated()) { logger.error("Can't notify listener", e); } } } serviceListeners.finishBroadcast(); } }
private void broadcastConnectionStatus(boolean isConnected, boolean willReconnect) { final int broadCastItems = mRosterCallbacks.beginBroadcast(); for (int i = 0; i < broadCastItems; i++) { try { mRosterCallbacks.getBroadcastItem(i).connectionStatusChanged(isConnected, willReconnect); } catch (RemoteException e) { logError("caught RemoteException: " + e.getMessage()); } } mRosterCallbacks.finishBroadcast(); }
private void notifyParticipate(String name, boolean joinOrLeave) { final int len = mCallbacks.beginBroadcast(); for (int i = 0; i < len; i++) { try { // 通知回调 mCallbacks.getBroadcastItem(i).onParticipate(name, joinOrLeave); } catch (RemoteException e) { e.printStackTrace(); } } mCallbacks.finishBroadcast(); }
private synchronized void notifyPersonalDeckObservers() { final int numPersonalDeckCallbacks = mPersonalDeckCallbacks.beginBroadcast(); for (int i = 0; i < numPersonalDeckCallbacks; i++) { try { mPersonalDeckCallbacks.getBroadcastItem(i).publishProgress(mPersonalDeckDownloads); } catch (RemoteException e) { // There is nothing special we need to do if the service has crashed Log.e(AnkiDroidApp.TAG, "RemoteException = " + e.getMessage()); e.printStackTrace(); } } mPersonalDeckCallbacks.finishBroadcast(); }
private synchronized void changeConnectionStatus(String host, String status) { // Broadcast to all clients the new value. final int N = callbackList.beginBroadcast(); for (int i = 0; i < N; ++i) { try { callbackList.getBroadcastItem(i).onConnectionStatusChanged(host, status); } catch (RemoteException e) { // The RemoteCallbackList will take care of removing // the dead object for us. } } callbackList.finishBroadcast(); }
public void setContactTyping(Contact contact, boolean isTyping) { int N = mRemoteListeners.beginBroadcast(); for (int i = 0; i < N; i++) { IChatListener listener = mRemoteListeners.getBroadcastItem(i); try { listener.onContactTyping(ChatSessionAdapter.this, contact, isTyping); } catch (RemoteException e) { // The RemoteCallbackList will take care of removing the // dead listeners. } } mRemoteListeners.finishBroadcast(); }
public void broadcastDeleted(ContactId contact, Set<String> sharingIds) { List<String> ids = new ArrayList<>(sharingIds); final int N = mVideoSharingListeners.beginBroadcast(); for (int i = 0; i < N; i++) { try { mVideoSharingListeners.getBroadcastItem(i).onDeleted(contact, ids); } catch (RemoteException e) { if (logger.isActivated()) { logger.error("Can't notify listener", e); } } } mVideoSharingListeners.finishBroadcast(); }
/** * Receive a new video sharing invitation * * @param session Video sharing session */ public void receiveVideoSharingInvitation(VideoStreamingSession session) { if (logger.isActivated()) { logger.info("Receive video sharing invitation from " + session.getRemoteContact()); } // Extract number from contact String number = PhoneUtils.extractNumberFromUri(session.getRemoteContact()); // Update rich call history VideoContent content = (VideoContent) session.getContent(); RichCallHistory.getInstance() .addVideoSharing( number, session.getSessionID(), VideoSharing.Direction.INCOMING, content, VideoSharing.State.INVITED); // Add session in the list VideoSharingImpl sessionApi = new VideoSharingImpl(session); VideoSharingServiceImpl.addVideoSharingSession(sessionApi); // Broadcast intent related to the received invitation Intent intent = new Intent(VideoSharingIntent.ACTION_NEW_INVITATION); intent.addFlags(Intent.FLAG_EXCLUDE_STOPPED_PACKAGES); intent.putExtra(VideoSharingIntent.EXTRA_CONTACT, number); intent.putExtra(VideoSharingIntent.EXTRA_DISPLAY_NAME, session.getRemoteDisplayName()); intent.putExtra(VideoSharingIntent.EXTRA_SHARING_ID, session.getSessionID()); intent.putExtra(VideoSharingIntent.EXTRA_ENCODING, content.getEncoding()); intent.putExtra(VideoSharingIntent.EXTRA_WIDTH, session.getVideoWidth()); intent.putExtra(VideoSharingIntent.EXTRA_HEIGHT, session.getVideoHeight()); AndroidFactory.getApplicationContext().sendBroadcast(intent); // Notify video sharing invitation listeners synchronized (lock) { final int N = listeners.beginBroadcast(); for (int i = 0; i < N; i++) { try { listeners.getBroadcastItem(i).onNewVideoSharing(session.getSessionID()); } catch (Exception e) { if (logger.isActivated()) { logger.error("Can't notify listener", e); } } } listeners.finishBroadcast(); } }
private void reportToCallbacks( final int token, final int opCode, final ResponseData responseData, final CallbackReporter reporter) { updateLastOperation(responseData); if (DEBUG) { Log.v(TAG, "Start broadcast"); } int c = apiCallbacks.beginBroadcast(); ResponseData noModelData = null; while (c > 0) { --c; try { final ApiMethodCallback callback = apiCallbacks.getBroadcastItem(c); if (DEBUG) { Log.d( TAG, "Report API " + reporter.name + "/op=" + opCode + "/token=" + token + " " + c + ": " + callback); } final boolean requiresModel = (Boolean) apiCallbacks.getBroadcastCookie(c); ResponseData sendingData = responseData; if (!requiresModel) { if (noModelData == null) { noModelData = ResponseData.withoutModel(responseData); } sendingData = noModelData; } reporter.report(callback, token, opCode, sendingData); } catch (final RemoteException e) { Log.e(TAG, "Cannot run callback report method", e); } } apiCallbacks.finishBroadcast(); if (DEBUG) { Log.v(TAG, "Finish broadcast"); } }
public void broadcastStateChanged( ContactId contact, String sharingId, State state, ReasonCode reasonCode) { int rcsState = state.toInt(); int rcsReasonCode = reasonCode.toInt(); final int N = mVideoSharingListeners.beginBroadcast(); for (int i = 0; i < N; i++) { try { mVideoSharingListeners .getBroadcastItem(i) .onStateChanged(contact, sharingId, rcsState, rcsReasonCode); } catch (RemoteException e) { if (logger.isActivated()) { logger.error("Can't notify listener", e); } } } mVideoSharingListeners.finishBroadcast(); }
@Override public boolean handleMessage(Message msg) { int N = callbacks.beginBroadcast(); for (int i = 0; i < N; i++) { try { if (msg.obj == null) { msg.obj = ""; } IDataServiceCallback cb = callbacks.getBroadcastItem(i); cb.valueChanged(msg.what, msg.obj.toString()); } catch (RemoteException e) { e.printStackTrace(); } } callbacks.finishBroadcast(); return false; }
private void dispatchListeners(int message, boolean argument) { synchronized (mListeners) { int N = mListeners.beginBroadcast(); for (int i = 0; i < N; i++) { ITorchCallback l = mListeners.getBroadcastItem(i); try { if (message == DISPATCH_ERROR) { l.onTorchError(); } else if (message == DISPATCH_STATE_CHANGE) { l.onTorchStateChanged(argument); } else if (message == DISPATCH_AVAILABILITY_CHANGED) { l.onTorchAvailabilityChanged(argument); } } catch (RemoteException e) { Log.w(TAG, "Unable to post progress to client listener", e); } } mListeners.finishBroadcast(); } }
/** * コールバックを実行する * * @param changedState 変化後の状態 */ private void execCallback(int changedState) { synchronized (playStateChangedCallbackList) { final int n = playStateChangedCallbackList.beginBroadcast(); for (int i = 0; i < n; ++i) { final PlayStateChangedCallbackInterface callback = playStateChangedCallbackList.getBroadcastItem(i); if (callback != null) { try { callback.changed(changedState); } catch (RemoteException e) { // 例外はどうしようもないので無視しておく Log.w(C.TAG, "Occurd RemoteException(" + e.toString() + ")."); } } } playStateChangedCallbackList.finishBroadcast(); } }
/** Broadcast the results from the query to all registered callback objects. */ private void broadcastQueryResults(AsyncResult ar) { // reset the state. synchronized (mCallbacks) { mState = QUERY_READY; // see if we need to do any work. if (ar == null) { if (DBG) { log("AsyncResult is null."); } return; } // TODO: we may need greater accuracy here, but for now, just a // simple status integer will suffice. int exception = (ar.exception == null) ? QUERY_OK : QUERY_EXCEPTION; if (DBG) { log("AsyncResult has exception " + exception); } // Make the calls to all the registered callbacks. for (int i = (mCallbacks.beginBroadcast() - 1); i >= 0; i--) { INetworkQueryServiceCallback cb = mCallbacks.getBroadcastItem(i); if (DBG) { log("broadcasting results to " + cb.getClass().toString()); } try { cb.onQueryComplete((ArrayList<OperatorInfo>) ar.result, exception); } catch (RemoteException e) { log("e = " + e); } } // finish up. mCallbacks.finishBroadcast(); } }