Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
mueller-ma committed Sep 27, 2017
1 parent 8cc341d commit 87465b2
Show file tree
Hide file tree
Showing 7 changed files with 86 additions and 27 deletions.
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,27 @@ 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;

SharedPreferences settings =
PreferenceManager.getDefaultSharedPreferences(getContext());
String showLegend = settings.getString(Constants.PREFERENCE_CHART_SHOW_LEGEND, "");
if(!showLegend.equals("auto")) {
chartUrl += "&legend=" + showLegend;
}
}
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
33 changes: 17 additions & 16 deletions mobile/src/main/java/org/openhab/habdroid/util/Constants.java
Expand Up @@ -10,21 +10,22 @@
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 PREFERENCE_CHART_SHOW_LEGEND = "default_openhab_chart_show_legend";
public static final String DEFAULT_GCM_SENDER_ID = "737820980945";
}
12 changes: 12 additions & 0 deletions mobile/src/main/res/values/arrays.xml
Expand Up @@ -27,4 +27,16 @@
<item>@string/settings_openhab_icon_format_png</item>
<item>@string/settings_openhab_icon_format_svg</item>
</string-array>

<string-array name="chart_show_legend_array">
<item>@string/chart_show_legend_auto</item>
<item>@string/chart_show_legend_always</item>
<item>@string/chart_show_legend_never</item>
</string-array>

<string-array name="chart_show_legend_array_values">
<item>@string/chart_show_legend_auto_values</item>
<item>@string/chart_show_legend_always_values</item>
<item>@string/chart_show_legend_never_values</item>
</string-array>
</resources>
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
7 changes: 7 additions & 0 deletions mobile/src/main/res/values/strings.xml
Expand Up @@ -129,4 +129,11 @@
<string name="about_links">Links</string>
<string name="about_links_list"><![CDATA[\u00B7 <a href="https://github.com/openhab/openhab.android">openHAB App source code</a><br><br> \u00B7 <a href="https://github.com/openhab/openhab.android/issues">Report a problem</a><br><br> \u00B7 <a href="http://docs.openhab.org/">openHAB Documentation</a><br><br> \u00B7 <a href="https://community.openhab.org/">Community Forum</a>]]></string>
<string name="about_copyright" translatable="false">© 2012 - %s openHAB Foundation</string>
<string name="settings_openhab_chart_show_legend">Show chart legend</string>
<string name="chart_show_legend_auto">When more than one item is shown</string>
<string name="chart_show_legend_always">Always</string>
<string name="chart_show_legend_never">Never</string>
<string name="chart_show_legend_auto_values" translatable="false">auto</string>
<string name="chart_show_legend_always_values" translatable="false">true</string>
<string name="chart_show_legend_never_values" translatable="false">false</string>
</resources>
11 changes: 10 additions & 1 deletion mobile/src/main/res/values/themes.xml
Expand Up @@ -17,6 +17,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 @@ -37,6 +39,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 @@ -57,6 +61,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 @@ -75,6 +81,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 @@ -93,9 +101,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>
21 changes: 14 additions & 7 deletions mobile/src/main/res/xml/preferences.xml
Expand Up @@ -65,6 +65,20 @@
android:defaultValue="@string/theme_value_light"
android:entries="@array/themeArray"
android:entryValues="@array/themeValues" />
<ListPreference
android:key="default_openhab_chart_show_legend"
android:title="@string/settings_openhab_chart_show_legend"
android:summary="%s"
android:defaultValue="@string/chart_show_legend_auto"
android:entries="@array/chart_show_legend_array"
android:entryValues="@array/chart_show_legend_array_values" />
<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 +89,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

0 comments on commit 87465b2

Please sign in to comment.