package com.wireless.apa;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStream;
import java.io.Writer;
import java.net.MalformedURLException;
import java.util.Properties;

import org.apache.commons.io.FileUtils;

import android.os.Environment;


public class PropertiesHelper {
		
		private Properties properties;
		private final String propertiesFilePath = Environment.getExternalStorageDirectory()  + "/WirelessRemote/properties/settings.properties";
		private final String DEFAULT_IMAGE_PATH = Environment.getExternalStorageDirectory()  + "/WirelessRemote/";
		

		private static PropertiesHelper instance = null;
		
		
				
				
		public String getImagePath() {
			return DEFAULT_IMAGE_PATH;
		}
		
		public static PropertiesHelper getInstance() {
			if (instance == null)
				instance = new PropertiesHelper();
			return instance;
		}
		
		public PropertiesHelper() {
			loadProperties();
		}
			
		public void loadProperties() {
			properties = new Properties();
			try {
				FileInputStream in = new FileInputStream(propertiesFilePath);
				properties.load(in);
				in.close();
			} catch (MalformedURLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}

		public void setProperty(String name, String value) {
			properties.setProperty(name, value);
			FileOutputStream fos;
			try {
				fos = new FileOutputStream(propertiesFilePath);
				properties.store(fos, "");
				loadProperties();
			} catch (FileNotFoundException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			
		}
		
		public String getProperty(String propertyName) {			
			return properties.getProperty(propertyName);
		}
		
		public void refresh() {
			loadProperties();
		}

		


		

}
