InputTransaction.java revision 6345562e2b351221a9bc0341f7dbd26095290b64
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 17package com.android.inputmethod.event; 18 19import com.android.inputmethod.latin.settings.SettingsValues; 20 21/** 22 * An object encapsulating a single transaction for input. 23 */ 24public 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 46 public InputTransaction(final SettingsValues settingsValues, final Event event, 47 final long timestamp, final int spaceState, final int shiftState) { 48 mSettingsValues = settingsValues; 49 mEvent = event; 50 mTimestamp = timestamp; 51 mSpaceState = spaceState; 52 mShiftState = shiftState; 53 } 54 55 /** 56 * Indicate that this transaction requires some type of shift update. 57 * @param updateType What type of shift update this requires. 58 */ 59 public void requireShiftUpdate(final int updateType) { 60 mRequiredShiftUpdate = Math.max(mRequiredShiftUpdate, updateType); 61 } 62 63 /** 64 * Gets what type of shift update this transaction requires. 65 * @return The shift update type. 66 */ 67 public int getRequiredShiftUpdate() { 68 return mRequiredShiftUpdate; 69 } 70 71 /** 72 * Indicate that this transaction requires updating the suggestions. 73 */ 74 public void setRequiresUpdateSuggestions() { 75 mRequiresUpdateSuggestions = true; 76 } 77 78 /** 79 * Find out whether this transaction requires updating the suggestions. 80 * @return Whether this transaction requires updating the suggestions. 81 */ 82 public boolean requiresUpdateSuggestions() { 83 return mRequiresUpdateSuggestions; 84 } 85 86 /** 87 * Indicate that this transaction affected the contents of the editor. 88 */ 89 public void setDidAffectContents() { 90 mDidAffectContents = true; 91 } 92 93 /** 94 * Find out whether this transaction affected contents of the editor. 95 * @return Whether this transaction affected contents of the editor. 96 */ 97 public boolean didAffectContents() { 98 return mDidAffectContents; 99 } 100} 101