11cf70bbf96930662cab0e699d70b62865766ff52Svetoslav Ganov/*
21cf70bbf96930662cab0e699d70b62865766ff52Svetoslav Ganov ** Copyright 2012, The Android Open Source Project
31cf70bbf96930662cab0e699d70b62865766ff52Svetoslav Ganov **
41cf70bbf96930662cab0e699d70b62865766ff52Svetoslav Ganov ** Licensed under the Apache License, Version 2.0 (the "License");
51cf70bbf96930662cab0e699d70b62865766ff52Svetoslav Ganov ** you may not use this file except in compliance with the License.
61cf70bbf96930662cab0e699d70b62865766ff52Svetoslav Ganov ** You may obtain a copy of the License at
71cf70bbf96930662cab0e699d70b62865766ff52Svetoslav Ganov **
81cf70bbf96930662cab0e699d70b62865766ff52Svetoslav Ganov **     http://www.apache.org/licenses/LICENSE-2.0
91cf70bbf96930662cab0e699d70b62865766ff52Svetoslav Ganov **
101cf70bbf96930662cab0e699d70b62865766ff52Svetoslav Ganov ** Unless required by applicable law or agreed to in writing, software
111cf70bbf96930662cab0e699d70b62865766ff52Svetoslav Ganov ** distributed under the License is distributed on an "AS IS" BASIS,
121cf70bbf96930662cab0e699d70b62865766ff52Svetoslav Ganov ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
131cf70bbf96930662cab0e699d70b62865766ff52Svetoslav Ganov ** See the License for the specific language governing permissions and
141cf70bbf96930662cab0e699d70b62865766ff52Svetoslav Ganov ** limitations under the License.
151cf70bbf96930662cab0e699d70b62865766ff52Svetoslav Ganov */
161cf70bbf96930662cab0e699d70b62865766ff52Svetoslav Ganov
171cf70bbf96930662cab0e699d70b62865766ff52Svetoslav Ganovpackage com.android.server.accessibility;
181cf70bbf96930662cab0e699d70b62865766ff52Svetoslav Ganov
191cf70bbf96930662cab0e699d70b62865766ff52Svetoslav Ganovimport android.view.KeyEvent;
201cf70bbf96930662cab0e699d70b62865766ff52Svetoslav Ganovimport android.view.MotionEvent;
211cf70bbf96930662cab0e699d70b62865766ff52Svetoslav Ganovimport android.view.accessibility.AccessibilityEvent;
221cf70bbf96930662cab0e699d70b62865766ff52Svetoslav Ganov
231cf70bbf96930662cab0e699d70b62865766ff52Svetoslav Ganov/**
241cf70bbf96930662cab0e699d70b62865766ff52Svetoslav Ganov * Interface for classes that can handle and potentially transform a stream of
251cf70bbf96930662cab0e699d70b62865766ff52Svetoslav Ganov * motion and accessibility events. Instances implementing this interface are
261cf70bbf96930662cab0e699d70b62865766ff52Svetoslav Ganov * ordered in a sequence to implement a transformation chain. An instance may
271cf70bbf96930662cab0e699d70b62865766ff52Svetoslav Ganov * consume, modify, and generate events. It is responsible to deliver the
281cf70bbf96930662cab0e699d70b62865766ff52Svetoslav Ganov * output events to the next transformation in the sequence set via
291cf70bbf96930662cab0e699d70b62865766ff52Svetoslav Ganov * {@link #setNext(EventStreamTransformation)}.
301cf70bbf96930662cab0e699d70b62865766ff52Svetoslav Ganov *
311cf70bbf96930662cab0e699d70b62865766ff52Svetoslav Ganov * Note that since instances implementing this interface are transformations
321cf70bbf96930662cab0e699d70b62865766ff52Svetoslav Ganov * of the event stream, an instance should work against the event stream
331cf70bbf96930662cab0e699d70b62865766ff52Svetoslav Ganov * potentially modified by previous ones. Hence, the order of transformations
341cf70bbf96930662cab0e699d70b62865766ff52Svetoslav Ganov * is important.
351cf70bbf96930662cab0e699d70b62865766ff52Svetoslav Ganov *
361cf70bbf96930662cab0e699d70b62865766ff52Svetoslav Ganov * It is a responsibility of each handler that decides to react to an event
371cf70bbf96930662cab0e699d70b62865766ff52Svetoslav Ganov * sequence and prevent any subsequent ones from performing an action to send
381cf70bbf96930662cab0e699d70b62865766ff52Svetoslav Ganov * the appropriate cancel event given it has delegated a part of the events
391cf70bbf96930662cab0e699d70b62865766ff52Svetoslav Ganov * that belong to the current gesture. This will ensure that subsequent
401cf70bbf96930662cab0e699d70b62865766ff52Svetoslav Ganov * transformations will not be left in an inconsistent state and the applications
411cf70bbf96930662cab0e699d70b62865766ff52Svetoslav Ganov * see a consistent event stream.
421cf70bbf96930662cab0e699d70b62865766ff52Svetoslav Ganov *
431cf70bbf96930662cab0e699d70b62865766ff52Svetoslav Ganov * For example, to cancel a {@link KeyEvent} the handler has to emit an event
441cf70bbf96930662cab0e699d70b62865766ff52Svetoslav Ganov * with action {@link KeyEvent#ACTION_UP} with the additional flag
451cf70bbf96930662cab0e699d70b62865766ff52Svetoslav Ganov * {@link KeyEvent#FLAG_CANCELED}. To cancel a {@link MotionEvent} the handler
461cf70bbf96930662cab0e699d70b62865766ff52Svetoslav Ganov * has to send an event with action {@link MotionEvent#ACTION_CANCEL}.
471cf70bbf96930662cab0e699d70b62865766ff52Svetoslav Ganov *
481cf70bbf96930662cab0e699d70b62865766ff52Svetoslav Ganov * It is a responsibility of each handler that received a cancel event to clear its
491cf70bbf96930662cab0e699d70b62865766ff52Svetoslav Ganov * internal state and to propagate the event to the next one to enable subsequent
501cf70bbf96930662cab0e699d70b62865766ff52Svetoslav Ganov * transformations to clear their internal state.
511cf70bbf96930662cab0e699d70b62865766ff52Svetoslav Ganov *
521cf70bbf96930662cab0e699d70b62865766ff52Svetoslav Ganov * It is a responsibility for each transformation to start handling events only
531cf70bbf96930662cab0e699d70b62865766ff52Svetoslav Ganov * after an event that designates the start of a well-formed event sequence.
541cf70bbf96930662cab0e699d70b62865766ff52Svetoslav Ganov * For example, if it received a down motion event followed by a cancel motion
551cf70bbf96930662cab0e699d70b62865766ff52Svetoslav Ganov * event, it should not handle subsequent move and up events until it gets a down.
561cf70bbf96930662cab0e699d70b62865766ff52Svetoslav Ganov */
571cf70bbf96930662cab0e699d70b62865766ff52Svetoslav Ganovinterface EventStreamTransformation {
581cf70bbf96930662cab0e699d70b62865766ff52Svetoslav Ganov
591cf70bbf96930662cab0e699d70b62865766ff52Svetoslav Ganov    /**
60c4fccd183f1bb47a027bb303af5e65bec2f68b1bSvetoslav     * Receives a motion event. Passed are the event transformed by previous
6145af84a483165f06c04d74baba67f90da29c6ad2Svetoslav Ganov     * transformations and the raw event to which no transformations have
6245af84a483165f06c04d74baba67f90da29c6ad2Svetoslav Ganov     * been applied.
631cf70bbf96930662cab0e699d70b62865766ff52Svetoslav Ganov     *
6445af84a483165f06c04d74baba67f90da29c6ad2Svetoslav Ganov     * @param event The transformed motion event.
6545af84a483165f06c04d74baba67f90da29c6ad2Svetoslav Ganov     * @param rawEvent The raw motion event.
661cf70bbf96930662cab0e699d70b62865766ff52Svetoslav Ganov     * @param policyFlags Policy flags for the event.
671cf70bbf96930662cab0e699d70b62865766ff52Svetoslav Ganov     */
6845af84a483165f06c04d74baba67f90da29c6ad2Svetoslav Ganov    public void onMotionEvent(MotionEvent event, MotionEvent rawEvent, int policyFlags);
691cf70bbf96930662cab0e699d70b62865766ff52Svetoslav Ganov
701cf70bbf96930662cab0e699d70b62865766ff52Svetoslav Ganov    /**
711cf70bbf96930662cab0e699d70b62865766ff52Svetoslav Ganov     * Receives an accessibility event.
721cf70bbf96930662cab0e699d70b62865766ff52Svetoslav Ganov     *
731cf70bbf96930662cab0e699d70b62865766ff52Svetoslav Ganov     * @param event The accessibility event.
741cf70bbf96930662cab0e699d70b62865766ff52Svetoslav Ganov     */
751cf70bbf96930662cab0e699d70b62865766ff52Svetoslav Ganov    public void onAccessibilityEvent(AccessibilityEvent event);
761cf70bbf96930662cab0e699d70b62865766ff52Svetoslav Ganov
771cf70bbf96930662cab0e699d70b62865766ff52Svetoslav Ganov    /**
781cf70bbf96930662cab0e699d70b62865766ff52Svetoslav Ganov     * Sets the next transformation.
791cf70bbf96930662cab0e699d70b62865766ff52Svetoslav Ganov     *
801cf70bbf96930662cab0e699d70b62865766ff52Svetoslav Ganov     * @param next The next transformation.
811cf70bbf96930662cab0e699d70b62865766ff52Svetoslav Ganov     */
821cf70bbf96930662cab0e699d70b62865766ff52Svetoslav Ganov    public void setNext(EventStreamTransformation next);
831cf70bbf96930662cab0e699d70b62865766ff52Svetoslav Ganov
841cf70bbf96930662cab0e699d70b62865766ff52Svetoslav Ganov    /**
851cf70bbf96930662cab0e699d70b62865766ff52Svetoslav Ganov     * Clears the internal state of this transformation.
861cf70bbf96930662cab0e699d70b62865766ff52Svetoslav Ganov     */
871cf70bbf96930662cab0e699d70b62865766ff52Svetoslav Ganov    public void clear();
881cf70bbf96930662cab0e699d70b62865766ff52Svetoslav Ganov
891cf70bbf96930662cab0e699d70b62865766ff52Svetoslav Ganov    /**
901cf70bbf96930662cab0e699d70b62865766ff52Svetoslav Ganov     * Destroys this transformation.
911cf70bbf96930662cab0e699d70b62865766ff52Svetoslav Ganov     */
921cf70bbf96930662cab0e699d70b62865766ff52Svetoslav Ganov    public void onDestroy();
931cf70bbf96930662cab0e699d70b62865766ff52Svetoslav Ganov}
94