Working bluetooth
// FREEBIE
This commit is contained in:
parent
d83a3d71bc
commit
961b9b882f
7 changed files with 80 additions and 40 deletions
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) {
|
||||
mediaPlayer.setLooping(loopEnabled);
|
||||
// AudioManager am = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
|
||||
// if (am.isBluetoothScoAvailableOffCall()
|
||||
// && ApplicationPreferencesActivity.getBluetoothEnabled(context)) {
|
||||
// am.startBluetoothSco();
|
||||
// am.setBluetoothScoOn(true);
|
||||
// }
|
||||
|
||||
AudioManager am = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
|
||||
|
||||
if (am.isBluetoothScoAvailableOffCall()) {
|
||||
am.startBluetoothSco();
|
||||
am.setBluetoothScoOn(true);
|
||||
}
|
||||
|
||||
mediaPlayer.start();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -20,7 +20,6 @@ package org.thoughtcrime.redphone.ui;
|
|||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.IntentFilter;
|
||||
import android.graphics.Color;
|
||||
import android.media.AudioManager;
|
||||
import android.os.Handler;
|
||||
import android.os.Message;
|
||||
|
@ -209,9 +208,9 @@ public class CallControls extends RelativeLayout {
|
|||
audioButton.setAudioMode(AudioUtils.getCurrentAudioMode(getContext()));
|
||||
|
||||
// if(ApplicationPreferencesActivity.getBluetoothEnabled(getContext())) {
|
||||
// IntentFilter filter = new IntentFilter();
|
||||
// filter.addAction(AudioUtils.getScoUpdateAction());
|
||||
// handleBluetoothIntent(getContext().registerReceiver(null, filter));
|
||||
IntentFilter filter = new IntentFilter();
|
||||
filter.addAction(AudioUtils.getScoUpdateAction());
|
||||
handleBluetoothIntent(getContext().registerReceiver(null, filter));
|
||||
// }
|
||||
}
|
||||
|
||||
|
@ -226,12 +225,12 @@ public class CallControls extends RelativeLayout {
|
|||
}
|
||||
|
||||
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())) {
|
||||
// audioButton.setHeadsetAvailable(true);
|
||||
// } else if (state.equals(AudioManager.SCO_AUDIO_STATE_DISCONNECTED)) {
|
||||
audioButton.setHeadsetAvailable(true);
|
||||
} else if (state.equals(AudioManager.SCO_AUDIO_STATE_DISCONNECTED)) {
|
||||
audioButton.setHeadsetAvailable(false);
|
||||
// }
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -3,12 +3,11 @@ package org.thoughtcrime.redphone.ui;
|
|||
import android.content.Context;
|
||||
import android.graphics.drawable.LayerDrawable;
|
||||
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.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.widget.CompoundButton;
|
||||
import android.widget.PopupMenu;
|
||||
|
||||
import org.thoughtcrime.redphone.util.AudioUtils;
|
||||
import org.thoughtcrime.securesms.R;
|
||||
|
@ -30,9 +29,9 @@ import static org.thoughtcrime.redphone.util.AudioUtils.AudioMode.SPEAKER;
|
|||
*/
|
||||
public class InCallAudioButton {
|
||||
private static final String TAG = InCallAudioButton.class.getName();
|
||||
private static final int HANDSET_ID = 0x10;
|
||||
private static final int HEADSET_ID = 0x20;
|
||||
private static final int SPEAKER_ID = 0x30;
|
||||
// private static final int HANDSET_ID = 0x10;
|
||||
// private static final int HEADSET_ID = 0x20;
|
||||
// private static final int SPEAKER_ID = 0x30;
|
||||
|
||||
private final CompoundButton mAudioButton;
|
||||
private boolean headsetAvailable;
|
||||
|
@ -160,32 +159,62 @@ public class InCallAudioButton {
|
|||
}
|
||||
|
||||
private void displayAudioChoiceDialog() {
|
||||
MenuBuilder mb = new MenuBuilder(context);
|
||||
mb.add(0, HANDSET_ID, 0, "Handset");
|
||||
mb.add(0, HEADSET_ID, 0, "Headset");
|
||||
mb.add(0, SPEAKER_ID, 0, "Speaker");
|
||||
mb.setCallback(new AudioRoutingPopupListener());
|
||||
// MenuBuilder mb = new MenuBuilder(context);
|
||||
// mb.add(0, HANDSET_ID, 0, "Handset");
|
||||
// mb.add(0, HEADSET_ID, 0, "Headset");
|
||||
// mb.add(0, SPEAKER_ID, 0, "Speaker");
|
||||
// mb.setCallback(new AudioRoutingPopupListener());
|
||||
|
||||
View attachmentView = ((View) mAudioButton.getParent()).findViewById(R.id.menuAttachment);
|
||||
PopupMenu popupMenu = new PopupMenu(context, attachmentView);
|
||||
// View attachmentView = ((View) mAudioButton.getParent()).findViewById(R.id.menuAttachment);
|
||||
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();
|
||||
// MenuPopupHelper mph = new MenuPopupHelper(context, mb, attachmentView);
|
||||
//
|
||||
// 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
|
||||
public boolean onMenuItemSelected(MenuBuilder menu, MenuItem item) {
|
||||
public boolean onMenuItemClick(MenuItem item) {
|
||||
switch (item.getItemId()) {
|
||||
case HANDSET_ID:
|
||||
case R.id.handset:
|
||||
currentMode = DEFAULT;
|
||||
break;
|
||||
case HEADSET_ID:
|
||||
case R.id.headset:
|
||||
currentMode = HEADSET;
|
||||
break;
|
||||
case SPEAKER_ID:
|
||||
case R.id.speaker:
|
||||
currentMode = SPEAKER;
|
||||
break;
|
||||
default:
|
||||
|
@ -197,11 +226,5 @@ public class InCallAudioButton {
|
|||
updateView();
|
||||
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
|
||||
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
|
||||
public Drawable asCallCard(Context context) {
|
||||
return context.getDrawable(resourceId);
|
||||
return context.getResources().getDrawable(resourceId);
|
||||
}
|
||||
|
||||
private static class ExpandingLayerDrawable extends LayerDrawable {
|
||||
|
|
|
@ -23,6 +23,6 @@ public class TransparentContactPhoto implements ContactPhoto {
|
|||
|
||||
@Override
|
||||
public Drawable asCallCard(Context context) {
|
||||
return context.getDrawable(R.drawable.ic_contact_picture);
|
||||
return context.getResources().getDrawable(R.drawable.ic_contact_picture);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue