Polish issues for voice, set up preferences listeners

pull/14/head
Tim Su 14 years ago
parent bbd997d917
commit 19ee36f9f1

Binary file not shown.

Binary file not shown.

Before

Width:  |  Height:  |  Size: 954 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1013 B

@ -97,7 +97,7 @@
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_weight="1" android:layout_weight="1"
android:src="@drawable/ic_btn_speak_now" android:src="@drawable/tango_microphone"
android:scaleType="fitCenter" android:scaleType="fitCenter"
android:visibility="gone"/> android:visibility="gone"/>
<EditText <EditText

@ -54,7 +54,7 @@
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_weight="1" android:layout_weight="1"
android:visibility="gone" android:visibility="gone"
android:src="@drawable/ic_btn_speak_now" android:src="@drawable/tango_microphone"
android:scaleType="fitCenter"/> android:scaleType="fitCenter"/>
<!-- Quick Add Button --> <!-- Quick Add Button -->

@ -3,8 +3,8 @@
<resources xmlns:android="http://schemas.android.com/apk/res/android"> <resources xmlns:android="http://schemas.android.com/apk/res/android">
<!-- Voice Add Prompt Text --> <!-- Voice Add Prompt Text -->
<string name="voice_add_prompt">Speak to add a task</string> <string name="voice_add_prompt">Speak to create a task</string>
<string name="voice_edit_prompt">Speak to edit this task</string> <string name="voice_edit_prompt">Speak to set task title</string>
<!-- Preference: Task List recognition-service is not installed, but available --> <!-- 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> <string name="EPr_voiceInputInstall_dlg">Voice-input is not installed.\nDo you want to go to the market and install it?</string>
@ -17,9 +17,9 @@
<!-- Preference: voice button description (true) --> <!-- Preference: voice button description (true) -->
<string name="EPr_voiceInputEnabled_desc_enabled">Voice input button will be displayed in task list page</string> <string name="EPr_voiceInputEnabled_desc_enabled">Voice input button will be displayed in task list page</string>
<!-- Preference: voice button description (false) --> <!-- Preference: voice button description (false) -->
<string name="EPr_voiceInputEnabled_desc_enabled">Voice input button will be hidden on task list page</string> <string name="EPr_voiceInputEnabled_desc_disabled">Voice input button will be hidden on task list page</string>
<!-- Preference: Task List Voice-button directly creates tasks --> <!-- Preference: Task List Voice-button directly creates tasks -->
<string name="EPr_voiceInputCreatesTask_title">Voice Input Creates Tasks</string> <string name="EPr_voiceInputCreatesTask_title">Directly Create Tasks</string>
<!-- Preference: Task List Voice-creation description (true) --> <!-- Preference: Task List Voice-creation description (true) -->
<string name="EPr_voiceInputCreatesTask_desc_enabled">Tasks will automatically be created from voice input</string> <string name="EPr_voiceInputCreatesTask_desc_enabled">Tasks will automatically be created from voice input</string>
<!-- Preference: Task List Voice-creation description (false) --> <!-- Preference: Task List Voice-creation description (false) -->
@ -32,10 +32,6 @@
<string name="EPr_voiceRemindersEnabled_desc_disabled">Astrid will sound a ringtone during task reminders</string> <string name="EPr_voiceRemindersEnabled_desc_disabled">Astrid will sound a ringtone during task reminders</string>
<!-- Preference Category: Voice Title --> <!-- Preference Category: Voice Title -->
<string name="EPr_voice_header">Voice</string> <string name="EPr_voice_header">Voice Input Settings</string>
<!-- Preference: Task List Voice Input Description (disabled) -->
<string name="EPr_voiceInput_desc_disabled">Voice-Button will be hidden</string>
<!-- Preference: Task List Voice Input Description (enabled) -->
<string name="EPr_voiceInput_desc_enabled">Voice-Button will be shown</string>
</resources> </resources>

