/*
 * Copyright (C) 2009 JavaRosa
 *
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
 * use this file except in compliance with the License. You may obtain a copy of
 * the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 * License for the specific language governing permissions and limitations under
 * the License.
 */

package org.javarosa.formmanager.view.transport;

import javax.microedition.lcdui.Choice;
import javax.microedition.lcdui.ChoiceGroup;
import javax.microedition.lcdui.CommandListener;
import javax.microedition.lcdui.Form;
import javax.microedition.lcdui.ItemStateListener;
import javax.microedition.lcdui.Spacer;

import org.javarosa.core.services.locale.Localization;

public class SendNowSendLaterForm extends Form {
	private ChoiceGroup cg;

	public static final int SEND_NOW_DEFAULT = 0;
	public static final int SEND_LATER = 1;
	public static final int SEND_NOW_SPEC = 2;

	public SendNowSendLaterForm(CommandListener activity, ItemStateListener itemListener) {
		//#style submitPopup
		super(Localization.get("sending.view.submit"));

		//#style submitYesNo
		this.cg = new ChoiceGroup(Localization.get("sending.view.when"), Choice.EXCLUSIVE);

		// NOTE! These Indexes are optimized to be added in a certain
		// order. _DO NOT_ change it without updating the static values
		// for their numerical order.
		this.cg.append(Localization.get("sending.view.now"), null);
		this.cg.append(Localization.get("sending.view.later"), null);
		

		//TODO: Add this back in for admin users. Who took it out?
		//this.cg.append(Locale.get("sending.view.new"), null);// clients wont need to
		// see
		// this

		append(this.cg);

		append(new Spacer(80, 0));

		setCommandListener(activity);
		setItemStateListener(itemListener);
	}

	public int getCommandChoice() {
		return this.cg.getSelectedIndex();
	}

}

@@ -776,46 +776,8 @@
 er;%0A
-import javax.microedition.lcdui.Form;%0A
 impo
@@ -918,16 +918,56 @@
 ization;
+%0A%0Aimport de.enough.polish.ui.FramedForm;
 %0A%0D%0Apubli
@@ -1003,16 +1003,22 @@
 extends 
+Framed
 Form %7B%0D%0A
@@ -1043,16 +1043,59 @@
 up cg;%0D%0A
+%0A%09private boolean seenKeyPressed = false;%0A%09
 %0D%0A%09publi
@@ -2177,15 +2177,487 @@
 x();%0D%0A%09%7D
-%0D
 %0A
+%09%0A%09// fix bug in polish 2.1.0 (and possibly earlier) where keydown event answers the last question%0A%09// in the form, and the keyup event from the same button press is passed to this view, automatically%0A%09// selecting 'send now'%0A%09//%0A    public void keyPressed(int keyCode) %7B%0A    %09super.keyPressed(keyCode);%0A    %09seenKeyPressed = true;%0A    %7D%0A    //%0A    public void keyReleased(int keyCode) %7B%0A    %09if (seenKeyPressed) %7B%0A    %09%09super.keyReleased(keyCode);%0A    %09%7D%0A    %7D%0D%0A    //////
 %0D%0A%7D%0D%0A

fix keypress bug where "send now" is automatically selected