Permalink
Browse files

First commit.

  • Loading branch information...
1 parent c8883a4 commit 88d15a87d5897e7165605c4023c0a466ae32146f @gregoriokusowski committed Jun 25, 2012
View
@@ -0,0 +1,8 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+ <classpathentry kind="src" path="src"/>
+ <classpathentry kind="src" path="gen"/>
+ <classpathentry kind="con" path="com.android.ide.eclipse.adt.ANDROID_FRAMEWORK"/>
+ <classpathentry kind="con" path="com.android.ide.eclipse.adt.LIBRARIES"/>
+ <classpathentry kind="output" path="bin/classes"/>
+</classpath>
View
@@ -0,0 +1,33 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+ <name>Accelerokey</name>
+ <comment></comment>
+ <projects>
+ </projects>
+ <buildSpec>
+ <buildCommand>
+ <name>com.android.ide.eclipse.adt.ResourceManagerBuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>com.android.ide.eclipse.adt.PreCompilerBuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.eclipse.jdt.core.javabuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>com.android.ide.eclipse.adt.ApkBuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ </buildSpec>
+ <natures>
+ <nature>com.android.ide.eclipse.adt.AndroidNature</nature>
+ <nature>org.eclipse.jdt.core.javanature</nature>
+ </natures>
+</projectDescription>
View
@@ -0,0 +1,29 @@
+<?xml version="1.0" encoding="utf-8"?>
+<manifest xmlns:android="http://schemas.android.com/apk/res/android"
+ package="br.feevale.accelerokey"
+ android:versionCode="1"
+ android:versionName="1.0" >
+
+ <uses-sdk android:minSdkVersion="7" />
+
+ <uses-permission android:name="android.permission.VIBRATE" >
+ </uses-permission>
+ <uses-permission android:name="android.permission.WAKE_LOCK" >
+ </uses-permission>
+
+ <application
+ android:icon="@drawable/ic_launcher"
+ android:label="@string/app_name" >
+ <activity
+ android:name=".AccelerokeyActivity"
+ android:label="@string/app_name"
+ android:screenOrientation="landscape" >
+ <intent-filter>
+ <action android:name="android.intent.action.MAIN" />
+
+ <category android:name="android.intent.category.LAUNCHER" />
+ </intent-filter>
+ </activity>
+ </application>
+
+</manifest>
View
@@ -0,0 +1,11 @@
+# This file is automatically generated by Android Tools.
+# Do not modify this file -- YOUR CHANGES WILL BE ERASED!
+#
+# This file must be checked in Version Control Systems.
+#
+# To customize properties used by the Ant build system use,
+# "ant.properties", and override values to adapt the script to your
+# project structure.
+
+# Project target.
+target=android-7
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
@@ -0,0 +1,46 @@
+<?xml version="1.0" encoding="utf-8"?>
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+ android:id="@+id/baseContainer"
+ android:layout_width="fill_parent"
+ android:layout_height="fill_parent"
+ android:orientation="vertical" >
+
+ <Gallery
+ android:id="@+id/charactersGallery"
+ android:layout_width="fill_parent"
+ android:layout_height="wrap_content"
+ android:spacing="20dp"
+ android:scrollbars="horizontal"/>
+
+ <LinearLayout
+ xmlns:android="http://schemas.android.com/apk/res/android"
+ android:layout_width="fill_parent"
+ android:layout_height="fill_parent"
+ android:orientation="horizontal" >
+
+ <Button
+ android:id="@+id/speak"
+ android:layout_width="0dp"
+ android:layout_height="fill_parent"
+ android:layout_weight="1"
+ android:gravity="left"
+ android:text="S" />
+
+ <TextView
+ android:id="@+id/word"
+ android:layout_width="0dp"
+ android:layout_height="wrap_content"
+ android:layout_weight="3"
+ android:gravity="bottom"
+ android:text="" />
+
+ <Button
+ android:id="@+id/backspace"
+ android:layout_width="0dp"
+ android:layout_height="fill_parent"
+ android:layout_weight="1"
+ android:gravity="right"
+ android:text="x" />
+ </LinearLayout>
+
+</LinearLayout>
@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="utf-8"?>
+<resources>
+
+ <string name="hello">Hello World, AccelerokeyActivity!</string>
+ <string name="app_name">Accelerokey</string>
+
+</resources>
@@ -0,0 +1,183 @@
+package br.feevale.accelerokey;
+
+import java.util.Locale;
+
+import android.app.Activity;
+import android.content.Intent;
+import android.hardware.Sensor;
+import android.hardware.SensorManager;
+import android.os.Bundle;
+import android.os.PowerManager;
+import android.os.PowerManager.WakeLock;
+import android.speech.tts.TextToSpeech;
+import android.speech.tts.TextToSpeech.OnInitListener;
+import android.view.Display;
+import android.view.View;
+import android.widget.Button;
+import android.widget.Gallery;
+import android.widget.TextView;
+
+public class AccelerokeyActivity extends Activity {
+
+ private Equilibrist equilibrist;
+
+ private SensorManager mSensorManager;
+ private PowerManager mPowerManager;
+ private WakeLock mWakeLock;
+ private EquilibristSensorEventListener equilibristSensorEventListener;
+ private Gallery gallery;
+ private TextView word;
+
+ /* Text to speech code */
+ public final static int TTS_CODE = 823832;
+
+ @Override
+ public void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+
+ /* sensor manager */
+ mSensorManager = (SensorManager) getSystemService(SENSOR_SERVICE);
+ Sensor sensor = mSensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER);
+ equilibristSensorEventListener = new EquilibristSensorEventListener(getEquilibrist());
+ mSensorManager.registerListener(equilibristSensorEventListener, sensor, SensorManager.SENSOR_DELAY_UI);
+
+
+ /* wake lock */
+ mPowerManager = (PowerManager) getSystemService(POWER_SERVICE);
+ mWakeLock = mPowerManager.newWakeLock(PowerManager.SCREEN_BRIGHT_WAKE_LOCK, getClass().getName());
+
+ /* layout */
+ setContentView(R.layout.main);
+
+ Display display = getWindowManager().getDefaultDisplay();
+ int height = display.getHeight() / 3;
+
+ gallery = (Gallery) findViewById(R.id.charactersGallery);
+ gallery.setAdapter(new CharacterListAdapter(this, height, (display.getHeight() / 5)));
+
+ word = (TextView) findViewById(R.id.word);
+
+ Button backspace = (Button) findViewById(R.id.backspace);
+ backspace.setTextSize(display.getHeight() / 5);
+ backspace.setOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(View v) {
+ String text = (String) word.getText();
+ if (text.length() > 0){
+ word.setText(text.substring(0, text.length() -1));
+ }
+ }
+ });
+
+ /* getting an available text to speech resource */
+ Intent checkIntent = new Intent();
+ checkIntent.setAction(TextToSpeech.Engine.ACTION_CHECK_TTS_DATA);
+ startActivityForResult(checkIntent, TTS_CODE);
+
+ Button speak = (Button) findViewById(R.id.speak);
+ speak.setTextSize(display.getHeight() / 5);
+ speak.setOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(View v) {
+ mTts.setLanguage(Locale.US);
+ mTts.speak((String) word.getText(), TextToSpeech.QUEUE_ADD, null);
+ }
+ });
+ }
+
+ private TextToSpeech mTts;
+
+ protected void onActivityResult(
+ int requestCode, int resultCode, Intent data) {
+ if (requestCode == TTS_CODE) {
+ if (resultCode == TextToSpeech.Engine.CHECK_VOICE_DATA_PASS) {
+ mTts = new TextToSpeech(this, new OnInitListener() {
+ @Override
+ public void onInit(int status) {
+ if(status == TextToSpeech.SUCCESS){
+
+ }else{
+
+ }
+ }
+ });
+ } else {
+ // missing data, install it
+ Intent installIntent = new Intent();
+ installIntent.setAction(
+ TextToSpeech.Engine.ACTION_INSTALL_TTS_DATA);
+ startActivity(installIntent);
+ }
+ }
+ }
+
+ @Override
+ protected void onResume() {
+ super.onResume();
+ mWakeLock.acquire();
+ }
+
+ @Override
+ protected void onPause() {
+ super.onPause();
+ mWakeLock.release();
+ }
+
+ @Override
+ protected void onStop() {
+ super.onStop();
+ mSensorManager.unregisterListener(equilibristSensorEventListener);
+ }
+
+ private Equilibrist getEquilibrist(){
+ if (equilibrist == null){
+ equilibrist = new Equilibrist(){
+ public void fall(CardinalDirection cardinalDirection) {
+ switch (cardinalDirection) {
+ case EAST:
+ moveOnXAxis(Direction.POSITIVE);
+ break;
+ case NORTH:
+ moveOnYAxis(Direction.NEGATIVE);
+ break;
+ case SOUTH:
+ moveOnYAxis(Direction.POSITIVE);
+ break;
+ case WEST:
+ moveOnXAxis(Direction.NEGATIVE);
+ break;
+ default:
+ break;
+ }
+ }
+ };
+ }
+ return equilibrist;
+ }
+
+ public void moveOnXAxis(Direction xDirection) {
+ int selectedItemPosition = gallery.getSelectedItemPosition();
+ int newPosition = selectedItemPosition;
+ if ( xDirection == Direction.NEGATIVE ){
+ newPosition -= 1;
+ }else{
+ newPosition += 1;
+ }
+ if (newPosition < 0){
+ newPosition = 0;
+ }else if(newPosition >= gallery.getAdapter().getCount()){
+ newPosition = gallery.getAdapter().getCount() - 1;
+ }
+
+ gallery.setSelection(newPosition, true);
+ gallery.requestChildFocus(gallery.getChildAt(newPosition), gallery.getFocusedChild());
+ }
+
+ public void moveOnYAxis(Direction yDirection) {
+ if(yDirection == Direction.NEGATIVE){
+ String text = (String) gallery.getSelectedItem();
+ word.setText(word.getText() + text);
+ }
+ }
+
+}
@@ -0,0 +1,11 @@
+package br.feevale.accelerokey;
+
+/**
+ * For your knowledge:
+ * N
+ * W E
+ * S
+ */
+public enum CardinalDirection {
+ NORTH, EAST, SOUTH, WEST
+}
@@ -0,0 +1,47 @@
+package br.feevale.accelerokey;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import android.content.Context;
+import android.view.View;
+import android.view.ViewGroup;
+import android.widget.BaseAdapter;
+import android.widget.TextView;
+/**
+ * Gallery adapter to show a list of characters (a..z) to be selected
+ */
+public class CharacterListAdapter extends BaseAdapter {
+ private List<TextView> buttons;
+
+ public CharacterListAdapter(Context c, int size, float height) {
+
+ buttons = new ArrayList<TextView>();
+ for (char i = 'A'; i <= 'Z'; i++) {
+ TextView child = new TextView(c);
+ child.setId(100 + i);
+ child.setText("" + new Character(i));
+ child.setWidth(size);
+ child.setHeight(size);
+ child.setTextSize(height);
+ buttons.add(child);
+ }
+
+ }
+
+ public int getCount() {
+ return buttons.size();
+ }
+
+ public Object getItem(int position) {
+ return buttons.get(position).getText();
+ }
+
+ public long getItemId(int position) {
+ return position;
+ }
+
+ public View getView(int position, View convertView, ViewGroup parent) {
+ return buttons.get(position);
+ }
+}
@@ -0,0 +1,5 @@
+package br.feevale.accelerokey;
+
+public enum Direction {
+ POSITIVE, NEGATIVE
+}
Oops, something went wrong.

0 comments on commit 88d15a8

Please sign in to comment.