• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java Session类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中com.google.android.gms.fitness.data.Session的典型用法代码示例。如果您正苦于以下问题:Java Session类的具体用法?Java Session怎么用?Java Session使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



Session类属于com.google.android.gms.fitness.data包,在下文中一共展示了Session类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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));
		}
	});
}
 
开发者ID:FauDroids,项目名称:KeepOn,代码行数:21,代码来源:SessionManager.java


示例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 */));
}
 
开发者ID:googlesamples,项目名称:android-play-games-in-motion,代码行数:28,代码来源:GoogleApiClientWrapper.java


示例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();
}
 
开发者ID:blackcj,项目名称:GoogleFitExample,代码行数:30,代码来源:DataQueries.java


示例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();
        }
    });
}
 
开发者ID:team-mount-ventoux,项目名称:JayPS-AndroidApp,代码行数:17,代码来源:GoogleFitSessionManager.java


示例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;
}
 
开发者ID:team-mount-ventoux,项目名称:JayPS-AndroidApp,代码行数:19,代码来源:GoogleFitSessionManager.java


示例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);
    }
 
开发者ID:team-mount-ventoux,项目名称:JayPS-AndroidApp,代码行数:23,代码来源:GoogleFitSessionManagerTest.java


示例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();
}
 
开发者ID:team-mount-ventoux,项目名称:JayPS-AndroidApp,代码行数:18,代码来源:GoogleFitSessionManagerTest.java


示例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)));
}
 
开发者ID:JimSeker,项目名称:googleplayAPI,代码行数:8,代码来源:SessionFragment.java


示例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);
		}
	});
}
 
开发者ID:FauDroids,项目名称:KeepOn,代码行数:12,代码来源:SessionManager.java


示例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;
	}
}
 
开发者ID:FauDroids,项目名称:KeepOn,代码行数:10,代码来源:SessionData.java


示例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);
        }
    }
}
 
开发者ID:team-mount-ventoux,项目名称:JayPS-AndroidApp,代码行数:12,代码来源:GoogleFitSessionManager.java


示例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();
}
 
开发者ID:team-mount-ventoux,项目名称:JayPS-AndroidApp,代码行数:8,代码来源:GooglePlayServices.java


示例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]
}
 
开发者ID:JimSeker,项目名称:googleplayAPI,代码行数:62,代码来源:SessionFragment.java


示例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);
				}
			});
		}
	});
}
 
开发者ID:FauDroids,项目名称:KeepOn,代码行数:57,代码来源:RecordingManager.java


示例15: getSession

import com.google.android.gms.fitness.data.Session; //导入依赖的package包/类
public Session getSession() {
	return session;
}
 
开发者ID:FauDroids,项目名称:KeepOn,代码行数:4,代码来源:SessionData.java


示例16: createUnknownDataPoint

import com.google.android.gms.fitness.data.Session; //导入依赖的package包/类
private void createUnknownDataPoint(Session session, long endTime) {
    DataPoint firstRunningDp = _activitySegments.createDataPoint()
            .setTimeInterval(session.getStartTime(TimeUnit.MILLISECONDS), endTime, TimeUnit.MILLISECONDS);
    firstRunningDp.getValue(Field.FIELD_ACTIVITY).setActivity(FitnessActivities.UNKNOWN);
    _activitySegments.add(firstRunningDp);
}
 
开发者ID:team-mount-ventoux,项目名称:JayPS-AndroidApp,代码行数:7,代码来源:GoogleFitSessionManager.java


示例17: insertDataPoints

import com.google.android.gms.fitness.data.Session; //导入依赖的package包/类
private void insertDataPoints(Session session) {
    _playServices.newSessionInsertRequest(session, _activitySegments);
    Log.d(TAG,"GoogleFit Session Saved");
}
 
开发者ID:team-mount-ventoux,项目名称:JayPS-AndroidApp,代码行数:5,代码来源:GoogleFitSessionManager.java


示例18: newSessionBuilder

import com.google.android.gms.fitness.data.Session; //导入依赖的package包/类
@Override
public Session.Builder newSessionBuilder() {
    return new Session.Builder();
}
 
开发者ID:team-mount-ventoux,项目名称:JayPS-AndroidApp,代码行数:5,代码来源:GooglePlayServices.java


示例19: testStartSessionSetsSession

import com.google.android.gms.fitness.data.Session; //导入依赖的package包/类
@SmallTest
public void testStartSessionSetsSession() throws Exception {
    _sessionManager.startSession(1000, _mockGoogleApiClient);

    verify(_mockSessionsApi,timeout(2000).times(1)).startSession(any(GoogleApiClient.class),any(Session.class));
}
 
开发者ID:team-mount-ventoux,项目名称:JayPS-AndroidApp,代码行数:7,代码来源:GoogleFitSessionManagerTest.java


示例20: newSessionBuilder

import com.google.android.gms.fitness.data.Session; //导入依赖的package包/类
public Session.Builder newSessionBuilder(); 
开发者ID:team-mount-ventoux,项目名称:JayPS-AndroidApp,代码行数:2,代码来源:IGooglePlayServices.java



注:本文中的com.google.android.gms.fitness.data.Session类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java RoleConstants类代码示例发布时间:2022-05-22
下一篇:
Java PrincipalBearingPrincipalResolver类代码示例发布时间:2022-05-22
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap