daily pastebin goal
5%
SHARE
TWEET

Untitled

a guest Feb 13th, 2018 53 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package com.example.mayank.hypertrackdemo;
  2.  
  3. import android.content.Intent;
  4. import android.support.annotation.NonNull;
  5. import android.support.v7.app.AppCompatActivity;
  6. import android.os.Bundle;
  7. import android.util.Log;
  8. import android.view.View;
  9. import android.widget.Button;
  10. import android.widget.Toast;
  11.  
  12. import com.google.android.gms.maps.model.LatLng;
  13. import com.hypertrack.lib.HyperTrack;
  14. import com.hypertrack.lib.callbacks.HyperTrackCallback;
  15. import com.hypertrack.lib.models.Action;
  16. import com.hypertrack.lib.models.ActionParams;
  17. import com.hypertrack.lib.models.ActionParamsBuilder;
  18. import com.hypertrack.lib.models.ErrorResponse;
  19. import com.hypertrack.lib.models.Place;
  20. import com.hypertrack.lib.models.SuccessResponse;
  21.  
  22. import java.util.ArrayList;
  23. import java.util.List;
  24. import java.util.ListIterator;
  25.  
  26. public class MainActivity extends AppCompatActivity {
  27.  
  28.     Button ticketing, tracking, startMockTracking, createAssignActions, completeActions, stopMockTracking ;
  29.     List<String> actionIds=new ArrayList<String>();
  30.     @Override
  31.     protected void onCreate(Bundle savedInstanceState) {
  32.         super.onCreate(savedInstanceState);
  33.         setContentView(R.layout.activity_main);
  34.         HyperTrack.requestPermissions(this);
  35.         HyperTrack.requestLocationServices(this);
  36.         HyperTrack.startTracking();
  37.  
  38.         ticketing = (Button) findViewById(R.id.ticketing);
  39.         tracking = (Button) findViewById(R.id.tracking);
  40.         startMockTracking = (Button) findViewById(R.id.startMockTracking);
  41.         createAssignActions = (Button) findViewById(R.id.createAssignActions);
  42.         completeActions = (Button) findViewById(R.id.completeActions);
  43.         stopMockTracking = (Button) findViewById(R.id.stopMockTracking);
  44.  
  45.         ticketing.setOnClickListener(new View.OnClickListener() {
  46.             @Override
  47.             public void onClick(View v) {
  48.                 //for potrait mode ..uncomment this!
  49.                 startActivity(new Intent(MainActivity.this, ScannerActivity_pot.class));
  50.  
  51.                 //for landscape mode ..uncomment this!
  52. //                startActivity(new Intent(MainActivity.this,ScannerActivity.class));
  53.             }
  54.         });
  55.  
  56.         tracking.setOnClickListener(new View.OnClickListener() {
  57.             @Override
  58.             public void onClick(View v) {
  59.                 startActivity(new Intent(MainActivity.this, Maps.class));
  60.             }
  61.         });
  62.  
  63.         startMockTracking.setOnClickListener(new View.OnClickListener() {
  64.             @Override
  65.             public void onClick(View v) {
  66.                 LatLng startLatLng = new LatLng(28.674547,77.28712900000005);
  67.                 LatLng destinationLatLng = new LatLng(24.3431489,86.0236363999999);
  68.  
  69.                 HyperTrack.startMockTracking(startLatLng, destinationLatLng, new HyperTrackCallback() {
  70.                     @Override
  71.                     public void onSuccess(@NonNull SuccessResponse response) {
  72.  
  73.                     }
  74.  
  75.                     @Override
  76.                     public void onError(@NonNull ErrorResponse errorResponse) {
  77.  
  78.                     }
  79.                 });
  80.             }
  81.         });
  82.  
  83.         createAssignActions.setOnClickListener(new View.OnClickListener() {
  84.             @Override
  85.             public void onClick(View v) {
  86.                 double pointX[] = {28.674547,28.6700495,24.3431489,28.6635,28.6636157,28.6580975,28.5876545,28.553353};
  87.                 double pointY[] = {77.28712900000005,77.2785876,86.0236363999999,77.2825378,77.285959,77.2901891,77.3074928,77.16210409999997};
  88.                 String busStopNames[] = {"Shahdara Terminal","Kanti Nagar Extension","Jharkhandi","East Azad Nagar","Swaran Cinema","Hans Apartment","Krishna Nagar A Block","Vasant Vihar"};
  89.  
  90.                 List<ActionParams> actionParamsList=new ArrayList<ActionParams>();
  91.                 for (int i = 0 ; i < busStopNames.length; i++) {
  92.  
  93.                     Place expectedPlace = new Place().setLocation(pointX[i], pointY[i])
  94.                             .setAddress(busStopNames[i])
  95.                             .setName(busStopNames[i]);
  96.  
  97.                     /**
  98.                      * Create ActionParams object specifying the Visit Action parameters including
  99.                      * ExpectedPlace, ExpectedAt time and Action's Lookup_id.
  100.                      */
  101.                     actionParamsList.add( new ActionParamsBuilder().setExpectedPlace(expectedPlace)
  102.                             .setType(Action.ACTION_TYPE_VISIT)
  103.                             .build()
  104.                     );
  105.                 }
  106.  
  107.                 // object creation and assignment
  108.                 createAndAssignActiononHyperTrack(actionParamsList,0);
  109.             }
  110.         });
  111.  
  112.         completeActions.setOnClickListener(new View.OnClickListener() {
  113.             @Override
  114.             public void onClick(View v) {
  115.                 completeActionsonHyperTrack(0);
  116.             }
  117.         });
  118.  
  119.         stopMockTracking.setOnClickListener(new View.OnClickListener() {
  120.             @Override
  121.             public void onClick(View v) {
  122.                 HyperTrack.stopMockTracking();
  123.             }
  124.         });
  125.     }
  126.  
  127.     private void createAndAssignActiononHyperTrack(final List<ActionParams> actionParams, final int index) {
  128.         if (index >= actionParams.size())
  129.             return;
  130.         HyperTrack.createAndAssignAction(actionParams.get(index), new HyperTrackCallback() {
  131.             @Override
  132.             public void onSuccess(@NonNull SuccessResponse response) {
  133.                 createAndAssignActiononHyperTrack(actionParams, index + 1);
  134.                 Action action = (Action) response.getResponseObject();
  135.                 Log.d("createAndAssignAction", "onSuccess: "+action.getId());
  136.                 actionIds.add(action.getId());
  137.             }
  138.             @Override
  139.             public void onError(@NonNull ErrorResponse errorResponse) {
  140.                 Log.d("createAndAssignAction", "onError: "+errorResponse.getErrorMessage());
  141.             }
  142.         });
  143.     }
  144.  
  145.     private void completeActionsonHyperTrack(int index) {
  146.         final String actionId = actionIds.get(index);
  147.         HyperTrack.getAction(actionId, new HyperTrackCallback() {
  148.             @Override
  149.             public void onSuccess(@NonNull SuccessResponse response) {
  150.                 // Handle getAction response here
  151.                 Action actionResponse = (Action) response.getResponseObject();
  152.                 HyperTrack.completeAction(actionId);
  153.             }
  154.  
  155.             @Override
  156.             public void onError(@NonNull ErrorResponse errorResponse) {
  157.                 // Handle getAction error here
  158.                 Log.d("completeActions", "onError: "+errorResponse.getErrorMessage());
  159.             }
  160.         });
  161.     }
  162. }
RAW Paste Data
Top