@ -24,21 +24,23 @@
android:key="@string/p_statistics" android:key="@string/p_statistics"
android:title="@string/EPr_statistics_title" android:title="@string/EPr_statistics_title"
android:defaultValue="true" /> android:defaultValue="true" />
<PreferenceScreen
android:title="@string/EPr_voice_header">
<CheckBoxPreference
android:key="@string/p_voiceInputEnabled"
android:title="@string/EPr_voiceInputEnabled_title"
android:defaultValue="true" />
<CheckBoxPreference
android:key="@string/p_voiceInputCreatesTask"
android:title="@string/EPr_voiceInputCreatesTask_title"
android:defaultValue="false" />
<CheckBoxPreference
android:key="@string/p_voiceRemindersEnabled"
android:title="@string/EPr_voiceRemindersEnabled_title"
android:defaultValue="false" />
</PreferenceScreen>
</PreferenceCategory> </PreferenceCategory>
<PreferenceCategory
android:title="@string/EPr_voice_header">
<CheckBoxPreference
android:key="@string/p_voiceInputEnabled"
android:title="@string/EPr_voiceInputEnabled_title"
android:defaultValue="false" />
<CheckBoxPreference
android:key="@string/p_voiceInputCreatesTask"
android:title="@string/EPr_voiceInputCreatesTask_title"
android:defaultValue="false" />
<CheckBoxPreference
android:key="@string/p_voiceRemindersEnabled"
android:title="@string/EPr_voiceRemindersEnabled_title"
android:defaultValue="false" />
</PreferenceCategory>
</PreferenceScreen> </PreferenceScreen>

