Commits

Romain Vernoux committed 18ad156

Tabbed nightly build

Comments (0)

Files changed (8)

Add a comment to this file

res/drawable/camel_dark.png

Added
New image
Add a comment to this file

res/drawable/camel_light.png

Added
New image
Add a comment to this file

res/drawable/ic_menu_compose_dark.png

Added
New image
Add a comment to this file

res/drawable/ic_menu_compose_light.png

Added
New image

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>

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>

res/layout/main.xml

 <?xml version="1.0" encoding="utf-8"?>
-<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
-    android:orientation="vertical"
+<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
+    android:id="@+id/tabhost"
     android:layout_width="fill_parent"
-    android:layout_height="fill_parent"
-    android:gravity="fill_vertical"
-    android:layout_marginBottom="10dip"
-    >
-<EditText
-    android:id="@+id/input"
-    android:layout_width="fill_parent" 
-    android:layout_height="wrap_content"
-    android:singleLine="true" 
-    />
-<ScrollView
-	android:id="@+id/scrollview"
-	android:layout_width="fill_parent"
-    android:layout_height="fill_parent"
-	android:layout_marginTop="10dip"
-    android:layout_marginLeft="10dip"
-    android:layout_marginRight="10dip"
-    android:layout_marginBottom="10dip">
-    
-	<TextView  
-	    android:id="@+id/output"
-	    android:layout_width="fill_parent" 
-	    android:layout_height="wrap_content"
-	    android:layout_marginBottom="10dip"
-	    />
-</ScrollView>
-</LinearLayout>
+    android:layout_height="fill_parent">
+	<LinearLayout 
+	    android:orientation="vertical"
+	    android:layout_width="fill_parent"
+	    android:layout_height="fill_parent"
+	    android:gravity="fill_vertical">
+		<TabWidget
+            android:id="@android:id/tabs"
+            android:layout_width="fill_parent"
+            android:layout_height="wrap_content" />
+        <FrameLayout
+            android:id="@android:id/tabcontent"
+            android:layout_width="fill_parent"
+            android:layout_height="fill_parent"
+            android:padding="5dip">
+            
+            
+            		<!-- Tab 1 start -->
+		            <LinearLayout 
+		            	android:id="@+id/tab1"
+					    android:orientation="vertical"
+					    android:layout_width="fill_parent"
+					    android:layout_height="fill_parent">
+			            <EditText
+					    android:id="@+id/input"
+					    android:layout_width="fill_parent" 
+					    android:layout_height="wrap_content"
+					    android:gravity="top" 
+					    />
+					    <LinearLayout
+					    	android:orientation="horizontal"
+					    	android:layout_width="fill_parent"
+					    	android:layout_height="wrap_content"
+					    	android:gravity="right">
+					    	<Button
+							    android:id="@+id/clear_button"
+							    android:layout_width="wrap_content"
+							    android:layout_height="wrap_content" 
+							    android:text="Clear"/>
+					    	<Button
+							    android:id="@+id/compile_button"
+							    android:layout_width="wrap_content"
+							    android:layout_height="wrap_content" 
+							    android:text="Compile"/>
+					    </LinearLayout>
+					    
+		            </LinearLayout>
+		            <!-- Tab 1 end -->
+		            
+		            
+		            <!-- Tab 2 start -->
+		            <LinearLayout 
+		            	android:id="@+id/tab2"
+					    android:orientation="vertical"
+					    android:layout_width="fill_parent"
+					    android:layout_height="fill_parent">
+			            <ScrollView
+							android:id="@+id/scrollview"
+							android:layout_width="fill_parent"
+						    android:layout_height="fill_parent"
+							android:layout_marginTop="10dip"
+						    android:layout_marginLeft="10dip"
+						    android:layout_marginRight="10dip"
+						    android:layout_marginBottom="10dip">
+						    
+							<TextView  
+							    android:id="@+id/output"
+							    android:layout_width="fill_parent" 
+							    android:layout_height="wrap_content"
+							    android:layout_marginBottom="10dip"
+							    />
+						</ScrollView>
+					</LinearLayout>
+					<!-- Tab 2 end -->
+					
+					
+		</FrameLayout>		
+	</LinearLayout>
+</TabHost>
+

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

  03/03/11
  - Old code related to the webview deleted
  - Scrolling in println
+ 
+ 04/03/11
+ - Tabs implementation (main.xml has been deeply changed)
+
 */
 
 /*   TO DO
  
  - Cleaning
  - Orientation Changes are crashing the app (we have to keep the Backthread alive during such process) 
- - Separate the User Input Screen from the Caml Output Screen (two tabs ?)
  - Fix the Copy Function
 
 */
  	Then, we have to queue the scroll process with a runnable, or else the screen won't scroll
  	and the last lines will appear under the bottom of the screen.
  
