Package fi.moprim.tmd.sdk
Class TmdCloudApi
- java.lang.Object
-
- fi.moprim.tmd.sdk.TmdCloudApi
-
public class TmdCloudApi extends java.lang.Object
This class offers static functions to interact with the Moprim Cloud. Most common use cases are fetching data and metadata and uploading data to the sync.
-
-
Field Summary
Fields Modifier and Type Field Description static boolean
DEFAULT_ALLOW_MOBILE_DATA
-
Constructor Summary
Constructors Constructor Description TmdCloudApi()
-
Method Summary
All Methods Static Methods Concrete Methods Deprecated Methods Modifier and Type Method Description static Result<java.lang.Boolean>
annotate(android.content.Context context, long timestampStart, long timestampEnd, java.lang.String mode, java.lang.String metadata, VehicleProfile vehicleProfile)
Label an interval of time with a mode and metadata This information will be forwarded to the cloud even if no corresponding data is available locallystatic Result<java.lang.Boolean>
annotate(android.content.Context context, long timestampStart, long timestampEnd, java.lang.String originalMode, java.lang.String correctedMode, java.lang.String metadata, VehicleProfile vehicleProfile)
Label an interval of time with a mode and metadata This information will be forwarded to the cloud even if no corresponding data is available locallystatic Result<TmdActivity>
annotateActivity(android.content.Context context, TmdActivity activity, java.lang.String metadata, VehicleProfile vehicleProfile)
Annotate the activity with new metadatastatic Result<TmdActivity>
correctActivity(android.content.Context context, TmdActivity activity, java.lang.String correctedLabel)
Correct the label of activitystatic Result<java.util.List<TmdActivity>>
fetchData(android.content.Context context, long start, long end)
Fetching data from the Moprim cloudstatic Result<java.util.List<TmdActivity>>
fetchData(android.content.Context context, long start, long end, boolean cacheOnly)
Fetching data from the Moprim cloudstatic Result<java.util.List<TmdActivity>>
fetchData(android.content.Context context, java.util.Date date)
Fetch TMD activity data from the Moprim Cloud for the defined datestatic Result<java.util.List<TmdActivity>>
fetchData(android.content.Context context, java.util.Date date, boolean cacheOnly)
Fetch TMD activity data from the Moprim Cloud for the defined datestatic Result<java.util.List<TmdActivity>>
fetchData(android.content.Context context, java.util.Date date, int offsetMinutes)
Fetch TMD activity data from the Moprim Cloud for the defined datestatic Result<java.util.List<TmdActivity>>
fetchData(android.content.Context context, java.util.Date date, int offsetMinutes, boolean cacheOnly)
Fetch TMD activity data from the Moprim Cloud for the defined datestatic Result<TmdCloudMetadata>
fetchMetadata(android.content.Context context)
Fetch the metadata from the Cloud.static Result<TmdCloudMetadata>
fetchMetadata(android.content.Context context, boolean cacheOnly)
Fetch the metadata from the Cloud.static Result<java.util.List<TmdStats>>
fetchStats(android.content.Context context, int last)
Fetching stats from the Moprim cloudstatic android.app.PendingIntent
getCallbackIntent()
Deprecated.since 0.5.0, use @link{TMD#getSdkMessenger} insteadstatic boolean
isMobileDataAllowed(android.content.Context context)
static void
setCallbackIntent(android.app.PendingIntent intent)
Deprecated.since 0.5.0static void
setDefaultMobileDataAllowed(android.content.Context context, boolean allowed)
This method should be called in the Application class to initialize the default use of mobile data for background data upload.static void
setMobileDataAllowed(android.content.Context context, boolean mobileDataAllowed)
static Result<TmdActivity>
updateActivity(android.content.Context context, TmdActivity activity, java.lang.String correctedLabel, java.lang.String metadata, VehicleProfile vehicleProfile)
Update the activity with new metadata and a corrected labelstatic Result<TmdUploadMetadata>
uploadData(android.content.Context context)
Upload the collected data to the cloud pro-activelystatic Result<TmdActivity>
validateActivity(android.content.Context context, TmdActivity activity)
Validate the label of activity
-
-
-
Field Detail
-
DEFAULT_ALLOW_MOBILE_DATA
public static final boolean DEFAULT_ALLOW_MOBILE_DATA
- See Also:
- Constant Field Values
-
-
Method Detail
-
setCallbackIntent
@Deprecated public static void setCallbackIntent(android.app.PendingIntent intent)
Deprecated.since 0.5.0Sets an callback intent for the background operation with the cloud.- Parameters:
intent
- the intent to be executed
-
getCallbackIntent
@Deprecated public static android.app.PendingIntent getCallbackIntent()
Deprecated.since 0.5.0, use @link{TMD#getSdkMessenger} instead- Returns:
- the callback that will be called during background operation with the cloud
-
fetchData
public static Result<java.util.List<TmdActivity>> fetchData(@NonNull android.content.Context context, @NonNull java.util.Date date)
Fetch TMD activity data from the Moprim Cloud for the defined date- Parameters:
context
- the contextdate
- the date- Returns:
- a list of TMD activities if successful, an error otherwise. If this method fails but cached data is available, error message can be accessed
-
fetchData
public static Result<java.util.List<TmdActivity>> fetchData(@NonNull android.content.Context context, @NonNull java.util.Date date, int offsetMinutes)
Fetch TMD activity data from the Moprim Cloud for the defined date- Parameters:
context
- the contextdate
- the dateoffsetMinutes
- the number of minutes to offset for the date. It can be negative- Returns:
- a list of TMD activities if successful, an error otherwise. If this method fails but cached data is available, error message can be accessed
-
fetchData
public static Result<java.util.List<TmdActivity>> fetchData(@NonNull android.content.Context context, @NonNull java.util.Date date, boolean cacheOnly)
Fetch TMD activity data from the Moprim Cloud for the defined date- Parameters:
context
- the contextdate
- the datecacheOnly
- set to true if you wish to use the cache only- Returns:
- a list of TMD activities if successful, an error otherwise. If this method fails but cached data is available, error message can be accessed
-
fetchData
public static Result<java.util.List<TmdActivity>> fetchData(@NonNull android.content.Context context, @NonNull java.util.Date date, int offsetMinutes, boolean cacheOnly)
Fetch TMD activity data from the Moprim Cloud for the defined date- Parameters:
context
- the contextdate
- the dateoffsetMinutes
- the number of minutes to add to start the datecacheOnly
- set to true if you wish to use the cache only- Returns:
- a list of TMD activities if successful, an error otherwise. If this method fails but cached data is available, error message can be accessed
-
fetchData
public static Result<java.util.List<TmdActivity>> fetchData(@NonNull android.content.Context context, long start, long end)
Fetching data from the Moprim cloud- Parameters:
context
- the contextstart
- the start time (timestamp in ms)end
- the end time (timestamp in ms)- Returns:
- a list of cached activities
-
fetchData
public static Result<java.util.List<TmdActivity>> fetchData(@NonNull android.content.Context context, long start, long end, boolean cacheOnly)
Fetching data from the Moprim cloud- Parameters:
context
- the contextstart
- the start time (timestamp in ms)end
- the end time (timestamp in ms)cacheOnly
- set to true if you wish not to request data from the cloud- Returns:
- a list of cached activities
-
fetchStats
public static Result<java.util.List<TmdStats>> fetchStats(@NonNull android.content.Context context, int last)
Fetching stats from the Moprim cloud- Parameters:
context
- the contextlast
- the number of days for the last period- Returns:
- the stats
-
fetchMetadata
public static Result<TmdCloudMetadata> fetchMetadata(@NonNull android.content.Context context)
Fetch the metadata from the Cloud. This function is usually called when one wants to know what data can be fetched from the Cloud- Parameters:
context
- the context- Returns:
- the cloud metadata
-
fetchMetadata
public static Result<TmdCloudMetadata> fetchMetadata(@NonNull android.content.Context context, boolean cacheOnly)
Fetch the metadata from the Cloud. This function is usually called when one wants to know what data can be fetched from the Cloud- Parameters:
context
- the contextcacheOnly
- if true, only check the cache- Returns:
- the cloud metadata
-
uploadData
public static Result<TmdUploadMetadata> uploadData(@NonNull android.content.Context context)
Upload the collected data to the cloud pro-actively- Parameters:
context
- the context running the request- Returns:
- how much data was collected
-
validateActivity
public static Result<TmdActivity> validateActivity(@NonNull android.content.Context context, TmdActivity activity)
Validate the label of activity- Parameters:
context
- the contextactivity
- the activity to validate- Returns:
- the validated activity
-
correctActivity
public static Result<TmdActivity> correctActivity(@NonNull android.content.Context context, TmdActivity activity, java.lang.String correctedLabel)
Correct the label of activity- Parameters:
context
- the contextactivity
- the activity to correctcorrectedLabel
- the new label- Returns:
- the corrected activity
-
annotateActivity
public static Result<TmdActivity> annotateActivity(@NonNull android.content.Context context, TmdActivity activity, java.lang.String metadata, VehicleProfile vehicleProfile)
Annotate the activity with new metadata- Parameters:
context
- the contextactivity
- the activity to correctmetadata
- the metadata- Returns:
- the annotated activity
-
updateActivity
public static Result<TmdActivity> updateActivity(@NonNull android.content.Context context, TmdActivity activity, java.lang.String correctedLabel, java.lang.String metadata, VehicleProfile vehicleProfile)
Update the activity with new metadata and a corrected label- Parameters:
context
- the contextactivity
- the activity to correctcorrectedLabel
- the new labelmetadata
- the metadata- Returns:
- the updated activity
-
annotate
public static Result<java.lang.Boolean> annotate(@NonNull android.content.Context context, long timestampStart, long timestampEnd, java.lang.String mode, java.lang.String metadata, VehicleProfile vehicleProfile)
Label an interval of time with a mode and metadata This information will be forwarded to the cloud even if no corresponding data is available locally- Parameters:
context
- the contexttimestampStart
- the start timestamp of the annotationtimestampEnd
- the end timestamp of the annotationmode
- the modemetadata
- the metadatavehicleProfile
- the vehicle profile- Returns:
- the true if the annotation was successfully saved.
-
annotate
public static Result<java.lang.Boolean> annotate(@NonNull android.content.Context context, long timestampStart, long timestampEnd, java.lang.String originalMode, java.lang.String correctedMode, java.lang.String metadata, VehicleProfile vehicleProfile)
Label an interval of time with a mode and metadata This information will be forwarded to the cloud even if no corresponding data is available locally- Parameters:
context
- the contexttimestampStart
- the start timestamp of the annotationtimestampEnd
- the end timestamp of the annotationoriginalMode
- the original mode for the activitycorrectedMode
- the corrected mode for the activitymetadata
- the metadata- Returns:
- the true if the annotation was successfully saved.
-
isMobileDataAllowed
public static boolean isMobileDataAllowed(@NonNull android.content.Context context)
-
setMobileDataAllowed
public static void setMobileDataAllowed(@NonNull android.content.Context context, boolean mobileDataAllowed)
-
setDefaultMobileDataAllowed
public static void setDefaultMobileDataAllowed(@NonNull android.content.Context context, boolean allowed)
This method should be called in the Application class to initialize the default use of mobile data for background data upload. Nothing happens if the- Parameters:
context
- the context of the applicationallowed
- if the use of mobile data is allow by default or not
-
-