Screen Shot 1

AnFengDe EPUB UI Component 20131021 is Released

After the last release in June, we kept receiving suggestions from developers, for which we felt the need to publish a new version. In this one the following features are enforced:

1, Support for MIPS, X86, ARMEBI, ARMEBI-V7A chip architectures;
2, Support for Android 4.3;
3, Updated and tested for iOS7 environment.

We’ve been developing UI for the new release. Indeed it has taken us quite a long time. But we think it’s worthy. Due to time and energy limitations, there’s been no optimization for the iOS7 interface. Most of the job with significance has been at the EPUB parsing layer.

AnFengDe EPUB UI Component 20130521 is released

In this release we’ve modified our project because some people want to load the inbuilt books and don’t want users to delete them. We deleted the add book function and delete book function. So if you want to add books to you project, you can put them in the books folder(in android is the assets/books), and the app will load them when it starts.

cropped-epubarabic.jpg

Running Unit Tests Automatically on the Emulator for Multiple Android Versions

It’s natural to write unit tests when developing Android applications, and it’s really convenient to do so in Eclipse by selecting “Run as Android Test”. Faced with testing for multiple Android versions, however, it’s troublesome because we will have to make manual selection of versions. Moreover, on the integrated test server only the command line is used. Obviously, we’ll benefit a lot if we have a script to control the versions automatically.

We first need to define an array loop:

all=(android2.2 android2.3 android3.2 android4.1 android4.2)
for i in "${all[@]}"
do
 .... run testcase and collect result....
done

There is the other issue: after starting the emulator from the command line, sometimes the command “adb” cannot detect it, causing the “adb wait-for-device” command to wait forever.   We wrote a small function to detect it, after starting the simulator, “adb devices” is called every second to scan if the word “offline” exists. If nothing is detected within one minute, then the current simulator is killed for restart.

# wait android emulator boot normally, sometime it looks booted,
# but adb cmd can not detected
function wait_emulator_boot(){
 bootok=0
 wait_time=1
 while [ $bootok -le 0 ]; do
   sleep 1
   # if detected offline status, it is boot ok
   bootok=`adb devices|grep offline|wc -l`
   (( wait_time++ ))
   # wait one minute, because more slower when version higher
   if [[ $wait_time -ge 60 ]]; then
     return
   fi
 done
 return
}

Next comes, without doubt, the emulator control by adb command and collecting test data. But there are some problems with the command adb, which, in particular, does not have return values. For example,

 adb install nobody.nobody.nobody

always returns 0. In other words, the script can’t detect if the installation succeeds or fails, an issue heaped with grumbles in Android forums.

The case with us is that the emulator already starts normally, by appearance at least, immediate executing of package installation would report:“Could not access the package manager, is the system running?”

Such error messages indicate that modules for software management are not ready yet inside the emulator. The higher the emulator version, the more serious the issue.

access_done=0
while [ $access_done -le 0 ]; do
  sleep 1
  access_done=`adb uninstall com.anfengde.epub.test|grep -v "Is the system running?"|wc -l`
done

Similarly, we keep scanning the output of error messages to see if it’s executable.

Full code is listed below so that it may be of use to you. Video clip of the running can be found at: Video Clip

#!/bin/bash
# Wirte by AFD Team, 2013.4.10
# define android version array for loop test
all=(android2.2 android2.3 android3.2 android4.1 android4.2)

# clean and build new version
ant clean
ant release

# wait android emulator boot normally, sometime it looks booted,
# but adb cmd can not detected
function wait_emulator_boot(){
  bootok=0
  wait_time=1
  while [ $bootok -le 0 ]; do
    sleep 1
    # if detected offline status, it is boot ok
    bootok=`adb devices|grep offline|wc -l`
    (( wait_time++ ))
    # wait one minute, because more slower when version higher
    if [[ $wait_time -ge 60 ]]; then
        return
    fi
  done
  return
}

