Skip to content

Commit 4479a4c

Browse files
author
David Graeff
committed
Tidy up icons. Add new plugin: WOL
1 parent 77fff9e commit 4479a4c

File tree

102 files changed

+935
-153
lines changed

Some content is hidden

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

102 files changed

+935
-153
lines changed

app/src/main/AndroidManifest.xml

+2-2
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@
112112
android:name=".main.EditActivity"
113113
android:configChanges="orientation|screenSize|keyboardHidden|layoutDirection"
114114
android:description="@string/shortcut_new_scene_desc"
115-
android:icon="@drawable/netpowerctrl"
115+
android:icon="@drawable/netpowerctrl_new"
116116
android:label="@string/shortcut_new_scene"
117117
android:theme="@style/Theme.StartTheme"
118118
android:windowSoftInputMode="stateHidden">
@@ -126,7 +126,7 @@
126126
android:name=".main.SelectExistingExecutableActivity"
127127
android:configChanges="orientation|screenSize|keyboardHidden|layoutDirection"
128128
android:description="@string/shortcut_existing_executable_desc"
129-
android:icon="@drawable/netpowerctrl"
129+
android:icon="@drawable/netpowerctrl_existing"
130130
android:label="@string/shortcut_existing_executable"
131131
android:launchMode="singleInstance"
132132
android:theme="@style/Theme.CustomLightThemeDialog"

app/src/main/java/oly/netpowerctrl/App.java

+16-18
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package oly.netpowerctrl;
22

33
import android.app.Application;
4-
import android.os.Build;
54
import android.os.Handler;
65

