Skip to content

Commit 6a12559

Browse files
author
davidgraeff
committed
Widget update improved, create scene from all current outlet states
1 parent 1955fae commit 6a12559

File tree

12 files changed

+483
-245
lines changed

12 files changed

+483
-245
lines changed

.idea/workspace.xml

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

app/app.iml

Lines changed: 17 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,10 @@
33
<component name="FacetManager">
44
<facet type="android" name="Android">
55
<configuration>
6-
<option name="SELECTED_BUILD_VARIANT" value="debug" />
7-
<option name="ASSEMBLE_TASK_NAME" value="assembleDebug" />
8-
<option name="COMPILE_JAVA_TASK_NAME" value="compileDebugJava" />
9-
<option name="ASSEMBLE_TEST_TASK_NAME" value="assembleDebugTest" />
10-
<option name="SOURCE_GEN_TASK_NAME" value="generateDebugSources" />
6+
<option name="SELECTED_BUILD_VARIANT" value="release" />
7+
<option name="ASSEMBLE_TASK_NAME" value="assembleRelease" />
8+
<option name="COMPILE_JAVA_TASK_NAME" value="compileReleaseJava" />
9+
<option name="SOURCE_GEN_TASK_NAME" value="generateReleaseSources" />
1110
<option name="ALLOW_USER_CONFIGURATION" value="false" />
1211
<option name="MANIFEST_FILE_RELATIVE_PATH" value="/src/main/AndroidManifest.xml" />
1312
<option name="RES_FOLDER_RELATIVE_PATH" value="/src/main/res" />
@@ -22,26 +21,21 @@
2221
</facet>
2322
</component>
2423
<component name="NewModuleRootManager" inherit-compiler-output="false">
25-
<output url="file://$MODULE_DIR$/build/classes/debug" />
24+
<output url="file://$MODULE_DIR$/build/classes/release" />
2625
<exclude-output />
2726
<content url="file://$MODULE_DIR$">
28-
<sourceFolder url="file://$MODULE_DIR$/build/source/r/debug" isTestSource="false" generated="true" />
29-
<sourceFolder url="file://$MODULE_DIR$/build/source/aidl/debug" isTestSource="false" generated="true" />
30-
<sourceFolder url="file://$MODULE_DIR$/build/source/buildConfig/debug" isTestSource="false" generated="true" />
31-
<sourceFolder url="file://$MODULE_DIR$/build/source/rs/debug" isTestSource="false" generated="true" />
32-
<sourceFolder url="file://$MODULE_DIR$/build/res/rs/debug" type="java-resource" />
33-
<sourceFolder url="file://$MODULE_DIR$/build/source/r/test/debug" isTestSource="true" />
34-
<sourceFolder url="file://$MODULE_DIR$/build/source/aidl/test/debug" isTestSource="true" />
35-
<sourceFolder url="file://$MODULE_DIR$/build/source/buildConfig/test/debug" isTestSource="true" />
36-
<sourceFolder url="file://$MODULE_DIR$/build/source/rs/test/debug" isTestSource="true" />
37-
<sourceFolder url="file://$MODULE_DIR$/build/res/rs/test/debug" type="java-test-resource" />
38-
<sourceFolder url="file://$MODULE_DIR$/src/debug/aidl" isTestSource="false" />
39-
<sourceFolder url="file://$MODULE_DIR$/src/debug/assets" isTestSource="false" />
40-
<sourceFolder url="file://$MODULE_DIR$/src/debug/java" isTestSource="false" />
41-
<sourceFolder url="file://$MODULE_DIR$/src/debug/jni" isTestSource="false" />
42-
<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" />
27+
<sourceFolder url="file://$MODULE_DIR$/build/source/r/release" isTestSource="false" generated="true" />
28+
<sourceFolder url="file://$MODULE_DIR$/build/source/aidl/release" isTestSource="false" generated="true" />
29+
<sourceFolder url="file://$MODULE_DIR$/build/source/buildConfig/release" isTestSource="false" generated="true" />
30+
<sourceFolder url="file://$MODULE_DIR$/build/source/rs/release" isTestSource="false" generated="true" />
31+
<sourceFolder url="file://$MODULE_DIR$/build/res/rs/release" type="java-resource" />
32+
<sourceFolder url="file://$MODULE_DIR$/src/release/aidl" isTestSource="false" />
33+
<sourceFolder url="file://$MODULE_DIR$/src/release/assets" isTestSource="false" />
34+
<sourceFolder url="file://$MODULE_DIR$/src/release/java" isTestSource="false" />
35+
<sourceFolder url="file://$MODULE_DIR$/src/release/jni" isTestSource="false" />
36+
<sourceFolder url="file://$MODULE_DIR$/src/release/rs" isTestSource="false" />
37+
<sourceFolder url="file://$MODULE_DIR$/src/release/res" type="java-resource" />
38+
<sourceFolder url="file://$MODULE_DIR$/src/release/resources" type="java-resource" />
4539
<sourceFolder url="file://$MODULE_DIR$/src/main/aidl" isTestSource="false" />
4640
<sourceFolder url="file://$MODULE_DIR$/src/main/assets" isTestSource="false" />
4741
<sourceFolder url="file://$MODULE_DIR$/src/main/java" isTestSource="false" />

