Skip to content

Commit 2857db3

Browse files
author
David Gräff
committed
refactor observers. bug fixes
1 parent 4f8d412 commit 2857db3

File tree

101 files changed

+2095
-2299
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

101 files changed

+2095
-2299
lines changed

.idea/misc.xml

+18
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/workspace.xml

+633-1,210
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

app/app.iml

+22-40
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@
33
<component name="FacetManager">
44
<facet type="android" name="Android">
55
<configuration>
6-
<option name="SELECTED_BUILD_VARIANT" value="vanillaDebug" />
7-
<option name="ASSEMBLE_TASK_NAME" value="assembleVanillaDebug" />
8-
<option name="COMPILE_JAVA_TASK_NAME" value="compileVanillaDebugJava" />
9-
<option name="ASSEMBLE_TEST_TASK_NAME" value="assembleVanillaDebugTest" />
10-
<option name="SOURCE_GEN_TASK_NAME" value="generateVanillaDebugSources" />
6+
<option name="SELECTED_BUILD_VARIANT" value="debug" />
7+
<option name="ASSEMBLE_TASK_NAME" value="assembleDebug" />
8+
<option name="COMPILE_JAVA_TASK_NAME" value="compileDebugJava" />
9+
<option name="ASSEMBLE_TEST_TASK_NAME" value="assembleDebugTest" />
10+
<option name="SOURCE_GEN_TASK_NAME" value="generateDebugSources" />
1111
<option name="ALLOW_USER_CONFIGURATION" value="false" />
1212
<option name="MANIFEST_FILE_RELATIVE_PATH" value="/src/main/AndroidManifest.xml" />
1313
<option name="RES_FOLDER_RELATIVE_PATH" value="/src/main/res" />
@@ -22,58 +22,38 @@
2222
</facet>
2323
</component>
2424
<component name="NewModuleRootManager" inherit-compiler-output="false">
25-
<output url="file://$MODULE_DIR$/build/intermediates/classes/vanilla/debug" />
25+
<output url="file://$MODULE_DIR$/build/intermediates/classes/debug" />
2626
<exclude-output />
2727
<content url="file://$MODULE_DIR$">
28-
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/r/vanilla/debug" isTestSource="false" generated="true" />
29-
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/aidl/vanilla/debug" isTestSource="false" generated="true" />
30-
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/buildConfig/vanilla/debug" isTestSource="false" generated="true" />
31-
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/rs/vanilla/debug" isTestSource="false" generated="true" />
32-
<sourceFolder url="file://$MODULE_DIR$/build/generated/res/rs/vanilla/debug" type="java-resource" />
33-
<sourceFolder url="file://$MODULE_DIR$/src/vanillaDebug/res" type="java-resource" />
34-
<sourceFolder url="file://$MODULE_DIR$/src/vanillaDebug/resources" type="java-resource" />
35-
<sourceFolder url="file://$MODULE_DIR$/src/vanillaDebug/aidl" isTestSource="false" />
36-
<sourceFolder url="file://$MODULE_DIR$/src/vanillaDebug/assets" isTestSource="false" />
37-
<sourceFolder url="file://$MODULE_DIR$/src/vanillaDebug/java" isTestSource="false" />
38-
<sourceFolder url="file://$MODULE_DIR$/src/vanillaDebug/jni" isTestSource="false" />
39-
<sourceFolder url="file://$MODULE_DIR$/src/vanillaDebug/rs" isTestSource="false" />
40-
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/r/test/vanilla/debug" isTestSource="true" generated="true" />
41-
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/aidl/test/vanilla/debug" isTestSource="true" generated="true" />
42-
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/buildConfig/test/vanilla/debug" isTestSource="true" generated="true" />
43-
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/rs/test/vanilla/debug" isTestSource="true" generated="true" />
44-
<sourceFolder url="file://$MODULE_DIR$/build/generated/res/rs/test/vanilla/debug" type="java-test-resource" />
45-
<sourceFolder url="file://$MODULE_DIR$/src/vanilla/res" type="java-resource" />
46-
<sourceFolder url="file://$MODULE_DIR$/src/vanilla/resources" type="java-resource" />
47-
<sourceFolder url="file://$MODULE_DIR$/src/vanilla/aidl" isTestSource="false" />
48-
<sourceFolder url="file://$MODULE_DIR$/src/vanilla/assets" isTestSource="false" />
49-
<sourceFolder url="file://$MODULE_DIR$/src/vanilla/java" isTestSource="false" />
50-
<sourceFolder url="file://$MODULE_DIR$/src/vanilla/jni" isTestSource="false" />
51-
<sourceFolder url="file://$MODULE_DIR$/src/vanilla/rs" isTestSource="false" />
52-
<sourceFolder url="file://$MODULE_DIR$/src/androidTestVanilla/res" type="java-test-resource" />
53-
<sourceFolder url="file://$MODULE_DIR$/src/androidTestVanilla/resources" type="java-test-resource" />
54-
<sourceFolder url="file://$MODULE_DIR$/src/androidTestVanilla/aidl" isTestSource="true" />
55-
<sourceFolder url="file://$MODULE_DIR$/src/androidTestVanilla/assets" isTestSource="true" />
56-
<sourceFolder url="file://$MODULE_DIR$/src/androidTestVanilla/java" isTestSource="true" />
57-
<sourceFolder url="file://$MODULE_DIR$/src/androidTestVanilla/jni" isTestSource="true" />
58-
<sourceFolder url="file://$MODULE_DIR$/src/androidTestVanilla/rs" isTestSource="true" />
28+
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/r/debug" isTestSource="false" generated="true" />
29+
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/aidl/debug" isTestSource="false" generated="true" />
30+
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/buildConfig/debug" isTestSource="false" generated="true" />
31+
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/rs/debug" isTestSource="false" generated="true" />
32+
<sourceFolder url="file://$MODULE_DIR$/build/generated/res/rs/debug" type="java-resource" />
33+
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/r/test/debug" isTestSource="true" generated="true" />
34+
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/aidl/test/debug" isTestSource="true" generated="true" />
35+
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/buildConfig/test/debug" isTestSource="true" generated="true" />
36+
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/rs/test/debug" isTestSource="true" generated="true" />
37+
<sourceFolder url="file://$MODULE_DIR$/build/generated/res/rs/test/debug" type="java-test-resource" />
5938
<sourceFolder url="file://$MODULE_DIR$/src/debug/res" type="java-resource" />
6039
<sourceFolder url="file://$MODULE_DIR$/src/debug/resources" type="java-resource" />
40+
<sourceFolder url="file://$MODULE_DIR$/src/debug/assets" type="java-resource" />
6141
<sourceFolder url="file://$MODULE_DIR$/src/debug/aidl" isTestSource="false" />
62-
<sourceFolder url="file://$MODULE_DIR$/src/debug/assets" isTestSource="false" />
6342
<sourceFolder url="file://$MODULE_DIR$/src/debug/java" isTestSource="false" />
6443
<sourceFolder url="file://$MODULE_DIR$/src/debug/jni" isTestSource="false" />
6544
<sourceFolder url="file://$MODULE_DIR$/src/debug/rs" isTestSource="false" />
6645
<sourceFolder url="file://$MODULE_DIR$/src/main/res" type="java-resource" />
6746
<sourceFolder url="file://$MODULE_DIR$/src/main/resources" type="java-resource" />
47+
<sourceFolder url="file://$MODULE_DIR$/src/main/assets" type="java-resource" />
6848
<sourceFolder url="file://$MODULE_DIR$/src/main/aidl" isTestSource="false" />
69-
<sourceFolder url="file://$MODULE_DIR$/src/main/assets" isTestSource="false" />
7049
<sourceFolder url="file://$MODULE_DIR$/src/main/java" isTestSource="false" />
50+
<sourceFolder url="file://$MODULE_DIR$/src/tests/java" isTestSource="false" />
7151
<sourceFolder url="file://$MODULE_DIR$/src/main/jni" isTestSource="false" />
7252
<sourceFolder url="file://$MODULE_DIR$/src/main/rs" isTestSource="false" />
7353
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/res" type="java-test-resource" />
7454
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/resources" type="java-test-resource" />
55+
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/assets" type="java-test-resource" />
7556
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/aidl" isTestSource="true" />
76-
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/assets" isTestSource="true" />
7757
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/java" isTestSource="true" />
7858
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/jni" isTestSource="true" />
7959
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/rs" isTestSource="true" />
@@ -101,11 +81,13 @@
10181
<orderEntry type="jdk" jdkName="Android API 20 Platform" jdkType="Android SDK" />
10282
<orderEntry type="sourceFolder" forTests="false" />
10383
<orderEntry type="library" exported="" name="support-v13-20.0.0" level="project" />
84+
<orderEntry type="library" exported="" scope="TEST" name="junit-4.12-beta-1" level="project" />
10485
<orderEntry type="library" exported="" name="library-0.9" level="project" />
10586
<orderEntry type="library" exported="" name="support-annotations-20.0.0" level="project" />
10687
<orderEntry type="library" exported="" name="support-v4-20.0.0" level="project" />
10788
<orderEntry type="library" exported="" name="play-services-5.0.89" level="project" />
10889
<orderEntry type="library" exported="" name="acra-4.5.0" level="project" />
90+
<orderEntry type="library" exported="" scope="TEST" name="hamcrest-core-1.3" level="project" />
10991
<orderEntry type="library" exported="" name="library-1.5.1" level="project" />
11092
</component>
11193
</module>

