├── .gitignore ├── .travis.yml ├── art ├── Promo.png ├── debug-icon.png ├── icon.png └── promo.sketch ├── build.gradle ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat └── src ├── androidTest └── java │ └── com │ └── f2prateek │ └── bee │ ├── BeeTestRunner.kt │ ├── MainActivityTest.kt │ └── Matchers.kt ├── debug ├── AndroidManifest.xml └── res │ ├── mipmap-hdpi │ └── ic_launcher.png │ ├── mipmap-mdpi │ └── ic_launcher.png │ ├── mipmap-xhdpi │ └── ic_launcher.png │ ├── mipmap-xxhdpi │ └── ic_launcher.png │ ├── mipmap-xxxhdpi │ └── ic_launcher.png │ └── values │ └── strings.xml ├── main ├── AndroidManifest.xml ├── java │ └── com │ │ └── f2prateek │ │ └── bee │ │ ├── Bee.kt │ │ ├── BeeApp.kt │ │ ├── CompositeSubscriptionExt.kt │ │ ├── MainActivity.kt │ │ └── PhoneStateReceiver.kt └── res │ ├── layout │ ├── activity_main.xml │ └── text_display.xml │ ├── mipmap-hdpi │ └── ic_launcher.png │ ├── mipmap-mdpi │ └── ic_launcher.png │ ├── mipmap-xhdpi │ └── ic_launcher.png │ ├── mipmap-xxhdpi │ └── ic_launcher.png │ ├── mipmap-xxxhdpi │ └── ic_launcher.png │ ├── values-w820dp │ └── dimens.xml │ └── values │ ├── colors.xml │ ├── dimens.xml │ ├── strings.xml │ └── styles.xml └── test └── java └── com └── f2prateek └── bee └── BeeTest.kt /.gitignore: -------------------------------------------------------------------------------- 1 | # Created by https://www.gitignore.io 2 | 3 | ### Android ### 4 | # Built application files 5 | *.apk 6 | *.ap_ 7 | 8 | # Files for the Dalvik VM 9 | *.dex 10 | 11 | # Java class files 12 | *.class 13 | 14 | # Generated files 15 | bin/ 16 | gen/ 17 | 18 | # Gradle files 19 | .gradle/ 20 | build/ 21 | /*/build/ 22 | 23 | # Local configuration file (sdk path, etc) 24 | local.properties 25 | 26 | # Proguard folder generated by Eclipse 27 | proguard/ 28 | 29 | # Log Files 30 | *.log 31 | 32 | ### Android Patch ### 33 | gen-external-apklibs 34 | 35 | ### Intellij ### 36 | # Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm 37 | 38 | *.iml 39 | 40 | ## Directory-based project format: 41 | .idea/ 42 | # if you remove the above rule, at least ignore the following: 43 | 44 | # User-specific stuff: 45 | # .idea/workspace.xml 46 | # .idea/tasks.xml 47 | # .idea/dictionaries 48 | 49 | # Sensitive or high-churn files: 50 | # .idea/dataSources.ids 51 | # .idea/dataSources.xml 52 | # .idea/sqlDataSources.xml 53 | # .idea/dynamic.xml 54 | # .idea/uiDesigner.xml 55 | 56 | # Gradle: 57 | # .idea/gradle.xml 58 | # .idea/libraries 59 | 60 | # Mongo Explorer plugin: 61 | # .idea/mongoSettings.xml 62 | 63 | ## File-based project format: 64 | *.ipr 65 | *.iws 66 | 67 | ## Plugin-specific files: 68 | 69 | # IntelliJ 70 | /out/ 71 | 72 | # mpeltonen/sbt-idea plugin 73 | .idea_modules/ 74 | 75 | # JIRA plugin 76 | atlassian-ide-plugin.xml 77 | 78 | # Crashlytics plugin (for Android Studio and IntelliJ) 79 | com_crashlytics_export_strings.xml 80 | crashlytics.properties 81 | crashlytics-build.properties 82 | 83 | 84 | ### OSX ### 85 | .DS_Store 86 | .AppleDouble 87 | .LSOverride 88 | 89 | # Icon must end with two \r 90 | Icon 91 | 92 | 93 | # Thumbnails 94 | ._* 95 | 96 | # Files that might appear in the root of a volume 97 | .DocumentRevisions-V100 98 | .fseventsd 99 | .Spotlight-V100 100 | .TemporaryItems 101 | .Trashes 102 | .VolumeIcon.icns 103 | 104 | # Directories potentially created on remote AFP share 105 | .AppleDB 106 | .AppleDesktop 107 | Network Trash Folder 108 | Temporary Items 109 | .apdisk 110 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: android 2 | 3 | jdk: 4 | - oraclejdk8 5 | 6 | android: 7 | components: 8 | - tools 9 | - platform-tools 10 | - build-tools-25.0.2 11 | - android-25 12 | - extra-android-m2repository 13 | - sys-img-armeabi-v7a-android-19 14 | 15 | before_script: 16 | - echo no | android create avd --force -n test -t android-19 --abi armeabi-v7a 17 | - emulator -avd test -no-audio -no-window & 18 | - android-wait-for-emulator 19 | - adb shell settings put global window_animation_scale 0 & 20 | - adb shell settings put global transition_animation_scale 0 & 21 | - adb shell settings put global animator_duration_scale 0 & 22 | - adb shell input keyevent 82 & 23 | 24 | env: 25 | global: 26 | - ADB_INSTALL_TIMEOUT=8 27 | 28 | notifications: 29 | email: false 30 | 31 | sudo: false 32 | -------------------------------------------------------------------------------- /art/Promo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/f2prateek/android-bee/097b6fdf09904088f4b0972f2ea0e6f9102eb2f7/art/Promo.png -------------------------------------------------------------------------------- /art/debug-icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/f2prateek/android-bee/097b6fdf09904088f4b0972f2ea0e6f9102eb2f7/art/debug-icon.png -------------------------------------------------------------------------------- /art/icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/f2prateek/android-bee/097b6fdf09904088f4b0972f2ea0e6f9102eb2f7/art/icon.png -------------------------------------------------------------------------------- /art/promo.sketch: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/f2prateek/android-bee/097b6fdf09904088f4b0972f2ea0e6f9102eb2f7/art/promo.sketch -------------------------------------------------------------------------------- /build.gradle: -------------------------------------------------------------------------------- 1 | buildscript { 2 | repositories { 3 | jcenter() 4 | } 5 | 6 | dependencies { 7 | classpath 'com.android.tools.build:gradle:2.3.2' 8 | classpath 'com.f2prateek.checkstyle:checkstyle:1.0.1' 9 | classpath 'com.stanfy.spoon:spoon-gradle-plugin:1.2.2' 10 | classpath 'org.jetbrains.kotlin:kotlin-gradle-plugin:1.1.2' 11 | } 12 | } 13 | 14 | apply plugin: 'com.android.application' 15 | apply plugin: 'kotlin-android' 16 | apply plugin: 'kotlin-android-extensions' 17 | apply plugin: 'spoon' 18 | 19 | def versionMajor = 0 20 | def versionMinor = 2 21 | def versionPatch = 0 22 | def versionBuild = 0 23 | 24 | def isTravis = "true" == System.getenv("TRAVIS") 25 | def preDexEnabled = "true" == System.getProperty("pre-dex", "true") 26 | 27 | android { 28 | compileSdkVersion 25 29 | buildToolsVersion '25.0.2' 30 | 31 | defaultConfig { 32 | applicationId 'com.f2prateek.bee' 33 | 34 | minSdkVersion 15 35 | targetSdkVersion 25 36 | 37 | versionCode versionMajor * 1000000 + versionMinor * 10000 + versionPatch * 100 + versionBuild 38 | versionName "${versionMajor}.${versionMinor}.${versionPatch}" 39 | 40 | testInstrumentationRunner "com.f2prateek.bee.BeeTestRunner" 41 | } 42 | 43 | dexOptions { 44 | // Skip pre-dexing when running on Travis CI or when disabled via -Dpre-dex=false. 45 | preDexLibraries = preDexEnabled && !isTravis 46 | } 47 | 48 | buildTypes { 49 | debug { 50 | applicationIdSuffix '.debug' 51 | } 52 | } 53 | 54 | lintOptions { 55 | textReport true 56 | textOutput 'stdout' 57 | abortOnError false 58 | } 59 | } 60 | 61 | configurations.all { 62 | resolutionStrategy { 63 | force 'com.android.support:support-annotations:25.3.1' 64 | } 65 | } 66 | 67 | dependencies { 68 | repositories { 69 | jcenter() 70 | } 71 | 72 | compile 'com.android.support:appcompat-v7:25.3.1' 73 | compile 'io.reactivex:rxandroid:1.2.1' 74 | compile 'io.reactivex:rxjava:1.3.0' 75 | compile 'com.jakewharton.rxbinding:rxbinding-kotlin:1.0.0' 76 | compile 'com.jakewharton.timber:timber:4.0.1' 77 | compile 'org.jetbrains.kotlin:kotlin-stdlib:1.1.2' 78 | 79 | testCompile 'junit:junit:4.12' 80 | testCompile 'com.google.truth:truth:0.27' 81 | 82 | androidTestCompile 'junit:junit:4.12' 83 | androidTestCompile 'com.android.support.test.espresso:espresso-core:2.2.2' 84 | androidTestCompile 'com.android.support.test:runner:0.5' 85 | androidTestCompile 'com.android.support.test:rules:0.5' 86 | androidTestCompile 'com.squareup.spoon:spoon-client:1.7.1' 87 | } 88 | -------------------------------------------------------------------------------- /gradle.properties: -------------------------------------------------------------------------------- 1 | # Project-wide Gradle settings. 2 | 3 | # IDE (e.g. Android Studio) users: 4 | # Gradle settings configured through the IDE *will override* 5 | # any settings specified in this file. 6 | 7 | # For more details on how to configure your build environment visit 8 | # http://www.gradle.org/docs/current/userguide/build_environment.html 9 | 10 | # Specifies the JVM arguments used for the daemon process. 11 | # The setting is particularly useful for tweaking memory settings. 12 | # Default value: -Xmx10248m -XX:MaxPermSize=256m 13 | # org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8 14 | 15 | # When configured, Gradle will run in incubating parallel mode. 16 | # This option should only be used with decoupled projects. More details, visit 17 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects 18 | # org.gradle.parallel=true -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/f2prateek/android-bee/097b6fdf09904088f4b0972f2ea0e6f9102eb2f7/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Mon May 22 23:04:06 PDT 2017 2 | distributionBase=GRADLE_USER_HOME 3 | distributionPath=wrapper/dists 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | distributionUrl=https\://services.gradle.org/distributions/gradle-3.3-all.zip 7 | -------------------------------------------------------------------------------- /gradlew: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | ############################################################################## 4 | ## 5 | ## Gradle start up script for UN*X 6 | ## 7 | ############################################################################## 8 | 9 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 10 | DEFAULT_JVM_OPTS="" 11 | 12 | APP_NAME="Gradle" 13 | APP_BASE_NAME=`basename "$0"` 14 | 15 | # Use the maximum available, or set MAX_FD != -1 to use that value. 16 | MAX_FD="maximum" 17 | 18 | warn ( ) { 19 | echo "$*" 20 | } 21 | 22 | die ( ) { 23 | echo 24 | echo "$*" 25 | echo 26 | exit 1 27 | } 28 | 29 | # OS specific support (must be 'true' or 'false'). 30 | cygwin=false 31 | msys=false 32 | darwin=false 33 | case "`uname`" in 34 | CYGWIN* ) 35 | cygwin=true 36 | ;; 37 | Darwin* ) 38 | darwin=true 39 | ;; 40 | MINGW* ) 41 | msys=true 42 | ;; 43 | esac 44 | 45 | # For Cygwin, ensure paths are in UNIX format before anything is touched. 46 | if $cygwin ; then 47 | [ -n "$JAVA_HOME" ] && JAVA_HOME=`cygpath --unix "$JAVA_HOME"` 48 | fi 49 | 50 | # Attempt to set APP_HOME 51 | # Resolve links: $0 may be a link 52 | PRG="$0" 53 | # Need this for relative symlinks. 54 | while [ -h "$PRG" ] ; do 55 | ls=`ls -ld "$PRG"` 56 | link=`expr "$ls" : '.*-> \(.*\)$'` 57 | if expr "$link" : '/.*' > /dev/null; then 58 | PRG="$link" 59 | else 60 | PRG=`dirname "$PRG"`"/$link" 61 | fi 62 | done 63 | SAVED="`pwd`" 64 | cd "`dirname \"$PRG\"`/" >&- 65 | APP_HOME="`pwd -P`" 66 | cd "$SAVED" >&- 67 | 68 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 69 | 70 | # Determine the Java command to use to start the JVM. 71 | if [ -n "$JAVA_HOME" ] ; then 72 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 73 | # IBM's JDK on AIX uses strange locations for the executables 74 | JAVACMD="$JAVA_HOME/jre/sh/java" 75 | else 76 | JAVACMD="$JAVA_HOME/bin/java" 77 | fi 78 | if [ ! -x "$JAVACMD" ] ; then 79 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 80 | 81 | Please set the JAVA_HOME variable in your environment to match the 82 | location of your Java installation." 83 | fi 84 | else 85 | JAVACMD="java" 86 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 87 | 88 | Please set the JAVA_HOME variable in your environment to match the 89 | location of your Java installation." 90 | fi 91 | 92 | # Increase the maximum file descriptors if we can. 93 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then 94 | MAX_FD_LIMIT=`ulimit -H -n` 95 | if [ $? -eq 0 ] ; then 96 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then 97 | MAX_FD="$MAX_FD_LIMIT" 98 | fi 99 | ulimit -n $MAX_FD 100 | if [ $? -ne 0 ] ; then 101 | warn "Could not set maximum file descriptor limit: $MAX_FD" 102 | fi 103 | else 104 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" 105 | fi 106 | fi 107 | 108 | # For Darwin, add options to specify how the application appears in the dock 109 | if $darwin; then 110 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" 111 | fi 112 | 113 | # For Cygwin, switch paths to Windows format before running java 114 | if $cygwin ; then 115 | APP_HOME=`cygpath --path --mixed "$APP_HOME"` 116 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` 117 | 118 | # We build the pattern for arguments to be converted via cygpath 119 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` 120 | SEP="" 121 | for dir in $ROOTDIRSRAW ; do 122 | ROOTDIRS="$ROOTDIRS$SEP$dir" 123 | SEP="|" 124 | done 125 | OURCYGPATTERN="(^($ROOTDIRS))" 126 | # Add a user-defined pattern to the cygpath arguments 127 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then 128 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" 129 | fi 130 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 131 | i=0 132 | for arg in "$@" ; do 133 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` 134 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option 135 | 136 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition 137 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` 138 | else 139 | eval `echo args$i`="\"$arg\"" 140 | fi 141 | i=$((i+1)) 142 | done 143 | case $i in 144 | (0) set -- ;; 145 | (1) set -- "$args0" ;; 146 | (2) set -- "$args0" "$args1" ;; 147 | (3) set -- "$args0" "$args1" "$args2" ;; 148 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;; 149 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; 150 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; 151 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; 152 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; 153 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; 154 | esac 155 | fi 156 | 157 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules 158 | function splitJvmOpts() { 159 | JVM_OPTS=("$@") 160 | } 161 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS 162 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME" 163 | 164 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@" 165 | -------------------------------------------------------------------------------- /gradlew.bat: -------------------------------------------------------------------------------- 1 | @if "%DEBUG%" == "" @echo off 2 | @rem ########################################################################## 3 | @rem 4 | @rem Gradle startup script for Windows 5 | @rem 6 | @rem ########################################################################## 7 | 8 | @rem Set local scope for the variables with windows NT shell 9 | if "%OS%"=="Windows_NT" setlocal 10 | 11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 12 | set DEFAULT_JVM_OPTS= 13 | 14 | set DIRNAME=%~dp0 15 | if "%DIRNAME%" == "" set DIRNAME=. 16 | set APP_BASE_NAME=%~n0 17 | set APP_HOME=%DIRNAME% 18 | 19 | @rem Find java.exe 20 | if defined JAVA_HOME goto findJavaFromJavaHome 21 | 22 | set JAVA_EXE=java.exe 23 | %JAVA_EXE% -version >NUL 2>&1 24 | if "%ERRORLEVEL%" == "0" goto init 25 | 26 | echo. 27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 28 | echo. 29 | echo Please set the JAVA_HOME variable in your environment to match the 30 | echo location of your Java installation. 31 | 32 | goto fail 33 | 34 | :findJavaFromJavaHome 35 | set JAVA_HOME=%JAVA_HOME:"=% 36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 37 | 38 | if exist "%JAVA_EXE%" goto init 39 | 40 | echo. 41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 42 | echo. 43 | echo Please set the JAVA_HOME variable in your environment to match the 44 | echo location of your Java installation. 45 | 46 | goto fail 47 | 48 | :init 49 | @rem Get command-line arguments, handling Windowz variants 50 | 51 | if not "%OS%" == "Windows_NT" goto win9xME_args 52 | if "%@eval[2+2]" == "4" goto 4NT_args 53 | 54 | :win9xME_args 55 | @rem Slurp the command line arguments. 56 | set CMD_LINE_ARGS= 57 | set _SKIP=2 58 | 59 | :win9xME_args_slurp 60 | if "x%~1" == "x" goto execute 61 | 62 | set CMD_LINE_ARGS=%* 63 | goto execute 64 | 65 | :4NT_args 66 | @rem Get arguments from the 4NT Shell from JP Software 67 | set CMD_LINE_ARGS=%$ 68 | 69 | :execute 70 | @rem Setup the command line 71 | 72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 73 | 74 | @rem Execute Gradle 75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% 76 | 77 | :end 78 | @rem End local scope for the variables with windows NT shell 79 | if "%ERRORLEVEL%"=="0" goto mainEnd 80 | 81 | :fail 82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 83 | rem the _cmd.exe /c_ return code! 84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 85 | exit /b 1 86 | 87 | :mainEnd 88 | if "%OS%"=="Windows_NT" endlocal 89 | 90 | :omega 91 | -------------------------------------------------------------------------------- /src/androidTest/java/com/f2prateek/bee/BeeTestRunner.kt: -------------------------------------------------------------------------------- 1 | package com.f2prateek.bee 2 | 3 | import android.app.KeyguardManager 4 | import android.content.Context.KEYGUARD_SERVICE 5 | import android.content.Context.POWER_SERVICE 6 | import android.os.PowerManager 7 | import android.os.PowerManager.* 8 | import android.support.test.runner.AndroidJUnitRunner 9 | 10 | class BeeTestRunner : AndroidJUnitRunner() { 11 | private lateinit var wakeLock: PowerManager.WakeLock 12 | 13 | @Suppress("Deprecation") 14 | override fun onStart() { 15 | val app = targetContext.applicationContext 16 | 17 | val name = BeeTestRunner::class.java.simpleName 18 | // Unlock the device so that the tests can input keystrokes. 19 | val keyguard = app.getSystemService(KEYGUARD_SERVICE) as KeyguardManager 20 | keyguard.newKeyguardLock(name).disableKeyguard() 21 | // Wake up the screen. 22 | val power = app.getSystemService(POWER_SERVICE) as PowerManager 23 | wakeLock = power.newWakeLock(FULL_WAKE_LOCK or ACQUIRE_CAUSES_WAKEUP or ON_AFTER_RELEASE, name) 24 | wakeLock.acquire() 25 | 26 | super.onStart() 27 | } 28 | 29 | override fun onDestroy() { 30 | super.onDestroy() 31 | 32 | wakeLock.release() 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/androidTest/java/com/f2prateek/bee/MainActivityTest.kt: -------------------------------------------------------------------------------- 1 | package com.f2prateek.bee 2 | 3 | import android.support.test.espresso.Espresso.onView 4 | import android.support.test.espresso.action.ViewActions.typeText 5 | import android.support.test.espresso.assertion.ViewAssertions.matches 6 | import android.support.test.espresso.matcher.ViewMatchers.withId 7 | import android.support.test.rule.ActivityTestRule 8 | import android.support.test.runner.AndroidJUnit4 9 | import com.squareup.spoon.Spoon 10 | import org.junit.BeforeClass 11 | import org.junit.Rule 12 | import org.junit.Test 13 | import org.junit.runner.RunWith 14 | import rx.plugins.RxJavaHooks 15 | import rx.schedulers.Schedulers 16 | 17 | @RunWith(AndroidJUnit4::class) 18 | class MainActivityTest { 19 | @Rule @JvmField 20 | val main = ActivityTestRule(MainActivity::class.java) 21 | 22 | @Test @Throws(Exception::class) 23 | fun display() { 24 | Spoon.screenshot(main.activity, "start") 25 | onView(withId(R.id.editor)).perform(typeText("Foo Bar")) 26 | Spoon.screenshot(main.activity, "typed_text") 27 | onView(withId(R.id.display)) // 28 | .check(matches(childWithText("Foxtrot Oscar Oscar\nBravo Alfa Romeo"))) 29 | Spoon.screenshot(main.activity, "end") 30 | } 31 | 32 | companion object { 33 | @BeforeClass @JvmStatic @Throws(Exception::class) 34 | fun setUpOnce() { 35 | RxJavaHooks.setOnComputationScheduler { Schedulers.immediate() } 36 | } 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /src/androidTest/java/com/f2prateek/bee/Matchers.kt: -------------------------------------------------------------------------------- 1 | package com.f2prateek.bee 2 | 3 | import android.support.test.espresso.matcher.BoundedMatcher 4 | import android.view.View 5 | import android.view.ViewGroup 6 | import android.widget.TextView 7 | import org.hamcrest.Description 8 | import org.hamcrest.Matcher 9 | 10 | /** Matches that a [ViewGroup] contains a child [TextView] with the given text. */ 11 | fun childWithText(text: String): Matcher { 12 | val matcher = org.hamcrest.Matchers.`is`(text) 13 | return childWithMatcher(object : BoundedMatcher(TextView::class.java) { 14 | override fun describeTo(description: Description) { 15 | description.appendText("with text: ") 16 | matcher.describeTo(description) 17 | } 18 | 19 | override fun matchesSafely(textView: TextView): Boolean { 20 | return matcher.matches(textView.text) 21 | } 22 | }) 23 | } 24 | 25 | /** 26 | * Matches that a [ViewGroup] contains a child [View] that matches the given 27 | * `matcher`. 28 | */ 29 | private fun childWithMatcher(matcher: Matcher<*>): Matcher { 30 | return object : BoundedMatcher(ViewGroup::class.java) { 31 | override fun describeTo(description: Description) { 32 | description.appendText("child with matcher: ") 33 | matcher.describeTo(description) 34 | } 35 | 36 | public override fun matchesSafely(viewGroup: ViewGroup): Boolean { 37 | return (0 until viewGroup.childCount).any { matcher.matches(viewGroup.getChildAt(it)) } 38 | } 39 | } 40 | } -------------------------------------------------------------------------------- /src/debug/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /src/debug/res/mipmap-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/f2prateek/android-bee/097b6fdf09904088f4b0972f2ea0e6f9102eb2f7/src/debug/res/mipmap-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /src/debug/res/mipmap-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/f2prateek/android-bee/097b6fdf09904088f4b0972f2ea0e6f9102eb2f7/src/debug/res/mipmap-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /src/debug/res/mipmap-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/f2prateek/android-bee/097b6fdf09904088f4b0972f2ea0e6f9102eb2f7/src/debug/res/mipmap-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /src/debug/res/mipmap-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/f2prateek/android-bee/097b6fdf09904088f4b0972f2ea0e6f9102eb2f7/src/debug/res/mipmap-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /src/debug/res/mipmap-xxxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/f2prateek/android-bee/097b6fdf09904088f4b0972f2ea0e6f9102eb2f7/src/debug/res/mipmap-xxxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /src/debug/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | Bee (Debug) 3 | 4 | -------------------------------------------------------------------------------- /src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | 13 | 14 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | -------------------------------------------------------------------------------- /src/main/java/com/f2prateek/bee/Bee.kt: -------------------------------------------------------------------------------- 1 | package com.f2prateek.bee 2 | 3 | fun CharSequence.spell(): String = this 4 | .split(Regex("""\s""")) 5 | .map { it.spellWord() } 6 | .joinToString("\n") 7 | 8 | fun String.spellWord(): String = this 9 | .map { it.spellChar() ?: it } 10 | .joinToString(" ") 11 | 12 | fun Char.spellChar(): String? { 13 | val c = Character.toLowerCase(this) 14 | when (c) { 15 | 'a' -> return "Alfa" 16 | 'b' -> return "Bravo" 17 | 'c' -> return "Charlie" 18 | 'd' -> return "Delta" 19 | 'e' -> return "Echo" 20 | 'f' -> return "Foxtrot" 21 | 'g' -> return "Golf" 22 | 'h' -> return "Hotel" 23 | 'i' -> return "India" 24 | 'j' -> return "Juliett" 25 | 'k' -> return "Kilo" 26 | 'l' -> return "Lima" 27 | 'm' -> return "Mike" 28 | 'n' -> return "November" 29 | 'o' -> return "Oscar" 30 | 'p' -> return "Papa" 31 | 'q' -> return "Quebec" 32 | 'r' -> return "Romeo" 33 | 's' -> return "Sierra" 34 | 't' -> return "Tango" 35 | 'u' -> return "Uniform" 36 | 'v' -> return "Victor" 37 | 'w' -> return "Whiskey" 38 | 'x' -> return "X-ray" 39 | 'y' -> return "Yankee" 40 | 'z' -> return "Zulu" 41 | '0' -> return "Zero" 42 | '1' -> return "One" 43 | '2' -> return "Two" 44 | '3' -> return "Three" 45 | '4' -> return "Four" 46 | '5' -> return "Five" 47 | '6' -> return "Six" 48 | '7' -> return "Seven" 49 | '8' -> return "Eight" 50 | '9' -> return "Nine" 51 | else -> return null 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /src/main/java/com/f2prateek/bee/BeeApp.kt: -------------------------------------------------------------------------------- 1 | package com.f2prateek.bee 2 | 3 | import android.app.Application 4 | import timber.log.Timber 5 | 6 | class BeeApp : Application() { 7 | override fun onCreate() { 8 | super.onCreate() 9 | 10 | if (BuildConfig.DEBUG) { 11 | Timber.plant(Timber.DebugTree()) 12 | } 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /src/main/java/com/f2prateek/bee/CompositeSubscriptionExt.kt: -------------------------------------------------------------------------------- 1 | package com.f2prateek.bee 2 | 3 | import rx.Subscription 4 | import rx.subscriptions.CompositeSubscription 5 | 6 | operator fun CompositeSubscription.plusAssign(subscription: Subscription) = add(subscription) 7 | -------------------------------------------------------------------------------- /src/main/java/com/f2prateek/bee/MainActivity.kt: -------------------------------------------------------------------------------- 1 | package com.f2prateek.bee 2 | 3 | import android.os.Bundle 4 | import android.support.v7.app.AppCompatActivity 5 | import android.widget.EditText 6 | import android.widget.TextSwitcher 7 | import com.jakewharton.rxbinding.widget.textChanges 8 | import rx.android.schedulers.AndroidSchedulers 9 | import rx.subscriptions.CompositeSubscription 10 | import java.util.concurrent.TimeUnit 11 | 12 | class MainActivity : AppCompatActivity() { 13 | lateinit private var editor: EditText 14 | lateinit private var display: TextSwitcher 15 | private val subscription = CompositeSubscription() 16 | 17 | override fun onCreate(savedInstanceState: Bundle?) { 18 | super.onCreate(savedInstanceState) 19 | setContentView(R.layout.activity_main) 20 | editor = findViewById(R.id.editor) as EditText 21 | display = findViewById(R.id.display) as TextSwitcher 22 | } 23 | 24 | override fun onResume() { 25 | super.onResume() 26 | subscription += editor.textChanges() 27 | .skip(1) // First event is a blank string "". 28 | .debounce(400, TimeUnit.MILLISECONDS) 29 | .map(CharSequence::spell) 30 | .observeOn(AndroidSchedulers.mainThread()) 31 | .subscribe(display::setText) 32 | } 33 | 34 | override fun onPause() { 35 | super.onPause() 36 | subscription.clear() 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /src/main/java/com/f2prateek/bee/PhoneStateReceiver.kt: -------------------------------------------------------------------------------- 1 | package com.f2prateek.bee 2 | 3 | import android.app.NotificationManager 4 | import android.app.PendingIntent 5 | import android.content.BroadcastReceiver 6 | import android.content.Context 7 | import android.content.Context.NOTIFICATION_SERVICE 8 | import android.content.Intent 9 | import android.support.v4.app.NotificationCompat 10 | import android.telephony.TelephonyManager 11 | import android.telephony.TelephonyManager.EXTRA_STATE_IDLE 12 | import android.telephony.TelephonyManager.EXTRA_STATE_OFFHOOK 13 | import android.telephony.TelephonyManager.EXTRA_STATE_RINGING 14 | import timber.log.Timber 15 | 16 | class PhoneStateReceiver : BroadcastReceiver() { 17 | override fun onReceive(context: Context, intent: Intent) { 18 | val notificationManager = context.getSystemService(NOTIFICATION_SERVICE) as NotificationManager 19 | 20 | val state = intent.getStringExtra(TelephonyManager.EXTRA_STATE) 21 | 22 | if (EXTRA_STATE_IDLE == state) { 23 | notificationManager.cancel(NOTIFICATION_ID) 24 | return 25 | } 26 | 27 | if (EXTRA_STATE_RINGING != state && EXTRA_STATE_OFFHOOK != state) { 28 | Timber.e("Unknown state: %s", state) 29 | return 30 | } 31 | 32 | val resources = context.resources 33 | val pendingIntent = launchMainActivity(context) 34 | 35 | val builder = NotificationCompat.Builder(context).setSmallIcon(R.mipmap.ic_launcher) 36 | .setContentTitle(resources.getString(R.string.app_name)) 37 | .setContentText(resources.getString(R.string.notification_description)) 38 | .setContentIntent(pendingIntent) 39 | 40 | notificationManager.notify(null, NOTIFICATION_ID, builder.build()) 41 | } 42 | 43 | private companion object { 44 | const val NOTIFICATION_ID = 0 45 | 46 | fun launchMainActivity(context: Context): PendingIntent { 47 | val intent = Intent(context, MainActivity::class.java) 48 | return PendingIntent.getActivity(context, 0, intent, 0) 49 | } 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /src/main/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 11 | 12 | 18 | 19 | 25 | 26 | 27 | 28 | 29 | 30 | -------------------------------------------------------------------------------- /src/main/res/layout/text_display.xml: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /src/main/res/mipmap-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/f2prateek/android-bee/097b6fdf09904088f4b0972f2ea0e6f9102eb2f7/src/main/res/mipmap-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /src/main/res/mipmap-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/f2prateek/android-bee/097b6fdf09904088f4b0972f2ea0e6f9102eb2f7/src/main/res/mipmap-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /src/main/res/mipmap-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/f2prateek/android-bee/097b6fdf09904088f4b0972f2ea0e6f9102eb2f7/src/main/res/mipmap-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /src/main/res/mipmap-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/f2prateek/android-bee/097b6fdf09904088f4b0972f2ea0e6f9102eb2f7/src/main/res/mipmap-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /src/main/res/mipmap-xxxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/f2prateek/android-bee/097b6fdf09904088f4b0972f2ea0e6f9102eb2f7/src/main/res/mipmap-xxxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /src/main/res/values-w820dp/dimens.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 64dp 4 | 5 | -------------------------------------------------------------------------------- /src/main/res/values/colors.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | #3F51B5 5 | #303F9F 6 | 7 | #00BCD4 --> 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /src/main/res/values/dimens.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 16dp 4 | 16dp 5 | 6 | -------------------------------------------------------------------------------- /src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | Bee 3 | Enter your text… 4 | Need some help to communicate a word? 5 | 6 | -------------------------------------------------------------------------------- /src/main/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /src/test/java/com/f2prateek/bee/BeeTest.kt: -------------------------------------------------------------------------------- 1 | package com.f2prateek.bee 2 | 3 | import com.google.common.truth.Truth.assertThat 4 | import org.junit.Test 5 | 6 | class BeeTest { 7 | @Test fun testCharacters() { 8 | assertThat("abcdefghijklmnopqrstuvwxyz".spell()) // 9 | .isEqualTo("Alfa Bravo Charlie Delta Echo Foxtrot Golf Hotel India Juliett Kilo " + 10 | "Lima Mike November Oscar Papa Quebec Romeo Sierra Tango Uniform Victor " + 11 | "Whiskey X-ray Yankee Zulu") 12 | } 13 | 14 | @Test fun testCharactersUppercase() { 15 | assertThat("ABCDEFGHIJKLMNOPQRSTUVWXYZ".spell()) 16 | .isEqualTo("Alfa Bravo Charlie Delta Echo Foxtrot Golf Hotel India Juliett Kilo " + 17 | "Lima Mike November Oscar Papa Quebec Romeo Sierra Tango Uniform Victor " + 18 | "Whiskey X-ray Yankee Zulu") 19 | } 20 | 21 | @Test fun testDigits() { 22 | assertThat("1234567890".spell()) 23 | .isEqualTo("One Two Three Four Five Six Seven Eight Nine Zero") 24 | } 25 | 26 | @Test fun testUnknown() { 27 | assertThat(",./".spell()).isEqualTo(", . /") 28 | } 29 | 30 | @Test fun testSpace() { 31 | assertThat("a b c".spell()).isEqualTo("Alfa\nBravo\nCharlie") 32 | } 33 | } 34 | --------------------------------------------------------------------------------