diff --git a/app/build.gradle b/app/build.gradle index 4f65fc4..d7118ab 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -6,8 +6,8 @@ android { applicationId "de.weseng.wifiweatherstation" minSdkVersion 15 targetSdkVersion 28 - versionCode 1 - versionName "1.0" + versionCode 20190302 + versionName "2019.3.2" testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" } buildTypes { @@ -25,4 +25,5 @@ dependencies { testImplementation 'junit:junit:4.12' androidTestImplementation 'com.android.support.test:runner:1.0.2' androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2' + implementation 'com.android.support:design:28.0.0' } diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index efe2634..c890c95 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -3,22 +3,31 @@ package="de.weseng.wifiweatherstation"> + + + + android:theme="@style/DarkTheme" + android:usesCleartextTraffic="true"> - + + + + - + \ 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 7488c8a..9b3436d 100644 --- a/app/src/main/java/de/weseng/wifiweatherstation/MainActivity.java +++ b/app/src/main/java/de/weseng/wifiweatherstation/MainActivity.java @@ -2,13 +2,18 @@ package de.weseng.wifiweatherstation; import android.app.ProgressDialog; import android.content.Context; +import android.content.Intent; +import android.content.SharedPreferences; import android.graphics.Bitmap; import android.graphics.Color; import android.net.ConnectivityManager; import android.net.NetworkInfo; +import android.net.wifi.SupplicantState; +import android.net.wifi.WifiConfiguration; +import android.net.wifi.WifiInfo; +import android.net.wifi.WifiManager; 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; @@ -17,15 +22,20 @@ import android.webkit.WebView; import android.webkit.WebViewClient; import android.widget.Toast; +import java.util.List; + + public class MainActivity extends AppCompatActivity { + public static final String PREFS_NAME = "Settings"; WebView myWebView; + public static String MESSAGE = "de.weseng.wifiweatherstation.MESSAGE"; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); final ProgressDialog pd = ProgressDialog.show(MainActivity.this, "", - "Bitte warten, die Ansicht wird geladen...", true); + getString(R.string.loading), true); /* apply layout to the current screen */ setContentView(R.layout.activity_main); @@ -48,6 +58,11 @@ public class MainActivity extends AppCompatActivity { myWebView.setBackgroundColor(Color.TRANSPARENT); myWebView.setPadding(0, 0, 0, 0); + SharedPreferences settings = getSharedPreferences(PREFS_NAME, 0); + String ssidLocal = "\"" + settings.getString("ssidLocal", getString(R.string.ssid)) + "\""; + + MESSAGE = ""; + myWebView.setWebViewClient(new WebViewClient() { @Override public void onPageStarted(WebView view, String url, Bitmap favicon) { @@ -79,19 +94,43 @@ public class MainActivity extends AppCompatActivity { if (savedInstanceState == null) { ConnectivityManager connManager = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo mWifi = connManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI); - + //MESSAGE = MESSAGE.concat("\nmWifi: " + mWifi.toString()); + //MESSAGE = MESSAGE.concat("\nmWifi.isConnected(): " + mWifi.isConnected()); // is: true + //MESSAGE = MESSAGE.concat("\nmWifi.getExtraInfo(): " + mWifi.getExtraInfo()); // is: null if (mWifi.isConnected()) { - // loadUrl needs: AndroidManifest.xml listOfConfigurations = wifiManager.getConfiguredNetworks(); + for (int index = 0; index < listOfConfigurations.size(); index++) { + WifiConfiguration configuration = listOfConfigurations.get(index); + if (configuration.networkId == wifiInfo.getNetworkId()) { + return configuration.SSID; + } + } + return null; + } @Override public boolean onKeyDown(int keyCode, KeyEvent event) { // Check if the key event was the Back button and if there's history @@ -107,23 +146,20 @@ public class MainActivity extends AppCompatActivity { @Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. - //getMenuInflater().inflate(R.menu.menu_main, menu); + getMenuInflater().inflate(R.menu.main, menu); return true; } @Override public boolean onOptionsItemSelected(MenuItem item) { - // Handle action bar item clicks here. The action bar will - // automatically handle clicks on the Home/Up button, so long - // as you specify a parent activity in AndroidManifest.xml. - int id = item.getItemId(); - - //noinspection SimplifiableIfStatement - if (id == R.string.action_settings) { - return true; + // Handle item selection + switch (item.getItemId()) { + case R.id.settings: + settings(); + return true; + default: + return super.onOptionsItemSelected(item); } - - return super.onOptionsItemSelected(item); } @Override @@ -138,4 +174,12 @@ public class MainActivity extends AppCompatActivity { myWebView.restoreState(savedInstanceState); } + /** Called when the user taps the Send button */ + public void settings() { + Intent intentSettings = new Intent(this, SettingsActivity.class); + intentSettings.putExtra(MESSAGE, MESSAGE); + startActivity(intentSettings); + } + + } diff --git a/app/src/main/java/de/weseng/wifiweatherstation/SettingsActivity.java b/app/src/main/java/de/weseng/wifiweatherstation/SettingsActivity.java new file mode 100644 index 0000000..9f11a71 --- /dev/null +++ b/app/src/main/java/de/weseng/wifiweatherstation/SettingsActivity.java @@ -0,0 +1,127 @@ +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"; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_settings); + + // Get the Intent that started this activity and extract the string + Intent intent = getIntent(); + String message = intent.getStringExtra(MainActivity.MESSAGE); + + SharedPreferences settings = getSharedPreferences(PREFS_NAME, 0); + String ssidLocal = settings.getString("ssidLocal", getString(R.string.ssid)); + String urlLocal = settings.getString("urlLocal", getString(R.string.url_local)); + String urlGlobal = settings.getString("urlGlobal", getString(R.string.url_global)); + //message = message.concat("\nSSIDLocal: " + ssidLocal); + + // Capture the layout's TextView and set the string as its text + TextView textView = findViewById(R.id.textView); + textView.setText(message); + + final EditText editTextSsid = findViewById(R.id.editTextSsidLocal); + editTextSsid.setText(ssidLocal); + editTextSsid.setOnKeyListener(new View.OnKeyListener() { + public boolean onKey(View v, int keyCode, KeyEvent event) { + // If the event is a key-down event on the "enter" button + if ((event.getAction() == KeyEvent.ACTION_DOWN) && + (keyCode == KeyEvent.KEYCODE_ENTER)) { + // Perform action on key press + String value = editTextSsid.getText().toString(); + //Toast.makeText(getApplicationContext(), value, Toast.LENGTH_SHORT).show(); + save("ssidLocal", value); + return true; + } + return false; + } + }); + + final EditText editTextUrlLocal = findViewById(R.id.editTextUrlLocal); + editTextUrlLocal.setText(urlLocal); + editTextUrlLocal.setOnKeyListener(new View.OnKeyListener() { + public boolean onKey(View v, int keyCode, KeyEvent event) { + // If the event is a key-down event on the "enter" button + if ((event.getAction() == KeyEvent.ACTION_DOWN) && + (keyCode == KeyEvent.KEYCODE_ENTER)) { + // Perform action on key press + String value = editTextUrlLocal.getText().toString(); + //Toast.makeText(getApplicationContext(), value, Toast.LENGTH_SHORT).show(); + save("urlLocal", value); + return true; + } + return false; + } + }); + + final EditText editTextUrlGlobal = findViewById(R.id.editTextUrlGlobal); + editTextUrlGlobal.setText(urlGlobal); + editTextUrlGlobal.setOnKeyListener(new View.OnKeyListener() { + public boolean onKey(View v, int keyCode, KeyEvent event) { + // If the event is a key-down event on the "enter" button + if ((event.getAction() == KeyEvent.ACTION_DOWN) && + (keyCode == KeyEvent.KEYCODE_ENTER)) { + // Perform action on key press + String value = editTextUrlGlobal.getText().toString(); + //Toast.makeText(getApplicationContext(), value, Toast.LENGTH_SHORT).show(); + save("urlGlobal", value); + return true; + } + return false; + } + }); + + } + + @Override + public void onBackPressed() { + // This will be called either automatically for you on 2.0 + // or later, or by the code above on earlier versions of the + // platform. + save_all(); + super.onBackPressed(); + return; + } + + @Override + protected void onStop(){ + super.onStop(); + save_all(); + } + + public void save_all() { + save("ssidLocal", ((EditText)findViewById(R.id.editTextSsidLocal)).getText().toString()); + save("urlLocal", ((EditText)findViewById(R.id.editTextUrlLocal)).getText().toString()); + save("urlGlobal", ((EditText)findViewById(R.id.editTextUrlGlobal)).getText().toString()); + } + + public void save(String key, String value) { + // We need an Editor object to make preference changes. + // All objects are from android.context.Context + SharedPreferences settings = getSharedPreferences(PREFS_NAME, 0); + SharedPreferences.Editor editor = settings.edit(); + editor.putString(key, value); + + // Commit the edits! + editor.commit(); + } +} diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml index 6dad876..cb20efb 100644 --- a/app/src/main/res/layout/activity_main.xml +++ b/app/src/main/res/layout/activity_main.xml @@ -14,6 +14,6 @@ app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintLeft_toLeftOf="parent" app:layout_constraintRight_toRightOf="parent" - app:layout_constraintTop_toTopOf="parent"> + app:layout_constraintTop_toTopOf="parent"/> \ No newline at end of file diff --git a/app/src/main/res/layout/activity_settings.xml b/app/src/main/res/layout/activity_settings.xml new file mode 100644 index 0000000..3818c13 --- /dev/null +++ b/app/src/main/res/layout/activity_settings.xml @@ -0,0 +1,75 @@ + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/menu/main.xml b/app/src/main/res/menu/main.xml new file mode 100644 index 0000000..9cfea8c --- /dev/null +++ b/app/src/main/res/menu/main.xml @@ -0,0 +1,7 @@ + + + + //android:icon="@drawable/ic_new_game" + //android:showAsAction="ifRoom" + diff --git a/app/src/main/res/values-de/strings.xml b/app/src/main/res/values-de/strings.xml new file mode 100644 index 0000000..889f74a --- /dev/null +++ b/app/src/main/res/values-de/strings.xml @@ -0,0 +1,5 @@ + + WiFi-Wetter-Station + Einstellungen + Bitte warten, die Ansicht wird geladen... + diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 4a1b46f..62665c1 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -1,4 +1,8 @@ WiFi Weather Station - Einstellungen + Settings + Please wait, the view is loading... + NETGEAR26-5G-2 + http://192.168.1.5/site/wifi-weather-station/ + http://inetsrv.no-ip.org/site/wifi-weather-station/ diff --git a/app/src/main/res/values/styles.xml b/app/src/main/res/values/styles.xml index 5885930..df18faa 100644 --- a/app/src/main/res/values/styles.xml +++ b/app/src/main/res/values/styles.xml @@ -1,7 +1,8 @@ -