public void refreshCallList(Resources resources) {
    if (callsList == null) {
      return;
    }

    callsList.removeAllViews();
    int index = 0;

    if (LinphoneManager.getLc().getCallsNb() == 0) {
      goBackToDialer();
      return;
    }

    isConferenceRunning = LinphoneManager.getLc().getConferenceSize() > 1;
    if (isConferenceRunning) {
      displayConferenceHeader();
      index++;
    }
    for (LinphoneCall call : LinphoneManager.getLc().getCalls()) {
      displayCall(resources, call, index);
      index++;
    }

    if (LinphoneManager.getLc().getCurrentCall() == null) {
      showAudioView();
    }

    callsList.invalidate();
  }
  @Override
  protected void onSaveInstanceState(Bundle outState) {
    outState.putBoolean("Speaker", LinphoneManager.getLc().isSpeakerEnabled());
    outState.putBoolean("Mic", LinphoneManager.getLc().isMicMuted());

    super.onSaveInstanceState(outState);
  }
  @Override
  public void onClick(View v) {
    int id = v.getId();

    if (id == R.id.clearFastChatField) {
      fastNewChat.setText("");
    } else if (id == R.id.ok) {
      edit.setVisibility(View.VISIBLE);
      ok.setVisibility(View.GONE);
      isEditMode = false;
      hideAndDisplayMessageIfNoChat();
    } else if (id == R.id.edit) {
      edit.setVisibility(View.GONE);
      ok.setVisibility(View.VISIBLE);
      isEditMode = true;
      hideAndDisplayMessageIfNoChat();
    } else if (id == R.id.newDiscussion) {
      String sipUri = fastNewChat.getText().toString();
      if (sipUri.equals("")) {
        LinphoneActivity.instance().displayContacts(true);
      } else {
        if (!LinphoneUtils.isSipAddress(sipUri)) {
          if (LinphoneManager.getLc().getDefaultProxyConfig() == null) {
            return;
          }
          sipUri = sipUri + "@" + LinphoneManager.getLc().getDefaultProxyConfig().getDomain();
        }
        if (!LinphoneUtils.isStrictSipAddress(sipUri)) {
          sipUri = "sip:" + sipUri;
        }
        LinphoneActivity.instance().displayChat(sipUri);
      }
    }
  }
  @Override
  public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY) {
    if (LinphoneUtils.isCallEstablished(LinphoneManager.getLc().getCurrentCall())) {
      if (mZoomFactor > 1) {
        // Video is zoomed, slide is used to change center of zoom
        if (distanceX > 0 && mZoomCenterX < 1) {
          mZoomCenterX += 0.01;
        } else if (distanceX < 0 && mZoomCenterX > 0) {
          mZoomCenterX -= 0.01;
        }
        if (distanceY < 0 && mZoomCenterY < 1) {
          mZoomCenterY += 0.01;
        } else if (distanceY > 0 && mZoomCenterY > 0) {
          mZoomCenterY -= 0.01;
        }

        if (mZoomCenterX > 1) mZoomCenterX = 1;
        if (mZoomCenterX < 0) mZoomCenterX = 0;
        if (mZoomCenterY > 1) mZoomCenterY = 1;
        if (mZoomCenterY < 0) mZoomCenterY = 0;

        LinphoneManager.getLc().getCurrentCall().zoomVideo(mZoomFactor, mZoomCenterX, mZoomCenterY);
        return true;
      }
    }

    return false;
  }
  @Override
  protected void onResume() {
    super.onResume();

    if (!LinphoneService.isReady()) {
      startService(new Intent(ACTION_MAIN).setClass(this, LinphoneService.class));
    }

    ContactsManager.getInstance().prepareContactsInBackground();

    updateMissedChatCount();

    displayMissedCalls(LinphoneManager.getLc().getMissedCallsCount());

    LinphoneManager.getInstance().changeStatusToOnline();

    if (getIntent().getIntExtra("PreviousActivity", 0) != CALL_ACTIVITY) {
      if (LinphoneManager.getLc().getCalls().length > 0) {
        LinphoneCall call = LinphoneManager.getLc().getCalls()[0];
        LinphoneCall.State callState = call.getState();
        if (callState == State.IncomingReceived) {
          startActivity(new Intent(this, IncomingCallActivity.class));
        } else {

          if (call.getCurrentParamsCopy().getVideoEnabled()) {
            startVideoActivity(call);
          } else {
            startIncallActivity(call);
          }
        }
      }
    }
  }
  @Override
  protected void onNewIntent(Intent intent) {
    super.onNewIntent(intent);

    Bundle extras = intent.getExtras();
    if (extras != null && extras.getBoolean("GoToChat", false)) {
      LinphoneService.instance().removeMessageNotification();
      String sipUri = extras.getString("ChatContactSipUri");
      displayChat(sipUri);
    } else if (extras != null && extras.getBoolean("Notification", false)) {
      if (LinphoneManager.getLc().getCallsNb() > 0) {
        LinphoneCall call = LinphoneManager.getLc().getCalls()[0];
        if (call.getCurrentParamsCopy().getVideoEnabled()) {
          startVideoActivity(call);
        } else {
          startIncallActivity(call);
        }
      }
    } else {
      if (dialerFragment != null) {
        if (extras != null && extras.containsKey("SipUriOrNumber")) {
          if (getResources().getBoolean(R.bool.automatically_start_intercepted_outgoing_gsm_call)) {
            ((DialerFragment) dialerFragment).newOutgoingCall(extras.getString("SipUriOrNumber"));
          } else {
            ((DialerFragment) dialerFragment)
                .displayTextInAddressBar(extras.getString("SipUriOrNumber"));
          }
        } else {
          ((DialerFragment) dialerFragment).newOutgoingCall(intent);
        }
      }
      if (LinphoneManager.getLc().getCalls().length > 0) {
        LinphoneCall calls[] = LinphoneManager.getLc().getCalls();
        if (calls.length > 0) {
          LinphoneCall call = calls[0];

          if (call != null && call.getState() != LinphoneCall.State.IncomingReceived) {
            if (call.getCurrentParamsCopy().getVideoEnabled()) {
              startVideoActivity(call);
            } else {
              startIncallActivity(call);
            }
          }
        }

        // If a call is ringing, start incomingcallactivity
        Collection<LinphoneCall.State> incoming = new ArrayList<LinphoneCall.State>();
        incoming.add(LinphoneCall.State.IncomingReceived);
        if (LinphoneUtils.getCallsInState(LinphoneManager.getLc(), incoming).size() > 0) {
          if (InCallActivity.isInstanciated()) {
            InCallActivity.instance().startIncomingCallActivity();
          } else {
            startActivity(new Intent(this, IncomingCallActivity.class));
          }
        }
      }
    }
  }
  public void acceptCallUpdate() {
    LinphoneCall call = LinphoneManager.getLc().getCurrentCall();
    if (call == null) {
      return;
    }

    LinphoneCallParams params = call.getCurrentParamsCopy();
    try {
      LinphoneManager.getLc().acceptCallUpdate(call, params);
    } catch (LinphoneCoreException e) {
      e.printStackTrace();
    }
  }
  private boolean importAndroidStoredMessagedIntoLibLinphoneStorage() {
    Log.w("Importing previous messages into new database...");
    try {
      ChatStorage db = LinphoneActivity.instance().getChatStorage();
      List<String> conversations = db.getChatList();
      for (int j = conversations.size() - 1; j >= 0; j--) {
        String correspondent = conversations.get(j);
        LinphoneChatRoom room = LinphoneManager.getLc().getOrCreateChatRoom(correspondent);
        for (ChatMessage message : db.getMessages(correspondent)) {
          LinphoneChatMessage msg =
              room.createLinphoneChatMessage(
                  message.getMessage(),
                  message.getUrl(),
                  message.getStatus(),
                  Long.parseLong(message.getTimestamp()),
                  true,
                  message.isIncoming());
          if (message.getImage() != null) {
            String path = saveImageAsFile(message.getId(), message.getImage());
            if (path != null) msg.setExternalBodyUrl(path);
          }
          msg.store();
        }
        db.removeDiscussion(correspondent);
      }
      return true;
    } catch (Exception e) {
      e.printStackTrace();
    }

    return false;
  }
  public void resetClassicMenuLayoutAndGoBackToCallIfStillRunning() {
    if (dialerFragment != null) {
      ((DialerFragment) dialerFragment).resetLayout(false);
    }

    if (LinphoneManager.isInstanciated() && LinphoneManager.getLc().getCallsNb() > 0) {
      LinphoneCall call = LinphoneManager.getLc().getCalls()[0];
      if (call.getState() == LinphoneCall.State.IncomingReceived) {
        startActivity(new Intent(LinphoneActivity.this, IncomingCallActivity.class));
      } else if (call.getCurrentParamsCopy().getVideoEnabled()) {
        startVideoActivity(call);
      } else {
        startIncallActivity(call);
      }
    }
  }
  @Override
  public void onClick(View v) {
    int id = v.getId();
    resetSelection();

    if (id == R.id.history) {
      changeCurrentFragment(FragmentsAvailable.HISTORY, null);
      history.setSelected(true);
      LinphoneManager.getLc().resetMissedCallsCount();
      displayMissedCalls(0);
    } else if (id == R.id.contacts) {
      changeCurrentFragment(FragmentsAvailable.CONTACTS, null);
      contacts.setSelected(true);
    } else if (id == R.id.dialer) {
      changeCurrentFragment(FragmentsAvailable.DIALER, null);
      dialer.setSelected(true);
    } else if (id == R.id.settings) {
      changeCurrentFragment(FragmentsAvailable.SETTINGS, null);
      settings.setSelected(true);
    } else if (id == R.id.about_chat) {
      Bundle b = new Bundle();
      b.putSerializable("About", FragmentsAvailable.ABOUT_INSTEAD_OF_CHAT);
      changeCurrentFragment(FragmentsAvailable.ABOUT_INSTEAD_OF_CHAT, b);
      aboutChat.setSelected(true);
    } else if (id == R.id.about_settings) {
      Bundle b = new Bundle();
      b.putSerializable("About", FragmentsAvailable.ABOUT_INSTEAD_OF_SETTINGS);
      changeCurrentFragment(FragmentsAvailable.ABOUT_INSTEAD_OF_SETTINGS, b);
      aboutSettings.setSelected(true);
    } else if (id == R.id.chat) {
      changeCurrentFragment(FragmentsAvailable.CHATLIST, null);
      chat.setSelected(true);
    }
  }
  public void switchCamera() {
    try {
      int videoDeviceId = LinphoneManager.getLc().getVideoDevice();
      videoDeviceId = (videoDeviceId + 1) % AndroidCameraConfiguration.retrieveCameras().length;
      LinphoneManager.getLc().setVideoDevice(videoDeviceId);
      CallManager.getInstance().updateCall();

      // previous call will cause graph reconstruction -> regive preview
      // window
      if (mCaptureView != null) {
        LinphoneManager.getLc().setPreviewWindow(mCaptureView);
      }
    } catch (ArithmeticException ae) {
      Log.e("Cannot swtich camera : no camera");
    }
  }
示例#12
0
 public void pauseOrResumeConference() {
   LinphoneCore lc = LinphoneManager.getLc();
   if (lc.isInConference()) {
     lc.leaveConference();
   } else {
     lc.enterConference();
   }
 }
示例#13
0
  private void refreshInCallActions() {
    try {
      if (isSpeakerEnabled) {
        speaker.setBackgroundResource(R.drawable.speaker_on);
        routeSpeaker.setBackgroundResource(R.drawable.route_speaker_on);
        routeReceiver.setBackgroundResource(R.drawable.route_receiver_off);
        routeBluetooth.setBackgroundResource(R.drawable.route_bluetooth_off);
      } else {
        speaker.setBackgroundResource(R.drawable.speaker_off);
        routeSpeaker.setBackgroundResource(R.drawable.route_speaker_off);
        if (BluetoothManager.getInstance().isUsingBluetoothAudioRoute()) {
          routeReceiver.setBackgroundResource(R.drawable.route_receiver_off);
          routeBluetooth.setBackgroundResource(R.drawable.route_bluetooth_on);
        } else {
          routeReceiver.setBackgroundResource(R.drawable.route_receiver_on);
          routeBluetooth.setBackgroundResource(R.drawable.route_bluetooth_off);
        }
      }
    } catch (NullPointerException npe) {
      Log.e("Bluetooth: Audio routes menu disabled on tablets for now (4)");
    }

    if (isMicMuted) {
      micro.setBackgroundResource(R.drawable.micro_off);
    } else {
      micro.setBackgroundResource(R.drawable.micro_on);
    }

    if (LinphoneManager.getLc().getCallsNb() > 1) {
      conference.setVisibility(View.VISIBLE);
      pause.setVisibility(View.GONE);
    } else {
      conference.setVisibility(View.GONE);
      pause.setVisibility(View.VISIBLE);

      List<LinphoneCall> pausedCalls =
          LinphoneUtils.getCallsInState(LinphoneManager.getLc(), Arrays.asList(State.Paused));
      if (pausedCalls.size() == 1) {
        pause.setBackgroundResource(R.drawable.pause_on);
      } else {
        pause.setBackgroundResource(R.drawable.pause_off);
      }
    }
  }
