Home | History | Annotate | Download | only in event
      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.event;
     18 
     19 import com.android.inputmethod.latin.settings.SettingsValues;
     20 
     21 /**
     22  * An object encapsulating a single transaction for input.
     23  */
     24 public class InputTransaction {
     25     // UPDATE_LATER is stronger than UPDATE_NOW. The reason for this is, if we have to update later,
     26     // it's because something will change that we can't evaluate now, which means that even if we
     27     // re-evaluate now we'll have to do it again later. The only case where that wouldn't apply
     28     // would be if we needed to update now to find out the new state right away, but then we
     29     // can't do it with this deferred mechanism anyway.
     30     public static final int SHIFT_NO_UPDATE = 0;
     31     public static final int SHIFT_UPDATE_NOW = 1;
     32     public static final int SHIFT_UPDATE_LATER = 2;
     33 
     34     // Initial conditions
     35     public final SettingsValues mSettingsValues;
     36     public final Event mEvent;
     37     public final long mTimestamp;
     38     public final int mSpaceState;
     39     public final int mShiftState;
     40 
     41     // Outputs
     42     private int mRequiredShiftUpdate = SHIFT_NO_UPDATE;
     43     private boolean mRequiresUpdateSuggestions = false;
     44     private boolean mDidAffectContents = false;
     45     private boolean mDidAutoCorrect = false;
     46 
     47     public InputTransaction(final SettingsValues settingsValues, final Event event,
     48             final long timestamp, final int spaceState, final int shiftState) {
     49         mSettingsValues = settingsValues;
     50         mEvent = event;
     51         mTimestamp = timestamp;
     52         mSpaceState = spaceState;
     53         mShiftState = shiftState;
     54     }
     55 
     56     /**
     57      * Indicate that this transaction requires some type of shift update.
     58      * @param updateType What type of shift update this requires.
     59      */
     60     public void requireShiftUpdate(final int updateType) {
     61         mRequiredShiftUpdate = Math.max(mRequiredShiftUpdate, updateType);
     62     }
     63 
     64     /**
     65      * Gets what type of shift update this transaction requires.
     66      * @return The shift update type.
     67      */
     68     public int getRequiredShiftUpdate() {
     69         return mRequiredShiftUpdate;
     70     }
     71 
     72     /**
     73      * Indicate that this transaction requires updating the suggestions.
     74      */
     75     public void setRequiresUpdateSuggestions() {
     76         mRequiresUpdateSuggestions = true;
     77     }
     78 
     79     /**
     80      * Find out whether this transaction requires updating the suggestions.
     81      * @return Whether this transaction requires updating the suggestions.
     82      */
     83     public boolean requiresUpdateSuggestions() {
     84         return mRequiresUpdateSuggestions;
     85     }
     86 
     87     /**
     88      * Indicate that this transaction affected the contents of the editor.
     89      */
     90     public void setDidAffectContents() {
     91         mDidAffectContents = true;
     92     }
     93 
     94     /**
     95      * Find out whether this transaction affected contents of the editor.
     96      * @return Whether this transaction affected contents of the editor.
     97      */
     98     public boolean didAffectContents() {
     99         return mDidAffectContents;
    100     }
    101 
    102     /**
    103      * Indicate that this transaction performed an auto-correction.
    104      */
    105     public void setDidAutoCorrect() {
    106         mDidAutoCorrect = true;
    107     }
    108 
    109     /**
    110      * Find out whether this transaction performed an auto-correction.
    111      * @return Whether this transaction performed an auto-correction.
    112      */
    113     public boolean didAutoCorrect() {
    114         return mDidAutoCorrect;
    115     }
    116 }
    117