Skip to content

Commit

Permalink
went back to webview for the radar image
Browse files Browse the repository at this point in the history
  • Loading branch information
evilbunny2008 committed Apr 2, 2018
1 parent 1d1eee7 commit 9817014
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 156 deletions.
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ android {
applicationId "com.odiousapps.weewxweather"
minSdkVersion 16
targetSdkVersion 26
versionCode 2010
versionName "0.2.10"
versionCode 2011
versionName "0.2.11"
}
buildTypes {
release {
Expand Down
1 change: 0 additions & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
android:fullBackupContent="@xml/backup_descriptor">
<activity
android:name=".MainActivity"
android:hardwareAccelerated="false"
android:label="@string/app_name"
android:theme="@style/AppTheme.NoActionBar"
android:configChanges="orientation"
Expand Down
131 changes: 0 additions & 131 deletions app/src/main/java/com/odiousapps/weewxweather/GifImageView.java

This file was deleted.

56 changes: 45 additions & 11 deletions app/src/main/java/com/odiousapps/weewxweather/Weather.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.webkit.WebView;
import android.webkit.WebSettings;
import android.widget.TextView;

import java.io.File;
Expand All @@ -24,8 +26,7 @@ class Weather
{
private Common common;
private View rootView;
//private WebView wv;
private GifImageView gif;
private WebView wv;

Weather(Common common)
{
Expand Down Expand Up @@ -83,25 +84,25 @@ public boolean onLongClick(View v)
}
});

gif = rootView.findViewById(R.id.radar);
gif.setOnLongClickListener(new View.OnLongClickListener()
wv = rootView.findViewById(R.id.radar);
wv.setOnLongClickListener(new View.OnLongClickListener()
{
@Override
public boolean onLongClick(View v)
{
Vibrator vibrator = (Vibrator)common.context.getSystemService(Context.VIBRATOR_SERVICE);
if(vibrator != null)
vibrator.vibrate(150);
Common.LogMessage("gif long press");
reloadWebView();
Common.LogMessage("wv long press");
loadWebView();
return true;
}
});

if(new File(common.context.getFilesDir() + "/radar.gif").exists())
gif.setGifFromFile(common.context.getFilesDir() + "/radar.gif");
loadWebView();

reloadWebView();
if(!common.GetStringPref("RADAR_URL", "").equals(""))
reloadWebView();

Common.LogMessage("weather.java -- adding a new filter");
IntentFilter filter = new IntentFilter();
Expand All @@ -118,13 +119,46 @@ private void forceRefresh()
myService.singleton.getWeather();
}

private void loadWebView()
{
String radar = common.context.getFilesDir() + "/radar.gif";

wv.getSettings().setAppCacheEnabled(false);
wv.getSettings().setCacheMode(WebSettings.LOAD_NO_CACHE);
wv.getSettings().setUserAgentString(Common.UA);
wv.clearCache(true);

if (radar.equals("") || !new File(radar).exists() || common.GetStringPref("RADAR_URL", "").equals(""))
{
String html = "<html><body>Radar URL not set or is still downloading. You can go to settings to change.</body></html>";
wv.loadDataWithBaseURL(null, html, "text/html", "utf-8", null);
return;
}

String html = "<!DOCTYPE html>\n" +
"<html>\n" +
" <head>\n" +
" <meta charset='utf-8'>\n" +
" <meta name='viewport' content='width=device-width, initial-scale=1.0'>\n" +
" </head>\n" +
" <body>\n" +
"\t<img style='margin:0px;padding:0px;border:0px;text-align:center;max-width:100%;width:auto;height:auto;'\n" +
"\tsrc='file://" + radar + "'>\n" +
" </body>\n" +
"</html>";
wv.loadDataWithBaseURL(null, html, "text/html", "utf-8", null);
}

private void reloadWebView()
{
Common.LogMessage("reload radar...");
final String radar = common.GetStringPref("RADAR_URL", "");

if(radar.equals(""))
{
loadWebView();
return;
}


Thread t = new Thread(new Runnable()
Expand All @@ -138,7 +172,7 @@ public void run()
URL url = new URL(radar);

InputStream ins = url.openStream();
File file = new File(common.context.getFilesDir(), "radar.gif");
File file = new File(common.context.getFilesDir(), "/radar.gif");
FileOutputStream out = null;

try
Expand Down Expand Up @@ -187,7 +221,7 @@ public void handleMessage(Message msg)
try
{
Common.LogMessage(common.context.getFilesDir() + "/radar.gif");
gif.setGifFromFile(common.context.getFilesDir() + "/radar.gif");
loadWebView();
} catch (Exception e) {
e.printStackTrace();
}
Expand Down
15 changes: 4 additions & 11 deletions app/src/main/res/layout/fragment_weather.xml
Original file line number Diff line number Diff line change
Expand Up @@ -250,17 +250,10 @@
android:gravity="center"
android:textSize="12sp"/>

<ScrollView
<WebView
android:id="@+id/radar"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clipToPadding="false"
android:fillViewport="false">
<com.odiousapps.weewxweather.GifImageView
android:id="@+id/radar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:scaleType="fitXY"/>
</ScrollView>
android:layout_height="match_parent"/>

</LinearLayout>
</android.support.constraint.ConstraintLayout>

0 comments on commit 9817014

Please sign in to comment.