diff --git a/res/layout/conversations.xml b/res/layout/conversations.xml
index cbcbc30..ce7bd1a 100644
--- a/res/layout/conversations.xml
+++ b/res/layout/conversations.xml
@@ -60,10 +60,21 @@ along with Yaaic. If not, see .
android:id="@+id/dots"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
-
+
+
+
+
\ No newline at end of file
diff --git a/src/org/yaaic/activity/ConversationActivity.java b/src/org/yaaic/activity/ConversationActivity.java
index 5114aa4..edbf0fd 100644
--- a/src/org/yaaic/activity/ConversationActivity.java
+++ b/src/org/yaaic/activity/ConversationActivity.java
@@ -20,7 +20,9 @@ along with Yaaic. If not, see .
*/
package org.yaaic.activity;
+import java.util.ArrayList;
import java.util.Collection;
+import java.util.List;
import org.yaaic.R;
import org.yaaic.Yaaic;
@@ -35,6 +37,7 @@ import org.yaaic.listener.ConversationClickListener;
import org.yaaic.listener.ConversationListener;
import org.yaaic.listener.ConversationSelectedListener;
import org.yaaic.listener.ServerListener;
+import org.yaaic.listener.SpeechClickListener;
import org.yaaic.model.Broadcast;
import org.yaaic.model.Conversation;
import org.yaaic.model.Extra;
@@ -54,8 +57,11 @@ import android.content.DialogInterface;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.ServiceConnection;
+import android.content.pm.PackageManager;
+import android.content.pm.ResolveInfo;
import android.os.Bundle;
import android.os.IBinder;
+import android.speech.RecognizerIntent;
import android.view.KeyEvent;
import android.view.Menu;
import android.view.MenuInflater;
@@ -63,6 +69,7 @@ import android.view.MenuItem;
import android.view.View;
import android.view.View.OnKeyListener;
import android.view.Window;
+import android.widget.Button;
import android.widget.EditText;
import android.widget.Gallery;
import android.widget.ImageView;
@@ -77,6 +84,8 @@ import android.widget.ViewSwitcher;
*/
public class ConversationActivity extends Activity implements ServiceConnection, ServerListener, ConversationListener, OnKeyListener
{
+ public static final int REQUEST_CODE_SPEECH = 99;
+
private static final int REQUEST_CODE_JOIN = 1;
private static final int REQUEST_CODE_USERS = 2;
private static final int REQUEST_CODE_USER = 3;
@@ -135,6 +144,16 @@ public class ConversationActivity extends Activity implements ServiceConnection,
deckAdapter.clearConversations();
}
+ // Check if speech recognition is available
+ PackageManager pm = getPackageManager();
+ Button speechButton = (Button) findViewById(R.id.speech);
+ List activities = pm.queryIntentActivities(new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH), 0);
+ if (activities.size() != 0) {
+ ((Button) findViewById(R.id.speech)).setOnClickListener(new SpeechClickListener(this));
+ } else {
+ speechButton.setVisibility(View.GONE);
+ }
+
// Optimization : cache field lookups
Collection mConversations = server.getConversations();
@@ -530,6 +549,15 @@ public class ConversationActivity extends Activity implements ServiceConnection,
}
switch (requestCode) {
+ case REQUEST_CODE_SPEECH:
+ ArrayList matches = data.getStringArrayListExtra(RecognizerIntent.EXTRA_RESULTS);
+ StringBuffer buffer = new StringBuffer();
+ for (String partial : matches) {
+ buffer.append(" ");
+ buffer.append(partial);
+ }
+ ((EditText) findViewById(R.id.input)).setText(buffer.toString().trim());
+ break;
case REQUEST_CODE_JOIN:
joinChannelBuffer = data.getExtras().getString("channel");
break;
diff --git a/src/org/yaaic/listener/SpeechClickListener.java b/src/org/yaaic/listener/SpeechClickListener.java
new file mode 100644
index 0000000..d135d3d
--- /dev/null
+++ b/src/org/yaaic/listener/SpeechClickListener.java
@@ -0,0 +1,63 @@
+/*
+Yaaic - Yet Another Android IRC Client
+
+Copyright 2009-2010 Sebastian Kaspari
+
+This file is part of Yaaic.
+
+Yaaic is free software: you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation, either version 3 of the License, or
+(at your option) any later version.
+
+Yaaic is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with Yaaic. If not, see .
+*/
+package org.yaaic.listener;
+
+import org.yaaic.activity.ConversationActivity;
+
+import android.app.Activity;
+import android.content.Intent;
+import android.speech.RecognizerIntent;
+import android.view.View;
+import android.view.View.OnClickListener;
+
+/**
+ * OnClickListener for the Speech Recognition Button
+ *
+ * @author Sebastian Kaspari
+ */
+public class SpeechClickListener implements OnClickListener
+{
+ private Activity activity;
+
+ /**
+ * Create a new listener for speech button
+ *
+ * @param activity
+ * @param input
+ */
+ public SpeechClickListener(Activity activity)
+ {
+ this.activity = activity;
+ }
+
+ /**
+ * On Click on speech button
+ */
+ public void onClick(View v)
+ {
+ Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
+
+ intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL, RecognizerIntent.LANGUAGE_MODEL_FREE_FORM);
+ intent.putExtra(RecognizerIntent.EXTRA_PROMPT, "");
+
+ activity.startActivityForResult(intent, ConversationActivity.REQUEST_CODE_SPEECH);
+ }
+}