Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make use of eclipse/smarthome#4291 #386

Merged
merged 4 commits into from
Oct 8, 2017
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ private OpenHAB2Widget(OpenHABWidget parent, JSONObject widgetJson, String iconF
this.setPeriod(widgetJson.getString("period"));
if (widgetJson.has("service"))
this.setService(widgetJson.getString("service"));
if (widgetJson.has("legend"))
this.setService(widgetJson.getString("legend"));

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wrong setter called

if (widgetJson.has("height"))
this.setHeight(widgetJson.getInt("height"));
if (widgetJson.has("iconcolor"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ public abstract class OpenHABWidget {
private String type;
private String url;
private String period = "";
private String service = "";
private String service = "";
private boolean legend = true;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suggest a Boolean with default null here, so that the behaviour is similiar to the other UI providers:
If the user does not set a legend attribute, it is not delivered in the REST API, and this should stay null.
In the OpenHABWidgetAdapter, check if this is not-null, and only append the `legend´ parameter to the chart URL if this is non-null.
(See comment in PR regarding default handling)
This gives the following behaviour:

  • User defines legend with true/false: legend parameter is appended to URL, respect users wish
  • User does NOT define legend: do not append legend parameter -> the OH ChartProvider takes the default (show legend if more than one item)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was aware of this problem, but couldn't find a good solution. Thanks!

private float minValue =0;
private float maxValue = 100;
private float step = 1;
Expand Down Expand Up @@ -192,6 +193,10 @@ public void setPeriod(String period) {

public void setService(String service) { this.service = service; }

public boolean getLegend() { return legend; }

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See above: Boolean


public void setLegend(boolean legend) { this.legend = legend; }

public int getHeight() {
return height;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,14 @@
package org.openhab.habdroid.ui;

import android.content.Context;
import android.content.SharedPreferences;
import android.net.Uri;
import android.os.Build;
import android.preference.PreferenceManager;
import android.support.v7.widget.SwitchCompat;
import android.util.DisplayMetrics;
import android.util.Log;
import android.util.TypedValue;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
Expand Down Expand Up @@ -44,6 +48,7 @@
import org.openhab.habdroid.ui.widget.ColorPickerDialog;
import org.openhab.habdroid.ui.widget.OnColorChangedListener;
import org.openhab.habdroid.ui.widget.SegmentedControlButton;
import org.openhab.habdroid.util.Constants;
import org.openhab.habdroid.util.MjpegStreamer;
import org.openhab.habdroid.util.MyAsyncHttpClient;
import org.openhab.habdroid.util.MyHttpClient;
Expand Down Expand Up @@ -499,10 +504,23 @@ public void onStopTrackingTouch(SeekBar seekBar) {
if (openHABWidget.getService() != null && openHABWidget.getService().length() > 0) {
chartUrl += "&service=" + openHABWidget.getService();
}
}
// add theme attribute
TypedValue chartTheme = new TypedValue();
if (getContext().getTheme().resolveAttribute(R.attr.chartTheme, chartTheme, true)) {
chartUrl += "&theme=" + chartTheme.string;
}

// add dpi attribute
WindowManager wm = (WindowManager) getContext().getSystemService(Context.WINDOW_SERVICE);
DisplayMetrics metrics = new DisplayMetrics();
wm.getDefaultDisplay().getMetrics(metrics);
int dpi = metrics.densityDpi;
chartUrl += "&dpi=" + dpi;

// add legend
chartUrl += "&legend=" + openHABWidget.getLegend();

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Only add legend parameter to URL if openHABWidget.getLegend() != null; see above

}
Log.d(TAG, "Chart url = " + chartUrl);
if (chartImage == null)
Log.e(TAG, "chartImage == null !!!");
ViewGroup.LayoutParams chartLayoutParams = chartImage.getLayoutParams();
chartLayoutParams.height = (int) (screenWidth/2);
chartImage.setLayoutParams(chartLayoutParams);
Expand Down
32 changes: 16 additions & 16 deletions mobile/src/main/java/org/openhab/habdroid/util/Constants.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,21 @@
package org.openhab.habdroid.util;

public class Constants {
public static final String PREFERENCE_APPVERSION = "default_openhab_appversion";
public static final String PREFERENCE_SCREENTIMEROFF = "default_openhab_screentimeroff";
public static final String PREFERENCE_USERNAME = "default_openhab_username";
public static final String PREFERENCE_PASSWORD = "default_openhab_password";
public static final String PREFERENCE_SITEMAP = "default_openhab_sitemap";
public static final String PREFERENCE_SSLCERT = "default_openhab_sslcert";
public static final String PREFERENCE_SSLHOST = "default_openhab_sslhost";
public static final String PREFERENCE_ALTURL = "default_openhab_alturl";
public static final String PREFERENCE_URL = "default_openhab_url";
public static final String PREFERENCE_THEME = "default_openhab_theme";
public static final String PREFERENCE_ANIMATION = "default_openhab_animation";
public static final String PREFERENCE_DEMOMODE = "default_openhab_demomode";
public static final String PREFERENCE_FULLSCREEN = "default_openhab_fullscreen";
public static final String PREFERENCE_TONE = "default_openhab_alertringtone";
public static final String PREFERENCE_SSLCLIENTCERT = "default_openhab_sslclientcert";
public static final String PREFERENCE_APPVERSION = "default_openhab_appversion";
public static final String PREFERENCE_SCREENTIMEROFF = "default_openhab_screentimeroff";
public static final String PREFERENCE_USERNAME = "default_openhab_username";
public static final String PREFERENCE_PASSWORD = "default_openhab_password";
public static final String PREFERENCE_SITEMAP = "default_openhab_sitemap";
public static final String PREFERENCE_SSLCERT = "default_openhab_sslcert";
public static final String PREFERENCE_SSLHOST = "default_openhab_sslhost";
public static final String PREFERENCE_ALTURL = "default_openhab_alturl";
public static final String PREFERENCE_URL = "default_openhab_url";
public static final String PREFERENCE_THEME = "default_openhab_theme";
public static final String PREFERENCE_ANIMATION = "default_openhab_animation";
public static final String PREFERENCE_DEMOMODE = "default_openhab_demomode";
public static final String PREFERENCE_FULLSCREEN = "default_openhab_fullscreen";
public static final String PREFERENCE_TONE = "default_openhab_alertringtone";
public static final String PREFERENCE_SSLCLIENTCERT = "default_openhab_sslclientcert";
public static final String PREFERENCE_SSLCLIENTCERT_HOWTO = "default_openhab_sslclientcert_howto";
public static final String DEFAULT_GCM_SENDER_ID = "737820980945";
public static final String DEFAULT_GCM_SENDER_ID = "737820980945";
}
1 change: 1 addition & 0 deletions mobile/src/main/res/values/attrs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
<attr name="customMicIcon" format="reference" />
<attr name="widgetlistItemDivider" format="reference" />
<attr name="frameWidgetDividerBackground" format="reference" />
<attr name="chartTheme" format="string|reference" />
</declare-styleable>

<attr name="themedDrawerBackground" format="reference|color" />
Expand Down
11 changes: 10 additions & 1 deletion mobile/src/main/res/values/themes.xml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@

<item name="themedDrawerBackground">?android:colorBackground</item>
<item name="themedHeaderTextColor">@color/colorAccent_themeDark</item>

<item name="chartTheme">white</item>
</style>

<style name="HABDroid.Dark" parent="@style/Theme.AppCompat">
Expand All @@ -51,6 +53,8 @@

<item name="themedDrawerBackground">?android:colorBackground</item>
<item name="themedHeaderTextColor">@color/colorAccent_themeDark</item>

<item name="chartTheme">dark</item>
</style>

<style name="HABDroid.Black" parent="@style/Theme.AppCompat">
Expand All @@ -71,6 +75,8 @@

<item name="themedDrawerBackground">@color/black</item>
<item name="themedHeaderTextColor">@color/colorAccent_themeDark</item>

<item name="chartTheme">black</item>
</style>

<style name="HABDroid.Basic_ui" parent="Theme.AppCompat.Light.NoActionBar">
Expand All @@ -89,6 +95,8 @@

<item name="themedDrawerBackground">?android:colorBackground</item>
<item name="themedHeaderTextColor">@color/colorAccent_themeDark</item>

<item name="chartTheme">white</item>
</style>

<style name="HABDroid.Basic_ui_dark" parent="Theme.AppCompat.NoActionBar">
Expand All @@ -107,9 +115,10 @@
<item name="android:itemBackground">#303030</item>
<item name="android:itemTextAppearance">@style/whiteText</item>


<item name="themedDrawerBackground">?android:colorBackground</item>
<item name="themedHeaderTextColor">@color/colorAccent_themeDark</item>

<item name="chartTheme">dark</item>
</style>

</resources>
14 changes: 7 additions & 7 deletions mobile/src/main/res/xml/preferences.xml
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,13 @@
android:defaultValue="@string/theme_value_light"
android:entries="@array/themeArray"
android:entryValues="@array/themeValues" />
<ListPreference
android:title="@string/settings_openhab_icon_format"
android:key="iconFormatType"
android:defaultValue="@string/settings_openhab_icon_format_png"
android:summary="%s"
android:entries="@array/iconTypeValues"
android:entryValues="@array/iconTypeValues" />
<CheckBoxPreference
android:defaultValue="false"
android:key="default_openhab_screentimeroff"
Expand All @@ -75,13 +82,6 @@
android:key="default_openhab_fullscreen"
android:summary="@string/settings_openhab_fullscreen_summary"
android:title="@string/settings_openhab_fullscreen" />
<ListPreference
android:title="@string/settings_openhab_icon_format"
android:key="iconFormatType"
android:defaultValue="@string/settings_openhab_icon_format_png"
android:summary="%s"
android:entries="@array/iconTypeValues"
android:entryValues="@array/iconTypeValues" />
</PreferenceCategory>
<PreferenceCategory android:title="@string/settings_misc_title">
<RingtonePreference
Expand Down