Commits

Romain Vernoux  committed 77b765e

major update, includes sources import/export

  • Participants
  • Parent commits e3e020a

Comments (0)

Files changed (50)

File AndroidManifest.xml

         <activity
         	android:theme="@style/MyTheme"
         	android:name=".About">
-        	
         </activity>
-
+        <activity
+        	android:theme="@style/MyTheme"
+        	android:name=".FileSave">
+        </activity>
+		<activity
+        	android:theme="@style/MyTheme"
+        	android:name=".FileOverwrite">
+        </activity>
+        <activity
+        	android:name=".FileOpen"
+        	android:theme="@android:style/Theme.Dialog"
+        	android:label="@string/menu_open">
+        </activity>
     </application>
     <uses-sdk android:minSdkVersion="3" />
 

File default.properties

 # project structure.
 
 # Project target.
-target=android-3
+target=android-7

File res/drawable-hdpi/camel_dark.png

Added
New image

File res/drawable-hdpi/camel_light.png

Added
New image

File res/drawable-hdpi/ic_menu_add.png

Added
New image

File res/drawable-hdpi/ic_menu_archive.png

Added
New image

File res/drawable-hdpi/ic_menu_clear_playlist.png

Added
New image

File res/drawable-hdpi/ic_menu_close_clear_cancel.png

Added
New image

File res/drawable-hdpi/ic_menu_compose_dark.png

Added
New image

File res/drawable-hdpi/ic_menu_compose_light.png

Added
New image

File res/drawable-hdpi/ic_menu_info_details.png

Added
New image

File res/drawable-hdpi/ic_menu_save.png

Added
New image

File res/drawable-hdpi/icon.png

Added
New image

File res/drawable-hdpi/ide_tab.xml

+<?xml version="1.0" encoding="utf-8"?>
+<selector xmlns:android="http://schemas.android.com/apk/res/android">
+    <!-- When selected, use grey -->
+    <item android:drawable="@drawable/ic_menu_compose_dark"
+          android:state_selected="true" />
+    <!-- When not selected, use white-->
+    <item android:drawable="@drawable/ic_menu_compose_light" />
+</selector>

File res/drawable-hdpi/toplevel_tab.xml

+<?xml version="1.0" encoding="utf-8"?>
+<selector xmlns:android="http://schemas.android.com/apk/res/android">
+    <!-- When selected, use grey -->
+    <item android:drawable="@drawable/camel_dark"
+          android:state_selected="true" />
+    <!-- When not selected, use white-->
+    <item android:drawable="@drawable/camel_light" />
+</selector>

File res/drawable-mdpi/camel_dark.png

Added
New image

File res/drawable-mdpi/camel_light.png

Added
New image

File res/drawable-mdpi/ic_menu_add.png

Added
New image

File res/drawable-mdpi/ic_menu_archive.png

Added
New image

File res/drawable-mdpi/ic_menu_clear_playlist.png

Added
New image

File res/drawable-mdpi/ic_menu_close_clear_cancel.png

Added
New image

File res/drawable-mdpi/ic_menu_compose_dark.png

Added
New image

File res/drawable-mdpi/ic_menu_compose_light.png

Added
New image

File res/drawable-mdpi/ic_menu_info_details.png

Added
New image

File res/drawable-mdpi/ic_menu_save.png

Added
New image

File res/drawable-mdpi/icon.png

Added
New image

File res/drawable-mdpi/ide_tab.xml

+<?xml version="1.0" encoding="utf-8"?>
+<selector xmlns:android="http://schemas.android.com/apk/res/android">
+    <!-- When selected, use grey -->
+    <item android:drawable="@drawable/ic_menu_compose_dark"
+          android:state_selected="true" />
+    <!-- When not selected, use white-->
+    <item android:drawable="@drawable/ic_menu_compose_light" />
+</selector>

File res/drawable-mdpi/toplevel_tab.xml

+<?xml version="1.0" encoding="utf-8"?>
+<selector xmlns:android="http://schemas.android.com/apk/res/android">
+    <!-- When selected, use grey -->
+    <item android:drawable="@drawable/camel_dark"
+          android:state_selected="true" />
+    <!-- When not selected, use white-->
+    <item android:drawable="@drawable/camel_light" />
+</selector>

