|
...
|
...
|
@@ -96,6 +96,184 @@ export class HealthAuthorization { |
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* The user's current Huawei Health activity-ring goals.
|
|
|
|
*
|
|
|
|
* Units: move is kcal, exercise is seconds, and stand is hours.
|
|
|
|
*
|
|
|
|
* Generated class from Pigeon that represents data sent in messages.
|
|
|
|
*/
|
|
|
|
export class HealthActivityGoal {
|
|
|
|
private move?: number;
|
|
|
|
|
|
|
|
public setMove(move: number | undefined): void {
|
|
|
|
this.move = move;
|
|
|
|
}
|
|
|
|
|
|
|
|
getMove(): number | undefined {
|
|
|
|
return this.move;
|
|
|
|
}
|
|
|
|
|
|
|
|
private step?: number;
|
|
|
|
|
|
|
|
public setStep(step: number | undefined): void {
|
|
|
|
this.step = step;
|
|
|
|
}
|
|
|
|
|
|
|
|
getStep(): number | undefined {
|
|
|
|
return this.step;
|
|
|
|
}
|
|
|
|
|
|
|
|
private stand?: number;
|
|
|
|
|
|
|
|
public setStand(stand: number | undefined): void {
|
|
|
|
this.stand = stand;
|
|
|
|
}
|
|
|
|
|
|
|
|
getStand(): number | undefined {
|
|
|
|
return this.stand;
|
|
|
|
}
|
|
|
|
|
|
|
|
private exercise?: number;
|
|
|
|
|
|
|
|
public setExercise(exercise: number | undefined): void {
|
|
|
|
this.exercise = exercise;
|
|
|
|
}
|
|
|
|
|
|
|
|
getExercise(): number | undefined {
|
|
|
|
return this.exercise;
|
|
|
|
}
|
|
|
|
|
|
|
|
constructor(move?: number, step?: number, stand?: number, exercise?: number) {
|
|
|
|
this.move = move;
|
|
|
|
this.step = step;
|
|
|
|
this.stand = stand;
|
|
|
|
this.exercise = exercise;
|
|
|
|
}
|
|
|
|
|
|
|
|
toList(): Array<Object | null> {
|
|
|
|
let arr: Array<Object | null> = new Array<Object | null>();
|
|
|
|
if (this.move === undefined || this.move === null) {
|
|
|
|
arr.push(null);
|
|
|
|
} else {
|
|
|
|
arr.push(this.move);
|
|
|
|
}
|
|
|
|
if (this.step === undefined || this.step === null) {
|
|
|
|
arr.push(null);
|
|
|
|
} else {
|
|
|
|
arr.push(this.step);
|
|
|
|
}
|
|
|
|
if (this.stand === undefined || this.stand === null) {
|
|
|
|
arr.push(null);
|
|
|
|
} else {
|
|
|
|
arr.push(this.stand);
|
|
|
|
}
|
|
|
|
if (this.exercise === undefined || this.exercise === null) {
|
|
|
|
arr.push(null);
|
|
|
|
} else {
|
|
|
|
arr.push(this.exercise);
|
|
|
|
}
|
|
|
|
return arr;
|
|
|
|
}
|
|
|
|
|
|
|
|
static fromList(arr: Object[]): HealthActivityGoal {
|
|
|
|
let move: number | undefined = undefined;
|
|
|
|
if (arr[0] !== null && arr[0] !== undefined) {
|
|
|
|
let moveObject: Object = arr[0];
|
|
|
|
move = moveObject as number | undefined;
|
|
|
|
}
|
|
|
|
let step: number | undefined = undefined;
|
|
|
|
if (arr[1] !== null && arr[1] !== undefined) {
|
|
|
|
let stepObject: Object = arr[1];
|
|
|
|
step = stepObject as number | undefined;
|
|
|
|
}
|
|
|
|
let stand: number | undefined = undefined;
|
|
|
|
if (arr[2] !== null && arr[2] !== undefined) {
|
|
|
|
let standObject: Object = arr[2];
|
|
|
|
stand = standObject as number | undefined;
|
|
|
|
}
|
|
|
|
let exercise: number | undefined = undefined;
|
|
|
|
if (arr[3] !== null && arr[3] !== undefined) {
|
|
|
|
let exerciseObject: Object = arr[3];
|
|
|
|
exercise = exerciseObject as number | undefined;
|
|
|
|
}
|
|
|
|
return new HealthActivityGoal(move, step, stand, exercise);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* One workout record read from Health Service Kit.
|
|
|
|
*
|
|
|
|
* Generated class from Pigeon that represents data sent in messages.
|
|
|
|
*/
|
|
|
|
export class HealthWorkoutDataPoint {
|
|
|
|
private startTime: number;
|
|
|
|
|
|
|
|
public setStartTime(startTime: number): void {
|
|
|
|
this.startTime = startTime;
|
|
|
|
}
|
|
|
|
|
|
|
|
getStartTime(): number {
|
|
|
|
return this.startTime;
|
|
|
|
}
|
|
|
|
|
|
|
|
private endTime: number;
|
|
|
|
|
|
|
|
public setEndTime(endTime: number): void {
|
|
|
|
this.endTime = endTime;
|
|
|
|
}
|
|
|
|
|
|
|
|
getEndTime(): number {
|
|
|
|
return this.endTime;
|
|
|
|
}
|
|
|
|
|
|
|
|
private activityType: number;
|
|
|
|
|
|
|
|
public setActivityType(activityType: number): void {
|
|
|
|
this.activityType = activityType;
|
|
|
|
}
|
|
|
|
|
|
|
|
getActivityType(): number {
|
|
|
|
return this.activityType;
|
|
|
|
}
|
|
|
|
|
|
|
|
constructor(startTime: number, endTime: number, activityType: number) {
|
|
|
|
this.startTime = startTime;
|
|
|
|
this.endTime = endTime;
|
|
|
|
this.activityType = activityType;
|
|
|
|
}
|
|
|
|
|
|
|
|
toList(): Array<Object | null> {
|
|
|
|
let arr: Array<Object | null> = new Array<Object | null>();
|
|
|
|
if (this.startTime === undefined || this.startTime === null) {
|
|
|
|
arr.push(null);
|
|
|
|
} else {
|
|
|
|
arr.push(this.startTime);
|
|
|
|
}
|
|
|
|
if (this.endTime === undefined || this.endTime === null) {
|
|
|
|
arr.push(null);
|
|
|
|
} else {
|
|
|
|
arr.push(this.endTime);
|
|
|
|
}
|
|
|
|
if (this.activityType === undefined || this.activityType === null) {
|
|
|
|
arr.push(null);
|
|
|
|
} else {
|
|
|
|
arr.push(this.activityType);
|
|
|
|
}
|
|
|
|
return arr;
|
|
|
|
}
|
|
|
|
|
|
|
|
static fromList(arr: Object[]): HealthWorkoutDataPoint {
|
|
|
|
let startTimeObject: Object = arr[0];
|
|
|
|
const startTime: number = startTimeObject as number;
|
|
|
|
let endTimeObject: Object = arr[1];
|
|
|
|
const endTime: number = endTimeObject as number;
|
|
|
|
let activityTypeObject: Object = arr[2];
|
|
|
|
const activityType: number = activityTypeObject as number;
|
|
|
|
return new HealthWorkoutDataPoint(startTime, endTime, activityType);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export class PigeonCodec extends StandardMessageCodec {
|
|
|
|
static readonly INSTANCE: PigeonCodec = new PigeonCodec();
|
|
|
|
|
|
...
|
...
|
@@ -112,6 +290,10 @@ export class PigeonCodec extends StandardMessageCodec { |
|
|
|
switch (type) {
|
|
|
|
case this.getByte(129):
|
|
|
|
return HealthAuthorization.fromList(super.readValue(buffer) as Object[]);
|
|
|
|
case this.getByte(130):
|
|
|
|
return HealthActivityGoal.fromList(super.readValue(buffer) as Object[]);
|
|
|
|
case this.getByte(131):
|
|
|
|
return HealthWorkoutDataPoint.fromList(super.readValue(buffer) as Object[]);
|
|
|
|
default:
|
|
|
|
return super.readValueOfType(type, buffer);
|
|
|
|
}
|
|
...
|
...
|
@@ -121,6 +303,12 @@ export class PigeonCodec extends StandardMessageCodec { |
|
|
|
if (value instanceof HealthAuthorization) {
|
|
|
|
stream.writeUint8(this.getByte(129));
|
|
|
|
this.writeValue(stream, (value as HealthAuthorization).toList());
|
|
|
|
} else if (value instanceof HealthActivityGoal) {
|
|
|
|
stream.writeUint8(this.getByte(130));
|
|
|
|
this.writeValue(stream, (value as HealthActivityGoal).toList());
|
|
|
|
} else if (value instanceof HealthWorkoutDataPoint) {
|
|
|
|
stream.writeUint8(this.getByte(131));
|
|
|
|
this.writeValue(stream, (value as HealthWorkoutDataPoint).toList());
|
|
|
|
} else {
|
|
|
|
super.writeValue(stream, value);
|
|
|
|
}
|
|
...
|
...
|
@@ -146,6 +334,10 @@ export abstract class HealthKitHostApi { |
|
|
|
* does not wait for, or return, the subsequently available cloud data.
|
|
|
|
*/
|
|
|
|
abstract syncHealthDataToCloud(result: Result<boolean>): void;
|
|
|
|
/* Reads the current activity-ring goals from Huawei Health on OHOS.*/
|
|
|
|
abstract readActivityGoal(result: Result<HealthActivityGoal | undefined>): void;
|
|
|
|
/* Reads workout records in the supplied Unix-seconds time range on OHOS.*/
|
|
|
|
abstract readWorkoutData(startTime: number, endTime: number, result: Result<Array<HealthWorkoutDataPoint>>): void;
|
|
|
|
/** The codec used by HealthKitHostApi. */
|
|
|
|
static getCodec(): MessageCodec<Object> {
|
|
|
|
return PigeonCodec.INSTANCE;
|
|
...
|
...
|
@@ -234,5 +426,68 @@ export abstract class HealthKitHostApi { |
|
|
|
channel.setMessageHandler(null);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
{
|
|
|
|
let channel: BasicMessageChannel<Object> =
|
|
|
|
new BasicMessageChannel(
|
|
|
|
binaryMessenger, 'dev.flutter.pigeon.doublefeel_flutter.HealthKitHostApi.readActivityGoal' + separatedMessageChannelSuffix, HealthKitHostApi.getCodec());
|
|
|
|
if (api != null) {
|
|
|
|
channel.setMessageHandler({
|
|
|
|
onMessage(message: Object, reply: Reply<Object>) {
|
|
|
|
class ResultImp implements Result<HealthActivityGoal | undefined>{
|
|
|
|
success(result: HealthActivityGoal | undefined): void {
|
|
|
|
let res: Array<Object | null> = [];
|
|
|
|
res.push(result);
|
|
|
|
reply.reply(res);
|
|
|
|
}
|
|
|
|
|
|
|
|
error(error: Error): void {
|
|
|
|
let wrappedError: Array<Object | null> = wrapError(error);
|
|
|
|
reply.reply(wrappedError);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
let resultCallback: Result<HealthActivityGoal | undefined> = new ResultImp();
|
|
|
|
|
|
|
|
api!.readActivityGoal(resultCallback);
|
|
|
|
} });
|
|
|
|
} else {
|
|
|
|
channel.setMessageHandler(null);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
{
|
|
|
|
let channel: BasicMessageChannel<Object> =
|
|
|
|
new BasicMessageChannel(
|
|
|
|
binaryMessenger, 'dev.flutter.pigeon.doublefeel_flutter.HealthKitHostApi.readWorkoutData' + separatedMessageChannelSuffix, HealthKitHostApi.getCodec());
|
|
|
|
if (api != null) {
|
|
|
|
channel.setMessageHandler({
|
|
|
|
onMessage(message: Object, reply: Reply<Object>) {
|
|
|
|
if (!(Array.isArray(message))) {
|
|
|
|
reply.reply(wrapError(new Error('Invalid Pigeon message: expected List.')));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
let args: Array<Object> = message as Array<Object>;
|
|
|
|
if (args.length < 2) {
|
|
|
|
reply.reply(wrapError(new Error('Invalid Pigeon message: expected at least 2 argument(s).')));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
class ResultImp implements Result<Array<HealthWorkoutDataPoint>>{
|
|
|
|
success(result: Array<HealthWorkoutDataPoint>): void {
|
|
|
|
let res: Array<Object | null> = [];
|
|
|
|
res.push(result);
|
|
|
|
reply.reply(res);
|
|
|
|
}
|
|
|
|
|
|
|
|
error(error: Error): void {
|
|
|
|
let wrappedError: Array<Object | null> = wrapError(error);
|
|
|
|
reply.reply(wrappedError);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
let resultCallback: Result<Array<HealthWorkoutDataPoint>> = new ResultImp();
|
|
|
|
|
|
|
|
api!.readWorkoutData(args[0] as number, args[1] as number, resultCallback);
|
|
|
|
} });
|
|
|
|
} else {
|
|
|
|
channel.setMessageHandler(null);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} |
...
|
...
|
|