Skip to content

Commit 127d8bb

Browse files
author
David Gräff
committed
new icon; a lot of bugs fixed (add device; crashes); refactor class names: own package for outlets view.
1 parent abe39df commit 127d8bb

File tree

91 files changed

+3045
-1696
lines changed

Some content is hidden

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

91 files changed

+3045
-1696
lines changed

.idea/dictionaries/david.xml

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/workspace.xml

Lines changed: 537 additions & 494 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

app/app.iml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,12 +82,15 @@
8282
<orderEntry type="jdk" jdkName="Android API 20 Platform" jdkType="Android SDK" />
8383
<orderEntry type="sourceFolder" forTests="false" />
8484
<orderEntry type="library" exported="" name="support-v13-20.0.0" level="project" />
85+
<orderEntry type="library" exported="" name="ndeftools-util-1.2.4" level="project" />
86+
<orderEntry type="library" exported="" name="ndeftools-1.2.4" level="project" />
8587
<orderEntry type="library" exported="" name="support-annotations-20.0.0" level="project" />
8688
<orderEntry type="library" exported="" name="support-v4-20.0.0" level="project" />
8789
<orderEntry type="library" exported="" name="acra-4.5.0" level="project" />
8890
<orderEntry type="library" exported="" scope="TEST" name="hamcrest-core-1.3" level="project" />
8991
<orderEntry type="library" exported="" name="library-1.5.1" level="project" />
9092
<orderEntry type="library" exported="" scope="TEST" name="junit-4.11" level="project" />
93+
<orderEntry type="library" exported="" name="zip4j-1.3.2" level="project" />
9194
<orderEntry type="module" module-name="Donations" exported="" />
9295
</component>
9396
</module>

