diff --git a/.idea/codeStyles/Project.xml b/.idea/codeStyles/Project.xml new file mode 100644 index 0000000..30aa626 --- /dev/null +++ b/.idea/codeStyles/Project.xml @@ -0,0 +1,29 @@ + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/gradle.xml b/.idea/gradle.xml new file mode 100644 index 0000000..2996d53 --- /dev/null +++ b/.idea/gradle.xml @@ -0,0 +1,15 @@ + + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..37a7509 --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,9 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/runConfigurations.xml b/.idea/runConfigurations.xml new file mode 100644 index 0000000..7f68460 --- /dev/null +++ b/.idea/runConfigurations.xml @@ -0,0 +1,12 @@ + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..35eb1dd --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index b6f70cb..efe2634 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -2,7 +2,10 @@ + + - \ No newline at end of file + diff --git a/app/src/main/java/de/weseng/wifiweatherstation/MainActivity.java b/app/src/main/java/de/weseng/wifiweatherstation/MainActivity.java index 8750d73..7488c8a 100644 --- a/app/src/main/java/de/weseng/wifiweatherstation/MainActivity.java +++ b/app/src/main/java/de/weseng/wifiweatherstation/MainActivity.java @@ -1,13 +1,141 @@ package de.weseng.wifiweatherstation; +import android.app.ProgressDialog; +import android.content.Context; +import android.graphics.Bitmap; +import android.graphics.Color; +import android.net.ConnectivityManager; +import android.net.NetworkInfo; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; +import android.util.Log; +import android.view.KeyEvent; +import android.view.Menu; +import android.view.MenuItem; +import android.webkit.WebSettings; +import android.webkit.WebView; +import android.webkit.WebViewClient; +import android.widget.Toast; public class MainActivity extends AppCompatActivity { + WebView myWebView; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); + + final ProgressDialog pd = ProgressDialog.show(MainActivity.this, "", + "Bitte warten, die Ansicht wird geladen...", true); + + /* apply layout to the current screen */ setContentView(R.layout.activity_main); + + /* find WebView element by its id*/ + if (savedInstanceState != null) + ((WebView) findViewById(R.id.webview)).restoreState(savedInstanceState); + myWebView = findViewById(R.id.webview); + + /* create new settings for WebView element */ + WebSettings webSettings = myWebView.getSettings(); + webSettings.setJavaScriptEnabled(true); + webSettings.setLoadWithOverviewMode(true); + webSettings.setUseWideViewPort(true); + //webSettings.setSupportZoom(true); + //webSettings.setBuiltInZoomControls(true); + + //myWebView.setBackgroundColor(getResources().getColor(R.color.black)); + //myWebView.setBackgroundResource(Color.TRANSPARENT); + myWebView.setBackgroundColor(Color.TRANSPARENT); + myWebView.setPadding(0, 0, 0, 0); + + myWebView.setWebViewClient(new WebViewClient() { + @Override + public void onPageStarted(WebView view, String url, Bitmap favicon) { + pd.show(); + } + + @Override + public void onPageFinished(WebView view, String url) { + pd.dismiss(); + String webUrl = myWebView.getUrl(); + } + + @Override + public boolean shouldOverrideUrlLoading(WebView view, String url) { + /* will open a new web page in webview*/ + view.loadUrl(url); + return true; + } + + public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) { + /*stop loading and show error.html page from assets folder*/ + /*see: http://xbsoftware.com/blog/web-android-two-steps/ */ + //view.stopLoading(); + //view.loadUrl(String.format("file:///android_asset/error.html?code=%s&description=%s&url=%s", Uri.encode(String.valueOf(errorCode)), Uri.encode(description), Uri.encode(failingUrl))); + Toast.makeText(getApplicationContext(), description, Toast.LENGTH_SHORT).show(); + } + }); + /* set URL site */ + if (savedInstanceState == null) { + ConnectivityManager connManager = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE); + NetworkInfo mWifi = connManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI); + + if (mWifi.isConnected()) { + // loadUrl needs: AndroidManifest.xml - + app:layout_constraintTop_toTopOf="parent"> \ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index acea888..4a1b46f 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -1,3 +1,4 @@ WiFi Weather Station + Einstellungen