blob: 5f2d09f5cc18dac39600b838b6e179e2b92630a8 [file] [log] [blame]
satok8fbd5522011-02-22 17:28:55 +09001/*
2 * Copyright (C) 2011 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#include <stdio.h>
18#include <string.h>
19
satok817e5172011-03-04 06:06:45 -080020#define LOG_TAG "LatinIME: proximity_info.cpp"
21
satok8fbd5522011-02-22 17:28:55 +090022#include "proximity_info.h"
23
24namespace latinime {
satok817e5172011-03-04 06:06:45 -080025ProximityInfo::ProximityInfo(const int maxProximityCharsSize, const int keyboardWidth,
26 const int keyboardHeight, const int gridWidth, const int gridHeight,
27 const uint32_t *proximityCharsArray)
28 : MAX_PROXIMITY_CHARS_SIZE(maxProximityCharsSize), KEYBOARD_WIDTH(keyboardWidth),
29 KEYBOARD_HEIGHT(keyboardHeight), GRID_WIDTH(gridWidth), GRID_HEIGHT(gridHeight),
30 CELL_WIDTH((keyboardWidth + gridWidth - 1) / gridWidth),
31 CELL_HEIGHT((keyboardHeight + gridHeight - 1) / gridHeight) {
32 const int len = GRID_WIDTH * GRID_HEIGHT * MAX_PROXIMITY_CHARS_SIZE;
33 mProximityCharsArray = new uint32_t[len];
34 if (DEBUG_PROXIMITY_INFO) {
35 LOGI("Create proximity info array %d", len);
36 }
37 memcpy(mProximityCharsArray, proximityCharsArray, len * sizeof(mProximityCharsArray[0]));
satok8fbd5522011-02-22 17:28:55 +090038}
39
40ProximityInfo::~ProximityInfo() {
41 delete[] mProximityCharsArray;
42}
satok817e5172011-03-04 06:06:45 -080043
44inline int ProximityInfo::getStartIndexFromCoordinates(const int x, const int y) const {
45 return (y / CELL_HEIGHT) * GRID_WIDTH + (x / CELL_WIDTH)
46 * MAX_PROXIMITY_CHARS_SIZE;
satok8fbd5522011-02-22 17:28:55 +090047}
satok817e5172011-03-04 06:06:45 -080048
49bool ProximityInfo::hasSpaceProximity(const int x, const int y) const {
50 const int startIndex = getStartIndexFromCoordinates(x, y);
51 if (DEBUG_PROXIMITY_INFO) {
52 LOGI("hasSpaceProximity: index %d", startIndex);
53 }
54 for (int i = 0; i < MAX_PROXIMITY_CHARS_SIZE; ++i) {
55 if (DEBUG_PROXIMITY_INFO) {
56 LOGI("Index: %d", mProximityCharsArray[startIndex + i]);
57 }
58 if (mProximityCharsArray[startIndex + i] == KEYCODE_SPACE) {
59 return true;
60 }
61 }
62 return false;
63}
64} // namespace latinime