dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #08163
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 1908: Add: Re-Download Activities
------------------------------------------------------------
revno: 1908
committer: Tran Ng Minh Luan <Luan@MinhLuan-PC>
branch nick: cbhis-mobile
timestamp: Mon 2010-08-30 15:09:07 +0700
message:
Add: Re-Download Activities
added:
mobile/dhis-mobile/src/org/hisp/dhis/mobile/util/DefaultAlertConfirmListener.java
mobile/dhis-mobile/src/org/hisp/dhis/mobile/util/DnlActivitiesConfirmAlertListener.java
modified:
mobile/dhis-mobile/.mtj
mobile/dhis-mobile/Application Descriptor
mobile/dhis-mobile/src/org/hisp/dhis/mobile/ui/DHISMIDlet.java
mobile/dhis-mobile/src/org/hisp/dhis/mobile/util/AlertConfirmListener.java
mobile/dhis-mobile/src/org/hisp/dhis/mobile/util/AlertUtil.java
--
lp:dhis2
https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk
Your team DHIS 2 developers is subscribed to branch lp:dhis2.
To unsubscribe from this branch go to https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk/+edit-subscription
=== modified file 'mobile/dhis-mobile/.mtj'
--- mobile/dhis-mobile/.mtj 2010-08-27 09:43:40 +0000
+++ mobile/dhis-mobile/.mtj 2010-08-30 08:09:07 +0000
@@ -8,8 +8,8 @@
<configuration active="true" name="DefaultFxPhone1">
<device group="Sun Java(TM) Wireless Toolkit 2.5.2_01 for CLDC" name="DefaultColorPhone"/>
<symbolSet name="DefaultFxPhone1">
+ <symbol name="MMAPI" value="1.2"/>
<symbol name="screen.isColor" value="true"/>
- <symbol name="MMAPI" value="1.2"/>
<symbol name="descriptor" value="FX Emulator"/>
<symbol name="screen.bitDepth" value="16"/>
<symbol name="JSR82" value="1.1"/>
=== modified file 'mobile/dhis-mobile/Application Descriptor'
--- mobile/dhis-mobile/Application Descriptor 2010-08-25 12:09:15 +0000
+++ mobile/dhis-mobile/Application Descriptor 2010-08-30 08:09:07 +0000
@@ -1,7 +1,7 @@
-MIDlet-Version: 0.1
-MIDlet-Vendor: HISP
-MIDlet-Jar-URL: dhis-mobile.jar
-MicroEdition-Configuration: CLDC-1.1
-MicroEdition-Profile: MIDP-2.1
-MIDlet-1: DHISMIDlet,/logos/dhis2.png,org.hisp.dhis.mobile.ui.DHISMIDlet
-MIDlet-Name: dhis-mobile
+MIDlet-Version: 0.1
+MIDlet-Vendor: HISP
+MIDlet-Jar-URL: dhis-mobile.jar
+MicroEdition-Configuration: CLDC-1.0
+MicroEdition-Profile: MIDP-2.0
+MIDlet-1: DHISMIDlet,/logos/dhis2.png,org.hisp.dhis.mobile.ui.DHISMIDlet
+MIDlet-Name: dhis-mobile
=== modified file 'mobile/dhis-mobile/src/org/hisp/dhis/mobile/ui/DHISMIDlet.java'
--- mobile/dhis-mobile/src/org/hisp/dhis/mobile/ui/DHISMIDlet.java 2010-08-28 10:25:49 +0000
+++ mobile/dhis-mobile/src/org/hisp/dhis/mobile/ui/DHISMIDlet.java 2010-08-30 08:09:07 +0000
@@ -28,6 +28,8 @@
import org.hisp.dhis.mobile.model.ProgramStageForm;
import org.hisp.dhis.mobile.model.User;
import org.hisp.dhis.mobile.util.AlertUtil;
+import org.hisp.dhis.mobile.util.DefaultAlertConfirmListener;
+import org.hisp.dhis.mobile.util.DnlActivitiesConfirmAlertListener;
public class DHISMIDlet
extends MIDlet
@@ -85,6 +87,8 @@
private Command mnuListDnldCmd;
+ private Command mnuListSettingCmd;
+
private Command mnuListExtCmd;
private Command frmDnldCmd;
@@ -148,8 +152,8 @@
*/
public void startMIDlet()
{
- getPinForm().addCommand(this.getPinFormExitCmd());
-
+ getPinForm().addCommand( this.getPinFormExitCmd() );
+
new SplashScreen( getLogo(), getDisplay(), (Displayable) getLoginForm(), (Displayable) getPinForm() );
}
@@ -246,6 +250,19 @@
{
mainMenuListAction();
}
+ else if ( command == getMnuListSettingCmd() )
+ {
+ switchDisplayable( null, getSettingsForm() );
+ }
+ else if ( command == getMnuListDnldCmd() )
+ {
+ // clear DataValue
+
+ this.getDisplay().setCurrent(
+ AlertUtil.getConfirmAlert( "Warning",
+ "All data which are not sent to the server will be clear, do you want to continue ?", new DnlActivitiesConfirmAlertListener(), this,
+ getMainMenuList(), getWaitForm("Redownloading Activities", "Downloading.....Please wait") ) );
+ }
else if ( command == mnuListExtCmd )
{
exitMIDlet();
@@ -257,10 +274,9 @@
{
switchDisplayable( null, getMainMenuList() );
}
- else if ( command == setngsSaveCmd )
+ else if ( command == stngsOkCmd )
{
- // should try to save global parameters.......
- saveSettings();
+ //save new settings
switchDisplayable( null, getMainMenuList() );
}
}
@@ -287,63 +303,74 @@
SettingsRectordStore settingRs = null;
if ( command == pinFormNextCmd )
{
- //check empty pin textfield
- if(!getPinTextField().getString().equals( "" )){
- // case 1: Later Startup, User Information has not been
- // loaded
-
- try
- {
- settingRs = new SettingsRectordStore( "SETTINGS" );
- if ( this.user == null )
- {
- if ( getPinTextField().getString().equals( settingRs.get( "pin" ) ) )
- {
- // Load User Information
- this.user = Storage.loadUser();
- // Load OrgUnit
- this.orgUnit = Storage.loadOrgUnit();
- // Load Activities
- switchDisplayable( null, this.getWaitForm( "Load Activities", "Loading.....please wait" ) );
- this.loadActivities();
- // Load Forms
- }
- else
- {
- this.getPinTextField().setString( "" );
- switchDisplayable(
- AlertUtil.getInfoAlert( "Error", "Wrong PIN number, please input again" ), getPinForm() );
- }
- // case 2: First Startup, User Information initialized
- // from input
- }
- else
- {
- // Save PIN
- settingRs.put( "pin", this.getPinTextField().getString() );
- settingRs.save();
- // Save User Information
- Storage.saveUser( this.user );
- // Clear, Download and Save activities
- switchDisplayable( null, this.getWaitForm( "Download Activities", "Downloading.....please wait" ) );
- downloadActivities();
- //Download and Save Forms
-
- }
- settingRs = null;
- }
- catch ( RecordStoreException e )
- {
- e.printStackTrace();
- }
- }else{
- switchDisplayable(AlertUtil.getInfoAlert( "Error", "You must input the 4-digit PIN code" ), getPinForm() );
- }
+ // check empty pin textfield
+ if ( !getPinTextField().getString().equals( "" ) )
+ {
+ // case 1: Later Startup, User Information has not been
+ // loaded
+
+ try
+ {
+ settingRs = new SettingsRectordStore( "SETTINGS" );
+ if ( this.user == null )
+ {
+ if ( getPinTextField().getString().equals( settingRs.get( "pin" ) ) )
+ {
+ // Load User Information
+ this.user = Storage.loadUser();
+ // Load OrgUnit
+ this.orgUnit = Storage.loadOrgUnit();
+ // Load Activities
+ switchDisplayable( null,
+ this.getWaitForm( "Load Activities", "Loading.....please wait" ) );
+ this.loadActivities();
+ // Load Forms
+ }
+ else
+ {
+ this.getPinTextField().setString( "" );
+ switchDisplayable(
+ AlertUtil.getInfoAlert( "Error", "Wrong PIN number, please input again" ),
+ getPinForm() );
+ }
+ // case 2: First Startup, User Information
+ // initialized
+ // from input
+ }
+ else
+ {
+ // Save PIN
+ settingRs.put( "pin", this.getPinTextField().getString() );
+ settingRs.save();
+ // Save User Information
+ Storage.saveUser( this.user );
+ // Clear, Download and Save activities
+ switchDisplayable( null,
+ this.getWaitForm( "Download Activities", "Downloading.....please wait" ) );
+ downloadActivities();
+ // Download and Save Forms
+
+ }
+ settingRs = null;
+ }
+ catch ( RecordStoreException e )
+ {
+ e.printStackTrace();
+ }
+ }
+ else
+ {
+ switchDisplayable( AlertUtil.getInfoAlert( "Error", "You must input the 4-digit PIN code" ),
+ getPinForm() );
+ }
}
else if ( command == pinFormReinitCmd )
{
- this.getDisplay().setCurrent( AlertUtil.getConfirmAlert( this, getPinForm(), getLoginForm() ) );
- }else if (command == pinFormExitCmd){
+ this.getDisplay().setCurrent(
+ AlertUtil.getConfirmAlert( "Confirmation", "Are you sure ?",new DefaultAlertConfirmListener( ), this, getPinForm(), getLoginForm() ) );
+ }
+ else if ( command == pinFormExitCmd )
+ {
exitMIDlet();
}
}
@@ -365,7 +392,7 @@
}
}.start();
}
-
+
/**
* Returns an initiliazed instance of exitCommand component.
*
@@ -379,7 +406,7 @@
}
return pinFormExitCmd;
}
-
+
/**
* Returns an initiliazed instance of exitCommand component.
*
@@ -456,17 +483,19 @@
if ( mainMenuList == null )
{
mainMenuList = new List( "Menu", Choice.IMPLICIT );
- //mainMenuList.append( DOWNLOAD_FORM, null );
+ // mainMenuList.append( DOWNLOAD_FORM, null );
mainMenuList.append( "Activity Plan", null );
mainMenuList.append( "Send Finished Records", null );
- //mainMenuList.append( "Download Activity Plan", null );
- //mainMenuList.append( "Record Data", null );
- //mainMenuList.append( "Settings", null );
+ // mainMenuList.append( "Download Activity Plan", null );
+ // mainMenuList.append( "Record Data", null );
+ // mainMenuList.append( "Settings", null );
mainMenuList.addCommand( getMnuListExtCmd() );
+ mainMenuList.addCommand( getMnuListDnldCmd() );
+ mainMenuList.addCommand( getMnuListSettingCmd() );
mainMenuList.setCommandListener( this );
-
+
mainMenuList.setFitPolicy( Choice.TEXT_WRAP_DEFAULT );
mainMenuList.setSelectedFlags( new boolean[] { false, false, false, false } );
}
@@ -482,20 +511,52 @@
String __selectedString = getMainMenuList().getString( getMainMenuList().getSelectedIndex() );
if ( __selectedString != null )
{
- if ( __selectedString.equals( "Activity Plan" ))
+ if ( __selectedString.equals( "Activity Plan" ) )
{
displayCurActivities();
}
- else if ( __selectedString.equals( "Record Data" ) )
- {
- this.displayDownloadedForms( Storage.getAllForm() );
- }
- else if ( __selectedString.equals( "Settings" ) )
- {
- loadSettings();
- switchDisplayable( null, getSettingsForm() );
- }
- }
+ else if ( __selectedString.equals( "Send Finished Records" ) )
+ {
+
+ }
+ // else if ( __selectedString.equals( "Record Data" ) )
+ // {
+ // this.displayDownloadedForms( Storage.getAllForm() );
+ // }
+ // else if ( __selectedString.equals( "Settings" ) )
+ // {
+ // loadSettings();
+ // switchDisplayable( null, getSettingsForm() );
+ // }
+ }
+ }
+
+ /**
+ * Returns an initiliazed instance of mnuListSettingCmd component.
+ *
+ * @return the initialized component instance
+ */
+ public Command getMnuListSettingCmd()
+ {
+ if ( mnuListSettingCmd == null )
+ {
+ mnuListSettingCmd = new Command( "Settings", Command.ITEM, 1 );
+ }
+ return mnuListSettingCmd;
+ }
+
+ /**
+ * Returns an initiliazed instance of mnuListDnldCmd component.
+ *
+ * @return the initialized component instance
+ */
+ public Command getMnuListDnldCmd()
+ {
+ if ( mnuListDnldCmd == null )
+ {
+ mnuListDnldCmd = new Command( "Download Activity", Command.ITEM, 1 );
+ }
+ return mnuListDnldCmd;
}
/**
@@ -513,20 +574,6 @@
return mnuListExtCmd;
}
- /**
- * Returns an initiliazed instance of mnuListDnldCmd component.
- *
- * @return the initialized component instance
- */
- public Command getMnuListDnldCmd()
- {
- if ( mnuListDnldCmd == null )
- {
- mnuListDnldCmd = new Command( "Download", Command.SCREEN, 0 );
- }
- return mnuListDnldCmd;
- }
-
public List getFormDownloadList()
{
if ( formDownloadList == null )
@@ -622,9 +669,15 @@
{
if ( settingsForm == null )
{
- settingsForm = new Form( "Configurable Parameters", new Item[] { getUrl(), getAdminPass() } );
+ //settingsForm = new Form( "Configurable Parameters", new Item[] { getUrl(), getAdminPass() } );
+ //settingsForm = new Form( "Configurable Parameters", new Item[] { getUrl() } );
+ System.out.println(getUrl().getString());
+ settingsForm = new Form("Configurable Parameters");
+
+
+ //settingsForm.append( getUrlInSetting() );
settingsForm.addCommand( getSetngsBakCmd() );
- settingsForm.addCommand( getSetngsSaveCmd() );
+ settingsForm.addCommand( getStngsOkCmd() );
settingsForm.setCommandListener( this );
}
return settingsForm;
@@ -864,7 +917,9 @@
loginForm.addCommand( getLgnFrmExtCmd() );
loginForm.addCommand( getLgnFrmLgnCmd() );
loginForm.setCommandListener( this );
- }else{
+ }
+ else
+ {
getPassword().setString( "" );
}
return loginForm;
@@ -997,8 +1052,8 @@
}
if ( user != null )
{
- DownloadManager downloadManager = new DownloadManager( this, getUrl().getString(),
- user, DownloadManager.DOWNLOAD_ORGUNIT );
+ DownloadManager downloadManager = new DownloadManager( this, getUrl().getString() + "user", user,
+ DownloadManager.DOWNLOAD_ORGUNIT );
downloadManager.start();
}
@@ -1017,12 +1072,14 @@
{
settingsRecord = new SettingsRectordStore( "SETTINGS" );
settingsRecord.put( "url", url.getString() );
- settingsRecord.put( "adminPass", adminPass.getString() );
+ //settingsRecord.put( "adminPass", adminPass.getString() );
settingsRecord.save();
}
catch ( RecordStoreException rse )
{
}
+
+ settingsRecord = null;
}
private void loadSettings()
=== modified file 'mobile/dhis-mobile/src/org/hisp/dhis/mobile/util/AlertConfirmListener.java'
--- mobile/dhis-mobile/src/org/hisp/dhis/mobile/util/AlertConfirmListener.java 2010-08-28 10:25:49 +0000
+++ mobile/dhis-mobile/src/org/hisp/dhis/mobile/util/AlertConfirmListener.java 2010-08-30 08:09:07 +0000
@@ -7,29 +7,44 @@
import org.hisp.dhis.mobile.ui.DHISMIDlet;
-public class AlertConfirmListener implements CommandListener
+public abstract class AlertConfirmListener implements CommandListener
{
- private Displayable currentScrren;
-
- private Displayable nextScreen;
-
- private MIDlet midlet;
-
- public AlertConfirmListener( MIDlet midlet, Displayable currentScrren, Displayable nextScreen )
+ protected Displayable currentScrren;
+
+ protected Displayable nextScreen;
+
+ protected MIDlet midlet;
+
+ public AlertConfirmListener( )
+ {
+
+ }
+
+ public void setCurrentScrren( Displayable currentScrren )
+ {
+ this.currentScrren = currentScrren;
+ }
+
+
+
+ public void setNextScreen( Displayable nextScreen )
+ {
+ this.nextScreen = nextScreen;
+ }
+
+
+
+ public void setMidlet( MIDlet midlet )
{
this.midlet = midlet;
- this.nextScreen = nextScreen;
- this.currentScrren = currentScrren;
}
+
+
public void commandAction( Command c, Displayable d )
{
- if(c.getCommandType() == Command.OK){
- //Do other actions
- ((DHISMIDlet)this.midlet).switchDisplayable(null,nextScreen);
- }else if(c.getCommandType() == Command.CANCEL){
- ((DHISMIDlet)this.midlet).switchDisplayable(null,currentScrren);
- }
+ //Define action when Command == OK
+ //Define action when Command == CANCEL
}
}
=== modified file 'mobile/dhis-mobile/src/org/hisp/dhis/mobile/util/AlertUtil.java'
--- mobile/dhis-mobile/src/org/hisp/dhis/mobile/util/AlertUtil.java 2010-08-28 10:25:49 +0000
+++ mobile/dhis-mobile/src/org/hisp/dhis/mobile/util/AlertUtil.java 2010-08-30 08:09:07 +0000
@@ -6,32 +6,39 @@
import javax.microedition.lcdui.Displayable;
import javax.microedition.midlet.MIDlet;
-public class AlertUtil{
-
- public static Alert getErrorAlert(String title, String msg){
- Alert alert = new Alert(title);
- alert.setString(msg);
- alert.setType(AlertType.ERROR);
- alert.setTimeout(Alert.FOREVER);
- return alert;
- }
-
- public static Alert getInfoAlert(String title, String msg){
- Alert alert = new Alert(title);
- alert.setString(msg);
- alert.setType(AlertType.INFO);
- alert.setTimeout(Alert.FOREVER);
- return alert;
- }
-
- public static Alert getConfirmAlert(MIDlet midlet, Displayable currentScreen, Displayable nextScreen){
-
- Alert alert = new Alert( "Confirmation", "Are you sure ?", null, AlertType.CONFIRMATION );
- alert.addCommand( new Command("YES",Command.OK,0) );
- alert.addCommand( new Command("NO",Command.CANCEL,0) );
- alert.setCommandListener( new AlertConfirmListener(midlet,currentScreen, nextScreen) );
- return alert;
- }
-
-
+public class AlertUtil
+{
+
+ public static Alert getErrorAlert( String title, String msg )
+ {
+ Alert alert = new Alert( title );
+ alert.setString( msg );
+ alert.setType( AlertType.ERROR );
+ alert.setTimeout( Alert.FOREVER );
+ return alert;
+ }
+
+ public static Alert getInfoAlert( String title, String msg )
+ {
+ Alert alert = new Alert( title );
+ alert.setString( msg );
+ alert.setType( AlertType.INFO );
+ alert.setTimeout( Alert.FOREVER );
+ return alert;
+ }
+
+ public static Alert getConfirmAlert( String title, String msg, AlertConfirmListener listener, MIDlet midlet,
+ Displayable currentScreen, Displayable nextScreen )
+ {
+
+ Alert alert = new Alert( title, msg, null, AlertType.CONFIRMATION );
+ alert.addCommand( new Command( "YES", Command.OK, 0 ) );
+ alert.addCommand( new Command( "NO", Command.CANCEL, 0 ) );
+ listener.setMidlet( midlet );
+ listener.setCurrentScrren( currentScreen );
+ listener.setNextScreen( nextScreen );
+ alert.setCommandListener( listener );
+ return alert;
+ }
+
}
=== added file 'mobile/dhis-mobile/src/org/hisp/dhis/mobile/util/DefaultAlertConfirmListener.java'
--- mobile/dhis-mobile/src/org/hisp/dhis/mobile/util/DefaultAlertConfirmListener.java 1970-01-01 00:00:00 +0000
+++ mobile/dhis-mobile/src/org/hisp/dhis/mobile/util/DefaultAlertConfirmListener.java 2010-08-30 08:09:07 +0000
@@ -0,0 +1,24 @@
+package org.hisp.dhis.mobile.util;
+
+import javax.microedition.lcdui.Command;
+import javax.microedition.lcdui.Displayable;
+
+
+import org.hisp.dhis.mobile.ui.DHISMIDlet;
+
+public class DefaultAlertConfirmListener extends AlertConfirmListener
+{
+ public DefaultAlertConfirmListener(){
+ }
+
+
+ public void commandAction( Command c, Displayable d )
+ {
+ if(c.getCommandType() == Command.OK){
+ ((DHISMIDlet)this.midlet).switchDisplayable(null,nextScreen);
+ }else if(c.getCommandType() == Command.CANCEL){
+ ((DHISMIDlet)this.midlet).switchDisplayable(null,currentScrren);
+ }
+ }
+
+}
=== added file 'mobile/dhis-mobile/src/org/hisp/dhis/mobile/util/DnlActivitiesConfirmAlertListener.java'
--- mobile/dhis-mobile/src/org/hisp/dhis/mobile/util/DnlActivitiesConfirmAlertListener.java 1970-01-01 00:00:00 +0000
+++ mobile/dhis-mobile/src/org/hisp/dhis/mobile/util/DnlActivitiesConfirmAlertListener.java 2010-08-30 08:09:07 +0000
@@ -0,0 +1,29 @@
+package org.hisp.dhis.mobile.util;
+
+import javax.microedition.lcdui.Command;
+import javax.microedition.lcdui.Displayable;
+
+
+import org.hisp.dhis.mobile.ui.DHISMIDlet;
+
+public class DnlActivitiesConfirmAlertListener
+ extends AlertConfirmListener
+{
+
+ public DnlActivitiesConfirmAlertListener()
+ {
+ }
+
+
+
+ public void commandAction( Command c, Displayable d )
+ {
+ if(c.getCommandType() == Command.OK){
+ ((DHISMIDlet)this.midlet).switchDisplayable(null,nextScreen);
+ ((DHISMIDlet)this.midlet).downloadActivities();
+ }else if(c.getCommandType() == Command.CANCEL){
+ ((DHISMIDlet)this.midlet).switchDisplayable(null,currentScrren);
+ }
+ }
+
+}