@Override public void onBackPressed() { if (BluetoothManager.getInstance() .getConnectionType() .equals(BluetoothManager.ConnectionType.HOST)) { BluetoothManager.getInstance().setConnectionType(BluetoothManager.ConnectionType.CLIENT); } BluetoothManager.getInstance().onBackPressed(); super.onBackPressed(); }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); mHandler = new Handler(); if (!getPackageManager().hasSystemFeature(PackageManager.FEATURE_BLUETOOTH_LE)) { Toast.makeText(this, "BLE Not Supported", Toast.LENGTH_SHORT).show(); finish(); } final BluetoothManager bluetoothManager = (BluetoothManager) getSystemService(Context.BLUETOOTH_SERVICE); mBluetoothAdapter = bluetoothManager.getAdapter(); }
@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 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); } } }
@Override protected void onCreate(Bundle savedInstanceState) { lobby = this; super.onCreate(savedInstanceState); requestWindowFeature(Window.FEATURE_NO_TITLE); // Titel weg getWindow() .setFlags( WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN); // Fullscreen setContentView(R.layout.current_lobby); // TODO: Als game afloopt moet bluetoothmanager op null worden gezet, ivm de if statement i // guess if (BluetoothManager.getInstance() == null || (BluetoothManager.getInstance() != null && BluetoothManager.getInstance() .getConnectionType() .equals(BluetoothManager.ConnectionType.HOST))) { findViewById(R.id.btnStartGame) .setOnClickListener( new View.OnClickListener() { @Override public void onClick(View view) { Game.isMultiplayerStarted = true; if (BluetoothManager.getInstance() != null && BluetoothManager.getInstance().getBluetoothConnection() != null) { if (BluetoothManager.getInstance() .getConnectionType() .equals(BluetoothManager.ConnectionType.HOST)) { BluetoothManager.getInstance() .getBluetoothConnection() .sendMessage(BluetoothManager.MessageType.startGame); } } startActivity(new Intent(Lobby.this, Game.class)); } }); } else { findViewById(R.id.btnStartGame).setVisibility(View.INVISIBLE); } findViewById(R.id.btnLobbyBack) .setOnClickListener( new View.OnClickListener() { @Override public void onClick(View view) { BluetoothManager.getInstance().onBackPressed(); startActivity(new Intent(Lobby.this, LobbyList.class)); } }); findViewById(R.id.btnSend) .setOnClickListener( new View.OnClickListener() { @Override public void onClick(View view) { EditText text = (EditText) findViewById(R.id.sendText); if (text.getText().toString().length() > 0) { if (BluetoothManager.getInstance() != null && BluetoothManager.getInstance().getBluetoothConnection() != null) { BluetoothManager.getInstance() .getBluetoothConnection() .sendMessage( BluetoothManager.MessageType.sChat, Settings.getName(), text.getText().toString()); addChat( Settings.getName(), text.getText() .toString()); // Hiermee wordt het bericht ook op het eigen scherm gezet text.setText(""); } } } }); ((ListView) findViewById(R.id.textHistory)) .setAdapter(new ArrayAdapter(getApplicationContext(), R.layout.simple_list_item_1)); ((ListView) findViewById(R.id.listviewPlayers)) .setAdapter(new ArrayAdapter(getApplicationContext(), R.layout.simple_list_item_1)); // Zet alvast voor de host zijn naam neer if (BluetoothManager.getInstance() .getConnectionType() .equals(BluetoothManager.ConnectionType.HOST)) { updatePlayerList(Settings.getName()); } }
public void onActivityResult(int requestCode, int resultCode, Intent data) { if (BluetoothManager.getInstance() != null) { BluetoothManager.getInstance().onActivityResult(requestCode, resultCode, data); } }
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(); }
@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(); } }
/** Starts the ringtone and/or vibrator */ void ring() { if (DBG) log("ring()..."); synchronized (this) { try { if (mBluetoothManager.showBluetoothIndication()) { mPowerManager.setAttentionLight(true, 0x000000ff); } else { mPowerManager.setAttentionLight(true, 0x00ffffff); } } catch (RemoteException ex) { // the other end of this binder call is in the system process. } /// M: if should not ring, bailing out @{ if (!shouldRing()) { return; } /// @} if (shouldVibrate() && mVibratorThread == null) { mContinueVibrating = true; mVibratorThread = new VibratorThread(); if (DBG) log("- starting vibrator..."); mVibratorThread.start(); } AudioManager audioManager = (AudioManager) mContext.getSystemService(Context.AUDIO_SERVICE); if (audioManager.getStreamVolume(AudioManager.STREAM_RING) == 0) { if (DBG) log("skipping ring because volume is zero"); /// M: update Audio Mode @{ PhoneUtils.setAudioMode(); sIsRingingAndVolumnZero = true; /// @} return; } makeLooper(); if (mFirstRingEventTime < 0) { mFirstRingEventTime = SystemClock.elapsedRealtime(); if (mRingHandler != null) { mRingHandler.sendEmptyMessage(PLAY_RING_ONCE); } } else { // For repeat rings, figure out by how much to delay // the ring so that it happens the correct amount of // time after the previous ring if (mFirstRingStartTime > 0) { // Delay subsequent rings by the delta between event // and play time of the first ring if (DBG) { log("delaying ring by " + (mFirstRingStartTime - mFirstRingEventTime)); } if (mRingHandler != null) { mRingHandler.sendEmptyMessageDelayed( PLAY_RING_ONCE, mFirstRingStartTime - mFirstRingEventTime); } } else { // We've gotten two ring events so far, but the ring // still hasn't started. Reset the event time to the // time of this event to maintain correct spacing. mFirstRingEventTime = SystemClock.elapsedRealtime(); } } } }