+ Compile button 
+ 	-> Is the toplevel "compiling" or "executing" ? I'm not sure.
+ 
+ Copy Function
+ 	-> Is it still useful ?
  */
 
 
 
 import android.app.Activity;
 import android.app.Dialog;
-import android.graphics.Color;
 import android.os.AsyncTask;
 import android.os.Bundle;
 import android.util.Log;
 import android.view.MenuItem;
 import android.view.MotionEvent;
 import android.view.View;
-import android.webkit.WebSettings;
-import android.webkit.WebView;
+import android.view.View.OnClickListener;
+import android.widget.Button;
 import android.widget.EditText;
 import android.widget.ScrollView;
+import android.widget.TabHost;
+import android.widget.TabHost.TabSpec;
 import android.widget.TextView;
 import android.widget.Toast;
 
 	public static final int MENU_ABOUT = 3;
 	public static final String TAG = "ocaml-android";
 	
+	private TabHost tabHost;
+	private Button compile_button;
+	private Button clear_button;
 	private EditText edit;
 	private TextView outView; 
 	private ScrollView scrollView;
 	volatile PrintWriter out = null;
 	private InputStream in = null;
-	private CharBuffer text = null;
-
 	
-	public void println(String line) { 
-		Log.d(TAG, "console output:"+line);
-		outView.setText(outView.getText().toString().concat(line));
-		scrollView.post(new Runnable() { 
-		    public void run() { 
-		        scrollView.scrollTo(0, outView.getHeight()); 
-		    } 
-		}); 
-		edit.requestFocus();
-	}
-
-	private void clear() { 
-		Log.d(TAG, "console clear");
-		outView.setText("");
-	}
+	
 	
 	
 	
 	public void onCreate(Bundle savedInstanceState) {
 		super.onCreate(savedInstanceState);
 		setContentView(R.layout.main);
+		
+		// TabView implementation start
+		tabHost=(TabHost)findViewById(R.id.tabhost);
+		tabHost.setup();
+
+		TabSpec spec1=tabHost.newTabSpec("Tab 1");
+		spec1.setIndicator("Code Editor",getResources().getDrawable(R.drawable.ide_tab));
+		spec1.setContent(R.id.tab1);
+		
+		TabSpec spec2=tabHost.newTabSpec("Tab 2");
+		spec2.setIndicator("OCaml Toplevel",getResources().getDrawable(R.drawable.toplevel_tab));
+		spec2.setContent(R.id.tab2);
+		
+		tabHost.addTab(spec1);
+		tabHost.addTab(spec2);
+		// TabView implementation end
+		
 		outView = (TextView) findViewById(R.id.output);
 		scrollView = (ScrollView) findViewById(R.id.scrollview);
 		
+		/* NOT ANYMORE
 		edit = (EditText)findViewById(R.id.input);
 		edit.setOnEditorActionListener(new TextView.OnEditorActionListener() {
 			public boolean onEditorAction(TextView view, int arg1, KeyEvent arg2) {
 				}
 				return true;
 			}
-		});
+		}); 
 		edit.requestFocus();
+		*/
+		
+		edit = (EditText) findViewById(R.id.input);
+		compile_button = (Button) findViewById(R.id.compile_button);
+		clear_button = (Button) findViewById(R.id.clear_button);
+		
+		
+		compile_button.setOnClickListener(
+			new OnClickListener() {
+
+				@Override
+				public void onClick(View arg0) {
+					// TODO Auto-generated method stub
+					if(out!=null && !"".equals(edit.getText().toString().trim())) {
+						String line = edit.getText().toString()+"\n";
+						println(line);
+						out.println(line);
+						out.flush();
+						
+					}
+				}
+				
+			}
+		);
+		clear_button.setOnClickListener(
+				new OnClickListener() {
+
+					@Override
+					public void onClick(View arg0) {
+						// TODO Auto-generated method stub
+						edit.setText("");
+					}
+					
+				}
+		);
+		
+		
 		new BackThread().execute(); 
 	}
-
+	
 	@Override
 	public void onResume() { 	
 		super.onResume();
 		IS01FullScreen.invoke();
 	}
 
+
+	
+	
+
+	public void println(String line) { 
+		Log.d(TAG, "console output:"+line);
+		outView.setText(outView.getText().toString().concat(line));
+		scrollView.post(new Runnable() { 
+		    public void run() { 
+		        scrollView.smoothScrollTo(0, outView.getHeight()); 
+		    } 
+		}); 
+		//edit.requestFocus();
+	}
+
+	private void clear() { 
+		Log.d(TAG, "console clear");
+		outView.setText("");
+	}
+	
 	@Override
 	public boolean onCreateOptionsMenu(Menu menu) { 
 		super.onCreateOptionsMenu(menu);
 		}
 	}
 	
-	
-	
-	
 	private class BackThread extends AsyncTask<Void,String,Void> { // NEW
 
 		@Override
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.