diff options
| -rw-r--r-- | api/current.xml | 1095 | ||||
| -rw-r--r-- | cmds/bootanimation/Android.mk | 30 | ||||
| -rw-r--r-- | cmds/bootanimation/BootAnimation.cpp (renamed from libs/surfaceflinger/BootAnimation.cpp) | 27 | ||||
| -rw-r--r-- | cmds/bootanimation/BootAnimation.h (renamed from libs/surfaceflinger/BootAnimation.h) | 6 | ||||
| -rw-r--r-- | cmds/bootanimation/bootanimation_main.cpp | 52 | ||||
| -rwxr-xr-x | core/java/android/gesture/Gesture.java (renamed from tests/sketch/src/com/android/gesture/Gesture.java) | 169 | ||||
| -rw-r--r-- | core/java/android/gesture/GestureConstants.java (renamed from tests/sketch/src/com/android/gesture/GestureActionListener.java) | 13 | ||||
| -rw-r--r-- | core/java/android/gesture/GestureLibrary.java (renamed from tests/sketch/src/com/android/gesture/GestureLibrary.java) | 238 | ||||
| -rwxr-xr-x | core/java/android/gesture/GestureOverlayView.java (renamed from tests/sketch/src/com/android/gesture/GestureOverlay.java) | 65 | ||||
| -rw-r--r-- | core/java/android/gesture/GesturePoint.java (renamed from tests/sketch/src/com/android/gesture/GesturePoint.java) | 14 | ||||
| -rw-r--r-- | core/java/android/gesture/GestureStroke.java (renamed from tests/sketch/src/com/android/gesture/GestureStroke.java) | 104 | ||||
| -rwxr-xr-x | core/java/android/gesture/GestureUtilities.java (renamed from tests/sketch/src/com/android/gesture/GestureUtilities.java) | 32 | ||||
| -rwxr-xr-x | core/java/android/gesture/Instance.java (renamed from tests/sketch/src/com/android/gesture/Instance.java) | 13 | ||||
| -rw-r--r-- | core/java/android/gesture/InstanceLearner.java (renamed from tests/sketch/src/com/android/gesture/InstanceLearner.java) | 24 | ||||
| -rwxr-xr-x | core/java/android/gesture/Learner.java (renamed from tests/sketch/src/com/android/gesture/Learner.java) | 2 | ||||
| -rw-r--r-- | core/java/android/gesture/LetterRecognizer.java (renamed from tests/sketch/src/com/android/gesture/LetterRecognizer.java) | 203 | ||||
| -rw-r--r-- | core/java/android/gesture/OrientedBoundingBox.java (renamed from tests/sketch/src/com/android/gesture/OrientedBoundingBox.java) | 7 | ||||
| -rwxr-xr-x | core/java/android/gesture/Prediction.java (renamed from tests/sketch/src/com/android/gesture/Prediction.java) | 2 | ||||
| -rw-r--r-- | core/java/android/gesture/TouchThroughGestureListener.java (renamed from tests/sketch/src/com/android/gesture/TouchThroughGesturing.java) | 80 | ||||
| -rw-r--r-- | core/java/android/view/SurfaceView.java | 13 | ||||
| -rw-r--r-- | core/java/android/view/Window.java | 6 | ||||
| -rw-r--r-- | core/java/android/view/WindowManager.java | 9 | ||||
| -rw-r--r-- | core/res/res/raw/latin_lowercase | bin | 36186 -> 28494 bytes | |||
| -rw-r--r-- | core/res/res/values/config.xml | 4 | ||||
| -rw-r--r-- | core/res/res/values/public.xml | 7 | ||||
| -rw-r--r-- | data/etc/platform.xml | 2 | ||||
| -rw-r--r-- | include/binder/Parcel.h | 18 | ||||
| -rw-r--r-- | include/tts/TtsEngine.h | 167 | ||||
| -rw-r--r-- | libs/binder/Parcel.cpp | 39 | ||||
| -rw-r--r-- | libs/surfaceflinger/Android.mk | 1 | ||||
| -rw-r--r-- | libs/surfaceflinger/SurfaceFlinger.cpp | 30 | ||||
| -rw-r--r-- | libs/surfaceflinger/SurfaceFlinger.h | 3 | ||||
| -rw-r--r-- | libs/surfaceflinger/VRamHeap.cpp | 2 | ||||
| -rw-r--r-- | libs/ui/ISurfaceFlingerClient.cpp | 13 | ||||
| -rw-r--r-- | libs/ui/Overlay.cpp | 12 | ||||
| -rwxr-xr-x | tests/sketch/AndroidManifest.xml | 25 | ||||
| -rw-r--r-- | tests/sketch/src/com/android/gesture/GestureConstants.java | 32 | ||||
| -rwxr-xr-x | tests/sketch/src/com/android/gesture/GestureListener.java | 30 | ||||
| -rw-r--r-- | tests/sketch/src/com/android/gesture/example/ContactListGestureOverlay.java | 27 | ||||
| -rw-r--r-- | tests/sketch/src/com/android/gesture/example/GestureEntry.java | 23 | ||||
| -rwxr-xr-x | tests/sketch/src/com/android/gesture/example/GestureLibViewer.java | 10 | ||||
| -rw-r--r-- | tests/sketch/tools/Converter.java | 10 |
42 files changed, 2004 insertions, 655 deletions
diff --git a/api/current.xml b/api/current.xml index b15703a354a4..dde1b762683d 100644 --- a/api/current.xml +++ b/api/current.xml @@ -2037,7 +2037,7 @@ type="int" transient="false" volatile="false" - value="16843433" + value="16843424" static="true" final="true" deprecated="not deprecated" @@ -2994,7 +2994,7 @@ type="int" transient="false" volatile="false" - value="16843434" + value="16843425" static="true" final="true" deprecated="not deprecated" @@ -49368,6 +49368,1097 @@ </method> </class> </package> +<package name="android.gesture" +> +<class name="Gesture" + extends="java.lang.Object" + abstract="false" + static="false" + final="false" + deprecated="not deprecated" + visibility="public" +> +<implements name="android.os.Parcelable"> +</implements> +<constructor name="Gesture" + type="android.gesture.Gesture" + static="false" + final="false" + deprecated="not deprecated" + visibility="public" +> +</constructor> +<method name="addStroke" + return="void" + abstract="false" + native="false" + synchronized="false" + static="false" + final="false" + deprecated="not deprecated" + visibility="public" +> +<parameter name="stroke" type="android.gesture.GestureStroke"> +</parameter> +</method> +<method name="describeContents" + return="int" + abstract="false" + native="false" + synchronized="false" + static="false" + final="false" + deprecated="not deprecated" + visibility="public" +> +</method> +<method name="getBoundingBox" + return="android.graphics.RectF" + abstract="false" + native="false" + synchronized="false" + static="false" + final="false" + deprecated="not deprecated" + visibility="public" +> +</method> +<method name="getID" + return="long" + abstract="false" + native="false" + synchronized="false" + static="false" + final="false" + deprecated="not deprecated" + visibility="public" +> +</method> +<method name="getLength" + return="float" + abstract="false" + native="false" + synchronized="false" + static="false" + final="false" + deprecated="not deprecated" + visibility="public" +> +</method> +<method name="getStrokes" + return="java.util.ArrayList<android.gesture.GestureStroke>" + abstract="false" + native="false" + synchronized="false" + static="false" + final="false" + deprecated="not deprecated" + visibility="public" +> +</method> +<method name="getStrokesCount" + return="int" + abstract="false" + native="false" + synchronized="false" + static="false" + final="false" + deprecated="not deprecated" + visibility="public" +> +</method> +<method name="toBitmap" + return="android.graphics.Bitmap" + abstract="false" + native="false" + synchronized="false" + static="false" + final="false" + deprecated="not deprecated" + visibility="public" +> +<parameter name="width" type="int"> +</parameter> +<parameter name="height" type="int"> +</parameter> +<parameter name="edge" type="int"> +</parameter> +<parameter name="numSample" type="int"> +</parameter> +<parameter name="color" type="int"> +</parameter> +</method> +<method name="toBitmap" + return="android.graphics.Bitmap" + abstract="false" + native="false" + synchronized="false" + static="false" + final="false" + deprecated="not deprecated" + visibility="public" +> +<parameter name="width" type="int"> +</parameter> +<parameter name="height" type="int"> +</parameter> +<parameter name="edge" type="int"> +</parameter> +<parameter name="color" type="int"> +</parameter> +</method> +<method name="writeToParcel" + return="void" + abstract="false" + native="false" + synchronized="false" + static="false" + final="false" + deprecated="not deprecated" + visibility="public" +> +<parameter name="out" type="android.os.Parcel"> +</parameter> +<parameter name="flags" type="int"> +</parameter> +</method> +<field name="CREATOR" + type="android.os.Parcelable.Creator" + transient="false" + volatile="false" + static="true" + final="true" + deprecated="not deprecated" + visibility="public" +> +</field> +</class> +<class name="GestureLibrary" + extends="java.lang.Object" + abstract="false" + static="false" + final="false" + deprecated="not deprecated" + visibility="public" +> +<constructor name="GestureLibrary" + type="android.gesture.GestureLibrary" + static="false" + final="false" + deprecated="not deprecated" + visibility="public" +> +<parameter name="path" type="java.lang.String"> +</parameter> +</constructor> +<method name="addGesture" + return="void" + abstract="false" + native="false" + synchronized="false" + static="false" + final="false" + deprecated="not deprecated" + visibility="public" +> +<parameter name="entryName" type="java.lang.String"> +</parameter> +<parameter name="gesture" type="android.gesture.Gesture"> +</parameter> +</method> +<method name="getGestureEntries" + return="java.util.Set<java.lang.String>" + abstract="false" + native="false" + synchronized="false" + static="false" + final="false" + deprecated="not deprecated" + visibility="public" +> +</method> +<method name="getGestures" + return="java.util.ArrayList<android.gesture.Gesture>" + abstract="false" + native="false" + synchronized="false" + static="false" + final="false" + deprecated="not deprecated" + visibility="public" +> +<parameter name="entryName" type="java.lang.String"> +</parameter> +</method> +<method name="getOrientationStyle" + return="int" + abstract="false" + native="false" + synchronized="false" + static="false" + final="false" + deprecated="not deprecated" + visibility="public" +> +</method> +<method name="getSequenceType" + return="int" + abstract="false" + native="false" + synchronized="false" + static="false" + final="false" + deprecated="not deprecated" + visibility="public" +> +</method> +<method name="load" + return="boolean" + abstract="false" + native="false" + synchronized="false" + static="false" + final="false" + deprecated="not deprecated" + visibility="public" +> +</method> +<method name="recognize" + return="java.util.ArrayList<android.gesture.Prediction>" + abstract="false" + native="false" + synchronized="false" + static="false" + final="false" + deprecated="not deprecated" + visibility="public" +> +<parameter name="gesture" type="android.gesture.Gesture"> +</parameter> +</method> +<method name="removeEntry" + return="void" + abstract="false" + native="false" + synchronized="false" + static="false" + final="false" + deprecated="not deprecated" + visibility="public" +> +<parameter name="entryName" type="java.lang.String"> +</parameter> +</method> +<method name="removeGesture" + return="void" + abstract="false" + native="false" + synchronized="false" + static="false" + final="false" + deprecated="not deprecated" + visibility="public" +> +<parameter name="entryName" type="java.lang.String"> +</parameter> +<parameter name="gesture" type="android.gesture.Gesture"> +</parameter> +</method> +<method name="save" + return="boolean" + abstract="false" + native="false" + synchronized="false" + static="false" + final="false" + deprecated="not deprecated" + visibility="public" +> +</method> +<method name="setOrientationStyle" + return="void" + abstract="false" + native="false" + synchronized="false" + static="false" + final="false" + deprecated="not deprecated" + visibility="public" +> +<parameter name="style" type="int"> +</parameter> +</method> +<method name="setSequenceType" + return="void" + abstract="false" + native="false" + synchronized="false" + static="false" + final="false" + deprecated="not deprecated" + visibility="public" +> +<parameter name="type" type="int"> +</parameter> +</method> +<field name="ORIENTATION_INVARIANT" + type="int" + transient="false" + volatile="false" + value="1" + static="true" + final="true" + deprecated="not deprecated" + visibility="public" +> +</field> +<field name="ORIENTATION_SENSITIVE" + type="int" + transient="false" + volatile="false" + value="2" + static="true" + final="true" + deprecated="not deprecated" + visibility="public" +> +</field> +<field name="SEQUENCE_INVARIANT" + type="int" + transient="false" + volatile="false" + value="1" + static="true" + final="true" + deprecated="not deprecated" + visibility="public" +> +</field> +<field name="SEQUENCE_SENSITIVE" + type="int" + transient="false" + volatile="false" + value="2" + static="true" + final="true" + deprecated="not deprecated" + visibility="public" +> +</field> +</class> +<class name="GestureOverlayView" + extends="android.view.View" + abstract="false" + static="false" + final="false" + deprecated="not deprecated" + visibility="public" +> +<constructor name="GestureOverlayView" + type="android.gesture.GestureOverlayView" + static="false" + final="false" + deprecated="not deprecated" + visibility="public" +> +<parameter name="context" type="android.content.Context"> +</parameter> +</constructor> +<constructor name="GestureOverlayView" + type="android.gesture.GestureOverlayView" + static="false" + final="false" + deprecated="not deprecated" + visibility="public" +> +<parameter name="context" type="android.content.Context"> +</parameter> +<parameter name="attrs" type="android.util.AttributeSet"> +</parameter> +</constructor> +<method name="addOnGestureListener" + return="void" + abstract="false" + native="false" + synchronized="false" + static="false" + final="false" + deprecated="not deprecated" + visibility="public" +> +<parameter name="listener" type="android.gesture.GestureOverlayView.OnGestureListener"> +</parameter> +</method> +<method name="cancelFadingOut" + return="void" + abstract="false" + native="false" + synchronized="false" + static="false" + final="false" + deprecated="not deprecated" + visibility="public" +> +</method> +<method name="clear" + return="void" + abstract="false" + native="false" + synchronized="false" + static="false" + final="false" + deprecated="not deprecated" + visibility="public" +> +<parameter name="fadeOut" type="boolean"> +</parameter> +</method> +<method name="getCurrentGesture" + return="android.gesture.Gesture" + abstract="false" + native="false" + synchronized="false" + static="false" + final="false" + deprecated="not deprecated" + visibility="public" +> +</method> +<method name="getCurrentStroke" + return="java.util.ArrayList<android.gesture.GesturePoint>" + abstract="false" + native="false" + synchronized="false" + static="false" + final="false" + deprecated="not deprecated" + visibility="public" +> +</method> +<method name="getGestureColor" + return="int" + abstract="false" + native="false" + synchronized="false" + static="false" + final="false" + deprecated="not deprecated" + visibility="public" +> +</method> +<method name="getUncertainGestureColor" + return="int" + abstract="false" + native="false" + synchronized="false" + static="false" + final="false" + deprecated="not deprecated" + visibility="public" +> +</method> +<method name="removeOnGestureListener" + return="void" + abstract="false" + native="false" + synchronized="false" + static="false" + final="false" + deprecated="not deprecated" + visibility="public" +> +<parameter name="listener" type="android.gesture.GestureOverlayView.OnGestureListener"> +</parameter> +</method> +<method name="setCurrentGesture" + return="void" + abstract="false" + native="false" + synchronized="false" + static="false" + final="false" + deprecated="not deprecated" + visibility="public" +> +<parameter name="gesture" type="android.gesture.Gesture"> +</parameter> +</method> +<method name="setGestureColor" + return="void" + abstract="false" + native="false" + synchronized="false" + static="false" + final="false" + deprecated="not deprecated" + visibility="public" +> +<parameter name="color" type="int"> +</parameter> +</method> +<method name="setGestureDrawingColor" + return="void" + abstract="false" + native="false" + synchronized="false" + static="false" + final="false" + deprecated="not deprecated" + visibility="public" +> +<parameter name="color" type="int"> +</parameter> +</method> +<method name="setUncertainGestureColor" + return="void" + abstract="false" + native="false" + synchronized="false" + static="false" + final="false" + deprecated="not deprecated" + visibility="public" +> +<parameter name="color" type="int"> +</parameter> +</method> +<field name="DEFAULT_GESTURE_COLOR" + type="int" + transient="false" + volatile="false" + value="-256" + static="true" + final="true" + deprecated="not deprecated" + visibility="public" +> +</field> +<field name="DEFAULT_UNCERTAIN_GESTURE_COLOR" + type="int" + transient="false" + volatile="false" + static="true" + final="true" + deprecated="not deprecated" + visibility="public" +> +</field> +</class> +<interface name="GestureOverlayView.OnGestureListener" + abstract="true" + static="true" + final="false" + deprecated="not deprecated" + visibility="public" +> +<method name="onGesture" + return="void" + abstract="true" + native="false" + synchronized="false" + static="false" + final="false" + deprecated="not deprecated" + visibility="public" +> +<parameter name="overlay" type="android.gesture.GestureOverlayView"> +</parameter> +<parameter name="event" type="android.view.MotionEvent"> +</parameter> +</method> +<method name="onGestureEnded" + return="void" + abstract="true" + native="false" + synchronized="false" + static="false" + final="false" + deprecated="not deprecated" + visibility="public" +> +<parameter name="overlay" type="android.gesture.GestureOverlayView"> +</parameter> +<parameter name="event" type="android.view.MotionEvent"> +</parameter> +</method> +<method name="onGestureStarted" + return="void" + abstract="true" + native="false" + synchronized="false" + static="false" + final="false" + deprecated="not deprecated" + visibility="public" +> +<parameter name="overlay" type="android.gesture.GestureOverlayView"> +</parameter> +<parameter name="event" type="android.view.MotionEvent"> +</parameter> +</method> +</interface> +<class name="GesturePoint" + extends="java.lang.Object" + abstract="false" + static="false" + final="false" + deprecated="not deprecated" + visibility="public" +> +<constructor name="GesturePoint" + type="android.gesture.GesturePoint" + static="false" + final="false" + deprecated="not deprecated" + visibility="public" +> +<parameter name="x" type="float"> +</parameter> +<parameter name="y" type="float"> +</parameter> +<parameter name="t" type="long"> +</parameter> +</constructor> +<field name="timestamp" + type="long" + transient="false" + volatile="false" + static="false" + final="true" + deprecated="not deprecated" + visibility="public" +> +</field> +<field name="x" + type="float" + transient="false" + volatile="false" + static="false" + final="true" + deprecated="not deprecated" + visibility="public" +> +</field> +<field name="y" + type="float" + transient="false" + volatile="false" + static="false" + final="true" + deprecated="not deprecated" + visibility="public" +> +</field> +</class> +<class name="GestureStroke" + extends="java.lang.Object" + abstract="false" + static="false" + final="false" + deprecated="not deprecated" + visibility="public" +> +<constructor name="GestureStroke" + type="android.gesture.GestureStroke" + static="false" + final="false" + deprecated="not deprecated" + visibility="public" +> +<parameter name="points" type="java.util.ArrayList<android.gesture.GesturePoint>"> +</parameter> +</constructor> +<method name="clearPath" + return="void" + abstract="false" + native="false" + synchronized="false" + static="false" + final="false" + deprecated="not deprecated" + visibility="public" +> +</method> +<method name="computeOrientedBoundingBox" + return="android.gesture.OrientedBoundingBox" + abstract="false" + native="false" + synchronized="false" + static="false" + final="false" + deprecated="not deprecated" + visibility="public" +> +</method> +<method name="toPath" + return="android.graphics.Path" + abstract="false" + native="false" + synchronized="false" + static="false" + final="false" + deprecated="not deprecated" + visibility="public" +> +<parameter name="width" type="float"> +</parameter> +<parameter name="height" type="float"> +</parameter> +<parameter name="numSample" type="int"> +</parameter> +</method> +<field name="boundingBox" + type="android.graphics.RectF" + transient="false" + volatile="false" + static="false" + final="true" + deprecated="not deprecated" + visibility="public" +> +</field> +<field name="length" + type="float" + transient="false" + volatile="false" + static="false" + final="true" + deprecated="not deprecated" + visibility="public" +> +</field> +<field name="points" + type="float[]" + transient="false" + volatile="false" + value="null" + static="false" + final="true" + deprecated="not deprecated" + visibility="public" +> +</field> +</class> +<class name="LetterRecognizer" + extends="java.lang.Object" + abstract="false" + static="false" + final="false" + deprecated="not deprecated" + visibility="public" +> +<method name="getLetterRecognizer" + return="android.gesture.LetterRecognizer" + abstract="false" + native="false" + synchronized="false" + static="true" + final="false" + deprecated="not deprecated" + visibility="public" +> +<parameter name="context" type="android.content.Context"> +</parameter> +<parameter name="type" type="int"> +</parameter> +</method> +<method name="recognize" + return="java.util.ArrayList<android.gesture.Prediction>" + abstract="false" + native="false" + synchronized="false" + static="false" + final="false" + deprecated="not deprecated" + visibility="public" +> +<parameter name="gesture" type="android.gesture.Gesture"> +</parameter> +</method> +<field name="RECOGNIZER_LATIN_LOWERCASE" + type="int" + transient="false" + volatile="false" + value="0" + static="true" + final="true" + deprecated="not deprecated" + visibility="public" +> +</field> +</class> +<class name="OrientedBoundingBox" + extends="java.lang.Object" + abstract="false" + static="false" + final="false" + deprecated="not deprecated" + visibility="public" +> +<field name="centerX" + type="float" + transient="false" + volatile="false" + static="false" + final="true" + deprecated="not deprecated" + visibility="public" +> +</field> +<field name="centerY" + type="float" + transient="false" + volatile="false" + static="false" + final="true" + deprecated="not deprecated" + visibility="public" +> +</field> +<field name="height" + type="float" + transient="false" + volatile="false" + static="false" + final="true" + deprecated="not deprecated" + visibility="public" +> +</field> +<field name="orientation" + type="float" + transient="false" + volatile="false" + static="false" + final="true" + deprecated="not deprecated" + visibility="public" +> +</field> +<field name="squareness" + type="float" + transient="false" + volatile="false" + static="false" + final="true" + deprecated="not deprecated" + visibility="public" +> +</field> +<field name="width" + type="float" + transient="false" + volatile="false" + static="false" + final="true" + deprecated="not deprecated" + visibility="public" +> +</field> +</class> +<class name="Prediction" + extends="java.lang.Object" + abstract="false" + static="false" + final="false" + deprecated="not deprecated" + visibility="public" +> +<field name="name" + type="java.lang.String" + transient="false" + volatile="false" + static="false" + final="true" + deprecated="not deprecated" + visibility="public" +> +</field> +<field name="score" + type="double" + transient="false" + volatile="false" + static="false" + final="false" + deprecated="not deprecated" + visibility="public" +> +</field> +</class> +<class name="TouchThroughGestureListener" + extends="java.lang.Object" + abstract="false" + static="false" + final="false" + deprecated="not deprecated" + visibility="public" +> +<implements name="android.gesture.GestureOverlayView.OnGestureListener"> +</implements> +<constructor name="TouchThroughGestureListener" + type="android.gesture.TouchThroughGestureListener" + static="false" + final="false" + deprecated="not deprecated" + visibility="public" +> +<parameter name="model" type="android.view.View"> +</parameter> +</constructor> +<constructor name="TouchThroughGestureListener" + type="android.gesture.TouchThroughGestureListener" + static="false" + final="false" + deprecated="not deprecated" + visibility="public" +> +<parameter name="model" type="android.view.View"> +</parameter> +<parameter name="stealEvents" type="boolean"> +</parameter> +</constructor> +<method name="addOnGestureActionListener" + return="void" + abstract="false" + native="false" + synchronized="false" + static="false" + final="false" + deprecated="not deprecated" + visibility="public" +> +<parameter name="listener" type="android.gesture.TouchThroughGestureListener.OnGesturePerformedListener"> +</parameter> +</method> +<method name="isGesturing" + return="boolean" + abstract="false" + native="false" + synchronized="false" + static="false" + final="false" + deprecated="not deprecated" + visibility="public" +> +</method> +<method name="onGesture" + return="void" + abstract="false" + native="false" + synchronized="false" + static="false" + final="false" + deprecated="not deprecated" + visibility="public" +> +<parameter name="overlay" type="android.gesture.GestureOverlayView"> +</parameter> +<parameter name="event" type="android.view.MotionEvent"> +</parameter> +</method> +<method name="onGestureEnded" + return="void" + abstract="false" + native="false" + synchronized="false" + static="false" + final="false" + deprecated="not deprecated" + visibility="public" +> +<parameter name="overlay" type="android.gesture.GestureOverlayView"> +</parameter> +<parameter name="event" type="android.view.MotionEvent"> +</parameter> +</method> +<method name="onGestureStarted" + return="void" + abstract="false" + native="false" + synchronized="false" + static="false" + final="false" + deprecated="not deprecated" + visibility="public" +> +<parameter name="overlay" type="android.gesture.GestureOverlayView"> +</parameter> +<parameter name="event" type="android.view.MotionEvent"> +</parameter> +</method> +<method name="removeOnGestureActionListener" + return="void" + abstract="false" + native="false" + synchronized="false" + static="false" + final="false" + deprecated="not deprecated" + visibility="public" +> +<parameter name="listener" type="android.gesture.TouchThroughGestureListener.OnGesturePerformedListener"> +</parameter> +</method> +<method name="setGestureType" + return="void" + abstract="false" + native="false" + synchronized="false" + static="false" + final="false" + deprecated="not deprecated" + visibility="public" +> +<parameter name="type" type="int"> +</parameter> +</method> +<field name="MULTIPLE_STROKE" + type="int" + transient="false" + volatile="false" + value="1" + static="true" + final="true" + deprecated="not deprecated" + visibility="public" +> +</field> +<field name="SINGLE_STROKE" + type="int" + transient="false" + volatile="false" + value="0" + static="true" + final="true" + deprecated="not deprecated" + visibility="public" +> +</field> +</class> +<interface name="TouchThroughGestureListener.OnGesturePerformedListener" + abstract="true" + static="true" + final="false" + deprecated="not deprecated" + visibility="public" +> +<method name="onGesturePerformed" + return="void" + abstract="true" + native="false" + synchronized="false" + static="false" + final="false" + deprecated="not deprecated" + visibility="public" +> +<parameter name="overlay" type="android.gesture.GestureOverlayView"> +</parameter> +<parameter name="gesture" type="android.gesture.Gesture"> +</parameter> +</method> +</interface> +</package> <package name="android.graphics" > <class name="AvoidXfermode" diff --git a/cmds/bootanimation/Android.mk b/cmds/bootanimation/Android.mk new file mode 100644 index 000000000000..9c94c2ef3cf9 --- /dev/null +++ b/cmds/bootanimation/Android.mk @@ -0,0 +1,30 @@ +LOCAL_PATH:= $(call my-dir) +include $(CLEAR_VARS) + +LOCAL_SRC_FILES:= \ + bootanimation_main.cpp \ + BootAnimation.cpp + +# need "-lrt" on Linux simulator to pick up clock_gettime +ifeq ($(TARGET_SIMULATOR),true) + ifeq ($(HOST_OS),linux) + LOCAL_LDLIBS += -lrt + endif +endif + +LOCAL_SHARED_LIBRARIES := \ + libcutils \ + libutils \ + libui \ + libcorecg \ + libsgl \ + libEGL \ + libGLESv1_CM + +LOCAL_C_INCLUDES := \ + $(call include-path-for, corecg graphics) + +LOCAL_MODULE:= bootanimation + + +include $(BUILD_EXECUTABLE) diff --git a/libs/surfaceflinger/BootAnimation.cpp b/cmds/bootanimation/BootAnimation.cpp index db403857323a..d565dc189d96 100644 --- a/libs/surfaceflinger/BootAnimation.cpp +++ b/cmds/bootanimation/BootAnimation.cpp @@ -22,6 +22,7 @@ #include <fcntl.h> #include <utils/misc.h> +#include <binder/IPCThreadState.h> #include <utils/threads.h> #include <utils/Atomic.h> #include <utils/Errors.h> @@ -49,10 +50,9 @@ namespace android { // --------------------------------------------------------------------------- -BootAnimation::BootAnimation(const sp<ISurfaceComposer>& composer) : - Thread(false) { - mSession = SurfaceComposerClient::clientForConnection( - composer->createConnection()->asBinder()); +BootAnimation::BootAnimation() : Thread(false) +{ + mSession = new SurfaceComposerClient(); } BootAnimation::~BootAnimation() { @@ -131,7 +131,7 @@ status_t BootAnimation::readyToRun() { // create the native surface sp<Surface> s = session()->createSurface(getpid(), 0, dinfo.w, dinfo.h, - PIXEL_FORMAT_RGB_565); + PIXEL_FORMAT_RGB_565, ISurfaceComposer::eGPU); session()->openTransaction(); s->setLayer(0x40000000); session()->closeTransaction(); @@ -144,7 +144,10 @@ status_t BootAnimation::readyToRun() { EGLConfig config; EGLSurface surface; EGLContext context; + EGLDisplay display = eglGetDisplay(EGL_DEFAULT_DISPLAY); + + eglInitialize(display, 0, 0); eglChooseConfig(display, attribs, &config, 1, &numConfigs); mNativeWindowSurface = new EGLNativeWindowSurface(s); @@ -170,17 +173,15 @@ status_t BootAnimation::readyToRun() { return NO_ERROR; } -void BootAnimation::requestExit() { - mBarrier.open(); - Thread::requestExit(); -} - bool BootAnimation::threadLoop() { bool r = android(); eglMakeCurrent(mDisplay, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT); eglDestroyContext(mDisplay, mContext); eglDestroySurface(mDisplay, mSurface); mNativeWindowSurface.clear(); + mFlingerSurface.clear(); + eglTerminate(mDisplay); + IPCThreadState::self()->stopProcess(); return r; } @@ -227,8 +228,10 @@ bool BootAnimation::android() { glBindTexture(GL_TEXTURE_2D, mAndroid[0].name); glDrawTexiOES(xc, yc, 0, mAndroid[0].w, mAndroid[0].h); - eglSwapBuffers(mDisplay, mSurface); - + EGLBoolean res = eglSwapBuffers(mDisplay, mSurface); + if (res == EGL_FALSE) + break; + // 12fps: don't animate too fast to preserve CPU const nsecs_t sleepTime = 83333 - ns2us(systemTime() - now); if (sleepTime > 0) diff --git a/libs/surfaceflinger/BootAnimation.h b/cmds/bootanimation/BootAnimation.h index 3fb6670b3ef4..42e9eed7d3eb 100644 --- a/libs/surfaceflinger/BootAnimation.h +++ b/cmds/bootanimation/BootAnimation.h @@ -29,8 +29,6 @@ #include <EGL/egl.h> #include <GLES/gl.h> -#include "Barrier.h" - class SkBitmap; namespace android { @@ -43,11 +41,10 @@ class EGLNativeWindowSurface; class BootAnimation : public Thread { public: - BootAnimation(const sp<ISurfaceComposer>& composer); + BootAnimation(); virtual ~BootAnimation(); const sp<SurfaceComposerClient>& session() const; - virtual void requestExit(); private: virtual bool threadLoop(); @@ -73,7 +70,6 @@ private: EGLDisplay mSurface; sp<Surface> mFlingerSurface; sp<EGLNativeWindowSurface> mNativeWindowSurface; - Barrier mBarrier; }; // --------------------------------------------------------------------------- diff --git a/cmds/bootanimation/bootanimation_main.cpp b/cmds/bootanimation/bootanimation_main.cpp new file mode 100644 index 000000000000..346f156f97e9 --- /dev/null +++ b/cmds/bootanimation/bootanimation_main.cpp @@ -0,0 +1,52 @@ +/* + * Copyright (C) 2007 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#define LOG_TAG "BootAnimation" + +#include <binder/IPCThreadState.h> +#include <binder/ProcessState.h> +#include <binder/IServiceManager.h> +#include <utils/Log.h> +#include <utils/threads.h> + +#include <ui/ISurfaceComposer.h> + +#if defined(HAVE_PTHREADS) +# include <pthread.h> +# include <sys/resource.h> +#endif + +#include "BootAnimation.h" + +using namespace android; + +// --------------------------------------------------------------------------- + +int main(int argc, char** argv) +{ +#if defined(HAVE_PTHREADS) + setpriority(PRIO_PROCESS, 0, ANDROID_PRIORITY_DISPLAY); +#endif + + sp<ProcessState> proc(ProcessState::self()); + ProcessState::self()->startThreadPool(); + + // create the boot animation object + sp<BootAnimation> boot = new BootAnimation(); + + IPCThreadState::self()->joinThreadPool(); + return 0; +} diff --git a/tests/sketch/src/com/android/gesture/Gesture.java b/core/java/android/gesture/Gesture.java index 44711cac5241..14530a12cefb 100755 --- a/tests/sketch/src/com/android/gesture/Gesture.java +++ b/core/java/android/gesture/Gesture.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package com.android.gesture; +package android.gesture; import android.graphics.Bitmap; import android.graphics.Canvas; @@ -23,10 +23,13 @@ import android.graphics.Path; import android.graphics.RectF; import android.os.Parcel; import android.os.Parcelable; - -import org.xmlpull.v1.XmlSerializer; +import android.util.Log; import java.io.IOException; +import java.io.DataOutputStream; +import java.io.DataInputStream; +import java.io.ByteArrayOutputStream; +import java.io.ByteArrayInputStream; import java.util.ArrayList; /** @@ -149,10 +152,12 @@ public class Gesture implements Parcelable { * @return the bitmap */ public Bitmap toBitmap(int width, int height, int edge, int numSample, int color) { - Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888); - Canvas canvas = new Canvas(bitmap); + final Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888); + final Canvas canvas = new Canvas(bitmap); + canvas.translate(edge, edge); - Paint paint = new Paint(); + + final Paint paint = new Paint(); paint.setAntiAlias(BITMAP_RENDERING_ANTIALIAS); paint.setDither(BITMAP_RENDERING_DITHER); paint.setColor(color); @@ -182,10 +187,12 @@ public class Gesture implements Parcelable { * @return the bitmap */ public Bitmap toBitmap(int width, int height, int edge, int color) { - Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888); - Canvas canvas = new Canvas(bitmap); + final Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888); + final Canvas canvas = new Canvas(bitmap); + canvas.translate(edge, edge); - Paint paint = new Paint(); + + final Paint paint = new Paint(); paint.setAntiAlias(BITMAP_RENDERING_ANTIALIAS); paint.setDither(BITMAP_RENDERING_DITHER); paint.setColor(color); @@ -193,78 +200,66 @@ public class Gesture implements Parcelable { paint.setStrokeJoin(Paint.Join.ROUND); paint.setStrokeCap(Paint.Cap.ROUND); paint.setStrokeWidth(BITMAP_RENDERING_WIDTH); - ArrayList<GestureStroke> strokes = mStrokes; - int count = strokes.size(); + + final ArrayList<GestureStroke> strokes = mStrokes; + final int count = strokes.size(); + for (int i = 0; i < count; i++) { - GestureStroke stroke = strokes.get(i); - stroke.draw(canvas, paint); + strokes.get(i).draw(canvas, paint); } return bitmap; } - /** - * Save the gesture as XML - * - * @param namespace - * @param serializer - * @throws IOException - */ - void toXML(String namespace, XmlSerializer serializer) throws IOException { - serializer.startTag(namespace, GestureConstants.XML_TAG_GESTURE); - serializer.attribute(namespace, GestureConstants.XML_TAG_ID, Long.toString(mGestureID)); - ArrayList<GestureStroke> strokes = mStrokes; - int count = strokes.size(); + void serialize(DataOutputStream out) throws IOException { + final ArrayList<GestureStroke> strokes = mStrokes; + final int count = strokes.size(); + + // Write gesture ID + out.writeLong(mGestureID); + // Write number of strokes + out.writeInt(count); + for (int i = 0; i < count; i++) { - GestureStroke stroke = strokes.get(i); - stroke.toXML(namespace, serializer); + strokes.get(i).serialize(out); } - serializer.endTag(namespace, GestureConstants.XML_TAG_GESTURE); } - /** - * Create the gesture from a string - * - * @param str - */ - public void createFromString(String str) { - int startIndex = 0; - int endIndex; - while ((endIndex = - str.indexOf(GestureConstants.STRING_GESTURE_DELIIMITER, startIndex + 1)) != -1) { - String token = str.substring(startIndex, endIndex); - if (startIndex > 0) { // stroke tokens - addStroke(GestureStroke.createFromString(token)); - } else { // id token - mGestureID = Long.parseLong(token); - } - startIndex = endIndex + 1; - } - } + static Gesture deserialize(DataInputStream in) throws IOException { + final Gesture gesture = new Gesture(); + + // Gesture ID + gesture.mGestureID = in.readLong(); + // Number of strokes + final int count = in.readInt(); - /** - * Convert the gesture to string - */ - @Override - public String toString() { - StringBuilder str = new StringBuilder(); - str.append(mGestureID); - ArrayList<GestureStroke> strokes = mStrokes; - int count = strokes.size(); for (int i = 0; i < count; i++) { - GestureStroke stroke = strokes.get(i); - str.append(GestureConstants.STRING_GESTURE_DELIIMITER); - str.append(stroke.toString()); + gesture.addStroke(GestureStroke.deserialize(in)); } - return str.toString(); + return gesture; } public static final Parcelable.Creator<Gesture> CREATOR = new Parcelable.Creator<Gesture>() { public Gesture createFromParcel(Parcel in) { - String str = in.readString(); - Gesture gesture = new Gesture(); - gesture.createFromString(str); + Gesture gesture = null; + final long gestureID = in.readLong(); + + final DataInputStream inStream = new DataInputStream( + new ByteArrayInputStream(in.createByteArray())); + + try { + gesture = deserialize(inStream); + } catch (IOException e) { + Log.e(GestureConstants.LOG_TAG, "Error reading Gesture from parcel:", e); + } finally { + GestureUtilities.closeStream(inStream); + } + + if (gesture != null) { + gesture.mGestureID = gestureID; + } + return gesture; } @@ -273,35 +268,31 @@ public class Gesture implements Parcelable { } }; - /** - * Build a gesture from a byte array - * - * @param bytes - * @return the gesture - */ - static Gesture buildFromArray(byte[] bytes) { - String str = new String(bytes); - Gesture gesture = new Gesture(); - gesture.createFromString(str); - return gesture; - } - - /** - * Save a gesture to a byte array - * - * @param stroke - * @return the byte array - */ - static byte[] saveToArray(Gesture stroke) { - String str = stroke.toString(); - return str.getBytes(); - } - public void writeToParcel(Parcel out, int flags) { - out.writeString(toString()); + out.writeLong(mGestureID); + + boolean result = false; + final ByteArrayOutputStream byteStream = + new ByteArrayOutputStream(GestureConstants.IO_BUFFER_SIZE); + final DataOutputStream outStream = new DataOutputStream(byteStream); + + try { + serialize(outStream); + result = true; + } catch (IOException e) { + Log.e(GestureConstants.LOG_TAG, "Error writing Gesture to parcel:", e); + } finally { + GestureUtilities.closeStream(outStream); + GestureUtilities.closeStream(byteStream); + } + + if (result) { + out.writeByteArray(byteStream.toByteArray()); + } } public int describeContents() { - return CONTENTS_FILE_DESCRIPTOR; + return 0; } } + diff --git a/tests/sketch/src/com/android/gesture/GestureActionListener.java b/core/java/android/gesture/GestureConstants.java index c9c523299f41..230db0c00c50 100644 --- a/tests/sketch/src/com/android/gesture/GestureActionListener.java +++ b/core/java/android/gesture/GestureConstants.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2008-2009 The Android Open Source Project + * Copyright (C) 2009 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,8 +14,13 @@ * limitations under the License. */ -package com.android.gesture; +package android.gesture; -public interface GestureActionListener { - public void onGesturePerformed(GestureOverlay overlay, Gesture gesture); +interface GestureConstants { + static final int STROKE_STRING_BUFFER_SIZE = 1024; + static final int STROKE_POINT_BUFFER_SIZE = 100; // number of points + + static final int IO_BUFFER_SIZE = 32 * 1024; // 32K + + static final String LOG_TAG = "Gestures"; } diff --git a/tests/sketch/src/com/android/gesture/GestureLibrary.java b/core/java/android/gesture/GestureLibrary.java index 915b840d0ec8..1cf192ec3446 100644 --- a/tests/sketch/src/com/android/gesture/GestureLibrary.java +++ b/core/java/android/gesture/GestureLibrary.java @@ -14,18 +14,10 @@ * limitations under the License. */ -package com.android.gesture; +package android.gesture; -import android.util.Config; import android.util.Log; -import android.util.Xml; -import android.util.Xml.Encoding; - -import org.xml.sax.Attributes; -import org.xml.sax.ContentHandler; -import org.xml.sax.Locator; -import org.xml.sax.SAXException; -import org.xmlpull.v1.XmlSerializer; +import android.os.SystemClock; import java.io.BufferedInputStream; import java.io.BufferedOutputStream; @@ -33,21 +25,41 @@ import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.IOException; -import java.io.PrintWriter; +import java.io.DataOutputStream; +import java.io.DataInputStream; import java.util.ArrayList; import java.util.HashMap; import java.util.Set; +import java.util.Map; -import static com.android.gesture.GestureConstants.LOG_TAG; +import static android.gesture.GestureConstants.LOG_TAG; /** * GestureLibrary maintains gesture examples and makes predictions on a new * gesture */ +// +// File format for GestureLibrary: +// +// Nb. bytes Java type Description +// ----------------------------------- +// Header +// 2 bytes short File format version number +// 4 bytes int Number of entries +// Entry +// X bytes UTF String Entry name +// 4 bytes int Number of gestures +// Gesture +// 8 bytes long Gesture ID +// 4 bytes int Number of strokes +// Stroke +// 4 bytes int Number of points +// Point +// 4 bytes float X coordinate of the point +// 4 bytes float Y coordinate of the point +// 8 bytes long Time stamp +// public class GestureLibrary { - - private static final String NAMESPACE = ""; - public static final int SEQUENCE_INVARIANT = 1; // when SEQUENCE_SENSITIVE is used, only single stroke gestures are currently allowed public static final int SEQUENCE_SENSITIVE = 2; @@ -56,12 +68,16 @@ public class GestureLibrary { public static final int ORIENTATION_INVARIANT = 1; public static final int ORIENTATION_SENSITIVE = 2; + private static final short FILE_FORMAT_VERSION = 1; + + private static final boolean PROFILE_LOADING_SAVING = false; + private int mSequenceType = SEQUENCE_SENSITIVE; private int mOrientationStyle = ORIENTATION_SENSITIVE; private final String mGestureFileName; - private final HashMap<String, ArrayList<Gesture>> mEntryName2gestures = + private final HashMap<String, ArrayList<Gesture>> mNamedGestures = new HashMap<String, ArrayList<Gesture>>(); private Learner mClassifier; @@ -90,11 +106,17 @@ public class GestureLibrary { return mOrientationStyle; } - public void setGestureType(int type) { + /** + * @param type SEQUENCE_INVARIANT or SEQUENCE_SENSITIVE + */ + public void setSequenceType(int type) { mSequenceType = type; } - public int getGestureType() { + /** + * @return SEQUENCE_INVARIANT or SEQUENCE_SENSITIVE + */ + public int getSequenceType() { return mSequenceType; } @@ -104,7 +126,7 @@ public class GestureLibrary { * @return a set of strings */ public Set<String> getGestureEntries() { - return mEntryName2gestures.keySet(); + return mNamedGestures.keySet(); } /** @@ -128,10 +150,10 @@ public class GestureLibrary { if (entryName == null || entryName.length() == 0) { return; } - ArrayList<Gesture> gestures = mEntryName2gestures.get(entryName); + ArrayList<Gesture> gestures = mNamedGestures.get(entryName); if (gestures == null) { gestures = new ArrayList<Gesture>(); - mEntryName2gestures.put(entryName, gestures); + mNamedGestures.put(entryName, gestures); } gestures.add(gesture); mClassifier.addInstance(Instance.createInstance(mSequenceType, gesture, entryName)); @@ -146,7 +168,7 @@ public class GestureLibrary { * @param gesture */ public void removeGesture(String entryName, Gesture gesture) { - ArrayList<Gesture> gestures = mEntryName2gestures.get(entryName); + ArrayList<Gesture> gestures = mNamedGestures.get(entryName); if (gestures == null) { return; } @@ -155,7 +177,7 @@ public class GestureLibrary { // if there are no more samples, remove the entry automatically if (gestures.isEmpty()) { - mEntryName2gestures.remove(entryName); + mNamedGestures.remove(entryName); } mClassifier.removeInstance(gesture.getID()); @@ -168,8 +190,8 @@ public class GestureLibrary { * * @param entryName the entry name */ - public void removeEntireEntry(String entryName) { - mEntryName2gestures.remove(entryName); + public void removeEntry(String entryName) { + mNamedGestures.remove(entryName); mClassifier.removeInstances(entryName); mChanged = true; } @@ -181,7 +203,7 @@ public class GestureLibrary { * @return the list of gestures that is under this name */ public ArrayList<Gesture> getGestures(String entryName) { - ArrayList<Gesture> gestures = mEntryName2gestures.get(entryName); + ArrayList<Gesture> gestures = mNamedGestures.get(entryName); if (gestures != null) { return new ArrayList<Gesture>(gestures); } else { @@ -197,8 +219,8 @@ public class GestureLibrary { return true; } - boolean result= false; - PrintWriter writer = null; + boolean result = false; + DataOutputStream out = null; try { File file = new File(mGestureFileName); @@ -208,40 +230,48 @@ public class GestureLibrary { } } - writer = new PrintWriter(new BufferedOutputStream(new FileOutputStream( - mGestureFileName), GestureConstants.IO_BUFFER_SIZE)); + long start; + if (PROFILE_LOADING_SAVING) { + start = SystemClock.elapsedRealtime(); + } + + final HashMap<String, ArrayList<Gesture>> maps = mNamedGestures; - final XmlSerializer serializer = Xml.newSerializer(); - serializer.setOutput(writer); - serializer.startDocument(Encoding.ISO_8859_1.name(), null); - serializer.startTag(NAMESPACE, GestureConstants.XML_TAG_LIBRARY); + out = new DataOutputStream(new BufferedOutputStream(new FileOutputStream(file), + GestureConstants.IO_BUFFER_SIZE)); + // Write version number + out.writeShort(FILE_FORMAT_VERSION); + // Write number of entries + out.writeInt(maps.size()); - final HashMap<String, ArrayList<Gesture>> maps = mEntryName2gestures; + for (Map.Entry<String, ArrayList<Gesture>> entry : maps.entrySet()) { + final String key = entry.getKey(); + final ArrayList<Gesture> examples = entry.getValue(); + final int count = examples.size(); + + // Write entry name + out.writeUTF(key); + // Write number of examples for this entry + out.writeInt(count); - for (String key : maps.keySet()) { - ArrayList<Gesture> examples = maps.get(key); - // save an entry - serializer.startTag(NAMESPACE, GestureConstants.XML_TAG_ENTRY); - serializer.attribute(NAMESPACE, GestureConstants.XML_TAG_NAME, key); - int count = examples.size(); for (int i = 0; i < count; i++) { - Gesture gesture = examples.get(i); - // save each gesture in the entry - gesture.toXML(NAMESPACE, serializer); + examples.get(i).serialize(out); } - serializer.endTag(NAMESPACE, GestureConstants.XML_TAG_ENTRY); } - serializer.endTag(NAMESPACE, GestureConstants.XML_TAG_LIBRARY); - serializer.endDocument(); - serializer.flush(); + out.flush(); + + if (PROFILE_LOADING_SAVING) { + long end = SystemClock.elapsedRealtime(); + Log.d(LOG_TAG, "Saving gestures library = " + (end - start) + " ms"); + } mChanged = false; result = true; } catch (IOException ex) { Log.d(LOG_TAG, "Failed to save gestures:", ex); } finally { - GestureUtilities.closeStream(writer); + GestureUtilities.closeStream(out); } return result; @@ -255,17 +285,30 @@ public class GestureLibrary { final File file = new File(mGestureFileName); if (file.exists()) { - BufferedInputStream in = null; + DataInputStream in = null; try { - if (Config.DEBUG) { - Log.v(LOG_TAG, "Load from " + mGestureFileName); + in = new DataInputStream(new BufferedInputStream( + new FileInputStream(mGestureFileName), GestureConstants.IO_BUFFER_SIZE)); + + long start; + if (PROFILE_LOADING_SAVING) { + start = SystemClock.elapsedRealtime(); + } + + // Read file format version number + final short versionNumber = in.readShort(); + switch (versionNumber) { + case 1: + readFormatV1(in); + break; } - in = new BufferedInputStream(new FileInputStream( - mGestureFileName), GestureConstants.IO_BUFFER_SIZE); - Xml.parse(in, Encoding.ISO_8859_1, new CompactInkHandler()); + + if (PROFILE_LOADING_SAVING) { + long end = SystemClock.elapsedRealtime(); + Log.d(LOG_TAG, "Loading gestures library = " + (end - start) + " ms"); + } + result = true; - } catch (SAXException ex) { - Log.d(LOG_TAG, "Failed to load gestures:", ex); } catch (IOException ex) { Log.d(LOG_TAG, "Failed to load gestures:", ex); } finally { @@ -276,69 +319,28 @@ public class GestureLibrary { return result; } - private class CompactInkHandler implements ContentHandler { - final StringBuilder mBuffer = new StringBuilder(GestureConstants.STROKE_STRING_BUFFER_SIZE); - - String mEntryName; - - Gesture mCurrentGesture = null; - ArrayList<Gesture> mGestures; - - CompactInkHandler() { - } - - public void characters(char[] ch, int start, int length) { - mBuffer.append(ch, start, length); - } - - public void endDocument() { - } - - public void endElement(String uri, String localName, String qName) { - if (localName.equals(GestureConstants.XML_TAG_ENTRY)) { - mEntryName2gestures.put(mEntryName, mGestures); - mGestures = null; - } else if (localName.equals(GestureConstants.XML_TAG_GESTURE)) { - mGestures.add(mCurrentGesture); - mClassifier.addInstance(Instance.createInstance(mSequenceType, - mCurrentGesture, mEntryName)); - mCurrentGesture = null; - } else if (localName.equals(GestureConstants.XML_TAG_STROKE)) { - mCurrentGesture.addStroke(GestureStroke.createFromString(mBuffer.toString())); - mBuffer.setLength(0); + private void readFormatV1(DataInputStream in) throws IOException { + final Learner classifier = mClassifier; + final HashMap<String, ArrayList<Gesture>> namedGestures = mNamedGestures; + namedGestures.clear(); + + // Number of entries in the library + final int entriesCount = in.readInt(); + + for (int i = 0; i < entriesCount; i++) { + // Entry name + final String name = in.readUTF(); + // Number of gestures + final int gestureCount = in.readInt(); + + final ArrayList<Gesture> gestures = new ArrayList<Gesture>(gestureCount); + for (int j = 0; j < gestureCount; j++) { + final Gesture gesture = Gesture.deserialize(in); + gestures.add(gesture); + classifier.addInstance(Instance.createInstance(mSequenceType, gesture, name)); } - } - - public void endPrefixMapping(String prefix) { - } - - public void ignorableWhitespace(char[] ch, int start, int length) { - } - - public void processingInstruction(String target, String data) { - } - - public void setDocumentLocator(Locator locator) { - } - - public void skippedEntity(String name) { - } - - public void startDocument() { - } - - public void startElement(String uri, String localName, String qName, Attributes attributes) { - if (localName.equals(GestureConstants.XML_TAG_ENTRY)) { - mGestures = new ArrayList<Gesture>(); - mEntryName = attributes.getValue(NAMESPACE, GestureConstants.XML_TAG_NAME); - } else if (localName.equals(GestureConstants.XML_TAG_GESTURE)) { - mCurrentGesture = new Gesture(); - mCurrentGesture.setID(Long.parseLong(attributes.getValue(NAMESPACE, - GestureConstants.XML_TAG_ID))); - } - } - public void startPrefixMapping(String prefix, String uri) { + namedGestures.put(name, gestures); } } } diff --git a/tests/sketch/src/com/android/gesture/GestureOverlay.java b/core/java/android/gesture/GestureOverlayView.java index 454cecbf2fa2..bffd12e636f4 100755 --- a/tests/sketch/src/com/android/gesture/GestureOverlay.java +++ b/core/java/android/gesture/GestureOverlayView.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package com.android.gesture; +package android.gesture; import android.content.Context; import android.graphics.Bitmap; @@ -23,6 +23,7 @@ import android.graphics.Canvas; import android.graphics.Paint; import android.graphics.Path; import android.graphics.Rect; +import android.graphics.Color; import android.os.Handler; import android.util.AttributeSet; import android.view.MotionEvent; @@ -35,7 +36,7 @@ import java.util.ArrayList; * widgets. The view can also be opaque. */ -public class GestureOverlay extends View { +public class GestureOverlayView extends View { static final float TOUCH_TOLERANCE = 3; // TODO: Move all these values into XML attributes @@ -52,20 +53,22 @@ public class GestureOverlay extends View { private static final boolean DITHER_FLAG = true; public static final int DEFAULT_GESTURE_COLOR = 0xFFFFFF00; + public static final int DEFAULT_UNCERTAIN_GESTURE_COLOR = Color.argb(60, 255, 255, 0); private static final int REFRESH_RANGE = 10; private static final BlurMaskFilter BLUR_MASK_FILTER = new BlurMaskFilter(1, BlurMaskFilter.Blur.NORMAL); - - // double buffering private Paint mGesturePaint; private final Paint mBitmapPaint = new Paint(Paint.DITHER_FLAG); private Bitmap mBitmap; // with transparent background private Canvas mBitmapCanvas; + private int mCertainGestureColor = DEFAULT_GESTURE_COLOR; + private int mUncertainGestureColor = DEFAULT_UNCERTAIN_GESTURE_COLOR; + // for rendering immediate ink feedback private Rect mInvalidRect = new Rect(); @@ -81,7 +84,7 @@ public class GestureOverlay extends View { private Gesture mCurrentGesture = null; // TODO: Make this a list of WeakReferences - private final ArrayList<GestureListener> mGestureListeners = new ArrayList<GestureListener>(); + private final ArrayList<OnGestureListener> mOnGestureListeners = new ArrayList<OnGestureListener>(); private ArrayList<GesturePoint> mPointBuffer = null; // fading out effect @@ -107,12 +110,12 @@ public class GestureOverlay extends View { } }; - public GestureOverlay(Context context) { + public GestureOverlayView(Context context) { super(context); init(); } - public GestureOverlay(Context context, AttributeSet attrs) { + public GestureOverlayView(Context context, AttributeSet attrs) { super(context, attrs); init(); } @@ -130,7 +133,7 @@ public class GestureOverlay extends View { * * @param color */ - public void setGestureColor(int color) { + public void setGestureDrawingColor(int color) { mGesturePaint.setColor(color); if (mCurrentGesture != null) { mBitmap.eraseColor(TRANSPARENT_BACKGROUND); @@ -138,6 +141,22 @@ public class GestureOverlay extends View { } } + public void setGestureColor(int color) { + mCertainGestureColor = color; + } + + public void setUncertainGestureColor(int color) { + mUncertainGestureColor = color; + } + + public int getUncertainGestureColor() { + return mUncertainGestureColor; + } + + public int getGestureColor() { + return mCertainGestureColor; + } + /** * Set the gesture to be shown in the view * @@ -199,12 +218,12 @@ public class GestureOverlay extends View { } } - public void addGestureListener(GestureListener listener) { - mGestureListeners.add(listener); + public void addOnGestureListener(OnGestureListener listener) { + mOnGestureListeners.add(listener); } - public void removeGestureListener(GestureListener listener) { - mGestureListeners.remove(listener); + public void removeOnGestureListener(OnGestureListener listener) { + mOnGestureListeners.remove(listener); } @Override @@ -281,11 +300,11 @@ public class GestureOverlay extends View { private Rect touchStart(MotionEvent event) { // pass the event to handlers - final ArrayList<GestureListener> listeners = mGestureListeners; + final ArrayList<OnGestureListener> listeners = mOnGestureListeners; final int count = listeners.size(); for (int i = 0; i < count; i++) { - GestureListener listener = listeners.get(i); - listener.onStartGesture(this, event); + OnGestureListener listener = listeners.get(i); + listener.onGestureStarted(this, event); } // if there is fading out going on, stop it. @@ -358,7 +377,7 @@ public class GestureOverlay extends View { mPointBuffer.add(new GesturePoint(x, y, event.getEventTime())); // pass the event to handlers - final ArrayList<GestureListener> listeners = mGestureListeners; + final ArrayList<OnGestureListener> listeners = mOnGestureListeners; final int count = listeners.size(); for (int i = 0; i < count; i++) { listeners.get(i).onGesture(this, event); @@ -377,14 +396,24 @@ public class GestureOverlay extends View { mGesturePaint.setMaskFilter(null); // pass the event to handlers - final ArrayList<GestureListener> listeners = mGestureListeners; + final ArrayList<OnGestureListener> listeners = mOnGestureListeners; final int count = listeners.size(); for (int i = 0; i < count; i++) { - listeners.get(i).onFinishGesture(this, event); + listeners.get(i).onGestureEnded(this, event); } mPath = null; mPointBuffer = null; } + /** + * An interface for processing gesture events + */ + public static interface OnGestureListener { + public void onGestureStarted(GestureOverlayView overlay, MotionEvent event); + + public void onGesture(GestureOverlayView overlay, MotionEvent event); + + public void onGestureEnded(GestureOverlayView overlay, MotionEvent event); + } } diff --git a/tests/sketch/src/com/android/gesture/GesturePoint.java b/core/java/android/gesture/GesturePoint.java index 81e59a492352..3698011fc7fc 100644 --- a/tests/sketch/src/com/android/gesture/GesturePoint.java +++ b/core/java/android/gesture/GesturePoint.java @@ -14,7 +14,10 @@ * limitations under the License. */ -package com.android.gesture; +package android.gesture; + +import java.io.DataInputStream; +import java.io.IOException; /** * A timed point of a gesture stroke @@ -31,4 +34,13 @@ public class GesturePoint { this.y = y; timestamp = t; } + + static GesturePoint deserialize(DataInputStream in) throws IOException { + // Read X and Y + final float x = in.readFloat(); + final float y = in.readFloat(); + // Read timestamp + final long timeStamp = in.readLong(); + return new GesturePoint(x, y, timeStamp); + } } diff --git a/tests/sketch/src/com/android/gesture/GestureStroke.java b/core/java/android/gesture/GestureStroke.java index c2ebc1733241..5160a76df7d1 100644 --- a/tests/sketch/src/com/android/gesture/GestureStroke.java +++ b/core/java/android/gesture/GestureStroke.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package com.android.gesture; +package android.gesture; import android.graphics.Canvas; import android.graphics.Matrix; @@ -22,9 +22,9 @@ import android.graphics.Paint; import android.graphics.Path; import android.graphics.RectF; -import org.xmlpull.v1.XmlSerializer; - import java.io.IOException; +import java.io.DataOutputStream; +import java.io.DataInputStream; import java.util.ArrayList; /** @@ -126,16 +126,16 @@ public class GestureStroke { * @param width the width of the bounding box of the target path * @param height the height of the bounding box of the target path * @param numSample the number of points needed + * * @return the path */ public Path toPath(float width, float height, int numSample) { final float[] pts = GestureUtilities.temporalSampling(this, numSample); final RectF rect = boundingBox; - final float scale = height / rect.height(); final Matrix matrix = new Matrix(); matrix.setTranslate(-rect.left, -rect.top); - matrix.postScale(scale, scale); + matrix.postScale(width / rect.width(), height / rect.height()); matrix.mapPoints(pts); float mX = 0; @@ -156,7 +156,8 @@ public class GestureStroke { } else { float dx = Math.abs(x - mX); float dy = Math.abs(y - mY); - if (dx >= GestureOverlay.TOUCH_TOLERANCE || dy >= GestureOverlay.TOUCH_TOLERANCE) { + if (dx >= GestureOverlayView.TOUCH_TOLERANCE || + dy >= GestureOverlayView.TOUCH_TOLERANCE) { path.quadTo(mX, mY, (x + mX) / 2, (y + mY) / 2); mX = x; mY = y; @@ -167,82 +168,41 @@ public class GestureStroke { return path; } - /** - * Save the gesture stroke as XML - * - * @param namespace - * @param serializer - * @throws IOException - */ - void toXML(String namespace, XmlSerializer serializer) throws IOException { - serializer.startTag(namespace, GestureConstants.XML_TAG_STROKE); - serializer.text(toString()); - serializer.endTag(namespace, GestureConstants.XML_TAG_STROKE); - } - - /** - * Create a gesture stroke from a string - * - * @param str - * @return the gesture stroke - */ - public static GestureStroke createFromString(String str) { - final ArrayList<GesturePoint> points = new ArrayList<GesturePoint>( - GestureConstants.STROKE_POINT_BUFFER_SIZE); - - int endIndex; - int startIndex = 0; - - while ((endIndex = - str.indexOf(GestureConstants.STRING_STROKE_DELIIMITER, startIndex + 1)) != -1) { - - // parse x - String token = str.substring(startIndex, endIndex); - float x = Float.parseFloat(token); - startIndex = endIndex + 1; - - // parse y - endIndex = str.indexOf(GestureConstants.STRING_STROKE_DELIIMITER, startIndex + 1); - token = str.substring(startIndex, endIndex); - float y = Float.parseFloat(token); - startIndex = endIndex + 1; - - // parse t - endIndex = str.indexOf(GestureConstants.STRING_STROKE_DELIIMITER, startIndex + 1); - token = str.substring(startIndex, endIndex); - long time = Long.parseLong(token); - startIndex = endIndex + 1; - - points.add(new GesturePoint(x, y, time)); - } - - return new GestureStroke(points); - } - - /** - * Convert the stroke to string - */ - @Override - public String toString() { - final StringBuilder str = new StringBuilder(GestureConstants.STROKE_STRING_BUFFER_SIZE); + void serialize(DataOutputStream out) throws IOException { final float[] pts = points; final long[] times = timestamps; final int count = points.length; + // Write number of points + out.writeInt(count / 2); + for (int i = 0; i < count; i += 2) { - str.append(pts[i]).append(GestureConstants.STRING_STROKE_DELIIMITER); - str.append(pts[i + 1]).append(GestureConstants.STRING_STROKE_DELIIMITER); - str.append(times[i / 2]).append(GestureConstants.STRING_STROKE_DELIIMITER); + // Write X + out.writeFloat(pts[i]); + // Write Y + out.writeFloat(pts[i + 1]); + // Write timestamp + out.writeLong(times[i / 2]); } - - return str.toString(); } + static GestureStroke deserialize(DataInputStream in) throws IOException { + // Number of points + final int count = in.readInt(); + + final ArrayList<GesturePoint> points = new ArrayList<GesturePoint>(count); + for (int i = 0; i < count; i++) { + points.add(GesturePoint.deserialize(in)); + } + + return new GestureStroke(points); + } + /** - * Invalidate the cached path that is used for rendering the stroke + * Invalidate the cached path that is used to render the stroke */ - public void invalidate() { - mCachedPath = null; + public void clearPath() { + if (mCachedPath != null) mCachedPath.rewind(); } /** diff --git a/tests/sketch/src/com/android/gesture/GestureUtilities.java b/core/java/android/gesture/GestureUtilities.java index 92de9874aca3..e47856c1a861 100755 --- a/tests/sketch/src/com/android/gesture/GestureUtilities.java +++ b/core/java/android/gesture/GestureUtilities.java @@ -14,17 +14,18 @@ * limitations under the License. */ -package com.android.gesture; +package android.gesture; import android.graphics.RectF; import android.graphics.Matrix; +import android.util.Log; import java.util.ArrayList; import java.util.Arrays; import java.io.Closeable; import java.io.IOException; -import static com.android.gesture.GestureConstants.*; +import static android.gesture.GestureConstants.*; final class GestureUtilities { private static final int TEMPORAL_SAMPLING_RATE = 16; @@ -42,7 +43,7 @@ final class GestureUtilities { try { stream.close(); } catch (IOException e) { - android.util.Log.e(LOG_TAG, "Could not close stream", e); + Log.e(LOG_TAG, "Could not close stream", e); } } } @@ -56,24 +57,25 @@ final class GestureUtilities { float sx = targetPatchSize / rect.width(); float sy = targetPatchSize / rect.height(); float scale = sx < sy ? sx : sy; - android.graphics.Matrix trans = new android.graphics.Matrix(); + + Matrix trans = new Matrix(); trans.setScale(scale, scale); - android.graphics.Matrix translate1 = new android.graphics.Matrix(); - translate1.setTranslate(-rect.centerX(), -rect.centerY()); - trans.preConcat(translate1); - android.graphics.Matrix translate2 = new android.graphics.Matrix(); - translate2.setTranslate(targetPatchSize / 2, targetPatchSize / 2); - trans.postConcat(translate2); - - ArrayList<GestureStroke> strokes = gesture.getStrokes(); - int count = strokes.size(); + trans.preTranslate(-rect.centerX(), -rect.centerY()); + trans.postTranslate(targetPatchSize / 2, targetPatchSize / 2); + + final ArrayList<GestureStroke> strokes = gesture.getStrokes(); + final int count = strokes.size(); + int size; float xpos; float ypos; + for (int index = 0; index < count; index++) { - GestureStroke stroke = strokes.get(index); + final GestureStroke stroke = strokes.get(index); size = stroke.points.length; - float[] pts = new float[size]; + + final float[] pts = new float[size]; + trans.mapPoints(pts, 0, stroke.points, 0, size / 2); float segmentEndX = -1; float segmentEndY = -1; diff --git a/tests/sketch/src/com/android/gesture/Instance.java b/core/java/android/gesture/Instance.java index b2e030e75c89..7922faba3f98 100755 --- a/tests/sketch/src/com/android/gesture/Instance.java +++ b/core/java/android/gesture/Instance.java @@ -14,7 +14,9 @@ * limitations under the License. */ -package com.android.gesture; +package android.gesture; + +import android.graphics.Matrix; /** * An instance represents a sample if the label is available or a query if the @@ -47,10 +49,12 @@ class Instance { private void normalize() { float[] sample = vector; float sum = 0; + int size = sample.length; for (int i = 0; i < size; i++) { sum += sample[i] * sample[i]; } + float magnitude = (float) Math.sqrt(sum); for (int i = 0; i < size; i++) { sample[i] /= magnitude; @@ -100,12 +104,11 @@ class Instance { } } - android.graphics.Matrix m = new android.graphics.Matrix(); + Matrix m = new Matrix(); m.setTranslate(-center[0], -center[1]); - android.graphics.Matrix rotation = new android.graphics.Matrix(); - rotation.setRotate(adjustment); - m.postConcat(rotation); + m.postRotate(adjustment); m.mapPoints(pts); + return pts; } diff --git a/tests/sketch/src/com/android/gesture/InstanceLearner.java b/core/java/android/gesture/InstanceLearner.java index 4495256eb80b..1739cdcbe915 100644 --- a/tests/sketch/src/com/android/gesture/InstanceLearner.java +++ b/core/java/android/gesture/InstanceLearner.java @@ -14,10 +14,11 @@ * limitations under the License. */ -package com.android.gesture; +package android.gesture; import android.util.Config; import android.util.Log; +import static android.gesture.GestureConstants.*; import java.util.ArrayList; import java.util.Collections; @@ -30,9 +31,6 @@ import java.util.TreeMap; */ class InstanceLearner extends Learner { - - private static final String LOGTAG = "InstanceLearner"; - @Override ArrayList<Prediction> classify(int gestureType, float[] vector) { ArrayList<Prediction> predictions = new ArrayList<Prediction>(); @@ -63,19 +61,15 @@ class InstanceLearner extends Learner { } double sum = 0; - Iterator<String> lableIterator = label2score.keySet().iterator(); - while (lableIterator.hasNext()) { - String name = lableIterator.next(); + for (String name : label2score.keySet()) { double score = label2score.get(name); sum += score; predictions.add(new Prediction(name, score)); } // normalize - Iterator<Prediction> predictionIterator = predictions.iterator(); - while (predictionIterator.hasNext()) { - Prediction name = predictionIterator.next(); - name.score /= sum; + for (Prediction prediction : predictions) { + prediction.score /= sum; } Collections.sort(predictions, new Comparator<Prediction>() { @@ -92,14 +86,6 @@ class InstanceLearner extends Learner { } }); - if (Config.DEBUG) { - predictionIterator = predictions.iterator(); - while (predictionIterator.hasNext()) { - Prediction name = predictionIterator.next(); - Log.v(LOGTAG, "prediction [" + name.name + " = " + name.score + "]"); - } - } - return predictions; } } diff --git a/tests/sketch/src/com/android/gesture/Learner.java b/core/java/android/gesture/Learner.java index 15b20536feab..feacde5f9736 100755 --- a/tests/sketch/src/com/android/gesture/Learner.java +++ b/core/java/android/gesture/Learner.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package com.android.gesture; +package android.gesture; import java.util.ArrayList; diff --git a/tests/sketch/src/com/android/gesture/LetterRecognizer.java b/core/java/android/gesture/LetterRecognizer.java index 086aedf1db2f..44767469bfb1 100644 --- a/tests/sketch/src/com/android/gesture/LetterRecognizer.java +++ b/core/java/android/gesture/LetterRecognizer.java @@ -14,14 +14,13 @@ * limitations under the License. */ -package com.android.gesture; +package android.gesture; import android.content.Context; import android.content.res.Resources; import android.util.Log; import java.io.BufferedInputStream; -import java.io.BufferedOutputStream; import java.io.DataInputStream; import java.io.IOException; import java.util.ArrayList; @@ -29,10 +28,13 @@ import java.util.Collections; import java.util.Comparator; import java.util.HashMap; +import static android.gesture.GestureConstants.LOG_TAG; + public class LetterRecognizer { - private static final String LOG_TAG = "LetterRecognizer"; + public final static int RECOGNIZER_LATIN_LOWERCASE = 0; + static final String GESTURE_FILE_NAME = "letters.gestures"; - public final static int LATIN_LOWERCASE = 0; + private final static int ADJUST_RANGE = 3; private SigmoidUnit[] mHiddenLayer; private SigmoidUnit[] mOutputLayer; @@ -41,59 +43,57 @@ public class LetterRecognizer { private final int mPatchSize; - static final String GESTURE_FILE_NAME = "letters.xml"; + private GestureLibrary mGestureLibrary; - private GestureLibrary mGestureLibrary; - private final static int ADJUST_RANGE = 3; - private static class SigmoidUnit { final float[] mWeights; + private boolean mComputed; + private float mResult; + SigmoidUnit(float[] weights) { mWeights = weights; } private float compute(float[] inputs) { - float sum = 0; + if (!mComputed) { + float sum = 0; - final int count = inputs.length; - final float[] weights = mWeights; + final int count = inputs.length; + final float[] weights = mWeights; - for (int i = 0; i < count; i++) { - sum += inputs[i] * weights[i]; - } - sum += weights[weights.length - 1]; + for (int i = 0; i < count; i++) { + sum += inputs[i] * weights[i]; + } + sum += weights[weights.length - 1]; - return 1.0f / (float) (1 + Math.exp(-sum)); + mResult = 1.0f / (float) (1 + Math.exp(-sum)); + mComputed = true; + } + return mResult; } } - private LetterRecognizer(int numOfInput, int numOfHidden, String[] classes) { - mPatchSize = (int)Math.sqrt(numOfInput); - mHiddenLayer = new SigmoidUnit[numOfHidden]; - mClasses = classes; - mOutputLayer = new SigmoidUnit[classes.length]; - } - - public void save() { - mGestureLibrary.save(); - } - public static LetterRecognizer getLetterRecognizer(Context context, int type) { switch (type) { - case LATIN_LOWERCASE: { + case RECOGNIZER_LATIN_LOWERCASE: { return createFromResource(context, com.android.internal.R.raw.latin_lowercase); } } return null; } + private LetterRecognizer(int numOfInput, int numOfHidden, String[] classes) { + mPatchSize = (int) Math.sqrt(numOfInput); + mHiddenLayer = new SigmoidUnit[numOfHidden]; + mClasses = classes; + mOutputLayer = new SigmoidUnit[classes.length]; + } + public ArrayList<Prediction> recognize(Gesture gesture) { float[] query = GestureUtilities.spatialSampling(gesture, mPatchSize); ArrayList<Prediction> predictions = classify(query); - if (mGestureLibrary != null) { - adjustPrediction(gesture, predictions); - } + adjustPrediction(gesture, predictions); return predictions; } @@ -151,40 +151,17 @@ public class LetterRecognizer { LetterRecognizer classifier = null; try { - in = new DataInputStream(new BufferedInputStream(resources.openRawResource(resourceID))); + in = new DataInputStream(new BufferedInputStream(resources.openRawResource(resourceID), + GestureConstants.IO_BUFFER_SIZE)); - final int iCount = in.readInt(); - final int hCount = in.readInt(); - final int oCount = in.readInt(); + final int version = in.readShort(); - final String[] classes = new String[oCount]; - for (int i = 0; i < classes.length; i++) { - classes[i] = in.readUTF(); + switch (version) { + case 1: + classifier = readV1(in); + break; } - classifier = new LetterRecognizer(iCount, hCount, classes); - SigmoidUnit[] hiddenLayer = new SigmoidUnit[hCount]; - SigmoidUnit[] outputLayer = new SigmoidUnit[oCount]; - - for (int i = 0; i < hCount; i++) { - float[] weights = new float[iCount + 1]; - for (int j = 0; j <= iCount; j++) { - weights[j] = in.readFloat(); - } - hiddenLayer[i] = new SigmoidUnit(weights); - } - - for (int i = 0; i < oCount; i++) { - float[] weights = new float[hCount + 1]; - for (int j = 0; j <= hCount; j++) { - weights[j] = in.readFloat(); - } - outputLayer[i] = new SigmoidUnit(weights); - } - - classifier.mHiddenLayer = hiddenLayer; - classifier.mOutputLayer = outputLayer; - } catch (IOException e) { Log.d(LOG_TAG, "Failed to load handwriting data:", e); } finally { @@ -193,35 +170,103 @@ public class LetterRecognizer { return classifier; } - - public void enablePersonalization(boolean enable) { - if (enable) { + + private static LetterRecognizer readV1(DataInputStream in) throws IOException { + + final int iCount = in.readInt(); + final int hCount = in.readInt(); + final int oCount = in.readInt(); + + final String[] classes = new String[oCount]; + for (int i = 0; i < classes.length; i++) { + classes[i] = in.readUTF(); + } + + final LetterRecognizer classifier = new LetterRecognizer(iCount, hCount, classes); + final SigmoidUnit[] hiddenLayer = new SigmoidUnit[hCount]; + final SigmoidUnit[] outputLayer = new SigmoidUnit[oCount]; + + for (int i = 0; i < hCount; i++) { + final float[] weights = new float[iCount + 1]; + for (int j = 0; j <= iCount; j++) { + weights[j] = in.readFloat(); + } + hiddenLayer[i] = new SigmoidUnit(weights); + } + + for (int i = 0; i < oCount; i++) { + final float[] weights = new float[hCount + 1]; + for (int j = 0; j <= hCount; j++) { + weights[j] = in.readFloat(); + } + outputLayer[i] = new SigmoidUnit(weights); + } + + classifier.mHiddenLayer = hiddenLayer; + classifier.mOutputLayer = outputLayer; + + return classifier; + } + + /** + * TODO: Publish this API once we figure out where we should save the personzlied + * gestures, and how to do so across all apps + * + * @hide + */ + public boolean save() { + if (mGestureLibrary != null) { + return mGestureLibrary.save(); + } + return false; + } + + /** + * TODO: Publish this API once we figure out where we should save the personzlied + * gestures, and how to do so across all apps + * + * @hide + */ + public void setPersonalizationEnabled(boolean enabled) { + if (enabled) { mGestureLibrary = new GestureLibrary(GESTURE_FILE_NAME); - mGestureLibrary.setGestureType(GestureLibrary.SEQUENCE_INVARIANT); + mGestureLibrary.setSequenceType(GestureLibrary.SEQUENCE_INVARIANT); mGestureLibrary.load(); } else { mGestureLibrary = null; } } + /** + * TODO: Publish this API once we figure out where we should save the personzlied + * gestures, and how to do so across all apps + * + * @hide + */ public void addExample(String letter, Gesture example) { - mGestureLibrary.addGesture(letter, example); + if (mGestureLibrary != null) { + mGestureLibrary.addGesture(letter, example); + } } private void adjustPrediction(Gesture query, ArrayList<Prediction> predictions) { - ArrayList<Prediction> results = mGestureLibrary.recognize(query); - HashMap<String, Prediction> topNList = new HashMap<String, Prediction>(); - for (int j = 0; j < ADJUST_RANGE; j++) { - Prediction prediction = predictions.remove(0); - topNList.put(prediction.name, prediction); - } - int count = results.size(); - for (int j = count - 1; j >= 0 && !topNList.isEmpty(); j--) { - Prediction item = results.get(j); - Prediction original = topNList.get(item.name); - if (original != null) { - predictions.add(0, original); - topNList.remove(item.name); + if (mGestureLibrary != null) { + final ArrayList<Prediction> results = mGestureLibrary.recognize(query); + final HashMap<String, Prediction> topNList = new HashMap<String, Prediction>(); + + for (int j = 0; j < ADJUST_RANGE; j++) { + Prediction prediction = predictions.remove(0); + topNList.put(prediction.name, prediction); + } + + final int count = results.size(); + for (int j = count - 1; j >= 0 && !topNList.isEmpty(); j--) { + final Prediction item = results.get(j); + final Prediction original = topNList.get(item.name); + if (original != null) { + predictions.add(0, original); + topNList.remove(item.name); + } } } } diff --git a/tests/sketch/src/com/android/gesture/OrientedBoundingBox.java b/core/java/android/gesture/OrientedBoundingBox.java index a07d125d5255..f1335ee12232 100644 --- a/tests/sketch/src/com/android/gesture/OrientedBoundingBox.java +++ b/core/java/android/gesture/OrientedBoundingBox.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package com.android.gesture; +package android.gesture; import android.graphics.Matrix; import android.graphics.Path; @@ -47,6 +47,11 @@ public class OrientedBoundingBox { } } + /** + * Currently used for debugging purpose only. + * + * @hide + */ public Path toPath() { Path path = new Path(); float[] point = new float[2]; diff --git a/tests/sketch/src/com/android/gesture/Prediction.java b/core/java/android/gesture/Prediction.java index 92d3ba4af604..ce6ad5745df6 100755 --- a/tests/sketch/src/com/android/gesture/Prediction.java +++ b/core/java/android/gesture/Prediction.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package com.android.gesture; +package android.gesture; public class Prediction { public final String name; diff --git a/tests/sketch/src/com/android/gesture/TouchThroughGesturing.java b/core/java/android/gesture/TouchThroughGestureListener.java index fc878c8fd221..7621ddf2781f 100644 --- a/tests/sketch/src/com/android/gesture/TouchThroughGesturing.java +++ b/core/java/android/gesture/TouchThroughGestureListener.java @@ -14,13 +14,13 @@ * limitations under the License. */ -package com.android.gesture; +package android.gesture; -import android.graphics.Color; import android.view.MotionEvent; import android.view.View; import java.util.ArrayList; +import java.lang.ref.WeakReference; /** * TouchThroughGesturing implements the interaction behavior that allows a user @@ -28,19 +28,15 @@ import java.util.ArrayList; * still allows a user to perform basic interactions (clicking, scrolling and panning) * with the underlying widget. */ - -public class TouchThroughGesturing implements GestureListener { +public class TouchThroughGestureListener implements GestureOverlayView.OnGestureListener { public static final int SINGLE_STROKE = 0; public static final int MULTIPLE_STROKE = 1; + // TODO: Add properties for all these private static final float STROKE_LENGTH_THRESHOLD = 30; private static final float SQUARENESS_THRESHOLD = 0.275f; private static final float ANGLE_THRESHOLD = 40; - private static final boolean STEAL_EVENTS = false; - - public static final int DEFAULT_UNCERTAIN_GESTURE_COLOR = Color.argb(60, 255, 255, 0); - private boolean mIsGesturing = false; private float mTotalLength; @@ -48,18 +44,23 @@ public class TouchThroughGesturing implements GestureListener { private float mX; private float mY; - // TODO: Use WeakReference? - private View mModel; + private WeakReference<View> mModel; private int mGestureType = SINGLE_STROKE; - private int mUncertainGestureColor = DEFAULT_UNCERTAIN_GESTURE_COLOR; // TODO: Use WeakReferences - private final ArrayList<GestureActionListener> mActionListeners = - new ArrayList<GestureActionListener>(); + private final ArrayList<OnGesturePerformedListener> mPerformedListeners = + new ArrayList<OnGesturePerformedListener>(); + + private boolean mStealEvents = false; + + public TouchThroughGestureListener(View model) { + this(model, false); + } - public TouchThroughGesturing(View model) { - mModel = model; + public TouchThroughGestureListener(View model, boolean stealEvents) { + mModel = new WeakReference<View>(model); + mStealEvents = stealEvents; } /** @@ -70,11 +71,7 @@ public class TouchThroughGesturing implements GestureListener { mGestureType = type; } - public void setUncertainGestureColor(int color) { - mUncertainGestureColor = color; - } - - public void onStartGesture(GestureOverlay overlay, MotionEvent event) { + public void onGestureStarted(GestureOverlayView overlay, MotionEvent event) { if (mGestureType == MULTIPLE_STROKE) { overlay.cancelFadingOut(); } @@ -86,16 +83,21 @@ public class TouchThroughGesturing implements GestureListener { if (mGestureType == SINGLE_STROKE || overlay.getCurrentGesture() == null || overlay.getCurrentGesture().getStrokesCount() == 0) { - overlay.setGestureColor(mUncertainGestureColor); + overlay.setGestureDrawingColor(overlay.getUncertainGestureColor()); } - mModel.dispatchTouchEvent(event); + dispatchEventToModel(event); + } + + private void dispatchEventToModel(MotionEvent event) { + View v = mModel.get(); + if (v != null) v.dispatchTouchEvent(event); } - public void onGesture(GestureOverlay overlay, MotionEvent event) { + public void onGesture(GestureOverlayView overlay, MotionEvent event) { //noinspection PointlessBooleanExpression - if (!STEAL_EVENTS) { - mModel.dispatchTouchEvent(event); + if (!mStealEvents) { + dispatchEventToModel(event); } if (mIsGesturing) { @@ -107,7 +109,7 @@ public class TouchThroughGesturing implements GestureListener { final float dx = x - mX; final float dy = y - mY; - mTotalLength += (float)Math.sqrt(dx * dx + dy * dy); + mTotalLength += (float) Math.sqrt(dx * dx + dy * dy); mX = x; mY = y; @@ -120,8 +122,8 @@ public class TouchThroughGesturing implements GestureListener { } if (box.squareness > SQUARENESS_THRESHOLD || angle < ANGLE_THRESHOLD) { mIsGesturing = true; - overlay.setGestureColor(GestureOverlay.DEFAULT_GESTURE_COLOR); - if (STEAL_EVENTS) { + overlay.setGestureDrawingColor(overlay.getGestureColor()); + if (mStealEvents) { event = MotionEvent.obtain(event.getDownTime(), System.currentTimeMillis(), MotionEvent.ACTION_UP, x, y, event.getPressure(), event.getSize(), event.getMetaState(), event.getXPrecision(), event.getYPrecision(), @@ -130,36 +132,40 @@ public class TouchThroughGesturing implements GestureListener { } } - if (STEAL_EVENTS) { - mModel.dispatchTouchEvent(event); + if (mStealEvents) { + dispatchEventToModel(event); } } - public void onFinishGesture(GestureOverlay overlay, MotionEvent event) { + public void onGestureEnded(GestureOverlayView overlay, MotionEvent event) { if (mIsGesturing) { overlay.clear(true); - final ArrayList<GestureActionListener> listeners = mActionListeners; + final ArrayList<OnGesturePerformedListener> listeners = mPerformedListeners; final int count = listeners.size(); for (int i = 0; i < count; i++) { listeners.get(i).onGesturePerformed(overlay, overlay.getCurrentGesture()); } } else { - mModel.dispatchTouchEvent(event); + dispatchEventToModel(event); overlay.clear(false); } } - public void addGestureActionListener(GestureActionListener listener) { - mActionListeners.add(listener); + public void addOnGestureActionListener(OnGesturePerformedListener listener) { + mPerformedListeners.add(listener); } - public void removeGestureActionListener(GestureActionListener listener) { - mActionListeners.remove(listener); + public void removeOnGestureActionListener(OnGesturePerformedListener listener) { + mPerformedListeners.remove(listener); } public boolean isGesturing() { return mIsGesturing; } + + public static interface OnGesturePerformedListener { + public void onGesturePerformed(GestureOverlayView overlay, Gesture gesture); + } } diff --git a/core/java/android/view/SurfaceView.java b/core/java/android/view/SurfaceView.java index 49e4e4cf12d6..e70c94c25ff0 100644 --- a/core/java/android/view/SurfaceView.java +++ b/core/java/android/view/SurfaceView.java @@ -101,6 +101,8 @@ public class SurfaceView extends View { static final int KEEP_SCREEN_ON_MSG = 1; static final int GET_NEW_SURFACE_MSG = 2; + int mWindowType = WindowManager.LayoutParams.TYPE_APPLICATION_MEDIA; + boolean mIsCreating = false; final Handler mHandler = new Handler() { @@ -286,6 +288,15 @@ public class SurfaceView extends View { super.dispatchDraw(canvas); } + /** + * Hack to allow special layering of windows. The type is one of the + * types in WindowManager.LayoutParams. This is a hack so: + * @hide + */ + public void setWindowType(int type) { + mWindowType = type; + } + private void updateWindow(boolean force) { if (!mHaveFrame) { return; @@ -343,7 +354,7 @@ public class SurfaceView extends View { if (mWindow == null) { mWindow = new MyWindow(this); - mLayout.type = WindowManager.LayoutParams.TYPE_APPLICATION_MEDIA; + mLayout.type = mWindowType; mLayout.gravity = Gravity.LEFT|Gravity.TOP; mSession.add(mWindow, mLayout, mVisible ? VISIBLE : GONE, mContentInsets); diff --git a/core/java/android/view/Window.java b/core/java/android/view/Window.java index b0e738cf879a..d7457a030468 100644 --- a/core/java/android/view/Window.java +++ b/core/java/android/view/Window.java @@ -376,8 +376,14 @@ public abstract class Window { String title; if (wp.type == WindowManager.LayoutParams.TYPE_APPLICATION_MEDIA) { title="Media"; + } else if (wp.type == WindowManager.LayoutParams.TYPE_APPLICATION_MEDIA_OVERLAY) { + title="MediaOvr"; } else if (wp.type == WindowManager.LayoutParams.TYPE_APPLICATION_PANEL) { title="Panel"; + } else if (wp.type == WindowManager.LayoutParams.TYPE_APPLICATION_SUB_PANEL) { + title="SubPanel"; + } else if (wp.type == WindowManager.LayoutParams.TYPE_APPLICATION_ATTACHED_DIALOG) { + title="AtchDlg"; } else { title=Integer.toString(wp.type); } diff --git a/core/java/android/view/WindowManager.java b/core/java/android/view/WindowManager.java index 72ef0ada1837..ec2069ccc28e 100644 --- a/core/java/android/view/WindowManager.java +++ b/core/java/android/view/WindowManager.java @@ -210,6 +210,15 @@ public interface WindowManager extends ViewManager { public static final int TYPE_APPLICATION_ATTACHED_DIALOG = FIRST_SUB_WINDOW+3; /** + * Window type: window for showing overlays on top of media windows. + * These windows are displayed between TYPE_APPLICATION_MEDIA and the + * application window. They should be translucent to be useful. This + * is a big ugly hack so: + * @hide + */ + public static final int TYPE_APPLICATION_MEDIA_OVERLAY = FIRST_SUB_WINDOW+4; + + /** * End of types of sub-windows. */ public static final int LAST_SUB_WINDOW = 1999; diff --git a/core/res/res/raw/latin_lowercase b/core/res/res/raw/latin_lowercase Binary files differindex 9c747d69facb..5c38b911a58f 100644 --- a/core/res/res/raw/latin_lowercase +++ b/core/res/res/raw/latin_lowercase diff --git a/core/res/res/values/config.xml b/core/res/res/values/config.xml index 83ac8e27e146..f655b274bc3c 100644 --- a/core/res/res/values/config.xml +++ b/core/res/res/values/config.xml @@ -34,4 +34,8 @@ <!-- The duration (in milliseconds) of a long animation. --> <integer name="config_longAnimTime">300</integer> + + <!-- Flag indicating whether Last Name comes before First Name. + This becomes true in Japan, for example.--> + <bool name="config_lastname_comes_before_firstname">false</bool> </resources> diff --git a/core/res/res/values/public.xml b/core/res/res/values/public.xml index 5eec44843485..199eac1d88e6 100644 --- a/core/res/res/values/public.xml +++ b/core/res/res/values/public.xml @@ -1132,12 +1132,13 @@ <!-- =============================================================== - Resources added in version 5 of the platform. + Resources added in Eclair. =============================================================== --> <eat-comment /> - <public type="attr" name="accountType" id="0x010102A9" /> - <public type="attr" name="contentAuthority" id="0x010102AA" /> + <public type="attr" name="accountType" /> + <public type="attr" name="contentAuthority" /> + <public type="drawable" name="stat_sys_vp_phone_call" /> <public type="drawable" name="stat_sys_vp_phone_call_on_hold" /> diff --git a/data/etc/platform.xml b/data/etc/platform.xml index 6d750b3f80ff..33d6b3bcf339 100644 --- a/data/etc/platform.xml +++ b/data/etc/platform.xml @@ -138,6 +138,8 @@ <assign-permission name="android.permission.ACCESS_DRM" uid="media" /> <assign-permission name="android.permission.ACCESS_SURFACE_FLINGER" uid="media" /> + <assign-permission name="android.permission.ACCESS_SURFACE_FLINGER" uid="graphics" /> + <!-- This is a list of all the libraries available for application code to link against. --> diff --git a/include/binder/Parcel.h b/include/binder/Parcel.h index 9087c4465b96..af1490a02973 100644 --- a/include/binder/Parcel.h +++ b/include/binder/Parcel.h @@ -80,8 +80,11 @@ public: status_t writeStrongBinder(const sp<IBinder>& val); status_t writeWeakBinder(const wp<IBinder>& val); - // doesn't take ownership of the native_handle - status_t writeNativeHandle(const native_handle& handle); + // Place a native_handle into the parcel (the native_handle's file- + // descriptors are dup'ed, so it is safe to delete the native_handle + // when this function returns). + // Doesn't take ownership of the native_handle. + status_t writeNativeHandle(const native_handle* handle); // Place a file descriptor into the parcel. The given fd must remain // valid for the lifetime of the parcel. @@ -114,12 +117,11 @@ public: wp<IBinder> readWeakBinder() const; - // if alloc is NULL, native_handle is allocated with malloc(), otherwise - // alloc is used. If the function fails, the effects of alloc() must be - // reverted by the caller. - native_handle* readNativeHandle( - native_handle* (*alloc)(void* cookie, int numFds, int ints), - void* cookie) const; + // Retrieve native_handle from the parcel. This returns a copy of the + // parcel's native_handle (the caller takes ownership). The caller + // must free the native_handle with native_handle_close() and + // native_handle_delete(). + native_handle* readNativeHandle() const; // Retrieve a file descriptor from the parcel. This returns the raw fd diff --git a/include/tts/TtsEngine.h b/include/tts/TtsEngine.h new file mode 100644 index 000000000000..06f382003055 --- /dev/null +++ b/include/tts/TtsEngine.h @@ -0,0 +1,167 @@ +/* + * Copyright (C) 2009 Google Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#include <media/AudioSystem.h> + +// This header defines the interface used by the Android platform +// to access Text-To-Speech functionality in shared libraries that implement speech +// synthesis and the management of resources associated with the synthesis. +// An example of the implementation of this interface can be found in +// FIXME: add path+name to implementation of default TTS engine +// Libraries implementing this interface are used in: +// frameworks/base/tts/jni/android_tts_SpeechSynthesis.cpp + +namespace android { + +// The callback is used by the implementation of this interface to notify its +// client, the Android TTS service, that the last requested synthesis has been +// completed. +// The callback for synthesis completed takes: +// void * - The userdata pointer set in the original synth call +// uint32_t - Track sampling rate in Hz +// audio_format - The AudioSystem::audio_format enum +// int - The number of channels +// int8_t * - A buffer of audio data only valid during the execution of the callback +// size_t - The size of the buffer +// Note about memory management: +// The implementation of TtsEngine is responsible for the management of the memory +// it allocates to store the synthesized speech. After the execution of the callback +// to hand the synthesized data to the client of TtsEngine, the TTS engine is +// free to reuse or free the previously allocated memory. +// This implies that the implementation of the "synthDoneCB" callback cannot use +// the pointer to the buffer of audio samples outside of the callback itself. +typedef void (synthDoneCB_t)(void *, uint32_t, AudioSystem::audio_format, int, int8_t *, size_t); + +class TtsEngine; +extern "C" TtsEngine* getTtsEngine(); + +enum tts_result { + TTS_SUCCESS = 0, + TTS_FAILURE = -1, + TTS_FEATURE_UNSUPPORTED = -2, + TTS_VALUE_INVALID = -3, + TTS_PROPERTY_UNSUPPORTED = -4, + TTS_PROPERTY_SIZE_TOO_SMALL = -5 +}; + +class TtsEngine +{ +public: + // Initialize the TTS engine and returns whether initialization succeeded. + // @param synthDoneCBPtr synthesis callback function pointer + // @return TTS_SUCCESS, or TTS_FAILURE + virtual tts_result init(synthDoneCB_t synthDoneCBPtr); + + // Shut down the TTS engine and releases all associated resources. + // @return TTS_SUCCESS, or TTS_FAILURE + virtual tts_result shutdown(); + + // Interrupt synthesis and flushes any synthesized data that hasn't been output yet. + // This will block until callbacks underway are completed. + // @return TTS_SUCCESS, or TTS_FAILURE + virtual tts_result stop(); + + // Load the resources associated with the specified language. The loaded language will + // only be used once a call to setLanguage() with the same language value is issued. + // Language values are based on the Android conventions for localization as described in + // the Android platform documentation on internationalization. This implies that language + // data is specified in the format xx-rYY, where xx is a two letter ISO 639-1 language code + // in lowercase and rYY is a two letter ISO 3166-1-alpha-2 language code in uppercase + // preceded by a lowercase "r". + // @param value pointer to the language value + // @param size length of the language value + // @return TTS_SUCCESS, or TTS_FAILURE + virtual tts_result loadLanguage(const char *value, const size_t size); + + // Signal the engine to use the specified language. This will force the language to be + // loaded if it wasn't loaded previously with loadLanguage(). + // See loadLanguage for the specification of the language. + // @param value pointer to the language value + // @param size length of the language value + // @return TTS_SUCCESS, or TTS_FAILURE + virtual tts_result setLanguage(const char *value, const size_t size); + + // Retrieve the currently set language, or an empty "value" if no language has + // been set. + // @param[out] value pointer to the retrieved language value + // @param[inout] iosize in: stores the size available to store the language value in *value + // out: stores the size required to hold the language value if + // getLanguage() returned TTS_PROPERTY_SIZE_TOO_SMALL, + // unchanged otherwise. + // @return TTS_SUCCESS, or TTS_PROPERTY_SIZE_TOO_SMALL, or TTS_FAILURE + virtual tts_result getLanguage(char *value, size_t *iosize); + + // Set a property for the the TTS engine + // "size" is the maximum size of "value" for properties "property" + // @param property pointer to the property name + // @param value pointer to the property value + // @param size maximum size required to store this type of property + // @return TTS_PROPERTY_UNSUPPORTED, or TTS_SUCCESS, or TTS_FAILURE, + // or TTS_VALUE_INVALID + virtual tts_result setProperty(const char *property, const char *value, const size_t size); + + // Retrieve a property from the TTS engine + // @param property pointer to the property name + // @param[out] value pointer to the retrieved language value + // @param[inout] iosize in: stores the size available to store the property value + // out: stores the size required to hold the language value if + // getLanguage() returned TTS_PROPERTY_SIZE_TOO_SMALL, + // unchanged otherwise. + // @return TTS_PROPERTY_UNSUPPORTED, or TTS_SUCCESS, or TTS_PROPERTY_SIZE_TOO_SMALL + virtual tts_result getProperty(const char *property, char *value, size_t *iosize); + + // Synthesize the text. + // When synthesis completes, the engine invokes the callback to notify the TTS framework. + // Note about the format of the input: the text parameter may use the following elements + // and their respective attributes as defined in the SSML 1.0 specification: + // * lang + // * say-as: + // o interpret-as + // * phoneme + // * voice: + // o gender, + // o age, + // o variant, + // o name + // * emphasis + // * break: + // o strength, + // o time + // * prosody: + // o pitch, + // o contour, + // o range, + // o rate, + // o duration, + // o volume + // * mark + // Differences between this text format and SSML are: + // * full SSML documents are not supported + // * namespaces are not supported + // Text is coded in UTF-8. + // @param text the UTF-8 text to synthesize + // @param userdata pointer to be returned when the call is invoked + // @return TTS_SUCCESS or TTS_FAILURE + virtual tts_result synthesizeText(const char *text, void *userdata); + + // Synthesize IPA text. When synthesis completes, the engine must call the given callback to notify the TTS API. + // @param ipa the IPA data to synthesize + // @param userdata pointer to be returned when the call is invoked + // @return TTS_FEATURE_UNSUPPORTED if IPA is not supported, otherwise TTS_SUCCESS or TTS_FAILURE + virtual tts_result synthesizeIpa(const char *ipa, void *userdata); +}; + +} // namespace android + diff --git a/libs/binder/Parcel.cpp b/libs/binder/Parcel.cpp index d29ec8c28613..0819c29154c4 100644 --- a/libs/binder/Parcel.cpp +++ b/libs/binder/Parcel.cpp @@ -650,28 +650,26 @@ status_t Parcel::writeWeakBinder(const wp<IBinder>& val) return flatten_binder(ProcessState::self(), val, this); } -status_t Parcel::writeNativeHandle(const native_handle& handle) +status_t Parcel::writeNativeHandle(const native_handle* handle) { - if (handle.version != sizeof(native_handle)) + if (handle->version != sizeof(native_handle)) return BAD_TYPE; status_t err; - err = writeInt32(handle.numFds); + err = writeInt32(handle->numFds); if (err != NO_ERROR) return err; - err = writeInt32(handle.numInts); + err = writeInt32(handle->numInts); if (err != NO_ERROR) return err; - for (int i=0 ; err==NO_ERROR && i<handle.numFds ; i++) - err = writeDupFileDescriptor(handle.data[i]); + for (int i=0 ; err==NO_ERROR && i<handle->numFds ; i++) + err = writeDupFileDescriptor(handle->data[i]); if (err != NO_ERROR) { LOGD("write native handle, write dup fd failed"); return err; } - - err = write(handle.data + handle.numFds, sizeof(int)*handle.numInts); - + err = write(handle->data + handle->numFds, sizeof(int)*handle->numInts); return err; } @@ -928,7 +926,7 @@ wp<IBinder> Parcel::readWeakBinder() const } -native_handle* Parcel::readNativeHandle(native_handle* (*alloc)(void*, int, int), void* cookie) const +native_handle* Parcel::readNativeHandle() const { int numFds, numInts; status_t err; @@ -937,30 +935,15 @@ native_handle* Parcel::readNativeHandle(native_handle* (*alloc)(void*, int, int) err = readInt32(&numInts); if (err != NO_ERROR) return 0; - native_handle* h; - if (alloc == 0) { - size_t size = sizeof(native_handle) + sizeof(int)*(numFds + numInts); - h = (native_handle*)malloc(size); - h->version = sizeof(native_handle); - h->numFds = numFds; - h->numInts = numInts; - } else { - h = alloc(cookie, numFds, numInts); - if (h->version != sizeof(native_handle)) { - return 0; - } - } + native_handle* h = native_handle_create(numFds, numInts); for (int i=0 ; err==NO_ERROR && i<numFds ; i++) { h->data[i] = dup(readFileDescriptor()); if (h->data[i] < 0) err = BAD_VALUE; } - err = read(h->data + numFds, sizeof(int)*numInts); - if (err != NO_ERROR) { - if (alloc == 0) { - free(h); - } + native_handle_close(h); + native_handle_delete(h); h = 0; } return h; diff --git a/libs/surfaceflinger/Android.mk b/libs/surfaceflinger/Android.mk index b7a464fdaf54..a5698f27e2bd 100644 --- a/libs/surfaceflinger/Android.mk +++ b/libs/surfaceflinger/Android.mk @@ -6,7 +6,6 @@ LOCAL_SRC_FILES:= \ DisplayHardware/DisplayHardware.cpp \ DisplayHardware/DisplayHardwareBase.cpp \ GPUHardware/GPUHardware.cpp \ - BootAnimation.cpp \ BlurFilter.cpp.arm \ CPUGauge.cpp \ Layer.cpp \ diff --git a/libs/surfaceflinger/SurfaceFlinger.cpp b/libs/surfaceflinger/SurfaceFlinger.cpp index 37d1deddbbe0..efaf0167cc36 100644 --- a/libs/surfaceflinger/SurfaceFlinger.cpp +++ b/libs/surfaceflinger/SurfaceFlinger.cpp @@ -62,6 +62,13 @@ #include "GPUHardware/GPUHardware.h" +/* ideally AID_GRAPHICS would be in a semi-public header + * or there would be a way to map a user/group name to its id + */ +#ifndef AID_GRAPHICS +#define AID_GRAPHICS 1003 +#endif + #define DISPLAY_COUNT 1 namespace android { @@ -185,7 +192,6 @@ SurfaceFlinger::SurfaceFlinger() mDebugCpu(0), mDebugFps(0), mDebugBackground(0), - mDebugNoBootAnimation(0), mSyncObject(), mDeplayedTransactionPending(0), mConsoleSignals(0), @@ -208,14 +214,11 @@ void SurfaceFlinger::init() mDebugBackground = atoi(value); property_get("debug.sf.showfps", value, "0"); mDebugFps = atoi(value); - property_get("debug.sf.nobootanimation", value, "0"); - mDebugNoBootAnimation = atoi(value); LOGI_IF(mDebugRegion, "showupdates enabled"); LOGI_IF(mDebugCpu, "showcpu enabled"); LOGI_IF(mDebugBackground, "showbackground enabled"); LOGI_IF(mDebugFps, "showfps enabled"); - LOGI_IF(mDebugNoBootAnimation, "boot animation disabled"); } SurfaceFlinger::~SurfaceFlinger() @@ -325,11 +328,8 @@ void SurfaceFlinger::bootFinished() { const nsecs_t now = systemTime(); const nsecs_t duration = now - mBootTime; - LOGI("Boot is finished (%ld ms)", long(ns2ms(duration)) ); - if (mBootAnimation != 0) { - mBootAnimation->requestExit(); - mBootAnimation.clear(); - } + LOGI("Boot is finished (%ld ms)", long(ns2ms(duration)) ); + property_set("ctl.stop", "bootanim"); } void SurfaceFlinger::onFirstRef() @@ -457,10 +457,10 @@ status_t SurfaceFlinger::readyToRun() if (mDebugCpu) mCpuGauge = new CPUGauge(this, ms2ns(500)); - // the boot animation! - if (mDebugNoBootAnimation == false) - mBootAnimation = new BootAnimation(this); - + + // start boot animation + property_set("ctl.start", "bootanim"); + return NO_ERROR; } @@ -1544,13 +1544,13 @@ status_t SurfaceFlinger::onTransact( // codes that require permission check IPCThreadState* ipc = IPCThreadState::self(); const int pid = ipc->getCallingPid(); + const int uid = ipc->getCallingUid(); const int self_pid = getpid(); - if (UNLIKELY(pid != self_pid)) { + if (UNLIKELY(pid != self_pid && uid != AID_GRAPHICS)) { // we're called from a different process, do the real check if (!checkCallingPermission( String16("android.permission.ACCESS_SURFACE_FLINGER"))) { - const int uid = ipc->getCallingUid(); LOGE("Permission Denial: " "can't access SurfaceFlinger pid=%d, uid=%d", pid, uid); return PERMISSION_DENIED; diff --git a/libs/surfaceflinger/SurfaceFlinger.h b/libs/surfaceflinger/SurfaceFlinger.h index 927908d4b75e..126bce8f6283 100644 --- a/libs/surfaceflinger/SurfaceFlinger.h +++ b/libs/surfaceflinger/SurfaceFlinger.h @@ -36,7 +36,6 @@ #include <private/ui/SurfaceFlingerSynchro.h> #include "Barrier.h" -#include "BootAnimation.h" #include "CPUGauge.h" #include "Layer.h" #include "Tokenizer.h" @@ -347,7 +346,6 @@ private: sp<SurfaceHeapManager> mSurfaceHeapManager; sp<GPUHardwareInterface> mGPU; GLuint mWormholeTexName; - sp<BootAnimation> mBootAnimation; nsecs_t mBootTime; // Can only accessed from the main thread, these members @@ -374,7 +372,6 @@ private: int mDebugCpu; int mDebugFps; int mDebugBackground; - int mDebugNoBootAnimation; // these are thread safe mutable Barrier mReadyToRunBarrier; diff --git a/libs/surfaceflinger/VRamHeap.cpp b/libs/surfaceflinger/VRamHeap.cpp index 7132d0d4bbac..68c0a5edda7a 100644 --- a/libs/surfaceflinger/VRamHeap.cpp +++ b/libs/surfaceflinger/VRamHeap.cpp @@ -35,6 +35,8 @@ #include <binder/MemoryHeapPmem.h> #include <binder/MemoryHeapBase.h> +#include <EGL/eglnatives.h> + #include "GPUHardware/GPUHardware.h" #include "SurfaceFlinger.h" #include "VRamHeap.h" diff --git a/libs/ui/ISurfaceFlingerClient.cpp b/libs/ui/ISurfaceFlingerClient.cpp index 69731ab0cfd3..a93ae67ab81d 100644 --- a/libs/ui/ISurfaceFlingerClient.cpp +++ b/libs/ui/ISurfaceFlingerClient.cpp @@ -35,6 +35,13 @@ // --------------------------------------------------------------------------- +/* ideally AID_GRAPHICS would be in a semi-public header + * or there would be a way to map a user/group name to its id + */ +#ifndef AID_GRAPHICS +#define AID_GRAPHICS 1003 +#endif + #define LIKELY( exp ) (__builtin_expect( (exp) != 0, true )) #define UNLIKELY( exp ) (__builtin_expect( (exp) != 0, false )) @@ -136,13 +143,13 @@ status_t BnSurfaceFlingerClient::onTransact( IPCThreadState* ipc = IPCThreadState::self(); const int pid = ipc->getCallingPid(); - const int self_pid = getpid(); - if (UNLIKELY(pid != self_pid)) { + const int uid = ipc->getCallingUid(); + const int self_pid = getpid(); + if (UNLIKELY(pid != self_pid && uid != AID_GRAPHICS)) { // we're called from a different process, do the real check if (!checkCallingPermission( String16("android.permission.ACCESS_SURFACE_FLINGER"))) { - const int uid = ipc->getCallingUid(); LOGE("Permission Denial: " "can't openGlobalTransaction pid=%d, uid=%d", pid, uid); return PERMISSION_DENIED; diff --git a/libs/ui/Overlay.cpp b/libs/ui/Overlay.cpp index 9fae416436f7..a092f8dd54e0 100644 --- a/libs/ui/Overlay.cpp +++ b/libs/ui/Overlay.cpp @@ -129,12 +129,8 @@ OverlayRef::OverlayRef(overlay_handle_t handle, const sp<IOverlay>& channel, OverlayRef::~OverlayRef() { if (mOwnHandle) { - /* FIXME: handles should be promoted to "real" API and be handled by - * the framework */ - for (int i=0 ; i<mOverlayHandle->numFds ; i++) { - close(mOverlayHandle->data[i]); - } - free((void*)mOverlayHandle); + native_handle_close(mOverlayHandle); + native_handle_delete(const_cast<native_handle*>(mOverlayHandle)); } } @@ -147,7 +143,7 @@ sp<OverlayRef> OverlayRef::readFromParcel(const Parcel& data) { uint32_t f = data.readInt32(); uint32_t ws = data.readInt32(); uint32_t hs = data.readInt32(); - native_handle* handle = data.readNativeHandle(NULL, NULL); + native_handle* handle = data.readNativeHandle(); result = new OverlayRef(); result->mOverlayHandle = handle; @@ -169,7 +165,7 @@ status_t OverlayRef::writeToParcel(Parcel* reply, const sp<OverlayRef>& o) { reply->writeInt32(o->mFormat); reply->writeInt32(o->mWidthStride); reply->writeInt32(o->mHeightStride); - reply->writeNativeHandle(*(o->mOverlayHandle)); + reply->writeNativeHandle(o->mOverlayHandle); } else { reply->writeStrongBinder(NULL); } diff --git a/tests/sketch/AndroidManifest.xml b/tests/sketch/AndroidManifest.xml index 1f4333c5d86a..fbf3a09bd224 100755 --- a/tests/sketch/AndroidManifest.xml +++ b/tests/sketch/AndroidManifest.xml @@ -14,25 +14,32 @@ limitations under the License. --> <manifest xmlns:android="http://schemas.android.com/apk/res/android" - package="com.android.gesture.example" - android:versionCode="1" - android:versionName="1.0.0"> - <uses-permission android:name="android.permission.READ_CONTACTS" /> - <application android:icon="@drawable/icon" android:label="@string/app_name"> - <activity android:name="com.android.gesture.example.GestureEntry" - android:label="@string/app_name"> + package="com.android.gesture.example"> + + <uses-permission android:name="android.permission.READ_CONTACTS" /> + <uses-permission android:name="android.permission.WRITE_SDCARD" /> + + <application android:icon="@drawable/icon" android:label="@string/app_name"> + + <activity + android:name="com.android.gesture.example.GestureEntry" + android:label="@string/app_name"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> + <activity android:name="com.android.gesture.example.GestureLibViewer"/> - <activity android:name="com.android.gesture.example.ContactListGestureOverlay" - android:label="@string/overlay_name"> + + <activity + android:name="com.android.gesture.example.ContactListGestureOverlay" + android:label="@string/overlay_name"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> + </application> </manifest> diff --git a/tests/sketch/src/com/android/gesture/GestureConstants.java b/tests/sketch/src/com/android/gesture/GestureConstants.java deleted file mode 100644 index cb64791df07f..000000000000 --- a/tests/sketch/src/com/android/gesture/GestureConstants.java +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Copyright (C) 2009 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.android.gesture; - -interface GestureConstants { - static final String XML_TAG_LIBRARY = "library"; - static final String XML_TAG_ENTRY = "entry"; - static final String XML_TAG_GESTURE = "gesture"; - static final String XML_TAG_STROKE = "stroke"; - static final String XML_TAG_ID = "id"; - static final String XML_TAG_NAME = "name"; - static final String STRING_GESTURE_DELIIMITER = "#"; - static final String STRING_STROKE_DELIIMITER = ","; - static final int STROKE_STRING_BUFFER_SIZE = 1024; - static final int STROKE_POINT_BUFFER_SIZE = 100; // number of points - static final int IO_BUFFER_SIZE = 8 * 1024; // 8K - String LOG_TAG = "GestureLibrary"; -} diff --git a/tests/sketch/src/com/android/gesture/GestureListener.java b/tests/sketch/src/com/android/gesture/GestureListener.java deleted file mode 100755 index 9b5071401fd0..000000000000 --- a/tests/sketch/src/com/android/gesture/GestureListener.java +++ /dev/null @@ -1,30 +0,0 @@ -/* - * Copyright (C) 2008-2009 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.android.gesture; - -import android.view.MotionEvent; - -/** - * An interface for processing gesture events - */ -public interface GestureListener { - public void onStartGesture(GestureOverlay overlay, MotionEvent event); - - public void onGesture(GestureOverlay overlay, MotionEvent event); - - public void onFinishGesture(GestureOverlay overlay, MotionEvent event); -} diff --git a/tests/sketch/src/com/android/gesture/example/ContactListGestureOverlay.java b/tests/sketch/src/com/android/gesture/example/ContactListGestureOverlay.java index 6eb2f2309cb4..eda42248ce45 100644 --- a/tests/sketch/src/com/android/gesture/example/ContactListGestureOverlay.java +++ b/tests/sketch/src/com/android/gesture/example/ContactListGestureOverlay.java @@ -30,12 +30,11 @@ import android.view.Window; import android.widget.AdapterView; import android.widget.ListView; -import com.android.gesture.Gesture; -import com.android.gesture.GestureActionListener; -import com.android.gesture.GestureOverlay; -import com.android.gesture.LetterRecognizer; -import com.android.gesture.Prediction; -import com.android.gesture.TouchThroughGesturing; +import android.gesture.Gesture; +import android.gesture.GestureOverlayView; +import android.gesture.LetterRecognizer; +import android.gesture.Prediction; +import android.gesture.TouchThroughGestureListener; import java.util.ArrayList; @@ -52,7 +51,7 @@ public class ContactListGestureOverlay extends Activity { private ContactAdapter mContactAdapter; - private TouchThroughGesturing mGestureProcessor; + private TouchThroughGestureListener mGestureProcessor; private LetterRecognizer mRecognizer; @@ -67,7 +66,7 @@ public class ContactListGestureOverlay extends Activity { setProgressBarIndeterminateVisibility(true); // create a letter recognizer - mRecognizer = LetterRecognizer.getLetterRecognizer(this, LetterRecognizer.LATIN_LOWERCASE); + mRecognizer = LetterRecognizer.getLetterRecognizer(this, LetterRecognizer.RECOGNIZER_LATIN_LOWERCASE); // load the contact list mContactList = (ListView) findViewById(R.id.list); @@ -95,11 +94,11 @@ public class ContactListGestureOverlay extends Activity { setProgressBarIndeterminateVisibility(false); // add a gesture overlay on top of the ListView - GestureOverlay overlay = new GestureOverlay(this); - mGestureProcessor = new TouchThroughGesturing(mContactList); - mGestureProcessor.setGestureType(TouchThroughGesturing.MULTIPLE_STROKE); - mGestureProcessor.addGestureActionListener(new GestureActionListener() { - public void onGesturePerformed(GestureOverlay overlay, Gesture gesture) { + GestureOverlayView overlay = new GestureOverlayView(this); + mGestureProcessor = new TouchThroughGestureListener(mContactList); + mGestureProcessor.setGestureType(TouchThroughGestureListener.MULTIPLE_STROKE); + mGestureProcessor.addOnGestureActionListener(new TouchThroughGestureListener.OnGesturePerformedListener() { + public void onGesturePerformed(GestureOverlayView overlay, Gesture gesture) { ArrayList<Prediction> predictions = mRecognizer.recognize(gesture); if (!predictions.isEmpty()) { Log.v(LOGTAG, "1st Prediction : " + predictions.get(0).name); @@ -112,7 +111,7 @@ public class ContactListGestureOverlay extends Activity { } } }); - overlay.addGestureListener(mGestureProcessor); + overlay.addOnGestureListener(mGestureProcessor); ViewGroup.LayoutParams params = new ViewGroup.LayoutParams( ViewGroup.LayoutParams.FILL_PARENT, ViewGroup.LayoutParams.FILL_PARENT); this.addContentView(overlay, params); diff --git a/tests/sketch/src/com/android/gesture/example/GestureEntry.java b/tests/sketch/src/com/android/gesture/example/GestureEntry.java index 03a26da9f678..200f89f03786 100644 --- a/tests/sketch/src/com/android/gesture/example/GestureEntry.java +++ b/tests/sketch/src/com/android/gesture/example/GestureEntry.java @@ -34,12 +34,11 @@ import android.widget.ArrayAdapter; import android.widget.EditText; import android.widget.Spinner; import android.widget.AdapterView.OnItemSelectedListener; +import android.gesture.Gesture; -import com.android.gesture.Gesture; -import com.android.gesture.GestureLibrary; -import com.android.gesture.GestureListener; -import com.android.gesture.GestureOverlay; -import com.android.gesture.Prediction; +import android.gesture.GestureLibrary; +import android.gesture.GestureOverlayView; +import android.gesture.Prediction; import java.io.File; import java.util.ArrayList; @@ -49,7 +48,7 @@ public class GestureEntry extends Activity { private static final String PARCEL_KEY = "gesture"; static final String GESTURE_FILE_NAME = Environment.getExternalStorageDirectory().getAbsolutePath() - + File.separator + "gestureEntry.xml"; + + File.separator + "demo_library.gestures"; private static final int DIALOG_NEW_ENTRY = 1; @@ -57,7 +56,7 @@ public class GestureEntry extends Activity { private static final int VIEW_ID = Menu.FIRST + 1; - private GestureOverlay mGesturePad; + private GestureOverlayView mGesturePad; private Spinner mRecognitionResult; @@ -96,17 +95,17 @@ public class GestureEntry extends Activity { }); // create the area for drawing a gesture - mGesturePad = (GestureOverlay) findViewById(R.id.drawingpad); + mGesturePad = (GestureOverlayView) findViewById(R.id.drawingpad); mGesturePad.setBackgroundColor(Color.BLACK); - mGesturePad.addGestureListener(new GestureListener() { - public void onFinishGesture(GestureOverlay overlay, MotionEvent event) { + mGesturePad.addOnGestureListener(new GestureOverlayView.OnGestureListener() { + public void onGestureEnded(GestureOverlayView overlay, MotionEvent event) { recognize(overlay.getCurrentGesture()); } - public void onGesture(GestureOverlay overlay, MotionEvent event) { + public void onGesture(GestureOverlayView overlay, MotionEvent event) { } - public void onStartGesture(GestureOverlay overlay, MotionEvent event) { + public void onGestureStarted(GestureOverlayView overlay, MotionEvent event) { overlay.clear(false); } }); diff --git a/tests/sketch/src/com/android/gesture/example/GestureLibViewer.java b/tests/sketch/src/com/android/gesture/example/GestureLibViewer.java index ca541105e603..aa07e7b972f9 100755 --- a/tests/sketch/src/com/android/gesture/example/GestureLibViewer.java +++ b/tests/sketch/src/com/android/gesture/example/GestureLibViewer.java @@ -26,10 +26,10 @@ import android.widget.ArrayAdapter; import android.widget.Button; import android.widget.Spinner; import android.widget.AdapterView.OnItemSelectedListener; +import android.gesture.Gesture; -import com.android.gesture.Gesture; -import com.android.gesture.GestureLibrary; -import com.android.gesture.GestureOverlay; +import android.gesture.GestureLibrary; +import android.gesture.GestureOverlayView; import java.util.ArrayList; import java.util.Collections; @@ -41,7 +41,7 @@ import java.util.Collections; public class GestureLibViewer extends Activity { - private GestureOverlay mGesturePad; + private GestureOverlayView mGesturePad; private Spinner mGestureCategory; @@ -90,7 +90,7 @@ public class GestureLibViewer extends Activity { setContentView(R.layout.gestureviewer); // create the area for drawing a gesture - mGesturePad = (GestureOverlay) findViewById(R.id.drawingpad); + mGesturePad = (GestureOverlayView) findViewById(R.id.drawingpad); mGesturePad.setEnabled(false); // init the gesture library diff --git a/tests/sketch/tools/Converter.java b/tests/sketch/tools/Converter.java index b4654f8c24dc..c0391d861217 100644 --- a/tests/sketch/tools/Converter.java +++ b/tests/sketch/tools/Converter.java @@ -15,6 +15,7 @@ import java.io.BufferedInputStream; */ public class Converter { private final File mFile; + private static final short VERSION_NUMBER = 1; Converter(File file) { mFile = file; @@ -63,10 +64,10 @@ public class Converter { iWeights = new float[hCount][]; for (int i = 0; i < hCount; i++) { - iWeights[i] = new float[iCount]; + iWeights[i] = new float[iCount + 1]; line = reader.readLine(); startIndex = 0; - for (int j = 0; j < iCount; j++) { + for (int j = 0; j <= iCount; j++) { endIndex = line.indexOf(" ", startIndex); iWeights[i][j] = Float.parseFloat(line.substring(startIndex, endIndex)); startIndex = endIndex + 1; @@ -75,10 +76,10 @@ public class Converter { oWeights = new float[oCount][]; for (int i = 0; i < oCount; i++) { - oWeights[i] = new float[hCount]; + oWeights[i] = new float[hCount + 1]; line = reader.readLine(); startIndex = 0; - for (int j = 0; j < hCount; j++) { + for (int j = 0; j <= hCount; j++) { endIndex = line.indexOf(" ", startIndex); oWeights[i][j] = Float.parseFloat(line.substring(startIndex, endIndex)); startIndex = endIndex + 1; @@ -105,6 +106,7 @@ public class Converter { try { out = new DataOutputStream(new FileOutputStream(mFile)); + out.writeShort(VERSION_NUMBER); out.writeInt(iCount); out.writeInt(hCount); out.writeInt(oCount); |