package org.javarosa.demo.util;

import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.CommandListener;
import javax.microedition.lcdui.Form;
import javax.microedition.lcdui.Gauge;

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


public class ProgressScreenFormDownload extends Form{
	
	private Gauge progressbar;
	private Thread updater_T;
	public final Command CMD_CANCEL = new Command(Localization.get("polish.command.cancel"),Command.BACK, 1);
	public final Command CMD_RETRY = new Command(Localization.get("menu.retry"),Command.ITEM, 1);

	public ProgressScreenFormDownload(String title,String  msg,CommandListener cmdListener) {
		//#style capturingPopup
		super(title);
		//#style capturingGauge
		progressbar = new Gauge(msg, false, Gauge.INDEFINITE, Gauge.CONTINUOUS_RUNNING );

		addCommand(CMD_CANCEL);
		append(progressbar);
		setCommandListener(cmdListener);
		
		// TODO if this is ever an incremental progress bar, put this back in?
		// updater_T = new HandledThread(new GaugeUpdater());
		// updater_T.start();
	}
	
	public void setText(String text) {
		progressbar.setLabel(text);
	}
	
	public void stopProgressBar(){
		progressbar.setValue(Gauge.CONTINUOUS_IDLE);
	}
	
	public void startProgressBar(){
		progressbar.setValue(Gauge.CONTINUOUS_RUNNING);
	}
	
	public void closeThread(){
		if(updater_T!=null){
			updater_T = null;			
		}
	}
	
	class GaugeUpdater implements Runnable {
		
		public void run() {

			int i = 0;
			while (progressbar.getValue() < progressbar.getMaxValue()) {
				
				try {
					Thread.sleep(500);
				} catch (InterruptedException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
				
				//i++;
			//	progressbar.setValue(progressbar.getValue()+(i%2)*2);
			}

		}
	}

	
}
	
@@ -67,16 +67,24 @@
 .Command
+Listener
 ;%0D%0Aimpor
@@ -114,484 +114,180 @@
 dui.
-CommandListener;%0D%0Aimport javax.microedition.lcdui.Form;%0D%0Aimport javax.microedition.lcdui.Gauge;%0D%0A%0D%0Aimport org.javarosa.core.services.locale.Localization;%0D%0A%0D%0A%0D%0Apublic class ProgressScreenFormDownload extends Form%7B%0D%0A%09%0D%0A%09private Gauge progressbar;%0D%0A%09private Thread updater_T;%0D%0A%09public final Command CMD_CANCEL = new Command(Localization.get(%22polish.command.cancel%22),Command.BACK, 1);%0D%0A%09public final Command CMD_RETRY = new Command(Localization.get(%22menu.retry%22),Command.ITEM, 1);
+Gauge;%0D%0A%0D%0Aimport org.javarosa.formmanager.view.ProgressScreen;%0D%0A%0D%0Aimport de.enough.polish.ui.UiAccess;%0D%0A%0D%0A%0D%0Apublic class ProgressScreenFormDownload extends ProgressScreen %7B
 %0D%0A%0D%0A
@@ -338,20 +338,21 @@
 tle,
+ 
 String 
- 
 msg,
+ 
 Comm
@@ -385,1168 +385,350 @@
 %0D%0A%09%09
-//#style capturingPopup%0D%0A%09%09super(title);%0D%0A%09%09//#style capturingGauge%0D%0A%09%09progressbar = new Gauge(msg, false, Gauge.INDEFINITE, Gauge.CONTINUOUS_RUNNING );%0D%0A%0D%0A%09%09addCommand(CMD_CANCEL);%0D%0A%09%09append(progressbar);%0D%0A%09%09setCommandListener(cmdListener);%0D%0A%09%09%0D%0A%09%09// TODO if this is ever an incremental progress bar, put this back in?%0D%0A%09%09// updater_T = new HandledThread(new GaugeUpdater());%0D%0A%09%09// updater_T.start();%0D%0A%09%7D%0D%0A%09%0D%0A%09public void setText(String text) %7B%0D%0A%09%09progressbar.setLabel(text);%0D%0A%09%7D%0D%0A%09%0D%0A%09public void stopProgressBar()%7B%0D%0A%09%09progressbar.setValue(Gauge.CONTINUOUS_IDLE);%0D%0A%09%7D%0D%0A%09%0D%0A%09public void startProgressBar()%7B%0D%0A%09%09progressbar.setValue(Gauge.CONTINUOUS_RUNNING);%0D%0A%09%7D%0D%0A%09%0D%0A%09public void closeThread()%7B%0D%0A%09%09if(updater_T!=null)%7B%0D%0A%09%09%09updater_T = null;%09%09%09%0D%0A%09%09%7D%0D%0A%09%7D%0D%0A%09%0D%0A%09class GaugeUpdater implements Runnable %7B%0D%0A%09%09%0D%0A%09%09public void run() %7B%0D%0A%0D%0A%09%09%09int i = 0;%0D%0A%09%09%09while (progressbar.getValue() %3C progressbar.getMaxValue()) %7B%0D%0A%09%09%09%09%0D%0A%09%09%09%09try %7B%0D%0A%09%09%09%09%09Thread.sleep(500);%0D%0A%09%09%09%09%7D catch (InterruptedException e) %7B%0D%0A%09%09%09%09%09// TODO Auto-generated catch block%0D%0A%09%09%09%09%09e.printStackTrace();%0D%0A%09%09%09%09%7D%0D%0A%09%09%09%09%0D%0A%09%09%09%09//i++;%0D%0A%09%09%09//%09progressbar.setValue(progressbar.getValue()+(i%252)*2);%0D%0A%09%09%09%7D%0D%0A%0D%0A%09%09%7D%0D%0A%09%7D%0D%0A
+super(title, msg, cmdListener, true);%0D%0A%09%09%0D%0A%09%09//#style capturingPopup%0D%0A%09%09UiAccess.setStyle(this);%0D%0A%09%09//#style capturingGauge%0D%0A%09%09UiAccess.setStyle(progressbar);%0D%0A%09%7D%0D%0A%09%0D%0A%09public void stopProgressBar()%7B%0D%0A%09%09progressbar.setValue(Gauge.CONTINUOUS_IDLE);%0D%0A%09%7D%0D%0A%09%0D%0A%09public void startProgressBar()%7B%0D%0A%09%09progressbar.setValue(Gauge.CONTINUOUS_RUNNING);%0D%0A%09%7D
 %0D%0A%09%0D

fix javarosa app mess