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

more methods in API

This commit is contained in:
Nikolay Pultsin 2011-06-18 20:13:04 +01:00
parent 81bbd64901
commit 726c28111d
3 changed files with 28 additions and 1 deletions

View file

@ -26,6 +26,12 @@ import org.geometerplus.fbreader.fbreader.FBReaderApp;
public class ApiImplementation extends ApiInterface.Stub { public class ApiImplementation extends ApiInterface.Stub {
private final FBReaderApp myReader = (FBReaderApp)FBReaderApp.Instance(); private final FBReaderApp myReader = (FBReaderApp)FBReaderApp.Instance();
@Override
public String getBookLanguage() {
// TODO: check for NPE
return myReader.Model.Book.getLanguage();
}
private TextPosition getTextPosition(ZLTextWordCursor cursor) { private TextPosition getTextPosition(ZLTextWordCursor cursor) {
return new TextPosition( return new TextPosition(
cursor.getParagraphIndex(), cursor.getParagraphIndex(),
@ -56,9 +62,16 @@ public class ApiImplementation extends ApiInterface.Stub {
return myReader.Model.BookTextModel.getParagraphsNumber(); return myReader.Model.BookTextModel.getParagraphsNumber();
} }
@Override
public int getElementsNumber(int paragraphIndex) {
final ZLTextWordCursor cursor = new ZLTextWordCursor(myReader.getTextView().getStartCursor());
cursor.moveToParagraph(paragraphIndex);
cursor.moveToParagraphEnd();
return cursor.getElementIndex();
}
@Override @Override
public String getParagraphText(int paragraphIndex) { public String getParagraphText(int paragraphIndex) {
// TODO: check for NPEs
final StringBuffer sb = new StringBuffer(); final StringBuffer sb = new StringBuffer();
final ZLTextWordCursor cursor = new ZLTextWordCursor(myReader.getTextView().getStartCursor()); final ZLTextWordCursor cursor = new ZLTextWordCursor(myReader.getTextView().getStartCursor());
cursor.moveToParagraph(paragraphIndex); cursor.moveToParagraph(paragraphIndex);

View file

@ -22,7 +22,12 @@ package org.geometerplus.android.fbreader.api;
import org.geometerplus.android.fbreader.api.TextPosition; import org.geometerplus.android.fbreader.api.TextPosition;
interface ApiInterface { interface ApiInterface {
//ApiObject request(String name, ApiObject[] parameters);
int getParagraphsNumber(); int getParagraphsNumber();
int getElementsNumber(int paragraphIndex);
String getBookLanguage();
TextPosition getPageStart(); TextPosition getPageStart();
TextPosition getPageEnd(); TextPosition getPageEnd();

View file

@ -65,6 +65,15 @@ public class ApiServiceConnection implements ServiceConnection {
} }
} }
public synchronized String getBookLanguage() throws ApiException {
checkConnection();
try {
return myInterface.getBookLanguage();
} catch (android.os.RemoteException e) {
throw new ApiException(e);
}
}
public synchronized TextPosition getPageStart() throws ApiException { public synchronized TextPosition getPageStart() throws ApiException {
checkConnection(); checkConnection();
try { try {