# loop android version array
for i in "${all[@]}"
do
    retry=1
    running=0
    while [ $running -le 0 ]; do
        adb -s emulator-5554 emu kill
        echo "startup emulator:" $i "times:" $retry
        # run emulator in background
        emulator -avd $i &
        wait_emulator_boot

        # recheck emulator status
        running=`adb devices|grep line|wc -l`
        echo "check status:" $running "time:" `date`
    done

    # boot normally, just wait online
    adb wait-for-device

    # check software manager work not
    access_done=0
    while [ $access_done -le 0 ]; do
        sleep 1
        access_done=`adb uninstall com.anfengde.epub.test|grep -v "Is the system running?"|wc -l`
    done

    adb uninstall com.anfengde.epub.test > /dev/null
    adb install ./bin/EPUB_SDKTest.apk

    # run testcase
    adb shell am instrument -w com.anfengde.epub.test/android.test.InstrumentationTestRunner
    adb -s emulator-5554 emu kill
done

Getting Started with EPUB SDK

See in google document: Get Started With EPUB SDK

Getting Started with EPUB SDK

Introduction

EPUB SDK is a development kit written in pure ANSI C, realizing EPUB 3.0 parsing and achieving excellent performance on mobile devices.
This development kit provides native development interfaces for both Android and iOS. It contains a framework for the iOS platform, a jar file and a shared library for the Android platform.
All you need to do is simple copying and importing, then you can directly reference in your own project.

Installation
The EPUB SDK is distributed as a .zip archive. The file name has the following naming convention: AnFengde-EPUB_SDK-<version>.zip, where

  • <version> is the versiom number, e.g. 20120704
  • for example: AnFengde-EPUB_SDK-20120704.zip

The distribution
After you have downloaded and extracted the archive to the desired location, you will find the following contents:

  • android    directory containing the EPUB SDK resources for the Android platform
    • EPUB_SDK_Example    directory containing the EPub SDK example for android
    • UI_Example    directory containing the UI component project for android
    • lib    directory containing the EPUB_UI library project
  • ios        directory containing the EPUB_SDK resources for the iOS platform
    • EPUB_SDK_Example    directory containing the EPub SDK example for iOS
    • UI_Example    directory containing the UI component project for iOS
    • lib     directory containing the framework AnFengDe_EPUB_SDK.framework and AnFengDe_EPUB_UI.embeddedframework
  • README.md
  • GettingStartedwithEPUBSDK.pdf
  • GettingStartedWithEPUBUIComponent.pdf

Setting Up Development Environment
For the Android platform, this guide assumes that you are using Eclipse as your Android IDE, and that you have installed and configured the Android SDK and ADT plug-in for Eclipse.
For iOS platform, this guide assumes that you are using Xcode as your IDE.
If you are using other IDEs, please consult the documentation of your IDE.

Using EPUB SDK in Your Application Project
Android Platform
In order to use our EPUB SDK in your application project, your project will need to reference both the jar file (anfengde-epub.jar ) and the shared library (libepubjni.so). You can copy the files under android/lib/EPUB_UI/libs (containing anfengde-epub.jar and armeabi/libepubjni.so) to your own project. Please put these files under project/libs folder. If no libs folder exists in your own project, you can create one manually.
Referencing the EPUB SDK implementation jar library
To add a reference to the jar library, follow these steps:

  • Method One
    • In Package Explorer, right-click on libs/anfengde-epub.jar and select Build Path->Add to Build Path.
  • Method Two
    • In Package Explorer, right-click on your project and select Properties.
    • In the Properties window, select Java Build Path, and then click on Libraries tab, then click on the Add External Jar button, and browse your jar file and click OK (Java Build Path->Libraries->Add External Jar->pick the jar file->OK).

Figure 1 – android EPUB SDK add jar-method one

Figure 2 – android EPUB SDK add jar-method two

After the above operations, you have succeeded in adding EPUB SDK to your own project, and your can use it for development.

iOS Platform
In order to use our EPUB SDK in your application project, your project will need to reference the framework of AnfengdeEpub.framework. All you need to do is to copy the framework ro your own iOS project and add it to the project.
Referencing the EPUB SDK framework
To add a reference to the framework, follow these steps:

  • In Project navigator, right-click Framework, then select Add File to “<projec name>”, and browse the framework and Add it. Then you will see as follow:

Figure 3 – Framework

