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