This is an automated email from the git hooks/post-receive script. New commit to branch develop in repository say-my-texts. See http://git.chorem.org/say-my-texts.git commit ba1a24f45ae48ce244b0f4692dfabf2739f4b2e6 Author: Kevin Morin <morin@codelutin.com> Date: Thu Aug 21 23:56:47 2014 +0200 refs #1055 Add a notification when SayMyTexts is active --- AndroidManifest.xml | 21 +- res/values-fr/strings.xml | 7 + res/values/strings.xml | 7 + .../android/saymytexts/SayMyTextService.java | 272 +++++++++++++-------- .../android/saymytexts/SettingsActivity.java | 6 +- .../BootCompletedBroadcastReceiver.java | 24 ++ .../DeviceConnectionBroadcastReceiver.java | 56 +++++ .../DictateSmsBroadcastReceiver.java | 4 +- .../NewTextBroadcastReceiver.java | 31 +-- .../SayNextActionBroadcastReceiver.java | 5 +- 10 files changed, 295 insertions(+), 138 deletions(-) diff --git a/AndroidManifest.xml b/AndroidManifest.xml index 3708ea7..79dc306 100644 --- a/AndroidManifest.xml +++ b/AndroidManifest.xml @@ -1,12 +1,12 @@ <?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="org.chorem.android.saymytexts" - android:versionCode="6" - android:versionName="2.1" + android:versionCode="8" + android:versionName="2.2" android:description="@string/app_description" android:installLocation="auto"> - <uses-sdk android:minSdkVersion="15" + <uses-sdk android:minSdkVersion="16" android:targetSdkVersion="17"/> <uses-permission android:name="android.permission.RECEIVE_SMS" /> @@ -17,6 +17,7 @@ <uses-permission android:name="android.permission.BLUETOOTH" /> <uses-permission android:name="android.permission.RECORD_AUDIO" /> <uses-permission android:name="android.permission.CALL_PHONE" /> + <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/> <uses-feature android:name="android.hardware.telephony" android:required="true"/> @@ -39,13 +40,17 @@ <service android:name=".SayMyTextService"/> - <receiver android:name=".NewTextBroadcastReceiver" + <receiver android:name=".broadcastreceiver.NewTextBroadcastReceiver" android:enabled="true"> <intent-filter android:priority="42"> <action android:name="android.provider.Telephony.SMS_RECEIVED" /> - <action android:name="android.bluetooth.device.action.ACL_CONNECTED" /> - <action android:name="android.bluetooth.device.action.ACL_DISCONNECT_REQUESTED" /> - <action android:name="android.bluetooth.device.action.ACL_DISCONNECTED" /> + </intent-filter> + </receiver> + + <receiver android:name=".broadcastreceiver.BootCompletedBroadcastReceiver" + android:enabled="true"> + <intent-filter> + <action android:name="android.intent.action.BOOT_COMPLETED" /> </intent-filter> </receiver> @@ -58,4 +63,4 @@ android:configChanges="orientation|screenSize|keyboardHidden"/> </application> -</manifest> +</manifest> \ No newline at end of file diff --git a/res/values-fr/strings.xml b/res/values-fr/strings.xml index ed45a9d..91a87a9 100644 --- a/res/values-fr/strings.xml +++ b/res/values-fr/strings.xml @@ -57,4 +57,11 @@ <string name="voice_not_recognized">Je n\'ai pas compris.</string> + <string name="notification_reading_active_title">Lecture des SMS active</string> + <string name="notification_reading_active_headset_connected">Un casque est branché.</string> + <string name="notification_reading_active_bt_device_connected">Un appareil bluetooth est connecté.</string> + <string name="notification_reading_unactive_title">Lecture des SMS inactive</string> + <string name="notification_reading_unactive_no_headset_connected">Pas de casque branché.</string> + <string name="notification_reading_unactive_no_headset_nor_bt_device_connected">Pas de casque branché ni d\'appareil bluetooth est connecté.</string> + </resources> diff --git a/res/values/strings.xml b/res/values/strings.xml index 35898d2..0866b66 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -57,4 +57,11 @@ <string name="cancel_action">cancel</string> <string name="voice_not_recognized">I did not understand.</string> + <string name="notification_reading_active_title">SMS reading active</string> + <string name="notification_reading_active_headset_connected">A headset is plugged.</string> + <string name="notification_reading_active_bt_device_connected">A bluetooth device is connected.</string> + <string name="notification_reading_unactive_title">SMS reading unactive</string> + <string name="notification_reading_unactive_no_headset_connected">No headset plugged.</string> + <string name="notification_reading_unactive_no_headset_nor_bt_device_connected">No headset plugged nor bluetooth device connected.</string> + </resources> diff --git a/src/org/chorem/android/saymytexts/SayMyTextService.java b/src/org/chorem/android/saymytexts/SayMyTextService.java index 3f1ed86..661a9f9 100644 --- a/src/org/chorem/android/saymytexts/SayMyTextService.java +++ b/src/org/chorem/android/saymytexts/SayMyTextService.java @@ -24,6 +24,9 @@ package org.chorem.android.saymytexts; * #L% */ +import android.app.Notification; +import android.app.NotificationManager; +import android.app.PendingIntent; import android.app.Service; import android.bluetooth.BluetoothDevice; import android.content.BroadcastReceiver; @@ -31,6 +34,7 @@ import android.content.Context; import android.content.Intent; import android.content.IntentFilter; import android.content.SharedPreferences; +import android.graphics.drawable.BitmapDrawable; import android.media.AudioManager; import android.net.Uri; import android.os.IBinder; @@ -41,7 +45,11 @@ import android.telephony.PhoneStateListener; import android.telephony.TelephonyManager; import android.util.Log; import android.widget.Toast; +import org.chorem.android.saymytexts.broadcastreceiver.DeviceConnectionBroadcastReceiver; +import org.chorem.android.saymytexts.broadcastreceiver.DictateSmsBroadcastReceiver; +import org.chorem.android.saymytexts.broadcastreceiver.SayNextActionBroadcastReceiver; +import java.awt.*; import java.util.ArrayList; import java.util.HashMap; import java.util.List; @@ -64,6 +72,7 @@ public class SayMyTextService extends Service implements TextToSpeech.OnInitList public static final String ACTION_REASK_ACTION = "org.chorem.android.saymytexts.REASK_ACTION"; public static final String ACTION_DICTATE_SMS = "org.chorem.android.saymytexts.DICTATE_SMS"; public static final String ACTION_CONFIRM_SMS_SENDING = "org.chorem.android.saymytexts.CONFIRM_SMS_SENDING"; + public static final String ACTION_HEADSET_PLUGGED = "org.chorem.android.saymytexts.HEADSET_PLUGGED"; /** SMS to read */ public static final String INTENT_EXTRA_SMS = "sms"; @@ -75,21 +84,34 @@ public class SayMyTextService extends Service implements TextToSpeech.OnInitList public static final String INTENT_EXTRA_DICTATED_MESSAGE = "dictatedMessage"; /** Attempt number: if set, it means that the user said something not understandable, so ask again */ public static final String INTENT_EXTRA_ATTEMPT_NUMBER = "attemptNumber"; + /** If true, a headset is plugged, false otherwise */ + public static final String INTENT_EXTRA_HEADSET_PLUGGED = "headsetPlugged"; /** utterance id when the bluetooth device is connected */ -// protected static final String BT_UTTERANCE_ID = "btUtteranceId"; protected static final String BT_ASK_NEXT_ACTION_UTTERANCE_ID = "btAskNextActionUtteranceId"; protected static final String ASK_NEXT_ACTION_UTTERANCE_ID = "askNextActionUtteranceId"; protected static final String OTHER_UTTERANCE_ID = "oherUtteranceId"; + protected static final int NOTIFICATION_ID = 42; + protected int maxAttemptNumber; + /** is reading enabled according to the settings */ + protected boolean readingActive = false; + + /** is the reading profile "always read" */ + protected boolean alwaysRead = false; + protected String readingProfile; protected boolean heisendroidModeEnabled; protected boolean interactionEnabled; + protected boolean notificationsEnabled = true; + + protected boolean notificationCancelable; + protected AudioManager audioManager; /** null if the texttospeech is not initialized */ @@ -109,6 +131,10 @@ public class SayMyTextService extends Service implements TextToSpeech.OnInitList /** bluetooth devices which are currently connected */ protected Map<BluetoothDevice, Integer> bluetoothDevices = new HashMap<>(); + protected boolean headsetPlugged = false; + + protected BroadcastReceiver deviceConnectionBroadcastReceiver; + /** * Listener to call state change */ @@ -122,8 +148,6 @@ public class SayMyTextService extends Service implements TextToSpeech.OnInitList } }; -// BluetoothHeadset mBluetoothHeadset; - @Override public void onCreate() { super.onCreate(); @@ -153,6 +177,7 @@ public class SayMyTextService extends Service implements TextToSpeech.OnInitList String[] readingProfileValues = getResources().getStringArray(R.array.preferences_reading_profile_values); String readingProfileKey = getString(R.string.preference_reading_profile_key); readingProfile = sharedPref.getString(readingProfileKey, readingProfileValues[0]); + updateReadingEnabled(); String heisendroidModeEnabledKey = getString(R.string.preference_enable_heisendroid_mode_key); heisendroidModeEnabled = sharedPref.getBoolean(heisendroidModeEnabledKey, true); @@ -162,33 +187,10 @@ public class SayMyTextService extends Service implements TextToSpeech.OnInitList sharedPref.registerOnSharedPreferenceChangeListener(this); -//// Get the default adapter -// final BluetoothAdapter mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter(); -// -//// Define Service Listener of BluetoothProfile -// BluetoothProfile.ServiceListener mProfileListener = new BluetoothProfile.ServiceListener() { -// public void onServiceConnected(int profile, BluetoothProfile proxy) { -// if (profile == BluetoothProfile.HEADSET) { -// mBluetoothHeadset = (BluetoothHeadset) proxy; -// List<BluetoothDevice> devices = mBluetoothHeadset.getConnectedDevices(); -// for ( final BluetoothDevice dev : devices ) { -// if (mBluetoothHeadset.isAudioConnected(dev)) { -// bluetoothDevices.put(dev, dev.getBluetoothClass().getDeviceClass()); -// } -// } -// mBluetoothAdapter.closeProfileProxy(BluetoothProfile.HEADSET, mBluetoothHeadset); -// } -// } -// public void onServiceDisconnected(int profile) { -// if (profile == BluetoothProfile.HEADSET) { -// mBluetoothHeadset = null; -// } -// } -// }; -// -//// Establish connection to the proxy. -// mBluetoothAdapter.getProfileProxy(this, mProfileListener, BluetoothProfile.HEADSET); - + deviceConnectionBroadcastReceiver = new DeviceConnectionBroadcastReceiver(); + IntentFilter filter = new IntentFilter(); + filter.addAction(Intent.ACTION_HEADSET_PLUG); + registerReceiver(deviceConnectionBroadcastReceiver, filter); } @Override @@ -200,6 +202,8 @@ public class SayMyTextService extends Service implements TextToSpeech.OnInitList SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(this); sharedPref.unregisterOnSharedPreferenceChangeListener(this); + + unregisterReceiver(deviceConnectionBroadcastReceiver); } @Override @@ -220,81 +224,74 @@ public class SayMyTextService extends Service implements TextToSpeech.OnInitList String action = intent.getAction(); Log.d(TAG, "action " + action); - final SMS sms = (SMS) intent.getSerializableExtra(INTENT_EXTRA_SMS); - int attemptNumber = intent.getIntExtra(INTENT_EXTRA_ATTEMPT_NUMBER, 0); - - switch (action) { - case ACTION_MANAGE_BT_DEVICE: - BluetoothDevice device = intent.getParcelableExtra(INTENT_EXTRA_BT_DEVICE); - // if a device is passed to the service - // add or remove the device from the connected devices - if (device != null) { - boolean addBtDevice = intent.getBooleanExtra(INTENT_EXTRA_ADD_BT_DEVICE, false); - if (addBtDevice) { - bluetoothDevices.put(device, device.getBluetoothClass().getDeviceClass()); - } else { - bluetoothDevices.remove(device); - } - } - break; - - case ACTION_REASK_ACTION: - askForActionAfterReading(sms, !bluetoothDevices.isEmpty(), ++attemptNumber); - break; - - case ACTION_DICTATE_SMS: - dictateSMS(sms, attemptNumber + 1); - break; - - case ACTION_CONFIRM_SMS_SENDING: - // if a message has just been dictated - final String dictatedMessage = intent.getStringExtra(INTENT_EXTRA_DICTATED_MESSAGE); - askSendingConfirmation(dictatedMessage, sms, ++attemptNumber); - break; - - case ACTION_READ_NEXT_SMS: - setCanSpeak(true); - break; - - default: - boolean readingEnabled; - String[] readingProfileValues = getResources().getStringArray(R.array.preferences_reading_profile_values); - if (readingProfileValues[0].equals(readingProfile)) { - readingEnabled = true; - - } else if (readingProfileValues[1].equals(readingProfile)) { - readingEnabled = audioManager.isWiredHeadsetOn() || !bluetoothDevices.isEmpty(); - - } else if (readingProfileValues[2].equals(readingProfile)) { - readingEnabled = audioManager.isWiredHeadsetOn(); - - } else { - readingEnabled = false; - } - - if (readingEnabled) { - if (!Boolean.FALSE.equals(canSpeak)) { - musicWasActive = audioManager.isMusicActive(); - speakerWasOn = audioManager.isSpeakerphoneOn(); - - if (musicWasActive) { - audioManager.setStreamMute(AudioManager.STREAM_MUSIC, musicWasActive); - } - - if (readingProfileValues[0].equals(readingProfile) - && !audioManager.isWiredHeadsetOn() && bluetoothDevices.isEmpty()) { - audioManager.setMode(AudioManager.MODE_IN_CALL); - audioManager.setSpeakerphoneOn(true); + if (action != null) { + final SMS sms = (SMS) intent.getSerializableExtra(INTENT_EXTRA_SMS); + int attemptNumber = intent.getIntExtra(INTENT_EXTRA_ATTEMPT_NUMBER, 0); + + switch (action) { + case ACTION_MANAGE_BT_DEVICE: + BluetoothDevice device = intent.getParcelableExtra(INTENT_EXTRA_BT_DEVICE); + // if a device is passed to the service + // add or remove the device from the connected devices + if (device != null) { + boolean addBtDevice = intent.getBooleanExtra(INTENT_EXTRA_ADD_BT_DEVICE, false); + if (addBtDevice) { + bluetoothDevices.put(device, device.getBluetoothClass().getDeviceClass()); + } else { + bluetoothDevices.remove(device); } + updateReadingEnabled(); } + break; + + case ACTION_HEADSET_PLUGGED: + headsetPlugged = intent.getBooleanExtra(INTENT_EXTRA_HEADSET_PLUGGED, false); + updateReadingEnabled(); + break; + + case ACTION_REASK_ACTION: + askForActionAfterReading(sms, !bluetoothDevices.isEmpty(), ++attemptNumber); + break; + + case ACTION_DICTATE_SMS: + dictateSMS(sms, attemptNumber + 1); + break; + + case ACTION_CONFIRM_SMS_SENDING: + // if a message has just been dictated + final String dictatedMessage = intent.getStringExtra(INTENT_EXTRA_DICTATED_MESSAGE); + askSendingConfirmation(dictatedMessage, sms, ++attemptNumber); + break; + + case ACTION_READ_NEXT_SMS: + setCanSpeak(true); + break; + + default: + if (readingActive) { + if (!Boolean.FALSE.equals(canSpeak)) { + musicWasActive = audioManager.isMusicActive(); + speakerWasOn = audioManager.isSpeakerphoneOn(); + + if (musicWasActive) { + audioManager.setStreamMute(AudioManager.STREAM_MUSIC, musicWasActive); + } + + // if read but no external device is connected, play through the speaker + if (alwaysRead && !headsetPlugged && bluetoothDevices.isEmpty()) { + audioManager.setMode(AudioManager.MODE_IN_CALL); + audioManager.setSpeakerphoneOn(true); + } + } - if (Boolean.TRUE.equals(canSpeak)) { - requestReading(sms); + if (Boolean.TRUE.equals(canSpeak)) { + requestReading(sms); - } else { - awaitingTexts.add(sms); + } else { + awaitingTexts.add(sms); + } } - } + } } result = START_STICKY; @@ -599,6 +596,7 @@ public class SayMyTextService extends Service implements TextToSpeech.OnInitList String[] readingProfileValues = getResources().getStringArray(R.array.preferences_reading_profile_values); readingProfile = sharedPreferences.getString(key, readingProfileValues[0]); + updateReadingEnabled(); } else if (key.equals(getString(R.string.preference_enable_heisendroid_mode_key))) { heisendroidModeEnabled = sharedPreferences.getBoolean(key, true); @@ -608,6 +606,80 @@ public class SayMyTextService extends Service implements TextToSpeech.OnInitList } } + protected void updateReadingEnabled() { + String[] readingProfileValues = getResources().getStringArray(R.array.preferences_reading_profile_values); + String[] readingProfileEntries = getResources().getStringArray(R.array.preferences_reading_profile_entries); + String desc; + + // always read + alwaysRead = readingProfileValues[0].equals(readingProfile); + if (alwaysRead) { + readingActive = true; + desc = readingProfileEntries[0]; + } + // if a bt device or a headset is connected + else if (readingProfileValues[1].equals(readingProfile)) { + readingActive = headsetPlugged || !bluetoothDevices.isEmpty(); + + if (!bluetoothDevices.isEmpty()) { + desc = getString(R.string.notification_reading_active_bt_device_connected); + + } else if (headsetPlugged) { + desc = getString(R.string.notification_reading_active_headset_connected); + + } else { + desc = getString(R.string.notification_reading_unactive_no_headset_nor_bt_device_connected); + } + } + // if a headset is connected + else if (readingProfileValues[2].equals(readingProfile)) { + readingActive = headsetPlugged; + desc = headsetPlugged ? + getString(R.string.notification_reading_active_headset_connected) : + getString(R.string.notification_reading_unactive_no_headset_connected); + } + // never read + else { + readingActive = false; + desc = readingProfileEntries[3]; + } + + updateNotification(desc); + } + + protected void updateNotification(String content) { + //TODO kmorin 20140821 add a setting to show notifsor not, cancelable or not + NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); + + if (notificationsEnabled) { + BitmapDrawable logo = (BitmapDrawable) getResources().getDrawable(R.drawable.logo_small); + Notification.Builder builder = new Notification.Builder(this) + .setLargeIcon(logo.getBitmap()) + .setContentText(content); + + //TODO kmorin 20140821 find other small icons + if (readingActive) { + builder.setSmallIcon(android.R.drawable.presence_audio_online) + .setContentTitle(getString(R.string.notification_reading_active_title)); + + } else { + builder.setSmallIcon(android.R.drawable.presence_audio_busy) + .setContentTitle(getString(R.string.notification_reading_unactive_title)); + } + + Intent settingsIntent = new Intent(this, SettingsActivity.class); + PendingIntent resultPendingIntent = PendingIntent.getActivity(this, 0, settingsIntent, PendingIntent.FLAG_UPDATE_CURRENT); + builder.setContentIntent(resultPendingIntent); + + Notification notification = builder.build(); + notification.flags = Notification.FLAG_NO_CLEAR; + notificationManager.notify(NOTIFICATION_ID, notification); + + } else { + notificationManager.cancel(NOTIFICATION_ID); + } + } + public interface Function { void apply(); } diff --git a/src/org/chorem/android/saymytexts/SettingsActivity.java b/src/org/chorem/android/saymytexts/SettingsActivity.java index 6e6232b..8b4fc8c 100644 --- a/src/org/chorem/android/saymytexts/SettingsActivity.java +++ b/src/org/chorem/android/saymytexts/SettingsActivity.java @@ -26,6 +26,7 @@ package org.chorem.android.saymytexts; import android.app.Activity; import android.app.AlertDialog; +import android.app.Application; import android.app.PendingIntent; import android.content.ActivityNotFoundException; import android.content.Context; @@ -88,6 +89,9 @@ public class SettingsActivity extends Activity { Intent installIntent = new Intent(TextToSpeech.Engine.ACTION_INSTALL_TTS_DATA); startActivity(installIntent); } + Intent serviceIntent = new Intent(this, SayMyTextService.class); + this.startService(serviceIntent); + } catch(ActivityNotFoundException eee) { Log.e(TAG, "No activity found fo texttospeech", eee); Toast.makeText(this, R.string.texttospeech_not_installed, Toast.LENGTH_LONG).show(); @@ -99,7 +103,7 @@ public class SettingsActivity extends Activity { } public static class SettingsFragment extends PreferenceFragment - implements SharedPreferences.OnSharedPreferenceChangeListener { + implements SharedPreferences.OnSharedPreferenceChangeListener { @Override public void onCreate(Bundle savedInstanceState) { diff --git a/src/org/chorem/android/saymytexts/broadcastreceiver/BootCompletedBroadcastReceiver.java b/src/org/chorem/android/saymytexts/broadcastreceiver/BootCompletedBroadcastReceiver.java new file mode 100644 index 0000000..3c227e0 --- /dev/null +++ b/src/org/chorem/android/saymytexts/broadcastreceiver/BootCompletedBroadcastReceiver.java @@ -0,0 +1,24 @@ +package org.chorem.android.saymytexts.broadcastreceiver; + +import android.content.BroadcastReceiver; +import android.content.Context; +import android.content.Intent; +import org.chorem.android.saymytexts.SayMyTextService; + +/** + * @author Kevin Morin (Code Lutin) + * @since 2.2 + */ +public class BootCompletedBroadcastReceiver extends BroadcastReceiver { + + @Override + public void onReceive(Context context, Intent intent) { + //we double check here for only boot complete event + if(intent.getAction().equalsIgnoreCase(Intent.ACTION_BOOT_COMPLETED)) { + //here we start the service + Intent serviceIntent = new Intent(context, SayMyTextService.class); + context.startService(serviceIntent); + } + } + +} diff --git a/src/org/chorem/android/saymytexts/broadcastreceiver/DeviceConnectionBroadcastReceiver.java b/src/org/chorem/android/saymytexts/broadcastreceiver/DeviceConnectionBroadcastReceiver.java new file mode 100644 index 0000000..4a1810e --- /dev/null +++ b/src/org/chorem/android/saymytexts/broadcastreceiver/DeviceConnectionBroadcastReceiver.java @@ -0,0 +1,56 @@ +package org.chorem.android.saymytexts.broadcastreceiver; + +import android.bluetooth.BluetoothClass; +import android.bluetooth.BluetoothDevice; +import android.content.BroadcastReceiver; +import android.content.Context; +import android.content.Intent; +import android.util.Log; +import org.chorem.android.saymytexts.SayMyTextService; + +/** + * @author Kevin Morin (Code Lutin) + * @since 2.2 + */ +public class DeviceConnectionBroadcastReceiver extends BroadcastReceiver { + + private static final String TAG = "DeviceConnectionBroadcastReceiver"; + + @Override + public void onReceive(Context context, Intent intent) { + Intent serviceIntent = new Intent(context, SayMyTextService.class); + String action = intent.getAction(); + + Log.d(TAG, "onReceive " + action); + if (Intent.ACTION_HEADSET_PLUG.equals(action)) { + int headSetState = intent.getIntExtra("state", 0); + serviceIntent.setAction(SayMyTextService.ACTION_HEADSET_PLUGGED); + serviceIntent.putExtra(SayMyTextService.INTENT_EXTRA_HEADSET_PLUGGED, headSetState > 0); + context.startService(serviceIntent); + + } else { + BluetoothDevice device = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE); + serviceIntent.setAction(SayMyTextService.ACTION_MANAGE_BT_DEVICE); + + if (BluetoothDevice.ACTION_ACL_CONNECTED.equals(action)) { + BluetoothClass bluetoothClass = device.getBluetoothClass(); + if (bluetoothClass != null) { + int majorDeviceClass = bluetoothClass.getMajorDeviceClass(); + if (majorDeviceClass == BluetoothClass.Device.Major.AUDIO_VIDEO) { + serviceIntent.putExtra(SayMyTextService.INTENT_EXTRA_BT_DEVICE, device); + serviceIntent.putExtra(SayMyTextService.INTENT_EXTRA_ADD_BT_DEVICE, true); + context.startService(serviceIntent); + } + + } else { + //error recognizing the bt class + } + + } else { + serviceIntent.putExtra(SayMyTextService.INTENT_EXTRA_BT_DEVICE, device); + serviceIntent.putExtra(SayMyTextService.INTENT_EXTRA_ADD_BT_DEVICE, false); + context.startService(serviceIntent); + } + } + } +} diff --git a/src/org/chorem/android/saymytexts/DictateSmsBroadcastReceiver.java b/src/org/chorem/android/saymytexts/broadcastreceiver/DictateSmsBroadcastReceiver.java similarity index 96% rename from src/org/chorem/android/saymytexts/DictateSmsBroadcastReceiver.java rename to src/org/chorem/android/saymytexts/broadcastreceiver/DictateSmsBroadcastReceiver.java index ad7e220..0916722 100644 --- a/src/org/chorem/android/saymytexts/DictateSmsBroadcastReceiver.java +++ b/src/org/chorem/android/saymytexts/broadcastreceiver/DictateSmsBroadcastReceiver.java @@ -1,4 +1,4 @@ -package org.chorem.android.saymytexts; +package org.chorem.android.saymytexts.broadcastreceiver; /* * #%L @@ -34,6 +34,8 @@ import android.speech.RecognitionListener; import android.speech.RecognizerIntent; import android.speech.SpeechRecognizer; import android.util.Log; +import org.chorem.android.saymytexts.SMS; +import org.chorem.android.saymytexts.SayMyTextService; import java.util.List; diff --git a/src/org/chorem/android/saymytexts/NewTextBroadcastReceiver.java b/src/org/chorem/android/saymytexts/broadcastreceiver/NewTextBroadcastReceiver.java similarity index 78% rename from src/org/chorem/android/saymytexts/NewTextBroadcastReceiver.java rename to src/org/chorem/android/saymytexts/broadcastreceiver/NewTextBroadcastReceiver.java index 5dd1eb6..f4f3867 100644 --- a/src/org/chorem/android/saymytexts/NewTextBroadcastReceiver.java +++ b/src/org/chorem/android/saymytexts/broadcastreceiver/NewTextBroadcastReceiver.java @@ -1,4 +1,4 @@ -package org.chorem.android.saymytexts; +package org.chorem.android.saymytexts.broadcastreceiver; /* * #%L @@ -24,8 +24,6 @@ package org.chorem.android.saymytexts; * #L% */ -import android.bluetooth.BluetoothClass; -import android.bluetooth.BluetoothDevice; import android.content.BroadcastReceiver; import android.content.ContentResolver; import android.content.Context; @@ -39,6 +37,9 @@ import android.provider.BaseColumns; import android.provider.ContactsContract; import android.telephony.SmsMessage; import android.util.Log; +import org.chorem.android.saymytexts.R; +import org.chorem.android.saymytexts.SMS; +import org.chorem.android.saymytexts.SayMyTextService; /** * Receives the SMSs and if the headset is plugged, start the service to say it out loud. @@ -93,30 +94,6 @@ public class NewTextBroadcastReceiver extends BroadcastReceiver { serviceIntent.setAction(SayMyTextService.ACTION_READ_SMS); context.startService(serviceIntent); } - - } else { - BluetoothDevice device = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE); - serviceIntent.setAction(SayMyTextService.ACTION_MANAGE_BT_DEVICE); - - if (BluetoothDevice.ACTION_ACL_CONNECTED.equals(action)) { - BluetoothClass bluetoothClass = device.getBluetoothClass(); - if (bluetoothClass != null) { - int majorDeviceClass = bluetoothClass.getMajorDeviceClass(); - if (majorDeviceClass == BluetoothClass.Device.Major.AUDIO_VIDEO) { - serviceIntent.putExtra(SayMyTextService.INTENT_EXTRA_BT_DEVICE, device); - serviceIntent.putExtra(SayMyTextService.INTENT_EXTRA_ADD_BT_DEVICE, true); - context.startService(serviceIntent); - } - - } else { - //error recognizing the bt class - } - - } else { - serviceIntent.putExtra(SayMyTextService.INTENT_EXTRA_BT_DEVICE, device); - serviceIntent.putExtra(SayMyTextService.INTENT_EXTRA_ADD_BT_DEVICE, false); - context.startService(serviceIntent); - } } } diff --git a/src/org/chorem/android/saymytexts/SayNextActionBroadcastReceiver.java b/src/org/chorem/android/saymytexts/broadcastreceiver/SayNextActionBroadcastReceiver.java similarity index 97% rename from src/org/chorem/android/saymytexts/SayNextActionBroadcastReceiver.java rename to src/org/chorem/android/saymytexts/broadcastreceiver/SayNextActionBroadcastReceiver.java index 46cc22f..c2d2970 100644 --- a/src/org/chorem/android/saymytexts/SayNextActionBroadcastReceiver.java +++ b/src/org/chorem/android/saymytexts/broadcastreceiver/SayNextActionBroadcastReceiver.java @@ -1,4 +1,4 @@ -package org.chorem.android.saymytexts; +package org.chorem.android.saymytexts.broadcastreceiver; /* * #%L @@ -37,6 +37,9 @@ import android.speech.RecognizerIntent; import android.speech.SpeechRecognizer; import android.telephony.SmsManager; import android.util.Log; +import org.chorem.android.saymytexts.R; +import org.chorem.android.saymytexts.SMS; +import org.chorem.android.saymytexts.SayMyTextService; import java.util.List; -- To stop receiving notification emails like this one, please contact chorem.org SCM administrator <admin+scm@chorem.org>.