示例#14
0
  private void enableAndRefreshInCallActions() {
    addCall.setEnabled(
        LinphoneManager.getLc().getCallsNb() < LinphoneManager.getLc().getMaxCalls());
    transfer.setEnabled(getResources().getBoolean(R.bool.allow_transfers));
    options.setEnabled(
        !getResources().getBoolean(R.bool.disable_options_in_call)
            && (addCall.isEnabled() || transfer.isEnabled()));

    micro.setEnabled(true);
    if (!isTablet()) {
      speaker.setEnabled(true);
    }
    transfer.setEnabled(true);
    pause.setEnabled(true);
    dialer.setEnabled(true);
    conference.setEnabled(true);

    refreshInCallActions();
  }
示例#15
0
  public void onCallStateChanged(final LinphoneCall call, final State state, final String message) {
    if (instance == null) {
      Log.i("Service not ready, discarding call state change to ", state.toString());
      return;
    }
    if (state == LinphoneCall.State.IncomingReceived) {
      onIncomingReceived();
    }

    if (state == State.CallUpdatedByRemote) {
      // If the correspondent proposes video while audio call
      boolean remoteVideo = call.getRemoteParams().getVideoEnabled();
      boolean localVideo = call.getCurrentParamsCopy().getVideoEnabled();
      boolean autoAcceptCameraPolicy = LinphoneManager.getInstance().isAutoAcceptCamera();
      if (remoteVideo && !localVideo && !autoAcceptCameraPolicy) {
        try {
          LinphoneManager.getLc().deferCallUpdate(call);

          if (incallListener() != null) incallListener().onCallStateChanged(call, state, message);
        } catch (LinphoneCoreException e) {
          e.printStackTrace();
        }
      }
    }

    if (state == State.StreamsRunning) {
      // Workaround bug current call seems to be updated after state changed to streams running
      //	refreshIncallIcon(call);
      mWifiLock.acquire();
    } else {
      //	refreshIncallIcon(LinphoneManager.getLc().getCurrentCall());
    }
    if ((state == State.CallEnd || state == State.Error)
        && LinphoneManager.getLc().getCallsNb() < 1) {
      mWifiLock.release();
    }
    //		mHandler.post(new Runnable() {
    //			public void run() {
    //				if (guiListener() != null)
    //					guiListener().onCallStateChanged(call, state, message);
    //			}
    //		});
  }
