@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 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); } } } } }
private String getString(int key) { if (mContext == null && LinphoneManager.isInstanciated()) { mContext = LinphoneManager.getInstance().getContext(); } return mContext.getString(key); }
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(); } }
@Override public void setAddresGoToDialerAndCall(String number, String name, Uri photo) { // Bundle extras = new Bundle(); // extras.putString("SipUri", number); // extras.putString("DisplayName", name); // extras.putString("Photo", photo == null ? null : photo.toString()); // changeCurrentFragment(FragmentsAvailable.DIALER, extras); AddressType address = new AddressText(this, null); address.setDisplayedName(name); address.setText(number); LinphoneManager.getInstance().newOutgoingCall(address); }
@Override protected void onDestroy() { LinphoneManager.getInstance().changeStatusToOnline(); if (mControlsHandler != null && mControls != null) { mControlsHandler.removeCallbacks(mControls); } mControls = null; mControlsHandler = null; unbindDrawables(findViewById(R.id.topLayout)); instance = null; super.onDestroy(); System.gc(); }
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); }
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); // } // }); }
@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(); }
private void initUI() { inflater = LayoutInflater.from(this); container = (ViewGroup) findViewById(R.id.topLayout); callsList = (TableLayout) findViewById(R.id.calls); micro = (TextView) findViewById(R.id.micro); micro.setOnClickListener(this); // micro.setEnabled(false); speaker = (TextView) findViewById(R.id.speaker); speaker.setOnClickListener(this); if (isTablet()) { speaker.setEnabled(false); } // speaker.setEnabled(false); addCall = (TextView) findViewById(R.id.addCall); addCall.setOnClickListener(this); addCall.setEnabled(false); transfer = (TextView) findViewById(R.id.transfer); transfer.setOnClickListener(this); transfer.setEnabled(false); options = (TextView) findViewById(R.id.options); options.setOnClickListener(this); options.setEnabled(false); pause = (TextView) findViewById(R.id.pause); pause.setOnClickListener(this); pause.setEnabled(false); hangUp = (TextView) findViewById(R.id.hangUp); hangUp.setOnClickListener(this); conference = (TextView) findViewById(R.id.conference); conference.setOnClickListener(this); dialer = (TextView) findViewById(R.id.dialer); dialer.setOnClickListener(this); dialer.setEnabled(false); numpad = (Numpad) findViewById(R.id.numpad); try { routeLayout = (LinearLayout) findViewById(R.id.routesLayout); audioRoute = (TextView) findViewById(R.id.audioRoute); audioRoute.setOnClickListener(this); routeSpeaker = (TextView) findViewById(R.id.routeSpeaker); routeSpeaker.setOnClickListener(this); routeReceiver = (TextView) findViewById(R.id.routeReceiver); routeReceiver.setOnClickListener(this); routeBluetooth = (TextView) findViewById(R.id.routeBluetooth); routeBluetooth.setOnClickListener(this); } catch (NullPointerException npe) { Log.e("Bluetooth: Audio routes menu disabled on tablets for now (1)"); } mControlsLayout = (ViewGroup) findViewById(R.id.menu); if (!isTransferAllowed) { addCall.setBackgroundResource(R.drawable.options_add_call); } if (!isAnimationDisabled) { slideInRightToLeft = AnimationUtils.loadAnimation(this, R.anim.slide_in_right_to_left); slideOutLeftToRight = AnimationUtils.loadAnimation(this, R.anim.slide_out_left_to_right); slideInBottomToTop = AnimationUtils.loadAnimation(this, R.anim.slide_in_bottom_to_top); slideInTopToBottom = AnimationUtils.loadAnimation(this, R.anim.slide_in_top_to_bottom); slideOutBottomToTop = AnimationUtils.loadAnimation(this, R.anim.slide_out_bottom_to_top); slideOutTopToBottom = AnimationUtils.loadAnimation(this, R.anim.slide_out_top_to_bottom); } if (BluetoothManager.getInstance().isBluetoothHeadsetAvailable()) { try { if (routeLayout != null) routeLayout.setVisibility(View.VISIBLE); audioRoute.setVisibility(View.VISIBLE); speaker.setVisibility(View.GONE); } catch (NullPointerException npe) { Log.e("Bluetooth: Audio routes menu disabled on tablets for now (2)"); } } else { try { if (routeLayout != null) routeLayout.setVisibility(View.GONE); audioRoute.setVisibility(View.GONE); speaker.setVisibility(View.VISIBLE); } catch (NullPointerException npe) { Log.e("Bluetooth: Audio routes menu disabled on tablets for now (3)"); } } LinphoneManager.getInstance().changeStatusToOnThePhone(); }
public void setTunnelMode(String mode) { getConfig().setString("app", "tunnel", mode); LinphoneManager.getInstance().initTunnelFromConf(); }