@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); } } }
private void displayChatHeader(String displayName, String pictureUri) { LinphoneAddress lAddress; try { lAddress = LinphoneCoreFactory.instance().createLinphoneAddress(sipUri); Contact contact = ContactsManager.getInstance() .findContactWithAddress(getActivity().getContentResolver(), lAddress); if (contact != null) { LinphoneUtils.setImagePictureFromUri( getActivity(), contactPicture.getView(), contact.getPhotoUri(), contact.getThumbnailUri(), R.drawable.unknown_small); } else { contactPicture.setImageResource(R.drawable.unknown_small); } } catch (LinphoneCoreException e) { e.printStackTrace(); } contactName.setTextSize(15); if (displayName == null && getResources().getBoolean(R.bool.only_display_username_if_unknown) && LinphoneUtils.isSipAddress(sipUri)) { contactName.setText(LinphoneUtils.getUsernameFromAddress(sipUri)); } else if (displayName == null) { contactName.setText(sipUri); } else { contactName.setText(displayName); } }
public boolean onKeyDown(int keyCode, KeyEvent event) { if (keyCode == KeyEvent.KEYCODE_BACK) { if (currentFragment == FragmentsAvailable.DIALER || currentFragment == FragmentsAvailable.CONTACTS || currentFragment == FragmentsAvailable.HISTORY || currentFragment == FragmentsAvailable.CHATLIST || currentFragment == FragmentsAvailable.ABOUT_INSTEAD_OF_CHAT || currentFragment == FragmentsAvailable.ABOUT_INSTEAD_OF_SETTINGS) { boolean isBackgroundModeActive = LinphonePreferences.instance().isBackgroundModeEnabled(); if (!isBackgroundModeActive) { stopService(new Intent(Intent.ACTION_MAIN).setClass(this, LinphoneService.class)); finish(); } else if (LinphoneUtils.onKeyBackGoHome(this, keyCode, event)) { return true; } } else { if (isTablet()) { if (currentFragment == FragmentsAvailable.SETTINGS) { updateAnimationsState(); } } } } else if (keyCode == KeyEvent.KEYCODE_MENU && statusFragment != null) { if (event.getRepeatCount() < 1) { statusFragment.openOrCloseStatusBar(true); } } return super.onKeyDown(keyCode, event); }
@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 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)); } } } } }
private void displayChatHeader(String displayName, String pictureUri) { if (displayName == null && getResources().getBoolean(R.bool.only_display_username_if_unknown) && LinphoneUtils.isSipAddress(sipUri)) { contactName.setText(LinphoneUtils.getUsernameFromAddress(sipUri)); } else if (displayName == null) { contactName.setText(sipUri); } else { contactName.setText(displayName); } if (pictureUri != null) { LinphoneUtils.setImagePictureFromUri( view.getContext(), contactPicture.getView(), Uri.parse(pictureUri), R.drawable.unknown_small); } else { contactPicture.setImageResource(R.drawable.unknown_small); } }
private void displayOrHideContactPicture( LinearLayout callView, Uri pictureUri, Uri thumbnailUri, boolean hide) { AvatarWithShadow contactPicture = (AvatarWithShadow) callView.findViewById(R.id.contactPicture); if (pictureUri != null) { LinphoneUtils.setImagePictureFromUri( callView.getContext(), contactPicture.getView(), Uri.parse(pictureUri.toString()), thumbnailUri, R.drawable.unknown_small); } callView.setVisibility(hide ? View.GONE : View.VISIBLE); }
public void showStatusBar() { if (isTablet()) { return; } if (statusFragment != null && !statusFragment.isVisible()) { // Hack to ensure statusFragment is visible after coming back to // dialer from chat statusFragment.getView().setVisibility(View.VISIBLE); } findViewById(R.id.status).setVisibility(View.VISIBLE); findViewById(R.id.fragmentContainer) .setPadding(0, LinphoneUtils.pixelsToDpi(getResources(), 40), 0, 0); }
private void setContactName( LinearLayout callView, LinphoneAddress lAddress, String sipUri, Resources resources) { TextView contact = (TextView) callView.findViewById(R.id.contactNameOrNumber); Contact lContact = ContactsManager.getInstance() .findContactWithAddress(callView.getContext().getContentResolver(), lAddress); if (lContact == null) { if (resources.getBoolean(R.bool.only_display_username_if_unknown) && LinphoneUtils.isSipAddress(sipUri)) { contact.setText(lAddress.getUserName()); } else { contact.setText(sipUri); } } else { contact.setText(lContact.getName()); } }
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); } } }
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 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; }
@Override public boolean onKeyDown(int keyCode, KeyEvent event) { if (LinphoneUtils.onKeyVolumeAdjust(keyCode)) return true; if (LinphoneUtils.onKeyBackGoHome(this, keyCode, event)) return true; return super.onKeyDown(keyCode, event); }
@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(); } }
public View getView(int position, View convertView, ViewGroup parent) { View view = null; if (convertView != null) { view = convertView; } else { view = mInflater.inflate(R.layout.chatlist_cell, parent, false); } String contact; boolean isDraft = false; if (position >= mDrafts.size()) { contact = mConversations.get(position - mDrafts.size()); } else { contact = mDrafts.get(position); isDraft = true; } view.setTag(contact); int unreadMessagesCount = LinphoneActivity.instance().getChatStorage().getUnreadMessageCount(contact); LinphoneAddress address; try { address = LinphoneCoreFactory.instance().createLinphoneAddress(contact); } catch (LinphoneCoreException e) { Log.e("Chat view cannot parse address", e); return view; } LinphoneUtils.findUriPictureOfContactAndSetDisplayName( address, view.getContext().getContentResolver()); String message = ""; if (useNativeAPI) { LinphoneChatRoom chatRoom = LinphoneManager.getLc().getOrCreateChatRoom(contact); LinphoneChatMessage[] history = chatRoom.getHistory(20); if (history != null && history.length > 0) { for (int i = history.length - 1; i >= 0; i--) { LinphoneChatMessage msg = history[i]; if (msg.getText() != null && msg.getText().length() > 0) { message = msg.getText(); break; } } } } else { List<ChatMessage> messages = LinphoneActivity.instance().getChatMessages(contact); if (messages != null && messages.size() > 0) { int iterator = messages.size() - 1; ChatMessage lastMessage = null; while (iterator >= 0) { lastMessage = messages.get(iterator); if (lastMessage.getMessage() == null) { iterator--; } else { iterator = -1; } } message = (lastMessage == null || lastMessage.getMessage() == null) ? "" : lastMessage.getMessage(); } } TextView lastMessageView = (TextView) view.findViewById(R.id.lastMessage); lastMessageView.setText(message); TextView sipUri = (TextView) view.findViewById(R.id.sipUri); sipUri.setSelected(true); // For animation if (getResources().getBoolean(R.bool.only_display_username_if_unknown) && address.getDisplayName() != null && LinphoneUtils.isSipAddress(address.getDisplayName())) { address.setDisplayName(LinphoneUtils.getUsernameFromAddress(address.getDisplayName())); } else if (getResources().getBoolean(R.bool.only_display_username_if_unknown) && LinphoneUtils.isSipAddress(contact)) { contact = LinphoneUtils.getUsernameFromAddress(contact); } sipUri.setText(address.getDisplayName() == null ? contact : address.getDisplayName()); if (isDraft) { view.findViewById(R.id.draft).setVisibility(View.VISIBLE); } ImageView delete = (ImageView) view.findViewById(R.id.delete); TextView unreadMessages = (TextView) view.findViewById(R.id.unreadMessages); if (unreadMessagesCount > 0) { unreadMessages.setVisibility(View.VISIBLE); unreadMessages.setText(String.valueOf(unreadMessagesCount)); } else { unreadMessages.setVisibility(View.GONE); } if (isEditMode) { delete.setVisibility(View.VISIBLE); } else { delete.setVisibility(View.INVISIBLE); } return view; }