package sliz.elektromery;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStreamWriter;

import android.content.Context;

public class appSettings {
	public static Context contextOfApplication;
	
	// Contains actual app settings
	
	// Frame detection method
	public static final int FRAME_DETECT_DETERM = 0;
	public static final int FRAME_DETECT_HAAR = 1;
	public static int mFrameDetectMethod = FRAME_DETECT_DETERM;
	
	// Digit segmentation method
	public static final int DIGIT_DETECT_VERTICAL_PROJ = 0;
	public static final int DIGIT_DETECT_CONTOURS = 1;
	public static int mDigitDetectMethod = DIGIT_DETECT_VERTICAL_PROJ;
	
	// OCR method
	public static final int OCR_GEOMETRIC = 0;
	public static final int OCR_FEATURES= 1;
	public static final int OCR_ANN= 2;
	public static int mOCRMethod = OCR_ANN;
	
	public static File mAppDir;
	public static File mAppDirFiles;
	
	public static String mSelectedFile = null;
	
	public boolean writeToFile(String data)
	{
	    File out;
	    OutputStreamWriter outStreamWriter = null;
	    FileOutputStream outStream = null;

	    out = new File((appSettings.mAppDirFiles), appSettings.mSelectedFile);

	    if ( out.exists() == false ){
            try {
				out.createNewFile();
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
				return false;
			}
	    }
	    try {
		    outStream = new FileOutputStream(out, true) ;
		    outStreamWriter = new OutputStreamWriter(outStream); 	 
			outStreamWriter.append(data);
			outStreamWriter.flush();
			outStreamWriter.append("\n");
			outStreamWriter.close();
		} catch (IOException e) {

			e.printStackTrace();
		}
	    return true;
	}      
	
	public void saveSettings()
	{
//		SharedPreferences sharedPref = contextOfApplication.getSharedPreferences("appSettings", Context.MODE_PRIVATE);
//		SharedPreferences.Editor editor = sharedPref.edit();
//		editor.putInt("mFrameDetectMethod", mFrameDetectMethod);
//		editor.putInt("mDigitDetectMethod", mDigitDetectMethod);
//		editor.putInt("mOCRMethod", mOCRMethod);
	}
	
	public void loadSettings()
	{
//		SharedPreferences sharedPref = contextOfApplication.getSharedPreferences("appSettings", Context.MODE_PRIVATE);
//		if(sharedPref.contains("mFrameDetectMethod"))
//			mFrameDetectMethod = contextOfApplication.getResources().getInteger(0);
//		if(sharedPref.contains("mDigitDetectMethod"))
//			mDigitDetectMethod = contextOfApplication.getResources().getInteger(1);
//		if(sharedPref.contains("mOCRMethod"))
//			mOCRMethod = contextOfApplication.getResources().getInteger(2);
		
	}

}
