Guest User

Android messages bundles

a guest
Aug 27th, 2013
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.44 KB | None | 0 0
  1. ******************************************************************************************************
  2. Handler code:
  3. ******************************************************************************************************
  4. private Handler uiMsgHandler = new Handler() {
  5. @Override
  6. public void handleMessage(Message msg) {
  7. int DlgId = 0;
  8. int ItemId = 0;
  9. String value;
  10.  
  11. Bundle b = new Bundle();
  12.  
  13. Set<String> s = null;
  14.  
  15. if (msg != null) {
  16. b = msg.getData();
  17. Log.i(TAG,"bundle is "+b);
  18.  
  19. s = b.keySet();
  20. if (s.size()==1) {
  21.  
  22. Iterator itr = s.iterator();
  23. while (itr.hasNext()) {
  24. String element = (String) itr.next();
  25. DlgId = Integer.parseInt(element);
  26. Log.i(TAG,"DigId is "+DlgId);
  27. }
  28.  
  29. // now we need to get the item id which is the first two digits/chars of the value string
  30.  
  31. value = b.getString(String.valueOf(DlgId));
  32. Log.i(TAG,"value is "+value);
  33. ItemId = Integer.parseInt(value.substring(0,2));
  34. // now we can handle each specific dialog
  35. Log.i(TAG,"ItemId is "+ItemId);
  36. switch (DlgId) {
  37. case 1:
  38.  
  39. switch (ItemId) {
  40. case 1:
  41. Log.i(TAG,"Bundle data for Dialog "+DlgId+" Item "+ItemId+" is "+value.substring(2));
  42. // someMemberVar = {to....}.substring(4,MsgLen);
  43. break;
  44. case 2:
  45. Log.i(TAG,"Bundle data for Dialog "+DlgId+" Item "+ItemId+" is "+value.substring(2));
  46. break;
  47. case 99:
  48. Log.i(TAG,"Bundle data for Dialog "+DlgId+" Item "+ItemId+" is "+value.substring(2));
  49. // doCloseDlg();
  50. break;
  51. default: /* item out of range */
  52. Log.i(TAG,"Error: DialogID "+DlgId+" with message item id "+ItemId+" is out of range");
  53. } // end of Variable switch
  54.  
  55. break;
  56.  
  57. default: /* dialog id was out of range */
  58. Log.i(TAG,"Error: dialog id was out of range");
  59. Log.i(TAG,"Bundle data for Dialog "+DlgId+" Item "+ItemId+"is "+value.substring(2));
  60. break;
  61.  
  62. } // end of Dialog switch
  63.  
  64. }
  65. } else {
  66. //we have too many keys!
  67. Log.i(TAG,"Error: Too many keys in bundle");
  68. }
  69.  
  70. }
  71. };
  72.  
  73. *******************************************************************************************************
  74. Part of custom dialog code
  75. *******************************************************************************************************
  76.  
  77. ....
  78. switch (id) { // id is the dialog id
  79. case 1:
  80.  
  81. .....
  82.  
  83. acceptButton.setOnClickListener(new View.OnClickListener() {
  84. @Override
  85. public void onClick(View v) {
  86. //Inform the user the button has been clicked
  87. Log.i(TAG, "ACCEPT BUTTON PRESSED");
  88.  
  89. // now we are going to do the messaging
  90.  
  91. // addOptQty is item id 01
  92. b.putString("" + id, "01" + addOptQty);
  93. Log.i(TAG,"first bundle string: "+id+"01"+addOptQty);
  94. Log.i(TAG,""+b);
  95. // msg.what=id;
  96. msg.setData(b);
  97. // msg.setTarget(mResponseHandler);
  98. Log.i(TAG,"first message is: "+msg.toString());
  99. // now send the message to the handler
  100. /* try {
  101. // msg.sendToTarget();
  102. Log.i(TAG,"delivery time est "+msg.getWhen());
  103. mResponseHandler.sendMessage(msg);
  104. } catch (Exception e) {
  105. Log.i(TAG, "ERROR SENDING MESSAGE");
  106. }
  107. */
  108. // addOptPrice is item id 02
  109. // b.clear();
  110. b.putString("" + id, "02" + addOptPrice);
  111. Log.i(TAG,"second bundle string: "+id+"02"+addOptPrice);
  112. Log.i(TAG,""+b);
  113. // msg.what=id+1;
  114. msg.setData(b);
  115. Log.i(TAG,"second message is: "+msg.toString());
  116.  
  117. // now send the message to the handler
  118. try {
  119. // msg.sendToTarget();
  120. Log.i(TAG,"delivery time est "+msg.getWhen());
  121. mResponseHandler.sendMessage(msg);
  122. } catch (Exception e) {
  123. Log.i(TAG, "ERROR SENDING MESSAGE");
  124. }
  125.  
  126.  
  127. }
  128. });
  129. ******************************************************************************************************
  130. output from log:
  131. ******************************************************************************************************
  132. 08-27 18:05:25.375 3349-3349/com.leadingordersolutions.OptionAnalyzer I/onCreateDialog:: ACCEPT BUTTON PRESSED
  133. 08-27 18:05:25.375 3349-3349/com.leadingordersolutions.OptionAnalyzer I/onCreateDialog:: first bundle string: 10125
  134. 08-27 18:05:25.375 3349-3349/com.leadingordersolutions.OptionAnalyzer I/onCreateDialog:: Bundle[{1=0125}]
  135. 08-27 18:05:25.375 3349-3349/com.leadingordersolutions.OptionAnalyzer I/onCreateDialog:: first message is: { what=0 when=-2h14m46s43ms }
  136. 08-27 18:05:25.375 3349-3349/com.leadingordersolutions.OptionAnalyzer I/onCreateDialog:: second bundle string: 1021.55
  137. 08-27 18:05:25.375 3349-3349/com.leadingordersolutions.OptionAnalyzer I/onCreateDialog:: Bundle[{1=021.55}]
  138. 08-27 18:05:25.375 3349-3349/com.leadingordersolutions.OptionAnalyzer I/onCreateDialog:: second message is: { what=0 when=-2h14m46s43ms }
  139. 08-27 18:05:25.375 3349-3349/com.leadingordersolutions.OptionAnalyzer I/onCreateDialog:: delivery time est 0
  140. 08-27 18:05:25.375 3349-3349/com.leadingordersolutions.OptionAnalyzer I/*** OptionDisplayActivity ***: bundle is Bundle[{1=021.55}]
  141. 08-27 18:05:25.375 3349-3349/com.leadingordersolutions.OptionAnalyzer I/*** OptionDisplayActivity ***: DigId is 1
  142. 08-27 18:05:25.375 3349-3349/com.leadingordersolutions.OptionAnalyzer I/*** OptionDisplayActivity ***: value is 021.55
  143. 08-27 18:05:25.375 3349-3349/com.leadingordersolutions.OptionAnalyzer I/*** OptionDisplayActivity ***: ItemId is 2
  144. 08-27 18:05:25.375 3349-3349/com.leadingordersolutions.OptionAnalyzer I/*** OptionDisplayActivity ***: Bundle data for Dialog 1 Item 2 is 1.55
Advertisement
Add Comment
Please, Sign In to add comment