Advertisement
moonlightcheese

ScreenQueryTask

Jul 20th, 2011
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 13.07 KB | None | 0 0
  1. /*********************************
  2. **SCROLL DOWN FOR LOGCAT OUTPUT **
  3. **********************************/
  4.  
  5. private class ScreenQueryTask extends AsyncTask<String, Void, Cursor> {
  6.         Messenger replyTo;
  7.         int arg1;
  8.        
  9.         public ScreenQueryTask(Messenger msgr, int arg1) {
  10.             this.replyTo = msgr;
  11.             this.arg1=arg1;
  12.         }
  13.        
  14.         protected Cursor doInBackground(String... screenQuery) {
  15.             //here we want to loop through the screen cursor and add names to the records from the contact list
  16.             Cursor screenCursor = null;
  17.             String display_name = "";
  18.             String _id = "";
  19.             String number = "";
  20.             String time = "";
  21.             String customer = "";
  22.             String duration = "";
  23.             String duration_billed = "";
  24.             String pending = "";
  25.             String call_id = "";
  26.             String job_id = "";
  27.             String job_name = "";
  28.             String job_num = "";
  29.            
  30.             MatrixCursor finalCursor = new MatrixCursor(
  31.                 new String[] {
  32.                     "android_call_id",
  33.                     mDbCallTable.COLUMN_PHONE,
  34.                     mDbCallTable.COLUMN_TIME,
  35.                     mDbCallTable.COLUMN_DURATION,
  36.                     mDbCallTable.COLUMN_DURATION_BILLED,
  37.                     mDbCallTable.COLUMN_PENDING,
  38.                     mDbCallTable.COLUMN_CALL_ID,
  39.                     mDbCallTable.COLUMN_JOB_ID,
  40.                     mDbCallTable.COLUMN_CUSTOMER,
  41.                     "android_job_id",
  42.                     mDbJobTable.COLUMN_NAME,
  43.                     mDbJobTable.COLUMN_JOB_NUMBER,
  44.                     "display_name"
  45.                 });
  46.            
  47.             String[] projection = new String[] { ContactsContract.Data.DISPLAY_NAME, ContactsContract.CommonDataKinds.Phone.NUMBER };
  48.             try {
  49.                 screenCursor = mDb.rawQuery(screenQuery[0], null);
  50.                 screenCursor.moveToFirst();
  51.             } catch(Exception e) {
  52.                 //
  53.             }
  54.            
  55.             Cursor cursor = null;
  56.            
  57.             do {
  58.                 try {
  59.                     //get all the columns from the screenCursor
  60.                     _id = screenCursor.getString(screenCursor.getColumnIndex("android_call_id"));
  61.                     number = screenCursor.getString(screenCursor.getColumnIndex(mDbCallTable.COLUMN_PHONE));
  62.                     time = screenCursor.getString(screenCursor.getColumnIndex(mDbCallTable.COLUMN_TIME));
  63.                     customer = screenCursor.getString(screenCursor.getColumnIndex(mDbCallTable.COLUMN_CUSTOMER));
  64.                     duration = screenCursor.getString(screenCursor.getColumnIndex(mDbCallTable.COLUMN_DURATION));
  65.                     duration_billed = screenCursor.getString(screenCursor.getColumnIndex(mDbCallTable.COLUMN_DURATION_BILLED));
  66.                     pending = screenCursor.getString(screenCursor.getColumnIndex(mDbCallTable.COLUMN_PENDING));
  67.                     call_id = screenCursor.getString(screenCursor.getColumnIndex(mDbCallTable.COLUMN_CALL_ID));
  68.                     job_id = screenCursor.getString(screenCursor.getColumnIndex("android_job_id"));
  69.                     job_name = screenCursor.getString(screenCursor.getColumnIndex(mDbJobTable.COLUMN_NAME));
  70.                     job_num = screenCursor.getString(screenCursor.getColumnIndex(mDbJobTable.COLUMN_JOB_NUMBER));
  71.                    
  72.                     //Log.i(LOG_TAG, "record: "+duration);
  73.                     ContentResolver contentResolver = getContentResolver();
  74.                    
  75.                     if(number.length()==7) {
  76.                         cursor = getContentResolver().query(ContactsContract.Data.CONTENT_URI, null,
  77.                             ContactsContract.CommonDataKinds.Phone.NUMBER+" LIKE ?",
  78.                             new String[] { "%"+number },
  79.                             null);
  80.                     } else if(number.length()==10) {
  81.                         cursor = getContentResolver().query(ContactsContract.Data.CONTENT_URI, null,
  82.                             "("+ContactsContract.CommonDataKinds.Phone.NUMBER+"=? AND LENGTH("+ContactsContract.CommonDataKinds.Phone.NUMBER+")=7) OR ("+ContactsContract.CommonDataKinds.Phone.NUMBER+"=? AND LENGTH("+ContactsContract.CommonDataKinds.Phone.NUMBER+")=10)",
  83.                             new String[] { number.substring(3), number },
  84.                             null);
  85.                     } else {
  86.                         cursor = getContentResolver().query(ContactsContract.Data.CONTENT_URI, null,
  87.                             ContactsContract.CommonDataKinds.Phone.NUMBER+"=?",
  88.                             new String[] { number },
  89.                             null);
  90.                     }
  91.                 } catch(Exception e) {
  92.                     //
  93.                 }
  94.                
  95.                 try {
  96.                     cursor.moveToFirst();
  97.                     display_name = cursor.getString(cursor.getColumnIndex(ContactsContract.Data.DISPLAY_NAME));
  98.                     if(_id!=null) {
  99.                         finalCursor.addRow(new String[] {_id, number, time, duration, duration_billed, pending, call_id, job_id, customer, job_id, job_name, job_num, display_name});
  100.                     }
  101.                     try {
  102.                         Log.i(LOG_TAG, "---------------------------");
  103.                         Log.i(LOG_TAG, "_id: "+_id);
  104.                         Log.i(LOG_TAG, "num: "+number);
  105.                         Log.i(LOG_TAG, "tim: "+time);
  106.                         Log.i(LOG_TAG, "dur: "+duration);
  107.                         Log.i(LOG_TAG, "drb: "+duration_billed);
  108.                         Log.i(LOG_TAG, "cid: "+call_id);
  109.                         Log.i(LOG_TAG, "job: "+job_name);
  110.                         Log.i(LOG_TAG, "jid: "+job_id);
  111.                         Log.i(LOG_TAG, "jnm: "+job_num);
  112.                         Log.i(LOG_TAG, "cnm: "+customer);
  113.                         Log.i(LOG_TAG, "pnd: "+pending);
  114.                         Log.i(LOG_TAG, "dnm: "+display_name);
  115.                     } catch(Exception e2) {
  116.                         Log.e(LOG_TAG, "problem printing value.");
  117.                     }
  118.                 } catch(Exception e) {
  119.                     Log.e(LOG_TAG, "error building matrix cursor for display: "+e.getMessage());
  120.                     try {
  121.                         Log.e(LOG_TAG, "---------------------------");
  122.                         Log.e(LOG_TAG, "_id: "+_id);
  123.                         Log.e(LOG_TAG, "num: "+number);
  124.                         Log.e(LOG_TAG, "tim: "+time);
  125.                         Log.e(LOG_TAG, "dur: "+duration);
  126.                         Log.e(LOG_TAG, "drb: "+duration_billed);
  127.                         Log.e(LOG_TAG, "cid: "+call_id);
  128.                         Log.e(LOG_TAG, "job: "+job_name);
  129.                         Log.e(LOG_TAG, "jid: "+job_id);
  130.                         Log.e(LOG_TAG, "jnm: "+job_num);
  131.                         Log.e(LOG_TAG, "cnm: "+customer);
  132.                         Log.e(LOG_TAG, "pnd: "+pending);
  133.                         Log.e(LOG_TAG, "dnm: "+display_name);
  134.                     } catch(Exception e2) {
  135.                         Log.e(LOG_TAG, "problem printing value.");
  136.                     }
  137.                 }
  138.                
  139.             } while(screenCursor.moveToNext());
  140.             return finalCursor;
  141.         }
  142.        
  143.         protected void onPostExecute(Cursor resultCursor) {
  144.             try {
  145.                 replyTo.send(Message.obtain(null, MinutemaidService.MESSAGE_QUERY_RESULT, this.arg1, 0, (Object)resultCursor));
  146.                 Log.i(LOG_TAG, "sending reply to query request");
  147.                 showNotification();
  148.             } catch (Exception e) {
  149.                 Log.e(LOG_TAG, "oops: "+e.getMessage());
  150.             }
  151.         }
  152.     };
  153.  
  154. /***** OUTPUT IN LOGCAT ********/
  155.  
  156. 07-20 16:10:57.778: ERROR/Minutemaid - Service(5271): error building matrix cursor for display: Index 0 requested, with a size of 0
  157. 07-20 16:10:57.778: ERROR/Minutemaid - Service(5271): ---------------------------
  158. 07-20 16:10:57.778: ERROR/Minutemaid - Service(5271): _id: 44
  159. 07-20 16:10:57.778: ERROR/Minutemaid - Service(5271): num: 6153456350
  160. 07-20 16:10:57.778: ERROR/Minutemaid - Service(5271): tim: 1311108541019
  161. 07-20 16:10:57.778: ERROR/Minutemaid - Service(5271): dur: 374
  162. 07-20 16:10:57.778: ERROR/Minutemaid - Service(5271): drb: 720
  163. 07-20 16:10:57.778: ERROR/Minutemaid - Service(5271): cid: 425
  164. 07-20 16:10:57.778: ERROR/Minutemaid - Service(5271): job: null
  165. 07-20 16:10:57.778: ERROR/Minutemaid - Service(5271): jid: null
  166. 07-20 16:10:57.778: ERROR/Minutemaid - Service(5271): jnm: null
  167. 07-20 16:10:57.778: ERROR/Minutemaid - Service(5271): cnm: null
  168. 07-20 16:10:57.778: ERROR/Minutemaid - Service(5271): pnd: 1
  169. 07-20 16:10:57.778: ERROR/Minutemaid - Service(5271): dnm:
  170. 07-20 16:10:57.808: ERROR/Minutemaid - Service(5271): error building matrix cursor for display: Index 0 requested, with a size of 0
  171. 07-20 16:10:57.808: ERROR/Minutemaid - Service(5271): ---------------------------
  172. 07-20 16:10:57.808: ERROR/Minutemaid - Service(5271): _id: 45
  173. 07-20 16:10:57.808: ERROR/Minutemaid - Service(5271): num: 8008480981
  174. 07-20 16:10:57.808: ERROR/Minutemaid - Service(5271): tim: 1311118955412
  175. 07-20 16:10:57.808: ERROR/Minutemaid - Service(5271): dur: 63
  176. 07-20 16:10:57.808: ERROR/Minutemaid - Service(5271): drb: 360
  177. 07-20 16:10:57.808: ERROR/Minutemaid - Service(5271): cid: 426
  178. 07-20 16:10:57.808: ERROR/Minutemaid - Service(5271): job: null
  179. 07-20 16:10:57.808: ERROR/Minutemaid - Service(5271): jid: null
  180. 07-20 16:10:57.808: ERROR/Minutemaid - Service(5271): jnm: null
  181. 07-20 16:10:57.808: ERROR/Minutemaid - Service(5271): cnm: null
  182. 07-20 16:10:57.808: ERROR/Minutemaid - Service(5271): pnd: 1
  183. 07-20 16:10:57.808: ERROR/Minutemaid - Service(5271): dnm:
  184. 07-20 16:10:57.878: INFO/Minutemaid - Service(5271): ---------------------------
  185. 07-20 16:10:57.878: INFO/Minutemaid - Service(5271): _id: 46
  186. 07-20 16:10:57.878: INFO/Minutemaid - Service(5271): num: 7133737664
  187. 07-20 16:10:57.888: INFO/Minutemaid - Service(5271): tim: 1311122175521
  188. 07-20 16:10:57.888: INFO/Minutemaid - Service(5271): dur: 17
  189. 07-20 16:10:57.888: INFO/Minutemaid - Service(5271): drb: 360
  190. 07-20 16:10:57.888: INFO/Minutemaid - Service(5271): cid: 428
  191. 07-20 16:10:57.888: INFO/Minutemaid - Service(5271): job: null
  192. 07-20 16:10:57.888: INFO/Minutemaid - Service(5271): jid: null
  193. 07-20 16:10:57.888: INFO/Minutemaid - Service(5271): jnm: null
  194. 07-20 16:10:57.888: INFO/Minutemaid - Service(5271): cnm: null
  195. 07-20 16:10:57.888: INFO/Minutemaid - Service(5271): pnd: 1
  196. 07-20 16:10:57.888: INFO/Minutemaid - Service(5271): dnm: Julia Walsh
  197. 07-20 16:10:57.908: INFO/Minutemaid - Service(5271): ---------------------------
  198. 07-20 16:10:57.908: INFO/Minutemaid - Service(5271): _id: 47
  199. 07-20 16:10:57.908: INFO/Minutemaid - Service(5271): num: 7133737664
  200. 07-20 16:10:57.908: INFO/Minutemaid - Service(5271): tim: 1311126243267
  201. 07-20 16:10:57.908: INFO/Minutemaid - Service(5271): dur: 40
  202. 07-20 16:10:57.908: INFO/Minutemaid - Service(5271): drb: 360
  203. 07-20 16:10:57.908: INFO/Minutemaid - Service(5271): cid: 430
  204. 07-20 16:10:57.908: INFO/Minutemaid - Service(5271): job: null
  205. 07-20 16:10:57.908: INFO/Minutemaid - Service(5271): jid: null
  206. 07-20 16:10:57.908: INFO/Minutemaid - Service(5271): jnm: null
  207. 07-20 16:10:57.908: INFO/Minutemaid - Service(5271): cnm: null
  208. 07-20 16:10:57.908: INFO/Minutemaid - Service(5271): pnd: 1
  209. 07-20 16:10:57.908: INFO/Minutemaid - Service(5271): dnm: Julia Walsh
  210. 07-20 16:10:57.938: INFO/Minutemaid - Service(5271): ---------------------------
  211. 07-20 16:10:57.938: INFO/Minutemaid - Service(5271): _id: 48
  212. 07-20 16:10:57.938: INFO/Minutemaid - Service(5271): num: 7133737664
  213. 07-20 16:10:57.938: INFO/Minutemaid - Service(5271): tim: 1311126566511
  214. 07-20 16:10:57.938: INFO/Minutemaid - Service(5271): dur: 66
  215. 07-20 16:10:57.938: INFO/Minutemaid - Service(5271): drb: 360
  216. 07-20 16:10:57.938: INFO/Minutemaid - Service(5271): cid: 431
  217. 07-20 16:10:57.938: INFO/Minutemaid - Service(5271): job: null
  218. 07-20 16:10:57.938: INFO/Minutemaid - Service(5271): jid: null
  219. 07-20 16:10:57.938: INFO/Minutemaid - Service(5271): jnm: null
  220. 07-20 16:10:57.938: INFO/Minutemaid - Service(5271): cnm: null
  221. 07-20 16:10:57.938: INFO/Minutemaid - Service(5271): pnd: 1
  222. 07-20 16:10:57.938: INFO/Minutemaid - Service(5271): dnm: Julia Walsh
  223. 07-20 16:10:57.958: INFO/Minutemaid - Service(5271): ---------------------------
  224. 07-20 16:10:57.958: INFO/Minutemaid - Service(5271): _id: 49
  225. 07-20 16:10:57.958: INFO/Minutemaid - Service(5271): num: 7133737664
  226. 07-20 16:10:57.958: INFO/Minutemaid - Service(5271): tim: 1311127116451
  227. 07-20 16:10:57.958: INFO/Minutemaid - Service(5271): dur: 5501
  228. 07-20 16:10:57.958: INFO/Minutemaid - Service(5271): drb: 5760
  229. 07-20 16:10:57.958: INFO/Minutemaid - Service(5271): cid: 432
  230. 07-20 16:10:57.958: INFO/Minutemaid - Service(5271): job: null
  231. 07-20 16:10:57.958: INFO/Minutemaid - Service(5271): jid: null
  232. 07-20 16:10:57.958: INFO/Minutemaid - Service(5271): jnm: null
  233. 07-20 16:10:57.958: INFO/Minutemaid - Service(5271): cnm: null
  234. 07-20 16:10:57.958: INFO/Minutemaid - Service(5271): pnd: 1
  235. 07-20 16:10:57.958: INFO/Minutemaid - Service(5271): dnm: Julia Walsh
  236. 07-20 16:10:57.988: ERROR/Minutemaid - Service(5271): error building matrix cursor for display: Index 0 requested, with a size of 0
  237. 07-20 16:10:57.988: ERROR/Minutemaid - Service(5271): ---------------------------
  238. 07-20 16:10:57.988: ERROR/Minutemaid - Service(5271): _id: 51
  239. 07-20 16:10:57.988: ERROR/Minutemaid - Service(5271): num: 6157261094
  240. 07-20 16:10:57.988: ERROR/Minutemaid - Service(5271): tim: 1311193655509
  241. 07-20 16:10:57.988: ERROR/Minutemaid - Service(5271): dur: 5
  242. 07-20 16:10:57.988: ERROR/Minutemaid - Service(5271): drb: 360
  243. 07-20 16:10:57.988: ERROR/Minutemaid - Service(5271): cid: 434
  244. 07-20 16:10:57.988: ERROR/Minutemaid - Service(5271): job: null
  245. 07-20 16:10:57.988: ERROR/Minutemaid - Service(5271): jid: null
  246. 07-20 16:10:57.988: ERROR/Minutemaid - Service(5271): jnm: null
  247. 07-20 16:10:57.988: ERROR/Minutemaid - Service(5271): cnm: null
  248. 07-20 16:10:57.988: ERROR/Minutemaid - Service(5271): pnd: 1
  249. 07-20 16:10:57.988: ERROR/Minutemaid - Service(5271): dnm: Julia Walsh
  250. 07-20 16:10:58.008: INFO/Minutemaid - Service(5271): ---------------------------
  251. 07-20 16:10:58.008: INFO/Minutemaid - Service(5271): _id: 50
  252. 07-20 16:10:58.008: INFO/Minutemaid - Service(5271): num: 6157262578
  253. 07-20 16:10:58.008: INFO/Minutemaid - Service(5271): tim: 1311184725046
  254. 07-20 16:10:58.008: INFO/Minutemaid - Service(5271): dur: 37
  255. 07-20 16:10:58.008: INFO/Minutemaid - Service(5271): drb: 360
  256. 07-20 16:10:58.008: INFO/Minutemaid - Service(5271): cid: 433
  257. 07-20 16:10:58.008: INFO/Minutemaid - Service(5271): job: null
  258. 07-20 16:10:58.008: INFO/Minutemaid - Service(5271): jid: null
  259. 07-20 16:10:58.008: INFO/Minutemaid - Service(5271): jnm: null
  260. 07-20 16:10:58.008: INFO/Minutemaid - Service(5271): cnm: Conceptual Systems
  261. 07-20 16:10:58.008: INFO/Minutemaid - Service(5271): pnd: 1
  262. 07-20 16:10:58.008: INFO/Minutemaid - Service(5271): dnm: Conceptual Systems
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement