some polishing on voice-features. please test with a fresh phone that doesnt have voicesearch and/or text-to-speech installed

pull/14/head
Arne Jans 14 years ago
parent 82dcd57e16
commit e9bcec1444

@ -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

@ -340,6 +340,10 @@
<!-- Preference: Task List Show Notes -->
<string name="EPr_showNotes_title">Show Notes In Task</string>
<!-- Preference: Task List recognition-service is not installed, but available -->
<string name="EPr_voiceInputInstall_dlg">Voice-input is not installed.\nDo you want to go to the market and install it?</string>
<!-- Preference: Task List recognition-service is not available for this system -->
<string name="EPr_voiceInputUnavailable_dlg">Unfortunately voice-input is not available for your system.\nIf possible, please update your system to 2.1 or later.</string>
<!-- Preference: Task List Show Voice-button if recognition-service is available -->
<string name="EPr_voiceInputEnabled_title">Enable voice-input</string>
<!-- Preference: Task List Voice-button directly creates tasks -->

@ -31,7 +31,7 @@
<CheckBoxPreference
android:key="@string/p_voiceInputEnabled"
android:title="@string/EPr_voiceInputEnabled_title"
android:defaultValue="true" />
android:defaultValue="false" />
<CheckBoxPreference
android:key="@string/p_voiceInputCreatesTask"
android:title="@string/EPr_voiceInputCreatesTask_title"
@ -39,6 +39,6 @@
<CheckBoxPreference
android:key="@string/p_voiceRemindersEnabled"
android:title="@string/EPr_voiceRemindersEnabled_title"
android:defaultValue="true" />
android:defaultValue="false" />
</PreferenceCategory>
</PreferenceScreen>

@ -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();

@ -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.

@ -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;
}
}
}

Loading…
Cancel
Save