app/src/main/AndroidManifest.xml

Lines changed: 3 additions & 3 deletions
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="19"
5-
android:versionName="2.1">
4+
android:versionCode="20"
5+
android:versionName="2.2">
66

77
<!-- Api level 14: Android 4.0 15. Dezember 2011 -->
88
<!-- Api level 16: Android 4.1 27. Juni 2012 -->
@@ -33,7 +33,7 @@
3333
android:label="@string/app_name"
3434
android:launchMode="singleTask"
3535
android:configChanges="orientation|screenSize|keyboardHidden|layoutDirection">
36-
<intent-filter>
36+
<intent-filter>
3737
<action android:name="android.intent.action.MAIN" />
3838
<category android:name="android.intent.category.LAUNCHER" />
3939
</intent-filter>

app/src/main/java/oly/netpowerctrl/listadapter/CreateSceneOutletsAdapter.java

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,8 @@ public static CreateSceneOutletsAdapter createByConfiguredDevices(Context contex
6060
// Enumerate all configured devices and outlets and create SceneOutlets
6161
for (DeviceInfo device : NetpowerctrlApplication.instance.configuredDevices) {
6262
for (OutletInfo oi : device.Outlets) {
63+
if (oi.Disabled)
64+
continue;
6365
oi.device = device;
6466
// Create SceneOutlet and set state to Toggle
6567
SceneOutlet so = SceneOutlet.fromOutletInfo(oi, false);
@@ -75,6 +77,8 @@ public static CreateSceneOutletsAdapter createByOutletCommands(Context context,
7577
for (DeviceInfo device : NetpowerctrlApplication.instance.configuredDevices) {
7678
for (OutletInfo oi : device.Outlets) {
7779
oi.device = device;
80+
if (oi.Disabled)
81+
continue;
7882
SceneOutlet c = SceneOutlet.fromOutletInfo(oi, false);
7983
int i = commands.indexOf(c);
8084
if (i != -1) {
@@ -106,9 +110,10 @@ public long getItemId(int position) {
106110
}
107111

108112
public View getView(int position, View convertView, ViewGroup parent) {
109-
113+
boolean newValue = false;
110114
if (convertView == null) {
111115
convertView = inflater.inflate(R.layout.create_scene_outlet_list_item, null);
116+
newValue = true;
112117
}
113118
SceneOutlet command = all_outlets.get(position);
114119
assert convertView != null;
@@ -140,11 +145,15 @@ public View getView(int position, View convertView, ViewGroup parent) {
140145
a.setAnimationListener(new AnimationListenerWithRadioGroup(r, false));
141146
r.startAnimation(a);
142147
} else if (r.getVisibility() == View.INVISIBLE && command.enabled) {
143-
r.clearAnimation();
144-
Animation a = AnimationUtils.loadAnimation(context, R.anim.animate_in);
145-
assert a != null;
146-
a.setAnimationListener(new AnimationListenerWithRadioGroup(r, true));
147-
r.startAnimation(a);
148+
if (!newValue) {
149+
r.clearAnimation();
150+
Animation a = AnimationUtils.loadAnimation(context, R.anim.animate_in);
151+
assert a != null;
152+
a.setAnimationListener(new AnimationListenerWithRadioGroup(r, true));
153+
r.startAnimation(a);
154+
} else {
155+
r.setVisibility(View.VISIBLE);
156+
}
148157
}
149158
r.check((command.state == 0) ? R.id.radio0 : ((command.state == 1) ? R.id.radio1 : R.id.radio2));
150159
return convertView;

app/src/main/java/oly/netpowerctrl/listadapter/ScenesListAdapter.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ public void addScene(Scene data) {
9494
return;
9595

9696
data.updateDeviceAndOutletLinks();
97+
data.sceneDetails = data.buildDetails();
9798

9899
int i = scenes.indexOf(data);
99100
if (i != -1) {

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

Lines changed: 56 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@
1010
import android.net.Uri;
1111
import android.os.Build;
1212
import android.os.Bundle;
13+
import android.util.Base64;
14+
15+
import java.io.UnsupportedEncodingException;
1316

1417
import oly.netpowerctrl.R;
1518

@@ -23,35 +26,62 @@ public Dialog onCreateDialog(Bundle savedInstanceState) {
2326
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
2427
builder.setIcon(R.drawable.netpowerctrl);
2528
builder.setTitle(R.string.app_name);
26-
builder.setItems(R.array.feedbackOptions, new DialogInterface.OnClickListener() {
29+
30+
// Support this app by a donations.
31+
String[] items = getResources().getStringArray(R.array.feedbackOptions);
32+
try {
33+
items[items.length - 1] = items[items.length - 1].replace("%s",
34+
new String(Base64.decode("UGF5UGFs", Base64.DEFAULT), "UTF-8"));
35+
} catch (Exception ignored) {
36+
}
37+
38+
builder.setItems(items, new DialogInterface.OnClickListener() {
2739
public void onClick(DialogInterface dialog, int which) {
28-
if (which == 0) { // mail
29-
@SuppressWarnings("ConstantConditions")
30-
ApplicationInfo info = getActivity().getApplicationContext().getApplicationInfo();
31-
PackageManager pm = getActivity().getApplicationContext().getPackageManager();
32-
Intent intent = new Intent(Intent.ACTION_SEND);
33-
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
34-
intent.putExtra(Intent.EXTRA_EMAIL, new String[]{"[email protected]"});
35-
try {
36-
intent.putExtra(Intent.EXTRA_SUBJECT, info.loadLabel(pm).toString() + "(" + pm.getPackageInfo(info.packageName, 0).versionName + ")" + " Contact Form | Device: " + Build.MANUFACTURER + " " + Build.DEVICE + "(" + Build.MODEL + ") API: " + Build.VERSION.SDK_INT);
37-
} catch (PackageManager.NameNotFoundException ignored) {
40+
switch (which) {
41+
case 0: { // mail
42+
@SuppressWarnings("ConstantConditions")
43+
ApplicationInfo info = getActivity().getApplicationContext().getApplicationInfo();
44+
PackageManager pm = getActivity().getApplicationContext().getPackageManager();
45+
Intent intent = new Intent(Intent.ACTION_SEND);
46+
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
47+
intent.putExtra(Intent.EXTRA_EMAIL, new String[]{"[email protected]"});
48+
try {
49+
intent.putExtra(Intent.EXTRA_SUBJECT, info.loadLabel(pm).toString() + "(" + pm.getPackageInfo(info.packageName, 0).versionName + ")" + " Contact Form | Device: " + Build.MANUFACTURER + " " + Build.DEVICE + "(" + Build.MODEL + ") API: " + Build.VERSION.SDK_INT);
50+
} catch (PackageManager.NameNotFoundException ignored) {
51+
}
52+
intent.setType("plain/html");
53+
getActivity().startActivity(intent);
54+
}
55+
break;
56+
case 1: { // bugtracker
57+
@SuppressWarnings("ConstantConditions")
58+
Intent browse = new Intent(Intent.ACTION_VIEW, Uri.parse("https://github.com/davidgraeff/Android-NetPowerctrl/issues"));
59+
getActivity().startActivity(browse);
3860
}
39-
intent.setType("plain/html");
40-
getActivity().startActivity(intent);
41-
} else if (which == 1) { // bugtracker
42-
@SuppressWarnings("ConstantConditions")
43-
Intent browse = new Intent(Intent.ACTION_VIEW, Uri.parse("https://github.com/davidgraeff/Android-NetPowerctrl/issues"));
44-
getActivity().startActivity(browse);
45-
} else if (which == 2) {
46-
@SuppressWarnings("ConstantConditions")
47-
Intent browse = new Intent(Intent.ACTION_VIEW, Uri.parse("https://github.com/davidgraeff/Android-NetPowerctrl"));
48-
getActivity().startActivity(browse);
49-
} else if (which == 3) {
50-
@SuppressWarnings("ConstantConditions")
51-
Intent browse = new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=" + getActivity().getPackageName()));
52-
getActivity().startActivity(browse);
61+
break;
62+
case 2: {
63+
@SuppressWarnings("ConstantConditions")
64+
Intent browse = new Intent(Intent.ACTION_VIEW, Uri.parse("https://github.com/davidgraeff/Android-NetPowerctrl"));
65+
getActivity().startActivity(browse);
66+
}
67+
break;
68+
case 3: {
69+
@SuppressWarnings("ConstantConditions")
70+
Intent browse = new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=" + getActivity().getPackageName()));
71+
getActivity().startActivity(browse);
72+
}
73+
break;
74+
case 4: {
75+
String p1 = "aHR0cHM6Ly93d3cucGF5cGFsLmNvbS9jZ2ktYmluL3dlYnNjcj9jbWQ9X3MteGNsaWNrJmhvc3RlZF9idXR0b25faWQ9OTNUQUFUSkIzV0pGMg==";
76+
try {
77+
String text = new String(Base64.decode(p1, Base64.DEFAULT), "UTF-8");
78+
Intent browse = new Intent(Intent.ACTION_VIEW, Uri.parse(text));
79+
getActivity().startActivity(browse);
80+
} catch (UnsupportedEncodingException ignored) {
81+
}
82+
}
83+
break;
5384
}
54-
5585
}
5686
});
5787

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ public void onCreate() {
165165
public void run() {
166166
Intent intent = new Intent(instance, NetpowerctrlService.class);
167167
startService(intent);
168-
bindService(intent, mConnection, Context.BIND_AUTO_CREATE);
168+
bindService(intent, mConnection, Context.BIND_AUTO_CREATE);
169169

170170
// Listen for wifi changes
171171
IntentFilter filter = new IntentFilter();

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

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323
import oly.netpowerctrl.anelservice.DeviceUpdateStateOrTimeout;
2424
import oly.netpowerctrl.datastructure.DeviceInfo;
2525
import oly.netpowerctrl.datastructure.OutletInfo;
26+
import oly.netpowerctrl.datastructure.Scene;
27+
import oly.netpowerctrl.datastructure.SceneOutlet;
2628
import oly.netpowerctrl.dragdrop.DragDropEnabled;
2729
import oly.netpowerctrl.dragdrop.DragListener;
2830
import oly.netpowerctrl.dragdrop.DragNDropListView;
@@ -115,6 +117,37 @@ public void onDeviceQueryFinished(int timeout_devices) {
115117
});
116118
return true;
117119
}
120+
case R.id.menu_add_scene:
121+
//noinspection ConstantConditions
122+
AlertDialog.Builder alert = new AlertDialog.Builder(getActivity());
123+
124+
alert.setTitle(getResources().getString(R.string.outlet_to_scene_title));
125+
alert.setMessage(getResources().getString(R.string.outlet_to_scene_message));
126+
127+
final EditText input = new EditText(alert.getContext());
128+
input.setText("");
129+
alert.setView(input);
130+
131+
alert.setPositiveButton(getResources().getString(android.R.string.ok), new DialogInterface.OnClickListener() {
132+
public void onClick(DialogInterface dialog, int whichButton) {
133+
Scene og = new Scene();
134+
og.sceneName = input.getText().toString();
135+
if (og.sceneName.trim().isEmpty())
136+
return;
137+
for (int i = 0; i < adapter.getCount(); ++i) {
138+
og.add(SceneOutlet.fromOutletInfo(adapter.getItem(i), true));
139+
}
140+
NetpowerctrlActivity.instance.getScenesAdapter().addScene(og);
141+
}
142+
});
143+
144+
alert.setNegativeButton(getResources().getString(android.R.string.cancel), new DialogInterface.OnClickListener() {
145+
public void onClick(DialogInterface dialog, int whichButton) {
146+
}
147+
});
148+
149+
alert.show();
150+
return true;
118151
case R.id.menu_showhidden: {
119152
adapter.setShowHidden(true);
120153
//noinspection ConstantConditions
@@ -188,7 +221,7 @@ public boolean onMenuItemClick(MenuItem menuItem) {
188221
AlertDialog.Builder alert = new AlertDialog.Builder(getActivity());
189222

190223
alert.setTitle(getResources().getString(R.string.outlet_rename_title));
191-
alert.setMessage(getResources().getString(R.string.outlet_rename_message).replaceFirst("%s", oi.getDeviceDescription()));
224+
alert.setMessage(getResources().getString(R.string.outlet_rename_message, oi.getDeviceDescription()));
192225

193226
final EditText input = new EditText(alert.getContext());
194227
input.setText(oi.getDescription());

app/src/main/java/oly/netpowerctrl/widget/WidgetUpdateService.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import android.widget.RemoteViews;
1515

1616
import oly.netpowerctrl.R;
17+
import oly.netpowerctrl.anelservice.DeviceQuery;
1718
import oly.netpowerctrl.anelservice.DeviceUpdate;
1819
import oly.netpowerctrl.anelservice.DeviceUpdateStateOrTimeout;
1920
import oly.netpowerctrl.anelservice.NetpowerctrlService;
@@ -153,7 +154,10 @@ public void onServiceReady(NetpowerctrlService mDiscoverService) {
153154
}
154155

155156
allWidgets.append(appWidgetId, new DeviceInfoOutletNumber(di, outlet.outletNumber));
156-
onDeviceUpdated(di);
157+
if (di.updated)
158+
onDeviceUpdated(di);
159+
else
160+
new DeviceQuery(WidgetUpdateService.this, di);
157161
}
158162

159163
}

app/src/main/res/menu/outlets.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,12 @@
66
android:showAsAction="always"
77
android:icon="@drawable/ic_menu_refresh" />
88

9+
<item
10+
android:id="@+id/menu_add_scene"
11+
android:title="@string/menu_add_scene"
12+
android:showAsAction="ifRoom"
13+
android:icon="@drawable/ic_menu_add" />
14+
915
<item
1016
android:id="@+id/menu_showdevicename"
1117
android:title="@string/menu_showdevicename"

0 commit comments

Comments
 (0)