diff --git a/SDKLauncher-Android/src/org/readium/sdk/android/launcher/ContainerList.java b/SDKLauncher-Android/src/org/readium/sdk/android/launcher/ContainerList.java index 7d3b87e5..57f121e1 100644 --- a/SDKLauncher-Android/src/org/readium/sdk/android/launcher/ContainerList.java +++ b/SDKLauncher-Android/src/org/readium/sdk/android/launcher/ContainerList.java @@ -49,6 +49,8 @@ import android.app.AlertDialog; import android.content.DialogInterface; +import android.os.Handler; +import android.os.Message; /** * @author chtian * @@ -71,6 +73,8 @@ public void done() { private Context context; private final String testPath = "epubtest"; + private Handler mHandler = null; + private String mBookName; @Override protected void onCreate(Bundle savedInstanceState) { @@ -100,34 +104,56 @@ protected void onCreate(Bundle savedInstanceState) { public void onItemClick(AdapterView arg0, View arg1, int arg2, long arg3) { - String bookName = list.get(arg2); + mBookName = list.get(arg2); - String path = Environment.getExternalStorageDirectory().getAbsolutePath() + "/" + testPath + "/" + bookName; + String path = Environment.getExternalStorageDirectory().getAbsolutePath() + "/" + testPath + "/" + mBookName; - Toast.makeText(context, "Select " + bookName, Toast.LENGTH_SHORT).show(); + Toast.makeText(context, "Select " + mBookName, Toast.LENGTH_SHORT).show(); m_SdkErrorHandler_Messages = new Stack(); EPub3.setSdkErrorHandler(ContainerList.this); - Container container = EPub3.openBook(path); - EPub3.setSdkErrorHandler(null); - - ContainerHolder.getInstance().put(container.getNativePtr(), container); - Intent intent = new Intent(getApplicationContext(), BookDataActivity.class); - intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); - intent.putExtra(Constants.BOOK_NAME, bookName); - intent.putExtra(Constants.CONTAINER_ID, container.getNativePtr()); - SdkErrorHandlerMessagesCompleted callback = new SdkErrorHandlerMessagesCompleted(intent) { - @Override - public void once() { - startActivity(m_intent); - } + mHandler = new Handler() { + @Override + public void handleMessage(Message msg) { + Container container = (Container)msg.obj; + if(container == null){ + //error message show + SdkErrorHandlerMessagesCompleted callback = new SdkErrorHandlerMessagesCompleted(null) { + @Override + public void once() { + //do notthing + } + }; + // async! + popSdkErrorHandlerMessage(context, callback); + } + else{ + ContainerHolder.getInstance().put(container.getNativePtr(), container); + + Intent intent = new Intent(getApplicationContext(), BookDataActivity.class); + intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); + intent.putExtra(Constants.BOOK_NAME, mBookName); + intent.putExtra(Constants.CONTAINER_ID, container.getNativePtr()); + + SdkErrorHandlerMessagesCompleted callback = new SdkErrorHandlerMessagesCompleted(intent) { + @Override + public void once() { + startActivity(m_intent); + } + }; + + // async! + popSdkErrorHandlerMessage(context, callback); + } + } }; - // async! - popSdkErrorHandlerMessage(context, callback); + //Run on thread + OpenBookOnThread task = new OpenBookOnThread(path); + task.start(); } }); @@ -135,6 +161,28 @@ public void once() { EPub3.setCachePath(getCacheDir().getAbsolutePath()); } + class OpenBookOnThread extends Thread{ + String mPath; + OpenBookOnThread(final String path){ + mPath = path; + } + @Override + public void run() + { + Container container = EPub3.openBook(mPath); + EPub3.setSdkErrorHandler(null); + Message msg = new Message(); + msg.obj = container; + mHandler.sendMessage(msg); + } + }; + + private void containerRegisterContentModules(Context context) + { + DrmInitialize drmInitialize = new DrmInitialize(); + drmInitialize.initialize(context); + } + private Stack m_SdkErrorHandler_Messages = null; // async! diff --git a/SDKLauncher-Android/src/org/readium/sdk/android/launcher/DrmInitialize.java b/SDKLauncher-Android/src/org/readium/sdk/android/launcher/DrmInitialize.java new file mode 100644 index 00000000..ef07be2f --- /dev/null +++ b/SDKLauncher-Android/src/org/readium/sdk/android/launcher/DrmInitialize.java @@ -0,0 +1,30 @@ +// +// DrmInitialize.java +// SDKLauncher-OSX +// +// Created by Fasoo.com Development Team on 2015-12-12. +// ( M.N. Kim ) +// +// Copyright (c) 2015 The Readium Foundation and contributors. All rights reserved. +// +// The Readium SDK is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see +// +package org.readium.sdk.android.launcher; + +import android.content.Context; + +public class DrmInitialize { + void initialize(Context context){ + } +}