diff --git a/app/src/main/java/com/forrestguice/suntimeswidget/settings/HelpPreference.java b/app/src/main/java/com/forrestguice/suntimeswidget/settings/HelpPreference.java new file mode 100644 index 000000000..083b11624 --- /dev/null +++ b/app/src/main/java/com/forrestguice/suntimeswidget/settings/HelpPreference.java @@ -0,0 +1,155 @@ +/** + Copyright (C) 2022 Forrest Guice + This file is part of SuntimesWidget. + + SuntimesWidget is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + SuntimesWidget is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with SuntimesWidget. If not, see . +*/ + +package com.forrestguice.suntimeswidget.settings; + +import android.annotation.TargetApi; +import android.content.Context; +import android.content.Intent; +import android.content.res.TypedArray; +import android.net.Uri; +import android.preference.DialogPreference; +import android.support.annotation.Nullable; +import android.util.AttributeSet; +import android.util.TypedValue; +import android.view.Gravity; +import android.view.View; +import android.view.ViewGroup; +import android.widget.LinearLayout; +import android.widget.TextView; + +import com.forrestguice.suntimeswidget.R; +import com.forrestguice.suntimeswidget.SuntimesUtils; + +/** + * A "preference" (non-persistent) that displays help content in a dialog. + */ +@TargetApi(11) +public class HelpPreference extends DialogPreference +{ + private CharSequence helpText = ""; + private String helpLink = null; + private TextView helpView; + + @TargetApi(21) + public HelpPreference(Context context) { + super(context); + } + + public HelpPreference(Context context, AttributeSet attrs) { + super(context, attrs); + setHelpText(context, attrs); + } + + @TargetApi(21) + public HelpPreference(Context context, AttributeSet attrs, int defStyleAttr) + { + super(context, attrs, defStyleAttr); + setHelpText(context, attrs); + } + + @TargetApi(21) + public HelpPreference(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) + { + super(context, attrs, defStyleAttr, defStyleRes); + setHelpText(context, attrs); + } + + @Override + protected View onCreateDialogView() + { + Context context = getContext(); + + float marginTopBottom = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 8, getContext().getResources().getDisplayMetrics()); + float marginLeftRight; + TypedArray a = context.obtainStyledAttributes(new int[] { R.attr.dialogPreferredPadding }); + marginLeftRight = context.getResources().getDimension(a.getResourceId(0, R.dimen.settingsGroup_margin)); + a.recycle(); + + helpView = new TextView(getContext()); + LinearLayout.LayoutParams params1 = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT); + params1.gravity = Gravity.START; + params1.setMargins((int)marginLeftRight, (int)marginTopBottom, (int)marginLeftRight, (int)marginTopBottom); + helpView.setLayoutParams(params1); + + LinearLayout dialogView = new LinearLayout(getContext()); + dialogView.setOrientation(LinearLayout.VERTICAL); + + LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT); + layoutParams.gravity = Gravity.CENTER; + dialogView.setLayoutParams(layoutParams); + + dialogView.addView(helpView); + return dialogView; + } + + @Override + protected void onBindDialogView(View v) + { + super.onBindDialogView(v); + helpView.setText(helpText); + } + + @Override + protected void onDialogClosed(boolean result) + { + if (result && (getPositiveButtonText() != null && helpLink != null)) { + openHelpLink(getContext()); + } + } + + @Override + protected Object onGetDefaultValue(TypedArray a, int i) { + return a.getInt(i, 0); + } + + @Override + protected void onSetInitialValue(boolean restoreValue, Object defaultValue) { + } + + public void setHelpText(Context context, @Nullable AttributeSet attrs) + { + if (attrs != null) + { + String buttonText = null; + TypedArray a = context.getTheme().obtainStyledAttributes(attrs, R.styleable.HelpPreference, 0, 0); + try { + this.helpText = SuntimesUtils.fromHtml(a.getString(R.styleable.HelpPreference_helpText)); + helpLink = a.getString(R.styleable.HelpPreference_helpLink); + buttonText = a.getString(R.styleable.HelpPreference_moreHelpButtonText); + } finally { + a.recycle(); + } + setPositiveButtonText(buttonText); + } + } + public CharSequence getHelpText() { + return helpText; + } + + public void openHelpLink(Context context) + { + if (context != null && helpLink != null) { + context.startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(helpLink))); + } + } + public String getHelpLink() { + return helpLink; + } + +} diff --git a/app/src/main/res/values/attrs.xml b/app/src/main/res/values/attrs.xml index 3c43a05e0..901259aea 100644 --- a/app/src/main/res/values/attrs.xml +++ b/app/src/main/res/values/attrs.xml @@ -171,4 +171,10 @@ + + + + + + diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 1535c4380..41fdf7128 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -27,6 +27,7 @@ World Map Moon Help + Online Help More Settings About @@ -289,6 +290,7 @@ Data Source: Sun Data Source Moon Data Source + About Data Sources Time Format: @@ -1870,6 +1872,18 @@ Follows algorithms published by the National Oceanic and Atmospheric Administration. Follows algorithms published by Dershowitz/Reingold in their book "Calendrical Calculations" (third edition). Based on astronomical calculations published by Jean Meeus in his book "Astronomical Algorithms" (second edition). + + +
+ The data source setting allows choosing between different libraries (or choosing between different algorithms offered by those libraries). The default is time4a-time4j.
+
+ This setting affects the speed and accuracy of calculations, and may limit which features are available.
+
+ For more information about available choices, or extending the app to support other libraries, see the online help. + ]]> +
+ https://github.com/forrestguice/SuntimesWidget/wiki/Help time4a-time4j diff --git a/app/src/main/res/xml/preference_general.xml b/app/src/main/res/xml/preference_general.xml index 725589715..a8cc914e9 100644 --- a/app/src/main/res/xml/preference_general.xml +++ b/app/src/main/res/xml/preference_general.xml @@ -57,6 +57,17 @@ android:dialogTitle="@string/configLabel_general_calculator_moon" android:summary="%s" android:entries="@null" android:entryValues="@null" android:defaultValue="@string/def_appwidget_0_general_calculator_moon" /> + + +