← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 1904: Tried to merge in changes (not all that easy)

 

Merge authors:
  Long <thanhlongngo1988>
------------------------------------------------------------
revno: 1904 [merge]
committer: Jo Størset <storset@xxxxxxxxx>
branch nick: cbhis-mobile
timestamp: Thu 2010-08-26 21:12:57 +0200
message:
  Tried to merge in changes (not all that easy)
added:
  mobile/dhis-mobile/src/org/hisp/dhis/mobile/db/OrgUnitRecordFilter.java
  mobile/dhis-mobile/src/org/hisp/dhis/mobile/db/OrgUnitRecordStore.java
  mobile/dhis-mobile/src/org/hisp/dhis/mobile/util/AlertUtil.java
modified:
  mobile/dhis-mobile/src/org/hisp/dhis/mobile/ui/DHISMIDlet.java
  mobile/dhis-mobile/src/org/hisp/dhis/mobile/ui/SplashScreen.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
=== added file 'mobile/dhis-mobile/src/org/hisp/dhis/mobile/db/OrgUnitRecordFilter.java'
--- mobile/dhis-mobile/src/org/hisp/dhis/mobile/db/OrgUnitRecordFilter.java	1970-01-01 00:00:00 +0000
+++ mobile/dhis-mobile/src/org/hisp/dhis/mobile/db/OrgUnitRecordFilter.java	2010-08-26 19:12:57 +0000
@@ -0,0 +1,19 @@
+package org.hisp.dhis.mobile.db;
+
+import org.hisp.dhis.mobile.model.AbstractModel;
+
+public class OrgUnitRecordFilter
+    extends AbstractModelRecordFilter
+{
+
+    public OrgUnitRecordFilter( AbstractModel model )
+    {
+        super( model );
+    }
+
+    public boolean matches( byte[] suspect )
+    {
+        return super.matches( suspect );
+    }
+
+}

=== added file 'mobile/dhis-mobile/src/org/hisp/dhis/mobile/db/OrgUnitRecordStore.java'
--- mobile/dhis-mobile/src/org/hisp/dhis/mobile/db/OrgUnitRecordStore.java	1970-01-01 00:00:00 +0000
+++ mobile/dhis-mobile/src/org/hisp/dhis/mobile/db/OrgUnitRecordStore.java	2010-08-26 19:12:57 +0000
@@ -0,0 +1,136 @@
+package org.hisp.dhis.mobile.db;
+
+import java.util.Enumeration;
+import java.util.Vector;
+
+import javax.microedition.rms.RecordEnumeration;
+import javax.microedition.rms.RecordFilter;
+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.OrgUnit;
+
+/**
+ * @author Tran Ng Minh Luan
+ * 
+ */
+public class OrgUnitRecordStore {
+
+	private String dbName;
+
+	private Vector orgUnitsVector;
+
+	// Constructor
+	public OrgUnitRecordStore() {
+
+	}
+
+	// Getter & Setter
+	public void setOrgUnitsVector(Vector orgUnitsVector) {
+		this.orgUnitsVector = orgUnitsVector;
+	}
+	
+	// Getter & Setter
+
+	public String getDbName() {
+		return dbName;
+	}
+
+	public void setDbName(String dbName) {
+		this.dbName = dbName;
+	}
+
+	// Supportive Methods
+	public void save() {
+		clear();
+		RecordStore rs = null;
+		try {
+			rs = RecordStore.openRecordStore(dbName, true);
+			if (orgUnitsVector != null && orgUnitsVector.size() > 0) {
+				Enumeration orgUnits = orgUnitsVector.elements();
+				byte[] orgUnitByte;
+				while (orgUnits.hasMoreElements()) {
+					orgUnitByte = OrgUnit.orgUnitToRecord((OrgUnit) orgUnits
+							.nextElement());
+					rs.addRecord(orgUnitByte, 0, orgUnitByte.length);
+				}
+				orgUnitByte = null;
+			}
+		} catch (RecordStoreException e) {
+			System.out.println(e.getMessage());
+		} finally {
+			if (rs != null)
+				try {
+					rs.closeRecordStore();
+				} catch (RecordStoreNotOpenException e) {
+					e.printStackTrace();
+				} catch (RecordStoreException e) {
+					e.printStackTrace();
+				}
+		}
+	}
+
+	public void update(AbstractModel model) {
+		RecordStore rs = null;
+		RecordEnumeration re = null;
+		try {
+			rs = RecordStore.openRecordStore(dbName, true);
+			RecordFilter rsFilter = new AbstractModelRecordFilter(model);
+			re = rs.enumerateRecords(rsFilter, null, false);
+			Integer id;
+			byte[] orgUnitByte;
+			while (re.hasNextElement()) {
+				id = new Integer(re.nextRecordId());
+				orgUnitByte = OrgUnit.orgUnitToRecord((OrgUnit) model);
+				rs.setRecord(id.intValue(), orgUnitByte, 0, orgUnitByte.length);
+
+			}
+			// release variable
+			orgUnitByte = null;
+			id = null;
+		} 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 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();
+				}
+		}
+	}
+
+}

