Skip to content

Instantly share code, notes, and snippets.

@the-jedi-droid
Last active September 11, 2015 08:03
Show Gist options
  • Save the-jedi-droid/4f086436d11637a26f87 to your computer and use it in GitHub Desktop.
Save the-jedi-droid/4f086436d11637a26f87 to your computer and use it in GitHub Desktop.
package io.hypertrack.driverdemo;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
import com.hypertrack.apps.assettracker.network.HyperTrack;
import com.hypertrack.apps.assettracker.service.TransmitterService;
public class MainActivity extends AppCompatActivity implements TransmitterService.StatusCallback {
//trip details
private String courierId;
private int[] orderIdArray;
//Fragment Manager and the fragment
private FragmentManager mMgr;
//Views on Main Acitivity
private Button startTripButton;
private Button endTripButton;
private Button deliveredButton;
//Trip ID
private String tripId;
private TransmitterService transmitterService;
private TransmitterActivityFragment transmitterActivityFragment;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
//Set public API key here
HyperTrack.setAPIKey("<API KEY>");
//Setup order details
transmitterService = new TransmitterService(this);
String courierId = "1";
int[] orderIds = {302};
transmitterService.setOrderDetails(courierId, orderIds);
//initialize views
initViews();
}
public void initViews() {
startTripButton = (Button)findViewById(R.id.startTripButton);
endTripButton = (Button)findViewById(R.id.endTripButton);
deliveredButton = (Button)findViewById(R.id.deliveredButton);
//To start tracking call startTracking method.
startTripButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
transmitterService.startTrip();
}
});
//To end tracking call endTracking method.
endTripButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
transmitterService.endTrip(Integer.valueOf(tripId));
}
});
//To notify delivery
deliveredButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
transmitterService.notifyDelivered(orderID);
}
});
}
@Override
public void onTripStarted(String tripId) {
// Callback method for trip started. Save this trip id for future references.
this.tripId = tripId;
}
@Override
public void onTripStartError() {
}
@Override
public void onTripEnded(String tripId) {
// Callback method for trip ended
}
@Override
public void onTripEndError() {
}
@Override
public void onDelivererd() {
// Callback method for delivered
}
@Override
public void onDelivererdError() {
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment