Advertisement
Guest User

Untitled

a guest
Nov 27th, 2014
166
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.18 KB | None | 0 0
  1. public void onActivityResult(int requestCode, int resultCode, Intent data)
  2. {
  3. if (resultCode == Activity.RESULT_OK && getActivity() != null)
  4. {
  5. if (requestCode == ZBAR_QR_SCANNER_REQUEST)
  6. {
  7. final ProgressDialog dialog = ProgressDialog.show(getActivity(), "Loading", "Checking reward...");
  8.  
  9. String contents = data.getStringExtra(ZBarConstants.SCAN_RESULT);
  10. ParseQuery<ParseObject> locationParentCompanyCheckQuery = new ParseQuery<ParseObject>("RetailLocation");
  11. locationParentCompanyCheckQuery.whereEqualTo("appCompany", LocalUser.getInstance().getParentCompany());
  12.  
  13. ParseQuery<ParseObject> qrCodequery = ParseQuery.getQuery(Constants.OBJECT_QRCODE);
  14. qrCodequery.whereMatchesQuery("location", locationParentCompanyCheckQuery);
  15. qrCodequery.whereEqualTo("objectId", contents);
  16. qrCodequery.include("location");
  17. qrCodequery.getFirstInBackground(new GetCallback<ParseObject>()
  18. {
  19. @Override
  20. public void done(final ParseObject qrCodeObject, ParseException e)
  21. {
  22. if (getActivity() != null)
  23. {
  24. dialog.cancel();
  25. if (e == null)
  26. {
  27. final ProgressDialog locationCheckDialog = ProgressDialog.show(getActivity(), "Loading", "Checking your location...");
  28. final ParseObject locationObject = qrCodeObject.getParseObject("location");
  29. ParseGeoPoint.getCurrentLocationInBackground(10000, new LocationCallback()
  30. {
  31. @Override
  32. public void done(ParseGeoPoint parseGeoPoint, ParseException e)
  33. {
  34. if (getActivity() != null && locationCheckDialog != null)
  35. {
  36. locationCheckDialog.dismiss();
  37. }
  38.  
  39. if (e == null)
  40. {
  41. if (parseGeoPoint != null)
  42. {
  43. double distanceKilometers = parseGeoPoint.distanceInKilometersTo(locationObject.
  44. getParseGeoPoint("location"));
  45. double distanceMeters = distanceKilometers * 1000.0;
  46.  
  47. if (distanceMeters <= locationObject.getDouble("vicinityRadius"))
  48. {
  49. int pointsToAward = qrCodeObject.getInt(Constants.POINTS_TO_AWARD);
  50. userData.put("rewardPoints", userData.getInt("rewardPoints") + pointsToAward);
  51. userData.put("qrScanDate", new Date());
  52. userData.saveInBackground(new SaveCallback()
  53. {
  54. @Override
  55. public void done(ParseException paramParseException)
  56. {
  57. updateRewardsTextView();
  58. }
  59. });
  60. }
  61. else
  62. {
  63. Toast.makeText(getActivity(), "You must scan this code in a store to win loyalty points", Toast.LENGTH_SHORT).show();
  64. }
  65. }
  66. else
  67. {
  68. Toast.makeText(getActivity(), "Error - couldn't fetch your location", Toast.LENGTH_SHORT).show();
  69. }
  70. }
  71. else
  72. {
  73. e.printStackTrace();
  74. }
  75. }
  76. });
  77. }
  78. else
  79. {
  80. Toast.makeText(getActivity(), "Invalid QR code", Toast.LENGTH_SHORT).show();
  81. }
  82. }
  83. }
  84. });
  85. }
  86. }
  87. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement