├── .gitignore ├── README.md ├── app ├── .gitignore ├── build.gradle ├── proguard-rules.pro └── src │ └── main │ ├── AndroidManifest.xml │ ├── ic_launcher-web.png │ ├── java │ └── com │ │ └── welltory │ │ └── dds │ │ └── android │ │ ├── MainActivity.java │ │ ├── ResultActivity.java │ │ ├── ScreenUtils.java │ │ ├── StressLevel.java │ │ └── WelltoryMeasurementUtils.java │ └── res │ ├── drawable-hdpi │ ├── image_start_bg.png │ ├── image_stress_arrow.png │ └── image_stress_level.png │ ├── drawable-mdpi │ ├── image_start_bg.png │ ├── image_stress_arrow.png │ └── image_stress_level.png │ ├── drawable-v24 │ ├── ic_launcher_background.xml │ └── ic_launcher_foreground.xml │ ├── drawable-xhdpi │ ├── image_start_bg.png │ ├── image_stress_arrow.png │ └── image_stress_level.png │ ├── drawable-xxhdpi │ ├── image_start_bg.png │ ├── image_stress_arrow.png │ └── image_stress_level.png │ ├── drawable-xxxhdpi │ ├── image_start_bg.png │ ├── image_stress_arrow.png │ └── image_stress_level.png │ ├── drawable │ ├── bg_result_widget.xml │ ├── bg_tag.xml │ ├── button.xml │ ├── ic_help.xml │ ├── ic_launcher_background.xml │ ├── ic_launcher_foreground.xml │ └── ic_welltory.xml │ ├── font │ ├── proxima.xml │ ├── proxima_bold.otf │ └── proxima_reg.otf │ ├── layout │ ├── activity_main.xml │ ├── activity_result.xml │ ├── view_extra_param.xml │ └── view_result.xml │ ├── mipmap-anydpi-v26 │ ├── ic_launcher.xml │ └── ic_launcher_round.xml │ ├── mipmap-hdpi │ ├── ic_launcher.png │ └── ic_launcher_round.png │ ├── mipmap-mdpi │ ├── ic_launcher.png │ └── ic_launcher_round.png │ ├── mipmap-xhdpi │ ├── ic_launcher.png │ └── ic_launcher_round.png │ ├── mipmap-xxhdpi │ ├── ic_launcher.png │ └── ic_launcher_round.png │ ├── mipmap-xxxhdpi │ ├── ic_launcher.png │ └── ic_launcher_round.png │ └── values │ ├── attrs.xml │ ├── colors.xml │ ├── strings.xml │ └── styles.xml ├── build.gradle ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── screens ├── Frame.jpg ├── screen_1.jpg ├── screen_2.jpg ├── screen_3.jpg └── screen_4.jpg └── settings.gradle /.gitignore: -------------------------------------------------------------------------------- 1 | *.iml 2 | .gradle 3 | /local.properties 4 | /.idea/workspace.xml 5 | /.idea/libraries 6 | .DS_Store 7 | /build 8 | /captures 9 | .idea/ 10 | .phraseapp.yml 11 | app/.externalNativeBuild 12 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Welltory Integration Android Demo 2 | 3 |

4 | Welltory flow 5 |