@ -22,6 +22,7 @@ import android.net.Uri;
import android.os.Bundle; import android.os.Bundle;
import android.preference.CheckBoxPreference; import android.preference.CheckBoxPreference;
import android.preference.Preference; import android.preference.Preference;
import android.preference.Preference.OnPreferenceChangeListener;
import android.preference.Preference.OnPreferenceClickListener; import android.preference.Preference.OnPreferenceClickListener;
import android.preference.PreferenceCategory; import android.preference.PreferenceCategory;
import android.preference.PreferenceScreen; import android.preference.PreferenceScreen;
@ -55,6 +56,8 @@ import com.todoroo.astrid.voice.VoiceOutputAssistant;
*/ */
public class EditPreferences extends TodorooPreferences { public class EditPreferences extends TodorooPreferences {
private static final int POWER_PACK_PREFERENCE = 1;
private static final String METADATA_CATEGORY = "category";//$NON-NLS-1$ private static final String METADATA_CATEGORY = "category";//$NON-NLS-1$
// --- instance variables // --- instance variables
@ -85,7 +88,16 @@ public class EditPreferences extends TodorooPreferences {
PreferenceScreen screen = getPreferenceScreen(); PreferenceScreen screen = getPreferenceScreen();
voiceInputAssistant = new VoiceInputAssistant(this); voiceInputAssistant = new VoiceInputAssistant(this);
// load plug-ins addPluginPreferences(screen);
screen.getPreference(POWER_PACK_PREFERENCE).setEnabled(addOnService.hasPowerPack());
addDebugPreferences();
addPreferenceListeners();
}
private void addPluginPreferences(PreferenceScreen screen) {
Intent queryIntent = new Intent(AstridApiConstants.ACTION_SETTINGS); Intent queryIntent = new Intent(AstridApiConstants.ACTION_SETTINGS);
PackageManager pm = getPackageManager(); PackageManager pm = getPackageManager();
List<ResolveInfo> resolveInfoList = pm.queryIntentActivities(queryIntent, List<ResolveInfo> resolveInfoList = pm.queryIntentActivities(queryIntent,
@ -140,12 +152,6 @@ public class EditPreferences extends TodorooPreferences {
for(Preference preference : entry.getValue()) for(Preference preference : entry.getValue())
screen.addPreference(preference); screen.addPreference(preference);
} }
// power pack
screen.getPreference(1).setEnabled(addOnService.hasPowerPack());
// debugging preferences
addDebugPreferences();
} }
@SuppressWarnings("nls") @SuppressWarnings("nls")
@ -211,65 +217,27 @@ public class EditPreferences extends TodorooPreferences {
taskService.clearDetails(Criterion.all); taskService.clearDetails(Criterion.all);
Flags.set(Flags.REFRESH); 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) {
dialog.dismiss();
// 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"));
try {
startActivity(marketIntent);
} catch (ActivityNotFoundException ane) {
DialogUtilities.okDialog(EditPreferences.this,
r.getString(R.string.EPr_marketUnavailable_dlg),
new OnClickListener() {
@Override
public void onClick(DialogInterface dialog,
int which) {
((CheckBoxPreference)preference).setChecked(false);
dialog.dismiss();
}
});
}
}
},
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();
// voice input and output
else if (r.getString(R.string.p_voiceInputEnabled).equals(preference.getKey())) {
if (value != null && !(Boolean)value)
preference.setSummary(R.string.EPr_voiceInputEnabled_desc_disabled);
else
preference.setSummary(R.string.EPr_voiceInputEnabled_desc_enabled);
} else if (r.getString(R.string.p_voiceRemindersEnabled).equals(preference.getKey())) {
if (value != null && !(Boolean)value)
preference.setSummary(R.string.EPr_voiceRemindersEnabled_desc_disabled);
else
preference.setSummary(R.string.EPr_voiceRemindersEnabled_desc_enabled);
} else if (r.getString(R.string.p_voiceInputCreatesTask).equals(preference.getKey())) {
if (value != null && !(Boolean)value)
preference.setSummary(R.string.EPr_voiceInputCreatesTask_desc_disabled);
else
preference.setSummary(R.string.EPr_voiceInputCreatesTask_desc_enabled);
} }
// statistics service
else if (r.getString(R.string.p_statistics).equals(preference.getKey())) { else if (r.getString(R.string.p_statistics).equals(preference.getKey())) {
if (value != null && !(Boolean)value) if (value != null && !(Boolean)value)
preference.setSummary(R.string.EPr_statistics_desc_disabled); preference.setSummary(R.string.EPr_statistics_desc_disabled);
@ -284,5 +252,87 @@ public class EditPreferences extends TodorooPreferences {
super.onActivityResult(requestCode, resultCode, data); super.onActivityResult(requestCode, resultCode, data);
} }
public void addPreferenceListeners() {
Resources r = getResources();
findPreference(r.getString(R.string.p_voiceInputEnabled)).setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
@Override
public boolean onPreferenceChange(Preference pref, Object newValue) {
onVoiceInputStatusChanged(pref, (Boolean)newValue);
return true;
}
});
findPreference(r.getString(R.string.p_voiceRemindersEnabled)).setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
@Override
public boolean onPreferenceChange(Preference pref, Object newValue) {
onVoiceReminderStatusChanged((Boolean)newValue);
return true;
}
});
}
private void onVoiceReminderStatusChanged(boolean newValue) {
if(!newValue)
return;
VoiceOutputAssistant.getInstance().checkIsTTSInstalled();
}
private void onVoiceInputStatusChanged(final Preference preference, boolean newValue) {
if(!newValue)
return;
final Resources r = getResources();
if (!voiceInputAssistant.isVoiceInputAvailable()) {
if (AndroidUtilities.getSdkVersion() > 6) {
DialogUtilities.okCancelDialog(this,
r.getString(R.string.EPr_voiceInputInstall_dlg),
new OnClickListener() {
@Override
public void onClick(DialogInterface dialog,
int which) {
dialog.dismiss();
// User wants to install voice search, 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")); //$NON-NLS-1$
try {
startActivity(marketIntent);
} catch (ActivityNotFoundException ane) {
DialogUtilities.okDialog(EditPreferences.this,
r.getString(R.string.EPr_marketUnavailable_dlg),
new OnClickListener() {
@Override
public void onClick(DialogInterface dialog1,
int which1) {
((CheckBoxPreference)preference).setChecked(false);
dialog1.dismiss();
}
});
}
}
},
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();
}
});
}
}
}
} }

