Skip to content

Commit 7dd3365

Browse files
author
David Gräff
committed
Plugin actions can be assigned to scenes now. RangedValues work. Help added to scene screen.
Changed plugin interface: Allow state messages. Allot of crash fixes.
1 parent f040f68 commit 7dd3365

File tree

60 files changed

+622
-352
lines changed

Some content is hidden

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

60 files changed

+622
-352
lines changed

Android-NetPowerctrl12.iml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<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">
3-
<component name="NewModuleRootManager" inherit-compiler-output="false">
4-
<output url="file://$MODULE_DIR$/build/classes/main" />
5-
<output-test url="file://$MODULE_DIR$/build/classes/test" />
3+
<component name="NewModuleRootManager" inherit-compiler-output="true">
64
<exclude-output />
75
<content url="file://$MODULE_DIR$">
86
<excludeFolder url="file://$MODULE_DIR$/.gradle" />

app/app.iml

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -35,27 +35,27 @@
3535
<sourceFolder url="file://$MODULE_DIR$/build/source/buildConfig/test/debug" isTestSource="true" generated="true" />
3636
<sourceFolder url="file://$MODULE_DIR$/build/source/rs/test/debug" isTestSource="true" generated="true" />
3737
<sourceFolder url="file://$MODULE_DIR$/build/res/rs/test/debug" type="java-test-resource" />
38+
<sourceFolder url="file://$MODULE_DIR$/src/debug/res" type="java-resource" />
39+
<sourceFolder url="file://$MODULE_DIR$/src/debug/resources" type="java-resource" />
3840
<sourceFolder url="file://$MODULE_DIR$/src/debug/aidl" isTestSource="false" />
3941
<sourceFolder url="file://$MODULE_DIR$/src/debug/assets" isTestSource="false" />
4042
<sourceFolder url="file://$MODULE_DIR$/src/debug/java" isTestSource="false" />
4143
<sourceFolder url="file://$MODULE_DIR$/src/debug/jni" isTestSource="false" />
4244
<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" />
45+
<sourceFolder url="file://$MODULE_DIR$/src/main/res" type="java-resource" />
46+
<sourceFolder url="file://$MODULE_DIR$/src/main/resources" type="java-resource" />
4547
<sourceFolder url="file://$MODULE_DIR$/src/main/aidl" isTestSource="false" />
4648
<sourceFolder url="file://$MODULE_DIR$/src/main/assets" isTestSource="false" />
4749
<sourceFolder url="file://$MODULE_DIR$/src/main/java" isTestSource="false" />
4850
<sourceFolder url="file://$MODULE_DIR$/src/main/jni" isTestSource="false" />
4951
<sourceFolder url="file://$MODULE_DIR$/src/main/rs" isTestSource="false" />
50-
<sourceFolder url="file://$MODULE_DIR$/src/main/res" type="java-resource" />
51-
<sourceFolder url="file://$MODULE_DIR$/src/main/resources" type="java-resource" />
52-
<sourceFolder url="file://$MODULE_DIR$/src/instrumentTest/aidl" isTestSource="true" />
53-
<sourceFolder url="file://$MODULE_DIR$/src/instrumentTest/assets" isTestSource="true" />
54-
<sourceFolder url="file://$MODULE_DIR$/src/instrumentTest/java" isTestSource="true" />
55-
<sourceFolder url="file://$MODULE_DIR$/src/instrumentTest/jni" isTestSource="true" />
56-
<sourceFolder url="file://$MODULE_DIR$/src/instrumentTest/rs" isTestSource="true" />
57-
<sourceFolder url="file://$MODULE_DIR$/src/instrumentTest/res" type="java-test-resource" />
58-
<sourceFolder url="file://$MODULE_DIR$/src/instrumentTest/resources" type="java-test-resource" />
52+
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/res" type="java-test-resource" />
53+
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/resources" type="java-test-resource" />
54+
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/aidl" isTestSource="true" />
55+
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/assets" isTestSource="true" />
56+
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/java" isTestSource="true" />
57+
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/jni" isTestSource="true" />
58+
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/rs" isTestSource="true" />
5959
<excludeFolder url="file://$MODULE_DIR$/build/apk" />
6060
<excludeFolder url="file://$MODULE_DIR$/build/assets" />
6161
<excludeFolder url="file://$MODULE_DIR$/build/bundles" />
@@ -70,9 +70,9 @@
7070
</content>
7171
<orderEntry type="jdk" jdkName="Android API 19 Platform" jdkType="Android SDK" />
7272
<orderEntry type="sourceFolder" forTests="false" />
73-
<orderEntry type="library" exported="" name="support-v13-19.0.1" level="project" />
74-
<orderEntry type="library" exported="" name="support-v4-19.0.1" level="project" />
73+
<orderEntry type="library" exported="" name="support-v4-19.1.0" level="project" />
7574
<orderEntry type="library" exported="" name="acra-4.5.0" level="project" />
75+
<orderEntry type="library" exported="" name="support-v13-19.1.0" level="project" />
7676
</component>
7777
</module>
7878

