private void sendImageMessage(String url, Bitmap bitmap) {
    LinphoneCore lc = LinphoneManager.getLcIfManagerNotDestroyedOrNull();
    boolean isNetworkReachable = lc == null ? false : lc.isNetworkReachable();

    if (chatRoom != null && url != null && url.length() > 0 && isNetworkReachable) {
      LinphoneChatMessage chatMessage = chatRoom.createLinphoneChatMessage("");
      chatMessage.setExternalBodyUrl(url);
      chatRoom.sendMessage(chatMessage, this);

      int newId = -1;
      if (LinphoneActivity.isInstanciated()) {
        newId = LinphoneActivity.instance().onMessageSent(sipUri, bitmap, url);
      }
      newId = chatMessage.getStorageId();
      latestImageMessages.put(newId, url);

      if (useLinphoneMessageStorage) url = saveImage(bitmap, newId, chatMessage);

      adapter.refreshHistory();
      adapter.notifyDataSetChanged();

      scrollToEnd();
    } else if (!isNetworkReachable && LinphoneActivity.isInstanciated()) {
      LinphoneActivity.instance()
          .displayCustomToast(getString(R.string.error_network_unreachable), Toast.LENGTH_LONG);
    }
  }
Exemple #2
0
  public void changeDisplayedChat(String newSipUri, String displayName, String pictureUri) {
    this.sipUri = newSipUri;
    this.displayName = displayName;
    this.pictureUri = pictureUri;

    if (!message.getText().toString().equals("") && LinphoneActivity.isInstanciated()) {
      ChatStorage chatStorage = LinphoneActivity.instance().getChatStorage();
      if (chatStorage.getDraft(sipUri) == null) {
        chatStorage.saveDraft(sipUri, message.getText().toString());
      } else {
        chatStorage.updateDraft(sipUri, message.getText().toString());
      }
    } else if (LinphoneActivity.isInstanciated()) {
      LinphoneActivity.instance().getChatStorage().deleteDraft(sipUri);
    }

    if (LinphoneActivity.isInstanciated()) {
      String draft = LinphoneActivity.instance().getChatStorage().getDraft(sipUri);
      if (draft == null) draft = "";
      message.setText(draft);
    }

    LinphoneCore lc = LinphoneManager.getLcIfManagerNotDestroyedOrNull();
    if (lc != null) {
      chatRoom = lc.getOrCreateChatRoom(sipUri);
      // Only works if using liblinphone storage
      chatRoom.markAsRead();
    }

    displayChatHeader(displayName, pictureUri);
    dispayMessageList();
  }
