@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);
          }
        }
Пример #2
0
  /**
   * 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();
    }
  }
Пример #3
0
        @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);
          }
        }
Пример #4
0
 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();
 }
Пример #7
0
 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 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();
 }
Пример #9
0
  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();
  }
  /**
   * 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();
    }
  }
Пример #11
0
  @Override
  public void onDestroy() {
    super.onDestroy();

    // 取消掉所有的回调
    mCallbacks.kill();
  }
Пример #12
0
 /** {@inheritDoc} */
 @Override
 public void removeMessageListener(IMessageListener listen) {
   Log.d(TAG, "Un ecouteur de moins");
   if (listen != null) {
     mRemoteListeners.unregister(listen);
   }
 }
 @Override
 public void removeCallback(final ApiMethodCallback callback) throws RemoteException {
   if (DEBUG) {
     Log.d(TAG, "Remove API callback " + callback);
   }
   apiCallbacks.unregister(callback);
 }
Пример #14
0
 /**
  * 注册一个远程回调监听器,用于主动更新客户端
  *
  * @param listener
  * @throws RemoteException
  */
 @Override
 public void registerUser(IOnComputerArrivedListener listener) throws RemoteException {
   mListener.register(listener); // 执行注册操作
   // 这里可以做一些主动更新客户端的操作,如:
   new Thread(
           new Runnable() {
             @Override
             public void run() {
               int counts = mListener.beginBroadcast();
               int count = counts;
               Log.i(tag, "count:" + count);
               int sum = 3;
               while (sum > 0) {
                 try {
                   Thread.sleep(3000);
                   ComputerEntity entity = new ComputerEntity(sum, "adc", "abc+" + sum);
                   count = counts;
                   while (count > 0) {
                     count--;
                     try {
                       mListener.getBroadcastItem(count).onComputerArrived(entity);
                     } catch (RemoteException e) {
                       e.printStackTrace();
                     }
                   }
                 } catch (InterruptedException e) {
                   e.printStackTrace();
                 }
                 sum--;
               }
               mListener.finishBroadcast();
             }
           })
       .start();
 }
 @Override
 public void unregisterPersonalDeckCallback(IPersonalDeckServiceCallback cb) {
   Log.i(AnkiDroidApp.TAG, "unregisterPersonalDeckCallback");
   if (cb != null) {
     mPersonalDeckCallbacks.unregister(cb);
   }
 }
Пример #16
0
  public void registerChatListener(IChatListener listener) {
    if (listener != null) {
      mRemoteListeners.register(listener);

      if (mDataHandlerListener != null) mDataHandlerListener.checkLastTransferRequest();
    }
  }
 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");
   }
 }
Пример #18
0
  /**
   * Unregisters a geoloc sharing invitation listener
   *
   * @param listener New geoloc sharing listener
   * @throws ServerApiException
   */
  public void removeNewGeolocSharingListener(INewGeolocSharingListener listener)
      throws ServerApiException {
    if (logger.isActivated()) {
      logger.info("Remove a geoloc sharing invitation listener");
    }

    listeners.unregister(listener);
  }
 @Override
 public void unregisterSharedDeckCallback(ISharedDeckServiceCallback cb)
     throws RemoteException {
   Log.i(AnkiDroidApp.TAG, "unregisterSharedDeckCallback");
   if (cb != null) {
     mSharedDeckCallbacks.unregister(cb);
   }
 }
 @Override
 public void registerPersonalDeckCallback(IPersonalDeckServiceCallback cb) {
   Log.i(AnkiDroidApp.TAG, "registerPersonalDeckCallback");
   if (cb != null) {
     mPersonalDeckCallbacks.register(cb);
     notifyPersonalDeckObservers();
   }
 }
  /**
   * Registers an video sharing invitation listener
   *
   * @param listener New video sharing listener
   * @throws ServerApiException
   */
  public void addNewVideoSharingListener(INewVideoSharingListener listener)
      throws ServerApiException {
    if (logger.isActivated()) {
      logger.info("Add an video sharing invitation listener");
    }

    listeners.register(listener);
  }
Пример #22
0
  @Override
  public void onDestroy() {
    super.onDestroy();

    ((AlarmManager) getSystemService(Context.ALARM_SERVICE)).cancel(mPAlarmIntent);
    mRosterCallbacks.kill();
    performDisconnect();
    unregisterReceiver(mAlarmReceiver);
  }
Пример #23
0
  /**
   * Unregisters a listener on service registration events
   *
   * @param listener Service registration listener
   */
  public void removeServiceRegistrationListener(IJoynServiceRegistrationListener listener) {
    synchronized (lock) {
      if (logger.isActivated()) {
        logger.info("Remove a service listener");
      }

      serviceListeners.unregister(listener);
    }
  }
Пример #24
0
  /**
   * Registers a listener on service registration events
   *
   * @param listener Service registration listener
   */
  public void addServiceRegistrationListener(IJoynServiceRegistrationListener listener) {
    synchronized (lock) {
      if (logger.isActivated()) {
        logger.info("Add a service listener");
      }

      serviceListeners.register(listener);
    }
  }
 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();
 }
Пример #26
0
 public void registerCallback(IConnectionChangeCallback callback) throws RemoteException {
   if (callback != null) {
     callbackList.register(callback);
   }
   try {
     callback.onConnectionStatusChanged("foo.com", CONNECTING);
   } catch (RemoteException e) {
     // ...
   }
 }
Пример #27
0
            @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;
            }
Пример #28
0
        @Override
        public boolean unregisterCallback(IDataServiceCallback callback) throws RemoteException {
          boolean flag = false;
          Logger.d(TAG, "unregisterCallback2 call callback = " + callback);
          if (callback != null) {
            flag = callbacks.unregister(callback);
          }

          return flag;
        }
Пример #29
0
 /**
  * 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();
   }
 }
  /**
   * コールバックを実行する
   *
   * @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();
    }
  }