1 /*
2  * Copyright (C) 2016 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 package com.android.cts.verifier.sensors.sixdof.Utils.PoseProvider;
17 
18 import android.content.Context;
19 
20 /**
21  * Base class for objects that provide pose data to the app.
22  */
23 public abstract class PoseProvider {
24     protected Context mContext;
25     protected PoseProviderListener mPoseProviderListener;
26 
27     protected PoseData mLatestPoseData;
28     protected Intrinsics mIntrinsics;
29 
30     public static final Object POSE_LOCK = new Object();
31 
32     public interface PoseProviderListener {
onSetupComplete()33         void onSetupComplete();
34 
onNewPoseData(PoseData newPoseData)35         void onNewPoseData(PoseData newPoseData);
36     }
37 
PoseProvider(Context context, PoseProviderListener listener)38     public PoseProvider(Context context, PoseProviderListener listener) {
39         mContext = context;
40         mPoseProviderListener = listener;
41     }
42 
onStartPoseProviding()43     public abstract void onStartPoseProviding();
44 
onStopPoseProviding()45     public abstract void onStopPoseProviding();
46 
setup()47     public abstract void setup();
48 
onNewPoseData(PoseData newPoseData)49     protected void onNewPoseData(PoseData newPoseData){
50         if (mPoseProviderListener != null) {
51             mPoseProviderListener.onNewPoseData(newPoseData);
52         }
53     }
54 
getLatestPoseData()55     public PoseData getLatestPoseData() {
56         synchronized (POSE_LOCK) {
57             return mLatestPoseData;
58         }
59     }
60 
getIntrinsics()61     public Intrinsics getIntrinsics() {
62         return mIntrinsics;
63     }
64 }
65