Brion VIBBER has submitted this change and it was merged.

Change subject: Initial commit
......................................................................


Initial commit

Has an initial cut of the Safe AsyncTask replacement that
also does proper exception surfacing. Couple of tests included.

Also contains a stub main activity.

mvn test does not run any of the tests yet. Need to be run from
an IDE specifically.

Change-Id: Ibc74b5bf2410e99991e4189b3c0b16e5f12df959
---
A pom.xml
A wikipedia-it/AndroidManifest.xml
A wikipedia-it/pom.xml
A wikipedia-it/res/drawable-hdpi/icon.png
A wikipedia-it/res/drawable-ldpi/icon.png
A wikipedia-it/res/drawable-mdpi/icon.png
A wikipedia-it/res/layout/main.xml
A wikipedia-it/res/values/strings.xml
A 
wikipedia-it/src/main/java/org/wikimedia/wikipedia/test/concurrency/AsyncTaskTest.java
A wikipedia/AndroidManifest.xml
A wikipedia/pom.xml
A wikipedia/res/drawable-hdpi/ic_launcher.png
A wikipedia/res/drawable-mdpi/ic_launcher.png
A wikipedia/res/drawable-xhdpi/ic_launcher.png
A wikipedia/res/drawable-xxhdpi/ic_launcher.png
A wikipedia/res/layout/activity_main.xml
A wikipedia/res/menu/main.xml
A wikipedia/res/values-sw600dp/dimens.xml
A wikipedia/res/values-sw720dp-land/dimens.xml
A wikipedia/res/values-v11/styles.xml
A wikipedia/res/values-v14/styles.xml
A wikipedia/res/values/dimens.xml
A wikipedia/res/values/strings.xml
A wikipedia/res/values/styles.xml
A wikipedia/src/main/java/org/wikimedia/wikipedia/HelloAndroidActivity.java
A 
wikipedia/src/main/java/org/wikimedia/wikipedia/concurrency/ExceptionHandlingAsyncTask.java
26 files changed, 562 insertions(+), 0 deletions(-)

Approvals:
  Brion VIBBER: Verified; Looks good to me, approved



diff --git a/pom.xml b/pom.xml
new file mode 100644
index 0000000..cab5152
--- /dev/null
+++ b/pom.xml
@@ -0,0 +1,82 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0"; 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
+       xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 
http://maven.apache.org/maven-v4_0_0.xsd";>
+       <modelVersion>4.0.0</modelVersion>
+       <groupId>org.wikimedia</groupId>
+       <artifactId>wikipedia-parent</artifactId>
+       <version>1.0-SNAPSHOT</version>
+       <packaging>pom</packaging>
+       <name>wikipedia - Parent</name>
+
+       <modules>
+               <module>wikipedia</module>
+               <module>wikipedia-it</module>
+       </modules>
+
+       <properties>
+               <platform.version>4.1.1.4</platform.version>
+               <android.plugin.version>3.7.0</android.plugin.version>
+       </properties>
+
+       <dependencyManagement>
+               <dependencies>
+                       <dependency>
+                               <groupId>com.google.android</groupId>
+                               <artifactId>android</artifactId>
+                               <version>${platform.version}</version>
+                               <scope>provided</scope>
+                       </dependency>
+                       <dependency>
+                               <groupId>com.google.android</groupId>
+                               <artifactId>android-test</artifactId>
+                               <version>${platform.version}</version>
+                               <scope>provided</scope>
+                       </dependency>
+                       <dependency>
+                               <groupId>junit</groupId>
+                               <artifactId>junit</artifactId>
+                               <version>4.11</version>
+                               <scope>provided</scope>
+                       </dependency>
+            <dependency>
+                <groupId>com.android.support</groupId>
+                <artifactId>support-v4</artifactId>
+                <version>18.0.0</version>
+            </dependency>
+            <dependency>
+                <groupId>com.android.support</groupId>
+                <artifactId>appcompat-v7</artifactId>
+                <version>18.0.0</version>
+                <type>aar</type>
+            </dependency>
+               </dependencies>
+       </dependencyManagement>
+
+    <repositories>
+        <repository>
+            <id>android-support-repository</id>
+            <url>file:///${env.ANDROID_HOME}/extras/android/m2repository/</url>
+        </repository>
+    </repositories>
+
+    <build>
+               <pluginManagement>
+                       <plugins>
+                               <plugin>
+                                       
<groupId>com.jayway.maven.plugins.android.generation2</groupId>
+                                       
<artifactId>android-maven-plugin</artifactId>
+                                       
<version>${android.plugin.version}</version>
+                                       <configuration>
+                                               <sdk>
+                                                       <platform>16</platform>
+                                               </sdk>
+                                                                               
        </configuration>
