From f27f4f1b9ad0a1266508b44e1aba29f72568fbc3 Mon Sep 17 00:00:00 2001 From: galadril Date: Mon, 7 Dec 2015 18:43:50 +0100 Subject: [PATCH] v0.1.147 - Fix for setting a favorites when list is filtered - #67 Icons now show on/off statusses - #38 import settings now also imports the Geofences - Various other fixes! --- .../domoticz/Adapters/DevicesAdapter.java | 85 +++++++------------ .../domoticz/Adapters/EventsAdapter.java | 9 +- .../domoticz/Adapters/LocationAdapter.java | 2 +- .../domoticz/Adapters/LogAdapter.java | 1 + .../domoticz/Adapters/SceneAdapter.java | 13 +-- .../domoticz/Adapters/SwitchesAdapter.java | 49 ++++++----- .../domoticz/Adapters/TemperatureAdapter.java | 17 ++-- .../domoticz/Adapters/TimersAdapter.java | 4 +- .../Adapters/UserVariablesAdapter.java | 9 +- .../domoticz/Adapters/UtilityAdapter.java | 10 +-- .../domoticz/Adapters/WeatherAdapter.java | 4 +- .../domoticz/Containers/DevicesInfo.java | 10 ++- .../Containers/ExtendedStatusInfo.java | 4 +- .../domoticz/Containers/TemperatureInfo.java | 7 ++ .../hnogames/domoticz/Domoticz/Domoticz.java | 40 +++++---- .../hnogames/domoticz/Fragments/Camera.java | 7 +- .../domoticz/Fragments/Dashboard.java | 23 ++--- .../domoticz/Fragments/Preference.java | 16 ++-- .../hnogames/domoticz/Fragments/Scenes.java | 2 +- .../hnogames/domoticz/Fragments/Switches.java | 16 +--- .../domoticz/Fragments/Temperature.java | 2 +- .../domoticz/Fragments/Utilities.java | 2 +- .../hnogames/domoticz/Fragments/Weather.java | 4 +- .../domoticz/GeoSettingsActivity.java | 2 +- .../nl/hnogames/domoticz/MainActivity.java | 2 +- .../GeofenceTransitionsIntentService.java | 3 +- .../Service/WearMessageListenerService.java | 4 +- .../domoticz/UI/ColorPickerDialog.java | 9 +- .../domoticz/UI/MultiSelectionSpinner.java | 8 +- .../hnogames/domoticz/Utils/ColorsUtil.java | 3 +- .../domoticz/Utils/PermissionsUtil.java | 25 +----- .../domoticz/Utils/SharedPrefUtil.java | 17 ++-- .../domoticz/Welcome/WelcomePage2.java | 17 ++-- .../domoticz/Welcome/WelcomePage3.java | 10 +-- .../domoticz/Welcome/WelcomeViewActivity.java | 2 - .../domoticz/app/DomoticzFragment.java | 3 +- 36 files changed, 198 insertions(+), 243 deletions(-) diff --git a/app/src/main/java/nl/hnogames/domoticz/Adapters/DevicesAdapter.java b/app/src/main/java/nl/hnogames/domoticz/Adapters/DevicesAdapter.java index 2470100..d11d703 100644 --- a/app/src/main/java/nl/hnogames/domoticz/Adapters/DevicesAdapter.java +++ b/app/src/main/java/nl/hnogames/domoticz/Adapters/DevicesAdapter.java @@ -55,9 +55,9 @@ public class DevicesAdapter extends BaseAdapter implements Filterable { public final int ID_SCENE_SWITCH = 2000; - Domoticz domoticz; + private Domoticz domoticz; private Context context; - private ArrayList filteredData = null; + public ArrayList filteredData = null; private ArrayList data = null; private switchesClickListener listener; private int layoutResourceId; @@ -87,6 +87,7 @@ public int compare(DevicesInfo left, DevicesInfo right) { this.listener = listener; } + @Override public int getCount() { return filteredData.size(); @@ -137,8 +138,7 @@ private View setSwitchRowId(DevicesInfo mExtendedStatusInfo, ViewHolder holder) row = setDefaultRowId(holder); break; } - } - else { + } else { boolean switchFound = true; switch (mExtendedStatusInfo.getSwitchTypeVal()) { case Domoticz.Device.Type.Value.ON_OFF: @@ -171,7 +171,7 @@ private View setSwitchRowId(DevicesInfo mExtendedStatusInfo, ViewHolder holder) break; default: - switchFound=false; + switchFound = false; break; } } @@ -329,8 +329,7 @@ private void setSwitchRowData(DevicesInfo mExtendedStatusInfo, setDefaultRowData(mExtendedStatusInfo, holder); break; } - } - else + } else switch (mExtendedStatusInfo.getSwitchTypeVal()) { case Domoticz.Device.Type.Value.ON_OFF: case Domoticz.Device.Type.Value.MEDIAPLAYER: @@ -383,20 +382,16 @@ private void setDefaultRowData(DevicesInfo mExtendedStatusInfo, if (holder.switch_battery_level != null) holder.switch_battery_level.setText(text); - Picasso.with(context).load(domoticz.getDrawableIcon(mExtendedStatusInfo.getTypeImg(), mExtendedStatusInfo.getSwitchType(), mExtendedStatusInfo.getStatusBoolean())).into(holder.iconRow); - if(!mExtendedStatusInfo.getStatusBoolean()) - holder.iconRow.setAlpha(0.5f); - else - holder.iconRow.setAlpha(1f); - if(!mExtendedStatusInfo.getStatusBoolean()) + holder.iconRow.setAlpha(1f); + if (!mExtendedStatusInfo.getStatusBoolean()) holder.iconRow.setAlpha(0.5f); else holder.iconRow.setAlpha(1f); } - private void setOnOffSwitchRowData(DevicesInfo mExtendedStatusInfo, - ViewHolder holder) { + private void setOnOffSwitchRowData(final DevicesInfo mExtendedStatusInfo, + final ViewHolder holder) { holder.isProtected = mExtendedStatusInfo.isProtected(); if (holder.switch_name != null) @@ -415,21 +410,15 @@ private void setOnOffSwitchRowData(DevicesInfo mExtendedStatusInfo, if (holder.isProtected) holder.onOffSwitch.setEnabled(false); - - Picasso.with(context).load(domoticz.getDrawableIcon(mExtendedStatusInfo.getTypeImg(), mExtendedStatusInfo.getSwitchType(), mExtendedStatusInfo.getStatusBoolean())).into(holder.iconRow); - if(!mExtendedStatusInfo.getStatusBoolean()) - holder.iconRow.setAlpha(0.5f); - else - holder.iconRow.setAlpha(1f); - if(!mExtendedStatusInfo.getStatusBoolean()) + if (!mExtendedStatusInfo.getStatusBoolean()) holder.iconRow.setAlpha(0.5f); else holder.iconRow.setAlpha(1f); if (holder.onOffSwitch != null) { - if(mExtendedStatusInfo.getType().equals(Domoticz.Scene.Type.GROUP) || mExtendedStatusInfo.getType().equals(Domoticz.Scene.Type.SCENE)) - holder.onOffSwitch.setId(mExtendedStatusInfo.getIdx()+this.ID_SCENE_SWITCH); + if (mExtendedStatusInfo.getType().equals(Domoticz.Scene.Type.GROUP) || mExtendedStatusInfo.getType().equals(Domoticz.Scene.Type.SCENE)) + holder.onOffSwitch.setId(mExtendedStatusInfo.getIdx() + this.ID_SCENE_SWITCH); else holder.onOffSwitch.setId(mExtendedStatusInfo.getIdx()); @@ -438,13 +427,18 @@ private void setOnOffSwitchRowData(DevicesInfo mExtendedStatusInfo, @Override public void onCheckedChanged(CompoundButton compoundButton, boolean checked) { handleOnOffSwitchClick(compoundButton.getId(), checked); + mExtendedStatusInfo.setStatusBoolean(checked); + if (!checked) + holder.iconRow.setAlpha(0.5f); + else + holder.iconRow.setAlpha(1f); } }); } if (holder.buttonLog != null) { - if(mExtendedStatusInfo.getType().equals(Domoticz.Scene.Type.GROUP) || mExtendedStatusInfo.getType().equals(Domoticz.Scene.Type.SCENE)) - holder.buttonLog.setId(mExtendedStatusInfo.getIdx()+this.ID_SCENE_SWITCH); + if (mExtendedStatusInfo.getType().equals(Domoticz.Scene.Type.GROUP) || mExtendedStatusInfo.getType().equals(Domoticz.Scene.Type.SCENE)) + holder.buttonLog.setId(mExtendedStatusInfo.getIdx() + this.ID_SCENE_SWITCH); else holder.buttonLog.setId(mExtendedStatusInfo.getIdx()); @@ -475,20 +469,14 @@ private void setPushOnOffSwitchRowData(DevicesInfo mExtendedStatusInfo, ViewHold if (holder.isProtected) holder.buttonOn.setEnabled(false); - - Picasso.with(context).load(domoticz.getDrawableIcon(mExtendedStatusInfo.getTypeImg(), mExtendedStatusInfo.getSwitchType(), mExtendedStatusInfo.getStatusBoolean())).into(holder.iconRow); - if(!mExtendedStatusInfo.getStatusBoolean()) - holder.iconRow.setAlpha(0.5f); - else - holder.iconRow.setAlpha(1f); - if(!mExtendedStatusInfo.getStatusBoolean()) + if (!mExtendedStatusInfo.getStatusBoolean()) holder.iconRow.setAlpha(0.5f); else holder.iconRow.setAlpha(1f); - if(mExtendedStatusInfo.getType().equals(Domoticz.Scene.Type.GROUP) || mExtendedStatusInfo.getType().equals(Domoticz.Scene.Type.SCENE)) - holder.buttonOn.setId(mExtendedStatusInfo.getIdx()+this.ID_SCENE_SWITCH); + if (mExtendedStatusInfo.getType().equals(Domoticz.Scene.Type.GROUP) || mExtendedStatusInfo.getType().equals(Domoticz.Scene.Type.SCENE)) + holder.buttonOn.setId(mExtendedStatusInfo.getIdx() + this.ID_SCENE_SWITCH); else holder.buttonOn.setId(mExtendedStatusInfo.getIdx()); @@ -512,8 +500,8 @@ public void onClick(View v) { }); if (holder.buttonLog != null) { - if(mExtendedStatusInfo.getType().equals(Domoticz.Scene.Type.GROUP) || mExtendedStatusInfo.getType().equals(Domoticz.Scene.Type.SCENE)) - holder.buttonLog.setId(mExtendedStatusInfo.getIdx()+this.ID_SCENE_SWITCH); + if (mExtendedStatusInfo.getType().equals(Domoticz.Scene.Type.GROUP) || mExtendedStatusInfo.getType().equals(Domoticz.Scene.Type.SCENE)) + holder.buttonLog.setId(mExtendedStatusInfo.getIdx() + this.ID_SCENE_SWITCH); else holder.buttonLog.setId(mExtendedStatusInfo.getIdx()); @@ -548,7 +536,6 @@ private void setBlindsRowData(DevicesInfo mExtendedStatusInfo, if (holder.switch_battery_level != null) holder.switch_battery_level.setText(text); - if (holder.isProtected) holder.buttonUp.setEnabled(false); holder.buttonUp.setId(mExtendedStatusInfo.getIdx()); holder.buttonUp.setOnClickListener(new View.OnClickListener() { @@ -567,14 +554,8 @@ public void onClick(View view) { } }); - - Picasso.with(context).load(domoticz.getDrawableIcon(mExtendedStatusInfo.getTypeImg(), mExtendedStatusInfo.getSwitchType(), mExtendedStatusInfo.getStatusBoolean())).into(holder.iconRow); - if(!mExtendedStatusInfo.getStatusBoolean()) - holder.iconRow.setAlpha(0.5f); - else - holder.iconRow.setAlpha(1f); - if(!mExtendedStatusInfo.getStatusBoolean()) + if (!mExtendedStatusInfo.getStatusBoolean()) holder.iconRow.setAlpha(0.5f); else holder.iconRow.setAlpha(1f); @@ -612,15 +593,12 @@ private void setDimmerRowData(final DevicesInfo mExtendedStatusInfo, mExtendedStatusInfo.getMaxDimLevel(), mExtendedStatusInfo.getLevel()); holder.switch_dimmer_level.setText(percentage); - Picasso.with(context).load(domoticz.getDrawableIcon(mExtendedStatusInfo.getTypeImg(), mExtendedStatusInfo.getSwitchType(), mExtendedStatusInfo.getStatusBoolean())).into(holder.iconRow); - if(!mExtendedStatusInfo.getStatusBoolean()) - holder.iconRow.setAlpha(0.5f); - else - holder.iconRow.setAlpha(1f); - if(!mExtendedStatusInfo.getStatusBoolean()) + Picasso.with(context).load(domoticz.getDrawableIcon(mExtendedStatusInfo.getTypeImg(), mExtendedStatusInfo.getSubType(), mExtendedStatusInfo.getStatusBoolean())).into(holder.iconRow); + if (!mExtendedStatusInfo.getStatusBoolean()) holder.iconRow.setAlpha(0.5f); else holder.iconRow.setAlpha(1f); + holder.dimmerOnOffSwitch.setId(mExtendedStatusInfo.getIdx()); if (holder.isProtected) @@ -639,6 +617,10 @@ public void onCheckedChanged(CompoundButton compoundButton, boolean checked) { holder.switch_dimmer_level.setVisibility(View.GONE); holder.dimmer.setVisibility(View.GONE); } + if (!checked) + holder.iconRow.setAlpha(0.5f); + else + holder.iconRow.setAlpha(1f); } }); @@ -674,7 +656,6 @@ public void onStopTrackingTouch(SeekBar seekBar) { } }); - if (!mExtendedStatusInfo.getStatusBoolean()) { holder.switch_dimmer_level.setVisibility(View.GONE); holder.dimmer.setVisibility(View.GONE); diff --git a/app/src/main/java/nl/hnogames/domoticz/Adapters/EventsAdapter.java b/app/src/main/java/nl/hnogames/domoticz/Adapters/EventsAdapter.java index abeb591..a643e88 100644 --- a/app/src/main/java/nl/hnogames/domoticz/Adapters/EventsAdapter.java +++ b/app/src/main/java/nl/hnogames/domoticz/Adapters/EventsAdapter.java @@ -50,10 +50,10 @@ public class EventsAdapter extends BaseAdapter implements Filterable { private static final String TAG = EventsAdapter.class.getSimpleName(); private final EventsClickListener listener; - Context context; - ArrayList filteredData = null; - ArrayList data = null; - Domoticz domoticz; + public Context context; + private ArrayList filteredData = null; + private ArrayList data = null; + private Domoticz domoticz; private ItemFilter mFilter = new ItemFilter(); public EventsAdapter(Context context, @@ -70,6 +70,7 @@ public EventsAdapter(Context context, this.listener = listener; } + @Override public int getCount() { return filteredData.size(); diff --git a/app/src/main/java/nl/hnogames/domoticz/Adapters/LocationAdapter.java b/app/src/main/java/nl/hnogames/domoticz/Adapters/LocationAdapter.java index 3f978db..540373c 100644 --- a/app/src/main/java/nl/hnogames/domoticz/Adapters/LocationAdapter.java +++ b/app/src/main/java/nl/hnogames/domoticz/Adapters/LocationAdapter.java @@ -46,7 +46,7 @@ public class LocationAdapter extends BaseAdapter { private static final String TAG = LocationAdapter.class.getSimpleName(); public ArrayList data = null; - Context context; + private Context context; private SharedPrefUtil prefs; private LocationClickListener listener; diff --git a/app/src/main/java/nl/hnogames/domoticz/Adapters/LogAdapter.java b/app/src/main/java/nl/hnogames/domoticz/Adapters/LogAdapter.java index de15cc7..a84e310 100644 --- a/app/src/main/java/nl/hnogames/domoticz/Adapters/LogAdapter.java +++ b/app/src/main/java/nl/hnogames/domoticz/Adapters/LogAdapter.java @@ -64,6 +64,7 @@ public LogAdapter(Context context, this.filteredData = data; } + @Override public int getCount() { return filteredData.size(); diff --git a/app/src/main/java/nl/hnogames/domoticz/Adapters/SceneAdapter.java b/app/src/main/java/nl/hnogames/domoticz/Adapters/SceneAdapter.java index 8239d53..7b42591 100644 --- a/app/src/main/java/nl/hnogames/domoticz/Adapters/SceneAdapter.java +++ b/app/src/main/java/nl/hnogames/domoticz/Adapters/SceneAdapter.java @@ -52,12 +52,12 @@ public class SceneAdapter extends BaseAdapter implements Filterable { private static final String TAG = SceneAdapter.class.getSimpleName(); private final ScenesClickListener listener; - Context context; - ArrayList filteredData = null; - ArrayList data = null; - Domoticz domoticz; + private Context context; + public ArrayList filteredData = null; + private ArrayList data = null; + private Domoticz domoticz; - ItemFilter mFilter = new ItemFilter(); + private ItemFilter mFilter = new ItemFilter(); public SceneAdapter(Context context, ArrayList data, @@ -79,6 +79,7 @@ public int compare(SceneInfo left, SceneInfo right) { this.listener = listener; } + @Override public int getCount() { return filteredData.size(); @@ -173,7 +174,7 @@ public void onCheckedChanged(CompoundButton compoundButton, boolean checked) { } Picasso.with(context).load(domoticz.getDrawableIcon(Domoticz.Scene.Type.GROUP.toLowerCase(), "", mSceneInfo.getStatusInBoolean())).into(holder.iconRow); - if(!mSceneInfo.getStatusInBoolean()) + if (!mSceneInfo.getStatusInBoolean()) holder.iconRow.setAlpha(0.5f); else holder.iconRow.setAlpha(1f); diff --git a/app/src/main/java/nl/hnogames/domoticz/Adapters/SwitchesAdapter.java b/app/src/main/java/nl/hnogames/domoticz/Adapters/SwitchesAdapter.java index 866b1d4..67d85ed 100644 --- a/app/src/main/java/nl/hnogames/domoticz/Adapters/SwitchesAdapter.java +++ b/app/src/main/java/nl/hnogames/domoticz/Adapters/SwitchesAdapter.java @@ -57,7 +57,7 @@ public class SwitchesAdapter extends BaseAdapter implements Filterable { Domoticz domoticz; private Context context; private ArrayList data = null; - private ArrayList filteredData = null; + public ArrayList filteredData = null; private switchesClickListener listener; private int layoutResourceId; private int previousDimmerValue; @@ -82,6 +82,7 @@ public int compare(ExtendedStatusInfo left, ExtendedStatusInfo right) { this.listener = listener; } + @Override public int getCount() { return filteredData.size(); @@ -147,7 +148,7 @@ private View setSwitchRowId(ExtendedStatusInfo mExtendedStatusInfo, ViewHolder h break; case Domoticz.Device.Type.Value.DIMMER: - if(mExtendedStatusInfo.getSubType().startsWith(Domoticz.Device.SubType.Name.RGB)) + if (mExtendedStatusInfo.getSubType().startsWith(Domoticz.Device.SubType.Name.RGB)) row = setDimmerRowId(holder, true); else row = setDimmerRowId(holder, false); @@ -228,7 +229,7 @@ private View setBlindsRowId(ViewHolder holder) { } private View setDimmerRowId(ViewHolder holder, boolean isRGB) { - if(isRGB) + if (isRGB) layoutResourceId = R.layout.switch_row_rgb_dimmer; else layoutResourceId = R.layout.switch_row_dimmer; @@ -247,7 +248,7 @@ private View setDimmerRowId(ViewHolder holder, boolean isRGB) { holder.buttonLog = (Button) row.findViewById(R.id.log_button); holder.buttonTimer = (Button) row.findViewById(R.id.timer_button); - if(isRGB) + if (isRGB) holder.buttonColor = (Button) row.findViewById(R.id.color_button); return row; } @@ -283,7 +284,7 @@ private void setSwitchRowData(ExtendedStatusInfo mExtendedStatusInfo, break; case Domoticz.Device.Type.Value.DIMMER: - if(mExtendedStatusInfo.getSubType().startsWith(Domoticz.Device.SubType.Name.RGB)) + if (mExtendedStatusInfo.getSubType().startsWith(Domoticz.Device.SubType.Name.RGB)) setDimmerRowData(mExtendedStatusInfo, holder, true); else setDimmerRowData(mExtendedStatusInfo, holder, false); @@ -295,8 +296,8 @@ private void setSwitchRowData(ExtendedStatusInfo mExtendedStatusInfo, } } - private void setOnOffSwitchRowData(ExtendedStatusInfo mExtendedStatusInfo, - ViewHolder holder) { + private void setOnOffSwitchRowData(final ExtendedStatusInfo mExtendedStatusInfo, + final ViewHolder holder) { holder.isProtected = mExtendedStatusInfo.isProtected(); holder.switch_name.setText(mExtendedStatusInfo.getName()); @@ -318,6 +319,12 @@ private void setOnOffSwitchRowData(ExtendedStatusInfo mExtendedStatusInfo, @Override public void onCheckedChanged(CompoundButton compoundButton, boolean checked) { handleOnOffSwitchClick(compoundButton.getId(), checked); + mExtendedStatusInfo.setStatusBoolean(checked); + + if (!checked) + holder.iconRow.setAlpha(0.5f); + else + holder.iconRow.setAlpha(1f); } }); @@ -339,13 +346,13 @@ public void onClick(View v) { if (mExtendedStatusInfo.getTimers().toLowerCase().equals("false")) holder.buttonTimer.setVisibility(View.INVISIBLE); - if(!mExtendedStatusInfo.getStatusBoolean()) + if (!mExtendedStatusInfo.getStatusBoolean()) holder.iconRow.setAlpha(0.5f); else holder.iconRow.setAlpha(1f); Picasso.with(context).load(domoticz.getDrawableIcon(mExtendedStatusInfo.getTypeImg(), mExtendedStatusInfo.getSwitchType(), mExtendedStatusInfo.getStatusBoolean())).into(holder.iconRow); - if(!mExtendedStatusInfo.getStatusBoolean()) + if (!mExtendedStatusInfo.getStatusBoolean()) holder.iconRow.setAlpha(0.5f); else holder.iconRow.setAlpha(1f); @@ -407,7 +414,7 @@ public void onClick(View v) { holder.buttonTimer.setVisibility(View.INVISIBLE); Picasso.with(context).load(domoticz.getDrawableIcon(mExtendedStatusInfo.getTypeImg(), mExtendedStatusInfo.getSwitchType(), mExtendedStatusInfo.getStatusBoolean())).into(holder.iconRow); - if(!mExtendedStatusInfo.getStatusBoolean()) + if (!mExtendedStatusInfo.getStatusBoolean()) holder.iconRow.setAlpha(0.5f); else holder.iconRow.setAlpha(1f); @@ -456,7 +463,7 @@ public void onClick(View view) { }); Picasso.with(context).load(domoticz.getDrawableIcon(mExtendedStatusInfo.getTypeImg(), mExtendedStatusInfo.getSwitchType(), mExtendedStatusInfo.getStatusBoolean())).into(holder.iconRow); - if(!mExtendedStatusInfo.getStatusBoolean()) + if (!mExtendedStatusInfo.getStatusBoolean()) holder.iconRow.setAlpha(0.5f); else holder.iconRow.setAlpha(1f); @@ -497,14 +504,18 @@ public void onCheckedChanged(CompoundButton compoundButton, boolean checked) { if (holder.dimmer.getProgress() <= 10) { holder.dimmer.setProgress(20);//dimmer turned on with default progress value } - if(isRGB) + if (isRGB) holder.buttonColor.setVisibility(View.VISIBLE); } else { holder.switch_dimmer_level.setVisibility(View.GONE); holder.dimmer.setVisibility(View.GONE); - if(isRGB) + if (isRGB) holder.buttonColor.setVisibility(View.GONE); } + if (!checked) + holder.iconRow.setAlpha(0.5f); + else + holder.iconRow.setAlpha(1f); } }); @@ -548,12 +559,12 @@ public void onStopTrackingTouch(SeekBar seekBar) { if (!mExtendedStatusInfo.getStatusBoolean()) { holder.switch_dimmer_level.setVisibility(View.GONE); holder.dimmer.setVisibility(View.GONE); - if(isRGB) + if (isRGB) holder.buttonColor.setVisibility(View.GONE); } else { holder.switch_dimmer_level.setVisibility(View.VISIBLE); holder.dimmer.setVisibility(View.VISIBLE); - if(isRGB) + if (isRGB) holder.buttonColor.setVisibility(View.VISIBLE); } @@ -576,8 +587,7 @@ public void onClick(View v) { if (mExtendedStatusInfo.getTimers().toLowerCase().equals("false")) holder.buttonTimer.setVisibility(View.INVISIBLE); - if(isRGB) - { + if (isRGB) { holder.buttonColor.setId(mExtendedStatusInfo.getIdx()); holder.buttonColor.setOnClickListener(new View.OnClickListener() { @Override @@ -587,12 +597,11 @@ public void onClick(View v) { }); } - Picasso.with(context).load(domoticz.getDrawableIcon(mExtendedStatusInfo.getTypeImg(), mExtendedStatusInfo.getSwitchType(), mExtendedStatusInfo.getStatusBoolean())).into(holder.iconRow); - if(!mExtendedStatusInfo.getStatusBoolean()) + Picasso.with(context).load(domoticz.getDrawableIcon(mExtendedStatusInfo.getTypeImg(), mExtendedStatusInfo.getSubType(), mExtendedStatusInfo.getStatusBoolean())).into(holder.iconRow); + if (!mExtendedStatusInfo.getStatusBoolean()) holder.iconRow.setAlpha(0.5f); else holder.iconRow.setAlpha(1f); - } private String calculateDimPercentage(int maxDimLevel, int level) { diff --git a/app/src/main/java/nl/hnogames/domoticz/Adapters/TemperatureAdapter.java b/app/src/main/java/nl/hnogames/domoticz/Adapters/TemperatureAdapter.java index 7b8112e..85c41ca 100644 --- a/app/src/main/java/nl/hnogames/domoticz/Adapters/TemperatureAdapter.java +++ b/app/src/main/java/nl/hnogames/domoticz/Adapters/TemperatureAdapter.java @@ -52,10 +52,10 @@ public class TemperatureAdapter extends BaseAdapter implements Filterable { private static final String TAG = TemperatureAdapter.class.getSimpleName(); private final TemperatureClickListener listener; - Domoticz domoticz; - Context context; - ArrayList filteredData = null; - ArrayList data = null; + private Domoticz domoticz; + private Context context; + public ArrayList filteredData = null; + private ArrayList data = null; private ItemFilter mFilter = new ItemFilter(); public TemperatureAdapter(Context context, @@ -76,6 +76,7 @@ public int compare(TemperatureInfo left, TemperatureInfo right) { this.listener = listener; } + @Override public int getCount() { return filteredData.size(); @@ -120,7 +121,13 @@ public View getView(int position, View convertView, ViewGroup parent) { holder.data = (TextView) convertView.findViewById(R.id.temperature_data); holder.hardware = (TextView) convertView.findViewById(R.id.temperature_hardware); holder.iconRow = (ImageView) convertView.findViewById(R.id.rowIcon); - Picasso.with(context).load(domoticz.getDrawableIcon(mTemperatureInfo.getTypeImg(), mTemperatureInfo.getType(), false)).into(holder.iconRow); + + + boolean toHot = false; + if (mTemperatureInfo.getTemperature() > 30) + toHot = true; + + Picasso.with(context).load(domoticz.getDrawableIcon(mTemperatureInfo.getTypeImg(), mTemperatureInfo.getType(), toHot)).into(holder.iconRow); holder.dayButton.setId(mTemperatureInfo.getIdx()); holder.dayButton.setOnClickListener(new View.OnClickListener() { diff --git a/app/src/main/java/nl/hnogames/domoticz/Adapters/TimersAdapter.java b/app/src/main/java/nl/hnogames/domoticz/Adapters/TimersAdapter.java index 91b819f..6cd127b 100644 --- a/app/src/main/java/nl/hnogames/domoticz/Adapters/TimersAdapter.java +++ b/app/src/main/java/nl/hnogames/domoticz/Adapters/TimersAdapter.java @@ -39,8 +39,8 @@ public class TimersAdapter extends BaseAdapter { private static final String TAG = TimersAdapter.class.getSimpleName(); - Context context; - ArrayList data = null; + private Context context; + private ArrayList data = null; public TimersAdapter(Context context, ArrayList data) { diff --git a/app/src/main/java/nl/hnogames/domoticz/Adapters/UserVariablesAdapter.java b/app/src/main/java/nl/hnogames/domoticz/Adapters/UserVariablesAdapter.java index 162118b..2d2fc6d 100644 --- a/app/src/main/java/nl/hnogames/domoticz/Adapters/UserVariablesAdapter.java +++ b/app/src/main/java/nl/hnogames/domoticz/Adapters/UserVariablesAdapter.java @@ -46,10 +46,10 @@ public class UserVariablesAdapter extends BaseAdapter implements Filterable { private static final String TAG = UserVariablesAdapter.class.getSimpleName(); - Context context; - ArrayList filteredData = null; - ArrayList data = null; - Domoticz domoticz; + private Context context; + public ArrayList filteredData = null; + private ArrayList data = null; + private Domoticz domoticz; private ItemFilter mFilter = new ItemFilter(); public UserVariablesAdapter(Context context, @@ -64,6 +64,7 @@ public UserVariablesAdapter(Context context, this.filteredData = data; } + @Override public int getCount() { return filteredData.size(); 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 6e6b5ae..3fd2c27 100644 --- a/app/src/main/java/nl/hnogames/domoticz/Adapters/UtilityAdapter.java +++ b/app/src/main/java/nl/hnogames/domoticz/Adapters/UtilityAdapter.java @@ -51,11 +51,11 @@ public class UtilityAdapter extends BaseAdapter implements Filterable { private static final String TAG = UtilityAdapter.class.getSimpleName(); private final UtilityClickListener listener; - Context context; - ArrayList filteredData = null; - ArrayList data = null; - Domoticz domoticz; - private ItemFilter mFilter = new ItemFilter(); + private Context context; + public ArrayList filteredData = null; + private ArrayList data = null; + private Domoticz domoticz; + private ItemFilter mFilter = new ItemFilter(); public UtilityAdapter(Context context, ArrayList data, diff --git a/app/src/main/java/nl/hnogames/domoticz/Adapters/WeatherAdapter.java b/app/src/main/java/nl/hnogames/domoticz/Adapters/WeatherAdapter.java index 97ea028..f274d4d 100644 --- a/app/src/main/java/nl/hnogames/domoticz/Adapters/WeatherAdapter.java +++ b/app/src/main/java/nl/hnogames/domoticz/Adapters/WeatherAdapter.java @@ -42,10 +42,8 @@ import java.util.Collections; import java.util.Comparator; -import nl.hnogames.domoticz.Containers.UtilitiesInfo; import nl.hnogames.domoticz.Containers.WeatherInfo; import nl.hnogames.domoticz.Domoticz.Domoticz; -import nl.hnogames.domoticz.Interfaces.UtilityClickListener; import nl.hnogames.domoticz.Interfaces.WeatherClickListener; import nl.hnogames.domoticz.R; @@ -55,7 +53,7 @@ public class WeatherAdapter extends BaseAdapter implements Filterable { private final WeatherClickListener listener; private Context context; - private ArrayList filteredData = null; + public ArrayList filteredData = null; private ArrayList data = null; private Domoticz domoticz; private ItemFilter mFilter = new ItemFilter(); 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 bc8ee96..2208e0f 100644 --- a/app/src/main/java/nl/hnogames/domoticz/Containers/DevicesInfo.java +++ b/app/src/main/java/nl/hnogames/domoticz/Containers/DevicesInfo.java @@ -30,13 +30,13 @@ public class DevicesInfo { private final String UNKNOWN = "Unknown"; private final String TAG = DevicesInfo.class.getSimpleName(); JSONObject jsonObject; - String SubType; boolean timers; int idx; String Name; String LastUpdate; long setPoint; String Type; + String SubType; int Favorite; int HardwareID; String HardwareName; @@ -136,10 +136,10 @@ public DevicesInfo(JSONObject row) throws JSONException { TypeImg = row.getString("TypeImg"); if (row.has("Type")) Type = row.getString("Type"); - if (row.has("Timers")) - timers = row.getBoolean("Timers"); if (row.has("SubType")) SubType = row.getString("SubType"); + if (row.has("Timers")) + timers = row.getBoolean("Timers"); idx = row.getInt("idx"); @@ -165,6 +165,10 @@ public String getTimers() { return Timers; } + public String getSubType() { + return SubType; + } + public String getPlanID() { return PlanID; } diff --git a/app/src/main/java/nl/hnogames/domoticz/Containers/ExtendedStatusInfo.java b/app/src/main/java/nl/hnogames/domoticz/Containers/ExtendedStatusInfo.java index 976ae4f..8d2ba70 100644 --- a/app/src/main/java/nl/hnogames/domoticz/Containers/ExtendedStatusInfo.java +++ b/app/src/main/java/nl/hnogames/domoticz/Containers/ExtendedStatusInfo.java @@ -66,8 +66,8 @@ public ExtendedStatusInfo(JSONObject row) throws JSONException { name = UNKNOWN; } - if (row.has("SubType")) - subtype = row.getString("SubType"); + if (row.has("SubType")) + subtype = row.getString("SubType"); try { if (row.has("Data")) diff --git a/app/src/main/java/nl/hnogames/domoticz/Containers/TemperatureInfo.java b/app/src/main/java/nl/hnogames/domoticz/Containers/TemperatureInfo.java index 10fc99d..9bc1d66 100644 --- a/app/src/main/java/nl/hnogames/domoticz/Containers/TemperatureInfo.java +++ b/app/src/main/java/nl/hnogames/domoticz/Containers/TemperatureInfo.java @@ -40,6 +40,7 @@ public class TemperatureInfo { int HardwareID; String HardwareName; String TypeImg; + double Temp; int signalLevel; public TemperatureInfo(JSONObject row) throws JSONException { @@ -52,6 +53,8 @@ public TemperatureInfo(JSONObject row) throws JSONException { HardwareID = row.getInt("HardwareID"); if (row.has("Type")) HardwareName = row.getString("Type"); + if (row.has("Temp")) + Temp = row.getDouble("Temp"); if (row.has("LastUpdate")) LastUpdate = row.getString("LastUpdate"); if (row.has("TypeImg")) @@ -116,6 +119,10 @@ public void setSignalLevel(int signalLevel) { this.signalLevel = signalLevel; } + public double getTemperature() { + return Temp; + } + public String getName() { return Name; } 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 aa236f9..4d153cd 100644 --- a/app/src/main/java/nl/hnogames/domoticz/Domoticz/Domoticz.java +++ b/app/src/main/java/nl/hnogames/domoticz/Domoticz/Domoticz.java @@ -624,7 +624,7 @@ public void setAction(int idx, setCommandParser parser = new setCommandParser(receiver); String url = constructSetUrl(jsonUrl, idx, jsonAction, value); - Log.v(TAG, "Action: "+url); + Log.v(TAG, "Action: " + url); RequestUtil.makeJsonPutRequest(parser, getUserCredentials(Authentication.USERNAME), getUserCredentials(Authentication.PASSWORD), @@ -633,14 +633,14 @@ public void setAction(int idx, } public void setRGBColorAction(int idx, - int jsonUrl, - int hue, - int brightness, - setCommandReceiver receiver) { + int jsonUrl, + int hue, + int brightness, + setCommandReceiver receiver) { setCommandParser parser = new setCommandParser(receiver); String url = constructSetUrl(jsonUrl, idx, Device.Dimmer.Action.COLOR, 0); url = url.replace("%hue%", String.valueOf(hue)).replace("%bright%", String.valueOf(brightness)); - Log.v(TAG, "Action: "+url); + Log.v(TAG, "Action: " + url); RequestUtil.makeJsonPutRequest(parser, getUserCredentials(Authentication.USERNAME), getUserCredentials(Authentication.PASSWORD), @@ -656,7 +656,7 @@ public void setEventAction(int id, setCommandParser parser = new setCommandParser(receiver); String url = constructSetUrl(jsonUrl, id, jsonAction, value); url += Uri.encode(xmlStatement); - Log.v(TAG, "Action: "+url); + Log.v(TAG, "Action: " + url); RequestUtil.makeJsonPutRequest(parser, getUserCredentials(Authentication.USERNAME), getUserCredentials(Authentication.PASSWORD), @@ -767,7 +767,7 @@ public void getGraphData(int idx, String range, String type, GraphDataReceiver r public int getDrawableIcon(String type, String subtype, boolean state) { int test = R.drawable.defaultimage; - switch (type) { + switch (type.toLowerCase()) { case "scene": return R.drawable.generic; case "group": @@ -779,10 +779,8 @@ public int getDrawableIcon(String type, String subtype, boolean state) { case "door": return R.drawable.door; case "lightbulb": - if(subtype!=null && subtype.length()>0 && subtype.equals(Device.Type.Name.DUSKSENSOR)) + if (subtype != null && subtype.length() > 0 && subtype.equals(Device.Type.Name.DUSKSENSOR)) return R.drawable.uvdark; - if(subtype!=null && subtype.length()>0 && subtype.startsWith(Device.SubType.Name.RGB)) - return R.drawable.rgb; else return R.drawable.lights; case "push": @@ -797,20 +795,26 @@ public int getDrawableIcon(String type, String subtype, boolean state) { return R.drawable.uv; case "contact": return R.drawable.contact; - case "LogitechMediaServer": + case "logitechMediaServer": return R.drawable.media; - case "Media": + case "media": return R.drawable.media; case "blinds": return R.drawable.down; case "dimmer": - return R.drawable.lights; + if (subtype != null && subtype.length() > 0 && subtype.startsWith(Device.SubType.Name.RGB)) + return R.drawable.rgb; + else + return R.drawable.dimmer; case "motion": return R.drawable.motion; case "security": return R.drawable.security; case "temperature": - return R.drawable.temperature; + if (state) + return R.drawable.heating; + else + return R.drawable.cooling; case "counter": return R.drawable.up; case "override_mini": @@ -825,15 +829,15 @@ public int getDrawableIcon(String type, String subtype, boolean state) { return R.drawable.leaf; case "hardware": return R.drawable.computer; - case "Fan": + case "fan": return R.drawable.fan; - case "Speaker": + case "speaker": return R.drawable.speaker; case "current": return R.drawable.wall; case "text": return R.drawable.text; - case "Alert": + case "alert": return R.drawable.siren; case "gauge": return R.drawable.gauge; diff --git a/app/src/main/java/nl/hnogames/domoticz/Fragments/Camera.java b/app/src/main/java/nl/hnogames/domoticz/Fragments/Camera.java index 630805b..909581d 100644 --- a/app/src/main/java/nl/hnogames/domoticz/Fragments/Camera.java +++ b/app/src/main/java/nl/hnogames/domoticz/Fragments/Camera.java @@ -46,7 +46,6 @@ import nl.hnogames.domoticz.R; import nl.hnogames.domoticz.Utils.PermissionsUtil; -import nl.hnogames.domoticz.Welcome.WelcomeViewActivity; public class Camera extends Fragment { @@ -72,8 +71,7 @@ public void onClick(View v) { if (!PermissionsUtil.canAccessStorage(getActivity())) { requestPermissions(PermissionsUtil.INITIAL_STORAGE_PERMS, PermissionsUtil.INITIAL_CAMERA_REQUEST); } - } - else { + } else { processImage(); } } @@ -96,8 +94,7 @@ public void onRequestPermissionsResult(int requestCode, String[] permissions, in } } - private void processImage() - { + private void processImage() { // Get access to the URI for the bitmap Uri bmpUri = getLocalBitmapUri(root); if (bmpUri != null) { 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 73d4818..fe5ccd6 100644 --- a/app/src/main/java/nl/hnogames/domoticz/Fragments/Dashboard.java +++ b/app/src/main/java/nl/hnogames/domoticz/Fragments/Dashboard.java @@ -169,7 +169,7 @@ private void createListView(ArrayList switches) { listView.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() { @Override public boolean onItemLongClick(AdapterView adapterView, View view, int index, long id) { - showInfoDialog(supportedSwitches.get(index)); + showInfoDialog(adapter.filteredData.get(index)); return true; } }); @@ -226,7 +226,7 @@ private void changeFavorite(final DevicesInfo mSwitch, final boolean isFavorite) if (isFavorite) jsonAction = Domoticz.Device.Favorite.ON; else jsonAction = Domoticz.Device.Favorite.OFF; - if(mSwitch.getType().equals(Domoticz.Scene.Type.GROUP) || mSwitch.getType().equals(Domoticz.Scene.Type.SCENE)){ + if (mSwitch.getType().equals(Domoticz.Scene.Type.GROUP) || mSwitch.getType().equals(Domoticz.Scene.Type.SCENE)) { jsonUrl = Domoticz.Json.Url.Set.SCENEFAVORITE; } @@ -234,7 +234,6 @@ private void changeFavorite(final DevicesInfo mSwitch, final boolean isFavorite) @Override public void onReceiveResult(String result) { successHandling(result, false); - mSwitch.setFavoriteBoolean(isFavorite); processDashboard(); } @@ -268,7 +267,7 @@ public void onSwitchClick(int idx, boolean checked) { else jsonAction = Domoticz.Device.Switch.Action.OFF; } - if(clickedSwitch.getType().equals(Domoticz.Scene.Type.GROUP) || clickedSwitch.getType().equals(Domoticz.Scene.Type.SCENE)) { + 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; @@ -279,7 +278,6 @@ public void onSwitchClick(int idx, boolean checked) { @Override public void onReceiveResult(String result) { successHandling(result, false); - processDashboard(); } @Override @@ -297,9 +295,9 @@ private DevicesInfo getDevice(int idx) { clickedSwitch = mExtendedStatusInfo; } } - if(clickedSwitch==null) { + if (clickedSwitch == null) { for (DevicesInfo mExtendedStatusInfo : extendedStatusSwitches) { - if(mExtendedStatusInfo.getType().equals(Domoticz.Scene.Type.GROUP) || mExtendedStatusInfo.getType().equals(Domoticz.Scene.Type.SCENE)) { + if (mExtendedStatusInfo.getType().equals(Domoticz.Scene.Type.GROUP) || mExtendedStatusInfo.getType().equals(Domoticz.Scene.Type.SCENE)) { if (mExtendedStatusInfo.getIdx() == (idx - adapter.ID_SCENE_SWITCH)) { clickedSwitch = mExtendedStatusInfo; } @@ -327,7 +325,7 @@ public void onButtonClick(int idx, boolean checked) { if (checked) jsonAction = Domoticz.Device.Switch.Action.ON; else jsonAction = Domoticz.Device.Switch.Action.OFF; - if(clickedSwitch.getType().equals(Domoticz.Scene.Type.GROUP) || clickedSwitch.getType().equals(Domoticz.Scene.Type.SCENE)) { + 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; @@ -347,13 +345,16 @@ public void onError(Exception error) { } @Override - public void onLogButtonClick(int idx) {} + public void onLogButtonClick(int idx) { + } @Override - public void onColorButtonClick(int idx) {} + public void onColorButtonClick(int idx) { + } @Override - public void onTimerButtonClick(int idx) {} + public void onTimerButtonClick(int idx) { + } @Override diff --git a/app/src/main/java/nl/hnogames/domoticz/Fragments/Preference.java b/app/src/main/java/nl/hnogames/domoticz/Fragments/Preference.java index c55e131..0ee54e1 100644 --- a/app/src/main/java/nl/hnogames/domoticz/Fragments/Preference.java +++ b/app/src/main/java/nl/hnogames/domoticz/Fragments/Preference.java @@ -40,7 +40,6 @@ import nl.hnogames.domoticz.R; import nl.hnogames.domoticz.Utils.PermissionsUtil; import nl.hnogames.domoticz.Utils.SharedPrefUtil; -import nl.hnogames.domoticz.Welcome.WelcomeViewActivity; public class Preference extends PreferenceFragment { @@ -73,11 +72,9 @@ public boolean onPreferenceClick(android.preference.Preference preference) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { if (!PermissionsUtil.canAccessStorage(getActivity())) { requestPermissions(PermissionsUtil.INITIAL_STORAGE_PERMS, PermissionsUtil.INITIAL_IMPORT_SETTINGS_REQUEST); - } - else + } else exportSettings(); - } - else { + } else { exportSettings(); } return false; @@ -91,11 +88,9 @@ public boolean onPreferenceClick(android.preference.Preference preference) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { if (!PermissionsUtil.canAccessStorage(getActivity())) { requestPermissions(PermissionsUtil.INITIAL_STORAGE_PERMS, PermissionsUtil.INITIAL_IMPORT_SETTINGS_REQUEST); - } - else + } else importSettings(); - } - else { + } else { importSettings(); } return false; @@ -128,8 +123,7 @@ private void importSettings() { Toast.makeText(getActivity(), "Failed to Import Settings.", Toast.LENGTH_SHORT).show(); } - private void exportSettings() - { + private void exportSettings() { Log.v("Export Settings", "Exporting settings to: " + SettingsFile.getPath()); if (mSharedPrefs.saveSharedPreferencesToFile(SettingsFile)) Toast.makeText(getActivity(), "Settings Exported.", Toast.LENGTH_SHORT).show(); diff --git a/app/src/main/java/nl/hnogames/domoticz/Fragments/Scenes.java b/app/src/main/java/nl/hnogames/domoticz/Fragments/Scenes.java index 24ade1a..560062c 100644 --- a/app/src/main/java/nl/hnogames/domoticz/Fragments/Scenes.java +++ b/app/src/main/java/nl/hnogames/domoticz/Fragments/Scenes.java @@ -118,7 +118,7 @@ public void createListView(final ArrayList scenes) { @Override public boolean onItemLongClick(AdapterView adapterView, View view, int index, long id) { - showInfoDialog(scenes.get(index)); + showInfoDialog(adapter.filteredData.get(index)); return true; } }); diff --git a/app/src/main/java/nl/hnogames/domoticz/Fragments/Switches.java b/app/src/main/java/nl/hnogames/domoticz/Fragments/Switches.java index abfe89a..04fa6bb 100644 --- a/app/src/main/java/nl/hnogames/domoticz/Fragments/Switches.java +++ b/app/src/main/java/nl/hnogames/domoticz/Fragments/Switches.java @@ -25,16 +25,13 @@ import android.app.Activity; import android.app.ProgressDialog; import android.content.Context; -import android.content.DialogInterface; import android.graphics.Color; import android.support.design.widget.CoordinatorLayout; import android.support.design.widget.Snackbar; -import android.support.v4.content.ContextCompat; import android.support.v4.widget.SwipeRefreshLayout; import android.util.Log; import android.view.View; import android.widget.AdapterView; -import android.widget.Button; import android.widget.ListView; import android.widget.Toast; @@ -185,7 +182,7 @@ private void createListView(ArrayList switches) { @Override public boolean onItemLongClick(AdapterView adapterView, View view, int index, long id) { - showInfoDialog(supportedSwitches.get(index)); + showInfoDialog(adapter.filteredData.get(index)); return true; } }); @@ -231,7 +228,6 @@ private void showLogDialog(ArrayList switchLogs) { getActivity(), switchLogs, R.layout.dialog_switch_logs); - infoDialog.show(); } } @@ -244,7 +240,6 @@ private void showTimerDialog(ArrayList switchLogs) { getActivity(), switchLogs, R.layout.dialog_switch_logs); - infoDialog.show(); } } @@ -258,7 +253,6 @@ private void changeFavorite(final ExtendedStatusInfo mSwitch, final boolean isFa else Snackbar.make(coordinatorLayout, mSwitch.getName() + " " + getActivity().getString(R.string.favorite_removed), Snackbar.LENGTH_SHORT).show(); - int jsonAction; int jsonUrl = Domoticz.Json.Url.Set.FAVORITE; @@ -307,7 +301,7 @@ public void onColorButtonClick(final int idx) { @Override public void onDismiss(int selectedColor) { float[] hsv = new float[3]; - Color.RGBToHSV(Color.red(selectedColor),Color.green(selectedColor),Color.blue(selectedColor), hsv); + Color.RGBToHSV(Color.red(selectedColor), Color.green(selectedColor), Color.blue(selectedColor), hsv); Log.v(TAG, "Selected HVS Color: h:" + hsv[0] + " v:" + hsv[1] + " s:" + hsv[2]); mDomoticz.setRGBColorAction(idx, @@ -317,8 +311,7 @@ public void onDismiss(int selectedColor) { new setCommandReceiver() { @Override public void onReceiveResult(String result) { - Snackbar.make(coordinatorLayout, "Color set for: "+getSwitch(idx).getName(), Snackbar.LENGTH_SHORT).show(); - getSwitchesData(); + Snackbar.make(coordinatorLayout, "Color set for: " + getSwitch(idx).getName(), Snackbar.LENGTH_SHORT).show(); } @Override @@ -383,7 +376,6 @@ public void onSwitchClick(int idx, boolean checked) { @Override public void onReceiveResult(String result) { successHandling(result, false); - getSwitchesData(); } @Override @@ -443,7 +435,6 @@ else if (jsonAction == Domoticz.Device.Blind.Action.DOWN) @Override public void onReceiveResult(String result) { successHandling(result, false); - getSwitchesData(); } @Override @@ -462,7 +453,6 @@ public void onDimmerChange(int idx, int value) { int jsonUrl = Domoticz.Json.Url.Set.SWITCHES; int jsonAction = Domoticz.Device.Dimmer.Action.DIM_LEVEL; - mDomoticz.setAction(idx, jsonUrl, jsonAction, value, new setCommandReceiver() { @Override public void onReceiveResult(String result) { diff --git a/app/src/main/java/nl/hnogames/domoticz/Fragments/Temperature.java b/app/src/main/java/nl/hnogames/domoticz/Fragments/Temperature.java index e92deee..04f25ff 100644 --- a/app/src/main/java/nl/hnogames/domoticz/Fragments/Temperature.java +++ b/app/src/main/java/nl/hnogames/domoticz/Fragments/Temperature.java @@ -118,7 +118,7 @@ public void onReceiveTemperatures(ArrayList mTemperatureInfos) @Override public boolean onItemLongClick(AdapterView adapterView, View view, int index, long id) { - showInfoDialog(Temperature.this.mTemperatureInfos.get(index)); + showInfoDialog(adapter.filteredData.get(index)); return true; } }); 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 249d56c..9f3a4bb 100644 --- a/app/src/main/java/nl/hnogames/domoticz/Fragments/Utilities.java +++ b/app/src/main/java/nl/hnogames/domoticz/Fragments/Utilities.java @@ -132,7 +132,7 @@ private void createListView() { @Override public boolean onItemLongClick(AdapterView adapterView, View view, int index, long id) { - showInfoDialog(Utilities.this.mUtilitiesInfos.get(index)); + showInfoDialog(adapter.filteredData.get(index)); return true; } }); diff --git a/app/src/main/java/nl/hnogames/domoticz/Fragments/Weather.java b/app/src/main/java/nl/hnogames/domoticz/Fragments/Weather.java index 0d9da1a..5022fab 100644 --- a/app/src/main/java/nl/hnogames/domoticz/Fragments/Weather.java +++ b/app/src/main/java/nl/hnogames/domoticz/Fragments/Weather.java @@ -98,12 +98,12 @@ public void onReceiveWeather(ArrayList mWeatherInfos) { @Override public boolean onItemLongClick(AdapterView adapterView, View view, int index, long id) { - showInfoDialog(Weather.this.mWeatherInfos.get(index)); + showInfoDialog(adapter.filteredData.get(index)); return true; } }); - mSwipeRefreshLayout.setRefreshing(false); + mSwipeRefreshLayout.setRefreshing(false); mSwipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() { @Override public void onRefresh() { diff --git a/app/src/main/java/nl/hnogames/domoticz/GeoSettingsActivity.java b/app/src/main/java/nl/hnogames/domoticz/GeoSettingsActivity.java index 2e78d11..0608517 100644 --- a/app/src/main/java/nl/hnogames/domoticz/GeoSettingsActivity.java +++ b/app/src/main/java/nl/hnogames/domoticz/GeoSettingsActivity.java @@ -312,7 +312,7 @@ public void getLocation(String usedLocationService) { return; } currectLocation = locationManager.getLastKnownLocation(LocationManager.NETWORK_PROVIDER); - if(currectLocation!=null) + if (currectLocation != null) setMarker(new LatLng(currectLocation.getLatitude(), currectLocation.getLongitude())); } diff --git a/app/src/main/java/nl/hnogames/domoticz/MainActivity.java b/app/src/main/java/nl/hnogames/domoticz/MainActivity.java index 51f6498..d8753ea 100644 --- a/app/src/main/java/nl/hnogames/domoticz/MainActivity.java +++ b/app/src/main/java/nl/hnogames/domoticz/MainActivity.java @@ -250,7 +250,7 @@ public void onDrawerOpened(View drawerView) { super.onDrawerOpened(drawerView); try { - if(searchViewAction!=null) + if (searchViewAction != null) searchViewAction.clearFocus(); } catch (Exception e) { e.printStackTrace(); diff --git a/app/src/main/java/nl/hnogames/domoticz/Service/GeofenceTransitionsIntentService.java b/app/src/main/java/nl/hnogames/domoticz/Service/GeofenceTransitionsIntentService.java index 0f3bbaf..76a56d3 100644 --- a/app/src/main/java/nl/hnogames/domoticz/Service/GeofenceTransitionsIntentService.java +++ b/app/src/main/java/nl/hnogames/domoticz/Service/GeofenceTransitionsIntentService.java @@ -113,7 +113,8 @@ protected void onHandleIntent(Intent intent) { } } } - }catch(Exception ex){} + } catch (Exception ex) { + } } diff --git a/app/src/main/java/nl/hnogames/domoticz/Service/WearMessageListenerService.java b/app/src/main/java/nl/hnogames/domoticz/Service/WearMessageListenerService.java index b8422aa..527a706 100644 --- a/app/src/main/java/nl/hnogames/domoticz/Service/WearMessageListenerService.java +++ b/app/src/main/java/nl/hnogames/domoticz/Service/WearMessageListenerService.java @@ -188,8 +188,8 @@ private void processAllSwitches(ArrayList extendedStatusSwit ArrayList supportedSwitches = new ArrayList<>(); - if(mSharedPrefs==null) - mSharedPrefs=new SharedPrefUtil(this); + if (mSharedPrefs == null) + mSharedPrefs = new SharedPrefUtil(this); if (!mSharedPrefs.showCustomWear() && mSharedPrefs.getWearSwitches() != null && mSharedPrefs.getWearSwitches().length > 0) { for (ExtendedStatusInfo mExtendedStatusInfo : extendedStatusSwitches) { diff --git a/app/src/main/java/nl/hnogames/domoticz/UI/ColorPickerDialog.java b/app/src/main/java/nl/hnogames/domoticz/UI/ColorPickerDialog.java index bb70a56..9939fea 100644 --- a/app/src/main/java/nl/hnogames/domoticz/UI/ColorPickerDialog.java +++ b/app/src/main/java/nl/hnogames/domoticz/UI/ColorPickerDialog.java @@ -24,20 +24,13 @@ import android.content.Context; import android.content.DialogInterface; -import android.view.MotionEvent; import android.view.View; -import android.widget.CompoundButton; -import android.widget.SeekBar; -import android.widget.Switch; -import android.widget.TextView; import com.afollestad.materialdialogs.MaterialDialog; import com.larswerkman.lobsterpicker.LobsterPicker; import com.larswerkman.lobsterpicker.sliders.LobsterOpacitySlider; import com.larswerkman.lobsterpicker.sliders.LobsterShadeSlider; -import nl.hnogames.domoticz.Containers.DevicesInfo; -import nl.hnogames.domoticz.Domoticz.Domoticz; import nl.hnogames.domoticz.R; public class ColorPickerDialog implements DialogInterface.OnDismissListener { @@ -45,7 +38,7 @@ public class ColorPickerDialog implements DialogInterface.OnDismissListener { private final MaterialDialog.Builder mdb; private DismissListener dismissListener; private Context mContext; - private int currentColor =0; + private int currentColor = 0; private LobsterPicker lobsterPicker; public ColorPickerDialog(Context mContext) { diff --git a/app/src/main/java/nl/hnogames/domoticz/UI/MultiSelectionSpinner.java b/app/src/main/java/nl/hnogames/domoticz/UI/MultiSelectionSpinner.java index 2464474..ac24ad4 100644 --- a/app/src/main/java/nl/hnogames/domoticz/UI/MultiSelectionSpinner.java +++ b/app/src/main/java/nl/hnogames/domoticz/UI/MultiSelectionSpinner.java @@ -187,7 +187,7 @@ public void setTitle(int title) { } public List getSelectedStrings() { - if(_items==null) + if (_items == null) return null; List selection = new LinkedList<>(); @@ -201,7 +201,7 @@ public List getSelectedStrings() { @SuppressWarnings("unused") public List getSelectedIndices() { - if(_items==null) + if (_items == null) return null; List selection = new LinkedList<>(); @@ -214,7 +214,7 @@ public List getSelectedIndices() { } private String buildSelectedItemString() { - if(_items==null) + if (_items == null) return null; StringBuilder sb = new StringBuilder(); @@ -235,7 +235,7 @@ private String buildSelectedItemString() { @SuppressWarnings("unused") public String getSelectedItemsAsString() { - if(_items==null) + if (_items == null) return null; StringBuilder sb = new StringBuilder(); diff --git a/app/src/main/java/nl/hnogames/domoticz/Utils/ColorsUtil.java b/app/src/main/java/nl/hnogames/domoticz/Utils/ColorsUtil.java index 2f7b824..2cb8466 100644 --- a/app/src/main/java/nl/hnogames/domoticz/Utils/ColorsUtil.java +++ b/app/src/main/java/nl/hnogames/domoticz/Utils/ColorsUtil.java @@ -25,7 +25,6 @@ import android.content.Context; import android.content.res.XmlResourceParser; import android.graphics.Color; -import android.util.Pair; import org.xmlpull.v1.XmlPullParserException; @@ -39,7 +38,7 @@ public class ColorsUtil { private static final String TAG = ColorsUtil.class.getSimpleName(); - public static int getRandomMaterialColor(Context mContext){ + public static int getRandomMaterialColor(Context mContext) { try { List allColors = getAllMaterialColors(mContext); return allColors.get(new Random().nextInt(allColors.size())); diff --git a/app/src/main/java/nl/hnogames/domoticz/Utils/PermissionsUtil.java b/app/src/main/java/nl/hnogames/domoticz/Utils/PermissionsUtil.java index affdc29..1cad8a6 100644 --- a/app/src/main/java/nl/hnogames/domoticz/Utils/PermissionsUtil.java +++ b/app/src/main/java/nl/hnogames/domoticz/Utils/PermissionsUtil.java @@ -26,50 +26,29 @@ import android.content.Context; import android.content.pm.PackageManager; import android.os.Build; -import android.support.annotation.Nullable; -import android.util.Base64; -import android.util.Log; - -import com.android.volley.AuthFailureError; -import com.android.volley.Request; -import com.android.volley.Response; -import com.android.volley.VolleyError; -import com.android.volley.toolbox.JsonObjectRequest; - -import org.json.JSONException; -import org.json.JSONObject; - -import java.util.HashMap; -import java.util.Map; - -import nl.hnogames.domoticz.Domoticz.Domoticz; -import nl.hnogames.domoticz.Interfaces.JSONParserInterface; -import nl.hnogames.domoticz.app.AppController; public class PermissionsUtil { - private static final String TAG = PermissionsUtil.class.getSimpleName(); - //these permissions are needed for Wifi scanning public static final String[] INITIAL_ACCESS_PERMS = { Manifest.permission.ACCESS_FINE_LOCATION, Manifest.permission.ACCESS_COARSE_LOCATION, }; - //these permissions are needed for storing camera images public static final String[] INITIAL_STORAGE_PERMS = { Manifest.permission.READ_EXTERNAL_STORAGE, Manifest.permission.WRITE_EXTERNAL_STORAGE }; - public static final int INITIAL_ACCESS_REQUEST = 1337; public static final int INITIAL_IMPORT_SETTINGS_REQUEST = 1887; public static final int INITIAL_EXPORT_SETTINGS_REQUEST = 1997; public static final int INITIAL_CAMERA_REQUEST = 1777; + private static final String TAG = PermissionsUtil.class.getSimpleName(); public static boolean canAccessLocation(Context context) { return (hasPermission(Manifest.permission.ACCESS_FINE_LOCATION, context)); } + public static boolean canAccessStorage(Context context) { return (hasPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE, context)); } 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 f1f816c..3bda0cc 100644 --- a/app/src/main/java/nl/hnogames/domoticz/Utils/SharedPrefUtil.java +++ b/app/src/main/java/nl/hnogames/domoticz/Utils/SharedPrefUtil.java @@ -29,7 +29,6 @@ import android.content.res.TypedArray; import android.os.Bundle; import android.preference.PreferenceManager; -import android.support.design.widget.Snackbar; import android.util.Log; import com.google.android.gms.common.api.GoogleApiClient; @@ -96,6 +95,7 @@ public class SharedPrefUtil { Context mContext; SharedPreferences prefs; SharedPreferences.Editor editor; + private GoogleApiClient mApiClient = null; public SharedPrefUtil(Context mContext) { this.mContext = mContext; @@ -264,7 +264,6 @@ public boolean showCustomWear() { return prefs.getBoolean(PREF_CUSTOM_WEAR, false); } - /* * Remote server settings */ @@ -428,7 +427,6 @@ public void setLocalSsid(List ssids) { editor.putStringSet(LOCAL_SERVER_SSID, set).apply(); } - /** * Method for setting local server addresses the same as the remote server addresses */ @@ -514,7 +512,7 @@ public void removeLocation(LocationInfo location) { } public boolean saveSharedPreferencesToFile(File dst) { - if(dst.exists()) + if (dst.exists()) dst.delete(); boolean res = false; @@ -590,23 +588,22 @@ else if (v instanceof Set) return res; } - private GoogleApiClient mApiClient = null; public void setGeoFenceService() { - final List mGeofenceList= new ArrayList<>(); - final ArrayList locations= getLocations(); + final List mGeofenceList = new ArrayList<>(); + final ArrayList locations = getLocations(); if (locations != null) for (LocationInfo locationInfo : locations) if (locationInfo.getEnabled()) mGeofenceList.add(locationInfo.toGeofence()); - if(locations!=null && locations.size()>0) { + if (locations != null && locations.size() > 0) { mApiClient = new GoogleApiClient.Builder(mContext) .addApi(LocationServices.API) .addConnectionCallbacks(new GoogleApiClient.ConnectionCallbacks() { @Override public void onConnected(Bundle bundle) { - PendingIntent mGeofenceRequestIntent = getGeofenceTransitionPendingIntent(); - LocationServices.GeofencingApi.addGeofences(mApiClient, mGeofenceList, mGeofenceRequestIntent); + PendingIntent mGeofenceRequestIntent = getGeofenceTransitionPendingIntent(); + LocationServices.GeofencingApi.addGeofences(mApiClient, mGeofenceList, mGeofenceRequestIntent); } @Override diff --git a/app/src/main/java/nl/hnogames/domoticz/Welcome/WelcomePage2.java b/app/src/main/java/nl/hnogames/domoticz/Welcome/WelcomePage2.java index e342582..3fcf814 100644 --- a/app/src/main/java/nl/hnogames/domoticz/Welcome/WelcomePage2.java +++ b/app/src/main/java/nl/hnogames/domoticz/Welcome/WelcomePage2.java @@ -18,11 +18,11 @@ public class WelcomePage2 extends Fragment { + private File SettingsFile; + public static final WelcomePage2 newInstance() { return new WelcomePage2(); } - private File SettingsFile; - @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, @@ -38,8 +38,7 @@ public void onClick(View v) { if (!PermissionsUtil.canAccessStorage(getActivity())) { requestPermissions(PermissionsUtil.INITIAL_STORAGE_PERMS, PermissionsUtil.INITIAL_IMPORT_SETTINGS_REQUEST); } - } - else { + } else { importSettings(); } } @@ -51,12 +50,11 @@ public void onClick(View v) { return v; } - private void importSettings() - { + private void importSettings() { SharedPrefUtil mSharedPrefs = new SharedPrefUtil(getActivity()); if (mSharedPrefs.loadSharedPreferencesFromFile(SettingsFile)) { Toast.makeText(getActivity(), "Settings Imported, we need to restart Domoticz!!", Toast.LENGTH_LONG).show(); - ((WelcomeViewActivity)getActivity()).finishWithResult(true); + ((WelcomeViewActivity) getActivity()).finishWithResult(true); } else Toast.makeText(getActivity(), "Failed to Import Settings.", Toast.LENGTH_SHORT).show(); } @@ -67,9 +65,8 @@ public void onRequestPermissionsResult(int requestCode, String[] permissions, in case PermissionsUtil.INITIAL_IMPORT_SETTINGS_REQUEST: if (PermissionsUtil.canAccessStorage(getActivity())) { importSettings(); - } - else - ((WelcomeViewActivity)getActivity()).finishWithResult(false); + } else + ((WelcomeViewActivity) getActivity()).finishWithResult(false); break; } } 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 c69b125..e60a6cc 100644 --- a/app/src/main/java/nl/hnogames/domoticz/Welcome/WelcomePage3.java +++ b/app/src/main/java/nl/hnogames/domoticz/Welcome/WelcomePage3.java @@ -1,8 +1,6 @@ package nl.hnogames.domoticz.Welcome; -import android.Manifest; import android.app.Fragment; -import android.content.pm.PackageManager; import android.os.Build; import android.os.Bundle; import android.view.LayoutInflater; @@ -139,8 +137,7 @@ private void setPreferenceValues() { if (!PermissionsUtil.canAccessLocation(getActivity())) { requestPermissions(PermissionsUtil.INITIAL_ACCESS_PERMS, PermissionsUtil.INITIAL_ACCESS_REQUEST); } - } - else + } else setSsid_spinner(); } @@ -150,9 +147,8 @@ public void onRequestPermissionsResult(int requestCode, String[] permissions, in case PermissionsUtil.INITIAL_ACCESS_REQUEST: if (PermissionsUtil.canAccessLocation(getActivity())) { setSsid_spinner(); - } - else - ((WelcomeViewActivity)getActivity()).finishWithResult(false); + } else + ((WelcomeViewActivity) getActivity()).finishWithResult(false); break; } } diff --git a/app/src/main/java/nl/hnogames/domoticz/Welcome/WelcomeViewActivity.java b/app/src/main/java/nl/hnogames/domoticz/Welcome/WelcomeViewActivity.java index a2f232c..4900159 100644 --- a/app/src/main/java/nl/hnogames/domoticz/Welcome/WelcomeViewActivity.java +++ b/app/src/main/java/nl/hnogames/domoticz/Welcome/WelcomeViewActivity.java @@ -1,11 +1,9 @@ package nl.hnogames.domoticz.Welcome; -import android.Manifest; import android.animation.ArgbEvaluator; import android.annotation.SuppressLint; import android.app.Fragment; import android.content.Intent; -import android.content.pm.PackageManager; import android.os.Build; import android.os.Bundle; import android.support.v4.app.FragmentActivity; diff --git a/app/src/main/java/nl/hnogames/domoticz/app/DomoticzFragment.java b/app/src/main/java/nl/hnogames/domoticz/app/DomoticzFragment.java index dc30eba..4c036b7 100644 --- a/app/src/main/java/nl/hnogames/domoticz/app/DomoticzFragment.java +++ b/app/src/main/java/nl/hnogames/domoticz/app/DomoticzFragment.java @@ -159,8 +159,7 @@ private void setErrorMessage(String message) { } public void addDebugText(String text) { - if(text!=null && text.length()>0) - { + if (text != null && text.length() > 0) { Logger(fragmentName, text); if (debug) { if (debugText != null) {