mirror of
https://github.com/oxen-io/session-android.git
synced 2025-04-16 09:21:25 +00:00
Working bluetooth
// FREEBIE
This commit is contained in:
parent
d83a3d71bc
commit
961b9b882f
16
res/menu/redphone_audio_popup_menu.xml
Normal file
16
res/menu/redphone_audio_popup_menu.xml
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<menu xmlns:android="http://schemas.android.com/apk/res/android">
|
||||||
|
|
||||||
|
<item
|
||||||
|
android:id="@+id/handset"
|
||||||
|
android:title="Handset"/>
|
||||||
|
|
||||||
|
<item
|
||||||
|
android:id="@+id/headset"
|
||||||
|
android:title="Headset"/>
|
||||||
|
|
||||||
|
<item
|
||||||
|
android:id="@+id/speaker"
|
||||||
|
android:title="Speaker"/>
|
||||||
|
|
||||||
|
</menu>
|
@ -140,12 +140,14 @@ public class OutgoingRinger implements MediaPlayer.OnCompletionListener,
|
|||||||
|
|
||||||
public void onPrepared(MediaPlayer mp) {
|
public void onPrepared(MediaPlayer mp) {
|
||||||
mediaPlayer.setLooping(loopEnabled);
|
mediaPlayer.setLooping(loopEnabled);
|
||||||
// AudioManager am = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
|
|
||||||
// if (am.isBluetoothScoAvailableOffCall()
|
AudioManager am = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
|
||||||
// && ApplicationPreferencesActivity.getBluetoothEnabled(context)) {
|
|
||||||
// am.startBluetoothSco();
|
if (am.isBluetoothScoAvailableOffCall()) {
|
||||||
// am.setBluetoothScoOn(true);
|
am.startBluetoothSco();
|
||||||
// }
|
am.setBluetoothScoOn(true);
|
||||||
|
}
|
||||||
|
|
||||||
mediaPlayer.start();
|
mediaPlayer.start();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -20,7 +20,6 @@ package org.thoughtcrime.redphone.ui;
|
|||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.IntentFilter;
|
import android.content.IntentFilter;
|
||||||
import android.graphics.Color;
|
|
||||||
import android.media.AudioManager;
|
import android.media.AudioManager;
|
||||||
import android.os.Handler;
|
import android.os.Handler;
|
||||||
import android.os.Message;
|
import android.os.Message;
|
||||||
@ -209,9 +208,9 @@ public class CallControls extends RelativeLayout {
|
|||||||
audioButton.setAudioMode(AudioUtils.getCurrentAudioMode(getContext()));
|
audioButton.setAudioMode(AudioUtils.getCurrentAudioMode(getContext()));
|
||||||
|
|
||||||
// if(ApplicationPreferencesActivity.getBluetoothEnabled(getContext())) {
|
// if(ApplicationPreferencesActivity.getBluetoothEnabled(getContext())) {
|
||||||
// IntentFilter filter = new IntentFilter();
|
IntentFilter filter = new IntentFilter();
|
||||||
// filter.addAction(AudioUtils.getScoUpdateAction());
|
filter.addAction(AudioUtils.getScoUpdateAction());
|
||||||
// handleBluetoothIntent(getContext().registerReceiver(null, filter));
|
handleBluetoothIntent(getContext().registerReceiver(null, filter));
|
||||||
// }
|
// }
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -226,12 +225,12 @@ public class CallControls extends RelativeLayout {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Integer state = intent.getIntExtra(AudioManager.EXTRA_SCO_AUDIO_STATE, -1);
|
Integer state = intent.getIntExtra(AudioManager.EXTRA_SCO_AUDIO_STATE, -1);
|
||||||
// if (state.equals(AudioManager.SCO_AUDIO_STATE_CONNECTED)
|
if (state.equals(AudioManager.SCO_AUDIO_STATE_CONNECTED)) {
|
||||||
// && ApplicationPreferencesActivity.getBluetoothEnabled(getContext())) {
|
// && ApplicationPreferencesActivity.getBluetoothEnabled(getContext())) {
|
||||||
// audioButton.setHeadsetAvailable(true);
|
audioButton.setHeadsetAvailable(true);
|
||||||
// } else if (state.equals(AudioManager.SCO_AUDIO_STATE_DISCONNECTED)) {
|
} else if (state.equals(AudioManager.SCO_AUDIO_STATE_DISCONNECTED)) {
|
||||||
audioButton.setHeadsetAvailable(false);
|
audioButton.setHeadsetAvailable(false);
|
||||||
// }
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -3,12 +3,11 @@ package org.thoughtcrime.redphone.ui;
|
|||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.graphics.drawable.LayerDrawable;
|
import android.graphics.drawable.LayerDrawable;
|
||||||
import android.support.v7.internal.view.menu.MenuBuilder;
|
import android.support.v7.internal.view.menu.MenuBuilder;
|
||||||
import android.support.v7.internal.view.menu.MenuPopupHelper;
|
import android.support.v7.widget.PopupMenu;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import android.view.MenuItem;
|
import android.view.MenuItem;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.widget.CompoundButton;
|
import android.widget.CompoundButton;
|
||||||
import android.widget.PopupMenu;
|
|
||||||
|
|
||||||
import org.thoughtcrime.redphone.util.AudioUtils;
|
import org.thoughtcrime.redphone.util.AudioUtils;
|
||||||
import org.thoughtcrime.securesms.R;
|
import org.thoughtcrime.securesms.R;
|
||||||
@ -30,9 +29,9 @@ import static org.thoughtcrime.redphone.util.AudioUtils.AudioMode.SPEAKER;
|
|||||||
*/
|
*/
|
||||||
public class InCallAudioButton {
|
public class InCallAudioButton {
|
||||||
private static final String TAG = InCallAudioButton.class.getName();
|
private static final String TAG = InCallAudioButton.class.getName();
|
||||||
private static final int HANDSET_ID = 0x10;
|
// private static final int HANDSET_ID = 0x10;
|
||||||
private static final int HEADSET_ID = 0x20;
|
// private static final int HEADSET_ID = 0x20;
|
||||||
private static final int SPEAKER_ID = 0x30;
|
// private static final int SPEAKER_ID = 0x30;
|
||||||
|
|
||||||
private final CompoundButton mAudioButton;
|
private final CompoundButton mAudioButton;
|
||||||
private boolean headsetAvailable;
|
private boolean headsetAvailable;
|
||||||
@ -160,32 +159,62 @@ public class InCallAudioButton {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void displayAudioChoiceDialog() {
|
private void displayAudioChoiceDialog() {
|
||||||
MenuBuilder mb = new MenuBuilder(context);
|
// MenuBuilder mb = new MenuBuilder(context);
|
||||||
mb.add(0, HANDSET_ID, 0, "Handset");
|
// mb.add(0, HANDSET_ID, 0, "Handset");
|
||||||
mb.add(0, HEADSET_ID, 0, "Headset");
|
// mb.add(0, HEADSET_ID, 0, "Headset");
|
||||||
mb.add(0, SPEAKER_ID, 0, "Speaker");
|
// mb.add(0, SPEAKER_ID, 0, "Speaker");
|
||||||
mb.setCallback(new AudioRoutingPopupListener());
|
// mb.setCallback(new AudioRoutingPopupListener());
|
||||||
|
|
||||||
View attachmentView = ((View) mAudioButton.getParent()).findViewById(R.id.menuAttachment);
|
// View attachmentView = ((View) mAudioButton.getParent()).findViewById(R.id.menuAttachment);
|
||||||
PopupMenu popupMenu = new PopupMenu(context, attachmentView);
|
Log.w(TAG, "Displaying popup...");
|
||||||
|
PopupMenu popupMenu = new PopupMenu(context, mAudioButton);
|
||||||
|
popupMenu.getMenuInflater().inflate(R.menu.redphone_audio_popup_menu, popupMenu.getMenu());
|
||||||
|
popupMenu.setOnMenuItemClickListener(new AudioRoutingPopupListener());
|
||||||
popupMenu.show();
|
popupMenu.show();
|
||||||
// MenuPopupHelper mph = new MenuPopupHelper(context, mb, attachmentView);
|
// MenuPopupHelper mph = new MenuPopupHelper(context, mb, attachmentView);
|
||||||
//
|
//
|
||||||
// mph.show();
|
// mph.show();
|
||||||
}
|
}
|
||||||
|
|
||||||
private class AudioRoutingPopupListener implements MenuBuilder.Callback {
|
private class AudioRoutingPopupListener implements PopupMenu.OnMenuItemClickListener {
|
||||||
|
|
||||||
|
// @Override
|
||||||
|
// public boolean onMenuItemSelected(MenuBuilder menu, MenuItem item) {
|
||||||
|
// switch (item.getItemId()) {
|
||||||
|
// case HANDSET_ID:
|
||||||
|
// currentMode = DEFAULT;
|
||||||
|
// break;
|
||||||
|
// case HEADSET_ID:
|
||||||
|
// currentMode = HEADSET;
|
||||||
|
// break;
|
||||||
|
// case SPEAKER_ID:
|
||||||
|
// currentMode = SPEAKER;
|
||||||
|
// break;
|
||||||
|
// default:
|
||||||
|
// Log.w(TAG, "Unknown item selected in audio popup menu: " + item.toString());
|
||||||
|
// }
|
||||||
|
// Log.d(TAG, "Selected: " + currentMode + " -- " + item.getItemId());
|
||||||
|
//
|
||||||
|
// listener.onAudioChange(currentMode);
|
||||||
|
// updateView();
|
||||||
|
// return true;
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// @Override
|
||||||
|
// public void onMenuModeChange(MenuBuilder menu) {
|
||||||
|
// //To change body of implemented methods use File | Settings | File Templates.
|
||||||
|
// }
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onMenuItemSelected(MenuBuilder menu, MenuItem item) {
|
public boolean onMenuItemClick(MenuItem item) {
|
||||||
switch (item.getItemId()) {
|
switch (item.getItemId()) {
|
||||||
case HANDSET_ID:
|
case R.id.handset:
|
||||||
currentMode = DEFAULT;
|
currentMode = DEFAULT;
|
||||||
break;
|
break;
|
||||||
case HEADSET_ID:
|
case R.id.headset:
|
||||||
currentMode = HEADSET;
|
currentMode = HEADSET;
|
||||||
break;
|
break;
|
||||||
case SPEAKER_ID:
|
case R.id.speaker:
|
||||||
currentMode = SPEAKER;
|
currentMode = SPEAKER;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
@ -197,11 +226,5 @@ public class InCallAudioButton {
|
|||||||
updateView();
|
updateView();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onMenuModeChange(MenuBuilder menu) {
|
|
||||||
//To change body of implemented methods use File | Settings | File Templates.
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -38,6 +38,6 @@ public class GeneratedContactPhoto implements ContactPhoto {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Drawable asCallCard(Context context) {
|
public Drawable asCallCard(Context context) {
|
||||||
return context.getDrawable(R.drawable.ic_contact_picture);
|
return context.getResources().getDrawable(R.drawable.ic_contact_picture);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -42,7 +42,7 @@ public class ResourceContactPhoto implements ContactPhoto {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Drawable asCallCard(Context context) {
|
public Drawable asCallCard(Context context) {
|
||||||
return context.getDrawable(resourceId);
|
return context.getResources().getDrawable(resourceId);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static class ExpandingLayerDrawable extends LayerDrawable {
|
private static class ExpandingLayerDrawable extends LayerDrawable {
|
||||||
|
@ -23,6 +23,6 @@ public class TransparentContactPhoto implements ContactPhoto {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Drawable asCallCard(Context context) {
|
public Drawable asCallCard(Context context) {
|
||||||
return context.getDrawable(R.drawable.ic_contact_picture);
|
return context.getResources().getDrawable(R.drawable.ic_contact_picture);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user