Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ******************************************************************************************************
- Handler code:
- ******************************************************************************************************
- private Handler uiMsgHandler = new Handler() {
- @Override
- public void handleMessage(Message msg) {
- int DlgId = 0;
- int ItemId = 0;
- String value;
- Bundle b = new Bundle();
- Set<String> s = null;
- if (msg != null) {
- b = msg.getData();
- Log.i(TAG,"bundle is "+b);
- s = b.keySet();
- if (s.size()==1) {
- Iterator itr = s.iterator();
- while (itr.hasNext()) {
- String element = (String) itr.next();
- DlgId = Integer.parseInt(element);
- Log.i(TAG,"DigId is "+DlgId);
- }
- // now we need to get the item id which is the first two digits/chars of the value string
- value = b.getString(String.valueOf(DlgId));
- Log.i(TAG,"value is "+value);
- ItemId = Integer.parseInt(value.substring(0,2));
- // now we can handle each specific dialog
- Log.i(TAG,"ItemId is "+ItemId);
- switch (DlgId) {
- case 1:
- switch (ItemId) {
- case 1:
- Log.i(TAG,"Bundle data for Dialog "+DlgId+" Item "+ItemId+" is "+value.substring(2));
- // someMemberVar = {to....}.substring(4,MsgLen);
- break;
- case 2:
- Log.i(TAG,"Bundle data for Dialog "+DlgId+" Item "+ItemId+" is "+value.substring(2));
- break;
- case 99:
- Log.i(TAG,"Bundle data for Dialog "+DlgId+" Item "+ItemId+" is "+value.substring(2));
- // doCloseDlg();
- break;
- default: /* item out of range */
- Log.i(TAG,"Error: DialogID "+DlgId+" with message item id "+ItemId+" is out of range");
- } // end of Variable switch
- break;
- default: /* dialog id was out of range */
- Log.i(TAG,"Error: dialog id was out of range");
- Log.i(TAG,"Bundle data for Dialog "+DlgId+" Item "+ItemId+"is "+value.substring(2));
- break;
- } // end of Dialog switch
- }
- } else {
- //we have too many keys!
- Log.i(TAG,"Error: Too many keys in bundle");
- }
- }
- };
- *******************************************************************************************************
- Part of custom dialog code
- *******************************************************************************************************
- ....
- switch (id) { // id is the dialog id
- case 1:
- .....
- acceptButton.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View v) {
- //Inform the user the button has been clicked
- Log.i(TAG, "ACCEPT BUTTON PRESSED");
- // now we are going to do the messaging
- // addOptQty is item id 01
- b.putString("" + id, "01" + addOptQty);
- Log.i(TAG,"first bundle string: "+id+"01"+addOptQty);
- Log.i(TAG,""+b);
- // msg.what=id;
- msg.setData(b);
- // msg.setTarget(mResponseHandler);
- Log.i(TAG,"first message is: "+msg.toString());
- // now send the message to the handler
- /* try {
- // msg.sendToTarget();
- Log.i(TAG,"delivery time est "+msg.getWhen());
- mResponseHandler.sendMessage(msg);
- } catch (Exception e) {
- Log.i(TAG, "ERROR SENDING MESSAGE");
- }
- */
- // addOptPrice is item id 02
- // b.clear();
- b.putString("" + id, "02" + addOptPrice);
- Log.i(TAG,"second bundle string: "+id+"02"+addOptPrice);
- Log.i(TAG,""+b);
- // msg.what=id+1;
- msg.setData(b);
- Log.i(TAG,"second message is: "+msg.toString());
- // now send the message to the handler
- try {
- // msg.sendToTarget();
- Log.i(TAG,"delivery time est "+msg.getWhen());
- mResponseHandler.sendMessage(msg);
- } catch (Exception e) {
- Log.i(TAG, "ERROR SENDING MESSAGE");
- }
- }
- });
- ******************************************************************************************************
- output from log:
- ******************************************************************************************************
- 08-27 18:05:25.375 3349-3349/com.leadingordersolutions.OptionAnalyzer I/onCreateDialog:: ACCEPT BUTTON PRESSED
- 08-27 18:05:25.375 3349-3349/com.leadingordersolutions.OptionAnalyzer I/onCreateDialog:: first bundle string: 10125
- 08-27 18:05:25.375 3349-3349/com.leadingordersolutions.OptionAnalyzer I/onCreateDialog:: Bundle[{1=0125}]
- 08-27 18:05:25.375 3349-3349/com.leadingordersolutions.OptionAnalyzer I/onCreateDialog:: first message is: { what=0 when=-2h14m46s43ms }
- 08-27 18:05:25.375 3349-3349/com.leadingordersolutions.OptionAnalyzer I/onCreateDialog:: second bundle string: 1021.55
- 08-27 18:05:25.375 3349-3349/com.leadingordersolutions.OptionAnalyzer I/onCreateDialog:: Bundle[{1=021.55}]
- 08-27 18:05:25.375 3349-3349/com.leadingordersolutions.OptionAnalyzer I/onCreateDialog:: second message is: { what=0 when=-2h14m46s43ms }
- 08-27 18:05:25.375 3349-3349/com.leadingordersolutions.OptionAnalyzer I/onCreateDialog:: delivery time est 0
- 08-27 18:05:25.375 3349-3349/com.leadingordersolutions.OptionAnalyzer I/*** OptionDisplayActivity ***: bundle is Bundle[{1=021.55}]
- 08-27 18:05:25.375 3349-3349/com.leadingordersolutions.OptionAnalyzer I/*** OptionDisplayActivity ***: DigId is 1
- 08-27 18:05:25.375 3349-3349/com.leadingordersolutions.OptionAnalyzer I/*** OptionDisplayActivity ***: value is 021.55
- 08-27 18:05:25.375 3349-3349/com.leadingordersolutions.OptionAnalyzer I/*** OptionDisplayActivity ***: ItemId is 2
- 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