@ -246,13 +246,16 @@ public final class TaskEditActivity extends TabActivity {
controls.add(new UrgencyControlSet(R.id.urgency)); controls.add(new UrgencyControlSet(R.id.urgency));
// prepare and set listener for voice-button // prepare and set listener for voice-button
voiceAddNoteButton = (ImageButton) findViewById(R.id.voiceAddNoteButton); if(addOnService.hasPowerPack()) {
notesEditText = (EditText) findViewById(R.id.notes); voiceAddNoteButton = (ImageButton) findViewById(R.id.voiceAddNoteButton);
int prompt = R.string.TEA_voice_edit_note_prompt; voiceAddNoteButton.setVisibility(View.VISIBLE);
voiceNoteAssistant = new VoiceInputAssistant(this, voiceAddNoteButton, notesEditText = (EditText) findViewById(R.id.notes);
notesEditText); int prompt = R.string.TEA_voice_edit_note_prompt;
voiceNoteAssistant.setLanguageModel(RecognizerIntent.LANGUAGE_MODEL_FREE_FORM); voiceNoteAssistant = new VoiceInputAssistant(this, voiceAddNoteButton,
voiceNoteAssistant.configureMicrophoneButton(prompt); notesEditText);
voiceNoteAssistant.setLanguageModel(RecognizerIntent.LANGUAGE_MODEL_FREE_FORM);
voiceNoteAssistant.configureMicrophoneButton(prompt);
}
new Thread() { new Thread() {
@Override @Override

@ -60,6 +60,7 @@ import com.todoroo.andlib.service.ContextManager;
import com.todoroo.andlib.service.DependencyInjectionService; import com.todoroo.andlib.service.DependencyInjectionService;
import com.todoroo.andlib.service.ExceptionService; import com.todoroo.andlib.service.ExceptionService;
import com.todoroo.andlib.utility.AndroidUtilities; import com.todoroo.andlib.utility.AndroidUtilities;
import com.todoroo.andlib.utility.Preferences;
import com.todoroo.andlib.widget.GestureService; import com.todoroo.andlib.widget.GestureService;
import com.todoroo.andlib.widget.GestureService.GestureInterface; import com.todoroo.andlib.widget.GestureService.GestureInterface;
import com.todoroo.astrid.activity.SortSelectionActivity.OnSortSelectedListener; import com.todoroo.astrid.activity.SortSelectionActivity.OnSortSelectedListener;
@ -149,6 +150,9 @@ public class TaskListActivity extends ListActivity implements OnScrollListener,
@Autowired @Autowired
protected Database database; protected Database database;
@Autowired
protected AddOnService addOnService;
protected TaskAdapter taskAdapter = null; protected TaskAdapter taskAdapter = null;
protected DetailReceiver detailReceiver = new DetailReceiver(); protected DetailReceiver detailReceiver = new DetailReceiver();
protected RefreshReceiver refreshReceiver = new RefreshReceiver(); protected RefreshReceiver refreshReceiver = new RefreshReceiver();
@ -449,7 +453,9 @@ public class TaskListActivity extends ListActivity implements OnScrollListener,
@Override @Override
protected void onResume() { protected void onResume() {
super.onResume(); super.onResume();
if (Preferences.getBoolean(R.string.p_voiceInputEnabled, true) && voiceInputAssistant.isVoiceInputAvailable()) { if (addOnService.hasPowerPack() &&
Preferences.getBoolean(R.string.p_voiceInputEnabled, true) &&
voiceInputAssistant.isVoiceInputAvailable()) {
voiceAddButton.setVisibility(View.VISIBLE); voiceAddButton.setVisibility(View.VISIBLE);
} else { } else {
voiceAddButton.setVisibility(View.GONE); voiceAddButton.setVisibility(View.GONE);

Loading…
Cancel
Save