1
0
mirror of https://github.com/moparisthebest/Yaaic synced 2024-11-29 04:12:18 -05:00

Fix voice recognition: Only add top match to the text input (and code cleanup)

This commit is contained in:
Sebastian Kaspari 2011-01-15 23:17:16 +01:00
parent e68ef9c8c2
commit 7c63155cfb

View File

@ -70,8 +70,8 @@ import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnKeyListener;
import android.view.inputmethod.InputMethodManager;
import android.view.Window;
import android.view.inputmethod.InputMethodManager;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Gallery;
@ -128,7 +128,7 @@ public class ConversationActivity extends Activity implements ServiceConnection,
requestWindowFeature(Window.FEATURE_NO_TITLE);
serverId = getIntent().getExtras().getInt("serverId");
server = (Server) Yaaic.getInstance().getServerById(serverId);
server = Yaaic.getInstance().getServerById(serverId);
setTitle("Yaaic - " + server.getTitle());
setContentView(R.layout.conversations);
@ -231,6 +231,7 @@ public class ConversationActivity extends Activity implements ServiceConnection,
// Join channel that has been selected in JoinActivity (onActivityResult())
if (joinChannelBuffer != null) {
new Thread() {
@Override
public void run() {
binder.getService().getConnection(serverId).joinChannel(joinChannelBuffer);
joinChannelBuffer = null;
@ -259,6 +260,7 @@ public class ConversationActivity extends Activity implements ServiceConnection,
/**
* On service connected
*/
@Override
public void onServiceConnected(ComponentName name, IBinder service)
{
this.binder = (IRCBinder) service;
@ -273,6 +275,7 @@ public class ConversationActivity extends Activity implements ServiceConnection,
/**
* On service disconnected
*/
@Override
public void onServiceDisconnected(ComponentName name)
{
this.binder = null;
@ -369,6 +372,7 @@ public class ConversationActivity extends Activity implements ServiceConnection,
/**
* On conversation message
*/
@Override
public void onConversationMessage(String target)
{
Conversation conversation = server.getConversation(target);
@ -399,6 +403,7 @@ public class ConversationActivity extends Activity implements ServiceConnection,
/**
* On new conversation
*/
@Override
public void onNewConversation(String target)
{
deckAdapter.addItem(server.getConversation(target));
@ -412,6 +417,7 @@ public class ConversationActivity extends Activity implements ServiceConnection,
/**
* On conversation remove
*/
@Override
public void onRemoveConversation(String target)
{
deckAdapter.removeItem(target);
@ -426,6 +432,7 @@ public class ConversationActivity extends Activity implements ServiceConnection,
/**
* On server status update
*/
@Override
public void onStatusUpdate()
{
((ImageView) findViewById(R.id.status)).setImageResource(server.getStatusIcon());
@ -448,6 +455,7 @@ public class ConversationActivity extends Activity implements ServiceConnection,
builder.setMessage(getResources().getString(R.string.reconnect_after_disconnect, server.getTitle()))
.setCancelable(false)
.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int id) {
binder.getService().getConnection(server.getId()).setAutojoinChannels(
server.getCurrentChannelNames()
@ -459,6 +467,7 @@ public class ConversationActivity extends Activity implements ServiceConnection,
}
})
.setNegativeButton(getString(R.string.negative_button), new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int id) {
dialog.cancel();
}
@ -491,6 +500,7 @@ public class ConversationActivity extends Activity implements ServiceConnection,
/**
* On key pressed (input line)
*/
@Override
public boolean onKey(View view, int keyCode, KeyEvent event)
{
EditText input = (EditText) view;
@ -670,12 +680,9 @@ public class ConversationActivity extends Activity implements ServiceConnection,
switch (requestCode) {
case REQUEST_CODE_SPEECH:
ArrayList<String> matches = data.getStringArrayListExtra(RecognizerIntent.EXTRA_RESULTS);
StringBuffer buffer = new StringBuffer();
for (String partial : matches) {
buffer.append(" ");
buffer.append(partial);
if (matches.size() > 0) {
((EditText) findViewById(R.id.input)).setText(matches.get(0));
}
((EditText) findViewById(R.id.input)).setText(buffer.toString().trim());
break;
case REQUEST_CODE_JOIN:
joinChannelBuffer = data.getExtras().getString("channel");
@ -721,6 +728,7 @@ public class ConversationActivity extends Activity implements ServiceConnection,
// Yes .. that's very ugly - we need some kind of queue that is handled after onResume()
new Thread() {
@Override
public void run() {
try {
Thread.sleep(1000);