Skip to content

Commit

Permalink
Merge pull request #2 from Juandesi/button_action
Browse files Browse the repository at this point in the history
Button action
  • Loading branch information
Juan Desimoni committed Apr 26, 2015
2 parents f0afc77 + 7b8deee commit c17a835
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 51 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,15 @@
package com.example.android.wearablemessageapiexample;

import android.app.Activity;
import android.app.SearchManager;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;
import android.os.AsyncTask;
import android.os.Bundle;
import android.speech.RecognizerIntent;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageButton;
import android.widget.Toast;

Expand All @@ -50,22 +49,19 @@ public class WearActivity extends Activity {

private final String COMMAND_PATH = "/command";
private static final int VOICE_RECOGNITION_REQUEST_CODE = 1001;

private GoogleApiClient apiClient;
private String remoteNodeId;
private EditText metTextHint;
private Button mbtSpeak, mbtRight, mbtLeft, mbtWalk;
private ImageButton mbtSpeak, mbtRight, mbtLeft, mbtWalk;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main_activity);

metTextHint = (EditText) findViewById(R.id.etTextHint);
mbtSpeak = (Button) findViewById(R.id.btSpeak);
mbtLeft = (Button) findViewById(R.id.btLeftSpin);
mbtRight = (Button) findViewById(R.id.btRightSpin);
mbtWalk = (Button) findViewById(R.id.btWalk);
mbtSpeak = (ImageButton) findViewById(R.id.btSpeak);
mbtLeft = (ImageButton) findViewById(R.id.btLeftSpin);
mbtRight = (ImageButton) findViewById(R.id.btRightSpin);
mbtWalk = (ImageButton) findViewById(R.id.btWalk);

apiClient = apiClientFactory();
checkVoiceRecognition();
Expand All @@ -88,10 +84,6 @@ public void speak(View view) {
intent.putExtra(RecognizerIntent.EXTRA_CALLING_PACKAGE, getClass()
.getPackage().getName());

// Display an hint to the user about what he should say.
intent.putExtra(RecognizerIntent.EXTRA_PROMPT, metTextHint.getText()
.toString());

// Given an hint to the recognizer about what the user is going to say
//There are two form of language model available
//1.LANGUAGE_MODEL_WEB_SEARCH : For short phrases
Expand All @@ -107,15 +99,24 @@ public void speak(View view) {
}

public void rightSpinMove(View view) {
Wearable.MessageApi.sendMessage(apiClient, remoteNodeId, COMMAND_PATH, RIGHT_SPIN_MOVE.getBytes());
new SendMessage().execute(RIGHT_SPIN_MOVE);
}

public void leftSpinMove(View view) {
Wearable.MessageApi.sendMessage(apiClient, remoteNodeId, COMMAND_PATH, LEFT_SPIN_MOVE.getBytes());
new SendMessage().execute(LEFT_SPIN_MOVE);
}

public void walkMove(View view) {
Wearable.MessageApi.sendMessage(apiClient, remoteNodeId, COMMAND_PATH, WALK_MOVE.getBytes());
new SendMessage().execute(WALK_MOVE);
}

private class SendMessage extends AsyncTask<String, Void, Void> {

@Override
protected Void doInBackground(String... params) {
Wearable.MessageApi.sendMessage(apiClient, remoteNodeId, COMMAND_PATH, params[0].getBytes());
return null;
}
}

@Override
Expand Down Expand Up @@ -156,8 +157,6 @@ void showToastMessage(String message){
Toast.makeText(this, message, Toast.LENGTH_SHORT).show();
}



@Override
protected void onResume() {
super.onResume();
Expand Down
Binary file modified wear/src/main/res/drawable-mdpi/left.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified wear/src/main/res/drawable-mdpi/right.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified wear/src/main/res/drawable-mdpi/walk.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
71 changes: 39 additions & 32 deletions wear/src/main/res/layout/main_activity.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,54 +15,61 @@
-->


<FrameLayout
android:layout_width="match_parent"
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/darwinbg"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
>

<Button
<ImageButton
android:id="@+id/btSpeak"
android:layout_height="28dp"
android:onClick="speak"
android:background="@drawable/punch"
android:layout_width="52dp"
android:src="@drawable/punch"
android:background="@color/white"
tools:context=".VoiceRecognitionActivity"
android:layout_marginBottom="27dp"
android:layout_gravity="center_horizontal|bottom" />
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal|bottom"
android:layout_below="@+id/btWalk"
android:layout_centerHorizontal="true"
android:layout_marginTop="10dp" />

<Button
android:layout_width="34dp"
android:layout_height="32dp"
android:background="@drawable/walk"
android:id="@+id/btWalk"
android:onClick="walkMove"
android:width="24dp"
android:height="24dp"
android:layout_gravity="center"
android:layout_marginTop="27dp"
/>
<ImageButton
android:src="@drawable/left"
android:background="@color/white"
android:id="@+id/btLeftSpin"
android:onClick="leftSpinMove"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_gravity="left|center_vertical"
android:layout_above="@+id/btSpeak"
android:layout_toStartOf="@+id/btSpeak" />

<Button
<ImageButton
android:layout_width="32dp"
android:layout_height="32dp"
android:background="@drawable/right"
android:src="@drawable/right"
android:background="@color/white"
android:id="@+id/btRightSpin"
android:onClick="rightSpinMove"
android:layout_marginEnd="25dp"
android:layout_gravity="right|center_vertical" />
android:layout_gravity="right|center_vertical"
android:layout_above="@+id/btSpeak"
android:layout_toEndOf="@+id/btSpeak" />

<Button
android:layout_width="41dp"
android:layout_height="34dp"
android:background="@drawable/left"
android:id="@+id/btLeftSpin"
android:onClick="leftSpinMove"
android:layout_marginStart="24dp"
android:layout_gravity="left|center_vertical" />
<ImageButton
android:src="@drawable/walk"
android:id="@+id/btWalk"
android:onClick="walkMove"
android:background="@color/white"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="10dp" />


</FrameLayout>
</RelativeLayout>

0 comments on commit c17a835

Please sign in to comment.