+                               </plugin>
+                               <plugin>
+                                       
<artifactId>maven-compiler-plugin</artifactId>
+                                       <version>3.1</version>
+                               </plugin>
+                       </plugins>
+               </pluginManagement>
+       </build>
+</project>
diff --git a/wikipedia-it/AndroidManifest.xml b/wikipedia-it/AndroidManifest.xml
new file mode 100644
index 0000000..55499a5
--- /dev/null
+++ b/wikipedia-it/AndroidManifest.xml
@@ -0,0 +1,12 @@
+<?xml version="1.0" encoding="utf-8"?>
+<manifest xmlns:android="http://schemas.android.com/apk/res/android";
+  package="org.wikimedia.wikipedia.test" android:versionCode="1" 
android:versionName="1.0-SNAPSHOT">
+
+  <application android:icon="@drawable/icon" android:label="@string/app_name">
+    <uses-library android:name="android.test.runner" />
+  </application>
+
+  <instrumentation android:targetPackage="org.wikimedia.wikipedia"
+    android:name="android.test.InstrumentationTestRunner" />
+
+</manifest>
diff --git a/wikipedia-it/pom.xml b/wikipedia-it/pom.xml
new file mode 100644
index 0000000..8876928
--- /dev/null
+++ b/wikipedia-it/pom.xml
@@ -0,0 +1,69 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0"; 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
+       xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 
http://maven.apache.org/maven-v4_0_0.xsd";>
+       <modelVersion>4.0.0</modelVersion>
+
+       <parent>
+               <groupId>org.wikimedia</groupId>
+               <artifactId>wikipedia-parent</artifactId>
+               <version>1.0-SNAPSHOT</version>
+       </parent>
+
+       <groupId>org.wikimedia</groupId>
+       <artifactId>wikipedia-it</artifactId>
+       <version>1.0-SNAPSHOT</version>
+       <packaging>apk</packaging>
+       <name>wikipedia-it - Integration tests</name>
+
+       <dependencies>
+               <dependency>
+                       <groupId>com.google.android</groupId>
+                       <artifactId>android-test</artifactId>
+                       <scope>provided</scope>
+               </dependency>
+               <dependency>
+                       <groupId>org.wikimedia</groupId>
+                       <artifactId>wikipedia</artifactId>
+                       <type>apk</type>
+                       <version>1.0-SNAPSHOT</version>
+                       <scope>provided</scope>
+               </dependency>
+               <dependency>
+                       <groupId>org.wikimedia</groupId>
+                       <artifactId>wikipedia</artifactId>
+                       <type>jar</type>
+                       <version>1.0-SNAPSHOT</version>
+                       <scope>provided</scope>
+               </dependency>
+       </dependencies>
+
+       <build>
+               <finalName>${project.artifactId}</finalName>
+               <plugins>
+                       <plugin>
+                               
<groupId>com.jayway.maven.plugins.android.generation2</groupId>
+                               <artifactId>android-maven-plugin</artifactId>
+                               <configuration>
+                                       <test>
+                                               
<!--<skip>true|false|auto</skip> -->
+                                               
<!--<instrumentationPackage>packageName</instrumentationPackage> -->
+                                               `
+                                               
<!--<instrumentationRunner>className</instrumentationRunner> -->
+                                               <!--<debug>true|false</debug> 
-->
+                                               
<!--<coverage>true|false</coverage> -->
+                                               
<!--<logonly>true|false</logonly> avd -->
+                                               
<!--<testsize>small|medium|large</testsize> -->
+                                               
<createReport>true</createReport>
+                                               <!--<classes> -->
+                                               
<!--<class>your.package.name.YourTestClass</class> -->
+                                               <!--</classes> -->
+                                               <!--<packages> -->
+                                               
<!--<package>your.package.name</package> -->
+                                               <!--</packages> -->
+                                       </test>
+                               </configuration>
+                               <extensions>true</extensions>
+                       </plugin>
+               </plugins>
+       </build>
+</project>
diff --git a/wikipedia-it/res/drawable-hdpi/icon.png 
b/wikipedia-it/res/drawable-hdpi/icon.png
new file mode 100644
index 0000000..8074c4c
--- /dev/null
+++ b/wikipedia-it/res/drawable-hdpi/icon.png
Binary files differ
diff --git a/wikipedia-it/res/drawable-ldpi/icon.png 
b/wikipedia-it/res/drawable-ldpi/icon.png
new file mode 100644
index 0000000..1095584
--- /dev/null
+++ b/wikipedia-it/res/drawable-ldpi/icon.png
Binary files differ
diff --git a/wikipedia-it/res/drawable-mdpi/icon.png 
b/wikipedia-it/res/drawable-mdpi/icon.png
new file mode 100644
index 0000000..a07c69f
--- /dev/null
+++ b/wikipedia-it/res/drawable-mdpi/icon.png
Binary files differ
diff --git a/wikipedia-it/res/layout/main.xml b/wikipedia-it/res/layout/main.xml
new file mode 100644
index 0000000..1fb4479
--- /dev/null
+++ b/wikipedia-it/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: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="@string/hello"
+    />
+</LinearLayout>
diff --git a/wikipedia-it/res/values/strings.xml 
b/wikipedia-it/res/values/strings.xml
new file mode 100644
index 0000000..27b22a0
--- /dev/null
+++ b/wikipedia-it/res/values/strings.xml
@@ -0,0 +1,5 @@
+<?xml version="1.0" encoding="utf-8"?>
+<resources>
+    <string name="hello">Hello wikipedia-it!</string>
+    <string name="app_name">wikipedia-it - tests</string>
+</resources>
diff --git 
a/wikipedia-it/src/main/java/org/wikimedia/wikipedia/test/concurrency/AsyncTaskTest.java
 
b/wikipedia-it/src/main/java/org/wikimedia/wikipedia/test/concurrency/AsyncTaskTest.java
new file mode 100644
index 0000000..ae845f5
--- /dev/null
+++ 
b/wikipedia-it/src/main/java/org/wikimedia/wikipedia/test/concurrency/AsyncTaskTest.java
@@ -0,0 +1,64 @@
+package org.wikimedia.wikipedia.test.concurrency;
+
+import android.test.AndroidTestCase;
+import com.sun.corba.se.spi.orbutil.threadpool.ThreadPool;
+import org.wikimedia.wikipedia.concurrency.ExceptionHandlingAsyncTask;
+
+import java.util.concurrent.*;
+
+public class AsyncTaskTest extends AndroidTestCase {
+    public static final int TASK_COMPLETION_TIMEOUT = 100;
+    private Executor executor;
+    private Executor getDefaultExecutor() {
+        if (executor == null) {
+            executor = new ScheduledThreadPoolExecutor(1);
+        }
+        return executor;
+    }
+
+    public void testFinishHandling() throws Exception {
+        final CountDownLatch onFinishLatch = new CountDownLatch(1);
+        final Integer returned = 42;
+        new ExceptionHandlingAsyncTask<Integer>(getDefaultExecutor()) {
+            @Override
+            public void onFinish(Integer result) {
+                assertEquals(returned, result);
+                onFinishLatch.countDown();
+            }
+
+            @Override
+            public void onCatch(Throwable caught) {
+                assertTrue("Exception called despite success", false);
+            }
+
+            @Override
+            public Integer performTask() throws Throwable {
+                return returned;
+            }
+        }.execute();
+        assertTrue(onFinishLatch.await(TASK_COMPLETION_TIMEOUT, 
TimeUnit.MILLISECONDS));
+    }
+
+    public void testExceptionHandling() throws Exception {
+        final CountDownLatch exceptionLatch = new CountDownLatch(1);
+        final Throwable thrown = new Exception();
+        new ExceptionHandlingAsyncTask<Void>(getDefaultExecutor()) {
+            @Override
+            public void onFinish(Void result) {
+                assertTrue("onFinish called despite exception", false);
+            }
+
+            @Override
+            public void onCatch(Throwable caught) {
+                assertSame(caught, thrown);
+                exceptionLatch.countDown();
+            }
+
+            @Override
+            public Void performTask() throws Throwable {
+                throw thrown;
+            }
+        }.execute();
+        assertTrue(exceptionLatch.await(TASK_COMPLETION_TIMEOUT, 
TimeUnit.MILLISECONDS));
+    }
+}
diff --git a/wikipedia/AndroidManifest.xml b/wikipedia/AndroidManifest.xml
new file mode 100644
index 0000000..27ca999
--- /dev/null
+++ b/wikipedia/AndroidManifest.xml
@@ -0,0 +1,25 @@
+<?xml version="1.0" encoding="utf-8"?>
+<manifest xmlns:android="http://schemas.android.com/apk/res/android";
+    package="org.wikimedia.wikipedia"
+    android:versionCode="1"
+    android:versionName="1.0-SNAPSHOT" >
+
+    <uses-sdk
+        android:minSdkVersion="8"
+        android:targetSdkVersion="16" />
+
+    <application
+        android:allowBackup="true"
+        android:icon="@drawable/ic_launcher"
+        android:label="@string/app_name"
+        android:theme="@style/AppTheme">
+        <activity android:name=".HelloAndroidActivity" >
+            <intent-filter>
+                <action android:name="android.intent.action.MAIN" />
+
+                <category android:name="android.intent.category.LAUNCHER" />
+            </intent-filter>
+        </activity>
+    </application>
+
+</manifest>
\ No newline at end of file
diff --git a/wikipedia/pom.xml b/wikipedia/pom.xml
new file mode 100644
index 0000000..d761c15
--- /dev/null
+++ b/wikipedia/pom.xml
@@ -0,0 +1,52 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0"; 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
+       xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 
http://maven.apache.org/maven-v4_0_0.xsd";>
+       <modelVersion>4.0.0</modelVersion>
+
+       <parent>
+               <groupId>org.wikimedia</groupId>
+               <artifactId>wikipedia-parent</artifactId>
+               <version>1.0-SNAPSHOT</version>
+       </parent>
+
+       <groupId>org.wikimedia</groupId>
+       <artifactId>wikipedia</artifactId>
+       <version>1.0-SNAPSHOT</version>
+       <packaging>apk</packaging>
+       <name>wikipedia - Application</name>
+
+       <dependencies>
+               <dependency>
+                       <groupId>com.google.android</groupId>
+                       <artifactId>android</artifactId>
+                       <version>${platform.version}</version>
+                       <scope>provided</scope>
+               </dependency>
+        <dependency>
+            <groupId>com.android.support</groupId>
+            <artifactId>support-v4</artifactId>
+            <type>jar</type>
+        </dependency>
+        <dependency>
+            <groupId>com.android.support</groupId>
+            <artifactId>appcompat-v7</artifactId>
+            <version>18.0.0</version>
+            <type>aar</type>
+        </dependency>
+        <dependency>
+            <groupId>org.mediawiki.api</groupId>
+            <artifactId>json</artifactId>
+            <version>1.0-SNAPSHOT</version>
+        </dependency>
+       </dependencies>
+       <build>
+               <finalName>${project.artifactId}</finalName>
+               <plugins>
+                       <plugin>
+                               
<groupId>com.jayway.maven.plugins.android.generation2</groupId>
+                               <artifactId>android-maven-plugin</artifactId>
+                               <extensions>true</extensions>
+                       </plugin>
+               </plugins>
+       </build>
+</project>
diff --git a/wikipedia/res/drawable-hdpi/ic_launcher.png 
b/wikipedia/res/drawable-hdpi/ic_launcher.png
new file mode 100644
index 0000000..288b665
--- /dev/null
+++ b/wikipedia/res/drawable-hdpi/ic_launcher.png
Binary files differ
diff --git a/wikipedia/res/drawable-mdpi/ic_launcher.png 
b/wikipedia/res/drawable-mdpi/ic_launcher.png
new file mode 100644
index 0000000..6ae570b
--- /dev/null
+++ b/wikipedia/res/drawable-mdpi/ic_launcher.png
Binary files differ
diff --git a/wikipedia/res/drawable-xhdpi/ic_launcher.png 
b/wikipedia/res/drawable-xhdpi/ic_launcher.png
new file mode 100644
index 0000000..d4fb7cd
--- /dev/null
+++ b/wikipedia/res/drawable-xhdpi/ic_launcher.png
Binary files differ
diff --git a/wikipedia/res/drawable-xxhdpi/ic_launcher.png 
b/wikipedia/res/drawable-xxhdpi/ic_launcher.png
new file mode 100644
index 0000000..85a6081
--- /dev/null
+++ b/wikipedia/res/drawable-xxhdpi/ic_launcher.png
Binary files differ
diff --git a/wikipedia/res/layout/activity_main.xml 
b/wikipedia/res/layout/activity_main.xml
new file mode 100644
index 0000000..9a28600
--- /dev/null
+++ b/wikipedia/res/layout/activity_main.xml
@@ -0,0 +1,25 @@
+<android.support.v4.widget.DrawerLayout
+        xmlns:android="http://schemas.android.com/apk/res/android";
+        android:id="@+id/drawer_layout"
+        android:layout_width="match_parent"
+        android:layout_height="match_parent">
+    <!-- The main content view -->
+    <FrameLayout
+            android:id="@+id/content_frame"
+            android:layout_width="match_parent"
+            android:layout_height="match_parent"/>
+    <!-- The navigation drawer -->
+    <LinearLayout android:id="@+id/left_drawer"
+              android:layout_width="240dp"
+              android:layout_height="match_parent"
+              android:layout_gravity="start"
+              android:orientation="vertical"
+              android:background="#111">
+        <TextView
+                android:layout_width="match_parent"
+                android:layout_height="wrap_content"
+                android:id="@+id/test_text"
+                android:text="Test"
+            />
+    </LinearLayout>
+</android.support.v4.widget.DrawerLayout>
diff --git a/wikipedia/res/menu/main.xml b/wikipedia/res/menu/main.xml
new file mode 100644
index 0000000..d227c49
--- /dev/null
+++ b/wikipedia/res/menu/main.xml
@@ -0,0 +1,9 @@
+<menu xmlns:android="http://schemas.android.com/apk/res/android"; >
+
+    <item
+        android:id="@+id/action_settings"
+        android:orderInCategory="100"
+        android:showAsAction="never"
+        android:title="@string/action_settings"/>
+
+</menu>
\ No newline at end of file
diff --git a/wikipedia/res/values-sw600dp/dimens.xml 
b/wikipedia/res/values-sw600dp/dimens.xml
new file mode 100644
index 0000000..1ba777d
--- /dev/null
+++ b/wikipedia/res/values-sw600dp/dimens.xml
@@ -0,0 +1,8 @@
+<resources>
+
+    <!--
+         Customize dimensions originally defined in res/values/dimens.xml 
(such as
+         screen margins) for sw600dp devices (e.g. 7" tablets) here.
+    -->
+
+</resources>
\ No newline at end of file
diff --git a/wikipedia/res/values-sw720dp-land/dimens.xml 
b/wikipedia/res/values-sw720dp-land/dimens.xml
new file mode 100644
index 0000000..eee741a
--- /dev/null
+++ b/wikipedia/res/values-sw720dp-land/dimens.xml
@@ -0,0 +1,9 @@
+<resources>
+
+    <!--
+         Customize dimensions originally defined in res/values/dimens.xml 
(such as
+         screen margins) for sw720dp devices (e.g. 10" tablets) in landscape 
here.
+    -->
+    <dimen name="activity_horizontal_margin">128dp</dimen>
+
+</resources>
\ No newline at end of file
diff --git a/wikipedia/res/values-v11/styles.xml 
b/wikipedia/res/values-v11/styles.xml
new file mode 100644
index 0000000..541752f
--- /dev/null
+++ b/wikipedia/res/values-v11/styles.xml
@@ -0,0 +1,11 @@
+<resources>
+
+    <!--
+        Base application theme for API 11+. This theme completely replaces
+        AppBaseTheme from res/values/styles.xml on API 11+ devices.
+    -->
+    <style name="AppBaseTheme" parent="android:Theme.Holo.Light">
+        <!-- API 11 theme customizations can go here. -->
+    </style>
+
+</resources>
\ No newline at end of file
diff --git a/wikipedia/res/values-v14/styles.xml 
b/wikipedia/res/values-v14/styles.xml
new file mode 100644
index 0000000..f20e015
--- /dev/null
+++ b/wikipedia/res/values-v14/styles.xml
@@ -0,0 +1,12 @@
+<resources>
+
+    <!--
+        Base application theme for API 14+. This theme completely replaces
+        AppBaseTheme from BOTH res/values/styles.xml and
+        res/values-v11/styles.xml on API 14+ devices.
+    -->
+    <style name="AppBaseTheme" parent="android:Theme.Holo.Light.DarkActionBar">
+        <!-- API 14 theme customizations can go here. -->
+    </style>
+
+</resources>
\ No newline at end of file
diff --git a/wikipedia/res/values/dimens.xml b/wikipedia/res/values/dimens.xml
new file mode 100644
index 0000000..a6dd140
--- /dev/null
+++ b/wikipedia/res/values/dimens.xml
@@ -0,0 +1,7 @@
+<resources>
+
+    <!-- Default screen margins, per the Android Design guidelines. -->
+    <dimen name="activity_horizontal_margin">16dp</dimen>
+    <dimen name="activity_vertical_margin">16dp</dimen>
+
+</resources>
\ No newline at end of file
diff --git a/wikipedia/res/values/strings.xml b/wikipedia/res/values/strings.xml
new file mode 100644
index 0000000..679f3bf
--- /dev/null
+++ b/wikipedia/res/values/strings.xml
@@ -0,0 +1,9 @@
+<?xml version="1.0" encoding="utf-8"?>
+<resources>
+
+    <string name="app_name">Hello Maven</string>
+    <string name="hello">Hello wikipedia!</string>
+    <string name="action_settings">Settings</string>
+    <string name="hello_world">Hello world!</string>
+
+</resources>
\ No newline at end of file
diff --git a/wikipedia/res/values/styles.xml b/wikipedia/res/values/styles.xml
new file mode 100644
index 0000000..4a10ca4
--- /dev/null
+++ b/wikipedia/res/values/styles.xml
@@ -0,0 +1,20 @@
+<resources>
+
+    <!--
+        Base application theme, dependent on API level. This theme is replaced
+        by AppBaseTheme from res/values-vXX/styles.xml on newer devices.
+    -->
+    <style name="AppBaseTheme" parent="android:Theme.Light">
+        <!--
+            Theme customizations available in newer API levels can go in
+            res/values-vXX/styles.xml, while customizations related to
+            backward-compatibility can go here.
+        -->
+    </style>
+
+    <!-- Application theme. -->
+    <style name="AppTheme" parent="AppBaseTheme">
+        <!-- All customizations that are NOT specific to a particular 
API-level can go here. -->
+    </style>
+
+</resources>
\ No newline at end of file
diff --git 
a/wikipedia/src/main/java/org/wikimedia/wikipedia/HelloAndroidActivity.java 
b/wikipedia/src/main/java/org/wikimedia/wikipedia/HelloAndroidActivity.java
new file mode 100644
index 0000000..896ab0a
--- /dev/null
+++ b/wikipedia/src/main/java/org/wikimedia/wikipedia/HelloAndroidActivity.java
@@ -0,0 +1,30 @@
+package org.wikimedia.wikipedia;
+
+import android.app.Activity;
+import android.os.Bundle;
+import android.support.v4.app.FragmentActivity;
+import android.util.Log;
+import android.view.Menu;
+
+public class HelloAndroidActivity extends FragmentActivity {
+
+    /**
+     * Called when the activity is first created.
+     * @param savedInstanceState If the activity is being re-initialized after
+     * previously being shut down then this Bundle contains the data it most
+     * recently supplied in onSaveInstanceState(Bundle). <b>Note: Otherwise it 
is null.</b>
+     */
+    @Override
+    public void onCreate(Bundle savedInstanceState) {
+        super.onCreate(savedInstanceState);
+        setContentView(R.layout.activity_main);
+    }
+
+    @Override
+    public boolean onCreateOptionsMenu(Menu menu) {
+       // Inflate the menu; this adds items to the action bar if it is present.
+       getMenuInflater().inflate(R.menu.main, menu);
+       return true;
+    }
+
+}
diff --git 
a/wikipedia/src/main/java/org/wikimedia/wikipedia/concurrency/ExceptionHandlingAsyncTask.java
 
b/wikipedia/src/main/java/org/wikimedia/wikipedia/concurrency/ExceptionHandlingAsyncTask.java
new file mode 100644
index 0000000..e56e0bf
--- /dev/null
+++ 
b/wikipedia/src/main/java/org/wikimedia/wikipedia/concurrency/ExceptionHandlingAsyncTask.java
@@ -0,0 +1,101 @@
+package org.wikimedia.wikipedia.concurrency;
+
+import android.os.AsyncTask;
+
+import java.util.concurrent.Executor;
+
+public abstract class ExceptionHandlingAsyncTask<T> {
+    private final BackingAsyncTask underlyingTask;
+
+    private final Executor executor;
+
+    /**
+     * @param executor The executor on which this Task will run.
+     */
+    public ExceptionHandlingAsyncTask(Executor executor) {
+        this.executor = executor;
+        underlyingTask =  new BackingAsyncTask();
+    }
+
+    /**
+     * Called before the background task is executed.
+     * <p/>
+     * Called on the UI Thread.
+     */
+    public void onBeforeExecute() {
+
+    }
+
+    /**
+     * Called when the background operation finishes successfully.
+     * <p/>
+     * Called on the UI Thread.
+     *
+     * @param result The result of the background operation.
+     */
+    public void onFinish(T result) {
+
+    }
+
+    /**
+     * Called when an exception is thrown in the background process.
+     * <p/>
+     * Called on the UI Thread.
+     *
+     * @param caught The exception that was thrown.
+     */
+    public void onCatch(Throwable caught) {
+
+    }
+
+
+    /**
+     * Called to perform the actual work in the background.
+     *
+     * Called on a background thread.
+     * @return The result of the operation that needed to be run in background.
+     */
+    public abstract T performTask() throws Throwable;
+
+    /**
+     * Start performing the task on the executor specified.
+     */
+    public void execute() {
+        underlyingTask.executeOnExecutor(executor);
+        java.util.concurrent.SynchronousQueue q;
+        java.util.concurrent.AbstractExecutorService e;
+    }
+
+    /**
+     * Private AsyncTask that actually performs the operations.
+     */
+    private class BackingAsyncTask extends AsyncTask<Void, Void, T> {
+        private Throwable thrown;
+
+        @Override
+        protected T doInBackground(Void... voids) {
+            try {
+                return performTask();
+            } catch (Throwable t) {
+                thrown = t;
+                return null;
+            }
+        }
+
+        @Override
+        protected void onPostExecute(T result) {
+            super.onPostExecute(result);
+            if (thrown != null) {
+                onCatch(thrown);
+            } else {
+                onFinish(result);
+            }
+        }
+
+        @Override
+        protected void onPreExecute() {
+            super.onPreExecute();
+            onBeforeExecute();
+        }
+    }
+}

-- 
To view, visit https://gerrit.wikimedia.org/r/92775
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: Ibc74b5bf2410e99991e4189b3c0b16e5f12df959
Gerrit-PatchSet: 1
Gerrit-Project: apps/android/wikipedia
Gerrit-Branch: master
Gerrit-Owner: Yuvipanda <[email protected]>
Gerrit-Reviewer: Brion VIBBER <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to