Пример #1
0
    @Override
    public void handleMessage(Message voipMessage) {

      if (voipMessage.what == -1) {
        Log.d(TAG, "App exiting request");
        myVoip.destroyLib();
        finish();
        Runtime.getRuntime().gc();
        android.os.Process.killProcess(android.os.Process.myPid());
        return;
      }

      VoipEventBundle myEventBundle = getEventBundle(voipMessage);
      Log.d(
          TAG,
          "HANDLE MESSAGE TYPE:"
              + myEventBundle.getEventType()
              + " EVENT:"
              + myEventBundle.getEvent());

      updateCallStateInfo();
      updateServerStateInfo();

      if (myEventBundle.getEventType() == VoipEventType.BUDDY_EVENT) {
        Log.d(TAG, "In handle Message for BUDDY STATE");
        IBuddy myBuddy = (IBuddy) myEventBundle.getData();
        this.app.addInfoLine("Buddy (" + myBuddy.getUri() + ") ->" + myBuddy.getStatusText());
        updateBuddyStateInfo(myBuddy);
      }
      // Register the account after the Lib Initialization
      if (myEventBundle.getEvent() == VoipEvent.LIB_INITIALIZED) {
        myVoip.registerAccount();
      } else if (myEventBundle.getEvent() == VoipEvent.ACCOUNT_REGISTERED) {
        this.app.addInfoLine("Ready to accept calls (adding buddy...)");
        // add a buddy so that we can receive presence notifications from it
        subscribeBuddies();
      } else if (myEventBundle.getEvent() == VoipEvent.CALL_INCOMING) handleIncomingCall();
      // else if  (myState.getState()==VoipState.CALL_ACTIVE)    {}

      // Unregister the account
      else if (myEventBundle.getEvent() == VoipEvent.CALL_HANGUP) {
        setupButtons(false);
        ICall callInfo = (ICall) myEventBundle.getData();
        Log.d(TAG, "Hangup from uri:" + callInfo.getRemoteUri());
        IBuddy myBuddy = myVoip.getAccount().getBuddy(callInfo.getRemoteUri());
        Log.d(TAG, "Current Buddy Status Text:" + myBuddy.getStatusText());
        updateBuddyStateInfo(myBuddy);
        // myVoip.unregisterAccount();
      }
      // Deinitialize the Voip Lib and release all allocated resources
      else if (myEventBundle.getEvent() == VoipEvent.LIB_DEINITIALIZED
          || myEventBundle.getEvent() == VoipEvent.LIB_DEINITIALIZATION_FAILED) {
        Log.d(TAG, "Setting to null MyVoipLib");
        this.app.myVoip = null;

        if (this.reinitRequest) {
          this.reinitRequest = false;
          this.app.runExample();
        }
      }
    } // end of handleMessage()