Using The Sample Project
The EPUB SDK distribution package includes the sample projects to show you how you can use some of the main features of the EPUB SDK in your application.
Android platform
To open and build the sample project, follow these steps:

  • File->New->project->Android->Android Project->Next.
  • Select Creating project from existing source, and browse the sample project. And modify Project Name = Example, then click Next. Check Build Target = Android 2.2, and Next. Modify Application Name =  Example, then Finish.

Figure 4 – import the sample project

Figure 5 – load the sample project

Figure 6 – import the sample project-2

After you have setup the sample project correctly, you can then build and run the application to see the sample work.

Figure 7 – running the sample project (left is Android, right is iOS)

iOS
For the iOS sample project, you can double-click example.xcodeproj. Then you can build and run the application to see the sample work.

Getting Started with EPUB UI Component

Getting Started with  EPUB UI Component

Introduction

EPUB UI Component is a development kit with which EPub 3.0 applications can be developed easily. Referenced in your project, the component helps your parsing and displays the book.

Installation

The EPUB UI Component is distributed as a .zip archive. The file has the following naming convention: AnFengde-EPUB_UI_Component-<version>.zip, where

  • <version> is the version number, e.g. 20120704
  • for example: AnFengde-EPUB_UI_Component-20120704.zip

The distribution

After downloading and extracting the archive to the desired location, you will find the following contents:

  • android    directory containing the EPUB SDK resources for the Android platform
    • EPUB_SDK_Example    directory containing the EPub SDK example for android
    • UI_Example    directory containing the UI component project for android
    • lib    directory containing the EPUB_UI library project
  • ios     directory containing the EPUB_SDK resources for the iOS platform
    • EPUB_SDK_Example    directory containing the EPub SDK example for iOS
    • UI_Example    directory containing the UI component project for iOS
    • lib     directory containing the framework AnFengDe_EPUB_SDK.framework and AnFengDe_EPUB_UI.embeddedframework
  • README.md
  • GettingStartedwithEPUBSDK.pdf
  • GettingStartedWithEPUBUIComponent.pdf

Setting Up Development Environment

For the Android platform, this guide assumes that you are using Eclipse as your Android IDE, and that you have installed and configured the Android SDK and ADT plug-in for Eclipse.
For iOS platform, this guide assumes that you are using Xcode as your IDE.
If you are using other IDEs, please consult the documentation of your IDE.

Using EPUB UI Component in Your Application Project

Android Platform
Epub UI Component is a Library Project in android platform, and getting started with it is very simple. You just add the library to your project. Now look at the sample and it will tell you how to reference the Epub UI Component in your android project.
Importing EPUB_UI Project
To import EPUB_UI library project in you Eclipse(Version: Juno Release).

  • File-> Import->Existing Android Code Into Workspace->Browse our EPUB_UI project

Figure 1-import the EPUB_UI project

Referencing EPUB_UI Project
To create an android project:

  • File->New->Android Project, name the project as CallEPubUI
  • Right click on the CallEPubUI project->Properties->Android->Add->EPUB_UI->OK->OK

Figure 2-CallEPubUI project

Figure 3-reference the EPUB_UI project(1)

Figure 3-reference the EPUB_UI project(2)

Opening the EPub Book

If everything is OK, now add the code in the main.xml of the CallEPubUI project.

<com.anfengde.epub.ui.BookView
android:id=”@+id/bookView1”
android:layout_width=”match_parent”
android:layout_height=”fill_parent” >
</com.anfengde.epub.ui.BookView>

Add the code in the AndroidManifest.xml of the CallEPubUI project.

in the manifest tag add the code:
<uses-permission android:name=”android.permission.INTERNET”/>
<uses-permission android:name=”android.permission.WRITE_EXTERNAL_STORAGE” />    <uses-permission android:name=”android.permission.WRITE_SETTINGS”/>
<uses-permission android:name=”android.permission.ACCESS_NETWORK_STATE”/> <uses-permission android:name=”android.permission.ACCESS_LOCATION_EXTRA_COMMANDS”/>

in the application tag add the code:

<activity android:name=”com.google.ads.AdActivity”     android:configChanges=”keyboard|keyboardHidden|orientation|
screenLayout|uiMode|screenSize|smallestScreenSize”/>