示例#16
0
 private void toggleMicro() {
   LinphoneCore lc = LinphoneManager.getLc();
   isMicMuted = !isMicMuted;
   lc.muteMic(isMicMuted);
   if (isMicMuted) {
     micro.setBackgroundResource(R.drawable.micro_off);
   } else {
     micro.setBackgroundResource(R.drawable.micro_on);
   }
 }
  private void onProfileChanged(int newProfile) {
    LinphoneCore lc = LinphoneManager.getLc();
    lc.setUploadBandwidth(bandwidthes[newProfile][0]);
    lc.setDownloadBandwidth(bandwidthes[newProfile][1]);

    if (lc.isIncall()) {
      CallManager.getInstance().reinvite();
    } else {
      updateWithProfileSettings(lc, null);
    }
  }
示例#18
0
  @Override
  public synchronized void onDestroy() {
    instance = null;
    LinphoneManager.getLc().setPresenceInfo(0, null, OnlineStatus.Offline);
    LinphoneManager.destroy();

    // Make sure our notification is gone.
    //	    stopForegroundCompat(NOTIF_ID);
    //	    mNM.cancel(INCALL_NOTIF_ID);
    mWifiLock.release();
    super.onDestroy();
  }
示例#19
0
 private void toggleSpeaker() {
   isSpeakerEnabled = !isSpeakerEnabled;
   if (isSpeakerEnabled) {
     LinphoneManager.getInstance().routeAudioToSpeaker();
     speaker.setBackgroundResource(R.drawable.speaker_on);
     LinphoneManager.getLc().enableSpeaker(isSpeakerEnabled);
   } else {
     Log.d("Toggle speaker off, routing back to earpiece");
     LinphoneManager.getInstance().routeAudioToReceiver();
     speaker.setBackgroundResource(R.drawable.speaker_off);
   }
 }
