Home | History | Annotate | Download | only in internal
      1 /*
      2  * Copyright (C) 2014 The Android Open Source Project
      3  *
      4  * Licensed under the Apache License, Version 2.0 (the "License");
      5  * you may not use this file except in compliance with the License.
      6  * You may obtain a copy of the License at
      7  *
      8  *      http://www.apache.org/licenses/LICENSE-2.0
      9  *
     10  * Unless required by applicable law or agreed to in writing, software
     11  * distributed under the License is distributed on an "AS IS" BASIS,
     12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13  * See the License for the specific language governing permissions and
     14  * limitations under the License.
     15  */
     16 
     17 package com.android.inputmethod.keyboard.internal;
     18 
     19 import com.android.inputmethod.keyboard.Key;
     20 import com.android.inputmethod.keyboard.PointerTracker;
     21 
     22 import javax.annotation.Nonnull;
     23 
     24 public interface TimerProxy {
     25     /**
     26      * Start a timer to detect if a user is typing keys.
     27      * @param typedKey the key that is typed.
     28      */
     29     public void startTypingStateTimer(@Nonnull Key typedKey);
     30 
     31     /**
     32      * Check if a user is key typing.
     33      * @return true if a user is in typing.
     34      */
     35     public boolean isTypingState();
     36 
     37     /**
     38      * Start a timer to simulate repeated key presses while a user keep pressing a key.
     39      * @param tracker the {@link PointerTracker} that points the key to be repeated.
     40      * @param repeatCount the number of times that the key is repeating. Starting from 1.
     41      * @param delay the interval delay to the next key repeat, in millisecond.
     42      */
     43     public void startKeyRepeatTimerOf(@Nonnull PointerTracker tracker, int repeatCount, int delay);
     44 
     45     /**
     46      * Start a timer to detect a long pressed key.
     47      * If a key pointed by <code>tracker</code> is a shift key, start another timer to detect
     48      * long pressed shift key.
     49      * @param tracker the {@link PointerTracker} that starts long pressing.
     50      * @param delay the delay to fire the long press timer, in millisecond.
     51      */
     52     public void startLongPressTimerOf(@Nonnull PointerTracker tracker, int delay);
     53 
     54     /**
     55      * Cancel timers for detecting a long pressed key and a long press shift key.
     56      * @param tracker cancel long press timers of this {@link PointerTracker}.
     57      */
     58     public void cancelLongPressTimersOf(@Nonnull PointerTracker tracker);
     59 
     60     /**
     61      * Cancel a timer for detecting a long pressed shift key.
     62      */
     63     public void cancelLongPressShiftKeyTimer();
     64 
     65     /**
     66      * Cancel timers for detecting repeated key press, long pressed key, and long pressed shift key.
     67      * @param tracker the {@link PointerTracker} that starts timers to be canceled.
     68      */
     69     public void cancelKeyTimersOf(@Nonnull PointerTracker tracker);
     70 
     71     /**
     72      * Start a timer to detect double tapped shift key.
     73      */
     74     public void startDoubleTapShiftKeyTimer();
     75 
     76     /**
     77      * Cancel a timer of detecting double tapped shift key.
     78      */
     79     public void cancelDoubleTapShiftKeyTimer();
     80 
     81     /**
     82      * Check if a timer of detecting double tapped shift key is running.
     83      * @return true if detecting double tapped shift key is on going.
     84      */
     85     public boolean isInDoubleTapShiftKeyTimeout();
     86 
     87     /**
     88      * Start a timer to fire updating batch input while <code>tracker</code> is on hold.
     89      * @param tracker the {@link PointerTracker} that stops moving.
     90      */
     91     public void startUpdateBatchInputTimer(@Nonnull PointerTracker tracker);
     92 
     93     /**
     94      * Cancel a timer of firing updating batch input.
     95      * @param tracker the {@link PointerTracker} that resumes moving or ends gesture input.
     96      */
     97     public void cancelUpdateBatchInputTimer(@Nonnull PointerTracker tracker);
     98 
     99     /**
    100      * Cancel all timers of firing updating batch input.
    101      */
    102     public void cancelAllUpdateBatchInputTimers();
    103 
    104     public static class Adapter implements TimerProxy {
    105         @Override
    106         public void startTypingStateTimer(@Nonnull Key typedKey) {}
    107         @Override
    108         public boolean isTypingState() { return false; }
    109         @Override
    110         public void startKeyRepeatTimerOf(@Nonnull PointerTracker tracker, int repeatCount,
    111                 int delay) {}
    112         @Override
    113         public void startLongPressTimerOf(@Nonnull PointerTracker tracker, int delay) {}
    114         @Override
    115         public void cancelLongPressTimersOf(@Nonnull PointerTracker tracker) {}
    116         @Override
    117         public void cancelLongPressShiftKeyTimer() {}
    118         @Override
    119         public void cancelKeyTimersOf(@Nonnull PointerTracker tracker) {}
    120         @Override
    121         public void startDoubleTapShiftKeyTimer() {}
    122         @Override
    123         public void cancelDoubleTapShiftKeyTimer() {}
    124         @Override
    125         public boolean isInDoubleTapShiftKeyTimeout() { return false; }
    126         @Override
    127         public void startUpdateBatchInputTimer(@Nonnull PointerTracker tracker) {}
    128         @Override
    129         public void cancelUpdateBatchInputTimer(@Nonnull PointerTracker tracker) {}
    130         @Override
    131         public void cancelAllUpdateBatchInputTimers() {}
    132     }
    133 }
    134