[say-my-texts] branch develop updated (49f8396 -> f32f18f)
This is an automated email from the git hooks/post-receive script. New change to branch develop in repository say-my-texts. See http://git.chorem.org/say-my-texts.git from 49f8396 add drawables new f32f18f refs #1055 Add a notification when SayMyTexts is active The 1 revisions listed above as "new" are entirely new to this repository and will be described in separate emails. The revisions listed as "adds" were already present in the repository and have only been added to this reference. Detailed log of new commits: commit f32f18f8533fecab960b35bfd2355d63ebf7a01d Author: Kevin Morin <morin@codelutin.com> Date: Thu Aug 28 00:07:33 2014 +0200 refs #1055 Add a notification when SayMyTexts is active Summary of changes: AndroidManifest.xml | 19 +- res/drawable/ic_stat_heisendroid.png | Bin 20910 -> 702 bytes res/values-fr/arrays.xml | 6 + res/values-fr/strings.xml | 8 + res/values/arrays.xml | 12 + res/values/preference_keys.xml | 1 + res/values/strings.xml | 8 + res/xml/preferences.xml | 6 + .../android/saymytexts/SayMyTextService.java | 277 +++++++++++++-------- .../android/saymytexts/SettingsActivity.java | 21 +- .../BootCompletedBroadcastReceiver.java | 24 ++ .../DeviceConnectionBroadcastReceiver.java | 56 +++++ .../DictateSmsBroadcastReceiver.java | 4 +- .../NewTextBroadcastReceiver.java | 31 +-- .../SayNextActionBroadcastReceiver.java | 5 +- 15 files changed, 341 insertions(+), 137 deletions(-) create mode 100644 src/org/chorem/android/saymytexts/broadcastreceiver/BootCompletedBroadcastReceiver.java create mode 100644 src/org/chorem/android/saymytexts/broadcastreceiver/DeviceConnectionBroadcastReceiver.java rename src/org/chorem/android/saymytexts/{ => broadcastreceiver}/DictateSmsBroadcastReceiver.java (96%) rename src/org/chorem/android/saymytexts/{ => broadcastreceiver}/NewTextBroadcastReceiver.java (76%) rename src/org/chorem/android/saymytexts/{ => broadcastreceiver}/SayNextActionBroadcastReceiver.java (97%) -- To stop receiving notification emails like this one, please contact chorem.org SCM administrator <admin+scm@chorem.org>.
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 f32f18f8533fecab960b35bfd2355d63ebf7a01d Author: Kevin Morin <morin@codelutin.com> Date: Thu Aug 28 00:07:33 2014 +0200 refs #1055 Add a notification when SayMyTexts is active --- AndroidManifest.xml | 19 +- res/drawable/ic_stat_heisendroid.png | Bin 20910 -> 702 bytes res/values-fr/arrays.xml | 6 + res/values-fr/strings.xml | 8 + res/values/arrays.xml | 12 + res/values/preference_keys.xml | 1 + res/values/strings.xml | 8 + res/xml/preferences.xml | 6 + .../android/saymytexts/SayMyTextService.java | 277 +++++++++++++-------- .../android/saymytexts/SettingsActivity.java | 21 +- .../BootCompletedBroadcastReceiver.java | 24 ++ .../DeviceConnectionBroadcastReceiver.java | 56 +++++ .../DictateSmsBroadcastReceiver.java | 4 +- .../NewTextBroadcastReceiver.java | 31 +-- .../SayNextActionBroadcastReceiver.java | 5 +- 15 files changed, 341 insertions(+), 137 deletions(-) diff --git a/AndroidManifest.xml b/AndroidManifest.xml index 10ca336..2a5a5bb 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="7" - android:versionName="2.1.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"/> @@ -41,13 +42,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> diff --git a/res/drawable/ic_stat_heisendroid.png b/res/drawable/ic_stat_heisendroid.png index b7da286..980972b 100644 Binary files a/res/drawable/ic_stat_heisendroid.png and b/res/drawable/ic_stat_heisendroid.png differ diff --git a/res/values-fr/arrays.xml b/res/values-fr/arrays.xml index da4a5db..53c1f2f 100644 --- a/res/values-fr/arrays.xml +++ b/res/values-fr/arrays.xml @@ -8,4 +8,10 @@ <item>Jamais</item> </string-array> + <string-array name="preferences_notifications_entries"> + <item>Désactivées</item> + <item>Annulables</item> + <item>Non annulables</item> + </string-array> + </resources> \ No newline at end of file diff --git a/res/values-fr/strings.xml b/res/values-fr/strings.xml index ce8009d..45ff85c 100644 --- a/res/values-fr/strings.xml +++ b/res/values-fr/strings.xml @@ -14,6 +14,7 @@ <string name="preference_enable_interaction_sublabel">appel ou réponse</string> <string name="preference_voice_recognizer_max_attempt_number_label">Nombre maximum d\'essais</string> <string name="preference_enable_heisendroid_mode_label">Mode Heisendroid</string> + <string name="preference_notifications_label">Notifications</string> <string name="preference_test_sms_label">Tester en m\'envoyant un SMS</string> <string name="test_sms_content">Heisendroïd</string> @@ -56,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/arrays.xml b/res/values/arrays.xml index d851bcc..9685a26 100644 --- a/res/values/arrays.xml +++ b/res/values/arrays.xml @@ -15,4 +15,16 @@ <item>Never</item> </string-array> + <string-array name="preferences_notifications_values"> + <item>disabled</item> + <item>cancelable</item> + <item>not_cancelable</item> + </string-array> + + <string-array name="preferences_notifications_entries"> + <item>Disabled</item> + <item>Cancelable</item> + <item>Not cancelable</item> + </string-array> + </resources> \ No newline at end of file diff --git a/res/values/preference_keys.xml b/res/values/preference_keys.xml index 43006d2..2699a03 100644 --- a/res/values/preference_keys.xml +++ b/res/values/preference_keys.xml @@ -4,6 +4,7 @@ <string name="preference_enable_interaction_key">enable_interaction</string> <string name="preference_enable_heisendroid_mode_key">enable_heisendroid_mode</string> <string name="preference_voice_recognizer_max_attempt_number_key">preference_voice_recognizer_max_attempt_number</string> + <string name="preference_notifications_key">preference_notifications_key</string> <string name="preference_test_sms_key">test_sms</string> <string name="preference_version_key">version</string> <string name="preference_documentation_key">documentation</string> diff --git a/res/values/strings.xml b/res/values/strings.xml index 646e2c7..6229f51 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -14,6 +14,7 @@ <string name="preference_enable_interaction_sublabel">call or answer</string> <string name="preference_voice_recognizer_max_attempt_number_label">Maximum attempt number</string> <string name="preference_enable_heisendroid_mode_label">Heisendroid mode</string> + <string name="preference_notifications_label">Notifications</string> <string name="preference_test_sms_label">Test by sending an SMS to myself</string> <string name="test_sms_content">Heisendroïd</string> @@ -56,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/res/xml/preferences.xml b/res/xml/preferences.xml index 742a108..b4077e3 100644 --- a/res/xml/preferences.xml +++ b/res/xml/preferences.xml @@ -24,6 +24,12 @@ android:title="@string/preference_enable_heisendroid_mode_label" android:defaultValue="false"/> + <ListPreference android:key="@string/preference_notifications_key" + android:title="@string/preference_notifications_label" + android:entries="@array/preferences_notifications_entries" + android:entryValues="@array/preferences_notifications_values" + android:defaultValue="cancelable"/> + <Preference android:key="@string/preference_test_sms_key" android:title="@string/preference_test_sms_label" android:persistent="false"/> diff --git a/src/org/chorem/android/saymytexts/SayMyTextService.java b/src/org/chorem/android/saymytexts/SayMyTextService.java index 3f1ed86..b9c2ffa 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,6 +45,9 @@ 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.util.ArrayList; import java.util.HashMap; @@ -64,6 +71,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 +83,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; + + protected boolean notificationsCancelable; + protected AudioManager audioManager; /** null if the texttospeech is not initialized */ @@ -109,6 +130,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 +147,6 @@ public class SayMyTextService extends Service implements TextToSpeech.OnInitList } }; -// BluetoothHeadset mBluetoothHeadset; - @Override public void onCreate() { super.onCreate(); @@ -160,35 +183,20 @@ public class SayMyTextService extends Service implements TextToSpeech.OnInitList String interactionPrefKey = getString(R.string.preference_enable_interaction_key); interactionEnabled = sharedPref.getBoolean(interactionPrefKey, true); - sharedPref.registerOnSharedPreferenceChangeListener(this); + String[] notificationsValues = + getResources().getStringArray(R.array.preferences_notifications_values); + String notificationMode = sharedPref.getString(key, notificationsValues[1]); + notificationsEnabled = !notificationMode.equals(notificationsValues[0]); + notificationsCancelable = !notificationMode.equals(notificationsValues[2]); + + updateReadingEnabled(); -//// 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); + sharedPref.registerOnSharedPreferenceChangeListener(this); + deviceConnectionBroadcastReceiver = new DeviceConnectionBroadcastReceiver(); + IntentFilter filter = new IntentFilter(); + filter.addAction(Intent.ACTION_HEADSET_PLUG); + registerReceiver(deviceConnectionBroadcastReceiver, filter); } @Override @@ -200,6 +208,8 @@ public class SayMyTextService extends Service implements TextToSpeech.OnInitList SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(this); sharedPref.unregisterOnSharedPreferenceChangeListener(this); + + unregisterReceiver(deviceConnectionBroadcastReceiver); } @Override @@ -220,81 +230,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,12 +602,86 @@ 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); } else if (key.equals(getString(R.string.preference_enable_interaction_key))) { interactionEnabled = sharedPreferences.getBoolean(key, true); + + } else if (key.equals(getString(R.string.preference_notifications_key))) { + String[] notificationsValues = + getResources().getStringArray(R.array.preferences_notifications_values); + String notificationMode = sharedPreferences.getString(key, notificationsValues[1]); + notificationsEnabled = !notificationMode.equals(notificationsValues[0]); + notificationsCancelable = !notificationMode.equals(notificationsValues[2]); + updateReadingEnabled(); + } + } + + 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 = null; + + // 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); + } + } + // if a headset is connected + else if (readingProfileValues[2].equals(readingProfile)) { + readingActive = headsetPlugged; + if (headsetPlugged) { + desc = getString(R.string.notification_reading_active_headset_connected); + } + } + // never read + else { + readingActive = false; + desc = readingProfileEntries[3]; + } + + updateNotification(desc); + } + + protected void updateNotification(String content) { + NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); + + if (notificationsEnabled && readingActive) { + BitmapDrawable logo = (BitmapDrawable) getResources().getDrawable(R.drawable.ic_launcher_heisendroid); + Notification.Builder builder = new Notification.Builder(this) + .setLargeIcon(logo.getBitmap()) + .setContentText(content); + builder.setSmallIcon(R.drawable.ic_stat_heisendroid) + .setContentTitle(getString(R.string.notification_reading_active_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(); + if (!notificationsCancelable) { + notification.flags = Notification.FLAG_NO_CLEAR; + } + + notificationManager.notify(NOTIFICATION_ID, notification); + + } else { + notificationManager.cancel(NOTIFICATION_ID); } } diff --git a/src/org/chorem/android/saymytexts/SettingsActivity.java b/src/org/chorem/android/saymytexts/SettingsActivity.java index 519bc75..339eb6a 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) { @@ -156,6 +160,16 @@ public class SettingsActivity extends Activity { preference.setSummary(String.valueOf(maxAttemptNumber)); preference.setEnabled(interactionEnabled); + key = getString(R.string.preference_enable_heisendroid_mode_key); + switchPreference = (SwitchPreference) findPreference(key); + enabled = sharedPref.getBoolean(key, switchPreference.isChecked()); + switchPreference.setChecked(enabled); + + key = getString(R.string.preference_notifications_key); + listPreference = (ListPreference) findPreference(key); + summary = listPreference.getEntry(); + listPreference.setSummary(summary); + sharedPref.registerOnSharedPreferenceChangeListener(this); } @@ -194,6 +208,11 @@ public class SettingsActivity extends Activity { SwitchPreference switchPreference = (SwitchPreference) findPreference(key); boolean enabled = sharedPreferences.getBoolean(key, switchPreference.isChecked()); switchPreference.setChecked(enabled); + + } else if (getString(R.string.preference_notifications_key).equals(key)) { + ListPreference preference = (ListPreference) findPreference(key); + CharSequence summary = preference.getEntry(); + preference.setSummary(summary); } } 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 76% rename from src/org/chorem/android/saymytexts/NewTextBroadcastReceiver.java rename to src/org/chorem/android/saymytexts/broadcastreceiver/NewTextBroadcastReceiver.java index 6260f34..2c47478 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. @@ -81,30 +82,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>.
participants (1)
-
chorem.org scm