6 | 7 | This demo app is intended for people who want to integrate with Welltory app to collect stress, energy and other HRV data about their users. The Demo app demonstrates how your app can work with Welltory. This integration is free and it’s created to help you add value for your users who already use Welltory. [Read more here](#install) 8 | 9 | To become an integration partner - [apply here](https://welltory.typeform.com/to/epJ3PR) 10 | 11 | 12 | Welltory is an app that measures people’s HRV with just a smartphone camera to calculate their stress and energy levels. You can redirect users to our app and direct them back to your app with measurement results. Welltory integration will allow you to collect data of the following parameters: 13 | 14 | * Stress (Welltory's proprietary algorithm trained on millions of measurements) 15 | * Energy (Welltory's proprietary algorithm trained on millions of measurements) 16 | * Productivity index (Welltory's proprietary algorithm trained on millions of measurements) 17 | * RMSSD index 18 | * SDNN index 19 | * Total power 20 | 21 | This demo is to demonstrate: 22 | * how the user is navigated from your app to the App Store, 23 | * how the measurement is taken, 24 | * a request asking the user to share the results of the measurement with your app, 25 | * the return to your application, 26 | * a sample of results presentation, 27 | and also the source code of the integration. 28 | 29 | Continue reading for installation. 30 | 31 | ### Table of Contents 32 | 1. [How to install](#install) 33 | 1. [Requirements](#requirements) 34 | 2. [Installation guide](#guide) 35 | 2. [Example usage](#usage) 36 | 3. [Integration](#integration) 37 | 4. [Measurement request](#request) 38 | 1. [Measurement request link and parameters](#link) 39 | 2. [Package visibility](#package_visibility) 40 | 5. [Stress results overview](#result) 41 | 1. [Configure your app to add it the list of approved domains](#configure_domain) 42 | 2. [Configure your website to host the 'apple-app-site-association' file](#configure_aasa) 43 | 6. [Stress results processing](#result_processing) 44 | 7. [Demo Applications](#demo) 45 | 8. [Questions](#questions) 46 | 9. [License and author info](#license) 47 | 48 | # How to install 49 | 50 | ### Requirements: 51 | 52 | * Android Studio 3.5 or later 53 | 54 | No additional tools required. 55 | 56 | ### Installation guide: 57 | 58 | * Clone the repository master brunch using ``` git clone https://github.com/Welltory/measure-stress-hrv-android.git ``` 59 | * Open project directory with the Android Studio 3.5+ 60 | * Run the project 61 | 62 | # Example usage 63 | 64 | 1. In the DDS Example application press "Measure now" button to start measurement 65 |

66 | Measure now 67 |

68 | 69 | 2. Welltory application will launch and automatically starts a measurement 70 |

71 | Measurement process 72 |

73 | 74 | 3. After measurement complete, results sharing window will appear 75 |

76 | Measurement result 77 |

78 | 79 | 4. After user presses "ok, let's do it" button measurement results and user controll pull back to the DDS application 80 |

81 | Presenting result 82 |

83 | 84 | 85 | # Integration 86 | 87 | Welltory doesn't provide any integration SDKs, all applications interaction are performed with intents. 88 | 89 | **You should start your integration filling out an [Integration Request Form](https://welltory.typeform.com/to/epJ3PR).** 90 | 91 | Please send us a live chat message [on our website](https://welltory.com/) if you have any questions. 92 | 93 | 94 | # Measurement request 95 | 96 | To start a measurement you should send URI intent 97 | 98 | Important: The intent link changes depending on whether Welltory is installed or not. 99 | 100 | ### Package visibility 101 | https://developer.android.com/training/package-visibility 102 | 103 | For apps with **targetSdkVersion** >= 30 you should add the following code to AndroidManifest.xml: 104 | ```java 105 | 106 | 107 | 108 | 109 | 110 | 111 | ``` 112 | 113 | ### Measurement request link 114 | 115 | For the very first measurement from your application, launch the following link: [https://play.google.com/store/apps/details?id=com.welltory.client.android&referrer=](#) 116 | 117 | Where the **referrer** contains: 118 | 119 | * source - Your application name. Will be displayed in Welltory interfaces. 120 | * callback - The application package and activity name divided with "/" symbol, to pass result data. ```com.welltory.dds.android/com.welltory.dds.android.MainActivity```, for example 121 | * other parameters - [optionally] list of parameters to pass with measurement results. If you want to pass your own parameters to the measurement result, you should add them as query parameters to the URI 122 | 123 | `Important: we DON’T save parameters in a database`\ 124 | `Important: Activity should have android:exported=”true” configuration` 125 | 126 | 127 | It will take the user to the measurement screen in case Welltory is installed, or redirect them to Google Play page to install it. 128 | 129 | Example: 130 | [https://play.google.com/store/apps/details?id=com.welltory.client.android&referrer=source%3DYourApp%26callback%3Dcom.welltory.dds.android%2Fcom.welltory.dds.android.MainActivity%26param1%3Dtest_param1](#) 131 | 132 | -------- 133 | 134 | Every following measurement request should be done using direct Welltory link: [welltory://branch/Measurement/Start/](#) 135 | 136 | 137 | Where the **utf_8_encoded_params** contains: 138 | 139 | * source - Your application name. Will be displayed in Welltory interfaces. 140 | * callback - The application package and activity name divided with "/" symbol, to pass result data. ```com.welltory.dds.android/com.welltory.dds.android.MainActivity```, for example 141 | * other parameters - [optionally] list of parameters to pass with measurement results. If you want to pass your own parameters to the measurement result, you should add them as query parameters to the URI 142 | 143 | `Important: we DON’T save parameters in a database`\ 144 | `Important: Activity should have android:exported=”true” configuration` 145 | 146 | Example: [welltory://branch/Measurement/Start/source%3DYourApp%26callback%3Dcom.welltory.dds.android%2Fcom.welltory.dds.android.MainActivity%26param1%3Dtest_param1](#) 147 | 148 | `Important: Execute Intent with FLAG_ACTIVITY_NEW_TASK and FLAG_ACTIVITY_CLEAR_TOP flags, to avoid a duplication of partner’s application instances.` 149 | 150 | Examples: 151 | 152 | ```java 153 | 154 | String callBackActivity = String.format(Locale.getDefault(), "%s/%s", 155 | activity.getPackageName(), activity.getClass().getName()); 156 | String params = String.format(Locale.getDefault(), 157 | "source=%s&callback=%s¶m1=test_param1", "YourApp", callBackActivity); 158 | Intent intent = null; 159 | try { 160 | String encodedParams = URLEncoder.encode(params, "UTF-8"); 161 | intent = new Intent(Intent.ACTION_VIEW, Uri.parse("welltory://branch/Measurement/Start/" + encodedParams)); 162 | if (intent.resolveActivity(activity.getPackageManager()) == null) { 163 | intent = new Intent(Intent.ACTION_VIEW, Uri.parse("https://play.google.com/store/apps/details?id=com.welltory.client.android&referrer=" + encodedParams)); 164 | } 165 | } catch (UnsupportedEncodingException e) { 166 | e.printStackTrace(); 167 | } 168 | if (intent != null) { 169 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP); 170 | activity.startActivity(intent); 171 | } 172 | 173 | 174 | ``` 175 | 176 | 177 | # Stress results overview 178 | 179 | After the user data has been processed, Welltory application will use your **callback** activity to send measurement results to your application. 180 | Welltory will put the following parameters into intent extras: 181 | 182 | 183 | | name | type | description | 184 | | ------ | ------ | ------ | 185 | | stress | Float (0.0 - 1.0) | user's stress % | 186 | | energy | Float (0.0 - 1.0) | user's energy % | 187 | | productivity | Float (0.0 - 1.0) | user's productivity % | 188 | | rmssd | Float | user's rmssd index | 189 | | sdnn | Float | user's sdnn index | 190 | | power | Float | user's power index | 191 | | token | String | Measurement share token. It allows to open a measurement webpage https://app.welltory.com/share-measurement?token= | 192 | | productivity_c | String | Productivity parameter interpretation color | 193 | | energy_c | String | Energy parameter interpretation color | 194 | | stress_c | String | Stress parameter interpretation color | 195 | | other parameters | String | Your custom parameters with keys and values you passed with URI 196 | 197 | Colours: 198 | * green - Good 199 | * yellow - Normal 200 | * red - Bad 201 | * unknown - Unknown 202 | 203 | # Stress results processing 204 | 205 | After `startActivity` is called, partner’s application should expect for results in `onNewIntent` or `onCreate` function (in case Android kills application's activity). \ 206 | Measurement results could be fetched from the Intent by calling `Intent.getFloatExta` 207 | 208 | Example: 209 | ```java 210 | @Override 211 | protected void onNewIntent(Intent intent) { 212 | super.onNewIntent(intent); 213 | resultView.setText(parseIntent(intent)); 214 | } 215 | 216 | private String parseIntent(Intent data) { 217 | if (data != null && data.hasExtra("stress")) { 218 | return String.format(Locale.getDefault(), "productivity=%s\nrmssd=%s\nenergy=%s\npower=%s\nstress=%s\nsdnn=%s", 219 | data.getFloatExtra("productivity", -1), 220 | data.getFloatExtra("rmssd", -1), 221 | data.getFloatExtra("energy", -1), 222 | data.getFloatExtra("power", -1), 223 | data.getFloatExtra("stress", -1), 224 | data.getFloatExtra("sdnn", -1)); 225 | } else { 226 | return null; 227 | } 228 | } 229 | ``` 230 | 231 | # Demo Applications 232 | This repository contains a working Demo DDS application. 233 | 234 | 235 | # Questions? 236 | If you have questions about the partnership, send us a live chat message [on our website](https://welltory.com/) 237 | 238 | # License and author info 239 | 240 | ``` 241 | Welltory Integration Android Example 242 | 243 | The MIT License (MIT) 244 | 245 | Copyright (c) 2019 Welltory Integration Android 246 | 247 | Permission is hereby granted, free of charge, to any person obtaining a copy 248 | of this software and associated documentation files (the "Software"), to deal 249 | in the Software without restriction, including without limitation the rights 250 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 251 | copies of the Software, and to permit persons to whom the Software is 252 | furnished to do so, subject to the following conditions: 253 | 254 | The above copyright notice and this permission notice shall be included in 255 | all copies or substantial portions of the Software. 256 | 257 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 258 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 259 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 260 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 261 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 262 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 263 | THE SOFTWARE. 264 | ``` 265 | -------------------------------------------------------------------------------- /app/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /app/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | 3 | android { 4 | compileSdkVersion 30 5 | buildToolsVersion "30.0.3" 6 | defaultConfig { 7 | applicationId "com.welltory.dds.android" 8 | minSdkVersion 21 9 | targetSdkVersion 30 10 | versionCode 1 11 | versionName "1.0" 12 | } 13 | buildTypes { 14 | release { 15 | minifyEnabled false 16 | proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' 17 | } 18 | } 19 | } 20 | 21 | dependencies { 22 | implementation fileTree(dir: 'libs', include: ['*.jar']) 23 | implementation 'androidx.appcompat:appcompat:1.0.2' 24 | implementation 'androidx.constraintlayout:constraintlayout:1.1.3' 25 | } 26 | -------------------------------------------------------------------------------- /app/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # You can control the set of applied configuration files using the 3 | # proguardFiles setting in build.gradle. 4 | # 5 | # For more details, see 6 | # http://developer.android.com/guide/developing/tools/proguard.html 7 | 8 | # If your project uses WebView with JS, uncomment the following 9 | # and specify the fully qualified class name to the JavaScript interface 10 | # class: 11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 12 | # public *; 13 | #} 14 | 15 | # Uncomment this to preserve the line number information for 16 | # debugging stack traces. 17 | #-keepattributes SourceFile,LineNumberTable 18 | 19 | # If you keep the line number information, uncomment this to 20 | # hide the original source file name. 21 | #-renamesourcefileattribute SourceFile 22 | -------------------------------------------------------------------------------- /app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 33 | 34 | 35 | -------------------------------------------------------------------------------- /app/src/main/ic_launcher-web.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/phpblackbox/measure-stress-hrv-android/a0f35d8bcbd46ee7106f5a67665afadf772aaa9d/app/src/main/ic_launcher-web.png -------------------------------------------------------------------------------- /app/src/main/java/com/welltory/dds/android/MainActivity.java: -------------------------------------------------------------------------------- 1 | 2 | package com.welltory.dds.android; 3 | 4 | import android.content.Intent; 5 | import android.os.Bundle; 6 | import android.view.View; 7 | 8 | import androidx.appcompat.app.AppCompatActivity; 9 | 10 | public class MainActivity extends AppCompatActivity { 11 | 12 | @Override 13 | protected void onCreate(Bundle savedInstanceState) { 14 | super.onCreate(savedInstanceState); 15 | setContentView(R.layout.activity_main); 16 | parseIntent(getIntent()); 17 | findViewById(R.id.button).setOnClickListener(new View.OnClickListener() { 18 | @Override 19 | public void onClick(View v) { 20 | WelltoryMeasurementUtils.startMeasurement(MainActivity.this); 21 | } 22 | }); 23 | } 24 | 25 | @Override 26 | protected void onNewIntent(Intent intent) { 27 | super.onNewIntent(intent); 28 | parseIntent(intent); 29 | } 30 | 31 | private void parseIntent(Intent data) { 32 | if (data != null && data.hasExtra("stress")) { 33 | startActivity(ResultActivity.startIntent(this, data.getExtras())); 34 | finish(); 35 | } 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /app/src/main/java/com/welltory/dds/android/ResultActivity.java: -------------------------------------------------------------------------------- 1 | package com.welltory.dds.android; 2 | 3 | import android.content.Context; 4 | import android.content.Intent; 5 | import android.graphics.drawable.GradientDrawable; 6 | import android.net.Uri; 7 | import android.os.Bundle; 8 | import android.view.LayoutInflater; 9 | import android.view.View; 10 | import android.view.ViewGroup; 11 | import android.widget.LinearLayout; 12 | import android.widget.TextView; 13 | 14 | import androidx.annotation.Nullable; 15 | import androidx.appcompat.app.AppCompatActivity; 16 | import androidx.core.content.ContextCompat; 17 | 18 | import java.util.ArrayList; 19 | import java.util.Locale; 20 | 21 | /** 22 | * Created: Belozerov Sergei 23 | * Company: Welltory Inc. 24 | * Date: 2019-09-04 25 | */ 26 | public class ResultActivity extends AppCompatActivity { 27 | private StressLevel stressLevel = null; 28 | private TextView stressLevelText = null; 29 | private TextView stressLevelPercent = null; 30 | private TextView detailsButton = null; 31 | private LinearLayout extraParamsContainer = null; 32 | private static final String PROD_TOKEN_URL = "https://app.welltory.com/share-measurement?token=%s"; 33 | private static final String STAGE_TOKEN_URL = "https://stage-app.welltory.com/share-measurement?token=%s"; 34 | 35 | public static final String EXTRA_STRESS = "stress"; 36 | public static final String EXTRA_STRESS_LEVEL = "stress_c"; 37 | public static final String EXTRA_TOKEN = "token"; 38 | public static final String EXTRA_IS_STAGE = "is_stage_server"; 39 | public static final String EXTRA_ENERGY = "energy"; 40 | public static final String EXTRA_PRODUCTIVITY = "productivity"; 41 | public static final String EXTRA_RMSSD = "rmssd"; 42 | public static final String EXTRA_SDNN = "sdnn"; 43 | 44 | @Override 45 | protected void onCreate(@Nullable Bundle savedInstanceState) { 46 | super.onCreate(savedInstanceState); 47 | setContentView(R.layout.activity_result); 48 | initViews(); 49 | initClickListeners(); 50 | 51 | parseIntent(getIntent()); 52 | } 53 | 54 | @Override 55 | protected void onNewIntent(Intent intent) { 56 | super.onNewIntent(intent); 57 | parseIntent(intent); 58 | } 59 | 60 | private void initClickListeners() { 61 | findViewById(R.id.help).setOnClickListener(new View.OnClickListener() { 62 | @Override 63 | public void onClick(View v) { 64 | Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("https://support.welltory.com/article/show/68986-how-to-use-your-measurement-results")); 65 | startActivity(intent); 66 | } 67 | }); 68 | findViewById(R.id.repeatButton).setOnClickListener(new View.OnClickListener() { 69 | @Override 70 | public void onClick(View v) { 71 | WelltoryMeasurementUtils.startMeasurement(ResultActivity.this); 72 | } 73 | }); 74 | } 75 | 76 | private void initViews() { 77 | stressLevel = findViewById(R.id.stressLevel); 78 | stressLevelPercent = findViewById(R.id.stressLevelPercent); 79 | stressLevelText = findViewById(R.id.stressLevelText); 80 | detailsButton = findViewById(R.id.details); 81 | extraParamsContainer = findViewById(R.id.extraParams); 82 | } 83 | 84 | public static Intent startIntent(Context context, Bundle extras) { 85 | Intent intent = new Intent(context, ResultActivity.class); 86 | intent.putExtras(extras); 87 | return intent; 88 | } 89 | 90 | private void parseIntent(Intent intent) { 91 | float stress = intent.getFloatExtra(EXTRA_STRESS, 0); 92 | String level = intent.getStringExtra(EXTRA_STRESS_LEVEL); 93 | final String token = intent.getStringExtra(EXTRA_TOKEN); 94 | if (level == null) 95 | level = "green"; 96 | stressLevelPercent.setText(String.format(Locale.getDefault(), "%.0f%%", stress * 100)); 97 | GradientDrawable shape = new GradientDrawable(); 98 | shape.setShape(GradientDrawable.RECTANGLE); 99 | shape.setCornerRadius(ScreenUtils.dp(this, 10)); 100 | String stressText = "Unknown"; 101 | switch (level) { 102 | case "green": 103 | stressText = getString(R.string.stressLevelGood); 104 | shape.setColor(ContextCompat.getColor(this, R.color.green)); 105 | break; 106 | case "yellow": 107 | stressText = getString(R.string.stressLevelAverage); 108 | shape.setColor(ContextCompat.getColor(this, R.color.yellow)); 109 | break; 110 | case "red": 111 | stressText = getString(R.string.stressLevelBad); 112 | shape.setColor(ContextCompat.getColor(this, R.color.red)); 113 | break; 114 | case "unknown": 115 | shape.setColor(ContextCompat.getColor(this, R.color.grey_6_40)); 116 | break; 117 | } 118 | stressLevelText.setText(stressText); 119 | stressLevelPercent.setBackground(shape); 120 | stressLevel.setStress(stress); 121 | 122 | detailsButton.setOnClickListener(new View.OnClickListener() { 123 | @Override 124 | public void onClick(View v) { 125 | if (token != null) { 126 | boolean isStage = getIntent().getBooleanExtra(EXTRA_IS_STAGE, false); 127 | Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(String.format(Locale.getDefault(), isStage ? STAGE_TOKEN_URL : PROD_TOKEN_URL, token))); 128 | startActivity(intent); 129 | } 130 | } 131 | }); 132 | 133 | addExtraParamsViews(intent); 134 | } 135 | 136 | private void addExtraParamsViews(Intent intent) { 137 | ArrayList extraParams = new ArrayList<>(); 138 | extraParams.add(new ExtraParam(getString(R.string.energy), 139 | getString(R.string.percentValue, intent.getFloatExtra(EXTRA_ENERGY, 0) * 100))); 140 | extraParams.add(new ExtraParam(getString(R.string.productivity), 141 | getString(R.string.percentValue, intent.getFloatExtra(EXTRA_PRODUCTIVITY, 0) * 100))); 142 | extraParams.add(new ExtraParam(getString(R.string.rmssd), 143 | getString(R.string.msValue, intent.getFloatExtra(EXTRA_RMSSD, 0)))); 144 | extraParams.add(new ExtraParam(getString(R.string.sdnn), 145 | getString(R.string.msValue, intent.getFloatExtra(EXTRA_SDNN, 0)))); 146 | 147 | extraParamsContainer.removeAllViews(); 148 | for (ExtraParam extraParam : extraParams) { 149 | View view = LayoutInflater.from(this).inflate(R.layout.view_extra_param, extraParamsContainer, false); 150 | LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(0, ViewGroup.LayoutParams.WRAP_CONTENT); 151 | layoutParams.weight = 1; 152 | ((TextView) view.findViewById(R.id.title)).setText(extraParam.name); 153 | ((TextView) view.findViewById(R.id.value)).setText(extraParam.value); 154 | extraParamsContainer.addView(view, layoutParams); 155 | } 156 | } 157 | 158 | private class ExtraParam { 159 | String name; 160 | String value; 161 | 162 | public ExtraParam(String name, String value) { 163 | this.name = name; 164 | this.value = value; 165 | } 166 | } 167 | } 168 | -------------------------------------------------------------------------------- /app/src/main/java/com/welltory/dds/android/ScreenUtils.java: -------------------------------------------------------------------------------- 1 | package com.welltory.dds.android; 2 | 3 | import android.content.Context; 4 | import android.util.DisplayMetrics; 5 | import android.util.TypedValue; 6 | 7 | /** 8 | * Created: Belozerov Sergei 9 | * Company: Welltory Inc. 10 | * Date: 2019-09-06 11 | */ 12 | public class ScreenUtils { 13 | public static int dp(Context context, float dipValue) { 14 | DisplayMetrics metrics = context.getResources().getDisplayMetrics(); 15 | return (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dipValue, metrics); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /app/src/main/java/com/welltory/dds/android/StressLevel.java: -------------------------------------------------------------------------------- 1 | package com.welltory.dds.android; 2 | 3 | import android.content.Context; 4 | import android.content.res.TypedArray; 5 | import android.graphics.Bitmap; 6 | import android.graphics.BitmapFactory; 7 | import android.graphics.Canvas; 8 | import android.graphics.Paint; 9 | import android.util.AttributeSet; 10 | import android.view.View; 11 | 12 | import androidx.annotation.Nullable; 13 | 14 | /** 15 | * Created: Belozerov Sergei 16 | * Company: Welltory Inc. 17 | * Date: 2019-09-05 18 | */ 19 | public class StressLevel extends View { 20 | 21 | private Bitmap bgBitmap; 22 | private Paint bitmapPaint = new Paint(); 23 | private Bitmap arrowBitmap; 24 | 25 | private float angle = 0; 26 | 27 | public void setStress(float stress) { 28 | setAngle(stress * 180f); 29 | } 30 | 31 | public float getAngle() { 32 | return angle; 33 | } 34 | 35 | public void setAngle(float angle) { 36 | this.angle = angle; 37 | } 38 | 39 | public StressLevel(Context context) { 40 | this(context, null); 41 | } 42 | 43 | public StressLevel(Context context, @Nullable AttributeSet attrs) { 44 | this(context, attrs, 0); 45 | } 46 | 47 | public StressLevel(Context context, @Nullable AttributeSet attrs, int defStyleAttr) { 48 | this(context, attrs, defStyleAttr, 0); 49 | } 50 | 51 | public StressLevel(Context context, @Nullable AttributeSet attrs, int defStyleAttr, int defStyleRes) { 52 | super(context, attrs, defStyleAttr, defStyleRes); 53 | if (attrs != null) { 54 | TypedArray typedArray = getContext().obtainStyledAttributes(attrs, R.styleable.StressLevel, 0, 0); 55 | angle = typedArray.getFloat(R.styleable.StressLevel_sl_angle, 0); 56 | typedArray.recycle(); 57 | } 58 | bitmapPaint.setAntiAlias(true); 59 | bgBitmap = BitmapFactory.decodeResource(context.getResources(), R.drawable.image_stress_level); 60 | arrowBitmap = BitmapFactory.decodeResource(context.getResources(), R.drawable.image_stress_arrow); 61 | } 62 | 63 | @Override 64 | protected void onDraw(Canvas canvas) { 65 | super.onDraw(canvas); 66 | canvas.drawBitmap(bgBitmap, (getWidth() - bgBitmap.getWidth()) / 2f, getHeight() - bgBitmap.getHeight(), bitmapPaint); 67 | canvas.save(); 68 | canvas.rotate(angle, getWidth() / 2, getHeight()); 69 | canvas.drawBitmap(arrowBitmap, 0, getHeight() - arrowBitmap.getHeight() / 2f, bitmapPaint); 70 | canvas.restore(); 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /app/src/main/java/com/welltory/dds/android/WelltoryMeasurementUtils.java: -------------------------------------------------------------------------------- 1 | package com.welltory.dds.android; 2 | 3 | import android.app.Activity; 4 | import android.content.Intent; 5 | import android.net.Uri; 6 | 7 | import java.io.UnsupportedEncodingException; 8 | import java.net.URLEncoder; 9 | import java.util.Locale; 10 | 11 | /** 12 | * Created: Belozerov Sergei 13 | * Company: Welltory Inc. 14 | * Date: 2019-09-06 15 | */ 16 | public class WelltoryMeasurementUtils { 17 | public static void startMeasurement(Activity activity) { 18 | String callBackActivity = String.format(Locale.getDefault(), "%s/%s", 19 | activity.getPackageName(), activity.getClass().getName()); 20 | String params = String.format(Locale.getDefault(), 21 | "source=%s&callback=%s¶m1=test_param1", "DemoApp", callBackActivity); 22 | Intent intent = null; 23 | try { 24 | String encodedParams = URLEncoder.encode(params, "UTF-8"); 25 | intent = new Intent(Intent.ACTION_VIEW, Uri.parse("welltory://branch/Measurement/Start/" + encodedParams)); 26 | if (intent.resolveActivity(activity.getPackageManager()) == null) { 27 | intent = new Intent(Intent.ACTION_VIEW, Uri.parse("https://play.google.com/store/apps/details?id=com.welltory.client.android&referrer=" + encodedParams)); 28 | } 29 | } catch (UnsupportedEncodingException e) { 30 | e.printStackTrace(); 31 | } 32 | if (intent != null) { 33 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP); 34 | activity.startActivity(intent); 35 | } 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /app/src/main/res/drawable-hdpi/image_start_bg.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/phpblackbox/measure-stress-hrv-android/a0f35d8bcbd46ee7106f5a67665afadf772aaa9d/app/src/main/res/drawable-hdpi/image_start_bg.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-hdpi/image_stress_arrow.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/phpblackbox/measure-stress-hrv-android/a0f35d8bcbd46ee7106f5a67665afadf772aaa9d/app/src/main/res/drawable-hdpi/image_stress_arrow.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-hdpi/image_stress_level.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/phpblackbox/measure-stress-hrv-android/a0f35d8bcbd46ee7106f5a67665afadf772aaa9d/app/src/main/res/drawable-hdpi/image_stress_level.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-mdpi/image_start_bg.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/phpblackbox/measure-stress-hrv-android/a0f35d8bcbd46ee7106f5a67665afadf772aaa9d/app/src/main/res/drawable-mdpi/image_start_bg.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-mdpi/image_stress_arrow.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/phpblackbox/measure-stress-hrv-android/a0f35d8bcbd46ee7106f5a67665afadf772aaa9d/app/src/main/res/drawable-mdpi/image_stress_arrow.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-mdpi/image_stress_level.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/phpblackbox/measure-stress-hrv-android/a0f35d8bcbd46ee7106f5a67665afadf772aaa9d/app/src/main/res/drawable-mdpi/image_stress_level.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-v24/ic_launcher_background.xml: -------------------------------------------------------------------------------- 1 | 7 | 10 | 11 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /app/src/main/res/drawable-v24/ic_launcher_foreground.xml: -------------------------------------------------------------------------------- 1 | 6 | 8 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /app/src/main/res/drawable-xhdpi/image_start_bg.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/phpblackbox/measure-stress-hrv-android/a0f35d8bcbd46ee7106f5a67665afadf772aaa9d/app/src/main/res/drawable-xhdpi/image_start_bg.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-xhdpi/image_stress_arrow.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/phpblackbox/measure-stress-hrv-android/a0f35d8bcbd46ee7106f5a67665afadf772aaa9d/app/src/main/res/drawable-xhdpi/image_stress_arrow.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-xhdpi/image_stress_level.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/phpblackbox/measure-stress-hrv-android/a0f35d8bcbd46ee7106f5a67665afadf772aaa9d/app/src/main/res/drawable-xhdpi/image_stress_level.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-xxhdpi/image_start_bg.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/phpblackbox/measure-stress-hrv-android/a0f35d8bcbd46ee7106f5a67665afadf772aaa9d/app/src/main/res/drawable-xxhdpi/image_start_bg.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-xxhdpi/image_stress_arrow.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/phpblackbox/measure-stress-hrv-android/a0f35d8bcbd46ee7106f5a67665afadf772aaa9d/app/src/main/res/drawable-xxhdpi/image_stress_arrow.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-xxhdpi/image_stress_level.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/phpblackbox/measure-stress-hrv-android/a0f35d8bcbd46ee7106f5a67665afadf772aaa9d/app/src/main/res/drawable-xxhdpi/image_stress_level.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-xxxhdpi/image_start_bg.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/phpblackbox/measure-stress-hrv-android/a0f35d8bcbd46ee7106f5a67665afadf772aaa9d/app/src/main/res/drawable-xxxhdpi/image_start_bg.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-xxxhdpi/image_stress_arrow.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/phpblackbox/measure-stress-hrv-android/a0f35d8bcbd46ee7106f5a67665afadf772aaa9d/app/src/main/res/drawable-xxxhdpi/image_stress_arrow.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-xxxhdpi/image_stress_level.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/phpblackbox/measure-stress-hrv-android/a0f35d8bcbd46ee7106f5a67665afadf772aaa9d/app/src/main/res/drawable-xxxhdpi/image_stress_level.png -------------------------------------------------------------------------------- /app/src/main/res/drawable/bg_result_widget.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/bg_tag.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/button.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_help.xml: -------------------------------------------------------------------------------- 1 | 6 | 10 | 16 | 17 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_launcher_background.xml: -------------------------------------------------------------------------------- 1 | 7 | 10 | 11 | 17 | 18 | 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_launcher_foreground.xml: -------------------------------------------------------------------------------- 1 | 6 | 8 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_welltory.xml: -------------------------------------------------------------------------------- 1 | 7 | 10 | 11 | 17 | 18 | 19 | 20 | 21 | 22 | 25 | 27 | 28 | 34 | 35 | 36 | 37 | 38 | 39 | 42 | 45 | 48 | 51 | 55 | 56 | -------------------------------------------------------------------------------- /app/src/main/res/font/proxima.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 7 | 8 | 12 | 13 | -------------------------------------------------------------------------------- /app/src/main/res/font/proxima_bold.otf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/phpblackbox/measure-stress-hrv-android/a0f35d8bcbd46ee7106f5a67665afadf772aaa9d/app/src/main/res/font/proxima_bold.otf -------------------------------------------------------------------------------- /app/src/main/res/font/proxima_reg.otf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/phpblackbox/measure-stress-hrv-android/a0f35d8bcbd46ee7106f5a67665afadf772aaa9d/app/src/main/res/font/proxima_reg.otf -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 9 | 10 | 11 |