diff --git a/astrid/plugin-src/com/todoroo/astrid/reminders/Notifications.java b/astrid/plugin-src/com/todoroo/astrid/reminders/Notifications.java index d781d104c..fe1df45e5 100644 --- a/astrid/plugin-src/com/todoroo/astrid/reminders/Notifications.java +++ b/astrid/plugin-src/com/todoroo/astrid/reminders/Notifications.java @@ -95,6 +95,8 @@ public class Notifications extends BroadcastReceiver { if(!showTaskNotification(id, type, reminder)) { notificationManager.cancel((int)id); } + // shutdown the VoiceOutputAssistant for now + VoiceOutputAssistant.getInstance().onDestroy(); } // --- notification creation diff --git a/astrid/res/values/strings-core.xml b/astrid/res/values/strings-core.xml index 2927ad48d..956e13c1b 100644 --- a/astrid/res/values/strings-core.xml +++ b/astrid/res/values/strings-core.xml @@ -340,6 +340,10 @@ Show Notes In Task + + Voice-input is not installed.\nDo you want to go to the market and install it? + + Unfortunately voice-input is not available for your system.\nIf possible, please update your system to 2.1 or later. Enable voice-input diff --git a/astrid/res/xml/preferences.xml b/astrid/res/xml/preferences.xml index ac859cf47..dbdc45d0d 100644 --- a/astrid/res/xml/preferences.xml +++ b/astrid/res/xml/preferences.xml @@ -31,7 +31,7 @@ + android:defaultValue="false" /> + android:defaultValue="false" /> diff --git a/astrid/src/com/todoroo/astrid/activity/EditPreferences.java b/astrid/src/com/todoroo/astrid/activity/EditPreferences.java index 0e455a2f4..8998a0e8e 100644 --- a/astrid/src/com/todoroo/astrid/activity/EditPreferences.java +++ b/astrid/src/com/todoroo/astrid/activity/EditPreferences.java @@ -11,11 +11,15 @@ import java.util.Map.Entry; import org.weloveastrid.rmilk.MilkPreferences; import org.weloveastrid.rmilk.MilkUtilities; +import android.content.DialogInterface; +import android.content.DialogInterface.OnClickListener; import android.content.Intent; import android.content.pm.PackageManager; import android.content.pm.ResolveInfo; import android.content.res.Resources; +import android.net.Uri; import android.os.Bundle; +import android.preference.CheckBoxPreference; import android.preference.Preference; import android.preference.Preference.OnPreferenceClickListener; import android.preference.PreferenceCategory; @@ -27,6 +31,7 @@ import com.todoroo.andlib.service.Autowired; import com.todoroo.andlib.service.ContextManager; import com.todoroo.andlib.service.DependencyInjectionService; import com.todoroo.andlib.sql.Criterion; +import com.todoroo.andlib.utility.AndroidUtilities; import com.todoroo.andlib.utility.DialogUtilities; import com.todoroo.andlib.utility.Preferences; import com.todoroo.andlib.widget.TodorooPreferences; @@ -38,6 +43,7 @@ import com.todoroo.astrid.service.StartupService; import com.todoroo.astrid.service.TaskService; import com.todoroo.astrid.utility.Constants; import com.todoroo.astrid.utility.Flags; +import com.todoroo.astrid.voice.VoiceInputAssistant; import com.todoroo.astrid.voice.VoiceOutputAssistant; /** @@ -58,6 +64,8 @@ public class EditPreferences extends TodorooPreferences { @Autowired private Database database; + private VoiceInputAssistant voiceInputAssistant; + public EditPreferences() { DependencyInjectionService.getInstance().inject(this); } @@ -74,6 +82,7 @@ public class EditPreferences extends TodorooPreferences { ContextManager.setContext(this); PreferenceScreen screen = getPreferenceScreen(); + voiceInputAssistant = new VoiceInputAssistant(this); // load plug-ins Intent queryIntent = new Intent(AstridApiConstants.ACTION_SETTINGS); @@ -190,7 +199,7 @@ public class EditPreferences extends TodorooPreferences { } @Override - public void updatePreferences(Preference preference, Object value) { + public void updatePreferences(final Preference preference, Object value) { Resources r = getResources(); if (r.getString(R.string.p_showNotes).equals(preference.getKey())) { if (value != null && !(Boolean)value) @@ -201,6 +210,47 @@ public class EditPreferences extends TodorooPreferences { taskService.clearDetails(Criterion.all); Flags.set(Flags.REFRESH); } + } else if (r.getString(R.string.p_voiceInputEnabled).equals(preference.getKey())) { + if (value != null && (Boolean)value) + if (!voiceInputAssistant.isVoiceInputAvailable()) { + // voicesearch available since 2.1 + if (AndroidUtilities.getSdkVersion() > 6) { + + DialogUtilities.okCancelDialog(this, + r.getString(R.string.EPr_voiceInputInstall_dlg), + new OnClickListener() { + @Override + public void onClick(DialogInterface dialog, + int which) { + // User wants to install voicesearch, take him to the market + Intent marketIntent = new Intent(Intent.ACTION_VIEW, + Uri.parse("market://search?q=pname:" + //$NON-NLS-1$ + "com.google.android.voicesearch.x")); + startActivity(marketIntent); + } + }, + new OnClickListener() { + @Override + public void onClick(DialogInterface dialog, + int which) { + ((CheckBoxPreference)preference).setChecked(false); + dialog.dismiss(); + } + }); + } else { + DialogUtilities.okDialog(this, + r.getString(R.string.EPr_voiceInputUnavailable_dlg), + new OnClickListener() { + @Override + public void onClick(DialogInterface dialog, + int which) { + ((CheckBoxPreference)preference).setChecked(false); + dialog.dismiss(); + } + }); + + } + } } else if (r.getString(R.string.p_voiceRemindersEnabled).equals(preference.getKey())) { if (value != null && (Boolean)value) VoiceOutputAssistant.getInstance().checkIsTTSInstalled(); diff --git a/astrid/src/com/todoroo/astrid/voice/VoiceInputAssistant.java b/astrid/src/com/todoroo/astrid/voice/VoiceInputAssistant.java index d02abc028..53524a03e 100644 --- a/astrid/src/com/todoroo/astrid/voice/VoiceInputAssistant.java +++ b/astrid/src/com/todoroo/astrid/voice/VoiceInputAssistant.java @@ -63,6 +63,18 @@ public class VoiceInputAssistant { return languageModel; } + /** + * Creates a new VoiceInputAssistant-instance simply for checking the availability of the + * RecognizerService. This is used for Preferences-Screens that dont want to provide + * a microphone-button themselves. + */ + public VoiceInputAssistant(Activity activity) { + Assert.assertNotNull("Each VoiceInputAssistant must be bound to an activity!", activity); + this.activity = activity; + this.voiceButton = null; + this.textField = null; + } + /** * Creates a new VoiceInputAssistance-instance for use with a specified button and textfield. * If you need more than one microphone-button on a given Activity, use the other constructor. diff --git a/astrid/src/com/todoroo/astrid/voice/VoiceOutputAssistant.java b/astrid/src/com/todoroo/astrid/voice/VoiceOutputAssistant.java index a905e3033..476a45728 100644 --- a/astrid/src/com/todoroo/astrid/voice/VoiceOutputAssistant.java +++ b/astrid/src/com/todoroo/astrid/voice/VoiceOutputAssistant.java @@ -132,4 +132,15 @@ public class VoiceOutputAssistant implements OnInitListener { } } + /** + * Has to be called in onDestroy of the activity that uses this instance of VoiceOutputAssistant. + */ + public void onDestroy() { + if (mTts != null && isTTSInitialized) { + mTts.shutdown(); + mTts = null; + isTTSInitialized = false; + } + } + }