File res/drawable/camel_dark.png

Removed
Old image

File res/drawable/camel_light.png

Removed
Old image

File res/drawable/ic_menu_add.png

Removed
Old image

File res/drawable/ic_menu_clear_playlist.png

Removed
Old image

File res/drawable/ic_menu_close_clear_cancel.png

Removed
Old image

File res/drawable/ic_menu_compose_dark.png

Removed
Old image

File res/drawable/ic_menu_compose_light.png

Removed
Old image

File res/drawable/ic_menu_info_details.png

Removed
Old image

File res/drawable/ic_menu_set_as.png

Removed
Old image

File res/drawable/icon.png

Removed
Old image

File res/drawable/ide_tab.xml

-<?xml version="1.0" encoding="utf-8"?>
-<selector xmlns:android="http://schemas.android.com/apk/res/android">
-    <!-- When selected, use grey -->
-    <item android:drawable="@drawable/ic_menu_compose_dark"
-          android:state_selected="true" />
-    <!-- When not selected, use white-->
-    <item android:drawable="@drawable/ic_menu_compose_light" />
-</selector>

File res/drawable/toplevel_tab.xml

-<?xml version="1.0" encoding="utf-8"?>
-<selector xmlns:android="http://schemas.android.com/apk/res/android">
-    <!-- When selected, use grey -->
-    <item android:drawable="@drawable/camel_dark"
-          android:state_selected="true" />
-    <!-- When not selected, use white-->
-    <item android:drawable="@drawable/camel_light" />
-</selector>

File res/layout/editpanel.xml

    	android:gravity="center" >
    	<Button
 	    android:id="@+id/add_button_up"
-	    android:layout_width="wrap_content"
+	    android:layout_width="fill_parent"
 	    android:layout_height="wrap_content"
+	    android:layout_weight="1"
 	    android:text="@string/add_button_up" />
    	<Button
 	    android:id="@+id/add_button_down"
-	    android:layout_width="wrap_content"
+	    android:layout_width="fill_parent"
 	    android:layout_height="wrap_content"
+	    android:layout_weight="1"
 	    android:text="@string/add_button_down" />
    	<Button
 	    android:id="@+id/delete_button"
-	    android:layout_width="wrap_content"
+	    android:layout_width="fill_parent"
 	    android:layout_height="wrap_content"
+	    android:layout_weight="1"
 	    android:text="@string/del_button"/>
    	<Button
 	    android:id="@+id/compile_button"
-	    android:layout_width="wrap_content"
-	    android:layout_height="wrap_content" 
+	    android:layout_width="fill_parent"
+	    android:layout_height="wrap_content"
+	    android:layout_weight="1" 
 	    android:text="@string/compile_button"/>
   </LinearLayout>
   </LinearLayout>

File res/layout/fileopen.xml

+<?xml version="1.0" encoding="utf-8"?>
+<LinearLayout
+  xmlns:android="http://schemas.android.com/apk/res/android"
+  android:layout_width="250dp"
+  android:layout_height="wrap_content"
+  android:orientation="vertical"
+  android:padding="10dip" >
+  	<TextView 
+		android:id="@+id/main" 
+		android:layout_width="fill_parent"
+		android:layout_height="wrap_content" 
+		android:text="@string/menu_open"
+		android:textStyle="bold" 
+		android:textSize="20sp" 
+		android:gravity="center" 
+		android:layout_marginBottom="20dp"/>
+  	<TextView
+  		android:layout_width="wrap_content"
+  		android:layout_height="wrap_content"
+  		android:text="Import sources from file:" />
+  	<ListView 
+  		android:id="@+id/listview"
+  		android:layout_width="fill_parent"
+  		android:layout_height="wrap_content"
+  		android:textFilterEnabled="true" />
+</LinearLayout>

File res/layout/fileoverwrite.xml

+<?xml version="1.0" encoding="utf-8"?>
+<LinearLayout
+  xmlns:android="http://schemas.android.com/apk/res/android"
+  android:layout_width="250dp"
+  android:layout_height="wrap_content"
+  android:orientation="vertical"
+  android:padding="10dip" >
+  	<TextView 
+		android:id="@+id/main" 
+		android:layout_width="fill_parent"
+		android:layout_height="wrap_content" 
+		android:text="@string/menu_save"
+		android:textStyle="bold" 
+		android:textSize="20sp" 
+		android:gravity="center" 
+		android:layout_marginBottom="20dp"/>
+  	<TextView
+  		android:layout_width="wrap_content"
+  		android:layout_height="wrap_content"
+  		android:text="@string/existing_file" 
+  		android:layout_marginBottom="20dp"/>
+ 	<LinearLayout
+ 		android:layout_width="fill_parent"
+ 		android:layout_height="wrap_content"
+ 		android:orientation="horizontal" 
+ 		android:gravity="center">
+ 			<Button
+ 				android:id="@+id/button_yes"
+ 				android:layout_width="100dp"
+ 				android:layout_height="wrap_content" 
+ 				android:text="Yes" />
+ 			<Button
+ 				android:id="@+id/button_no"
+ 				android:layout_width="100dp"
+ 				android:layout_height="wrap_content" 
+ 				android:text="No" />
+ 	</LinearLayout>
+</LinearLayout>

File res/layout/filesave.xml

+<?xml version="1.0" encoding="utf-8"?>
+<LinearLayout
+  xmlns:android="http://schemas.android.com/apk/res/android"
+  android:layout_width="250dp"
+  android:layout_height="wrap_content"
+  android:orientation="vertical"
+  android:padding="10dip" >
+  	<TextView 
+		android:id="@+id/main" 
+		android:layout_width="fill_parent"
+		android:layout_height="wrap_content" 
+		android:text="@string/menu_save"
+		android:textStyle="bold" 
+		android:textSize="20sp" 
+		android:gravity="center" 
+		android:layout_marginBottom="20dp"/>
+  	<TextView
+  		android:layout_width="wrap_content"
+  		android:layout_height="wrap_content"
+  		android:text="File name:" />
+ 	<EditText
+		android:id="@+id/filename"
+		android:layout_width="fill_parent"
+		android:layout_height="wrap_content"
+		android:singleLine="true"
+		android:layout_marginBottom="20dp"/>
+ 	<LinearLayout
+ 		android:layout_width="fill_parent"
+ 		android:layout_height="wrap_content"
+ 		android:orientation="horizontal" 
+ 		android:gravity="center">
+ 			<Button
+ 				android:id="@+id/button_save"
+ 				android:layout_width="100dp"
+ 				android:layout_height="wrap_content" 
+ 				android:text="Save" />
+ 			<Button
+ 				android:id="@+id/button_cancel"
+ 				android:layout_width="100dp"
+ 				android:layout_height="wrap_content" 
+ 				android:text="Cancel" />
+ 	</LinearLayout>
+</LinearLayout>

File res/layout/list_item.xml

+<?xml version="1.0" encoding="utf-8"?>
+<TextView xmlns:android="http://schemas.android.com/apk/res/android"
+    android:layout_width="fill_parent"
+    android:layout_height="fill_parent"
+    android:padding="10dp"
+    android:textSize="16sp" 
+    android:textColor="@android:color/primary_text_dark">
+</TextView>

File res/values/strings.xml

 <resources>
     <string name="app_name">OCaml Toplevel for Android</string>
     <string name='menu_addpanel'>Add Panel</string>
-    <string name='menu_clipboard'>Copy to Clipboard</string>
+    <string name='menu_open'>Import Sources</string>
+    <string name='menu_save'>Save Sources</string>
     <string name='menu_clear'>Clear Output</string>
     <string name="menu_about">About</string>
     <string name="menu_quit">Exit</string>
     <string name="del_button">Delete</string>
     <string name="compile_button">Compile</string>
     <string name="clear_toast">View cleared by user</string>
-    <string name="clipboard_toast">Panel contents merged and copied to Clipboard</string>
+    <string name="clipboard_toast">Sources merged and copied to Clipboard</string>
+    <string name="file_external_toast">Sources merged and saved in sdcard/ocaml/.</string>
+    <string name="file_readonly_toast">External storage access denied. Please check that your phone is not connected to your computer in Mass Storage Mode and try again.</string>
+    <string name="file_no_sdcard">Error : unable to access SD Card.</string>
+    <string name="file_not_saved">Sources not saved.</string>
+    <string name="file_write_fail">Error while saving your sources. Please try again.</string>
+    <string name="filename_hint">Enter a new or an existing file name.</string>
+    <string name="file_read_fail">Error while reading the file: file corrupted.</string>
+    <string name="existing_file">This file already exists. Do you want to overwrite it?</string>
+    <string name="file_directory_not_found">Directory not found or empty.</string>
     <string name='copyright'>Copyright &#169; 2011 Keigo IMAI\n
 Copyright &#169; 2011 Romain VERNOUX\n
 Copyright &#169; 1995-2011 INRIA\n\n

File src/jp/co/itpl/ocamlandroid/FileOpen.java

+package jp.co.itpl.ocamlandroid;
+
+import java.io.File;
+
+import android.app.Activity;
+import android.app.ListActivity;
+import android.content.Intent;
+import android.os.Bundle;
+import android.view.View;
+import android.view.Window;
+import android.widget.AdapterView;
+import android.widget.AdapterView.OnItemClickListener;
+import android.widget.ArrayAdapter;
+import android.widget.ListAdapter;
+import android.widget.ListView;
+
+public class FileOpen extends Activity {
+
+	public void onCreate(Bundle savedInstanceState) {
+		super.onCreate(savedInstanceState);
+		this.requestWindowFeature(Window.FEATURE_NO_TITLE);
+		setContentView(R.layout.fileopen);
+		
+		final String path = this.getIntent().getExtras().getString("path");
+		File file = new File(path);
+		final String[] liste = file.list();
+		
+		ArrayAdapter<String> aa = new ArrayAdapter<String>(this, R.layout.list_item, liste);
+
+		ListView lv = (ListView)findViewById(R.id.listview);
+		lv.setTextFilterEnabled(true);
+		lv.setAdapter(aa);
+	
+		lv.setOnItemClickListener(new OnItemClickListener() {
+		    
+			  @Override
+			  public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
+		      Intent intent = new Intent(FileOpen.this, MainActivity.class);
+		      intent.putExtra("file", path + File.separator + liste[position]);
+		      setResult(Activity.RESULT_OK, intent);
+		      FileOpen.this.finish();
+		    }
+
+		  });
+		}
+}

File src/jp/co/itpl/ocamlandroid/FileOverwrite.java

+package jp.co.itpl.ocamlandroid;
+
+import android.app.Activity;
+import android.content.Context;
+import android.content.Intent;
+import android.os.Bundle;
+import android.view.View;
+import android.view.Window;
+import android.view.View.OnClickListener;
+import android.view.inputmethod.InputMethodManager;
+import android.widget.Button;
+import android.widget.EditText;
+
+public class FileOverwrite extends Activity {
+
+	public void onCreate(Bundle savedInstanceState) {
+		super.onCreate(savedInstanceState);
+		this.requestWindowFeature(Window.FEATURE_NO_TITLE);
+		setContentView(R.layout.fileoverwrite);
+		
+		Button button_yes = (Button) findViewById(R.id.button_yes);
+		Button button_no = (Button) findViewById(R.id.button_no);
+		
+		button_yes.setOnClickListener(
+				new OnClickListener() {
+
+					@Override
+					public void onClick(View arg0) {
+						// TODO Auto-generated method stub
+							setResult(Activity.RESULT_OK);
+							FileOverwrite.this.finish();
+						}
+				});
+				
+		button_no.setOnClickListener(
+				new OnClickListener() {
+
+					@Override
+					public void onClick(View arg0) {
+						// TODO Auto-generated method stub
+							setResult(Activity.RESULT_CANCELED);
+							FileOverwrite.this.finish();
+						}
+				});
+	}
+}

File src/jp/co/itpl/ocamlandroid/FileSave.java