=== 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-26 14:59:39 +0000
+++ mobile/dhis-mobile/src/org/hisp/dhis/mobile/ui/DHISMIDlet.java	2010-08-26 19:12:57 +0000
@@ -28,6 +28,7 @@
 import org.hisp.dhis.mobile.model.OrgUnit;
 import org.hisp.dhis.mobile.model.ProgramStageForm;
 import org.hisp.dhis.mobile.model.User;
+import org.hisp.dhis.mobile.util.AlertUtil;
 
 public class DHISMIDlet
     extends MIDlet
@@ -1107,8 +1108,6 @@
         System.out.println( "The form is:  " + programStageForm.getName() + "  with an ID of:  "
             + programStageForm.getId() );
 
-        System.out.println( ".... and the values:  " );
-
         Vector des = programStageForm.getDataElements();
 
         for ( int i = 0; i < des.size(); i++ )
@@ -1134,12 +1133,10 @@
 
     public void error( String error )
     {
-        Form errorForm = new Form( "Problem with server configuration" );
-        errorForm.append( error );
-        switchDisplayable( null, errorForm  );
+        switchDisplayable( AlertUtil.getErrorAlert( "Problem with server", error ), getLoginForm() );
     }
 
     public void loginNeeded() {
-        switchDisplayable( new Alert( "Username/password was wrong" ), getLoginForm());   
+        switchDisplayable( AlertUtil.getInfoAlert( "Login failed", "Username/password was wrong" ), getLoginForm());   
     }
 }

=== 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-26 14:59:39 +0000
+++ mobile/dhis-mobile/src/org/hisp/dhis/mobile/ui/SplashScreen.java	2010-08-26 19:12:57 +0000
@@ -34,7 +34,8 @@
     }
 
     protected void paint( Graphics g ){
-        g.setColor(255, 255, 255);
+        //g.setColor(255, 255, 255);
+        g.setColor(66, 80, 115);
         g.fillRect(0, 0, getWidth(), getHeight());
         if (image != null)
             g.drawImage (image, getWidth()/2, getHeight()/2, Graphics.HCENTER | Graphics.VCENTER);

=== added file 'mobile/dhis-mobile/src/org/hisp/dhis/mobile/util/AlertUtil.java'
--- mobile/dhis-mobile/src/org/hisp/dhis/mobile/util/AlertUtil.java	1970-01-01 00:00:00 +0000
+++ mobile/dhis-mobile/src/org/hisp/dhis/mobile/util/AlertUtil.java	2010-08-26 19:12:57 +0000
@@ -0,0 +1,23 @@
+package org.hisp.dhis.mobile.util;
+
+import javax.microedition.lcdui.Alert;
+import javax.microedition.lcdui.AlertType;
+
+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;
+	}
+}