Skip to content

Commit

Permalink
project import
Browse files Browse the repository at this point in the history
  • Loading branch information
zapnap committed Jul 18, 2011
0 parents commit 8d0e61b
Show file tree
Hide file tree
Showing 13 changed files with 195 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
bin
gen
19 changes: 19 additions & 0 deletions AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -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>
20 changes: 20 additions & 0 deletions LICENSE.txt
Original file line number Diff line number Diff line change
@@ -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.
25 changes: 25 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -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.
7 changes: 7 additions & 0 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
require "rubygems"
require "pindah"

Pindah.spec = {
:name => "upordown",
:target_version => "2.1"
}
Binary file added jars/jsoup-1.6.1.jar
Binary file not shown.
Binary file added libs/jsoup-1.6.1.jar
Binary file not shown.
Binary file added res/drawable-hdpi/ic_launcher.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added res/drawable-ldpi/ic_launcher.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added res/drawable-mdpi/ic_launcher.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
46 changes: 46 additions & 0 deletions res/layout/main.xml
Original file line number Diff line number Diff line change
@@ -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>
9 changes: 9 additions & 0 deletions res/values/strings.xml
Original file line number Diff line number Diff line change
@@ -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>
67 changes: 67 additions & 0 deletions src/org/zerosum/upordown/StatusActivity.mirah
Original file line number Diff line number Diff line change
@@ -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.