Move voice add button to action bar

pull/253/head
Alex Baker 10 years ago
parent 1e708455e6
commit b9920fd85d

@ -58,6 +58,7 @@ import org.tasks.ui.NavigationDrawerFragment;
import javax.inject.Inject;
import static com.todoroo.astrid.voice.RecognizerApi.RecognizerApiListener;
import static com.todoroo.astrid.voice.VoiceRecognizer.voiceInputAvailable;
import static org.tasks.ui.NavigationDrawerFragment.OnFilterItemClickedListener;
public class TaskListActivity extends AstridActivity implements OnPageChangeListener, OnFilterItemClickedListener, RecognizerApiListener {
@ -158,6 +159,7 @@ public class TaskListActivity extends AstridActivity implements OnPageChangeList
menu.findItem(R.id.menu_clear_completed).setVisible(true);
menu.findItem(R.id.menu_sort).setVisible(false);
}
menu.findItem(R.id.menu_voice_add).setVisible(voiceInputAvailable(this));
final MenuItem item = menu.findItem(R.id.menu_search);
final SearchView actionView = (SearchView) MenuItemCompat.getActionView(item);
actionView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
@ -471,6 +473,9 @@ public class TaskListActivity extends AstridActivity implements OnPageChangeList
case R.id.menu_settings:
tlf.showSettings();
return true;
case R.id.menu_voice_add:
getTaskListFragment().startVoiceRecognition();
return true;
case R.id.menu_sort:
AlertDialog dialog = SortSelectionActivity.createDialog(
this, tlf.hasDraggableOption(), tlf, tlf.getSortFlags(), tlf.getSort());
@ -550,7 +555,7 @@ public class TaskListActivity extends AstridActivity implements OnPageChangeList
if (tlf != null) {
QuickAddBar quickAdd = tlf.quickAddBar;
if (quickAdd != null) {
VoiceRecognizer vr = quickAdd.getVoiceRecognizer();
VoiceRecognizer vr = getTaskListFragment().getVoiceRecognizer();
if (vr != null) {
vr.cancel();
}

@ -73,6 +73,7 @@ import com.todoroo.astrid.tags.TaskToTagMetadata;
import com.todoroo.astrid.timers.TimerPlugin;
import com.todoroo.astrid.ui.QuickAddBar;
import com.todoroo.astrid.utility.Flags;
import com.todoroo.astrid.voice.VoiceRecognizer;
import com.todoroo.astrid.widget.TasksWidget;
import org.slf4j.Logger;
@ -223,6 +224,10 @@ public class TaskListFragment extends InjectingListFragment implements OnSortSel
emptyView.setRefreshing(ongoing);
}
public VoiceRecognizer getVoiceRecognizer() {
return voiceRecognizer;
}
/**
* Container Activity must implement this interface and we ensure that it
* does during the onAttach() callback
@ -507,15 +512,28 @@ public class TaskListFragment extends InjectingListFragment implements OnSortSel
@Override
public void onStart() {
super.onStart();
quickAddBar.setupRecognizerApi();
setupRecognizerApi();
}
@Override
public void onStop() {
super.onStop();
quickAddBar.destroyRecognizerApi();
destroyRecognizerApi();
}
private VoiceRecognizer voiceRecognizer;
public void setupRecognizerApi() {
voiceRecognizer = VoiceRecognizer.instantiateVoiceRecognizer(getActivity(), (TaskListActivity) getActivity());
}
public void destroyRecognizerApi() {
voiceRecognizer.destroyRecognizerApi();
}
public void startVoiceRecognition() {
voiceRecognizer.startVoiceRecognition(getActivity(), this);
}
@Override
public void onResume() {
super.onResume();

@ -36,8 +36,6 @@ import com.todoroo.astrid.gcal.GCalHelper;
import com.todoroo.astrid.repeats.RepeatControlSet;
import com.todoroo.astrid.service.TaskCreator;
import com.todoroo.astrid.service.TaskService;
import com.todoroo.astrid.utility.Flags;
import com.todoroo.astrid.voice.VoiceRecognizer;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -59,7 +57,6 @@ public class QuickAddBar extends LinearLayout {
private static final Logger log = LoggerFactory.getLogger(QuickAddBar.class);
private ImageButton voiceAddButton;
private ImageButton quickAddButton;
private EditText quickAddBox;
private LinearLayout quickAddControls;
@ -75,8 +72,6 @@ public class QuickAddBar extends LinearLayout {
@Inject ActivityPreferences preferences;
@Inject DateChangedAlerts dateChangedAlerts;
private VoiceRecognizer voiceRecognizer;
private TaskListActivity activity;
private TaskListFragment fragment;
@ -165,17 +160,6 @@ public class QuickAddBar extends LinearLayout {
}
});
// prepare and set listener for voice add button
voiceAddButton = (ImageButton) findViewById(
R.id.voiceAddButton);
voiceAddButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
startVoiceRecognition();
}
});
// set listener for extended addbutton
quickAddButton.setOnLongClickListener(new OnLongClickListener() {
@Override
@ -191,12 +175,6 @@ public class QuickAddBar extends LinearLayout {
}
});
if (VoiceRecognizer.voiceInputAvailable(activity)) {
voiceAddButton.setVisibility(View.VISIBLE);
} else {
voiceAddButton.setVisibility(View.GONE);
}
setUpQuickAddControlSets();
}
@ -321,34 +299,10 @@ public class QuickAddBar extends LinearLayout {
}
public boolean onActivityResult(int requestCode, int resultCode, Intent data) {
// handle the result of voice recognition, put it into the textfield
if (voiceRecognizer.handleActivityResult(requestCode, resultCode, data, quickAddBox)) {
// if user wants, create the task directly (with defaultvalues)
// after saying it
quickAddTask(quickAddBox.getText().toString(), true);
// the rest of onActivityResult is totally unrelated to
// voicerecognition, so bail out
return true;
} else if (requestCode == TaskEditFragment.REQUEST_CODE_CONTACT) {
if (requestCode == TaskEditFragment.REQUEST_CODE_CONTACT) {
return true;
}
return false;
}
public VoiceRecognizer getVoiceRecognizer() {
return voiceRecognizer;
}
public void startVoiceRecognition() {
voiceRecognizer.startVoiceRecognition(activity, fragment);
}
public void setupRecognizerApi() {
voiceRecognizer = VoiceRecognizer.instantiateVoiceRecognizer(activity, activity, voiceAddButton);
}
public void destroyRecognizerApi() {
voiceRecognizer.destroyRecognizerApi();
}
}

@ -6,6 +6,7 @@
package com.todoroo.astrid.voice;
import android.annotation.TargetApi;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
@ -56,22 +57,22 @@ public class VoiceRecognizer {
private static VoiceRecognizer instance = null;
public static VoiceRecognizer instantiateVoiceRecognizer(Context context, RecognizerApiListener listener, ImageButton voiceAddButton) {
public static VoiceRecognizer instantiateVoiceRecognizer(Activity activity, RecognizerApiListener listener) {
synchronized(VoiceRecognizer.class) {
if (instance == null) {
instance = new VoiceRecognizer();
}
}
if (speechRecordingAvailable(context)) {
if (speechRecordingAvailable(activity)) {
if (instance.recognizerApi != null) {
instance.recognizerApi.destroy();
}
instance.recognizerApi = new RecognizerApi(context);
instance.recognizerApi = new RecognizerApi(activity);
instance.recognizerApi.setListener(listener);
} else {
instance.voiceInputAssistant = new VoiceInputAssistant(voiceAddButton);
instance.voiceInputAssistant = new VoiceInputAssistant(activity);
}
return instance;
}

@ -23,21 +23,6 @@
android:gravity="center_vertical"
android:orientation="horizontal">
<!-- Voice Add Button -->
<ImageButton android:id="@+id/voiceAddButton"
android:layout_width="39dip"
android:layout_height="39dip"
android:layout_gravity="center_vertical"
android:layout_marginLeft="4dip"
android:layout_marginRight="2dip"
android:paddingLeft="10dip"
android:paddingRight="10dip"
android:layout_weight="1"
android:visibility="gone"
android:background="@android:color/transparent"
android:src="?attr/ic_action_mic"
android:scaleType="center"/>
<!-- Quick Add Task -->
<EditText android:id="@+id/quickAddText"
android:layout_width="wrap_content"

@ -3,6 +3,11 @@
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tasks="http://schemas.android.com/apk/res-auto">
<item
android:id="@+id/menu_voice_add"
android:title="@string/EPr_voiceInputEnabled_title"
android:icon="?attr/ic_action_mic"
tasks:showAsAction="ifRoom"/>
<item
android:id="@+id/menu_search"
android:title="@string/TLA_menu_search"

Loading…
Cancel
Save