satok | 8fbd552 | 2011-02-22 17:28:55 +0900 | [diff] [blame] | 1 | /* |
| 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 | |
satok | 817e517 | 2011-03-04 06:06:45 -0800 | [diff] [blame] | 20 | #define LOG_TAG "LatinIME: proximity_info.cpp" |
| 21 | |
satok | 8fbd552 | 2011-02-22 17:28:55 +0900 | [diff] [blame] | 22 | #include "proximity_info.h" |
| 23 | |
| 24 | namespace latinime { |
Ken Wakasa | ce9e52a | 2011-06-18 13:09:55 +0900 | [diff] [blame^] | 25 | |
satok | 817e517 | 2011-03-04 06:06:45 -0800 | [diff] [blame] | 26 | ProximityInfo::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])); |
satok | 8fbd552 | 2011-02-22 17:28:55 +0900 | [diff] [blame] | 39 | } |
| 40 | |
| 41 | ProximityInfo::~ProximityInfo() { |
| 42 | delete[] mProximityCharsArray; |
| 43 | } |
satok | 817e517 | 2011-03-04 06:06:45 -0800 | [diff] [blame] | 44 | |
| 45 | inline int ProximityInfo::getStartIndexFromCoordinates(const int x, const int y) const { |
satok | 3c4bb77 | 2011-03-04 22:50:19 -0800 | [diff] [blame] | 46 | return ((y / CELL_HEIGHT) * GRID_WIDTH + (x / CELL_WIDTH)) |
satok | 817e517 | 2011-03-04 06:06:45 -0800 | [diff] [blame] | 47 | * MAX_PROXIMITY_CHARS_SIZE; |
satok | 8fbd552 | 2011-02-22 17:28:55 +0900 | [diff] [blame] | 48 | } |
satok | 817e517 | 2011-03-04 06:06:45 -0800 | [diff] [blame] | 49 | |
| 50 | bool 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 Wakasa | ce9e52a | 2011-06-18 13:09:55 +0900 | [diff] [blame^] | 65 | |
| 66 | } // namespace latinime |