//#preprocess
package com.mmtechco.surface.monitor;

import com.mmtechco.surface.Surface;
import com.mmtechco.surface.ui.KeypadLockScreen;
import com.mmtechco.util.Logger;
import com.mmtechco.util.ToolsBB;

import net.rim.device.api.system.KeyListener;
import net.rim.device.api.ui.Keypad;
import net.rim.device.api.ui.Screen;
import net.rim.device.api.ui.Ui;
import net.rim.device.api.ui.UiEngine;

public final class LockKeyListener implements KeyListener {
	private static final String TAG = ToolsBB
			.getSimpleClassName(LockKeyListener.class);
	private static Logger logger = Logger.getInstance();
	
	private int lastTime;

	public boolean keyChar(char key, int status, int time) {
		return false;
	}

	public boolean keyDown(int keycode, int time) {
		if (Keypad.key(keycode) == Keypad.KEY_VOLUME_UP) {
			logger.log(TAG, "Volume key caught. Last time: " + lastTime + " Current time: " + time);
			// Continue if second press is within a second
			if (time - lastTime < 1000) {
				logger.log(TAG, "Pushing lockscreen");
				//#ifdef TOUCH
				Screen lockscreen = new TouchLockScreen();
				//#else
				Screen lockscreen = new KeypadLockScreen();
				//#endif
				Ui.getUiEngine().pushGlobalScreen(lockscreen,
						Surface.SCREEN_PRIORITY_LOCKSCREEN,
						UiEngine.GLOBAL_SHOW_LOWER);
			}
			lastTime = time;
			// Consume event
			return true;
		}
		return false;
	}

	public boolean keyRepeat(int keycode, int time) {
		return false;
	}

	public boolean keyStatus(int keycode, int time) {
		return false;
	}

	public boolean keyUp(int keycode, int time) {
		return false;
	}
}
@@ -83,16 +83,58 @@
 urface;%0A
+import com.mmtechco.surface.net.Messager;%0A
 import c
@@ -170,24 +170,24 @@
 LockScreen;%0A
-
 import com.m
@@ -876,19 +876,18 @@
 ume 
-key
+up
  caught.
  Las
@@ -886,59 +886,9 @@
 ght.
- Last time: %22 + lastTime + %22 Current time: %22 + time
+%22
 );%0A%09
@@ -1243,16 +1243,16 @@
 SCREEN,%0A
-
 %09%09%09%09%09%09Ui
@@ -1343,16 +1343,372 @@
 ue;%0A%09%09%7D%0A
+%09%09else if (Keypad.key(keycode) == Keypad.KEY_VOLUME_DOWN) %7B%0A%09%09%09logger.log(TAG, %22Volume down caught.%22);%0A%09%09%09// Continue if second press is within a second%0A%09%09%09if (time - lastTime %3C 1000) %7B%0A%09%09%09%09logger.log(TAG, %22Sending Alert%22);%0A%09%09%09%09Messager.sendMessage(Messager.type_alert, %22Sending Alert...%22);%0A%09%09%09%7D%0A%09%09%09lastTime = time;%0A%09%09%09// Consume event%0A%09%09%09return true;%0A%09%09%7D%0A
 %09%09return

Send Alert on double-tap of volume down key