app/build.gradle

+12-12
Original file line numberDiff line numberDiff line change
@@ -4,22 +4,20 @@ android {
44
compileSdkVersion 20
55
buildToolsVersion '20'
66

7-
productFlavors {
8-
//noinspection GroovyMissingReturnStatement
9-
vanilla {
10-
11-
}
12-
13-
old23 {
14-
minSdkVersion 8
15-
}
16-
}
7+
// productFlavors {
8+
// //noinspection GroovyMissingReturnStatement
9+
// vanilla {
10+
//
11+
// }
12+
// }
1713

1814
defaultConfig {
1915
minSdkVersion 14
2016
targetSdkVersion 20
21-
versionCode 81
22-
versionName "5.7"
17+
versionCode 83
18+
versionName "5.7.2"
19+
applicationId "oly.netpowerctrl"
20+
testApplicationId "oly.netpowerctrl.tests"
2321
}
2422

2523
lintOptions {
@@ -44,6 +42,7 @@ android {
4442
runProguard false
4543
}
4644
}
45+
sourceSets { main { java.srcDirs = ['src/main/java', 'src/tests/java'] } }
4746
}
4847

4948
dependencies {
@@ -53,4 +52,5 @@ dependencies {
5352
compile 'ch.acra:acra:4.5.0'
5453
compile 'com.android.support:support-v13:20.0.0'
5554
compile 'com.github.chrisbanes.actionbarpulltorefresh:library:0.9'
55+
androidTestCompile 'junit:junit:4.+'
5656
}

app/src/main/AndroidManifest.xml

-6
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,6 @@
2424

2525
<uses-sdk tools:node="replace" />
2626

27-
<!--<permission-->
28-
<!--android:name="oly.netpowerctrl.plugins"-->
29-
<!--android:label="@string/app_name"-->
30-
<!--android:description="@string/app_name"-->
31-
<!--android:protectionLevel="signature" />-->
32-
3327
<application
3428
android:name=".application_state.NetpowerctrlApplication"
3529
android:allowBackup="true"

app/src/main/java/oly/netpowerctrl/anel/AnelBroadcastSendJob.java

+16-9
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package oly.netpowerctrl.anel;
22

3+
import android.content.Context;
34
import android.util.Log;
45

56
import java.net.DatagramPacket;
@@ -13,7 +14,9 @@
1314

1415
import oly.netpowerctrl.R;
1516
import oly.netpowerctrl.application_state.NetpowerctrlApplication;
17+
import oly.netpowerctrl.application_state.NetpowerctrlService;
1618
import oly.netpowerctrl.application_state.PluginInterface;
19+
import oly.netpowerctrl.application_state.RuntimeDataController;
1720
import oly.netpowerctrl.devices.Device;
1821
import oly.netpowerctrl.devices.DeviceConnection;
1922
import oly.netpowerctrl.network.UDPSending;
@@ -22,26 +25,30 @@
2225
* A DeviceSend.Job that provide broadcast sending to anel devices.
2326
*/
2427
public class AnelBroadcastSendJob implements UDPSending.Job {
25-
private void sendPacket(UDPSending udpSending, InetAddress ip, int SendPort, byte[] message) {
28+
private void sendPacket(Context context, UDPSending udpSending, InetAddress ip, int SendPort, byte[] message) {
2629
try {
2730
udpSending.datagramSocket.setBroadcast(true);
2831
udpSending.datagramSocket.send(new DatagramPacket(message, message.length, ip, SendPort));
2932
//Log.w("AnelBroadcastSendJob",ip.getHostAddress());
3033
} catch (final SocketException e) {
3134
if (e.getMessage().contains("ENETUNREACH"))
32-
UDPSending.onError(UDPSending.NETWORK_UNREACHABLE, ip.getHostAddress(), SendPort, e);
35+
UDPSending.onError(context, UDPSending.NETWORK_UNREACHABLE, ip.getHostAddress(), SendPort, e);
3336
else {
34-
UDPSending.onError(UDPSending.INQUERY_BROADCAST_REQUEST, ip.getHostAddress(), SendPort, e);
37+
UDPSending.onError(context, UDPSending.INQUERY_BROADCAST_REQUEST, ip.getHostAddress(), SendPort, e);
3538
}
3639
} catch (final Exception e) {
3740
e.printStackTrace();
38-
UDPSending.onError(UDPSending.INQUERY_BROADCAST_REQUEST, ip.getHostAddress(), SendPort, e);
41+
UDPSending.onError(context, UDPSending.INQUERY_BROADCAST_REQUEST, ip.getHostAddress(), SendPort, e);
3942
}
4043
}
4144

4245
@Override
4346
public void process(UDPSending UDPSending) {
44-
Set<Integer> ports = NetpowerctrlApplication.getDataController().getAllSendPorts();
47+
Context context = NetpowerctrlService.getService();
48+
if (context == null)
49+
return;
50+
51+
Set<Integer> ports = RuntimeDataController.getDataController().getAllSendPorts();
4552
boolean foundBroadcastAddresses = false;
4653

4754
Enumeration list;
@@ -60,7 +67,7 @@ public void process(UDPSending UDPSending) {
6067
InetAddress broadcast = address.getBroadcast();
6168
if (broadcast == null) continue;
6269
for (int port : ports)
63-
sendPacket(UDPSending, broadcast, port, "wer da?\r\n".getBytes());
70+
sendPacket(context, UDPSending, broadcast, port, "wer da?\r\n".getBytes());
6471
foundBroadcastAddresses = true;
6572
}
6673
}
@@ -73,17 +80,17 @@ public void process(UDPSending UDPSending) {
7380
if (!foundBroadcastAddresses) {
7481
// Broadcast not allowed on this network. Show hint to user
7582
// Toast.makeText(NetpowerctrlApplication.instance,
76-
// NetpowerctrlApplication.instance.getString(R.string.devices_no_new_on_network),
83+
// NetpowerctrlApplication.getAppString(R.string.devices_no_new_on_network),
7784
// Toast.LENGTH_SHORT).show();
7885

7986
// Query all existing anel devices directly
8087

81-
List<Device> devices = NetpowerctrlApplication.getDataController().deviceCollection.devices;
88+
List<Device> devices = RuntimeDataController.getDataController().deviceCollection.devices;
8289
for (Device device : devices) {
8390
if (device.pluginID.equals(AnelPlugin.PLUGIN_ID)) {
8491
PluginInterface i = device.getPluginInterface();
8592
if (i == null) {
86-
device.setNotReachableAll(NetpowerctrlApplication.instance.getString(R.string.error_plugin_not_installed));
93+
device.setNotReachableAll(NetpowerctrlApplication.getAppString(R.string.error_plugin_not_installed));
8794
continue;
8895
}
8996
for (DeviceConnection ci : device.DeviceConnections) {

app/src/main/java/oly/netpowerctrl/anel/AnelCreateDevice.java

+17-10
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package oly.netpowerctrl.anel;
22

3+
import android.content.Context;
34
import android.os.Handler;
45

56
import java.util.List;
@@ -9,20 +10,26 @@
910
import oly.netpowerctrl.devices.Device;
1011
import oly.netpowerctrl.network.DeviceObserverResult;
1112
import oly.netpowerctrl.network.DeviceQuery;
12-
import oly.netpowerctrl.network.DeviceUpdate;
13+
import oly.netpowerctrl.network.onConfiguredDeviceUpdate;
1314

1415
/**
1516
* Created by david on 20.08.14.
1617
*/
17-
public class AnelCreateDevice implements DeviceObserverResult, DeviceUpdate {
18+
public class AnelCreateDevice implements DeviceObserverResult, onConfiguredDeviceUpdate {
1819
public final Device device;
1920
public AnelCreateDeviceResult listener = null;
2021
TestStates test_state = TestStates.TEST_INIT;
2122
private DeviceQuery deviceQuery;
2223

2324
public AnelCreateDevice(Device di) {
25+
assert di != null;
26+
device = di;
27+
}
28+
29+
public AnelCreateDevice(String defaultDeviceName, Device di) {
2430
if (di == null) {
25-
device = Device.createNewDevice(AnelUDPDeviceDiscoveryThread.anelPlugin.getPluginID());
31+
device = new Device(AnelUDPDeviceDiscoveryThread.anelPlugin.getPluginID());
32+
device.DeviceName = defaultDeviceName;
2633
device.setPluginInterface(AnelUDPDeviceDiscoveryThread.anelPlugin);
2734
// Default values for user and password
2835
device.UserName = "admin";
@@ -31,10 +38,10 @@ public AnelCreateDevice(Device di) {
3138
device = di;
3239
}
3340

34-
public boolean wakeupPlugin() {
41+
public boolean wakeupPlugin(Context context) {
3542
PluginInterface pluginInterface = device.getPluginInterface();
3643
if (pluginInterface != null) {
37-
pluginInterface.enterFullNetworkState(device);
44+
pluginInterface.enterFullNetworkState(context, device);
3845
return true;
3946
} else {
4047
return false;
@@ -43,11 +50,11 @@ public boolean wakeupPlugin() {
4350

4451
@Override
4552
public void onDeviceUpdated(Device di) {
46-
onDeviceUpdated(di, false);
53+
onConfiguredDeviceUpdated(di, false);
4754
}
4855

4956
@Override
50-
public void onDeviceUpdated(Device updated_device, boolean willBeRemoved) {
57+
public void onConfiguredDeviceUpdated(Device updated_device, boolean willBeRemoved) {
5158
if (!updated_device.equalsByUniqueID(device))
5259
return;
5360

@@ -110,11 +117,11 @@ public void onObserverJobFinished(List<Device> timeout_devices) {
110117
}
111118

112119
@SuppressWarnings("BooleanMethodIsAlwaysInverted")
113-
public boolean startTest() {
120+
public boolean startTest(Context context) {
114121
test_state = TestStates.TEST_REACHABLE;
115122

116-
if (wakeupPlugin())
117-
deviceQuery = new DeviceQuery(this, device);
123+
if (wakeupPlugin(context))
124+
deviceQuery = new DeviceQuery(context, this, device);
118125
else
119126
return false;
120127
return true;

0 commit comments

Comments
 (0)