Compare commits
43 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| b14e5cfcb0 | |||
| fee76c2d93 | |||
| a07041901b | |||
| c370011616 | |||
| b8f155974c | |||
| 2fb22a6256 | |||
| bd60d945bb | |||
| 8f58410af9 | |||
| fc67cc944c | |||
| c8473017ec | |||
| 1b9daf60ee | |||
| 2bc0033aa8 | |||
| e71d71cf9c | |||
| 64a068596b | |||
| c10693930d | |||
| c0f309edf3 | |||
| b1cc631748 | |||
| a89059f5dc | |||
| 2cc8f9e7d5 | |||
| 29950b62e4 | |||
| 65de4b333c | |||
| 63fcf4918f | |||
| c9880b0139 | |||
| 13eabb7720 | |||
| 743b773ea3 | |||
| 249eee5dfb | |||
| 90c68d0d19 | |||
| d10a427911 | |||
| 05755a3213 | |||
| e18a633de1 | |||
| 0e68cdf744 | |||
| 7f119a8d0d | |||
| fde1e7e957 | |||
| 0ad96d505c | |||
| d4ff76fc25 | |||
| 85c1395361 | |||
| 1443e57c57 | |||
| 3b75f6213c | |||
| e9d5de64a5 | |||
| 19c61383f6 | |||
| cb6cc97fa4 | |||
| 0651bf0c2a | |||
| ae9b9e57cb |
@@ -1,5 +0,0 @@
|
||||
language: objective-c
|
||||
osx_image: xcode11
|
||||
xcode_project: ResearchKit.xcodeproj
|
||||
xcode_scheme: ResearchKit
|
||||
xcode_destination: platform=iOS Simulator,OS=13.0,name=iPhone 11 Pro Max
|
||||
@@ -6,7 +6,7 @@ codebase. However, other types of contributions are welcome too, in
|
||||
keeping with the ResearchKit™ framework [best practices](../../wiki/best-practices). For example,
|
||||
contributions of original free-to-use survey content, back-end integrations,
|
||||
validation data, and analysis or processing tools are all welcome. Ask
|
||||
on the [*ResearchKit* Forum](https://forums.developer.apple.com/community/researchkit) or [contact us](https://developer.apple.com/contact/researchkit/) for guidance.
|
||||
on the [*ResearchKit* Forum](https://developer.apple.com/forums/tags/researchkit) or [contact us](mailto:researchkit@apple.com) for guidance.
|
||||
|
||||
|
||||
Contributing software
|
||||
@@ -16,8 +16,7 @@ This page assumes you already know how to check out and build the
|
||||
code. Contributions to the ResearchKit framework are expected to comply with the
|
||||
[ResearchKit Contribution Terms and License Policy](#contribution); please familiarize yourself
|
||||
with this policy prior to submitting a pull request. For any contribution, ensure that you own
|
||||
the rights or have permission from the copyright holder. (e.g. code, images, surveys, videos
|
||||
and other content you may include)
|
||||
the rights or have permission from the copyright holder (e.g. code, images, surveys, videos and other content you may include).
|
||||
|
||||
To contribute to ResearchKit:
|
||||
|
||||
@@ -27,7 +26,7 @@ To contribute to ResearchKit:
|
||||
4. [Run the tests.](#test)
|
||||
5. [Submit a pull request.](#request)
|
||||
6. Make any changes requested by the reviewer, and update your pull request as needed.
|
||||
7. Once accepted, your pull request will be merged into master.
|
||||
7. Once accepted, your pull request will be merged into main.
|
||||
|
||||
Choosing an issue to work on<a name="create"></a>
|
||||
----------------------------
|
||||
@@ -36,13 +35,12 @@ To find an issue to work on, either pick something that you need for
|
||||
your app, or select one of the issues from our [issue list](../../issues). Or,
|
||||
consider one of the areas where we'd like to extend ResearchKit:
|
||||
|
||||
* Faster 'get started' to a useful app
|
||||
* More active tasks
|
||||
* Data analysis for active tasks
|
||||
* More consent sections
|
||||
* Back end integrations
|
||||
* Improving the APIs needed to get started with a ResearchKit project
|
||||
* New Active Tasks
|
||||
* Data analysis for Active Tasks
|
||||
* Backend integrations
|
||||
|
||||
If in doubt, bring your idea up on the [*ResearchKit* Forum](https://forums.developer.apple.com/community/researchkit).
|
||||
If in doubt, bring your idea up on the [ResearchKit Forum](https://developer.apple.com/forums/tags/researchkit).
|
||||
|
||||
|
||||
Creating a personal fork<a name="fork"></a>
|
||||
@@ -56,8 +54,7 @@ Develop your changes in your fork<a name="develop"></a>
|
||||
---------------------------------
|
||||
|
||||
Develop your changes using your normal development process. If you
|
||||
already have code from an existing project, you may need to adjust its
|
||||
style to more closely match the [ResearchKit framework coding style](./docs-standalone/coding-style-guide.md).
|
||||
already have code from an existing project, you may need to adjust its style to more closely match the [ResearchKit framework coding style](./docs-standalone/coding-style-guide.md).
|
||||
|
||||
New components may need to expose new Public or Private
|
||||
headers. Public headers are for APIs that are likely to be a stable
|
||||
@@ -78,7 +75,7 @@ code to other existing demo apps to exercise your feature.
|
||||
When adding UI driven components, make sure that they are accessible.
|
||||
Follow the steps outlined in the [Best Practices](../../wiki/best-practices)
|
||||
section under Accessibility. Before submitting the pull request, you should
|
||||
audit your components with Voice Over (or other relevant assistive technologies)
|
||||
audit your components with VoiceOver (or other relevant assistive technologies)
|
||||
enabled.
|
||||
|
||||
Keep changes that fix different issues separate. For bug fixes,
|
||||
@@ -99,11 +96,11 @@ verify that test apps run on both device and simulator.
|
||||
|
||||
Where your code affects UI presentation, also test:
|
||||
|
||||
* Multiple device form factors (for instance, iPhone 4S, iPhone 5, iPhone 6, iPhone 6 Plus).
|
||||
* Multiple device form factors (for instance, iPhone SE, iPhone 14, iPhone 15 Pro, iPhone 15 Pro Max).
|
||||
* Dynamic text, especially at the "Large" setting.
|
||||
* Rotation between portrait and landscape, where appropriate.
|
||||
|
||||
You can use the apps in the `Testing` and `samples` directories to
|
||||
You can use the `ORKCatalog` app in the `samples` directory to
|
||||
test your changes.
|
||||
|
||||
Submit a pull request<a name="request"></a>
|
||||
@@ -120,7 +117,7 @@ After acceptance<a name="after"></a>
|
||||
----------------
|
||||
|
||||
Once your pull request has been accepted, your changes will be merged
|
||||
to master. You are still responsible for your change after it is
|
||||
to main. You are still responsible for your change after it is
|
||||
accepted. Stay in contact, in case bugs are detected that may require
|
||||
your attention.
|
||||
|
||||
@@ -134,7 +131,7 @@ documentation, or other issues during this process.
|
||||
Release process
|
||||
-----------------
|
||||
|
||||
The `master` branch is used for work in progress. On `master`:
|
||||
The `main` branch is used for work in progress. On `main`:
|
||||
|
||||
* All test apps should build and run error free.
|
||||
* Unit tests should all pass.
|
||||
@@ -142,9 +139,9 @@ The `master` branch is used for work in progress. On `master`:
|
||||
base language).
|
||||
|
||||
The project will make periodic releases. When preparing a stable release, we
|
||||
will branch from `master` to a convergence branch. During this process,
|
||||
will branch from `main` to a convergence branch. During this process,
|
||||
changes will be made first to the convergence branch, and then merged into
|
||||
`master`. On the convergence branch, changes will be made only to:
|
||||
`main`. On the convergence branch, changes will be made only to:
|
||||
|
||||
* Fix high priority issues.
|
||||
* Update documentation.
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
Copyright (c) 2015, Apple Inc. All rights reserved.
|
||||
Copyright (c) 2015-2024, Apple Inc. All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification,
|
||||
are permitted provided that the following conditions are met:
|
||||
|
||||
@@ -6,279 +6,170 @@ ResearchKit Framework
|
||||
The *ResearchKit™ framework* is an open source software framework that makes it easy to create apps
|
||||
for medical research or for other research projects.
|
||||
|
||||
# Table of Contents
|
||||
|
||||
* [Requirements](#requirements)
|
||||
* [Documentation](#documentation)
|
||||
* [Getting Started](#gettingstarted)
|
||||
* [Documentation](docs/)
|
||||
* [Best Practices](../../wiki/best-practices)
|
||||
* [Contributing to ResearchKit](CONTRIBUTING.md)
|
||||
* [Installing](#installation)
|
||||
* [ORKCatalog App](#orkcatalog-app)
|
||||
* [Surveys](#surveys)
|
||||
* [Consent](#consent)
|
||||
* [Active Tasks](#active-tasks)
|
||||
* [Getting Help](#getting-help)
|
||||
* [License](#license)
|
||||
|
||||
# Requirements <a name="requirements"></a>
|
||||
|
||||
The *ResearchKit framework* codebase supports iOS and requires Xcode 12.0 or newer. The *ResearchKit framework* has a Base SDK version of 13.0.
|
||||
|
||||
# Documentation <a name="documentation"></a>
|
||||
|
||||
<img width="1000" alt="ebedded-framework" src="https://github.com/ResearchKit/ResearchKit/assets/29615893/19d6edd3-3d95-4416-9ac4-24ccb35e09c2">
|
||||
|
||||
View the *ResearchKit framework* documentation by setting ResearchKit as your target in Xcode and selecting 'Build Documentation' in the Product menu dropdown.
|
||||
|
||||
|
||||
# Getting Started <a name="gettingstarted"></a>
|
||||
|
||||
* [Website](https://www.researchandcare.org)
|
||||
* [ResearchKit BSD License](#license)
|
||||
* [WWDC: ResearchKit and CareKit Reimagined](https://developer.apple.com/videos/play/wwdc2019/217/)
|
||||
|
||||
Getting More Information
|
||||
========================
|
||||
|
||||
* Join the [*ResearchKit* Forum](https://forums.developer.apple.com/community/researchkit) for discussing uses of the *ResearchKit framework and* related projects.
|
||||
### Install as an embedded framework <a name="installation"></a>
|
||||
|
||||
Use Cases
|
||||
===========
|
||||
Download the project source code and drag in ResearchKit.xcodeproj. Then, embed *ResearchKit* framework in your app by adding it to the "Frameworks, Libraries, and Embedded Content" section for your target as shown in the figure below.
|
||||
|
||||
A task in the *ResearchKit framework* contains a set of steps to present to a user. Everything,
|
||||
whether it’s a *survey*, the *consent process*, or *active tasks*, is represented as a task that can
|
||||
be presented with a task view controller.
|
||||
<img width="1000" alt="ebedded-framework" src="https://github.com/ResearchKit/ResearchKit/assets/29615893/7479f313-ecc7-4d94-8c64-c58ae7362a4d">
|
||||
|
||||
Surveys
|
||||
-------
|
||||
### ORKCatalog App <a name="orkcatalog-app"></a>
|
||||
|
||||
The included catalog app demonstrates the different modules that are available in *ResearchKit*. Find the
|
||||
project in ResearchKit's [`samples`](samples) directory.
|
||||
|
||||
| | |
|
||||
|---|---|
|
||||
|  |  |
|
||||
|
||||
# Surveys <a name="surveys"></a>
|
||||
|
||||
The *ResearchKit framework* provides a pre-built user interface for surveys, which can be presented
|
||||
modally on an *iPhone*, *iPod Touch*, or *iPad*. See
|
||||
*[Creating Surveys](docs/Survey/)* for more
|
||||
information.
|
||||
modally on an *iPhone* or *iPad*. The example below shows the process to present a height question for a participant to answer.
|
||||
|
||||
```swift
|
||||
import ResearchKit
|
||||
import ResearchKitUI
|
||||
|
||||
let sectionHeaderFormItem = ORKFormItem(sectionTitle: "Your question here.")
|
||||
|
||||
Consent
|
||||
----------------
|
||||
let heightQuestionFormItem = ORKFormItem(identifier: "heightQuestionFormItem1", text: nil, answerFormat: ORKAnswerFormat.heightAnswerFormat())
|
||||
heightQuestionFormItem.placeholder = "Tap here"
|
||||
|
||||
The *ResearchKit framework* provides visual consent templates that you can customize to explain the
|
||||
details of your research study and obtain a signature if needed.
|
||||
See *[Obtaining Consent](docs/InformedConsent/)* for
|
||||
more information.
|
||||
let formStep = ORKFormStep(identifier: "HeightQuestionIdentifier", title: "Height", text: "Local system")
|
||||
formStep.formItems = [sectionHeaderFormItem, heightQuestionFormItem]
|
||||
|
||||
return formStep
|
||||
```
|
||||
|
||||
Active Tasks
|
||||
------------
|
||||
The height question is presented in the figure below.
|
||||
|
||||
| | |
|
||||
|---|---|
|
||||
|  |  |
|
||||
|
||||
# Consent <a name="consent"></a>
|
||||
|
||||
The *ResearchKit framework* provides classes that you can customize to explain the
|
||||
details of your research study and obtain a signature if needed. Use *ResearchKit's* provided classes to quickly welcome, and inform your participants of what the study entails.
|
||||
|
||||
```swift
|
||||
import ResearchKit
|
||||
import ResearchKitUI
|
||||
|
||||
// Welcome page.
|
||||
let welcomeStep = ORKInstructionStep(identifier: String(describing: Identifier.consentWelcomeInstructionStep))
|
||||
welcomeStep.iconImage = UIImage(systemName: "hand.wave")
|
||||
welcomeStep.title = "Welcome!"
|
||||
welcomeStep.detailText = "Thank you for joining our study. Tap Next to learn more before signing up."
|
||||
|
||||
// Before You Join page.
|
||||
let beforeYouJoinStep = ORKInstructionStep(identifier: String(describing: Identifier.informedConsentInstructionStep))
|
||||
beforeYouJoinStep.iconImage = UIImage(systemName: "doc.text.magnifyingglass")
|
||||
beforeYouJoinStep.title = "Before You Join"
|
||||
|
||||
let sharingHealthDataBodyItem = ORKBodyItem(text: "The study will ask you to share some of your Health data.",
|
||||
detailText: nil,
|
||||
image: UIImage(systemName: "heart.fill"),
|
||||
learnMoreItem: nil,
|
||||
bodyItemStyle: .image)
|
||||
|
||||
let completingTasksBodyItem = ORKBodyItem(text: "You will be asked to complete various tasks over the duration of the study.",
|
||||
detailText: nil,
|
||||
image: UIImage(systemName: "checkmark.circle.fill"),
|
||||
learnMoreItem: nil,
|
||||
bodyItemStyle: .image)
|
||||
|
||||
let signatureBodyItem = ORKBodyItem(text: "Before joining, we will ask you to sign an informed consent document.",
|
||||
detailText: nil,
|
||||
image: UIImage(systemName: "signature"),
|
||||
learnMoreItem: nil,
|
||||
bodyItemStyle: .image)
|
||||
|
||||
let secureDataBodyItem = ORKBodyItem(text: "Your data is kept private and secure.",
|
||||
detailText: nil,
|
||||
image: UIImage(systemName: "lock.fill"),
|
||||
learnMoreItem: nil,
|
||||
bodyItemStyle: .image)
|
||||
|
||||
beforeYouJoinStep.bodyItems = [
|
||||
sharingHealthDataBodyItem,
|
||||
completingTasksBodyItem,
|
||||
signatureBodyItem,
|
||||
secureDataBodyItem
|
||||
]
|
||||
```
|
||||
The consent steps are presented in the figure below.
|
||||
|
||||
| | |
|
||||
|---|---|
|
||||
|  |  |
|
||||
|
||||
Vist the `Obtaining Consent`article in ResearchKit's Documentation for
|
||||
more examples that include signature collection and PDF file storage.
|
||||
|
||||
# Active Tasks <a name="active-tasks"></a>
|
||||
|
||||
Some studies may need data beyond survey questions or the passive data collection capabilities
|
||||
available through use of the *HealthKit* and *CoreMotion* APIs if you are programming for *iOS*.
|
||||
*ResearchKit*'s active tasks invite users to perform activities under semi-controlled conditions,
|
||||
while *iPhone* sensors actively collect data. See
|
||||
*[Active Tasks](docs/ActiveTasks/)* for more
|
||||
information.
|
||||
while *iPhone* sensors actively collect data.
|
||||
ResearchKit active tasks are not diagnostic tools nor medical devices of any kind and output from those active tasks may not be used for diagnosis. Developers and researchers are responsible for complying with all applicable laws and regulations with respect to further development and use of the active tasks.
|
||||
|
||||
Charts
|
||||
------------
|
||||
*ResearchKit* includes a *Charts module*. It features three chart types: a *pie chart* (`ORKPieChartView`), a *line graph chart* (`ORKLineGraphChartView`), and a *discrete graph chart* (`ORKDiscreteGraphChartView`).
|
||||
|
||||
The views in the *Charts module* can be used independently of the rest of *ResearchKit*. They don't automatically connect with any other part of *ResearchKit*: the developer has to supply the data to be displayed through the views' `dataSources`, which allows for maximum flexibility.
|
||||
|
||||
|
||||
Getting Started<a name="gettingstarted"></a>
|
||||
===============
|
||||
|
||||
|
||||
Requirements
|
||||
------------
|
||||
|
||||
The primary *ResearchKit framework* codebase supports *iOS* and requires *Xcode 8.0* or newer. The
|
||||
*ResearchKit framework* has a *Base SDK* version of *8.0*, meaning that apps using the *ResearchKit
|
||||
framework* can run on devices with *iOS 8.0* or newer.
|
||||
|
||||
|
||||
Installation
|
||||
------------
|
||||
|
||||
The latest stable version of *ResearchKit framework* can be cloned with
|
||||
|
||||
```
|
||||
git clone -b stable https://github.com/ResearchKit/ResearchKit.git
|
||||
```
|
||||
|
||||
Or, for the latest changes, use the `master` branch:
|
||||
|
||||
```
|
||||
git clone https://github.com/ResearchKit/ResearchKit.git
|
||||
```
|
||||
|
||||
Building
|
||||
--------
|
||||
|
||||
Build the *ResearchKit framework* by opening `ResearchKit.xcodeproj` and running the `ResearchKit`
|
||||
framework target. Optionally, run the unit tests too.
|
||||
|
||||
|
||||
Adding the ResearchKit framework to your App
|
||||
------------------------------
|
||||
|
||||
This walk-through shows how to embed the *ResearchKit framework* in your app as a dynamic framework,
|
||||
and present a simple task view controller.
|
||||
|
||||
### 1. Add the ResearchKit framework to Your Project
|
||||
|
||||
To get started, drag `ResearchKit.xcodeproj` from your checkout into your *iOS* app project
|
||||
in *Xcode*:
|
||||
|
||||
<center>
|
||||
<figure>
|
||||
<img src="../../wiki/AddingResearchKitXcode.png" alt="Adding the ResearchKit framework to your
|
||||
project" align="middle"/>
|
||||
</figure>
|
||||
</center>
|
||||
|
||||
Then, embed the *ResearchKit framework* as a dynamic framework in your app, by adding it to the
|
||||
*Embedded Binaries* section of the *General* pane for your target as shown in the figure below.
|
||||
|
||||
<center>
|
||||
<figure>
|
||||
<img src="../../wiki/AddedBinaries.png" width="100%" alt="Adding the ResearchKit framework to
|
||||
Embedded Binaries" align="middle"/>
|
||||
<figcaption><center>Adding the ResearchKit framework to Embedded Binaries</center></figcaption>
|
||||
</figure>
|
||||
</center>
|
||||
|
||||
Note: You can also import *ResearchKit* into your project using a
|
||||
[dependency manager](./docs-standalone/dependency-management.md) such as *CocoaPods* or *Carthage*.
|
||||
|
||||
### 2. Create a Step
|
||||
|
||||
In this walk-through, we will use the *ResearchKit framework* to modally present a simple
|
||||
single-step task showing a single instruction.
|
||||
|
||||
Create a step for your task by adding some code, perhaps in `viewDidAppear:` of an existing view
|
||||
controller. To keep things simple, we'll use an instruction step (`ORKInstructionStep`) and name
|
||||
the step `myStep`.
|
||||
|
||||
*Objective-C*
|
||||
|
||||
```objc
|
||||
ORKInstructionStep *myStep =
|
||||
[[ORKInstructionStep alloc] initWithIdentifier:@"intro"];
|
||||
myStep.title = @"Welcome to ResearchKit";
|
||||
```
|
||||
|
||||
*Swift*
|
||||
Use predefined tasks provided by *ResearchKit* to guide your participants through specific actions.
|
||||
|
||||
```swift
|
||||
let myStep = ORKInstructionStep(identifier: "intro")
|
||||
myStep.title = "Welcome to ResearchKit"
|
||||
```
|
||||
import ResearchKit
|
||||
import ResearchKitUI
|
||||
import ResearchKitActiveTask
|
||||
|
||||
### 3. Create a Task
|
||||
|
||||
Use the ordered task class (`ORKOrderedTask`) to create a task that contains `myStep`. An ordered
|
||||
task is just a task where the order and selection of later steps does not depend on the results of
|
||||
earlier ones. Name your task `task` and initialize it with `myStep`.
|
||||
|
||||
*Objective-C*
|
||||
|
||||
```objc
|
||||
ORKOrderedTask *task =
|
||||
[[ORKOrderedTask alloc] initWithIdentifier:@"task" steps:@[myStep]];
|
||||
```
|
||||
|
||||
*Swift*
|
||||
|
||||
```swift
|
||||
let task = ORKOrderedTask(identifier: "task", steps: [myStep])
|
||||
```
|
||||
|
||||
### 4. Present the Task
|
||||
|
||||
Create a task view controller (`ORKTaskViewController`) and initialize it with your `task`. A task
|
||||
view controller manages a task and collects the results of each step. In this case, your task view
|
||||
controller simply displays your instruction step.
|
||||
|
||||
*Objective-C*
|
||||
|
||||
```objc
|
||||
ORKTaskViewController *taskViewController =
|
||||
[[ORKTaskViewController alloc] initWithTask:task taskRunUUID:nil];
|
||||
taskViewController.delegate = self;
|
||||
[self presentViewController:taskViewController animated:YES completion:nil];
|
||||
```
|
||||
|
||||
*Swift*
|
||||
|
||||
```swift
|
||||
let taskViewController = ORKTaskViewController(task: task, taskRun: nil)
|
||||
let orderedTask = ORKOrderedTask.dBHLToneAudiometryTask(withIdentifier: "dBHLToneAudiometryTaskIdentifier",
|
||||
intendedUseDescription: nil, options: [])
|
||||
|
||||
let taskViewController = ORKTaskViewController(task: orderedTask, taskRun: nil)
|
||||
taskViewController.delegate = self
|
||||
present(taskViewController, animated: true, completion: nil)
|
||||
|
||||
present(taskViewController, animated: true)
|
||||
```
|
||||
The dBHL Tone Audiometry task is presented in the figure below.
|
||||
|
||||
The above snippet assumes that your class implements the `ORKTaskViewControllerDelegate` protocol.
|
||||
This has just one required method, which you must implement in order to handle the completion of
|
||||
the task:
|
||||
| | |
|
||||
|---|---|
|
||||
|  |  |
|
||||
|
||||
*Objective-C*
|
||||
# Getting Help <a name="getting-help"></a>
|
||||
|
||||
```objc
|
||||
- (void)taskViewController:(ORKTaskViewController *)taskViewController
|
||||
didFinishWithReason:(ORKTaskViewControllerFinishReason)reason
|
||||
error:(NSError *)error {
|
||||
GitHub is our primary forum for ResearchKit. Feel free to open up issues about questions, problems, or ideas.
|
||||
|
||||
ORKTaskResult *taskResult = [taskViewController result];
|
||||
// You could do something with the result here.
|
||||
# License <a name="license"></a>
|
||||
|
||||
// Then, dismiss the task view controller.
|
||||
[self dismissViewControllerAnimated:YES completion:nil];
|
||||
}
|
||||
```
|
||||
|
||||
*Swift*
|
||||
|
||||
```swift
|
||||
func taskViewController(_ taskViewController: ORKTaskViewController,
|
||||
didFinishWith reason: ORKTaskViewControllerFinishReason,
|
||||
error: Error?) {
|
||||
let taskResult = taskViewController.result
|
||||
// You could do something with the result here.
|
||||
|
||||
// Then, dismiss the task view controller.
|
||||
dismiss(animated: true, completion: nil)
|
||||
}
|
||||
```
|
||||
|
||||
|
||||
If you now run your app, you should see your first *ResearchKit framework* instruction step:
|
||||
|
||||
<center>
|
||||
<figure>
|
||||
<img src="../../wiki/HelloWorld.png" width="50%" alt="HelloWorld example screenshot" align="middle"/>
|
||||
</figure>
|
||||
</center>
|
||||
|
||||
|
||||
|
||||
What else can the ResearchKit framework do?
|
||||
-----------------------------
|
||||
|
||||
The *ResearchKit* [`ORKCatalog`](samples/ORKCatalog) sample app is a good place to start. Find the
|
||||
project in ResearchKit's [`samples`](samples) directory. This project includes a list of all the
|
||||
types of steps supported by the *ResearchKit framework* in the first tab, and displays a browser for the
|
||||
results of the last completed task in the second tab. The third tab shows some examples from the *Charts module*.
|
||||
|
||||
|
||||
|
||||
License<a name="license"></a>
|
||||
=======
|
||||
|
||||
The source in the *ResearchKit* repository is made available under the following license unless
|
||||
another license is explicitly identified:
|
||||
|
||||
```
|
||||
Copyright (c) 2015 - 2018, Apple Inc. All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification,
|
||||
are permitted provided that the following conditions are met:
|
||||
|
||||
1. Redistributions of source code must retain the above copyright notice, this
|
||||
list of conditions and the following disclaimer.
|
||||
|
||||
2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
this list of conditions and the following disclaimer in the documentation and/or
|
||||
other materials provided with the distribution.
|
||||
|
||||
3. Neither the name of the copyright holder(s) nor the names of any contributors
|
||||
may be used to endorse or promote products derived from this software without
|
||||
specific prior written permission. No license is granted to the trademarks of
|
||||
the copyright holders even if such marks are included in this software.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
|
||||
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
```
|
||||
This project is made available under the terms of a BSD license. See the [LICENSE](LICENSE) file.
|
||||
|
||||
@@ -1,5 +1,33 @@
|
||||
# ResearchKit Release Notes
|
||||
|
||||
## ResearchKit 3.0 Release Notes
|
||||
|
||||
*ResearchKit 3.0* is a beta release
|
||||
|
||||
In addition to general stability and performance improvements, ResearchKit 3.0 includes the following updates.
|
||||
|
||||
### Framework Updates
|
||||
|
||||
In order to modularize ResearchKit we have separated its functionality into the following modules.
|
||||
|
||||
- **ResearchKit**
|
||||
contains the core classes and objects needed to run ResearchKit in any environment.
|
||||
|
||||
- **ResearchKitUI**
|
||||
contains the UI classes and objects needed to present ResearchKit views in an IOS environment.
|
||||
|
||||
- **ResearchKitActiveTask**
|
||||
contains the classes and objects needed to present Active Tasks in an IOS enviroment. These tasks usually require access to device sensors.
|
||||
|
||||
### Future Deprecations
|
||||
The following APIs will be labeled deprecated spring of 2025.
|
||||
|
||||
- **Consent**
|
||||
Our `ORKConsent` APIs will be deprecated in favor of using existing functionality (e.g `ORKInstructionStep` and `ORKWebViewStep`) to achieve informed consent. Please visit the `ORKCatalog` app to view a recommended example.
|
||||
|
||||
- **Question Step**
|
||||
The `ORKQuestionStep` will be deprecated in favor of using the `ORKFormStep`. Certain answer formats will present slightly different UI when used with a `ORKFormStep`. Updates will be made to ensure backwards compatibility before the question step is removed.
|
||||
|
||||
## ResearchKit 2.0 Release Notes
|
||||
|
||||
*ResearchKit 2.0* supports *iOS* and requires *Xcode 9.0* or newer.
|
||||
|
||||
@@ -1,19 +1,10 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<Workspace
|
||||
version = "1.0">
|
||||
<FileRef
|
||||
location = "group:samples/ORKParkinsonStudy/ORKParkinsonStudy.xcodeproj">
|
||||
</FileRef>
|
||||
<FileRef
|
||||
location = "group:ResearchKit.xcodeproj">
|
||||
</FileRef>
|
||||
<FileRef
|
||||
location = "group:Testing/ORKTest/ORKTest.xcodeproj">
|
||||
</FileRef>
|
||||
<FileRef
|
||||
location = "group:samples/ORKCatalog/ORKCatalog.xcodeproj">
|
||||
</FileRef>
|
||||
<FileRef
|
||||
location = "group:samples/ORKSample/ORKSample.xcodeproj">
|
||||
</FileRef>
|
||||
</Workspace>
|
||||
|
||||
@@ -1,18 +0,0 @@
|
||||
Pod::Spec.new do |s|
|
||||
s.name = 'ResearchKit'
|
||||
s.version = '2.1.0-beta'
|
||||
s.summary = 'ResearchKit is an open source software framework that makes it easy to create apps for medical research or for other research projects.'
|
||||
s.homepage = 'https://www.github.com/ResearchKit/ResearchKit'
|
||||
s.documentation_url = 'http://researchkit.github.io/docs/'
|
||||
s.license = { :type => 'BSD', :file => 'LICENSE' }
|
||||
s.author = { 'researchkit.org' => 'http://researchkit.org' }
|
||||
s.source = { :git => 'https://github.com/ResearchKit/ResearchKit.git', :tag => s.version.to_s }
|
||||
s.public_header_files = `./scripts/find_headers.rb --public`.split("\n")
|
||||
s.private_header_files = `./scripts/find_headers.rb --private`.split("\n")
|
||||
s.source_files = 'ResearchKit/**/*.{h,m,swift}'
|
||||
s.resources = 'ResearchKit/**/*.{fsh,vsh}', 'ResearchKit/Animations/**/*.m4v', 'ResearchKit/Artwork.xcassets', 'ResearchKit/Localized/*.lproj'
|
||||
s.platform = :ios, '11.0'
|
||||
s.requires_arc = true
|
||||
s.swift_version = '5'
|
||||
s.module_map = "ResearchKit/ResearchKit.modulemap"
|
||||
end
|
||||
@@ -1,10 +1,10 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<Scheme
|
||||
version = "1.3">
|
||||
LastUpgradeVersion = "1200"
|
||||
LastUpgradeVersion = "1500"
|
||||
version = "1.7">
|
||||
<BuildAction
|
||||
parallelizeBuildables = "YES"
|
||||
buildImplicitDependencies = "NO">
|
||||
buildImplicitDependencies = "YES">
|
||||
<BuildActionEntries>
|
||||
<BuildActionEntry
|
||||
buildForTesting = "YES"
|
||||
@@ -15,58 +15,32 @@
|
||||
<BuildableReference
|
||||
BuildableIdentifier = "primary"
|
||||
BlueprintIdentifier = "B183A4731A8535D100C76870"
|
||||
BuildableName = "ResearchKit.framework"
|
||||
BuildableName = ".framework"
|
||||
BlueprintName = "ResearchKit"
|
||||
ReferencedContainer = "container:ResearchKit.xcodeproj">
|
||||
</BuildableReference>
|
||||
</BuildActionEntry>
|
||||
<BuildActionEntry
|
||||
buildForTesting = "YES"
|
||||
buildForRunning = "NO"
|
||||
buildForProfiling = "NO"
|
||||
buildForArchiving = "NO"
|
||||
buildForAnalyzing = "NO">
|
||||
<BuildableReference
|
||||
BuildableIdentifier = "primary"
|
||||
BlueprintIdentifier = "86CC8E991AC09332001CCD89"
|
||||
BuildableName = "ResearchKitTests.xctest"
|
||||
BlueprintName = "ResearchKitTests"
|
||||
ReferencedContainer = "container:ResearchKit.xcodeproj">
|
||||
</BuildableReference>
|
||||
</BuildActionEntry>
|
||||
</BuildActionEntries>
|
||||
</BuildAction>
|
||||
<TestAction
|
||||
buildConfiguration = "Debug"
|
||||
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
|
||||
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
|
||||
shouldUseLaunchSchemeArgsEnv = "YES">
|
||||
<MacroExpansion>
|
||||
<BuildableReference
|
||||
BuildableIdentifier = "primary"
|
||||
BlueprintIdentifier = "B183A4731A8535D100C76870"
|
||||
BuildableName = "ResearchKit.framework"
|
||||
BlueprintName = "ResearchKit"
|
||||
ReferencedContainer = "container:ResearchKit.xcodeproj">
|
||||
</BuildableReference>
|
||||
</MacroExpansion>
|
||||
<Testables>
|
||||
<TestableReference
|
||||
skipped = "NO">
|
||||
<BuildableReference
|
||||
BuildableIdentifier = "primary"
|
||||
BlueprintIdentifier = "86CC8E991AC09332001CCD89"
|
||||
BuildableName = "ResearchKitTests.xctest"
|
||||
BlueprintName = "ResearchKitTests"
|
||||
ReferencedContainer = "container:ResearchKit.xcodeproj">
|
||||
</BuildableReference>
|
||||
</TestableReference>
|
||||
</Testables>
|
||||
shouldUseLaunchSchemeArgsEnv = "YES"
|
||||
codeCoverageEnabled = "YES">
|
||||
<TestPlans>
|
||||
<TestPlanReference
|
||||
reference = "container:ResearchKit.xctestplan"
|
||||
default = "YES">
|
||||
</TestPlanReference>
|
||||
</TestPlans>
|
||||
</TestAction>
|
||||
<LaunchAction
|
||||
buildConfiguration = "Debug"
|
||||
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
|
||||
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
|
||||
enableAddressSanitizer = "YES"
|
||||
enableUBSanitizer = "YES"
|
||||
launchStyle = "0"
|
||||
useCustomWorkingDirectory = "NO"
|
||||
ignoresPersistentStateOnLaunch = "NO"
|
||||
@@ -77,7 +51,7 @@
|
||||
<BuildableReference
|
||||
BuildableIdentifier = "primary"
|
||||
BlueprintIdentifier = "B183A4731A8535D100C76870"
|
||||
BuildableName = "ResearchKit.framework"
|
||||
BuildableName = ".framework"
|
||||
BlueprintName = "ResearchKit"
|
||||
ReferencedContainer = "container:ResearchKit.xcodeproj">
|
||||
</BuildableReference>
|
||||
@@ -93,7 +67,7 @@
|
||||
<BuildableReference
|
||||
BuildableIdentifier = "primary"
|
||||
BlueprintIdentifier = "B183A4731A8535D100C76870"
|
||||
BuildableName = "ResearchKit.framework"
|
||||
BuildableName = ".framework"
|
||||
BlueprintName = "ResearchKit"
|
||||
ReferencedContainer = "container:ResearchKit.xcodeproj">
|
||||
</BuildableReference>
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<Scheme
|
||||
LastUpgradeVersion = "1200"
|
||||
LastUpgradeVersion = "1500"
|
||||
version = "1.3">
|
||||
<BuildAction
|
||||
parallelizeBuildables = "YES"
|
||||
@@ -33,7 +33,7 @@
|
||||
<BuildableReference
|
||||
BuildableIdentifier = "primary"
|
||||
BlueprintIdentifier = "B183A4731A8535D100C76870"
|
||||
BuildableName = "ResearchKit.framework"
|
||||
BuildableName = ".framework"
|
||||
BlueprintName = "ResearchKit"
|
||||
ReferencedContainer = "container:ResearchKit.xcodeproj">
|
||||
</BuildableReference>
|
||||
@@ -50,6 +50,11 @@
|
||||
BlueprintName = "ResearchKitTests"
|
||||
ReferencedContainer = "container:ResearchKit.xcodeproj">
|
||||
</BuildableReference>
|
||||
<SkippedTests>
|
||||
<Test
|
||||
Identifier = "ORKDataCollectionTests">
|
||||
</Test>
|
||||
</SkippedTests>
|
||||
</TestableReference>
|
||||
</Testables>
|
||||
</TestAction>
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<Scheme
|
||||
LastUpgradeVersion = "1200"
|
||||
LastUpgradeVersion = "1340"
|
||||
version = "1.3">
|
||||
<BuildAction
|
||||
parallelizeBuildables = "YES"
|
||||
@@ -14,9 +14,9 @@
|
||||
buildForAnalyzing = "YES">
|
||||
<BuildableReference
|
||||
BuildableIdentifier = "primary"
|
||||
BlueprintIdentifier = "B18FF3A41A9FE25700C0C3B0"
|
||||
BuildableName = "docs"
|
||||
BlueprintName = "docs"
|
||||
BlueprintIdentifier = "CA1C7A40288B0C68004DAB3A"
|
||||
BuildableName = "ResearchKitUI.framework"
|
||||
BlueprintName = "ResearchKitUI (iOS)"
|
||||
ReferencedContainer = "container:ResearchKit.xcodeproj">
|
||||
</BuildableReference>
|
||||
</BuildActionEntry>
|
||||
@@ -40,15 +40,6 @@
|
||||
debugDocumentVersioning = "YES"
|
||||
debugServiceExtension = "internal"
|
||||
allowLocationSimulation = "YES">
|
||||
<MacroExpansion>
|
||||
<BuildableReference
|
||||
BuildableIdentifier = "primary"
|
||||
BlueprintIdentifier = "B18FF3A41A9FE25700C0C3B0"
|
||||
BuildableName = "docs"
|
||||
BlueprintName = "docs"
|
||||
ReferencedContainer = "container:ResearchKit.xcodeproj">
|
||||
</BuildableReference>
|
||||
</MacroExpansion>
|
||||
</LaunchAction>
|
||||
<ProfileAction
|
||||
buildConfiguration = "Release"
|
||||
@@ -59,9 +50,9 @@
|
||||
<MacroExpansion>
|
||||
<BuildableReference
|
||||
BuildableIdentifier = "primary"
|
||||
BlueprintIdentifier = "B18FF3A41A9FE25700C0C3B0"
|
||||
BuildableName = "docs"
|
||||
BlueprintName = "docs"
|
||||
BlueprintIdentifier = "CA1C7A40288B0C68004DAB3A"
|
||||
BuildableName = "ResearchKitUI.framework"
|
||||
BlueprintName = "ResearchKitUI (iOS)"
|
||||
ReferencedContainer = "container:ResearchKit.xcodeproj">
|
||||
</BuildableReference>
|
||||
</MacroExpansion>
|
||||
@@ -0,0 +1,27 @@
|
||||
{
|
||||
"configurations" : [
|
||||
{
|
||||
"id" : "A9C8689E-BBEE-4643-8C5D-DBA6A5AF01B2",
|
||||
"name" : "Configuration 1",
|
||||
"options" : {
|
||||
|
||||
}
|
||||
}
|
||||
],
|
||||
"defaultOptions" : {
|
||||
|
||||
},
|
||||
"testTargets" : [
|
||||
{
|
||||
"skippedTests" : [
|
||||
"ORKDataCollectionTests"
|
||||
],
|
||||
"target" : {
|
||||
"containerPath" : "container:ResearchKit.xcodeproj",
|
||||
"identifier" : "86CC8E991AC09332001CCD89",
|
||||
"name" : "ResearchKitTests"
|
||||
}
|
||||
}
|
||||
],
|
||||
"version" : 1
|
||||
}
|
||||
@@ -1,283 +0,0 @@
|
||||
/*
|
||||
Copyright (c) 2019, Novartis.
|
||||
Copyright (c) 2019, Apple Inc. All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification,
|
||||
are permitted provided that the following conditions are met:
|
||||
|
||||
1. Redistributions of source code must retain the above copyright notice, this
|
||||
list of conditions and the following disclaimer.
|
||||
|
||||
2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
this list of conditions and the following disclaimer in the documentation and/or
|
||||
other materials provided with the distribution.
|
||||
|
||||
3. Neither the name of the copyright holder(s) nor the names of any contributors
|
||||
may be used to endorse or promote products derived from this software without
|
||||
specific prior written permission. No license is granted to the trademarks of
|
||||
the copyright holders even if such marks are included in this software.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
|
||||
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
public enum CircleSliderOption {
|
||||
case startAngle(Double)
|
||||
case barColor(UIColor)
|
||||
case trackingColor(UIColor)
|
||||
case thumbColor(UIColor)
|
||||
case thumbImage(UIImage)
|
||||
case barWidth(CGFloat)
|
||||
case thumbWidth(CGFloat)
|
||||
case maxValue(Float)
|
||||
case minValue(Float)
|
||||
case sliderEnabled(Bool)
|
||||
case viewInset(CGFloat)
|
||||
case minMaxSwitchTreshold(Float)
|
||||
}
|
||||
|
||||
open class CircleSlider: UISlider {
|
||||
|
||||
private let minThumbTouchAreaWidth: CGFloat = 44
|
||||
private var latestDegree: Double = 0
|
||||
private var startValue: Float = 0
|
||||
open var sliderValue: Float {
|
||||
get {
|
||||
return startValue
|
||||
}
|
||||
set {
|
||||
var value = newValue
|
||||
let significantChange = (maxValue - minValue) * (1.0 - minMaxSwitchTreshold)
|
||||
let isSignificantChangeOccured = abs(newValue - startValue) > significantChange
|
||||
|
||||
if isSignificantChangeOccured {
|
||||
if startValue < newValue {
|
||||
value = minValue
|
||||
} else {
|
||||
value = maxValue
|
||||
}
|
||||
} else {
|
||||
value = newValue
|
||||
}
|
||||
|
||||
startValue = value
|
||||
sendActions(for: .valueChanged)
|
||||
var degree = Math.degreeFromValue(startAngle, value: sliderValue, maxValue: maxValue, minValue: minValue)
|
||||
|
||||
if startValue == maxValue {
|
||||
degree -= degree / (360 * 100)
|
||||
}
|
||||
|
||||
layout(degree)
|
||||
}
|
||||
}
|
||||
private var trackLayer: TrackLayer! {
|
||||
didSet {
|
||||
layer.addSublayer(trackLayer)
|
||||
}
|
||||
}
|
||||
private var thumbView: UIView! {
|
||||
didSet {
|
||||
if sliderEnabled {
|
||||
thumbView.backgroundColor = thumbColor
|
||||
thumbView.center = thumbCenter(startAngle)
|
||||
thumbView.layer.cornerRadius = thumbView!.bounds.size.width * 0.5
|
||||
addSubview(thumbView)
|
||||
if let thumbImage = thumbImage {
|
||||
let thumbImageView = UIImageView(frame: thumbView.bounds)
|
||||
thumbImageView.image = thumbImage
|
||||
thumbView.addSubview(thumbImageView)
|
||||
thumbView.backgroundColor = UIColor.clear
|
||||
}
|
||||
} else {
|
||||
thumbView.isHidden = true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private var startAngle: Double = -90
|
||||
private var barColor = UIColor.lightGray
|
||||
private var trackingColor = UIColor.blue
|
||||
private var thumbColor = UIColor.black
|
||||
private var barWidth: CGFloat = 20
|
||||
private var maxValue: Float = 101
|
||||
private var minValue: Float = 0
|
||||
private var sliderEnabled = true
|
||||
private var viewInset: CGFloat = 20
|
||||
private var minMaxSwitchTreshold: Float = 0.0
|
||||
private var thumbImage: UIImage?
|
||||
private var _thumbWidth: CGFloat?
|
||||
private var thumbWidth: CGFloat {
|
||||
get {
|
||||
if let retValue = _thumbWidth {
|
||||
return retValue
|
||||
}
|
||||
|
||||
return (thumbImage?.size.height)!
|
||||
}
|
||||
set {
|
||||
_thumbWidth = newValue
|
||||
}
|
||||
}
|
||||
|
||||
override open func awakeFromNib() {
|
||||
super.awakeFromNib()
|
||||
backgroundColor = UIColor.clear
|
||||
}
|
||||
|
||||
public init(frame: CGRect, options: [CircleSliderOption]?) {
|
||||
super.init(frame: frame)
|
||||
if let options = options {
|
||||
build(options)
|
||||
|
||||
let tapGesture = UITapGestureRecognizer(target: self, action: #selector(tapHandle(sender:)))
|
||||
tapGesture.numberOfTouchesRequired = 1
|
||||
let panGesture = UIPanGestureRecognizer(target: self, action: #selector(tapHandle(sender:)))
|
||||
addGestureRecognizer(tapGesture)
|
||||
addGestureRecognizer(panGesture)
|
||||
}
|
||||
}
|
||||
|
||||
required public init?(coder aDecoder: NSCoder) {
|
||||
fatalError("init(coder:) has not been implemented")
|
||||
}
|
||||
|
||||
override open func layoutSublayers(of layer: CALayer) {
|
||||
if trackLayer == nil {
|
||||
trackLayer = TrackLayer(bounds: bounds.insetBy(dx: viewInset, dy: viewInset), setting: createLayerSetting())
|
||||
}
|
||||
if thumbView == nil {
|
||||
if let image = thumbImage {
|
||||
thumbView = UIView(frame: CGRect(x: 0, y: 0, width: image.size.width, height: image.size.height))
|
||||
} else {
|
||||
thumbView = UIView(frame: CGRect(x: 0, y: 0, width: thumbWidth, height: thumbWidth))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override open func hitTest(_ point: CGPoint, with event: UIEvent?) -> UIView? {
|
||||
if !sliderEnabled {
|
||||
return nil
|
||||
}
|
||||
|
||||
return self
|
||||
}
|
||||
|
||||
open override func point(inside point: CGPoint, with event: UIEvent?) -> Bool {
|
||||
var bounds = self.bounds
|
||||
bounds = bounds.insetBy(dx: 100.0, dy: 100.0)
|
||||
return bounds.contains(point)
|
||||
}
|
||||
|
||||
override open func continueTracking(_ touch: UITouch, with event: UIEvent?) -> Bool {
|
||||
let degree = Math.pointPairToBearingDegrees(center, endPoint: touch.location(in: self))
|
||||
latestDegree = degree
|
||||
layout(degree)
|
||||
let value = Float(Math.adjustValue(startAngle, degree: degree, maxValue: maxValue, minValue: minValue))
|
||||
thumbView.transform = CGAffineTransform(rotationAngle: CGFloat(Math.degreesToRadians(degree)))
|
||||
sliderValue = value
|
||||
return true
|
||||
}
|
||||
|
||||
@objc
|
||||
func tapHandle(sender: UIGestureRecognizer) {
|
||||
if isUserInteractionEnabled {
|
||||
let degree = Math.pointPairToBearingDegrees(center, endPoint: sender.location(in: self))
|
||||
latestDegree = degree
|
||||
layout(degree)
|
||||
let value = Float(Math.adjustValue(startAngle, degree: degree, maxValue: maxValue, minValue: minValue))
|
||||
thumbView.transform = CGAffineTransform(rotationAngle: CGFloat(Math.degreesToRadians(degree)))
|
||||
sliderValue = value
|
||||
}
|
||||
}
|
||||
|
||||
open func changeOptions(_ options: [CircleSliderOption]) {
|
||||
build(options)
|
||||
redraw()
|
||||
}
|
||||
|
||||
private func redraw() {
|
||||
|
||||
if trackLayer != nil {
|
||||
trackLayer.removeFromSuperlayer()
|
||||
}
|
||||
trackLayer = TrackLayer(bounds: bounds.insetBy(dx: viewInset, dy: viewInset), setting: createLayerSetting())
|
||||
if thumbView != nil {
|
||||
thumbView.removeFromSuperview()
|
||||
}
|
||||
|
||||
if let image = thumbImage {
|
||||
thumbView = UIView(frame: CGRect(x: 0, y: 0, width: image.size.width, height: image.size.height))
|
||||
} else {
|
||||
thumbView = UIView(frame: CGRect(x: 0, y: 0, width: thumbWidth, height: thumbWidth))
|
||||
}
|
||||
|
||||
self.layout(self.latestDegree)
|
||||
}
|
||||
|
||||
func build(_ options: [CircleSliderOption]) {
|
||||
for option in options {
|
||||
switch option {
|
||||
case let .startAngle(value):
|
||||
startAngle = value
|
||||
latestDegree = startAngle
|
||||
case let .barColor(value):
|
||||
barColor = value
|
||||
case let .trackingColor(value):
|
||||
trackingColor = value
|
||||
case let .thumbColor(value):
|
||||
thumbColor = value
|
||||
case let .barWidth(value):
|
||||
barWidth = value
|
||||
case let .thumbWidth(value):
|
||||
thumbWidth = value
|
||||
case let .maxValue(value):
|
||||
maxValue = value
|
||||
maxValue += 1
|
||||
case let .minValue(value):
|
||||
minValue = value
|
||||
startValue = minValue
|
||||
case let .sliderEnabled(value):
|
||||
sliderEnabled = value
|
||||
case let .viewInset(value):
|
||||
viewInset = value
|
||||
case let .minMaxSwitchTreshold(value):
|
||||
minMaxSwitchTreshold = value
|
||||
case let .thumbImage(value):
|
||||
thumbImage = value
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private func layout(_ degree: Double) {
|
||||
if let trackLayer = trackLayer, let thumbView = self.thumbView {
|
||||
trackLayer.degree = degree
|
||||
thumbView.center = thumbCenter(degree)
|
||||
thumbView.transform = CGAffineTransform(rotationAngle: CGFloat(Math.degreesToRadians(degree)))
|
||||
trackLayer.setNeedsDisplay()
|
||||
}
|
||||
}
|
||||
|
||||
private func createLayerSetting() -> TrackLayer.Setting {
|
||||
var setting = TrackLayer.Setting()
|
||||
setting.startAngle = startAngle
|
||||
setting.barColor = barColor
|
||||
setting.trackingColor = trackingColor
|
||||
setting.barWidth = barWidth
|
||||
return setting
|
||||
}
|
||||
|
||||
private func thumbCenter(_ degree: Double) -> CGPoint {
|
||||
let radius = (bounds.insetBy(dx: viewInset, dy: viewInset).width * 0.5) - (barWidth * 0.5) + 5
|
||||
return Math.pointFromAngle(frame, angle: degree, radius: Double(radius))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,126 +0,0 @@
|
||||
/*
|
||||
Copyright (c) 2019, Novartis.
|
||||
Copyright (c) 2019, Apple Inc. All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification,
|
||||
are permitted provided that the following conditions are met:
|
||||
|
||||
1. Redistributions of source code must retain the above copyright notice, this
|
||||
list of conditions and the following disclaimer.
|
||||
|
||||
2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
this list of conditions and the following disclaimer in the documentation and/or
|
||||
other materials provided with the distribution.
|
||||
|
||||
3. Neither the name of the copyright holder(s) nor the names of any contributors
|
||||
may be used to endorse or promote products derived from this software without
|
||||
specific prior written permission. No license is granted to the trademarks of
|
||||
the copyright holders even if such marks are included in this software.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
|
||||
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
public enum DeviceType: String {
|
||||
|
||||
case iPhone5 = "iPhone5"
|
||||
case iPhone5C = "iPhone5C"
|
||||
case iPhone5S = "iPhone5S"
|
||||
case iPhone6Plus = "iPhone6Plus"
|
||||
case iPhone6 = "iPhone6"
|
||||
case iPhone6S = "iPhone6S"
|
||||
case iPhone6SPlus = "iPhone6SPlus"
|
||||
case iPhone7 = "iPhone7"
|
||||
case iPhone7Plus = "iPhone7Plus"
|
||||
case iPhoneSE = "iPhoneSE"
|
||||
|
||||
case IPodTouch5 = "iPod5,1"
|
||||
case IPodTouch6 = "iPod7,1"
|
||||
}
|
||||
|
||||
func parseDeviceType(_ identifier: String) -> DeviceType {
|
||||
|
||||
switch identifier {
|
||||
case "iPhone5,1", "iPhone5,2": return .iPhone5
|
||||
case "iPhone5,3", "iPhone5,4": return .iPhone5C
|
||||
case "iPhone6,1", "iPhone6,2": return .iPhone5S
|
||||
case "iPhone7,1": return .iPhone6Plus
|
||||
case "iPhone7,2": return .iPhone6
|
||||
case "iPhone8,2": return .iPhone6SPlus
|
||||
case "iPhone8,1": return .iPhone6S
|
||||
case "iPhone9,1", "iPhone9,3": return .iPhone7
|
||||
case "iPhone9,2", "iPhone9,4": return .iPhone7Plus
|
||||
case "iPhone8,4": return .iPhoneSE
|
||||
|
||||
case "iPod5,1": return .IPodTouch5
|
||||
case "iPod7,1": return .IPodTouch6
|
||||
|
||||
default:
|
||||
if UIDevice.iPhonePlus {
|
||||
return .iPhone7Plus
|
||||
} else {
|
||||
return .iPhone7
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var pixelPerInchIphonePlus: CGFloat = 401
|
||||
|
||||
var pixelPerInchIphone: CGFloat = 326
|
||||
|
||||
var inchPerMm: CGFloat = 25.4
|
||||
|
||||
var renderedPixels: CGFloat = 1.15
|
||||
|
||||
func parsePixelPerInch(deviceType: DeviceType) -> CGFloat {
|
||||
|
||||
switch deviceType {
|
||||
case .iPhone5, .iPhone5C, .iPhone5S, .iPhoneSE, .iPhone6, .iPhone6S, .iPhone7, .IPodTouch5, .IPodTouch6: return pixelPerInchIphone
|
||||
case .iPhone6Plus, .iPhone6SPlus, .iPhone7Plus: return pixelPerInchIphonePlus
|
||||
}
|
||||
}
|
||||
|
||||
public extension UIDevice {
|
||||
|
||||
class var deviceType: DeviceType {
|
||||
var systemInfo = utsname()
|
||||
uname(&systemInfo)
|
||||
|
||||
let machine = systemInfo.machine
|
||||
let mirror = Mirror(reflecting: machine)
|
||||
var identifier = ""
|
||||
|
||||
for child in mirror.children {
|
||||
if let value = child.value as? Int8, value != 0 {
|
||||
identifier.append(String(UnicodeScalar(UInt8(value))))
|
||||
}
|
||||
}
|
||||
|
||||
return parseDeviceType(identifier)
|
||||
}
|
||||
|
||||
class var pixelsPerMm: CGFloat {
|
||||
return parsePixelPerInch(deviceType: UIDevice.deviceType) / inchPerMm
|
||||
}
|
||||
|
||||
class var iPhonePlus: Bool {
|
||||
if UIDevice.current.userInterfaceIdiom != .phone {
|
||||
return false
|
||||
}
|
||||
|
||||
if UIScreen.main.scale > 2.9 {
|
||||
return true
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,181 +0,0 @@
|
||||
/*
|
||||
Copyright (c) 2019, Novartis.
|
||||
Copyright (c) 2019, Apple Inc. All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification,
|
||||
are permitted provided that the following conditions are met:
|
||||
|
||||
1. Redistributions of source code must retain the above copyright notice, this
|
||||
list of conditions and the following disclaimer.
|
||||
|
||||
2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
this list of conditions and the following disclaimer in the documentation and/or
|
||||
other materials provided with the distribution.
|
||||
|
||||
3. Neither the name of the copyright holder(s) nor the names of any contributors
|
||||
may be used to endorse or promote products derived from this software without
|
||||
specific prior written permission. No license is granted to the trademarks of
|
||||
the copyright holders even if such marks are included in this software.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
|
||||
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
internal class EyeActivitySlider: UIView {
|
||||
|
||||
private var testType: VisionStepType?
|
||||
|
||||
private var incorrectAnswers = 0
|
||||
private let contentGap: CGFloat = 20.0
|
||||
private let toleranceAngle = 22.5
|
||||
private let letterAngles = [0, 45, 90, 135, 180, 225, 270, 315]
|
||||
private var letterSize: CGFloat {
|
||||
var letterSize: CGFloat!
|
||||
|
||||
if self.testType == .visualAcuity {
|
||||
letterSize = letterMmSizes[currentStep] * UIDevice.pixelsPerMm / UIScreen.main.nativeScale
|
||||
} else {
|
||||
letterSize = 20 * UIDevice.pixelsPerMm / UIScreen.main.nativeScale
|
||||
}
|
||||
|
||||
return letterSize
|
||||
}
|
||||
|
||||
private var currentStep = 0
|
||||
private var letterMmSizes: [CGFloat] = [5.82, 4.65, 3.72, 2.91, 2.33, 1.86, 1.45, 1.16, 0.93, 0.73, 0.58, 0.47, 0.37]
|
||||
private var contrastLevels: [CGFloat] = [0.9, 0.92, 0.937, 0.95, 0.96, 0.968, 0.975, 0.98, 0.984, 0.9875, 0.99]
|
||||
private var stepScores: [Int] = [50, 55, 60, 65, 70, 75, 80, 85, 90, 95, 100, 105, 110]
|
||||
private var letterAngle = 0.0
|
||||
|
||||
private lazy var letterImageView: UIImageView = {
|
||||
let letterImage = UIImage(named: "iCNLandoltC",
|
||||
in: Bundle(for: type(of: self)),
|
||||
compatibleWith: nil)
|
||||
let imageView = UIImageView(image: letterImage!)
|
||||
return imageView
|
||||
}()
|
||||
|
||||
private lazy var circleImageView: UIImageView = {
|
||||
let circleImage = UIImage(named: "orangeGrayCircle",
|
||||
in: Bundle(for: type(of: self)),
|
||||
compatibleWith: nil)
|
||||
return UIImageView(image: circleImage!)
|
||||
}()
|
||||
|
||||
private var slider: CircleSlider?
|
||||
|
||||
internal init(testType: VisionStepType) {
|
||||
super.init(frame: CGRect())
|
||||
|
||||
self.testType = testType
|
||||
commonInit()
|
||||
}
|
||||
|
||||
required internal init?(coder aDecoder: NSCoder) {
|
||||
super.init(coder: aDecoder)
|
||||
commonInit()
|
||||
}
|
||||
|
||||
private func commonInit() {
|
||||
addSubview(letterImageView)
|
||||
|
||||
circleImageView.contentMode = .scaleAspectFit
|
||||
addSubview(circleImageView)
|
||||
|
||||
let thumbImage = UIImage(named: "iCNDialPointerWithShadow",
|
||||
in: Bundle(for: type(of: self)),
|
||||
compatibleWith: nil)
|
||||
|
||||
slider = CircleSlider(frame: bounds, options: [
|
||||
CircleSliderOption.barColor(UIColor.clear),
|
||||
CircleSliderOption.trackingColor(UIColor.clear),
|
||||
CircleSliderOption.startAngle(0),
|
||||
CircleSliderOption.maxValue(360),
|
||||
CircleSliderOption.minValue(0),
|
||||
CircleSliderOption.thumbImage(thumbImage!)
|
||||
])
|
||||
|
||||
addSubview(slider!)
|
||||
updateSliderAndLetter()
|
||||
}
|
||||
|
||||
override public func layoutSubviews() {
|
||||
super.layoutSubviews()
|
||||
|
||||
letterAngle = Double(letterAngles[Int(arc4random_uniform(7))])
|
||||
letterImageView.transform = CGAffineTransform.identity
|
||||
letterImageView.frame = CGRect(origin: CGPoint(), size: CGSize(width: letterSize, height: letterSize))
|
||||
letterImageView.center = CGPoint(x: bounds.size.width / 2, y: bounds.size.height / 2)
|
||||
letterImageView.transform = CGAffineTransform(rotationAngle: CGFloat(Math.degreesToRadians(letterAngle)))
|
||||
letterImageView.alpha = getAlpha()
|
||||
slider?.frame = bounds
|
||||
|
||||
var frame = contentFrame()
|
||||
circleImageView.frame = frame
|
||||
|
||||
let labelMargin: CGFloat = 30.0
|
||||
frame.origin.x += labelMargin
|
||||
frame.origin.y += labelMargin
|
||||
frame.size.width -= labelMargin * 2
|
||||
frame.size.height -= labelMargin * 2
|
||||
}
|
||||
|
||||
private func updateSliderAndLetter() {
|
||||
guard incorrectAnswers < 2 else { return }
|
||||
|
||||
letterImageView.isHidden = false
|
||||
slider?.sliderValue = 0
|
||||
slider?.isUserInteractionEnabled = true
|
||||
slider?.isHidden = false
|
||||
setNeedsLayout()
|
||||
}
|
||||
|
||||
private func contentFrame() -> CGRect {
|
||||
let sideLength = min(bounds.size.width, bounds.size.height) - contentGap
|
||||
let contentFrame = CGRect(x: (bounds.size.width - sideLength) / 2, y: (bounds.size.height - sideLength) / 2, width: sideLength, height: sideLength)
|
||||
return contentFrame
|
||||
}
|
||||
|
||||
private func getAlpha() -> CGFloat {
|
||||
return testType == .visualAcuity ? 1.0 : (1 - contrastLevels[currentStep])
|
||||
}
|
||||
|
||||
private func getResult() -> Bool {
|
||||
let sliderValue = Double((slider?.sliderValue)!)
|
||||
let leftMargin = letterAngle - toleranceAngle
|
||||
let rightMargin = letterAngle + toleranceAngle
|
||||
let result = sliderValue > leftMargin && sliderValue < rightMargin
|
||||
|
||||
if result == false {
|
||||
incorrectAnswers += 1
|
||||
} else {
|
||||
currentStep += 1
|
||||
}
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
internal func hideLetter() {
|
||||
letterImageView.isHidden = true
|
||||
}
|
||||
|
||||
internal func fetchResultDataAndUpdateSlider() -> (outcome: Bool, letterAngle: Double, sliderAngle: Double, score: Int, incorrectAnswers: Int, maxScore: Int) {
|
||||
let outcome = getResult()
|
||||
let score = stepScores[currentStep]
|
||||
let currentSliderValue = Double((slider?.sliderValue)!)
|
||||
let currentLetterAngle = letterAngle
|
||||
let maxScore = testType == .visualAcuity ? stepScores.last! : stepScores[contrastLevels.count - 1]
|
||||
updateSliderAndLetter()
|
||||
|
||||
return (outcome, currentLetterAngle, currentSliderValue, score, incorrectAnswers, maxScore)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,76 +0,0 @@
|
||||
/*
|
||||
Copyright (c) 2019, Novartis.
|
||||
Copyright (c) 2019, Apple Inc. All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification,
|
||||
are permitted provided that the following conditions are met:
|
||||
|
||||
1. Redistributions of source code must retain the above copyright notice, this
|
||||
list of conditions and the following disclaimer.
|
||||
|
||||
2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
this list of conditions and the following disclaimer in the documentation and/or
|
||||
other materials provided with the distribution.
|
||||
|
||||
3. Neither the name of the copyright holder(s) nor the names of any contributors
|
||||
may be used to endorse or promote products derived from this software without
|
||||
specific prior written permission. No license is granted to the trademarks of
|
||||
the copyright holders even if such marks are included in this software.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
|
||||
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
internal class Math {
|
||||
|
||||
internal class func degreesToRadians(_ angle: Double) -> Double {
|
||||
return angle / 180 * .pi
|
||||
}
|
||||
|
||||
internal class func pointFromAngle(_ frame: CGRect, angle: Double, radius: Double) -> CGPoint {
|
||||
let radian = degreesToRadians(angle)
|
||||
let xPoint = Double(frame.midX) + cos(radian) * radius
|
||||
let yPoint = Double(frame.midY) + sin(radian) * radius
|
||||
return CGPoint(x: xPoint, y: yPoint)
|
||||
}
|
||||
|
||||
internal class func pointPairToBearingDegrees(_ startPoint: CGPoint, endPoint: CGPoint) -> Double {
|
||||
let originPoint = CGPoint(x: endPoint.x - startPoint.x, y: endPoint.y - startPoint.y)
|
||||
let bearingRadians = atan2(Double(originPoint.y), Double(originPoint.x))
|
||||
var bearingDegrees = bearingRadians * (180.0 / .pi)
|
||||
bearingDegrees = (bearingDegrees > 0.0 ? bearingDegrees : (360.0 + bearingDegrees))
|
||||
return bearingDegrees
|
||||
}
|
||||
|
||||
internal class func adjustValue(_ startAngle: Double, degree: Double, maxValue: Float, minValue: Float) -> Double {
|
||||
let ratio = Double((maxValue - minValue) / 360)
|
||||
let ratioStart = ratio * startAngle
|
||||
let ratioDegree = ratio * degree
|
||||
let adjustValue: Double
|
||||
if startAngle < 0 {
|
||||
adjustValue = (360 + startAngle) > degree ? (ratioDegree - ratioStart) : (ratioDegree - ratioStart) - (360 * ratio)
|
||||
} else {
|
||||
adjustValue = (360 - (360 - startAngle)) < degree ? (ratioDegree - ratioStart) : (ratioDegree - ratioStart) + (360 * ratio)
|
||||
}
|
||||
return adjustValue + (Double(minValue))
|
||||
}
|
||||
|
||||
internal class func adjustDegree(_ startAngle: Double, degree: Double) -> Double {
|
||||
return (360 + startAngle) > degree ? degree : -(360 - degree)
|
||||
}
|
||||
|
||||
internal class func degreeFromValue(_ startAngle: Double, value: Float, maxValue: Float, minValue: Float) -> Double {
|
||||
let ratio = Double((maxValue - minValue) / 360)
|
||||
let angle = Double(value) / ratio
|
||||
return angle + startAngle - (Double(minValue) / ratio)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,255 +0,0 @@
|
||||
/*
|
||||
Copyright (c) 2018, Apple Inc. All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification,
|
||||
are permitted provided that the following conditions are met:
|
||||
|
||||
1. Redistributions of source code must retain the above copyright notice, this
|
||||
list of conditions and the following disclaimer.
|
||||
|
||||
2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
this list of conditions and the following disclaimer in the documentation and/or
|
||||
other materials provided with the distribution.
|
||||
|
||||
3. Neither the name of the copyright holder(s) nor the names of any contributors
|
||||
may be used to endorse or promote products derived from this software without
|
||||
specific prior written permission. No license is granted to the trademarks of
|
||||
the copyright holders even if such marks are included in this software.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
|
||||
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
|
||||
#import "ORKEnvironmentSPLMeterContentView.h"
|
||||
|
||||
#import "ORKRoundTappingButton.h"
|
||||
#import "ORKUnitLabel.h"
|
||||
#import "ORKHelpers_Internal.h"
|
||||
#import "ORKSkin.h"
|
||||
#import "ORKRingView.h"
|
||||
#import "ORKProgressView.h"
|
||||
#import "ORKCompletionCheckmarkView.h"
|
||||
|
||||
static const CGFloat CircleIndicatorMaxDiameter = 150.0;
|
||||
static const CGFloat RingViewTopPadding = 24.0;
|
||||
static const CGFloat InstructionLabelTopPadding = 50.0;
|
||||
static const CGFloat InstructionLabelBottomPadding = 10.0;
|
||||
|
||||
static CGFloat CircleIndicatorViewScaleFactorForProgress(CGFloat progress) {
|
||||
|
||||
CGFloat y1 = 0.5, x1 = 0.8, y2 = 1.4, x2 = 1.2;
|
||||
|
||||
if (progress < x1) // lower limit for diameter
|
||||
{
|
||||
return y1;
|
||||
}
|
||||
else if (progress > x2) // upper limit for diameter
|
||||
{
|
||||
return y2;
|
||||
}
|
||||
else // linear interpolation
|
||||
{
|
||||
return y1 + (y2 - y1)/(x2 - x1) * (progress - x1);
|
||||
}
|
||||
}
|
||||
|
||||
static CGFloat CircleIndicatorPulseVarianceForProgress(CGFloat progress) {
|
||||
|
||||
// Linear Interpolation
|
||||
// kMin: Lower bound of interpolation. (Matches above)
|
||||
// kMax: Higher bound of interpolation. (Matches above)
|
||||
// min: Lower bound of variance.
|
||||
// max: Higher bound of variance.
|
||||
CGFloat min = 0.0075, max = 0.025;
|
||||
CGFloat kMin = 0.8, kMax = 1.2;
|
||||
|
||||
if (progress < kMin)
|
||||
{
|
||||
return min;
|
||||
}
|
||||
else if (progress > kMax)
|
||||
{
|
||||
return max;
|
||||
}
|
||||
else
|
||||
{
|
||||
return min + (max - min)/(kMax - kMin) * (progress - kMin);
|
||||
}
|
||||
}
|
||||
|
||||
@interface ORKEnvironmentSPLMeterContentView ()
|
||||
@property(nonatomic, strong) ORKRingView *ringView;
|
||||
@end
|
||||
|
||||
@implementation ORKEnvironmentSPLMeterContentView {
|
||||
UIView *_circleIndicatorView;
|
||||
UILabel *_DBInstructionLabel;
|
||||
CGFloat preValue;
|
||||
CGFloat currentValue;
|
||||
UIColor *_circleIndicatorNoiseColor;
|
||||
}
|
||||
|
||||
- (instancetype)init {
|
||||
self = [super init];
|
||||
if (self) {
|
||||
preValue = -M_PI_2;
|
||||
currentValue = 0.0;
|
||||
_circleIndicatorNoiseColor = UIColor.systemOrangeColor;
|
||||
self.translatesAutoresizingMaskIntoConstraints = NO;
|
||||
[self setupRingView];
|
||||
[self setupCircleIndicatorView];
|
||||
[self setProgressCircle:0.0];
|
||||
[self setupDBInstructionLabel];
|
||||
}
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void)setupRingView {
|
||||
if (!_ringView) {
|
||||
_ringView = [ORKRingView new];
|
||||
}
|
||||
_ringView.animationDuration = 0.0;
|
||||
_ringView.translatesAutoresizingMaskIntoConstraints = NO;
|
||||
[self addSubview:_ringView];
|
||||
|
||||
[[_ringView.centerXAnchor constraintEqualToAnchor:self.centerXAnchor] setActive:YES];
|
||||
[[_ringView.topAnchor constraintEqualToAnchor:self.topAnchor constant:RingViewTopPadding] setActive:YES];
|
||||
[_ringView setColor:UIColor.grayColor];
|
||||
}
|
||||
|
||||
- (void)setupCircleIndicatorView {
|
||||
if (!_circleIndicatorView) {
|
||||
_circleIndicatorView = [UIView new];
|
||||
}
|
||||
_circleIndicatorView.translatesAutoresizingMaskIntoConstraints = NO;
|
||||
[self insertSubview:_circleIndicatorView belowSubview:_ringView];
|
||||
|
||||
[[_circleIndicatorView.centerXAnchor constraintEqualToAnchor:_ringView.centerXAnchor] setActive:YES];
|
||||
[[_circleIndicatorView.centerYAnchor constraintEqualToAnchor:_ringView.centerYAnchor] setActive:YES];
|
||||
[[_circleIndicatorView.heightAnchor constraintEqualToConstant:CircleIndicatorMaxDiameter] setActive:YES];
|
||||
[[_circleIndicatorView.widthAnchor constraintEqualToConstant:CircleIndicatorMaxDiameter] setActive:YES];
|
||||
_circleIndicatorView.layer.cornerRadius = CircleIndicatorMaxDiameter * 0.5;
|
||||
}
|
||||
|
||||
- (void)setupDBInstructionLabel {
|
||||
if (!_DBInstructionLabel) {
|
||||
_DBInstructionLabel = [ORKLabel new];
|
||||
_DBInstructionLabel.numberOfLines = 0;
|
||||
_DBInstructionLabel.textColor = UIColor.systemGrayColor;
|
||||
_DBInstructionLabel.text = ORKLocalizedString(@"ENVIRONMENTSPL_OK", nil);
|
||||
}
|
||||
_DBInstructionLabel.translatesAutoresizingMaskIntoConstraints = NO;
|
||||
[self addSubview:_DBInstructionLabel];
|
||||
|
||||
[[_DBInstructionLabel.centerXAnchor constraintEqualToAnchor:self.centerXAnchor] setActive:YES];
|
||||
[[_DBInstructionLabel.topAnchor constraintEqualToAnchor:_circleIndicatorView.bottomAnchor constant:InstructionLabelTopPadding] setActive:YES];
|
||||
[[_DBInstructionLabel.bottomAnchor constraintLessThanOrEqualToAnchor:self.bottomAnchor constant:-InstructionLabelBottomPadding] setActive:YES];
|
||||
}
|
||||
|
||||
- (void)setProgressCircle:(CGFloat)progress {
|
||||
|
||||
CGFloat circleDiameter = CircleIndicatorViewScaleFactorForProgress(progress);
|
||||
CGFloat variance = CircleIndicatorPulseVarianceForProgress(progress);
|
||||
|
||||
[self startPulsingWithTranformScaleFactor:circleDiameter variance:variance];
|
||||
|
||||
if (progress >= ORKRingViewMaximumValue)
|
||||
{
|
||||
|
||||
[_ringView setBackgroundLayerStrokeColor:[UIColor.whiteColor colorWithAlphaComponent:0.3] circleStrokeColor:UIColor.whiteColor withAnimationDuration:0.8];
|
||||
}
|
||||
else
|
||||
{
|
||||
[_ringView resetLayerColors];
|
||||
}
|
||||
|
||||
[UIView animateWithDuration:0.8
|
||||
delay:0
|
||||
options:UIViewAnimationOptionCurveLinear
|
||||
animations:^{
|
||||
_circleIndicatorView.transform = CGAffineTransformMakeScale(circleDiameter, circleDiameter);
|
||||
_circleIndicatorView.backgroundColor = progress >= ORKRingViewMaximumValue ? _circleIndicatorNoiseColor : self.tintColor;
|
||||
} completion:nil];
|
||||
|
||||
[self updateInstructionForValue:progress];
|
||||
}
|
||||
|
||||
- (ORKRingView *)ringView
|
||||
{
|
||||
return _ringView;
|
||||
}
|
||||
|
||||
- (void)startPulsingWithTranformScaleFactor:(CGFloat)transformScaleFactor variance:(CGFloat)variance {
|
||||
|
||||
[self stopPulsing];
|
||||
|
||||
CAKeyframeAnimation *pulse = [CAKeyframeAnimation animationWithKeyPath:@"transform.scale.xy"];
|
||||
pulse.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
|
||||
pulse.repeatCount = MAXFLOAT;
|
||||
pulse.duration = 0.6;
|
||||
pulse.values = @[
|
||||
@(transformScaleFactor),
|
||||
@(transformScaleFactor * (1 - variance)),
|
||||
@(transformScaleFactor),
|
||||
@(transformScaleFactor * (1 + variance)),
|
||||
@(transformScaleFactor)
|
||||
];
|
||||
|
||||
[_circleIndicatorView.layer addAnimation:pulse forKey:@"pulse"];
|
||||
}
|
||||
|
||||
- (void)stopPulsing {
|
||||
[_circleIndicatorView.layer removeAnimationForKey:@"pulse"];
|
||||
}
|
||||
|
||||
- (void)setProgress:(CGFloat)progress {
|
||||
CGFloat value = progress < ORKRingViewMinimumValue ? ORKRingViewMinimumValue : progress;
|
||||
[_ringView setValue:value];
|
||||
}
|
||||
|
||||
- (void)updateInstructionForValue:(CGFloat)progress
|
||||
{
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
|
||||
NSString *currentInstruction = [_DBInstructionLabel.text copy];
|
||||
NSString *newInstruction = progress >= ORKRingViewMaximumValue ? ORKLocalizedString(@"ENVIRONMENTSPL_NOISE", nil) : ORKLocalizedString(@"ENVIRONMENTSPL_OK", nil);
|
||||
|
||||
if (![newInstruction isEqualToString:currentInstruction])
|
||||
{
|
||||
_DBInstructionLabel.text = newInstruction;
|
||||
|
||||
if (UIAccessibilityIsVoiceOverRunning() && [self.voiceOverDelegate respondsToSelector:@selector(contentView:shouldAnnounce:)])
|
||||
{
|
||||
[self.voiceOverDelegate contentView:self shouldAnnounce:_DBInstructionLabel.text];
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
- (void)finishStep:(ORKActiveStepViewController *)viewController {
|
||||
[super finishStep:viewController];
|
||||
}
|
||||
|
||||
- (void)reachedOptimumNoiseLevel {
|
||||
[self stopPulsing];
|
||||
_ringView.hidden = YES;
|
||||
_circleIndicatorView.hidden = YES;
|
||||
ORKCompletionCheckmarkView *checkmarkView = [[ORKCompletionCheckmarkView alloc] initWithDimension:_ringView.bounds.size.width];
|
||||
checkmarkView.translatesAutoresizingMaskIntoConstraints = NO;
|
||||
[self insertSubview:checkmarkView aboveSubview:_ringView];
|
||||
[[checkmarkView.centerXAnchor constraintEqualToAnchor:_ringView.centerXAnchor] setActive:YES];
|
||||
[[checkmarkView.centerYAnchor constraintEqualToAnchor:_ringView.centerYAnchor] setActive:YES];
|
||||
[checkmarkView setAnimationPoint:1 animated:YES];
|
||||
}
|
||||
|
||||
@end
|
||||
@@ -1,346 +0,0 @@
|
||||
/*
|
||||
Copyright (c) 2015, Apple Inc. All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification,
|
||||
are permitted provided that the following conditions are met:
|
||||
|
||||
1. Redistributions of source code must retain the above copyright notice, this
|
||||
list of conditions and the following disclaimer.
|
||||
|
||||
2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
this list of conditions and the following disclaimer in the documentation and/or
|
||||
other materials provided with the distribution.
|
||||
|
||||
3. Neither the name of the copyright holder(s) nor the names of any contributors
|
||||
may be used to endorse or promote products derived from this software without
|
||||
specific prior written permission. No license is granted to the trademarks of
|
||||
the copyright holders even if such marks are included in this software.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
|
||||
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
|
||||
#import "ORKFitnessContentView.h"
|
||||
|
||||
#import "ORKActiveStepQuantityView.h"
|
||||
#import "ORKTintedImageView.h"
|
||||
|
||||
#import "ORKHelpers_Internal.h"
|
||||
#import "ORKSkin.h"
|
||||
|
||||
@import CoreMotion;
|
||||
@import HealthKit;
|
||||
|
||||
|
||||
// #define LAYOUT_TEST 1
|
||||
// #define LAYOUT_DEBUG 1
|
||||
|
||||
@interface ORKFitnessContentView () {
|
||||
ORKQuantityLabel *_timerLabel;
|
||||
ORKQuantityPairView *_quantityPairView;
|
||||
UIView *_imageSpacer1;
|
||||
UIView *_imageSpacer2;
|
||||
ORKTintedImageView *_imageView;
|
||||
NSLengthFormatter *_lengthFormatter;
|
||||
NSLayoutConstraint *_imageRatioConstraint;
|
||||
NSLayoutConstraint *_topConstraint;
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
|
||||
@implementation ORKFitnessContentView
|
||||
|
||||
- (ORKActiveStepQuantityView *)distanceView {
|
||||
return _quantityPairView.leftView;
|
||||
}
|
||||
|
||||
- (ORKActiveStepQuantityView *)heartRateView {
|
||||
return _quantityPairView.rightView;
|
||||
}
|
||||
|
||||
- (instancetype)initWithFrame:(CGRect)frame {
|
||||
self = [super initWithFrame:frame];
|
||||
if (self) {
|
||||
_timerLabel = [ORKQuantityLabel new];
|
||||
_quantityPairView = [ORKQuantityPairView new];
|
||||
_imageSpacer1 = [UIView new];
|
||||
_imageSpacer1.translatesAutoresizingMaskIntoConstraints = NO;
|
||||
_imageSpacer2 = [UIView new];
|
||||
_imageSpacer2.translatesAutoresizingMaskIntoConstraints = NO;
|
||||
[self addSubview:_imageSpacer1];
|
||||
[self addSubview:_imageSpacer2];
|
||||
[self heartRateView].image = [UIImage imageNamed:@"heart-fitness" inBundle:[NSBundle bundleForClass:[self class]] compatibleWithTraitCollection:nil];
|
||||
[self updateLengthFormatter];
|
||||
_imageView = [ORKTintedImageView new];
|
||||
_imageView.contentMode = UIViewContentModeScaleAspectFit;
|
||||
_imageView.shouldApplyTint = YES;
|
||||
_timerLabel.translatesAutoresizingMaskIntoConstraints = NO;
|
||||
_quantityPairView.translatesAutoresizingMaskIntoConstraints = NO;
|
||||
_imageView.translatesAutoresizingMaskIntoConstraints = NO;
|
||||
self.translatesAutoresizingMaskIntoConstraints = NO;
|
||||
[self updateKeylineVisible];
|
||||
|
||||
_timerLabel.accessibilityTraits |= UIAccessibilityTraitUpdatesFrequently;
|
||||
_imageView.isAccessibilityElement = NO;
|
||||
|
||||
self.hasHeartRate = _hasHeartRate;
|
||||
self.hasDistance = _hasDistance;
|
||||
|
||||
#if LAYOUT_TEST
|
||||
self.timeLeft = 60 * 5;
|
||||
self.hasHeartRate = YES;
|
||||
self.hasDistance = YES;
|
||||
self.distanceInMeters = 100;
|
||||
self.heartRate = @"22";
|
||||
#endif
|
||||
#if LAYOUT_DEBUG
|
||||
self.backgroundColor = [[UIColor redColor] colorWithAlphaComponent:0.2];
|
||||
_quantityPairView.backgroundColor = [[UIColor orangeColor] colorWithAlphaComponent:0.2];
|
||||
#endif
|
||||
|
||||
[self setDistanceInMeters:0];
|
||||
[self heartRateView].title = ORKLocalizedString(@"FITNESS_HEARTRATE_TITLE", nil);
|
||||
|
||||
[self addSubview:_quantityPairView];
|
||||
[self addSubview:_imageView];
|
||||
[self addSubview:_timerLabel];
|
||||
[self setUpConstraints];
|
||||
|
||||
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(localeDidChange:) name:NSCurrentLocaleDidChangeNotification object:nil];
|
||||
|
||||
[self tintColorDidChange];
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void)dealloc {
|
||||
[[NSNotificationCenter defaultCenter] removeObserver:self];
|
||||
}
|
||||
|
||||
- (void)updateLengthFormatter {
|
||||
_lengthFormatter = [NSLengthFormatter new];
|
||||
_lengthFormatter.numberFormatter.maximumFractionDigits = 1;
|
||||
_lengthFormatter.numberFormatter.maximumSignificantDigits = 3;
|
||||
}
|
||||
|
||||
- (void)localeDidChange:(NSNotification *)notification {
|
||||
[self updateLengthFormatter];
|
||||
[self setDistanceInMeters:_distanceInMeters];
|
||||
}
|
||||
|
||||
- (void)willMoveToWindow:(UIWindow *)newWindow {
|
||||
[super willMoveToWindow:newWindow];
|
||||
[self updateConstraintConstantsForWindow:newWindow];
|
||||
}
|
||||
|
||||
- (void)updateConstraintConstantsForWindow:(UIWindow *)window {
|
||||
const CGFloat CaptionBaselineToTimerTop = ORKGetMetricForWindow(ORKScreenMetricCaptionBaselineToFitnessTimerTop, window);
|
||||
const CGFloat CaptionBaselineToStepViewTop = ORKGetMetricForWindow(ORKScreenMetricLearnMoreBaselineToStepViewTop, window);
|
||||
_topConstraint.constant = (CaptionBaselineToTimerTop - CaptionBaselineToStepViewTop);
|
||||
}
|
||||
|
||||
- (void)setUpConstraints {
|
||||
NSMutableArray *constraints = [NSMutableArray array];
|
||||
NSDictionary *views = NSDictionaryOfVariableBindings(_timerLabel, _imageView, _quantityPairView, _imageSpacer1, _imageSpacer2);
|
||||
|
||||
[constraints addObjectsFromArray:
|
||||
[NSLayoutConstraint constraintsWithVisualFormat:@"V:[_timerLabel][_imageSpacer1(>=0)][_imageView]"
|
||||
options:NSLayoutFormatAlignAllCenterX
|
||||
metrics:nil
|
||||
views:views]];
|
||||
|
||||
_topConstraint = [NSLayoutConstraint constraintWithItem:_timerLabel
|
||||
attribute:NSLayoutAttributeTop
|
||||
relatedBy:NSLayoutRelationEqual
|
||||
toItem:self
|
||||
attribute:NSLayoutAttributeTop
|
||||
multiplier:1.0
|
||||
constant:0.0];
|
||||
[constraints addObject:_topConstraint];
|
||||
|
||||
[constraints addObject:[NSLayoutConstraint constraintWithItem:_timerLabel
|
||||
attribute:NSLayoutAttributeCenterX
|
||||
relatedBy:NSLayoutRelationEqual
|
||||
toItem:self
|
||||
attribute:NSLayoutAttributeCenterX
|
||||
multiplier:1.0
|
||||
constant:0.0]];
|
||||
|
||||
[constraints addObject:[NSLayoutConstraint constraintWithItem:_timerLabel
|
||||
attribute:NSLayoutAttributeWidth
|
||||
relatedBy:NSLayoutRelationLessThanOrEqual
|
||||
toItem:self attribute:NSLayoutAttributeWidth
|
||||
multiplier:1.0
|
||||
constant:0.0]];
|
||||
|
||||
[constraints addObject:[NSLayoutConstraint constraintWithItem:_imageView
|
||||
attribute:NSLayoutAttributeWidth
|
||||
relatedBy:NSLayoutRelationLessThanOrEqual
|
||||
toItem:self attribute:NSLayoutAttributeWidth
|
||||
multiplier:1.0
|
||||
constant:0.0]];
|
||||
|
||||
[constraints addObjectsFromArray:
|
||||
[NSLayoutConstraint constraintsWithVisualFormat:@"V:[_imageView][_imageSpacer2(>=0)][_quantityPairView]|"
|
||||
options:(NSLayoutFormatOptions)0
|
||||
metrics:nil
|
||||
views:views]];
|
||||
|
||||
[constraints addObject:[NSLayoutConstraint constraintWithItem:_imageSpacer1
|
||||
attribute:NSLayoutAttributeWidth
|
||||
relatedBy:NSLayoutRelationEqual
|
||||
toItem:nil
|
||||
attribute:NSLayoutAttributeNotAnAttribute
|
||||
multiplier:1.0
|
||||
constant:0.0]];
|
||||
|
||||
[constraints addObject:[NSLayoutConstraint constraintWithItem:_imageSpacer2
|
||||
attribute:NSLayoutAttributeWidth
|
||||
relatedBy:NSLayoutRelationEqual
|
||||
toItem:nil
|
||||
attribute:NSLayoutAttributeNotAnAttribute
|
||||
multiplier:1.0
|
||||
constant:0.0]];
|
||||
|
||||
[constraints addObject:[NSLayoutConstraint constraintWithItem:_imageSpacer1
|
||||
attribute:NSLayoutAttributeHeight
|
||||
relatedBy:NSLayoutRelationEqual
|
||||
toItem:_imageSpacer2
|
||||
attribute:NSLayoutAttributeHeight
|
||||
multiplier:1.0
|
||||
constant:0.0]];
|
||||
|
||||
NSLayoutConstraint *imageSpacerHeightConstraint = [NSLayoutConstraint constraintWithItem:_imageSpacer1
|
||||
attribute:NSLayoutAttributeHeight
|
||||
relatedBy:NSLayoutRelationEqual
|
||||
toItem:nil
|
||||
attribute:NSLayoutAttributeNotAnAttribute
|
||||
multiplier:1.0
|
||||
constant:CGFLOAT_MIN];
|
||||
imageSpacerHeightConstraint.priority = UILayoutPriorityDefaultLow - 1;
|
||||
[constraints addObject:imageSpacerHeightConstraint];
|
||||
|
||||
[constraints addObjectsFromArray:
|
||||
[NSLayoutConstraint constraintsWithVisualFormat:@"H:|[_quantityPairView]|"
|
||||
options:(NSLayoutFormatOptions)0
|
||||
metrics:nil
|
||||
views:views]];
|
||||
|
||||
NSLayoutConstraint *maxWidthConstraint = [NSLayoutConstraint constraintWithItem:self
|
||||
attribute:NSLayoutAttributeWidth
|
||||
relatedBy:NSLayoutRelationEqual
|
||||
toItem:nil
|
||||
attribute:NSLayoutAttributeNotAnAttribute
|
||||
multiplier:1.0
|
||||
constant:ORKScreenMetricMaxDimension];
|
||||
maxWidthConstraint.priority = UILayoutPriorityRequired - 1;
|
||||
[constraints addObject:maxWidthConstraint];
|
||||
|
||||
[NSLayoutConstraint activateConstraints:constraints];
|
||||
[self updateConstraintConstantsForWindow:self.window];
|
||||
}
|
||||
|
||||
- (void)setImage:(UIImage *)image {
|
||||
_image = image;
|
||||
_imageView.image = image;
|
||||
|
||||
_imageRatioConstraint.active = NO;
|
||||
|
||||
CGSize size = image.size;
|
||||
if (size.width > 0 && size.height > 0) {
|
||||
_imageRatioConstraint = [NSLayoutConstraint constraintWithItem:_imageView
|
||||
attribute:NSLayoutAttributeHeight
|
||||
relatedBy:NSLayoutRelationEqual
|
||||
toItem:_imageView
|
||||
attribute:NSLayoutAttributeWidth
|
||||
multiplier:size.height / size.width
|
||||
constant:0.0];
|
||||
_imageRatioConstraint.active = YES;
|
||||
}
|
||||
}
|
||||
|
||||
- (void)setHasDistance:(BOOL)hasDistance {
|
||||
_hasDistance = hasDistance;
|
||||
[self distanceView].enabled = _hasDistance;
|
||||
[self updateKeylineVisible];
|
||||
}
|
||||
|
||||
- (void)setHasHeartRate:(BOOL)hasHeartRate {
|
||||
_hasHeartRate = hasHeartRate;
|
||||
[self heartRateView].enabled = _hasHeartRate;
|
||||
[self updateKeylineVisible];
|
||||
}
|
||||
|
||||
- (void)setHeartRate:(NSString *)heartRate {
|
||||
_heartRate = heartRate;
|
||||
[self heartRateView].value = heartRate;
|
||||
}
|
||||
|
||||
- (void)updateKeylineVisible {
|
||||
[_quantityPairView setKeylineHidden:!(_hasDistance && _hasHeartRate)];
|
||||
}
|
||||
|
||||
- (void)setDistanceInMeters:(double)distanceInMeters {
|
||||
_distanceInMeters = distanceInMeters;
|
||||
double displayDistance = _distanceInMeters;
|
||||
NSString *distanceString = nil;
|
||||
NSLengthFormatterUnit unit;
|
||||
NSString *unitString = [_lengthFormatter unitStringFromMeters:displayDistance usedUnit:&unit];
|
||||
|
||||
switch (unit) {
|
||||
case NSLengthFormatterUnitCentimeter:
|
||||
case NSLengthFormatterUnitMillimeter:
|
||||
unit = NSLengthFormatterUnitMeter;
|
||||
// Force showing 0 meters if the distance is sufficiently short to be displayed in cm or mm
|
||||
unitString = [_lengthFormatter unitStringFromValue:0 unit:NSLengthFormatterUnitMeter];
|
||||
displayDistance = 0;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
// Use HealthKit to convert the unit, so we can use the number formatter directly.
|
||||
HKUnit *hkUnit = [HKUnit unitFromLengthFormatterUnit:unit];
|
||||
double conversionFactor = 1.0;
|
||||
if ([hkUnit isNull] && (unit == NSLengthFormatterUnitYard)) {
|
||||
hkUnit = [HKUnit footUnit];
|
||||
conversionFactor = 1.0 / 3.0;
|
||||
}
|
||||
HKQuantity *quantity = [HKQuantity quantityWithUnit:[HKUnit meterUnit] doubleValue:displayDistance];
|
||||
distanceString = [_lengthFormatter.numberFormatter stringFromNumber:@([quantity doubleValueForUnit:hkUnit]*conversionFactor)];
|
||||
|
||||
[self distanceView].title = [NSString localizedStringWithFormat:ORKLocalizedString(@"FITNESS_DISTANCE_TITLE_FORMAT", nil), unitString];
|
||||
[self distanceView].value = distanceString;
|
||||
}
|
||||
|
||||
- (void)setTimeLeft:(NSTimeInterval)timeLeft {
|
||||
_timeLeft = timeLeft;
|
||||
[self updateTimerLabel];
|
||||
}
|
||||
|
||||
- (void)updateTimerLabel {
|
||||
static NSDateComponentsFormatter *formatter = nil;
|
||||
static dispatch_once_t onceToken;
|
||||
dispatch_once(&onceToken, ^{
|
||||
formatter = [NSDateComponentsFormatter new];
|
||||
formatter.unitsStyle = NSDateComponentsFormatterUnitsStylePositional;
|
||||
formatter.zeroFormattingBehavior = NSDateComponentsFormatterZeroFormattingBehaviorPad;
|
||||
formatter.allowedUnits = NSCalendarUnitMinute | NSCalendarUnitSecond;
|
||||
});
|
||||
|
||||
NSString *labelString = [formatter stringFromTimeInterval:MAX(round(_timeLeft),0)];
|
||||
_timerLabel.text = labelString;
|
||||
_timerLabel.hidden = (labelString == nil);
|
||||
}
|
||||
|
||||
@end
|
||||
@@ -1,106 +0,0 @@
|
||||
/*
|
||||
Copyright (c) 2019, Novartis.
|
||||
Copyright (c) 2019, Apple Inc. All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification,
|
||||
are permitted provided that the following conditions are met:
|
||||
|
||||
1. Redistributions of source code must retain the above copyright notice, this
|
||||
list of conditions and the following disclaimer.
|
||||
|
||||
2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
this list of conditions and the following disclaimer in the documentation and/or
|
||||
other materials provided with the distribution.
|
||||
|
||||
3. Neither the name of the copyright holder(s) nor the names of any contributors
|
||||
may be used to endorse or promote products derived from this software without
|
||||
specific prior written permission. No license is granted to the trademarks of
|
||||
the copyright holders even if such marks are included in this software.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
|
||||
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
import ResearchKit.Private
|
||||
|
||||
public class ORKLandoltCResult: ORKResult {
|
||||
|
||||
public var outcome: Bool?
|
||||
public var letterAngle: Double?
|
||||
public var sliderAngle: Double?
|
||||
public var score: Int?
|
||||
|
||||
enum Keys: String {
|
||||
case outcome
|
||||
case letterAngle
|
||||
case sliderAngle
|
||||
case score
|
||||
}
|
||||
|
||||
public init(identifier: String, outcome: Bool, letterAngle: Double, sliderAngle: Double, score: Int) {
|
||||
super.init(identifier: identifier)
|
||||
|
||||
self.outcome = outcome
|
||||
self.letterAngle = letterAngle
|
||||
self.sliderAngle = sliderAngle
|
||||
self.score = score
|
||||
}
|
||||
|
||||
override public func encode(with aCoder: NSCoder) {
|
||||
super.encode(with: aCoder)
|
||||
|
||||
aCoder.encode(outcome, forKey: Keys.outcome.rawValue)
|
||||
aCoder.encode(letterAngle, forKey: Keys.letterAngle.rawValue)
|
||||
aCoder.encode(sliderAngle, forKey: Keys.sliderAngle.rawValue)
|
||||
aCoder.encode(score, forKey: Keys.score.rawValue)
|
||||
}
|
||||
|
||||
required init?(coder aDecoder: NSCoder) {
|
||||
super.init(coder: aDecoder)
|
||||
|
||||
outcome = aDecoder.decodeObject(forKey: Keys.outcome.rawValue) as? Bool ?? false
|
||||
letterAngle = aDecoder.decodeObject(forKey: Keys.letterAngle.rawValue) as? Double ?? 0.0
|
||||
sliderAngle = aDecoder.decodeObject(forKey: Keys.sliderAngle.rawValue) as? Double ?? 0.0
|
||||
score = aDecoder.decodeObject(forKey: Keys.score.rawValue) as? Int ?? 0
|
||||
}
|
||||
|
||||
override public func copy(with zone: NSZone? = nil) -> Any {
|
||||
let result = super.copy(with: zone) as! ORKLandoltCResult
|
||||
|
||||
result.outcome = outcome
|
||||
result.letterAngle = letterAngle
|
||||
result.sliderAngle = sliderAngle
|
||||
result.score = score
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
override public func isEqual(_ object: Any?) -> Bool {
|
||||
let isParentSame = super.isEqual(object)
|
||||
|
||||
if let castObject = object as? ORKLandoltCResult {
|
||||
|
||||
return (isParentSame &&
|
||||
ORKEqualObjects(outcome as Any, castObject.outcome as Any) &&
|
||||
ORKEqualObjects(letterAngle as Any, castObject.letterAngle as Any) &&
|
||||
ORKEqualObjects(sliderAngle as Any, castObject.sliderAngle as Any) &&
|
||||
ORKEqualObjects(score as Any, castObject.score as Any))
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
override public func description(withNumberOfPaddingSpaces numberOfPaddingSpaces: UInt) -> String {
|
||||
let descriptionString = " \(descriptionPrefix(withNumberOfPaddingSpaces: numberOfPaddingSpaces)); Outcome: \(String(describing: outcome)); LetterAngle: \(String(describing: letterAngle)); SliderAngle: \(String(describing: sliderAngle)); Score: \(String(describing: score))"
|
||||
return descriptionString
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,105 +0,0 @@
|
||||
/*
|
||||
Copyright (c) 2019, Novartis.
|
||||
Copyright (c) 2019, Apple Inc. All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification,
|
||||
are permitted provided that the following conditions are met:
|
||||
|
||||
1. Redistributions of source code must retain the above copyright notice, this
|
||||
list of conditions and the following disclaimer.
|
||||
|
||||
2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
this list of conditions and the following disclaimer in the documentation and/or
|
||||
other materials provided with the distribution.
|
||||
|
||||
3. Neither the name of the copyright holder(s) nor the names of any contributors
|
||||
may be used to endorse or promote products derived from this software without
|
||||
specific prior written permission. No license is granted to the trademarks of
|
||||
the copyright holders even if such marks are included in this software.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
|
||||
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
@objc
|
||||
public enum VisionStepLeftOrRightEye: Int {
|
||||
case left
|
||||
case right
|
||||
}
|
||||
|
||||
@objc
|
||||
public enum VisionStepType: Int {
|
||||
case visualAcuity
|
||||
case contrastSensitivity
|
||||
}
|
||||
|
||||
@objc
|
||||
public class ORKLandoltCStep: ORKActiveStep {
|
||||
|
||||
public var testType: VisionStepType?
|
||||
public var eyeToTest: VisionStepLeftOrRightEye?
|
||||
|
||||
enum Key: String {
|
||||
case testType
|
||||
case eyeToTest
|
||||
}
|
||||
|
||||
public override class func stepViewControllerClass() -> AnyClass {
|
||||
return ORKLandoltCStepViewController.self
|
||||
}
|
||||
|
||||
public class func supportsSecureCoding() -> Bool {
|
||||
return true
|
||||
}
|
||||
|
||||
@objc
|
||||
public init(identifier: String, testType: VisionStepType, eyeToTest: VisionStepLeftOrRightEye) {
|
||||
super.init(identifier: identifier)
|
||||
self.testType = testType
|
||||
self.eyeToTest = eyeToTest
|
||||
}
|
||||
|
||||
public override var allowsBackNavigation: Bool {
|
||||
return false
|
||||
}
|
||||
|
||||
public override func copy(with zone: NSZone? = nil) -> Any {
|
||||
let visionStep: ORKLandoltCStep = super.copy(with: zone) as! ORKLandoltCStep
|
||||
return visionStep
|
||||
}
|
||||
|
||||
public required init(coder aDecoder: NSCoder) {
|
||||
super.init(coder: aDecoder)
|
||||
|
||||
if let typeValue = aDecoder.decodeObject(forKey: "stepType") as? Int {
|
||||
testType = VisionStepType(rawValue: typeValue)
|
||||
}
|
||||
|
||||
if let eyeValue = aDecoder.decodeObject(forKey: "eyeToTest") as? Int {
|
||||
eyeToTest = VisionStepLeftOrRightEye(rawValue: eyeValue)
|
||||
}
|
||||
}
|
||||
|
||||
public override func encode(with aCoder: NSCoder) {
|
||||
super.encode(with: aCoder)
|
||||
aCoder.encode(testType, forKey: Key.testType.rawValue)
|
||||
aCoder.encode(eyeToTest, forKey: Key.eyeToTest.rawValue)
|
||||
}
|
||||
|
||||
public override func isEqual(_ object: Any?) -> Bool {
|
||||
if let object = object as? ORKLandoltCStep {
|
||||
return testType == object.testType && eyeToTest == object.eyeToTest
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,81 +0,0 @@
|
||||
/*
|
||||
Copyright (c) 2019, Novartis.
|
||||
Copyright (c) 2019, Apple Inc. All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification,
|
||||
are permitted provided that the following conditions are met:
|
||||
|
||||
1. Redistributions of source code must retain the above copyright notice, this
|
||||
list of conditions and the following disclaimer.
|
||||
|
||||
2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
this list of conditions and the following disclaimer in the documentation and/or
|
||||
other materials provided with the distribution.
|
||||
|
||||
3. Neither the name of the copyright holder(s) nor the names of any contributors
|
||||
may be used to endorse or promote products derived from this software without
|
||||
specific prior written permission. No license is granted to the trademarks of
|
||||
the copyright holders even if such marks are included in this software.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
|
||||
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
import ResearchKit.Private
|
||||
|
||||
internal class ORKLandoltCStepContentView: UIView {
|
||||
|
||||
var eyeActivitySlider: EyeActivitySlider?
|
||||
private var testType: VisionStepType?
|
||||
|
||||
internal init(testType: VisionStepType) {
|
||||
super.init(frame: CGRect())
|
||||
translatesAutoresizingMaskIntoConstraints = false
|
||||
|
||||
self.testType = testType
|
||||
setupSubviews()
|
||||
setupConstraints()
|
||||
}
|
||||
|
||||
internal required init?(coder aDecoder: NSCoder) {
|
||||
super.init(coder: aDecoder)
|
||||
}
|
||||
|
||||
internal func setupSubviews() {
|
||||
guard let typeValue = testType else {
|
||||
return
|
||||
}
|
||||
|
||||
eyeActivitySlider = EyeActivitySlider(testType: typeValue)
|
||||
addSubview(eyeActivitySlider!)
|
||||
}
|
||||
|
||||
internal func setupConstraints() {
|
||||
eyeActivitySlider?.translatesAutoresizingMaskIntoConstraints = false
|
||||
|
||||
NSLayoutConstraint.activate([
|
||||
NSLayoutConstraint(item: eyeActivitySlider!,
|
||||
attribute: .width,
|
||||
relatedBy: .equal,
|
||||
toItem: self,
|
||||
attribute: .width,
|
||||
multiplier: 1.0,
|
||||
constant: 0.0),
|
||||
NSLayoutConstraint(item: eyeActivitySlider!,
|
||||
attribute: .height,
|
||||
relatedBy: .equal,
|
||||
toItem: self,
|
||||
attribute: .width,
|
||||
multiplier: 1.0,
|
||||
constant: 0.0)
|
||||
])
|
||||
}
|
||||
}
|
||||
@@ -1,268 +0,0 @@
|
||||
/*
|
||||
Copyright (c) 2019, Novartis.
|
||||
Copyright (c) 2019, Apple Inc. All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification,
|
||||
are permitted provided that the following conditions are met:
|
||||
|
||||
1. Redistributions of source code must retain the above copyright notice, this
|
||||
list of conditions and the following disclaimer.
|
||||
|
||||
2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
this list of conditions and the following disclaimer in the documentation and/or
|
||||
other materials provided with the distribution.
|
||||
|
||||
3. Neither the name of the copyright holder(s) nor the names of any contributors
|
||||
may be used to endorse or promote products derived from this software without
|
||||
specific prior written permission. No license is granted to the trademarks of
|
||||
the copyright holders even if such marks are included in this software.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
|
||||
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
import ResearchKit.Private
|
||||
|
||||
public class ORKLandoltCStepViewController: ORKActiveStepViewController {
|
||||
|
||||
private var activityTimer = Timer()
|
||||
private var results = NSMutableArray()
|
||||
private var visionStepView: ORKLandoltCStepView
|
||||
private var eyeToTest: VisionStepLeftOrRightEye?
|
||||
private var testType: VisionStepType?
|
||||
|
||||
public override init(step: ORKStep?) {
|
||||
if let visionStep = step as? ORKLandoltCStep {
|
||||
eyeToTest = visionStep.eyeToTest
|
||||
testType = visionStep.testType
|
||||
}
|
||||
visionStepView = ORKLandoltCStepView(testType: testType)
|
||||
super.init(step: step)
|
||||
}
|
||||
|
||||
required init?(coder: NSCoder) {
|
||||
fatalError("init(coder:) has not been implemented")
|
||||
}
|
||||
|
||||
public override var result: ORKStepResult? {
|
||||
let stepResult = super.result
|
||||
stepResult?.results = results.copy() as? [ORKResult]
|
||||
|
||||
return stepResult!
|
||||
}
|
||||
|
||||
|
||||
public override func viewDidLoad() {
|
||||
super.viewDidLoad()
|
||||
view.backgroundColor = UIColor.white
|
||||
activeStepView?.customContentView = visionStepView
|
||||
activeStepView?.removeCustomContentPadding()
|
||||
activeStepView?.customContentFillsAvailableSpace = true
|
||||
|
||||
// TODO: Localize
|
||||
visionStepView.currentEyeLabel.text = eyeToTest == .left ? "Left Eye" : "Right Eye"
|
||||
visionStepView.continueButton.addTarget(self, action: #selector(continueButtonWasPressed), for: .touchUpInside)
|
||||
startTimer()
|
||||
}
|
||||
|
||||
override public func stepDidFinish() {
|
||||
super.stepDidFinish()
|
||||
goForward()
|
||||
}
|
||||
|
||||
private func startTimer() {
|
||||
activityTimer = Timer.scheduledTimer(timeInterval: 5.0, target: self, selector: #selector(hideCircle), userInfo: nil, repeats: false)
|
||||
}
|
||||
|
||||
@objc
|
||||
private func hideCircle() {
|
||||
activityTimer.invalidate()
|
||||
visionStepView.visionContentView?.eyeActivitySlider?.hideLetter()
|
||||
visionStepView.topInstructionLabel.isHidden = false
|
||||
}
|
||||
|
||||
@objc
|
||||
private func continueButtonWasPressed() {
|
||||
activityTimer.invalidate()
|
||||
visionStepView.topInstructionLabel.isHidden = true
|
||||
visionStepView.continueButton.isEnabled = false
|
||||
|
||||
if let resultData = visionStepView.visionContentView?.eyeActivitySlider?.fetchResultDataAndUpdateSlider() {
|
||||
let stepResult: ORKLandoltCResult = ORKLandoltCResult(identifier: step!.identifier,
|
||||
outcome: resultData.outcome,
|
||||
letterAngle: resultData.letterAngle,
|
||||
sliderAngle: resultData.sliderAngle,
|
||||
score: resultData.score)
|
||||
results.add(stepResult)
|
||||
|
||||
if resultData.incorrectAnswers == 2 || resultData.score == resultData.maxScore {
|
||||
stepDidFinish()
|
||||
} else {
|
||||
visionStepView.continueButton.isEnabled = true
|
||||
startTimer()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public class ORKLandoltCStepView: UIView {
|
||||
|
||||
var visionContentView: ORKLandoltCStepContentView?
|
||||
|
||||
let continueButtonCornerRadius: CGFloat = 12.0
|
||||
let eyeLabelTopPadding: CGFloat = 20.0
|
||||
let instructionLabelTopPadding: CGFloat = 15.0
|
||||
let visionContentTopPadding: CGFloat = 10.0
|
||||
|
||||
let continueButton = ORKRoundTappingButton()
|
||||
let currentEyeLabel = UILabel()
|
||||
let topInstructionLabel = UILabel()
|
||||
|
||||
init(testType: VisionStepType!) {
|
||||
super.init(frame: .zero)
|
||||
setupCurrentEyeLabel()
|
||||
setupTopInstructionLabel()
|
||||
setupVisionContentView(testType: testType)
|
||||
setupContinueButton()
|
||||
setupConstraints()
|
||||
}
|
||||
|
||||
required init?(coder: NSCoder) {
|
||||
fatalError("init(coder:) has not been implemented")
|
||||
}
|
||||
|
||||
func setupVisionContentView(testType: VisionStepType!) {
|
||||
if visionContentView == nil {
|
||||
visionContentView = ORKLandoltCStepContentView(testType: testType)
|
||||
}
|
||||
addSubview(visionContentView!)
|
||||
}
|
||||
|
||||
func setupCurrentEyeLabel() {
|
||||
currentEyeLabel.isHidden = true
|
||||
currentEyeLabel.textAlignment = .center
|
||||
currentEyeLabel.textColor = UIColor.black
|
||||
currentEyeLabel.numberOfLines = 0
|
||||
// TODO: set FontDescriptor
|
||||
currentEyeLabel.font = UIFont(name: "", size: 20.0)
|
||||
addSubview(currentEyeLabel)
|
||||
}
|
||||
|
||||
func setupTopInstructionLabel() {
|
||||
topInstructionLabel.textAlignment = .center
|
||||
topInstructionLabel.numberOfLines = 0
|
||||
topInstructionLabel.textColor = UIColor.black
|
||||
// TODO: Localize
|
||||
topInstructionLabel.text = "Move the dial to where you think the opening in the letter was."
|
||||
// TODO: set FontDescriptor
|
||||
topInstructionLabel.font = UIFont(name: "", size: 20.0)
|
||||
topInstructionLabel.isHidden = true
|
||||
addSubview(topInstructionLabel)
|
||||
}
|
||||
|
||||
func setupContinueButton() {
|
||||
// TODO: Localize
|
||||
continueButton.diameter = 60.0
|
||||
continueButton.setTitle("Next", for: UIControl.State.normal)
|
||||
continueButton.backgroundColor = tintColor
|
||||
continueButton.layer.cornerRadius = continueButtonCornerRadius
|
||||
addSubview(continueButton)
|
||||
}
|
||||
|
||||
private func setupConstraints() {
|
||||
currentEyeLabel.translatesAutoresizingMaskIntoConstraints = false
|
||||
topInstructionLabel.translatesAutoresizingMaskIntoConstraints = false
|
||||
visionContentView?.translatesAutoresizingMaskIntoConstraints = false
|
||||
continueButton.translatesAutoresizingMaskIntoConstraints = false
|
||||
|
||||
let constraints = [
|
||||
NSLayoutConstraint(item: currentEyeLabel,
|
||||
attribute: .top,
|
||||
relatedBy: .equal,
|
||||
toItem: self,
|
||||
attribute: .top,
|
||||
multiplier: 1.0,
|
||||
constant: eyeLabelTopPadding),
|
||||
NSLayoutConstraint(item: currentEyeLabel,
|
||||
attribute: .centerX,
|
||||
relatedBy: .equal,
|
||||
toItem: self,
|
||||
attribute: .centerX,
|
||||
multiplier: 1.0,
|
||||
constant: 0.0),
|
||||
NSLayoutConstraint(item: topInstructionLabel,
|
||||
attribute: .top,
|
||||
relatedBy: .equal,
|
||||
toItem: currentEyeLabel,
|
||||
attribute: .bottom,
|
||||
multiplier: 1.0,
|
||||
constant: instructionLabelTopPadding),
|
||||
NSLayoutConstraint(item: topInstructionLabel,
|
||||
attribute: .centerX,
|
||||
relatedBy: .equal,
|
||||
toItem: self,
|
||||
attribute: .centerX,
|
||||
multiplier: 1.0,
|
||||
constant: 0.0),
|
||||
NSLayoutConstraint(item: topInstructionLabel,
|
||||
attribute: .width,
|
||||
relatedBy: .equal,
|
||||
toItem: self,
|
||||
attribute: .width,
|
||||
multiplier: 0.8,
|
||||
constant: 0.0),
|
||||
NSLayoutConstraint(item: visionContentView!,
|
||||
attribute: .top,
|
||||
relatedBy: .equal,
|
||||
toItem: topInstructionLabel,
|
||||
attribute: .bottom,
|
||||
multiplier: 1.0,
|
||||
constant: visionContentTopPadding),
|
||||
NSLayoutConstraint(item: visionContentView!,
|
||||
attribute: .centerX,
|
||||
relatedBy: .equal,
|
||||
toItem: self,
|
||||
attribute: .centerX,
|
||||
multiplier: 1.0,
|
||||
constant: 0.0),
|
||||
NSLayoutConstraint(item: visionContentView!,
|
||||
attribute: .width,
|
||||
relatedBy: .equal,
|
||||
toItem: self,
|
||||
attribute: .width,
|
||||
multiplier: 0.8,
|
||||
constant: 0.0),
|
||||
NSLayoutConstraint(item: visionContentView!,
|
||||
attribute: .height,
|
||||
relatedBy: .equal,
|
||||
toItem: self,
|
||||
attribute: .height,
|
||||
multiplier: 0.8,
|
||||
constant: 0.0),
|
||||
NSLayoutConstraint(item: continueButton,
|
||||
attribute: .centerX,
|
||||
relatedBy: .equal,
|
||||
toItem: self,
|
||||
attribute: .centerX,
|
||||
multiplier: 1.0,
|
||||
constant: 0.0),
|
||||
NSLayoutConstraint(item: continueButton,
|
||||
attribute: .bottom,
|
||||
relatedBy: .equal,
|
||||
toItem: self,
|
||||
attribute: .bottom,
|
||||
multiplier: 1.0,
|
||||
constant: -20.0)
|
||||
]
|
||||
|
||||
NSLayoutConstraint.activate(constraints)
|
||||
}
|
||||
}
|
||||
@@ -1,256 +0,0 @@
|
||||
/*
|
||||
Copyright (c) 2018, Apple Inc. All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification,
|
||||
are permitted provided that the following conditions are met:
|
||||
|
||||
1. Redistributions of source code must retain the above copyright notice, this
|
||||
list of conditions and the following disclaimer.
|
||||
|
||||
2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
this list of conditions and the following disclaimer in the documentation and/or
|
||||
other materials provided with the distribution.
|
||||
|
||||
3. Neither the name of the copyright holder(s) nor the names of any contributors
|
||||
may be used to endorse or promote products derived from this software without
|
||||
specific prior written permission. No license is granted to the trademarks of
|
||||
the copyright holders even if such marks are included in this software.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
|
||||
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
|
||||
#import "ORKSpeechRecognitionContentView.h"
|
||||
#import "ORKAudioGraphView.h"
|
||||
|
||||
#import "ORKHeadlineLabel.h"
|
||||
#import "ORKSubheadlineLabel.h"
|
||||
#import "ORKLabel.h"
|
||||
|
||||
#import "ORKAccessibility.h"
|
||||
#import "ORKHelpers_Internal.h"
|
||||
#import "ORKSkin.h"
|
||||
#import "ORKBorderedButton.h"
|
||||
|
||||
@interface ORKSpeechRecognitionContentView () <UITextFieldDelegate>
|
||||
|
||||
@property (nonatomic, strong) ORKAudioGraphView *graphView;
|
||||
@property (nonatomic, strong) ORKSubheadlineLabel *transcriptLabel;
|
||||
|
||||
@end
|
||||
|
||||
|
||||
@implementation ORKSpeechRecognitionContentView {
|
||||
NSMutableArray *_samples;
|
||||
UIColor *_keyColor;
|
||||
UIImageView *_imageView;
|
||||
UILabel *_textLabel;
|
||||
}
|
||||
|
||||
- (instancetype)initWithFrame:(CGRect)frame {
|
||||
self = [super initWithFrame:frame];
|
||||
if (self) {
|
||||
self.layoutMargins = ORKStandardFullScreenLayoutMarginsForView(self);
|
||||
self.translatesAutoresizingMaskIntoConstraints = NO;
|
||||
|
||||
[self setupTranscriptLabel];
|
||||
[self setupGraphView];
|
||||
[self setupRecordButton];
|
||||
[self setupImageView];
|
||||
[self setupTextLabel];
|
||||
[self updateGraphSamples];
|
||||
[self applyKeyColor];
|
||||
[self setUpConstraints];
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void)setupImageView {
|
||||
_imageView = [UIImageView new];
|
||||
_imageView.contentMode = UIViewContentModeScaleAspectFit;
|
||||
_imageView.translatesAutoresizingMaskIntoConstraints = NO;
|
||||
[self addSubview:_imageView];
|
||||
}
|
||||
|
||||
- (void)setupTextLabel {
|
||||
_textLabel = [UILabel new];
|
||||
_textLabel.font = [[UIFontMetrics metricsForTextStyle:UIFontTextStyleTitle2] scaledFontForFont:[UIFont systemFontOfSize:25.0 weight:UIFontWeightMedium]];
|
||||
_textLabel.textColor = [self tintColor];
|
||||
_textLabel.textAlignment = NSTextAlignmentCenter;
|
||||
_textLabel.translatesAutoresizingMaskIntoConstraints = NO;
|
||||
_textLabel.lineBreakMode = NSLineBreakByWordWrapping;
|
||||
_textLabel.numberOfLines = 0;
|
||||
_textLabel.adjustsFontForContentSizeCategory = YES;
|
||||
[self addSubview:_textLabel];
|
||||
}
|
||||
|
||||
- (void)setupGraphView {
|
||||
self.graphView = [ORKAudioGraphView new];
|
||||
_graphView.translatesAutoresizingMaskIntoConstraints = NO;
|
||||
_graphView.isAccessibilityElement = YES;
|
||||
_graphView.accessibilityLabel = ORKLocalizedString(@"AX_SPEECH_RECOGNITION_WAVEFORM", nil);
|
||||
_graphView.accessibilityTraits = UIAccessibilityTraitImage;
|
||||
|
||||
[self addSubview:_graphView];
|
||||
}
|
||||
|
||||
- (void)setupTranscriptLabel {
|
||||
_transcriptLabel = [ORKSubheadlineLabel new];
|
||||
_transcriptLabel.textAlignment = NSTextAlignmentCenter;
|
||||
_transcriptLabel.translatesAutoresizingMaskIntoConstraints = NO;
|
||||
_transcriptLabel.text = ORKLocalizedString(@"SPEECH_RECOGNITION_TRANSCRIPTION_LABEL", nil);
|
||||
_transcriptLabel.lineBreakMode = NSLineBreakByWordWrapping;
|
||||
_transcriptLabel.numberOfLines = 0;
|
||||
|
||||
[self addSubview:_transcriptLabel];
|
||||
}
|
||||
|
||||
- (void)setupRecordButton {
|
||||
self.recordButton = [[ORKBorderedButton alloc] init];
|
||||
self.recordButton.translatesAutoresizingMaskIntoConstraints = NO;
|
||||
[self.recordButton setTitle:ORKLocalizedString(@"SPEECH_RECOGNITION_START_RECORD_LABEL", nil)
|
||||
forState:UIControlStateNormal];
|
||||
self.recordButton.enabled = YES;
|
||||
self.recordButton.accessibilityTraits = UIAccessibilityTraitButton | UIAccessibilityTraitStartsMediaSession;
|
||||
self.recordButton.accessibilityHint = ORKLocalizedString(@"AX_SPEECH_RECOGNITION_START_RECORDING_HINT", nil);
|
||||
[self addSubview:_recordButton];
|
||||
}
|
||||
|
||||
- (void)setSpeechRecognitionText:(NSString *)speechRecognitionText {
|
||||
_speechRecognitionText = speechRecognitionText;
|
||||
[_textLabel setText:speechRecognitionText];
|
||||
}
|
||||
|
||||
- (void)setSpeechRecognitionImage:(UIImage *)speechRecognitionImage {
|
||||
_speechRecognitionImage = speechRecognitionImage;
|
||||
[_imageView setImage:speechRecognitionImage];
|
||||
}
|
||||
|
||||
- (void)tintColorDidChange {
|
||||
[self applyKeyColor];
|
||||
}
|
||||
|
||||
- (void)setFinished:(BOOL)finished {
|
||||
_finished = finished;
|
||||
}
|
||||
|
||||
- (void)applyKeyColor {
|
||||
UIColor *keyColor = [self keyColor];
|
||||
_graphView.keyColor = keyColor;
|
||||
}
|
||||
|
||||
- (UIColor *)keyColor {
|
||||
return _keyColor ? : [self tintColor];
|
||||
}
|
||||
|
||||
- (void)setKeyColor:(UIColor *)keyColor {
|
||||
_keyColor = keyColor;
|
||||
[self applyKeyColor];
|
||||
}
|
||||
|
||||
- (void)setUpConstraints {
|
||||
NSMutableArray *constraints = [NSMutableArray array];
|
||||
|
||||
NSDictionary *views = NSDictionaryOfVariableBindings(_imageView, _textLabel, _transcriptLabel, _graphView, _recordButton);
|
||||
const CGFloat graphHeight = 150;
|
||||
|
||||
// In case the text on the button is large, ensure that the button can grow larger than the default height if needed
|
||||
[constraints addObjectsFromArray:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|-[_imageView]-[_textLabel]-(5)-[_graphView(graphHeight)]-[_transcriptLabel]-buttonGap-[_recordButton(50@250)]-topBottomMargin-|"
|
||||
options:(NSLayoutFormatOptions)0
|
||||
metrics:@{
|
||||
@"graphHeight": @(graphHeight),
|
||||
@"topBottomMargin" : @(5),
|
||||
@"buttonGap" : @(20)
|
||||
}
|
||||
views:views]];
|
||||
|
||||
|
||||
const CGFloat sideMargin = self.layoutMargins.left + (2 * ORKStandardLeftMarginForTableViewCell(self));
|
||||
const CGFloat twiceSideMargin = sideMargin * 2;
|
||||
|
||||
[constraints addObjectsFromArray:
|
||||
[NSLayoutConstraint constraintsWithVisualFormat:@"H:|-[_imageView]-|"
|
||||
options:0
|
||||
metrics: nil
|
||||
views:views]];
|
||||
|
||||
[constraints addObjectsFromArray:
|
||||
[NSLayoutConstraint constraintsWithVisualFormat:@"H:|-[_textLabel]-|"
|
||||
options:0
|
||||
metrics: nil
|
||||
views:views]];
|
||||
[constraints addObjectsFromArray:
|
||||
[NSLayoutConstraint constraintsWithVisualFormat:@"H:|-sideMargin-[_graphView]-sideMargin-|"
|
||||
options:0
|
||||
metrics: @{@"sideMargin": @(sideMargin)}
|
||||
views:views]];
|
||||
|
||||
[constraints addObjectsFromArray:
|
||||
[NSLayoutConstraint constraintsWithVisualFormat:@"H:|-[_transcriptLabel]-|"
|
||||
options:0
|
||||
metrics: @{@"sideMargin": @(sideMargin)}
|
||||
views:views]];
|
||||
|
||||
// In case the text on the button is large, ensure that the button can grow larger than the default width if needed
|
||||
[constraints addObjectsFromArray:
|
||||
[NSLayoutConstraint constraintsWithVisualFormat:@"H:|-twiceSideMargin@250-[_recordButton(200@250)]-twiceSideMargin@250-|"
|
||||
options:0
|
||||
metrics: @{@"twiceSideMargin": @(twiceSideMargin)}
|
||||
views:views]];
|
||||
[constraints addObject:[_recordButton.centerXAnchor constraintEqualToAnchor:self.centerXAnchor]];
|
||||
[constraints addObject:[_recordButton.leadingAnchor constraintGreaterThanOrEqualToAnchor:self.layoutMarginsGuide.leadingAnchor]];
|
||||
[constraints addObject:[_recordButton.trailingAnchor constraintLessThanOrEqualToAnchor:self.layoutMarginsGuide.trailingAnchor]];
|
||||
|
||||
[NSLayoutConstraint activateConstraints:constraints];
|
||||
}
|
||||
|
||||
- (void)setShouldHideTranscript:(BOOL)shouldHideTranscript {
|
||||
_shouldHideTranscript = shouldHideTranscript;
|
||||
if (shouldHideTranscript) {
|
||||
_transcriptLabel.text = nil;
|
||||
}
|
||||
}
|
||||
|
||||
- (void)updateGraphSamples {
|
||||
_graphView.values = _samples;
|
||||
}
|
||||
|
||||
- (void)addSample:(NSNumber *)sample {
|
||||
NSAssert(sample != nil, @"Sample should be non-nil");
|
||||
if (!_samples) {
|
||||
_samples = [NSMutableArray array];
|
||||
}
|
||||
[_samples addObject:sample];
|
||||
// Try to keep around 250 samples
|
||||
if (_samples.count > 500) {
|
||||
_samples = [[_samples subarrayWithRange:(NSRange){250, _samples.count - 250}] mutableCopy];
|
||||
}
|
||||
[self updateGraphSamples];
|
||||
}
|
||||
|
||||
- (void)updateRecognitionText:(NSString *)recognitionText {
|
||||
if (!_shouldHideTranscript) {
|
||||
_transcriptLabel.text = recognitionText;
|
||||
}
|
||||
}
|
||||
|
||||
- (void)addRecognitionError:(NSString *)errorMsg {
|
||||
_transcriptLabel.textColor = [UIColor ork_redColor];
|
||||
_transcriptLabel.text = errorMsg;
|
||||
}
|
||||
|
||||
- (void)removeAllSamples {
|
||||
_samples = nil;
|
||||
[self updateGraphSamples];
|
||||
}
|
||||
|
||||
@end
|
||||
@@ -1,283 +0,0 @@
|
||||
/*
|
||||
Copyright (c) 2018, Apple Inc. All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification,
|
||||
are permitted provided that the following conditions are met:
|
||||
|
||||
1. Redistributions of source code must retain the above copyright notice, this
|
||||
list of conditions and the following disclaimer.
|
||||
|
||||
2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
this list of conditions and the following disclaimer in the documentation and/or
|
||||
other materials provided with the distribution.
|
||||
|
||||
3. Neither the name of the copyright holder(s) nor the names of any contributors
|
||||
may be used to endorse or promote products derived from this software without
|
||||
specific prior written permission. No license is granted to the trademarks of
|
||||
the copyright holders even if such marks are included in this software.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
|
||||
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
|
||||
@import AVFoundation;
|
||||
@import Accelerate;
|
||||
|
||||
#import "ORKSpeechRecognitionStepViewController.h"
|
||||
|
||||
#import "ORKQuestionStep.h"
|
||||
#import "ORKAnswerFormat.h"
|
||||
#import "ORKTask.h"
|
||||
#import "ORKActiveStepView.h"
|
||||
#import "ORKActiveStepViewController_Internal.h"
|
||||
|
||||
#import "ORKSpeechRecognitionContentView.h"
|
||||
#import "ORKStreamingAudioRecorder.h"
|
||||
#import "ORKSpeechRecognizer.h"
|
||||
#import "ORKSpeechRecognitionStep.h"
|
||||
#import "ORKSpeechRecognitionError.h"
|
||||
|
||||
#import "ORKHelpers_Internal.h"
|
||||
#import "ORKBorderedButton.h"
|
||||
#import "ORKSpeechRecognitionResult.h"
|
||||
#import "ORKResult_Private.h"
|
||||
#import "ORKCollectionResult_Private.h"
|
||||
#import "ORKStepViewController_Internal.h"
|
||||
#import "ORKTaskViewController.h"
|
||||
|
||||
#import "ORKOrderedTask.h"
|
||||
|
||||
|
||||
@interface ORKSpeechRecognitionStepViewController () <ORKStreamingAudioResultDelegate, ORKSpeechRecognitionDelegate, UITextFieldDelegate>
|
||||
|
||||
@end
|
||||
|
||||
|
||||
@implementation ORKSpeechRecognitionStepViewController {
|
||||
ORKSpeechRecognitionContentView *_speechRecognitionContentView;
|
||||
ORKStreamingAudioRecorder *_audioRecorder;
|
||||
ORKSpeechRecognizer *_speechRecognizer;
|
||||
|
||||
dispatch_queue_t _speechRecognitionQueue;
|
||||
ORKSpeechRecognitionResult *_localResult;
|
||||
BOOL _errorState;
|
||||
float _peakPower;
|
||||
}
|
||||
|
||||
- (instancetype)initWithStep:(ORKStep *)step {
|
||||
self = [super initWithStep:step];
|
||||
if (self) {
|
||||
self.suspendIfInactive = YES;
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void)viewDidLoad {
|
||||
[super viewDidLoad];
|
||||
|
||||
ORKSpeechRecognitionStep *step = (ORKSpeechRecognitionStep *) self.step;
|
||||
_speechRecognitionContentView = [ORKSpeechRecognitionContentView new];
|
||||
_speechRecognitionContentView.shouldHideTranscript = step.shouldHideTranscript;
|
||||
self.activeStepView.activeCustomView = _speechRecognitionContentView;
|
||||
_speechRecognitionContentView.speechRecognitionImage = step.speechRecognitionImage;
|
||||
_speechRecognitionContentView.speechRecognitionText = step.speechRecognitionText;
|
||||
|
||||
[_speechRecognitionContentView.recordButton addTarget:self
|
||||
action:@selector(recordButtonPressed:)
|
||||
forControlEvents:UIControlEventTouchDown];
|
||||
|
||||
_errorState = NO;
|
||||
|
||||
[ORKSpeechRecognizer requestAuthorization];
|
||||
|
||||
_localResult = [[ORKSpeechRecognitionResult alloc] initWithIdentifier:self.step.identifier];
|
||||
_speechRecognitionQueue = dispatch_queue_create("SpeechRecognitionQueue", DISPATCH_QUEUE_SERIAL);
|
||||
}
|
||||
|
||||
- (void)initializeRecognizer {
|
||||
_speechRecognizer = [[ORKSpeechRecognizer alloc] init];
|
||||
|
||||
if (_speechRecognizer) {
|
||||
[_speechRecognizer startRecognitionWithLocale:[NSLocale localeWithLocaleIdentifier:((ORKSpeechRecognitionStep *)self.step).speechRecognizerLocale] reportPartialResults:YES responseDelegate:self errorHandler:^(NSError *error) {
|
||||
if (error) {
|
||||
[self stopWithError:error];
|
||||
}
|
||||
}];
|
||||
}
|
||||
}
|
||||
|
||||
- (void)recordButtonPressed:(id)sender {
|
||||
if (sender == _speechRecognitionContentView.recordButton) {
|
||||
if ([_speechRecognitionContentView.recordButton.titleLabel.text
|
||||
isEqualToString:ORKLocalizedString(@"SPEECH_RECOGNITION_STOP_RECORD_LABEL", nil)]) {
|
||||
[self stopWithError:nil];
|
||||
} else {
|
||||
|
||||
[self initializeRecognizer];
|
||||
|
||||
[self start];
|
||||
[_speechRecognitionContentView.recordButton setTitle:ORKLocalizedString(@"SPEECH_RECOGNITION_STOP_RECORD_LABEL", nil)
|
||||
forState:UIControlStateNormal];
|
||||
_speechRecognitionContentView.recordButton.enabled = YES;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
- (void)recordersDidChange {
|
||||
ORKStreamingAudioRecorder *audioRecorder = nil;
|
||||
for (ORKRecorder *recorder in self.recorders) {
|
||||
if ([recorder isKindOfClass:[ORKStreamingAudioRecorder class]]) {
|
||||
audioRecorder = (ORKStreamingAudioRecorder *)recorder;
|
||||
break;
|
||||
}
|
||||
}
|
||||
_audioRecorder = audioRecorder;
|
||||
}
|
||||
|
||||
- (ORKStepResult *)result {
|
||||
ORKStepResult *sResult = [super result];
|
||||
if (_speechRecognitionQueue) {
|
||||
dispatch_sync(_speechRecognitionQueue, ^{
|
||||
if (_localResult != nil) {
|
||||
NSMutableArray *results = [NSMutableArray arrayWithArray:sResult.results];
|
||||
[results addObject:_localResult];
|
||||
sResult.results = [results copy];
|
||||
}
|
||||
});
|
||||
}
|
||||
return sResult;
|
||||
}
|
||||
|
||||
- (void)stopWithError:(NSError *)error {
|
||||
if (_speechRecognizer) {
|
||||
[_speechRecognizer endAudio];
|
||||
}
|
||||
|
||||
if (error) {
|
||||
ORK_Log_Error("Speech recognition failed with error message: \"%@\"", error.localizedDescription);
|
||||
[_speechRecognitionContentView addRecognitionError:error.localizedDescription];
|
||||
_speechRecognitionContentView.recordButton.enabled = NO;
|
||||
_errorState = YES;
|
||||
}
|
||||
[self stopRecorders];
|
||||
}
|
||||
|
||||
- (void)resume {
|
||||
// Background processing is not supported
|
||||
}
|
||||
|
||||
- (void)goForward {
|
||||
if ([self hasNextStep]) {
|
||||
ORKQuestionStep *nextStep = [self nextStep];
|
||||
if (nextStep) {
|
||||
[((ORKTextAnswerFormat *)nextStep.answerFormat) setDefaultTextAnswer: [_localResult.transcription formattedString]];
|
||||
}
|
||||
}
|
||||
[super goForward];
|
||||
}
|
||||
|
||||
- (nullable ORKQuestionStep *)nextStep {
|
||||
ORKOrderedTask *task = (ORKOrderedTask *)[self.taskViewController task];
|
||||
NSUInteger nextStepIndex = [task indexOfStep:[self step]] + 1;
|
||||
ORKStep *nextStep = [task steps][nextStepIndex];
|
||||
|
||||
if ([nextStep isKindOfClass:[ORKQuestionStep class]]) {
|
||||
return (ORKQuestionStep *)nextStep;
|
||||
} else {
|
||||
return nil;
|
||||
}
|
||||
}
|
||||
|
||||
- (void)stepDidFinish {
|
||||
_speechRecognitionContentView.finished = YES;
|
||||
}
|
||||
|
||||
- (void)recorder:(ORKRecorder *)recorder didFailWithError:(NSError *)error {
|
||||
[super recorder:recorder didFailWithError:error];
|
||||
[self stopWithError:error];
|
||||
}
|
||||
|
||||
// Methods running on a different thread
|
||||
|
||||
#pragma mark - ORKStreamingAudioResultDelegate
|
||||
- (void)audioAvailable:(AVAudioPCMBuffer *)buffer {
|
||||
if (_errorState) {
|
||||
return;
|
||||
}
|
||||
[_speechRecognizer addAudio:buffer];
|
||||
|
||||
// audio metering display
|
||||
float * const *channelData = [buffer floatChannelData];
|
||||
if (channelData[0]) {
|
||||
float avgValue = 0;
|
||||
unsigned long nFrames = [buffer frameLength];
|
||||
vDSP_maxmgv(channelData[0], 1 , &avgValue, nFrames);
|
||||
float lvlLowPassTrig = 0.3;
|
||||
_peakPower = lvlLowPassTrig * ((avgValue == 0)? -100 : 20* log10(avgValue)) + (1 - lvlLowPassTrig) * _peakPower;
|
||||
float clampedValue = MAX(_peakPower / 60.0, -1) + 1;
|
||||
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
[_speechRecognitionContentView addSample:@(clampedValue)];
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
#pragma mark - ORKSpeechRecognitionDelegate
|
||||
|
||||
- (void)didFinishRecognitionWithError:(NSError *)error {
|
||||
if (_errorState) {
|
||||
return;
|
||||
}
|
||||
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
if (error) {
|
||||
ORK_Log_Error("Speech framework failed with error code: %ld, and error description: %@", (long)error.code, error.localizedDescription);
|
||||
NSError *recognitionError = [NSError errorWithDomain:ORKErrorDomain
|
||||
code:ORKSpeechRecognitionErrorRecognitionFailed
|
||||
userInfo:@{NSLocalizedDescriptionKey:ORKLocalizedString(@"SPEECH_RECOGNITION_FAILED", nil)}];
|
||||
[self stopWithError:recognitionError];
|
||||
} else {
|
||||
[self stopWithError:nil];
|
||||
[self finish];
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
- (void)didHypothesizeTranscription:(SFTranscription *)transcription {
|
||||
if (_errorState) {
|
||||
return;
|
||||
}
|
||||
dispatch_sync(_speechRecognitionQueue, ^{
|
||||
_localResult.transcription = transcription;
|
||||
});
|
||||
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
[_speechRecognitionContentView updateRecognitionText:[transcription formattedString]];
|
||||
});
|
||||
}
|
||||
|
||||
- (void)availabilityDidChange:(BOOL)available {
|
||||
if (!available) {
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
[self stopWithError:[NSError errorWithDomain:ORKErrorDomain
|
||||
code:ORKSpeechRecognitionErrorLanguageNotAvailable
|
||||
userInfo:@{NSLocalizedDescriptionKey:ORKLocalizedString(@"Speech recognizer not available", nil)}]];
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
- (void)recordersWillStart {
|
||||
ORK_Log_Debug("Recorder is starting");
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
@@ -1,168 +0,0 @@
|
||||
/*
|
||||
Copyright (c) 2019, Apple Inc. All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification,
|
||||
are permitted provided that the following conditions are met:
|
||||
|
||||
1. Redistributions of source code must retain the above copyright notice, this
|
||||
list of conditions and the following disclaimer.
|
||||
|
||||
2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
this list of conditions and the following disclaimer in the documentation and/or
|
||||
other materials provided with the distribution.
|
||||
|
||||
3. Neither the name of the copyright holder(s) nor the names of any contributors
|
||||
may be used to endorse or promote products derived from this software without
|
||||
specific prior written permission. No license is granted to the trademarks of
|
||||
the copyright holders even if such marks are included in this software.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
|
||||
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
|
||||
internal class ORKSwiftStroopContentView: ORKActiveStepCustomView {
|
||||
|
||||
public var colorLabelText: String?
|
||||
public var colorLabelColor: UIColor?
|
||||
|
||||
public let redButton: ORKBorderedButton = {
|
||||
let button = ORKBorderedButton()
|
||||
button.translatesAutoresizingMaskIntoConstraints = false
|
||||
button.setTitle(ORKSwiftLocalizedString("STROOP_COLOR_RED_INITIAL", ""), for: .normal)
|
||||
return button
|
||||
}()
|
||||
|
||||
public let greenButton: ORKBorderedButton = {
|
||||
let button = ORKBorderedButton()
|
||||
button.translatesAutoresizingMaskIntoConstraints = false
|
||||
button.setTitle(ORKSwiftLocalizedString("STROOP_COLOR_GREEN_INITIAL", ""), for: .normal)
|
||||
return button
|
||||
}()
|
||||
|
||||
public let blueButton: ORKBorderedButton = {
|
||||
let button = ORKBorderedButton()
|
||||
button.translatesAutoresizingMaskIntoConstraints = false
|
||||
button.setTitle(ORKSwiftLocalizedString("STROOP_COLOR_BLUE_INITIAL", ""), for: .normal)
|
||||
return button
|
||||
}()
|
||||
|
||||
public let yellowButton: ORKBorderedButton = {
|
||||
let button = ORKBorderedButton()
|
||||
button.translatesAutoresizingMaskIntoConstraints = false
|
||||
button.setTitle(ORKSwiftLocalizedString("STROOP_COLOR_YELLOW_INITIAL", ""), for: .normal)
|
||||
return button
|
||||
}()
|
||||
|
||||
private let colorLabel: UILabel = {
|
||||
let label = UILabel()
|
||||
let colorLabelFontSize: CGFloat = 60.0
|
||||
label.numberOfLines = 1
|
||||
label.text = " "
|
||||
label.textAlignment = .center
|
||||
label.translatesAutoresizingMaskIntoConstraints = false
|
||||
label.font = UIFont.systemFont(ofSize: colorLabelFontSize)
|
||||
label.adjustsFontSizeToFitWidth = true
|
||||
return label
|
||||
}()
|
||||
|
||||
private let buttonStackView: UIStackView
|
||||
|
||||
private let minimumButtonHeight: CGFloat = 60.0
|
||||
private let buttonStackViewSpacing: CGFloat = 20.0
|
||||
|
||||
private override init(frame: CGRect) {
|
||||
buttonStackView = UIStackView(arrangedSubviews: [redButton, greenButton, blueButton, yellowButton])
|
||||
super.init(frame: frame)
|
||||
setup()
|
||||
}
|
||||
|
||||
internal required init?(coder aDecoder: NSCoder) {
|
||||
buttonStackView = UIStackView(arrangedSubviews: [redButton, greenButton, blueButton, yellowButton])
|
||||
super.init(coder: aDecoder)
|
||||
setup()
|
||||
}
|
||||
|
||||
internal func setup() {
|
||||
self.translatesAutoresizingMaskIntoConstraints = false
|
||||
buttonStackView.translatesAutoresizingMaskIntoConstraints = false
|
||||
buttonStackView.spacing = buttonStackViewSpacing
|
||||
buttonStackView.axis = .horizontal
|
||||
self.addSubview(colorLabel)
|
||||
self.addSubview(buttonStackView)
|
||||
setUpConstraints()
|
||||
}
|
||||
|
||||
internal func setColorLabelText(colorLabelText text: String) {
|
||||
colorLabelText = text
|
||||
colorLabel.text = text
|
||||
setNeedsDisplay()
|
||||
}
|
||||
|
||||
internal func setColorLabelColor(colorLabelColor color: UIColor) {
|
||||
colorLabelColor = color
|
||||
colorLabel.textColor = color
|
||||
setNeedsDisplay()
|
||||
}
|
||||
|
||||
internal func getColorLabelText() -> String {
|
||||
return colorLabel.text!
|
||||
}
|
||||
|
||||
internal func getColorLabelColor() -> UIColor {
|
||||
return colorLabel.textColor
|
||||
}
|
||||
|
||||
internal func setUpConstraints() {
|
||||
|
||||
var constraints = [NSLayoutConstraint]()
|
||||
var views = [String: Any]()
|
||||
views["colorLabel"] = colorLabel
|
||||
views["buttonStackView"] = buttonStackView
|
||||
|
||||
constraints += NSLayoutConstraint.constraints(withVisualFormat: "V:|-(==30)-[colorLabel]-(>=10)-[buttonStackView]-(==30)-|",
|
||||
options: .alignAllCenterX,
|
||||
metrics: nil,
|
||||
views: views)
|
||||
|
||||
constraints += [
|
||||
NSLayoutConstraint(item: buttonStackView as Any,
|
||||
attribute: .height,
|
||||
relatedBy: .equal,
|
||||
toItem: nil,
|
||||
attribute: .notAnAttribute,
|
||||
multiplier: 1.0,
|
||||
constant: minimumButtonHeight),
|
||||
NSLayoutConstraint(item: buttonStackView as Any,
|
||||
attribute: .centerX,
|
||||
relatedBy: .equal,
|
||||
toItem: self,
|
||||
attribute: .centerX,
|
||||
multiplier: 1.0,
|
||||
constant: 0.0)
|
||||
]
|
||||
|
||||
for button in [redButton, greenButton, blueButton, yellowButton] {
|
||||
constraints += [
|
||||
NSLayoutConstraint(item: button,
|
||||
attribute: .width,
|
||||
relatedBy: .equal,
|
||||
toItem: button,
|
||||
attribute: .height,
|
||||
multiplier: 1.0,
|
||||
constant: 0.0)
|
||||
]
|
||||
}
|
||||
|
||||
self.addConstraints(constraints)
|
||||
NSLayoutConstraint.activate(constraints)
|
||||
}
|
||||
}
|
||||
@@ -1,106 +0,0 @@
|
||||
/*
|
||||
Copyright (c) 2019, Apple Inc. All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification,
|
||||
are permitted provided that the following conditions are met:
|
||||
|
||||
1. Redistributions of source code must retain the above copyright notice, this
|
||||
list of conditions and the following disclaimer.
|
||||
|
||||
2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
this list of conditions and the following disclaimer in the documentation and/or
|
||||
other materials provided with the distribution.
|
||||
|
||||
3. Neither the name of the copyright holder(s) nor the names of any contributors
|
||||
may be used to endorse or promote products derived from this software without
|
||||
specific prior written permission. No license is granted to the trademarks of
|
||||
the copyright holders even if such marks are included in this software.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
|
||||
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
|
||||
import ResearchKit.Private
|
||||
|
||||
public class ORKSwiftStroopResult: ORKResult {
|
||||
|
||||
public var startTime: TimeInterval?
|
||||
public var endTime: TimeInterval?
|
||||
public var color: String?
|
||||
public var text: String?
|
||||
public var colorSelected: String?
|
||||
|
||||
enum Keys: String {
|
||||
case startTime
|
||||
case endTime
|
||||
case color
|
||||
case text
|
||||
case colorSelected
|
||||
}
|
||||
|
||||
public override init(identifier: String) {
|
||||
super.init(identifier: identifier)
|
||||
}
|
||||
|
||||
public override func encode(with aCoder: NSCoder) {
|
||||
super.encode(with: aCoder)
|
||||
aCoder.encode(startTime, forKey: Keys.startTime.rawValue)
|
||||
aCoder.encode(endTime, forKey: Keys.endTime.rawValue)
|
||||
aCoder.encode(color, forKey: Keys.color.rawValue)
|
||||
aCoder.encode(text, forKey: Keys.text.rawValue)
|
||||
aCoder.encode(colorSelected, forKey: Keys.colorSelected.rawValue)
|
||||
}
|
||||
|
||||
public required init?(coder aDecoder: NSCoder) {
|
||||
super.init(coder: aDecoder)
|
||||
startTime = aDecoder.decodeObject(forKey: Keys.startTime.rawValue) as? Double
|
||||
endTime = aDecoder.decodeObject(forKey: Keys.endTime.rawValue) as? Double
|
||||
color = aDecoder.decodeObject(forKey: Keys.color.rawValue) as? String
|
||||
text = aDecoder.decodeObject(forKey: Keys.text.rawValue) as? String
|
||||
colorSelected = aDecoder.decodeObject(forKey: Keys.colorSelected.rawValue) as? String
|
||||
}
|
||||
|
||||
public class func supportsSecureCoding() -> Bool {
|
||||
return true
|
||||
}
|
||||
|
||||
override public func isEqual(_ object: Any?) -> Bool {
|
||||
let isParentSame = super.isEqual(object)
|
||||
|
||||
if let castObject = object as? ORKSwiftStroopResult {
|
||||
return (isParentSame &&
|
||||
(startTime == castObject.startTime) &&
|
||||
(endTime == castObject.endTime) &&
|
||||
(color == castObject.color) &&
|
||||
(text == castObject.text) &&
|
||||
(colorSelected == castObject.colorSelected))
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
override public func copy(with zone: NSZone? = nil) -> Any {
|
||||
if let result = super.copy(with: zone) as? ORKSwiftStroopResult {
|
||||
result.startTime = startTime
|
||||
result.endTime = endTime
|
||||
result.color = color
|
||||
result.text = text
|
||||
result.colorSelected = colorSelected
|
||||
return result
|
||||
} else {
|
||||
return super.copy(with: zone)
|
||||
}
|
||||
}
|
||||
|
||||
public override func description(withNumberOfPaddingSpaces numberOfPaddingSpaces: UInt) -> String {
|
||||
return "\(descriptionPrefix(withNumberOfPaddingSpaces: numberOfPaddingSpaces)); color: \(color ?? "") text: \(text ?? "") colorSelected: \(colorSelected ?? "") \(descriptionSuffix())"
|
||||
}
|
||||
}
|
||||
@@ -1,94 +0,0 @@
|
||||
/*
|
||||
Copyright (c) 2019, Apple Inc. All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification,
|
||||
are permitted provided that the following conditions are met:
|
||||
|
||||
1. Redistributions of source code must retain the above copyright notice, this
|
||||
list of conditions and the following disclaimer.
|
||||
|
||||
2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
this list of conditions and the following disclaimer in the documentation and/or
|
||||
other materials provided with the distribution.
|
||||
|
||||
3. Neither the name of the copyright holder(s) nor the names of any contributors
|
||||
may be used to endorse or promote products derived from this software without
|
||||
specific prior written permission. No license is granted to the trademarks of
|
||||
the copyright holders even if such marks are included in this software.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
|
||||
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
|
||||
import Foundation
|
||||
|
||||
public class ORKSwiftStroopStep: ORKActiveStep {
|
||||
|
||||
public var numberOfAttempts = 0
|
||||
private let minimumAttempts = 10
|
||||
|
||||
enum Key: String {
|
||||
case numberOfAttempts
|
||||
}
|
||||
|
||||
public override class func stepViewControllerClass() -> AnyClass {
|
||||
return ORKSwiftStroopStepViewController.self
|
||||
}
|
||||
|
||||
public class func supportsSecureCoding() -> Bool {
|
||||
return true
|
||||
}
|
||||
|
||||
public override init(identifier: String) {
|
||||
super.init(identifier: identifier)
|
||||
|
||||
shouldVibrateOnStart = true
|
||||
shouldShowDefaultTimer = false
|
||||
shouldContinueOnFinish = true
|
||||
stepDuration = TimeInterval(NSIntegerMax)
|
||||
}
|
||||
|
||||
public override func validateParameters() {
|
||||
super.validateParameters()
|
||||
assert(numberOfAttempts >= minimumAttempts, "number of attempts should be greater or equal to \(minimumAttempts)")
|
||||
}
|
||||
|
||||
public override func startsFinished() -> Bool {
|
||||
return false
|
||||
}
|
||||
|
||||
public override var allowsBackNavigation: Bool {
|
||||
return false
|
||||
}
|
||||
|
||||
public override func copy(with zone: NSZone? = nil) -> Any {
|
||||
let stroopStep = super.copy(with: zone)
|
||||
return stroopStep
|
||||
}
|
||||
|
||||
required init(coder aDecoder: NSCoder) {
|
||||
super.init(coder: aDecoder)
|
||||
numberOfAttempts = aDecoder.decodeInteger(forKey: Key.numberOfAttempts.rawValue)
|
||||
}
|
||||
|
||||
public override func encode(with aCoder: NSCoder) {
|
||||
super.encode(with: aCoder)
|
||||
aCoder.encode(numberOfAttempts, forKey: Key.numberOfAttempts.rawValue)
|
||||
}
|
||||
|
||||
public override func isEqual(_ object: Any?) -> Bool {
|
||||
if let object = object as? ORKSwiftStroopStep {
|
||||
return numberOfAttempts == object.numberOfAttempts
|
||||
}
|
||||
return false
|
||||
}
|
||||
}
|
||||
@@ -1,205 +0,0 @@
|
||||
/*
|
||||
Copyright (c) 2019, Apple Inc. All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification,
|
||||
are permitted provided that the following conditions are met:
|
||||
|
||||
1. Redistributions of source code must retain the above copyright notice, this
|
||||
list of conditions and the following disclaimer.
|
||||
|
||||
2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
this list of conditions and the following disclaimer in the documentation and/or
|
||||
other materials provided with the distribution.
|
||||
|
||||
3. Neither the name of the copyright holder(s) nor the names of any contributors
|
||||
may be used to endorse or promote products derived from this software without
|
||||
specific prior written permission. No license is granted to the trademarks of
|
||||
the copyright holders even if such marks are included in this software.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
|
||||
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
|
||||
import ResearchKit.Private
|
||||
|
||||
public class ORKSwiftStroopStepViewController: ORKActiveStepViewController {
|
||||
|
||||
private let stroopContentView = ORKSwiftStroopContentView()
|
||||
private var colors = [String: UIColor]()
|
||||
private var differentColorLabels = [String: [UIColor]]()
|
||||
private var questionNumber = 0
|
||||
|
||||
private let red = UIColor(red: 1.0, green: 0.0, blue: 0.0, alpha: 1.0)
|
||||
private let green = UIColor(red: 0.0, green: 1.0, blue: 0.0, alpha: 1.0)
|
||||
private let blue = UIColor(red: 0.0, green: 0.0, blue: 1.0, alpha: 1.0)
|
||||
private let yellow = UIColor(red: 1.0, green: 1.0, blue: 0.0, alpha: 1.0)
|
||||
|
||||
private let redString = ORKSwiftLocalizedString("STROOP_COLOR_RED", "")
|
||||
private let greenString = ORKSwiftLocalizedString("STROOP_COLOR_GREEN", "")
|
||||
private let blueString = ORKSwiftLocalizedString("STROOP_COLOR_BLUE", "")
|
||||
private let yellowString = ORKSwiftLocalizedString("STROOP_COLOR_YELLOW", "")
|
||||
|
||||
private var nextQuestionTimer: Timer?
|
||||
private var results: NSMutableArray?
|
||||
private var startTime: TimeInterval?
|
||||
private var endTime: TimeInterval?
|
||||
|
||||
public override init(step: ORKStep?) {
|
||||
super.init(step: step)
|
||||
suspendIfInactive = true
|
||||
}
|
||||
|
||||
internal required init?(coder aDecoder: NSCoder) {
|
||||
fatalError("init(coder:) has not been implemented")
|
||||
}
|
||||
|
||||
private func stroopStep() -> ORKSwiftStroopStep {
|
||||
return step as! ORKSwiftStroopStep
|
||||
}
|
||||
|
||||
public override func viewDidLoad() {
|
||||
super.viewDidLoad()
|
||||
|
||||
results = NSMutableArray()
|
||||
|
||||
colors[redString] = red
|
||||
colors[blueString] = blue
|
||||
colors[yellowString] = yellow
|
||||
colors[greenString] = green
|
||||
|
||||
differentColorLabels[redString] = [blue, green, yellow]
|
||||
differentColorLabels[blueString] = [red, green, yellow]
|
||||
differentColorLabels[yellowString] = [red, blue, green]
|
||||
differentColorLabels[greenString] = [red, blue, yellow]
|
||||
|
||||
activeStepView?.activeCustomView = stroopContentView
|
||||
activeStepView?.customContentFillsAvailableSpace = true
|
||||
|
||||
stroopContentView.redButton.addTarget(self, action: #selector(buttonPressed), for: .touchUpInside)
|
||||
stroopContentView.greenButton.addTarget(self, action: #selector(buttonPressed), for: .touchUpInside)
|
||||
stroopContentView.blueButton.addTarget(self, action: #selector(buttonPressed), for: .touchUpInside)
|
||||
stroopContentView.yellowButton.addTarget(self, action: #selector(buttonPressed), for: .touchUpInside)
|
||||
}
|
||||
|
||||
@objc
|
||||
private func buttonPressed(sender: Any) {
|
||||
|
||||
if stroopContentView.colorLabelText != " " {
|
||||
setButtonDisabled()
|
||||
if let button = sender as? ORKBorderedButton {
|
||||
|
||||
if button == stroopContentView.redButton {
|
||||
createResult(color: (colors as NSDictionary).allKeys(for: stroopContentView.colorLabelColor!).first as? String ?? "", withText: stroopContentView.colorLabelText!, withColorSelected: redString)
|
||||
} else if button == stroopContentView.greenButton {
|
||||
createResult(color: (colors as NSDictionary).allKeys(for: stroopContentView.colorLabelColor!).first as? String ?? "", withText: stroopContentView.colorLabelText!, withColorSelected: greenString)
|
||||
} else if button == stroopContentView.blueButton {
|
||||
createResult(color: (colors as NSDictionary).allKeys(for: stroopContentView.colorLabelColor!).first as? String ?? "", withText: stroopContentView.colorLabelText!, withColorSelected: blueString)
|
||||
} else if button == stroopContentView.yellowButton {
|
||||
createResult(color: (colors as NSDictionary).allKeys(for: stroopContentView.colorLabelColor!).first as? String ?? "", withText: stroopContentView.colorLabelText!, withColorSelected: yellowString)
|
||||
}
|
||||
|
||||
nextQuestionTimer = Timer.scheduledTimer(timeInterval: 0.5,
|
||||
target: self,
|
||||
selector: #selector(startNextQuestionOrFinish),
|
||||
userInfo: nil,
|
||||
repeats: false)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public override func viewDidAppear(_ animated: Bool) {
|
||||
super.viewDidAppear(animated)
|
||||
start()
|
||||
}
|
||||
|
||||
public override func stepDidFinish() {
|
||||
super.stepDidFinish()
|
||||
stroopContentView.finishStep(self)
|
||||
goForward()
|
||||
}
|
||||
|
||||
public override var result: ORKStepResult? {
|
||||
let stepResult = super.result
|
||||
if results != nil {
|
||||
stepResult?.results = results?.copy() as? [ORKResult]
|
||||
}
|
||||
return stepResult!
|
||||
}
|
||||
|
||||
public override func start() {
|
||||
super.start()
|
||||
startQuestion()
|
||||
}
|
||||
|
||||
private func createResult(color: String, withText text: String, withColorSelected colorSelected: String) {
|
||||
let stroopResult = ORKSwiftStroopResult(identifier: (step!.identifier))
|
||||
stroopResult.startTime = startTime
|
||||
stroopResult.endTime = ProcessInfo.processInfo.systemUptime
|
||||
stroopResult.color = color
|
||||
stroopResult.text = text
|
||||
stroopResult.colorSelected = colorSelected
|
||||
results?.add(stroopResult)
|
||||
}
|
||||
|
||||
@objc
|
||||
private func startNextQuestionOrFinish() {
|
||||
if nextQuestionTimer != nil {
|
||||
nextQuestionTimer?.invalidate()
|
||||
nextQuestionTimer = nil
|
||||
}
|
||||
questionNumber += 1
|
||||
if questionNumber == stroopStep().numberOfAttempts {
|
||||
finish()
|
||||
} else {
|
||||
startQuestion()
|
||||
}
|
||||
}
|
||||
|
||||
private func startQuestion() {
|
||||
let pattern: Int = Int(arc4random()) % 2
|
||||
if pattern == 0 {
|
||||
let index: Int = Int(arc4random()) % differentColorLabels.keys.count
|
||||
let text = Array(differentColorLabels.keys)[index]
|
||||
stroopContentView.setColorLabelText(colorLabelText: text)
|
||||
let color = colors[text]!
|
||||
stroopContentView.colorLabelColor = color
|
||||
stroopContentView.setColorLabelColor(colorLabelColor: color)
|
||||
} else {
|
||||
let index: Int = Int(arc4random()) % differentColorLabels.keys.count
|
||||
let text = Array(differentColorLabels.keys)[index]
|
||||
stroopContentView.setColorLabelText(colorLabelText: text)
|
||||
let colorArray = differentColorLabels[text]!
|
||||
let randomColorIndex = Int(arc4random()) % colorArray.count
|
||||
let color = colorArray[randomColorIndex]
|
||||
stroopContentView.setColorLabelColor(colorLabelColor: color)
|
||||
}
|
||||
|
||||
setButtonsEnabled()
|
||||
startTime = ProcessInfo.processInfo.systemUptime
|
||||
}
|
||||
|
||||
private func setButtonDisabled() {
|
||||
|
||||
stroopContentView.redButton.isEnabled = false
|
||||
stroopContentView.greenButton.isEnabled = false
|
||||
stroopContentView.blueButton.isEnabled = false
|
||||
stroopContentView.yellowButton.isEnabled = false
|
||||
}
|
||||
|
||||
private func setButtonsEnabled() {
|
||||
|
||||
stroopContentView.redButton.isEnabled = true
|
||||
stroopContentView.greenButton.isEnabled = true
|
||||
stroopContentView.blueButton.isEnabled = true
|
||||
stroopContentView.yellowButton.isEnabled = true
|
||||
}
|
||||
}
|
||||
@@ -1,435 +0,0 @@
|
||||
/*
|
||||
Copyright (c) 2018, Apple Inc. All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification,
|
||||
are permitted provided that the following conditions are met:
|
||||
|
||||
1. Redistributions of source code must retain the above copyright notice, this
|
||||
list of conditions and the following disclaimer.
|
||||
|
||||
2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
this list of conditions and the following disclaimer in the documentation and/or
|
||||
other materials provided with the distribution.
|
||||
|
||||
3. Neither the name of the copyright holder(s) nor the names of any contributors
|
||||
may be used to endorse or promote products derived from this software without
|
||||
specific prior written permission. No license is granted to the trademarks of
|
||||
the copyright holders even if such marks are included in this software.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
|
||||
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
|
||||
#import "ORKdBHLToneAudiometryStepViewController.h"
|
||||
|
||||
#import "ORKActiveStepView.h"
|
||||
#import "ORKActiveStep_Internal.h"
|
||||
#import "ORKStepHeaderView_Internal.h"
|
||||
#import "ORKNavigationContainerView.h"
|
||||
#import "ORKStepContainerView.h"
|
||||
|
||||
#import "ORKdBHLToneAudiometryAudioGenerator.h"
|
||||
#import "ORKRoundTappingButton.h"
|
||||
#import "ORKdBHLToneAudiometryContentView.h"
|
||||
#import "ORKStepContainerView_Private.h"
|
||||
|
||||
#import "ORKActiveStepViewController_Internal.h"
|
||||
#import "ORKStepViewController_Internal.h"
|
||||
|
||||
#import "ORKCollectionResult_Private.h"
|
||||
#import "ORKdBHLToneAudiometryResult.h"
|
||||
#import "ORKdBHLToneAudiometryStep.h"
|
||||
|
||||
#import "ORKHelpers_Internal.h"
|
||||
#import "ORKTaskViewController_Private.h"
|
||||
#import "ORKOrderedTask.h"
|
||||
|
||||
@interface ORKdBHLToneAudiometryTransitions: NSObject
|
||||
|
||||
@property (nonatomic, assign) float userInitiated;
|
||||
@property (nonatomic, assign) float totalTransitions;
|
||||
|
||||
@end
|
||||
|
||||
@implementation ORKdBHLToneAudiometryTransitions
|
||||
|
||||
- (instancetype)init
|
||||
{
|
||||
self = [super init];
|
||||
if (self) {
|
||||
_userInitiated = 1;
|
||||
_totalTransitions = 1;
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
@interface ORKdBHLToneAudiometryStepViewController () <ORKdBHLToneAudiometryAudioGeneratorDelegate> {
|
||||
double _prevFreq;
|
||||
double _currentdBHL;
|
||||
double _dBHLStepUpSize;
|
||||
double _dBHLStepDownSize;
|
||||
double _dBHLMinimumThreshold;
|
||||
int _currentTestIndex;
|
||||
int _indexOfFreqLoopList;
|
||||
NSUInteger _indexOfStepUpMissingList;
|
||||
int _numberOfTransitionsPerFreq;
|
||||
NSInteger _maxNumberOfTransitionsPerFreq;
|
||||
BOOL _initialDescent;
|
||||
BOOL _ackOnce;
|
||||
BOOL _usingMissingList;
|
||||
ORKdBHLToneAudiometryAudioGenerator *_audioGenerator;
|
||||
NSArray *_freqLoopList;
|
||||
NSArray *_stepUpMissingList;
|
||||
NSMutableArray *_arrayOfResultSamples;
|
||||
NSMutableArray *_arrayOfResultUnits;
|
||||
NSMutableDictionary *_transitionsDictionary;
|
||||
UIImpactFeedbackGenerator *_hapticFeedback;
|
||||
ORKdBHLToneAudiometryFrequencySample *_resultSample;
|
||||
ORKdBHLToneAudiometryUnit *_resultUnit;
|
||||
ORKAudioChannel _audioChannel;
|
||||
dispatch_block_t _preStimulusDelayWorkBlock;
|
||||
dispatch_block_t _pulseDurationWorkBlock;
|
||||
dispatch_block_t _postStimulusDelayWorkBlock;
|
||||
}
|
||||
|
||||
@property (nonatomic, strong) ORKdBHLToneAudiometryContentView *dBHLToneAudiometryContentView;
|
||||
|
||||
@end
|
||||
|
||||
@implementation ORKdBHLToneAudiometryStepViewController
|
||||
|
||||
- (instancetype)initWithStep:(ORKStep *)step {
|
||||
self = [super initWithStep:step];
|
||||
|
||||
if (self) {
|
||||
self.suspendIfInactive = YES;
|
||||
_indexOfFreqLoopList = 0;
|
||||
_indexOfStepUpMissingList = 0;
|
||||
_initialDescent = YES;
|
||||
_ackOnce = NO;
|
||||
_usingMissingList = YES;
|
||||
_prevFreq = 0;
|
||||
_currentTestIndex = 0;
|
||||
_transitionsDictionary = [NSMutableDictionary dictionary];
|
||||
_arrayOfResultSamples = [NSMutableArray array];
|
||||
_arrayOfResultUnits = [NSMutableArray array];
|
||||
}
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void)initializeInternalButtonItems {
|
||||
[super initializeInternalButtonItems];
|
||||
|
||||
// Don't show next button
|
||||
self.internalContinueButtonItem = nil;
|
||||
self.internalDoneButtonItem = nil;
|
||||
}
|
||||
|
||||
- (ORKdBHLToneAudiometryStep *)dBHLToneAudiometryStep {
|
||||
return (ORKdBHLToneAudiometryStep *)self.step;
|
||||
}
|
||||
|
||||
- (void)viewDidLoad {
|
||||
[super viewDidLoad];
|
||||
|
||||
[self configureStep];
|
||||
}
|
||||
|
||||
- (void)configureStep {
|
||||
ORKdBHLToneAudiometryStep *dBHLTAStep = [self dBHLToneAudiometryStep];
|
||||
|
||||
_maxNumberOfTransitionsPerFreq = dBHLTAStep.maxNumberOfTransitionsPerFrequency;
|
||||
_freqLoopList = dBHLTAStep.frequencyList;
|
||||
_stepUpMissingList = @[ [NSNumber numberWithDouble:dBHLTAStep.dBHLStepUpSizeFirstMiss],
|
||||
[NSNumber numberWithDouble:dBHLTAStep.dBHLStepUpSizeSecondMiss],
|
||||
[NSNumber numberWithDouble:dBHLTAStep.dBHLStepUpSizeThirdMiss] ];
|
||||
_currentdBHL = dBHLTAStep.initialdBHLValue;
|
||||
_dBHLStepDownSize = dBHLTAStep.dBHLStepDownSize;
|
||||
_dBHLStepUpSize = dBHLTAStep.dBHLStepUpSize;
|
||||
_dBHLMinimumThreshold = dBHLTAStep.dBHLMinimumThreshold;
|
||||
|
||||
self.dBHLToneAudiometryContentView = [[ORKdBHLToneAudiometryContentView alloc] init];
|
||||
self.activeStepView.activeCustomView = self.dBHLToneAudiometryContentView;
|
||||
self.activeStepView.customContentFillsAvailableSpace = YES;
|
||||
[self.activeStepView.navigationFooterView setHidden:YES];
|
||||
|
||||
[self.dBHLToneAudiometryContentView.tapButton addTarget:self action:@selector(tapButtonPressed) forControlEvents:UIControlEventTouchDown];
|
||||
|
||||
_audioChannel = [self dBHLToneAudiometryStep].earPreference;
|
||||
_audioGenerator = [[ORKdBHLToneAudiometryAudioGenerator alloc] initForHeadphones:[self dBHLToneAudiometryStep].headphoneType];
|
||||
_audioGenerator.delegate = self;
|
||||
_hapticFeedback = [[UIImpactFeedbackGenerator alloc] initWithStyle: UIImpactFeedbackStyleHeavy];
|
||||
}
|
||||
|
||||
- (void)viewDidAppear:(BOOL)animated {
|
||||
[super viewDidAppear:animated];
|
||||
[self start];
|
||||
}
|
||||
|
||||
- (void)animatedBHLButton {
|
||||
[self.dBHLToneAudiometryContentView.layer removeAllAnimations];
|
||||
[UIView animateWithDuration:0.1
|
||||
delay:0.0
|
||||
usingSpringWithDamping:0.1
|
||||
initialSpringVelocity:0.0
|
||||
options:UIViewAnimationOptionCurveEaseOut|UIViewAnimationOptionAllowUserInteraction
|
||||
animations:^{
|
||||
[self.dBHLToneAudiometryContentView.tapButton setTransform:CGAffineTransformMakeScale(0.88, 0.88)];
|
||||
} completion:^(BOOL finished) {
|
||||
[UIView animateWithDuration:1.0
|
||||
delay:0.0
|
||||
usingSpringWithDamping:0.4
|
||||
initialSpringVelocity:0.0
|
||||
options:UIViewAnimationOptionCurveLinear|UIViewAnimationOptionAllowUserInteraction
|
||||
animations:^{
|
||||
[self.dBHLToneAudiometryContentView.tapButton setTransform:CGAffineTransformMakeScale(1.0, 1.0)];
|
||||
} completion:nil];
|
||||
}];
|
||||
}
|
||||
|
||||
- (void)viewDidDisappear:(BOOL)animated {
|
||||
[super viewDidDisappear:animated];
|
||||
[[NSNotificationCenter defaultCenter] removeObserver:self];
|
||||
_audioGenerator.delegate = nil;
|
||||
}
|
||||
|
||||
- (void)viewWillDisappear:(BOOL)animated {
|
||||
[super viewWillDisappear:animated];
|
||||
[self stopAudio];
|
||||
}
|
||||
|
||||
- (ORKStepResult *)result {
|
||||
ORKStepResult *sResult = [super result];
|
||||
// "Now" is the end time of the result, which is either actually now,
|
||||
// or the last time we were in the responder chain.
|
||||
NSDate *now = sResult.endDate;
|
||||
|
||||
NSMutableArray *results = [NSMutableArray arrayWithArray:sResult.results];
|
||||
|
||||
ORKdBHLToneAudiometryResult *toneResult = [[ORKdBHLToneAudiometryResult alloc] initWithIdentifier:self.step.identifier];
|
||||
toneResult.startDate = sResult.startDate;
|
||||
toneResult.endDate = now;
|
||||
toneResult.samples = [_arrayOfResultSamples copy];
|
||||
toneResult.outputVolume = [AVAudioSession sharedInstance].outputVolume;
|
||||
toneResult.headphoneType = self.dBHLToneAudiometryStep.headphoneType;
|
||||
toneResult.tonePlaybackDuration = [self dBHLToneAudiometryStep].toneDuration;
|
||||
toneResult.postStimulusDelay = [self dBHLToneAudiometryStep].postStimulusDelay;
|
||||
[results addObject:toneResult];
|
||||
|
||||
sResult.results = [results copy];
|
||||
|
||||
return sResult;
|
||||
}
|
||||
|
||||
- (void)stepDidFinish {
|
||||
[super stepDidFinish];
|
||||
[self stopAudio];
|
||||
[self.dBHLToneAudiometryContentView finishStep:self];
|
||||
[self goForward];
|
||||
}
|
||||
|
||||
- (void)start {
|
||||
[super start];
|
||||
[self estimatedBHLAndPlayToneWithFrequency:_freqLoopList[_indexOfFreqLoopList]];
|
||||
}
|
||||
|
||||
- (void)stopAudio {
|
||||
[_audioGenerator stop];
|
||||
if (_preStimulusDelayWorkBlock) {
|
||||
dispatch_block_cancel(_preStimulusDelayWorkBlock);
|
||||
dispatch_block_cancel(_pulseDurationWorkBlock);
|
||||
dispatch_block_cancel(_postStimulusDelayWorkBlock);
|
||||
}
|
||||
}
|
||||
|
||||
- (void)estimatedBHLAndPlayToneWithFrequency: (NSNumber *)freq {
|
||||
[self stopAudio];
|
||||
if (_prevFreq != [freq doubleValue]) {
|
||||
CGFloat progress = 0.001 + (CGFloat)_indexOfFreqLoopList / _freqLoopList.count;
|
||||
[self.dBHLToneAudiometryContentView setProgress:progress
|
||||
animated:YES];
|
||||
|
||||
_numberOfTransitionsPerFreq = 0;
|
||||
_currentdBHL = [self dBHLToneAudiometryStep].initialdBHLValue;
|
||||
_initialDescent = YES;
|
||||
_ackOnce = NO;
|
||||
_transitionsDictionary = nil;
|
||||
_transitionsDictionary = [NSMutableDictionary dictionary];
|
||||
if (_resultSample) {
|
||||
_resultSample.units = [_arrayOfResultUnits copy];
|
||||
}
|
||||
_arrayOfResultUnits = [NSMutableArray array];
|
||||
_prevFreq = [freq doubleValue];
|
||||
_resultSample = [ORKdBHLToneAudiometryFrequencySample new];
|
||||
_resultSample.channel = _audioChannel;
|
||||
_resultSample.frequency = [freq doubleValue];
|
||||
_resultSample.calculatedThreshold = ORKInvalidDBHLValue;
|
||||
[_arrayOfResultSamples addObject:_resultSample];
|
||||
} else {
|
||||
_numberOfTransitionsPerFreq += 1;
|
||||
if (_numberOfTransitionsPerFreq >= _maxNumberOfTransitionsPerFreq) {
|
||||
_indexOfFreqLoopList += 1;
|
||||
if (_indexOfFreqLoopList >= _freqLoopList.count) {
|
||||
_resultSample.units = [_arrayOfResultUnits copy];
|
||||
[self finish];
|
||||
return;
|
||||
} else {
|
||||
[self estimatedBHLAndPlayToneWithFrequency:_freqLoopList[_indexOfFreqLoopList]];
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
_resultUnit = [ORKdBHLToneAudiometryUnit new];
|
||||
_resultUnit.dBHLValue = _currentdBHL;
|
||||
_resultUnit.startOfUnitTimeStamp = self.runtime;
|
||||
[_arrayOfResultUnits addObject:_resultUnit];
|
||||
|
||||
ORKdBHLToneAudiometryTransitions *currentTransition = [_transitionsDictionary objectForKey:[NSNumber numberWithFloat:_currentdBHL]];
|
||||
if (!_initialDescent) {
|
||||
if (currentTransition) {
|
||||
currentTransition.userInitiated += 1;
|
||||
currentTransition.totalTransitions += 1;
|
||||
} else {
|
||||
currentTransition = [[ORKdBHLToneAudiometryTransitions alloc] init];
|
||||
[_transitionsDictionary setObject:currentTransition forKey:[NSNumber numberWithFloat:_currentdBHL]];
|
||||
}
|
||||
}
|
||||
const NSTimeInterval toneDuration = [self dBHLToneAudiometryStep].toneDuration;
|
||||
const NSTimeInterval postStimulusDelay = [self dBHLToneAudiometryStep].postStimulusDelay;
|
||||
|
||||
double delay1 = arc4random_uniform([self dBHLToneAudiometryStep].maxRandomPreStimulusDelay - 1);
|
||||
double delay2 = (double)arc4random_uniform(10)/10;
|
||||
double preStimulusDelay = delay1 + delay2 + 1;
|
||||
_resultUnit.preStimulusDelay = preStimulusDelay;
|
||||
|
||||
_preStimulusDelayWorkBlock = dispatch_block_create(DISPATCH_BLOCK_INHERIT_QOS_CLASS, ^{
|
||||
[_audioGenerator playSoundAtFrequency:[freq floatValue] onChannel:_audioChannel dBHL:_currentdBHL];
|
||||
});
|
||||
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(preStimulusDelay * NSEC_PER_SEC)), dispatch_get_main_queue(), _preStimulusDelayWorkBlock);
|
||||
|
||||
_pulseDurationWorkBlock = dispatch_block_create(DISPATCH_BLOCK_INHERIT_QOS_CLASS, ^{
|
||||
[_audioGenerator stop];
|
||||
});
|
||||
// adding 0.2 seconds to account for the fadeInDuration which is being set in ORKdBHLToneAudiometryAudioGenerator
|
||||
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)((preStimulusDelay + toneDuration + 0.2) * NSEC_PER_SEC)), dispatch_get_main_queue(), _pulseDurationWorkBlock);
|
||||
|
||||
ORKWeakTypeOf(self)weakSelf = self;
|
||||
_postStimulusDelayWorkBlock = dispatch_block_create(DISPATCH_BLOCK_INHERIT_QOS_CLASS, ^{
|
||||
ORKStrongTypeOf(self) strongSelf = weakSelf;
|
||||
NSUInteger storedTestIndex = _currentTestIndex;
|
||||
if (_currentTestIndex == storedTestIndex) {
|
||||
if (_initialDescent && _ackOnce) {
|
||||
_initialDescent = NO;
|
||||
ORKdBHLToneAudiometryTransitions *newTransition = [[ORKdBHLToneAudiometryTransitions alloc] init];
|
||||
newTransition.userInitiated -= 1;
|
||||
[_transitionsDictionary setObject:newTransition forKey:[NSNumber numberWithFloat:_currentdBHL]];
|
||||
}
|
||||
if (_usingMissingList && (_indexOfStepUpMissingList < _stepUpMissingList.count)) {
|
||||
_currentdBHL = _currentdBHL + [_stepUpMissingList[_indexOfStepUpMissingList] doubleValue];
|
||||
_indexOfStepUpMissingList = _indexOfStepUpMissingList + 1;
|
||||
} else {
|
||||
_usingMissingList = NO;
|
||||
_currentdBHL = _currentdBHL + _dBHLStepUpSize;
|
||||
}
|
||||
if (currentTransition) {
|
||||
currentTransition.userInitiated -= 1;
|
||||
}
|
||||
_resultUnit.timeoutTimeStamp = self.runtime;
|
||||
_currentTestIndex += 1;
|
||||
[strongSelf estimatedBHLAndPlayToneWithFrequency:_freqLoopList[_indexOfFreqLoopList]];
|
||||
return;
|
||||
}
|
||||
});
|
||||
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)((preStimulusDelay + toneDuration + postStimulusDelay) * NSEC_PER_SEC)), dispatch_get_main_queue(), _postStimulusDelayWorkBlock);
|
||||
|
||||
}
|
||||
|
||||
- (void)tapButtonPressed {
|
||||
[self animatedBHLButton];
|
||||
_ackOnce = YES;
|
||||
[_hapticFeedback impactOccurred];
|
||||
_currentTestIndex += 1;
|
||||
_resultUnit.userTapTimeStamp = self.runtime;
|
||||
[self stopAudio];
|
||||
BOOL falseResponseTap = (_resultUnit.userTapTimeStamp - _resultUnit.startOfUnitTimeStamp < _resultUnit.preStimulusDelay);
|
||||
if (falseResponseTap) {
|
||||
NSNumber *currentKey = [NSNumber numberWithFloat:_currentdBHL];
|
||||
ORKdBHLToneAudiometryTransitions *currentTransitionObject = [_transitionsDictionary objectForKey:currentKey];
|
||||
currentTransitionObject.userInitiated -= 1;
|
||||
} else if ([self validateResultFordBHL:_currentdBHL]) {
|
||||
_resultSample.calculatedThreshold = _currentdBHL;
|
||||
_indexOfFreqLoopList += 1;
|
||||
if (_indexOfFreqLoopList >= _freqLoopList.count) {
|
||||
_resultSample.units = [_arrayOfResultUnits copy];
|
||||
[self finish];
|
||||
return;
|
||||
} else {
|
||||
_currentdBHL = [self dBHLToneAudiometryStep].initialdBHLValue;
|
||||
[self estimatedBHLAndPlayToneWithFrequency:_freqLoopList[_indexOfFreqLoopList]];
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if ((_currentdBHL - _dBHLStepDownSize >= _dBHLMinimumThreshold) && !falseResponseTap) {
|
||||
_usingMissingList = NO;
|
||||
_currentdBHL = _currentdBHL - _dBHLStepDownSize;
|
||||
}
|
||||
|
||||
[self estimatedBHLAndPlayToneWithFrequency:_freqLoopList[_indexOfFreqLoopList]];
|
||||
return;
|
||||
}
|
||||
|
||||
- (BOOL)validateResultFordBHL:(float)dBHL {
|
||||
NSNumber *currentKey = [NSNumber numberWithFloat:_currentdBHL];
|
||||
ORKdBHLToneAudiometryTransitions *currentTransitionObject = [_transitionsDictionary objectForKey:currentKey];
|
||||
if ((currentTransitionObject.userInitiated/currentTransitionObject.totalTransitions >= 0.5) && currentTransitionObject.totalTransitions >= 2) {
|
||||
ORKdBHLToneAudiometryTransitions *previousTransitionObject = [_transitionsDictionary objectForKey:[NSNumber numberWithFloat:(dBHL - _dBHLStepUpSize)]];
|
||||
if ((previousTransitionObject.userInitiated/previousTransitionObject.totalTransitions <= 0.5) && (previousTransitionObject.totalTransitions >= 2)) {
|
||||
if (currentTransitionObject.totalTransitions == 2) {
|
||||
if (currentTransitionObject.userInitiated/currentTransitionObject.totalTransitions == 1.0) {
|
||||
_resultSample.calculatedThreshold = dBHL;
|
||||
return YES;
|
||||
} else {
|
||||
return NO;
|
||||
}
|
||||
} else {
|
||||
_resultSample.calculatedThreshold = dBHL;
|
||||
return YES;
|
||||
}
|
||||
}
|
||||
}
|
||||
return NO;
|
||||
}
|
||||
|
||||
- (void)toneWillStartClipping {
|
||||
if (_usingMissingList
|
||||
&& (_indexOfStepUpMissingList <= _stepUpMissingList.count)) {
|
||||
_usingMissingList = NO;
|
||||
_currentdBHL = _currentdBHL - [_stepUpMissingList[_indexOfStepUpMissingList - (_indexOfStepUpMissingList == 0 ? 0 : 1)] doubleValue] + _dBHLStepUpSize;
|
||||
[self estimatedBHLAndPlayToneWithFrequency:_freqLoopList[_indexOfFreqLoopList]];
|
||||
} else {
|
||||
_indexOfFreqLoopList += 1;
|
||||
if (_indexOfFreqLoopList >= _freqLoopList.count) {
|
||||
_resultSample.units = [_arrayOfResultUnits copy];
|
||||
[self finish];
|
||||
} else {
|
||||
[self estimatedBHLAndPlayToneWithFrequency:_freqLoopList[_indexOfFreqLoopList]];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
@@ -1,105 +0,0 @@
|
||||
/*
|
||||
Copyright (c) 2019, Novartis.
|
||||
Copyright (c) 2019, Apple Inc. All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification,
|
||||
are permitted provided that the following conditions are met:
|
||||
|
||||
1. Redistributions of source code must retain the above copyright notice, this
|
||||
list of conditions and the following disclaimer.
|
||||
|
||||
2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
this list of conditions and the following disclaimer in the documentation and/or
|
||||
other materials provided with the distribution.
|
||||
|
||||
3. Neither the name of the copyright holder(s) nor the names of any contributors
|
||||
may be used to endorse or promote products derived from this software without
|
||||
specific prior written permission. No license is granted to the trademarks of
|
||||
the copyright holders even if such marks are included in this software.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
|
||||
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
internal class TrackLayer: CAShapeLayer {
|
||||
|
||||
struct Setting {
|
||||
var startAngle = Double()
|
||||
var barWidth = CGFloat()
|
||||
var barColor = UIColor()
|
||||
var trackingColor = UIColor()
|
||||
}
|
||||
|
||||
internal var setting = Setting()
|
||||
internal var degree: Double = 0
|
||||
internal var hollowRadius: CGFloat {
|
||||
return (bounds.width * 0.5) - setting.barWidth
|
||||
}
|
||||
internal var currentCenter: CGPoint {
|
||||
return CGPoint(x: bounds.midX, y: bounds.midY)
|
||||
}
|
||||
internal var hollowRect: CGRect {
|
||||
return CGRect(
|
||||
x: currentCenter.x - hollowRadius,
|
||||
y: currentCenter.y - hollowRadius,
|
||||
width: hollowRadius * 2.0,
|
||||
height: hollowRadius * 2.0)
|
||||
}
|
||||
internal init(bounds: CGRect, setting: Setting) {
|
||||
super.init()
|
||||
self.bounds = bounds
|
||||
self.setting = setting
|
||||
cornerRadius = bounds.size.width * 0.5
|
||||
masksToBounds = true
|
||||
position = currentCenter
|
||||
backgroundColor = setting.barColor.cgColor
|
||||
mask()
|
||||
}
|
||||
|
||||
required init?(coder aDecoder: NSCoder) {
|
||||
fatalError("init(coder:) has not been implemented")
|
||||
}
|
||||
|
||||
override internal func draw(in ctx: CGContext) {
|
||||
drawTrack(ctx: ctx)
|
||||
}
|
||||
|
||||
private func mask() {
|
||||
let maskLayer = CAShapeLayer()
|
||||
maskLayer.bounds = bounds
|
||||
let ovalRect = hollowRect
|
||||
let path = UIBezierPath(ovalIn: ovalRect)
|
||||
path.append(UIBezierPath(rect: maskLayer.bounds))
|
||||
maskLayer.path = path.cgPath
|
||||
maskLayer.position = currentCenter
|
||||
maskLayer.fillRule = CAShapeLayerFillRule.evenOdd
|
||||
mask = maskLayer
|
||||
}
|
||||
|
||||
private func drawTrack(ctx: CGContext) {
|
||||
let adjustDegree = Math.adjustDegree(setting.startAngle, degree: degree)
|
||||
let centerX = currentCenter.x
|
||||
let centerY = currentCenter.y
|
||||
let radius = min(centerX, centerY)
|
||||
ctx.setFillColor(setting.trackingColor.cgColor)
|
||||
ctx.beginPath()
|
||||
ctx.move(to: CGPoint(x: centerX, y: centerY))
|
||||
ctx.addArc(center: CGPoint(x: centerX, y: centerY),
|
||||
radius: radius,
|
||||
startAngle: CGFloat(Math.degreesToRadians(setting.startAngle)),
|
||||
endAngle: CGFloat(Math.degreesToRadians(adjustDegree)),
|
||||
clockwise: false)
|
||||
|
||||
ctx.closePath()
|
||||
ctx.fillPath()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"info" : {
|
||||
"version" : 1,
|
||||
"author" : "xcode"
|
||||
"author" : "xcode",
|
||||
"version" : 1
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
Before Width: | Height: | Size: 5.7 KiB |
|
Before Width: | Height: | Size: 14 KiB |
|
Before Width: | Height: | Size: 22 KiB |
@@ -1,21 +1,23 @@
|
||||
{
|
||||
"images" : [
|
||||
{
|
||||
"filename" : "Face.png",
|
||||
"idiom" : "universal",
|
||||
"filename" : "Poppies.jpg",
|
||||
"scale" : "1x"
|
||||
},
|
||||
{
|
||||
"filename" : "Face@2x.png",
|
||||
"idiom" : "universal",
|
||||
"scale" : "2x"
|
||||
},
|
||||
{
|
||||
"filename" : "Face@3x.png",
|
||||
"idiom" : "universal",
|
||||
"scale" : "3x"
|
||||
}
|
||||
],
|
||||
"info" : {
|
||||
"version" : 1,
|
||||
"author" : "xcode"
|
||||
"author" : "xcode",
|
||||
"version" : 1
|
||||
}
|
||||
}
|
||||
}
|
||||
|
After Width: | Height: | Size: 9.2 KiB |
|
After Width: | Height: | Size: 24 KiB |
|
After Width: | Height: | Size: 45 KiB |
@@ -1,8 +1,8 @@
|
||||
{
|
||||
"images" : [
|
||||
{
|
||||
"filename" : "guideAreaCorners.pdf",
|
||||
"idiom" : "universal",
|
||||
"filename" : "orangeGrayCircle.png",
|
||||
"scale" : "1x"
|
||||
},
|
||||
{
|
||||
@@ -15,7 +15,7 @@
|
||||
}
|
||||
],
|
||||
"info" : {
|
||||
"version" : 1,
|
||||
"author" : "xcode"
|
||||
"author" : "xcode",
|
||||
"version" : 1
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Before Width: | Height: | Size: 5.8 KiB |
|
Before Width: | Height: | Size: 14 KiB |
|
Before Width: | Height: | Size: 24 KiB |
@@ -1,21 +1,23 @@
|
||||
{
|
||||
"images" : [
|
||||
{
|
||||
"filename" : "airpods@1x.png",
|
||||
"idiom" : "universal",
|
||||
"filename" : "iCNLandoltC.png",
|
||||
"scale" : "1x"
|
||||
},
|
||||
{
|
||||
"filename" : "airpods@2x.png",
|
||||
"idiom" : "universal",
|
||||
"scale" : "2x"
|
||||
},
|
||||
{
|
||||
"filename" : "airpods@3x.png",
|
||||
"idiom" : "universal",
|
||||
"scale" : "3x"
|
||||
}
|
||||
],
|
||||
"info" : {
|
||||
"version" : 1,
|
||||
"author" : "xcode"
|
||||
"author" : "xcode",
|
||||
"version" : 1
|
||||
}
|
||||
}
|
||||
}
|
||||
|
After Width: | Height: | Size: 1.0 KiB |
|
After Width: | Height: | Size: 1.6 KiB |
|
After Width: | Height: | Size: 2.2 KiB |
@@ -1,23 +1,23 @@
|
||||
{
|
||||
"images" : [
|
||||
{
|
||||
"filename" : "airpods_3rd_gen@1x.png",
|
||||
"idiom" : "universal",
|
||||
"filename" : "touchAbilityTap.png",
|
||||
"scale" : "1x"
|
||||
},
|
||||
{
|
||||
"filename" : "airpods_3rd_gen@2x.png",
|
||||
"idiom" : "universal",
|
||||
"filename" : "touchAbilityTap@2x.png",
|
||||
"scale" : "2x"
|
||||
},
|
||||
{
|
||||
"filename" : "airpods_3rd_gen@3x.png",
|
||||
"idiom" : "universal",
|
||||
"filename" : "touchAbilityTap@3x.png",
|
||||
"scale" : "3x"
|
||||
}
|
||||
],
|
||||
"info" : {
|
||||
"version" : 1,
|
||||
"author" : "xcode"
|
||||
"author" : "xcode",
|
||||
"version" : 1
|
||||
}
|
||||
}
|
||||
}
|
||||
|
After Width: | Height: | Size: 998 B |
|
After Width: | Height: | Size: 1.6 KiB |
|
After Width: | Height: | Size: 2.3 KiB |
@@ -1,23 +1,23 @@
|
||||
{
|
||||
"images" : [
|
||||
{
|
||||
"filename" : "airpods_max@1x.png",
|
||||
"idiom" : "universal",
|
||||
"filename" : "VisualExam.png",
|
||||
"scale" : "1x"
|
||||
},
|
||||
{
|
||||
"filename" : "airpods_max@2x.png",
|
||||
"idiom" : "universal",
|
||||
"filename" : "VisualExam@2x.png",
|
||||
"scale" : "2x"
|
||||
},
|
||||
{
|
||||
"filename" : "airpods_max@3x.png",
|
||||
"idiom" : "universal",
|
||||
"filename" : "VisualExam@3x.png",
|
||||
"scale" : "3x"
|
||||
}
|
||||
],
|
||||
"info" : {
|
||||
"version" : 1,
|
||||
"author" : "xcode"
|
||||
"author" : "xcode",
|
||||
"version" : 1
|
||||
}
|
||||
}
|
||||
}
|
||||
|
After Width: | Height: | Size: 1.4 KiB |
|
After Width: | Height: | Size: 2.6 KiB |
|
After Width: | Height: | Size: 3.9 KiB |
@@ -0,0 +1,23 @@
|
||||
{
|
||||
"images" : [
|
||||
{
|
||||
"filename" : "airpods_pro@1x.png",
|
||||
"idiom" : "universal",
|
||||
"scale" : "1x"
|
||||
},
|
||||
{
|
||||
"filename" : "airpods_pro@2x.png",
|
||||
"idiom" : "universal",
|
||||
"scale" : "2x"
|
||||
},
|
||||
{
|
||||
"filename" : "airpods_pro@3x.png",
|
||||
"idiom" : "universal",
|
||||
"scale" : "3x"
|
||||
}
|
||||
],
|
||||
"info" : {
|
||||
"author" : "xcode",
|
||||
"version" : 1
|
||||
}
|
||||
}
|
||||
|
After Width: | Height: | Size: 1.0 KiB |
|
After Width: | Height: | Size: 1.8 KiB |
|
After Width: | Height: | Size: 2.6 KiB |
@@ -0,0 +1,23 @@
|
||||
{
|
||||
"images" : [
|
||||
{
|
||||
"filename" : "earpods@1x.png",
|
||||
"idiom" : "universal",
|
||||
"scale" : "1x"
|
||||
},
|
||||
{
|
||||
"filename" : "earpods@2x.png",
|
||||
"idiom" : "universal",
|
||||
"scale" : "2x"
|
||||
},
|
||||
{
|
||||
"filename" : "earpods@3x.png",
|
||||
"idiom" : "universal",
|
||||
"scale" : "3x"
|
||||
}
|
||||
],
|
||||
"info" : {
|
||||
"author" : "xcode",
|
||||
"version" : 1
|
||||
}
|
||||
}
|
||||
|
After Width: | Height: | Size: 998 B |
|
After Width: | Height: | Size: 1.5 KiB |
|
After Width: | Height: | Size: 2.1 KiB |
@@ -2,17 +2,17 @@
|
||||
"images" : [
|
||||
{
|
||||
"idiom" : "universal",
|
||||
"filename" : "ContrastExam.png",
|
||||
"filename" : "Tone-Audiometry-Headphones.pdf",
|
||||
"scale" : "1x"
|
||||
},
|
||||
{
|
||||
"idiom" : "universal",
|
||||
"filename" : "ContrastExam@2x.png",
|
||||
"filename" : "Tone-Audiometry-Headphones@2x.png",
|
||||
"scale" : "2x"
|
||||
},
|
||||
{
|
||||
"idiom" : "universal",
|
||||
"filename" : "ContrastExam@3x.png",
|
||||
"filename" : "Tone-Audiometry-Headphones@3x.png",
|
||||
"scale" : "3x"
|
||||
}
|
||||
],
|
||||
|
After Width: | Height: | Size: 1.3 KiB |
|
After Width: | Height: | Size: 1.9 KiB |
|
Before Width: | Height: | Size: 606 B After Width: | Height: | Size: 606 B |
|
Before Width: | Height: | Size: 822 B After Width: | Height: | Size: 822 B |
|
Before Width: | Height: | Size: 1.2 KiB After Width: | Height: | Size: 1.2 KiB |
@@ -1,23 +0,0 @@
|
||||
{
|
||||
"images" : [
|
||||
{
|
||||
"idiom" : "universal",
|
||||
"filename" : "touchAbilityHorizontalScroll.png",
|
||||
"scale" : "1x"
|
||||
},
|
||||
{
|
||||
"idiom" : "universal",
|
||||
"filename" : "touchAbilityHorizontalScroll@2x.png",
|
||||
"scale" : "2x"
|
||||
},
|
||||
{
|
||||
"idiom" : "universal",
|
||||
"filename" : "touchAbilityHorizontalScroll@3x.png",
|
||||
"scale" : "3x"
|
||||
}
|
||||
],
|
||||
"info" : {
|
||||
"version" : 1,
|
||||
"author" : "xcode"
|
||||
}
|
||||
}
|
||||
|
Before Width: | Height: | Size: 4.2 KiB |
|
Before Width: | Height: | Size: 9.2 KiB |
|
Before Width: | Height: | Size: 16 KiB |
@@ -1,23 +0,0 @@
|
||||
{
|
||||
"images" : [
|
||||
{
|
||||
"idiom" : "universal",
|
||||
"filename" : "touchAbilityInstruction.png",
|
||||
"scale" : "1x"
|
||||
},
|
||||
{
|
||||
"idiom" : "universal",
|
||||
"filename" : "touchAbilityInstruction@2x.png",
|
||||
"scale" : "2x"
|
||||
},
|
||||
{
|
||||
"idiom" : "universal",
|
||||
"filename" : "touchAbilityInstruction@3x.png",
|
||||
"scale" : "3x"
|
||||
}
|
||||
],
|
||||
"info" : {
|
||||
"version" : 1,
|
||||
"author" : "xcode"
|
||||
}
|
||||
}
|
||||
|
Before Width: | Height: | Size: 5.6 KiB |
|
Before Width: | Height: | Size: 13 KiB |
|
Before Width: | Height: | Size: 22 KiB |
@@ -1,23 +0,0 @@
|
||||
{
|
||||
"images" : [
|
||||
{
|
||||
"idiom" : "universal",
|
||||
"filename" : "touchAbilityPinch.png",
|
||||
"scale" : "1x"
|
||||
},
|
||||
{
|
||||
"idiom" : "universal",
|
||||
"filename" : "touchAbilityPinch@2x.png",
|
||||
"scale" : "2x"
|
||||
},
|
||||
{
|
||||
"idiom" : "universal",
|
||||
"filename" : "touchAbilityPinch@3x.png",
|
||||
"scale" : "3x"
|
||||
}
|
||||
],
|
||||
"info" : {
|
||||
"version" : 1,
|
||||
"author" : "xcode"
|
||||
}
|
||||
}
|
||||
|
Before Width: | Height: | Size: 4.3 KiB |
|
Before Width: | Height: | Size: 9.0 KiB |
|
Before Width: | Height: | Size: 16 KiB |
@@ -1,23 +0,0 @@
|
||||
{
|
||||
"images" : [
|
||||
{
|
||||
"idiom" : "universal",
|
||||
"filename" : "touchAbilityRotation.png",
|
||||
"scale" : "1x"
|
||||
},
|
||||
{
|
||||
"idiom" : "universal",
|
||||
"filename" : "touchAbilityRotation@2x.png",
|
||||
"scale" : "2x"
|
||||
},
|
||||
{
|
||||
"idiom" : "universal",
|
||||
"filename" : "touchAbilityRotation@3x.png",
|
||||
"scale" : "3x"
|
||||
}
|
||||
],
|
||||
"info" : {
|
||||
"version" : 1,
|
||||
"author" : "xcode"
|
||||
}
|
||||
}
|
||||
|
Before Width: | Height: | Size: 6.5 KiB |