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 18package com.replica.replicaisland; 19 20public class InputButton { 21 private boolean mDown; 22 private float mLastPressedTime; 23 private float mDownTime; 24 private float mMagnitude; 25 26 public void press(float currentTime, float magnitude) { 27 if (!mDown) { 28 mDown = true; 29 mDownTime = currentTime; 30 } 31 mMagnitude = magnitude; 32 mLastPressedTime = currentTime; 33 } 34 35 public void release() { 36 mDown = false; 37 } 38 39 public final boolean getPressed() { 40 return mDown; 41 } 42 43 public final boolean getTriggered(float currentTime) { 44 return mDown && currentTime - mDownTime <= BaseObject.sSystemRegistry.timeSystem.getFrameDelta() * 2.0f; 45 } 46 47 public final float getPressedDuration(float currentTime) { 48 return currentTime - mDownTime; 49 } 50 51 public final float getLastPressedTime() { 52 return mLastPressedTime; 53 } 54 55 public final float getMagnitude() { 56 float magnitude = 0.0f; 57 if (mDown) { 58 magnitude = mMagnitude; 59 } 60 return magnitude; 61 } 62 63 public final void setMagnitude(float magnitude) { 64 mMagnitude = magnitude; 65 } 66 67 public final void reset() { 68 mDown = false; 69 mMagnitude = 0.0f; 70 mLastPressedTime = 0.0f; 71 mDownTime = 0.0f; 72 } 73} 74