Permalink
Browse files

initial commit

  • Loading branch information...
0 parents commit f8ccc70e4285f2948bbe0288f84428b5aa0fca21 @svenefftinge committed Dec 13, 2011
1 .gitignore
@@ -0,0 +1 @@
+bin
2 README
@@ -0,0 +1,2 @@
+Tiny project illustrating how to use Xtend for Android development.
+See also http://blog.efftinge.de/2011/12/writing-android-uis-with-xtend.html
10 my.android.app/.classpath
@@ -0,0 +1,10 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+ <classpathentry kind="src" path="src"/>
+ <classpathentry kind="src" path="gen"/>
+ <classpathentry kind="con" path="com.android.ide.eclipse.adt.ANDROID_FRAMEWORK"/>
+ <classpathentry kind="con" path="com.android.ide.eclipse.adt.LIBRARIES"/>
+ <classpathentry kind="lib" path="org.eclipse.xtend2.lib-2.2.0.jar"/>
+ <classpathentry kind="lib" path="guava-10.0.1.jar"/>
+ <classpathentry kind="output" path="bin/classes"/>
+</classpath>
39 my.android.app/.project
@@ -0,0 +1,39 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+ <name>my.android.app</name>
+ <comment></comment>
+ <projects>
+ </projects>
+ <buildSpec>
+ <buildCommand>
+ <name>com.android.ide.eclipse.adt.ResourceManagerBuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>com.android.ide.eclipse.adt.PreCompilerBuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.eclipse.jdt.core.javabuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>com.android.ide.eclipse.adt.ApkBuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.eclipse.xtext.ui.shared.xtextBuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ </buildSpec>
+ <natures>
+ <nature>com.android.ide.eclipse.adt.AndroidNature</nature>
+ <nature>org.eclipse.jdt.core.javanature</nature>
+ <nature>org.eclipse.xtext.ui.shared.xtextNature</nature>
+ </natures>
+</projectDescription>
10 my.android.app/.settings/org.eclipse.xtext.xtend2.Xtend2.prefs
@@ -0,0 +1,10 @@
+#Mon Dec 12 13:11:43 CET 2011
+autobuilding=true
+eclipse.preferences.version=1
+is_project_specific=true
+outlet.DEFAULT_OUTPUT.cleanDirectory=false
+outlet.DEFAULT_OUTPUT.cleanupDerived=true
+outlet.DEFAULT_OUTPUT.createDirectory=true
+outlet.DEFAULT_OUTPUT.derived=true
+outlet.DEFAULT_OUTPUT.directory=gen
+outlet.DEFAULT_OUTPUT.override=true
23 my.android.app/AndroidManifest.xml
@@ -0,0 +1,23 @@
+<?xml version="1.0" encoding="utf-8"?>
+<manifest xmlns:android="http://schemas.android.com/apk/res/android"
+ package="my.android.app"
+ android:versionCode="1"
+ android:versionName="1.0" >
+
+ <uses-sdk android:minSdkVersion="14" />
+
+ <application
+ android:icon="@drawable/ic_launcher"
+ android:label="@string/app_name" >
+ <activity
+ android:label="@string/app_name"
+ android:name="my.android.AppActivity" >
+ <intent-filter >
+ <action android:name="android.intent.action.MAIN" />
+
+ <category android:name="android.intent.category.LAUNCHER" />
+ </intent-filter>
+ </activity>
+ </application>
+
+</manifest>
47 my.android.app/gen/my/android/AppActivity.java
@@ -0,0 +1,47 @@
+package my.android;
+
+import android.app.Activity;
+import android.os.Bundle;
+import android.view.View;
+import android.view.View.OnClickListener;
+import android.widget.Button;
+import android.widget.LinearLayout;
+import android.widget.TextView;
+import android.widget.Toast;
+import my.android.UiBuilder;
+import org.eclipse.xtext.xbase.lib.Procedures.Procedure1;
+
+@SuppressWarnings("all")
+public class AppActivity extends Activity {
+ public void onCreate(final Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ final Procedure1<LinearLayout> _function = new Procedure1<LinearLayout>() {
+ public void apply(final LinearLayout it) {
+ {
+ it.setOrientation(LinearLayout.VERTICAL);
+ TextView _textView = UiBuilder.textView(AppActivity.this, "Hello Android!");
+ UiBuilder.setView(it, _textView);
+ final Procedure1<Button> _function = new Procedure1<Button>() {
+ public void apply(final Button it) {
+ final Procedure1<View> _function = new Procedure1<View>() {
+ public void apply(final View it) {
+ Toast _textMessage = UiBuilder.textMessage(AppActivity.this, "Hello you clicked me!");
+ _textMessage.show();
+ }
+ };
+ it.setOnClickListener(new OnClickListener() {
+ public void onClick(View arg0) {
+ _function.apply(arg0);
+ }
+ });
+ }
+ };
+ Button _button = UiBuilder.button(AppActivity.this, "Click Me!", _function);
+ UiBuilder.setView(it, _button);
+ }
+ }
+ };
+ LinearLayout _linearLayout = UiBuilder.linearLayout(this, _function);
+ this.setContentView(_linearLayout);
+ }
+}
44 my.android.app/gen/my/android/UiBuilder.java
@@ -0,0 +1,44 @@
+package my.android;
+
+import android.content.Context;
+import android.view.View;
+import android.view.ViewGroup;
+import android.widget.Button;
+import android.widget.LinearLayout;
+import android.widget.TextView;
+import android.widget.Toast;
+import org.eclipse.xtext.xbase.lib.Procedures.Procedure1;
+
+@SuppressWarnings("all")
+public class UiBuilder {
+ public static LinearLayout linearLayout(final Context context, final Procedure1<? super LinearLayout> initializer) {
+ LinearLayout _linearLayout = new LinearLayout(context);
+ final LinearLayout layout = _linearLayout;
+ initializer.apply(layout);
+ return layout;
+ }
+
+ public static TextView textView(final Context context, final String text) {
+ TextView _textView = new TextView(context);
+ final TextView result = _textView;
+ result.setText(text);
+ return result;
+ }
+
+ public static void setView(final ViewGroup group, final View view) {
+ group.addView(view);
+ }
+
+ public static Button button(final Context context, final String text, final Procedure1<? super Button> initializer) {
+ Button _button = new Button(context);
+ final Button result = _button;
+ result.setText(text);
+ initializer.apply(result);
+ return result;
+ }
+
+ public static Toast textMessage(final Context context, final String text) {
+ Toast _makeText = Toast.makeText(context, text, Toast.LENGTH_SHORT);
+ return _makeText;
+ }
+}
23 my.android.app/gen/my/android/app/R.java
@@ -0,0 +1,23 @@
+/* AUTO-GENERATED FILE. DO NOT MODIFY.
+ *
+ * This class was automatically generated by the
+ * aapt tool from the resource data it found. It
+ * should not be modified by hand.
+ */
+
+package my.android.app;
+
+public final class R {
+ public static final class attr {
+ }
+ public static final class drawable {
+ public static final int ic_launcher=0x7f020000;
+ }
+ public static final class layout {
+ public static final int main=0x7f030000;
+ }
+ public static final class string {
+ public static final int app_name=0x7f040001;
+ public static final int hello=0x7f040000;
+ }
+}
BIN my.android.app/guava-10.0.1.jar
Binary file not shown.
BIN my.android.app/org.eclipse.xtend2.lib-2.2.0.jar
Binary file not shown.
40 my.android.app/proguard.cfg
@@ -0,0 +1,40 @@
+-optimizationpasses 5
+-dontusemixedcaseclassnames
+-dontskipnonpubliclibraryclasses
+-dontpreverify
+-verbose
+-optimizations !code/simplification/arithmetic,!field/*,!class/merging/*
+
+-keep public class * extends android.app.Activity
+-keep public class * extends android.app.Application
+-keep public class * extends android.app.Service
+-keep public class * extends android.content.BroadcastReceiver
+-keep public class * extends android.content.ContentProvider
+-keep public class * extends android.app.backup.BackupAgentHelper
+-keep public class * extends android.preference.Preference
+-keep public class com.android.vending.licensing.ILicensingService
+
+-keepclasseswithmembernames class * {
+ native <methods>;
+}
+
+-keepclasseswithmembers class * {
+ public <init>(android.content.Context, android.util.AttributeSet);
+}
+
+-keepclasseswithmembers class * {
+ public <init>(android.content.Context, android.util.AttributeSet, int);
+}
+
+-keepclassmembers class * extends android.app.Activity {
+ public void *(android.view.View);
+}
+
+-keepclassmembers enum * {
+ public static **[] values();
+ public static ** valueOf(java.lang.String);
+}
+
+-keep class * implements android.os.Parcelable {
+ public static final android.os.Parcelable$Creator *;
+}
11 my.android.app/project.properties
@@ -0,0 +1,11 @@
+# This file is automatically generated by Android Tools.
+# Do not modify this file -- YOUR CHANGES WILL BE ERASED!
+#
+# This file must be checked in Version Control Systems.
+#
+# To customize properties used by the Ant build system use,
+# "ant.properties", and override values to adapt the script to your
+# project structure.
+
+# Project target.
+target=android-14
BIN my.android.app/res/drawable-hdpi/ic_launcher.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
BIN my.android.app/res/drawable-ldpi/ic_launcher.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
BIN my.android.app/res/drawable-mdpi/ic_launcher.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
12 my.android.app/res/layout/main.xml
@@ -0,0 +1,12 @@
+<?xml version="1.0" encoding="utf-8"?>
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+ android:layout_width="fill_parent"
+ android:layout_height="fill_parent"
+ android:orientation="vertical" >
+
+ <TextView
+ android:layout_width="fill_parent"
+ android:layout_height="wrap_content"
+ android:text="@string/hello" />
+
+</LinearLayout>
7 my.android.app/res/values/strings.xml
@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="utf-8"?>
+<resources>
+
+ <string name="hello">Hello World, AppActivity!</string>
+ <string name="app_name">My.android.app</string>
+
+</resources>
28 my.android.app/src/my/android/AppActivity.xtend
@@ -0,0 +1,28 @@
+package my.android
+
+import android.app.Activity
+import android.os.Bundle
+
+import static android.widget.LinearLayout.*
+import static extension my.android.UiBuilder.*
+
+class AppActivity extends Activity {
+
+ override void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+
+ contentView = this.linearLayout [
+
+ orientation = VERTICAL
+
+ view = this.textView ("Hello Android!")
+
+ view = this.button ("Click Me!") [
+ onClickListener = [
+ this.textMessage('Hello you clicked me!').show
+ ]
+ ]
+ ]
+ }
+
+}
39 my.android.app/src/my/android/UiBuilder.xtend
@@ -0,0 +1,39 @@
+package my.android
+
+import android.content.Context
+import android.widget.LinearLayout
+import android.widget.TextView
+import android.view.ViewGroup
+import android.view.View
+import android.widget.Button
+import android.widget.Toast
+
+class UiBuilder {
+
+ def static linearLayout(Context context, (LinearLayout)=>void initializer) {
+ val layout = new LinearLayout(context)
+ initializer.apply(layout)
+ return layout
+ }
+
+ def static textView(Context context, String text) {
+ val result = new TextView(context)
+ result.text = text
+ return result
+ }
+
+ def static setView(ViewGroup group, View view) {
+ group.addView(view)
+ }
+
+ def static button(Context context, String text, (Button)=>void initializer) {
+ val result = new Button(context)
+ result.text = text
+ initializer.apply(result)
+ return result
+ }
+
+ def static textMessage(Context context, String text) {
+ Toast::makeText(context, text, Toast::LENGTH_SHORT)
+ }
+}

0 comments on commit f8ccc70

Please sign in to comment.