• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2013 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.latin.utils;
18 
19 import android.text.TextUtils;
20 
21 import com.android.inputmethod.latin.Constants;
22 import com.android.inputmethod.latin.LatinImeLogger;
23 import com.android.inputmethod.latin.WordComposer;
24 
25 public final class LatinImeLoggerUtils {
LatinImeLoggerUtils()26     private LatinImeLoggerUtils() {
27         // This utility class is not publicly instantiable.
28     }
29 
onNonSeparator(final char code, final int x, final int y)30     public static void onNonSeparator(final char code, final int x, final int y) {
31         UserLogRingCharBuffer.getInstance().push(code, x, y);
32         LatinImeLogger.logOnInputChar();
33     }
34 
onSeparator(final int code, final int x, final int y)35     public static void onSeparator(final int code, final int x, final int y) {
36         // Helper method to log a single code point separator
37         // TODO: cache this mapping of a code point to a string in a sparse array in StringUtils
38         onSeparator(new String(new int[]{code}, 0, 1), x, y);
39     }
40 
onSeparator(final String separator, final int x, final int y)41     public static void onSeparator(final String separator, final int x, final int y) {
42         final int length = separator.length();
43         for (int i = 0; i < length; i = Character.offsetByCodePoints(separator, i, 1)) {
44             int codePoint = Character.codePointAt(separator, i);
45             // TODO: accept code points
46             UserLogRingCharBuffer.getInstance().push((char)codePoint, x, y);
47         }
48         LatinImeLogger.logOnInputSeparator();
49     }
50 
onAutoCorrection(final String typedWord, final String correctedWord, final String separatorString, final WordComposer wordComposer)51     public static void onAutoCorrection(final String typedWord, final String correctedWord,
52             final String separatorString, final WordComposer wordComposer) {
53         final boolean isBatchMode = wordComposer.isBatchMode();
54         if (!isBatchMode && TextUtils.isEmpty(typedWord)) {
55             return;
56         }
57         // TODO: this fails when the separator is more than 1 code point long, but
58         // the backend can't handle it yet. The only case when this happens is with
59         // smileys and other multi-character keys.
60         final int codePoint = TextUtils.isEmpty(separatorString) ? Constants.NOT_A_CODE
61                 : separatorString.codePointAt(0);
62         if (!isBatchMode) {
63             LatinImeLogger.logOnAutoCorrectionForTyping(typedWord, correctedWord, codePoint);
64         } else {
65             if (!TextUtils.isEmpty(correctedWord)) {
66                 // We must make sure that InputPointer contains only the relative timestamps,
67                 // not actual timestamps.
68                 LatinImeLogger.logOnAutoCorrectionForGeometric(
69                         "", correctedWord, codePoint, wordComposer.getInputPointers());
70             }
71         }
72     }
73 
onAutoCorrectionCancellation()74     public static void onAutoCorrectionCancellation() {
75         LatinImeLogger.logOnAutoCorrectionCancelled();
76     }
77 }
78