diff --git a/app/build.gradle b/app/build.gradle index 33b1b8a..7259c78 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -6,8 +6,8 @@ android { applicationId "com.odiousapps.weewxweather" minSdkVersion 19 targetSdkVersion 28 - versionCode 5014 - versionName "0.5.14" + versionCode 6000 + versionName "0.6.0" } buildTypes { release { diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 58df25b..bb07742 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -12,6 +12,7 @@ adapter = new ArrayAdapter<>(common.context, R.layout.spinner_layout, paths); adapter.setDropDownViewResource(R.layout.spinner_layout); s1.setAdapter(adapter); - s1.setSelection(pos); s1.setOnItemSelectedListener(this); - Switch metric_forecasts = findViewById(R.id.metric_forecasts); - metric_forecasts.setChecked(common.GetBoolPref("metric", true)); - - Switch show_indoor = findViewById(R.id.show_indoor); - show_indoor.setChecked(common.GetBoolPref("showIndoor", false)); - - Switch wifi_only = findViewById(R.id.wifi_only); - wifi_only.setChecked(common.GetBoolPref("onlyWIFI", false)); - - boolean radarforecast = common.GetBoolPref("radarforecast", true); - RadioButton showForecast = findViewById(R.id.showForecast); - if(!radarforecast) - showForecast.setChecked(true); + metric_forecasts = findViewById(R.id.metric_forecasts); + show_indoor = findViewById(R.id.show_indoor); b1 = findViewById(R.id.button); b2 = findViewById(R.id.deleteData); b3 = findViewById(R.id.aboutButton); - LinearLayout settingsLayout = findViewById(R.id.settingsLayout); - settingsLayout.setVisibility(View.VISIBLE); - LinearLayout aboutLayout = findViewById(R.id.aboutLayout); - aboutLayout.setVisibility(View.GONE); + fgColour = findViewById(R.id.fgPicker); + bgColour = findViewById(R.id.bgPicker); b1.setOnClickListener(new View.OnClickListener() { @@ -217,9 +165,9 @@ public void onClick(View arg0) { public void onClick(View arg0) { - if(showSettings) + if(showSettings) { - showSettings = false; + showSettings = false; b1.setVisibility(View.INVISIBLE); b2.setVisibility(View.INVISIBLE); b3.setText(R.string.settings2); @@ -243,7 +191,64 @@ public void onClick(View arg0) } }); - TextView tv = findViewById(R.id.aboutText); + tv = findViewById(R.id.aboutText); + doSettings(); + + common.setAlarm("MainActivity"); + } + + private void showUpdateAvailable() + { + final AlertDialog.Builder d = new AlertDialog.Builder(this); + d.setTitle("weeWX Weather App"); + d.setMessage("This app has been updated but the server you are connecting to hasn't updated the Inigo Plugin for weeWX. Fields may not show up properly until weeWX is updated."); + d.setPositiveButton("OK", null); + d.setIcon(R.drawable.ic_launcher_foreground); + d.show(); + } + + private void doSettings() + { + settingsURL.setText(common.GetStringPref("SETTINGS_URL", "https://example.com/weewx/inigo-settings.txt")); + settingsURL.setOnFocusChangeListener(new View.OnFocusChangeListener() + { + @Override + public void onFocusChange(View v, boolean hasFocus) + { + if (!hasFocus) + hideKeyboard(v); + } + }); + + customURL.setText(common.GetStringPref("custom_url", "")); + customURL.setOnFocusChangeListener(new View.OnFocusChangeListener() + { + @Override + public void onFocusChange(View v, boolean hasFocus) + { + if (!hasFocus) + hideKeyboard(v); + } + }); + + pos = common.GetIntPref("updateInterval", 1); + s1.setSelection(pos); + + metric_forecasts.setChecked(common.GetBoolPref("metric", true)); + show_indoor.setChecked(common.GetBoolPref("showIndoor", false)); + + Switch wifi_only = findViewById(R.id.wifi_only); + wifi_only.setChecked(common.GetBoolPref("onlyWIFI", false)); + + boolean radarforecast = common.GetBoolPref("radarforecast", true); + RadioButton showForecast = findViewById(R.id.showForecast); + if(!radarforecast) + showForecast.setChecked(true); + + LinearLayout settingsLayout = findViewById(R.id.settingsLayout); + settingsLayout.setVisibility(View.VISIBLE); + LinearLayout aboutLayout = findViewById(R.id.aboutLayout); + aboutLayout.setVisibility(View.GONE); String lines = "Big thanks to the weeWX project, as this app " + "wouldn't be possible otherwise.

" + @@ -256,7 +261,6 @@ public void onClick(View arg0) // https://github.com/Pes8/android-material-color-picker-dialog - fgColour = findViewById(R.id.fgPicker); String hex = "#" + Integer.toHexString(common.GetIntPref("fgColour", 0xFF000000)).toUpperCase(); fgColour.setText(hex); fgColour.setOnClickListener(new View.OnClickListener() @@ -268,7 +272,6 @@ public void onClick(View v) } }); - bgColour = findViewById(R.id.bgPicker); hex = "#" + Integer.toHexString(common.GetIntPref("bgColour", 0xFFFFFFFF)).toUpperCase(); bgColour.setText(hex); bgColour.setOnClickListener(new View.OnClickListener() diff --git a/app/src/main/java/com/odiousapps/weewxweather/RNAutoStart.java b/app/src/main/java/com/odiousapps/weewxweather/RNAutoStart.java index 90f5e80..da08f88 100644 --- a/app/src/main/java/com/odiousapps/weewxweather/RNAutoStart.java +++ b/app/src/main/java/com/odiousapps/weewxweather/RNAutoStart.java @@ -1,7 +1,5 @@ package com.odiousapps.weewxweather; -import android.app.AlarmManager; -import android.app.PendingIntent; import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; diff --git a/app/src/main/java/com/odiousapps/weewxweather/Stats.java b/app/src/main/java/com/odiousapps/weewxweather/Stats.java index c35d67d..30f083d 100644 --- a/app/src/main/java/com/odiousapps/weewxweather/Stats.java +++ b/app/src/main/java/com/odiousapps/weewxweather/Stats.java @@ -240,8 +240,8 @@ private void updateFields() return; // Today Stats - checkFields((TextView) rootView.findViewById(R.id.textView), bits[56]); - checkFields((TextView) rootView.findViewById(R.id.textView2), bits[54] + " " + bits[55]); + checkFields((TextView)rootView.findViewById(R.id.textView), bits[56]); + checkFields((TextView)rootView.findViewById(R.id.textView2), bits[54] + " " + bits[55]); double percent = (seekBar.getProgress() + 90) / 100.00; NumberFormat formatter = new DecimalFormat("#0.00"); diff --git a/app/src/main/java/com/odiousapps/weewxweather/UpdateCheck.java b/app/src/main/java/com/odiousapps/weewxweather/UpdateCheck.java index 23ee5a3..344cd8f 100644 --- a/app/src/main/java/com/odiousapps/weewxweather/UpdateCheck.java +++ b/app/src/main/java/com/odiousapps/weewxweather/UpdateCheck.java @@ -1,7 +1,5 @@ package com.odiousapps.weewxweather; -import android.app.AlarmManager; -import android.app.PendingIntent; import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; diff --git a/app/src/main/java/com/odiousapps/weewxweather/Weather.java b/app/src/main/java/com/odiousapps/weewxweather/Weather.java index f3926d6..8163b94 100644 --- a/app/src/main/java/com/odiousapps/weewxweather/Weather.java +++ b/app/src/main/java/com/odiousapps/weewxweather/Weather.java @@ -17,7 +17,6 @@ import android.webkit.WebChromeClient; import android.webkit.WebView; import android.webkit.WebViewClient; -import android.widget.LinearLayout; import android.widget.TextView; import java.io.BufferedReader; @@ -48,6 +47,8 @@ private void checkFields(TextView tv, String txt) private View updateFields() { + int iw = 17; + Common.LogMessage("updateFields()"); String bits[] = common.GetStringPref("LastDownload","").split("\\|"); if(bits.length < 65) @@ -55,42 +56,105 @@ private View updateFields() checkFields((TextView)rootView.findViewById(R.id.textView), bits[56]); checkFields((TextView)rootView.findViewById(R.id.textView2), bits[54] + " " + bits[55]); - checkFields((TextView)rootView.findViewById(R.id.textView3), bits[0] + bits[60]); + WebView current = rootView.findViewById(R.id.current); + current.getSettings().setUserAgentString(Common.UA); + current.setOnLongClickListener(new View.OnLongClickListener() + { + @Override + public boolean onLongClick(View v) + { + Vibrator vibrator = (Vibrator)common.context.getSystemService(Context.VIBRATOR_SERVICE); + if(vibrator != null) + vibrator.vibrate(250); + Common.LogMessage("current long press"); + updateFields(); + return true; + } + }); + + current.setWebViewClient(new WebViewClient() + { + @Override + public boolean shouldOverrideUrlLoading(WebView view, String url) + { + return false; + } + }); + current.setWebChromeClient(new WebChromeClient() + { + @Override + public boolean onConsoleMessage(ConsoleMessage cm) + { + return true; + } + }); + + String stmp; + StringBuilder sb = new StringBuilder(); + + String header = ""; + String footer = ""; + sb.append(header); + + sb.append(""); + + stmp = ""; if(bits.length > 203) - checkFields((TextView)rootView.findViewById(R.id.appTemp), "AT: " + bits[203] + bits[60]); + stmp += "
" + bits[0] + bits[60] + "AT: " + bits[203] + bits[60] +"
"; + else + stmp += " "; + + sb.append(stmp); + sb.append(""); - checkFields((TextView)rootView.findViewById(R.id.textView4), bits[25] + bits[61]); - checkFields((TextView)rootView.findViewById(R.id.textView5), bits[37] + bits[63]); - checkFields((TextView)rootView.findViewById(R.id.textView6), bits[29]); - checkFields((TextView)rootView.findViewById(R.id.textView7), bits[6] + bits[64]); + stmp = "" + + ""; + sb.append(stmp); + + stmp = "" + + ""; + sb.append(stmp); String rain = bits[20] + bits[62] + " since mn"; if(bits.length > 160 && !bits[160].equals("")) rain = bits[158] + bits[62] + " since " + bits[160]; - checkFields((TextView)rootView.findViewById(R.id.textView8), rain); - checkFields((TextView)rootView.findViewById(R.id.textView9), bits[12] + bits[60]); - checkFields((TextView)rootView.findViewById(R.id.textView10), bits[45] + "UVI"); - checkFields((TextView)rootView.findViewById(R.id.textView11), bits[43] + "W/m\u00B2"); - - checkFields((TextView)rootView.findViewById(R.id.textView12), bits[57]); - checkFields((TextView)rootView.findViewById(R.id.textView13), bits[58]); - checkFields((TextView)rootView.findViewById(R.id.textView14), bits[47]); - checkFields((TextView)rootView.findViewById(R.id.textView15), bits[48]); + stmp = "" + + ""; + sb.append(stmp); - LinearLayout homerow = rootView.findViewById(R.id.homerow); - if(common.GetBoolPref("showIndoor", false)) - homerow.setVisibility(View.VISIBLE); - else - homerow.setVisibility(View.GONE); + stmp = "" + + ""; + sb.append(stmp); - if(bits.length > 166) + if(bits.length > 202 && common.GetBoolPref("showIndoor", false)) { - checkFields((TextView) rootView.findViewById(R.id.hometemp), bits[161] + bits[60]); - checkFields((TextView) rootView.findViewById(R.id.homehumid), bits[166] + bits[64]); + stmp = "" + + ""; + sb.append(stmp); } + stmp = "
" + bits[25] + bits[61] + "" + bits[1] + bits[60] + "
" + bits[37] + bits[63] + "" + bits[6] + bits[64] + "
" + rain + "" + bits[12] + bits[60] + "
" + bits[45] + "UVI" + bits[43] + "W/m\u00B2
" + bits[161] + bits[60] + "" + bits[166] + bits[64] + "
"; + sb.append(stmp); + + sb.append(""); + + stmp = "" + + "" + + "" + + "" + + ""; + sb.append(stmp); + + stmp = "
" + bits[57] + "" + bits[58] + "" + bits[47] + "" + bits[48] + "
"; + sb.append(stmp); + + sb.append(footer); + String html = sb.toString().trim(); + + current.loadDataWithBaseURL("file:///android_res/drawable/", html, "text/html", "utf-8", null); + return rootView; } @@ -252,7 +316,6 @@ public void run() wv.loadDataWithBaseURL("file:///android_res/drawable/", fc, "text/html", "utf-8", null); } }); - } else if(fctype.toLowerCase().equals("weatherzone")) { String[] content = common.processWZ(data); if(content == null || content.length <= 0) @@ -269,14 +332,6 @@ public void run() wv.loadDataWithBaseURL("file:///android_res/drawable/", fc, "text/html", "utf-8", null); } }); - - /* - if(common.GetStringPref("fctype", "yahoo").toLowerCase().equals("yahoo")) - im.setImageResource(R.drawable.purple); - else if(common.GetStringPref("fctype", "yahoo").toLowerCase().equals("weatherzone")) - im.setImageResource(R.drawable.wz); - */ - } } } diff --git a/app/src/main/java/com/odiousapps/weewxweather/WidgetProvider.java b/app/src/main/java/com/odiousapps/weewxweather/WidgetProvider.java index 66de651..a44faa0 100644 --- a/app/src/main/java/com/odiousapps/weewxweather/WidgetProvider.java +++ b/app/src/main/java/com/odiousapps/weewxweather/WidgetProvider.java @@ -1,6 +1,5 @@ package com.odiousapps.weewxweather; -import android.app.AlarmManager; import android.app.PendingIntent; import android.appwidget.AppWidgetManager; import android.appwidget.AppWidgetProvider; @@ -12,6 +11,17 @@ public class WidgetProvider extends AppWidgetProvider { Common common = null; + @Override + public void onReceive(Context context, Intent intent) + { + Common.LogMessage("onReceive() called.."); + AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(context); + int[] appWidgetIds = intent.getIntArrayExtra("appWidgetIds"); + + if(appWidgetIds != null && appWidgetIds.length > 0) + onUpdate(context, appWidgetManager, appWidgetIds); + } + @Override public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) { diff --git a/app/src/main/res/layout/fragment_weather.xml b/app/src/main/res/layout/fragment_weather.xml index 4be1170..32fac19 100644 --- a/app/src/main/res/layout/fragment_weather.xml +++ b/app/src/main/res/layout/fragment_weather.xml @@ -1,6 +1,5 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + android:layout_height="wrap_content"/>