Skip to content

Commit 9e1c87c

Browse files
author
David Gräff
committed
Clean unused resources, fix lint warnings.
Add dark theme variant of radio button. Less saturation for the off-state image. Wake up from engery saving mode option. Improve nfc description and add nfc settings button
1 parent d5253aa commit 9e1c87c

File tree

161 files changed

+1340
-1787
lines changed

Some content is hidden

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

161 files changed

+1340
-1787
lines changed

.idea/inspectionProfiles/Project_Default.xml

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

.idea/misc.xml

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

.idea/workspace.xml

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

app/build.gradle

+4
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@ android {
99
targetSdkVersion 19
1010
}
1111

12+
lintOptions {
13+
abortOnError false
14+
}
15+
1216
buildTypes {
1317
release {
1418
zipAlign true

app/src/main/AndroidManifest.xml

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
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="46"
5-
android:versionName="3.0">
4+
android:versionCode="47"
5+
android:versionName="3.1">
66

77
<!-- Api level 14: Android 4.0 15. Dezember 2011 -->
88
<!-- Api level 16: Android 4.1 27. Juni 2012 -->

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
import oly.netpowerctrl.network.DeviceSend;
1818

1919
/**
20-
* Created by david on 21.02.14.
20+
* A DeviceSend.Job that provide broadcast sending to anel devices.
2121
*/
2222
public class AnelBroadcastSendJob implements DeviceSend.Job {
2323
private void sendPacket(DeviceSend deviceSend, InetAddress ip, int SendPort, byte[] message) {

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

+3-3
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,11 @@
1313
import oly.netpowerctrl.preferences.SharedPrefs;
1414
import oly.netpowerctrl.utils.ShowToast;
1515

16-
public class AnelDeviceDiscoveryThread extends Thread {
17-
private int receive_port;
16+
class AnelDeviceDiscoveryThread extends Thread {
17+
private final int receive_port;
1818
private boolean keep_running;
1919
private DatagramSocket socket;
20-
private AnelPlugin anelPlugin;
20+
private final AnelPlugin anelPlugin;
2121

2222
public AnelDeviceDiscoveryThread(AnelPlugin anelPlugin, int port) {
2323
this.anelPlugin = anelPlugin;

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

+6-6
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
* This is a specialized class for Anel devices.
3838
*/
3939
final public class AnelPlugin implements PluginInterface {
40-
private List<AnelDeviceDiscoveryThread> discoveryThreads = new ArrayList<AnelDeviceDiscoveryThread>();
40+
private final List<AnelDeviceDiscoveryThread> discoveryThreads = new ArrayList<AnelDeviceDiscoveryThread>();
4141

4242
public void startDiscoveryThreads(int additional_port) {
4343
// Get all ports of configured devices and add the additional_port if != 0
@@ -147,7 +147,7 @@ private static void executeDeviceBatch(DeviceInfo di, List<Scene.PortAndCommand>
147147
DevicePort oi = it.next();
148148
if (oi.Disabled || oi.current_value == 0)
149149
continue;
150-
int id = (int) oi.id;
150+
int id = oi.id;
151151
if (id >= 10) {
152152
data_io = switchOn(data_io, id - 10);
153153
} else {
@@ -160,7 +160,7 @@ private static void executeDeviceBatch(DeviceInfo di, List<Scene.PortAndCommand>
160160
for (Scene.PortAndCommand c : command_list) {
161161
c.port.last_command_timecode = System.currentTimeMillis();
162162

163-
int id = (int) c.port.id;
163+
int id = c.port.id;
164164
if (id >= 10) {
165165
containsIO = true;
166166
} else {
@@ -213,7 +213,7 @@ private static void executeDeviceBatch(DeviceInfo di, List<Scene.PortAndCommand>
213213
callback.onExecutionFinished(command_list.size());
214214
}
215215

216-
static final byte[] requestMessage = "wer da?\r\n".getBytes();
216+
private static final byte[] requestMessage = "wer da?\r\n".getBytes();
217217

218218
/**
219219
* Switch a single outlet or io port
@@ -250,7 +250,7 @@ else if (command == DevicePort.TOGGLE)
250250
callback.onExecutionFinished(1);
251251
}
252252

253-
static Thread renameThread;
253+
private static Thread renameThread;
254254

255255
@Override
256256
public void finish() {
@@ -329,7 +329,7 @@ public void run() {
329329
renameThread.start();
330330
}
331331

332-
private List<Scene.PortAndCommand> command_list = new ArrayList<Scene.PortAndCommand>();
332+
private final List<Scene.PortAndCommand> command_list = new ArrayList<Scene.PortAndCommand>();
333333

334334
@Override
335335
public void addToTransaction(DevicePort port, int command) {

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

+4-4
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ private enum TestStates {TEST_INIT, TEST_REACHABLE, TEST_ACCESS, TEST_OK}
3636
private DeviceInfo device;
3737
private DeviceQuery deviceQuery;
3838

39-
public ConfigureDeviceFragment() {
39+
private ConfigureDeviceFragment() {
4040
}
4141

4242
public static ConfigureDeviceFragment instantiate(Context ctx, DeviceInfo di) {
@@ -156,8 +156,8 @@ public void onCreate(Bundle savedInstanceState) {
156156
if (getArguments() != null) {
157157
try {
158158
device = DeviceInfo.fromJSON(JSONHelper.getReader(getArguments().getString(DEVICE_PARAMETER)));
159-
} catch (IOException e) {
160-
} catch (ClassNotFoundException e) {
159+
} catch (IOException ignored) {
160+
} catch (ClassNotFoundException ignored) {
161161
}
162162
}
163163

@@ -237,7 +237,7 @@ public void onDeviceQueryFinished(List<DeviceInfo> timeout_devices) {
237237
}
238238

239239
@Override
240-
public void onDeviceError(DeviceInfo di, String error_message) {
240+
public void onDeviceError(DeviceInfo di) {
241241
if (test_state == TestStates.TEST_ACCESS) {
242242
if (di.equalsByUniqueID(device)) {
243243
test_state = TestStates.TEST_INIT;

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

+25-22
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,14 @@
2121
/**
2222
* For displaying DeviceInfo fields in a ListView
2323
*/
24-
public class DeviceConfigurationAdapter extends BaseAdapter implements View.OnClickListener {
24+
class DeviceConfigurationAdapter extends BaseAdapter implements View.OnClickListener {
2525
public static class ReviewItem {
26-
public static final int DEFAULT_WEIGHT = 0;
2726

28-
public String mTitle;
27+
public final String mTitle;
2928
public String mDisplayValueString;
3029
public int mDisplayValueInt;
3130
public boolean mDisplayValueBoolean;
32-
public int mPageKey;
31+
public final int mPageKey;
3332
public int type = 0; // o string, 1 int, 2 boolean
3433
public boolean mEnabled;
3534

@@ -49,19 +48,19 @@ public ReviewItem(String title, int displayValue, int pageKey, boolean enabled)
4948
type = 1;
5049
}
5150

52-
public ReviewItem(String title, boolean displayValue, int pageKey) {
51+
public ReviewItem(String title, boolean displayValue) {
5352
mTitle = title;
5453
mDisplayValueBoolean = displayValue;
55-
mPageKey = pageKey;
54+
mPageKey = DeviceConfigurationAdapter.DefaultPorts;
5655
mEnabled = true;
5756
type = 2;
5857
}
5958
}
6059

61-
public List<ReviewItem> deviceConfigurationOptions = new ArrayList<ReviewItem>();
62-
private Context context;
63-
private DeviceInfo deviceInfo;
64-
private LayoutInflater inflater;
60+
private final List<ReviewItem> deviceConfigurationOptions = new ArrayList<ReviewItem>();
61+
private final Context context;
62+
private final DeviceInfo deviceInfo;
63+
private final LayoutInflater inflater;
6564

6665
private static final int DeviceName = 0;
6766
private static final int HostName = 1;
@@ -79,7 +78,7 @@ public DeviceConfigurationAdapter(Context context, DeviceInfo deviceInfo) {
7978
deviceConfigurationOptions.add(new ReviewItem(context.getString(R.string.device_ip), deviceInfo.HostName, HostName));
8079
deviceConfigurationOptions.add(new ReviewItem(context.getString(R.string.device_username), deviceInfo.UserName, UserName));
8180
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));
81+
deviceConfigurationOptions.add(new ReviewItem(context.getString(R.string.device_default_ports), deviceInfo.DefaultPorts));
8382
deviceConfigurationOptions.add(new ReviewItem(context.getString(R.string.device_recv_udp), deviceInfo.ReceivePort, ReceivePort, !deviceInfo.DefaultPorts));
8483
deviceConfigurationOptions.add(new ReviewItem(context.getString(R.string.device_send_udp), deviceInfo.SendPort, SendPort, !deviceInfo.DefaultPorts));
8584
}
@@ -120,6 +119,7 @@ public View getView(int position, View convertView, ViewGroup container) {
120119
convertView = inflater.inflate(R.layout.device_configuration_item, null);
121120

122121
ReviewItem reviewItem = deviceConfigurationOptions.get(position);
122+
assert convertView != null;
123123
((TextView) convertView.findViewById(R.id.titleText)).setText(reviewItem.mTitle);
124124
TextView text = (TextView) convertView.findViewById(R.id.textOption);
125125
CheckBox checkbox = (CheckBox) convertView.findViewById(R.id.checkboxOption);
@@ -171,17 +171,20 @@ public void onClick(final View view) {
171171
return;
172172
}
173173

174-
final EditText text = new EditText(context);
175-
text.setText(((TextView) view).getText());
174+
EditText textView = new EditText(context);
175+
textView.setText(((TextView) view).getText());
176176
AlertDialog.Builder builder = new AlertDialog.Builder(context);
177-
builder.setView(text);
177+
builder.setView(textView);
178+
179+
@SuppressWarnings("ConstantConditions")
180+
final String text = textView.getText().toString();
178181

179182
switch (key) {
180183
case DeviceName:
181184
builder.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
182185
@Override
183186
public void onClick(DialogInterface dialogInterface, int i) {
184-
item.mDisplayValueString = text.getText().toString();
187+
item.mDisplayValueString = text;
185188
deviceInfo.DeviceName = item.mDisplayValueString;
186189
notifyDataSetChanged();
187190
}
@@ -191,7 +194,7 @@ public void onClick(DialogInterface dialogInterface, int i) {
191194
builder.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
192195
@Override
193196
public void onClick(DialogInterface dialogInterface, int i) {
194-
item.mDisplayValueString = text.getText().toString();
197+
item.mDisplayValueString = text;
195198
deviceInfo.HostName = item.mDisplayValueString;
196199
notifyDataSetChanged();
197200
}
@@ -201,7 +204,7 @@ public void onClick(DialogInterface dialogInterface, int i) {
201204
builder.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
202205
@Override
203206
public void onClick(DialogInterface dialogInterface, int i) {
204-
item.mDisplayValueString = text.getText().toString();
207+
item.mDisplayValueString = text;
205208
deviceInfo.UserName = item.mDisplayValueString;
206209
notifyDataSetChanged();
207210
}
@@ -211,29 +214,29 @@ public void onClick(DialogInterface dialogInterface, int i) {
211214
builder.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
212215
@Override
213216
public void onClick(DialogInterface dialogInterface, int i) {
214-
item.mDisplayValueString = text.getText().toString();
217+
item.mDisplayValueString = text;
215218
deviceInfo.Password = item.mDisplayValueString;
216219
notifyDataSetChanged();
217220
}
218221
});
219222
break;
220223
case ReceivePort:
221-
text.setInputType(InputType.TYPE_CLASS_NUMBER);
224+
textView.setInputType(InputType.TYPE_CLASS_NUMBER);
222225
builder.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
223226
@Override
224227
public void onClick(DialogInterface dialogInterface, int i) {
225-
item.mDisplayValueInt = Integer.valueOf(text.getText().toString());
228+
item.mDisplayValueInt = Integer.valueOf(text);
226229
deviceInfo.ReceivePort = item.mDisplayValueInt;
227230
notifyDataSetChanged();
228231
}
229232
});
230233
break;
231234
case SendPort:
232-
text.setInputType(InputType.TYPE_CLASS_NUMBER);
235+
textView.setInputType(InputType.TYPE_CLASS_NUMBER);
233236
builder.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
234237
@Override
235238
public void onClick(DialogInterface dialogInterface, int i) {
236-
item.mDisplayValueInt = Integer.valueOf(text.getText().toString());
239+
item.mDisplayValueInt = Integer.valueOf(text);
237240
deviceInfo.SendPort = item.mDisplayValueInt;
238241
notifyDataSetChanged();
239242
}

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

+10-13
Original file line numberDiff line numberDiff line change
@@ -37,27 +37,25 @@
3737
resToastText = R.string.crash_toast_text)
3838
public class NetpowerctrlApplication extends Application {
3939
public static NetpowerctrlApplication instance;
40-
private Handler mainThreadHandler = new Handler(Looper.getMainLooper());
40+
private final Handler mainThreadHandler = new Handler(Looper.getMainLooper());
4141

4242
private RuntimeDataController dataController = null;
4343
private int mDiscoverServiceRefCount = 0;
4444
private NetpowerctrlService mDiscoverService;
4545
private boolean mWaitForService;
46-
private ArrayList<ServiceReady> observersServiceReady = new ArrayList<ServiceReady>();
46+
private final ArrayList<ServiceReady> observersServiceReady = new ArrayList<ServiceReady>();
4747

4848
public boolean isServiceReady() {
4949
return (mDiscoverService != null);
5050
}
5151

5252
@SuppressWarnings("unused")
53-
public boolean registerServiceReadyObserver(ServiceReady o) {
53+
public void registerServiceReadyObserver(ServiceReady o) {
5454
if (!observersServiceReady.contains(o)) {
5555
observersServiceReady.add(o);
5656
if (mDiscoverService != null)
57-
o.onServiceReady(mDiscoverService);
58-
return true;
57+
o.onServiceReady();
5958
}
60-
return false;
6159
}
6260

6361
@SuppressWarnings("unused")
@@ -68,15 +66,14 @@ public void unregisterServiceReadyObserver(ServiceReady o) {
6866
private void notifyServiceReady() {
6967
Iterator<ServiceReady> it = observersServiceReady.iterator();
7068
while (it.hasNext()) {
71-
if (!it.next().onServiceReady(mDiscoverService))
69+
if (!it.next().onServiceReady())
7270
it.remove();
7371
}
7472
}
7573

7674
private void notifyServiceFinished() {
77-
Iterator<ServiceReady> it = observersServiceReady.iterator();
78-
while (it.hasNext()) {
79-
it.next().onServiceFinished();
75+
for (ServiceReady anObserversServiceReady : observersServiceReady) {
76+
anObserversServiceReady.onServiceFinished();
8077
}
8178
}
8279

@@ -101,8 +98,8 @@ public void run() {
10198
}, 180);
10299
}
103100

104-
private Handler stopServiceHandler = new Handler();
105-
private Runnable stopRunnable = new Runnable() {
101+
private final Handler stopServiceHandler = new Handler();
102+
private final Runnable stopRunnable = new Runnable() {
106103
@Override
107104
public void run() {
108105
try {
@@ -161,7 +158,7 @@ public void findDevices(final DeviceQueryResult callback) {
161158
/**
162159
* Defines callbacks for service binding, passed to bindService()
163160
*/
164-
private ServiceConnection mConnection = new ServiceConnection() {
161+
private final ServiceConnection mConnection = new ServiceConnection() {
165162

166163
@Override
167164
public void onServiceConnected(ComponentName className,

0 commit comments

Comments
 (0)