Skip to content

Commit 3382754

Browse files
author
davidgraeff
committed
Version 1.9a
* Fix many widget problems and a crash * Move all send code to DeviceSend * Sending is in one worker thread with a queue now * Delay work in onCreate-Activity for a smoother gui * Plugins working Problems: * PluginController does not update DrawerAdapter on a second Activity start (when PluginController object already exists)
1 parent c851e17 commit 3382754

Some content is hidden

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

52 files changed

+2050
-1022
lines changed

.idea/dictionaries/david.xml

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

.idea/gradle.xml

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

.idea/workspace.xml

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

Android-NetPowerctrl12.iml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<module external.linked.project.path="$MODULE_DIR$" external.root.project.path="$MODULE_DIR$" external.system.id="GRADLE" type="JAVA_MODULE" version="4">
2+
<module external.linked.project.path="$MODULE_DIR$" external.root.project.path="$MODULE_DIR$" external.system.id="GRADLE" external.system.module.group="" external.system.module.version="unspecified" type="JAVA_MODULE" version="4">
33
<component name="NewModuleRootManager" inherit-compiler-output="false">
44
<output url="file://$MODULE_DIR$/build/classes/main" />
55
<output-test url="file://$MODULE_DIR$/build/classes/test" />

app/app.iml

+20-26
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<module external.linked.project.path="$MODULE_DIR$" external.root.project.path="$MODULE_DIR$/.." external.system.id="GRADLE" type="JAVA_MODULE" version="4">
2+
<module external.linked.project.path="$MODULE_DIR$" external.root.project.path="$MODULE_DIR$/.." external.system.id="GRADLE" external.system.module.group="Android-NetPowerctrl12" external.system.module.version="unspecified" type="JAVA_MODULE" version="4">
33
<component name="FacetManager">
44
<facet type="android" name="Android">
55
<configuration>
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" />
6+
<option name="SELECTED_BUILD_VARIANT" value="release" />
7+
<option name="ASSEMBLE_TASK_NAME" value="assembleRelease" />
8+
<option name="COMPILE_JAVA_TASK_NAME" value="compileReleaseJava" />
9+
<option name="SOURCE_GEN_TASK_NAME" value="generateReleaseSources" />
1110
<option name="ALLOW_USER_CONFIGURATION" value="false" />
1211
<option name="MANIFEST_FILE_RELATIVE_PATH" value="/src/main/AndroidManifest.xml" />
1312
<option name="RES_FOLDER_RELATIVE_PATH" value="/src/main/res" />
@@ -22,26 +21,21 @@
2221
</facet>
2322
</component>
2423
<component name="NewModuleRootManager" inherit-compiler-output="false">
25-
<output url="file://$MODULE_DIR$/build/classes/debug" />
24+
<output url="file://$MODULE_DIR$/build/classes/release" />
2625
<exclude-output />
2726
<content url="file://$MODULE_DIR$">
28-
<sourceFolder url="file://$MODULE_DIR$/build/source/r/debug" isTestSource="false" generated="true" />
29-
<sourceFolder url="file://$MODULE_DIR$/build/source/aidl/debug" isTestSource="false" generated="true" />
30-
<sourceFolder url="file://$MODULE_DIR$/build/source/buildConfig/debug" isTestSource="false" generated="true" />
31-
<sourceFolder url="file://$MODULE_DIR$/build/source/rs/debug" isTestSource="false" generated="true" />
32-
<sourceFolder url="file://$MODULE_DIR$/build/res/rs/debug" type="java-resource" />
33-
<sourceFolder url="file://$MODULE_DIR$/build/source/r/test/debug" isTestSource="true" />
34-
<sourceFolder url="file://$MODULE_DIR$/build/source/aidl/test/debug" isTestSource="true" />
35-
<sourceFolder url="file://$MODULE_DIR$/build/source/buildConfig/test/debug" isTestSource="true" />
36-
<sourceFolder url="file://$MODULE_DIR$/build/source/rs/test/debug" isTestSource="true" />
37-
<sourceFolder url="file://$MODULE_DIR$/build/res/rs/test/debug" type="java-test-resource" />
38-
<sourceFolder url="file://$MODULE_DIR$/src/debug/aidl" isTestSource="false" />
39-
<sourceFolder url="file://$MODULE_DIR$/src/debug/assets" isTestSource="false" />
40-
<sourceFolder url="file://$MODULE_DIR$/src/debug/java" isTestSource="false" />
41-
<sourceFolder url="file://$MODULE_DIR$/src/debug/jni" isTestSource="false" />
42-
<sourceFolder url="file://$MODULE_DIR$/src/debug/rs" isTestSource="false" />
43-
<sourceFolder url="file://$MODULE_DIR$/src/debug/res" type="java-resource" />
44-
<sourceFolder url="file://$MODULE_DIR$/src/debug/resources" type="java-resource" />
27+
<sourceFolder url="file://$MODULE_DIR$/build/source/r/release" isTestSource="false" generated="true" />
28+
<sourceFolder url="file://$MODULE_DIR$/build/source/aidl/release" isTestSource="false" generated="true" />
29+
<sourceFolder url="file://$MODULE_DIR$/build/source/buildConfig/release" isTestSource="false" generated="true" />
30+
<sourceFolder url="file://$MODULE_DIR$/build/source/rs/release" isTestSource="false" generated="true" />
31+
<sourceFolder url="file://$MODULE_DIR$/build/res/rs/release" type="java-resource" />
32+
<sourceFolder url="file://$MODULE_DIR$/src/release/aidl" isTestSource="false" />
33+
<sourceFolder url="file://$MODULE_DIR$/src/release/assets" isTestSource="false" />
34+
<sourceFolder url="file://$MODULE_DIR$/src/release/java" isTestSource="false" />
35+
<sourceFolder url="file://$MODULE_DIR$/src/release/jni" isTestSource="false" />
36+
<sourceFolder url="file://$MODULE_DIR$/src/release/rs" isTestSource="false" />
37+
<sourceFolder url="file://$MODULE_DIR$/src/release/res" type="java-resource" />
38+
<sourceFolder url="file://$MODULE_DIR$/src/release/resources" type="java-resource" />
4539
<sourceFolder url="file://$MODULE_DIR$/src/main/aidl" isTestSource="false" />
4640
<sourceFolder url="file://$MODULE_DIR$/src/main/assets" isTestSource="false" />
4741
<sourceFolder url="file://$MODULE_DIR$/src/main/java" isTestSource="false" />
@@ -68,9 +62,9 @@
6862
<excludeFolder url="file://$MODULE_DIR$/build/symbols" />
6963
<excludeFolder url="file://$MODULE_DIR$/build/tmp" />
7064
</content>
71-
<orderEntry type="jdk" jdkName="Android API 16 Platform" jdkType="Android SDK" />
65+
<orderEntry type="jdk" jdkName="Android API 19 Platform" jdkType="Android SDK" />
7266
<orderEntry type="sourceFolder" forTests="false" />
73-
<orderEntry type="library" exported="" name="support-v4-19.0.0" level="project" />
67+
<orderEntry type="library" exported="" name="support-v4-19.0.1" level="project" />
7468
</component>
7569
</module>
7670