app/build.gradle

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ android {
1616
defaultConfig {
1717
minSdkVersion 14
1818
targetSdkVersion 20
19-
versionCode 84
20-
versionName "5.8"
19+
versionCode 87
20+
versionName "5.9.2"
2121
applicationId appID
2222
testApplicationId "oly.netpowerctrl.tests"
2323
testInstrumentationRunner "android.test.InstrumentationTestRunner"
@@ -76,5 +76,8 @@ dependencies {
7676
compile 'com.github.gabrielemariotti.changeloglib:library:1.5.1'
7777
compile 'ch.acra:acra:4.5.0'
7878
compile 'com.android.support:support-v13:20.0.0'
79+
compile 'net.lingala.zip4j:zip4j:1.3.2'
80+
compile 'com.google.code.ndef-tools-for-android:ndeftools:1.2.4'
81+
compile 'com.google.code.ndef-tools-for-android:ndeftools-util:1.2.4'
7982
androidTestCompile 'junit:junit:4.11'
8083
}

app/src/main/AndroidManifest.xml

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -67,11 +67,6 @@
6767
<intent-filter>
6868
<action android:name="android.intent.action.MAIN" />
6969
</intent-filter>
70-
<intent-filter>
71-
<action android:name="android.nfc.action.NDEF_DISCOVERED" />
72-
<category android:name="android.intent.category.DEFAULT" />
73-
<data android:mimeType="application/oly.netpowerctrl" />
74-
</intent-filter>
7570
</activity>
7671

7772
<activity
@@ -84,6 +79,11 @@
8479
<intent-filter>
8580
<action android:name="android.intent.action.MAIN" />
8681
</intent-filter>
82+
<intent-filter>
83+
<action android:name="android.nfc.action.NDEF_DISCOVERED" />
84+
<category android:name="android.intent.category.DEFAULT" />
85+
<data android:mimeType="application/oly.netpowerctrl" />
86+
</intent-filter>
8787
</activity>
8888

8989
<activity
@@ -99,13 +99,20 @@
9999
</intent-filter>
100100
</activity>
101101

102+
<activity
103+
android:name=".main.NfcTagWriterActivity"
104+
android:configChanges="orientation|screenSize|keyboardHidden|layoutDirection"
105+
android:description="@string/app_name_widget"
106+
android:icon="@drawable/netpowerctrl"
107+
android:label="@string/app_name"
108+
android:theme="@style/Theme.Transparent"></activity>
109+
102110
<activity
103111
android:name=".scenes.EditSceneActivity"
104112
android:configChanges="orientation|screenSize|keyboardHidden|layoutDirection"
105113
android:description="@string/app_name_shortcut_desc"
106114
android:icon="@drawable/netpowerctrl"
107115
android:label="@string/app_name_shortcut"
108-
android:noHistory="true"
109116
android:theme="@style/Theme.StartTheme"
110117
android:uiOptions="splitActionBarWhenNarrow">
111118
<meta-data

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ public boolean isTestOK() {
8989

9090
@Override
9191
public boolean updated(DeviceCollection deviceCollection, Device updated_device, ObserverUpdateActions action) {
92-
if (!updated_device.equalsByUniqueID(device))
92+
if (updated_device.UniqueDeviceID == null || !updated_device.equalsByUniqueID(device))
9393
return true;
9494

9595
if (!updated_device.isReachable()) {

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

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -85,12 +85,18 @@ private void executeDeviceBatch(Device device, List<Scene.PortAndCommand> comman
8585
onExecutionFinished callback) {
8686
// Get necessary objects
8787
ListenService service = ListenService.getService();
88-
if (service == null)
88+
if (service == null) {
89+
if (callback != null)
90+
callback.onExecutionFinished(command_list.size());
8991
return;
92+
}
9093

9194
DeviceConnection ci = device.getFirstReachableConnection();
92-
if (ci == null)
95+
if (ci == null) {
96+
if (callback != null)
97+
callback.onExecutionFinished(command_list.size());
9398
return;
99+
}
94100

95101
if (ci instanceof DeviceConnectionHTTP) { // http
96102
// Use Http instead of UDP for sending. For each batch command we will send a single http request
@@ -103,11 +109,15 @@ private void executeDeviceBatch(Device device, List<Scene.PortAndCommand> comman
103109
HttpThreadPool.execute(HttpThreadPool.createHTTPRunner((DeviceConnectionHTTP) ci, "ctrl.htm",
104110
"F" + String.valueOf(port.id - 1) + "=s", (DeviceConnectionHTTP) ci, false, AnelPluginHttp.receiveSwitchResponseHtml));
105111
}
106-
} else if (!(ci instanceof DeviceConnectionUDP)) { // not udp: return: unknown protocol
112+
} else if (!(ci instanceof DeviceConnectionUDP)) { // unknown protocol
113+
if (callback != null)
114+
callback.onExecutionFinished(command_list.size());
107115
return;
108116
}
109117

110118
if (warnUDPSending()) {
119+
if (callback != null)
120+
callback.onExecutionFinished(command_list.size());
111121
return;
112122
}
113123

@@ -120,32 +130,23 @@ private void executeDeviceBatch(Device device, List<Scene.PortAndCommand> comman
120130
byte data_io = 0;
121131
boolean containsOutlets = false;
122132
boolean containsIO = false;
123-
int valid_commands = 0;
124133

125134
// First step: Setup data byte (outlet, io) to reflect the current state of the device ports.
126135
device.lockDevicePorts();
127136
Iterator<DevicePort> it = device.getDevicePortIterator();
128137
while (it.hasNext()) {
129138
DevicePort oi = it.next();
130-
if (oi.Disabled || oi.current_value == 0)
139+
if (oi.Disabled || oi.current_value == 0) // Only take "ON" commands into account for the bulk change byte
131140
continue;
132141
int id = oi.id;
133142
if (id >= 10 && id < 20) {
134143
data_io = switchOn(data_io, id - 10);
135-
++valid_commands;
136144
} else if (id >= 0) {
137145
data_outlet = switchOn(data_outlet, id);
138-
++valid_commands;
139146
}
140147
}
141148
device.releaseDevicePorts();
142149

143-
if (valid_commands == 0) {
144-
if (callback != null)
145-
callback.onExecutionFinished(command_list.size());
146-
return;
147-
}
148-
149150
// Second step: Apply commands
150151
for (Scene.PortAndCommand c : command_list) {
151152
c.port.last_command_timecode = System.currentTimeMillis();
@@ -560,8 +561,10 @@ public void rename(final DevicePort port, final String new_name, final onAsyncRu
560561
// and have to set all the others to the same values as before)
561562
final String getData = "dd.htm?DD" + String.valueOf(port.id);
562563
final DeviceConnectionHTTP ci = (DeviceConnectionHTTP) port.device.getFirstReachableConnection("HTTP");
563-
if (ci == null)
564+
if (ci == null) {
565+
Toast.makeText(App.instance, R.string.error_rename_only_with_http_connection, Toast.LENGTH_SHORT).show();
564566
return;
567+
}
565568

566569
HttpThreadPool.execute(HttpThreadPool.createHTTPRunner(ci, getData, null,
567570
port, true, new HttpThreadPool.HTTPCallback<DevicePort>() {

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

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
package oly.netpowerctrl.anel;
22

3-
import android.util.Log;
4-
53
import org.xml.sax.InputSource;
64
import org.xml.sax.SAXException;
75
import org.xml.sax.XMLReader;
@@ -31,7 +29,7 @@ public class AnelPluginHttp {
3129
static final HttpThreadPool.HTTPCallback<DeviceConnection> receiveCtrlHtml = new HttpThreadPool.HTTPCallback<DeviceConnection>() {
3230
@Override
3331
public void httpResponse(DeviceConnection ci, boolean callback_success, String response_message) {
34-
Log.w("AnelPluginHttp", "http receive" + response_message);
32+
//Log.w("AnelPluginHttp", "http receive" + response_message);
3533
final Device device = ci.getDevice();
3634
if (!callback_success) {
3735
ci.setNotReachable(response_message);

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

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,8 @@ public void run() {
8383
disabledOutlets = Integer.parseInt(msg[14]);
8484
} catch (NumberFormatException ignored) {
8585
}
86+
}
87+
if (msg.length > 15) {
8688
int httpPort;
8789
try {
8890
httpPort = Integer.parseInt(msg[15]);
@@ -93,31 +95,29 @@ public void run() {
9395
deviceConnection = new DeviceConnectionHTTP(di, HostName, httpPort);
9496
deviceConnection.setIsAssignedByDevice(true);
9597
di.addConnection(deviceConnection);
96-
97-
// IO ports
98-
if (msg.length > 23) {
99-
// 1-based id. IO output range: 11..19, IO input range is 21..29
100-
int io_id = 10;
101-
for (int i = 16; i <= 23; ++i) {
102-
io_id++;
103-
String io_port[] = msg[i].split(",");
104-
if (io_port.length != 3) continue;
105-
106-
DevicePort oi = new DevicePort(di, DevicePort.DevicePortType.TypeToggle);
107-
108-
if (io_port[1].equals("1")) // input
109-
oi.id = io_id + 10;
110-
else
111-
oi.id = io_id;
112-
113-
oi.setDescription(io_port[0]);
114-
oi.current_value = io_port[2].equals("1") ? DevicePort.ON : DevicePort.OFF;
115-
di.add(oi);
116-
}
117-
di.Features.add(new DeviceFeatureTemperature(msg[24]));
118-
di.Version = msg[25].trim();
98+
}
99+
// IO ports
100+
if (msg.length > 25) {
101+
// 1-based id. IO output range: 11..19, IO input range is 21..29
102+
int io_id = 10;
103+
for (int i = 16; i <= 23; ++i) {
104+
io_id++;
105+
String io_port[] = msg[i].split(",");
106+
if (io_port.length != 3) continue;
107+
108+
DevicePort oi = new DevicePort(di, DevicePort.DevicePortType.TypeToggle);
109+
110+
if (io_port[1].equals("1")) // input
111+
oi.id = io_id + 10;
112+
else
113+
oi.id = io_id;
114+
115+
oi.setDescription(io_port[0]);
116+
oi.current_value = io_port[2].equals("1") ? DevicePort.ON : DevicePort.OFF;
117+
di.add(oi);
119118
}
120-
119+
di.Features.add(new DeviceFeatureTemperature(msg[24]));
120+
di.Version = msg[25].trim();
121121
}
122122
// For old firmwares
123123
else if (msg.length < 14) {

app/src/main/java/oly/netpowerctrl/data/AppData.java

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ public class AppData {
4040
public static final DataQueryCompletedObserver observersDataQueryCompleted = new DataQueryCompletedObserver();
4141
public static final DataLoadedObserver observersOnDataLoaded = new DataLoadedObserver();
4242
public static final NewDeviceObserver observersNew = new NewDeviceObserver();
43+
private static final String TAG = AppData.class.getName();
4344

4445
public final List<Device> newDevices = new ArrayList<>();
4546
final public DeviceCollection deviceCollection = new DeviceCollection();
@@ -67,12 +68,17 @@ public static void useAppData() {
6768

6869
appData.loadStoreJSonData = new LoadStoreJSonData();
6970
appData.loadStoreJSonData.loadData(appData);
71+
LoadStoreIconData.init();
7072
}
7173

7274
public static boolean isDataLoaded() {
7375
return observersOnDataLoaded.dataLoaded;
7476
}
7577

78+
public LoadStoreJSonData getLoadStoreJSonData() {
79+
return loadStoreJSonData;
80+
}
81+
7682
/**
7783
* Load all devices, scenes, groups, timers. This is called by useAppData.
7884
* Loading of data is asynchronous and done in a background thread. Do no assume data to be
@@ -312,12 +318,16 @@ public void execute(Scene scene, onExecutionFinished callback) {
312318

313319
for (SceneItem item : scene.sceneItems) {
314320
DevicePort p = getInstance().findDevicePort(item.uuid);
315-
if (p == null)
321+
if (p == null) {
322+
Log.e(TAG, "Execute scene, DevicePort not found " + item.uuid.toString());
316323
continue;
324+
}
317325

318326
PluginInterface remote = p.device.getPluginInterface();
319-
if (remote == null)
327+
if (remote == null) {
328+
Log.e(TAG, "Execute scene, PluginInterface not found " + item.uuid.toString());
320329
continue;
330+
}
321331

322332
int command = item.command;
323333
// Replace toggle by master command if master is set

0 commit comments

Comments
 (0)