Android support (still not useable, just a test)
[fanfix.git] / src / be / nikiroo / fanfix / reader / android / AndroidReader.java
diff --git a/src/be/nikiroo/fanfix/reader/android/AndroidReader.java b/src/be/nikiroo/fanfix/reader/android/AndroidReader.java
new file mode 100644 (file)
index 0000000..85f07f2
--- /dev/null
@@ -0,0 +1,62 @@
+package be.nikiroo.fanfix.reader.android;
+
+import android.app.Activity;
+import android.content.Intent;
+import android.net.Uri;
+
+import java.io.File;
+import java.io.IOException;
+
+import be.nikiroo.fanfix.reader.BasicReader;
+
+public class AndroidReader extends BasicReader {
+       private Activity app;
+
+       /**
+        * Do not use.
+        */
+       private AndroidReader() {
+               // Required for reflection
+       }
+
+       public AndroidReader(Activity app) {
+               this.app = app;
+       }
+
+       @Override
+       public void read() throws IOException {
+       }
+
+       @Override
+       public void browse(String source) {
+       }
+
+       @Override
+       protected void start(File target, String program) throws IOException {
+               if (program == null) {
+                       try {
+                               Intent[] intents = new Intent[] { //
+                               new Intent(Intent.ACTION_VIEW), //
+                                               new Intent(Intent.ACTION_OPEN_DOCUMENT) //
+                               };
+
+                               for (Intent intent : intents) {
+                                       intent.setDataAndType(Uri.parse(target.toURI().toString()),
+                                                       "application/x-cbz");
+                               }
+
+                               Intent chooserIntent = Intent.createChooser(intents[0],
+                                               "Open CBZ in...");
+
+                               // chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS,
+                               // intents);
+
+                               app.startActivity(chooserIntent);
+                       } catch (UnsupportedOperationException e) {
+                               super.start(target, program);
+                       }
+               } else {
+                       super.start(target, program);
+               }
+       }
+}