76
import org.acra.ACRA;
@@ -25,7 +24,7 @@
2524
public class App extends Application {
2625
static final boolean isDebugFlag = BuildConfig.BUILD_TYPE.equals("debug");
2726
public static App instance;
28-
public static boolean useErrorReporter = (Build.VERSION.SDK_INT <= Build.VERSION_CODES.KITKAT); // Lollipop acra does not work;
27+
//public static boolean useErrorReporter = (Build.VERSION.SDK_INT <= Build.VERSION_CODES.KITKAT); // Lollipop acra does not work;
2928
private final GuiThreadHandler mainThreadHandler = new GuiThreadHandler();
3029
private LifecycleHandler lifecycleHandler;
3130

@@ -76,23 +75,22 @@ public static void setErrorReportContentLogFile(String filename) {
7675
public void onCreate() {
7776
super.onCreate();
7877
LoadStoreIconData.onCreate(this);
79-
if (useErrorReporter) {
80-
ACRAConfiguration config = ACRA.getNewDefaultConfig(this);
81-
config.setFormUri(getString(R.string.acralyzer_http_url));
82-
config.setFormUriBasicAuthLogin(getString(R.string.acralyzer_http_login));
83-
config.setFormUriBasicAuthPassword(getString(R.string.acralyzer_http_pwd));
84-
config.setReportType(HttpSender.Type.JSON);
85-
config.setResToastText(R.string.crash_toast_text);
86-
config.setBuildConfigClass(BuildConfig.class);
87-
try {
88-
config.setMode(ReportingInteractionMode.TOAST);
89-
} catch (ACRAConfigurationException e) {
90-
e.printStackTrace();
91-
}
92-
config.setCustomReportContent(new ReportField[]{ReportField.REPORT_ID, ReportField.APP_VERSION_CODE, ReportField.APP_VERSION_NAME, ReportField.PACKAGE_NAME, ReportField.PHONE_MODEL, ReportField.ANDROID_VERSION, ReportField.BUILD, ReportField.BRAND, ReportField.PRODUCT, ReportField.TOTAL_MEM_SIZE, ReportField.AVAILABLE_MEM_SIZE, ReportField.CUSTOM_DATA, ReportField.STACK_TRACE, ReportField.USER_COMMENT, ReportField.USER_APP_START_DATE, ReportField.USER_CRASH_DATE, ReportField.USER_EMAIL, ReportField.IS_SILENT, ReportField.DEVICE_FEATURES, ReportField.SHARED_PREFERENCES, ReportField.THREAD_DETAILS});
93-
ACRA.setConfig(config);
94-
ACRA.init(this);
78+
79+
ACRAConfiguration config = ACRA.getNewDefaultConfig(this);
80+
config.setFormUri(getString(R.string.acralyzer_http_url));
81+
config.setFormUriBasicAuthLogin(getString(R.string.acralyzer_http_login));
82+
config.setFormUriBasicAuthPassword(getString(R.string.acralyzer_http_pwd));
83+
config.setReportType(HttpSender.Type.JSON);
84+
config.setResToastText(R.string.crash_toast_text);
85+
config.setBuildConfigClass(BuildConfig.class);
86+
try {
87+
config.setMode(ReportingInteractionMode.TOAST);
88+
} catch (ACRAConfigurationException e) {
89+
e.printStackTrace();
9590
}
91+
config.setCustomReportContent(new ReportField[]{ReportField.REPORT_ID, ReportField.APP_VERSION_CODE, ReportField.APP_VERSION_NAME, ReportField.PACKAGE_NAME, ReportField.PHONE_MODEL, ReportField.ANDROID_VERSION, ReportField.BUILD, ReportField.BRAND, ReportField.PRODUCT, ReportField.TOTAL_MEM_SIZE, ReportField.AVAILABLE_MEM_SIZE, ReportField.CUSTOM_DATA, ReportField.STACK_TRACE, ReportField.USER_COMMENT, ReportField.USER_APP_START_DATE, ReportField.USER_CRASH_DATE, ReportField.USER_EMAIL, ReportField.IS_SILENT, ReportField.DEVICE_FEATURES, ReportField.SHARED_PREFERENCES, ReportField.THREAD_DETAILS});
92+
ACRA.setConfig(config);
93+
ACRA.init(this);
9694

9795
lifecycleHandler = new LifecycleHandler();
9896
registerActivityLifecycleCallbacks(lifecycleHandler);

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

+9-11
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package oly.netpowerctrl.data;
22

3+
import android.app.Activity;
34
import android.content.Context;
45
import android.support.annotation.NonNull;
56
import android.support.annotation.Nullable;
@@ -12,7 +13,6 @@
1213
import oly.netpowerctrl.executables.ExecutableAndCommand;
1314
import oly.netpowerctrl.executables.onNameChangeResult;
1415
import oly.netpowerctrl.ioconnection.IOConnection;
15-
import oly.netpowerctrl.ioconnection.onNewIOConnection;
1616
import oly.netpowerctrl.network.onExecutionFinished;
1717

1818
/**
@@ -78,13 +78,7 @@ public void openConfigurationPage(Credentials credentials) {
7878
@Nullable
7979
abstract public Credentials createNewDefaultCredentials();
8080

81-
public boolean hasEditableCredentials() {
82-
return false;
83-
}
84-
85-
public boolean isNewIOConnectionAllowed(Credentials credentials) {
86-
return false;
87-
}
81+
public abstract boolean isNewIOConnectionAllowed(Credentials credentials);
8882

8983
/**
9084
* Provide credentials and then the plugin will call you back asynchronously with a new connection.
@@ -94,10 +88,14 @@ public boolean isNewIOConnectionAllowed(Credentials credentials) {
9488
* implementation. Otherwise you may show a dialog to the user and make him select the type of connection to create.
9589
*
9690
* @param credentials Credentials that identify a device.
97-
* @param callback The callback method with the new IOConnection.
91+
* @param activity The activity on which dialogs etc can be shown to select/create a connection.
9892
*/
99-
public void addNewIOConnection(@NonNull Credentials credentials, @NonNull onNewIOConnection callback) {
93+
public void addNewIOConnection(@NonNull Credentials credentials, @NonNull Activity activity) {
10094
}
10195

102-
public abstract boolean supportsRemoteRename();
96+
public abstract boolean supportProperty(Properties property);
97+
98+
public enum Properties {
99+
RemoteRename, EditableUsername, EditablePassword, ManuallyAddDevice
100+
}
103101
}

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

+15-19
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
import oly.netpowerctrl.network.UDPSend;
3636
import oly.netpowerctrl.plugin_anel.AnelPlugin;
3737
import oly.netpowerctrl.plugin_simpleudp.SimpleUDPPlugin;
38+
import oly.netpowerctrl.plugin_wol.WOLPlugin;
3839
import oly.netpowerctrl.status_bar.FavCollection;
3940
import oly.netpowerctrl.utils.Logging;
4041

@@ -112,10 +113,6 @@ public static DataService getService() {
112113
return mDiscoverService;
113114
}
114115

115-
public boolean isDataLoaded() {
116-
return observersOnDataLoaded.isDone();
117-
}
118-
119116
/**
120117
* Called by the asynchronous loading process after loading is done.
121118
*/
@@ -137,17 +134,6 @@ public IBinder onBind(Intent intent) {
137134
return null;
138135
}
139136

140-
/**
141-
* Called after an alarm is executed. If the service is not used anymore (weakHashMap empty),
142-
* then stop the service.
143-
*/
144-
public void checkStopAfterAlarm() {
145-
if (weakHashMap.size() == 0) {
146-
service_shutdown_reason = "StopAfterAlarm";
147-
App.getMainThreadHandler().sendEmptyMessageDelayed(GuiThreadHandler.SERVICE_DELAYED_EXIT, 2000);
148-
}
149-
}
150-
151137
/**
152138
* Startup is like this:
153139
* 1) Create anel plugin
@@ -185,6 +171,7 @@ public int onStartCommand(@Nullable final Intent intent, final int flags, final
185171
discoverExtensions();
186172
plugins.add(new AnelPlugin(this));
187173
plugins.add(new SimpleUDPPlugin(this));
174+
plugins.add(new WOLPlugin(this));
188175

189176
// Load all Devices, Scenes etc from disk.
190177
/**
@@ -249,11 +236,16 @@ public AbstractBasePlugin getPlugin(int position) {
249236
return plugins.get(position);
250237
}
251238

252-
public String[] pluginNames() {
253-
String[] ids = new String[plugins.size()];
239+
public String[] pluginNames(List<String> pluginIDs, FilterPlugin filterPlugin) {
240+
List<String> names = new ArrayList<>();
254241
for (int i = 0; i < plugins.size(); ++i)
255-
ids[i] = plugins.get(i).getLocalizedName();
256-
return ids;
242+
if (filterPlugin.accept(plugins.get(i))) {
243+
names.add(plugins.get(i).getLocalizedName());
244+
pluginIDs.add(plugins.get(i).getPluginID());
245+
}
246+
String[] t = new String[names.size()];
247+
names.toArray(t);
248+
return t;
257249
}
258250

259251
public AbstractBasePlugin getPlugin(String plugin_id) {
@@ -416,4 +408,8 @@ public void remove(Credentials credentials) {
416408
this.connections.remove(credentials);
417409
this.credentials.remove(credentials);
418410
}
411+
412+
public interface FilterPlugin {
413+
boolean accept(AbstractBasePlugin plugin);
414+
}
419415
}

app/src/main/java/oly/netpowerctrl/devices/CredentialsDialog.java

+22-4
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,9 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle sa
5050

5151
textView = (EditText) view.findViewById(R.id.device_username);
5252
textView.setText(credentials.userName);
53+
if (!credentials.getPlugin().supportProperty(AbstractBasePlugin.Properties.EditableUsername)) {
54+
textView.setVisibility(View.GONE);
55+
}
5356

5457
textView = (EditText) view.findViewById(R.id.device_password);
5558
textView.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD);
@@ -67,6 +70,11 @@ public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
6770
}
6871
});
6972

73+
if (!credentials.getPlugin().supportProperty(AbstractBasePlugin.Properties.EditablePassword)) {
74+
textView.setVisibility(View.GONE);
75+
c.setVisibility(View.GONE);
76+
}
77+
7078
return view;
7179
}
7280

@@ -88,14 +96,25 @@ public void onClick(View view) {
8896
textView = (EditText) getDialog().findViewById(R.id.device_password);
8997
password = (textView.getText().toString());
9098

91-
if (deviceName.trim().length() == 0 || userName.trim().length() == 0 || password.trim().length() == 0) {
99+
if (!credentials.getPlugin().supportProperty(AbstractBasePlugin.Properties.EditableUsername)) {
100+
textView.setVisibility(View.GONE);
101+
}
102+
103+
boolean needUser = credentials.getPlugin().supportProperty(AbstractBasePlugin.Properties.EditableUsername);
104+
boolean needPwd = credentials.getPlugin().supportProperty(AbstractBasePlugin.Properties.EditablePassword);
105+
106+
if (deviceName.trim().length() == 0 ||
107+
(needUser && userName.trim().length() == 0) ||
108+
(needPwd && password.trim().length() == 0)) {
92109
Toast.makeText(getActivity(), R.string.error_device_incomplete, Toast.LENGTH_SHORT).show();
93110
return;
94111
}
95112

96113
credentials.deviceName = deviceName;
97-
credentials.userName = userName;
98-
credentials.password = password;
114+
if (needUser)
115+
credentials.userName = userName;
116+
if (needPwd)
117+
credentials.password = password;
99118

100119
DataService.getService().addToConfiguredDevices(credentials);
101120
dismiss();
@@ -109,5 +128,4 @@ public void onClick(View view) {
109128
}).negativeAction(android.R.string.cancel);
110129
return dialog;
111130
}
112-
113131
}

app/src/main/java/oly/netpowerctrl/executables/Executable.java

+3-1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import java.util.Set;
1313
import java.util.TreeSet;
1414

15+
import oly.netpowerctrl.data.AbstractBasePlugin;
1516
import oly.netpowerctrl.data.DataService;
1617
import oly.netpowerctrl.devices.Credentials;
1718
import oly.netpowerctrl.ioconnection.IOConnectionsCollection;
@@ -138,7 +139,7 @@ public int getCurrentValueToggled() {
138139
public void setTitle(String title, @NonNull onNameChangeResult callback) {
139140
if (title.equals(this.title)) return;
140141

141-
if (credentials != null && credentials.getPlugin().supportsRemoteRename()) {
142+
if (credentials != null && credentials.getPlugin().supportProperty(AbstractBasePlugin.Properties.RemoteRename)) {
142143
callback.onNameChangeStart(this);
143144
credentials.getPlugin().setTitle(this, title, callback);
144145
} else
@@ -337,6 +338,7 @@ public Credentials getCredentials() {
337338
*/
338339
public void setCredentials(Credentials credentials, IOConnectionsCollection connectionsCollection) {
339340
this.credentials = credentials;
341+
this.deviceUID = credentials.getUid();
340342
updateCachedReachability(connectionsCollection.getReachableState(this));
341343
}
342344

app/src/main/java/oly/netpowerctrl/ioconnection/IOConnection.java

-2
Original file line numberDiff line numberDiff line change
@@ -236,8 +236,6 @@ public void resetChanged() {
236236
lastUsed = System.currentTimeMillis();
237237
}
238238

239-
public abstract int getDestinationPort();
240-
241239
public abstract String getProtocol();
242240

243241
public final boolean equals(IOConnection otherConnection) {

app/src/main/java/oly/netpowerctrl/ioconnection/IOConnectionFabric.java

+4
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import java.io.IOException;
88
import java.io.InputStreamReader;
99

10+
import oly.netpowerctrl.ioconnection.adapter.IOConnectionIP;
1011
import oly.netpowerctrl.utils.FactoryInterface;
1112

1213
/**
@@ -39,6 +40,9 @@ public IOConnection newInstance(FileInputStream fileInputStream) throws IOExcept
3940
case IOConnectionHTTP.PROTOCOL:
4041
ioConnection = new IOConnectionHTTP();
4142
break;
43+
case IOConnectionIP.PROTOCOL:
44+
ioConnection = new IOConnectionIP();
45+
break;
4246
default:
4347
throw new ClassNotFoundException("Unexpected connection_type: " + name);
4448
}

app/src/main/java/oly/netpowerctrl/ioconnection/IOConnectionHTTP.java

-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ protected void read(@NonNull JsonReader reader, String name) throws IOException
4141
}
4242
}
4343

44-
@Override
4544
public int getDestinationPort() {
4645
return PortHttp;
4746
}

app/src/main/java/oly/netpowerctrl/ioconnection/IOConnectionHttpDialog.java

+3-2
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,6 @@
2828
import oly.netpowerctrl.ui.FragmentUtils;
2929
import oly.netpowerctrl.ui.ThemeHelper;
3030

31-
;
32-
3331
/**
3432
* This dialog allows the user to setup a new
3533
*/
@@ -58,7 +56,10 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle sa
5856
progressView = (ProgressView) rootView.findViewById(R.id.connection_progressbar);
5957
btnTest = (Button) rootView.findViewById(R.id.btnTest);
6058
newHost = (EditText) rootView.findViewById(R.id.device_host);
59+
newHost.setText(ioConnection.hostName);
6160
newPort = (EditText) rootView.findViewById(R.id.device_http_port);
61+
if (ioConnection.getDestinationPort() != -1)
62+
newPort.setText(String.valueOf(ioConnection.getDestinationPort()));
6263
connectionStateImage = ((ImageView) rootView.findViewById(R.id.connection_reachable));
6364
connectionStateImage.setVisibility(View.VISIBLE);
6465
connectionStateImage.setImageResource(android.R.drawable.presence_offline);

0 commit comments

Comments
 (0)