This repository has been archived by the owner. It is now read-only.
Permalink
Browse files

Initial commit.

  • Loading branch information...
technomancy committed Dec 28, 2010
0 parents commit 7b025bfc51a00e91ddf9c9de25a1487892754567
@@ -0,0 +1,2 @@
+local.properties
+bin
@@ -0,0 +1,19 @@
+<?xml version="1.0" encoding="utf-8"?>
+<manifest xmlns:android="http://schemas.android.com/apk/res/android"
+ package="griva.della.ferrante"
+ android:versionCode="1"
+ android:versionName="1.0">
+ <uses-permission android:name="android.permission.INTERNET" />
+ <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
+ <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
+ <uses-permission android:name="android.permission.INTERNET" />
+ <application android:label="@string/app_name" android:icon="@drawable/icon">
+ <activity android:name="Start"
+ android:label="@string/app_name">
+ <intent-filter>
+ <action android:name="android.intent.action.MAIN" />
+ <category android:name="android.intent.category.LAUNCHER" />
+ </intent-filter>
+ </activity>
+ </application>
+</manifest>
@@ -0,0 +1,38 @@
+import android.app.Service
+import android.util.Log
+
+import android.hardware.SensorListener
+import android.hardware.SensorManager
+
+class Locator < Activity
+ @tag = "Locator"
+ def onCreate(state)
+ super(state)
+ @sensors = SensorManager(getSystemService(Context.SENSOR_SERVICE))
+ # @listener = LocationListener.new
+ # setContentView(CompassView.new(self))
+ end
+
+ def onResume
+ Log.d(@tag, "Resumed")
+ super()
+ # @sensors.registerListener(@listener,
+ # SensorManager.SENSOR_ORIENTATION,
+ # SensorManager.SENSOR_DELAY_GAME)
+ end
+
+ def onStop
+ Log.d(@tag, "Stopped")
+ super()
+ # @sensors.unregisterListener(@listener)
+ end
+end
+
+# class CompassListener
+# implements SensorListener
+
+# def onSensorChanged(sensor, values)
+# @values = values
+# @view.invalidate
+# end
+# end
@@ -0,0 +1,65 @@
+import android.app.Activity
+import android.content.Context
+import android.util.Log
+
+import android.view.View
+import android.graphics.Canvas
+import android.graphics.Color
+import android.graphics.Paint
+import android.graphics.Path
+
+import android.hardware.SensorListener
+import android.hardware.SensorManager
+
+class Navigate < Activity
+ @tag = "Navigate"
+ def onCreate(state)
+ super(state)
+ @sensors = SensorManager(getSystemService(Context.SENSOR_SERVICE))
+ @listener = CompassListener.new
+ setContentView(CompassView.new(self))
+ end
+
+ def onResume
+ Log.d(@tag, "Resumed")
+ super()
+ @sensors.registerListener(@listener,
+ SensorManager.SENSOR_ORIENTATION,
+ SensorManager.SENSOR_DELAY_GAME)
+ end
+
+ def onStop
+ Log.d(@tag, "Stopped")
+ super()
+ @sensors.unregisterListener(@listener)
+ end
+end
+
+class CompassListener
+ implements SensorListener
+
+ def onSensorChanged(sensor, values)
+ @values = values
+ @view.invalidate
+ end
+end
+
+class CompassView < View
+ def initialize(context:Context)
+ super(context)
+ @paint = Paint.new(Paint.ANTI_ALIAS_FLAG)
+ @paint.setColor(Color.WHITE)
+
+ @path = Path.new
+ @path.moveTo(0, -30)
+ @path.lineTo(-15, 45)
+ @path.lineTo(15, 45)
+ @path.close
+ end
+
+ def onDraw(canvas)
+ canvas.drawColor(Color.BLACK)
+ canvas.translate(canvas.getWidth / 2, canvas.getHeight / 2)
+ canvas.drawPath(@path, @paint)
+ end
+end
@@ -0,0 +1,17 @@
+# This file is used to override default values used by the Ant build system.
+#
+# This file must be checked in Version Control Systems, as it is
+# integral to the build system of your project.
+
+# This file is only used by the Ant script.
+
+# You can use this to override default values such as
+# 'source.dir' for the location of your java source folder and
+# 'out.dir' for the location of your output folder.
+
+# You can also use it define how the release builds are signed by declaring
+# the following properties:
+# 'key.store' for the location of your keystore and
+# 'key.alias' for the name of the key to use.
+# The password will be asked during the build when you use the 'release' target.
+
@@ -0,0 +1,95 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project name="Ferrante" default="help">
+
+<!-- The local.properties file is created and updated by the 'android'
+ tool.
+ It contains the path to the SDK. It should *NOT* be checked into
+ Version Control Systems. -->
+ <property file="local.properties" />
+
+ <!-- The build.properties file can be created by you and is never touched
+ by the 'android' tool. This is the place to change some of the
+ default property values used by the Ant rules.
+ Here are some properties you may want to change/update:
+
+ source.dir
+ The name of the source directory. Default is 'src'.
+ out.dir
+ The name of the output directory. Default is 'bin'.
+
+ Properties related to the SDK location or the project target should
+ be updated using the 'android' tool with the 'update' action.
+
+ This file is an integral part of the build system for your
+ application and should be checked into Version Control Systems.
+
+ -->
+ <property file="build.properties" />
+
+ <!-- The default.properties file is created and updated by the 'android'
+ tool, as well as ADT.
+ This file is an integral part of the build system for your
+ application and should be checked into Version Control Systems. -->
+ <property file="default.properties" />
+
+ <!-- Custom Android task to deal with the project target, and import the
+ proper rules.
+ This requires ant 1.6.0 or above. -->
+ <path id="android.antlibs">
+ <pathelement path="${sdk.dir}/tools/lib/anttasks.jar" />
+ <pathelement path="${sdk.dir}/tools/lib/sdklib.jar" />
+ <pathelement path="${sdk.dir}/tools/lib/androidprefs.jar" />
+ </path>
+
+ <taskdef name="setup"
+ classname="com.android.ant.SetupTask"
+ classpathref="android.antlibs" />
+
+<!-- extension targets. Uncomment the ones where you want to do custom work
+ in between standard targets -->
+<!--
+ <target name="-pre-build">
+ </target>
+ <target name="-pre-compile">
+ </target>
+
+ [This is typically used for code obfuscation.
+ Compiled code location: ${out.classes.absolute.dir}
+ If this is not done in place, override ${out.dex.input.absolute.dir}]
+ <target name="-post-compile">
+ </target>
+-->
+
+
+ <!-- Execute the Android Setup task that will setup some properties
+ specific to the target, and import the build rules files. -->
+
+ <target name="compile" depends="-resource-src, -aidl"
+ description="Compiles project's .mirah files into .class files">
+ <exec executable="mirahc" dir="src">
+ <arg line="-c ${sdk.dir}/platforms/${target-version}/android.jar:gen/" />
+ <arg value="-d" />
+ <arg value="../bin/classes/" />
+ <arg value="." />
+ </exec>
+ </target>
+
+ <!--
+ The rules file is imported from
+ <SDK>/platforms/<target_platform>/ant/ant_rules_r#.xml
+
+ To customize existing targets, there are two options:
+ - Customize only one target:
+ - copy/paste the target into this file, *before* the
+ <setup> task.
+ - customize it to your needs.
+ - Customize the whole script.
+ - copy/paste the content of the rules files (minus the top node)
+ into this file, *after* the <setup> task
+ - disable the import of the rules by changing the setup task
+ below to <setup import="false" />.
+ - customize to your needs.
+ -->
+ <setup />
+
+</project>
@@ -0,0 +1,12 @@
+# 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,
+# "build.properties", and override values to adapt the script to your
+# project structure.
+
+# Project target.
+target=android-8
+target-version=android-8
@@ -0,0 +1,22 @@
+/* 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 griva.della.ferrante;
+
+public final class R {
+ public static final class attr {
+ }
+ public static final class drawable {
+ public static final int icon=0x7f020000;
+ }
+ public static final class layout {
+ public static final int main=0x7f030000;
+ }
+ public static final class string {
+ public static final int app_name=0x7f040000;
+ }
+}
@@ -0,0 +1,10 @@
+# This file is automatically generated by Android Tools.
+# Do not modify this file -- YOUR CHANGES WILL BE ERASED!
+#
+# This file must *NOT* be checked in Version Control Systems,
+# as it contains information specific to your local configuration.
+
+# location of the SDK. This is only used by Ant
+# For customization when using a Version Control System, please read the
+# header note.
+sdk.dir=/home/phil/src/android/sdk
@@ -0,0 +1,13 @@
+<?xml version="1.0" encoding="utf-8"?>
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+ android:orientation="vertical"
+ android:layout_width="fill_parent"
+ android:layout_height="fill_parent"
+ >
+<TextView
+ android:layout_width="fill_parent"
+ android:layout_height="wrap_content"
+ android:text="Hello Ferrante"
+ />
+</LinearLayout>
+
@@ -0,0 +1,4 @@
+<?xml version="1.0" encoding="utf-8"?>
+<resources>
+ <string name="app_name">Ferrante</string>
+</resources>
@@ -0,0 +1,90 @@
+import android.app.Activity
+import android.util.Log
+
+import android.net.http.AndroidHttpClient
+import org.apache.http.client.methods.HttpPost
+import org.apache.http.HttpResponse
+import org.json.JSONObject
+
+import java.io.InputStreamReader
+import java.io.BufferedReader
+import java.util.concurrent.Executors
+import java.util.concurrent.TimeUnit
+
+import android.widget.Button
+import android.widget.LinearLayout
+import android.widget.EditText
+import android.view.View
+
+
+class Start < Activity
+ # USER_AGENT = "Ferrante (http://github.com/technomancy/ferrante)"
+ # TAG = "Ferrante/Start"
+
+ def onCreate(state)
+ super state
+ @outer = LinearLayout.new(self).setOrientation(LinearLayout.VERTICAL)
+ @exec = Executors.newSingleThreadExecutor
+ this = self
+ @start_button = add_button("Start")
+ @start_button.setMinimumHeight(100)
+ @start_button.setOnClickListener {|v| this.start }
+
+ setContentView(@outer)
+ end
+
+ def start
+ @start_button.setText("Starting...")
+ @start_button.setEnabled(false)
+ Log.i("Ferrante", "Clicked Start")
+ client = AndroidHttpClient.newInstance("Ferrante")
+
+ future = @exec.submit {client.execute(HttpPost.new("http://p.hagelb.org/start"))}
+
+ begin
+ wait_for_follower(future.get(5, TimeUnit.SECONDS))
+ rescue => e
+ Log.w("Ferrante", "Couldn't start.")
+ end
+ end
+
+ def wait_for_follower(response:HttpResponse)
+ Log.i("Ferrante", "waiting")
+ this = self
+ stream = response.getEntity.getContent
+ payload = BufferedReader.new(InputStreamReader.new(stream, "UTF-8")).readLine
+ link = JSONObject.new(payload).getString("link")
+ show_link(link)
+ add_button("Copy").setOnClickListener {|v| this.copy }
+ add_button("Cancel").setOnClickListener {|v| this.cancel }
+ poll(link)
+ end
+
+ def show_link(link:String)
+ @link_text = EditText.new self
+ @link_text.setText link
+ @outer.addView @link_text
+ end
+
+ def add_button(text:String)
+ button = Button.new self
+ button.setText text
+ @outer.addView button
+ button
+ end
+
+ def poll(link:String)
+ @start_button.setText("Waiting for follower...")
+ end
+
+ def copy
+ end
+
+ def cancel
+ end
+
+ def onDestroy
+ @exec.shutdownNow
+ super
+ end
+end
Oops, something went wrong.

0 comments on commit 7b025bf

Please sign in to comment.