// Copyright 2001-2005, Danger, Inc.  All Rights Reserved.
// This file is subject to the Danger, Inc. Sample Code License,
// which is provided in the file SAMPLE_CODE_LICENSE.
// Copies are also available from http://developer.danger.com/

package com.example.GUIDemo;

import danger.app.Application;
import danger.app.Event;
import danger.ui.TextInputAlertWindow;

/**
 * LRTextInputAlertWindow: This is a subclass to allow for an improvement to the
 * TextInputAlertWindow UI, while showing the standard use of the class.
 * 
 * The addition is to add in the Previous/Next function to the dialog when
 * created, so that it is easy to cycle through all the available elements. It
 * won't add actual buttons to the windows, because that confuses the demo and
 * changes the focus order in bad ways. For example, a TextEdit click upon done
 * moves to the next button, which should be Go Ahead. With buttons, it would go
 * to Previous.
 * 
 * Rather than have buttons, this will simply handle the widget events in an
 * invisible fashion, because it's part of this demo program as a convenience,
 * not part of the dialogs.
 * 
 * This also allows for keeping the resource definitions small and concise for
 * the actual widgets themselves. The goal is to keep the resource definitions
 * simple to understand and use.
 * 
 */

public class LRTextInputAlertWindow extends TextInputAlertWindow implements
		Resources, Commands {

	private static GUIDemo sApplication = (GUIDemo) Application.getCurrentApp();

	// This default constructor is required by the DRC in order to support the
	// override ability. Unfortunately, under 2.0, there is no default
	// constructor
	// in the superclass. Therefore, call one of the other constructors with the
	// empty title parameter. The title will still come from the resource file.
	// Under 2.3 this still works, but is unnecessary.
	public LRTextInputAlertWindow() {
		super("");
	}

	public LRTextInputAlertWindow(int arg0, String arg1, boolean arg2) {
		super(arg0, arg1, arg2);
	}

	public LRTextInputAlertWindow(int arg0, String arg1) {
		super(arg0, arg1);
	}

	public LRTextInputAlertWindow(String arg1) {
		super(arg1);
	}

	/**
	 * Handle the up events for the shoulder buttons. First, hide the top
	 * window, which will be the current demostration dialog.
	 * 
	 * For Left-Shoulder, send the EVENT_PREVIOUS, for Right-Shoulder send the
	 * EVENT_NEXT. That will be handled by the current ScreenWindow, either
	 * ResourceWindow, or ProgramWindow and move into the next dialog.
	 */
	public boolean eventWidgetUp(int whichWidget, Event arg1) {
		Event newEvent;

		switch (whichWidget) {
		case Event.DEVICE_BUTTON_LEFT_SHOULDER:
			hide();
			newEvent = new Event(sApplication.getFrontScreenWindow(),
					EVENT_PREVIOUS);
			newEvent.sendToTarget();
			return true;
		case Event.DEVICE_BUTTON_RIGHT_SHOULDER:
			hide();
			newEvent = new Event(sApplication.getFrontScreenWindow(),
					EVENT_NEXT);
			newEvent.sendToTarget();
			return true;
		}

		return super.eventWidgetUp(whichWidget, arg1);
	}
}