+package jp.co.itpl.ocamlandroid;
+
+import android.app.Activity;
+import android.content.Context;
+import android.content.Intent;
+import android.os.Bundle;
+import android.view.View;
+import android.view.Window;
+import android.view.View.OnClickListener;
+import android.view.inputmethod.InputMethodManager;
+import android.widget.Button;
+import android.widget.EditText;
+
+public class FileSave extends Activity {
+
+	public void onCreate(Bundle savedInstanceState) {
+		super.onCreate(savedInstanceState);
+		this.requestWindowFeature(Window.FEATURE_NO_TITLE);
+		setContentView(R.layout.filesave);
+		
+		String previous_filename = this.getIntent().getExtras().getString("previous_filename");
+		
+		Button button_save = (Button) findViewById(R.id.button_save);
+		Button button_cancel = (Button) findViewById(R.id.button_cancel);
+		
+		final EditText fileName = (EditText) findViewById(R.id.filename);
+		
+		fileName.setText(previous_filename);
+		fileName.selectAll();
+		
+		button_save.setOnClickListener(
+				new OnClickListener() {
+
+					@Override
+					public void onClick(View arg0) {
+						// TODO Auto-generated method stub
+						String result;
+						if(!(result = fileName.getText().toString()).equals("")){
+							Intent intent = new Intent(FileSave.this, MainActivity.class);
+							intent.putExtra("fileName", result);
+							setResult(Activity.RESULT_OK, intent);
+							FileSave.this.finish();
+						}
+					}
+				});
+				
+	
+		button_cancel.setOnClickListener(
+			new OnClickListener() {
+
+				@Override
+				public void onClick(View arg0) {
+					// TODO Auto-generated method stub
+					setResult(Activity.RESULT_CANCELED);
+					FileSave.this.finish();
+				}
+			});
+			
+	}
+}