app/build.gradle

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
apply plugin: 'android'
22

33
android {
4-
compileSdkVersion 16
5-
buildToolsVersion '19.0.0'
4+
compileSdkVersion 19
5+
buildToolsVersion '19.0.1'
66

77
defaultConfig {
8-
minSdkVersion 16
9-
targetSdkVersion 17
8+
minSdkVersion 14
9+
targetSdkVersion 19
1010
}
1111

1212
buildTypes {

app/src/main/AndroidManifest.xml

+11-8
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
33
package="oly.netpowerctrl"
4-
android:versionCode="12"
5-
android:versionName="1.7">
4+
android:versionCode="15"
5+
android:versionName="1.9a">
66

7+
<!-- Api level 14: Android 4.0 15. Dezember 2011 -->
78
<!-- Api level 16: Android 4.1 27. Juni 2012 -->
8-
<uses-sdk
9-
android:minSdkVersion="16"
10-
android:targetSdkVersion="19" />
9+
<!--<uses-sdk
10+
android:minSdkVersion="14"
11+
android:targetSdkVersion="19" />-->
1112

1213
<uses-permission android:name="android.permission.INTERNET" />
1314
<uses-permission android:name="android.permission.NFC" />
@@ -31,7 +32,8 @@
3132
android:name="oly.netpowerctrl.main.NetpowerctrlActivity"
3233
android:label="@string/app_name"
3334
android:launchMode="singleTask"
34-
android:theme="@style/Theme.CustomLightTheme">
35+
android:configChanges="orientation"
36+
android:theme="@style/Theme.Transparent">
3537
<intent-filter>
3638
<action android:name="android.intent.action.MAIN" />
3739
<category android:name="android.intent.category.LAUNCHER" />
@@ -62,7 +64,7 @@
6264
android:label="@string/app_name"
6365
android:description="@string/app_name_shortcut_desc"
6466
android:icon="@drawable/widget"
65-
android:theme="@style/Theme.CustomLightTheme">
67+
android:theme="@style/Theme.Transparent">
6668
<intent-filter>
6769
<action android:name="android.appwidget.action.APPWIDGET_CONFIGURE" />
6870
</intent-filter>
@@ -72,7 +74,8 @@
7274
android:icon="@drawable/netpowerctrl"
7375
android:label="@string/app_name_shortcut"
7476
android:description="@string/app_name_shortcut_desc"
75-
android:theme="@style/Theme.CustomLightTheme"
77+
android:configChanges="orientation"
78+
android:theme="@style/Theme.Transparent"
7679
android:name="oly.netpowerctrl.shortcut.ShortcutCreatorActivity">
7780
<intent-filter>
7881
<action android:name="android.intent.action.CREATE_SHORTCUT" />
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package oly.netpowerctrl.plugins;
2+
3+
import oly.netpowerctrl.plugins.INetPwrCtrlPluginResult;
4+
5+
interface INetPwrCtrlPlugin {
6+
void requestValues(INetPwrCtrlPluginResult cb);
7+
void updateIntValue(int id, int value, INetPwrCtrlPluginResult cb);
8+
void updateBooleanValue(int id, boolean value, INetPwrCtrlPluginResult cb);
9+
void executeAction(int id, INetPwrCtrlPluginResult cb);
10+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package oly.netpowerctrl.plugins;
2+
3+
interface INetPwrCtrlPluginResult {
4+
void intValue(int id, String name, int min, int max, int value);
5+
void booleanValue(int id, String name, boolean value);
6+
void action(int id, String name);
7+
void header(int id, String name);
8+
void finished();
9+
}

app/src/main/java/oly/netpowerctrl/anelservice/DeviceQuery.java

+7-73
Original file line numberDiff line numberDiff line change
@@ -3,23 +3,13 @@
33
import android.content.Context;
44
import android.os.Handler;
55

6-
import java.net.DatagramPacket;
7-
import java.net.DatagramSocket;
8-
import java.net.InetAddress;
9-
import java.net.InterfaceAddress;
10-
import java.net.NetworkInterface;
11-
import java.net.SocketException;
12-
import java.nio.ByteBuffer;
136
import java.util.ArrayList;
147
import java.util.Collection;
15-
import java.util.Enumeration;
168
import java.util.Iterator;
179

18-
import oly.netpowerctrl.R;
1910
import oly.netpowerctrl.datastructure.DeviceCommand;
2011
import oly.netpowerctrl.datastructure.DeviceInfo;
2112
import oly.netpowerctrl.main.NetpowerctrlApplication;
22-
import oly.netpowerctrl.utils.ShowToast;
2313

2414
/**
2515
* Use the static sendQuery and sendBroadcastQuery methods to issue a query to one
@@ -51,7 +41,7 @@ public DeviceQuery(Context context, DeviceUpdateStateOrTimeout target, DeviceInf
5141

5242

5343
// Send out broadcast
54-
if (!sendQuery(context, device_to_observe.HostName, device_to_observe.SendPort, rangeCheck)) {
44+
if (!DeviceSend.instance().sendQuery(context, device_to_observe.HostName, device_to_observe.SendPort, rangeCheck)) {
5545
// Device not in range, immediately timeout
5646
timeoutHandler.postDelayed(timeoutRunnable, 0);
5747
} else
@@ -73,14 +63,14 @@ public DeviceQuery(Context context, DeviceUpdateStateOrTimeout target,
7363
sendBroadcastQuery(context);
7464
else
7565
for (DeviceInfo di : devices_to_observe)
76-
sendQuery(context, di.HostName, di.SendPort, rangeCheck);
66+
DeviceSend.instance().sendQuery(context, di.HostName, di.SendPort, rangeCheck);
7767
}
7868

7969
/**
8070
* Return true if all devices responded and this DeviceQuery object
8171
* have to be removed.
8272
*
83-
* @param received_data
73+
* @param received_data The DeviceInfo object all observes should be notified of.
8474
*/
8575
public boolean notifyObservers(DeviceInfo received_data) {
8676
Iterator<DeviceInfo> it = devices_to_observe.iterator();
@@ -103,71 +93,15 @@ public boolean notifyObservers(DeviceInfo received_data) {
10393
* Used to be used only from the DeviceSend class for requesting an update
10494
* after a command has been send
10595
*
106-
* @param context
107-
* @param device_command
96+
* @param context Context
97+
* @param device_command A DeviceCommand object containing destination IP, Port and commands
10898
*/
10999
static void sendQuery(final Context context, DeviceCommand device_command) {
110-
sendQuery(context, device_command.dest.getHostAddress(), device_command.port, false);
111-
}
112-
113-
private static boolean sendQuery(final Context context, final String hostname, final int port, boolean rangeCheck) {
114-
if (rangeCheck) {
115-
try {
116-
if (!isIPinNetworkAddressPool(InetAddress.getByName(hostname))) {
117-
ShowToast.FromOtherThread(context, context.getResources().getString(R.string.error_not_in_range) + ": " + hostname);
118-
return false;
119-
}
120-
} catch (final Exception e) {
121-
ShowToast.FromOtherThread(context, context.getResources().getString(R.string.error_not_in_range) + ": " + hostname);
122-
return false;
123-
}
124-
}
125-
new Thread(new Runnable() {
126-
public void run() {
127-
try {
128-
String messageStr = "wer da?\r\n";
129-
DatagramSocket s = new DatagramSocket();
130-
s.setBroadcast(true);
131-
InetAddress host = InetAddress.getByName(hostname);
132-
int msg_length = messageStr.length();
133-
byte[] message = messageStr.getBytes();
134-
DatagramPacket p = new DatagramPacket(message, msg_length, host, port);
135-
s.send(p);
136-
s.close();
137-
} catch (final Exception e) {
138-
ShowToast.FromOtherThread(context, context.getResources().getString(R.string.error_sending_inquiry) + ": " + e.getMessage());
139-
}
140-
}
141-
}).start();
142-
return true;
100+
DeviceSend.instance().sendQuery(context, device_command.dest.getHostAddress(), device_command.port, false);
143101
}
144102

145103
private static void sendBroadcastQuery(final Context context) {
146104
for (int port : NetpowerctrlApplication.instance.getAllSendPorts())
147-
sendQuery(context, "255.255.255.255", port, false);
148-
}
149-
150-
static private boolean isIPinNetworkAddressPool(InetAddress ip) throws SocketException {
151-
byte[] ipAddressBytes = ip.getAddress();
152-
// Iterate all NICs (network interface cards)...
153-
for (Enumeration networkInterfaceEnumerator = NetworkInterface.getNetworkInterfaces(); networkInterfaceEnumerator.hasMoreElements(); ) {
154-
NetworkInterface networkInterface = (NetworkInterface) networkInterfaceEnumerator.nextElement();
155-
for (InterfaceAddress interfaceAddress : networkInterface.getInterfaceAddresses()) {
156-
InetAddress interfaceIPAddress = interfaceAddress.getAddress();
157-
byte[] interfaceIPBytes = interfaceIPAddress.getAddress();
158-
if (ipAddressBytes.length != interfaceIPBytes.length)
159-
continue; // different ip versions
160-
161-
byte[] subNetMaskBytes = ByteBuffer.allocate(4).putInt(interfaceAddress.getNetworkPrefixLength()).array();
162-
// check each byte of both addresses while applying the subNet mask
163-
for (int i = 0; i < interfaceIPBytes.length; ++i) {
164-
if ((ipAddressBytes[i] & subNetMaskBytes[i]) !=
165-
(interfaceIPBytes[i] & subNetMaskBytes[i]))
166-
continue; // byte not identical, the ip is not for this network interface
167-
}
168-
return true;
169-
}
170-
}
171-
return false;
105+
DeviceSend.instance().sendQuery(context, "255.255.255.255", port, false);
172106
}
173107
}

0 commit comments

Comments
 (0)