Placeline

Placeline is useful in tracking your daily activity with near-zero battery impact. We automatically use the combination of device sensors - GPS, WiFi, network, accelerometer, pedometer, gyroscope, compass - to deliver accuracy. Placeline is powered by the HyperTrack SDK which collects location and activity data for your users.

Basic Setup

For using placeline in the app, you need to complete the basic integration of HyperTrack SDK by following the instructions from here iOS or Android.

Placeline Data Format

Placeline object contains detailed information about the activity like the start time, end time, location, steps and more. An example JSON representation is given here.

Get Placeline Data in your App

Use the following function to get placeline data from HyperTrack's SDK. It returns a Placeline object which have segments of activities.

 HyperTrack.getPlaceline(date: Date()) { (placeLine, error) in
    if let error = error {
        // Handle get placeline API error here
        ...
        return
    }

    // placeline object consists of segments of activities
    if let placeLine = placeLine {
        for hypertrackActivity in placeLine.segments {
            // retrieve the activities from placeline and use them
                    ...
        }
    }
}
[HyperTrack getPlacelineWithDate:[NSDate date] completionHandler:^(HyperTrackPlaceline * placeline, HyperTrackError * error) {
    if (error != nil){
       // handle placeline api error
        return
    }

    if (placeline != nil){

         // placeline object consists of segments of activities
        [placeline.segments enumerateObjectsUsingBlock:^(HyperTrackActivity * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
         // retrieve the activities from placeline and use them
                      ...
         }];
     }
  }];
Date date = new Date();
HyperTrack.getPlaceline(date, new HyperTrackCallback() {
    @Override
    public void onSuccess(@NonNull SuccessResponse response) {
        // Handle getPlaceline success here
        if (response != null) {
            PlacelineData = (PlacelineData) response.getResponseObject();
        }
    }

    @Override
    public void onError(@NonNull ErrorResponse errorResponse) {
        // Handle getPlaceline error here
        Log.d("Placeline", "onError: " + errorResponse.getErrorMessage());
    }
});

Get Placeline View in your Android App

Step 1: Setup Activity

  • Firstly, add the following xml snippet in your view layout to enable PlacelineFragment.
<fragment
    android:id="@+id/placeline_fragment"
    android:name="com.hypertrack.lib.internal.consumer.view.Placeline.PlacelineFragment"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:layout="@layout/placeline_fragment" />
  • Secondly, instantiate PlacelineFragment in the onCreate method of the activity in which placeline fragment has been included.
PlacelineFragment placelineFragment = (PlacelineFragment) getSupportFragmentManager().findFragmentById(R.id.placeline_fragment);

Once all of the above is done, the code snippet would look like as below.

@Override
protected void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);

  ...

  // Initialize Placeline Fragment added in Activity Layout
  PlacelineFragment placelineFragment = (PlacelineFragment) getSupportFragmentManager().findFragmentById(R.id.placeline_fragment); 

  ...
}

Step 2: Disable ActionBar

In case your AppTheme adds an ActionBar by default, disable the default Action Bar for the activity containing PlacelineFragment by adding the following under your Activity's theme style-tag in styles.xml file. Refer to Android documentation on Setting up the AppBar.

<!-- Change Placeline activity's theme to remove default ActionBar. -->
<style name="PlacelineActivityTheme" parent="Theme.AppCompat.Light.NoActionBar">
    ...
    <!-- We will be using the toolbar so no need to show ActionBar -->
    <item name="windowActionBar">false</item>
    <item name="windowNoTitle">true</item>
    <item name="colorAccent">@color/colorAccent</item>
      ...
</style>

Add the android:theme attribute to the <activity> tag in AndroidManifest.xml file.

<!-- Placeline Activity Tag -->
 <activity android:name=".PlacelineActivity"
    android:theme="@style/PlacelineActivityTheme"/>

Step 3: Start Placeline Activity

Placeline Activity can be the Launcher activity or it can start from some other activity as normal activity.

Launcher Activity

Add the following xml snippet in your AndroidManifest.xml file to make PlacelineActivity as a launcher activity.

<activity
    android:name=".PlacelineActivity"
    android:theme="@style/PlacelineActivityTheme">
    <intent-filter>
        <action android:name="android.intent.action.MAIN" />
        <category android:name="android.intent.category.LAUNCHER" />
    </intent-filter>
</activity>

Normal Activity

Add the following snippet in your activity from which you want to start PlacelineActivity.

public void startPlaceline(View view) {
    startActivity(new Intent(this, PlacelineActivity.class));
}

Get Placeline View in your iOS App

To get the placeline view in your ViewController, just call the getPlacelineView function. It takes the desired frame of the view and date as parameter. If you don't specify the date, the default date chosen is today's date.

 override func viewDidAppear(_ animated: Bool) {
        super.viewDidAppear(true)
        // get placeline view with a frame size and date.
        let placelineView =  HyperTrack.getPlacelineView(frame: self.view.frame)
        // add placeline view as subview
        self.view.addSubview(placelineView)
}
- (void) viewDidAppear:(BOOL)animated {
    // get placeline view with a frame size and date.
    PlacelineView * view = [HyperTrack getPlacelineViewWithFrame:self.view.frame forDate:[NSDate date]];
    // add placeline view as subview
    [self.view addSubview:view]  ;
}

results matching ""

    No results matching ""