blob: 209c31e6e64254e79249852908edf86deab8a0ec [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 {
Ken Wakasace9e52a2011-06-18 13:09:55 +090025
satok817e5172011-03-04 06:06:45 -080026ProximityInfo::ProximityInfo(const int maxProximityCharsSize, const int keyboardWidth,
27 const int keyboardHeight, const int gridWidth, const int gridHeight,
28 const uint32_t *proximityCharsArray)
29 : MAX_PROXIMITY_CHARS_SIZE(maxProximityCharsSize), KEYBOARD_WIDTH(keyboardWidth),
30 KEYBOARD_HEIGHT(keyboardHeight), GRID_WIDTH(gridWidth), GRID_HEIGHT(gridHeight),
31 CELL_WIDTH((keyboardWidth + gridWidth - 1) / gridWidth),
32 CELL_HEIGHT((keyboardHeight + gridHeight - 1) / gridHeight) {
33 const int len = GRID_WIDTH * GRID_HEIGHT * MAX_PROXIMITY_CHARS_SIZE;
34 mProximityCharsArray = new uint32_t[len];
35 if (DEBUG_PROXIMITY_INFO) {
36 LOGI("Create proximity info array %d", len);
37 }
38 memcpy(mProximityCharsArray, proximityCharsArray, len * sizeof(mProximityCharsArray[0]));
satok8fbd5522011-02-22 17:28:55 +090039}
40
41ProximityInfo::~ProximityInfo() {
42 delete[] mProximityCharsArray;
43}
satok817e5172011-03-04 06:06:45 -080044
45inline int ProximityInfo::getStartIndexFromCoordinates(const int x, const int y) const {
satok3c4bb772011-03-04 22:50:19 -080046 return ((y / CELL_HEIGHT) * GRID_WIDTH + (x / CELL_WIDTH))
satok817e5172011-03-04 06:06:45 -080047 * MAX_PROXIMITY_CHARS_SIZE;
satok8fbd5522011-02-22 17:28:55 +090048}
satok817e5172011-03-04 06:06:45 -080049
50bool ProximityInfo::hasSpaceProximity(const int x, const int y) const {
51 const int startIndex = getStartIndexFromCoordinates(x, y);
52 if (DEBUG_PROXIMITY_INFO) {
53 LOGI("hasSpaceProximity: index %d", startIndex);
54 }
55 for (int i = 0; i < MAX_PROXIMITY_CHARS_SIZE; ++i) {
56 if (DEBUG_PROXIMITY_INFO) {
57 LOGI("Index: %d", mProximityCharsArray[startIndex + i]);
58 }
59 if (mProximityCharsArray[startIndex + i] == KEYCODE_SPACE) {
60 return true;
61 }
62 }
63 return false;
64}
Ken Wakasace9e52a2011-06-18 13:09:55 +090065
66} // namespace latinime