1
0
Fork 0
mirror of https://github.com/geometer/FBReaderJ.git synced 2025-10-04 10:19:33 +02:00

API implementation (in progress)

This commit is contained in:
Nikolay Pultsin 2011-06-18 01:01:04 +01:00
parent c48df4b0f0
commit 92929e6752
5 changed files with 143 additions and 14 deletions

View file

@ -39,6 +39,16 @@ public class ApiServiceConnection implements ServiceConnection {
}
}
public synchronized void disconnect() {
if (myInterface != null) {
try {
myContext.unbindService(this);
} catch (IllegalArgumentException e) {
}
myInterface = null;
}
}
public synchronized void onServiceConnected(ComponentName className, IBinder service) {
System.err.println("onServiceConnected call");
myInterface = ApiInterface.Stub.asInterface(service);
@ -51,23 +61,41 @@ public class ApiServiceConnection implements ServiceConnection {
private void checkConnection() throws ApiException {
if (myInterface == null) {
throw new ApiException("No connection with FBReader");
throw new ApiException("Not connected to FBReader");
}
}
public synchronized int getPageStartParagraphIndex() throws ApiException {
public synchronized TextPosition getPageStart() throws ApiException {
checkConnection();
try {
return myInterface.getPageStartParagraphIndex();
return myInterface.getPageStart();
} catch (android.os.RemoteException e) {
throw new ApiException(e);
}
}
public synchronized int getMaxParagraphIndex() throws ApiException {
public synchronized TextPosition getPageEnd() throws ApiException {
checkConnection();
try {
return myInterface.getMaxParagraphIndex();
return myInterface.getPageEnd();
} catch (android.os.RemoteException e) {
throw new ApiException(e);
}
}
public synchronized void setPageStart(TextPosition position) throws ApiException {
checkConnection();
try {
myInterface.setPageStart(position);
} catch (android.os.RemoteException e) {
throw new ApiException(e);
}
}
public synchronized int getParagraphsNumber() throws ApiException {
checkConnection();
try {
return myInterface.getParagraphsNumber();
} catch (android.os.RemoteException e) {
throw new ApiException(e);
}