Exemple #3
0
  @SuppressLint("UseSparseArrays")
  @Override
  public void onResume() {
    message.addTextChangedListener(textWatcher);
    addVirtualKeyboardVisiblityListener();

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

    if (LinphoneActivity.isInstanciated()) {
      if (getResources().getBoolean(R.bool.show_statusbar_only_on_dialer)) {
        LinphoneActivity.instance().hideStatusBar();
      }
      LinphoneActivity.instance().updateChatFragment(this);
    }

    String draft = getArguments().getString("messageDraft");
    message.setText(draft);

    remoteComposing.setVisibility(chatRoom.isRemoteComposing() ? View.VISIBLE : View.GONE);
    dispayMessageList();

    super.onResume();
  }
  private void sendTextMessage(String messageToSend) {
    LinphoneCore lc = LinphoneManager.getLcIfManagerNotDestroyedOrNull();
    boolean isNetworkReachable = lc == null ? false : lc.isNetworkReachable();

    if (chatRoom != null
        && messageToSend != null
        && messageToSend.length() > 0
        && isNetworkReachable) {
      LinphoneChatMessage chatMessage = chatRoom.createLinphoneChatMessage(messageToSend);
      chatRoom.sendMessage(chatMessage, this);

      if (LinphoneActivity.isInstanciated()) {
        LinphoneActivity.instance().onMessageSent(sipUri, messageToSend);
      }

      adapter.refreshHistory();
      adapter.notifyDataSetChanged();

      Log.i("Sent message current status: " + chatMessage.getStatus());
      scrollToEnd();
    } else if (!isNetworkReachable && LinphoneActivity.isInstanciated()) {
      LinphoneActivity.instance()
          .displayCustomToast(getString(R.string.error_network_unreachable), Toast.LENGTH_LONG);
    }
  }
 private void pauseOrResumeCall() {
   LinphoneCore lc = LinphoneManager.getLcIfManagerNotDestroyedOrNull();
   if (lc != null && lc.getCallsNb() >= 1) {
     LinphoneCall call = lc.getCalls()[0];
     pauseOrResumeCall(call);
   }
 }
    @Override
    public void onOrientationChanged(final int o) {
      if (o == OrientationEventListener.ORIENTATION_UNKNOWN) {
        return;
      }

      int degrees = 270;
      if (o < 45 || o > 315) degrees = 0;
      else if (o < 135) degrees = 90;
      else if (o < 225) degrees = 180;

      if (mAlwaysChangingPhoneAngle == degrees) {
        return;
      }
      mAlwaysChangingPhoneAngle = degrees;

      Log.d("Phone orientation changed to ", degrees);
      int rotation = (360 - degrees) % 360;
      LinphoneCore lc = LinphoneManager.getLcIfManagerNotDestroyedOrNull();
      if (lc != null) {
        lc.setDeviceRotation(rotation);
        LinphoneCall currentCall = lc.getCurrentCall();
        if (currentCall != null
            && currentCall.cameraEnabled()
            && currentCall.getCurrentParamsCopy().getVideoEnabled()) {
          lc.updateCall(currentCall, null);
        }
      }
    }
Exemple #7
0
 public void refresh(ContentResolver cr) {
   this.numbersOrAddresses = Compatibility.extractContactNumbersAndAddresses(id, cr);
   LinphoneCore lc = LinphoneManager.getLcIfManagerNotDestroyedOrNull();
   if (lc != null && lc.getFriendList() != null) {
     for (LinphoneFriend friend : lc.getFriendList()) {
       if (id.equals(friend.getRefKey())) {
         hasFriends = true;
         this.numbersOrAddresses.add(friend.getAddress().asStringUriOnly());
       }
     }
   }
   this.name = Compatibility.refreshContactName(cr, id);
 }
  @Override
  protected void onPause() {
    LinphoneCore lc = LinphoneManager.getLcIfManagerNotDestroyedOrNull();
    if (lc != null) {
      lc.removeListener(mListener);
    }

    super.onPause();

    if (mControlsHandler != null && mControls != null) {
      mControlsHandler.removeCallbacks(mControls);
    }
    mControls = null;
  }
  @Override
  protected void onResume() {
    instance = this;

    LinphoneManager.startProximitySensorForActivity(this);
    setCallControlsVisibleAndRemoveCallbacks();

    super.onResume();

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

    refreshCallList(getResources());
  }
Exemple #10
0
  private void sendImageMessage(String path) {
    LinphoneCore lc = LinphoneManager.getLcIfManagerNotDestroyedOrNull();
    boolean isNetworkReachable = lc == null ? false : lc.isNetworkReachable();

    if (chatRoom != null && path != null && path.length() > 0 && isNetworkReachable) {
      Bitmap bm = BitmapFactory.decodeFile(path);
      if (bm != null) {
        FileUploadPrepareTask task = new FileUploadPrepareTask(getActivity(), path);
        task.execute(bm);
      } else {
        Log.e("Error, bitmap factory can't read " + path);
      }
    } else if (!isNetworkReachable && LinphoneActivity.isInstanciated()) {
      LinphoneActivity.instance()
          .displayCustomToast(getString(R.string.error_network_unreachable), Toast.LENGTH_LONG);
    }
  }
  @Override
  public void onPause() {
    latestImageMessages = null;
    message.removeTextChangedListener(textWatcher);
    removeVirtualKeyboardVisiblityListener();

    LinphoneService.instance().removeMessageNotification();

    LinphoneCore lc = LinphoneManager.getLcIfManagerNotDestroyedOrNull();
    if (lc != null) {
      lc.removeListener(this);
    }

    super.onPause();

    onSaveInstanceState(getArguments());
  }
  @Override
  protected void onDestroy() {
    if (mOrientationHelper != null) {
      mOrientationHelper.disable();
      mOrientationHelper = null;
    }

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

    instance = null;
    super.onDestroy();

    unbindDrawables(findViewById(R.id.topLayout));
    System.gc();
  }
 @Override
 public void onClick(View v) {
   if (LinphoneActivity.isInstanciated()) {
     LinphoneCore lc = LinphoneManager.getLcIfManagerNotDestroyedOrNull();
     if (v == sendLogButton) {
       // LinphoneUtils.collectLogs(LinphoneActivity.instance(),
       // getString(R.string.about_bugreport_email));
       if (lc != null) {
         lc.uploadLogCollection();
       }
     } else if (v == resetLogButton) {
       if (lc != null) {
         lc.resetLogCollection();
       }
     } else {
       LinphoneActivity.instance().exit();
     }
   }
 }