app/build.gradle

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ apply plugin: 'android'
22

33
android {
44
compileSdkVersion 19
5-
buildToolsVersion '19.0.1'
5+
buildToolsVersion '19.0.3'
66

77
defaultConfig {
88
minSdkVersion 14
@@ -19,6 +19,8 @@ android {
1919
}
2020

2121
dependencies {
22-
compile 'ch.acra:acra:4.5.0@jar'
23-
compile 'com.android.support:support-v13:+'
22+
debugCompile 'ch.acra:acra:4.5.0@jar'
23+
debugCompile 'com.android.support:support-v13:+'
24+
releaseCompile 'ch.acra:acra:4.5.0@jar'
25+
releaseCompile 'com.android.support:support-v13:+'
2426
}

app/src/main/AndroidManifest.xml

Lines changed: 4 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="30"
5-
android:versionName="2.6b">
4+
android:versionCode="33"
5+
android:versionName="2.7a">
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"
@@ -16,6 +16,7 @@
1616
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
1717
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
1818
<uses-permission android:name="com.android.launcher.permission.INSTALL_SHORTCUT" />
19+
<!--<uses-permission android:name="android.permission.GET_ACCOUNTS" />-->
1920

2021
<permission
2122
android:name="oly.netpowerctrl.plugins"

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
package oly.netpowerctrl.plugins;
2+
import java.util.List;
23

34
interface INetPwrCtrlPluginResult {
5+
void initDone(in List<String> states, int success_state);
46
void pluginState(int state);
57
void intValue(int id, String name, int min, int max, int value);
68
void booleanValue(int id, String name, boolean value);
7-
void action(int id, String name);
9+
void action(int id, int groupID, String name);
810
void header(String name);
911
void finished();
1012

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ static DeviceInfo createReceivedAnelDevice(String DeviceName, String HostName,
7171
di.Password = "anel";
7272

7373
di.SendPort = SharedPrefs.getDefaultSendPort();
74-
di.reachable = true;
74+
di.setReachable();
7575
di.updated = System.currentTimeMillis();
7676
return di;
7777
}

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

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
import oly.netpowerctrl.datastructure.DeviceInfo;
99
import oly.netpowerctrl.datastructure.DevicePort;
10+
import oly.netpowerctrl.datastructure.ExecutionFinished;
1011
import oly.netpowerctrl.datastructure.Executor;
1112
import oly.netpowerctrl.network.DeviceSend;
1213

@@ -41,7 +42,7 @@ private static byte toggle(byte data, int outletNumber) {
4142
/**
4243
* @param command_list
4344
*/
44-
public static void execute(List<Executor.PortAndCommand> command_list) {
45+
public static void execute(List<Executor.PortAndCommand> command_list, ExecutionFinished callback) {
4546
TreeMap<DeviceInfo, List<Executor.PortAndCommand>> commands_grouped_by_devices =
4647
new TreeMap<DeviceInfo, List<Executor.PortAndCommand>>();
4748

@@ -58,14 +59,12 @@ public static void execute(List<Executor.PortAndCommand> command_list) {
5859

5960
// execute by device
6061
for (TreeMap.Entry<DeviceInfo, List<Executor.PortAndCommand>> entry : commands_grouped_by_devices.entrySet()) {
61-
DeviceInfo device = entry.getKey();
62-
List<Executor.PortAndCommand> value = entry.getValue();
63-
execute(device, value);
62+
execute(entry.getKey(), entry.getValue(), callback);
6463
}
6564

6665
}
6766

68-
public static void execute(DeviceInfo di, List<Executor.PortAndCommand> command_list) {
67+
public static void execute(DeviceInfo di, List<Executor.PortAndCommand> command_list, ExecutionFinished callback) {
6968
// build bulk change byte, see: www.anel-elektronik.de/forum_neu/viewtopic.php?f=16&t=207
7069
// “Sw” + Steckdosen + User + Passwort
7170
// Steckdosen = Zustand aller Steckdosen binär
@@ -141,6 +140,9 @@ public static void execute(DeviceInfo di, List<Executor.PortAndCommand> command_
141140
data[2] = data_io;
142141
DeviceSend.instance().addJob(new DeviceSend.SendJob(di, data, DeviceSend.INQUERY_REQUEST, true));
143142
}
143+
144+
if (callback != null)
145+
callback.onExecutionFinished(command_list.size());
144146
}
145147

146148
/**
@@ -149,7 +151,7 @@ public static void execute(DeviceInfo di, List<Executor.PortAndCommand> command_
149151
* @param port
150152
* @param command
151153
*/
152-
public static void execute(DevicePort port, int command) {
154+
public static void execute(DevicePort port, int command, ExecutionFinished callback) {
153155
port.last_command_timecode = System.currentTimeMillis();
154156
boolean bValue = false;
155157
if (command == DevicePort.ON)
@@ -171,6 +173,9 @@ else if (command == DevicePort.TOGGLE)
171173
}
172174

173175
DeviceSend.instance().addJob(new DeviceSend.SendJob(port.device, data, DeviceSend.INQUERY_REQUEST, true));
176+
177+
if (callback != null)
178+
callback.onExecutionFinished(1);
174179
}
175180

176181
public static void sendBroadcastQuery() {

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ public void onDeviceUpdated(DeviceInfo di) {
209209
test_state = TestStates.TEST_ACCESS;
210210
// Just send the current value of the first device port as target value.
211211
// Should change nothing but we will get a feedback if the credentials are working.
212-
AnelExecutor.execute(device.DevicePorts.get(0), device.DevicePorts.get(0).current_value);
212+
AnelExecutor.execute(device.DevicePorts.get(0), device.DevicePorts.get(0).current_value, null);
213213
Handler handler = new Handler();
214214
// Timeout is 1,1s
215215
handler.postDelayed(new Runnable() {
@@ -227,7 +227,7 @@ public void run() {
227227
} else if (test_state == TestStates.TEST_ACCESS) {
228228
//noinspection ConstantConditions
229229
Toast.makeText(getActivity(), getActivity().getString(R.string.device_test_ok), Toast.LENGTH_SHORT).show();
230-
device.reachable = true;
230+
device.setReachable();
231231
test_state = TestStates.TEST_OK;
232232
}
233233
}

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

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,11 @@ public static class ReviewItem {
3333
public int type = 0; // o string, 1 int, 2 boolean
3434
public boolean mEnabled;
3535

36-
public ReviewItem(String title, String displayValue, int pageKey, boolean enabled) {
36+
public ReviewItem(String title, String displayValue, int pageKey) {
3737
mTitle = title;
3838
mDisplayValueString = displayValue;
3939
mPageKey = pageKey;
40-
mEnabled = enabled;
40+
mEnabled = true;
4141
type = 0;
4242
}
4343

@@ -49,11 +49,11 @@ public ReviewItem(String title, int displayValue, int pageKey, boolean enabled)
4949
type = 1;
5050
}
5151

52-
public ReviewItem(String title, boolean displayValue, int pageKey, boolean enabled) {
52+
public ReviewItem(String title, boolean displayValue, int pageKey) {
5353
mTitle = title;
5454
mDisplayValueBoolean = displayValue;
5555
mPageKey = pageKey;
56-
mEnabled = enabled;
56+
mEnabled = true;
5757
type = 2;
5858
}
5959
}
@@ -75,13 +75,13 @@ public DeviceConfigurationAdapter(Context context, DeviceInfo deviceInfo) {
7575
this.context = context;
7676
this.deviceInfo = deviceInfo;
7777
inflater = LayoutInflater.from(context);
78-
deviceConfigurationOptions.add(new ReviewItem("Name", deviceInfo.DeviceName, DeviceName, true));
79-
deviceConfigurationOptions.add(new ReviewItem("Host/IP", deviceInfo.HostName, HostName, true));
80-
deviceConfigurationOptions.add(new ReviewItem("Username", deviceInfo.UserName, UserName, true));
81-
deviceConfigurationOptions.add(new ReviewItem("Password", deviceInfo.Password, Password, true));
82-
deviceConfigurationOptions.add(new ReviewItem("Use default ports", deviceInfo.DefaultPorts, DefaultPorts, true));
83-
deviceConfigurationOptions.add(new ReviewItem("App receive port", deviceInfo.ReceivePort, ReceivePort, !deviceInfo.DefaultPorts));
84-
deviceConfigurationOptions.add(new ReviewItem("App send port", deviceInfo.SendPort, SendPort, !deviceInfo.DefaultPorts));
78+
deviceConfigurationOptions.add(new ReviewItem(context.getString(R.string.device_name), deviceInfo.DeviceName, DeviceName));
79+
deviceConfigurationOptions.add(new ReviewItem(context.getString(R.string.device_ip), deviceInfo.HostName, HostName));
80+
deviceConfigurationOptions.add(new ReviewItem(context.getString(R.string.device_username), deviceInfo.UserName, UserName));
81+
deviceConfigurationOptions.add(new ReviewItem(context.getString(R.string.device_password), deviceInfo.Password, Password));
82+
deviceConfigurationOptions.add(new ReviewItem(context.getString(R.string.device_default_ports), deviceInfo.DefaultPorts, DefaultPorts));
83+
deviceConfigurationOptions.add(new ReviewItem(context.getString(R.string.device_recv_udp), deviceInfo.ReceivePort, ReceivePort, !deviceInfo.DefaultPorts));
84+
deviceConfigurationOptions.add(new ReviewItem(context.getString(R.string.device_send_udp), deviceInfo.SendPort, SendPort, !deviceInfo.DefaultPorts));
8585
}
8686

8787
@Override
@@ -117,7 +117,7 @@ public long getItemId(int position) {
117117
@Override
118118
public View getView(int position, View convertView, ViewGroup container) {
119119
if (convertView == null)
120-
convertView = inflater.inflate(R.layout.device_configuration_item, null);
120+
convertView = inflater.inflate(R.layout.device_configuration_item, container);
121121

122122
ReviewItem reviewItem = deviceConfigurationOptions.get(position);
123123
((TextView) convertView.findViewById(R.id.titleText)).setText(reviewItem.mTitle);

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

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,10 @@ public class NetpowerctrlApplication extends Application {
4848
private PluginController pluginController;
4949
private ArrayList<ServiceReady> observersServiceReady = new ArrayList<ServiceReady>();
5050

51+
public boolean isServiceReady() {
52+
return (mDiscoverService != null);
53+
}
54+
5155
@SuppressWarnings("unused")
5256
public boolean registerServiceReadyObserver(ServiceReady o) {
5357
if (!observersServiceReady.contains(o)) {
@@ -72,6 +76,13 @@ private void notifyServiceReady() {
7276
}
7377
}
7478

79+
private void notifyServiceFinished() {
80+
Iterator<ServiceReady> it = observersServiceReady.iterator();
81+
while (it.hasNext()) {
82+
it.next().onServiceFinished();
83+
}
84+
}
85+
7586
@Override
7687
public void onCreate() {
7788
super.onCreate();
@@ -151,7 +162,8 @@ public void detectNewDevicesAndReachability() {
151162

152163
// The following mechanism allows only one update request within a
153164
// 1sec timeframe and only if the service is available and not in reduced mode.
154-
if (isDetecting || mWaitForService || mDiscoverService.isNetworkReducedMode)
165+
if (isDetecting || mWaitForService || mDiscoverService == null ||
166+
mDiscoverService.isNetworkReducedMode)
155167
return;
156168

157169
isDetecting = true;
@@ -222,12 +234,13 @@ public void onServiceConnected(ComponentName className,
222234
detectNewDevicesAndReachability();
223235

224236
// Notify all observers that we are ready
225-
instance.notifyServiceReady();
237+
notifyServiceReady();
226238
}
227239

228240
// Service crashed
229241
@Override
230242
public void onServiceDisconnected(ComponentName arg0) {
243+
notifyServiceFinished();
231244
mDiscoverServiceRefCount = 0;
232245
mDiscoverService = null;
233246
mWaitForService = false;
@@ -238,8 +251,8 @@ public NetpowerctrlService getService() {
238251
return mDiscoverService;
239252
}
240253

241-
public PluginController getPluginController() {
242-
return pluginController;
254+
static public PluginController getPluginController() {
255+
return instance.pluginController;
243256
}
244257

245258
static public RuntimeDataController getDataController() {

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ public void addToConfiguredDevices(DeviceInfo current_device, boolean write_to_d
203203
}
204204

205205
// Initiate detect devices, if this added device is not flagged as reachable at the moment.
206-
if (!current_device.reachable)
206+
if (!current_device.isReachable())
207207
new DeviceQuery(null, current_device);
208208
}
209209

@@ -274,7 +274,7 @@ public void saveConfiguredDevices(boolean updateObservers) {
274274
public int getReachableConfiguredDevices() {
275275
int r = 0;
276276
for (DeviceInfo di : configuredDevices)
277-
if (di.reachable)
277+
if (di.isReachable())
278278
++r;
279279
return r;
280280
}

0 commit comments

Comments
 (0)