From e72b74b840f2379f4f00dc696f7691627c8e5914 Mon Sep 17 00:00:00 2001 From: Joe Page Date: Tue, 26 Jan 2021 10:11:54 -0500 Subject: [PATCH 1/6] - merge DiscoveryCallback and DiscoveryListener so app can get notified when discovery is complete --- .idea/runConfigurations.xml | 10 ++ .idea/vcs.xml | 6 ++ .idea/workspace.xml | 101 +++--------------- .../be/teletask/onvif/DiscoveryThread.java | 6 +- .../be/teletask/onvif/OnvifDiscovery.java | 9 +- .../onvif/listeners/DiscoveryCallback.java | 19 ---- .../onvif/listeners/DiscoveryListener.java | 2 + 7 files changed, 44 insertions(+), 109 deletions(-) create mode 100644 .idea/runConfigurations.xml create mode 100644 .idea/vcs.xml delete mode 100644 lib/src/main/java/be/teletask/onvif/listeners/DiscoveryCallback.java diff --git a/.idea/runConfigurations.xml b/.idea/runConfigurations.xml new file mode 100644 index 0000000..797acea --- /dev/null +++ b/.idea/runConfigurations.xml @@ -0,0 +1,10 @@ + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..94a25f7 --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.idea/workspace.xml b/.idea/workspace.xml index 4736b15..78af79e 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -1,74 +1,35 @@ + + - - - - - - - - - - - - - + + - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + - - + + + + + + + + + + + + + + + + + @@ -43,7 +183,55 @@ - - \ No newline at end of file diff --git a/app/.gitignore b/app/.gitignore new file mode 100644 index 0000000..42afabf --- /dev/null +++ b/app/.gitignore @@ -0,0 +1 @@ +/build \ No newline at end of file diff --git a/app/build.gradle b/app/build.gradle new file mode 100644 index 0000000..18eda69 --- /dev/null +++ b/app/build.gradle @@ -0,0 +1,40 @@ +plugins { + id 'com.android.application' +} + +android { + compileSdkVersion 30 + buildToolsVersion "30.0.3" + + defaultConfig { + applicationId "com.test.app" + minSdkVersion 19 + targetSdkVersion 30 + versionCode 1 + versionName "1.0" + + testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" + } + + buildTypes { + release { + minifyEnabled false + proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' + } + } + compileOptions { + sourceCompatibility JavaVersion.VERSION_1_8 + targetCompatibility JavaVersion.VERSION_1_8 + } +} + +dependencies { + + implementation 'androidx.appcompat:appcompat:1.2.0' + implementation 'com.google.android.material:material:1.2.1' + implementation 'androidx.constraintlayout:constraintlayout:2.0.4' + implementation project(path: ':lib') + testImplementation 'junit:junit:4.+' + androidTestImplementation 'androidx.test.ext:junit:1.1.2' + androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0' +} \ No newline at end of file diff --git a/app/proguard-rules.pro b/app/proguard-rules.pro new file mode 100644 index 0000000..481bb43 --- /dev/null +++ b/app/proguard-rules.pro @@ -0,0 +1,21 @@ +# Add project specific ProGuard rules here. +# You can control the set of applied configuration files using the +# proguardFiles setting in build.gradle. +# +# For more details, see +# http://developer.android.com/guide/developing/tools/proguard.html + +# If your project uses WebView with JS, uncomment the following +# and specify the fully qualified class name to the JavaScript interface +# class: +#-keepclassmembers class fqcn.of.javascript.interface.for.webview { +# public *; +#} + +# Uncomment this to preserve the line number information for +# debugging stack traces. +#-keepattributes SourceFile,LineNumberTable + +# If you keep the line number information, uncomment this to +# hide the original source file name. +#-renamesourcefileattribute SourceFile \ No newline at end of file diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml new file mode 100644 index 0000000..6beae90 --- /dev/null +++ b/app/src/main/AndroidManifest.xml @@ -0,0 +1,24 @@ + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/java/com/test/app/MainActivity.java b/app/src/main/java/com/test/app/MainActivity.java new file mode 100644 index 0000000..3118e84 --- /dev/null +++ b/app/src/main/java/com/test/app/MainActivity.java @@ -0,0 +1,86 @@ +package com.test.app; + +import android.content.Context; +import android.net.wifi.WifiManager; +import android.os.Bundle; +import android.os.Handler; +import android.os.Looper; +import android.util.Log; +import android.widget.TextView; + +import java.util.List; + +import androidx.appcompat.app.AppCompatActivity; +import be.teletask.onvif.DiscoveryManager; +import be.teletask.onvif.DiscoveryMode; +import be.teletask.onvif.listeners.DiscoveryListener; +import be.teletask.onvif.models.Device; + +public class MainActivity extends AppCompatActivity { + private static final String TAG = MainActivity.class.getSimpleName(); + + TextView resultsText; + WifiManager.MulticastLock lock; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_main); + + findViewById(R.id.discoverButton).setOnClickListener(v -> { + startDiscovery(); + }); + + resultsText = findViewById(R.id.resultsText); + } + + private void startDiscovery() { + resultsText.setText(""); + lockMulticast(); + DiscoveryManager discoveryManager = new DiscoveryManager(); + discoveryManager.setDiscoveryTimeout(10000); + discoveryManager.discover(DiscoveryMode.ONVIF, new DiscoveryListener() { + @Override + public void onDiscoveryStarted() { + Log.d(TAG, "discovery started"); + updateText("discovery started"); + } + + @Override + public void onDevicesFound(List devices) { + for (Device device : devices) { + Log.d(TAG, "device found: " + device.getHostName()); + updateText("device found: " + device.getHostName()); + } + } + + @Override + public void onDiscoveryFinished() { + Log.d(TAG, "discovery finished"); + updateText("discovery finished"); + unlockMulticast(); + } + }); + } + + private void updateText(String text) { + new Handler(Looper.getMainLooper()).post(() -> { + String currentText = resultsText.getText().toString(); + resultsText.setText(currentText + "\n" + text); + }); + } + + private void lockMulticast() { + WifiManager wifi = (WifiManager) getApplicationContext().getSystemService(Context.WIFI_SERVICE); + if (wifi == null) return; + + lock = wifi.createMulticastLock("ONVIF"); + lock.acquire(); + } + + private void unlockMulticast() { + if (lock != null) { + lock.release(); + } + } +} \ No newline at end of file diff --git a/app/src/main/res/drawable-v24/ic_launcher_foreground.xml b/app/src/main/res/drawable-v24/ic_launcher_foreground.xml new file mode 100644 index 0000000..2b068d1 --- /dev/null +++ b/app/src/main/res/drawable-v24/ic_launcher_foreground.xml @@ -0,0 +1,30 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/drawable/ic_launcher_background.xml b/app/src/main/res/drawable/ic_launcher_background.xml new file mode 100644 index 0000000..07d5da9 --- /dev/null +++ b/app/src/main/res/drawable/ic_launcher_background.xml @@ -0,0 +1,170 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml new file mode 100644 index 0000000..433a022 --- /dev/null +++ b/app/src/main/res/layout/activity_main.xml @@ -0,0 +1,26 @@ + + + + + +