├── examples └── BeaconstacExample │ ├── app │ ├── .gitignore │ ├── libs │ │ └── YouTubeAndroidPlayerApi.jar │ ├── src │ │ ├── main │ │ │ ├── res │ │ │ │ ├── drawable-hdpi │ │ │ │ │ └── icon.png │ │ │ │ ├── drawable-mdpi │ │ │ │ │ └── icon.png │ │ │ │ ├── drawable-xhdpi │ │ │ │ │ └── icon.png │ │ │ │ ├── drawable-xxhdpi │ │ │ │ │ └── icon.png │ │ │ │ ├── mipmap-hdpi │ │ │ │ │ └── ic_launcher.png │ │ │ │ ├── mipmap-mdpi │ │ │ │ │ └── ic_launcher.png │ │ │ │ ├── mipmap-xhdpi │ │ │ │ │ └── ic_launcher.png │ │ │ │ ├── mipmap-xxhdpi │ │ │ │ │ └── ic_launcher.png │ │ │ │ ├── drawable-nodpi │ │ │ │ │ └── ic_play_circle_filled_white_36dp.png │ │ │ │ ├── values │ │ │ │ │ ├── styles.xml │ │ │ │ │ ├── dimens.xml │ │ │ │ │ └── strings.xml │ │ │ │ ├── layout │ │ │ │ │ ├── fragment_carousel_dialog.xml │ │ │ │ │ ├── beacon_view.xml │ │ │ │ │ ├── activity_main.xml │ │ │ │ │ ├── dialog_fragment_carousel.xml │ │ │ │ │ ├── dialog_youtube_popup.xml │ │ │ │ │ ├── dialog_fragment_carousel_notification.xml │ │ │ │ │ └── dialog_youtube_popup_notification.xml │ │ │ │ ├── values-w820dp │ │ │ │ │ └── dimens.xml │ │ │ │ └── menu │ │ │ │ │ └── menu_main.xml │ │ │ ├── AndroidManifest.xml │ │ │ └── java │ │ │ │ └── com │ │ │ │ └── mobstac │ │ │ │ └── beaconstacdemo │ │ │ │ ├── BeaconstacUtils.java │ │ │ │ ├── BeaconAdapter.java │ │ │ │ ├── NearbyBeaconBroadcastReceiver.java │ │ │ │ └── MainActivity.java │ │ └── androidTest │ │ │ └── java │ │ │ └── com │ │ │ └── mobstac │ │ │ └── beaconstacdemo │ │ │ └── ApplicationTest.java │ ├── proguard-rules.pro │ └── build.gradle │ ├── settings.gradle │ ├── .gitignore │ ├── gradle │ └── wrapper │ │ ├── gradle-wrapper.jar │ │ └── gradle-wrapper.properties │ ├── build.gradle │ └── gradle.properties ├── Beaconstac SDK V2 (Deprecated) ├── BeaconstacExample │ ├── app │ │ ├── .gitignore │ │ ├── libs │ │ │ └── YouTubeAndroidPlayerApi.jar │ │ ├── src │ │ │ ├── main │ │ │ │ ├── res │ │ │ │ │ ├── drawable-hdpi │ │ │ │ │ │ └── icon.png │ │ │ │ │ ├── drawable-mdpi │ │ │ │ │ │ └── icon.png │ │ │ │ │ ├── drawable-xhdpi │ │ │ │ │ │ └── icon.png │ │ │ │ │ ├── drawable-xxhdpi │ │ │ │ │ │ └── icon.png │ │ │ │ │ ├── mipmap-hdpi │ │ │ │ │ │ └── ic_launcher.png │ │ │ │ │ ├── mipmap-mdpi │ │ │ │ │ │ └── ic_launcher.png │ │ │ │ │ ├── mipmap-xhdpi │ │ │ │ │ │ └── ic_launcher.png │ │ │ │ │ ├── mipmap-xxhdpi │ │ │ │ │ │ └── ic_launcher.png │ │ │ │ │ ├── drawable-nodpi │ │ │ │ │ │ └── ic_play_circle_filled_white_36dp.png │ │ │ │ │ ├── values │ │ │ │ │ │ ├── styles.xml │ │ │ │ │ │ ├── dimens.xml │ │ │ │ │ │ └── strings.xml │ │ │ │ │ ├── layout │ │ │ │ │ │ ├── fragment_carousel_dialog.xml │ │ │ │ │ │ ├── beacon_view.xml │ │ │ │ │ │ ├── activity_main.xml │ │ │ │ │ │ ├── dialog_fragment_carousel.xml │ │ │ │ │ │ ├── dialog_youtube_popup.xml │ │ │ │ │ │ ├── dialog_fragment_carousel_notification.xml │ │ │ │ │ │ └── dialog_youtube_popup_notification.xml │ │ │ │ │ ├── values-w820dp │ │ │ │ │ │ └── dimens.xml │ │ │ │ │ └── menu │ │ │ │ │ │ └── menu_main.xml │ │ │ │ ├── java │ │ │ │ │ └── com │ │ │ │ │ │ └── mobstac │ │ │ │ │ │ └── beaconstacdemo │ │ │ │ │ │ ├── BeaconstacDemo.java │ │ │ │ │ │ ├── MyBitmapLruCache.java │ │ │ │ │ │ ├── MyVolley.java │ │ │ │ │ │ ├── BeaconstacUtils.java │ │ │ │ │ │ ├── CarouselImageFragment.java │ │ │ │ │ │ ├── CustomViewPager.java │ │ │ │ │ │ ├── BeaconAdapter.java │ │ │ │ │ │ ├── ImageCarouselDialog.java │ │ │ │ │ │ ├── YoutubePlayerDialog.java │ │ │ │ │ │ └── MainActivity.java │ │ │ │ └── AndroidManifest.xml │ │ │ └── androidTest │ │ │ │ └── java │ │ │ │ └── com │ │ │ │ └── mobstac │ │ │ │ └── beaconstacdemo │ │ │ │ └── ApplicationTest.java │ │ ├── proguard-rules.pro │ │ └── build.gradle │ ├── settings.gradle │ ├── .gitignore │ ├── gradle │ │ └── wrapper │ │ │ ├── gradle-wrapper.jar │ │ │ └── gradle-wrapper.properties │ ├── build.gradle │ └── gradle.properties └── README.md ├── .gitignore ├── LICENSE └── README.md /examples/BeaconstacExample/app/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /examples/BeaconstacExample/settings.gradle: -------------------------------------------------------------------------------- 1 | include ':app' 2 | -------------------------------------------------------------------------------- /Beaconstac SDK V2 (Deprecated)/BeaconstacExample/app/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /Beaconstac SDK V2 (Deprecated)/BeaconstacExample/settings.gradle: -------------------------------------------------------------------------------- 1 | include ':app' 2 | -------------------------------------------------------------------------------- /examples/BeaconstacExample/.gitignore: -------------------------------------------------------------------------------- 1 | # Created by .ignore support plugin (hsz.mobi) 2 | -------------------------------------------------------------------------------- /Beaconstac SDK V2 (Deprecated)/BeaconstacExample/.gitignore: -------------------------------------------------------------------------------- 1 | # Created by .ignore support plugin (hsz.mobi) 2 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .gradle 2 | local.properties 3 | .idea 4 | .DS_Store 5 | build 6 | captures 7 | *.iml 8 | gradlew 9 | gradlew.bat -------------------------------------------------------------------------------- /examples/BeaconstacExample/gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Beaconstac/Android-SDK/HEAD/examples/BeaconstacExample/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /examples/BeaconstacExample/app/libs/YouTubeAndroidPlayerApi.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Beaconstac/Android-SDK/HEAD/examples/BeaconstacExample/app/libs/YouTubeAndroidPlayerApi.jar -------------------------------------------------------------------------------- /examples/BeaconstacExample/app/src/main/res/drawable-hdpi/icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Beaconstac/Android-SDK/HEAD/examples/BeaconstacExample/app/src/main/res/drawable-hdpi/icon.png -------------------------------------------------------------------------------- /examples/BeaconstacExample/app/src/main/res/drawable-mdpi/icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Beaconstac/Android-SDK/HEAD/examples/BeaconstacExample/app/src/main/res/drawable-mdpi/icon.png -------------------------------------------------------------------------------- /examples/BeaconstacExample/app/src/main/res/drawable-xhdpi/icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Beaconstac/Android-SDK/HEAD/examples/BeaconstacExample/app/src/main/res/drawable-xhdpi/icon.png -------------------------------------------------------------------------------- /examples/BeaconstacExample/app/src/main/res/drawable-xxhdpi/icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Beaconstac/Android-SDK/HEAD/examples/BeaconstacExample/app/src/main/res/drawable-xxhdpi/icon.png -------------------------------------------------------------------------------- /examples/BeaconstacExample/app/src/main/res/mipmap-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Beaconstac/Android-SDK/HEAD/examples/BeaconstacExample/app/src/main/res/mipmap-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /examples/BeaconstacExample/app/src/main/res/mipmap-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Beaconstac/Android-SDK/HEAD/examples/BeaconstacExample/app/src/main/res/mipmap-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /examples/BeaconstacExample/app/src/main/res/mipmap-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Beaconstac/Android-SDK/HEAD/examples/BeaconstacExample/app/src/main/res/mipmap-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /examples/BeaconstacExample/app/src/main/res/mipmap-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Beaconstac/Android-SDK/HEAD/examples/BeaconstacExample/app/src/main/res/mipmap-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /Beaconstac SDK V2 (Deprecated)/BeaconstacExample/gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Beaconstac/Android-SDK/HEAD/Beaconstac SDK V2 (Deprecated)/BeaconstacExample/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /Beaconstac SDK V2 (Deprecated)/BeaconstacExample/app/libs/YouTubeAndroidPlayerApi.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Beaconstac/Android-SDK/HEAD/Beaconstac SDK V2 (Deprecated)/BeaconstacExample/app/libs/YouTubeAndroidPlayerApi.jar -------------------------------------------------------------------------------- /Beaconstac SDK V2 (Deprecated)/BeaconstacExample/app/src/main/res/drawable-hdpi/icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Beaconstac/Android-SDK/HEAD/Beaconstac SDK V2 (Deprecated)/BeaconstacExample/app/src/main/res/drawable-hdpi/icon.png -------------------------------------------------------------------------------- /Beaconstac SDK V2 (Deprecated)/BeaconstacExample/app/src/main/res/drawable-mdpi/icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Beaconstac/Android-SDK/HEAD/Beaconstac SDK V2 (Deprecated)/BeaconstacExample/app/src/main/res/drawable-mdpi/icon.png -------------------------------------------------------------------------------- /Beaconstac SDK V2 (Deprecated)/BeaconstacExample/app/src/main/res/drawable-xhdpi/icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Beaconstac/Android-SDK/HEAD/Beaconstac SDK V2 (Deprecated)/BeaconstacExample/app/src/main/res/drawable-xhdpi/icon.png -------------------------------------------------------------------------------- /Beaconstac SDK V2 (Deprecated)/BeaconstacExample/app/src/main/res/drawable-xxhdpi/icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Beaconstac/Android-SDK/HEAD/Beaconstac SDK V2 (Deprecated)/BeaconstacExample/app/src/main/res/drawable-xxhdpi/icon.png -------------------------------------------------------------------------------- /Beaconstac SDK V2 (Deprecated)/BeaconstacExample/app/src/main/res/mipmap-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Beaconstac/Android-SDK/HEAD/Beaconstac SDK V2 (Deprecated)/BeaconstacExample/app/src/main/res/mipmap-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /Beaconstac SDK V2 (Deprecated)/BeaconstacExample/app/src/main/res/mipmap-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Beaconstac/Android-SDK/HEAD/Beaconstac SDK V2 (Deprecated)/BeaconstacExample/app/src/main/res/mipmap-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /Beaconstac SDK V2 (Deprecated)/BeaconstacExample/app/src/main/res/mipmap-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Beaconstac/Android-SDK/HEAD/Beaconstac SDK V2 (Deprecated)/BeaconstacExample/app/src/main/res/mipmap-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /Beaconstac SDK V2 (Deprecated)/BeaconstacExample/app/src/main/res/mipmap-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Beaconstac/Android-SDK/HEAD/Beaconstac SDK V2 (Deprecated)/BeaconstacExample/app/src/main/res/mipmap-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /examples/BeaconstacExample/app/src/main/res/drawable-nodpi/ic_play_circle_filled_white_36dp.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Beaconstac/Android-SDK/HEAD/examples/BeaconstacExample/app/src/main/res/drawable-nodpi/ic_play_circle_filled_white_36dp.png -------------------------------------------------------------------------------- /examples/BeaconstacExample/app/src/main/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /Beaconstac SDK V2 (Deprecated)/BeaconstacExample/app/src/main/res/drawable-nodpi/ic_play_circle_filled_white_36dp.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Beaconstac/Android-SDK/HEAD/Beaconstac SDK V2 (Deprecated)/BeaconstacExample/app/src/main/res/drawable-nodpi/ic_play_circle_filled_white_36dp.png -------------------------------------------------------------------------------- /examples/BeaconstacExample/app/src/main/res/values/dimens.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 16dp 4 | 16dp 5 | 6 | -------------------------------------------------------------------------------- /Beaconstac SDK V2 (Deprecated)/BeaconstacExample/app/src/main/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /Beaconstac SDK V2 (Deprecated)/BeaconstacExample/app/src/main/res/values/dimens.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 16dp 4 | 16dp 5 | 6 | -------------------------------------------------------------------------------- /examples/BeaconstacExample/gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Thu Jun 13 17:08:57 IST 2019 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-5.1.1-all.zip 7 | -------------------------------------------------------------------------------- /Beaconstac SDK V2 (Deprecated)/BeaconstacExample/gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Fri Mar 10 18:06:55 IST 2017 2 | distributionBase=GRADLE_USER_HOME 3 | distributionPath=wrapper/dists 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | distributionUrl=https\://services.gradle.org/distributions/gradle-3.3-all.zip 7 | -------------------------------------------------------------------------------- /examples/BeaconstacExample/app/src/main/res/layout/fragment_carousel_dialog.xml: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /Beaconstac SDK V2 (Deprecated)/BeaconstacExample/app/src/main/res/layout/fragment_carousel_dialog.xml: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /Beaconstac SDK V2 (Deprecated)/BeaconstacExample/app/src/main/java/com/mobstac/beaconstacdemo/BeaconstacDemo.java: -------------------------------------------------------------------------------- 1 | package com.mobstac.beaconstacdemo; 2 | 3 | import android.app.Application; 4 | 5 | 6 | public class BeaconstacDemo extends Application { 7 | 8 | @Override 9 | public void onCreate() { 10 | super.onCreate(); 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /examples/BeaconstacExample/app/src/main/res/values-w820dp/dimens.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 64dp 6 | 7 | -------------------------------------------------------------------------------- /Beaconstac SDK V2 (Deprecated)/BeaconstacExample/app/src/main/res/values-w820dp/dimens.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 64dp 6 | 7 | -------------------------------------------------------------------------------- /examples/BeaconstacExample/app/src/main/res/menu/menu_main.xml: -------------------------------------------------------------------------------- 1 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /Beaconstac SDK V2 (Deprecated)/BeaconstacExample/app/src/main/res/menu/menu_main.xml: -------------------------------------------------------------------------------- 1 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /examples/BeaconstacExample/app/src/androidTest/java/com/mobstac/beaconstacdemo/ApplicationTest.java: -------------------------------------------------------------------------------- 1 | package com.mobstac.beaconstacdemo; 2 | 3 | import android.app.Application; 4 | import android.test.ApplicationTestCase; 5 | 6 | /** 7 | * Testing Fundamentals 8 | */ 9 | public class ApplicationTest extends ApplicationTestCase { 10 | public ApplicationTest() { 11 | super(Application.class); 12 | } 13 | } -------------------------------------------------------------------------------- /Beaconstac SDK V2 (Deprecated)/BeaconstacExample/app/src/androidTest/java/com/mobstac/beaconstacdemo/ApplicationTest.java: -------------------------------------------------------------------------------- 1 | package com.mobstac.beaconstacdemo; 2 | 3 | import android.app.Application; 4 | import android.test.ApplicationTestCase; 5 | 6 | /** 7 | * Testing Fundamentals 8 | */ 9 | public class ApplicationTest extends ApplicationTestCase { 10 | public ApplicationTest() { 11 | super(Application.class); 12 | } 13 | } -------------------------------------------------------------------------------- /Beaconstac SDK V2 (Deprecated)/BeaconstacExample/build.gradle: -------------------------------------------------------------------------------- 1 | // Top-level build file where you can add configuration options common to all sub-projects/modules. 2 | 3 | buildscript { 4 | repositories { 5 | jcenter() 6 | } 7 | dependencies { 8 | classpath 'com.android.tools.build:gradle:2.3.3' 9 | 10 | // NOTE: Do not place your application dependencies here; they belong 11 | // in the individual module build.gradle files 12 | } 13 | } 14 | 15 | allprojects { 16 | repositories { 17 | jcenter() 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /examples/BeaconstacExample/build.gradle: -------------------------------------------------------------------------------- 1 | // Top-level build file where you can add configuration options common to all sub-projects/modules. 2 | 3 | buildscript { 4 | repositories { 5 | jcenter() 6 | google() 7 | } 8 | dependencies { 9 | classpath 'com.android.tools.build:gradle:3.4.1' 10 | 11 | // NOTE: Do not place your application dependencies here; they belong 12 | // in the individual module build.gradle files 13 | } 14 | } 15 | 16 | allprojects { 17 | repositories { 18 | jcenter() 19 | google() 20 | } 21 | } -------------------------------------------------------------------------------- /examples/BeaconstacExample/app/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # By default, the flags in this file are appended to flags specified 3 | # in /Users/bhashkar/Library/Android/sdk/tools/proguard/proguard-android.txt 4 | # You can edit the include path and order by changing the proguardFiles 5 | # directive in build.gradle. 6 | # 7 | # For more details, see 8 | # http://developer.android.com/guide/developing/tools/proguard.html 9 | 10 | # Add any project specific keep options here: 11 | 12 | # If your project uses WebView with JS, uncomment the following 13 | # and specify the fully qualified class name to the JavaScript interface 14 | # class: 15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 16 | # public *; 17 | #} 18 | -------------------------------------------------------------------------------- /Beaconstac SDK V2 (Deprecated)/BeaconstacExample/app/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # By default, the flags in this file are appended to flags specified 3 | # in /Users/bhashkar/Library/Android/sdk/tools/proguard/proguard-android.txt 4 | # You can edit the include path and order by changing the proguardFiles 5 | # directive in build.gradle. 6 | # 7 | # For more details, see 8 | # http://developer.android.com/guide/developing/tools/proguard.html 9 | 10 | # Add any project specific keep options here: 11 | 12 | # If your project uses WebView with JS, uncomment the following 13 | # and specify the fully qualified class name to the JavaScript interface 14 | # class: 15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 16 | # public *; 17 | #} 18 | -------------------------------------------------------------------------------- /examples/BeaconstacExample/app/src/main/res/layout/beacon_view.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | 13 | 18 | 19 | -------------------------------------------------------------------------------- /Beaconstac SDK V2 (Deprecated)/BeaconstacExample/app/src/main/res/layout/beacon_view.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | 13 | 18 | 19 | -------------------------------------------------------------------------------- /examples/BeaconstacExample/app/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | BeaconstacDemo 3 | 4 | Hello world! 5 | Settings 6 | MainActivity 7 | BLE not supported on this device. 8 | Bluetooth not supported on device. 9 | Unknown beacon 10 | Please enable Bluetooth and launch the app again. 11 | Bluetooth Disabled 12 | Dismiss 13 | com.mobstac.beaconstacdemo.provider 14 | 15 | 16 | -------------------------------------------------------------------------------- /Beaconstac SDK V2 (Deprecated)/BeaconstacExample/app/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | 3 | android { 4 | compileSdkVersion 25 5 | buildToolsVersion "25.0.2" 6 | 7 | defaultConfig { 8 | applicationId "com.mobstac.beaconstacdemo" 9 | minSdkVersion 14 10 | targetSdkVersion 25 11 | versionCode 3 12 | versionName "2.3" 13 | } 14 | buildTypes { 15 | release { 16 | minifyEnabled false 17 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 18 | } 19 | } 20 | } 21 | 22 | dependencies { 23 | compile fileTree(dir: 'libs', include: ['*.jar']) 24 | compile 'com.android.support:appcompat-v7:25.2.0' 25 | compile 'com.android.support:design:25.2.0' 26 | compile 'com.mobstac.beaconstac:beaconstac_sdk:2.0.3' 27 | 28 | } -------------------------------------------------------------------------------- /Beaconstac SDK V2 (Deprecated)/BeaconstacExample/app/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | BeaconstacDemo 3 | 4 | Hello world! 5 | Settings 6 | MainActivity 7 | BLE not supported on this device. 8 | Bluetooth not supported on device. 9 | Unknown beacon 10 | Please enable Bluetooth and launch the app again. 11 | Bluetooth Disabled 12 | Dismiss 13 | com.mobstac.beaconstacdemo.provider 14 | 15 | 16 | -------------------------------------------------------------------------------- /examples/BeaconstacExample/app/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | 3 | android { 4 | compileSdkVersion 28 5 | buildToolsVersion '28.0.3' 6 | 7 | defaultConfig { 8 | applicationId "com.mobstac.beaconstacdemo" 9 | minSdkVersion 17 10 | targetSdkVersion 28 11 | versionCode 1 12 | versionName "1.0" 13 | } 14 | buildTypes { 15 | release { 16 | minifyEnabled false 17 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 18 | } 19 | } 20 | } 21 | 22 | dependencies { 23 | implementation fileTree(dir: 'libs', include: ['*.jar']) 24 | implementation 'com.android.support:appcompat-v7:28.0.0' 25 | implementation 'com.android.support:design:28.0.0' 26 | implementation 'com.mobstac.beaconstac:proximity:3.30' 27 | implementation 'com.google.android.gms:play-services-nearby:16.0.0' 28 | } 29 | -------------------------------------------------------------------------------- /examples/BeaconstacExample/gradle.properties: -------------------------------------------------------------------------------- 1 | # Project-wide Gradle settings. 2 | 3 | # IDE (e.g. Android Studio) users: 4 | # Gradle settings configured through the IDE *will override* 5 | # any settings specified in this file. 6 | 7 | # For more details on how to configure your build environment visit 8 | # http://www.gradle.org/docs/current/userguide/build_environment.html 9 | 10 | # Specifies the JVM arguments used for the daemon process. 11 | # The setting is particularly useful for tweaking memory settings. 12 | # Default value: -Xmx10248m -XX:MaxPermSize=256m 13 | # org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8 14 | 15 | # When configured, Gradle will run in incubating parallel mode. 16 | # This option should only be used with decoupled projects. More details, visit 17 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects 18 | # org.gradle.parallel=true -------------------------------------------------------------------------------- /Beaconstac SDK V2 (Deprecated)/BeaconstacExample/gradle.properties: -------------------------------------------------------------------------------- 1 | # Project-wide Gradle settings. 2 | 3 | # IDE (e.g. Android Studio) users: 4 | # Gradle settings configured through the IDE *will override* 5 | # any settings specified in this file. 6 | 7 | # For more details on how to configure your build environment visit 8 | # http://www.gradle.org/docs/current/userguide/build_environment.html 9 | 10 | # Specifies the JVM arguments used for the daemon process. 11 | # The setting is particularly useful for tweaking memory settings. 12 | # Default value: -Xmx10248m -XX:MaxPermSize=256m 13 | # org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8 14 | 15 | # When configured, Gradle will run in incubating parallel mode. 16 | # This option should only be used with decoupled projects. More details, visit 17 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects 18 | # org.gradle.parallel=true -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2015 Beaconstac 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | 23 | -------------------------------------------------------------------------------- /Beaconstac SDK V2 (Deprecated)/BeaconstacExample/app/src/main/java/com/mobstac/beaconstacdemo/MyBitmapLruCache.java: -------------------------------------------------------------------------------- 1 | package com.mobstac.beaconstacdemo; 2 | 3 | import android.graphics.Bitmap; 4 | import android.support.v4.util.LruCache; 5 | 6 | import com.android.volley.toolbox.ImageLoader; 7 | 8 | 9 | public class MyBitmapLruCache extends LruCache implements ImageLoader.ImageCache { 10 | 11 | public static int getDefaultLruCacheSize() { 12 | final int maxMemory = (int) (Runtime.getRuntime().maxMemory() / 1024); 13 | return maxMemory / 8; 14 | } 15 | 16 | public MyBitmapLruCache() { 17 | this(getDefaultLruCacheSize()); 18 | } 19 | 20 | public MyBitmapLruCache(int sizeInKB) { 21 | super(sizeInKB); 22 | } 23 | 24 | @Override 25 | protected int sizeOf(String key, Bitmap value) { 26 | return value.getRowBytes() * value.getHeight() / 1024; 27 | } 28 | 29 | @Override 30 | public Bitmap getBitmap(String url) { 31 | return get(url); 32 | } 33 | 34 | @Override 35 | public void putBitmap(String url, Bitmap bitmap) { 36 | put(url, bitmap); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /Beaconstac SDK V2 (Deprecated)/BeaconstacExample/app/src/main/java/com/mobstac/beaconstacdemo/MyVolley.java: -------------------------------------------------------------------------------- 1 | package com.mobstac.beaconstacdemo; 2 | 3 | import android.content.Context; 4 | 5 | import com.android.volley.Request; 6 | import com.android.volley.RequestQueue; 7 | import com.android.volley.toolbox.ImageLoader; 8 | import com.android.volley.toolbox.Volley; 9 | 10 | 11 | public class MyVolley { 12 | 13 | private static MyVolley mInstance; 14 | private RequestQueue mRequestQueue; 15 | private ImageLoader mImageLoader; 16 | private static Context mCtx; 17 | 18 | private MyVolley(Context context) { 19 | mCtx = context; 20 | mRequestQueue = getRequestQueue(); 21 | mImageLoader = new ImageLoader(mRequestQueue, new MyBitmapLruCache()); 22 | } 23 | 24 | public static synchronized MyVolley getInstance(Context context) { 25 | if (mInstance == null) { 26 | mInstance = new MyVolley(context); 27 | } 28 | return mInstance; 29 | } 30 | 31 | public RequestQueue getRequestQueue() { 32 | if (mRequestQueue == null) 33 | mRequestQueue = Volley.newRequestQueue(mCtx.getApplicationContext()); 34 | 35 | mRequestQueue.getCache().clear(); 36 | 37 | return mRequestQueue; 38 | } 39 | 40 | public void addToRequestQueue(Request req) { 41 | getRequestQueue().add(req); 42 | } 43 | 44 | public ImageLoader getImageLoader() { 45 | return mImageLoader; 46 | } 47 | 48 | 49 | } -------------------------------------------------------------------------------- /examples/BeaconstacExample/app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 15 | 16 | 21 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 35 | 36 | 37 | 38 | -------------------------------------------------------------------------------- /Beaconstac SDK V2 (Deprecated)/BeaconstacExample/app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 15 | 16 | 22 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | -------------------------------------------------------------------------------- /examples/BeaconstacExample/app/src/main/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 10 | 11 | 16 | 17 | 24 | 25 | 33 | 34 | 42 | 43 | -------------------------------------------------------------------------------- /Beaconstac SDK V2 (Deprecated)/BeaconstacExample/app/src/main/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 10 | 11 | 16 | 17 | 24 | 25 | 33 | 34 | 42 | 43 | -------------------------------------------------------------------------------- /examples/BeaconstacExample/app/src/main/java/com/mobstac/beaconstacdemo/BeaconstacUtils.java: -------------------------------------------------------------------------------- 1 | package com.mobstac.beaconstacdemo; 2 | 3 | import android.app.Activity; 4 | import android.graphics.Color; 5 | import android.support.design.widget.Snackbar; 6 | import android.util.TypedValue; 7 | import android.view.View; 8 | import android.widget.TextView; 9 | 10 | /** 11 | * Created by shashankraj on 01/02/17. 12 | * 13 | * Utility class for common repeatedly usable functions 14 | */ 15 | 16 | public class BeaconstacUtils { 17 | /** 18 | * Display a snackBar, threadsafe, can be called from a background thread 19 | * 20 | * @param message Message to display in the toast 21 | * @param activity Calling activity's reference 22 | */ 23 | public static void snackBar(final String message, final Activity activity, 24 | final String textColorCode) { 25 | 26 | if (activity != null) 27 | activity.runOnUiThread(new Runnable() { 28 | @Override 29 | public void run() { 30 | 31 | Snackbar snackbar = Snackbar 32 | .make(activity.findViewById(android.R.id.content), message, Snackbar.LENGTH_LONG); 33 | snackbar.setActionTextColor(Color.GRAY); 34 | 35 | if (textColorCode != null) { 36 | View snackBarView = snackbar.getView(); 37 | TextView textView = (TextView) 38 | snackBarView.findViewById(android.support.design.R.id.snackbar_text); 39 | textView.setTextSize(TypedValue.COMPLEX_UNIT_SP, 16); 40 | textView.setTextColor(Color.parseColor(textColorCode)); 41 | } 42 | 43 | snackbar.show(); 44 | 45 | } 46 | }); 47 | } 48 | 49 | } 50 | -------------------------------------------------------------------------------- /Beaconstac SDK V2 (Deprecated)/BeaconstacExample/app/src/main/java/com/mobstac/beaconstacdemo/BeaconstacUtils.java: -------------------------------------------------------------------------------- 1 | package com.mobstac.beaconstacdemo; 2 | 3 | import android.app.Activity; 4 | import android.graphics.Color; 5 | import android.support.design.widget.Snackbar; 6 | import android.util.TypedValue; 7 | import android.view.View; 8 | import android.widget.TextView; 9 | 10 | /** 11 | * Created by shashankraj on 01/02/17. 12 | * 13 | * Utility class for common repeatedly usable functions 14 | */ 15 | 16 | public class BeaconstacUtils { 17 | /** 18 | * Display a snackBar, threadsafe, can be called from a background thread 19 | * 20 | * @param message Message to display in the toast 21 | * @param activity Calling activity's reference 22 | */ 23 | public static void snackBar(final String message, final Activity activity, 24 | final String textColorCode) { 25 | 26 | if (activity != null) 27 | activity.runOnUiThread(new Runnable() { 28 | @Override 29 | public void run() { 30 | 31 | Snackbar snackbar = Snackbar 32 | .make(activity.findViewById(android.R.id.content), message, Snackbar.LENGTH_LONG); 33 | snackbar.setActionTextColor(Color.GRAY); 34 | 35 | if (textColorCode != null) { 36 | View snackBarView = snackbar.getView(); 37 | TextView textView = (TextView) 38 | snackBarView.findViewById(android.support.design.R.id.snackbar_text); 39 | textView.setTextSize(TypedValue.COMPLEX_UNIT_SP, 16); 40 | textView.setTextColor(Color.parseColor(textColorCode)); 41 | } 42 | 43 | snackbar.show(); 44 | 45 | } 46 | }); 47 | } 48 | 49 | } 50 | -------------------------------------------------------------------------------- /Beaconstac SDK V2 (Deprecated)/BeaconstacExample/app/src/main/java/com/mobstac/beaconstacdemo/CarouselImageFragment.java: -------------------------------------------------------------------------------- 1 | package com.mobstac.beaconstacdemo; 2 | 3 | import android.os.Bundle; 4 | import android.support.v4.app.Fragment; 5 | import android.view.LayoutInflater; 6 | import android.view.View; 7 | import android.view.ViewGroup; 8 | 9 | import com.android.volley.toolbox.ImageLoader; 10 | import com.android.volley.toolbox.NetworkImageView; 11 | 12 | 13 | public class CarouselImageFragment extends Fragment { 14 | 15 | NetworkImageView image; 16 | 17 | 18 | public static CarouselImageFragment newInstance(String url) { 19 | CarouselImageFragment fragment = new CarouselImageFragment(); 20 | Bundle args = new Bundle(); 21 | args.putString("url", url); 22 | fragment.setArguments(args); 23 | return fragment; 24 | } 25 | 26 | public CarouselImageFragment() { 27 | // Required empty public constructor 28 | } 29 | 30 | @Override 31 | public void onCreate(Bundle savedInstanceState) { 32 | super.onCreate(savedInstanceState); 33 | } 34 | 35 | @Override 36 | public View onCreateView(LayoutInflater inflater, ViewGroup container, 37 | Bundle savedInstanceState) { 38 | // Inflate the layout for this fragment 39 | View rootView = inflater.inflate(R.layout.fragment_carousel_dialog, container, false); 40 | 41 | image = (NetworkImageView) rootView.findViewById(R.id.carousel_image); 42 | 43 | String url = getArguments().getString("url"); 44 | 45 | ImageLoader imgLoader = MyVolley.getInstance(getActivity().getApplicationContext()) 46 | .getImageLoader(); 47 | 48 | image.setImageUrl(url, imgLoader); 49 | 50 | return rootView; 51 | } 52 | 53 | 54 | @Override 55 | public void onDetach() { 56 | super.onDetach(); 57 | } 58 | 59 | 60 | } -------------------------------------------------------------------------------- /Beaconstac SDK V2 (Deprecated)/BeaconstacExample/app/src/main/java/com/mobstac/beaconstacdemo/CustomViewPager.java: -------------------------------------------------------------------------------- 1 | package com.mobstac.beaconstacdemo; 2 | 3 | import android.content.Context; 4 | import android.support.v4.view.PagerAdapter; 5 | import android.support.v4.view.ViewPager; 6 | import android.util.AttributeSet; 7 | import android.view.MotionEvent; 8 | import android.view.View; 9 | 10 | /** 11 | * Created by kislaykishore on 19/08/15. 12 | *