Exemple #14
0
  private void sendTextMessage(String messageToSend) {
    LinphoneCore lc = LinphoneManager.getLcIfManagerNotDestroyedOrNull();
    boolean isNetworkReachable = lc == null ? false : lc.isNetworkReachable();

    if (chatRoom != null
        && messageToSend != null
        && messageToSend.length() > 0
        && isNetworkReachable) {
      LinphoneChatMessage message = chatRoom.createLinphoneChatMessage(messageToSend);
      message.setListener(this);
      chatRoom.sendChatMessage(message);

      if (LinphoneActivity.isInstanciated()) {
        LinphoneActivity.instance().onMessageSent(sipUri, messageToSend);
      }

      invalidate();
      Log.i("Sent message current status: " + message.getStatus());
    } else if (!isNetworkReachable && LinphoneActivity.isInstanciated()) {
      LinphoneActivity.instance()
          .displayCustomToast(getString(R.string.error_network_unreachable), Toast.LENGTH_LONG);
    }
  }
Exemple #15
0
  @Override
  public void onPause() {
    message.removeTextChangedListener(textWatcher);
    removeVirtualKeyboardVisiblityListener();

    LinphoneService.instance().removeMessageNotification();

    if (LinphoneActivity.isInstanciated()) {
      LinphoneActivity.instance().updateChatFragment(null);
    }

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

    onSaveInstanceState(getArguments());

    // Hide keybord
    InputMethodManager imm =
        (InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVICE);
    imm.hideSoftInputFromWindow(message.getWindowToken(), 0);
    super.onPause();
  }
  @Override
  public View onCreateView(
      LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    sipUri = getArguments().getString("SipUri");
    String displayName = getArguments().getString("DisplayName");
    String pictureUri = getArguments().getString("PictureUri");

    view = inflater.inflate(R.layout.chat, container, false);

    useLinphoneMessageStorage = getResources().getBoolean(R.bool.use_linphone_chat_storage);

    contactName = (TextView) view.findViewById(R.id.contactName);
    contactPicture = (AvatarWithShadow) view.findViewById(R.id.contactPicture);

    sendMessage = (TextView) view.findViewById(R.id.sendMessage);
    sendMessage.setOnClickListener(this);

    remoteComposing = (TextView) view.findViewById(R.id.remoteComposing);
    remoteComposing.setVisibility(View.GONE);

    messagesList = (ListView) view.findViewById(R.id.chatMessageList);

    message = (EditText) view.findViewById(R.id.message);
    if (!getActivity().getResources().getBoolean(R.bool.allow_chat_multiline)) {
      message.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_SHORT_MESSAGE);
      message.setMaxLines(1);
    }

    uploadLayout = (RelativeLayout) view.findViewById(R.id.uploadLayout);
    uploadLayout.setVisibility(View.GONE);
    textLayout = (RelativeLayout) view.findViewById(R.id.messageLayout);

    progressBar = (ProgressBar) view.findViewById(R.id.progressbar);
    sendImage = (TextView) view.findViewById(R.id.sendPicture);
    if (!getResources().getBoolean(R.bool.disable_chat_send_file)) {
      registerForContextMenu(sendImage);
      sendImage.setOnClickListener(
          new OnClickListener() {
            @Override
            public void onClick(View v) {
              pickImage();
            }
          });
    } else {
      sendImage.setEnabled(false);
    }

    cancelUpload = (ImageView) view.findViewById(R.id.cancelUpload);
    cancelUpload.setOnClickListener(
        new OnClickListener() {
          @Override
          public void onClick(View v) {
            uploadThread.interrupt();
            uploadLayout.setVisibility(View.GONE);
            textLayout.setVisibility(View.VISIBLE);
            progressBar.setProgress(0);
          }
        });

    LinphoneCore lc = LinphoneManager.getLcIfManagerNotDestroyedOrNull();
    if (lc != null) {
      chatRoom = lc.getOrCreateChatRoom(sipUri);
      // Only works if using liblinphone storage
      chatRoom.markAsRead();
    }

    displayChatHeader(displayName, pictureUri);

    uploadServerUri = LinphonePreferences.instance().getSharingPictureServerUrl();

    textWatcher =
        new TextWatcher() {
          public void afterTextChanged(Editable arg0) {}

          public void beforeTextChanged(CharSequence arg0, int arg1, int arg2, int arg3) {}

          public void onTextChanged(CharSequence arg0, int arg1, int arg2, int arg3) {
            if (message.getText().toString().equals("")) {
              sendMessage.setEnabled(false);
            } else {
              if (chatRoom != null) chatRoom.compose();
              sendMessage.setEnabled(true);
            }
          }
        };

    // Force hide keyboard
    if (LinphoneActivity.isInstanciated()) {
      InputMethodManager imm =
          (InputMethodManager)
              LinphoneActivity.instance().getSystemService(Context.INPUT_METHOD_SERVICE);
      imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
    }

    // Workaround for SGS3 issue
    if (savedInstanceState != null) {
      fileToUploadPath = savedInstanceState.getString("fileToUploadPath");
      imageToUpload = savedInstanceState.getParcelable("imageToUpload");
    }
    if (fileToUploadPath != null || imageToUpload != null) {
      sendImage.post(
          new Runnable() {
            @Override
            public void run() {
              sendImage.showContextMenu();
            }
          });
    }

    return view;
  }
  private LinphoneCore getLc() {
    if (!LinphoneManager.isInstanciated()) return null;

    return LinphoneManager.getLcIfManagerNotDestroyedOrNull();
  }
