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); } }
private String getString(int key) { if (mContext == null && LinphoneManager.isInstanciated()) { mContext = LinphoneManager.getInstance().getContext(); } return mContext.getString(key); }
@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 onSaveInstanceState(Bundle outState) { outState.putBoolean("Speaker", LinphoneManager.getLc().isSpeakerEnabled()); outState.putBoolean("Mic", LinphoneManager.getLc().isMicMuted()); super.onSaveInstanceState(outState); }
@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; }
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 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 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)); } } } } }
@Override public void onClick(View v) { int id = v.getId(); if (id == R.id.micro) { toggleMicro(); } else if (id == R.id.speaker) { toggleSpeaker(); } else if (id == R.id.addCall) { goBackToDialer(); } else if (id == R.id.pause) { pauseOrResumeCall(); } else if (id == R.id.hangUp) { hangUp(); } else if (id == R.id.dialer) { hideOrDisplayNumpad(); } else if (id == R.id.conference) { enterConference(); } else if (id == R.id.transfer) { goBackToDialerAndDisplayTransferButton(); } else if (id == R.id.options) { hideOrDisplayCallOptions(); } else if (id == R.id.audioRoute) { hideOrDisplayAudioRoutes(); } else if (id == R.id.routeBluetooth) { if (BluetoothManager.getInstance().routeAudioToBluetooth()) { isSpeakerEnabled = false; routeBluetooth.setBackgroundResource(R.drawable.route_bluetooth_on); routeReceiver.setBackgroundResource(R.drawable.route_receiver_off); routeSpeaker.setBackgroundResource(R.drawable.route_speaker_off); } hideOrDisplayAudioRoutes(); } else if (id == R.id.routeReceiver) { LinphoneManager.getInstance().routeAudioToReceiver(); isSpeakerEnabled = false; routeBluetooth.setBackgroundResource(R.drawable.route_bluetooth_off); routeReceiver.setBackgroundResource(R.drawable.route_receiver_on); routeSpeaker.setBackgroundResource(R.drawable.route_speaker_off); hideOrDisplayAudioRoutes(); } else if (id == R.id.routeSpeaker) { LinphoneManager.getInstance().routeAudioToSpeaker(); isSpeakerEnabled = true; routeBluetooth.setBackgroundResource(R.drawable.route_bluetooth_off); routeReceiver.setBackgroundResource(R.drawable.route_receiver_off); routeSpeaker.setBackgroundResource(R.drawable.route_speaker_on); hideOrDisplayAudioRoutes(); } else if (id == R.id.callStatus) { LinphoneCall call = (LinphoneCall) v.getTag(); pauseOrResumeCall(call); } else if (id == R.id.conferenceStatus) { pauseOrResumeConference(); } }
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); } }
@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(); }
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(); } }
public LpConfig getConfig() { LinphoneCore lc = getLc(); if (lc != null) { return lc.getConfig(); } if (!LinphoneManager.isInstanciated()) { Log.w("LinphoneManager not instanciated yet..."); return LinphoneCoreFactory.instance() .createLpConfig(mContext.getFilesDir().getAbsolutePath() + "/.linphonerc"); } return LinphoneCoreFactory.instance() .createLpConfig(LinphoneManager.getInstance().mLinphoneConfigFile); }
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 setTunnelPort(int port) { TunnelConfig config = getTunnelConfig(); if (config != null) { config.setPort(port); LinphoneManager.getInstance().initTunnelFromConf(); } }
public void setTunnelHost(String host) { TunnelConfig config = getTunnelConfig(); if (config != null) { config.setHost(host); LinphoneManager.getInstance().initTunnelFromConf(); } }
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"); } }
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); } }
@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(); }
public void onCreate() { super.onCreate(); Log.m11091e("dddd", "Call SipLibService onCreate"); Log.m11095i(START_LINPHONE_LOGS); this.mNM = (NotificationManager) getSystemService("notification"); LinphoneManager.createAndStart(this, this); this.mWifiManager = (WifiManager) getSystemService("wifi"); if (Version.sdkAboveOrEqual(12)) { startWifiLock(); } instance = this; if (Version.sdkStrictlyBelow(5)) { try { getClass().getMethod("setForeground", mSetFgSign); } catch (Throwable e) { Log.m11090e(e, "Couldn't find foreground method"); } } else { try { getClass().getMethod("startForeground", mStartFgSign); getClass().getMethod("stopForeground", mStopFgSign); } catch (Throwable e2) { Log.m11090e(e2, "Couldn't find startGoreground or stopForeground"); } } if (!this.mTestDelayElapsed) { this.mHandler.postDelayed(new C27971(), 5000); } this.mKeepAlivePendingIntent = PendingIntent.getBroadcast( this, IC_LEVEL_ORANGE, new Intent(this, KeepAliveHandler.class), 1073741824); ((AlarmManager) getSystemService("alarm")) .setRepeating(2, SystemClock.elapsedRealtime() + 1000, 60000, this.mKeepAlivePendingIntent); }
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(); }
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); } }
@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); } } }
@Override protected void onResume() { instance = this; LinphoneManager.startProximitySensorForActivity(this); setCallControlsVisibleAndRemoveCallbacks(); super.onResume(); LinphoneCore lc = LinphoneManager.getLcIfManagerNotDestroyedOrNull(); if (lc != null) { lc.addListener(mListener); } refreshCallList(getResources()); }
public void pauseOrResumeConference() { LinphoneCore lc = LinphoneManager.getLc(); if (lc.isInConference()) { lc.leaveConference(); } else { lc.enterConference(); } }
public synchronized void onDestroy() { instance = null; LinphoneManager.destroy(); if (Version.sdkAboveOrEqual(12)) { this.mWifiLock.release(); } ((AlarmManager) getSystemService("alarm")).cancel(this.mKeepAlivePendingIntent); super.onDestroy(); }
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); } } }
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); } }