File src/jp/co/itpl/ocamlandroid/MainActivity.java

 /*   TO DO
  
  - Wait for Feedbacks
- - autorisations
+ - Permissions
  - Beta demand : file open/save feature
  - Beta demand : import modules
  
 
 package jp.co.itpl.ocamlandroid;
 
+import java.io.BufferedReader;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
 import java.io.IOException;
 import java.io.InputStream;
+import java.io.InputStreamReader;
 import java.io.OutputStreamWriter;
 import java.io.PrintWriter;
 
 import android.content.Intent;
 import android.os.AsyncTask;
 import android.os.Bundle;
-import android.text.ClipboardManager;
+import android.os.Environment;
 import android.text.Html;
 import android.util.Log;
 import android.view.LayoutInflater;
 
 public class MainActivity extends Activity {
 	public static final int MENU_ADDPANEL = 0;
-	public static final int MENU_CLIPBOARD = 1;
-	public static final int MENU_CLEAR = 2;
-	public static final int MENU_ABOUT = 3;
-	public static final int MENU_QUIT = 4;
+	public static final int MENU_SAVE = 1;
+	public static final int MENU_OPEN = 2;
+	public static final int MENU_CLEAR = 3;
+	public static final int MENU_ABOUT = 4;
+	public static final int MENU_QUIT = 5;
 	public static final int FROM_TOPLEVEL = 1;
 	public static final int FROM_USER = 2;
 	public static final int EDITTEXT = 0;
 	public static final int DELETE_BUTTON = 2;
 	public static final int PANEL_UP = 3;
 	public static final int PANEL_DOWN = 4;
+	public static final int FILE_NAME = 0;
+	public static final int OVERWRITE = 1;
+	public static final int OPEN_FILE = 2;
 	public static final String TOPLEVEL_START_TAG = "";
 	public static final String TOPLEVEL_END_TAG = "";
 	public static final String USER_START_TAG = "<b>";
 	private BackThread backThread = null;
 	private LinearLayout editPanelView = null;
 	private int editPanel_number;
-
-	
-	
-	
+	private String fileName = "";
 	
 	
 	@Override
 		println("",FROM_USER); // Causes the view to display the old text after a orientation change.
 		
 		backThread = new BackThread();
-		backThread.execute();
-					
+		backThread.execute();	
+		
 	}
 	
 	/*
 		delete_button.setId(10*(index+1)+DELETE_BUTTON);
 		panel_up_button.setId(10*(index+1)+PANEL_UP);
 		panel_down_button.setId(10*(index+1)+PANEL_DOWN);
-		// For instance, the compile_button in the third editPanel has ID = 3*10+1 = 21 where 3 stands for "third panel" and "1" for "compile_button".
+		// For instance, the compile_button in the third editPanel has ID = 3*10+1 = 31 where 3 stands for "third panel" and "1" for "compile_button".
 		
 		
 		
 						println(line, FROM_USER);
 						out.println(line);
 						out.flush();
-						
 					}
 				}
 				
 					@Override
 					public void onClick(View arg0) {
 						// TODO Auto-generated method stub
-						delEditPanel(arg0.getId()/10);
+						if(editPanel_number > 2){
+							delEditPanel(arg0.getId()/10);
+						}
 					}
 					
 				}
 	}
 	
 	public void println(String line, int origin) { 
-		Log.d(TAG, "console output: "+line);
+		//Log.d(TAG, "console output: "+line);
 		String line2 = line.replace("<", "&lt;").replace("\n", "<br />");
 		if(origin == FROM_USER){
 			output_text = output_text.concat(USER_START_TAG).concat(line2).concat(USER_END_TAG);
 		Toast.makeText(MainActivity.this, R.string.clear_toast, Toast.LENGTH_SHORT).show();
 	}
 	
+	private String merge(){
+		String content = "";
+		for(int k = 1; k < editPanel_number; k++){
+			content = content.concat(((EditText) findViewById(10*k+ EDITTEXT)).getText().toString()).concat("\n\n");
+		}
+		content = content.substring(0, content.length()-2);
+		return content;
+	}
+	
+	private void saveFile(String name, boolean overwrite) {
+		String state = Environment.getExternalStorageState();
+		FileOutputStream fOut = null; 
+        OutputStreamWriter osw = null;
+	    if (Environment.MEDIA_MOUNTED.equals(state)) {
+	    	String path = Environment.getExternalStorageDirectory().getAbsolutePath()+ File.separator + "ocaml";
+	    	new File(path).mkdirs();
+	    	File file = new File(path + File.separator + name);
+	    	if(file.isFile() && !overwrite){
+	    		Intent intent = new Intent(MainActivity.this, FileOverwrite.class);
+	    		startActivityForResult(intent, OVERWRITE);
+	    	} else {
+			try{ 
+	           fOut = new FileOutputStream(file);       
+	            osw = new OutputStreamWriter(fOut); 
+	            osw.write(merge()); 
+                Toast.makeText(MainActivity.this, R.string.file_external_toast, Toast.LENGTH_LONG).show();
+	            } catch (Exception e) {       
+	            	Toast.makeText(MainActivity.this, R.string.file_write_fail, Toast.LENGTH_LONG).show();
+	            } finally {
+	            	try {
+						osw.close();
+					} catch (IOException e) {
+						// TODO Auto-generated catch block
+						e.printStackTrace();
+					} 
+	            }
+	            Log.d(TAG,"File saved in " + path + ".");
+	    	}
+	    } else if (Environment.MEDIA_SHARED.equals(state)) {
+	        Toast.makeText(MainActivity.this, R.string.file_readonly_toast, Toast.LENGTH_LONG).show();
+	    } else {
+	    	Toast.makeText(MainActivity.this, R.string.file_no_sdcard, Toast.LENGTH_LONG).show();
+	    }
+	}
+
+	private void openFile(String name) {
+		FileInputStream fis = null; 
+        InputStreamReader isr = null;
+        BufferedReader br = null;
+        String content = "";
+	   	try{ 
+           fis = new FileInputStream(name);  
+           isr = new InputStreamReader(fis);
+           br = new BufferedReader(isr);
+           String line;
+           while ((line = br.readLine()) != null) {
+                content = content + line + "\n";
+              }
+          
+          } catch (Exception e) {
+        	  Toast.makeText(MainActivity.this, R.string.file_read_fail, Toast.LENGTH_LONG).show();
+          } finally {
+        	  try {
+					br.close();
+				} catch (IOException e) {
+					// TODO Auto-generated catch block
+					e.printStackTrace();
+				}
+          }
+        Log.d(TAG,"Sources imported from " + name + ".");
+	    int current = editPanel_number;
+		addEditPanel(current-1);
+		((EditText) findViewById(10*current + EDITTEXT)).setText(content.substring(0, content.length()-1));		
+	}
+	
+	private void menuSave(){
+		Intent intent = new Intent(MainActivity.this, FileSave.class);
+		intent.putExtra("previous_filename", fileName);
+		startActivityForResult(intent, FILE_NAME);
+	}
+	
+	private void menuOpen(){
+		String state = Environment.getExternalStorageState();
+		if (Environment.MEDIA_MOUNTED.equals(state)) {
+	    	String path = Environment.getExternalStorageDirectory().getAbsolutePath()+ File.separator + "ocaml";
+	    	File file = new File(path);
+	    	if(!file.isDirectory() || file.list().length == 0){
+	    		Toast.makeText(MainActivity.this, R.string.file_directory_not_found, Toast.LENGTH_LONG).show();
+	    	} else {
+	    		Intent intent = new Intent(MainActivity.this, FileOpen.class);
+	    		intent.putExtra("path", path);
+	    		startActivityForResult(intent, OPEN_FILE);
+	    	}
+	    } else if (Environment.MEDIA_SHARED.equals(state)) {
+	        Toast.makeText(MainActivity.this, R.string.file_readonly_toast, Toast.LENGTH_LONG).show();
+	    } else {
+	    	Toast.makeText(MainActivity.this, R.string.file_no_sdcard, Toast.LENGTH_LONG).show();
+	    }
+	}
+	
+	protected void onActivityResult(int requestCode, int result, Intent intent){
+		switch(requestCode){
+			case FILE_NAME:
+				if(result == Activity.RESULT_OK){
+					String name = intent.getExtras().getString("fileName");
+					
+					fileName = name;
+					saveFile(name, false);
+				} else {
+					Toast.makeText(MainActivity.this, R.string.file_not_saved, Toast.LENGTH_LONG).show();
+				}
+				break;
+			case OVERWRITE:
+				if(result == Activity.RESULT_OK){
+					saveFile(fileName, true);
+				} else {
+					Toast.makeText(MainActivity.this, R.string.file_not_saved, Toast.LENGTH_LONG).show();
+				}
+				break;
+			case OPEN_FILE:
+				if(result== Activity.RESULT_OK){
+					String file = intent.getExtras().getString("file");
+					openFile(file);
+				}
+				break;
+		}
+	}
+	
 	@Override
-	public boolean onCreateOptionsMenu(Menu menu) { 
+ 	public boolean onCreateOptionsMenu(Menu menu) { 
 		super.onCreateOptionsMenu(menu);
 		
-		menu.add(Menu.NONE, MENU_ADDPANEL, Menu.NONE, R.string.menu_addpanel)
-			.setIcon(R.drawable.ic_menu_add);
-		menu.add(Menu.NONE, MENU_CLIPBOARD, Menu.NONE, R.string.menu_clipboard)
-		.setIcon(R.drawable.ic_menu_set_as);
+		menu.add(Menu.NONE, MENU_OPEN, Menu.NONE, R.string.menu_open)
+			.setIcon(R.drawable.ic_menu_archive);
+		menu.add(Menu.NONE, MENU_SAVE, Menu.NONE, R.string.menu_save)
+			.setIcon(R.drawable.ic_menu_save);
 		menu.add(Menu.NONE, MENU_CLEAR, Menu.NONE, R.string.menu_clear)
 			.setIcon(R.drawable.ic_menu_clear_playlist);
 		menu.add(Menu.NONE, MENU_ABOUT, Menu.NONE, R.string.menu_about)
 		
 		return true;
 	}
-
 	
 	@Override
 	public boolean onOptionsItemSelected(MenuItem item) { 
 		switch (item.getItemId()) {
-		case MENU_ADDPANEL:
-			addEditPanel(editPanel_number-1);
+		case MENU_OPEN:
+			menuOpen();
 			return true;
-		case MENU_CLIPBOARD:
-			String content = "";
-			for(int k = 1; k < editPanel_number; k++){
-				content = content.concat(((EditText) findViewById(10*k+ EDITTEXT)).getText().toString()).concat("\n\n");
-			}
-			content = content.substring(0, content.length()-2);
-			ClipboardManager clipboard = (ClipboardManager) getSystemService(CLIPBOARD_SERVICE); 
-			clipboard.setText(content);
-			tabHost.setCurrentTab(0);
-			Toast.makeText(MainActivity.this, R.string.clipboard_toast, Toast.LENGTH_SHORT).show();
+		case MENU_SAVE:
+			menuSave();;
 			return true;
 		case MENU_CLEAR:
 			clear();