示例#20
0
  private void hangUp() {
    LinphoneCore lc = LinphoneManager.getLc();
    LinphoneCall currentCall = lc.getCurrentCall();

    if (currentCall != null) {
      lc.terminateCall(currentCall);
    } else if (lc.isInConference()) {
      lc.terminateConference();
    } else {
      lc.terminateAllCalls();
    }
  }
示例#21
0
 public void onCallStateChanged(LinphoneCall linphoneCall, State state, String str) {
   if (instance == null) {
     Log.m11095i("Service not ready, discarding call state change to ", state.toString());
     return;
   }
   if (state == State.IncomingReceived) {
     onIncomingReceived();
   }
   if (state == State.CallUpdatedByRemote) {
     boolean videoEnabled = linphoneCall.getRemoteParams().getVideoEnabled();
     boolean videoEnabled2 = linphoneCall.getCurrentParamsCopy().getVideoEnabled();
     boolean shouldAutomaticallyAcceptVideoRequests =
         LinphonePreferences.instance().shouldAutomaticallyAcceptVideoRequests();
     if (!(!videoEnabled
         || videoEnabled2
         || shouldAutomaticallyAcceptVideoRequests
         || LinphoneManager.getLc().isInConference())) {
       try {
         LinphoneManager.getLc().deferCallUpdate(linphoneCall);
       } catch (Throwable e) {
         C1104b.m6368b((Object) this, e);
       }
     }
   }
   if (state == State.StreamsRunning) {
     if (getResources().getBoolean(C1134b.enable_call_notification)) {}
     if (Version.sdkAboveOrEqual(12)) {
       this.mWifiLock.acquire();
     }
   } else if (getResources().getBoolean(C1134b.enable_call_notification)) {
   }
   if ((state == State.CallEnd || state == State.Error)
       && LinphoneManager.getLc().getCallsNb() < 1
       && Version.sdkAboveOrEqual(12)) {
     this.mWifiLock.release();
   }
   this.mHandler.post(new C28015(linphoneCall, state, str));
 }
  @Override
  public boolean onDoubleTap(MotionEvent e) {
    if (LinphoneUtils.isCallEstablished(LinphoneManager.getLc().getCurrentCall())) {
      Log.i("================videoSize===002==");
      if (mZoomFactor == 1.f) {
        // Zoom to make the video fill the screen vertically
        float portraitZoomFactor =
            ((float) mVideoView.getHeight()) / (float) ((3 * mVideoView.getWidth()) / 4);
        // Zoom to make the video fill the screen horizontally
        float landscapeZoomFactor =
            ((float) mVideoView.getWidth()) / (float) ((3 * mVideoView.getHeight()) / 4);

        mZoomFactor = Math.max(portraitZoomFactor, landscapeZoomFactor);
      } else {
        resetZoom();
      }

      LinphoneManager.getLc().getCurrentCall().zoomVideo(mZoomFactor, mZoomCenterX, mZoomCenterY);
      return true;
    }

    return false;
  }
