Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
* Make use of eclipse-archived/smarthome#4291

This commit enhances charts to support themes, scale legend according to
dpi and create option to hide legend

Signed-off-by: mueller-ma <mueller-ma@users.noreply.github.com>

* Read legend setting from oh server

Signed-off-by: mueller-ma <mueller-ma@users.noreply.github.com>

* Use Boolean

Signed-off-by: mueller-ma <mueller-ma@users.noreply.github.com>
  • Loading branch information
mueller-ma authored and digitaldan committed Oct 8, 2017
1 parent 50f0a19 commit b1a1991
Show file tree
Hide file tree
Showing 7 changed files with 65 additions and 28 deletions.
Expand Up @@ -84,6 +84,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.setLegend(widgetJson.getBoolean("legend"));
if (widgetJson.has("height"))
this.setHeight(widgetJson.getInt("height"));
if (widgetJson.has("iconcolor"))
Expand Down
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 = null;
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; }

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

public int getHeight() {
return height;
}
Expand Down
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,25 @@ 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
if(openHABWidget.getLegend() != null) {
chartUrl += "&legend=" + openHABWidget.getLegend();
}
}
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
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
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
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
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:defaultValue="@string/settings_openhab_icon_format_png"
android:entries="@array/iconTypeNames"
android:entryValues="@array/iconTypeValues"
android:key="iconFormatType"
android:summary="%s"
android:title="@string/settings_openhab_icon_format" />
</PreferenceCategory>
<PreferenceCategory android:title="@string/settings_misc_title">
<RingtonePreference
Expand Down

0 comments on commit b1a1991

Please sign in to comment.