Permalink
Browse files

project import

  • Loading branch information...
0 parents commit 8d0e61b342d211ac1a97485f50ff9816ba73864c @zapnap committed Jul 18, 2011
@@ -0,0 +1,2 @@
+bin
+gen
@@ -0,0 +1,19 @@
+<?xml version="1.0" encoding="utf-8"?>
+<manifest xmlns:android="http://schemas.android.com/apk/res/android"
+ package="org.zerosum.upordown"
+ android:versionCode="1"
+ android:versionName="1.0">
+ <application android:label="@string/app_name"
+ android:debuggable="true"
+ android:icon="@drawable/ic_launcher">
+
+ <activity android:name="StatusActivity"
+ 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>
+ <uses-permission android:name="android.permission.INTERNET" />
+</manifest>
@@ -0,0 +1,20 @@
+Copyright (c) 2011 Nick Plante
+
+Permission is hereby granted, free of charge, to any person obtaining
+a copy of this software and associated documentation files (the
+"Software"), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sublicense, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice shall be
+included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,25 @@
+# Up or Down?
+
+A super-simple sample Android application that uses
+http://downforeveryoneorjustme.com to test whether or not a website is
+online.
+
+This app is written in Mirah using the Pindah build tool. It
+demonstrates the following:
+
+* Basic Mirah syntax for use with Pindah
+* How to use blocks and Android callbacks with Mirah
+* How to leverage third-party Java libraries in Mirah (jsoup)
+* How to handle exceptions in Mirah
+* How to deal with Mirah scoping weirdness (this = self)
+
+## Homework Ideas
+
+* Add a ProgressDialog and make the site test an AsyncTask
+* Record a log of website test history to a ListView
+* Allow users to browse test history through a separate activity
+* Store test history in a local Sqlite database (ListAdapter)
+
+## Credits
+
+Copyright (c) 2011 Nick Plante. See LICENSE.txt for further details.
@@ -0,0 +1,7 @@
+require "rubygems"
+require "pindah"
+
+Pindah.spec = {
+ :name => "upordown",
+ :target_version => "2.1"
+}
Binary file not shown.
Binary file not shown.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@@ -0,0 +1,46 @@
+<?xml version="1.0" encoding="utf-8"?>
+<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
+ android:orientation="vertical"
+ android:layout_width="fill_parent"
+ android:layout_height="fill_parent">
+ <LinearLayout
+ android:orientation="vertical"
+ android:layout_width="fill_parent"
+ android:layout_height="wrap_content">
+ <TextView
+ android:layout_width="fill_parent"
+ android:layout_height="wrap_content"
+ android:gravity="center_horizontal"
+ android:textSize="20sp"
+ android:textStyle="bold"
+ android:text="@string/app_title" />
+ <TextView
+ android:layout_width="fill_parent"
+ android:layout_height="wrap_content"
+ android:gravity="center_horizontal"
+ android:textSize="18sp"
+ android:textStyle="bold"
+ android:layout_marginBottom="10dip"
+ android:text="@string/app_subtitle" />
+ <EditText android:id="@+id/url_txt"
+ android:layout_width="fill_parent"
+ android:singleLine = "true"
+ android:layout_height="wrap_content"
+ android:inputType="textUri"
+ android:hint="@string/url_example" />
+ <Button android:id="@+id/submit_btn"
+ android:layout_width="140dip"
+ android:layout_marginTop="6dip"
+ android:layout_height="wrap_content"
+ android:layout_gravity="center"
+ android:gravity="center"
+ android:text="@string/submit_btn" />
+ </LinearLayout>
+ <TextView
+ android:layout_width="fill_parent"
+ android:layout_height="wrap_content"
+ android:gravity="center_horizontal"
+ android:layout_alignParentBottom="true"
+ android:autoLink="web"
+ android:text="@string/powered_by" />
+</RelativeLayout>
@@ -0,0 +1,9 @@
+<?xml version="1.0" encoding="utf-8"?>
+<resources>
+ <string name="app_name">Up or Down?</string>
+ <string name="app_title">Is this site down for everyone?</string>
+ <string name="app_subtitle">( or just me? )</string>
+ <string name="url_example">tumblr.com</string>
+ <string name="submit_btn">Test It!</string>
+ <string name="powered_by">Visit http://DownForEveryoneOrJustMe.com</string>
+</resources>
@@ -0,0 +1,67 @@
+package org.zerosum.upordown
+
+import android.app.Activity
+import android.app.Dialog
+import android.app.AlertDialog
+import android.content.Context
+import android.util.Log
+import android.view.View
+import android.widget.EditText
+import android.widget.Button
+
+import java.net.URL
+import java.net.SocketTimeoutException
+
+import org.jsoup.Jsoup
+import org.jsoup.nodes.Document
+
+class StatusActivity < Activity
+ def onCreate(state)
+ super state
+ setContentView R.layout.main
+
+ Log.d 'StatusActivity', 'init'
+ @url = EditText findViewById(R.id.url_txt)
+ @submit = Button findViewById(R.id.submit_btn)
+
+ setListeners
+ end
+
+ def getUrl
+ @url.getText.toString
+ end
+
+ def setListeners
+ this = self
+ @submit.setOnClickListener do |v|
+ Log.d 'StatusActivity', 'click'
+ status = this.checkSiteStatus(this.getUrl)
+ this.showResult status
+ end
+ end
+
+ def showResult(message:String)
+ alert = AlertDialog.Builder.new(self)
+ alert.setTitle 'Site Test Results'
+ alert.setMessage message
+ alert.setPositiveButton('OK') do |dialog, which|
+ dialog.dismiss
+ end
+
+ alert.show
+ end
+
+ def checkSiteStatus(address:String):String
+ return "Please specify a URL to test" if address.equals('')
+
+ begin
+ doc = Jsoup.connect("http://downforeveryoneorjustme.com/" + address).get
+ res = doc.select("#container").first.text
+
+ Log.d 'StatusActivity', 'Full response from server is: ' + res
+ res.substring(0, res.indexOf('Check another'))
+ rescue SocketTimeoutException => ex
+ "Unable to contact the server. How ironic!"
+ end
+ end
+end

0 comments on commit 8d0e61b

Please sign in to comment.