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 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); } } }
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(); }
@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 int getStatusIconResource( LinphoneCore.RegistrationState state, boolean isDefaultAccount) { try { LinphoneCore lc = RedfoxManager.getLcIfManagerNotDestroyedOrNull(); boolean defaultAccountConnected = (isDefaultAccount && lc != null && lc.getDefaultProxyConfig() != null && lc.getDefaultProxyConfig().isRegistered()) || !isDefaultAccount; if (state == RegistrationState.RegistrationOk && defaultAccountConnected) { return R.drawable.led_connected; } else if (state == RegistrationState.RegistrationProgress) { return R.drawable.led_inprogress; } else if (state == RegistrationState.RegistrationFailed) { return R.drawable.led_error; } else { return R.drawable.led_disconnected; } } catch (Exception e) { e.printStackTrace(); } return R.drawable.led_disconnected; }
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); } }
@Override public View onCreateView( LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View view = inflater.inflate(R.layout.status, container, false); statusText = (TextView) view.findViewById(R.id.status_text); statusLed = (ImageView) view.findViewById(R.id.status_led); mListener = new LinphoneCoreListenerBase() { @Override public void registrationState( final LinphoneCore lc, final LinphoneProxyConfig proxy, final LinphoneCore.RegistrationState state, String smessage) { if (!isAttached || !RedfoxService.isReady()) { return; } if (lc.getProxyConfigList() == null) { statusLed.setImageResource(R.drawable.led_disconnected); statusText.setText(getString(R.string.no_account)); } else { statusLed.setVisibility(View.VISIBLE); } if (lc.getDefaultProxyConfig() != null && lc.getDefaultProxyConfig().equals(proxy)) { statusLed.setImageResource(getStatusIconResource(state, true)); statusText.setText(getStatusIconText(state)); } else if (lc.getDefaultProxyConfig() == null) { statusLed.setImageResource(getStatusIconResource(state, true)); statusText.setText(getStatusIconText(state)); } try { statusText.setOnClickListener( new OnClickListener() { @Override public void onClick(View v) { lc.refreshRegisters(); } }); } catch (IllegalStateException ise) { } } }; LinphoneCore lc = RedfoxManager.getLcIfManagerNotDestroyedOrNull(); if (lc != null) { lc.addListener(mListener); LinphoneProxyConfig lpc = lc.getDefaultProxyConfig(); if (lpc != null) { mListener.registrationState(lc, lpc, lpc.getState(), null); } } return view; }
public void pauseOrResumeConference() { LinphoneCore lc = LinphoneManager.getLc(); if (lc.isInConference()) { lc.leaveConference(); } else { lc.enterConference(); } }
@Override public void onDestroy() { LinphoneCore lc = RedfoxManager.getLcIfManagerNotDestroyedOrNull(); if (lc != null) { lc.removeListener(mListener); } super.onDestroy(); }
@Override protected void onPause() { LinphoneCore lc = LinphoneManager.getLcIfManagerNotDestroyedOrNull(); if (lc != null) { lc.removeListener(mListener); } super.onPause(); }
@Override protected void onResume() { super.onResume(); LinphoneCore lc = LinphoneManager.getLcIfManagerNotDestroyedOrNull(); if (lc != null) { lc.addListener(mListener); } }
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); } }
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; }
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); }
@Override protected void tearDown() throws Exception { // TODO Auto-generated method stub super.tearDown(); mCore.destroy(); mCore = 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()); }
@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()); }
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 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(); } } }
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); } }
@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(); }
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(); } }
@Override public void onResume() { super.onResume(); LinphoneCore lc = RedfoxManager.getLcIfManagerNotDestroyedOrNull(); if (lc != null) { LinphoneCall call = lc.getCurrentCall(); if (isInCall && (call != null || lc.getConferenceSize() > 1 || lc.getCallsNb() > 0)) { // We are obviously connected if (lc.getDefaultProxyConfig() == null) { statusLed.setImageResource(R.drawable.led_disconnected); statusText.setText(getString(R.string.no_account)); } else { statusLed.setImageResource( getStatusIconResource(lc.getDefaultProxyConfig().getState(), true)); statusText.setText(getStatusIconText(lc.getDefaultProxyConfig().getState())); } } } else { statusText.setVisibility(View.VISIBLE); } }
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); } } }
@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());*/ }