Skip to content

Commit f040f68

Browse files
author
David Gräff
committed
Add screenshots, Change plugin interface, remove help text, improve feedback/nfc sections, add groups, refactored all anel stuff into anel package, improve dynamic gridview auto columns
1 parent 11792ef commit f040f68

File tree

92 files changed

+2595
-1426
lines changed

Some content is hidden

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

92 files changed

+2595
-1426
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ support libraries (v13) and need at least android 4.0 (sdk version 14, released
4747

4848
### Authors
4949
* david.graeff(at)web_de
50+
* Some icons from http://www.clker.com/
5051

5152
### License
5253
Dual licensed: GPLv2+GPLv3

app/src/main/AndroidManifest.xml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
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="26"
5-
android:versionName="2.5">
4+
android:versionCode="30"
5+
android:versionName="2.6b">
66

7-
<!-- Api level 14: Android 4.0 15. Dezember 2011 -->
7+
<!-- Api level 14: Android 4.0 15. Dezember 2011 -->
88
<!-- Api level 16: Android 4.1 27. Juni 2012 -->
99
<!--<uses-sdk
1010
android:minSdkVersion="14"

app/src/main/aidl/oly/netpowerctrl/plugins/INetPwrCtrlPlugin.aidl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import oly.netpowerctrl.plugins.INetPwrCtrlPluginResult;
44

55
interface INetPwrCtrlPlugin {
66
void init(INetPwrCtrlPluginResult cb);
7+
void finish();
78
void requestValues();
89
void updateIntValue(int id, int value);
910
void updateBooleanValue(int id, boolean value);
Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
package oly.netpowerctrl.plugins;
22

33
interface INetPwrCtrlPluginResult {
4-
void ready();
4+
void pluginState(int state);
55
void intValue(int id, String name, int min, int max, int value);
66
void booleanValue(int id, String name, boolean value);
77
void action(int id, String name);
8-
void header(int id, String name);
8+
void header(String name);
99
void finished();
10+
1011
}

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,8 @@ public void process(DeviceSend deviceSend) {
7676
// Query all existing devices directly
7777
ArrayList<DeviceInfo> devices = NetpowerctrlApplication.getDataController().configuredDevices;
7878
for (DeviceInfo di : devices) {
79-
deviceSend.addSendJob(di, "wer da?\r\n".getBytes(), DeviceSend.INQUERY_REQUEST, false);
79+
if (di.deviceType == DeviceInfo.DeviceType.AnelDevice)
80+
AnelExecutor.sendQuery(di);
8081
}
8182
}
8283
}

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,11 @@ static DeviceInfo createReceivedAnelDevice(String DeviceName, String HostName,
6464
DeviceInfo di = DeviceInfo.createNewDevice(DeviceInfo.DeviceType.AnelDevice);
6565
di.DeviceName = DeviceName;
6666
di.HostName = HostName;
67-
di.MacAddress = MacAddress;
67+
di.UniqueDeviceID = MacAddress;
6868
di.ReceivePort = receive_port;
69+
// Default values for user and password
70+
di.UserName = "admin";
71+
di.Password = "anel";
6972

7073
di.SendPort = SharedPrefs.getDefaultSendPort();
7174
di.reachable = true;

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

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
import oly.netpowerctrl.network.DeviceSend;
1212

1313
/**
14-
* For executing a command on a DevicePort or commands for multiple DevicePorts (bulk).
14+
* For executing a name on a DevicePort or commands for multiple DevicePorts (bulk).
1515
* This is a specialized class for Anel devices.
1616
*/
1717
final public class AnelExecutor {
@@ -127,18 +127,19 @@ public static void execute(DeviceInfo di, List<Executor.PortAndCommand> command_
127127
// Thirst step: Send data
128128
String access = di.UserName + di.Password;
129129
byte[] data = new byte[3 + access.length()];
130-
data[0] = 'S';
131-
data[1] = 'w';
132-
data[2] = data_outlet;
133130
System.arraycopy(access.getBytes(), 0, data, 3, access.length());
134131

135132
if (containsOutlets) {
136-
DeviceSend.instance().addSendJob(di, data, DeviceSend.INQUERY_REQUEST, false);
137-
} else if (containsIO) {
133+
data[0] = 'S';
134+
data[1] = 'w';
135+
data[2] = data_outlet;
136+
DeviceSend.instance().addJob(new DeviceSend.SendJob(di, data, DeviceSend.INQUERY_REQUEST, true));
137+
}
138+
if (containsIO) {
138139
data[0] = 'I';
139140
data[1] = 'O';
140141
data[2] = data_io;
141-
DeviceSend.instance().addSendJob(di, data, DeviceSend.INQUERY_REQUEST, false);
142+
DeviceSend.instance().addJob(new DeviceSend.SendJob(di, data, DeviceSend.INQUERY_REQUEST, true));
142143
}
143144
}
144145

@@ -168,6 +169,15 @@ else if (command == DevicePort.TOGGLE)
168169
data = String.format(Locale.US, "%s%d%s%s", bValue ? "Sw_on" : "Sw_off",
169170
port.id, port.device.UserName, port.device.Password).getBytes();
170171
}
171-
DeviceSend.instance().addSendJob(port.device, data, DeviceSend.INQUERY_REQUEST, false);
172+
173+
DeviceSend.instance().addJob(new DeviceSend.SendJob(port.device, data, DeviceSend.INQUERY_REQUEST, true));
174+
}
175+
176+
public static void sendBroadcastQuery() {
177+
DeviceSend.instance().addJob(new AnelBroadcastSendJob());
178+
}
179+
180+
public static void sendQuery(DeviceInfo di) {
181+
DeviceSend.instance().addJob(new DeviceSend.SendJob(di, "wer da?\r\n".getBytes(), DeviceSend.INQUERY_REQUEST, true));
172182
}
173183
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ public Dialog onCreateDialog(Bundle savedInstanceState) {
105105
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
106106
builder.setTitle(R.string.configure_device);
107107
builder.setView(view);
108-
builder.setPositiveButton(R.string.device_save, new DialogInterface.OnClickListener() {
108+
builder.setPositiveButton(R.string.save, new DialogInterface.OnClickListener() {
109109
@Override
110110
public void onClick(DialogInterface dialogInterface, int i) {
111111
}
@@ -202,7 +202,7 @@ public void onDeviceUpdated(DeviceInfo di) {
202202

203203
if (test_state == TestStates.TEST_REACHABLE) {
204204
// Update stored device with received values
205-
device.MacAddress = di.MacAddress;
205+
device.UniqueDeviceID = di.UniqueDeviceID;
206206
device.DeviceName = di.DeviceName;
207207
device.copyFreshValues(di);
208208
// Test user+password by setting a device port.

app/src/main/java/oly/netpowerctrl/application_state/NetpowerctrlApplication.java

Lines changed: 59 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
public class NetpowerctrlApplication extends Application {
4242
public static NetpowerctrlApplication instance;
4343

44-
private RuntimeDataController dataController = new RuntimeDataController();
44+
private RuntimeDataController dataController = null;
4545
private int mDiscoverServiceRefCount = 0;
4646
private NetpowerctrlService mDiscoverService;
4747
private boolean mWaitForService;
@@ -78,12 +78,7 @@ public void onCreate() {
7878
// The following line triggers the initialization of ACRA
7979
ACRA.init(this);
8080
instance = this;
81-
dataController.reloadConfiguredDevices();
82-
83-
// Plugins
84-
if (SharedPrefs.getLoadExtensions())
85-
pluginController = new PluginController();
86-
81+
dataController = new RuntimeDataController();
8782

8883
// Start listen service and listener for wifi changes
8984
mWaitForService = true;
@@ -98,8 +93,37 @@ public void run() {
9893
}, 180);
9994
}
10095

96+
private Handler stopServiceHandler = new Handler();
97+
private Runnable stopRunnable = new Runnable() {
98+
@Override
99+
public void run() {
100+
try {
101+
mDiscoverService = null;
102+
mWaitForService = false;
103+
unbindService(mConnection);
104+
} catch (IllegalArgumentException ignored) {
105+
}
106+
107+
dataController.clear();
108+
109+
// stop send queue
110+
DeviceSend.instance().interrupt();
111+
112+
if (pluginController != null) {
113+
pluginController.finish();
114+
pluginController = null;
115+
}
116+
117+
if (SharedPrefs.notifyOnStop()) {
118+
ShowToast.FromOtherThread(NetpowerctrlApplication.this, getString(R.string.service_stopped));
119+
}
120+
}
121+
};
122+
101123
public void useListener() {
102124
++mDiscoverServiceRefCount;
125+
// Stop delayed stop-service
126+
stopServiceHandler.removeCallbacks(stopRunnable);
103127
// Service is not running anymore, restart it
104128
if (mDiscoverService == null && !mWaitForService) {
105129
mWaitForService = true;
@@ -114,21 +138,7 @@ public void stopUseListener() {
114138
mDiscoverServiceRefCount--;
115139
}
116140
if (mDiscoverServiceRefCount == 0) {
117-
try {
118-
mDiscoverService = null;
119-
mWaitForService = false;
120-
unbindService(mConnection);
121-
} catch (IllegalArgumentException ignored) {
122-
}
123-
124-
dataController.clear();
125-
126-
// stop send queue
127-
DeviceSend.instance().interrupt();
128-
129-
if (SharedPrefs.notifyOnStop()) {
130-
ShowToast.FromOtherThread(this, getString(R.string.service_stopped));
131-
}
141+
stopServiceHandler.postDelayed(stopRunnable, 2000);
132142
}
133143
}
134144

@@ -140,8 +150,8 @@ public void stopUseListener() {
140150
public void detectNewDevicesAndReachability() {
141151

142152
// The following mechanism allows only one update request within a
143-
// 1sec timeframe.
144-
if (isDetecting)
153+
// 1sec timeframe and only if the service is available and not in reduced mode.
154+
if (isDetecting || mWaitForService || mDiscoverService.isNetworkReducedMode)
145155
return;
146156

147157
isDetecting = true;
@@ -166,8 +176,23 @@ public void onDeviceUpdated(DeviceInfo di) {
166176

167177
@Override
168178
public void onDeviceQueryFinished(List<DeviceInfo> timeout_devices) {
169-
if (timeout_devices.size() > 0)
170-
dataController.notifyConfiguredObservers(timeout_devices);
179+
if (timeout_devices.size() == 0)
180+
return;
181+
182+
// Do we need to go into network reduced mode?
183+
List<DeviceInfo> remaining = new ArrayList<DeviceInfo>(dataController.configuredDevices);
184+
remaining.removeAll(timeout_devices);
185+
boolean containsNetworkReachableDevices = false;
186+
for (DeviceInfo di : remaining) {
187+
if (di.deviceType == DeviceInfo.DeviceType.AnelDevice) {
188+
containsNetworkReachableDevices = true;
189+
break;
190+
}
191+
}
192+
if (!containsNetworkReachableDevices)
193+
mDiscoverService.setNetworkReducedMode();
194+
195+
dataController.notifyConfiguredObservers(timeout_devices);
171196
}
172197
});
173198
}
@@ -187,10 +212,17 @@ public void onServiceConnected(ComponentName className,
187212
mDiscoverService.registerDeviceUpdateObserver(dataController);
188213
if (mDiscoverServiceRefCount == 0)
189214
mDiscoverServiceRefCount = 1;
190-
instance.notifyServiceReady();
191215
mWaitForService = false;
216+
217+
// Plugins
218+
if (SharedPrefs.getLoadExtensions())
219+
pluginController = new PluginController();
220+
192221
// We do a device detection in the wifi change listener already
193222
detectNewDevicesAndReachability();
223+
224+
// Notify all observers that we are ready
225+
instance.notifyServiceReady();
194226
}
195227

196228
// Service crashed

0 commit comments

Comments
 (0)