Pay attention to space symbol. If some problems occur, please set project target in project.properties to android-13 or above and then clean the project.

As a last step, add some codes in the onCreate method of the CallEPubUIActivity.

BookView bookView = (BookView) findViewById(R.id.bookView1);
bookView.setPath(Constants.CACHE_PAHT);
bookView.initBook();
bookView.openShelf();

bookView1” is the EPUB UI Component ID, you can change it.
Constants.CACHE_PAHT
is the cache path.        

Note:
If you want to associate your project with ePub file type. You can add this code below to your <activity> tag in the AndroidManifest.xml.

<intent-­filter>
<action android:name=”android.intent.action.VIEW” />
<category android:name=”android.intent.category.DEFAULT” />
<category android:name=”android.intent.category.BROWSABLE” />

 
<data
android:host=”*” android:scheme=”file” />
<data
android:mimeType=”*/*” android:pathPattern=”.*\\.epub” />
</intent-­filter>
And then you can invoke openBookFromFileExplorer(Intent intent) to get the book path from the intent to open the book. Refer to our project.


Run the CallEPubUI project. Now you can add books to the bookshelf.

Figure 4-the book showing up


IOS Platform
Epub UI Component is the framework in iOS platform, and getting started with it is very simple. You just add the framework to your project. Now look at the sample and you know how to reference it in your iOS project.
Creating a Project
To create a new project and name it as CallEPubUI with Xcode(Version 4.2.1)

  • Create a new Xcode project -> Application->Single View Application

Figure 5-create a single view application

Figure 6-CallEPubUI project

Adding the Frameworks and Resources
To add the frameworks and resources to CallEPubUI project in Xcode:

  • Right click on the Frameworks in the CallEPubUI project
  • select “Add Files to “CallEPubUI””
  • select  AnFengDe_EPUB_SDK.framework and AnFengDe_EPUB_UI.embeddedframework, and then add them to CallEPubUI project.
  • In Build Phases option drag .js files from Compile Sources to CopyBundle Resources

Figure 7-add framework to CallEPubUI project

Add iOS framework
Add the following frameworks to your project:

  • MediaPlayer.framework
  • MessageUI.framework
  • SystemConfiguration.framework
  • AudioToolbox.framework
  • CoreGraphics.framework
  • libsqlite3.dylib

Figure 8-add iOS framework


Add -all_load under Other Linker Flags in the project build info: CallEPubUI target ->Build Settings ->Linking ->Other Linker Flags->Add “-all_load”.

Opening the EPUB Book

If everything is OK, the CallEPubUI project looks like this:


Figure 9-the resources list of CallEPubUI project


Now add some codes in the AppDelegate.h (not ViewController.h).

#import <UIKit/UIKit.h>
#import <AnFengDe_EPUB_UI/EPubUIHeader.h>
@interface AppDelegate : UIResponder <UIApplicationDelegate>
@property (strong, nonatomic) UIWindow *window;
@property (strong, nonatomic) EPubRootViewController *rootEpubView;

@end

And in the AppDelegate.m (not ViewController.m), some codes are added to the method:

@implementation AppDelegate

@synthesize window = _window;
@synthesize rootEpubView;

– (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
self.rootEpubView = [[EPubRootViewController alloc] initWithNibName:@”EPubRootViewController” bundle:nil];
self.window.rootViewController = self.rootEpubView;
[self.window makeKeyAndVisible];
   return YES;
}

Note:
If you want to associate your project with ePub file type. You need to add the option in your project info.plist file like this:

It is different in the different version Xcode, so maybe you need to find the right way to do that.

And then you can invoke openBookFromSafari(NSURL *url) to get the book path from the url to open the book. Refer to our project.

 

Run the CallEPubUI project.

Figure 10-the book showing up

AnFengDe EPUB SDK Android development enviroment setting

Please copy our library files under lib folder to your android project’s libs folder. If no libs folder exists in your project, you can create one manually.

android epub sdk dev path for copy

android epub sdk dev path for copy

And now you have succeeded adding epub sdk library.

android epub sdk build setting

Example

We supplied an example for your reference under example folder. The project can run on both the device and the simulator.

More

For more information, please contact us.