├── .gitignore ├── 48677318581_445c3214d8_k.jpg ├── 48677490747_2eb7ffc006_k.jpg ├── 48677491947_a06fae30bc_kz.jpg ├── 49413920108_e256778ce2_k.jpg ├── LICENSE ├── README.md ├── app ├── .gitignore ├── build.gradle ├── proguard-rules.pro └── src │ └── main │ ├── AndroidManifest.xml │ ├── java │ └── com │ │ └── specialprojects │ │ └── experiments │ │ └── envelopecall │ │ ├── EnvelopeCallApp.kt │ │ ├── FileDownloader.kt │ │ ├── audio │ │ ├── DTMF.kt │ │ ├── DTMFPlayer.kt │ │ └── SoundPoolHolder.kt │ │ ├── contants.kt │ │ ├── prefs │ │ ├── BooleanPreference.kt │ │ └── LongPreference.kt │ │ ├── sensor │ │ └── ProximitySensor.kt │ │ ├── telephony │ │ ├── CallService.kt │ │ └── CallState.kt │ │ └── ui │ │ ├── HelpActivity.kt │ │ ├── HomeActivity.kt │ │ ├── SplashActivity.kt │ │ ├── StatisticsActivity.kt │ │ ├── adapters │ │ └── BindableAdapter.kt │ │ ├── call │ │ └── CallActivity.kt │ │ ├── onboarding │ │ ├── OnboardingActivity.kt │ │ └── OnboardingAdapter.kt │ │ └── util │ │ └── Views.kt │ └── res │ ├── drawable │ ├── btn_clock_background.xml │ ├── btn_clock_background_ready.xml │ ├── btn_dial_background.xml │ ├── btn_dial_background_black.xml │ ├── btn_dial_background_ready.xml │ ├── call_button_ready_state.xml │ ├── call_button_state.xml │ ├── ic_app_icon.xml │ ├── ic_close_white_24dp.xml │ ├── ic_launcher_foreground.xml │ ├── ic_logo.xml │ └── splash_background.xml │ ├── font │ ├── dmsans_regular.ttf │ └── varela_regular.otf │ ├── layout │ ├── activity_countdown.xml │ ├── activity_help.xml │ ├── activity_home.xml │ ├── activity_main.xml │ ├── activity_onboarding.xml │ ├── activity_statistics.xml │ └── list_item_onboarding.xml │ ├── mipmap-anydpi-v26 │ ├── ic_launcher.xml │ └── ic_launcher_round.xml │ ├── raw │ ├── dtmf_0.mp3 │ ├── dtmf_1.mp3 │ ├── dtmf_2.mp3 │ ├── dtmf_3.mp3 │ ├── dtmf_4.mp3 │ ├── dtmf_5.mp3 │ ├── dtmf_6.mp3 │ ├── dtmf_7.mp3 │ ├── dtmf_8.mp3 │ ├── dtmf_9.mp3 │ ├── dtmf_hash.mp3 │ ├── dtmf_star.mp3 │ ├── hour_1.mp3 │ ├── hour_2.mp3 │ ├── minutes_1.mp3 │ ├── minutes_2.mp3 │ └── unlock.mp3 │ └── values │ ├── colors.xml │ ├── dimens.xml │ ├── ic_launcher_background.xml │ ├── strings.xml │ └── styles.xml ├── build.gradle ├── google-unplugged-envelope-instructions.pdf ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat └── settings.gradle /.gitignore: -------------------------------------------------------------------------------- 1 | # IDEA 2 | *.iml 3 | /.idea 4 | !/.idea/runConfigurations 5 | 6 | # Gradle 7 | .gradle 8 | build 9 | /reports 10 | 11 | # Gradle Android 12 | /local.properties 13 | 14 | # OSX 15 | .DS_Store 16 | -------------------------------------------------------------------------------- /48677318581_445c3214d8_k.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/specialprojects-experiments/envelope/b9361b593ac102e9e8a6b9fbfd7ba15dd72b7c0b/48677318581_445c3214d8_k.jpg -------------------------------------------------------------------------------- /48677490747_2eb7ffc006_k.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/specialprojects-experiments/envelope/b9361b593ac102e9e8a6b9fbfd7ba15dd72b7c0b/48677490747_2eb7ffc006_k.jpg -------------------------------------------------------------------------------- /48677491947_a06fae30bc_kz.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/specialprojects-experiments/envelope/b9361b593ac102e9e8a6b9fbfd7ba15dd72b7c0b/48677491947_a06fae30bc_kz.jpg -------------------------------------------------------------------------------- /49413920108_e256778ce2_k.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/specialprojects-experiments/envelope/b9361b593ac102e9e8a6b9fbfd7ba15dd72b7c0b/49413920108_e256778ce2_k.jpg -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright [yyyy] [name of copyright owner] 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Envelope 2 | 3 | https://youtu.be/Au14zEGkRaQ 4 | 5 | A set of envelopes which temporarily transform your phone into a simpler, calmer device, helping you take a break away from your digital world. 6 | One envelope turns your phone into a very basic device which can only make and receive calls, while the other turns your phone into a photo and video camera with no screen, helping you focus on what’s in front of you. 7 | 8 | ![Envelope Image](48677491947_a06fae30bc_kz.jpg) 9 | 10 | Please note this currently only works on the Google Pixel 3a 11 | 12 | This code is for an app which lets you use an envelope to make and receive calls only. 13 | Once inside an envelope your device will act as a simple phone, which only allows you to make and receive calls. 14 | 15 | ![Envelope Image](48677490747_2eb7ffc006_k.jpg) 16 | 17 | We hope this little experiment can help you try a digital detox from technology and help you focus on the things that matter the most. 18 | 19 | Envelope is an experimental open source Android app which is available to try right now. All of the code is available on Github for people to play with and hopefully adapt and evolve! 20 | 21 | ![Envelope Image](49413920108_e256778ce2_k.jpg) 22 | 23 | [Download the DIY envelope pdf for the Pixel 3a](https://github.com/specialprojects-experiments/envelope/blob/master/google-unplugged-envelope-instructions.pdf) 24 | 25 | [Try the app on the Google Play Store](https://play.google.com/store/apps/details?id=com.specialprojects.experiments.envelopecall) 26 | 27 | [Find out even more on our site](http://specialprojects.studio/project/envelope) 28 | -------------------------------------------------------------------------------- /app/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /app/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | apply plugin: 'kotlin-android' 3 | 4 | android { 5 | compileSdkVersion 29 6 | buildToolsVersion "29.0.2" 7 | defaultConfig { 8 | applicationId "com.specialprojects.experiments.envelopecall" 9 | minSdkVersion 29 10 | targetSdkVersion 29 11 | versionCode 3 12 | versionName "1.0" 13 | } 14 | 15 | def keys = new Properties() 16 | file("../keys.properties").withInputStream { 17 | stream -> keys.load(stream) 18 | } 19 | 20 | signingConfigs { 21 | paperPhone { 22 | storeFile file(keys.storeFile) 23 | storePassword keys.storePassword 24 | keyAlias keys.keyAlias 25 | keyPassword keys.keyPassword 26 | } 27 | } 28 | 29 | buildTypes { 30 | release { 31 | minifyEnabled false 32 | signingConfig signingConfigs.paperPhone 33 | proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' 34 | } 35 | } 36 | } 37 | 38 | dependencies { 39 | implementation deps.kotlin.stdlib.jdk 40 | implementation deps.androidx.appCompat 41 | implementation deps.androidx.core 42 | implementation deps.androidx.viewPager 43 | implementation deps.androidx.lifecycle.extensions 44 | implementation deps.pageIndicatorView 45 | implementation deps.timber 46 | } 47 | -------------------------------------------------------------------------------- /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 | 4 | 5 | 6 | 7 | 8 | 9 | 17 | 18 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | -------------------------------------------------------------------------------- /app/src/main/java/com/specialprojects/experiments/envelopecall/EnvelopeCallApp.kt: -------------------------------------------------------------------------------- 1 | package com.specialprojects.experiments.envelopecall 2 | 3 | import android.app.Application 4 | import android.content.Context 5 | import android.preference.PreferenceManager 6 | import androidx.lifecycle.* 7 | import com.specialprojects.experiments.envelopecall.audio.SoundPoolHolder 8 | import com.specialprojects.experiments.envelopecall.prefs.BooleanPreference 9 | import com.specialprojects.experiments.envelopecall.prefs.LongPreference 10 | import com.specialprojects.experiments.envelopecall.telephony.CallState 11 | import timber.log.Timber 12 | 13 | class EnvelopeCallApp: Application(), LifecycleObserver { 14 | lateinit var onboardingPreference: BooleanPreference 15 | lateinit var usagePreference: LongPreference 16 | val callState = MutableLiveData() 17 | 18 | var foregroundState = true 19 | 20 | override fun onCreate() { 21 | super.onCreate() 22 | 23 | val preferenceManager = PreferenceManager.getDefaultSharedPreferences(this) 24 | 25 | onboardingPreference = 26 | BooleanPreference( 27 | preferenceManager, 28 | "completedOnboarding" 29 | ) 30 | 31 | usagePreference = 32 | LongPreference( 33 | preferenceManager, 34 | "usageAccess" 35 | ) 36 | 37 | if (BuildConfig.DEBUG) { 38 | Timber.plant(Timber.DebugTree()) 39 | } 40 | 41 | SoundPoolHolder.init() 42 | SoundPoolHolder.loadSounds(this) 43 | 44 | ProcessLifecycleOwner.get().lifecycle.addObserver(this) 45 | } 46 | 47 | fun appendUsage(usage: Long) { 48 | val current = usagePreference.get() 49 | usagePreference.set(current + usage) 50 | } 51 | 52 | override fun onLowMemory() { 53 | super.onLowMemory() 54 | 55 | SoundPoolHolder.release() 56 | } 57 | 58 | companion object { 59 | @JvmStatic 60 | fun obtain(context: Context): EnvelopeCallApp { 61 | return context.applicationContext as EnvelopeCallApp 62 | } 63 | } 64 | 65 | @OnLifecycleEvent(Lifecycle.Event.ON_STOP) 66 | fun onAppBackgrounded() { 67 | foregroundState = false 68 | } 69 | 70 | @OnLifecycleEvent(Lifecycle.Event.ON_START) 71 | fun onAppForegrounded() { 72 | foregroundState = true 73 | } 74 | } -------------------------------------------------------------------------------- /app/src/main/java/com/specialprojects/experiments/envelopecall/FileDownloader.kt: -------------------------------------------------------------------------------- 1 | package com.specialprojects.experiments.envelopecall 2 | 3 | import android.app.DownloadManager 4 | import android.content.ContentResolver 5 | import android.content.Context 6 | import android.database.Cursor 7 | import android.net.Uri 8 | import android.os.Environment 9 | import android.provider.MediaStore 10 | 11 | 12 | object FileDownloader { 13 | fun maybeStartDownload(context: Context, uriString: String): Long { 14 | val downloadManager = context.getSystemService(Context.DOWNLOAD_SERVICE) as DownloadManager 15 | 16 | val fileUri = Uri.parse(uriString) 17 | val fileName = getFileName(fileUri) 18 | val request = DownloadManager.Request(fileUri).apply { 19 | setTitle(fileName) 20 | setDescription(fileName) 21 | setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS, fileName) 22 | setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED) 23 | } 24 | 25 | return downloadManager.enqueue(request) 26 | } 27 | 28 | fun getFileMimeType(context: Context, id: Long): String { 29 | val downloadManager = context.getSystemService(Context.DOWNLOAD_SERVICE) as DownloadManager 30 | 31 | return downloadManager.getMimeTypeForDownloadedFile(id) 32 | } 33 | 34 | private fun getFileName(uri: Uri): String? { 35 | var result = uri.path 36 | 37 | uri.path?.also { 38 | val cut = it.lastIndexOf('/') 39 | if (cut != -1) { 40 | result = result?.substring(cut + 1) 41 | } 42 | 43 | return result 44 | } 45 | 46 | return null 47 | } 48 | } -------------------------------------------------------------------------------- /app/src/main/java/com/specialprojects/experiments/envelopecall/audio/DTMF.kt: -------------------------------------------------------------------------------- 1 | package com.specialprojects.experiments.envelopecall.audio 2 | 3 | import kotlin.math.sin 4 | 5 | object DTMF { 6 | /** 7 | * The list of valid DTMF frequencies. See the [WikiPedia article on DTMF](http://en.wikipedia.org/wiki/Dual-tone_multi-frequency_signaling). 8 | */ 9 | val DTMF_FREQUENCIES = 10 | doubleArrayOf(697.0, 770.0, 852.0, 941.0, 1209.0, 1336.0, 1477.0, 1633.0) 11 | /** 12 | * The list of valid DTMF characters. See the [WikiPedia article on DTMF](http://en.wikipedia.org/wiki/Dual-tone_multi-frequency_signaling) for the relation between the characters 13 | * and frequencies. 14 | */ 15 | val DTMF_CHARACTERS = arrayOf( 16 | charArrayOf('1', '2', '3', 'A'), 17 | charArrayOf('4', '5', '6', 'B'), 18 | charArrayOf('7', '8', '9', 'C'), 19 | charArrayOf('*', '0', '#', 'D') 20 | ) 21 | 22 | /** 23 | * Generate a DTMF - tone for a valid DTMF character. 24 | * @param character a valid DTMF character (present in DTMF_CHARACTERS} 25 | * @return a float buffer of predefined length (7168 samples) with the correct DTMF tone representing the character. 26 | */ 27 | fun generateDTMFTone(character: Char): DoubleArray { 28 | var firstFrequency = -1.0 29 | var secondFrequency = -1.0 30 | for (row in DTMF_CHARACTERS.indices) { 31 | for (col in DTMF_CHARACTERS[row].indices) { 32 | if (DTMF_CHARACTERS[row][col] == character) { 33 | firstFrequency = DTMF_FREQUENCIES[row] 34 | secondFrequency = DTMF_FREQUENCIES[col + 4] 35 | } 36 | } 37 | } 38 | return audioBufferDTMF( 39 | firstFrequency, 40 | secondFrequency, 41 | 512 * 2 * 10 42 | ) 43 | } 44 | 45 | /** 46 | * Checks if the given character is present in DTMF_CHARACTERS. 47 | * 48 | * @param character 49 | * the character to check. 50 | * @return True if the given character is present in 51 | * DTMF_CHARACTERS, false otherwise. 52 | */ 53 | fun isDTMFCharacter(character: Char): Boolean { 54 | var firstFrequency = -1.0 55 | var secondFrequency = -1.0 56 | for (row in DTMF_CHARACTERS.indices) { 57 | for (col in DTMF_CHARACTERS[row].indices) { 58 | if (DTMF_CHARACTERS[row][col] == character) { 59 | firstFrequency = DTMF_FREQUENCIES[row] 60 | secondFrequency = DTMF_FREQUENCIES[col + 4] 61 | } 62 | } 63 | } 64 | return firstFrequency != -1.0 && secondFrequency != -1.0 65 | } 66 | 67 | /** 68 | * Creates an audio buffer in a float array of the defined size. The sample 69 | * rate is 44100Hz by default. It mixes the two given frequencies with an 70 | * amplitude of 0.5. 71 | * 72 | * @param f0 73 | * The first fundamental frequency. 74 | * @param f1 75 | * The second fundamental frequency. 76 | * @param size 77 | * The size of the float array (sample rate is 44.1kHz). 78 | * @return An array of the defined size. 79 | */ 80 | fun audioBufferDTMF( 81 | f0: Double, f1: Double, 82 | size: Int 83 | ): DoubleArray { 84 | val sampleRate = 44100.0 85 | val amplitudeF0 = 0.4 86 | val amplitudeF1 = 0.4 87 | val twoPiF0 = 2 * Math.PI * f0 88 | val twoPiF1 = 2 * Math.PI * f1 89 | val buffer = DoubleArray(size) 90 | for (sample in buffer.indices) { 91 | val time = sample / sampleRate 92 | val f0Component = amplitudeF0 * sin(twoPiF0 * time) 93 | val f1Component = amplitudeF1 * sin(twoPiF1 * time) 94 | buffer[sample] = (f0Component + f1Component) 95 | } 96 | return buffer 97 | } 98 | } -------------------------------------------------------------------------------- /app/src/main/java/com/specialprojects/experiments/envelopecall/audio/DTMFPlayer.kt: -------------------------------------------------------------------------------- 1 | package com.specialprojects.experiments.envelopecall.audio 2 | 3 | import android.media.AudioAttributes 4 | import android.media.AudioFormat 5 | import android.media.AudioManager 6 | import android.media.AudioTrack 7 | import timber.log.Timber 8 | import java.nio.ByteBuffer 9 | import kotlin.experimental.and 10 | 11 | class DTMFPlayer { 12 | 13 | private val audioTrack: AudioTrack? = null 14 | 15 | fun init() { 16 | val buffsize = AudioTrack.getMinBufferSize(7168, 17 | AudioFormat.CHANNEL_OUT_MONO, AudioFormat.ENCODING_PCM_16BIT) 18 | 19 | val audioTrack = AudioTrack( 20 | AudioAttributes.Builder() 21 | .setUsage(AudioAttributes.USAGE_MEDIA) 22 | .setContentType(AudioAttributes.CONTENT_TYPE_SONIFICATION) 23 | .build(), 24 | AudioFormat.Builder() 25 | .setSampleRate(44100) 26 | .setChannelMask(AudioFormat.CHANNEL_OUT_MONO) 27 | .setEncoding(AudioFormat.ENCODING_PCM_16BIT) 28 | .build(), buffsize, 29 | AudioTrack.MODE_STREAM, 30 | AudioManager.AUDIO_SESSION_ID_GENERATE) 31 | 32 | audioTrack.setPlaybackPositionUpdateListener(object: AudioTrack.OnPlaybackPositionUpdateListener { 33 | override fun onMarkerReached(audioTrack: AudioTrack) { 34 | Timber.d("onMarkerReached()") 35 | } 36 | 37 | override fun onPeriodicNotification(audioTrack: AudioTrack) { 38 | Timber.d("onPeriodicNotification()") 39 | } 40 | }) 41 | audioTrack.play() 42 | } 43 | 44 | fun playChar(char: Char) { 45 | writeSound(DTMF.generateDTMFTone(char)) 46 | } 47 | 48 | private fun writeSound(samples: DoubleArray) { 49 | val generatedSnd: ByteArray = get16BitPcm(samples) 50 | audioTrack?.write(generatedSnd, 0, generatedSnd.size) 51 | } 52 | 53 | private fun get16BitPcm(samples: DoubleArray): ByteArray { 54 | val buffer = ByteBuffer.allocate(8 * samples.size) 55 | 56 | var index = 0 57 | 58 | for (sample in samples) { 59 | val maxSample = ((sample * Short.MAX_VALUE)).toShort() 60 | 61 | buffer.putShort(index++, (maxSample and 0x00ff)) 62 | buffer.putShort(index++, ((maxSample and 0x00ff).toInt() ushr 8).toShort()) 63 | } 64 | 65 | Timber.d("Sample index: $index") 66 | 67 | return buffer.array() 68 | } 69 | 70 | fun destroy() { 71 | audioTrack?.apply { 72 | stop() 73 | release() 74 | } 75 | } 76 | } -------------------------------------------------------------------------------- /app/src/main/java/com/specialprojects/experiments/envelopecall/audio/SoundPoolHolder.kt: -------------------------------------------------------------------------------- 1 | package com.specialprojects.experiments.envelopecall.audio 2 | 3 | import android.content.Context 4 | import android.media.AudioAttributes 5 | import android.media.SoundPool 6 | import com.specialprojects.experiments.envelopecall.R 7 | import timber.log.Timber 8 | 9 | object SoundPoolHolder { 10 | private var soundPool: SoundPool? = null 11 | 12 | private val tonePool = mutableMapOf() 13 | 14 | private val idSoundMap = mapOf( 15 | R.id.one to R.raw.dtmf_1, 16 | R.id.two to R.raw.dtmf_2, 17 | R.id.three to R.raw.dtmf_3, 18 | R.id.four to R.raw.dtmf_4, 19 | R.id.five to R.raw.dtmf_5, 20 | R.id.six to R.raw.dtmf_6, 21 | R.id.seven to R.raw.dtmf_7, 22 | R.id.eight to R.raw.dtmf_8, 23 | R.id.nine to R.raw.dtmf_9, 24 | R.id.zero to R.raw.dtmf_0, 25 | R.id.star to R.raw.dtmf_star, 26 | R.id.hash to R.raw.dtmf_hash 27 | ) 28 | 29 | private val clockSoundMap = mapOf( 30 | 4 to R.raw.hour_1, 31 | 5 to R.raw.hour_2, 32 | 7 to R.raw.minutes_1, 33 | 8 to R.raw.minutes_2 34 | ) 35 | 36 | fun init() { 37 | val attributes = AudioAttributes.Builder() 38 | .setUsage(AudioAttributes.USAGE_GAME) 39 | .setContentType(AudioAttributes.CONTENT_TYPE_SONIFICATION) 40 | .build() 41 | 42 | soundPool = SoundPool.Builder() 43 | .setMaxStreams(4) 44 | .setAudioAttributes(attributes) 45 | .build() 46 | } 47 | 48 | fun loadSounds(context: Context) { 49 | tonePool.clear() 50 | tonePool.apply { 51 | soundPool?.let { 52 | val id = it.load(context, R.raw.unlock, 1) 53 | put(6, id) 54 | 55 | for(i in idSoundMap) { 56 | val soundId = it.load(context, i.value, 1) 57 | put(i.key, soundId) 58 | } 59 | 60 | for(i in clockSoundMap) { 61 | val soundId = it.load(context, i.value, 1) 62 | put(i.key, soundId) 63 | } 64 | } 65 | } 66 | } 67 | 68 | fun release() { 69 | soundPool?.release() 70 | soundPool = null 71 | } 72 | 73 | fun playSound(id: Int){ 74 | tonePool[id]?.let { 75 | Timber.d("Playing sound with id: $id") 76 | soundPool?.play(it, 1f, 1f, 1, 0, 1f) 77 | } 78 | } 79 | } -------------------------------------------------------------------------------- /app/src/main/java/com/specialprojects/experiments/envelopecall/contants.kt: -------------------------------------------------------------------------------- 1 | package com.specialprojects.experiments.envelopecall 2 | 3 | const val PDF_URL = "https://s3-eu-west-1.amazonaws.com/media.designersfriend.co.uk/sps/media/uploads/misc/downloads/google-unplugged-envelope-instructions.pdf" -------------------------------------------------------------------------------- /app/src/main/java/com/specialprojects/experiments/envelopecall/prefs/BooleanPreference.kt: -------------------------------------------------------------------------------- 1 | package com.specialprojects.experiments.envelopecall.prefs 2 | 3 | import android.content.SharedPreferences 4 | 5 | class BooleanPreference(private val preferences: SharedPreferences, 6 | private val key: String, private val defaultValue: Boolean = false) { 7 | 8 | fun get(): Boolean { 9 | return preferences.getBoolean(key, defaultValue) 10 | } 11 | 12 | val isSet: Boolean 13 | get() = preferences.contains(key) 14 | 15 | fun set(value: Boolean) { 16 | preferences.edit().putBoolean(key, value).apply() 17 | } 18 | 19 | fun delete() { 20 | preferences.edit().remove(key).apply() 21 | } 22 | } -------------------------------------------------------------------------------- /app/src/main/java/com/specialprojects/experiments/envelopecall/prefs/LongPreference.kt: -------------------------------------------------------------------------------- 1 | package com.specialprojects.experiments.envelopecall.prefs 2 | 3 | import android.content.SharedPreferences 4 | 5 | class LongPreference(private val preferences: SharedPreferences, 6 | private val key: String, private val defaultValue: Long = 0L) { 7 | 8 | fun get(): Long { 9 | return preferences.getLong(key, defaultValue) 10 | } 11 | 12 | val isSet: Boolean 13 | get() = preferences.contains(key) 14 | 15 | fun set(value: Long) { 16 | preferences.edit().putLong(key, value).apply() 17 | } 18 | 19 | fun delete() { 20 | preferences.edit().remove(key).apply() 21 | } 22 | } -------------------------------------------------------------------------------- /app/src/main/java/com/specialprojects/experiments/envelopecall/sensor/ProximitySensor.kt: -------------------------------------------------------------------------------- 1 | package com.specialprojects.experiments.envelopecall.sensor 2 | 3 | import android.content.Context 4 | import android.hardware.Sensor 5 | import android.hardware.SensorEvent 6 | import android.hardware.SensorEventListener 7 | import android.hardware.SensorManager 8 | import androidx.lifecycle.MutableLiveData 9 | 10 | enum class ProximityState { 11 | Near, 12 | Far 13 | } 14 | 15 | class ProximitySensor(context: Context): SensorEventListener { 16 | private val sensorManager: SensorManager = context.getSystemService(Context.SENSOR_SERVICE) as SensorManager 17 | private val proximity: Sensor = sensorManager.getDefaultSensor(Sensor.TYPE_PROXIMITY) 18 | 19 | override fun onAccuracyChanged(sensor: Sensor, accuracy: Int) { 20 | // Do something here if sensor accuracy changes. 21 | } 22 | 23 | val state: MutableLiveData = MutableLiveData() 24 | 25 | override fun onSensorChanged(event: SensorEvent) { 26 | val distance = event.values[0] 27 | 28 | if (distance == proximity.maximumRange) state.postValue(ProximityState.Far) else state.postValue( 29 | ProximityState.Near 30 | ) 31 | } 32 | 33 | fun startListening() { 34 | sensorManager.registerListener(this, proximity, SensorManager.SENSOR_DELAY_NORMAL) 35 | } 36 | 37 | fun stopListening() { 38 | sensorManager.unregisterListener(this) 39 | } 40 | } -------------------------------------------------------------------------------- /app/src/main/java/com/specialprojects/experiments/envelopecall/telephony/CallService.kt: -------------------------------------------------------------------------------- 1 | package com.specialprojects.experiments.envelopecall.telephony 2 | 3 | import android.app.Notification 4 | import android.app.NotificationChannel 5 | import android.app.NotificationManager 6 | import android.app.PendingIntent 7 | import android.content.Context 8 | import android.content.Intent 9 | import android.media.AudioAttributes 10 | import android.media.AudioManager 11 | import android.media.RingtoneManager 12 | import android.telecom.Call 13 | import android.telecom.InCallService 14 | import androidx.core.app.NotificationCompat 15 | import com.specialprojects.experiments.envelopecall.* 16 | import com.specialprojects.experiments.envelopecall.ui.call.CallActivity 17 | import timber.log.Timber 18 | 19 | 20 | class CallService: InCallService() { 21 | override fun onCallAdded(call: Call) { 22 | call.registerCallback(callback) 23 | Timber.d("onCallAdded()") 24 | super.onCallAdded(call) 25 | 26 | if (call.state == Call.STATE_RINGING) { 27 | with(applicationContext as EnvelopeCallApp) { 28 | callState.postValue(CallState.Ringing(call)) 29 | 30 | if (!foregroundState) { 31 | postNotification() 32 | } 33 | } 34 | } 35 | } 36 | 37 | override fun onBringToForeground(showDialpad: Boolean) { 38 | Timber.d("showDialpad: $showDialpad") 39 | } 40 | 41 | private val YOUR_CHANNEL_ID: String = "calls" 42 | 43 | lateinit var notificationManager: NotificationManager 44 | 45 | override fun onCreate() { 46 | super.onCreate() 47 | 48 | notificationManager = getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager 49 | } 50 | 51 | fun removeNotification() { 52 | notificationManager.cancel("calling", 2) 53 | } 54 | 55 | fun postNotification() { 56 | val channel = NotificationChannel(YOUR_CHANNEL_ID, "Incoming Calls", NotificationManager.IMPORTANCE_HIGH) 57 | channel.setSound(null, null) 58 | notificationManager.createNotificationChannel(channel) 59 | 60 | val intent = Intent(Intent.ACTION_MAIN, null) 61 | intent.flags = Intent.FLAG_ACTIVITY_NO_USER_ACTION or Intent.FLAG_ACTIVITY_NEW_TASK 62 | intent.setClass(this, CallActivity::class.java) 63 | val pendingIntent = PendingIntent.getActivity(this, 1, intent, 0) 64 | 65 | val builder = NotificationCompat.Builder(this, YOUR_CHANNEL_ID).apply { 66 | setOngoing(true) 67 | setContentIntent(pendingIntent) 68 | setFullScreenIntent(pendingIntent, true) 69 | } 70 | 71 | builder.setSmallIcon(R.drawable.ic_launcher_foreground) 72 | builder.setContentTitle("New call") 73 | builder.setContentText("New call") 74 | 75 | notificationManager.notify("calling", 2, builder.build()) 76 | } 77 | 78 | private val callback = object : Call.Callback() { 79 | override fun onStateChanged(call: Call, newState: Int) { 80 | Timber.d("Call ${call.details}") 81 | Timber.d(newState.asString()) 82 | 83 | (applicationContext as EnvelopeCallApp).callState.postValue( 84 | when(newState) { 85 | Call.STATE_ACTIVE -> CallState.Active(call) 86 | Call.STATE_RINGING -> CallState.Ringing(call) 87 | Call.STATE_DIALING -> CallState.Dialing(call) 88 | Call.STATE_DISCONNECTED -> CallState.Default 89 | else -> CallState.Default 90 | }) 91 | } 92 | } 93 | 94 | override fun onCallRemoved(call: Call) { 95 | Timber.d("onCallRemoved()") 96 | super.onCallRemoved(call) 97 | call.unregisterCallback(callback) 98 | 99 | removeNotification() 100 | } 101 | } -------------------------------------------------------------------------------- /app/src/main/java/com/specialprojects/experiments/envelopecall/telephony/CallState.kt: -------------------------------------------------------------------------------- 1 | package com.specialprojects.experiments.envelopecall.telephony 2 | 3 | import android.telecom.Call 4 | import timber.log.Timber 5 | 6 | fun Int.asString() = when (this) { 7 | Call.STATE_NEW -> "NEW" 8 | Call.STATE_RINGING -> "RINGING" 9 | Call.STATE_DIALING -> "DIALING" 10 | Call.STATE_ACTIVE -> "ACTIVE" 11 | Call.STATE_HOLDING -> "HOLDING" 12 | Call.STATE_DISCONNECTED -> "DISCONNECTED" 13 | Call.STATE_CONNECTING -> "CONNECTING" 14 | Call.STATE_DISCONNECTING -> "DISCONNECTING" 15 | Call.STATE_SELECT_PHONE_ACCOUNT -> "SELECT_PHONE_ACCOUNT" 16 | else -> { 17 | Timber.w("Unknown state $this") 18 | "UNKNOWN" 19 | } 20 | } 21 | 22 | sealed class CallState { 23 | class Ringing(val call: Call) : CallState() 24 | class Dialing(val call: Call) : CallState() 25 | class Active(val call: Call) : CallState() 26 | object Default : CallState() 27 | } -------------------------------------------------------------------------------- /app/src/main/java/com/specialprojects/experiments/envelopecall/ui/HelpActivity.kt: -------------------------------------------------------------------------------- 1 | package com.specialprojects.experiments.envelopecall.ui 2 | 3 | import android.app.DownloadManager 4 | import android.content.BroadcastReceiver 5 | import android.content.Context 6 | import android.content.Intent 7 | import android.content.IntentFilter 8 | import android.graphics.Color 9 | import android.net.Uri 10 | import android.os.Bundle 11 | import android.provider.Settings 12 | import android.text.Spannable 13 | import android.text.SpannableString 14 | import android.text.Spanned 15 | import android.text.TextPaint 16 | import android.text.method.LinkMovementMethod 17 | import android.text.style.ClickableSpan 18 | import android.view.View 19 | import android.widget.Button 20 | import android.widget.TextView 21 | import android.widget.Toast 22 | import androidx.appcompat.app.AppCompatActivity 23 | import com.specialprojects.experiments.envelopecall.FileDownloader 24 | import com.specialprojects.experiments.envelopecall.PDF_URL 25 | import com.specialprojects.experiments.envelopecall.R 26 | import com.specialprojects.experiments.envelopecall.ui.onboarding.OnboardingActivity 27 | import com.specialprojects.experiments.envelopecall.ui.util.bindView 28 | 29 | class HelpActivity: AppCompatActivity() { 30 | private val setupView by bindView(R.id.setup_screens) 31 | private val privacyView by bindView(R.id.privacy) 32 | private val envelopeView by bindView(R.id.making_envelope) 33 | private val permissionsView by bindView(R.id.permissions) 34 | private val linkView by bindView(R.id.link) 35 | 36 | override fun onCreate(savedInstanceState: Bundle?) { 37 | super.onCreate(savedInstanceState) 38 | setContentView(R.layout.activity_help) 39 | 40 | findViewById