├── beacon-keeper-library ├── .gitignore ├── src │ └── main │ │ ├── res │ │ ├── .gitignore │ │ └── values │ │ │ ├── config.xml │ │ │ └── strings.xml │ │ ├── AndroidManifest.xml │ │ └── java │ │ └── com │ │ └── m039 │ │ └── beacon │ │ └── keeper │ │ ├── C.java │ │ ├── L.java │ │ ├── util │ │ ├── OnEnableBluetoothCallback.java │ │ └── SimpleLeScanner.java │ │ ├── receiver │ │ └── BeaconReceiver.java │ │ ├── content │ │ ├── IBeacon.java │ │ ├── BeaconEntity.java │ │ └── BeaconFactory.java │ │ ├── U.java │ │ └── service │ │ └── BeaconService.java └── build.gradle ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── beacon-keeper-app ├── src │ └── main │ │ ├── assets │ │ └── fonts │ │ │ ├── Intro-Bold.otf │ │ │ ├── Intro-Light.otf │ │ │ └── Intro-Regular.otf │ │ ├── res │ │ ├── drawable-hdpi │ │ │ ├── radar.png │ │ │ ├── about_logo.png │ │ │ ├── btn_settings.png │ │ │ ├── ic_launcher.png │ │ │ ├── ico_settings.png │ │ │ ├── radar_circle.png │ │ │ ├── splash__logo.png │ │ │ ├── switch_thumb.png │ │ │ ├── switch_track.png │ │ │ ├── beacon_entity__producer__estimote.png │ │ │ ├── beacon_entity__producer__kontakt.png │ │ │ ├── beacon_entity__producer__qualcomm.png │ │ │ ├── beacon_entity__producer__unknown.png │ │ │ └── beacon_entity__producer__sticknfind.png │ │ ├── drawable-ldpi │ │ │ ├── radar.png │ │ │ ├── about_logo.png │ │ │ ├── btn_settings.png │ │ │ ├── ic_launcher.png │ │ │ ├── ico_settings.png │ │ │ ├── radar_circle.png │ │ │ ├── splash__logo.png │ │ │ ├── switch_thumb.png │ │ │ ├── switch_track.png │ │ │ ├── beacon_entity__producer__estimote.png │ │ │ ├── beacon_entity__producer__kontakt.png │ │ │ ├── beacon_entity__producer__qualcomm.png │ │ │ ├── beacon_entity__producer__unknown.png │ │ │ └── beacon_entity__producer__sticknfind.png │ │ ├── drawable-mdpi │ │ │ ├── radar.png │ │ │ ├── about_logo.png │ │ │ ├── btn_settings.png │ │ │ ├── ic_launcher.png │ │ │ ├── ico_settings.png │ │ │ ├── radar_circle.png │ │ │ ├── splash__logo.png │ │ │ ├── switch_thumb.png │ │ │ ├── switch_track.png │ │ │ ├── beacon_entity__producer__estimote.png │ │ │ ├── beacon_entity__producer__kontakt.png │ │ │ ├── beacon_entity__producer__qualcomm.png │ │ │ ├── beacon_entity__producer__unknown.png │ │ │ └── beacon_entity__producer__sticknfind.png │ │ ├── drawable-xhdpi │ │ │ ├── radar.png │ │ │ ├── about_logo.png │ │ │ ├── btn_settings.png │ │ │ ├── ic_launcher.png │ │ │ ├── ico_settings.png │ │ │ ├── radar_circle.png │ │ │ ├── splash__logo.png │ │ │ ├── switch_thumb.png │ │ │ ├── switch_track.png │ │ │ ├── beacon_entity__producer__kontakt.png │ │ │ ├── beacon_entity__producer__unknown.png │ │ │ ├── beacon_entity__producer__estimote.png │ │ │ ├── beacon_entity__producer__qualcomm.png │ │ │ └── beacon_entity__producer__sticknfind.png │ │ ├── drawable-xxhdpi │ │ │ └── ic_launcher.png │ │ ├── values │ │ │ ├── attrs.xml │ │ │ ├── dimens.xml │ │ │ ├── colors.xml │ │ │ ├── themes.xml │ │ │ ├── strings.xml │ │ │ └── styles.xml │ │ ├── anim │ │ │ ├── enter_in.xml │ │ │ ├── enter_out.xml │ │ │ ├── finish_in.xml │ │ │ └── finish_out.xml │ │ ├── xml │ │ │ ├── google_analytics_tracker.xml │ │ │ └── preferences.xml │ │ ├── drawable │ │ │ ├── button_normal.xml │ │ │ ├── button_selected.xml │ │ │ ├── switcher_thumb.xml │ │ │ ├── switcher_track.xml │ │ │ └── button.xml │ │ ├── color │ │ │ └── button.xml │ │ └── layout │ │ │ ├── a_settings.xml │ │ │ ├── e_list.xml │ │ │ ├── a_beacons.xml │ │ │ ├── f_splash.xml │ │ │ ├── a_about.xml │ │ │ └── a_beacon.xml │ │ ├── java │ │ └── com │ │ │ └── m039 │ │ │ └── beacon │ │ │ └── keeper │ │ │ ├── fragment │ │ │ ├── BaseFragment.java │ │ │ └── SplashF.java │ │ │ ├── app │ │ │ └── MainApplication.java │ │ │ ├── activity │ │ │ ├── AboutA.java │ │ │ ├── SettingsA.java │ │ │ ├── BaseActivity.java │ │ │ ├── BeaconA.java │ │ │ └── BeaconsA.java │ │ │ ├── widget │ │ │ └── DividerItemDecoration.java │ │ │ └── adapter │ │ │ └── BeaconEntityAdapter.java │ │ └── AndroidManifest.xml └── build.gradle ├── settings.gradle ├── beacon-keeper-samples ├── beacon-keeper-background-sample │ ├── src │ │ └── main │ │ │ ├── res │ │ │ ├── drawable-xhdpi │ │ │ │ └── ic_launcher.png │ │ │ ├── values │ │ │ │ └── strings.xml │ │ │ └── layout │ │ │ │ └── a_main.xml │ │ │ ├── java │ │ │ └── com │ │ │ │ └── m039 │ │ │ │ └── beacon │ │ │ │ └── keeper │ │ │ │ ├── app │ │ │ │ └── MainApplication.java │ │ │ │ ├── activity │ │ │ │ └── MainActivity.java │ │ │ │ └── receiver │ │ │ │ └── MainReceiver.java │ │ │ └── AndroidManifest.xml │ └── build.gradle └── beacon-keeper-foreground-sample │ ├── src │ └── main │ │ ├── res │ │ ├── drawable-xhdpi │ │ │ └── ic_launcher.png │ │ ├── values │ │ │ └── strings.xml │ │ └── layout │ │ │ └── a_main.xml │ │ ├── java │ │ └── com │ │ │ └── m039 │ │ │ └── beacon │ │ │ └── keeper │ │ │ ├── app │ │ │ └── MainApplication.java │ │ │ └── activity │ │ │ └── MainActivity.java │ │ └── AndroidManifest.xml │ └── build.gradle ├── .gitignore ├── Readme.md ├── gradlew.bat ├── gradlew └── LICENSE-2.0.txt /beacon-keeper-library/.gitignore: -------------------------------------------------------------------------------- 1 | /target 2 | -------------------------------------------------------------------------------- /beacon-keeper-library/src/main/res/.gitignore: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/m039/beacon-keeper/HEAD/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /beacon-keeper-app/src/main/assets/fonts/Intro-Bold.otf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/m039/beacon-keeper/HEAD/beacon-keeper-app/src/main/assets/fonts/Intro-Bold.otf -------------------------------------------------------------------------------- /beacon-keeper-app/src/main/res/drawable-hdpi/radar.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/m039/beacon-keeper/HEAD/beacon-keeper-app/src/main/res/drawable-hdpi/radar.png -------------------------------------------------------------------------------- /beacon-keeper-app/src/main/res/drawable-ldpi/radar.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/m039/beacon-keeper/HEAD/beacon-keeper-app/src/main/res/drawable-ldpi/radar.png -------------------------------------------------------------------------------- /beacon-keeper-app/src/main/res/drawable-mdpi/radar.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/m039/beacon-keeper/HEAD/beacon-keeper-app/src/main/res/drawable-mdpi/radar.png -------------------------------------------------------------------------------- /beacon-keeper-app/src/main/assets/fonts/Intro-Light.otf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/m039/beacon-keeper/HEAD/beacon-keeper-app/src/main/assets/fonts/Intro-Light.otf -------------------------------------------------------------------------------- /beacon-keeper-app/src/main/assets/fonts/Intro-Regular.otf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/m039/beacon-keeper/HEAD/beacon-keeper-app/src/main/assets/fonts/Intro-Regular.otf -------------------------------------------------------------------------------- /beacon-keeper-app/src/main/res/drawable-xhdpi/radar.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/m039/beacon-keeper/HEAD/beacon-keeper-app/src/main/res/drawable-xhdpi/radar.png -------------------------------------------------------------------------------- /beacon-keeper-library/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.library' 2 | 3 | android { 4 | compileSdkVersion 22 5 | buildToolsVersion "21.1.2" 6 | } 7 | -------------------------------------------------------------------------------- /beacon-keeper-app/src/main/res/drawable-hdpi/about_logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/m039/beacon-keeper/HEAD/beacon-keeper-app/src/main/res/drawable-hdpi/about_logo.png -------------------------------------------------------------------------------- /beacon-keeper-app/src/main/res/drawable-ldpi/about_logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/m039/beacon-keeper/HEAD/beacon-keeper-app/src/main/res/drawable-ldpi/about_logo.png -------------------------------------------------------------------------------- /beacon-keeper-app/src/main/res/drawable-mdpi/about_logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/m039/beacon-keeper/HEAD/beacon-keeper-app/src/main/res/drawable-mdpi/about_logo.png -------------------------------------------------------------------------------- /beacon-keeper-app/src/main/res/drawable-hdpi/btn_settings.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/m039/beacon-keeper/HEAD/beacon-keeper-app/src/main/res/drawable-hdpi/btn_settings.png -------------------------------------------------------------------------------- /beacon-keeper-app/src/main/res/drawable-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/m039/beacon-keeper/HEAD/beacon-keeper-app/src/main/res/drawable-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /beacon-keeper-app/src/main/res/drawable-hdpi/ico_settings.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/m039/beacon-keeper/HEAD/beacon-keeper-app/src/main/res/drawable-hdpi/ico_settings.png -------------------------------------------------------------------------------- /beacon-keeper-app/src/main/res/drawable-hdpi/radar_circle.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/m039/beacon-keeper/HEAD/beacon-keeper-app/src/main/res/drawable-hdpi/radar_circle.png -------------------------------------------------------------------------------- /beacon-keeper-app/src/main/res/drawable-hdpi/splash__logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/m039/beacon-keeper/HEAD/beacon-keeper-app/src/main/res/drawable-hdpi/splash__logo.png -------------------------------------------------------------------------------- /beacon-keeper-app/src/main/res/drawable-hdpi/switch_thumb.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/m039/beacon-keeper/HEAD/beacon-keeper-app/src/main/res/drawable-hdpi/switch_thumb.png -------------------------------------------------------------------------------- /beacon-keeper-app/src/main/res/drawable-hdpi/switch_track.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/m039/beacon-keeper/HEAD/beacon-keeper-app/src/main/res/drawable-hdpi/switch_track.png -------------------------------------------------------------------------------- /beacon-keeper-app/src/main/res/drawable-ldpi/btn_settings.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/m039/beacon-keeper/HEAD/beacon-keeper-app/src/main/res/drawable-ldpi/btn_settings.png -------------------------------------------------------------------------------- /beacon-keeper-app/src/main/res/drawable-ldpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/m039/beacon-keeper/HEAD/beacon-keeper-app/src/main/res/drawable-ldpi/ic_launcher.png -------------------------------------------------------------------------------- /beacon-keeper-app/src/main/res/drawable-ldpi/ico_settings.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/m039/beacon-keeper/HEAD/beacon-keeper-app/src/main/res/drawable-ldpi/ico_settings.png -------------------------------------------------------------------------------- /beacon-keeper-app/src/main/res/drawable-ldpi/radar_circle.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/m039/beacon-keeper/HEAD/beacon-keeper-app/src/main/res/drawable-ldpi/radar_circle.png -------------------------------------------------------------------------------- /beacon-keeper-app/src/main/res/drawable-ldpi/splash__logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/m039/beacon-keeper/HEAD/beacon-keeper-app/src/main/res/drawable-ldpi/splash__logo.png -------------------------------------------------------------------------------- /beacon-keeper-app/src/main/res/drawable-ldpi/switch_thumb.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/m039/beacon-keeper/HEAD/beacon-keeper-app/src/main/res/drawable-ldpi/switch_thumb.png -------------------------------------------------------------------------------- /beacon-keeper-app/src/main/res/drawable-ldpi/switch_track.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/m039/beacon-keeper/HEAD/beacon-keeper-app/src/main/res/drawable-ldpi/switch_track.png -------------------------------------------------------------------------------- /beacon-keeper-app/src/main/res/drawable-mdpi/btn_settings.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/m039/beacon-keeper/HEAD/beacon-keeper-app/src/main/res/drawable-mdpi/btn_settings.png -------------------------------------------------------------------------------- /beacon-keeper-app/src/main/res/drawable-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/m039/beacon-keeper/HEAD/beacon-keeper-app/src/main/res/drawable-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /beacon-keeper-app/src/main/res/drawable-mdpi/ico_settings.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/m039/beacon-keeper/HEAD/beacon-keeper-app/src/main/res/drawable-mdpi/ico_settings.png -------------------------------------------------------------------------------- /beacon-keeper-app/src/main/res/drawable-mdpi/radar_circle.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/m039/beacon-keeper/HEAD/beacon-keeper-app/src/main/res/drawable-mdpi/radar_circle.png -------------------------------------------------------------------------------- /beacon-keeper-app/src/main/res/drawable-mdpi/splash__logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/m039/beacon-keeper/HEAD/beacon-keeper-app/src/main/res/drawable-mdpi/splash__logo.png -------------------------------------------------------------------------------- /beacon-keeper-app/src/main/res/drawable-mdpi/switch_thumb.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/m039/beacon-keeper/HEAD/beacon-keeper-app/src/main/res/drawable-mdpi/switch_thumb.png -------------------------------------------------------------------------------- /beacon-keeper-app/src/main/res/drawable-mdpi/switch_track.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/m039/beacon-keeper/HEAD/beacon-keeper-app/src/main/res/drawable-mdpi/switch_track.png -------------------------------------------------------------------------------- /beacon-keeper-app/src/main/res/drawable-xhdpi/about_logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/m039/beacon-keeper/HEAD/beacon-keeper-app/src/main/res/drawable-xhdpi/about_logo.png -------------------------------------------------------------------------------- /beacon-keeper-app/src/main/res/drawable-xhdpi/btn_settings.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/m039/beacon-keeper/HEAD/beacon-keeper-app/src/main/res/drawable-xhdpi/btn_settings.png -------------------------------------------------------------------------------- /beacon-keeper-app/src/main/res/drawable-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/m039/beacon-keeper/HEAD/beacon-keeper-app/src/main/res/drawable-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /beacon-keeper-app/src/main/res/drawable-xhdpi/ico_settings.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/m039/beacon-keeper/HEAD/beacon-keeper-app/src/main/res/drawable-xhdpi/ico_settings.png -------------------------------------------------------------------------------- /beacon-keeper-app/src/main/res/drawable-xhdpi/radar_circle.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/m039/beacon-keeper/HEAD/beacon-keeper-app/src/main/res/drawable-xhdpi/radar_circle.png -------------------------------------------------------------------------------- /beacon-keeper-app/src/main/res/drawable-xhdpi/splash__logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/m039/beacon-keeper/HEAD/beacon-keeper-app/src/main/res/drawable-xhdpi/splash__logo.png -------------------------------------------------------------------------------- /beacon-keeper-app/src/main/res/drawable-xhdpi/switch_thumb.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/m039/beacon-keeper/HEAD/beacon-keeper-app/src/main/res/drawable-xhdpi/switch_thumb.png -------------------------------------------------------------------------------- /beacon-keeper-app/src/main/res/drawable-xhdpi/switch_track.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/m039/beacon-keeper/HEAD/beacon-keeper-app/src/main/res/drawable-xhdpi/switch_track.png -------------------------------------------------------------------------------- /beacon-keeper-app/src/main/res/drawable-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/m039/beacon-keeper/HEAD/beacon-keeper-app/src/main/res/drawable-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /beacon-keeper-app/src/main/res/values/attrs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | include ":beacon-keeper-library", ":beacon-keeper-samples:beacon-keeper-background-sample", ":beacon-keeper-samples:beacon-keeper-foreground-sample", ":beacon-keeper-app" 2 | -------------------------------------------------------------------------------- /beacon-keeper-app/src/main/res/drawable-hdpi/beacon_entity__producer__estimote.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/m039/beacon-keeper/HEAD/beacon-keeper-app/src/main/res/drawable-hdpi/beacon_entity__producer__estimote.png -------------------------------------------------------------------------------- /beacon-keeper-app/src/main/res/drawable-hdpi/beacon_entity__producer__kontakt.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/m039/beacon-keeper/HEAD/beacon-keeper-app/src/main/res/drawable-hdpi/beacon_entity__producer__kontakt.png -------------------------------------------------------------------------------- /beacon-keeper-app/src/main/res/drawable-hdpi/beacon_entity__producer__qualcomm.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/m039/beacon-keeper/HEAD/beacon-keeper-app/src/main/res/drawable-hdpi/beacon_entity__producer__qualcomm.png -------------------------------------------------------------------------------- /beacon-keeper-app/src/main/res/drawable-hdpi/beacon_entity__producer__unknown.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/m039/beacon-keeper/HEAD/beacon-keeper-app/src/main/res/drawable-hdpi/beacon_entity__producer__unknown.png -------------------------------------------------------------------------------- /beacon-keeper-app/src/main/res/drawable-ldpi/beacon_entity__producer__estimote.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/m039/beacon-keeper/HEAD/beacon-keeper-app/src/main/res/drawable-ldpi/beacon_entity__producer__estimote.png -------------------------------------------------------------------------------- /beacon-keeper-app/src/main/res/drawable-ldpi/beacon_entity__producer__kontakt.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/m039/beacon-keeper/HEAD/beacon-keeper-app/src/main/res/drawable-ldpi/beacon_entity__producer__kontakt.png -------------------------------------------------------------------------------- /beacon-keeper-app/src/main/res/drawable-ldpi/beacon_entity__producer__qualcomm.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/m039/beacon-keeper/HEAD/beacon-keeper-app/src/main/res/drawable-ldpi/beacon_entity__producer__qualcomm.png -------------------------------------------------------------------------------- /beacon-keeper-app/src/main/res/drawable-ldpi/beacon_entity__producer__unknown.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/m039/beacon-keeper/HEAD/beacon-keeper-app/src/main/res/drawable-ldpi/beacon_entity__producer__unknown.png -------------------------------------------------------------------------------- /beacon-keeper-app/src/main/res/drawable-mdpi/beacon_entity__producer__estimote.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/m039/beacon-keeper/HEAD/beacon-keeper-app/src/main/res/drawable-mdpi/beacon_entity__producer__estimote.png -------------------------------------------------------------------------------- /beacon-keeper-app/src/main/res/drawable-mdpi/beacon_entity__producer__kontakt.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/m039/beacon-keeper/HEAD/beacon-keeper-app/src/main/res/drawable-mdpi/beacon_entity__producer__kontakt.png -------------------------------------------------------------------------------- /beacon-keeper-app/src/main/res/drawable-mdpi/beacon_entity__producer__qualcomm.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/m039/beacon-keeper/HEAD/beacon-keeper-app/src/main/res/drawable-mdpi/beacon_entity__producer__qualcomm.png -------------------------------------------------------------------------------- /beacon-keeper-app/src/main/res/drawable-mdpi/beacon_entity__producer__unknown.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/m039/beacon-keeper/HEAD/beacon-keeper-app/src/main/res/drawable-mdpi/beacon_entity__producer__unknown.png -------------------------------------------------------------------------------- /beacon-keeper-app/src/main/res/drawable-xhdpi/beacon_entity__producer__kontakt.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/m039/beacon-keeper/HEAD/beacon-keeper-app/src/main/res/drawable-xhdpi/beacon_entity__producer__kontakt.png -------------------------------------------------------------------------------- /beacon-keeper-app/src/main/res/drawable-xhdpi/beacon_entity__producer__unknown.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/m039/beacon-keeper/HEAD/beacon-keeper-app/src/main/res/drawable-xhdpi/beacon_entity__producer__unknown.png -------------------------------------------------------------------------------- /beacon-keeper-app/src/main/res/drawable-hdpi/beacon_entity__producer__sticknfind.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/m039/beacon-keeper/HEAD/beacon-keeper-app/src/main/res/drawable-hdpi/beacon_entity__producer__sticknfind.png -------------------------------------------------------------------------------- /beacon-keeper-app/src/main/res/drawable-ldpi/beacon_entity__producer__sticknfind.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/m039/beacon-keeper/HEAD/beacon-keeper-app/src/main/res/drawable-ldpi/beacon_entity__producer__sticknfind.png -------------------------------------------------------------------------------- /beacon-keeper-app/src/main/res/drawable-mdpi/beacon_entity__producer__sticknfind.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/m039/beacon-keeper/HEAD/beacon-keeper-app/src/main/res/drawable-mdpi/beacon_entity__producer__sticknfind.png -------------------------------------------------------------------------------- /beacon-keeper-app/src/main/res/drawable-xhdpi/beacon_entity__producer__estimote.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/m039/beacon-keeper/HEAD/beacon-keeper-app/src/main/res/drawable-xhdpi/beacon_entity__producer__estimote.png -------------------------------------------------------------------------------- /beacon-keeper-app/src/main/res/drawable-xhdpi/beacon_entity__producer__qualcomm.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/m039/beacon-keeper/HEAD/beacon-keeper-app/src/main/res/drawable-xhdpi/beacon_entity__producer__qualcomm.png -------------------------------------------------------------------------------- /beacon-keeper-app/src/main/res/drawable-xhdpi/beacon_entity__producer__sticknfind.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/m039/beacon-keeper/HEAD/beacon-keeper-app/src/main/res/drawable-xhdpi/beacon_entity__producer__sticknfind.png -------------------------------------------------------------------------------- /beacon-keeper-samples/beacon-keeper-background-sample/src/main/res/drawable-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/m039/beacon-keeper/HEAD/beacon-keeper-samples/beacon-keeper-background-sample/src/main/res/drawable-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /beacon-keeper-samples/beacon-keeper-foreground-sample/src/main/res/drawable-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/m039/beacon-keeper/HEAD/beacon-keeper-samples/beacon-keeper-foreground-sample/src/main/res/drawable-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Sat Aug 01 15:11:19 MSK 2015 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-2.2-all.zip 7 | -------------------------------------------------------------------------------- /beacon-keeper-app/src/main/res/anim/enter_in.xml: -------------------------------------------------------------------------------- 1 | 3 | 7 | 8 | -------------------------------------------------------------------------------- /beacon-keeper-app/src/main/res/xml/google_analytics_tracker.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 300 5 | 6 | true 7 | 8 | UA-37266719-4 9 | 10 | 11 | -------------------------------------------------------------------------------- /beacon-keeper-app/src/main/res/anim/enter_out.xml: -------------------------------------------------------------------------------- 1 | 3 | 7 | 8 | -------------------------------------------------------------------------------- /beacon-keeper-app/src/main/res/anim/finish_in.xml: -------------------------------------------------------------------------------- 1 | 3 | 6 | 7 | -------------------------------------------------------------------------------- /beacon-keeper-app/src/main/res/anim/finish_out.xml: -------------------------------------------------------------------------------- 1 | 3 | 7 | 8 | -------------------------------------------------------------------------------- /beacon-keeper-app/src/main/res/drawable/button_normal.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /beacon-keeper-app/src/main/res/drawable/button_selected.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /beacon-keeper-library/src/main/res/values/config.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 1000 5 | 1000 6 | 30000 7 | 8 | 9 | -------------------------------------------------------------------------------- /beacon-keeper-app/src/main/res/values/dimens.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 200dp 5 | 200dp 6 | 24dp 7 | 8 | 100dp 9 | 100dp 10 | 11 | 12 | -------------------------------------------------------------------------------- /beacon-keeper-samples/beacon-keeper-background-sample/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | BeaconKeeper background sample 5 | This is background sample.\nUse logcat to see if it is working.\nDon\'t forget to turn bluetooth on! 6 | 7 | 8 | -------------------------------------------------------------------------------- /beacon-keeper-samples/beacon-keeper-foreground-sample/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | BeaconKeeper foreground sample 5 | This is foreground sample.\nUse logcat to see if it is working.\nDon\'t forget to turn bluetooth on! 6 | 7 | 8 | -------------------------------------------------------------------------------- /beacon-keeper-app/src/main/res/drawable/switcher_thumb.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 9 | 10 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /beacon-keeper-app/src/main/res/drawable/switcher_track.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 9 | 10 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /beacon-keeper-app/src/main/res/values/colors.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | #ed4a3b 5 | @android:color/white 6 | #000 7 | #00F 8 | #0F0 9 | 10 | #1a1a1a 11 | 12 | 13 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | local.properties 2 | build/ 3 | target 4 | bin 5 | gen 6 | .classpath 7 | .project 8 | .settings 9 | .idea 10 | .factorypath 11 | *.iml 12 | .gradle 13 | sandbox 14 | doc/TodoDesign.md 15 | design 16 | beacon-keeper.apk 17 | release.keystore 18 | sign.sh 19 | doc/ 20 | pom_back.xml 21 | *.sig 22 | beacon-keeper-app/gen-external-apklibs/ 23 | .m039-android-project 24 | project.properties 25 | out/ -------------------------------------------------------------------------------- /beacon-keeper-samples/beacon-keeper-background-sample/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | 3 | android { 4 | compileSdkVersion 22 5 | buildToolsVersion "22.0.1" 6 | 7 | defaultConfig { 8 | minSdkVersion 18 9 | targetSdkVersion 22 10 | versionCode 1 11 | versionName "1.0" 12 | } 13 | } 14 | 15 | dependencies { 16 | compile project (":beacon-keeper-library") 17 | } 18 | -------------------------------------------------------------------------------- /beacon-keeper-samples/beacon-keeper-foreground-sample/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | 3 | android { 4 | compileSdkVersion 22 5 | buildToolsVersion "22.0.1" 6 | 7 | defaultConfig { 8 | minSdkVersion 18 9 | targetSdkVersion 22 10 | versionCode 1 11 | versionName "1.0" 12 | } 13 | } 14 | 15 | dependencies { 16 | compile project (":beacon-keeper-library") 17 | } 18 | -------------------------------------------------------------------------------- /beacon-keeper-app/src/main/res/color/button.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 7 | 8 | 11 | 12 | 15 | 16 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /beacon-keeper-app/src/main/res/values/themes.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 9 | 10 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /beacon-keeper-library/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 10 | 11 | 12 | 15 | 16 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /beacon-keeper-app/build.gradle: -------------------------------------------------------------------------------- 1 | repositories { 2 | mavenCentral() 3 | } 4 | 5 | apply plugin: 'com.android.application' 6 | 7 | android { 8 | compileSdkVersion 22 9 | buildToolsVersion "22.0.1" 10 | 11 | defaultConfig { 12 | minSdkVersion 18 13 | targetSdkVersion 22 14 | versionCode 1 15 | versionName "1.0" 16 | } 17 | } 18 | 19 | dependencies { 20 | compile project (':beacon-keeper-library') 21 | compile 'com.android.support:recyclerview-v7:+' 22 | compile 'com.google.android.gms:play-services:+' 23 | compile 'uk.co.chrisjenx:calligraphy:1.2.0' 24 | } 25 | -------------------------------------------------------------------------------- /beacon-keeper-app/src/main/res/drawable/button.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 7 | 8 | 11 | 12 | 15 | 16 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /beacon-keeper-samples/beacon-keeper-background-sample/src/main/res/layout/a_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | 16 | 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /beacon-keeper-samples/beacon-keeper-foreground-sample/src/main/res/layout/a_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | 16 | 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /beacon-keeper-library/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | far 5 | near 6 | immediate 7 | 8 | ibeacon_keeper__pref_key__scanning_time_ms 9 | ibeacon_keeper__pref_key__idle_time_ms 10 | ibeacon_keeper__pref_key__beacon_ttl_ms 11 | 12 | 13 | -------------------------------------------------------------------------------- /beacon-keeper-app/src/main/java/com/m039/beacon/keeper/fragment/BaseFragment.java: -------------------------------------------------------------------------------- 1 | /** BaseFragment.java --- 2 | * 3 | * Copyright (C) 2014 Dmitry Mozgin 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | * 17 | */ 18 | 19 | package com.m039.beacon.keeper.fragment; 20 | 21 | import android.app.Fragment; 22 | 23 | /** 24 | * 25 | * 26 | * Created: 07/05/14 27 | * 28 | * @author Dmitry Mozgin 29 | * @version 30 | * @since 31 | */ 32 | public class BaseFragment extends Fragment { 33 | 34 | 35 | } // BaseFragment 36 | -------------------------------------------------------------------------------- /beacon-keeper-library/src/main/java/com/m039/beacon/keeper/C.java: -------------------------------------------------------------------------------- 1 | /** C.java --- 2 | * 3 | * Copyright (C) 2014 Dmitry Mozgin 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | * 17 | */ 18 | 19 | package com.m039.beacon.keeper; 20 | 21 | import com.m039.beacon.keeper.library.BuildConfig; 22 | 23 | /** 24 | * 25 | * 26 | * Created: 07/03/14 27 | * 28 | * @author Dmitry Mozgin 29 | * @version 30 | * @since 31 | */ 32 | public class C { 33 | 34 | public final static boolean DEBUG = BuildConfig.DEBUG; 35 | public final static int NO_ID = 0; 36 | 37 | } // C 38 | -------------------------------------------------------------------------------- /beacon-keeper-samples/beacon-keeper-background-sample/src/main/java/com/m039/beacon/keeper/app/MainApplication.java: -------------------------------------------------------------------------------- 1 | /** MainApplication.java --- 2 | * 3 | * Copyright (C) 2014 Dmitry Mozgin 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | * 17 | */ 18 | 19 | package com.m039.beacon.keeper.app; 20 | 21 | import android.app.Application; 22 | 23 | import com.m039.beacon.keeper.service.BeaconService; 24 | 25 | /** 26 | * 27 | * 28 | * Created: 29 | * 30 | * @author 31 | * @version 32 | * @since 33 | */ 34 | public class MainApplication extends Application { 35 | 36 | @Override 37 | public void onCreate () { 38 | super.onCreate (); 39 | 40 | BeaconService.onApplicationCreate(this); 41 | } 42 | 43 | } // MainApplication 44 | -------------------------------------------------------------------------------- /beacon-keeper-samples/beacon-keeper-foreground-sample/src/main/java/com/m039/beacon/keeper/app/MainApplication.java: -------------------------------------------------------------------------------- 1 | /** MainApplication.java --- 2 | * 3 | * Copyright (C) 2014 Dmitry Mozgin 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | * 17 | */ 18 | 19 | package com.m039.beacon.keeper.app; 20 | 21 | import android.app.Application; 22 | 23 | import com.m039.beacon.keeper.service.BeaconService; 24 | 25 | /** 26 | * 27 | * 28 | * Created: 29 | * 30 | * @author 31 | * @version 32 | * @since 33 | */ 34 | public class MainApplication extends Application { 35 | 36 | @Override 37 | public void onCreate () { 38 | super.onCreate (); 39 | 40 | BeaconService.onApplicationCreate(this); 41 | } 42 | 43 | } // MainApplication 44 | -------------------------------------------------------------------------------- /beacon-keeper-samples/beacon-keeper-foreground-sample/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 25 | 26 | 27 | 28 | 29 | -------------------------------------------------------------------------------- /beacon-keeper-samples/beacon-keeper-background-sample/src/main/java/com/m039/beacon/keeper/activity/MainActivity.java: -------------------------------------------------------------------------------- 1 | /** MainActivity.java --- 2 | * 3 | * Copyright (C) 2014 Dmitry Mozgin 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | * 17 | */ 18 | 19 | package com.m039.beacon.keeper.activity; 20 | 21 | import com.m039.beacon.keeper.background_sample.R; 22 | import android.app.Activity; 23 | import android.os.Bundle; 24 | 25 | /** 26 | * 27 | * 28 | * Created: 29 | * 30 | * @author 31 | * @version 32 | * @since 33 | */ 34 | public class MainActivity extends Activity { 35 | 36 | @Override 37 | protected void onCreate(Bundle savedInstanceState) { 38 | super.onCreate(savedInstanceState); 39 | setContentView(R.layout.a_main); 40 | } 41 | 42 | 43 | } // MainActivity 44 | -------------------------------------------------------------------------------- /Readme.md: -------------------------------------------------------------------------------- 1 | Beacon Keeper 2 | ============= 3 | 4 | Beacon Keeper is a small, simple and solid library for working with iBeacons for Android. Before using it you may want to try it with [a standalone application](https://play.google.com/store/apps/details?id=com.m039.beacon.keeper.app). 5 | 6 | If you need a more robust approach, you should prefer [android-beacon-library](https://github.com/AltBeacon/android-beacon-library). 7 | 8 | Main features 9 | ------------- 10 | 11 | * Locating iBeacons in background. 12 | * Dead simple [samples](https://github.com/m039/beacon-keeper/tree/master/beacon-keeper-samples). 13 | 14 | Acknowledges 15 | ------------ 16 | 17 | [RadiusNetworks](https://github.com/RadiusNetworks) for their contributions to community. 18 | 19 | License 20 | ------- 21 | 22 | Copyright (c) 2014 Dmitry Mozgin 23 | 24 | Licensed under the Apache License, Version 2.0 (the "License"); 25 | you may not use this file except in compliance with the License. 26 | You may obtain a copy of the License at 27 | 28 | http://www.apache.org/licenses/LICENSE-2.0 29 | 30 | Unless required by applicable law or agreed to in writing, software 31 | distributed under the License is distributed on an "AS IS" BASIS, 32 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 33 | See the License for the specific language governing permissions and 34 | limitations under the License. 35 | -------------------------------------------------------------------------------- /beacon-keeper-app/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Beacon\nKeeper 5 | 6 | Scanning time in ms 7 | Idle time in ms 8 | Beacon time to live 9 | How long beacon considered visible 10 | 11 | Beacon\nKeeper 12 | 13 | Bluetooth\ndisabled 14 | Bluetooth\nenabled 15 | Enabling\nbluetooth 16 | Disabling\nbluetooth 17 | 18 | settings 19 | about 20 | 21 | @string/app_name 22 | Beacon Keeper is standalone application that shows use cases of it\'s own library.\nThe main goal of this project is to create solid and simple library for locating and working with iBeacons for Android. 23 | Click it here: 24 | link 25 | Copyright(c) 2014\nDmitry Mozgin 26 | 27 | 28 | -------------------------------------------------------------------------------- /beacon-keeper-app/src/main/res/xml/preferences.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 10 | 11 | 17 | 18 | 24 | 25 | 26 | 27 | 31 | 32 | 39 | 40 | 41 | 42 | 43 | -------------------------------------------------------------------------------- /beacon-keeper-library/src/main/java/com/m039/beacon/keeper/L.java: -------------------------------------------------------------------------------- 1 | /** L.java --- 2 | * 3 | * Copyright (C) 2014 Dmitry Mozgin 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | * 17 | */ 18 | 19 | package com.m039.beacon.keeper; 20 | 21 | import android.util.Log; 22 | 23 | /** 24 | * 25 | * 26 | * Created: 07/03/14 27 | * 28 | * @author Dmitry Mozgin 29 | * @version 30 | * @since 31 | */ 32 | public class L { 33 | 34 | public static final String TAG = "m039-L"; 35 | 36 | public static int d (String msg) { 37 | return d(TAG, msg); 38 | } 39 | 40 | public static int d (String tag, String msg) { 41 | return d(tag, msg, (Object[]) null); 42 | } 43 | 44 | public static int d(String tag, String fmt, Object ... args) { 45 | if (C.DEBUG) { 46 | return Log.d(tag, String.format(fmt, args)); 47 | } 48 | 49 | return -1; 50 | } 51 | 52 | public static int wtf(String tag, String msg) { 53 | if (C.DEBUG) { 54 | return Log.wtf(tag, msg); 55 | } 56 | 57 | return -1; 58 | } 59 | 60 | } // L 61 | -------------------------------------------------------------------------------- /beacon-keeper-samples/beacon-keeper-background-sample/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 26 | 27 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | -------------------------------------------------------------------------------- /beacon-keeper-app/src/main/java/com/m039/beacon/keeper/app/MainApplication.java: -------------------------------------------------------------------------------- 1 | /** MainApplication.java --- 2 | * 3 | * Copyright (C) 2014 Dmitry Mozgin 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | * 17 | */ 18 | 19 | package com.m039.beacon.keeper.app; 20 | 21 | import uk.co.chrisjenx.calligraphy.CalligraphyConfig; 22 | 23 | import android.app.Application; 24 | 25 | import com.google.android.gms.analytics.GoogleAnalytics; 26 | import com.google.android.gms.analytics.Tracker; 27 | import com.m039.beacon.keeper.service.BeaconService; 28 | 29 | /** 30 | * 31 | * 32 | * Created: 03/22/14 33 | * 34 | * @author Dmitry Mozgin 35 | * @version 36 | * @since 37 | */ 38 | public class MainApplication extends Application { 39 | 40 | @Override 41 | public void onCreate () { 42 | super.onCreate (); 43 | 44 | BeaconService.onApplicationCreate(this); 45 | 46 | CalligraphyConfig.initDefault("fonts/Intro-Regular.otf", R.attr.fontPath); 47 | } 48 | 49 | Tracker mTracker = null; 50 | 51 | public synchronized Tracker getTracker() { 52 | if (mTracker == null) { 53 | mTracker = GoogleAnalytics.getInstance(this).newTracker(R.xml.google_analytics_tracker); 54 | } 55 | 56 | return mTracker; 57 | } 58 | 59 | 60 | } // MainApplication 61 | -------------------------------------------------------------------------------- /beacon-keeper-app/src/main/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 7 | 8 | 9 | 14 | 15 | 20 | 21 | 26 | 27 | 33 | 34 | 38 | 39 | 49 | 50 | 51 | -------------------------------------------------------------------------------- /beacon-keeper-samples/beacon-keeper-background-sample/src/main/java/com/m039/beacon/keeper/receiver/MainReceiver.java: -------------------------------------------------------------------------------- 1 | /** MainReceiver.java --- 2 | * 3 | * Copyright (C) 2014 Dmitry Mozgin 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | * 17 | */ 18 | 19 | package com.m039.beacon.keeper.receiver; 20 | 21 | import com.m039.beacon.keeper.content.BeaconEntity; 22 | import com.m039.beacon.keeper.service.BeaconService; 23 | 24 | 25 | import android.content.Context; 26 | import android.content.Intent; 27 | 28 | /** 29 | * 30 | * 31 | * Created: 32 | * 33 | * @author 34 | * @version 35 | * @since 36 | */ 37 | public class MainReceiver extends com.m039.beacon.keeper.receiver.BeaconReceiver { 38 | 39 | @Override 40 | public void onReceive(Context context, Intent intent) { 41 | String action = intent.getAction(); 42 | 43 | if (action.equals(Intent.ACTION_BOOT_COMPLETED)) { 44 | BeaconService.onBootCompleted(context); 45 | android.util.Log.d("MainReceiver", "onBootCompleted"); 46 | } else { 47 | super.onReceive(context, intent); 48 | } 49 | } 50 | 51 | @Override 52 | protected void onFoundBeacon(Context context, BeaconEntity beaconEntity) { 53 | android.util.Log.d("MainReceiver", "onFoundBeacon | " + beaconEntity.getIBeacon()); 54 | } 55 | 56 | } // MainReceiver 57 | -------------------------------------------------------------------------------- /beacon-keeper-app/src/main/java/com/m039/beacon/keeper/activity/AboutA.java: -------------------------------------------------------------------------------- 1 | /** AboutA.java --- 2 | * 3 | * Copyright (C) 2014 Dmitry Mozgin 4 | * 5 | * Author: Dmitry Mozgin 6 | * 7 | * 8 | */ 9 | 10 | package com.m039.beacon.keeper.activity; 11 | 12 | import android.app.Activity; 13 | import android.content.Intent; 14 | import android.content.pm.PackageManager; 15 | import android.net.Uri; 16 | import android.os.Bundle; 17 | import android.view.View; 18 | import android.widget.TextView; 19 | 20 | import com.m039.beacon.keeper.app.R; 21 | 22 | /** 23 | * 24 | * 25 | * Created: 26 | * 27 | * @author Dmitry Mozgin 28 | * @version 1 29 | * @since Sat Dec 20 08:45:26 2014 30 | */ 31 | public class AboutA extends BaseActivity { 32 | 33 | public static void startActivity(Activity a) { 34 | a.startActivity(new Intent(a, AboutA.class)); 35 | a.overridePendingTransition (R.anim.enter_in, R.anim.enter_out); 36 | } 37 | 38 | @Override 39 | protected void onCreate(Bundle savedInstanceState) { 40 | super.onCreate(savedInstanceState); 41 | setContentView(R.layout.a_about); 42 | 43 | // set versionName 44 | 45 | try { 46 | ((TextView) findViewById(R.id.version_name)) 47 | .setText("v" + getPackageManager().getPackageInfo(getPackageName(), 0).versionName); 48 | } catch (PackageManager.NameNotFoundException e) { 49 | } 50 | 51 | // set link button listener 52 | 53 | findViewById(R.id.link).setOnClickListener(new View.OnClickListener() { 54 | @Override 55 | public void onClick(View v) { 56 | Intent i = new Intent(Intent.ACTION_VIEW); 57 | i.setData(Uri.parse("https://github.com/m039/beacon-keeper")); 58 | startActivity(i); 59 | } 60 | }); 61 | } 62 | 63 | @Override 64 | public void onBackPressed() { 65 | super.onBackPressed(); 66 | 67 | overridePendingTransition (R.anim.finish_in, R.anim.finish_out); 68 | } 69 | 70 | } // AboutA 71 | -------------------------------------------------------------------------------- /beacon-keeper-samples/beacon-keeper-foreground-sample/src/main/java/com/m039/beacon/keeper/activity/MainActivity.java: -------------------------------------------------------------------------------- 1 | /** MainActivity.java --- 2 | * 3 | * Copyright (C) 2014 Dmitry Mozgin 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | * 17 | */ 18 | 19 | package com.m039.beacon.keeper.activity; 20 | 21 | import android.content.Context; 22 | import android.app.Activity; 23 | import android.os.Bundle; 24 | 25 | import com.m039.beacon.keeper.foreground_sample.R; 26 | import com.m039.beacon.keeper.receiver.BeaconReceiver; 27 | import com.m039.beacon.keeper.content.BeaconEntity; 28 | 29 | /** 30 | * 31 | * 32 | * Created: 33 | * 34 | * @author 35 | * @version 36 | * @since 37 | */ 38 | public class MainActivity extends Activity { 39 | 40 | @Override 41 | protected void onCreate(Bundle savedInstanceState) { 42 | super.onCreate(savedInstanceState); 43 | setContentView(R.layout.a_main); 44 | } 45 | 46 | private BeaconReceiver mBeaconReceiver = new BeaconReceiver() { 47 | 48 | @Override 49 | protected void onFoundBeacon(Context ctx, BeaconEntity beaconEntity) { 50 | android.util.Log.d("MainActivity", "onFoundBeacon | " + beaconEntity.getIBeacon()); 51 | } 52 | 53 | }; 54 | 55 | @Override 56 | protected void onStart() { 57 | super.onStart(); 58 | 59 | mBeaconReceiver.register(this); 60 | } 61 | 62 | @Override 63 | protected void onStop() { 64 | super.onStop(); 65 | 66 | mBeaconReceiver.unregister(this); 67 | } 68 | 69 | 70 | } // MainActivity 71 | -------------------------------------------------------------------------------- /beacon-keeper-library/src/main/java/com/m039/beacon/keeper/util/OnEnableBluetoothCallback.java: -------------------------------------------------------------------------------- 1 | /** OnEnableBluetoothCallback.java --- 2 | * 3 | * Copyright (C) 2014 Dmitry Mozgin 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | * 17 | */ 18 | 19 | package com.m039.beacon.keeper.util; 20 | 21 | import android.app.Activity; 22 | import android.content.Intent; 23 | import android.os.Bundle; 24 | 25 | import com.m039.beacon.keeper.U; 26 | 27 | /** 28 | * 29 | * 30 | * Created: 06/26/14 31 | * 32 | * @author Dmitry Mozgin 33 | * @version 34 | * @since 35 | */ 36 | public abstract class OnEnableBluetoothCallback { 37 | 38 | private int mRequestCode = -1; 39 | 40 | public void onCreate(Activity a, Bundle savedInstanceState, int requestCode) { 41 | mRequestCode = requestCode; 42 | 43 | if (U.BLE.checkPermissions(a) && 44 | U.BLE.checkFeatures(a)) { 45 | 46 | if (U.BLE.isEnabled(a)) { 47 | onBluetoothEnabled(); 48 | } else { 49 | a.startActivityForResult(U.BLE.createRequestEnableIntent(), requestCode); 50 | } 51 | 52 | } else { 53 | onBluetoothDisabled(); 54 | } 55 | } 56 | 57 | public void onActivityResult (Activity a, int requestCode, int resultCode, Intent data) { 58 | if (requestCode == mRequestCode && 59 | resultCode == Activity.RESULT_OK) { 60 | onBluetoothEnabled(); 61 | } else { 62 | onBluetoothDisabled(); 63 | } 64 | } 65 | 66 | abstract public void onBluetoothEnabled(); 67 | abstract public void onBluetoothDisabled(); 68 | 69 | 70 | } // OnEnableBluetoothCallback 71 | -------------------------------------------------------------------------------- /beacon-keeper-app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 23 | 24 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 40 | 41 | 45 | 46 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | -------------------------------------------------------------------------------- /beacon-keeper-app/src/main/res/layout/a_settings.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | 15 | 16 | 22 | 23 | 30 | 31 | 41 | 42 | 43 | 44 | 45 | 49 | 50 | 61 | 62 | 70 | 71 | 72 | 73 | -------------------------------------------------------------------------------- /beacon-keeper-app/src/main/java/com/m039/beacon/keeper/activity/SettingsA.java: -------------------------------------------------------------------------------- 1 | /** SettingsA.java --- 2 | * 3 | * Copyright (C) 2014 Dmitry Mozgin 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | * 17 | */ 18 | 19 | package com.m039.beacon.keeper.activity; 20 | 21 | import android.app.Activity; 22 | import android.content.Intent; 23 | import android.os.Bundle; 24 | import android.preference.PreferenceFragment; 25 | import android.view.View; 26 | 27 | import com.m039.beacon.keeper.app.R; 28 | 29 | /** 30 | * 31 | * 32 | * Created: 33 | * 34 | * @author Dmitry Mozgin 35 | * @version 1 36 | * @since Sat Dec 20 08:11:50 2014 37 | */ 38 | public class SettingsA extends BaseActivity { 39 | 40 | public static void startActivity(Activity a) { 41 | a.startActivity(new Intent(a, SettingsA.class)); 42 | a.overridePendingTransition (R.anim.enter_in, R.anim.enter_out); 43 | } 44 | 45 | @Override 46 | protected void onCreate(Bundle savedInstanceState) { 47 | super.onCreate(savedInstanceState); 48 | setContentView(R.layout.a_settings); 49 | 50 | if (savedInstanceState == null) { 51 | getFragmentManager() 52 | .beginTransaction() 53 | .replace(R.id.fragment, new SettingsFragment()) 54 | .commit(); 55 | } 56 | 57 | findViewById(R.id.about).setOnClickListener(new View.OnClickListener() { 58 | @Override 59 | public void onClick(View v) { 60 | AboutA.startActivity(SettingsA.this); 61 | } 62 | }); 63 | } 64 | 65 | @Override 66 | public void onBackPressed() { 67 | super.onBackPressed(); 68 | 69 | overridePendingTransition (R.anim.finish_in, R.anim.finish_out); 70 | } 71 | 72 | public static class SettingsFragment extends PreferenceFragment { 73 | 74 | @Override 75 | public void onCreate(Bundle savedInstanceState) { 76 | super.onCreate(savedInstanceState); 77 | addPreferencesFromResource(R.xml.preferences); 78 | } 79 | 80 | } 81 | 82 | } // SettingsA 83 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /beacon-keeper-app/src/main/res/layout/e_list.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | 17 | 18 | 27 | 28 | 38 | 39 | 47 | 48 | 57 | 58 | 68 | 69 | 79 | 80 | 89 | 90 | 91 | -------------------------------------------------------------------------------- /beacon-keeper-library/src/main/java/com/m039/beacon/keeper/receiver/BeaconReceiver.java: -------------------------------------------------------------------------------- 1 | /** BeaconReceiver.java --- 2 | * 3 | * Copyright (C) 2014 Dmitry Mozgin 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | * 17 | */ 18 | 19 | package com.m039.beacon.keeper.receiver; 20 | 21 | import android.bluetooth.BluetoothAdapter; 22 | import android.content.BroadcastReceiver; 23 | import android.content.Context; 24 | import android.content.Intent; 25 | import android.content.IntentFilter; 26 | 27 | import com.m039.beacon.keeper.content.BeaconEntity; 28 | import com.m039.beacon.keeper.service.BeaconService; 29 | 30 | /** 31 | * 32 | * 33 | * Created: 07/01/14 34 | * 35 | * @author Dmitry Mozgin 36 | * @version 37 | * @since 38 | */ 39 | public class BeaconReceiver extends BroadcastReceiver 40 | { 41 | public static final String TAG = "m039-BeaconReceiver"; 42 | 43 | public static Intent registerReceiver(Context ctx, BroadcastReceiver br) { 44 | IntentFilter filter = new IntentFilter(); 45 | 46 | filter.addAction(BeaconService.ACTION_FOUND_BEACON); 47 | filter.addAction(BluetoothAdapter.ACTION_STATE_CHANGED); 48 | 49 | return ctx.registerReceiver(br, filter); 50 | } 51 | 52 | public static void unregisterReceiver(Context ctx, BroadcastReceiver br) { 53 | ctx.unregisterReceiver(br); 54 | } 55 | 56 | public Intent register(Context ctx) { 57 | return registerReceiver(ctx, this); 58 | } 59 | 60 | public void unregister(Context ctx) { 61 | unregisterReceiver(ctx, this); 62 | } 63 | 64 | @Override 65 | public void onReceive(Context context, Intent intent) { 66 | String action = intent.getAction(); 67 | 68 | if (action.equals(BeaconService.ACTION_FOUND_BEACON)) { 69 | onFoundBeacon(context, (BeaconEntity) intent.getParcelableExtra(BeaconService.EXTRA_BEACON_ENTITY)); 70 | } else if (action.equals(BluetoothAdapter.ACTION_STATE_CHANGED)) { 71 | int state = intent.getIntExtra(BluetoothAdapter.EXTRA_STATE, -1); 72 | if (state != -1) { 73 | onBluetoothStateChanged(context, state); 74 | } 75 | } 76 | } 77 | 78 | protected void onFoundBeacon(Context ctx, BeaconEntity beaconEntity) { 79 | } 80 | 81 | /** 82 | * @see android.bluetooth.BluetoothAdapter#ACTION_STATE_CHANGED 83 | */ 84 | protected void onBluetoothStateChanged(Context ctx, int state) { 85 | } 86 | 87 | } // BeaconReceiver 88 | -------------------------------------------------------------------------------- /beacon-keeper-library/src/main/java/com/m039/beacon/keeper/util/SimpleLeScanner.java: -------------------------------------------------------------------------------- 1 | /** SimpleLeScanner.java --- 2 | * 3 | * Copyright (C) 2014 Dmitry Mozgin 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | * 17 | */ 18 | 19 | package com.m039.beacon.keeper.util; 20 | 21 | import android.bluetooth.BluetoothAdapter; 22 | import android.bluetooth.BluetoothDevice; 23 | import android.content.Context; 24 | 25 | import com.m039.beacon.keeper.U; 26 | import com.m039.beacon.keeper.L; 27 | import com.m039.beacon.keeper.content.BeaconEntity; 28 | import com.m039.beacon.keeper.content.BeaconFactory; 29 | 30 | /** 31 | * 32 | * 33 | * Created: 34 | * 35 | * @author 36 | * @version 37 | * @since 38 | */ 39 | public class SimpleLeScanner { 40 | 41 | public static final String TAG = "m039-SimpleLeScanner"; 42 | 43 | public static abstract class LeScanCallback 44 | implements BluetoothAdapter.LeScanCallback { 45 | @Override 46 | public void onLeScan (BluetoothDevice device, int rssi, byte[] scanRecord) { 47 | BeaconEntity beaconEntity = BeaconFactory.decode(device, rssi, scanRecord); 48 | if (beaconEntity != null) { 49 | onLeScan(beaconEntity); 50 | } 51 | } 52 | 53 | public abstract void onLeScan(BeaconEntity beaconEntity); 54 | } 55 | 56 | private boolean mIsScanning = false; 57 | final private Context mContext; 58 | 59 | public SimpleLeScanner(Context ctx) { 60 | mContext = ctx.getApplicationContext(); 61 | } 62 | 63 | public boolean startScan(LeScanCallback callback) { 64 | BluetoothAdapter ba = U.getBluetoothAdapter(mContext); 65 | if (ba != null && ba.isEnabled() && !mIsScanning && callback != null) { 66 | if (ba.startLeScan(callback)) { 67 | mIsScanning = true; 68 | onStartScan(); 69 | return true; 70 | } 71 | } 72 | 73 | L.wtf(TAG, "Failed to startScan"); 74 | 75 | return false; 76 | } 77 | 78 | public void stopScan(LeScanCallback callback) { 79 | BluetoothAdapter ba = U.getBluetoothAdapter(mContext); 80 | if (ba != null && mIsScanning && callback != null) { 81 | ba.stopLeScan(callback); 82 | mIsScanning = false; 83 | onStopScan(); 84 | } else { 85 | L.wtf(TAG, "Failed to stopScan"); 86 | } 87 | } 88 | 89 | protected void onStartScan() { 90 | } 91 | 92 | protected void onStopScan() { 93 | } 94 | 95 | } // SimpleLeScanner 96 | -------------------------------------------------------------------------------- /beacon-keeper-app/src/main/java/com/m039/beacon/keeper/activity/BaseActivity.java: -------------------------------------------------------------------------------- 1 | /** BaseActivity.java --- 2 | * 3 | * Copyright (C) 2014 Dmitry Mozgin 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | * 17 | */ 18 | 19 | package com.m039.beacon.keeper.activity; 20 | 21 | import uk.co.chrisjenx.calligraphy.CalligraphyContextWrapper; 22 | 23 | import android.app.Activity; 24 | import android.content.Context; 25 | import android.os.Bundle; 26 | import android.os.Handler; 27 | import android.os.Message; 28 | 29 | import com.google.android.gms.analytics.HitBuilders; 30 | import com.google.android.gms.analytics.Tracker; 31 | import com.m039.beacon.keeper.app.MainApplication; 32 | import com.m039.beacon.keeper.content.BeaconEntity; 33 | import com.m039.beacon.keeper.receiver.BeaconReceiver; 34 | 35 | /** 36 | * 37 | * 38 | * Created: 06/17/14 39 | * 40 | * @author Dmitry Mozgin 41 | * @version 42 | * @since 43 | */ 44 | public class BaseActivity extends Activity { 45 | 46 | private static final int WHAT_PERIODIC_UPDATE = 0; 47 | 48 | private Handler mHandler = new Handler() { 49 | 50 | @Override 51 | public void handleMessage (Message msg) { 52 | if (msg.what == WHAT_PERIODIC_UPDATE) { 53 | onPeriodicUpdate(); 54 | sendEmptyMessageDelayed(msg.what, 1000); 55 | } 56 | } 57 | 58 | }; 59 | 60 | private BeaconReceiver mBeaconReceiver = new BeaconReceiver() { 61 | 62 | @Override 63 | protected void onFoundBeacon(Context ctx, BeaconEntity beaconEntity) { 64 | BaseActivity.this.onFoundBeacon(beaconEntity); 65 | } 66 | 67 | }; 68 | 69 | @Override 70 | protected void onCreate(Bundle savedInstanceState) { 71 | super.onCreate(savedInstanceState); 72 | 73 | Tracker t = ((MainApplication) getApplication()).getTracker(); 74 | t.setScreenName(getClass().getSimpleName()); 75 | t.send(new HitBuilders.AppViewBuilder().build()); 76 | } 77 | 78 | @Override 79 | protected void attachBaseContext(Context newBase) { 80 | super.attachBaseContext(new CalligraphyContextWrapper(newBase)); 81 | } 82 | 83 | @Override 84 | protected void onStart() { 85 | super.onStart(); 86 | 87 | mBeaconReceiver.register(this); 88 | startHandleMessages(); 89 | } 90 | 91 | @Override 92 | protected void onStop() { 93 | super.onStop(); 94 | 95 | mBeaconReceiver.unregister(this); 96 | stopHandleMessages(); 97 | } 98 | 99 | private void startHandleMessages() { 100 | mHandler.sendEmptyMessage(WHAT_PERIODIC_UPDATE); 101 | } 102 | 103 | private void stopHandleMessages() { 104 | mHandler.removeMessages(WHAT_PERIODIC_UPDATE); 105 | } 106 | 107 | protected void onPeriodicUpdate() { 108 | } 109 | 110 | protected void onFoundBeacon(BeaconEntity beaconEntity) { 111 | } 112 | 113 | } // BaseActivity 114 | -------------------------------------------------------------------------------- /beacon-keeper-app/src/main/res/layout/a_beacons.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | 13 | 14 | 21 | 22 | 28 | 29 | 34 | 35 | 42 | 43 | 49 | 50 | 57 | 58 | 68 | 69 | 70 | 71 | 76 | 77 | 84 | 85 | 86 | 87 | 88 | 89 | 94 | 95 | 101 | 102 | 103 | 104 | 105 | 106 | 111 | 112 | 113 | -------------------------------------------------------------------------------- /beacon-keeper-app/src/main/res/layout/f_splash.xml: -------------------------------------------------------------------------------- 1 | 2 | 9 | 10 | 15 | 16 | 23 | 24 | 29 | 30 | 35 | 36 | 51 | 52 | 59 | 60 | 61 | 62 | 73 | 74 | 75 | 76 | 77 | 83 | 84 | 91 | 92 | 97 | 98 | 109 | 110 | 111 | 112 | 113 | -------------------------------------------------------------------------------- /beacon-keeper-app/src/main/res/layout/a_about.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | 15 | 16 | 22 | 23 | 30 | 31 | 32 | 33 | 34 | 39 | 40 | 51 | 52 | 63 | 64 | 72 | 73 | 82 | 83 | 92 | 93 | 103 | 104 | 112 | 113 | 114 | 115 | -------------------------------------------------------------------------------- /beacon-keeper-library/src/main/java/com/m039/beacon/keeper/content/IBeacon.java: -------------------------------------------------------------------------------- 1 | /** IBeacon.java --- 2 | * 3 | * Copyright (C) 2014 Dmitry Mozgin 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | * 17 | */ 18 | 19 | package com.m039.beacon.keeper.content; 20 | 21 | import android.os.Parcel; 22 | import android.os.Parcelable; 23 | 24 | /** 25 | * 26 | * 27 | * Created: 07/01/14 28 | * 29 | * @author Dmitry Mozgin 30 | * @version 31 | * @since 32 | */ 33 | public final class IBeacon 34 | implements Parcelable, 35 | Comparable 36 | { 37 | 38 | protected String mUuid; 39 | protected int mMajor; 40 | protected int mMinor; 41 | protected int mTxPower; 42 | 43 | protected IBeacon() { 44 | } 45 | 46 | public IBeacon(String uuid, int major, int minor, int txPower) { 47 | mUuid = uuid; 48 | mMajor = major; 49 | mMinor = minor; 50 | mTxPower = txPower; 51 | } 52 | 53 | public String getUuid() { 54 | return mUuid; 55 | } 56 | 57 | public int getMajor() { 58 | return mMajor; 59 | } 60 | 61 | public int getMinor() { 62 | return mMinor; 63 | } 64 | 65 | public int getTxPower() { 66 | return mTxPower; 67 | } 68 | 69 | @Override 70 | public int hashCode() { 71 | int result = 17; 72 | 73 | result = 31 * result + (mUuid == null? 0 : mUuid.hashCode()); 74 | result = 31 * result + mMinor; 75 | result = 31 * result + mMajor; 76 | 77 | return result; 78 | } 79 | 80 | 81 | @Override 82 | public boolean equals(Object o) { 83 | if (this == o) { 84 | return true; 85 | } 86 | 87 | if (!(o instanceof IBeacon)) { 88 | return false; 89 | } 90 | 91 | 92 | IBeacon lhs = (IBeacon) o; 93 | 94 | return (mUuid == null? 95 | lhs.mUuid == null : mUuid.equalsIgnoreCase(lhs.mUuid)) && 96 | mMajor == lhs.mMajor && 97 | mMinor == lhs.mMinor; 98 | } 99 | 100 | @Override 101 | public String toString() { 102 | return String.format("IBeacon uuid: '%s', major: %d, minor: %d, txPower: %d", 103 | mUuid, mMajor, mMinor, mTxPower); 104 | } 105 | 106 | @Override 107 | public int compareTo (IBeacon another) { 108 | if (!(another instanceof IBeacon)) { 109 | throw new ClassCastException("A IBeacon object expected."); 110 | } 111 | 112 | int compare; 113 | 114 | compare = mUuid.compareTo(another.mUuid); 115 | if (compare != 0) { 116 | return compare; 117 | } 118 | 119 | compare = Integer.compare(mMajor, another.mMajor); 120 | if (compare != 0) { 121 | return compare; 122 | } 123 | 124 | return Integer.compare(mMinor, another.mMinor); 125 | } 126 | 127 | // 128 | // Parcelable 129 | // 130 | 131 | private IBeacon(Parcel in) { 132 | mUuid = in.readString(); 133 | mMajor = in.readInt(); 134 | mMinor = in.readInt(); 135 | mTxPower = in.readInt(); 136 | } 137 | 138 | public int describeContents() { 139 | return 0; 140 | } 141 | 142 | public void writeToParcel(Parcel out, int flags) { 143 | out.writeString(mUuid); 144 | out.writeInt(mMajor); 145 | out.writeInt(mMinor); 146 | out.writeInt(mTxPower); 147 | } 148 | 149 | public static final Parcelable.Creator CREATOR = new Parcelable.Creator() { 150 | public IBeacon createFromParcel(Parcel in) { 151 | return new IBeacon(in); 152 | } 153 | 154 | public IBeacon[] newArray(int size) { 155 | return new IBeacon[size]; 156 | } 157 | }; 158 | 159 | } // IBeacon 160 | -------------------------------------------------------------------------------- /beacon-keeper-app/src/main/java/com/m039/beacon/keeper/widget/DividerItemDecoration.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2014 The Android Open Source Project 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.m039.beacon.keeper.widget; 17 | 18 | import android.content.Context; 19 | import android.content.res.TypedArray; 20 | import android.graphics.Canvas; 21 | import android.graphics.Rect; 22 | import android.graphics.drawable.Drawable; 23 | import android.support.v7.widget.LinearLayoutManager; 24 | import android.support.v7.widget.RecyclerView; 25 | import android.view.View; 26 | 27 | import com.m039.beacon.keeper.app.R; 28 | 29 | public class DividerItemDecoration extends RecyclerView.ItemDecoration { 30 | 31 | private static final int[] ATTRS = new int[]{ 32 | android.R.attr.listDivider 33 | }; 34 | 35 | public static final int HORIZONTAL_LIST = LinearLayoutManager.HORIZONTAL; 36 | 37 | public static final int VERTICAL_LIST = LinearLayoutManager.VERTICAL; 38 | 39 | private Drawable mDivider; 40 | 41 | private int mOrientation; 42 | private int mPadding; // bad, not universal 43 | 44 | public DividerItemDecoration(Context context, int orientation) { 45 | final TypedArray a = context.obtainStyledAttributes(ATTRS); 46 | mDivider = a.getDrawable(0); 47 | a.recycle(); 48 | setOrientation(orientation); 49 | 50 | mPadding = context.getResources().getDimensionPixelOffset(R.dimen.e_list_padding); 51 | } 52 | 53 | public void setOrientation(int orientation) { 54 | if (orientation != HORIZONTAL_LIST && orientation != VERTICAL_LIST) { 55 | throw new IllegalArgumentException("invalid orientation"); 56 | } 57 | mOrientation = orientation; 58 | } 59 | 60 | @Override 61 | public void onDraw(Canvas c, RecyclerView parent) { 62 | if (mOrientation == VERTICAL_LIST) { 63 | drawVertical(c, parent); 64 | } else { 65 | drawHorizontal(c, parent); 66 | } 67 | } 68 | 69 | public void drawVertical(Canvas c, RecyclerView parent) { 70 | final int left = parent.getPaddingLeft() + mPadding; 71 | final int right = parent.getWidth() - parent.getPaddingRight() - mPadding; 72 | 73 | final int childCount = parent.getChildCount() - 1; 74 | for (int i = 0; i < childCount; i++) { 75 | final View child = parent.getChildAt(i); 76 | final RecyclerView.LayoutParams params = (RecyclerView.LayoutParams) child 77 | .getLayoutParams(); 78 | final int top = child.getBottom() + params.bottomMargin; 79 | final int bottom = top + mDivider.getIntrinsicHeight(); 80 | mDivider.setBounds(left, top, right, bottom); 81 | mDivider.draw(c); 82 | } 83 | } 84 | 85 | public void drawHorizontal(Canvas c, RecyclerView parent) { 86 | final int top = parent.getPaddingTop(); 87 | final int bottom = parent.getHeight() - parent.getPaddingBottom(); 88 | 89 | final int childCount = parent.getChildCount() - 1; 90 | for (int i = 0; i < childCount; i++) { 91 | final View child = parent.getChildAt(i); 92 | final RecyclerView.LayoutParams params = (RecyclerView.LayoutParams) child 93 | .getLayoutParams(); 94 | final int left = child.getRight() + params.rightMargin; 95 | final int right = left + mDivider.getIntrinsicHeight(); 96 | mDivider.setBounds(left, top, right, bottom); 97 | mDivider.draw(c); 98 | } 99 | } 100 | 101 | @Override 102 | public void getItemOffsets(Rect outRect, int itemPosition, RecyclerView parent) { 103 | if (mOrientation == VERTICAL_LIST) { 104 | outRect.set(0, 0, 0, mDivider.getIntrinsicHeight()); 105 | } else { 106 | outRect.set(0, 0, mDivider.getIntrinsicWidth(), 0); 107 | } 108 | } 109 | } 110 | -------------------------------------------------------------------------------- /beacon-keeper-app/src/main/java/com/m039/beacon/keeper/activity/BeaconA.java: -------------------------------------------------------------------------------- 1 | /** BeaconA.java --- 2 | * 3 | * Copyright (C) 2014 Dmitry Mozgin 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | * 17 | */ 18 | 19 | package com.m039.beacon.keeper.activity; 20 | 21 | import java.util.ArrayList; 22 | import java.util.List; 23 | 24 | import android.app.Activity; 25 | import android.content.Intent; 26 | import android.os.Bundle; 27 | import android.util.Pair; 28 | import android.widget.ImageView; 29 | import android.widget.TextView; 30 | 31 | import com.m039.beacon.keeper.app.R; 32 | import com.m039.beacon.keeper.content.BeaconEntity; 33 | 34 | /** 35 | * 36 | * 37 | * Created: 38 | * 39 | * @author Dmitry Mozgin 40 | * @version 1 41 | * @since Sat Dec 20 06:38:54 2014 42 | */ 43 | public class BeaconA extends BaseActivity { 44 | 45 | public static final String EXTRA_BEACON_ENTITY = 46 | "com.m039.beacon.keeper.activity.extra.beacon_entity"; 47 | 48 | public static void startActivity(Activity a, BeaconEntity beaconEntity) { 49 | Intent i = new Intent(a, BeaconA.class); 50 | i.putExtra(EXTRA_BEACON_ENTITY, beaconEntity); 51 | a.startActivity(i); 52 | 53 | a.overridePendingTransition (R.anim.enter_in, R.anim.enter_out); 54 | } 55 | 56 | private BeaconEntity mBeaconEntity; 57 | 58 | @Override 59 | protected void onCreate(Bundle savedInstanceState) { 60 | super.onCreate(savedInstanceState); 61 | setContentView(R.layout.a_beacon); 62 | 63 | mBeaconEntity = (BeaconEntity) getIntent().getParcelableExtra(EXTRA_BEACON_ENTITY); 64 | } 65 | 66 | @Override 67 | public void onBackPressed() { 68 | super.onBackPressed(); 69 | 70 | overridePendingTransition (R.anim.finish_in, R.anim.finish_out); 71 | } 72 | 73 | @Override 74 | protected void onFoundBeacon(BeaconEntity beaconEntity) { 75 | if (mBeaconEntity.equals(beaconEntity)) { 76 | mBeaconEntity = beaconEntity; 77 | } 78 | } 79 | 80 | @Override 81 | protected void onPostCreate(Bundle savedInstanceState) { 82 | super.onPostCreate(savedInstanceState); 83 | 84 | onUpdate(); 85 | } 86 | 87 | @Override 88 | protected void onPeriodicUpdate() { 89 | onUpdate(); 90 | } 91 | 92 | private void onUpdate() { 93 | List> pairs = new ArrayList>(); 94 | 95 | pairs.add(Pair.create(R.id.producer_name, mBeaconEntity.getProducerName())); 96 | pairs.add(Pair.create(R.id.uuid, mBeaconEntity.getUuid())); 97 | pairs.add(Pair.create(R.id.major, String.valueOf(mBeaconEntity.getMajor()))); 98 | pairs.add(Pair.create(R.id.minor, String.valueOf(mBeaconEntity.getMinor()))); 99 | pairs.add(Pair.create(R.id.tx_power, String.valueOf(mBeaconEntity.getTxPower()))); 100 | pairs.add(Pair.create(R.id.distance, getString(mBeaconEntity.getDistanceStringId()))); 101 | pairs.add(Pair.create(R.id.accuracy, String.valueOf(mBeaconEntity.getAccuracy()))); 102 | pairs.add(Pair.create(R.id.last_update, String.valueOf(mBeaconEntity.getLastSeenTimestamp()))); 103 | 104 | for (Pair p: pairs) { 105 | TextView tv = (TextView) findViewById(p.first); 106 | if (tv != null) { 107 | tv.setText(p.second); 108 | } 109 | } 110 | 111 | ((ImageView) findViewById(R.id.producer_icon)).setImageResource(findProducerIcon()); 112 | } 113 | 114 | private int findProducerIcon() { 115 | switch (mBeaconEntity.getProducer()) { 116 | case BeaconEntity.PRODUCER_ESTIMOTE: 117 | return R.drawable.beacon_entity__producer__estimote; 118 | case BeaconEntity.PRODUCER_KONTAKT: 119 | return R.drawable.beacon_entity__producer__kontakt; 120 | case BeaconEntity.PRODUCER_QUALCOMM: 121 | return R.drawable.beacon_entity__producer__qualcomm; 122 | case BeaconEntity.PRODUCER_STICKNFIND: 123 | return R.drawable.beacon_entity__producer__sticknfind; 124 | case BeaconEntity.PRODUCER_UNKNOWN: 125 | default: 126 | return R.drawable.beacon_entity__producer__unknown; 127 | } 128 | } 129 | 130 | } // BeaconA 131 | -------------------------------------------------------------------------------- /beacon-keeper-app/src/main/java/com/m039/beacon/keeper/adapter/BeaconEntityAdapter.java: -------------------------------------------------------------------------------- 1 | /** Beacon.java --- 2 | * 3 | * Copyright (C) 2014 Dmitry Mozgin 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | * 17 | */ 18 | 19 | package com.m039.beacon.keeper.adapter; 20 | 21 | import java.util.ArrayList; 22 | import java.util.List; 23 | 24 | import android.content.Context; 25 | import android.support.v7.widget.RecyclerView; 26 | import android.view.LayoutInflater; 27 | import android.view.View; 28 | import android.view.ViewGroup; 29 | import android.widget.TextView; 30 | 31 | import com.m039.beacon.keeper.app.R; 32 | import com.m039.beacon.keeper.content.BeaconEntity; 33 | 34 | /** 35 | * 36 | * 37 | * Created: 38 | * 39 | * @author 40 | * @version 41 | * @since 42 | */ 43 | public class BeaconEntityAdapter 44 | extends RecyclerView.Adapter 45 | implements View.OnClickListener 46 | { 47 | 48 | private List mBeaconEntities; 49 | 50 | public BeaconEntityAdapter() { 51 | this(new ArrayList()); 52 | } 53 | 54 | public BeaconEntityAdapter(List beaconEntities) { 55 | if (beaconEntities == null) { 56 | throw new IllegalArgumentException("beaconEntities is null"); 57 | } 58 | 59 | mBeaconEntities = beaconEntities; 60 | } 61 | 62 | public boolean replace(BeaconEntity beaconEntity) { 63 | int index = mBeaconEntities.indexOf(beaconEntity); 64 | boolean result = false; 65 | 66 | if (index == -1) { 67 | result = mBeaconEntities.add(beaconEntity); 68 | if (result) { 69 | notifyItemInserted(mBeaconEntities.size() - 1); 70 | } 71 | 72 | } else { 73 | mBeaconEntities.set(index, beaconEntity); 74 | result = true; 75 | notifyItemChanged(index); 76 | } 77 | 78 | return result; 79 | } 80 | 81 | public void clear () { 82 | int size = mBeaconEntities.size(); 83 | mBeaconEntities.clear(); 84 | notifyItemRangeRemoved(0, size); 85 | } 86 | 87 | public void removeOld(int timeToLiveMs) { 88 | List toRemove = null; 89 | long currentTimeMs = System.currentTimeMillis(); 90 | 91 | for (BeaconEntity beaconEntity : mBeaconEntities) { 92 | if ((currentTimeMs - beaconEntity.getTimestamp()) > timeToLiveMs) { 93 | if (toRemove == null) { 94 | toRemove = new ArrayList(); 95 | } 96 | 97 | toRemove.add(beaconEntity); 98 | } 99 | } 100 | 101 | if (toRemove != null) { 102 | mBeaconEntities.removeAll(toRemove); 103 | } 104 | } 105 | 106 | public static class ViewHolder extends RecyclerView.ViewHolder { 107 | 108 | TextView uuid; 109 | TextView major; 110 | TextView minor; 111 | TextView producerName; 112 | 113 | ViewHolder(View v) { 114 | super(v); 115 | 116 | uuid = (TextView) v.findViewById(R.id.uuid); 117 | major = (TextView) v.findViewById(R.id.major); 118 | minor = (TextView) v.findViewById(R.id.minor); 119 | producerName = (TextView) v.findViewById(R.id.producer_name); 120 | } 121 | 122 | } 123 | 124 | @Override 125 | public BeaconEntityAdapter.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { 126 | LayoutInflater inflater = (LayoutInflater) parent 127 | .getContext() 128 | .getSystemService (Context.LAYOUT_INFLATER_SERVICE); 129 | 130 | View v = inflater.inflate(R.layout.e_list, parent, false); 131 | 132 | ViewHolder vh = new ViewHolder(v); 133 | 134 | v.setOnClickListener(this); 135 | v.setTag(vh); 136 | 137 | return vh; 138 | } 139 | 140 | @Override 141 | public void onClick(View view) { 142 | ViewHolder vh = (ViewHolder) view.getTag(); 143 | onClick(mBeaconEntities.get(vh.getPosition())); 144 | } 145 | 146 | protected void onClick(BeaconEntity beaconEntity) { 147 | } 148 | 149 | @Override 150 | public void onBindViewHolder(ViewHolder h, int position) { 151 | BeaconEntity beaconEntity = mBeaconEntities.get(position); 152 | 153 | h.uuid.setText(beaconEntity.getUuid()); 154 | h.major.setText(String.valueOf(beaconEntity.getMajor())); 155 | h.minor.setText(String.valueOf(beaconEntity.getMinor())); 156 | h.producerName.setText(beaconEntity.getProducerName()); 157 | } 158 | 159 | @Override 160 | public int getItemCount() { 161 | return mBeaconEntities.size(); 162 | } 163 | 164 | } // BeaconEntityAdapter 165 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /beacon-keeper-app/src/main/res/layout/a_beacon.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | 15 | 16 | 22 | 23 | 30 | 31 | 39 | 40 | 41 | 42 | 43 | 48 | 49 | 56 | 57 | 64 | 65 | 73 | 74 | 82 | 83 | 89 | 90 | 96 | 97 | 103 | 104 | 110 | 111 | 117 | 118 | 124 | 125 | 126 | 127 | 136 | 137 | 143 | 144 | 150 | 151 | 157 | 158 | 164 | 165 | 171 | 172 | 178 | 179 | 180 | 181 | 182 | -------------------------------------------------------------------------------- /beacon-keeper-library/src/main/java/com/m039/beacon/keeper/U.java: -------------------------------------------------------------------------------- 1 | /** U.java --- 2 | * 3 | * Copyright (C) 2014 Dmitry Mozgin 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | * 17 | */ 18 | 19 | package com.m039.beacon.keeper; 20 | 21 | import android.bluetooth.BluetoothAdapter; 22 | import android.bluetooth.BluetoothManager; 23 | import android.content.ComponentName; 24 | import android.content.Context; 25 | import android.content.Intent; 26 | import android.content.pm.PackageManager; 27 | import android.os.Bundle; 28 | import android.preference.PreferenceManager; 29 | import android.text.format.DateUtils; 30 | import android.util.Log; 31 | 32 | import com.m039.beacon.keeper.content.BeaconEntity; 33 | 34 | /** 35 | * 36 | * 37 | * Created: 06/26/14 38 | * 39 | * @author Dmitry Mozgin 40 | * @version 41 | * @since 42 | */ 43 | public class U { 44 | 45 | public static final String TAG = "m039-U"; 46 | 47 | public static class BLE { 48 | 49 | /** 50 | * @return true if ble permissions is set 51 | */ 52 | public static boolean checkPermissions(Context ctx) { 53 | PackageManager packageManager = ctx.getPackageManager(); 54 | String packageName = ctx.getPackageName(); 55 | 56 | for (String permission : new String[] { 57 | android.Manifest.permission.BLUETOOTH, 58 | android.Manifest.permission.BLUETOOTH_ADMIN, 59 | }) { 60 | if (packageManager.checkPermission(permission, packageName) 61 | != PackageManager.PERMISSION_GRANTED) { 62 | return false; 63 | } 64 | } 65 | 66 | return true; 67 | } 68 | 69 | /** 70 | * @return true if ble features is set 71 | */ 72 | public static boolean checkFeatures(Context ctx) { 73 | PackageManager packageManager = ctx.getPackageManager(); 74 | 75 | if (packageManager.hasSystemFeature(PackageManager.FEATURE_BLUETOOTH_LE)) { 76 | return true; 77 | } 78 | 79 | return false; 80 | } 81 | 82 | /** 83 | * @return check if ble is enabled 84 | */ 85 | public static boolean isEnabled(Context ctx) { 86 | BluetoothAdapter ba = getBluetoothAdapter(ctx); 87 | return ba != null && ba.isEnabled(); 88 | } 89 | 90 | public static boolean enable(Context ctx) { 91 | BluetoothAdapter ba = getBluetoothAdapter(ctx); 92 | return ba != null && ba.enable(); 93 | } 94 | 95 | public static boolean disable(Context ctx) { 96 | BluetoothAdapter ba = getBluetoothAdapter(ctx); 97 | return ba != null && ba.disable(); 98 | } 99 | 100 | public static Intent createRequestEnableIntent() { 101 | return new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE); 102 | } 103 | } 104 | 105 | public static class Service { 106 | public static Bundle getMetaData(Context ctx, Class clazz) { 107 | try { 108 | return ctx 109 | .getPackageManager() 110 | .getServiceInfo(new ComponentName(ctx, clazz), PackageManager.GET_META_DATA) 111 | .metaData; 112 | } catch (PackageManager.NameNotFoundException e) { 113 | Log.wtf(TAG, e); 114 | return null; 115 | } catch (NullPointerException e) { 116 | Log.wtf(TAG, e); 117 | return null; 118 | } 119 | } 120 | } 121 | 122 | public static class SharedPreferences { 123 | public static android.content.SharedPreferences getDefaultSharedPreferences(Context ctx) { 124 | return PreferenceManager.getDefaultSharedPreferences(ctx); 125 | } 126 | 127 | public static int getInteger(Context ctx, String key, int defValue) { 128 | return getInteger(getDefaultSharedPreferences(ctx), key, defValue); 129 | } 130 | 131 | public static int getInteger(android.content.SharedPreferences sp, String key, int defValue) { 132 | try { 133 | return Integer.parseInt(sp.getString(key, String.valueOf(defValue))); 134 | } catch (NumberFormatException e) { 135 | return defValue; 136 | } 137 | } 138 | } 139 | 140 | public static class IBeacon { 141 | public static float calculateAccuracy(int txPower, int rssi) { 142 | if (rssi == 0) { 143 | return -1.0f; 144 | } 145 | 146 | float ratio = (float) rssi / (float) txPower; 147 | if (ratio < 1.0) { 148 | return (float) Math.pow(ratio, 10); 149 | } else { 150 | return (0.89976f) * (float) Math.pow(ratio, 7.7095f) + 0.111f; 151 | } 152 | } 153 | 154 | public static CharSequence getLastUpdate(BeaconEntity beaconEntity) { 155 | return DateUtils 156 | .getRelativeTimeSpanString(beaconEntity.getLastSeenTimestamp(), 157 | System.currentTimeMillis(), 158 | DateUtils.SECOND_IN_MILLIS); 159 | } 160 | } 161 | 162 | public static BluetoothManager getBluetoothManager(Context ctx) { 163 | return (BluetoothManager) ctx.getSystemService(Context.BLUETOOTH_SERVICE); 164 | } 165 | 166 | public static BluetoothAdapter getBluetoothAdapter(Context ctx) { 167 | BluetoothManager bm = getBluetoothManager(ctx); 168 | return (bm != null)? bm.getAdapter() : null; 169 | } 170 | 171 | 172 | public static String byteArrayToHex(byte[] a) { 173 | StringBuilder sb = new StringBuilder(a.length * 3); 174 | for(byte b: a) 175 | sb.append(String.format("%02x ", b & 0xff)); 176 | 177 | return sb.toString(); 178 | } 179 | 180 | } // U 181 | -------------------------------------------------------------------------------- /beacon-keeper-library/src/main/java/com/m039/beacon/keeper/content/BeaconEntity.java: -------------------------------------------------------------------------------- 1 | /** BeaconEntity.java --- 2 | * 3 | * Copyright (C) 2014 Dmitry Mozgin 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | * 17 | */ 18 | 19 | package com.m039.beacon.keeper.content; 20 | 21 | import android.bluetooth.BluetoothDevice; 22 | import android.os.Parcel; 23 | import android.os.Parcelable; 24 | 25 | import com.m039.beacon.keeper.C; 26 | import com.m039.beacon.keeper.library.R; 27 | 28 | /** 29 | * 30 | * 31 | * Created: 07/03/14 32 | * 33 | * @author Dmitry Mozgin 34 | * @version 35 | * @since 36 | */ 37 | public class BeaconEntity 38 | implements Parcelable, 39 | Comparable 40 | { 41 | 42 | public static final int PRODUCER_UNKNOWN = 0; 43 | public static final int PRODUCER_ESTIMOTE = 1; 44 | public static final int PRODUCER_KONTAKT = 2; 45 | public static final int PRODUCER_QUALCOMM = 3; // doesn't support yet 46 | public static final int PRODUCER_STICKNFIND = 4; // doesn't support yet 47 | 48 | public static final int DISTANCE_FAR = 0; 49 | public static final int DISTANCE_NEAR = 1; 50 | public static final int DISTANCE_IMMEDIATE = 2; 51 | 52 | final protected IBeacon mIBeacon; 53 | 54 | protected int mProducer = PRODUCER_UNKNOWN; 55 | protected long mTimestamp = -1; 56 | protected BluetoothDevice mBluetoothDevice; 57 | protected int mRssi = 0; 58 | protected int mDistance = DISTANCE_FAR; 59 | protected float mAccuracy = -1.0f; 60 | 61 | protected byte[] mScanDataDebug = null; 62 | 63 | public BeaconEntity(IBeacon iBeacon) { 64 | if (iBeacon == null) { 65 | throw new IllegalArgumentException("ibeacon should be not null"); 66 | } 67 | 68 | mIBeacon = iBeacon; 69 | } 70 | 71 | public IBeacon getIBeacon() { 72 | return mIBeacon; 73 | } 74 | 75 | public String getUuid() { 76 | return mIBeacon.getUuid(); 77 | } 78 | 79 | public int getMajor() { 80 | return mIBeacon.getMajor(); 81 | } 82 | 83 | public int getMinor() { 84 | return mIBeacon.getMinor(); 85 | } 86 | 87 | public int getTxPower() { 88 | return mIBeacon.getTxPower(); 89 | } 90 | 91 | public int getProducer() { 92 | return mProducer; 93 | } 94 | 95 | public String getProducerName() { 96 | if (mProducer == BeaconEntity.PRODUCER_ESTIMOTE) { 97 | return "Estimote"; 98 | } else if (mProducer == BeaconEntity.PRODUCER_KONTAKT) { 99 | return "Kontakt"; 100 | } else { 101 | return "Unknown"; 102 | } 103 | } 104 | 105 | public int getDistance() { 106 | return mDistance; 107 | } 108 | 109 | public int getDistanceStringId() { 110 | if (mDistance == DISTANCE_FAR) { 111 | return R.string.beacon_entity__distance__far; 112 | } else if (mDistance == DISTANCE_NEAR) { 113 | return R.string.beacon_entity__distance__near; 114 | } else if (mDistance == DISTANCE_IMMEDIATE) { 115 | return R.string.beacon_entity__distance__immediate; 116 | } 117 | 118 | return C.NO_ID; 119 | } 120 | 121 | public long getTimestamp() { 122 | return mTimestamp; 123 | } 124 | 125 | public long getLastSeenTimestamp() { 126 | return getTimestamp(); 127 | } 128 | 129 | public BluetoothDevice getBluetoothDevice() { 130 | return mBluetoothDevice; 131 | } 132 | 133 | public int getRssi() { 134 | return mRssi; 135 | } 136 | 137 | public float getAccuracy() { 138 | return mAccuracy; 139 | } 140 | 141 | /** 142 | * @return scanData if C.DEBUG is true 143 | */ 144 | public byte[] getScanDataDebug() { 145 | return mScanDataDebug; 146 | } 147 | 148 | @Override 149 | public int hashCode() { 150 | return mIBeacon.hashCode(); 151 | } 152 | 153 | @Override 154 | public boolean equals(Object o) { 155 | if (this == o) { 156 | return true; 157 | } 158 | 159 | if (!(o instanceof BeaconEntity)) { 160 | return false; 161 | } 162 | 163 | BeaconEntity lhs = (BeaconEntity) o; 164 | 165 | return (mIBeacon == null? 166 | lhs.mIBeacon == null : mIBeacon.equals(lhs.mIBeacon)); 167 | } 168 | 169 | @Override 170 | public int compareTo (BeaconEntity another) { 171 | if (!(another instanceof BeaconEntity)) { 172 | throw new ClassCastException("A BeaconEntity object expected."); 173 | } 174 | 175 | return mIBeacon.compareTo(another.mIBeacon); 176 | } 177 | 178 | // 179 | // Parcelable 180 | // 181 | 182 | private BeaconEntity(Parcel in) { 183 | mIBeacon = (IBeacon) in.readParcelable(IBeacon.class.getClassLoader()); 184 | mBluetoothDevice = (BluetoothDevice) in.readParcelable(BluetoothDevice.class.getClassLoader()); 185 | mProducer = in.readInt(); 186 | mRssi = in.readInt(); 187 | mDistance = in.readInt(); 188 | mTimestamp = in.readLong(); 189 | mAccuracy = in.readFloat(); 190 | } 191 | 192 | public int describeContents() { 193 | return 0; 194 | } 195 | 196 | public void writeToParcel(Parcel out, int flags) { 197 | out.writeParcelable(mIBeacon, flags); 198 | out.writeParcelable(mBluetoothDevice, flags); 199 | out.writeInt(mProducer); 200 | out.writeInt(mRssi); 201 | out.writeInt(mDistance); 202 | out.writeLong(mTimestamp); 203 | out.writeFloat(mAccuracy); 204 | } 205 | 206 | public static final Parcelable.Creator CREATOR = new Parcelable.Creator() { 207 | public BeaconEntity createFromParcel(Parcel in) { 208 | return new BeaconEntity(in); 209 | } 210 | 211 | public BeaconEntity[] newArray(int size) { 212 | return new BeaconEntity[size]; 213 | } 214 | }; 215 | 216 | } // BeaconEntity 217 | -------------------------------------------------------------------------------- /beacon-keeper-library/src/main/java/com/m039/beacon/keeper/content/BeaconFactory.java: -------------------------------------------------------------------------------- 1 | /** BeaconFactory.java --- 2 | * 3 | * Copyright (C) 2014 Dmitry Mozgin 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | * 17 | */ 18 | 19 | package com.m039.beacon.keeper.content; 20 | 21 | import java.util.Arrays; 22 | 23 | import android.bluetooth.BluetoothDevice; 24 | 25 | import com.m039.beacon.keeper.C; 26 | import com.m039.beacon.keeper.U; 27 | 28 | /** 29 | * 30 | * 31 | * Created: 07/01/14 32 | * 33 | * @author Dmitry Mozgin 34 | * @version 35 | * @since 36 | */ 37 | public class BeaconFactory { 38 | 39 | private static byte[] IBEACON_PREFIX = new byte[] { 40 | (byte) 0x02, (byte) 0x01, (byte) 0x06, (byte) 0x1a, 41 | (byte) 0xff, (byte) 0x4c, (byte) 0x00, (byte) 0x02, 42 | (byte) 0x15 43 | }; 44 | 45 | private static int IBEACON_PREFIX_START = 0; 46 | private static int IBEACON_PREFIX_LENGTH = 9; 47 | private static int IBEACON_PREFIX_END = IBEACON_PREFIX_START + IBEACON_PREFIX_LENGTH; 48 | 49 | private static int PROXIMITY_UUID_START = IBEACON_PREFIX_END; 50 | private static int PROXIMITY_UUID_LENGTH = 16; 51 | private static int PROXIMITY_UUID_END = PROXIMITY_UUID_START + PROXIMITY_UUID_LENGTH; 52 | 53 | private static int MAJOR_START = PROXIMITY_UUID_END; 54 | private static int MAJOR_LENGTH = 2; 55 | private static int MAJOR_END = MAJOR_START + MAJOR_LENGTH; 56 | 57 | private static int MINOR_START = MAJOR_END; 58 | private static int MINOR_LENGTH = 2; 59 | private static int MINOR_END = MINOR_START + MINOR_LENGTH; 60 | 61 | private static int TX_POWER_START = MINOR_END; 62 | private static int TX_POWER_LENGTH = 1; 63 | private static int TX_POWER_END = TX_POWER_START + TX_POWER_LENGTH; 64 | 65 | private static int SCANRECORD_SIZE = TX_POWER_END; 66 | 67 | /** 68 | * @param scanRecord the actual packet bytes 69 | * @return null or an instance of an IBeacon 70 | */ 71 | public static IBeacon decodeScanRecord(byte[] scanRecord) { 72 | if (scanRecord != null && scanRecord.length >= SCANRECORD_SIZE) { 73 | 74 | byte iBeaconPrefix[] = Arrays 75 | .copyOfRange(scanRecord, IBEACON_PREFIX_START, IBEACON_PREFIX_END); 76 | 77 | if (!Arrays.equals(iBeaconPrefix, IBEACON_PREFIX)) { 78 | return null; 79 | } 80 | 81 | byte uuid[] = Arrays 82 | .copyOfRange(scanRecord, PROXIMITY_UUID_START, PROXIMITY_UUID_END); 83 | byte major[] = Arrays 84 | .copyOfRange(scanRecord, MAJOR_START, MAJOR_END); 85 | byte minor[] = Arrays 86 | .copyOfRange(scanRecord, MINOR_START, MINOR_END); 87 | byte txPower[] = Arrays 88 | .copyOfRange(scanRecord, TX_POWER_START, TX_POWER_END); 89 | 90 | IBeacon iBeacon = new IBeacon(); 91 | 92 | iBeacon.mUuid = toUuidString(uuid); 93 | iBeacon.mMajor = (major[0] & 0xff) * 0x100 + (major[1] & 0xff); 94 | iBeacon.mMinor = (minor[0] & 0xff) * 0x100 + (minor[1] & 0xff); 95 | iBeacon.mTxPower = txPower[0]; 96 | 97 | return iBeacon; 98 | } 99 | 100 | return null; 101 | } 102 | 103 | /** 104 | * @param device 105 | * @param rssi 106 | * @param scanRecord the actiual packet bytes 107 | * @return null or an instance of an BeaconEntity 108 | * @see android.bluetooth.BluetoothAdapter.LeScanCallback 109 | */ 110 | public static BeaconEntity decode(BluetoothDevice device, int rssi, byte[] scanRecord) { 111 | IBeacon iBeacon = decodeScanRecord(scanRecord); 112 | if (iBeacon == null) { 113 | return null; 114 | } 115 | 116 | BeaconEntity beaconEntity = new BeaconEntity(iBeacon); 117 | 118 | beaconEntity.mBluetoothDevice = device; 119 | 120 | fillProducer(beaconEntity); 121 | fillTimestamp(beaconEntity); 122 | fillRssi(beaconEntity, rssi); 123 | 124 | if (C.DEBUG) { 125 | beaconEntity.mScanDataDebug = Arrays.copyOf(scanRecord, scanRecord.length); 126 | } 127 | 128 | return beaconEntity; 129 | } 130 | 131 | private static String toUuidString(byte uuid[]) { 132 | if (uuid == null || uuid.length != 16) { 133 | return "00000000-0000-0000-0000-000000000000"; 134 | } 135 | 136 | StringBuilder sb = new StringBuilder(); 137 | 138 | int k = 0; 139 | 140 | for (int i = 0; i < 4; i++) { 141 | sb.append(String.format("%02x", uuid[k++] & 0xff)); 142 | } 143 | 144 | sb.append('-'); 145 | 146 | for (int i = 0; i < 2; i++) { 147 | sb.append(String.format("%02x", uuid[k++] & 0xff)); 148 | } 149 | 150 | sb.append('-'); 151 | 152 | for (int i = 0; i < 2; i++) { 153 | sb.append(String.format("%02x", uuid[k++] & 0xff)); 154 | } 155 | 156 | sb.append('-'); 157 | 158 | for (int i = 0; i < 2; i++) { 159 | sb.append(String.format("%02x", uuid[k++] & 0xff)); 160 | } 161 | 162 | sb.append('-'); 163 | 164 | for (int i = 0; i < 6; i++) { 165 | sb.append(String.format("%02x", uuid[k++] & 0xff)); 166 | } 167 | 168 | return sb.toString(); 169 | } 170 | 171 | private static void fillProducer(BeaconEntity beaconEntity) { 172 | int producer = BeaconEntity.PRODUCER_UNKNOWN; 173 | 174 | String proximityUuid = beaconEntity.getUuid(); 175 | 176 | if (proximityUuid.equalsIgnoreCase("b9407f30-f5f8-466e-aff9-25556b57fe6d")) { 177 | producer = BeaconEntity.PRODUCER_ESTIMOTE; 178 | } else if (proximityUuid.equalsIgnoreCase("f7826da6-4fa2-4e98-8024-bc5b71e0893e")) { 179 | producer = BeaconEntity.PRODUCER_KONTAKT; 180 | } 181 | 182 | beaconEntity.mProducer = producer; 183 | } 184 | 185 | private static void fillTimestamp(BeaconEntity beaconEntity) { 186 | beaconEntity.mTimestamp = System.currentTimeMillis(); 187 | } 188 | 189 | private static void fillRssi(BeaconEntity beaconEntity, int rssi) { 190 | beaconEntity.mRssi = rssi; 191 | beaconEntity.mAccuracy = U.IBeacon.calculateAccuracy(beaconEntity.getTxPower(), rssi); 192 | 193 | if (beaconEntity.mAccuracy < 1) { 194 | beaconEntity.mDistance = BeaconEntity.DISTANCE_IMMEDIATE; 195 | } else if (beaconEntity.mAccuracy > 10) { 196 | beaconEntity.mDistance = BeaconEntity.DISTANCE_FAR; 197 | } else { 198 | beaconEntity.mDistance = BeaconEntity.DISTANCE_NEAR; 199 | } 200 | } 201 | 202 | } // BeaconFactory 203 | -------------------------------------------------------------------------------- /beacon-keeper-app/src/main/java/com/m039/beacon/keeper/fragment/SplashF.java: -------------------------------------------------------------------------------- 1 | /** SplashF.java --- 2 | * 3 | * Copyright (C) 2014 Dmitry Mozgin 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | * 17 | */ 18 | 19 | package com.m039.beacon.keeper.fragment; 20 | 21 | import android.app.Activity; 22 | import android.bluetooth.BluetoothAdapter; 23 | import android.content.BroadcastReceiver; 24 | import android.content.Context; 25 | import android.content.Intent; 26 | import android.content.IntentFilter; 27 | import android.os.Bundle; 28 | import android.view.LayoutInflater; 29 | import android.view.View; 30 | import android.view.ViewGroup; 31 | import android.widget.CompoundButton; 32 | import android.widget.Switch; 33 | import android.widget.TextView; 34 | 35 | import com.m039.beacon.keeper.U; 36 | import com.m039.beacon.keeper.app.R; 37 | 38 | /** 39 | * 40 | * 41 | * Created: 42 | * 43 | * @author Dmitry Mozgin 44 | * @version 1 45 | * @since Fri Aug 8 23:05:19 2014 46 | */ 47 | public class SplashF extends BaseFragment { 48 | 49 | public static SplashF newInstance() { 50 | return new SplashF(); 51 | } 52 | 53 | @Override 54 | public void onCreate(Bundle savedInstanceState) { 55 | super.onCreate(savedInstanceState); 56 | } 57 | 58 | private Switch mSwitcher; 59 | private View mSwitcherPb; 60 | 61 | private ViewGroup mEnabled; 62 | private ViewGroup mDisabled; 63 | private TextView mDisabledLabel; 64 | 65 | @Override 66 | public View onCreateView(LayoutInflater inflater, ViewGroup parent, Bundle savedInstanceState) { 67 | View view = inflater.inflate(R.layout.f_splash, parent, false); 68 | 69 | mEnabled = (ViewGroup) view.findViewById(R.id.enabled); 70 | mDisabled = (ViewGroup) view.findViewById(R.id.disabled); 71 | 72 | mDisabledLabel = (TextView) mDisabled.findViewById(R.id.disabled_label); 73 | 74 | mSwitcherPb = mDisabled.findViewById(R.id.switcher_pb); 75 | 76 | mSwitcher = (Switch) mDisabled.findViewById(R.id.switcher); 77 | mSwitcher.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { 78 | 79 | @Override 80 | public void onCheckedChanged (CompoundButton v, boolean isChecked) { 81 | Context ctx = v.getContext(); 82 | 83 | if (v.isChecked() && !U.BLE.isEnabled(ctx)) { 84 | U.BLE.enable(ctx); 85 | v.setEnabled(false); 86 | } else if (!v.isChecked() && U.BLE.isEnabled(ctx)) { 87 | U.BLE.disable(ctx); 88 | v.setEnabled(false); 89 | } 90 | } 91 | 92 | }); 93 | 94 | return view; 95 | } 96 | 97 | @Override 98 | public void onDestroyView() { 99 | super.onDestroyView(); 100 | 101 | mSwitcher = null; 102 | } 103 | 104 | public interface OnSwitchBluetooth { 105 | 106 | public void onBluetoothSwitchOn(); 107 | 108 | public void onBluetoothSwitchOff(); 109 | 110 | } 111 | 112 | private BroadcastReceiver mBroadcastReceiver = new BroadcastReceiver() { 113 | 114 | @Override 115 | public void onReceive(Context context, Intent intent) { 116 | if (intent == null) 117 | return; 118 | 119 | String action = intent.getAction(); 120 | if (action.equals(BluetoothAdapter.ACTION_STATE_CHANGED)) { 121 | final int state = intent.getIntExtra(BluetoothAdapter.EXTRA_STATE, -1); 122 | if (state != -1) { 123 | switch (state) { 124 | case BluetoothAdapter.STATE_OFF: 125 | mDisabledLabel.setText(R.string.f_splash_bluetooth_disabled); 126 | mSwitcher.setChecked(false); 127 | mSwitcher.setEnabled(true); 128 | mSwitcher.setVisibility(View.VISIBLE); 129 | mSwitcherPb.setVisibility(View.INVISIBLE); 130 | 131 | mEnabled.setVisibility(View.INVISIBLE); 132 | mDisabled.setVisibility(View.VISIBLE); 133 | 134 | { 135 | Object a = getActivity(); 136 | if (a instanceof OnSwitchBluetooth) { 137 | ((OnSwitchBluetooth) a).onBluetoothSwitchOff(); 138 | } 139 | } 140 | break; 141 | case BluetoothAdapter.STATE_ON: 142 | mDisabledLabel.setText(R.string.f_splash_bluetooth_enabled); 143 | mSwitcher.setChecked(true); 144 | mSwitcher.setEnabled(true); 145 | mSwitcher.setVisibility(View.VISIBLE); 146 | mSwitcherPb.setVisibility(View.INVISIBLE); 147 | 148 | mEnabled.setVisibility(View.VISIBLE); 149 | mDisabled.setVisibility(View.INVISIBLE); 150 | 151 | { 152 | Object a = getActivity(); 153 | if (a instanceof OnSwitchBluetooth) { 154 | ((OnSwitchBluetooth) a).onBluetoothSwitchOn(); 155 | } 156 | } 157 | break; 158 | case BluetoothAdapter.STATE_TURNING_OFF: 159 | mDisabledLabel.setText(R.string.f_splash_bluetooth_turning_off); 160 | mSwitcher.setEnabled(false); 161 | mSwitcher.setVisibility(View.INVISIBLE); 162 | mSwitcherPb.setVisibility(View.VISIBLE); 163 | break; 164 | case BluetoothAdapter.STATE_TURNING_ON: 165 | mDisabledLabel.setText(R.string.f_splash_bluetooth_turning_on); 166 | mSwitcher.setEnabled(false); 167 | mSwitcher.setVisibility(View.INVISIBLE); 168 | mSwitcherPb.setVisibility(View.VISIBLE); 169 | break; 170 | } 171 | } 172 | } 173 | } 174 | 175 | }; 176 | 177 | @Override 178 | public void onStart() { 179 | super.onStart(); 180 | 181 | Activity a = getActivity(); 182 | 183 | if (a != null) { 184 | if (U.BLE.isEnabled(a)) { 185 | mSwitcher.setChecked(true); 186 | mEnabled.setVisibility(View.VISIBLE); 187 | mDisabled.setVisibility(View.INVISIBLE); 188 | } else { 189 | mSwitcher.setChecked(false); 190 | mEnabled.setVisibility(View.INVISIBLE); 191 | mDisabled.setVisibility(View.VISIBLE); 192 | } 193 | 194 | mSwitcher.setEnabled(true); 195 | mSwitcherPb.setVisibility(View.INVISIBLE); 196 | 197 | a.registerReceiver(mBroadcastReceiver, 198 | new IntentFilter(BluetoothAdapter.ACTION_STATE_CHANGED)); 199 | } 200 | } 201 | 202 | @Override 203 | public void onStop() { 204 | super.onStop(); 205 | 206 | Activity a = getActivity(); 207 | if (a != null) { 208 | a.unregisterReceiver(mBroadcastReceiver); 209 | } 210 | } 211 | 212 | 213 | } // SplashF 214 | -------------------------------------------------------------------------------- /beacon-keeper-library/src/main/java/com/m039/beacon/keeper/service/BeaconService.java: -------------------------------------------------------------------------------- 1 | /** BeaconService.java --- 2 | * 3 | * Copyright (C) 2014 Dmitry Mozgin 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | * 17 | */ 18 | 19 | package com.m039.beacon.keeper.service; 20 | 21 | import android.app.AlarmManager; 22 | import android.app.PendingIntent; 23 | import android.app.Service; 24 | import android.content.Context; 25 | import android.content.Intent; 26 | import android.content.SharedPreferences; 27 | import android.content.res.Resources; 28 | import android.os.Handler; 29 | import android.os.HandlerThread; 30 | import android.os.Looper; 31 | import android.os.IBinder; 32 | 33 | import com.m039.beacon.keeper.L; 34 | import com.m039.beacon.keeper.U; 35 | import com.m039.beacon.keeper.content.BeaconEntity; 36 | import com.m039.beacon.keeper.library.R; 37 | import com.m039.beacon.keeper.util.SimpleLeScanner; 38 | 39 | /** 40 | * 41 | * 42 | * Created: 07/01/14 43 | * 44 | * @author Dmitry Mozgin 45 | * @version 46 | * @since 47 | */ 48 | public class BeaconService extends Service { 49 | 50 | public static final String TAG = "m039-BeaconService"; 51 | 52 | public static final String PACKAGE = "com.m039.beacon.keeper.service."; 53 | 54 | public static final String ACTION_FOUND_BEACON = PACKAGE + "action.FOUND_BEACON"; 55 | public static final String ACTION_BLE_DISABLED = PACKAGE + "action.BLE_DISABLED"; 56 | public static final String ACTION_BLE_ENABLED = PACKAGE + "action.BLE_ENABLED"; 57 | 58 | public static final String EXTRA_BEACON_ENTITY = PACKAGE + "extra.beacon_entity"; 59 | 60 | private static boolean sSharedPreferencesHasChanged = false; 61 | private static boolean sSharedPreferencesChangeListenerRegistered = false; 62 | 63 | public static void onApplicationCreate(Context ctx) { 64 | startServiceByAlarmManager(ctx); 65 | } 66 | 67 | public static void onBootCompleted(Context ctx) { 68 | startServiceByAlarmManager(ctx); 69 | } 70 | 71 | public static void startService(Context ctx) { 72 | ctx.startService(new Intent(ctx, BeaconService.class)); 73 | } 74 | 75 | private static void startServiceByAlarmManager(Context ctx) { 76 | Intent i = new Intent(ctx, BeaconService.class); 77 | PendingIntent pi = PendingIntent.getService(ctx, 0, i, PendingIntent.FLAG_UPDATE_CURRENT); 78 | 79 | AlarmManager am = (AlarmManager) ctx.getSystemService(Context.ALARM_SERVICE); 80 | am.setRepeating(AlarmManager.RTC_WAKEUP, 81 | System.currentTimeMillis(), 82 | getRepeatTimeMs(ctx), 83 | pi); 84 | 85 | if (!sSharedPreferencesChangeListenerRegistered) { 86 | final String keyScanningTimeMs = ctx 87 | .getString(R.string.beacon_keeper__pref_key__scanning_time_ms); 88 | final String keyIdleTimeMs = ctx 89 | .getString(R.string.beacon_keeper__pref_key__idle_time_ms); 90 | 91 | U.SharedPreferences.getDefaultSharedPreferences(ctx) 92 | .registerOnSharedPreferenceChangeListener 93 | ( 94 | new SharedPreferences.OnSharedPreferenceChangeListener() { 95 | @Override 96 | public void onSharedPreferenceChanged (SharedPreferences sharedPreferences, String key) { 97 | if (key != null && 98 | (key.equals(keyScanningTimeMs) || 99 | key.equals(keyIdleTimeMs))) { 100 | L.d(TAG, "BeaconService.onSharedPreferenceChanged: %s", key); 101 | sSharedPreferencesHasChanged = true; 102 | 103 | // Todo: only check if value is changed 104 | } 105 | } 106 | } 107 | ); 108 | 109 | sSharedPreferencesChangeListenerRegistered = true; 110 | } 111 | } 112 | 113 | private static void restartServiceByAlarmManager(Context ctx) { 114 | Intent i = new Intent(ctx, BeaconService.class); 115 | PendingIntent pi = PendingIntent.getService(ctx, 0, i, PendingIntent.FLAG_NO_CREATE); 116 | 117 | if (pi != null) { 118 | // alarm is set => restart 119 | 120 | AlarmManager am = (AlarmManager) ctx.getSystemService(Context.ALARM_SERVICE); 121 | am.setRepeating(AlarmManager.RTC_WAKEUP, 122 | System.currentTimeMillis(), 123 | getRepeatTimeMs(ctx), 124 | pi); 125 | 126 | } else { 127 | // alarm is not set => do nothing 128 | } 129 | } 130 | 131 | private static int getScanningTimeMs(Context ctx) { 132 | Resources res = ctx.getResources(); 133 | 134 | String key = res.getString(R.string.beacon_keeper__pref_key__scanning_time_ms); 135 | int defValue = res.getInteger(R.integer.beacon_keeper__scanning_time_ms_default); 136 | 137 | return U.SharedPreferences.getInteger(ctx, key, defValue); 138 | } 139 | 140 | private static int getIdleTimeMs(Context ctx) { 141 | Resources res = ctx.getResources(); 142 | 143 | String key = res.getString(R.string.beacon_keeper__pref_key__idle_time_ms); 144 | int defValue = res.getInteger(R.integer.beacon_keeper__idle_time_ms_default); 145 | 146 | return U.SharedPreferences.getInteger(ctx, key, defValue); 147 | } 148 | 149 | private static int getRepeatTimeMs(Context ctx) { 150 | return getIdleTimeMs(ctx) + getScanningTimeMs(ctx); 151 | } 152 | 153 | private SimpleLeScanner mSimpleLeScanner = null; 154 | private SimpleLeScanner.LeScanCallback mLeScanCallback = new SimpleLeScanner.LeScanCallback() { 155 | 156 | @Override 157 | public void onLeScan(BeaconEntity beaconEntity) { 158 | sendFoundBeaconBroadcast(beaconEntity); 159 | } 160 | 161 | }; 162 | 163 | private long mRunningTimeDebug = 0; 164 | private Handler mHandler; 165 | private boolean mStartedSuccessfully = false; 166 | 167 | @Override 168 | public void onCreate() { 169 | super.onCreate(); 170 | 171 | HandlerThread ht = new HandlerThread("HandlerThread [" + BeaconService.class.getSimpleName() + "]"); 172 | ht.start(); 173 | 174 | mRunningTimeDebug = System.currentTimeMillis(); 175 | mSimpleLeScanner = new SimpleLeScanner(this); 176 | 177 | (mHandler = new Handler(ht.getLooper())) 178 | .post(new Runnable() { 179 | 180 | @Override 181 | public void run() { 182 | if (mStartedSuccessfully = mSimpleLeScanner.startScan(mLeScanCallback)) { 183 | stopScan(false); 184 | } else { 185 | stopScan(true); 186 | } 187 | 188 | } 189 | 190 | }); 191 | } 192 | 193 | @Override 194 | public void onDestroy() { 195 | super.onDestroy(); 196 | 197 | L.d(TAG, "onDestroy: startTime %s runningTime %s", 198 | mRunningTimeDebug, System.currentTimeMillis() - mRunningTimeDebug); 199 | 200 | stopScan(true); 201 | 202 | if (sSharedPreferencesHasChanged) { 203 | restartServiceByAlarmManager(this); 204 | sSharedPreferencesHasChanged = false; 205 | } 206 | } 207 | 208 | private void stopScan(boolean force) { 209 | if (mSimpleLeScanner != null) { 210 | if (force) { 211 | mHandler.post(mOnStopScanRunnable); 212 | } else { 213 | mHandler.postDelayed(mOnStopScanRunnable, getScanningTimeMs(this)); 214 | } 215 | } 216 | } 217 | 218 | private Runnable mOnStopScanRunnable = new Runnable() { 219 | 220 | @Override 221 | public void run() { 222 | if (mSimpleLeScanner != null) { 223 | if (mStartedSuccessfully) { 224 | mSimpleLeScanner.stopScan(mLeScanCallback); 225 | } 226 | mSimpleLeScanner = null; 227 | 228 | mHandler.getLooper().quit(); 229 | mHandler = null; 230 | 231 | stopSelf(); 232 | } 233 | } 234 | 235 | }; 236 | 237 | @Override 238 | public int onStartCommand(Intent intent, int flags, int startId) { 239 | super.onStartCommand(intent, flags, startId); 240 | return START_NOT_STICKY; 241 | } 242 | 243 | private void sendFoundBeaconBroadcast(final BeaconEntity beaconEntity) { 244 | final Context ctx = getApplicationContext(); 245 | 246 | runOnUiThread(new Runnable() { 247 | 248 | @Override 249 | public void run() { 250 | Intent intent = new Intent(); 251 | intent.setAction(ACTION_FOUND_BEACON); 252 | intent.putExtra(EXTRA_BEACON_ENTITY, beaconEntity); 253 | ctx.sendBroadcast(intent); 254 | } 255 | 256 | }); 257 | } 258 | 259 | @Override 260 | public IBinder onBind(Intent intent) { 261 | return null; 262 | } 263 | 264 | private static void runOnUiThread(Runnable run) { 265 | new Handler(Looper.getMainLooper()).post(run); 266 | } 267 | 268 | private static void runOnUiThread(Runnable run, long delayMillis) { 269 | new Handler(Looper.getMainLooper()).postDelayed(run, delayMillis); 270 | } 271 | 272 | } // BeaconService 273 | -------------------------------------------------------------------------------- /beacon-keeper-app/src/main/java/com/m039/beacon/keeper/activity/BeaconsA.java: -------------------------------------------------------------------------------- 1 | /** BeaconsA.java --- 2 | * 3 | * Copyright (C) 2014 Dmitry Mozgin 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | * 17 | */ 18 | 19 | package com.m039.beacon.keeper.activity; 20 | 21 | import android.animation.Animator; 22 | import android.animation.AnimatorListenerAdapter; 23 | import android.animation.ObjectAnimator; 24 | import android.content.res.Resources; 25 | import android.os.Bundle; 26 | import android.os.Handler; 27 | import android.os.Message; 28 | import android.support.v7.widget.DefaultItemAnimator; 29 | import android.support.v7.widget.LinearLayoutManager; 30 | import android.support.v7.widget.RecyclerView; 31 | import android.util.Property; 32 | import android.view.View; 33 | import android.view.ViewGroup; 34 | import android.widget.TextView; 35 | 36 | import com.m039.beacon.keeper.U; 37 | import com.m039.beacon.keeper.adapter.BeaconEntityAdapter; 38 | import com.m039.beacon.keeper.app.R; 39 | import com.m039.beacon.keeper.content.BeaconEntity; 40 | import com.m039.beacon.keeper.fragment.SplashF; 41 | import com.m039.beacon.keeper.widget.DividerItemDecoration; 42 | 43 | /** 44 | * 45 | * 46 | * Created: 47 | * 48 | * @author Dmitry Mozgin 49 | * @version 1 50 | * @since Sat Dec 20 00:52:19 2014 51 | */ 52 | public class BeaconsA extends BaseActivity 53 | implements SplashF.OnSwitchBluetooth 54 | { 55 | 56 | private static final int WHAT_RADAR_UPDATE = 0; 57 | 58 | private ViewGroup mTop; 59 | private ViewGroup mBottom; 60 | private ViewGroup mOverlay; 61 | 62 | private TextView mNumberOfBeacons; 63 | private RecyclerView mRecycler; 64 | private View mRadar; 65 | 66 | private Handler mRadarHandler = new Handler() { 67 | 68 | @Override 69 | public void handleMessage (Message msg) { 70 | if (msg.what == WHAT_RADAR_UPDATE) { 71 | onRadarUpdate(); 72 | sendEmptyMessageDelayed(msg.what, 100); 73 | } 74 | } 75 | 76 | }; 77 | 78 | private BeaconEntityAdapter mBeaconEntityAdapter = 79 | new BeaconEntityAdapter() { 80 | 81 | @Override 82 | protected void onClick(BeaconEntity beaconEntity) { 83 | BeaconA.startActivity(BeaconsA.this, beaconEntity); 84 | } 85 | 86 | }; 87 | 88 | @Override 89 | public void onCreate(Bundle savedInstanceState) { 90 | super.onCreate(savedInstanceState); 91 | setContentView(R.layout.a_beacons); 92 | 93 | mTop = (ViewGroup) findViewById(R.id.top); 94 | mBottom = (ViewGroup) findViewById(R.id.bottom); 95 | mOverlay = (ViewGroup) findViewById(R.id.overlay); 96 | 97 | mNumberOfBeacons = (TextView) findViewById(R.id.number_of_beacons); 98 | mRecycler = (RecyclerView) findViewById(R.id.recycler); 99 | mRadar = findViewById(R.id.radar); 100 | 101 | if (mRecycler != null) { 102 | mRecycler.setHasFixedSize(true); 103 | mRecycler.setLayoutManager(new LinearLayoutManager(this)); 104 | mRecycler.setItemAnimator(new DefaultItemAnimator()); 105 | mRecycler.addItemDecoration(new DividerItemDecoration(this, DividerItemDecoration.VERTICAL_LIST)); 106 | mRecycler.setAdapter(mBeaconEntityAdapter); 107 | } 108 | 109 | findViewById(R.id.settings).setOnClickListener(mOnButtonClickListener); 110 | 111 | // Default State 112 | 113 | mOverlay.setVisibility(View.VISIBLE); 114 | mTop.setVisibility(View.INVISIBLE); 115 | mBottom.setVisibility(View.INVISIBLE); 116 | 117 | // fragments 118 | 119 | if (savedInstanceState == null) { 120 | getFragmentManager() 121 | .beginTransaction() 122 | .add(R.id.overlay, SplashF.newInstance()) 123 | .commit(); 124 | } 125 | } 126 | 127 | View.OnClickListener mOnButtonClickListener = new View.OnClickListener() { 128 | 129 | @Override 130 | public void onClick(View v) { 131 | if (v.getId() == R.id.settings) { 132 | SettingsA.startActivity(BeaconsA.this); 133 | } 134 | } 135 | 136 | }; 137 | 138 | @Override 139 | protected void onFoundBeacon(BeaconEntity beaconEntity) { 140 | mBeaconEntityAdapter.replace(beaconEntity); 141 | } 142 | 143 | @Override 144 | protected void onPeriodicUpdate() { 145 | Resources res = getResources(); 146 | 147 | mBeaconEntityAdapter 148 | .removeOld(U.SharedPreferences.getInteger(this, res.getString(R.string.beacon_keeper__pref_key__beacon_ttl_ms),res.getInteger(R.integer.beacon_keeper__beacon_ttl_ms_default))); 149 | mBeaconEntityAdapter 150 | .notifyDataSetChanged(); 151 | 152 | if (mNumberOfBeacons != null) { 153 | mNumberOfBeacons.setText(String.valueOf(mBeaconEntityAdapter.getItemCount())); 154 | } 155 | } 156 | 157 | public static class AnimatorHelper { 158 | 159 | private static final long DURATION = 500L; 160 | private static final long START_DELAY = 700L; 161 | private static final String PROPERTY_NAME = "value"; 162 | 163 | private float mValue = 0; // initial state 164 | 165 | private ObjectAnimator mAnimator; 166 | 167 | Property mProperty = 168 | new Property(Float.class, PROPERTY_NAME) { 169 | 170 | @Override 171 | public Float get (AnimatorHelper object) { 172 | return onGet(); 173 | } 174 | 175 | @Override 176 | public void set(AnimatorHelper obj, Float v) { 177 | onSet(v); 178 | } 179 | 180 | }; 181 | 182 | AnimatorListenerAdapter mAnimatorListenerAdapter = 183 | new AnimatorListenerAdapter() { 184 | 185 | @Override 186 | public void onAnimationStart (Animator animation) { 187 | AnimatorHelper.this.onAnimationStart(mValue); 188 | } 189 | 190 | @Override 191 | public void onAnimationEnd (Animator animation) { 192 | AnimatorHelper.this.onAnimationEnd(mValue); 193 | } 194 | }; 195 | 196 | { 197 | mAnimator = new ObjectAnimator(); 198 | mAnimator.addListener(mAnimatorListenerAdapter); 199 | mAnimator.setDuration(DURATION); 200 | mAnimator.setStartDelay(START_DELAY); 201 | mAnimator.setProperty(mProperty); 202 | mAnimator.setPropertyName(PROPERTY_NAME); 203 | mAnimator.setTarget(this); 204 | } 205 | 206 | protected float onGet() { 207 | return mValue; 208 | } 209 | 210 | protected void onSet(float v) { 211 | mValue = v; 212 | } 213 | 214 | protected void onAnimationStart(float v) { 215 | } 216 | 217 | protected void onAnimationEnd(float v) { 218 | } 219 | 220 | public void open() { 221 | if (mValue == 1) 222 | return; // don't do anything 223 | 224 | if (mAnimator.isRunning()) { 225 | mAnimator.cancel(); 226 | } 227 | 228 | mAnimator.setFloatValues(mValue, 1); 229 | mAnimator.start(); 230 | } 231 | 232 | public void close() { 233 | if (mValue == 0) 234 | return; // don't do anything 235 | 236 | if (mAnimator.isRunning()) { 237 | mAnimator.cancel(); 238 | } 239 | 240 | mAnimator.setFloatValues(mValue, 0); 241 | mAnimator.start(); 242 | } 243 | 244 | } 245 | 246 | private AnimatorHelper mAnimatorHelper = 247 | new AnimatorHelper() { 248 | 249 | float barHeight = -1; 250 | float moveAwayDistance = -1; 251 | 252 | @Override 253 | protected float onGet() { 254 | return super.onGet(); 255 | } 256 | 257 | @Override 258 | protected void onSet(float v) { 259 | super.onSet(v); 260 | 261 | float iv = 1 - v; 262 | 263 | if (barHeight == -1 || moveAwayDistance == -1) { 264 | barHeight = getResources().getDimensionPixelOffset(R.dimen.bar_height); 265 | moveAwayDistance = getResources().getDimensionPixelOffset(R.dimen.move_away_distance); 266 | } 267 | 268 | mTop.getLayoutParams().height = (int) (barHeight * v); 269 | mTop.requestLayout(); 270 | 271 | mOverlay.setAlpha(iv); 272 | mOverlay.setTranslationY(moveAwayDistance * v); 273 | 274 | mBottom.setAlpha(v); 275 | } 276 | 277 | @Override 278 | protected void onAnimationStart(float v) { 279 | mOverlay.setVisibility(View.VISIBLE); 280 | mTop.setVisibility(View.VISIBLE); 281 | mBottom.setVisibility(View.VISIBLE); 282 | } 283 | 284 | @Override 285 | protected void onAnimationEnd(float v) { 286 | if (v == 0) { 287 | 288 | mOverlay.setVisibility(View.VISIBLE); 289 | mTop.setVisibility(View.INVISIBLE); 290 | mBottom.setVisibility(View.INVISIBLE); 291 | 292 | } else { 293 | // v == 1; 294 | 295 | mOverlay.setVisibility(View.INVISIBLE); 296 | mTop.setVisibility(View.VISIBLE); 297 | mBottom.setVisibility(View.VISIBLE); 298 | } 299 | } 300 | 301 | }; 302 | 303 | @Override 304 | protected void onResume() { 305 | super.onResume(); 306 | 307 | if (U.BLE.isEnabled(this)) { 308 | mAnimatorHelper.open(); 309 | } else { 310 | mAnimatorHelper.close(); 311 | } 312 | } 313 | 314 | @Override 315 | protected void onStart() { 316 | super.onStart(); 317 | 318 | mRadarHandler.sendEmptyMessage(WHAT_RADAR_UPDATE); 319 | } 320 | 321 | @Override 322 | protected void onStop() { 323 | super.onStop(); 324 | 325 | mRadarHandler.removeMessages(WHAT_RADAR_UPDATE); 326 | } 327 | 328 | protected void onRadarUpdate() { 329 | if (mTop.getVisibility() == View.VISIBLE) { 330 | mRadar.setRotation(mRadar.getRotation() + 4); 331 | } 332 | } 333 | 334 | @Override 335 | public void onBluetoothSwitchOn() { 336 | mAnimatorHelper.open(); 337 | } 338 | 339 | @Override 340 | public void onBluetoothSwitchOff() { 341 | mAnimatorHelper.close(); 342 | } 343 | 344 | } // BeaconsA 345 | -------------------------------------------------------------------------------- /LICENSE-2.0.txt: -------------------------------------------------------------------------------- 1 | 2 | Apache License 3 | Version 2.0, January 2004 4 | http://www.apache.org/licenses/ 5 | 6 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 7 | 8 | 1. Definitions. 9 | 10 | "License" shall mean the terms and conditions for use, reproduction, 11 | and distribution as defined by Sections 1 through 9 of this document. 12 | 13 | "Licensor" shall mean the copyright owner or entity authorized by 14 | the copyright owner that is granting the License. 15 | 16 | "Legal Entity" shall mean the union of the acting entity and all 17 | other entities that control, are controlled by, or are under common 18 | control with that entity. For the purposes of this definition, 19 | "control" means (i) the power, direct or indirect, to cause the 20 | direction or management of such entity, whether by contract or 21 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 22 | outstanding shares, or (iii) beneficial ownership of such entity. 23 | 24 | "You" (or "Your") shall mean an individual or Legal Entity 25 | exercising permissions granted by this License. 26 | 27 | "Source" form shall mean the preferred form for making modifications, 28 | including but not limited to software source code, documentation 29 | source, and configuration files. 30 | 31 | "Object" form shall mean any form resulting from mechanical 32 | transformation or translation of a Source form, including but 33 | not limited to compiled object code, generated documentation, 34 | and conversions to other media types. 35 | 36 | "Work" shall mean the work of authorship, whether in Source or 37 | Object form, made available under the License, as indicated by a 38 | copyright notice that is included in or attached to the work 39 | (an example is provided in the Appendix below). 40 | 41 | "Derivative Works" shall mean any work, whether in Source or Object 42 | form, that is based on (or derived from) the Work and for which the 43 | editorial revisions, annotations, elaborations, or other modifications 44 | represent, as a whole, an original work of authorship. For the purposes 45 | of this License, Derivative Works shall not include works that remain 46 | separable from, or merely link (or bind by name) to the interfaces of, 47 | the Work and Derivative Works thereof. 48 | 49 | "Contribution" shall mean any work of authorship, including 50 | the original version of the Work and any modifications or additions 51 | to that Work or Derivative Works thereof, that is intentionally 52 | submitted to Licensor for inclusion in the Work by the copyright owner 53 | or by an individual or Legal Entity authorized to submit on behalf of 54 | the copyright owner. For the purposes of this definition, "submitted" 55 | means any form of electronic, verbal, or written communication sent 56 | to the Licensor or its representatives, including but not limited to 57 | communication on electronic mailing lists, source code control systems, 58 | and issue tracking systems that are managed by, or on behalf of, the 59 | Licensor for the purpose of discussing and improving the Work, but 60 | excluding communication that is conspicuously marked or otherwise 61 | designated in writing by the copyright owner as "Not a Contribution." 62 | 63 | "Contributor" shall mean Licensor and any individual or Legal Entity 64 | on behalf of whom a Contribution has been received by Licensor and 65 | subsequently incorporated within the Work. 66 | 67 | 2. Grant of Copyright License. Subject to the terms and conditions of 68 | this License, each Contributor hereby grants to You a perpetual, 69 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 70 | copyright license to reproduce, prepare Derivative Works of, 71 | publicly display, publicly perform, sublicense, and distribute the 72 | Work and such Derivative Works in Source or Object form. 73 | 74 | 3. Grant of Patent License. Subject to the terms and conditions of 75 | this License, each Contributor hereby grants to You a perpetual, 76 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 77 | (except as stated in this section) patent license to make, have made, 78 | use, offer to sell, sell, import, and otherwise transfer the Work, 79 | where such license applies only to those patent claims licensable 80 | by such Contributor that are necessarily infringed by their 81 | Contribution(s) alone or by combination of their Contribution(s) 82 | with the Work to which such Contribution(s) was submitted. If You 83 | institute patent litigation against any entity (including a 84 | cross-claim or counterclaim in a lawsuit) alleging that the Work 85 | or a Contribution incorporated within the Work constitutes direct 86 | or contributory patent infringement, then any patent licenses 87 | granted to You under this License for that Work shall terminate 88 | as of the date such litigation is filed. 89 | 90 | 4. Redistribution. You may reproduce and distribute copies of the 91 | Work or Derivative Works thereof in any medium, with or without 92 | modifications, and in Source or Object form, provided that You 93 | meet the following conditions: 94 | 95 | (a) You must give any other recipients of the Work or 96 | Derivative Works a copy of this License; and 97 | 98 | (b) You must cause any modified files to carry prominent notices 99 | stating that You changed the files; and 100 | 101 | (c) You must retain, in the Source form of any Derivative Works 102 | that You distribute, all copyright, patent, trademark, and 103 | attribution notices from the Source form of the Work, 104 | excluding those notices that do not pertain to any part of 105 | the Derivative Works; and 106 | 107 | (d) If the Work includes a "NOTICE" text file as part of its 108 | distribution, then any Derivative Works that You distribute must 109 | include a readable copy of the attribution notices contained 110 | within such NOTICE file, excluding those notices that do not 111 | pertain to any part of the Derivative Works, in at least one 112 | of the following places: within a NOTICE text file distributed 113 | as part of the Derivative Works; within the Source form or 114 | documentation, if provided along with the Derivative Works; or, 115 | within a display generated by the Derivative Works, if and 116 | wherever such third-party notices normally appear. The contents 117 | of the NOTICE file are for informational purposes only and 118 | do not modify the License. You may add Your own attribution 119 | notices within Derivative Works that You distribute, alongside 120 | or as an addendum to the NOTICE text from the Work, provided 121 | that such additional attribution notices cannot be construed 122 | as modifying the License. 123 | 124 | You may add Your own copyright statement to Your modifications and 125 | may provide additional or different license terms and conditions 126 | for use, reproduction, or distribution of Your modifications, or 127 | for any such Derivative Works as a whole, provided Your use, 128 | reproduction, and distribution of the Work otherwise complies with 129 | the conditions stated in this License. 130 | 131 | 5. Submission of Contributions. Unless You explicitly state otherwise, 132 | any Contribution intentionally submitted for inclusion in the Work 133 | by You to the Licensor shall be under the terms and conditions of 134 | this License, without any additional terms or conditions. 135 | Notwithstanding the above, nothing herein shall supersede or modify 136 | the terms of any separate license agreement you may have executed 137 | with Licensor regarding such Contributions. 138 | 139 | 6. Trademarks. This License does not grant permission to use the trade 140 | names, trademarks, service marks, or product names of the Licensor, 141 | except as required for reasonable and customary use in describing the 142 | origin of the Work and reproducing the content of the NOTICE file. 143 | 144 | 7. Disclaimer of Warranty. Unless required by applicable law or 145 | agreed to in writing, Licensor provides the Work (and each 146 | Contributor provides its Contributions) on an "AS IS" BASIS, 147 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 148 | implied, including, without limitation, any warranties or conditions 149 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 150 | PARTICULAR PURPOSE. You are solely responsible for determining the 151 | appropriateness of using or redistributing the Work and assume any 152 | risks associated with Your exercise of permissions under this License. 153 | 154 | 8. Limitation of Liability. In no event and under no legal theory, 155 | whether in tort (including negligence), contract, or otherwise, 156 | unless required by applicable law (such as deliberate and grossly 157 | negligent acts) or agreed to in writing, shall any Contributor be 158 | liable to You for damages, including any direct, indirect, special, 159 | incidental, or consequential damages of any character arising as a 160 | result of this License or out of the use or inability to use the 161 | Work (including but not limited to damages for loss of goodwill, 162 | work stoppage, computer failure or malfunction, or any and all 163 | other commercial damages or losses), even if such Contributor 164 | has been advised of the possibility of such damages. 165 | 166 | 9. Accepting Warranty or Additional Liability. While redistributing 167 | the Work or Derivative Works thereof, You may choose to offer, 168 | and charge a fee for, acceptance of support, warranty, indemnity, 169 | or other liability obligations and/or rights consistent with this 170 | License. However, in accepting such obligations, You may act only 171 | on Your own behalf and on Your sole responsibility, not on behalf 172 | of any other Contributor, and only if You agree to indemnify, 173 | defend, and hold each Contributor harmless for any liability 174 | incurred by, or claims asserted against, such Contributor by reason 175 | of your accepting any such warranty or additional liability. 176 | 177 | END OF TERMS AND CONDITIONS 178 | 179 | APPENDIX: How to apply the Apache License to your work. 180 | 181 | To apply the Apache License to your work, attach the following 182 | boilerplate notice, with the fields enclosed by brackets "[]" 183 | replaced with your own identifying information. (Don't include 184 | the brackets!) The text should be enclosed in the appropriate 185 | comment syntax for the file format. We also recommend that a 186 | file or class name and description of purpose be included on the 187 | same "printed page" as the copyright notice for easier 188 | identification within third-party archives. 189 | 190 | Copyright [yyyy] [name of copyright owner] 191 | 192 | Licensed under the Apache License, Version 2.0 (the "License"); 193 | you may not use this file except in compliance with the License. 194 | You may obtain a copy of the License at 195 | 196 | http://www.apache.org/licenses/LICENSE-2.0 197 | 198 | Unless required by applicable law or agreed to in writing, software 199 | distributed under the License is distributed on an "AS IS" BASIS, 200 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 201 | See the License for the specific language governing permissions and 202 | limitations under the License. 203 | --------------------------------------------------------------------------------