Skip to content

Commit 221e029

Browse files
author
davidgraeff
committed
Notify on shortcut click, if option is set
1 parent 2e7fd29 commit 221e029

File tree

12 files changed

+265
-214
lines changed

12 files changed

+265
-214
lines changed

.idea/workspace.xml

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

app/src/main/AndroidManifest.xml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<!-- Api level 16: Android 4.1 27. Juni 2012 -->
88
<uses-sdk
99
android:minSdkVersion="16"
10-
android:targetSdkVersion="17" />
10+
android:targetSdkVersion="19" />
1111

1212
<uses-permission android:name="android.permission.INTERNET" />
1313
<uses-permission android:name="android.permission.NFC" />
@@ -60,6 +60,8 @@
6060
<activity
6161
android:name="oly.netpowerctrl.widget.WidgetConfig"
6262
android:label="@string/app_name"
63+
android:description="@string/app_name_shortcut_desc"
64+
android:icon="@drawable/widget"
6365
android:theme="@style/Theme.CustomLightTheme">
6466
<intent-filter>
6567
<action android:name="android.appwidget.action.APPWIDGET_CONFIGURE" />

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

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
import android.content.Context;
44
import android.graphics.Typeface;
5-
import android.util.Log;
65
import android.view.LayoutInflater;
76
import android.view.View;
87
import android.view.ViewGroup;
@@ -24,11 +23,8 @@
2423
import oly.netpowerctrl.utils.ListItemMenu;
2524

2625
public class CreateSceneOutletsAdapter extends BaseAdapter implements ListAdapter, View.OnClickListener {
27-
private final Animation slideinleft;
28-
private final Animation slideinright;
2926
private final Context context;
3027
private List<SceneOutlet> all_outlets;
31-
private List<Boolean> running = new ArrayList<Boolean>();
3228
private LayoutInflater inflater;
3329
private ListItemMenu listItemMenu = null;
3430

@@ -69,7 +65,6 @@ public static CreateSceneOutletsAdapter createByConfiguredDevices(Context contex
6965
SceneOutlet so = SceneOutlet.fromOutletInfo(oi, false);
7066
so.state = SceneOutlet.ON;
7167
o.all_outlets.add(so);
72-
o.running.add(false);
7368
}
7469
}
7570
return o;
@@ -96,8 +91,6 @@ private CreateSceneOutletsAdapter(Context context) {
9691
this.context = context;
9792
inflater = LayoutInflater.from(context);
9893
all_outlets = new ArrayList<SceneOutlet>();
99-
slideinleft = AnimationUtils.loadAnimation(context, R.anim.animate_in);
100-
slideinright = AnimationUtils.loadAnimation(context, R.anim.animate_out);
10194
}
10295

