overwrite web style, change min sdk to 16 and add German hints
This commit is contained in:
@@ -4,7 +4,7 @@ android {
|
||||
compileSdkVersion 28
|
||||
defaultConfig {
|
||||
applicationId "de.weseng.wifiweatherstation"
|
||||
minSdkVersion 15
|
||||
minSdkVersion 16
|
||||
targetSdkVersion 28
|
||||
versionCode 20190302
|
||||
versionName "2019.3.2"
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
package="de.weseng.wifiweatherstation">
|
||||
|
||||
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
|
||||
@@ -14,7 +15,8 @@
|
||||
android:roundIcon="@mipmap/ic_launcher_round"
|
||||
android:supportsRtl="true"
|
||||
android:theme="@style/DarkTheme"
|
||||
android:usesCleartextTraffic="true">
|
||||
android:usesCleartextTraffic="true"
|
||||
tools:ignore="AllowBackup,GoogleAppIndexingWarning">
|
||||
<activity android:name=".MainActivity">
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.MAIN" />
|
||||
|
||||
3
app/src/main/assets/style.css
Normal file
3
app/src/main/assets/style.css
Normal file
@@ -0,0 +1,3 @@
|
||||
body {
|
||||
background-color: transparent;
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
package de.weseng.wifiweatherstation;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.app.ProgressDialog;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
@@ -14,6 +15,7 @@ import android.net.wifi.WifiInfo;
|
||||
import android.net.wifi.WifiManager;
|
||||
import android.support.v7.app.AppCompatActivity;
|
||||
import android.os.Bundle;
|
||||
import android.util.Base64;
|
||||
import android.view.KeyEvent;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuItem;
|
||||
@@ -22,6 +24,7 @@ import android.webkit.WebView;
|
||||
import android.webkit.WebViewClient;
|
||||
import android.widget.Toast;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.util.List;
|
||||
|
||||
|
||||
@@ -30,6 +33,7 @@ public class MainActivity extends AppCompatActivity {
|
||||
WebView myWebView;
|
||||
public static String MESSAGE = "de.weseng.wifiweatherstation.MESSAGE";
|
||||
|
||||
@SuppressLint("SetJavaScriptEnabled")
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
@@ -71,8 +75,11 @@ public class MainActivity extends AppCompatActivity {
|
||||
|
||||
@Override
|
||||
public void onPageFinished(WebView view, String url) {
|
||||
// Inject CSS when page is done loading
|
||||
injectCSS();
|
||||
|
||||
pd.dismiss();
|
||||
String webUrl = myWebView.getUrl();
|
||||
//String webUrl = myWebView.getUrl();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -174,6 +181,30 @@ public class MainActivity extends AppCompatActivity {
|
||||
myWebView.restoreState(savedInstanceState);
|
||||
}
|
||||
|
||||
|
||||
// Inject CSS method: read style.css from assets folder
|
||||
// Append stylesheet to document head
|
||||
private void injectCSS() {
|
||||
try {
|
||||
InputStream inputStream = getAssets().open("style.css");
|
||||
byte[] buffer = new byte[inputStream.available()];
|
||||
//noinspection ResultOfMethodCallIgnored
|
||||
inputStream.read(buffer); // read is necessary!
|
||||
inputStream.close();
|
||||
String encoded = Base64.encodeToString(buffer, Base64.NO_WRAP);
|
||||
myWebView.loadUrl("javascript:(function() {" +
|
||||
"var parent = document.getElementsByTagName('head').item(0);" +
|
||||
"var style = document.createElement('style');" +
|
||||
"style.type = 'text/css';" +
|
||||
// Tell the browser to BASE64-decode the string into your script !!!
|
||||
"style.innerHTML = window.atob('" + encoded + "');" +
|
||||
"parent.appendChild(style)" +
|
||||
"})()");
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
/** Called when the user taps the Send button */
|
||||
public void settings() {
|
||||
Intent intentSettings = new Intent(this, SettingsActivity.class);
|
||||
|
||||
@@ -1,21 +1,13 @@
|
||||
package de.weseng.wifiweatherstation;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
import android.net.ConnectivityManager;
|
||||
import android.net.NetworkInfo;
|
||||
import android.support.v7.app.AppCompatActivity;
|
||||
import android.os.Bundle;
|
||||
import android.view.KeyEvent;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.view.inputmethod.EditorInfo;
|
||||
import android.widget.EditText;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import static de.weseng.wifiweatherstation.MainActivity.PREFS_NAME;
|
||||
|
||||
public class SettingsActivity extends AppCompatActivity {
|
||||
public static final String PREFS_NAME = "Settings";
|
||||
@@ -99,7 +91,6 @@ public class SettingsActivity extends AppCompatActivity {
|
||||
// platform.
|
||||
save_all();
|
||||
super.onBackPressed();
|
||||
return;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -122,6 +113,6 @@ public class SettingsActivity extends AppCompatActivity {
|
||||
editor.putString(key, value);
|
||||
|
||||
// Commit the edits!
|
||||
editor.commit();
|
||||
editor.apply();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="16dp"
|
||||
android:text="TextView"
|
||||
android:text=""
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent" />
|
||||
@@ -30,7 +30,7 @@
|
||||
android:id="@+id/editTextSsidLocal"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:hint="SSID"
|
||||
android:hint="@string/hint_ssid"
|
||||
android:inputType="text" />
|
||||
</android.support.design.widget.TextInputLayout>
|
||||
|
||||
@@ -48,7 +48,7 @@
|
||||
android:id="@+id/editTextUrlLocal"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:hint="Local URL"
|
||||
android:hint="@string/hint_url_local"
|
||||
android:inputType="text" />
|
||||
</android.support.design.widget.TextInputLayout>
|
||||
|
||||
@@ -66,10 +66,8 @@
|
||||
android:id="@+id/editTextUrlGlobal"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:hint="Global URL"
|
||||
android:hint="@string/hint_url_global"
|
||||
android:inputType="text" />
|
||||
</android.support.design.widget.TextInputLayout>
|
||||
|
||||
|
||||
|
||||
</android.support.constraint.ConstraintLayout>
|
||||
@@ -2,6 +2,6 @@
|
||||
<menu xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<item android:id="@+id/settings"
|
||||
android:title="@string/settings"/>
|
||||
//android:icon="@drawable/ic_new_game"
|
||||
//android:showAsAction="ifRoom"
|
||||
<!--android:icon="@drawable/ic_new_game"-->
|
||||
<!--android:showAsAction="ifRoom"-->
|
||||
</menu>
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
<resources>
|
||||
<string name="app_name">WiFi-Wetter-Station</string>
|
||||
<string name="settings">Einstellungen</string>
|
||||
<string name="loading">Bitte warten, die Ansicht wird geladen...</string>
|
||||
<string name="loading">Bitte warten, die Ansicht wird geladen…</string>
|
||||
<string name="hint_url_local">Lokale URL</string>
|
||||
<string name="hint_url_global">Globale URL</string>
|
||||
</resources>
|
||||
|
||||
@@ -1,8 +1,11 @@
|
||||
<resources>
|
||||
<string name="app_name">WiFi Weather Station</string>
|
||||
<string name="settings">Settings</string>
|
||||
<string name="loading">Please wait, the view is loading...</string>
|
||||
<string name="loading">Please wait, the view is loading…</string>
|
||||
<string name="ssid" translatable="false">NETGEAR26-5G-2</string>
|
||||
<string name="url_local" translatable="false">http://192.168.1.5/site/wifi-weather-station/</string>
|
||||
<string name="url_global" translatable="false">http://inetsrv.no-ip.org/site/wifi-weather-station/</string>
|
||||
<string name="hint_ssid" translatable="false">SSID</string>
|
||||
<string name="hint_url_local">Local URL</string>
|
||||
<string name="hint_url_global">Global URL</string>
|
||||
</resources>
|
||||
|
||||
Reference in New Issue
Block a user