本文整理汇总了Java中com.google.android.gms.fitness.data.Session类的典型用法代码示例。如果您正苦于以下问题:Java Session类的具体用法?Java Session怎么用?Java Session使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Session类属于com.google.android.gms.fitness.data包,在下文中一共展示了Session类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: loadSessionData
import com.google.android.gms.fitness.data.Session; //导入依赖的package包/类
public Observable<SessionData> loadSessionData(final GoogleApiClient googleApiClient, final String sessionId) {
// create read request (only read distance, not location for overview)
final SessionReadRequest readRequest = createReadRequest()
.setSessionId(sessionId)
.build();
return Observable.defer(new Func0<Observable<SessionData>>() {
@Override
public Observable<SessionData> call() {
SessionReadResult readResult = Fitness.SessionsApi.readSession(googleApiClient, readRequest).await();
if (readResult.getSessions().isEmpty()) throw new IllegalStateException("error finding session " + sessionId);
// parse result
Session session = readResult.getSessions().get(0);
List<Location> locations = locationsFromDataSet(readResult.getDataSet(session, DataType.TYPE_LOCATION_SAMPLE).get(0));
Timber.d("found " + locations.size() + " locations");
return Observable.just(new SessionData(session, locations));
}
});
}
示例2: startFitDataSession
import com.google.android.gms.fitness.data.Session; //导入依赖的package包/类
/**
* Starts a new session for Fit data. This will take care of registering all the sensors,
* recording the sensor data, and registering the data set as a session to Google Fit.
* @param dataTypeSettings Types of data to listen to, in an array.
* @param sessionDescription The description of the session.
* @param listener The OnDataPointListener to receive sensor events.
*/
public void startFitDataSession(FitDataTypeSetting[] dataTypeSettings,
String sessionDescription, OnDataPointListener listener) {
for (FitDataTypeSetting dataTypeSetting : dataTypeSettings) {
registerFitDataListener(dataTypeSetting, listener);
startRecordingFitData(dataTypeSetting);
}
Session session = new Session.Builder()
.setName(SESSION_NAME)
.setDescription(sessionDescription)
.setActivity(FitnessActivities.RUNNING_JOGGING)
.setStartTime(System.currentTimeMillis(), TimeUnit.MILLISECONDS)
.build();
PendingResult<Status> pendingResult =
Fitness.SessionsApi.startSession(mGoogleApiClient, session);
pendingResult.setResultCallback(new FitResultCallback<Status>(
this, FitResultCallback.RegisterType.SESSION, null /* dataType */,
true /* subscribe */));
}
示例3: createSession
import com.google.android.gms.fitness.data.Session; //导入依赖的package包/类
/**
* Sessions can include multiple data set types.
*
* @param startTime Start time for the activity in milliseconds
* @param endTime End time for the activity in milliseconds
* @param stepCountDelta Number of steps during the activity
* @param activityName Name of the activity, must match FitnessActivities types
* @param packageName Package name for the app
* @return Resulting insert request
*/
public static SessionInsertRequest createSession(long startTime, long endTime, int stepCountDelta, String activityName, String packageName, Device device) {
// Create a session with metadata about the activity.
Session session = new Session.Builder()
.setName(TAG)
//.setDescription("Long run around Shoreline Park")
.setIdentifier(packageName + ":" + startTime)
.setActivity(FitnessActivities.WALKING)
.setStartTime(startTime, TimeUnit.MILLISECONDS)
.setEndTime(endTime, TimeUnit.MILLISECONDS)
.build();
// Build a session insert request
return new SessionInsertRequest.Builder()
.setSession(session)
.addDataSet(createStepDeltaDataSet(startTime, endTime, stepCountDelta, packageName, device))
.addDataSet(createActivityDataSet(startTime, endTime, activityName, packageName, device))
.build();
}
示例4: saveActiveSession
import com.google.android.gms.fitness.data.Session; //导入依赖的package包/类
@Override
public void saveActiveSession(final long endTime) {
PendingResult<SessionStopResult> pendingResult = _sessionsApi.stopSession(_googleAPIClient, _sessionIdentifier);
pendingResult.setResultCallback(new ResultCallback<SessionStopResult>() {
@Override
public void onResult(SessionStopResult sessionStopResult) {
if (sessionStopResult.getSessions().size() > 0) {
for (Session session : sessionStopResult.getSessions()) {
buildDataPoints(session, endTime);
insertDataPoints(session);
}
}
_sessionDataList.clear();
}
});
}
示例5: createSession
import com.google.android.gms.fitness.data.Session; //导入依赖的package包/类
private Session createSession(long startTime) {
//String description = "";
String sessionName = _playServices.generateSessionName();
_sessionIdentifier = _playServices.generateSessionIdentifier(startTime);
Session session = _playServices.newSessionBuilder()
.setName(sessionName)
.setIdentifier(_sessionIdentifier)
//.setDescription(description)
.setStartTime(startTime, TimeUnit.MILLISECONDS)
// optional - if your app knows what activity:
//.setActivity(FitnessActivities.RUNNING)
.build();
_sessionsApi.startSession(_googleAPIClient, session);
return session;
}
示例6: setupMocks
import com.google.android.gms.fitness.data.Session; //导入依赖的package包/类
private void setupMocks() {
_mockContext = mock(Context.class);
when(_mockContext.getPackageName()).thenReturn("com.somepackage.or.other");
_mockGoogleApiClient = mock(GoogleApiClient.class);
_mockSessionsApi = mock(SessionsApi.class);
_mockSession = mock(Session.class);
_mockSessionBuilder = mock(Session.Builder.class);
when(_mockSessionBuilder.setName(anyString())).thenReturn(_mockSessionBuilder);
when(_mockSessionBuilder.setIdentifier(anyString())).thenReturn(_mockSessionBuilder);
when(_mockSessionBuilder.setStartTime(anyLong(),any(TimeUnit.class))).thenReturn(_mockSessionBuilder);
when(_mockSessionBuilder.build()).thenReturn(_mockSession);
_mockPlayServices = mock(IGooglePlayServices.class);
when(_mockPlayServices.newSessionBuilder()).thenReturn(_mockSessionBuilder);
_mockResult = mock(PendingResult.class);
when(_mockSessionsApi.stopSession(any(GoogleApiClient.class),anyString())).thenReturn(_mockResult);
}
示例7: getDataSet
import com.google.android.gms.fitness.data.Session; //导入依赖的package包/类
private DataSet getDataSet() {
ArrayList<Session> sessions = new ArrayList<>();
sessions.add(_mockSession);
ArgumentCaptor<ResultCallback> captor = ArgumentCaptor.forClass(ResultCallback.class);
verify(_mockResult, times(1)).setResultCallback(captor.capture());
ArgumentCaptor<Session> sessionArgumentCaptor = ArgumentCaptor.forClass(Session.class);
captor.getValue().onResult(new SessionStopResult(new Status(1), sessions));
ArgumentCaptor<DataSet> dataSetArgumentCaptor = ArgumentCaptor.forClass(DataSet.class);
verify(_mockPlayServices,times(1)).newSessionInsertRequest(sessionArgumentCaptor.capture(), dataSetArgumentCaptor.capture());
assertEquals(_mockSession, sessionArgumentCaptor.getValue());
return dataSetArgumentCaptor.getValue();
}
示例8: showSession
import com.google.android.gms.fitness.data.Session; //导入依赖的package包/类
private void showSession(Session session) {
DateFormat dateFormat = getTimeInstance();
sendmessage("Data returned for Session: " + session.getName());
sendmessage("Description: " + session.getDescription());
sendmessage("Start: " + dateFormat.format(session.getStartTime(TimeUnit.MILLISECONDS)));
sendmessage("End: " + dateFormat.format(session.getEndTime(TimeUnit.MILLISECONDS)));
}
示例9: createSession
import com.google.android.gms.fitness.data.Session; //导入依赖的package包/类
public Observable<Status> createSession(final GoogleApiClient googleApiClient, final Session session, final DataSet ... dataSets) {
return Observable.defer(new Func0<Observable<Status>>() {
@Override
public Observable<Status> call() {
SessionInsertRequest.Builder requestBuilder = new SessionInsertRequest.Builder().setSession(session);
for (DataSet dataSet : dataSets) requestBuilder.addDataSet(dataSet);
Status status = Fitness.SessionsApi.insertSession(googleApiClient, requestBuilder.build()).await();
return Observable.just(status);
}
});
}
示例10: SessionData
import com.google.android.gms.fitness.data.Session; //导入依赖的package包/类
protected SessionData(Parcel in) {
session = (Session) in.readValue(Session.class.getClassLoader());
if (in.readByte() == 0x01) {
locations = new ArrayList<Location>();
in.readList(locations, Location.class.getClassLoader());
} else {
locations = null;
}
}
示例11: buildDataPoints
import com.google.android.gms.fitness.data.Session; //导入依赖的package包/类
private void buildDataPoints(Session session, long endTime) {
if(_sessionDataList.size() < 1) {
createUnknownDataPoint(session, endTime);
} else {
SessionData nextData = null;
for(int n=0; n < _sessionDataList.size(); n++) {
long calculatedEndTime = (_sessionDataList.size() == n + 1) ? endTime : _sessionDataList.get(n+1).getStartTime();
createActivityDataPoint(_sessionDataList.get(n), calculatedEndTime);
}
}
}
示例12: newSessionInsertRequest
import com.google.android.gms.fitness.data.Session; //导入依赖的package包/类
@Override
public SessionInsertRequest newSessionInsertRequest(Session session, DataSet dataSet) {
return new SessionInsertRequest.Builder()
.addDataSet(dataSet)
.setSession(session)
.build();
}
示例13: viewSessionData
import com.google.android.gms.fitness.data.Session; //导入依赖的package包/类
/**
* Creates and executes a {@link SessionReadRequest} using {@link
* com.google.android.gms.fitness.SessionsClient} to verify the insertion succeeded .
*/
private Task<SessionReadResponse> viewSessionData() {
sendmessage("Reading Session API results for session: " + SAMPLE_SESSION_NAME);
// Begin by creating the query.
SessionReadRequest readRequest;
// [START build_read_session_request]
// Set a start and end time for our query, using a start time of 1 week before this moment.
Calendar cal = Calendar.getInstance();
Date now = new Date();
cal.setTime(now);
long endTime = cal.getTimeInMillis();
cal.add(Calendar.WEEK_OF_YEAR, -1);
long startTime = cal.getTimeInMillis();
// Build a session read request
readRequest = new SessionReadRequest.Builder()
.setTimeInterval(startTime, endTime, TimeUnit.MILLISECONDS)
.read(DataType.TYPE_SPEED)
.setSessionName(SAMPLE_SESSION_NAME)
.build();
// [END build_read_session_request]
// [START read_session]
// Invoke the Sessions API to fetch the session with the query and wait for the result
// of the read request. Note: Fitness.SessionsApi.readSession() requires the
// ACCESS_FINE_LOCATION permission.
return Fitness.getSessionsClient(getActivity(), GoogleSignIn.getLastSignedInAccount(getContext()))
.readSession(readRequest)
.addOnSuccessListener(new OnSuccessListener<SessionReadResponse>() {
@Override
public void onSuccess(SessionReadResponse sessionReadResponse) {
// Get a list of the sessions that match the criteria to check the result.
List<Session> sessions = sessionReadResponse.getSessions();
sendmessage( "Session read was successful. Number of returned sessions is: "
+ sessions.size());
for (Session session : sessions) {
// Process the session
showSession(session);
// Process the data sets for this session
List<DataSet> dataSets = sessionReadResponse.getDataSet(session);
for (DataSet dataSet : dataSets) {
showDataSet(dataSet);
}
}
}
})
.addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception e) {
sendmessage( "Failed to read session");
}
});
// [END read_session]
}
示例14: stopAndSaveRecording
import com.google.android.gms.fitness.data.Session; //导入依赖的package包/类
public Observable<RecordingResult> stopAndSaveRecording(final GoogleApiClient googleApiClient) {
return Observable.defer(new Func0<Observable<RecordingResult>>() {
@Override
public Observable<RecordingResult> call() {
// create location data
DataSet locationDataSet = recordedLocationsToDataSet();
Observable<Status> resultObservable;
if (!locationDataSet.isEmpty()) {
// create session
long startTimestamp = locationDataSet.getDataPoints().get(0).getTimestamp(TimeUnit.MILLISECONDS);
final Session session = new Session.Builder()
.setName("TheAwesomeKeepOnSession")
.setIdentifier(UUID.randomUUID().toString())
.setDescription("A session for testing")
.setStartTime(startTimestamp, TimeUnit.MILLISECONDS)
.setEndTime(System.currentTimeMillis(), TimeUnit.MILLISECONDS)
.setActivity(FitnessActivities.RUNNING_JOGGING)
.build();
resultObservable = sessionManager
// save session
.createSession(googleApiClient, session, locationDataSet)
// add session to challenge
.flatMap(new Func1<Status, Observable<Status>>() {
@Override
public Observable<Status> call(Status status) {
if (status.isSuccess()) {
challenge.addSessionId(session.getIdentifier());
challenge.save();
}
return Observable.just(status);
}
});
} else {
// discard empty sessions
Timber.w("discarding empty session");
resultObservable = Observable.just(null);
}
stopAndDiscardRecording(googleApiClient);
return resultObservable.flatMap(new Func1<Status, Observable<RecordingResult>>() {
@Override
public Observable<RecordingResult> call(Status saveStatus) {
RecordingResult recordingResult;
if (saveStatus == null) recordingResult = new RecordingResult(true, null);
else recordingResult = new RecordingResult(false, saveStatus);
return Observable.just(recordingResult);
}
});
}
});
}
示例15: getSession
import com.google.android.gms.fitness.data.Session; //导入依赖的package包/类
public Session getSession() {
return session;
}