10396
public int getCount() {
@@ -116,10 +109,9 @@ public View getView(int position, View convertView, ViewGroup parent) {
116109

117110
if (convertView == null) {
118111
convertView = inflater.inflate(R.layout.create_scene_outlet_list_item, null);
119-
assert convertView != null;
120-
RadioGroup r = (RadioGroup) convertView.findViewById(R.id.radioGroup);
121112
}
122113
SceneOutlet command = all_outlets.get(position);
114+
assert convertView != null;
123115
TextView tv = (TextView) convertView.findViewById(R.id.outlet_list_text);
124116
tv.setOnClickListener(this);
125117
tv.setText(command.description);
@@ -144,11 +136,13 @@ public View getView(int position, View convertView, ViewGroup parent) {
144136
if (r.getVisibility() == View.VISIBLE && !command.enabled) {
145137
r.clearAnimation();
146138
Animation a = AnimationUtils.loadAnimation(context, R.anim.animate_out);
139+
assert a != null;
147140
a.setAnimationListener(new AnimationListenerWithRadioGroup(r, false));
148141
r.startAnimation(a);
149142
} else if (r.getVisibility() == View.INVISIBLE && command.enabled) {
150143
r.clearAnimation();
151144
Animation a = AnimationUtils.loadAnimation(context, R.anim.animate_in);
145+
assert a != null;
152146
a.setAnimationListener(new AnimationListenerWithRadioGroup(r, true));
153147
r.startAnimation(a);
154148
}
@@ -172,9 +166,7 @@ public void onClick(View view) {
172166
int position = (Integer) view.getTag();
173167
SceneOutlet info = all_outlets.get(position);
174168
int buttonId = view.getId();
175-
int sel = (buttonId == R.id.radio0) ? 0 : ((buttonId == R.id.radio1) ? 1 : 2);
176-
Log.w("RADIO", "SEL" + Integer.valueOf(sel).toString());
177-
info.state = sel; //1:off;2:on;3:toggle
169+
info.state = (buttonId == R.id.radio0) ? 0 : ((buttonId == R.id.radio1) ? 1 : 2); //1:off;2:on;3:toggle
178170
if (listItemMenu != null)
179171
listItemMenu.onMenuItemClicked(view, position);
180172
}

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,12 @@ public void run() {
100100
}
101101
};
102102

103+
@Override
104+
protected void onDestroy() {
105+
super.onDestroy();
106+
pluginController.destroy();
107+
}
108+
103109
@Override
104110
protected void onCreate(Bundle savedInstanceState) {
105111
instance = this;

app/src/main/java/oly/netpowerctrl/plugins/PluginController.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,10 @@ public PluginController(Context context, DrawerAdapter drawerAdapter) {
6161
mDrawerAdapter = drawerAdapter;
6262
}
6363

64+
public void destroy() {
65+
context.unregisterReceiver(onBroadcast);
66+
}
67+
6468
private void removePlugin() {
6569

6670
}

app/src/main/java/oly/netpowerctrl/shortcut/ShortcutCreatorActivity.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ public class ShortcutCreatorActivity extends Activity implements ListItemMenu {
3030
public static final String RESULT_SCENE = "commands";
3131
private CreateSceneOutletsAdapter adpOutlets = null;
3232
private Switch show_mainWindow;
33+
private Switch enable_feedback;
3334
private EditText shortcutName;
3435
private final Context that = this;
3536
private Scene og;
@@ -42,6 +43,8 @@ protected void onCreate(final Bundle savedInstanceState) {
4243
setContentView(R.layout.create_scene_activity);
4344

4445
show_mainWindow = (Switch) findViewById(R.id.shortcut_show_mainwindow);
46+
enable_feedback = (Switch) findViewById(R.id.shortcut_enable_feedback);
47+
4548
shortcutName = (EditText) findViewById(R.id.shortcut_name);
4649
shortcutName.addTextChangedListener(new TextWatcher() {
4750
@Override
@@ -90,6 +93,7 @@ public void afterTextChanged(Editable editable) {
9093

9194
if (isForGroups) {
9295
show_mainWindow.setVisibility(View.GONE);
96+
enable_feedback.setVisibility(View.GONE);
9397
if (isLoaded)
9498
setTitle(R.string.title_scene_edit);
9599
else
@@ -112,7 +116,7 @@ public void onClick(View v) {
112116
og.sceneName = shortcutName.getText().toString();
113117
if (og.sceneName.isEmpty() || og.length() == 0)
114118
return;
115-
Intent extra = Shortcuts.createShortcutExecutionIntent(that, og, show_mainWindow.isChecked());
119+
Intent extra = Shortcuts.createShortcutExecutionIntent(that, og, show_mainWindow.isChecked(), enable_feedback.isChecked());
116120
// Return result
117121
setResult(RESULT_OK, Shortcuts.createShortcut(that, extra, og.sceneName));
118122
finish();

app/src/main/java/oly/netpowerctrl/shortcut/ShortcutExecutionActivity.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,12 @@ protected void onCreate(final Bundle savedInstanceState) {
8080
Intent mainIt = new Intent(this, NetpowerctrlActivity.class);
8181
startActivity(mainIt);
8282
}
83+
84+
if (extra.getBoolean("enable_feedback")) {
85+
//noinspection ConstantConditions
86+
Toast.makeText(this,
87+
this.getString(R.string.scene_executed, g.sceneName), Toast.LENGTH_SHORT).show();
88+
}
8389
}
8490

8591
@Override

app/src/main/java/oly/netpowerctrl/shortcut/Shortcuts.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@
1212
public class Shortcuts {
1313
static public Intent createShortcutExecutionIntent(Context context,
1414
Scene og,
15-
boolean show_mainWindow) {
15+
boolean show_mainWindow,
16+
boolean enable_feedback) {
1617
if (og.length() == 0) {
1718
return null;
1819
}
@@ -27,6 +28,10 @@ static public Intent createShortcutExecutionIntent(Context context,
2728
shortcutIntent.putExtra("show_mainWindow", true);
2829
}
2930

31+
if (enable_feedback) {
32+
shortcutIntent.putExtra("enable_feedback", true);
33+
}
34+
3035
return shortcutIntent;
3136
}
3237

app/src/main/res/anim/animate_out.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<set xmlns:android="http://schemas.android.com/apk/res/android"
2-
android:interpolator="@android:anim/bounce_interpolator">
2+
android:interpolator="@android:anim/accelerate_interpolator">
33

44
<translate
55
android:duration="500"

app/src/main/res/layout/create_scene_activity.xml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,15 @@
2323
android:paddingLeft="16dip"
2424
android:text="@string/shortcut_show_mainwindow" />
2525

26+
<Switch
27+
android:id="@+id/shortcut_enable_feedback"
28+
android:layout_width="match_parent"
29+
android:layout_height="wrap_content"
30+
android:layout_marginBottom="5dp"
31+
android:layout_marginTop="5dp"
32+
android:paddingLeft="16dip"
33+
android:text="@string/shortcut_enable_feedback" />
34+
2635
<LinearLayout
2736
android:paddingLeft="16dip"
2837
android:layout_width="match_parent"

0 commit comments

Comments
 (0)