示例#23
0
  private void displayConferenceHeader() {
    LinearLayout conferenceHeader =
        (LinearLayout) inflater.inflate(R.layout.conference_header, container, false);

    ImageView conferenceState = (ImageView) conferenceHeader.findViewById(R.id.conferenceStatus);
    conferenceState.setOnClickListener(this);
    if (LinphoneManager.getLc().isInConference()) {
      conferenceState.setImageResource(R.drawable.play);
    } else {
      conferenceState.setImageResource(R.drawable.pause);
    }

    callsList.addView(conferenceHeader);
  }
  @Override
  public void onResume() {
    super.onResume();

    if (mVideoView != null) {
      ((GLSurfaceView) mVideoView).onResume();
    }

    if (androidVideoWindowImpl != null) {
      synchronized (androidVideoWindowImpl) {
        LinphoneManager.getLc().setVideoWindow(androidVideoWindowImpl);
      }
    }

    mGestureDetector = new GestureDetector(inCallActivity, this);
    mScaleDetector = Compatibility.getScaleGestureDetector(inCallActivity, this);
  }
  @Override
  public void onPause() {
    if (androidVideoWindowImpl != null) {
      synchronized (androidVideoWindowImpl) {
        /*
         * this call will destroy native opengl renderer which is used by
         * androidVideoWindowImpl
         */
        LinphoneManager.getLc().setVideoWindow(null);
      }
    }

    if (mVideoView != null) {
      ((GLSurfaceView) mVideoView).onPause();
    }

    super.onPause();
  }
示例#26
0
 public void pauseOrResumeCall(LinphoneCall call) {
   LinphoneCore lc = LinphoneManager.getLc();
   if (call != null && LinphoneUtils.isCallRunning(call)) {
     if (call.isInConference()) {
       lc.removeFromConference(call);
       if (lc.getConferenceSize() <= 1) {
         lc.leaveConference();
       }
     } else {
       lc.pauseCall(call);
       pause.setBackgroundResource(R.drawable.pause_on);
     }
   } else if (call != null) {
     if (call.getState() == State.Paused) {
       lc.resumeCall(call);
       pause.setBackgroundResource(R.drawable.pause_off);
     }
   }
 }
  public boolean onScale(CompatibilityScaleGestureDetector detector) {

    Log.i("================videoSize===001==");

    mZoomFactor *= detector.getScaleFactor();
    // Don't let the object get too small or too large.
    // Zoom to make the video fill the screen vertically
    float portraitZoomFactor =
        ((float) mVideoView.getHeight()) / (float) ((3 * mVideoView.getWidth()) / 4);
    // Zoom to make the video fill the screen horizontally
    float landscapeZoomFactor =
        ((float) mVideoView.getWidth()) / (float) ((3 * mVideoView.getHeight()) / 4);
    mZoomFactor =
        Math.max(0.1f, Math.min(mZoomFactor, Math.max(portraitZoomFactor, landscapeZoomFactor)));

    LinphoneCall currentCall = LinphoneManager.getLc().getCurrentCall();
    if (currentCall != null) {
      currentCall.zoomVideo(mZoomFactor, mZoomCenterX, mZoomCenterY);
      return true;
    }
    return false;
  }
 @Override
 protected void onActivityResult(int requestCode, int resultCode, Intent data) {
   if (resultCode == Activity.RESULT_FIRST_USER && requestCode == SETTINGS_ACTIVITY) {
     if (data.getExtras().getBoolean("Exit", false)) {
       exit();
     } else {
       FragmentsAvailable newFragment =
           (FragmentsAvailable) data.getExtras().getSerializable("FragmentToDisplay");
       changeCurrentFragment(newFragment, null, true);
       selectMenu(newFragment);
     }
   } else if (resultCode == Activity.RESULT_FIRST_USER && requestCode == CALL_ACTIVITY) {
     getIntent().putExtra("PreviousActivity", CALL_ACTIVITY);
     boolean callTransfer = data == null ? false : data.getBooleanExtra("Transfer", false);
     if (LinphoneManager.getLc().getCallsNb() > 0) {
       initInCallMenuLayout(callTransfer);
     } else {
       resetClassicMenuLayoutAndGoBackToCallIfStillRunning();
     }
   } else {
     super.onActivityResult(requestCode, resultCode, data);
   }
 }
