Changeset 129
- Timestamp:
- 02/08/09 21:31:46 (12 months ago)
- Location:
- trunk
- Files:
-
- 8 modified
Legend:
- Unmodified
- Added
- Removed
-
trunk/rapidandroid/org.rapidandroid/src/org/rapidandroid/RapidAndroidApplication.java
r128 r129 19 19 // TODO Auto-generated method stub 20 20 super.onCreate(); 21 Debug.startMethodTracing("rapidandroid_application"); 21 22 ModelBootstrap.InitApplicationDatabase(this.getApplicationContext()); 22 23 -
trunk/rapidandroid/org.rapidandroid/src/org/rapidandroid/activity/Dashboard.java
r128 r129 522 522 523 523 private void startActivityChart() { 524 Debug.stopMethodTracing(); 524 525 if (mListviewCursor == null) { 525 526 Builder noDataDialog = new AlertDialog.Builder(this); -
trunk/rapidandroid/org.rapidandroid/src/org/rapidandroid/activity/chart/ChartBroker.java
r128 r129 56 56 protected Date mStartDate = Constants.NULLDATE; 57 57 protected Date mEndDate = Constants.NULLDATE; 58 // protected Calendar mStartCal = Constants.NULLCALENDAR; //we may need to switch to using calendar's due to the sheer number of conversions we're doing with them back and forth. 59 // protected Calendar mEndCal = Constants.NULLCALENDAR; 58 60 59 61 protected SmsDbHelper rawDB; -
trunk/rapidandroid/org.rapidandroid/src/org/rapidandroid/content/translation/MessageTranslator.java
r122 r129 16 16 /** 17 17 * Helper class to simplify the insertion and querying of raw SMS messages from 18 * the content provider. 19 * 20 * <br>Goal for this class is to return Message objects instead of cursors. 18 * the content provider. 19 * 20 * <br> 21 * Goal for this class is to return Message objects instead of cursors. 21 22 * 22 23 * @author Daniel Myung [email protected] … … 30 31 private static HashMap<Integer, Monitor> mMonitorHash = new HashMap<Integer, Monitor>(); 31 32 private static HashMap<String, Monitor> mMonitorHashByPhone = new HashMap<String, Monitor>(); 32 33 33 34 /** 34 * To ease DB hits on the insert of messages, the monitorhash has two hastables indexed by phone number and ID. 35 * We need to update this thing on each new insert. 35 * To ease DB hits on the insert of messages, the monitorhash has two 36 * hastables indexed by phone number and ID. We need to update this thing on 37 * each new insert. 38 * 36 39 * @param context 37 40 */ … … 40 43 mMonitorHash = new HashMap<Integer, Monitor>(); 41 44 mMonitorHashByPhone = new HashMap<String, Monitor>(); 42 Cursor monitorCursor = context.getContentResolver().query(RapidSmsDBConstants.Monitor.CONTENT_URI, null, null, 43 null, null); 44 if (monitorCursor.getCount() == 0) { 45 monitorCursor.close(); 46 return; 47 } 48 49 50 monitorCursor.moveToFirst(); 51 52 do { 53 // (int id, String firstName, String lastName, String alias, 54 // String phone, String email, int incomingMessages) { 55 56 57 58 Monitor newMonitor = new Monitor(monitorCursor.getInt(Monitor.COL_ID), 59 monitorCursor.getString(Monitor.COL_FIRSTNAME), 60 monitorCursor.getString(Monitor.COL_LASTNAME), 61 monitorCursor.getString(Monitor.COL_ALIAS), 62 monitorCursor.getString(Monitor.COL_PHONE), 63 monitorCursor.getString(Monitor.COL_EMAIL), 64 monitorCursor.getInt(Monitor.COL_MESSAGECOUNT), 65 monitorCursor.getInt(Monitor.COL_RECEIVE_REPLY)==1); 66 mMonitorHash.put(Integer.valueOf(newMonitor.getID()), newMonitor); 67 mMonitorHashByPhone.put(newMonitor.getPhone(), newMonitor); 68 } while (monitorCursor.moveToNext()); 45 Cursor monitorCursor = context.getContentResolver() 46 .query(RapidSmsDBConstants.Monitor.CONTENT_URI, null, null, 47 null, null); 48 // if (monitorCursor.getCount() == 0) { 49 // monitorCursor.close(); 50 // return; 51 // } 52 53 if (monitorCursor.moveToFirst()) { 54 55 do { 56 // (int id, String firstName, String lastName, String alias, 57 // String phone, String email, int incomingMessages) { 58 59 Monitor newMonitor = new Monitor(monitorCursor 60 .getInt(Monitor.COL_ID), monitorCursor 61 .getString(Monitor.COL_FIRSTNAME), monitorCursor 62 .getString(Monitor.COL_LASTNAME), monitorCursor 63 .getString(Monitor.COL_ALIAS), monitorCursor 64 .getString(Monitor.COL_PHONE), monitorCursor 65 .getString(Monitor.COL_EMAIL), monitorCursor 66 .getInt(Monitor.COL_MESSAGECOUNT), monitorCursor 67 .getInt(Monitor.COL_RECEIVE_REPLY) == 1); 68 mMonitorHash.put(Integer.valueOf(newMonitor.getID()), 69 newMonitor); 70 mMonitorHashByPhone.put(newMonitor.getPhone(), newMonitor); 71 } while (monitorCursor.moveToNext()); 72 } 73 69 74 monitorCursor.close(); 70 75 } … … 72 77 /** 73 78 * Get a handle to monitor for a given ID 79 * 74 80 * @param context 75 81 * @param monitorID … … 82 88 } else { 83 89 throw new IllegalArgumentException( 84 90 "Error in application state. The monitor hash should always be up to date when querying"); 85 91 } 86 92 } … … 88 94 /** 89 95 * Get a monitor or insert a new one based upon a given phone number 90 * 91 * @returns The monitor found or created. This is necesary to do link a new message to a Monitor.ID 96 * 97 * @returns The monitor found or created. This is necesary to do link a new 98 * message to a Monitor.ID 92 99 * 93 100 */ 94 101 public static synchronized Monitor GetMonitorAndInsertIfNew(Context context, String phone) { 95 96 97 102 if (mMonitorHashByPhone.containsKey(phone)) { 98 103 return mMonitorHashByPhone.get(phone); … … 101 106 cv.put(RapidSmsDBConstants.Monitor.PHONE, phone); 102 107 Uri newUri = context.getContentResolver().insert(RapidSmsDBConstants.Monitor.CONTENT_URI, cv); 103 updateMonitorHash(context);108 //updateMonitorHash(context); 104 109 return mMonitorHashByPhone.get(phone); 105 110 } … … 111 116 } 112 117 113 Uri getMessageUri = Uri.parse(RapidSmsDBConstants.Message.CONTENT_URI_STRING + messageID); 114 115 Cursor msgCursor = context.getContentResolver().query(getMessageUri, null, null, null, null); 118 Uri getMessageUri = Uri 119 .parse(RapidSmsDBConstants.Message.CONTENT_URI_STRING 120 + messageID); 121 122 Cursor msgCursor = context.getContentResolver().query(getMessageUri, 123 null, null, null, null); 116 124 msgCursor.moveToFirst(); 117 125 if (msgCursor.getCount() != 1) { 126 msgCursor.close(); 118 127 return null; 119 128 } else { … … 121 130 String datestring = msgCursor.getString(Message.COL_TIME); 122 131 Date msgDate = Message.SQLDateFormatter.parse(datestring); 123 124 String recvstring = msgCursor.getString(Message.COL_RECEIVE_TIME); 125 Date recvDate = msgDate; //for old entries, should we set it to null or just copy it? 126 if(recvstring == null || recvstring == "") { 132 133 String recvstring = msgCursor 134 .getString(Message.COL_RECEIVE_TIME); 135 Date recvDate = msgDate; // for old entries, should we set it to 136 // null or just copy it? 137 if (recvstring == null || recvstring == "") { 127 138 recvDate = Message.SQLDateFormatter.parse(datestring); 128 139 } 129 130 131 Message newMessage = new Message( 132 msgCursor.getInt(Message.COL_ID), 133 msgCursor.getString(Message.COL_MESSAGE), 134 msgDate, 135 mMonitorHash.get(Integer.valueOf(msgCursor.getInt(Message.COL_MONITOR))), 136 recvDate 137 ); 140 141 Message newMessage = new Message(msgCursor 142 .getInt(Message.COL_ID), msgCursor 143 .getString(Message.COL_MESSAGE), msgDate, mMonitorHash 144 .get(Integer.valueOf(msgCursor 145 .getInt(Message.COL_MONITOR))), recvDate); 138 146 msgCursor.close(); 139 147 return newMessage; … … 144 152 } 145 153 146 public static synchronized Message[] GetMessages(Context context, int[] messages) { 154 public static synchronized Message[] GetMessages(Context context, 155 int[] messages) { 147 156 if (mMonitorHash == null) { 148 157 updateMonitorHash(context); … … 159 168 whereclause += ")"; 160 169 161 Cursor msgCursor = context.getContentResolver().query(getMessageUri, null, whereclause, null, "time DESC"); 170 Cursor msgCursor = context.getContentResolver().query(getMessageUri, 171 null, whereclause, null, "time DESC"); 162 172 int retlen = msgCursor.getCount(); 163 173 Message[] ret = new Message[retlen]; … … 168 178 String datestring = msgCursor.getString(Message.COL_TIME); 169 179 Date msgDate = Message.SQLDateFormatter.parse(datestring); 170 171 String recvstring = msgCursor.getString(Message.COL_RECEIVE_TIME); 172 Date recvDate = msgDate; //for old entries, should we set it to null or just copy it? 173 174 if(recvstring == null || recvstring == "") { 180 181 String recvstring = msgCursor 182 .getString(Message.COL_RECEIVE_TIME); 183 Date recvDate = msgDate; // for old entries, should we set it to 184 // null or just copy it? 185 186 if (recvstring == null || recvstring == "") { 175 187 recvDate = Message.SQLDateFormatter.parse(datestring); 176 188 } 177 178 Message newMessage = new Message( 179 msgCursor.getInt(Message.COL_ID), 180 msgCursor.getString(Message.COL_MESSAGE), 181 msgDate, 182 mMonitorHash.get(Integer.valueOf(msgCursor.getInt(Message.COL_MONITOR))), 183 recvDate 184 ); 189 190 Message newMessage = new Message(msgCursor 191 .getInt(Message.COL_ID), msgCursor 192 .getString(Message.COL_MESSAGE), msgDate, mMonitorHash 193 .get(Integer.valueOf(msgCursor 194 .getInt(Message.COL_MONITOR))), recvDate); 185 195 ret[i] = newMessage; 186 196 } catch (Exception ex) { -
trunk/rapidandroid/org.rapidandroid/src/org/rapidandroid/data/SmsDbHelper.java
r122 r129 83 83 + "\"monitor_id\" integer NULL REFERENCES \"rapidandroid_monitor\" (\"id\")," 84 84 + "\"time\" datetime NOT NULL," + "\"message\" varchar(160) NOT NULL," 85 + "\"is_outgoing\" bool NOT NULL," + "\"is_virtual\" bool NOT NULL);"; 85 + "\"is_outgoing\" bool NOT NULL," + "\"is_virtual\" bool NOT NULL," 86 + "\"receive_time\" datetime NULL);"; 86 87 87 88 String mCreateTable_Monitor = "CREATE TABLE \"rapidandroid_monitor\" (" -
trunk/rapidandroid/org.rapidandroid/src/org/rapidandroid/receiver/SmsParseReceiver.java
r120 r129 65 65 } 66 66 if (prefixes == null) { 67 initLists(); 67 initLists(); //profiler shows us that this is being called frequently on new messages. 68 68 } 69 69 // TODO Auto-generated method stub -
trunk/rapidandroid/org.rapidandroid/src/org/rapidandroid/receiver/SmsReceiver.java
r128 r129 66 66 67 67 messageValues.put(RapidSmsDBConstants.Message.MONITOR, monitor.getID()); 68 messageValues.put(RapidSmsDBConstants.Message.TIME, Message.SQLDateFormatter.format(ts)); 68 messageValues.put(RapidSmsDBConstants.Message.TIME, Message.SQLDateFormatter.format(ts)); //expensive string formatting operation. 69 //messageValues.put(RapidSmsDBConstants.Message.TIME, mesg.getTimestampMillis()); //longs don't store as datetimes 69 70 messageValues.put(RapidSmsDBConstants.Message.IS_OUTGOING, false); 70 71 Date now = new Date(); 71 messageValues.put(RapidSmsDBConstants.Message.RECEIVE_TIME, Message.SQLDateFormatter.format(now)); 72 messageValues.put(RapidSmsDBConstants.Message.RECEIVE_TIME, Message.SQLDateFormatter.format(now)); //profile has shown this is an expensive operation 73 //messageValues.put(RapidSmsDBConstants.Message.RECEIVE_TIME, now.getTime()); //but this doesn't fracking work to convert to a datetime value. 72 74 boolean successfulSave = false; 73 75 Uri msgUri = null; -
trunk/rapidjava/org.rapidsms.java/src/org/rapidsms/java/core/Constants.java
r93 r129 1 1 package org.rapidsms.java.core; 2 2 3 import java.util.Calendar; 3 4 import java.util.Date; 4 5 import java.util.GregorianCalendar; … … 11 12 public class Constants { 12 13 public static final Date NULLDATE = new GregorianCalendar(1900,1,1,5,0).getTime(); 14 public static final Calendar NULLCALENDAR = new GregorianCalendar(1900,1,1,5,0); 13 15 }