From 02f7b642cffcf1a08870192553d485aedae73159 Mon Sep 17 00:00:00 2001 From: Jens Date: Mon, 23 Oct 2023 23:44:21 +0200 Subject: [PATCH] Wifi trigger hint --- .../ActivityManageTriggerWifi.java | 49 ++++++++++++++++++- .../java/com/jens/automation2/Trigger.java | 5 +- .../layout/activity_manage_trigger_wifi.xml | 8 +++ app/src/main/res/values/strings.xml | 1 + .../metadata/android/en-US/changelogs/135.txt | 3 +- 5 files changed, 63 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/com/jens/automation2/ActivityManageTriggerWifi.java b/app/src/main/java/com/jens/automation2/ActivityManageTriggerWifi.java index 5b09480..219649c 100644 --- a/app/src/main/java/com/jens/automation2/ActivityManageTriggerWifi.java +++ b/app/src/main/java/com/jens/automation2/ActivityManageTriggerWifi.java @@ -12,11 +12,15 @@ import android.net.wifi.WifiConfiguration; import android.net.wifi.WifiManager; import android.os.Build; import android.os.Bundle; +import android.text.Editable; +import android.text.TextWatcher; import android.util.Log; +import android.view.KeyEvent; import android.view.View; import android.widget.AdapterView; import android.widget.ArrayAdapter; import android.widget.Button; +import android.widget.CompoundButton; import android.widget.EditText; import android.widget.RadioButton; import android.widget.Spinner; @@ -43,7 +47,7 @@ public class ActivityManageTriggerWifi extends Activity List wifiList = new ArrayList<>(); ArrayAdapter wifiSpinnerAdapter; private final static int requestCodeLocationPermission = 124; - TextView tvWifiTriggerNameLocationNotice; + TextView tvWifiTriggerNameLocationNotice, tvWifiTriggerDisconnectionHint; @Override protected void onCreate(@Nullable Bundle savedInstanceState) @@ -59,6 +63,9 @@ public class ActivityManageTriggerWifi extends Activity bTriggerWifiSave = (Button) findViewById(R.id.bTriggerWifiSave); bLoadWifiList = (Button) findViewById(R.id.bLoadWifiList); tvWifiTriggerNameLocationNotice = (TextView)findViewById(R.id.tvWifiTriggerNameLocationNotice); + tvWifiTriggerDisconnectionHint = (TextView)findViewById(R.id.tvWifiTriggerDisconnectionHint); + + tvWifiTriggerDisconnectionHint.setVisibility(View.GONE); wifiSpinnerAdapter = new ArrayAdapter(this, R.layout.text_view_for_poi_listview_mediumtextsize, wifiList); spinnerWifiList.setAdapter(wifiSpinnerAdapter); @@ -101,6 +108,11 @@ public class ActivityManageTriggerWifi extends Activity public void onItemSelected(AdapterView parent, View view, int position, long id) { etTriggerWifiName.setText(wifiList.get(position)); + + if(etTriggerWifiName.getText().toString().length() > 0 && rbTriggerWifiDisconnected.isChecked()) + tvWifiTriggerDisconnectionHint.setVisibility(View.VISIBLE); + else + tvWifiTriggerDisconnectionHint.setVisibility(View.GONE); } @Override @@ -118,6 +130,41 @@ public class ActivityManageTriggerWifi extends Activity loadWifis(); } }); + + rbTriggerWifiDisconnected.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() + { + @Override + public void onCheckedChanged(CompoundButton compoundButton, boolean b) + { + if(etTriggerWifiName.getText().toString().length() > 0 && b) + tvWifiTriggerDisconnectionHint.setVisibility(View.VISIBLE); + else + tvWifiTriggerDisconnectionHint.setVisibility(View.GONE); + } + }); + etTriggerWifiName.addTextChangedListener(new TextWatcher() + { + @Override + public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) + { + + } + + @Override + public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) + { + if(etTriggerWifiName.getText().toString().length() > 0 && rbTriggerWifiDisconnected.isChecked()) + tvWifiTriggerDisconnectionHint.setVisibility(View.VISIBLE); + else + tvWifiTriggerDisconnectionHint.setVisibility(View.GONE); + } + + @Override + public void afterTextChanged(Editable editable) + { + + } + }); } public void loadWifis() diff --git a/app/src/main/java/com/jens/automation2/Trigger.java b/app/src/main/java/com/jens/automation2/Trigger.java index 829de8a..687356a 100644 --- a/app/src/main/java/com/jens/automation2/Trigger.java +++ b/app/src/main/java/com/jens/automation2/Trigger.java @@ -815,7 +815,10 @@ public class Trigger } else { - if (!WifiBroadcastReceiver.getLastWifiSsidReal().equals(this.getTriggerParameter2()) && !(Miscellaneous.isRegularExpression(this.getTriggerParameter2()) && WifiBroadcastReceiver.getLastWifiSsidReal().matches(this.getTriggerParameter2()))) + if ( + !Settings.serviceStartDone + || + (!WifiBroadcastReceiver.getLastWifiSsidReal().equals(this.getTriggerParameter2()) && !(Miscellaneous.isRegularExpression(this.getTriggerParameter2()) && WifiBroadcastReceiver.getLastWifiSsidReal().matches(this.getTriggerParameter2())))) { Miscellaneous.logEvent("i", Miscellaneous.getAnyContext().getResources().getString(R.string.ruleCheckOf), String.format(String.format(Miscellaneous.getAnyContext().getResources().getString(R.string.ruleDoesntApplyNotTheCorrectSsid), getParentRule().getName(), this.getTriggerParameter2(), WifiBroadcastReceiver.getLastWifiSsidReal()), this.getParentRule().getName()), 3); return false; diff --git a/app/src/main/res/layout/activity_manage_trigger_wifi.xml b/app/src/main/res/layout/activity_manage_trigger_wifi.xml index aad445c..9a4dd70 100644 --- a/app/src/main/res/layout/activity_manage_trigger_wifi.xml +++ b/app/src/main/res/layout/activity_manage_trigger_wifi.xml @@ -103,6 +103,14 @@ + +