示例#29
0
  private void hideOrDisplayCallOptions() {
    boolean isOrientationLandscape =
        getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE;

    if (addCall.getVisibility() == View.VISIBLE) {
      options.setBackgroundResource(R.drawable.options);
      if (isAnimationDisabled) {
        if (isTransferAllowed) {
          transfer.setVisibility(View.INVISIBLE);
        }
        addCall.setVisibility(View.INVISIBLE);
      } else {
        if (isOrientationLandscape) {
          hideAnimatedLandscapeCallOptions();
        } else {
          hideAnimatedPortraitCallOptions();
        }
      }
      options.setSelected(false);
    } else {
      if (isAnimationDisabled) {
        if (isTransferAllowed) {
          transfer.setVisibility(View.VISIBLE);
        }
        addCall.setVisibility(View.VISIBLE);
        options.setBackgroundResource(R.drawable.options_alt);
      } else {
        if (isOrientationLandscape) {
          showAnimatedLandscapeCallOptions();
        } else {
          showAnimatedPortraitCallOptions();
        }
      }
      options.setSelected(true);
      transfer.setEnabled(LinphoneManager.getLc().getCurrentCall() != null);
    }
  }
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    if (isTablet() && getRequestedOrientation() != ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE) {
      setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
    } else if (!isTablet()
        && getRequestedOrientation() != ActivityInfo.SCREEN_ORIENTATION_PORTRAIT) {
      setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
    }

    if (!LinphoneManager.isInstanciated()) {
      Log.e("No service running: avoid crash by starting the launcher", this.getClass().getName());
      // super.onCreate called earlier
      finish();
      startActivity(getIntent().setClass(this, LinphoneLauncherActivity.class));
      return;
    }

    boolean useFirstLoginActivity =
        getResources().getBoolean(R.bool.display_account_wizard_at_first_start);
    if (LinphonePreferences.instance().isProvisioningLoginViewEnabled()) {
      Intent wizard = new Intent();
      wizard.setClass(this, RemoteProvisioningLoginActivity.class);
      wizard.putExtra("Domain", LinphoneManager.getInstance().wizardLoginViewDomain);
      startActivityForResult(wizard, REMOTE_PROVISIONING_LOGIN_ACTIVITY);
    } else if (useFirstLoginActivity && LinphonePreferences.instance().isFirstLaunch()) {
      if (LinphonePreferences.instance().getAccountCount() > 0) {
        LinphonePreferences.instance().firstLaunchSuccessful();
      } else {
        startActivityForResult(
            new Intent().setClass(this, SetupActivity.class), FIRST_LOGIN_ACTIVITY);
      }
    }

    if (getResources().getBoolean(R.bool.use_linphone_tag)) {
      ContactsManager.getInstance()
          .initializeSyncAccount(getApplicationContext(), getContentResolver());
    } else {
      ContactsManager.getInstance()
          .initializeContactManager(getApplicationContext(), getContentResolver());
    }

    if (!LinphonePreferences.instance().isContactsMigrationDone()) {
      ContactsManager.getInstance().migrateContacts();
      LinphonePreferences.instance().contactsMigrationDone();
    }

    setContentView(R.layout.main);
    instance = this;
    fragmentsHistory = new ArrayList<FragmentsAvailable>();
    initButtons();

    currentFragment = nextFragment = FragmentsAvailable.DIALER;
    fragmentsHistory.add(currentFragment);
    if (savedInstanceState == null) {
      if (findViewById(R.id.fragmentContainer) != null) {
        dialerFragment = new DialerFragment();
        dialerFragment.setArguments(getIntent().getExtras());
        getSupportFragmentManager()
            .beginTransaction()
            .add(R.id.fragmentContainer, dialerFragment, currentFragment.toString())
            .commit();
        selectMenu(FragmentsAvailable.DIALER);
      }
    }

    mListener =
        new LinphoneCoreListenerBase() {
          @Override
          public void messageReceived(
              LinphoneCore lc, LinphoneChatRoom cr, LinphoneChatMessage message) {
            if (!displayChatMessageNotification(message.getFrom().asStringUriOnly())) {
              cr.markAsRead();
            }
            displayMissedChats(getChatStorage().getUnreadMessageCount());
            if (messageListFragment != null && messageListFragment.isVisible()) {
              ((ChatListFragment) messageListFragment).refresh();
            }
          }

          @Override
          public void registrationState(
              LinphoneCore lc,
              LinphoneProxyConfig proxy,
              LinphoneCore.RegistrationState state,
              String smessage) {
            if (state.equals(RegistrationState.RegistrationCleared)) {
              if (lc != null) {
                LinphoneAuthInfo authInfo =
                    lc.findAuthInfo(proxy.getIdentity(), proxy.getRealm(), proxy.getDomain());
                if (authInfo != null) lc.removeAuthInfo(authInfo);
              }
            }
          }

          @Override
          public void callState(
              LinphoneCore lc, LinphoneCall call, LinphoneCall.State state, String message) {
            if (state == State.IncomingReceived) {
              startActivity(new Intent(LinphoneActivity.instance(), IncomingCallActivity.class));
            } else if (state == State.OutgoingInit) {
              if (call.getCurrentParamsCopy().getVideoEnabled()) {
                startVideoActivity(call);
              } else {
                startIncallActivity(call);
              }
            } else if (state == State.CallEnd
                || state == State.Error
                || state == State.CallReleased) {
              // Convert LinphoneCore message for internalization
              if (message != null && message.equals("Call declined.")) {
                displayCustomToast(getString(R.string.error_call_declined), Toast.LENGTH_LONG);
              } else if (message != null && message.equals("Not Found")) {
                displayCustomToast(getString(R.string.error_user_not_found), Toast.LENGTH_LONG);
              } else if (message != null && message.equals("Unsupported media type")) {
                displayCustomToast(getString(R.string.error_incompatible_media), Toast.LENGTH_LONG);
              } else if (message != null && state == State.Error) {
                displayCustomToast(
                    getString(R.string.error_unknown) + " - " + message, Toast.LENGTH_LONG);
              }
              resetClassicMenuLayoutAndGoBackToCallIfStillRunning();
            }

            int missedCalls = LinphoneManager.getLc().getMissedCallsCount();
            displayMissedCalls(missedCalls);
          }
        };

    LinphoneCore lc = LinphoneManager.getLcIfManagerNotDestroyedOrNull();
    if (lc != null) {
      lc.addListener(mListener);
    }

    int missedCalls = LinphoneManager.getLc().getMissedCallsCount();
    displayMissedCalls(missedCalls);

    int rotation = getWindowManager().getDefaultDisplay().getRotation();
    switch (rotation) {
      case Surface.ROTATION_0:
        rotation = 0;
        break;
      case Surface.ROTATION_90:
        rotation = 90;
        break;
      case Surface.ROTATION_180:
        rotation = 180;
        break;
      case Surface.ROTATION_270:
        rotation = 270;
        break;
    }

    LinphoneManager.getLc().setDeviceRotation(rotation);
    mAlwaysChangingPhoneAngle = rotation;

    updateAnimationsState();
  }