13 | * A viewPager class which calculates it's height on runTime rather than occupying the whole screen 14 | */ 15 | 16 | public class CustomViewPager extends ViewPager { 17 | 18 | private boolean isPagingEnabled = true; 19 | private boolean isResizeEnabled = true; 20 | 21 | PagerAdapter mPagerAdapter; 22 | 23 | public CustomViewPager(Context context) { 24 | super(context); 25 | } 26 | 27 | public CustomViewPager(Context context, AttributeSet attrs) { 28 | super(context, attrs); 29 | } 30 | 31 | @Override 32 | public boolean onTouchEvent(MotionEvent event) { 33 | return this.isPagingEnabled && super.onTouchEvent(event); 34 | } 35 | 36 | @Override 37 | public boolean onInterceptTouchEvent(MotionEvent event) { 38 | return this.isPagingEnabled && super.onInterceptTouchEvent(event); 39 | } 40 | 41 | public void setPagingEnabled(boolean b) { 42 | this.isPagingEnabled = b; 43 | } 44 | 45 | public void setResizeEnabled(boolean isResizeEnabled) { 46 | this.isResizeEnabled = isResizeEnabled; 47 | } 48 | 49 | @Override 50 | protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { 51 | 52 | if (isResizeEnabled) { 53 | 54 | int height = 0; 55 | 56 | for (int i = 0; i < getChildCount(); i++) { 57 | View child = getChildAt(i); 58 | child.measure(widthMeasureSpec, MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED)); 59 | int h = child.getMeasuredHeight(); 60 | if (h > height) height = h; 61 | } 62 | 63 | heightMeasureSpec = MeasureSpec.makeMeasureSpec(height, MeasureSpec.EXACTLY); 64 | } 65 | 66 | super.onMeasure(widthMeasureSpec, heightMeasureSpec); 67 | } 68 | 69 | 70 | } -------------------------------------------------------------------------------- /examples/BeaconstacExample/app/src/main/res/layout/dialog_fragment_carousel.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 8 | 13 | 14 | 22 | 23 | 29 | 30 | 36 | 37 | 43 | 44 | 56 | 57 | 58 | 59 | 60 | -------------------------------------------------------------------------------- /Beaconstac SDK V2 (Deprecated)/BeaconstacExample/app/src/main/res/layout/dialog_fragment_carousel.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 8 | 13 | 14 | 22 | 23 | 29 | 30 | 36 | 37 | 43 | 44 | 56 | 57 | 58 | 59 | 60 | -------------------------------------------------------------------------------- /examples/BeaconstacExample/app/src/main/res/layout/dialog_youtube_popup.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 11 | 12 | 15 | 16 | 23 | 24 | 30 | 31 | 38 | 39 | 47 | 48 | 49 | 50 | 56 | 57 | 71 | 72 | 73 | 74 | -------------------------------------------------------------------------------- /Beaconstac SDK V2 (Deprecated)/BeaconstacExample/app/src/main/res/layout/dialog_youtube_popup.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 11 | 12 | 15 | 16 | 23 | 24 | 30 | 31 | 38 | 39 | 47 | 48 | 49 | 50 | 56 | 57 | 71 | 72 | 73 | 74 | -------------------------------------------------------------------------------- /examples/BeaconstacExample/app/src/main/java/com/mobstac/beaconstacdemo/BeaconAdapter.java: -------------------------------------------------------------------------------- 1 | package com.mobstac.beaconstacdemo; 2 | 3 | import android.content.Context; 4 | import android.view.LayoutInflater; 5 | import android.view.View; 6 | import android.view.ViewGroup; 7 | import android.widget.BaseAdapter; 8 | import android.widget.TextView; 9 | 10 | import com.mobstac.beaconstac.models.MBeacon; 11 | 12 | import java.util.ArrayList; 13 | import java.util.Collections; 14 | import java.util.Comparator; 15 | 16 | 17 | public class BeaconAdapter extends BaseAdapter { 18 | private ArrayList beacons; 19 | private Context ctx; 20 | private LayoutInflater myInflator; 21 | 22 | BeaconAdapter(ArrayList arr, Context c) { 23 | super(); 24 | beacons = arr; 25 | ctx = c; 26 | myInflator = (LayoutInflater) ctx.getSystemService(Context.LAYOUT_INFLATER_SERVICE); 27 | } 28 | 29 | void addBeacon(MBeacon beacon) { 30 | if(!beacons.contains(beacon)) { 31 | beacons.add(beacon); 32 | } 33 | } 34 | 35 | void removeBeacon(MBeacon beacon) { 36 | if(beacons.contains(beacon)) { 37 | beacons.remove(beacon); 38 | } 39 | } 40 | 41 | void clear() { 42 | beacons.clear(); 43 | } 44 | 45 | @Override 46 | public int getCount() { 47 | return beacons.size(); 48 | } 49 | 50 | @Override 51 | public MBeacon getItem(int position) { 52 | return beacons.get(position); 53 | } 54 | 55 | @Override 56 | public long getItemId(int position) { 57 | return position; 58 | } 59 | 60 | @Override 61 | public void notifyDataSetChanged() { 62 | Collections.sort(beacons, new Comparator() { 63 | @Override 64 | public int compare(MBeacon lhs, MBeacon rhs) { 65 | if (lhs.getRSSI() > rhs.getRSSI()) 66 | return -1; 67 | else if (lhs.getRSSI() < rhs.getRSSI()) 68 | return 1; 69 | else 70 | return 0; 71 | } 72 | }); 73 | 74 | super.notifyDataSetChanged(); 75 | } 76 | 77 | @Override 78 | public View getView(int position, View view, ViewGroup parent) { 79 | 80 | if (view == null) { 81 | view = myInflator.inflate(R.layout.beacon_view, parent, false); 82 | } 83 | MBeacon beacon = beacons.get(position); 84 | 85 | TextView name = (TextView) view.findViewById(R.id.device_name); 86 | name.setText(beacon.getName().toString()); 87 | 88 | TextView key = (TextView) view.findViewById(R.id.device_address); 89 | key.setText("Major: " + beacon.getMajor() + "\t\t\t Minor: " + beacon.getMinor() + 90 | " \t\t\t Filtered RSSI: " + beacon.getRSSI()); 91 | 92 | if (beacon.getIsCampedOn()) { 93 | view.setBackgroundResource(android.R.color.holo_green_light); 94 | } else { 95 | view.setBackgroundResource(android.R.color.background_light); 96 | } 97 | 98 | return view; 99 | 100 | } 101 | } 102 | -------------------------------------------------------------------------------- /Beaconstac SDK V2 (Deprecated)/BeaconstacExample/app/src/main/java/com/mobstac/beaconstacdemo/BeaconAdapter.java: -------------------------------------------------------------------------------- 1 | package com.mobstac.beaconstacdemo; 2 | 3 | import android.content.Context; 4 | import android.view.LayoutInflater; 5 | import android.view.View; 6 | import android.view.ViewGroup; 7 | import android.widget.BaseAdapter; 8 | import android.widget.TextView; 9 | 10 | import com.mobstac.beaconstac.models.MSBeacon; 11 | 12 | import java.util.ArrayList; 13 | import java.util.Collections; 14 | import java.util.Comparator; 15 | 16 | 17 | public class BeaconAdapter extends BaseAdapter { 18 | private ArrayList beacons; 19 | private Context ctx; 20 | private LayoutInflater myInflator; 21 | 22 | public BeaconAdapter(ArrayList arr, Context c) { 23 | super(); 24 | beacons = arr; 25 | ctx = c; 26 | myInflator = (LayoutInflater) ctx.getSystemService(Context.LAYOUT_INFLATER_SERVICE); 27 | } 28 | 29 | public void addBeacon(MSBeacon beacon) { 30 | if(!beacons.contains(beacon)) { 31 | beacons.add(beacon); 32 | } 33 | } 34 | 35 | public void removeBeacon(MSBeacon beacon) { 36 | if(beacons.contains(beacon)) { 37 | beacons.remove(beacon); 38 | } 39 | } 40 | 41 | public void clear() { 42 | beacons.clear(); 43 | } 44 | 45 | @Override 46 | public int getCount() { 47 | return beacons.size(); 48 | } 49 | 50 | @Override 51 | public MSBeacon getItem(int position) { 52 | return beacons.get(position); 53 | } 54 | 55 | @Override 56 | public long getItemId(int position) { 57 | return position; 58 | } 59 | 60 | @Override 61 | public void notifyDataSetChanged() { 62 | Collections.sort(beacons, new Comparator() { 63 | @Override 64 | public int compare(MSBeacon lhs, MSBeacon rhs) { 65 | if (lhs.getLatestRSSI() > rhs.getLatestRSSI()) 66 | return -1; 67 | else if (lhs.getLatestRSSI() < rhs.getLatestRSSI()) 68 | return 1; 69 | else 70 | return 0; 71 | } 72 | }); 73 | 74 | super.notifyDataSetChanged(); 75 | } 76 | 77 | @Override 78 | public View getView(int position, View view, ViewGroup parent) { 79 | 80 | if (view == null) { 81 | view = myInflator.inflate(R.layout.beacon_view, parent, false); 82 | } 83 | MSBeacon beacon = beacons.get(position); 84 | 85 | TextView name = (TextView) view.findViewById(R.id.device_name); 86 | name.setText(beacon.getBeaconUUID().toString()); 87 | 88 | TextView key = (TextView) view.findViewById(R.id.device_address); 89 | key.setText("Major: " + beacon.getMajor() + "\t\t\t Minor: " + beacon.getMinor() + 90 | " \t\t\t Mean RSSI: " + beacon.getMeanRSSI()); 91 | 92 | if (beacon.getIsCampedOn()) { 93 | view.setBackgroundResource(android.R.color.holo_green_light); 94 | } else { 95 | view.setBackgroundResource(android.R.color.background_light); 96 | } 97 | 98 | return view; 99 | 100 | } 101 | } 102 | -------------------------------------------------------------------------------- /examples/BeaconstacExample/app/src/main/res/layout/dialog_fragment_carousel_notification.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 8 | 13 | 14 | 22 | 23 | 29 | 30 | 36 | 37 | 43 | 44 | 48 | 49 | 63 | 64 | 70 | 71 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | -------------------------------------------------------------------------------- /Beaconstac SDK V2 (Deprecated)/BeaconstacExample/app/src/main/res/layout/dialog_fragment_carousel_notification.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 8 | 13 | 14 | 22 | 23 | 29 | 30 | 36 | 37 | 43 | 44 | 48 | 49 | 63 | 64 | 70 | 71 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | -------------------------------------------------------------------------------- /examples/BeaconstacExample/app/src/main/res/layout/dialog_youtube_popup_notification.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 11 | 12 | 15 | 16 | 23 | 24 | 30 | 31 | 38 | 39 | 47 | 48 | 49 | 50 | 56 | 57 | 61 | 62 | 76 | 77 | 83 | 84 | 98 | 99 | 100 | 101 | 102 | 103 | -------------------------------------------------------------------------------- /Beaconstac SDK V2 (Deprecated)/BeaconstacExample/app/src/main/res/layout/dialog_youtube_popup_notification.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 11 | 12 | 15 | 16 | 23 | 24 | 30 | 31 | 38 | 39 | 47 | 48 | 49 | 50 | 56 | 57 | 61 | 62 | 76 | 77 | 83 | 84 | 98 | 99 | 100 | 101 | 102 | 103 | -------------------------------------------------------------------------------- /examples/BeaconstacExample/app/src/main/java/com/mobstac/beaconstacdemo/NearbyBeaconBroadcastReceiver.java: -------------------------------------------------------------------------------- 1 | package com.mobstac.beaconstacdemo; 2 | 3 | import android.Manifest; 4 | import android.content.BroadcastReceiver; 5 | import android.content.Context; 6 | import android.content.Intent; 7 | import android.content.pm.PackageManager; 8 | import android.os.Handler; 9 | import android.support.v4.app.ActivityCompat; 10 | 11 | import com.google.android.gms.nearby.Nearby; 12 | import com.google.android.gms.nearby.messages.Message; 13 | import com.google.android.gms.nearby.messages.MessageListener; 14 | import com.mobstac.beaconstac.Beaconstac; 15 | import com.mobstac.beaconstac.core.MSException; 16 | import com.mobstac.beaconstac.interfaces.MSErrorListener; 17 | import com.mobstac.beaconstac.interfaces.MSSyncListener; 18 | import com.mobstac.beaconstac.utils.Util; 19 | 20 | public class NearbyBeaconBroadcastReceiver extends BroadcastReceiver { 21 | 22 | Beaconstac beaconstac = null; 23 | 24 | @Override 25 | public void onReceive(final Context context, Intent intent) { 26 | if (Util.isAppIsInBackground(context.getApplicationContext())) { 27 | Nearby.getMessagesClient(context).handleIntent(intent, new MessageListener() { 28 | @Override 29 | public void onFound(Message message) { 30 | try { 31 | if (ActivityCompat.checkSelfPermission(context.getApplicationContext(), Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED || ActivityCompat.checkSelfPermission(context.getApplicationContext(), Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) { 32 | return; 33 | } 34 | beaconstac = Beaconstac.initialize(context.getApplicationContext(), "MY_DEVELOPER_TOKEN", new MSSyncListener() { 35 | @Override 36 | public void onSuccess() { 37 | beaconstac.startScanningBeacons(context, new MSErrorListener() { 38 | @Override 39 | public void onError(MSException msException) { 40 | 41 | } 42 | }); 43 | autoStopScan(context, 10000); 44 | } 45 | 46 | @Override 47 | public void onFailure(MSException msException) { 48 | 49 | } 50 | }); 51 | } catch (MSException e) { 52 | e.printStackTrace(); 53 | } 54 | } 55 | 56 | @Override 57 | public void onLost(Message message) { 58 | } 59 | }); 60 | } 61 | } 62 | 63 | private void autoStopScan(final Context context, int duration) { 64 | if (beaconstac != null) { 65 | Handler handler = new Handler(); 66 | handler.postDelayed(new Runnable() { 67 | @Override 68 | public void run() { 69 | beaconstac.stopScanningBeacons(context, new MSErrorListener() { 70 | @Override 71 | public void onError(MSException msException) { 72 | 73 | } 74 | }); 75 | } 76 | }, duration); // Set the duration for which the scan needs to run for. 77 | } else { 78 | // Handle reinitialization if Beaconstac's instance is null. 79 | Handler handler = new Handler(); 80 | handler.postDelayed(new Runnable() { 81 | @Override 82 | public void run() { 83 | try { 84 | if (ActivityCompat.checkSelfPermission(context.getApplicationContext(), Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED || ActivityCompat.checkSelfPermission(context.getApplicationContext(), Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) { 85 | return; 86 | } 87 | beaconstac = Beaconstac.initialize(context.getApplicationContext(), "MY_DEVELOPER_TOKEN", new MSSyncListener() { 88 | @Override 89 | public void onSuccess() { 90 | beaconstac.stopScanningBeacons(context, new MSErrorListener() { 91 | @Override 92 | public void onError(MSException msException) { 93 | 94 | } 95 | }); 96 | } 97 | 98 | @Override 99 | public void onFailure(MSException msException) { 100 | // Stop scan even if initialization failed 101 | beaconstac.stopScanningBeacons(context, new MSErrorListener() { 102 | @Override 103 | public void onError(MSException msException) { 104 | 105 | } 106 | }); 107 | } 108 | }); 109 | } catch (MSException e) { 110 | e.printStackTrace(); 111 | } 112 | } 113 | }, duration); // Set the duration for which the scan needs to run for. 114 | 115 | } 116 | } 117 | } 118 | -------------------------------------------------------------------------------- /examples/BeaconstacExample/app/src/main/java/com/mobstac/beaconstacdemo/MainActivity.java: -------------------------------------------------------------------------------- 1 | package com.mobstac.beaconstacdemo; 2 | 3 | import android.Manifest; 4 | import android.content.pm.PackageManager; 5 | import android.os.Bundle; 6 | import android.support.v4.app.ActivityCompat; 7 | import android.support.v4.content.ContextCompat; 8 | import android.support.v7.app.AppCompatActivity; 9 | import android.util.Log; 10 | import android.widget.ListView; 11 | import android.widget.TextView; 12 | 13 | import com.mobstac.beaconstac.Beaconstac; 14 | import com.mobstac.beaconstac.core.MSException; 15 | import com.mobstac.beaconstac.interfaces.BeaconScannerCallbacks; 16 | import com.mobstac.beaconstac.interfaces.MSErrorListener; 17 | import com.mobstac.beaconstac.models.MBeacon; 18 | import com.mobstac.beaconstac.models.MRule; 19 | import com.mobstac.beaconstac.utils.MSConstants; 20 | 21 | import java.util.ArrayList; 22 | 23 | public class MainActivity extends AppCompatActivity { 24 | 25 | Beaconstac beaconstac; 26 | private ArrayList beacons = new ArrayList<>(); 27 | private BeaconAdapter beaconAdapter; 28 | private TextView bCount; 29 | private TextView testCamped; 30 | BeaconScannerCallbacks beaconScannerCallbacks; 31 | 32 | @Override 33 | protected void onCreate(Bundle savedInstanceState) { 34 | super.onCreate(savedInstanceState); 35 | setContentView(R.layout.activity_main); 36 | init(); 37 | initializeBeaconstac(); 38 | } 39 | 40 | private void init() { 41 | 42 | ListView beaconList = (ListView) findViewById(R.id.beaconListView); 43 | beaconAdapter = new BeaconAdapter(beacons, this); 44 | beaconList.setAdapter(beaconAdapter); 45 | 46 | bCount = (TextView) findViewById(R.id.beaconCount); 47 | testCamped = (TextView) findViewById(R.id.CampedView); 48 | 49 | beaconScannerCallbacks = new BeaconScannerCallbacks() { 50 | @Override 51 | public void onScannedBeacons(ArrayList rangedBeacons) { 52 | bCount.setText(String.valueOf(rangedBeacons.size())); 53 | beaconAdapter.clear(); 54 | beacons.addAll(rangedBeacons); 55 | beaconAdapter.notifyDataSetChanged(); 56 | 57 | } 58 | 59 | @Override 60 | public void onCampedBeacon(MBeacon beacon) { 61 | testCamped.setText("Camped: " + beacon.getMajor() + ":" + beacon.getMinor()); 62 | beaconAdapter.addBeacon(beacon); 63 | beaconAdapter.notifyDataSetChanged(); 64 | } 65 | 66 | @Override 67 | public void onExitedBeacon(MBeacon beacon) { 68 | testCamped.setText("Exited: " + beacon.getMajor() + ":" + beacon.getMinor()); 69 | beaconAdapter.removeBeacon(beacon); 70 | beaconAdapter.notifyDataSetChanged(); 71 | } 72 | 73 | @Override 74 | public void onRuleTriggered(MRule rule) { 75 | } 76 | 77 | }; 78 | 79 | } 80 | 81 | private void initializeBeaconstac() { 82 | if (checkPermission()) { 83 | try { 84 | beaconstac = Beaconstac.initialize(getApplicationContext(), "MY_DEVELOPER_TOKEN", new MSErrorListener() { 85 | @Override 86 | public void onError(MSException e) { 87 | Log.e("Beaconstac", "Initialization failed"); 88 | } 89 | }); 90 | } catch (MSException e) { 91 | e.printStackTrace(); 92 | } 93 | if (beaconstac != null) { 94 | beaconstac.setBeaconScannerCallbacks(beaconScannerCallbacks); 95 | beaconstac.subscribeForBackgroundUpdates(this, new NearbyBeaconBroadcastReceiver()); 96 | } 97 | } 98 | } 99 | 100 | private boolean checkPermission() { 101 | if (ContextCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED || 102 | ContextCompat.checkSelfPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED 103 | ) { 104 | ActivityCompat.requestPermissions(this, 105 | new String[]{Manifest.permission.ACCESS_FINE_LOCATION, Manifest.permission.ACCESS_COARSE_LOCATION}, 106 | MSConstants.REQUEST_LOCATION_PERMISSION); 107 | return false; 108 | } else { 109 | return true; 110 | 111 | } 112 | } 113 | 114 | @Override 115 | protected void onPause() { 116 | super.onPause(); 117 | bCount.setText(String.valueOf(beacons.size())); 118 | } 119 | 120 | @Override 121 | protected void onResume() { 122 | super.onResume(); 123 | init(); 124 | bCount.setText(String.valueOf(beacons.size())); 125 | } 126 | 127 | 128 | @Override 129 | public void onDestroy() { 130 | super.onDestroy(); 131 | beaconstac.stopScanningBeacons(this, new MSErrorListener() { 132 | @Override 133 | public void onError(MSException msException) { 134 | 135 | } 136 | }); 137 | } 138 | 139 | @Override 140 | public void onRequestPermissionsResult(int requestCode, 141 | String permissions[], int[] grantResults) { 142 | switch (requestCode) { 143 | case MSConstants.REQUEST_LOCATION_PERMISSION: { 144 | // If request is cancelled, the result arrays are empty. 145 | if (grantResults.length > 0 146 | && grantResults[0] == PackageManager.PERMISSION_GRANTED) { 147 | initializeBeaconstac(); 148 | } 149 | } 150 | } 151 | } 152 | } 153 | -------------------------------------------------------------------------------- /Beaconstac SDK V2 (Deprecated)/BeaconstacExample/app/src/main/java/com/mobstac/beaconstacdemo/ImageCarouselDialog.java: -------------------------------------------------------------------------------- 1 | package com.mobstac.beaconstacdemo; 2 | 3 | import android.content.Context; 4 | import android.content.DialogInterface; 5 | import android.content.Intent; 6 | import android.net.Uri; 7 | import android.os.Bundle; 8 | import android.support.v4.app.DialogFragment; 9 | import android.support.v4.app.Fragment; 10 | import android.support.v4.app.FragmentManager; 11 | import android.support.v4.app.FragmentPagerAdapter; 12 | import android.view.LayoutInflater; 13 | import android.view.View; 14 | import android.view.ViewGroup; 15 | import android.view.Window; 16 | import android.widget.TextView; 17 | 18 | import com.mobstac.beaconstac.utils.MSLogger; 19 | 20 | import java.util.ArrayList; 21 | 22 | /** 23 | * Created by kislaykishore on 19/08/15. 24 | */ 25 | public class ImageCarouselDialog extends DialogFragment { 26 | 27 | Context mContext; 28 | 29 | TextView titleView, textView, closeDialog, okDialog; 30 | String title, text; 31 | ArrayList imageUrls; 32 | 33 | CustomViewPager imagePager; 34 | 35 | public ImageCarouselDialog() { 36 | 37 | } 38 | 39 | @Override 40 | public void show(FragmentManager manager, String tag) { 41 | super.show(manager, tag); 42 | } 43 | 44 | /** 45 | * Returns a new Instance of ImageCarouselDialog 46 | * 47 | * @param title Title of dialog (pass null to hide title) 48 | * @param text Summary of dialog (pass null to hide summary) 49 | * @param url ArrayList containing URLs of images (pass null to hide images) 50 | */ 51 | 52 | public static ImageCarouselDialog newInstance(String title, String text, ArrayList url, String ok_label, String ok_action) { 53 | ImageCarouselDialog imageCarouselDialog = new ImageCarouselDialog(); 54 | Bundle args = new Bundle(); 55 | args.putString("title", title); 56 | args.putString("text", text); 57 | args.putString("ok_label", ok_label); 58 | args.putString("ok_action", ok_action); 59 | args.putStringArrayList("url", url); 60 | imageCarouselDialog.setArguments(args); 61 | return imageCarouselDialog; 62 | } 63 | 64 | 65 | @Override 66 | public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { 67 | final String ok_label = getArguments().getString("ok_label"); 68 | final String ok_action = getArguments().getString("ok_action"); 69 | View rootView; 70 | if (ok_label.equals("")) { 71 | rootView = inflater.inflate(R.layout.dialog_fragment_carousel, container, false); 72 | } else { 73 | rootView = inflater.inflate(R.layout.dialog_fragment_carousel_notification, container, false); 74 | } 75 | getDialog().getWindow().requestFeature(Window.FEATURE_NO_TITLE); 76 | setCancelable(false); 77 | 78 | mContext = getActivity(); 79 | 80 | title = getArguments().getString("title"); 81 | text = getArguments().getString("text"); 82 | imageUrls = getArguments().getStringArrayList("url"); 83 | 84 | closeDialog = (TextView) rootView.findViewById(R.id.dialog_close); 85 | titleView = (TextView) rootView.findViewById(R.id.carousel_title); 86 | textView = (TextView) rootView.findViewById(R.id.carousel_text); 87 | imagePager = (CustomViewPager) rootView.findViewById(R.id.image_pager); 88 | 89 | 90 | if (title == null) 91 | titleView.setVisibility(View.GONE); 92 | else 93 | titleView.setText(title); 94 | 95 | if (text == null) 96 | textView.setVisibility(View.GONE); 97 | else 98 | textView.setText(text); 99 | 100 | if (imageUrls == null) 101 | imagePager.setVisibility(View.GONE); 102 | else { 103 | PagerAdapter pagerAdapter = new PagerAdapter(getChildFragmentManager()); 104 | imagePager.setAdapter(pagerAdapter); 105 | } 106 | 107 | closeDialog.setOnClickListener(new View.OnClickListener() { 108 | @Override 109 | public void onClick(View v) { 110 | dismiss(); 111 | } 112 | }); 113 | 114 | 115 | if (!ok_label.equals("")) { 116 | okDialog = (TextView) rootView.findViewById(R.id.dialog_ok); 117 | okDialog.setText(ok_label); 118 | okDialog.setOnClickListener(new View.OnClickListener() { 119 | @Override 120 | public void onClick(View v) { 121 | dismiss(); 122 | try { 123 | Uri uri = Uri.parse(ok_action); // missing 'http://' will cause crashed 124 | Intent openUrl = new Intent(Intent.ACTION_VIEW, uri); 125 | openUrl.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); 126 | getActivity().getApplicationContext().startActivity(openUrl); 127 | } catch (Exception e) { 128 | MSLogger.error("Cannot open this url"); 129 | } 130 | } 131 | 132 | 133 | }); 134 | } 135 | return rootView; 136 | } 137 | 138 | 139 | public class PagerAdapter extends FragmentPagerAdapter { 140 | 141 | 142 | public PagerAdapter(FragmentManager fm) { 143 | super(fm); 144 | } 145 | 146 | @Override 147 | public int getCount() { 148 | return imageUrls.size(); 149 | } 150 | 151 | @Override 152 | public Fragment getItem(int position) { 153 | return CarouselImageFragment.newInstance(imageUrls.get(position)); 154 | } 155 | 156 | } 157 | 158 | @Override 159 | public void onDismiss(DialogInterface dialog) { 160 | super.onDismiss(dialog); 161 | if (getActivity() instanceof MainActivity) { 162 | MainActivity experienceDemoActivity 163 | = (MainActivity) getActivity(); 164 | experienceDemoActivity.setIsPopupVisible(false); 165 | } 166 | } 167 | 168 | @Override 169 | public void onCancel(DialogInterface dialogInterface) { 170 | super.onCancel(dialogInterface); 171 | if (getActivity() instanceof MainActivity) { 172 | MainActivity experienceDemoActivity 173 | = (MainActivity) getActivity(); 174 | experienceDemoActivity.setIsPopupVisible(false); 175 | } 176 | } 177 | 178 | } -------------------------------------------------------------------------------- /Beaconstac SDK V2 (Deprecated)/BeaconstacExample/app/src/main/java/com/mobstac/beaconstacdemo/YoutubePlayerDialog.java: -------------------------------------------------------------------------------- 1 | package com.mobstac.beaconstacdemo; 2 | 3 | import android.content.Context; 4 | import android.content.DialogInterface; 5 | import android.content.Intent; 6 | import android.net.Uri; 7 | import android.os.Bundle; 8 | import android.provider.SyncStateContract; 9 | import android.support.v4.app.DialogFragment; 10 | import android.view.LayoutInflater; 11 | import android.view.View; 12 | import android.view.ViewGroup; 13 | import android.view.Window; 14 | import android.widget.ImageView; 15 | import android.widget.ProgressBar; 16 | import android.widget.TextView; 17 | 18 | import com.google.android.youtube.player.YouTubeInitializationResult; 19 | import com.google.android.youtube.player.YouTubeStandalonePlayer; 20 | import com.google.android.youtube.player.YouTubeThumbnailLoader; 21 | import com.google.android.youtube.player.YouTubeThumbnailView; 22 | import com.mobstac.beaconstac.utils.MSLogger; 23 | 24 | /** 25 | * Created by kislaykishore on 19/08/15. 26 | */ 27 | public class YoutubePlayerDialog extends DialogFragment { 28 | 29 | Context mContext; 30 | 31 | private String VIDEO_ID, API_KEY = "AIzaSyCc56j2m22CNQY4qfmgWdhXzH_rVgCXA0I"; 32 | 33 | private YouTubeThumbnailView youTubeThumbnailView; 34 | private TextView errorText, closeDialog, okDialog; 35 | private ProgressBar loading; 36 | private ImageView playButton; 37 | 38 | public YoutubePlayerDialog() { 39 | 40 | } 41 | 42 | /** 43 | * Returns a new Instance of youtubePlayerDialog 44 | * 45 | * @param youtubeId Youtube ID of the video 46 | */ 47 | 48 | public static YoutubePlayerDialog newInstance(String youtubeId, String ok_label, String ok_action) { 49 | YoutubePlayerDialog youtubePlayerDialog = new YoutubePlayerDialog(); 50 | Bundle args = new Bundle(); 51 | args.putString("ytId", youtubeId); 52 | args.putString("ok_label", ok_label); 53 | args.putString("ok_action", ok_action); 54 | youtubePlayerDialog.setArguments(args); 55 | return youtubePlayerDialog; 56 | } 57 | 58 | 59 | @Override 60 | public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { 61 | final String ok_label = getArguments().getString("ok_label"); 62 | final String ok_action = getArguments().getString("ok_action"); 63 | View rootView; 64 | if (ok_label.equals("")) { 65 | rootView = inflater.inflate(R.layout.dialog_youtube_popup, container, false); 66 | } else { 67 | rootView = inflater.inflate(R.layout.dialog_youtube_popup_notification, container, false); 68 | } 69 | 70 | getDialog().getWindow().requestFeature(Window.FEATURE_NO_TITLE); 71 | setCancelable(false); 72 | 73 | mContext = getActivity(); 74 | errorText = (TextView) rootView.findViewById(R.id.youtube_error); 75 | closeDialog = (TextView) rootView.findViewById(R.id.youtube_dialog_close); 76 | loading = (ProgressBar) rootView.findViewById(R.id.youtube_loading); 77 | playButton = (ImageView) rootView.findViewById(R.id.youtube_play_button); 78 | 79 | VIDEO_ID = getArguments().getString("ytId"); 80 | 81 | closeDialog.setOnClickListener(new View.OnClickListener() { 82 | @Override 83 | public void onClick(View v) { 84 | dismiss(); 85 | } 86 | }); 87 | 88 | if (!ok_label.equals("")) { 89 | okDialog = (TextView) rootView.findViewById(R.id.dialog_ok); 90 | okDialog.setText(ok_label); 91 | okDialog.setOnClickListener(new View.OnClickListener() { 92 | @Override 93 | public void onClick(View v) { 94 | dismiss(); 95 | try { 96 | Uri uri = Uri.parse(ok_action); // missing 'http://' will cause crashed 97 | Intent openUrl = new Intent(Intent.ACTION_VIEW, uri); 98 | openUrl.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); 99 | getActivity().getApplicationContext().startActivity(openUrl); 100 | } catch (Exception e) { 101 | MSLogger.error("Cannot open this url"); 102 | } 103 | } 104 | }); 105 | } 106 | 107 | youTubeThumbnailView = (YouTubeThumbnailView) rootView.findViewById(R.id.youtube_thumbnail); 108 | 109 | youTubeThumbnailView.initialize(API_KEY, new ThumbnailListener()); 110 | 111 | return rootView; 112 | } 113 | 114 | 115 | @Override 116 | public void onDismiss(DialogInterface dialog) { 117 | super.onDismiss(dialog); 118 | if (getActivity() instanceof MainActivity) { 119 | MainActivity mainActivity 120 | = (MainActivity) getActivity(); 121 | mainActivity.setIsPopupVisible(false); 122 | } 123 | } 124 | 125 | @Override 126 | public void onCancel(DialogInterface dialogInterface) { 127 | super.onCancel(dialogInterface); 128 | if (getActivity() instanceof MainActivity) { 129 | MainActivity mainActivity 130 | = (MainActivity) getActivity(); 131 | mainActivity.setIsPopupVisible(false); 132 | } 133 | } 134 | 135 | class ThumbnailListener implements 136 | YouTubeThumbnailView.OnInitializedListener, 137 | YouTubeThumbnailLoader.OnThumbnailLoadedListener { 138 | 139 | @Override 140 | public void onInitializationSuccess( 141 | YouTubeThumbnailView view, YouTubeThumbnailLoader loader) { 142 | loader.setOnThumbnailLoadedListener(this); 143 | loader.setVideo(VIDEO_ID); 144 | 145 | view.setOnClickListener(new View.OnClickListener() { 146 | @Override 147 | public void onClick(View v) { 148 | Intent intent = YouTubeStandalonePlayer.createVideoIntent(getActivity(), 149 | API_KEY, VIDEO_ID); 150 | startActivity(intent); 151 | dismiss(); 152 | } 153 | }); 154 | 155 | } 156 | 157 | @Override 158 | public void onInitializationFailure( 159 | YouTubeThumbnailView view, YouTubeInitializationResult loader) { 160 | errorText.setText("Error while loading video"); 161 | } 162 | 163 | @Override 164 | public void onThumbnailLoaded(YouTubeThumbnailView view, String videoId) { 165 | loading.setVisibility(View.GONE); 166 | playButton.setVisibility(View.VISIBLE); 167 | } 168 | 169 | @Override 170 | public void onThumbnailError(YouTubeThumbnailView view, YouTubeThumbnailLoader.ErrorReason errorReason) { 171 | errorText.setText("Error while loading video"); 172 | } 173 | } 174 | 175 | } -------------------------------------------------------------------------------- /Beaconstac SDK V2 (Deprecated)/README.md: -------------------------------------------------------------------------------- 1 | # Android-SDK (Deprecated) 2 | 3 | ## Please use the new version of the SDK. 4 | 5 | ## Introduction 6 | 7 | Beaconstac SDK is an easy way to enable proximity marketing and location analytics through an iBeacon-compliant BLE network. 8 | 9 | ## Documentation 10 | 11 | Please refer to the API documentation on the [Beaconstac developer hub](http://docs.beaconstac.com/docs/references/android/). 12 | 13 | ## Integration with your existing project in Android Studio 14 | 15 | 1. You can obtain the SDK from Gradle using - 16 | ```groovy 17 | compile 'com.mobstac.beaconstac:beaconstac_sdk:2.0.4' 18 | ``` 19 | Latest version
20 | [ ![Download](https://api.bintray.com/packages/mobstac/maven/beaconstac_sdk/images/download.svg) ](https://bintray.com/mobstac/maven/beaconstac_sdk/_latestVersion) 21 | 22 | 2. Refresh all Gradle projects. 23 | 24 | 3. Add `uses-feature` tag to app manifest: 25 | 26 | 29 | 30 | 4. Add the following permissions to app manifest: 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 5. Add the Beaconstac BLEService to your app manifest: 40 | 41 | 42 | 43 | 6. To get the Beaconstac instance, insert the `developer token` and `organisation id` and add a MSSyncListener: 44 | 45 | // Note that this will sync Beacons, Rules and Notifications implicitly but Tags and Places will not be synced. 46 | Beaconstac bstacInstance = Beaconstac.getInstance(this, "Developer_token", organisation id , new MSSyncListener() { 47 | @Override 48 | public void onSuccess() { 49 | //Initialization successful. 50 | } 51 | 52 | @Override 53 | public void onFailure(MSException msException) { 54 | //Initialization failed. 55 | } 56 | }); 57 | 58 | 7. You can also sync them individually if required: 59 | 60 | // To sync Beacons 61 | bstacInstance.syncBeacons(new MSSyncListener() { 62 | @Override 63 | public void onSuccess() { 64 | //Beacons Synced 65 | } 66 | 67 | @Override 68 | public void onFailure(MSException e) { 69 | //Failed to sync Beacons 70 | } 71 | }); 72 | 73 | // To sync Rules 74 | bstacInstance.syncRules(new MSSyncListener() { 75 | @Override 76 | public void onSuccess() { 77 | //Rules synced 78 | } 79 | 80 | @Override 81 | public void onFailure(MSException e) { 82 | //Failed to sync Rules 83 | } 84 | }); 85 | 86 | // To sync Notifications 87 | bstacInstance.syncNotifications(new MSSyncListener() { 88 | @Override 89 | public void onSuccess() { 90 | //Notifications Synced 91 | } 92 | 93 | @Override 94 | public void onFailure(MSException e) { 95 | //Failed to sync Notifications 96 | } 97 | }); 98 | 99 | // To sync Tags 100 | bstacInstance.syncTags(new MSSyncListener() { 101 | @Override 102 | public void onSuccess() { 103 | //Tags synced 104 | } 105 | 106 | @Override 107 | public void onFailure(MSException e) { 108 | //Failed to sync tags 109 | } 110 | }); 111 | 112 | // To sync Places 113 | bstacInstance.syncPlaces(new MSSyncListener() { 114 | @Override 115 | public void onSuccess() { 116 | //Places synced 117 | } 118 | 119 | @Override 120 | public void onFailure(MSException e) { 121 | //Failed to sync places 122 | } 123 | }); 124 | 125 | 126 | 8. To monitor beacon regions, configure the `UUID` and `region_identifier`. 127 | 128 | // set region parameters (UUID and unique region identifier) 129 | bstacInstance.setRegionParams("Enter your UUID here", 130 | "com.mobstac.beaconstacexample"); 131 | 132 | 9. Call `startRangingBeacons` on the `Beaconstac` instance after configuring the params as mentioned in the previous step. The method will need a `MSErrorListener` to handle error in ranging beacons. 133 | 134 | // start scanning beacons 135 | bstacInstance.startRangingBeacons(new MSErrorListener() { 136 | @Override 137 | public void onError(MSException e) { 138 | //BLE not supoorted 139 | } 140 | }); 141 | 142 | 10. If you want to stop scanning for the beacons, call `stopRangingBeacons` on the `Beaconstac` instance. The method will need a `MSErrorListener` to handle error in stop ranging beacons. 143 | 144 | // stop scanning 145 | bstacInstance.stopRangingBeacons(new MSErrorListener() { 146 | @Override 147 | public void onError(MSException e) { 148 | //BLE not supported 149 | } 150 | }); 151 | 152 | 11. You need to add a `BeaconScannerCallbacks` to get the events that are being triggered. 153 | 154 | // This is a listener to listen to events being triggered 155 | bstacInstance.setBeaconScannerCallbacks(new BeaconScannerCallbacks() { 156 | @Override 157 | public void onRangedBeacons(ArrayList arrayList) { 158 | 159 | } 160 | 161 | @Override 162 | public void onCampedBeacon(MSBeacon msBeacon) { 163 | 164 | } 165 | 166 | @Override 167 | public void onExitedBeacon(MSBeacon msBeacon) { 168 | 169 | } 170 | 171 | @Override 172 | public void onEnteredRegion(String s) { 173 | 174 | } 175 | 176 | @Override 177 | public void onExitedRegion(String s) { 178 | 179 | } 180 | 181 | @Override 182 | public void onRuleTriggered(String s, ArrayList arrayList) { 183 | 184 | 185 | } 186 | }); 187 | 188 | You can find more information and example usage in the `BeaconstacExample` app contained in the `examples` directory of this repo. -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Beaconstac Android-SDK 2 | 3 | ## Introduction 4 | 5 | Beaconstac Advanced Android SDK is meant only for specialized use cases. Please check with the support team before deciding to integrate this SDK. 6 | 7 | ## Integrate with your existing project in Android Studio 8 | 9 | ### In the `build.gradle` file of the app, add the following in the dependencies section: 10 | ```groovy 11 | implementation 'com.android.support.constraint:constraint-layout:1.0.2' 12 | implementation 'com.mobstac.beaconstac:proximity:3.3+' 13 | ``` 14 | 15 | If you want to receive background updates as shown in the sample app [here](examples/BeaconstacExample/app/src/main/java/com/mobstac/beaconstacdemo/NearbyBeaconBroadcastReceiver.java), add this to your app gradle 16 | ```groovy 17 | implementation 'com.google.android.gms:play-services-nearby:16.0.0' 18 | ``` 19 | 20 | 21 | Latest version 22 | 23 | [ ![Download](https://api.bintray.com/packages/mobstac/maven/proximity/images/download.svg) ](https://bintray.com/mobstac/maven/proximity/_latestVersion) 24 | 25 | ## Permissions 26 | 27 | __Beaconstac requires the following permissions__ 28 | ```xml 29 | 30 | 31 | 32 | 33 | 34 | 35 | ``` 36 | 37 | It is not necessary to explicitly add these permissions to your app. They will be added automatically when you include the SDK. 38 | 39 | ### Runtime permissions 40 | 41 | Since Android 6.0, Android has introduced the concept of runtime permissions. Beaconstac SDK requires one runtime permission: 42 | 43 | __Location__ 44 | 45 | Beaconstac requires the location permission to scan for nearby beacons. Beaconstac SDK's initialize() will fail if location permission is denied. 46 | 47 | ### Prerequisites 48 | 49 | 1. Please extract your developer token from the Beaconstac dashboard under "My Account". 50 | 2. Internet access is required to initialize the SDK. 51 | 3. Bluetooth enabled for scanning beacons. 52 | 53 | ## Usage 54 | 55 | ### Use our one line integration 56 | 57 | __Note:__ If this is used, the Beaconstac SDK will automatically start scanning for beacons and trigger notifications based on rules defined on Beaconstac dashboard. You can also explicitly start or stop beacon scanning by calling `Beaconstac.getInstance(getApplicationContext()).startScanningBeacons()` and `Beaconstac.getInstance(getApplicationContext()).stopScanningBeacons()` respectively. Please refer [advanced](#3-start-scan) for more info. 58 | 59 | __For using the SDK while the app is in the background or terminated state, please refer [Handling background scanning and delivering notifications](#handling-background-scanning-and-delivering-notifications).__ 60 | 61 | ```java 62 | Beaconstac.initialize(getApplicationContext(), MY_DEVELOPER_TOKEN, new MSErrorListener() { 63 | @Override 64 | public void onError(MSException msException) { 65 | Log.d("Beaconstac", msException.getErrorMessage()); 66 | } 67 | }); 68 | ``` 69 | 70 | ### OR 71 | 72 | ### Use our advanced integration 73 | 74 | __1. Initialise the SDK with your developer token (preferably in the Application class)__ 75 | 76 | ```java 77 | 78 | Beaconstac.initialize(getApplicationContext(), MY_DEVELOPER_TOKEN, new MSSyncListener() { 79 | @Override 80 | public void onSuccess() { 81 | Log.d("Beaconstac", "Initialization successful"); 82 | Beaconstac.getInstance(getApplicationContext()).startScanningBeacons(new MSErrorListener() { 83 | @Override 84 | public void onError(MSException msException) { 85 | 86 | } 87 | }); 88 | } 89 | 90 | @Override 91 | public void onFailure(MSException e) { 92 | Log.d("Beaconstac", "Initialization failed"); 93 | } 94 | 95 | }); 96 | ``` 97 | 98 | __2. Get Beaconstac instance__ 99 | ```java 100 | Beaconstac beaconstac = Beaconstac.getInstance(getApplicationContext()); 101 | ``` 102 | #### 3. Start scan 103 | 104 | ```java 105 | Beaconstac.getInstance(getApplicationContext()).startScanningBeacons(getApplicationContext(), new MSErrorListener() { 106 | @Override 107 | public void onError(MSException msException) { 108 | 109 | } 110 | }); 111 | ``` 112 | __4. Stop scan__ 113 | ```java 114 | Beaconstac.getInstance(getApplicationContext()).stopScanningBeacons(getApplicationContext(), new MSErrorListener() { 115 | @Override 116 | public void onError(MSException msException) { 117 | 118 | } 119 | }); 120 | ``` 121 | 122 | __5. Get beacon event callbacks__ 123 | 124 | __Note: You only need to implement this if you want to get callbacks for beacon events.__ 125 | 126 | ```java 127 | Beaconstac.getInstance(getApplicationContext()).setBeaconScannerCallbacks(new BeaconScannerCallbacks() { 128 | @Override 129 | public void onScannedBeacons(ArrayList rangedBeacons) { 130 | } 131 | 132 | @Override 133 | public void onCampedBeacon(MBeacon beacon) { 134 | } 135 | 136 | @Override 137 | public void onExitedBeacon(MBeacon beacon) { 138 | } 139 | 140 | @Override 141 | public void onRuleTriggered(MRule rule) { 142 | } 143 | 144 | }); 145 | ``` 146 | 147 | __6. Override Beaconstac SDK's notification__ 148 | 149 | __Note: If you implement this method Beaconstac SDK will not trigger any notification. A `Notification.Builder` object will returned to the app and it will be the application's responsibility to modify and trigger the notifications.__ 150 | 151 | ```java 152 | Beaconstac.getInstance(getApplicationContext()).overrideBeaconstacNotification(new BeaconstacNotification() { 153 | @Override 154 | public void notificationTrigger(Notification.Builder notification) { 155 | 156 | } 157 | }); 158 | ``` 159 | 160 | 161 | __7. Add additional values to your webhooks__ 162 | 163 | ```java 164 | Beaconstac.getInstance(getApplicationContext()).addValuesToWebhook(MY_KEY, VALUE); 165 | ``` 166 | 167 | OR 168 | ```java 169 | Beaconstac.getInstance(getApplicationContext()).addValuesToWebhook(MY_KEY_VALUE_HASHMAP); 170 | ``` 171 | 172 | __8. Set user's name__ 173 | ```java 174 | Beaconstac.getInstance(getApplicationContext()).setUserName(getApplicationContext(), USER_FIRST_NAME , USER_LAST_NAME); 175 | ``` 176 | 177 | __9. Set user's email__ 178 | ```java 179 | Beaconstac.getInstance(getApplicationContext()).setUserEmail(getApplicationContext(), USER_EMAIL); 180 | ``` 181 | 182 | __10. Set scan power mode__ 183 | 184 | Set the power mode for bluetooth low energy scan callbacks. Set to HIGH for frequent scans with high power consumption. 185 | Default value is set to BALANCED. 186 | ```java 187 | Beaconstac.getInstance(getApplicationContext()).setPowerMode(POWER_MODE); 188 | ``` 189 | 190 | __11. Set latch latency__ 191 | 192 | Set the device's willingness to camp-on to new beacons if it is already camped on to one. If set to LOW the device switches to the other beacons quickly and if set to HIGH the device's attachment will be steady. 193 | The default value is set to MEDIUM. 194 | ```java 195 | Beaconstac.getInstance(getApplicationContext()).setLatchLatency(LATCH_LATENCY); 196 | ``` 197 | 198 | ## Handling background scanning and delivering notifications 199 | 200 | 201 | ### App running in the background 202 | 203 | __For Android < 8__ 204 | 205 | _You can scan for beacons when the app is in the foreground or in the background._ 206 | 207 | __For Android >= 8__ 208 | 209 | _You scan for beacons when the app is in the foreground. 210 | If you need to scan for beacons while the app is running in the background, please start a [FOREGROUND SERVICE](https://developer.android.com/guide/components/services#Foreground) and start the scan inside the service._ 211 | 212 | 213 | ### App in terminated state 214 | 215 | You can use the following method to register a `BroadcastReceiver` and get callbacks when the device enters the range of a new beacon or beacon goes out of range. 216 | 217 | The `BroadcastReceiver` will receive callbacks as follows. 218 | 219 | _1. Periodically
_ 220 | _2. When device screen is turned on._ 221 | 222 | *__Note: The `BroadcastReceiver` will be unregistered when the device reboots, please make sure you register the receiver again.__* 223 | 224 | __BroadcastReceiver example implementation__ 225 | ```java 226 | public class MyBroadcastReceiver extends BroadcastReceiver { 227 | @Override 228 | public void onReceive(Context context, Intent intent) { 229 | Nearby.getMessagesClient(context).handleIntent(intent, new MessageListener() { 230 | @Override 231 | public void onFound(Message message) { 232 | } 233 | 234 | @Override 235 | public void onLost(Message message) { 236 | } 237 | }); 238 | } 239 | } 240 | ``` 241 | 242 | __1. Subscribe for updates__ 243 | 244 | ```java 245 | Beaconstac.getInstance(getApplicationContext()).subscribeForBackgroundUpdates(getApplicationContext(), new MyBroadcastReceiver()); 246 | ``` 247 | 248 | Once a callback is received by the receiver you can choose to start scanning for beacons using the Beaconstac SDK and once done you *must* stop the scan. Please refer to the example receiver [here](https://github.com/Beaconstac/Android-SDK/blob/master/examples/BeaconstacExample/app/src/main/java/com/mobstac/beaconstacdemo/NearbyBeaconBroadcastReceiver.java). 249 | 250 | *__Note: Stopping the scan is required and should be a mandatory step. If not stopped, the Beaconstac SDK will keep scanning indefinitely. This will result in high power consumption and will keep on showing a persistent notification on devices running on Android 8 and above.__* 251 | 252 | 253 | __2. Unsubscribe from updates__ 254 | 255 | ```java 256 | Beaconstac.getInstance(getApplicationContext()).unSubscribeFromBackgroundUpdates(getApplicationContext(), new MyBroadcastReceiver()); 257 | ``` 258 | 259 | __Due to the restriction added on Android 8 and above on running background tasks, a persistent notification will be shown when the SDK is running in the background. Please see [this](https://developer.android.com/about/versions/oreo/background) for more details.__ 260 | 261 | ``` 262 | Please add the following string resources to your app with suitable changes to the text value. 263 | 264 | Notification title 265 | Notification subtitle 266 | 267 | Please add a drawable resource named ic_launcher to override the default icon for the persistent notification shown when the scan runs in background. 268 | ``` 269 | 270 | You can find more information and example usage in the `BeaconstacExample` app contained in the `examples` directory of this repo. 271 | -------------------------------------------------------------------------------- /Beaconstac SDK V2 (Deprecated)/BeaconstacExample/app/src/main/java/com/mobstac/beaconstacdemo/MainActivity.java: -------------------------------------------------------------------------------- 1 | package com.mobstac.beaconstacdemo; 2 | 3 | import android.Manifest; 4 | import android.app.Activity; 5 | import android.app.AlertDialog; 6 | import android.app.NotificationManager; 7 | import android.app.PendingIntent; 8 | import android.bluetooth.BluetoothAdapter; 9 | import android.bluetooth.BluetoothManager; 10 | import android.content.Context; 11 | import android.content.DialogInterface; 12 | import android.content.Intent; 13 | import android.content.pm.PackageManager; 14 | import android.net.Uri; 15 | import android.os.Build; 16 | import android.os.Bundle; 17 | import android.support.v4.app.ActivityCompat; 18 | import android.support.v4.app.FragmentManager; 19 | import android.support.v4.app.NotificationCompat; 20 | import android.support.v4.content.ContextCompat; 21 | import android.support.v7.app.AppCompatActivity; 22 | import android.util.Log; 23 | import android.webkit.WebView; 24 | import android.webkit.WebViewClient; 25 | import android.widget.ListView; 26 | import android.widget.TextView; 27 | 28 | import com.mobstac.beaconstac.Beaconstac; 29 | import com.mobstac.beaconstac.core.ErrorCodes; 30 | import com.mobstac.beaconstac.core.MSException; 31 | import com.mobstac.beaconstac.interfaces.BeaconScannerCallbacks; 32 | import com.mobstac.beaconstac.interfaces.MSErrorListener; 33 | import com.mobstac.beaconstac.interfaces.MSSyncListener; 34 | import com.mobstac.beaconstac.interfaces.Webhook; 35 | import com.mobstac.beaconstac.models.MSAction; 36 | import com.mobstac.beaconstac.models.MSBeacon; 37 | import com.mobstac.beaconstac.models.MSCard; 38 | import com.mobstac.beaconstac.models.MSMedia; 39 | import com.mobstac.beaconstac.utils.MSConstants; 40 | import com.mobstac.beaconstac.utils.MSLogger; 41 | 42 | import org.json.JSONObject; 43 | 44 | import java.util.ArrayList; 45 | import java.util.HashMap; 46 | import java.util.regex.Matcher; 47 | import java.util.regex.Pattern; 48 | 49 | 50 | public class MainActivity extends AppCompatActivity { 51 | 52 | private static final String TAG = MainActivity.class.getSimpleName(); 53 | private static final int REQUEST_ENABLE_BT = 1; 54 | private ArrayList beacons = new ArrayList<>(); 55 | private boolean isPopupVisible = false; 56 | private BeaconAdapter beaconAdapter; 57 | private ListView beaconList; 58 | private TextView bCount; 59 | private TextView testCamped; 60 | private BluetoothAdapter mBluetoothAdapter; 61 | private Beaconstac bstac; 62 | private Activity mainActivity = this; 63 | private boolean appInForeground = false; 64 | 65 | @Override 66 | protected void onCreate(Bundle savedInstanceState) { 67 | super.onCreate(savedInstanceState); 68 | setContentView(R.layout.activity_main); 69 | 70 | // Use this check to determine whether BLE is supported on the device. 71 | try { 72 | if (!getPackageManager().hasSystemFeature(PackageManager.FEATURE_BLUETOOTH_LE)) 73 | throw new MSException(MSConstants.ERROR_BLE_NOT_SUPPORTED, ErrorCodes.BLE_NOT_SUPPORTED); 74 | 75 | } catch (MSException msException) { 76 | 77 | } 78 | 79 | 80 | // Initializes a Bluetooth adapter. For API level 18 and above, get a reference to 81 | // BluetoothAdapter through BluetoothManager. 82 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) { 83 | BluetoothManager mBluetoothManager = (BluetoothManager) getSystemService(Context.BLUETOOTH_SERVICE); 84 | mBluetoothAdapter = mBluetoothManager.getAdapter(); 85 | } 86 | 87 | // Checks if Bluetooth is supported on the device. 88 | try { 89 | if (mBluetoothAdapter == null) { 90 | Log.e(TAG, "Unable to obtain a BluetoothAdapter."); 91 | throw new MSException(MSConstants.ERROR_BLUETOOTH_NOT_FOUND, ErrorCodes.BLUETOOTH_NOT_FOUND); 92 | 93 | } else { 94 | if (!mBluetoothAdapter.isEnabled()) { 95 | Intent enableBtIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE); 96 | startActivityForResult(enableBtIntent, REQUEST_ENABLE_BT); 97 | } 98 | } 99 | } catch (MSException msException) { 100 | 101 | } 102 | 103 | 104 | bstac = Beaconstac.getInstance(this, "0", -1, new MSSyncListener() { 105 | @Override 106 | public void onSuccess() { 107 | Log.i(TAG, "Initialisation Successful"); 108 | } 109 | 110 | @Override 111 | public void onFailure(MSException msException) { 112 | Log.e(TAG, "Initialisation Failed" + String.valueOf(msException.getErrorCode())); 113 | } 114 | }); 115 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) 116 | checkPermission(); 117 | 118 | init(); 119 | 120 | bstac.setRegionParams("F94DBB23-2266-7822-3782-57BEAC0952AC", "com.mobstac.beaconstacdemo"); 121 | 122 | bstac.startRangingBeacons(new MSErrorListener() { 123 | @Override 124 | public void onError(MSException e) { 125 | Log.d(TAG, "BLE not supported!"); 126 | } 127 | }); 128 | 129 | bstac.setBeaconScannerCallbacks(new BeaconScannerCallbacks() { 130 | 131 | @Override 132 | public void onRangedBeacons(ArrayList rangedBeacons) { 133 | bCount.setText("" + rangedBeacons.size()); 134 | beaconAdapter.clear(); 135 | beacons.addAll(rangedBeacons); 136 | beaconAdapter.notifyDataSetChanged(); 137 | } 138 | 139 | @Override 140 | public void onCampedBeacon(MSBeacon beacon) { 141 | 142 | testCamped.setText("Camped: " + beacon.getMajor() + ":" + beacon.getMinor()); 143 | beaconAdapter.addBeacon(beacon); 144 | beaconAdapter.notifyDataSetChanged(); 145 | } 146 | 147 | @Override 148 | public void onExitedBeacon(MSBeacon beacon) { 149 | 150 | testCamped.setText("Exited: " + beacon.getMajor() + ":" + beacon.getMinor()); 151 | beaconAdapter.removeBeacon(beacon); 152 | beaconAdapter.notifyDataSetChanged(); 153 | 154 | } 155 | 156 | @Override 157 | public void onEnteredRegion(String mRegionIdentifier) { 158 | 159 | beaconAdapter.clear(); 160 | beaconAdapter.notifyDataSetChanged(); 161 | bCount.setText("" + beacons.size()); 162 | 163 | BeaconstacUtils.snackBar("Entered Region", mainActivity, MSConstants.COLOUR_WHITE); 164 | } 165 | 166 | @Override 167 | public void onExitedRegion(String mRegionIdentifier) { 168 | 169 | beaconAdapter.clear(); 170 | beaconAdapter.notifyDataSetChanged(); 171 | bCount.setText("" + beacons.size()); 172 | 173 | BeaconstacUtils.snackBar("Exited Region", mainActivity, MSConstants.COLOUR_WHITE); 174 | } 175 | 176 | @Override 177 | public void onRuleTriggered(String ruleName, ArrayList actions) { 178 | HashMap messageMap; 179 | MSLogger.log("appInForeground " + appInForeground); 180 | if (appInForeground) { 181 | for (MSAction action : actions) { 182 | messageMap = action.getMessage(); 183 | String ok_label = ""; 184 | String ok_action = ""; 185 | switch (action.getType()) { 186 | case MSActionTypePopup: 187 | if (!isPopupVisible) { 188 | isPopupVisible = true; 189 | ok_label = (String) messageMap.get("notificationOkLabel"); 190 | ok_action = (String) messageMap.get("notificationOkAction"); 191 | showPopupDialog(action.getName(), (String) messageMap.get("text"), null, ok_label, ok_action); 192 | } 193 | break; 194 | 195 | case MSActionTypeCard: 196 | if (!isPopupVisible) { 197 | isPopupVisible = true; 198 | MSCard card = (MSCard) messageMap.get("card"); 199 | MSMedia m; 200 | String src; 201 | AlertDialog.Builder dialog; 202 | 203 | String title = card.getTitle(); 204 | 205 | switch (card.getType()) { 206 | case MSCardTypePhoto: 207 | ArrayList urls = new ArrayList<>(); 208 | for (int i = 0; i < card.getMediaArray().size(); i++) { 209 | m = card.getMediaArray().get(i); 210 | src = m.getMediaUrl().toString(); 211 | urls.add(src); 212 | } 213 | ok_label = (String) messageMap.get("notificationOkLabel"); 214 | ok_action = (String) messageMap.get("notificationOkAction"); 215 | showPopupDialog(title, null, urls, ok_label, ok_action); 216 | break; 217 | 218 | case MSCardTypeSummary: 219 | ArrayList cardUrls = new ArrayList<>(); 220 | for (int i = 0; i < card.getMediaArray().size(); i++) { 221 | m = card.getMediaArray().get(i); 222 | src = m.getMediaUrl().toString(); 223 | cardUrls.add(src); 224 | } 225 | ok_label = (String) messageMap.get("notificationOkLabel"); 226 | ok_action = (String) messageMap.get("notificationOkAction"); 227 | showPopupDialog(card.getTitle(), card.getBody(), cardUrls, ok_label, ok_action); 228 | break; 229 | 230 | case MSCardTypeMedia: 231 | if (!card.getMediaArray().isEmpty()) { 232 | m = card.getMediaArray().get(0); 233 | src = m.getMediaUrl().toString(); 234 | 235 | // handle custom url types 236 | String ytId = extractYTId(src); 237 | if (ytId != null) { 238 | 239 | ok_label = (String) messageMap.get("notificationOkLabel"); 240 | ok_action = (String) messageMap.get("notificationOkAction"); 241 | showYoutubePopup(ytId, ok_label, ok_action); 242 | 243 | } else { 244 | dialog = new AlertDialog.Builder(MainActivity.this); 245 | dialog.setOnDismissListener(new DialogInterface.OnDismissListener() { 246 | @Override 247 | public void onDismiss(DialogInterface dialog) { 248 | isPopupVisible = false; 249 | } 250 | }); 251 | final WebView webView = new WebView(MainActivity.this); 252 | webView.getSettings().setJavaScriptEnabled(true); 253 | webView.setWebViewClient(new WebViewClient()); 254 | webView.loadUrl(src); 255 | 256 | ok_label = (String) messageMap.get("notificationOkLabel"); 257 | final String ok_actionForWebDialog = (String) messageMap.get("notificationOkAction"); 258 | if (ok_label != null && !ok_label.equals("") && ok_label.trim().length() != 0) { 259 | 260 | dialog.setPositiveButton(ok_label, new DialogInterface.OnClickListener() { 261 | @Override 262 | public void onClick(DialogInterface dialog, int which) { 263 | dialog.dismiss(); 264 | try { 265 | Uri uri = Uri.parse(ok_actionForWebDialog); // missing 'http://' will cause crashed 266 | Intent openUrl = new Intent(Intent.ACTION_VIEW, uri); 267 | openUrl.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); 268 | startActivity(openUrl); 269 | } catch (Exception e) { 270 | MSLogger.error("Cannot open this url"); 271 | } 272 | } 273 | }); 274 | } 275 | 276 | dialog.setView(webView); 277 | dialog.setNeutralButton("Close", null); 278 | dialog.show(); 279 | } 280 | } 281 | break; 282 | case MSCardTypePage: 283 | ArrayList cardUrl = new ArrayList<>(); 284 | for (int i = 0; i < card.getMediaArray().size(); i++) { 285 | m = card.getMediaArray().get(i); 286 | src = m.getMediaUrl().toString(); 287 | cardUrl.add(src); 288 | } 289 | ok_label = (String) messageMap.get("notificationOkLabel"); 290 | ok_action = (String) messageMap.get("notificationOkAction"); 291 | showPopupDialog(card.getTitle(), card.getBody(), cardUrl, ok_label, ok_action); 292 | break; 293 | } 294 | } 295 | break; 296 | 297 | case MSActionTypeWebpage: 298 | if (!isPopupVisible) { 299 | final AlertDialog.Builder dialog = new AlertDialog.Builder(MainActivity.this); 300 | dialog.setOnDismissListener(new DialogInterface.OnDismissListener() { 301 | @Override 302 | public void onDismiss(DialogInterface dialog) { 303 | isPopupVisible = false; 304 | } 305 | }); 306 | 307 | final WebView webView = new WebView(MainActivity.this); 308 | webView.getSettings().setJavaScriptEnabled(true); 309 | webView.setWebViewClient(new WebViewClient()); 310 | webView.loadUrl(messageMap.get("url").toString()); 311 | 312 | dialog.setView(webView); 313 | dialog.setPositiveButton("Close", null); 314 | dialog.show(); 315 | 316 | isPopupVisible = true; 317 | } 318 | break; 319 | 320 | case MSActionTypeCustom: 321 | MSLogger.log("Card id: " + action.getActionID()); 322 | break; 323 | 324 | case MSActionTypeNotification: 325 | bstac.showDefaultNotification(action); 326 | break; 327 | 328 | case MSActionTypeWebhook: 329 | //TODO: Implement listener 330 | break; 331 | } 332 | } 333 | } else { 334 | for (MSAction action : actions) { 335 | MSAction.MSActionType type = action.getType(); 336 | if (type == MSAction.MSActionType.MSActionTypeCard || type == MSAction.MSActionType.MSActionTypeNotification) 337 | bstac.showDefaultNotification(action); 338 | } 339 | 340 | BeaconstacUtils.snackBar("Rule " + ruleName, mainActivity, MSConstants.COLOUR_WHITE); 341 | } 342 | } 343 | }); 344 | 345 | } 346 | 347 | private void init() { 348 | beaconList = (ListView) findViewById(R.id.beaconListView); 349 | beaconAdapter = new BeaconAdapter(beacons, this); 350 | beaconList.setAdapter(beaconAdapter); 351 | 352 | bCount = (TextView) findViewById(R.id.beaconCount); 353 | testCamped = (TextView) findViewById(R.id.CampedView); 354 | 355 | } 356 | 357 | 358 | @Override 359 | protected void onPause() { 360 | super.onPause(); 361 | bCount.setText("" + beacons.size()); 362 | appInForeground = false; 363 | } 364 | 365 | @Override 366 | protected void onResume() { 367 | super.onResume(); 368 | init(); 369 | bCount.setText("" + beacons.size()); 370 | appInForeground = true; 371 | } 372 | 373 | @Override 374 | protected void onDestroy() { 375 | super.onDestroy(); 376 | if (bstac != null) 377 | bstac.stopRangingBeacons(new MSErrorListener() { 378 | @Override 379 | public void onError(MSException e) { 380 | Log.d(TAG, "BLE not supported!"); 381 | } 382 | }); 383 | } 384 | 385 | // Callback intent results 386 | @Override 387 | protected void onActivityResult(int requestCode, int resultCode, Intent data) { 388 | if (requestCode == REQUEST_ENABLE_BT && resultCode == Activity.RESULT_CANCELED) { 389 | finish(); 390 | } 391 | 392 | if (bstac != null) { 393 | bstac.startRangingBeacons(new MSErrorListener() { 394 | @Override 395 | public void onError(MSException e) { 396 | Log.d(TAG, "BLE not supported!"); 397 | } 398 | }); 399 | } 400 | } 401 | 402 | 403 | /** 404 | * Opens a dialogFragment to display offers 405 | * 406 | * @param title Title of dialog (pass null to hide title) 407 | * @param text Summary of dialog (pass null to hide summary) 408 | * @param url ArrayList containing URLs of images (pass null to hide images) 409 | */ 410 | private void showPopupDialog(String title, String text, ArrayList url, String... ok_data) { 411 | String ok_label = ""; 412 | String ok_action = ""; 413 | 414 | if (ok_data.length == 2) { 415 | if (ok_data[0] != null && ok_data[1] != null) { 416 | ok_label = ok_data[0]; 417 | ok_action = ok_data[1]; 418 | } 419 | } 420 | 421 | 422 | FragmentManager fragmentManager = getSupportFragmentManager(); 423 | ImageCarouselDialog imageCarouselDialog = 424 | ImageCarouselDialog.newInstance(title, text, url, ok_label, ok_action); 425 | imageCarouselDialog.setRetainInstance(true); 426 | isPopupVisible = true; 427 | 428 | imageCarouselDialog.show(fragmentManager, "Dialog Fragment"); 429 | } 430 | 431 | public void setIsPopupVisible(boolean isPopupVisible) { 432 | this.isPopupVisible = isPopupVisible; 433 | } 434 | 435 | /** 436 | * Displays a popup to show youTubevideos 437 | * 438 | * @param youTubeID ID of the video extracted from the URL 439 | */ 440 | private void showYoutubePopup(String youTubeID, String... ok_data) { 441 | String ok_label = ""; 442 | String ok_action = ""; 443 | 444 | if (ok_data.length == 2) { 445 | if (ok_data[0] != null && ok_data[1] != null) { 446 | ok_label = ok_data[0]; 447 | ok_action = ok_data[1]; 448 | } 449 | } 450 | 451 | FragmentManager fragmentManager = getSupportFragmentManager(); 452 | YoutubePlayerDialog youtubePlayerDialog = 453 | YoutubePlayerDialog.newInstance(youTubeID, ok_label, ok_action); 454 | youtubePlayerDialog.setRetainInstance(true); 455 | isPopupVisible = true; 456 | youtubePlayerDialog.show(fragmentManager, "Dialog Fragment"); 457 | 458 | } 459 | 460 | /** 461 | * regex to get youtube video id from url 462 | * 463 | * @param ytUrl URL of the video 464 | * @return Youtube video ID 465 | */ 466 | 467 | public static String extractYTId(String ytUrl) { 468 | String vId = null; 469 | Pattern pattern = Pattern.compile(".*(?:youtu.be\\/|v\\/|u\\/\\w\\/|embed\\/|watch\\?v=)([^#\\&\\?]*).*"); 470 | Matcher matcher = pattern.matcher(ytUrl); 471 | if (matcher.matches()) { 472 | vId = matcher.group(1); 473 | } 474 | return vId; 475 | } 476 | 477 | private void sendNotification(String title, String text) { 478 | Context context = this; 479 | Intent activityIntent = new Intent(context.getApplicationContext(), MainActivity.class); 480 | PendingIntent pendingIntent = PendingIntent.getActivity( 481 | context.getApplicationContext(), 482 | 0, 483 | activityIntent, 484 | PendingIntent.FLAG_UPDATE_CURRENT 485 | ); 486 | 487 | NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context.getApplicationContext()) 488 | .setContentText(text) 489 | .setContentTitle(title) 490 | .setSmallIcon(R.drawable.icon) 491 | .setContentIntent(pendingIntent); 492 | NotificationManager notificationManager = (NotificationManager) 493 | context.getApplicationContext().getSystemService(Context.NOTIFICATION_SERVICE); 494 | notificationManager.notify(870, mBuilder.build()); 495 | } 496 | 497 | 498 | private void checkPermission() { 499 | if (ContextCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED || 500 | ContextCompat.checkSelfPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED 501 | ) { 502 | 503 | ActivityCompat.requestPermissions(this, 504 | new String[]{Manifest.permission.ACCESS_FINE_LOCATION, Manifest.permission.ACCESS_COARSE_LOCATION}, 505 | MSConstants.REQUEST_LOCATION_PERMISSION); 506 | } 507 | } 508 | 509 | @Override 510 | public void onRequestPermissionsResult(int requestCode, 511 | String permissions[], int[] grantResults) { 512 | switch (requestCode) { 513 | case MSConstants.REQUEST_LOCATION_PERMISSION: { 514 | // If request is cancelled, the result arrays are empty. 515 | if (grantResults.length > 0 516 | && grantResults[0] == PackageManager.PERMISSION_GRANTED) { 517 | bstac.startRangingBeacons(new MSErrorListener() { 518 | @Override 519 | public void onError(MSException msException) { 520 | Log.d(TAG, "Error while ranging beacons"); 521 | } 522 | }); 523 | } 524 | return; 525 | } 526 | } 527 | } 528 | 529 | } --------------------------------------------------------------------------------