dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #08164
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 1907: Check PIN
------------------------------------------------------------
revno: 1907
committer: Tran Ng Minh Luan <Luan@MinhLuan-PC>
branch nick: cbhis-mobile
timestamp: Sat 2010-08-28 17:25:49 +0700
message:
Check PIN
Download-Save Activities (First Startup)
Load Activities (Later Startup)
View Activities
added:
mobile/dhis-mobile/src/org/hisp/dhis/mobile/db/ActivityRecordOrdUnitIdFilter.java
mobile/dhis-mobile/src/org/hisp/dhis/mobile/db/ActivityRecordStore.java
mobile/dhis-mobile/src/org/hisp/dhis/mobile/util/AlertConfirmListener.java
modified:
mobile/dhis-mobile/src/org/hisp/dhis/mobile/connection/DownloadManager.java
mobile/dhis-mobile/src/org/hisp/dhis/mobile/db/ModelRecordStore.java
mobile/dhis-mobile/src/org/hisp/dhis/mobile/db/OrgUnitRecordStore.java
mobile/dhis-mobile/src/org/hisp/dhis/mobile/db/Storage.java
mobile/dhis-mobile/src/org/hisp/dhis/mobile/ui/DHISMIDlet.java
mobile/dhis-mobile/src/org/hisp/dhis/mobile/ui/SplashScreen.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/src/org/hisp/dhis/mobile/connection/DownloadManager.java'
--- mobile/dhis-mobile/src/org/hisp/dhis/mobile/connection/DownloadManager.java 2010-08-27 09:43:40 +0000
+++ mobile/dhis-mobile/src/org/hisp/dhis/mobile/connection/DownloadManager.java 2010-08-28 10:25:49 +0000
@@ -85,7 +85,8 @@
{
Vector activitiesVector = (Vector) download( url, new ActivityPlanParser() );
dhisMIDlet.saveActivities( activitiesVector );
- dhisMIDlet.displayCurActivities();
+ dhisMIDlet.switchDisplayable( null, dhisMIDlet.getMainMenuList() );
+ //dhisMIDlet.displayCurActivities();
}
else if ( task.equals( DOWNLOAD_ALL ) )
{
=== added file 'mobile/dhis-mobile/src/org/hisp/dhis/mobile/db/ActivityRecordOrdUnitIdFilter.java'
--- mobile/dhis-mobile/src/org/hisp/dhis/mobile/db/ActivityRecordOrdUnitIdFilter.java 1970-01-01 00:00:00 +0000
+++ mobile/dhis-mobile/src/org/hisp/dhis/mobile/db/ActivityRecordOrdUnitIdFilter.java 2010-08-28 10:25:49 +0000
@@ -0,0 +1,51 @@
+package org.hisp.dhis.mobile.db;
+
+import java.io.ByteArrayInputStream;
+import java.io.DataInputStream;
+import java.io.IOException;
+
+import javax.microedition.rms.RecordFilter;
+
+/**
+ * @author Tran Ng Minh Luan
+ *
+ */
+public class ActivityRecordOrdUnitIdFilter implements RecordFilter{
+ private int orgUnitId;
+
+ public ActivityRecordOrdUnitIdFilter(int orgUnitId) {
+ this.orgUnitId = orgUnitId;
+ }
+
+ public int getOrgUnitId() {
+ return orgUnitId;
+ }
+
+ public void setOrgUnitId(int orgUnitId) {
+ this.orgUnitId = orgUnitId;
+ }
+
+ public boolean matches(byte[] candidate){
+ ByteArrayInputStream bis = new ByteArrayInputStream(candidate);
+ DataInputStream dis = new DataInputStream(bis);
+ try{
+ if(dis.readInt() == this.orgUnitId){
+ return true;
+ }else{
+ return false;
+ }
+ }catch(Exception e){
+ System.out.println("Activity Filter get exception");
+ return false;
+ }
+ finally{
+ try {
+ bis.close();
+ dis.close();
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+
+ }
+ }
+}
=== added file 'mobile/dhis-mobile/src/org/hisp/dhis/mobile/db/ActivityRecordStore.java'
--- mobile/dhis-mobile/src/org/hisp/dhis/mobile/db/ActivityRecordStore.java 1970-01-01 00:00:00 +0000
+++ mobile/dhis-mobile/src/org/hisp/dhis/mobile/db/ActivityRecordStore.java 2010-08-28 10:25:49 +0000
@@ -0,0 +1,168 @@
+package org.hisp.dhis.mobile.db;
+
+import java.util.Enumeration;
+import java.util.Vector;
+import javax.microedition.rms.RecordEnumeration;
+import javax.microedition.rms.RecordStore;
+import javax.microedition.rms.RecordStoreException;
+import javax.microedition.rms.RecordStoreNotOpenException;
+import org.hisp.dhis.mobile.model.Activity;
+
+/**
+ * @author Tran Ng Minh Luan
+ *
+ */
+public class ActivityRecordStore {
+ private String dbName;
+ private Vector activityVector;
+
+ //Constructor
+ public ActivityRecordStore() {
+ this.dbName = ModelRecordStore.ACTIVITY_DB;
+ }
+
+ //Getter & Setter
+
+ public Vector getActivityVector() {
+ return activityVector;
+ }
+
+ public void setActivityVector(Vector activityVector) {
+ this.activityVector = activityVector;
+ }
+
+ //Supportive methods
+ public void save() {
+ RecordStore rs = null;
+ clear();
+ try {
+ rs = RecordStore.openRecordStore(dbName, true);
+
+ if (activityVector != null && activityVector.size() > 0) {
+
+ Enumeration activities = activityVector.elements();
+ byte[] activityByte;
+ Activity activity;
+ while (activities.hasMoreElements()) {
+
+ activity = (Activity) activities.nextElement();
+
+ activityByte = Activity.activityToRecord(activity);
+ rs.addRecord(activityByte, 0, activityByte.length);
+ }
+ activityByte = null;
+ activity = null;
+ }
+ } catch (RecordStoreException e) {
+ } finally {
+ if (rs != null)
+ try {
+ rs.closeRecordStore();
+ } catch (RecordStoreNotOpenException e) {
+ e.printStackTrace();
+ } catch (RecordStoreException e) {
+ e.printStackTrace();
+ }
+ }
+ }
+
+ public void clear() {
+ RecordStore rs = null;
+ RecordEnumeration re = null;
+ try {
+ rs = RecordStore.openRecordStore(dbName, true);
+ re = rs.enumerateRecords(null, null, false);
+ int id;
+ while (re.hasNextElement()) {
+ id = re.nextRecordId();
+ rs.deleteRecord(id);
+ }
+ } catch (Exception e) {
+
+ } finally {
+ if (re != null)
+ re.destroy();
+ if (rs != null)
+ try {
+ rs.closeRecordStore();
+ } catch (RecordStoreNotOpenException e) {
+ e.printStackTrace();
+ } catch (RecordStoreException e) {
+ e.printStackTrace();
+ }
+ }
+ }
+
+ public Vector loadAll(){
+ RecordStore rs = null;
+ RecordEnumeration re = null;
+ activityVector = new Vector();
+ try {
+ rs = RecordStore.openRecordStore(dbName, true);
+ re = rs.enumerateRecords(null, null, false);
+ while (re.hasNextElement()) {
+ activityVector.addElement(Activity.recordToActivity(re.nextRecord()));
+ }
+ } catch (Exception e) {
+
+ } finally {
+ if (re != null)
+ re.destroy();
+ if (rs != null)
+ try {
+ rs.closeRecordStore();
+ } catch (RecordStoreNotOpenException e) {
+ e.printStackTrace();
+ } catch (RecordStoreException e) {
+ e.printStackTrace();
+ }
+ }
+ return getActivityVector();
+ }
+
+
+
+
+ //This Method is used in case two CHW share one mobile, so we need to filter activities of different orgunits.
+
+// public Vector load(int orgUnitId){
+// RecordStore rs = null;
+// RecordEnumeration re = null;
+// this.activityVector = new Vector();
+// RecordFilter rf = new ActivityRecordOrdUnitIdFilter(orgUnitId);
+//
+// try {
+// rs = RecordStore.openRecordStore(dbName, true);
+// re = rs.enumerateRecords(rf, null, false);
+// while (re.hasNextElement()) {
+// byte[] activityByte = re.nextRecord();
+// Activity activity = Activity.recordToActivity(activityByte);
+// activityVector.addElement(activity);
+// }
+// rf = null;
+// } catch (RecordStoreFullException e) {
+// System.out.println("exception record store activity full");
+// e.printStackTrace();
+// } catch (RecordStoreNotFoundException e) {
+// System.out.println("exception record store activity not found");
+// e.printStackTrace();
+// } catch (RecordStoreException e) {
+// System.out.println("exception record store activity general");
+// e.printStackTrace();
+// } finally {
+// rf = null;
+// if (re != null)
+// re.destroy();
+// if (rs != null)
+// try {
+// rs.closeRecordStore();
+// } catch (RecordStoreNotOpenException e) {
+// e.printStackTrace();
+// } catch (RecordStoreException e) {
+// e.printStackTrace();
+// }
+// }
+// return getActivityVector();
+// }
+
+}
=== modified file 'mobile/dhis-mobile/src/org/hisp/dhis/mobile/db/ModelRecordStore.java'
--- mobile/dhis-mobile/src/org/hisp/dhis/mobile/db/ModelRecordStore.java 2010-08-27 09:43:40 +0000
+++ mobile/dhis-mobile/src/org/hisp/dhis/mobile/db/ModelRecordStore.java 2010-08-28 10:25:49 +0000
@@ -78,6 +78,11 @@
}
}
+
+
+
+
+
//need to do this is in a better way...
public void AddDataElementRecords(Vector des) throws RecordStoreException
{
=== modified file 'mobile/dhis-mobile/src/org/hisp/dhis/mobile/db/OrgUnitRecordStore.java'
--- mobile/dhis-mobile/src/org/hisp/dhis/mobile/db/OrgUnitRecordStore.java 2010-08-27 09:43:40 +0000
+++ mobile/dhis-mobile/src/org/hisp/dhis/mobile/db/OrgUnitRecordStore.java 2010-08-28 10:25:49 +0000
@@ -16,6 +16,7 @@
* @author Tran Ng Minh Luan
*
*/
+
public class OrgUnitRecordStore
{
@@ -26,7 +27,7 @@
// Constructor
public OrgUnitRecordStore()
{
- this.dbName = "ORGUNIT";
+ this.dbName = ModelRecordStore.ORGUNIT_DB;
}
// Getter & Setter
=== modified file 'mobile/dhis-mobile/src/org/hisp/dhis/mobile/db/Storage.java'
--- mobile/dhis-mobile/src/org/hisp/dhis/mobile/db/Storage.java 2010-08-27 09:43:40 +0000
+++ mobile/dhis-mobile/src/org/hisp/dhis/mobile/db/Storage.java 2010-08-28 10:25:49 +0000
@@ -26,16 +26,12 @@
*/
package org.hisp.dhis.mobile.db;
-import java.util.Enumeration;
import java.util.Vector;
-
import javax.microedition.rms.RecordEnumeration;
import javax.microedition.rms.RecordStore;
import javax.microedition.rms.RecordStoreException;
import javax.microedition.rms.RecordStoreNotOpenException;
-
import org.hisp.dhis.mobile.model.AbstractModel;
-import org.hisp.dhis.mobile.model.Activity;
import org.hisp.dhis.mobile.model.OrgUnit;
import org.hisp.dhis.mobile.model.ProgramStageForm;
import org.hisp.dhis.mobile.model.User;
@@ -83,24 +79,19 @@
return (AbstractModel) getAllForm().elementAt( index );
}
- public static void storeActivities( Vector activitiesVector )
+ public static void storeActivities( Vector activityVector )
{
- ModelRecordStore modelRecordStore = new ModelRecordStore( ModelRecordStore.ACTIVITY_DB );
- Enumeration activities = activitiesVector.elements();
- Activity activity = null;
- int i = 0;
- while ( activities.hasMoreElements() )
- {
- try
- {
- activity = (Activity) activities.nextElement();
- modelRecordStore.addRecord( Activity.activityToRecord( activity ) );
- i += 1;
- }
- catch ( RecordStoreException rse )
- {
- }
- }
+ clear(ModelRecordStore.ACTIVITY_DB);
+ ActivityRecordStore activityRecordStore = new ActivityRecordStore();
+ activityRecordStore.setActivityVector( activityVector );
+ activityRecordStore.save();
+ activityRecordStore = null;
+ }
+
+ public static Vector loadActivities(){
+ ActivityRecordStore activityRecordStore = new ActivityRecordStore();
+ return activityRecordStore.loadAll();
+
}
public static void storeForm( ProgramStageForm programStageForm )
@@ -127,19 +118,37 @@
public static void saveOrgUnit( OrgUnit orgUnit )
{
- // ModelRecordStore modelRecordStore;
- // try
- // {
- // modelRecordStore = new ModelRecordStore( ModelRecordStore.ORGUNIT_DB
- // );
- // modelRecordStore.addRecord( OrgUnit.orgUnitToRecord( orgUnit ) );
- // }
- // catch ( RecordStoreException rse )
- // {
- // }
- OrgUnitRecordStore orgUnitStore = new OrgUnitRecordStore();
- orgUnitStore.save( orgUnit );
- orgUnitStore = null;
+ clear(ModelRecordStore.ORGUNIT_DB);
+ ModelRecordStore modelRecordStore;
+ try
+ {
+ modelRecordStore = new ModelRecordStore( ModelRecordStore.ORGUNIT_DB );
+ modelRecordStore.addRecord( OrgUnit.orgUnitToRecord( orgUnit ) );
+ }
+ catch ( RecordStoreException rse )
+ {
+ }
+ }
+
+ public static OrgUnit loadOrgUnit()
+ {
+ RecordStore rs = null;
+ RecordEnumeration re = null;
+ OrgUnit orgUnit = null;
+ try
+ {
+ rs = RecordStore.openRecordStore( ModelRecordStore.ORGUNIT_DB, true );
+ re = rs.enumerateRecords( null, null, false );
+ while(re.hasNextElement()){
+ orgUnit = OrgUnit.recordToOrgUnit( re.nextRecord());
+ }
+ return orgUnit;
+ }
+ catch ( RecordStoreException rse )
+ {
+ rse.printStackTrace();
+ return null;
+ }
}
public static void saveUser( User user )
@@ -157,6 +166,27 @@
}
}
+ public static User loadUser()
+ {
+ RecordStore rs = null;
+ RecordEnumeration re = null;
+ User user = null;
+ try
+ {
+ rs = RecordStore.openRecordStore( ModelRecordStore.USER_DB, true );
+ re = rs.enumerateRecords( null, null, false );
+ while(re.hasNextElement()){
+ user = User.recordToUser(re.nextRecord());
+ }
+ return user;
+ }
+ catch ( RecordStoreException rse )
+ {
+ rse.printStackTrace();
+ return null;
+ }
+ }
+
public static void clear( String dbName )
{
RecordStore rs = null;
=== 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-27 09:43:40 +0000
+++ mobile/dhis-mobile/src/org/hisp/dhis/mobile/ui/DHISMIDlet.java 2010-08-28 10:25:49 +0000
@@ -34,9 +34,7 @@
implements CommandListener
{
- private String serverUrl = "http://localhost:8080/api/";
-
- private static final String DOWNLOAD_FORM = "Download Form";
+ private String serverUrl = "http://localhost:8080/dhis-web-api/api/";
private boolean midletPaused = false;
@@ -48,17 +46,17 @@
private Vector programStagesVector = new Vector();
+ private Vector activitiesVector = new Vector();
+
private OrgUnit orgUnit;
- private Vector activitiesVector = new Vector();
-
private ProgramStageForm programStageForm;
private List mainMenuList;
private List formDownloadList;
- private Form activityList;
+ private List activityList;
private Form settingsForm;
@@ -74,6 +72,8 @@
private Form pinForm;
+ private Form waitForm;
+
// add one more form to handle downloaded form list
private List downloadedFormsList;
@@ -148,8 +148,10 @@
*/
public void startMIDlet()
{
- new SplashScreen( getLogo(), getDisplay(), (Displayable) getLoginForm(), (Displayable) getPinForm());
+ getPinForm().addCommand(this.getPinFormExitCmd());
+ new SplashScreen( getLogo(), getDisplay(), (Displayable) getLoginForm(), (Displayable) getPinForm() );
+
}
/**
@@ -173,6 +175,7 @@
{
Display display = getDisplay();
+
if ( alert == null )
{
display.setCurrent( nextDisplayable );
@@ -235,22 +238,6 @@
else if ( command == lgnFrmLgnCmd )
{
login();
- if ( user != null )
- {
- // DownloadManager downloadManager = new DownloadManager(
- // this, serverUrl + "user", user,
- // DownloadManager.DOWNLOAD_ALL );
- // downloadManager.start();
- // Form waitForm = new Form( "Making connection" );
- // waitForm.append( "Please wait........" );
- // switchDisplayable( null, waitForm );
- // switchDisplayable( null, getMainMenuList() );
- }
- else
- {
- // getDisplay().setCurrent( new Alert( "You must login" ),
- // loginForm );
- }
}
}
else if ( displayable == mainMenuList )
@@ -294,36 +281,105 @@
{
this.switchDisplayable( null, mainMenuList );
}
- } else if (displayable == pinForm){
- if (command == pinFormNextCmd){
- this.saveData();
- } else if (command == pinFormReinitCmd) {
- switchDisplayable( null, getLoginForm() );
- }
- }
- }
-
- private void saveData()
- {
- try
- {
- SettingsRectordStore settingStore = new SettingsRectordStore( "SETTINGS" );
- settingStore.put( "pin", this.getPinTextField().getString() );
- settingStore.save();
- }
- catch ( RecordStoreException e )
- {
- System.out.println(e.getMessage());
- }
-
- }
-
- private void savePin()
- {
- // TODO Auto-generated method stub
-
- }
-
+ }
+ else if ( displayable == pinForm )
+ {
+ 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() );
+ }
+ }
+ else if ( command == pinFormReinitCmd )
+ {
+ this.getDisplay().setCurrent( AlertUtil.getConfirmAlert( this, getPinForm(), getLoginForm() ) );
+ }else if (command == pinFormExitCmd){
+ exitMIDlet();
+ }
+ }
+ }
+
+ /**
+ * Returns an vector of activities loaded from RMS
+ */
+
+ // this Thread should moved to manager class like DownloadManager
+ private void loadActivities()
+ {
+ new Thread()
+ {
+ public void run()
+ {
+ activitiesVector = Storage.loadActivities();
+ switchDisplayable( null, getMainMenuList() );
+ }
+ }.start();
+ }
+
+ /**
+ * Returns an initiliazed instance of exitCommand component.
+ *
+ * @return the initialized component instance
+ */
+ public Command getPinFormExitCmd()
+ {
+ if ( pinFormExitCmd == null )
+ {
+ pinFormExitCmd = new Command( "Exit", Command.EXIT, 0 );
+ }
+ return pinFormExitCmd;
+ }
+
/**
* Returns an initiliazed instance of exitCommand component.
*
@@ -400,14 +456,17 @@
if ( mainMenuList == null )
{
mainMenuList = new List( "Menu", Choice.IMPLICIT );
- mainMenuList.append( DOWNLOAD_FORM, null );
- mainMenuList.append( "Download Activity Plan", null );
- mainMenuList.append( "Record Data", null );
- mainMenuList.append( "Settings", 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.addCommand( getMnuListExtCmd() );
mainMenuList.setCommandListener( this );
+
mainMenuList.setFitPolicy( Choice.TEXT_WRAP_DEFAULT );
mainMenuList.setSelectedFlags( new boolean[] { false, false, false, false } );
}
@@ -423,20 +482,9 @@
String __selectedString = getMainMenuList().getString( getMainMenuList().getSelectedIndex() );
if ( __selectedString != null )
{
- if ( __selectedString.equals( DOWNLOAD_FORM ) )
- {
- browseForms();
- Form waitForm = new Form( "Making connection" );
- waitForm.append( "Please wait........" );
- switchDisplayable( null, waitForm );
- }
- else if ( __selectedString.equals( "Download Activity Plan" ) )
- {
- browseActivities();
- Form waitForm = new Form( "Making connection" );
- waitForm.append( "Please wait........" );
- switchDisplayable( null, waitForm );
- System.out.println( "I will download activity plans from here" );
+ if ( __selectedString.equals( "Activity Plan" ))
+ {
+ displayCurActivities();
}
else if ( __selectedString.equals( "Record Data" ) )
{
@@ -493,14 +541,10 @@
public void downloadActivities()
{
- String urlDownloadActivities = orgUnit.getActivitiesLink();
+ String urlDownloadActivities = this.orgUnit.getActivitiesLink();
downloadManager = new DownloadManager( this, urlDownloadActivities, user, DownloadManager.DOWNLOAD_ACTIVITYPLAN );
downloadManager.start();
-
- Form form = new Form( "Downloading" );
- form.append( "Please wait" );
- switchDisplayable( null, form );
}
/**
@@ -551,6 +595,24 @@
return actvyPlnListBakCmd;
}
+ public Form getWaitForm( String title, String msg )
+ {
+ if ( waitForm == null )
+ {
+ waitForm = new Form( title );
+ waitForm.append( msg );
+ return waitForm;
+ }
+ else
+ {
+ waitForm.deleteAll();
+ waitForm.setTitle( title );
+ waitForm.append( msg );
+ return waitForm;
+ }
+
+ }
+
/**
* Returns an initiliazed instance of settingsForm component.
*
@@ -714,6 +776,10 @@
pinForm.addCommand( this.getPinFormReinitCmd() );
pinForm.setCommandListener( this );
}
+ else if ( pinForm != null )
+ {
+ getPinTextField().setString( "" );
+ }
return pinForm;
}
@@ -739,7 +805,7 @@
{
if ( pinTextField == null )
{
- pinTextField = new TextField( "PIN", "", 4, TextField.NUMERIC );
+ pinTextField = new TextField( "PIN", "", 4, TextField.NUMERIC | TextField.PASSWORD );
}
return pinTextField;
@@ -798,6 +864,8 @@
loginForm.addCommand( getLgnFrmExtCmd() );
loginForm.addCommand( getLgnFrmLgnCmd() );
loginForm.setCommandListener( this );
+ }else{
+ getPassword().setString( "" );
}
return loginForm;
}
@@ -918,7 +986,6 @@
private void login()
{
-
if ( getUserName().getString() != null && getPassword().getString() != null )
{
String username = getUserName().getString().trim();
@@ -928,10 +995,9 @@
user = new User( username, password );
}
}
- // Take action based on login value
if ( user != null )
{
- DownloadManager downloadManager = new DownloadManager( this, "http://localhost:8080/dhis-web-api/api/user",
+ DownloadManager downloadManager = new DownloadManager( this, getUrl().getString(),
user, DownloadManager.DOWNLOAD_ORGUNIT );
downloadManager.start();
@@ -975,20 +1041,6 @@
}
}
- private void browseActivities()
- {
- if ( activitiesVector == null || activitiesVector.size() == 0 )
- {
- downloadManager = new DownloadManager( this, serverUrl + "user", user, DownloadManager.DOWNLOAD_ORGUNIT );
- downloadManager.start();
- }
- else
- {
- displayCurActivities();
- }
-
- }
-
private void browseForms()
{
loadSettings();
@@ -1034,7 +1086,8 @@
{
if ( activitiesVector == null || activitiesVector.size() == 0 )
{
- getActivitiesList().append( "No Activity Available" );
+ getActivitiesList().deleteAll();
+ getActivitiesList().append( "No Activity Available", null );
}
else
{
@@ -1042,20 +1095,20 @@
for ( int i = 0; i < activitiesVector.size(); i++ )
{
Activity activity = (Activity) activitiesVector.elementAt( i );
- getActivitiesList().append( "\n-------\n" );
- getActivitiesList().append( "Beneficiary: " + activity.getBeneficiary().getFullName() );
- getActivitiesList().append( "Due Date: " + activity.getDueDate().toString() );
+ getActivitiesList().append(
+ "Beneficiary: " + activity.getBeneficiary().getFullName() + "\n" + "Due Date: "
+ + activity.getDueDate().toString() + "\n", null );
activity = null;
}
}
switchDisplayable( null, activityList );
}
- public Form getActivitiesList()
+ public List getActivitiesList()
{
if ( activityList == null )
{
- activityList = new Form( "Current Activities" );
+ activityList = new List( "Current Activities", Choice.IMPLICIT );
activityList.addCommand( getActvyPlnListBakCmd() );
activityList.setCommandListener( this );
}
=== modified file 'mobile/dhis-mobile/src/org/hisp/dhis/mobile/ui/SplashScreen.java'
--- mobile/dhis-mobile/src/org/hisp/dhis/mobile/ui/SplashScreen.java 2010-08-27 09:43:40 +0000
+++ mobile/dhis-mobile/src/org/hisp/dhis/mobile/ui/SplashScreen.java 2010-08-28 10:25:49 +0000
@@ -12,8 +12,7 @@
import org.hisp.dhis.mobile.db.SettingsRectordStore;
-public class SplashScreen
- extends Canvas
+public class SplashScreen extends Canvas
{
private Display display;
=== added file 'mobile/dhis-mobile/src/org/hisp/dhis/mobile/util/AlertConfirmListener.java'
--- mobile/dhis-mobile/src/org/hisp/dhis/mobile/util/AlertConfirmListener.java 1970-01-01 00:00:00 +0000
+++ mobile/dhis-mobile/src/org/hisp/dhis/mobile/util/AlertConfirmListener.java 2010-08-28 10:25:49 +0000
@@ -0,0 +1,35 @@
+package org.hisp.dhis.mobile.util;
+
+import javax.microedition.lcdui.Command;
+import javax.microedition.lcdui.CommandListener;
+import javax.microedition.lcdui.Displayable;
+import javax.microedition.midlet.MIDlet;
+
+import org.hisp.dhis.mobile.ui.DHISMIDlet;
+
+public class AlertConfirmListener implements CommandListener
+{
+ private Displayable currentScrren;
+
+ private Displayable nextScreen;
+
+ private MIDlet midlet;
+
+ public AlertConfirmListener( MIDlet midlet, Displayable currentScrren, Displayable nextScreen )
+ {
+ 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);
+ }
+ }
+
+}
=== 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-26 19:12:57 +0000
+++ mobile/dhis-mobile/src/org/hisp/dhis/mobile/util/AlertUtil.java 2010-08-28 10:25:49 +0000
@@ -2,8 +2,11 @@
import javax.microedition.lcdui.Alert;
import javax.microedition.lcdui.AlertType;
+import javax.microedition.lcdui.Command;
+import javax.microedition.lcdui.Displayable;
+import javax.microedition.midlet.MIDlet;
-public class AlertUtil {
+public class AlertUtil{
public static Alert getErrorAlert(String title, String msg){
Alert alert = new Alert(title);
@@ -20,4 +23,15 @@
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;
+ }
+
+
}