Exemple #18
0
  @Override
  public View onCreateView(
      LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    instance = this;
    View view = inflater.inflate(R.layout.chat, container, false);

    // Retain the fragment across configuration changes
    setRetainInstance(true);

    // Retrieve parameter from intent
    sipUri = getArguments().getString("SipUri");
    displayName = getArguments().getString("DisplayName");
    pictureUri = getArguments().getString("PictureUri");

    // Initialize UI
    contactName = (TextView) view.findViewById(R.id.contactName);
    contactPicture = (AvatarWithShadow) view.findViewById(R.id.contactPicture);
    messagesList = (ListView) view.findViewById(R.id.chatMessageList);
    textLayout = (RelativeLayout) view.findViewById(R.id.messageLayout);
    progressBar = (ProgressBar) view.findViewById(R.id.progressbar);
    topBar = (LinearLayout) view.findViewById(R.id.topbar);

    sendMessage = (TextView) view.findViewById(R.id.sendMessage);
    sendMessage.setOnClickListener(this);

    remoteComposing = (TextView) view.findViewById(R.id.remoteComposing);
    remoteComposing.setVisibility(View.GONE);

    uploadLayout = (RelativeLayout) view.findViewById(R.id.uploadLayout);
    uploadLayout.setVisibility(View.GONE);

    displayChatHeader(displayName, pictureUri);

    // Manage multiline
    message = (EditText) view.findViewById(R.id.message);
    if (!getResources().getBoolean(R.bool.allow_chat_multiline)) {
      message.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_SHORT_MESSAGE);
      message.setMaxLines(1);
    }

    sendImage = (TextView) view.findViewById(R.id.sendPicture);
    if (!getResources().getBoolean(R.bool.disable_chat_send_file)) {
      sendImage.setOnClickListener(
          new View.OnClickListener() {
            @Override
            public void onClick(View v) {
              pickImage();
            }
          });
    } else {
      sendImage.setEnabled(false);
    }

    back = (TextView) view.findViewById(R.id.back);
    if (back != null) {
      back.setOnClickListener(
          new View.OnClickListener() {
            @Override
            public void onClick(View v) {
              getActivity().finish();
            }
          });
    }

    cancelUpload = (ImageView) view.findViewById(R.id.cancelUpload);
    cancelUpload.setOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View v) {
            if (currentMessageInFileTransferUploadState != null) {
              uploadLayout.setVisibility(View.GONE);
              textLayout.setVisibility(View.VISIBLE);
              progressBar.setProgress(0);
              currentMessageInFileTransferUploadState.cancelFileTransfer();
              currentMessageInFileTransferUploadState = null;
            }
          }
        });

    LinphoneCore lc = LinphoneManager.getLcIfManagerNotDestroyedOrNull();
    if (lc != null) {
      chatRoom = lc.getOrCreateChatRoom(sipUri);
      // Only works if using liblinphone storage
      chatRoom.markAsRead();
    }

    mListener =
        new LinphoneCoreListenerBase() {
          @Override
          public void messageReceived(
              LinphoneCore lc, LinphoneChatRoom cr, LinphoneChatMessage message) {
            LinphoneAddress from = cr.getPeerAddress();
            if (from.asStringUriOnly().equals(sipUri)) {
              invalidate();
            }
          }

          @Override
          public void isComposingReceived(LinphoneCore lc, LinphoneChatRoom room) {
            if (chatRoom != null
                && room != null
                && chatRoom
                    .getPeerAddress()
                    .asStringUriOnly()
                    .equals(room.getPeerAddress().asStringUriOnly())) {
              remoteComposing.setVisibility(
                  chatRoom.isRemoteComposing() ? View.VISIBLE : View.GONE);
            }
          }
        };

    textWatcher =
        new TextWatcher() {
          public void afterTextChanged(Editable arg0) {}

          public void beforeTextChanged(CharSequence arg0, int arg1, int arg2, int arg3) {}

          public void onTextChanged(CharSequence arg0, int arg1, int arg2, int arg3) {
            if (message.getText().toString().equals("")) {
              sendMessage.setEnabled(false);
            } else {
              if (chatRoom != null) chatRoom.compose();
              sendMessage.setEnabled(true);
            }
          }
        };

    // Force hide keyboard
    getActivity()
        .getWindow()
        .setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);

    return view;
  }
  // Added by me
  public void createGroupChat(String groupName, String[] groupMembers, int groupSize) {
    // Intent intent = new Intent(this, ChatActivity.class);
    // intent.putExtra("GroupName", groupName);
    // intent.putExtra("GroupMembers", groupMembers);
    // intent.putExtra("GroupSize", groupSize);
    // intent.putExtra("ChatType", 1);

    LinphoneCore lc = LinphoneManager.getLcIfManagerNotDestroyedOrNull();
    if (lc != null) {
      LinphoneChatRoom chatRoom = null;
      chatRoom = lc.getOrCreateGroupChatRoom(groupName, groupMembers, groupSize, 0, 0);

      if (chatRoom != null) {
        LinphoneAddress la = chatRoom.getPeerAddress();

        String sipUri = la.asStringUriOnly();
        String displayName = la.getDisplayName();
        String addrStr = la.asString();

        // intent.putExtra("SipUri", sipUri);
        // intent.putExtra("DisplayName", displayName);

        LinphoneProxyConfig pc = lc.getDefaultProxyConfig();
        String identity = pc.getIdentity();

        String id = "";
        try {
          la = LinphoneCoreFactory.instance().createLinphoneAddress(identity);
          id = la.getUserName();
        } catch (LinphoneCoreException e) {
          Log.e("Cannot display chat", e);
          // return;
        }

        String message = id + " created group " + groupName;
        LinphoneChatMessage msg = chatRoom.createLinphoneGroupChatMessage(message);
        chatRoom.sendGroupChatMessage(msg);
        // chatRoom.sendGroupMessage(message);

        onMessageSent(sipUri, message);

        goToChatList();

        /*String toDisplay = "Display Name: " + displayName;
        toDisplay += "\nSIP URI: " + sipUri;
        toDisplay += "\nGroup Name: " + chatRoom.getGroupName();
        toDisplay += "\nGroup Address: " + addrStr;
        displayCustomToast(toDisplay, Toast.LENGTH_SHORT);*/
      }

      // LinphoneProxyConfig pc = lc.getDefaultProxyConfig();
      // String identity = pc.getIdentity();
      // displayCustomToast("I am: " + identity, Toast.LENGTH_SHORT);
    }

    /*startOrientationSensor();
    startActivityForResult(intent, CHAT_ACTIVITY);

    LinphoneService.instance().resetMessageNotifCount();
    LinphoneService.instance().removeMessageNotification();
    displayMissedChats(getChatStorage().getUnreadMessageCount());*/
  }
  @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();
  }
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    instance = this;

    getWindow()
        .addFlags(
            WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON
                | WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED);
    setContentView(R.layout.incall);

    isTransferAllowed = getApplicationContext().getResources().getBoolean(R.bool.allow_transfers);
    isSpeakerEnabled = LinphoneManager.getLcIfManagerNotDestroyedOrNull().isSpeakerEnabled();

    if (Version.sdkAboveOrEqual(Version.API11_HONEYCOMB_30)) {
      if (!BluetoothManager.getInstance().isBluetoothHeadsetAvailable()) {
        BluetoothManager.getInstance().initBluetooth();
      } else {
        isSpeakerEnabled = false;
      }
    }

    isAnimationDisabled =
        getApplicationContext().getResources().getBoolean(R.bool.disable_animations)
            || !LinphonePreferences.instance().areAnimationsEnabled();

    mListener =
        new LinphoneCoreListenerBase() {
          @Override
          public void callState(
              LinphoneCore lc, final LinphoneCall call, LinphoneCall.State state, String message) {
            if (LinphoneManager.getLc().getCallsNb() == 0) {
              finish();
              return;
            }

            if (state == State.IncomingReceived) {
              startIncomingCallActivity();
              return;
            }

            if (state == State.StreamsRunning) {
              LinphoneManager.getLc().enableSpeaker(isSpeakerEnabled);

              isMicMuted = LinphoneManager.getLc().isMicMuted();
              enableAndRefreshInCallActions();

              if (status != null) {
                status.refreshStatusItems(call);
              }
            }

            refreshInCallActions();

            refreshCallList(getResources());

            if (state == State.CallUpdatedByRemote) {
              acceptCallUpdate();
              return;
            }

            transfer.setEnabled(LinphoneManager.getLc().getCurrentCall() != null);
          }
        };

    if (findViewById(R.id.fragmentContainer) != null) {

      initUI();

      if (LinphoneManager.getLc().getCallsNb() > 0) {
        LinphoneCall call = LinphoneManager.getLc().getCalls()[0];

        if (LinphoneUtils.isCallEstablished(call)) {
          enableAndRefreshInCallActions();
        }
      }

      if (savedInstanceState != null) {
        // Fragment already created, no need to create it again (else it will generate a memory leak
        // with duplicated fragments)
        isSpeakerEnabled = savedInstanceState.getBoolean("Speaker");
        isMicMuted = savedInstanceState.getBoolean("Mic");
        refreshInCallActions();
        return;
      }

      audioCallFragment = new AudioCallFragment();

      if (BluetoothManager.getInstance().isBluetoothHeadsetAvailable()) {
        BluetoothManager.getInstance().routeAudioToBluetooth();
      }

      audioCallFragment.setArguments(getIntent().getExtras());
      getSupportFragmentManager()
          .beginTransaction()
          .add(R.id.fragmentContainer, audioCallFragment)
          .commitAllowingStateLoss();
    }
  }