forked from jens/Automation
		
	Import/export configuration and Spanish translation.
This commit is contained in:
		@@ -119,21 +119,62 @@ public class ActivityMaintenance extends Activity
 | 
				
			|||||||
                if(resultCode == RESULT_OK)
 | 
					                if(resultCode == RESULT_OK)
 | 
				
			||||||
                {
 | 
					                {
 | 
				
			||||||
                    Uri uriTree = data.getData();
 | 
					                    Uri uriTree = data.getData();
 | 
				
			||||||
                    DocumentFile directory = DocumentFile.fromTreeUri(this, uriTree);
 | 
					                    importFiles(uriTree);
 | 
				
			||||||
                    for(DocumentFile file : directory.listFiles())
 | 
					 | 
				
			||||||
                    {
 | 
					 | 
				
			||||||
                        if(file.canRead() && file.getName().equals(XmlFileInterface.settingsFileName))
 | 
					 | 
				
			||||||
                        {
 | 
					 | 
				
			||||||
                            // import rules, locations, etc.
 | 
					 | 
				
			||||||
                            Miscellaneous.copyFileUsingStream(file, Miscellaneous.getWriteableFolder() + "/" + XmlFileInterface.settingsFileName);
 | 
					 | 
				
			||||||
                        }
 | 
					 | 
				
			||||||
                        else if(false && file.canRead() && file.getName().equals(XmlFileInterface.settingsFileName))
 | 
					 | 
				
			||||||
                        {
 | 
					 | 
				
			||||||
                            // import rules, locations, etc.
 | 
					 | 
				
			||||||
                        }
 | 
					 | 
				
			||||||
                    }
 | 
					 | 
				
			||||||
                }
 | 
					                }
 | 
				
			||||||
                break;
 | 
					                break;
 | 
				
			||||||
 | 
					            case requestCodeExport:
 | 
				
			||||||
 | 
					                if(resultCode == RESULT_OK)
 | 
				
			||||||
 | 
					                {
 | 
				
			||||||
 | 
					                    Uri uriTree = data.getData();
 | 
				
			||||||
 | 
					                    exportFiles(uriTree);
 | 
				
			||||||
 | 
					                }
 | 
				
			||||||
 | 
					                break;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    void importFiles(Uri uriTree)
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					//        https://stackoverflow.com/questions/46237558/android-strange-behavior-of-documentfile-inputstream
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        DocumentFile directory = DocumentFile.fromTreeUri(this, uriTree);
 | 
				
			||||||
 | 
					        for(DocumentFile file : directory.listFiles())
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					            if(file.canRead() && file.getName().equals(XmlFileInterface.settingsFileName))
 | 
				
			||||||
 | 
					            {
 | 
				
			||||||
 | 
					                // import rules, locations, etc.
 | 
				
			||||||
 | 
					                if(Miscellaneous.copyDocumentFileToFile(file, new File(Miscellaneous.getWriteableFolder() + "/" + XmlFileInterface.settingsFileName + "2")))
 | 
				
			||||||
 | 
					                {
 | 
				
			||||||
 | 
					                    // reload file
 | 
				
			||||||
 | 
					                    Toast.makeText(ActivityMaintenance.this, getResources().getString(R.string.rulesImportedSuccessfully), Toast.LENGTH_LONG).show();
 | 
				
			||||||
 | 
					                }
 | 
				
			||||||
 | 
					                else
 | 
				
			||||||
 | 
					                    Toast.makeText(ActivityMaintenance.this, getResources().getString(R.string.rulesImportError), Toast.LENGTH_LONG).show();
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					            else if(false && file.canRead() && file.getName().equals(XmlFileInterface.settingsFileName))
 | 
				
			||||||
 | 
					            {
 | 
				
			||||||
 | 
					                // import rules, locations, etc.
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    void exportFiles(Uri uriTree)
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					        DocumentFile directory = DocumentFile.fromTreeUri(this, uriTree);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        File src = new File(Miscellaneous.getWriteableFolder() + "/" + XmlFileInterface.settingsFileName);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        DocumentFile dst = directory.createFile("text/xml", XmlFileInterface.settingsFileName);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        if(dst.canWrite())
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					            // import rules, locations, etc.
 | 
				
			||||||
 | 
					            if(Miscellaneous.copyFileToDocumentFile(src, dst))
 | 
				
			||||||
 | 
					            {
 | 
				
			||||||
 | 
					                // reload file
 | 
				
			||||||
 | 
					                Toast.makeText(ActivityMaintenance.this, getResources().getString(R.string.rulesExportedSuccessfully), Toast.LENGTH_LONG).show();
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					            else
 | 
				
			||||||
 | 
					                Toast.makeText(ActivityMaintenance.this, getResources().getString(R.string.rulesExportError), Toast.LENGTH_LONG).show();
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1215,7 +1215,85 @@ public class Miscellaneous extends Service
 | 
				
			|||||||
		return returnValue;
 | 
							return returnValue;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	public static String copyDocumentFile(String inputPath, String inputFile, Uri treeUri)
 | 
						public static boolean copyDocumentFileToFile(DocumentFile src, File dst)
 | 
				
			||||||
 | 
						{
 | 
				
			||||||
 | 
							InputStream in = null;
 | 
				
			||||||
 | 
							OutputStream out = null;
 | 
				
			||||||
 | 
							String error = null;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							try
 | 
				
			||||||
 | 
							{
 | 
				
			||||||
 | 
								in = Miscellaneous.getAnyContext().getContentResolver().openInputStream(src.getUri());
 | 
				
			||||||
 | 
								out = new FileOutputStream(dst);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								byte[] buffer = new byte[1024];
 | 
				
			||||||
 | 
								int read;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								while ((read = in.read(buffer)) != -1)
 | 
				
			||||||
 | 
								{
 | 
				
			||||||
 | 
									out.write(buffer, 0, read);
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								in.close();
 | 
				
			||||||
 | 
								// write the output file (You have now copied the file)
 | 
				
			||||||
 | 
								out.flush();
 | 
				
			||||||
 | 
								out.close();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								return true;
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							catch (FileNotFoundException fnfe1)
 | 
				
			||||||
 | 
							{
 | 
				
			||||||
 | 
								error = fnfe1.getMessage();
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							catch (Exception e)
 | 
				
			||||||
 | 
							{
 | 
				
			||||||
 | 
								error = e.getMessage();
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							return false;
 | 
				
			||||||
 | 
					//		return error;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						public static boolean copyFileToDocumentFile(File src, DocumentFile dst)
 | 
				
			||||||
 | 
						{
 | 
				
			||||||
 | 
							InputStream in = null;
 | 
				
			||||||
 | 
							OutputStream out = null;
 | 
				
			||||||
 | 
							String error = null;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							try
 | 
				
			||||||
 | 
							{
 | 
				
			||||||
 | 
								in = new FileInputStream(src);
 | 
				
			||||||
 | 
								out = Miscellaneous.getAnyContext().getContentResolver().openOutputStream(dst.getUri());
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								byte[] buffer = new byte[1024];
 | 
				
			||||||
 | 
								int read;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								while ((read = in.read(buffer)) != -1)
 | 
				
			||||||
 | 
								{
 | 
				
			||||||
 | 
									out.write(buffer, 0, read);
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								in.close();
 | 
				
			||||||
 | 
								// write the output file (You have now copied the file)
 | 
				
			||||||
 | 
								out.flush();
 | 
				
			||||||
 | 
								out.close();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								return true;
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							catch (FileNotFoundException fnfe1)
 | 
				
			||||||
 | 
							{
 | 
				
			||||||
 | 
								error = fnfe1.getMessage();
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							catch (Exception e)
 | 
				
			||||||
 | 
							{
 | 
				
			||||||
 | 
								error = e.getMessage();
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							return false;
 | 
				
			||||||
 | 
					//		return error;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						/*public static String copyDocumentFile(String inputPath, String inputFile, Uri treeUri)
 | 
				
			||||||
	{
 | 
						{
 | 
				
			||||||
		InputStream in = null;
 | 
							InputStream in = null;
 | 
				
			||||||
		OutputStream out = null;
 | 
							OutputStream out = null;
 | 
				
			||||||
@@ -1223,14 +1301,16 @@ public class Miscellaneous extends Service
 | 
				
			|||||||
		DocumentFile pickedDir = DocumentFile.fromTreeUri(getActivity(), treeUri);
 | 
							DocumentFile pickedDir = DocumentFile.fromTreeUri(getActivity(), treeUri);
 | 
				
			||||||
		String extension = inputFile.substring(inputFile.lastIndexOf(".")+1,inputFile.length());
 | 
							String extension = inputFile.substring(inputFile.lastIndexOf(".")+1,inputFile.length());
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		try {
 | 
							try
 | 
				
			||||||
 | 
							{
 | 
				
			||||||
			DocumentFile newFile = pickedDir.createFile("audio/"+extension, inputFile);
 | 
								DocumentFile newFile = pickedDir.createFile("audio/"+extension, inputFile);
 | 
				
			||||||
			out = getActivity().getContentResolver().openOutputStream(newFile.getUri());
 | 
								out = getActivity().getContentResolver().openOutputStream(newFile.getUri());
 | 
				
			||||||
			in = new FileInputStream(inputPath + inputFile);
 | 
								in = new FileInputStream(inputPath + inputFile);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
			byte[] buffer = new byte[1024];
 | 
								byte[] buffer = new byte[1024];
 | 
				
			||||||
			int read;
 | 
								int read;
 | 
				
			||||||
			while ((read = in.read(buffer)) != -1) {
 | 
								while ((read = in.read(buffer)) != -1)
 | 
				
			||||||
 | 
								{
 | 
				
			||||||
				out.write(buffer, 0, read);
 | 
									out.write(buffer, 0, read);
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
			in.close();
 | 
								in.close();
 | 
				
			||||||
@@ -1238,13 +1318,18 @@ public class Miscellaneous extends Service
 | 
				
			|||||||
			out.flush();
 | 
								out.flush();
 | 
				
			||||||
			out.close();
 | 
								out.close();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		} catch (FileNotFoundException fnfe1) {
 | 
							}
 | 
				
			||||||
 | 
							catch (FileNotFoundException fnfe1)
 | 
				
			||||||
 | 
							{
 | 
				
			||||||
			error = fnfe1.getMessage();
 | 
								error = fnfe1.getMessage();
 | 
				
			||||||
		} catch (Exception e) {
 | 
							}
 | 
				
			||||||
 | 
							catch (Exception e)
 | 
				
			||||||
 | 
							{
 | 
				
			||||||
			error = e.getMessage();
 | 
								error = e.getMessage();
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		return error;
 | 
							return error;
 | 
				
			||||||
	}
 | 
						}*/
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	public static boolean googleToBlameForLocation(boolean checkExistingRules)
 | 
						public static boolean googleToBlameForLocation(boolean checkExistingRules)
 | 
				
			||||||
	{
 | 
						{
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -9,7 +9,7 @@
 | 
				
			|||||||
    <string name="addPoi">Crear lugar</string>
 | 
					    <string name="addPoi">Crear lugar</string>
 | 
				
			||||||
    <string name="addRule">Crear regla</string>
 | 
					    <string name="addRule">Crear regla</string>
 | 
				
			||||||
    <string name="poiList">Listo de lugares:</string>
 | 
					    <string name="poiList">Listo de lugares:</string>
 | 
				
			||||||
    <string name="ruleList">Listo del reglas:</string>
 | 
					    <string name="ruleList">Lista de reglas:</string>
 | 
				
			||||||
    <string name="pleaseEnterValidName">Inserta un nombre válido, por favor.</string>
 | 
					    <string name="pleaseEnterValidName">Inserta un nombre válido, por favor.</string>
 | 
				
			||||||
    <string name="pleaseSpecifiyTrigger">Inserta al menos un disparador, por favor.</string>
 | 
					    <string name="pleaseSpecifiyTrigger">Inserta al menos un disparador, por favor.</string>
 | 
				
			||||||
    <string name="pleaseSpecifiyAction">Inserta al menos un acción, por favor.</string>
 | 
					    <string name="pleaseSpecifiyAction">Inserta al menos un acción, por favor.</string>
 | 
				
			||||||
@@ -118,4 +118,50 @@
 | 
				
			|||||||
    <string name="poiStillReferenced">Todavia hay reglas cuales usan este lugar (%1$s). No puedo borrar el.</string>
 | 
					    <string name="poiStillReferenced">Todavia hay reglas cuales usan este lugar (%1$s). No puedo borrar el.</string>
 | 
				
			||||||
    <string name="generalSettings">Reglajes generales.</string>
 | 
					    <string name="generalSettings">Reglajes generales.</string>
 | 
				
			||||||
    <string name="startAtSystemBoot">Inicializar al boot.</string>
 | 
					    <string name="startAtSystemBoot">Inicializar al boot.</string>
 | 
				
			||||||
 | 
					    <string name="writeLogFile">Guardar un archivo protocolo</string>
 | 
				
			||||||
 | 
					    <string name="wifiState">Estado wifi</string>
 | 
				
			||||||
 | 
					    <string name="showHelp">Descripción</string>
 | 
				
			||||||
 | 
					    <string name="rules">Reglas</string>
 | 
				
			||||||
 | 
					    <string name="timeframes">Intervalo</string>
 | 
				
			||||||
 | 
					    <string name="helpTitleEnergySaving">Configuración de ahorro de energia</string>
 | 
				
			||||||
 | 
					    <string name="speedMaximumTime">Tiempo en minutos</string>
 | 
				
			||||||
 | 
					    <string name="exceeds">exede</string>
 | 
				
			||||||
 | 
					    <string name="dropsBelow">es menos que</string>
 | 
				
			||||||
 | 
					    <string name="triggerPointOfInterest">Lugar</string>
 | 
				
			||||||
 | 
					    <string name="triggerTimeFrame">Intervalo</string>
 | 
				
			||||||
 | 
					    <string name="triggerSpeed">Velocidad</string>
 | 
				
			||||||
 | 
					    <string name="actionSetWifi">Wifi</string>
 | 
				
			||||||
 | 
					    <string name="actionSetBluetooth">Bluetooth</string>
 | 
				
			||||||
 | 
					    <string name="actionSetWifiTethering">Enrutador wifi</string>
 | 
				
			||||||
 | 
					    <string name="actionSetUsbTethering">Enrutador USB</string>
 | 
				
			||||||
 | 
					    <string name="actionTurnBluetoothOn">encender Bluetooth</string>
 | 
				
			||||||
 | 
					    <string name="actionTurnWifiOn">encender wifi</string>
 | 
				
			||||||
 | 
					    <string name="actionTurnWifiOff">desactivar Bluetooth</string>
 | 
				
			||||||
 | 
					    <string name="actionTurnBluetoothOff">desactivar Bluetooth</string>
 | 
				
			||||||
 | 
					    <string name="actionTriggerUrl">Abrir URL en antecedentes</string>
 | 
				
			||||||
 | 
					    <string name="actionChangeSoundProfile">Cambiar perfil sonido</string>
 | 
				
			||||||
 | 
					    <string name="actionTurnUsbTetheringOn">encender enrutador USB</string>
 | 
				
			||||||
 | 
					    <string name="actionTurnUsbTetheringOff">desactivar enrutador USB</string>
 | 
				
			||||||
 | 
					    <string name="actionTurnWifiTetheringOn">encender enrutatdor wifi</string>
 | 
				
			||||||
 | 
					    <string name="actionTurnWifiTetheringOff">desactivar enrutador wifi</string>
 | 
				
			||||||
 | 
					    <string name="actionTurnAirplaneModeOn">encender modo de vuelo</string>
 | 
				
			||||||
 | 
					    <string name="actionTurnAirplaneModeOff">desactivar modo de vuelo</string>
 | 
				
			||||||
 | 
					    <string name="activePoi">Lugar activo</string>
 | 
				
			||||||
 | 
					    <string name="closestPoi">Lugar mas cerca</string>
 | 
				
			||||||
 | 
					    <string name="poi">Posición</string>
 | 
				
			||||||
 | 
					    <string name="pois">posiciónes</string>
 | 
				
			||||||
 | 
					    <string name="serviceNotRunning">Servicio not esta activo</string>
 | 
				
			||||||
 | 
					    <string name="general">General</string>
 | 
				
			||||||
 | 
					    <string name="startServiceAfterAppUpdate">Encender servicio después un update si estuve activado</string>
 | 
				
			||||||
 | 
					    <string name="startServiceAfterAppUpdateShort">Encender servicio después un update</string>
 | 
				
			||||||
 | 
					    <string name="cancel">Cancelar</string>
 | 
				
			||||||
 | 
					    <string name="wifiName">Nombre de wifi</string>
 | 
				
			||||||
 | 
					    <string name="wifiConnection">Coneción a un wifi</string>
 | 
				
			||||||
 | 
					    <string name="exceeding">exedendo</string>
 | 
				
			||||||
 | 
					    <string name="droppingBelow">estendo menos que</string>
 | 
				
			||||||
 | 
					    <string name="anyWifi">algun wifi</string>
 | 
				
			||||||
 | 
					    <string name="selectApplication">Elega la app</string>
 | 
				
			||||||
 | 
					    <string name="selectPackageOfApplication">Elega el paquete de la app</string>
 | 
				
			||||||
 | 
					    <string name="selectActivityToBeStarted">Elega la actividad de la app</string>
 | 
				
			||||||
 | 
					    <string name="errorStartingOtherActivity">Error encendiendo otra app</string>
 | 
				
			||||||
</resources>
 | 
					</resources>
 | 
				
			||||||
@@ -650,4 +650,8 @@
 | 
				
			|||||||
    <string name="importConfiguration">Import configuration</string>
 | 
					    <string name="importConfiguration">Import configuration</string>
 | 
				
			||||||
    <string name="exportConfiguration">Export configuration</string>
 | 
					    <string name="exportConfiguration">Export configuration</string>
 | 
				
			||||||
    <string name="moreSettings">More settings</string>
 | 
					    <string name="moreSettings">More settings</string>
 | 
				
			||||||
 | 
					    <string name="rulesImportedSuccessfully">Rules and locations have been imported successfully.</string>
 | 
				
			||||||
 | 
					    <string name="rulesImportError">There was an error importing rules and locations.</string>
 | 
				
			||||||
 | 
					    <string name="rulesExportedSuccessfully">Rules and locations exported successfully.</string>
 | 
				
			||||||
 | 
					    <string name="rulesExportError">Error exporting rules and locations.</string>
 | 
				
			||||||
</resources>
 | 
					</resources>
 | 
				
			||||||
		Reference in New Issue
	
	Block a user