diff --git a/app/src/apkFlavor/java/com/jens/automation2/Rule.java b/app/src/apkFlavor/java/com/jens/automation2/Rule.java index 3c0a35e8..94bc569d 100644 --- a/app/src/apkFlavor/java/com/jens/automation2/Rule.java +++ b/app/src/apkFlavor/java/com/jens/automation2/Rule.java @@ -875,7 +875,18 @@ public class Rule implements Comparable Miscellaneous.logEvent("i", String.format(context.getResources().getString(R.string.ruleCheckOf), this.getName()), String.format(context.getResources().getString(R.string.ruleIsDeactivatedCantApply), this.getName()), 3); return false; } - + + public boolean cloneRule(Context context) + { + Rule newRule = new Rule(); + newRule.setName(this.getName() + " - clone"); + newRule.setRuleActive(this.isRuleActive()); + newRule.setRuleToggle(this.isRuleToggle()); + newRule.setTriggerSet(this.getTriggerSet()); + newRule.setActionSet(this.getActionSet()); + return newRule.create(context); + } + private class ActivateRuleTask extends AsyncTask { boolean wasActivated = false; diff --git a/app/src/main/java/com/jens/automation2/ActivityMainRules.java b/app/src/main/java/com/jens/automation2/ActivityMainRules.java index 0343715f..cfb4fb62 100644 --- a/app/src/main/java/com/jens/automation2/ActivityMainRules.java +++ b/app/src/main/java/com/jens/automation2/ActivityMainRules.java @@ -52,12 +52,6 @@ public class ActivityMainRules extends ActivityGeneric @Override public void onClick(View v) { -// if(!ActivityPermissions.havePermission(ActivityPermissions.writeExternalStoragePermissionName, ActivityMainRules.this)) -// { -// Toast.makeText(ActivityMainRules.this, getResources().getString(R.string.appRequiresPermissiontoAccessExternalStorage), Toast.LENGTH_LONG).show(); -// return; -// } - ruleToEdit = null; Intent startAddRuleIntent = new Intent(ActivityMainRules.this, ActivityManageRule.class); startActivityForResult(startAddRuleIntent, 3000); @@ -190,7 +184,7 @@ public class ActivityMainRules extends ActivityGeneric { AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(this); alertDialogBuilder.setTitle(getResources().getString(R.string.whatToDoWithRule)); - alertDialogBuilder.setItems(new String[]{ getResources().getString(R.string.runManually), getResources().getString(R.string.edit), getResources().getString(R.string.deleteCapital) }, new DialogInterface.OnClickListener() + alertDialogBuilder.setItems(new String[]{ getResources().getString(R.string.runManually), getResources().getString(R.string.edit), getResources().getString(R.string.deleteCapital), getResources().getString(R.string.clone) }, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) @@ -218,6 +212,11 @@ public class ActivityMainRules extends ActivityGeneric if(ruleThisIsAbout.delete()) updateListView(); break; + case 3: + ruleToEdit = ruleThisIsAbout; + if(ruleToEdit.cloneRule(ActivityMainRules.this)) + updateListView(); + break; } } }); diff --git a/app/src/main/java/com/jens/automation2/ActivityManagePoi.java b/app/src/main/java/com/jens/automation2/ActivityManagePoi.java index 0bba97b5..06d2143e 100644 --- a/app/src/main/java/com/jens/automation2/ActivityManagePoi.java +++ b/app/src/main/java/com/jens/automation2/ActivityManagePoi.java @@ -22,6 +22,8 @@ import android.widget.ImageButton; import android.widget.Toast; import java.util.Calendar; +import java.util.Timer; +import java.util.TimerTask; public class ActivityManagePoi extends Activity { @@ -34,8 +36,9 @@ public class ActivityManagePoi extends Activity ImageButton ibShowOnMap; EditText guiPoiName, guiPoiLatitude, guiPoiLongitude, guiPoiRadius; Calendar locationSearchStart = null; + Timer timer = null; - final static int defaultRadius = 300; + final static int defaultRadius = 250; final static int searchTimeout = 120; private static ProgressDialog progressDialog; @@ -157,6 +160,7 @@ public class ActivityManagePoi extends Activity else { locationSearchStart = Calendar.getInstance(); + startTimeout(); Miscellaneous.logEvent("i", "POI Manager", getResources().getString(R.string.logGettingPositionWithProvider) + " " + provider1, 3); myLocationManager.requestLocationUpdates(provider1, 500, Settings.satisfactoryAccuracyNetwork, myLocationListenerNetwork); @@ -165,31 +169,66 @@ public class ActivityManagePoi extends Activity myLocationManager.requestLocationUpdates(provider2, 500, Settings.satisfactoryAccuracyGps, myLocationListenerGps); } } - + + private void startTimeout() + { + if(timer != null) + stopTimeout(); + + timer = new Timer(); + + class TimeoutTask extends TimerTask + { + public void run() + { + //calculate the new position of myBall + } + } + + Miscellaneous.logEvent("i", "POI Manager", "Starting timeout for location search: " + String.valueOf(searchTimeout) + " seconds", 5); + + TimerTask updateBall = new TimeoutTask(); + timer.scheduleAtFixedRate(updateBall, 0, searchTimeout * 1000); + } + + private void stopTimeout() + { + Miscellaneous.logEvent("i", "POI Manager", "Stopping timeout for location search.", 5); + + if(timer != null) + { + timer.purge(); + timer.cancel(); + } + } + private void compareLocations() { Miscellaneous.logEvent("i", "POI Manager", getResources().getString(R.string.comparing), 4); + // We have GPS if(locationGps != null) { + myLocationManager.removeUpdates(myLocationListenerNetwork); + guiPoiLatitude.setText(String.valueOf(locationGps.getLatitude())); guiPoiLongitude.setText(String.valueOf(locationGps.getLongitude())); + String text; if(locationNetwork != null) { double variance = locationGps.distanceTo(locationNetwork); - String text = String.format(getResources().getString(R.string.distanceBetween), Math.round(variance)); - Miscellaneous.logEvent("i", "POI Manager", text, 4); + text = String.format(getResources().getString(R.string.distanceBetween), Math.round(variance)); getDialog(text, Math.round(variance) + 1).show(); } else { - progressDialog.dismiss(); - myLocationManager.removeUpdates(myLocationListenerNetwork); - guiPoiRadius.setText("250"); + text = String.format(getResources().getString(R.string.locationFound), defaultRadius); + getDialog(text, defaultRadius).show(); } - } + Miscellaneous.logEvent("i", "POI Manager", text, 4); + } // we have a great network signal else if(locationNetwork != null && locationNetwork.getAccuracy() <= Settings.satisfactoryAccuracyGps && locationNetwork.getAccuracy() <= defaultRadius) { /* @@ -197,11 +236,14 @@ public class ActivityManagePoi extends Activity to accept it a sole result. In that case we suggest a default radius, no variance. */ + guiPoiLatitude.setText(String.valueOf(locationNetwork.getLatitude())); + guiPoiLongitude.setText(String.valueOf(locationNetwork.getLongitude())); + String text = String.format(getResources().getString(R.string.locationFound), defaultRadius); Miscellaneous.logEvent("i", "POI Manager", text, 4); getDialog(text, defaultRadius).show(); - } + } // we have a bad network signal else if( locationNetwork != null && @@ -210,9 +252,13 @@ public class ActivityManagePoi extends Activity (locationSearchStart.getTimeInMillis() + ((long)searchTimeout * 1000)) ) { - // Only a network location was found that is also not very accurate. + // Only a network location was found and it is also not very accurate. + + guiPoiLatitude.setText(String.valueOf(locationNetwork.getLatitude())); + guiPoiLongitude.setText(String.valueOf(locationNetwork.getLongitude())); String text = String.format(getResources().getString(R.string.locationFoundInaccurate), defaultRadius); + getDialog(text, defaultRadius).show(); Miscellaneous.logEvent("i", "POI Manager", text, 4); } else @@ -276,6 +322,7 @@ public class ActivityManagePoi extends Activity // { // Miscellaneous.logEvent("i", "POI Manager", "satisfactoryNetworkAccuracy of " + String.valueOf(Settings.SATISFACTORY_ACCURACY_GPS) + "m reached. Removing location updates..."); + Miscellaneous.logEvent("i", "POI Manager", "Unsubscribing from GPS location updates.", 5); myLocationManager.removeUpdates(this); locationGps = location; @@ -311,8 +358,7 @@ public class ActivityManagePoi extends Activity public void onLocationChanged(Location location) { Miscellaneous.logEvent("i", "POI Manager", getResources().getString(R.string.logGotNetworkUpdate) + " " + String.valueOf(location.getAccuracy()), 3); - String text = "Network position found. satisfactoryNetworkAccuracy of " + String.valueOf(Settings.satisfactoryAccuracyNetwork) + "m reached. Removing location updates..."; - Miscellaneous.logEvent("i", "POI Manager", text, 5); + myLocationManager.removeUpdates(this); locationNetwork = location; @@ -320,6 +366,7 @@ public class ActivityManagePoi extends Activity if(location.getAccuracy() <= Settings.satisfactoryAccuracyGps) { // Accuracy is so good that we don't need to wait for GPS result + Miscellaneous.logEvent("i", "POI Manager", "Unsubscribing from network location updates.", 5); myLocationManager.removeUpdates(myLocationListenerGps); } diff --git a/app/src/main/java/com/jens/automation2/PointOfInterest.java b/app/src/main/java/com/jens/automation2/PointOfInterest.java index c9e5f7e5..7a42031a 100644 --- a/app/src/main/java/com/jens/automation2/PointOfInterest.java +++ b/app/src/main/java/com/jens/automation2/PointOfInterest.java @@ -805,6 +805,7 @@ public class PointOfInterest implements Comparable { String text = String.format(Miscellaneous.getAnyContext().getResources().getString(R.string.overlapBetweenPois), otherPoi.getName(), String.valueOf(overlap)); Miscellaneous.logEvent("w", "POI", text, 2); +// Miscellaneous.messageBox("POI", text, Miscellaneous.getAnyContext()).show(); Toast.makeText(Miscellaneous.getAnyContext(), text, Toast.LENGTH_LONG).show(); return false; } diff --git a/app/src/main/res/values-de/strings.xml b/app/src/main/res/values-de/strings.xml index a2c5ecdc..546e6705 100644 --- a/app/src/main/res/values-de/strings.xml +++ b/app/src/main/res/values-de/strings.xml @@ -14,8 +14,7 @@ Automations-Dienst gestarted. Version %1$s. Der Abstand zwischen GPS- und Mobilfunk-Position beträgt %1$d m. Dies +1 sollte der minimale Radius sein. - Sowohl Netzwerk- als auch GPS Position sind bekannt. Vergleiche... - Falls Sie in einem Gebäude sind wird empfohlen das Gerät in die Nähe eines Fensters zu bringen bis eine Position ermittelt werden konnte. Andernfalls kann es sehr lange dauern oder es funktioniert gar nicht. + Falls Sie in einem Gebäude sind, wird empfohlen das Gerät in die Nähe eines Fensters zu bringen bis eine Position ermittelt werden konnte. Andernfalls kann es sehr lange dauern oder es funktioniert gar nicht. Position wird ermittelt. Bitte warten... Ja Nein @@ -580,4 +579,10 @@ Es gibt keine bekannten WLANs auf Ihrem Gerät. Die Liste von WLANs auf Ihrem Gerät könnte verwendet werden, um zu ermitteln, an welchen Orten Sie waren. Deshalb ist die Positions-Berechtigung nötig, um die Liste dieser WLANs zu laden. Wenn Sie eines aus der Liste auswählen möchten, müssen Sie diese Berechtigung gewähren. Wenn nicht, können Sie immer noch eines manuell eingeben. Diese Funktion öffnet NICHT den Browser, sondern löst die HTTP Anfrage im Hintergrund aus. Sie können das z.B. benutzen, um Befehle an Ihre Heimautomatisierung zu schicken. + Klonen + Es gibt eine neue Version der Anwendung. Möchten Sie den Browser öffnen, um sie herunterzuladen? + Nur bei der APK Version. + Nach Updates suchen + Position gefunden. Der vorgeschlagene Mindestradius für Orte beträgt %1$d m. + Es konnte nur eine ungenaue Position gefunden werden. Das funktioniert u.U. nicht zuverlässig. Der vorgeschlagene Mindestradius für Orte beträgt %1$d m. \ No newline at end of file diff --git a/app/src/main/res/values-es/strings.xml b/app/src/main/res/values-es/strings.xml index e29139d1..e7dce5b4 100644 --- a/app/src/main/res/values-es/strings.xml +++ b/app/src/main/res/values-es/strings.xml @@ -14,7 +14,6 @@ Automation servicio ha iniciado. Versión %1$s. Distancia entre el sitio GPS y el sitio red está %1$d metros. Este +1m debe ser el mínimo. - Tengo tanto sitio red como sitio gps. Estoy comparando... Si está en una edificación vaya cerca de una ventana hasta que una posición haya sido encontrada. Sino podria durar mucho tiempo o no seria posible. Buscando posición. Espere, por favor... Si @@ -517,4 +516,11 @@ Incluya las paréntecis en su texto.\n\n[uniqueid] - el número único de su dis Si crea una norma con vigilancia del proceso la aplicación va a revisar periodicamente si el proceso esta activo. Puede ajustar la frecuencia en la configuración. Puede relentizar la reacción, pero vigilancia permanente gasta mucha bateria. No hay una broadcast del sistema operativo para este evento. Muchos fabricantes intentan conservar energia en limitando la actividades de segundo plano de otras apps. Desafortunadamente el resultado es que en esas aplicaciones no funcionan por completo. Automation esta entre ellas. Vease esta pagina para determinar como excluir Automation de tales medidas. Tiempo maximo entre 2 sitios para determinar la velocidad. + Clonar + Hay nueva versión de la app. Quiere abrir un browser y descargar lo? + Buscar updates + Esta función NO abre el browser, pero enciende un URL en el fondo. Puede usar lo por ejemplo para enviar comandos a su automatización de la casa. + Solo en la versión APK. + Determine un posición. El radio minimo sugeri es %1$d m. + Solo pude determinar una posición imprecisa. Puede ser va a funcionar poco fiable. El radio minimo sugeri es %1$d m. \ No newline at end of file diff --git a/app/src/main/res/values-it/strings.xml b/app/src/main/res/values-it/strings.xml index 6ae1a2e4..f73568ad 100644 --- a/app/src/main/res/values-it/strings.xml +++ b/app/src/main/res/values-it/strings.xml @@ -125,7 +125,6 @@ vicino a Posizione più vicina: Controllare i tunnels dell\'applicazione wireguard - Ho la posizione sia dalla rete che dal GPS e le sto confrontando... Configurazione esportata con successo. Configurazione esportata con successo. connesso @@ -579,4 +578,5 @@ con etichetta Memorizza un file di log Si + Clonare diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 75312855..7794a3ea 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -17,7 +17,7 @@ Starting service. Don\'t have all location measurings, yet. Can\'t do comparison. Distance between GPS location and network location is %1$d meters. This +1m should be the absolute minimum radius. - Have both network and gps location. Comparing... + Have both network and gps location. Comparing... No suitable location providers could be used. If you are in a building it is strongly advised to place your device next to a window until a position has been found. Otherwise it may take a very long time if it is able to find one at all. Getting position. Please wait... @@ -678,6 +678,7 @@ Check for updates Only applies to APK version. There\'s a new update available. Would you like opening the browser to download it? - Location found. The suggested minimum radius for locations is %1$d." + Location found. The suggested minimum radius for locations is %1$d m. Only a location with a limited accuracy could be found. It might not work reliably. The suggested minimum radius for locations is %1$d." + Clone \ No newline at end of file