1 /* 2 * Copyright (C) 2010 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 18 package com.replica.replicaisland; 19 20 21 import android.view.KeyEvent; 22 23 public class InputKeyboard { 24 private InputButton[] mKeys; 25 26 public InputKeyboard() { 27 final int count = KeyEvent.getMaxKeyCode(); 28 mKeys = new InputButton[count]; 29 for (int x = 0; x < count; x++) { 30 mKeys[x] = new InputButton(); 31 } 32 } 33 34 public void press(float currentTime, int keycode) { 35 assert keycode >= 0 && keycode < mKeys.length; 36 if (keycode >= 0 && keycode < mKeys.length){ 37 mKeys[keycode].press(currentTime, 1.0f); 38 } 39 } 40 41 public void release(int keycode) { 42 assert keycode >= 0 && keycode < mKeys.length; 43 if (keycode >= 0 && keycode < mKeys.length){ 44 mKeys[keycode].release(); 45 } 46 } 47 48 public void releaseAll() { 49 final int count = mKeys.length; 50 for (int x = 0; x < count; x++) { 51 mKeys[x].release(); 52 } 53 } 54 55 public InputButton[] getKeys() { 56 return mKeys; 57 } 58 59 public void resetAll() { 60 final int count = mKeys.length; 61 for (int x = 0; x < count; x++) { 62 mKeys[x].reset(); 63 } 64 } 65 } 66