diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml
index 64b49a5..cdd2be3 100644
--- a/app/src/main/AndroidManifest.xml
+++ b/app/src/main/AndroidManifest.xml
@@ -11,6 +11,50 @@
android:theme="@style/AppTheme"
tools:replace="android:icon, android:label, android:theme, android:name">
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
0)
+ holder.switch_battery_level.setText("Usage: " + mExtendedStatusInfo.getUsage());
if (mExtendedStatusInfo.getCounterToday() != null && mExtendedStatusInfo.getCounterToday().length() > 0)
holder.switch_battery_level.append(" Today: " + mExtendedStatusInfo.getCounterToday());
+ if (mExtendedStatusInfo.getCounter() != null && mExtendedStatusInfo.getCounter().length() > 0 &&
+ !mExtendedStatusInfo.getCounter().equals(mExtendedStatusInfo.getData()))
+ holder.switch_battery_level.append(" Total: " + mExtendedStatusInfo.getCounter());
- Picasso.with(context).load(domoticz.getDrawableIcon(mExtendedStatusInfo.getTypeImg(), mExtendedStatusInfo.getSwitchType(), mExtendedStatusInfo.getStatusBoolean())).into(holder.iconRow);
+ Picasso.with(context).load(domoticz.getDrawableIcon(mExtendedStatusInfo.getTypeImg(), mExtendedStatusInfo.getType(), mExtendedStatusInfo.getStatusBoolean())).into(holder.iconRow);
holder.iconRow.setAlpha(1f);
if (!mExtendedStatusInfo.getStatusBoolean())
holder.iconRow.setAlpha(0.5f);
diff --git a/app/src/main/java/nl/hnogames/domoticz/Adapters/UtilityAdapter.java b/app/src/main/java/nl/hnogames/domoticz/Adapters/UtilityAdapter.java
index ab03a1f..bb3dfd5 100644
--- a/app/src/main/java/nl/hnogames/domoticz/Adapters/UtilityAdapter.java
+++ b/app/src/main/java/nl/hnogames/domoticz/Adapters/UtilityAdapter.java
@@ -166,8 +166,13 @@ public void onClick(View view) {
holder.data.append(": " + mUtilitiesInfo.getData());
holder.hardware.append(": " + mUtilitiesInfo.getHardwareName());
+ if(mUtilitiesInfo.getUsage()!=null && mUtilitiesInfo.getUsage().length()>0)
+ holder.data.setText("Usage: " + mUtilitiesInfo.getUsage());
if (mUtilitiesInfo.getCounterToday() != null && mUtilitiesInfo.getCounterToday().length() > 0)
holder.data.append(" Today: " + mUtilitiesInfo.getCounterToday());
+ if (mUtilitiesInfo.getCounter() != null && mUtilitiesInfo.getCounter().length() > 0 &&
+ !mUtilitiesInfo.getCounter().equals(mUtilitiesInfo.getData()))
+ holder.data.append(" Total: " + mUtilitiesInfo.getCounter());
holder.dayButton.setId(mUtilitiesInfo.getIdx());
holder.dayButton.setOnClickListener(new View.OnClickListener() {
diff --git a/app/src/main/java/nl/hnogames/domoticz/Containers/DevicesInfo.java b/app/src/main/java/nl/hnogames/domoticz/Containers/DevicesInfo.java
index 279b9c5..7ed4010 100644
--- a/app/src/main/java/nl/hnogames/domoticz/Containers/DevicesInfo.java
+++ b/app/src/main/java/nl/hnogames/domoticz/Containers/DevicesInfo.java
@@ -27,37 +27,39 @@
import org.json.JSONException;
import org.json.JSONObject;
-public class DevicesInfo {
+public class DevicesInfo implements Comparable {
private final String UNKNOWN = "Unknown";
private final String TAG = DevicesInfo.class.getSimpleName();
- JSONObject jsonObject;
- boolean timers;
- int idx;
- String Name;
- String LastUpdate;
- long setPoint;
- String Type;
- String SubType;
- int Favorite;
- int HardwareID;
- String HardwareName;
- String TypeImg;
- String PlanID;
- int batteryLevel;
- int maxDimLevel;
- int signalLevel;
- String status;
- int level;
- int switchTypeVal;
- String switchType;
- String CounterToday;
- String Data;
- String Timers;
- boolean statusBoolean;
- boolean isProtected;
-
- public DevicesInfo(JSONObject row) throws JSONException {
+ private JSONObject jsonObject;
+ private boolean timers;
+ private int idx;
+ private String Name;
+ private String LastUpdate;
+ private long setPoint;
+ private String Type;
+ private String SubType;
+ private int Favorite;
+ private int HardwareID;
+ private String HardwareName;
+ private String TypeImg;
+ private String PlanID;
+ private int batteryLevel;
+ private int maxDimLevel;
+ private int signalLevel;
+ private String status;
+ private int level;
+ private int switchTypeVal;
+ private String switchType;
+ private String CounterToday;
+ private String Counter;
+ private String Usage;
+ private String Data;
+ private String Timers;
+ private boolean statusBoolean;
+ private boolean isProtected;
+
+ public DevicesInfo(JSONObject row) throws JSONException {
this.jsonObject = row;
try {
if (row.has("LevelInt"))
@@ -72,12 +74,12 @@ public DevicesInfo(JSONObject row) throws JSONException {
maxDimLevel = 1;
}
- try {
- if (row.has("CounterToday"))
- CounterToday = row.getString("CounterToday");
- } catch (Exception e) {
- CounterToday = "";
- }
+ if (row.has("Counter"))
+ Counter = row.getString("Counter");
+ if (row.has("CounterToday"))
+ CounterToday = row.getString("CounterToday");
+ if (row.has("Usage"))
+ Usage = row.getString("Usage");
try {
if (row.has("Status"))
@@ -171,6 +173,14 @@ public void setFavoriteBoolean(boolean favorite) {
else this.Favorite = 0;
}
+ public String getCounter() {
+ return Counter;
+ }
+
+ public String getUsage() {
+ return Usage;
+ }
+
public String getTimers() {
return Timers;
}
@@ -333,4 +343,9 @@ public int getSwitchTypeVal() {
public String getSwitchType() {
return switchType;
}
+
+ @Override
+ public int compareTo(Object another) {
+ return this.getName().compareTo(((DevicesInfo)another).getName());
+ }
}
\ No newline at end of file
diff --git a/app/src/main/java/nl/hnogames/domoticz/Containers/LocationInfo.java b/app/src/main/java/nl/hnogames/domoticz/Containers/LocationInfo.java
index 8d8d81e..6eaa8dc 100644
--- a/app/src/main/java/nl/hnogames/domoticz/Containers/LocationInfo.java
+++ b/app/src/main/java/nl/hnogames/domoticz/Containers/LocationInfo.java
@@ -85,6 +85,9 @@ public LatLng getLocation() {
* @return A Geofence object.
*/
public Geofence toGeofence() {
+ if(radius<=0)
+ radius=400;//default
+
// Build a new Geofence object.
return new Geofence.Builder()
.setRequestId(String.valueOf(id))
diff --git a/app/src/main/java/nl/hnogames/domoticz/Containers/UtilitiesInfo.java b/app/src/main/java/nl/hnogames/domoticz/Containers/UtilitiesInfo.java
index e918fa5..9076a32 100644
--- a/app/src/main/java/nl/hnogames/domoticz/Containers/UtilitiesInfo.java
+++ b/app/src/main/java/nl/hnogames/domoticz/Containers/UtilitiesInfo.java
@@ -44,6 +44,8 @@ public class UtilitiesInfo {
String HardwareName;
String TypeImg;
String CounterToday;
+ String Counter;
+ String Usage;
int signalLevel;
public UtilitiesInfo(JSONObject row) throws JSONException {
@@ -68,8 +70,12 @@ public UtilitiesInfo(JSONObject row) throws JSONException {
Data = row.getString("Data");
if (row.has("Type"))
Type = row.getString("Type");
+ if (row.has("Counter"))
+ Counter = row.getString("Counter");
if (row.has("CounterToday"))
CounterToday = row.getString("CounterToday");
+ if (row.has("Usage"))
+ Usage = row.getString("Usage");
if (row.has("SubType"))
SubType = row.getString("SubType");
idx = row.getInt("idx");
@@ -114,6 +120,14 @@ public String getName() {
return Name;
}
+ public String getCounter() {
+ return Counter;
+ }
+
+ public String getUsage() {
+ return Usage;
+ }
+
public void setName(String name) {
Name = name;
}
diff --git a/app/src/main/java/nl/hnogames/domoticz/Domoticz/DevicesParser.java b/app/src/main/java/nl/hnogames/domoticz/Domoticz/DevicesParser.java
index 1548b82..978b318 100644
--- a/app/src/main/java/nl/hnogames/domoticz/Domoticz/DevicesParser.java
+++ b/app/src/main/java/nl/hnogames/domoticz/Domoticz/DevicesParser.java
@@ -38,11 +38,26 @@ public class DevicesParser implements JSONParserInterface {
private static final String TAG = DevicesParser.class.getSimpleName();
private DevicesReceiver receiver;
+ private int idx = 999999;
public DevicesParser(DevicesReceiver receiver) {
this.receiver = receiver;
}
+ public DevicesParser(DevicesReceiver receiver, int idx) {
+ this.receiver = receiver;
+ this.idx=idx;
+ }
+
+ private DevicesInfo getDevice(int idx, ArrayList mDevicesInfo) {
+ for (DevicesInfo s : mDevicesInfo) {
+ if (s.getIdx() == idx) {
+ return s;
+ }
+ }
+ return null;
+ }
+
@Override
public void parseResult(String result) {
@@ -58,8 +73,11 @@ public void parseResult(String result) {
}
}
- receiver.onReceiveDevices(mDevices);
-
+ if(idx == 999999)
+ receiver.onReceiveDevices(mDevices);
+ else{
+ receiver.onReceiveDevice(getDevice(idx, mDevices));
+ }
} catch (JSONException e) {
Log.e(TAG, "DevicesParser JSON exception");
e.printStackTrace();
diff --git a/app/src/main/java/nl/hnogames/domoticz/Domoticz/Domoticz.java b/app/src/main/java/nl/hnogames/domoticz/Domoticz/Domoticz.java
index 0aa44a8..33e06b6 100644
--- a/app/src/main/java/nl/hnogames/domoticz/Domoticz/Domoticz.java
+++ b/app/src/main/java/nl/hnogames/domoticz/Domoticz/Domoticz.java
@@ -82,6 +82,11 @@ public class Domoticz {
private final PhoneConnectionUtil mPhoneConnectionUtil;
Context mContext;
+ public void Disconnect(){
+ if(mPhoneConnectionUtil!=null)
+ mPhoneConnectionUtil.stopReceiver();
+ }
+
public Domoticz(Context mContext) {
this.mContext = mContext;
mSharedPrefUtil = new SharedPrefUtil(mContext);
@@ -732,6 +737,17 @@ public void getDevices(DevicesReceiver receiver, int plan) {
url);
}
+ public void getDevice(DevicesReceiver receiver, int idx) {
+ DevicesParser parser = new DevicesParser(receiver, idx);
+ String url = constructGetUrl(Json.Url.Request.DEVICES);
+
+ RequestUtil.makeJsonGetResultRequest(parser,
+ getUserCredentials(Authentication.USERNAME),
+ getUserCredentials(Authentication.PASSWORD),
+ url);
+ }
+
+
public void getLogs(LogsReceiver receiver) {
LogsParser parser = new LogsParser(receiver);
String url = constructGetUrl(Json.Url.Request.LOG);
@@ -837,7 +853,10 @@ public int getDrawableIcon(String type, String subtype, boolean state) {
else
return R.drawable.cooling;
case "counter":
- return R.drawable.up;
+ if (subtype != null && subtype.length() > 0 && subtype.equals("P1 Smart Meter"))
+ return R.drawable.wall;
+ else
+ return R.drawable.up;
case "override_mini":
return R.drawable.defaultimage;
case "visibility":
diff --git a/app/src/main/java/nl/hnogames/domoticz/Fragments/Dashboard.java b/app/src/main/java/nl/hnogames/domoticz/Fragments/Dashboard.java
index 3cfeb9e..38c8aa1 100644
--- a/app/src/main/java/nl/hnogames/domoticz/Fragments/Dashboard.java
+++ b/app/src/main/java/nl/hnogames/domoticz/Fragments/Dashboard.java
@@ -112,6 +112,10 @@ public void onReceiveDevices(ArrayList switches) {
processDevices(switches);
}
+ @Override
+ public void onReceiveDevice(DevicesInfo mDevicesInfo) {
+ }
+
@Override
public void onError(Exception error) {
errorHandling(error);
diff --git a/app/src/main/java/nl/hnogames/domoticz/Fragments/Utilities.java b/app/src/main/java/nl/hnogames/domoticz/Fragments/Utilities.java
index 9f3a4bb..4d9c61a 100644
--- a/app/src/main/java/nl/hnogames/domoticz/Fragments/Utilities.java
+++ b/app/src/main/java/nl/hnogames/domoticz/Fragments/Utilities.java
@@ -207,6 +207,7 @@ private void updateThermostatSetPointValue(int idx, double newSetPoint) {
break;
}
}
+
notifyDataSetChanged();
}
@@ -215,9 +216,16 @@ private void updateThermostatSetPointValue(int idx, double newSetPoint) {
*/
private void notifyDataSetChanged() {
addDebugText("notifyDataSetChanged");
- // adapter.notifyDataSetChanged();
+
+ // save index and top position
+ int index = listView.getFirstVisiblePosition();
+ View v = listView.getChildAt(0);
+ int top = (v == null) ? 0 : v.getTop();
+
+ adapter.notifyDataSetChanged();
listView.setAdapter(adapter);
+ listView.setSelectionFromTop(index, top);
}
/**
@@ -292,7 +300,6 @@ public void onThermostatClick(final int idx, int action, double newSetPoint) {
addDebugText("Set idx " + idx + " to " + String.valueOf(newSetPoint));
thermostatSetPointValue = newSetPoint;
-
int jsonUrl = Domoticz.Json.Url.Set.TEMP;
mDomoticz.setAction(idx, jsonUrl, action, newSetPoint, new setCommandReceiver() {
diff --git a/app/src/main/java/nl/hnogames/domoticz/Interfaces/DevicesReceiver.java b/app/src/main/java/nl/hnogames/domoticz/Interfaces/DevicesReceiver.java
index 53b36d2..0fd82c7 100644
--- a/app/src/main/java/nl/hnogames/domoticz/Interfaces/DevicesReceiver.java
+++ b/app/src/main/java/nl/hnogames/domoticz/Interfaces/DevicesReceiver.java
@@ -27,8 +27,7 @@
import nl.hnogames.domoticz.Containers.DevicesInfo;
public interface DevicesReceiver {
-
void onReceiveDevices(ArrayList mDevicesInfo);
-
+ void onReceiveDevice(DevicesInfo mDevicesInfo);
void onError(Exception error);
}
diff --git a/app/src/main/java/nl/hnogames/domoticz/MainActivity.java b/app/src/main/java/nl/hnogames/domoticz/MainActivity.java
index cd748cb..49d1b34 100644
--- a/app/src/main/java/nl/hnogames/domoticz/MainActivity.java
+++ b/app/src/main/java/nl/hnogames/domoticz/MainActivity.java
@@ -74,6 +74,7 @@ public class MainActivity extends AppCompatActivity {
private SharedPrefUtil mSharedPrefs;
private NavigationAdapter mAdapter; // Declaring Adapter For Recycler View
private SearchView searchViewAction;
+ private Domoticz domoticz;
@Override
protected void onCreate(Bundle savedInstanceState) {
@@ -104,7 +105,7 @@ private void buildScreen() {
addFragment();
//get latest update version
- Domoticz domoticz = new Domoticz(this);
+ domoticz = new Domoticz(this);
domoticz.getUpdate(new UpdateReceiver() {
@Override
public void onReceiveUpdate(String version) {
@@ -122,6 +123,7 @@ public void onError(Exception error) {
Snackbar.make(coordinatorLayout, "Could not check for updates:" + error.getMessage(), Snackbar.LENGTH_SHORT).show();
}
});
+
} else {
Intent welcomeWizard = new Intent(this, WelcomeViewActivity.class);
startActivityForResult(welcomeWizard, iWelcomeResultCode);
@@ -129,6 +131,15 @@ public void onError(Exception error) {
}
}
+ @Override
+ protected void onStop()
+ {
+ if(domoticz!=null)
+ domoticz.Disconnect();
+
+ super.onStop();
+ }
+
/* Called when the second activity's finished */
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (data != null && resultCode == RESULT_OK) {
@@ -147,12 +158,9 @@ protected void onActivityResult(int requestCode, int resultCode, Intent data) {
((DomoticzFragment) f).refreshFragment();
} else if (f instanceof DomoticzCardFragment)
((DomoticzCardFragment) f).refreshFragment();
- {
- }
updateDrawerItems();
break;
-
}
}
}
diff --git a/app/src/main/java/nl/hnogames/domoticz/Service/BootUpReceiver.java b/app/src/main/java/nl/hnogames/domoticz/Service/BootUpReceiver.java
new file mode 100644
index 0000000..334a3eb
--- /dev/null
+++ b/app/src/main/java/nl/hnogames/domoticz/Service/BootUpReceiver.java
@@ -0,0 +1,46 @@
+/*
+ * Copyright (C) 2015 Domoticz
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+
+package nl.hnogames.domoticz.Service;
+
+import android.appwidget.AppWidgetManager;
+import android.content.BroadcastReceiver;
+import android.content.ComponentName;
+import android.content.Context;
+import android.content.Intent;
+import static android.appwidget.AppWidgetManager.EXTRA_APPWIDGET_ID;
+
+public class BootUpReceiver extends BroadcastReceiver {
+ @Override
+ public void onReceive(Context context, Intent intent) {
+ //refresh all widgets
+ AppWidgetManager widgetManager = AppWidgetManager.getInstance(context);
+ ComponentName widgetComponent = new ComponentName(context, WidgetProviderLarge.class);
+ int[] appWidgetIds = widgetManager.getAppWidgetIds(widgetComponent);
+ for (int i = 0; i < appWidgetIds.length; i++) {
+ Intent updateIntent = new Intent(context, WidgetProviderLarge.UpdateWidgetService.class);
+ updateIntent.putExtra(EXTRA_APPWIDGET_ID, appWidgetIds[i]);
+ updateIntent.setAction("FROM WIDGET PROVIDER");
+ context.startService(updateIntent);
+ }
+ }
+}
\ No newline at end of file
diff --git a/app/src/main/java/nl/hnogames/domoticz/Service/WidgetIntentReceiver.java b/app/src/main/java/nl/hnogames/domoticz/Service/WidgetIntentReceiver.java
new file mode 100644
index 0000000..b981c76
--- /dev/null
+++ b/app/src/main/java/nl/hnogames/domoticz/Service/WidgetIntentReceiver.java
@@ -0,0 +1,232 @@
+/*
+ * Copyright (C) 2015 Domoticz
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+
+package nl.hnogames.domoticz.Service;
+
+import android.appwidget.AppWidgetManager;
+import android.content.BroadcastReceiver;
+import android.content.Context;
+import android.content.Intent;
+import android.widget.Toast;
+
+import java.util.ArrayList;
+
+import nl.hnogames.domoticz.Containers.DevicesInfo;
+import nl.hnogames.domoticz.Domoticz.Domoticz;
+import nl.hnogames.domoticz.Interfaces.DevicesReceiver;
+import nl.hnogames.domoticz.Interfaces.setCommandReceiver;
+import nl.hnogames.domoticz.Utils.SharedPrefUtil;
+
+/**
+ * Created by m.heinis on 12/10/2015.
+ */
+public class WidgetIntentReceiver extends BroadcastReceiver {
+
+ private int widgetID = 0;
+
+ @Override
+ public void onReceive(Context context, Intent intent) {
+ widgetID = intent.getIntExtra("WIDGETID", 999999);
+ int idx = intent.getIntExtra("IDX", 999999);
+ if (intent.getAction().equals("nl.hnogames.domoticz.Service.WIDGET_TOGGLE_ACTION")) {
+ toggleSwitch(context, idx);
+ }
+ }
+
+ private DevicesInfo getDevice(int idx, ArrayList mDevicesInfo) {
+ for (DevicesInfo s : mDevicesInfo) {
+ if (s.getIdx() == idx) {
+ return s;
+ }
+ }
+ return null;
+ }
+
+ private boolean isOnOffSwitch(DevicesInfo mExtendedStatusInfo) {
+ if (mExtendedStatusInfo.getSwitchTypeVal() == 0 &&
+ (mExtendedStatusInfo.getSwitchType() == null || mExtendedStatusInfo.getSwitchType().equals(null))) {
+ switch (mExtendedStatusInfo.getType()) {
+ case Domoticz.Scene.Type.GROUP:
+ return true;
+ }
+ } else {
+ boolean switchFound = true;
+ switch (mExtendedStatusInfo.getSwitchTypeVal()) {
+ case Domoticz.Device.Type.Value.ON_OFF:
+ case Domoticz.Device.Type.Value.MEDIAPLAYER:
+ case Domoticz.Device.Type.Value.X10SIREN:
+ case Domoticz.Device.Type.Value.DIMMER:
+ case Domoticz.Device.Type.Value.DOORLOCK:
+ return true;
+ }
+ }
+ return false;
+ }
+
+
+ private boolean isPushOnSwitch(DevicesInfo mExtendedStatusInfo) {
+ if (mExtendedStatusInfo.getSwitchTypeVal() == 0 &&
+ (mExtendedStatusInfo.getSwitchType() == null || mExtendedStatusInfo.getSwitchType().equals(null))) {
+ switch (mExtendedStatusInfo.getType()) {
+ case Domoticz.Scene.Type.SCENE:
+ return true;
+
+ }
+ } else
+ switch (mExtendedStatusInfo.getSwitchTypeVal()) {
+ case Domoticz.Device.Type.Value.PUSH_ON_BUTTON:
+ case Domoticz.Device.Type.Value.SMOKE_DETECTOR:
+ case Domoticz.Device.Type.Value.DOORBELL:
+ return true;
+
+ }
+ return false;
+ }
+
+
+ private boolean isPushOffSwitch(DevicesInfo mExtendedStatusInfo) {
+ if (mExtendedStatusInfo.getSwitchTypeVal() == 0 &&
+ (mExtendedStatusInfo.getSwitchType() == null || mExtendedStatusInfo.getSwitchType().equals(null))) {
+ return false;
+ } else
+ switch (mExtendedStatusInfo.getSwitchTypeVal()) {
+ case Domoticz.Device.Type.Value.PUSH_OFF_BUTTON:
+ return true;
+ }
+ return false;
+ }
+
+ private void toggleSwitch(final Context context, int idx) {
+ SharedPrefUtil mSharedPrefs = new SharedPrefUtil(context);
+ final Domoticz domoticz = new Domoticz(context);
+ domoticz.getDevice(new DevicesReceiver() {
+ @Override
+ public void onReceiveDevices(ArrayList mDevicesInfo) {
+ }
+
+ @Override
+ public void onReceiveDevice(DevicesInfo s) {
+ if (isOnOffSwitch(s))
+ onSwitchClick(s, !s.getStatusBoolean(), domoticz, context);
+ if (isPushOffSwitch(s))
+ onButtonClick(s, false, domoticz, context);
+ if (isPushOnSwitch(s))
+ onButtonClick(s, true, domoticz, context);
+ }
+
+ @Override
+ public void onError(Exception error) {
+ Toast.makeText(context, "Failed to toggling switch.", Toast.LENGTH_SHORT).show();
+ }
+ }, idx);
+ }
+
+ public void onBlindClick(final DevicesInfo clickedSwitch, int jsonAction, Domoticz mDomoticz, final Context context) {
+ int jsonUrl = Domoticz.Json.Url.Set.SWITCHES;
+ int idx = clickedSwitch.getIdx();
+ mDomoticz.setAction(idx, jsonUrl, jsonAction, 0, new setCommandReceiver() {
+ @Override
+ public void onReceiveResult(String result) {
+ Toast.makeText(context, "Switch toggled: " + clickedSwitch.getName() + " Widget: " + widgetID, Toast.LENGTH_SHORT).show();
+ updateWidget(context);
+ }
+
+ @Override
+ public void onError(Exception error) {
+ Toast.makeText(context, "Failed to toggle switch." + widgetID, Toast.LENGTH_SHORT).show();
+ }
+ });
+ }
+
+ public void onButtonClick(final DevicesInfo clickedSwitch, boolean checked, Domoticz mDomoticz, final Context context) {
+ int jsonAction;
+ int jsonUrl = Domoticz.Json.Url.Set.SWITCHES;
+
+ if (checked) jsonAction = Domoticz.Device.Switch.Action.ON;
+ else jsonAction = Domoticz.Device.Switch.Action.OFF;
+
+ int idx = clickedSwitch.getIdx();
+ if (clickedSwitch.getType().equals(Domoticz.Scene.Type.GROUP) || clickedSwitch.getType().equals(Domoticz.Scene.Type.SCENE)) {
+ jsonUrl = Domoticz.Json.Url.Set.SCENES;
+ if (checked) jsonAction = Domoticz.Scene.Action.ON;
+ else jsonAction = Domoticz.Scene.Action.OFF;
+ idx = idx - 4000;
+ }
+ mDomoticz.setAction(idx, jsonUrl, jsonAction, 0, new setCommandReceiver() {
+ @Override
+ public void onReceiveResult(String result) {
+ Toast.makeText(context, "Switch toggled: " + clickedSwitch.getName() + " Widget: " + widgetID, Toast.LENGTH_SHORT).show();
+ updateWidget(context);
+ }
+
+ @Override
+ public void onError(Exception error) {
+ Toast.makeText(context, "Failed to toggle switch." + widgetID, Toast.LENGTH_SHORT).show();
+ }
+ });
+ }
+
+ public void onSwitchClick(final DevicesInfo clickedSwitch, boolean checked, Domoticz mDomoticz, final Context context) {
+
+ if (clickedSwitch != null) {
+ int jsonAction;
+ int jsonUrl = Domoticz.Json.Url.Set.SWITCHES;
+ if (clickedSwitch.getSwitchTypeVal() == Domoticz.Device.Type.Value.BLINDS ||
+ clickedSwitch.getSwitchTypeVal() == Domoticz.Device.Type.Value.BLINDPERCENTAGE) {
+ if (checked) jsonAction = Domoticz.Device.Switch.Action.OFF;
+ else jsonAction = Domoticz.Device.Switch.Action.ON;
+ } else {
+ if (checked) jsonAction = Domoticz.Device.Switch.Action.ON;
+ else jsonAction = Domoticz.Device.Switch.Action.OFF;
+ }
+
+ int idx = clickedSwitch.getIdx();
+ if (clickedSwitch.getType().equals(Domoticz.Scene.Type.GROUP) || clickedSwitch.getType().equals(Domoticz.Scene.Type.SCENE)) {
+ jsonUrl = Domoticz.Json.Url.Set.SCENES;
+ if (checked) jsonAction = Domoticz.Scene.Action.ON;
+ else jsonAction = Domoticz.Scene.Action.OFF;
+ idx = idx - 4000;
+ }
+
+ mDomoticz.setAction(idx, jsonUrl, jsonAction, 0, new setCommandReceiver() {
+ @Override
+ public void onReceiveResult(String result) {
+ Toast.makeText(context, "Switch toggled: " + clickedSwitch.getName() + " Widget: " + widgetID, Toast.LENGTH_SHORT).show();
+ updateWidget(context);
+ }
+
+ @Override
+ public void onError(Exception error) {
+ Toast.makeText(context, "Failed to toggle switch." + widgetID, Toast.LENGTH_SHORT).show();
+ }
+ });
+ }
+ }
+
+ private void updateWidget(Context context) {
+ Intent intent = new Intent(context, WidgetProviderLarge.class);
+ intent.setAction(AppWidgetManager.ACTION_APPWIDGET_UPDATE);
+ int[] ids = {widgetID};
+ intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_IDS, ids);
+ context.sendBroadcast(intent);
+ }
+}
diff --git a/app/src/main/java/nl/hnogames/domoticz/Service/WidgetProviderLarge.java b/app/src/main/java/nl/hnogames/domoticz/Service/WidgetProviderLarge.java
new file mode 100644
index 0000000..391e7a9
--- /dev/null
+++ b/app/src/main/java/nl/hnogames/domoticz/Service/WidgetProviderLarge.java
@@ -0,0 +1,184 @@
+/*
+ * Copyright (C) 2015 Domoticz
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+
+package nl.hnogames.domoticz.Service;
+
+import android.app.IntentService;
+import android.app.PendingIntent;
+import android.appwidget.AppWidgetManager;
+import android.appwidget.AppWidgetProvider;
+import android.content.Context;
+import android.content.Intent;
+import android.view.View;
+import android.widget.RemoteViews;
+
+import java.util.ArrayList;
+
+import nl.hnogames.domoticz.Containers.DevicesInfo;
+import nl.hnogames.domoticz.Domoticz.Domoticz;
+import nl.hnogames.domoticz.Interfaces.DevicesReceiver;
+import nl.hnogames.domoticz.R;
+import nl.hnogames.domoticz.Utils.SharedPrefUtil;
+
+import static android.appwidget.AppWidgetManager.EXTRA_APPWIDGET_ID;
+import static android.appwidget.AppWidgetManager.INVALID_APPWIDGET_ID;
+
+public class WidgetProviderLarge extends AppWidgetProvider {
+ Context context;
+
+ @Override
+ public void onUpdate(Context context, AppWidgetManager appWidgetManager,
+ int[] appWidgetIds) {
+ super.onUpdate(context, appWidgetManager, appWidgetIds);
+ this.context = context;
+ if (appWidgetIds != null) {
+ for (int mAppWidgetId : appWidgetIds) {
+ Intent intent = new Intent(context, UpdateWidgetService.class);
+ intent.putExtra(EXTRA_APPWIDGET_ID, mAppWidgetId);
+ intent.setAction("FROM WIDGET PROVIDER");
+ context.startService(intent);
+ }
+ }
+ }
+
+ public static class UpdateWidgetService extends IntentService {
+ private RemoteViews views;
+
+ public UpdateWidgetService() {
+ super("UpdateWidgetService");
+ }
+
+ @Override
+ protected void onHandleIntent(Intent intent) {
+ AppWidgetManager appWidgetManager = AppWidgetManager
+ .getInstance(UpdateWidgetService.this);
+
+ int incomingAppWidgetId = intent.getIntExtra(EXTRA_APPWIDGET_ID,
+ INVALID_APPWIDGET_ID);
+ if (incomingAppWidgetId != INVALID_APPWIDGET_ID) {
+ try {
+ updateAppWidget(appWidgetManager, incomingAppWidgetId, intent);
+ } catch (NullPointerException e) {
+ }
+ }
+ }
+
+ public void updateAppWidget(final AppWidgetManager appWidgetManager,
+ final int appWidgetId, Intent intent) {
+
+ final SharedPrefUtil mSharedPrefs = new SharedPrefUtil(getApplicationContext());
+
+ final String packageName = this.getPackageName();
+ views = new RemoteViews(packageName, R.layout.widget_layout);//default
+ final Domoticz domoticz = new Domoticz(getApplicationContext());
+
+ int idx = mSharedPrefs.getWidgetIDX(appWidgetId);
+ domoticz.getDevice(new DevicesReceiver() {
+ @Override
+ public void onReceiveDevices(ArrayList mDevicesInfo) {}
+
+ @Override
+ public void onReceiveDevice(DevicesInfo s) {
+ if (s != null) {
+ boolean withButtons = withButtons(s);
+ if (withButtons)
+ views = new RemoteViews(packageName, R.layout.widget_layout);//default
+
+ String text = s.getData();
+ views.setTextViewText(R.id.title, s.getName());
+ if (s.getUsage() != null && s.getUsage().length() > 0)
+ text = s.getUsage();
+ if (s.getCounterToday() != null && s.getCounterToday().length() > 0)
+ text += " Today: " + s.getCounterToday();
+ if (s.getCounter() != null && s.getCounter().length() > 0 &&
+ !s.getCounter().equals(s.getData()))
+ text += " Total: " + s.getCounter();
+
+ views.setTextViewText(R.id.desc, text);
+
+ if (withButtons && s.getStatus() != null) {
+ if (s.getStatusBoolean())
+ views.setTextViewText(R.id.on_button, "off");
+ else
+ views.setTextViewText(R.id.on_button, "on");
+
+ views.setOnClickPendingIntent(R.id.on_button, buildButtonPendingIntent(
+ UpdateWidgetService.this,
+ mSharedPrefs.getWidgetIDforIDX(s.getIdx()),
+ s.getIdx()));
+ views.setViewVisibility(R.id.on_button, View.VISIBLE);
+ }
+ else{
+ views.setViewVisibility(R.id.on_button, View.GONE);
+ }
+
+ views.setImageViewResource(R.id.rowIcon, domoticz.getDrawableIcon(s.getTypeImg(), s.getSwitchType(), true));
+ appWidgetManager.updateAppWidget(mSharedPrefs.getWidgetIDforIDX(s.getIdx()), views);
+ }
+ }
+
+ @Override
+ public void onError(Exception error) {
+ }
+
+ }, idx);
+ }
+
+ public PendingIntent buildButtonPendingIntent(Context context, int widgetid, int idx) {
+ Intent intent = new Intent();
+ intent.setAction("nl.hnogames.domoticz.Service.WIDGET_TOGGLE_ACTION");
+ intent.putExtra("IDX", idx);
+ intent.putExtra("WIDGETID", widgetid);
+ return PendingIntent.getBroadcast(context, widgetid, intent, 0);
+ }
+
+ private boolean withButtons(DevicesInfo s) {
+ boolean withButton = false;
+ if (s != null && !s.isProtected()) {
+ if (s.getSwitchTypeVal() == 0 &&
+ (s.getSwitchType() == null || s.getSwitchType().equals(null))) {
+ switch (s.getType()) {
+ case Domoticz.Scene.Type.GROUP:
+ case Domoticz.Scene.Type.SCENE:
+ withButton = true;
+ break;
+ }
+ } else {
+ switch (s.getSwitchTypeVal()) {
+ case Domoticz.Device.Type.Value.ON_OFF:
+ case Domoticz.Device.Type.Value.MEDIAPLAYER:
+ case Domoticz.Device.Type.Value.X10SIREN:
+ case Domoticz.Device.Type.Value.DOORLOCK:
+ case Domoticz.Device.Type.Value.PUSH_ON_BUTTON:
+ case Domoticz.Device.Type.Value.SMOKE_DETECTOR:
+ case Domoticz.Device.Type.Value.DOORBELL:
+ case Domoticz.Device.Type.Value.PUSH_OFF_BUTTON:
+ case Domoticz.Device.Type.Value.DIMMER:
+ withButton = true;
+ break;
+ }
+ }
+ }
+ return withButton;
+ }
+ }
+}
\ No newline at end of file
diff --git a/app/src/main/java/nl/hnogames/domoticz/UI/SwitchsDialog.java b/app/src/main/java/nl/hnogames/domoticz/UI/SwitchsDialog.java
index 4721b4c..d1bac07 100644
--- a/app/src/main/java/nl/hnogames/domoticz/UI/SwitchsDialog.java
+++ b/app/src/main/java/nl/hnogames/domoticz/UI/SwitchsDialog.java
@@ -96,7 +96,6 @@ public String[] processSwitches() {
return listData;
}
-
public void onDismissListener(DismissListener dismissListener) {
this.dismissListener = dismissListener;
}
diff --git a/app/src/main/java/nl/hnogames/domoticz/Utils/PhoneConnectionUtil.java b/app/src/main/java/nl/hnogames/domoticz/Utils/PhoneConnectionUtil.java
index 109f73e..e2ed4f1 100644
--- a/app/src/main/java/nl/hnogames/domoticz/Utils/PhoneConnectionUtil.java
+++ b/app/src/main/java/nl/hnogames/domoticz/Utils/PhoneConnectionUtil.java
@@ -44,6 +44,7 @@ public class PhoneConnectionUtil {
private NetworkInfo networkWifiInfo;
private NetworkInfo networkCellInfo;
private WifiSSIDListener listener;
+ private BroadcastReceiver receiver;
public PhoneConnectionUtil(Context mContext,
final WifiSSIDListener listener) {
@@ -53,11 +54,10 @@ public PhoneConnectionUtil(Context mContext,
networkWifiInfo = connManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
networkCellInfo = connManager.getNetworkInfo(ConnectivityManager.TYPE_MOBILE);
this.listener=listener;
- mContext.registerReceiver(new BroadcastReceiver()
- {
+
+ receiver =new BroadcastReceiver() {
@Override
- public void onReceive(Context c, Intent intent)
- {
+ public void onReceive(Context c, Intent intent) {
List results = wifiManager.getScanResults();
CharSequence[] entries = new CharSequence[0];
@@ -66,7 +66,7 @@ public void onReceive(Context c, Intent intent)
int i = 0;
for (ScanResult result : results) {
- if(result.SSID!=null && result.SSID.length()>0) {
+ if (result.SSID != null && result.SSID.length() > 0) {
entries[i] = result.SSID;
i++;
}
@@ -74,10 +74,19 @@ public void onReceive(Context c, Intent intent)
}
listener.ReceiveSSIDs(entries);
}
- }, new IntentFilter(WifiManager.SCAN_RESULTS_AVAILABLE_ACTION));
+ };
+ }
+
+ public void stopReceiver(){
+ try {
+ mContext.unregisterReceiver(receiver);
+ }catch(Exception ex){}
}
public void startSsidScan() {
+ try {
+ mContext.registerReceiver(receiver, new IntentFilter(WifiManager.SCAN_RESULTS_AVAILABLE_ACTION));
+ }catch(Exception ex){}
wifiManager.startScan();
}
diff --git a/app/src/main/java/nl/hnogames/domoticz/Utils/SharedPrefUtil.java b/app/src/main/java/nl/hnogames/domoticz/Utils/SharedPrefUtil.java
index 1bcde93..a867b55 100644
--- a/app/src/main/java/nl/hnogames/domoticz/Utils/SharedPrefUtil.java
+++ b/app/src/main/java/nl/hnogames/domoticz/Utils/SharedPrefUtil.java
@@ -91,6 +91,7 @@ public class SharedPrefUtil {
"local_server_authentication_method";
private static final String LOCAL_SERVER_SSID = "local_server_ssid";
+ public static final int INVALID_IDX = 999999;
Context mContext;
SharedPreferences prefs;
@@ -103,6 +104,22 @@ public SharedPrefUtil(Context mContext) {
editor = prefs.edit();
}
+ public void setWidgetIDX(int widgetID, int idx) {
+ editor.putInt("WIDGET"+widgetID, idx).apply();
+ }
+
+ public int getWidgetIDX(int widgetID) {
+ return prefs.getInt("WIDGET"+widgetID, INVALID_IDX);
+ }
+
+ public void setWidgetIDforIDX(int widgetID, int idx) {
+ editor.putInt("WIDGETIDX"+idx, widgetID).apply();
+ }
+
+ public int getWidgetIDforIDX(int idx) {
+ return prefs.getInt("WIDGETIDX"+idx, INVALID_IDX);
+ }
+
/*
* Generic settings
*/
diff --git a/app/src/main/java/nl/hnogames/domoticz/Utils/WidgetUtils.java b/app/src/main/java/nl/hnogames/domoticz/Utils/WidgetUtils.java
new file mode 100644
index 0000000..1618638
--- /dev/null
+++ b/app/src/main/java/nl/hnogames/domoticz/Utils/WidgetUtils.java
@@ -0,0 +1,31 @@
+/*
+ * Copyright (C) 2015 Domoticz
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+
+package nl.hnogames.domoticz.Utils;
+
+/**
+ * Created by m.heinis on 12/10/2015.
+ */
+
+public class WidgetUtils {
+ public final static String WIDGET_UPDATE_ACTION ="nl.hnogames.domoticz.Utils.intent.action.UPDATE_WIDGET";
+}
\ No newline at end of file
diff --git a/app/src/main/java/nl/hnogames/domoticz/Welcome/WelcomePage3.java b/app/src/main/java/nl/hnogames/domoticz/Welcome/WelcomePage3.java
index 141704c..529f4df 100644
--- a/app/src/main/java/nl/hnogames/domoticz/Welcome/WelcomePage3.java
+++ b/app/src/main/java/nl/hnogames/domoticz/Welcome/WelcomePage3.java
@@ -48,6 +48,7 @@ public class WelcomePage3 extends Fragment {
private boolean hasBeenVisibleToUser = false;
private MultiSelectionSpinner local_wifi_spinner;
private int callingInstance;
+ private PhoneConnectionUtil mPhoneConnectionUtil;
public static WelcomePage3 newInstance(int instance) {
WelcomePage3 f = new WelcomePage3();
@@ -154,9 +155,12 @@ public void onRequestPermissionsResult(int requestCode, String[] permissions, in
case PermissionsUtil.INITIAL_ACCESS_REQUEST:
if (PermissionsUtil.canAccessLocation(getActivity())) {
setSsid_spinner();
- } else
+ } else {
+ if(mPhoneConnectionUtil!=null)
+ mPhoneConnectionUtil.stopReceiver();
+
((WelcomeViewActivity) getActivity()).finishWithResult(false);
- break;
+ }break;
}
}
@@ -174,7 +178,7 @@ private void setSsid_spinner() {
}
}
- PhoneConnectionUtil mPhoneConnectionUtil = new PhoneConnectionUtil(getActivity(), new WifiSSIDListener() {
+ mPhoneConnectionUtil = new PhoneConnectionUtil(getActivity(), new WifiSSIDListener() {
@Override
public void ReceiveSSIDs(CharSequence[] ssidFound) {
if (ssidFound == null || ssidFound.length < 1) {
@@ -193,6 +197,7 @@ public void ReceiveSSIDs(CharSequence[] ssidFound) {
// Set SSID's from shared preferences to selected
local_wifi_spinner.setSelection(ssidListFromPrefs);
}
+ mPhoneConnectionUtil.stopReceiver();
}
});
mPhoneConnectionUtil.startSsidScan();
diff --git a/app/src/main/java/nl/hnogames/domoticz/Welcome/WelcomePage4.java b/app/src/main/java/nl/hnogames/domoticz/Welcome/WelcomePage4.java
index 13afe1f..132f5ad 100644
--- a/app/src/main/java/nl/hnogames/domoticz/Welcome/WelcomePage4.java
+++ b/app/src/main/java/nl/hnogames/domoticz/Welcome/WelcomePage4.java
@@ -75,6 +75,10 @@ public void onReceiveDevices(ArrayList mDevicesInfo) {
setSuccessText(tempText);
}
+ @Override
+ public void onReceiveDevice(DevicesInfo mDevicesInfo) {
+ }
+
@Override
public void onError(Exception error) {
setErrorText(mDomoticz.getErrorMessage(error));
diff --git a/app/src/main/java/nl/hnogames/domoticz/WidgetActionActivity.java b/app/src/main/java/nl/hnogames/domoticz/WidgetActionActivity.java
new file mode 100644
index 0000000..18a7fea
--- /dev/null
+++ b/app/src/main/java/nl/hnogames/domoticz/WidgetActionActivity.java
@@ -0,0 +1,154 @@
+package nl.hnogames.domoticz;
+
+import android.appwidget.AppWidgetManager;
+import android.appwidget.AppWidgetProviderInfo;
+import android.content.Intent;
+import android.os.Bundle;
+import android.support.v7.app.AppCompatActivity;
+import android.util.Log;
+import android.view.View;
+import android.widget.AdapterView;
+import android.widget.ArrayAdapter;
+import android.widget.ListView;
+import android.widget.Toast;
+
+import java.util.ArrayList;
+
+import nl.hnogames.domoticz.Containers.DevicesInfo;
+import nl.hnogames.domoticz.Domoticz.Domoticz;
+import nl.hnogames.domoticz.Interfaces.DevicesReceiver;
+import nl.hnogames.domoticz.Service.WidgetProviderLarge;
+import nl.hnogames.domoticz.Utils.SharedPrefUtil;
+import nl.hnogames.domoticz.Welcome.WelcomeViewActivity;
+
+import static android.appwidget.AppWidgetManager.EXTRA_APPWIDGET_ID;
+import static android.appwidget.AppWidgetManager.INVALID_APPWIDGET_ID;
+
+/**
+ * Created by m.heinis on 12/10/2015.
+ */
+public class WidgetActionActivity extends AppCompatActivity
+{
+ private SharedPrefUtil mSharedPrefs;
+ private final int iWelcomeResultCode = 885;
+ private Domoticz domoticz;
+
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ setContentView(R.layout.widget_configuration);
+ setResult(RESULT_CANCELED);
+
+ mSharedPrefs = new SharedPrefUtil(this);
+ domoticz = new Domoticz(this);
+
+ this.setTitle("Choose Switch");
+ getSupportActionBar().setDisplayHomeAsUpEnabled(false);
+ getSupportActionBar().setHomeButtonEnabled(false);
+
+ //1) Is domoticz connected?
+ if (mSharedPrefs.isFirstStart()) {
+ mSharedPrefs.setNavigationDefaults();
+ Intent welcomeWizard = new Intent(this, WelcomeViewActivity.class);
+ startActivityForResult(welcomeWizard, iWelcomeResultCode);
+ mSharedPrefs.setFirstStart(false);
+ } else {
+ //2) Show list of switches to choose from
+ initListViews();
+ }
+ }
+
+ /* Called when the second activity's finished */
+ protected void onActivityResult(int requestCode, int resultCode, Intent data) {
+ if (data != null && resultCode == RESULT_OK) {
+ switch (requestCode) {
+ case iWelcomeResultCode:
+ Bundle res = data.getExtras();
+ if (!res.getBoolean("RESULT", false))
+ this.finish();
+ else {
+ initListViews();
+ }
+ break;
+ }
+ }
+ }
+
+ public void initListViews() {
+ if (mSharedPrefs.isWelcomeWizardSuccess()) {
+ Log.i(this.getClass().getSimpleName(), "Showing switches for widget");
+ domoticz.getDevices(new DevicesReceiver() {
+ @Override
+ public void onReceiveDevices(final ArrayList mDevicesInfo) {
+ String[] listData = processSwitches(mDevicesInfo);
+ ListView listView = (ListView) findViewById(R.id.list);
+ ArrayAdapter adapter = new ArrayAdapter(WidgetActionActivity.this,
+ android.R.layout.simple_list_item_1, android.R.id.text1, listData);
+ listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
+ @Override
+ public void onItemClick(AdapterView> parent, View view, int position, long id) {
+ showAppWidget(mDevicesInfo.get(position));
+ }
+ });
+ listView.setAdapter(adapter);
+ }
+
+ @Override
+ public void onReceiveDevice(DevicesInfo mDevicesInfo) {
+ }
+
+ @Override
+ public void onError(Exception error) {
+ Toast.makeText(WidgetActionActivity.this, "Failed to get switches", Toast.LENGTH_SHORT).show();
+ WidgetActionActivity.this.finish();
+ }
+ },0);
+ } else {
+ Intent welcomeWizard = new Intent(this, WelcomeViewActivity.class);
+ startActivityForResult(welcomeWizard, iWelcomeResultCode);
+ overridePendingTransition(android.R.anim.fade_in, android.R.anim.fade_out);
+ }
+ }
+
+ public String[] processSwitches(ArrayList switches) {
+ String[] listData = new String[switches.size()];
+ int counter = 0;
+ for (DevicesInfo s : switches) {
+ String log = s.getIdx() + " | " + s.getName();
+ listData[counter] = log;
+ counter++;
+ }
+ return listData;
+ }
+
+ int mAppWidgetId;
+ private void showAppWidget(DevicesInfo mSelectedSwitch) {
+ mAppWidgetId = AppWidgetManager.INVALID_APPWIDGET_ID;
+ Intent intent = getIntent();
+ Bundle extras = intent.getExtras();
+
+ if (extras != null) {
+ mAppWidgetId = extras.getInt(EXTRA_APPWIDGET_ID,
+ INVALID_APPWIDGET_ID);
+
+ AppWidgetProviderInfo providerInfo = AppWidgetManager.getInstance(
+ getBaseContext()).getAppWidgetInfo(mAppWidgetId);
+
+ //save widget id in combination with idx in sharedpreferences
+ mSharedPrefs.setWidgetIDX(mAppWidgetId, mSelectedSwitch.getIdx());
+
+ Intent startService = new Intent(WidgetActionActivity.this,
+ WidgetProviderLarge.UpdateWidgetService.class);
+ startService.putExtra(EXTRA_APPWIDGET_ID, mAppWidgetId);
+ startService.setAction("FROM CONFIGURATION ACTIVITY");
+ startService(startService);
+ setResult(RESULT_OK, startService);
+
+ finish();
+ }
+ if (mAppWidgetId == INVALID_APPWIDGET_ID) {
+ Log.i("I am invalid", "I am invalid");
+ finish();
+ }
+ }
+}
\ No newline at end of file
diff --git a/app/src/main/java/nl/hnogames/domoticz/WidgetConfigurationActivity.java b/app/src/main/java/nl/hnogames/domoticz/WidgetConfigurationActivity.java
new file mode 100644
index 0000000..d3a3013
--- /dev/null
+++ b/app/src/main/java/nl/hnogames/domoticz/WidgetConfigurationActivity.java
@@ -0,0 +1,182 @@
+package nl.hnogames.domoticz;
+
+import static android.appwidget.AppWidgetManager.EXTRA_APPWIDGET_ID;
+import static android.appwidget.AppWidgetManager.INVALID_APPWIDGET_ID;
+
+import android.appwidget.AppWidgetManager;
+import android.appwidget.AppWidgetProviderInfo;
+import android.content.Intent;
+import android.os.Bundle;
+import android.support.v7.app.AppCompatActivity;
+import android.util.Log;
+import android.view.View;
+import android.widget.AdapterView;
+import android.widget.ArrayAdapter;
+import android.widget.ListView;
+import android.widget.Toast;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.Comparator;
+
+import nl.hnogames.domoticz.Containers.DevicesInfo;
+import nl.hnogames.domoticz.Containers.SwitchInfo;
+import nl.hnogames.domoticz.Domoticz.Domoticz;
+import nl.hnogames.domoticz.Interfaces.DevicesReceiver;
+import nl.hnogames.domoticz.Interfaces.SwitchesReceiver;
+import nl.hnogames.domoticz.Service.WidgetProviderLarge;
+import nl.hnogames.domoticz.Utils.SharedPrefUtil;
+import nl.hnogames.domoticz.Welcome.WelcomeViewActivity;
+
+/**
+ * Created by m.heinis on 12/10/2015.
+ */
+public class WidgetConfigurationActivity extends AppCompatActivity
+{
+
+ private SharedPrefUtil mSharedPrefs;
+ private final int iWelcomeResultCode = 885;
+ private Domoticz domoticz;
+
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ setContentView(R.layout.widget_configuration);
+ setResult(RESULT_CANCELED);
+
+ mSharedPrefs = new SharedPrefUtil(this);
+ domoticz = new Domoticz(this);
+
+ this.setTitle("Choose Switch");
+ getSupportActionBar().setDisplayHomeAsUpEnabled(false);
+ getSupportActionBar().setHomeButtonEnabled(false);
+
+ //1) Is domoticz connected?
+ if (mSharedPrefs.isFirstStart()) {
+ mSharedPrefs.setNavigationDefaults();
+ Intent welcomeWizard = new Intent(this, WelcomeViewActivity.class);
+ startActivityForResult(welcomeWizard, iWelcomeResultCode);
+ mSharedPrefs.setFirstStart(false);
+ } else {
+ //2) Show list of switches to choose from
+ initListViews();
+ }
+ }
+
+ /* Called when the second activity's finished */
+ protected void onActivityResult(int requestCode, int resultCode, Intent data) {
+ if (data != null && resultCode == RESULT_OK) {
+ switch (requestCode) {
+ case iWelcomeResultCode:
+ Bundle res = data.getExtras();
+ if (!res.getBoolean("RESULT", false))
+ this.finish();
+ else {
+ initListViews();
+ }
+ break;
+ }
+ }
+ }
+
+ public void initListViews() {
+ if (mSharedPrefs.isWelcomeWizardSuccess()) {
+ Log.i(this.getClass().getSimpleName(), "Showing switches for widget");
+ domoticz.getDevices(new DevicesReceiver() {
+ @Override
+ public void onReceiveDevices(final ArrayList mDevicesInfo) {
+ final ArrayList mDevices = new ArrayList();
+ for (DevicesInfo s : mDevicesInfo) {
+ if (!s.getType().equals(Domoticz.Scene.Type.GROUP) && !s.getType().equals(Domoticz.Scene.Type.SCENE)) {
+ mDevices.add(s);
+ }
+ }
+ Collections.sort(mDevices);
+
+ String[] listData = processSwitches(mDevices);
+ ListView listView = (ListView) findViewById(R.id.list);
+ ArrayAdapter adapter = new ArrayAdapter(WidgetConfigurationActivity.this,
+ android.R.layout.simple_list_item_1, android.R.id.text1, listData);
+ listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
+ @Override
+ public void onItemClick(AdapterView> parent, View view, int position, long id) {
+ showAppWidget(mDevices.get(position));
+ }
+ });
+ listView.setAdapter(adapter);
+ }
+
+ @Override
+ public void onReceiveDevice(DevicesInfo mDevicesInfo) {
+ }
+
+ @Override
+ public void onError(Exception error) {
+ Toast.makeText(WidgetConfigurationActivity.this, "Failed to get switches", Toast.LENGTH_SHORT).show();
+ WidgetConfigurationActivity.this.finish();
+ }
+ },0);
+ } else {
+ Intent welcomeWizard = new Intent(this, WelcomeViewActivity.class);
+ startActivityForResult(welcomeWizard, iWelcomeResultCode);
+ overridePendingTransition(android.R.anim.fade_in, android.R.anim.fade_out);
+ }
+ }
+
+ @Override
+ protected void onStop()
+ {
+ if(domoticz!=null)
+ domoticz.Disconnect();
+
+ super.onStop();
+ }
+
+ public String[] processSwitches(ArrayList switches) {
+ String[] listData = new String[switches.size()];
+ int counter = 0;
+ for (DevicesInfo s : switches) {
+
+ String log = s.getName();
+ listData[counter] = log;
+ counter++;
+
+ }
+ Arrays.sort(listData);
+ return listData;
+ }
+
+ int mAppWidgetId;
+ private void showAppWidget(DevicesInfo mSelectedSwitch) {
+ mAppWidgetId = AppWidgetManager.INVALID_APPWIDGET_ID;
+ Intent intent = getIntent();
+ Bundle extras = intent.getExtras();
+
+ int idx = mSelectedSwitch.getIdx();
+
+ if (extras != null) {
+ mAppWidgetId = extras.getInt(EXTRA_APPWIDGET_ID,
+ INVALID_APPWIDGET_ID);
+
+ //AppWidgetProviderInfo providerInfo = AppWidgetManager.getInstance(
+ // getBaseContext()).getAppWidgetInfo(mAppWidgetId);
+
+ mSharedPrefs.setWidgetIDX(mAppWidgetId, idx);
+ mSharedPrefs.setWidgetIDforIDX(mAppWidgetId, idx);
+
+ Intent startService = new Intent(WidgetConfigurationActivity.this,
+ WidgetProviderLarge.UpdateWidgetService.class);
+ startService.putExtra(EXTRA_APPWIDGET_ID, mAppWidgetId);
+ startService.setAction("FROM CONFIGURATION ACTIVITY");
+ startService(startService);
+ setResult(RESULT_OK, startService);
+
+ finish();
+ }
+ if (mAppWidgetId == INVALID_APPWIDGET_ID) {
+ Log.i("I am invalid", "I am invalid");
+ finish();
+ }
+ }
+}
\ No newline at end of file
diff --git a/app/src/main/res/drawable-hdpi-v14/appwidget_bg.9.png b/app/src/main/res/drawable-hdpi-v14/appwidget_bg.9.png
new file mode 100644
index 0000000..1783677
Binary files /dev/null and b/app/src/main/res/drawable-hdpi-v14/appwidget_bg.9.png differ
diff --git a/app/src/main/res/drawable-hdpi-v14/appwidget_bg_focused.9.png b/app/src/main/res/drawable-hdpi-v14/appwidget_bg_focused.9.png
new file mode 100644
index 0000000..901a080
Binary files /dev/null and b/app/src/main/res/drawable-hdpi-v14/appwidget_bg_focused.9.png differ
diff --git a/app/src/main/res/drawable-hdpi-v14/appwidget_bg_pressed.9.png b/app/src/main/res/drawable-hdpi-v14/appwidget_bg_pressed.9.png
new file mode 100644
index 0000000..efacbcf
Binary files /dev/null and b/app/src/main/res/drawable-hdpi-v14/appwidget_bg_pressed.9.png differ
diff --git a/app/src/main/res/drawable-hdpi-v14/appwidget_dark_bg.9.png b/app/src/main/res/drawable-hdpi-v14/appwidget_dark_bg.9.png
new file mode 100644
index 0000000..02ee440
Binary files /dev/null and b/app/src/main/res/drawable-hdpi-v14/appwidget_dark_bg.9.png differ
diff --git a/app/src/main/res/drawable-hdpi-v14/appwidget_dark_bg_focused.9.png b/app/src/main/res/drawable-hdpi-v14/appwidget_dark_bg_focused.9.png
new file mode 100644
index 0000000..ccc0177
Binary files /dev/null and b/app/src/main/res/drawable-hdpi-v14/appwidget_dark_bg_focused.9.png differ
diff --git a/app/src/main/res/drawable-hdpi-v14/appwidget_inner_focused_c.9.png b/app/src/main/res/drawable-hdpi-v14/appwidget_inner_focused_c.9.png
new file mode 100644
index 0000000..5aafacd
Binary files /dev/null and b/app/src/main/res/drawable-hdpi-v14/appwidget_inner_focused_c.9.png differ
diff --git a/app/src/main/res/drawable-hdpi-v14/appwidget_inner_focused_l.9.png b/app/src/main/res/drawable-hdpi-v14/appwidget_inner_focused_l.9.png
new file mode 100644
index 0000000..ab6e8f3
Binary files /dev/null and b/app/src/main/res/drawable-hdpi-v14/appwidget_inner_focused_l.9.png differ
diff --git a/app/src/main/res/drawable-hdpi-v14/appwidget_inner_focused_r.9.png b/app/src/main/res/drawable-hdpi-v14/appwidget_inner_focused_r.9.png
new file mode 100644
index 0000000..6c1b3c6
Binary files /dev/null and b/app/src/main/res/drawable-hdpi-v14/appwidget_inner_focused_r.9.png differ
diff --git a/app/src/main/res/drawable-hdpi-v14/appwidget_inner_pressed_c.9.png b/app/src/main/res/drawable-hdpi-v14/appwidget_inner_pressed_c.9.png
new file mode 100644
index 0000000..470f5c0
Binary files /dev/null and b/app/src/main/res/drawable-hdpi-v14/appwidget_inner_pressed_c.9.png differ
diff --git a/app/src/main/res/drawable-hdpi-v14/appwidget_inner_pressed_l.9.png b/app/src/main/res/drawable-hdpi-v14/appwidget_inner_pressed_l.9.png
new file mode 100644
index 0000000..e3aa8db
Binary files /dev/null and b/app/src/main/res/drawable-hdpi-v14/appwidget_inner_pressed_l.9.png differ
diff --git a/app/src/main/res/drawable-hdpi-v14/appwidget_inner_pressed_r.9.png b/app/src/main/res/drawable-hdpi-v14/appwidget_inner_pressed_r.9.png
new file mode 100644
index 0000000..9e27d2f
Binary files /dev/null and b/app/src/main/res/drawable-hdpi-v14/appwidget_inner_pressed_r.9.png differ
diff --git a/app/src/main/res/drawable-hdpi/appwidget_bg.9.png b/app/src/main/res/drawable-hdpi/appwidget_bg.9.png
new file mode 100644
index 0000000..d9af8fb
Binary files /dev/null and b/app/src/main/res/drawable-hdpi/appwidget_bg.9.png differ
diff --git a/app/src/main/res/drawable-hdpi/appwidget_bg_focused.9.png b/app/src/main/res/drawable-hdpi/appwidget_bg_focused.9.png
new file mode 100644
index 0000000..ee098af
Binary files /dev/null and b/app/src/main/res/drawable-hdpi/appwidget_bg_focused.9.png differ
diff --git a/app/src/main/res/drawable-hdpi/appwidget_bg_pressed.9.png b/app/src/main/res/drawable-hdpi/appwidget_bg_pressed.9.png
new file mode 100644
index 0000000..03ca2a1
Binary files /dev/null and b/app/src/main/res/drawable-hdpi/appwidget_bg_pressed.9.png differ
diff --git a/app/src/main/res/drawable-hdpi/appwidget_dark_bg.9.png b/app/src/main/res/drawable-hdpi/appwidget_dark_bg.9.png
new file mode 100644
index 0000000..3b29eae
Binary files /dev/null and b/app/src/main/res/drawable-hdpi/appwidget_dark_bg.9.png differ
diff --git a/app/src/main/res/drawable-hdpi/appwidget_dark_bg_focused.9.png b/app/src/main/res/drawable-hdpi/appwidget_dark_bg_focused.9.png
new file mode 100644
index 0000000..9fae722
Binary files /dev/null and b/app/src/main/res/drawable-hdpi/appwidget_dark_bg_focused.9.png differ
diff --git a/app/src/main/res/drawable-hdpi/appwidget_dark_bg_pressed.9.png b/app/src/main/res/drawable-hdpi/appwidget_dark_bg_pressed.9.png
new file mode 100644
index 0000000..8df4c69
Binary files /dev/null and b/app/src/main/res/drawable-hdpi/appwidget_dark_bg_pressed.9.png differ
diff --git a/app/src/main/res/drawable-hdpi/appwidget_inner_focused_c.9.png b/app/src/main/res/drawable-hdpi/appwidget_inner_focused_c.9.png
new file mode 100644
index 0000000..a949bd2
Binary files /dev/null and b/app/src/main/res/drawable-hdpi/appwidget_inner_focused_c.9.png differ
diff --git a/app/src/main/res/drawable-hdpi/appwidget_inner_focused_l.9.png b/app/src/main/res/drawable-hdpi/appwidget_inner_focused_l.9.png
new file mode 100644
index 0000000..4aaca6c
Binary files /dev/null and b/app/src/main/res/drawable-hdpi/appwidget_inner_focused_l.9.png differ
diff --git a/app/src/main/res/drawable-hdpi/appwidget_inner_focused_r.9.png b/app/src/main/res/drawable-hdpi/appwidget_inner_focused_r.9.png
new file mode 100644
index 0000000..1fc0f90
Binary files /dev/null and b/app/src/main/res/drawable-hdpi/appwidget_inner_focused_r.9.png differ
diff --git a/app/src/main/res/drawable-hdpi/appwidget_inner_pressed_c.9.png b/app/src/main/res/drawable-hdpi/appwidget_inner_pressed_c.9.png
new file mode 100644
index 0000000..ca6f16c
Binary files /dev/null and b/app/src/main/res/drawable-hdpi/appwidget_inner_pressed_c.9.png differ
diff --git a/app/src/main/res/drawable-hdpi/appwidget_inner_pressed_l.9.png b/app/src/main/res/drawable-hdpi/appwidget_inner_pressed_l.9.png
new file mode 100644
index 0000000..642eb3d
Binary files /dev/null and b/app/src/main/res/drawable-hdpi/appwidget_inner_pressed_l.9.png differ
diff --git a/app/src/main/res/drawable-hdpi/appwidget_inner_pressed_r.9.png b/app/src/main/res/drawable-hdpi/appwidget_inner_pressed_r.9.png
new file mode 100644
index 0000000..5e1f70a
Binary files /dev/null and b/app/src/main/res/drawable-hdpi/appwidget_inner_pressed_r.9.png differ
diff --git a/app/src/main/res/drawable-mdpi-v14/appwidget_bg.9.png b/app/src/main/res/drawable-mdpi-v14/appwidget_bg.9.png
new file mode 100644
index 0000000..2ae3070
Binary files /dev/null and b/app/src/main/res/drawable-mdpi-v14/appwidget_bg.9.png differ
diff --git a/app/src/main/res/drawable-mdpi-v14/appwidget_bg_focused.9.png b/app/src/main/res/drawable-mdpi-v14/appwidget_bg_focused.9.png
new file mode 100644
index 0000000..5044f84
Binary files /dev/null and b/app/src/main/res/drawable-mdpi-v14/appwidget_bg_focused.9.png differ
diff --git a/app/src/main/res/drawable-mdpi-v14/appwidget_bg_pressed.9.png b/app/src/main/res/drawable-mdpi-v14/appwidget_bg_pressed.9.png
new file mode 100644
index 0000000..5c03b8a
Binary files /dev/null and b/app/src/main/res/drawable-mdpi-v14/appwidget_bg_pressed.9.png differ
diff --git a/app/src/main/res/drawable-mdpi-v14/appwidget_dark_bg.9.png b/app/src/main/res/drawable-mdpi-v14/appwidget_dark_bg.9.png
new file mode 100644
index 0000000..a245d91
Binary files /dev/null and b/app/src/main/res/drawable-mdpi-v14/appwidget_dark_bg.9.png differ
diff --git a/app/src/main/res/drawable-mdpi-v14/appwidget_dark_bg_focused.9.png b/app/src/main/res/drawable-mdpi-v14/appwidget_dark_bg_focused.9.png
new file mode 100644
index 0000000..fa2d682
Binary files /dev/null and b/app/src/main/res/drawable-mdpi-v14/appwidget_dark_bg_focused.9.png differ
diff --git a/app/src/main/res/drawable-mdpi-v14/appwidget_inner_focused_c.9.png b/app/src/main/res/drawable-mdpi-v14/appwidget_inner_focused_c.9.png
new file mode 100644
index 0000000..cc50fe9
Binary files /dev/null and b/app/src/main/res/drawable-mdpi-v14/appwidget_inner_focused_c.9.png differ
diff --git a/app/src/main/res/drawable-mdpi-v14/appwidget_inner_focused_l.9.png b/app/src/main/res/drawable-mdpi-v14/appwidget_inner_focused_l.9.png
new file mode 100644
index 0000000..feaa6c7
Binary files /dev/null and b/app/src/main/res/drawable-mdpi-v14/appwidget_inner_focused_l.9.png differ
diff --git a/app/src/main/res/drawable-mdpi-v14/appwidget_inner_focused_r.9.png b/app/src/main/res/drawable-mdpi-v14/appwidget_inner_focused_r.9.png
new file mode 100644
index 0000000..8d22c56
Binary files /dev/null and b/app/src/main/res/drawable-mdpi-v14/appwidget_inner_focused_r.9.png differ
diff --git a/app/src/main/res/drawable-mdpi-v14/appwidget_inner_pressed_c.9.png b/app/src/main/res/drawable-mdpi-v14/appwidget_inner_pressed_c.9.png
new file mode 100644
index 0000000..aa80a7c
Binary files /dev/null and b/app/src/main/res/drawable-mdpi-v14/appwidget_inner_pressed_c.9.png differ
diff --git a/app/src/main/res/drawable-mdpi-v14/appwidget_inner_pressed_l.9.png b/app/src/main/res/drawable-mdpi-v14/appwidget_inner_pressed_l.9.png
new file mode 100644
index 0000000..e49e8a9
Binary files /dev/null and b/app/src/main/res/drawable-mdpi-v14/appwidget_inner_pressed_l.9.png differ
diff --git a/app/src/main/res/drawable-mdpi-v14/appwidget_inner_pressed_r.9.png b/app/src/main/res/drawable-mdpi-v14/appwidget_inner_pressed_r.9.png
new file mode 100644
index 0000000..a54ecd0
Binary files /dev/null and b/app/src/main/res/drawable-mdpi-v14/appwidget_inner_pressed_r.9.png differ
diff --git a/app/src/main/res/drawable-mdpi/appwidget_bg.9.png b/app/src/main/res/drawable-mdpi/appwidget_bg.9.png
new file mode 100644
index 0000000..8049191
Binary files /dev/null and b/app/src/main/res/drawable-mdpi/appwidget_bg.9.png differ
diff --git a/app/src/main/res/drawable-mdpi/appwidget_bg_focused.9.png b/app/src/main/res/drawable-mdpi/appwidget_bg_focused.9.png
new file mode 100644
index 0000000..f4bbb08
Binary files /dev/null and b/app/src/main/res/drawable-mdpi/appwidget_bg_focused.9.png differ
diff --git a/app/src/main/res/drawable-mdpi/appwidget_bg_pressed.9.png b/app/src/main/res/drawable-mdpi/appwidget_bg_pressed.9.png
new file mode 100644
index 0000000..d060b77
Binary files /dev/null and b/app/src/main/res/drawable-mdpi/appwidget_bg_pressed.9.png differ
diff --git a/app/src/main/res/drawable-mdpi/appwidget_dark_bg.9.png b/app/src/main/res/drawable-mdpi/appwidget_dark_bg.9.png
new file mode 100644
index 0000000..afe41b6
Binary files /dev/null and b/app/src/main/res/drawable-mdpi/appwidget_dark_bg.9.png differ
diff --git a/app/src/main/res/drawable-mdpi/appwidget_dark_bg_focused.9.png b/app/src/main/res/drawable-mdpi/appwidget_dark_bg_focused.9.png
new file mode 100644
index 0000000..8b4ce3f
Binary files /dev/null and b/app/src/main/res/drawable-mdpi/appwidget_dark_bg_focused.9.png differ
diff --git a/app/src/main/res/drawable-mdpi/appwidget_dark_bg_pressed.9.png b/app/src/main/res/drawable-mdpi/appwidget_dark_bg_pressed.9.png
new file mode 100644
index 0000000..ca8d5ac
Binary files /dev/null and b/app/src/main/res/drawable-mdpi/appwidget_dark_bg_pressed.9.png differ
diff --git a/app/src/main/res/drawable-mdpi/appwidget_inner_focused_c.9.png b/app/src/main/res/drawable-mdpi/appwidget_inner_focused_c.9.png
new file mode 100644
index 0000000..1450e65
Binary files /dev/null and b/app/src/main/res/drawable-mdpi/appwidget_inner_focused_c.9.png differ
diff --git a/app/src/main/res/drawable-mdpi/appwidget_inner_focused_l.9.png b/app/src/main/res/drawable-mdpi/appwidget_inner_focused_l.9.png
new file mode 100644
index 0000000..6e8f100
Binary files /dev/null and b/app/src/main/res/drawable-mdpi/appwidget_inner_focused_l.9.png differ
diff --git a/app/src/main/res/drawable-mdpi/appwidget_inner_focused_r.9.png b/app/src/main/res/drawable-mdpi/appwidget_inner_focused_r.9.png
new file mode 100644
index 0000000..bc8757b
Binary files /dev/null and b/app/src/main/res/drawable-mdpi/appwidget_inner_focused_r.9.png differ
diff --git a/app/src/main/res/drawable-mdpi/appwidget_inner_pressed_c.9.png b/app/src/main/res/drawable-mdpi/appwidget_inner_pressed_c.9.png
new file mode 100644
index 0000000..bd542ba
Binary files /dev/null and b/app/src/main/res/drawable-mdpi/appwidget_inner_pressed_c.9.png differ
diff --git a/app/src/main/res/drawable-mdpi/appwidget_inner_pressed_l.9.png b/app/src/main/res/drawable-mdpi/appwidget_inner_pressed_l.9.png
new file mode 100644
index 0000000..575ecf4
Binary files /dev/null and b/app/src/main/res/drawable-mdpi/appwidget_inner_pressed_l.9.png differ
diff --git a/app/src/main/res/drawable-mdpi/appwidget_inner_pressed_r.9.png b/app/src/main/res/drawable-mdpi/appwidget_inner_pressed_r.9.png
new file mode 100644
index 0000000..79eaea3
Binary files /dev/null and b/app/src/main/res/drawable-mdpi/appwidget_inner_pressed_r.9.png differ
diff --git a/app/src/main/res/drawable-nodpi/widget_preview_dark.png b/app/src/main/res/drawable-nodpi/widget_preview_dark.png
new file mode 100644
index 0000000..ba4bcee
Binary files /dev/null and b/app/src/main/res/drawable-nodpi/widget_preview_dark.png differ
diff --git a/app/src/main/res/drawable-nodpi/widget_preview_light.png b/app/src/main/res/drawable-nodpi/widget_preview_light.png
new file mode 100644
index 0000000..9d3bd6c
Binary files /dev/null and b/app/src/main/res/drawable-nodpi/widget_preview_light.png differ
diff --git a/app/src/main/res/drawable-xhdpi-v14/appwidget_bg.9.png b/app/src/main/res/drawable-xhdpi-v14/appwidget_bg.9.png
new file mode 100644
index 0000000..909f498
Binary files /dev/null and b/app/src/main/res/drawable-xhdpi-v14/appwidget_bg.9.png differ
diff --git a/app/src/main/res/drawable-xhdpi-v14/appwidget_bg_focused.9.png b/app/src/main/res/drawable-xhdpi-v14/appwidget_bg_focused.9.png
new file mode 100644
index 0000000..fccb4d9
Binary files /dev/null and b/app/src/main/res/drawable-xhdpi-v14/appwidget_bg_focused.9.png differ
diff --git a/app/src/main/res/drawable-xhdpi-v14/appwidget_bg_pressed.9.png b/app/src/main/res/drawable-xhdpi-v14/appwidget_bg_pressed.9.png
new file mode 100644
index 0000000..97a3ba0
Binary files /dev/null and b/app/src/main/res/drawable-xhdpi-v14/appwidget_bg_pressed.9.png differ
diff --git a/app/src/main/res/drawable-xhdpi-v14/appwidget_dark_bg.9.png b/app/src/main/res/drawable-xhdpi-v14/appwidget_dark_bg.9.png
new file mode 100644
index 0000000..7ccb762
Binary files /dev/null and b/app/src/main/res/drawable-xhdpi-v14/appwidget_dark_bg.9.png differ
diff --git a/app/src/main/res/drawable-xhdpi-v14/appwidget_dark_bg_focused.9.png b/app/src/main/res/drawable-xhdpi-v14/appwidget_dark_bg_focused.9.png
new file mode 100644
index 0000000..da9289e
Binary files /dev/null and b/app/src/main/res/drawable-xhdpi-v14/appwidget_dark_bg_focused.9.png differ
diff --git a/app/src/main/res/drawable-xhdpi-v14/appwidget_inner_focused_c.9.png b/app/src/main/res/drawable-xhdpi-v14/appwidget_inner_focused_c.9.png
new file mode 100644
index 0000000..0de253c
Binary files /dev/null and b/app/src/main/res/drawable-xhdpi-v14/appwidget_inner_focused_c.9.png differ
diff --git a/app/src/main/res/drawable-xhdpi-v14/appwidget_inner_focused_l.9.png b/app/src/main/res/drawable-xhdpi-v14/appwidget_inner_focused_l.9.png
new file mode 100644
index 0000000..ce9decd
Binary files /dev/null and b/app/src/main/res/drawable-xhdpi-v14/appwidget_inner_focused_l.9.png differ
diff --git a/app/src/main/res/drawable-xhdpi-v14/appwidget_inner_focused_r.9.png b/app/src/main/res/drawable-xhdpi-v14/appwidget_inner_focused_r.9.png
new file mode 100644
index 0000000..448cd83
Binary files /dev/null and b/app/src/main/res/drawable-xhdpi-v14/appwidget_inner_focused_r.9.png differ
diff --git a/app/src/main/res/drawable-xhdpi-v14/appwidget_inner_pressed_c.9.png b/app/src/main/res/drawable-xhdpi-v14/appwidget_inner_pressed_c.9.png
new file mode 100644
index 0000000..defdbb9
Binary files /dev/null and b/app/src/main/res/drawable-xhdpi-v14/appwidget_inner_pressed_c.9.png differ
diff --git a/app/src/main/res/drawable-xhdpi-v14/appwidget_inner_pressed_l.9.png b/app/src/main/res/drawable-xhdpi-v14/appwidget_inner_pressed_l.9.png
new file mode 100644
index 0000000..582d0e1
Binary files /dev/null and b/app/src/main/res/drawable-xhdpi-v14/appwidget_inner_pressed_l.9.png differ
diff --git a/app/src/main/res/drawable-xhdpi-v14/appwidget_inner_pressed_r.9.png b/app/src/main/res/drawable-xhdpi-v14/appwidget_inner_pressed_r.9.png
new file mode 100644
index 0000000..9732dd7
Binary files /dev/null and b/app/src/main/res/drawable-xhdpi-v14/appwidget_inner_pressed_r.9.png differ
diff --git a/app/src/main/res/drawable/appwidget_bg_clickable.xml b/app/src/main/res/drawable/appwidget_bg_clickable.xml
new file mode 100644
index 0000000..dde1cb5
--- /dev/null
+++ b/app/src/main/res/drawable/appwidget_bg_clickable.xml
@@ -0,0 +1,24 @@
+
+
+
+
+
+
+
diff --git a/app/src/main/res/drawable/appwidget_button_center.xml b/app/src/main/res/drawable/appwidget_button_center.xml
new file mode 100644
index 0000000..06f5f57
--- /dev/null
+++ b/app/src/main/res/drawable/appwidget_button_center.xml
@@ -0,0 +1,25 @@
+
+
+
+
+
+
+
diff --git a/app/src/main/res/drawable/appwidget_button_left.xml b/app/src/main/res/drawable/appwidget_button_left.xml
new file mode 100644
index 0000000..7382f05
--- /dev/null
+++ b/app/src/main/res/drawable/appwidget_button_left.xml
@@ -0,0 +1,25 @@
+
+
+
+
+
+
+
diff --git a/app/src/main/res/drawable/appwidget_button_right.xml b/app/src/main/res/drawable/appwidget_button_right.xml
new file mode 100644
index 0000000..a812259
--- /dev/null
+++ b/app/src/main/res/drawable/appwidget_button_right.xml
@@ -0,0 +1,25 @@
+
+
+
+
+
+
+
diff --git a/app/src/main/res/drawable/appwidget_dark_bg_clickable.xml b/app/src/main/res/drawable/appwidget_dark_bg_clickable.xml
new file mode 100644
index 0000000..7cfc9d2
--- /dev/null
+++ b/app/src/main/res/drawable/appwidget_dark_bg_clickable.xml
@@ -0,0 +1,24 @@
+
+
+
+
+
+
+
diff --git a/app/src/main/res/layout/widget_configuration.xml b/app/src/main/res/layout/widget_configuration.xml
new file mode 100644
index 0000000..0e8c7b1
--- /dev/null
+++ b/app/src/main/res/layout/widget_configuration.xml
@@ -0,0 +1,21 @@
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/app/src/main/res/layout/widget_layout.xml b/app/src/main/res/layout/widget_layout.xml
new file mode 100644
index 0000000..65e2907
--- /dev/null
+++ b/app/src/main/res/layout/widget_layout.xml
@@ -0,0 +1,64 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/app/src/main/res/layout/widget_layout_default.xml b/app/src/main/res/layout/widget_layout_default.xml
new file mode 100644
index 0000000..e903626
--- /dev/null
+++ b/app/src/main/res/layout/widget_layout_default.xml
@@ -0,0 +1,54 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/app/src/main/res/xml/appwidgetprovider.xml b/app/src/main/res/xml/appwidgetprovider.xml
new file mode 100644
index 0000000..66c3e32
--- /dev/null
+++ b/app/src/main/res/xml/appwidgetprovider.xml
@@ -0,0 +1,10 @@
+
+
+
\ No newline at end of file