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

synchronization with callback-api branch

This commit is contained in:
Nikolay Pultsin 2011-12-30 09:39:47 +00:00
parent 3098622b3e
commit 70afcac495
4 changed files with 31 additions and 5 deletions

View file

@ -47,7 +47,7 @@ import org.geometerplus.fbreader.tips.TipsManager;
import org.geometerplus.android.fbreader.library.SQLiteBooksDatabase; import org.geometerplus.android.fbreader.library.SQLiteBooksDatabase;
import org.geometerplus.android.fbreader.library.KillerCallback; import org.geometerplus.android.fbreader.library.KillerCallback;
import org.geometerplus.android.fbreader.api.PluginApi; import org.geometerplus.android.fbreader.api.*;
import org.geometerplus.android.fbreader.tips.TipsActivity; import org.geometerplus.android.fbreader.tips.TipsActivity;
import org.geometerplus.android.util.UIUtil; import org.geometerplus.android.util.UIUtil;
@ -261,10 +261,12 @@ public final class FBReader extends ZLAndroidActivity {
} catch (Throwable t) { } catch (Throwable t) {
} }
PopupPanel.restoreVisibilities(FBReaderApp.Instance()); PopupPanel.restoreVisibilities(FBReaderApp.Instance());
ApiServerImplementation.sendEvent(this, ApiListener.EVENT_READ_MODE_OPENED);
} }
@Override @Override
public void onStop() { public void onStop() {
ApiServerImplementation.sendEvent(this, ApiListener.EVENT_READ_MODE_CLOSED);
PopupPanel.removeAllWindows(FBReaderApp.Instance(), this); PopupPanel.removeAllWindows(FBReaderApp.Instance(), this);
super.onStop(); super.onStop();
} }

View file

@ -14,7 +14,9 @@ public class ApiClientImplementation implements ServiceConnection, Api, ApiMetho
void onConnected(); void onConnected();
} }
private static String ACTION_API = "android.fbreader.action.API"; private static final String ACTION_API = "android.fbreader.action.API";
static final String ACTION_API_CALLBACK = "android.fbreader.action.API_CALLBACK";
static final String EVENT_TYPE = "event.type";
private final Context myContext; private final Context myContext;
private ConnectionListener myListener; private ConnectionListener myListener;

View file

@ -0,0 +1,12 @@
/*
* This code is in the public domain.
*/
package org.geometerplus.android.fbreader.api;
public interface ApiListener {
String EVENT_READ_MODE_OPENED = "startReading";
String EVENT_READ_MODE_CLOSED = "stopReading";
void onEvent(int event);
}

View file

@ -21,6 +21,9 @@ package org.geometerplus.android.fbreader.api;
import java.util.*; import java.util.*;
import android.content.ContextWrapper;
import android.content.Intent;
import org.geometerplus.zlibrary.core.library.ZLibrary; import org.geometerplus.zlibrary.core.library.ZLibrary;
import org.geometerplus.zlibrary.core.config.ZLConfig; import org.geometerplus.zlibrary.core.config.ZLConfig;
@ -29,6 +32,13 @@ import org.geometerplus.zlibrary.text.view.*;
import org.geometerplus.fbreader.fbreader.FBReaderApp; import org.geometerplus.fbreader.fbreader.FBReaderApp;
public class ApiServerImplementation extends ApiInterface.Stub implements Api, ApiMethods { public class ApiServerImplementation extends ApiInterface.Stub implements Api, ApiMethods {
public static void sendEvent(ContextWrapper context, String eventType) {
context.sendBroadcast(
new Intent(ApiClientImplementation.ACTION_API_CALLBACK)
.putExtra(ApiClientImplementation.EVENT_TYPE, eventType)
);
}
private final FBReaderApp myReader = (FBReaderApp)FBReaderApp.Instance(); private final FBReaderApp myReader = (FBReaderApp)FBReaderApp.Instance();
private ApiObject.Error unsupportedMethodError(int method) { private ApiObject.Error unsupportedMethodError(int method) {
@ -96,7 +106,7 @@ public class ApiServerImplementation extends ApiInterface.Stub implements Api, A
} }
} catch (Throwable e) { } catch (Throwable e) {
return new ApiObject.Error("Exception in method " + method + ": " + e); return new ApiObject.Error("Exception in method " + method + ": " + e);
} }
} }
public List<ApiObject> requestList(int method, ApiObject[] parameters) { public List<ApiObject> requestList(int method, ApiObject[] parameters) {
@ -115,7 +125,7 @@ public class ApiServerImplementation extends ApiInterface.Stub implements Api, A
} }
} catch (Throwable e) { } catch (Throwable e) {
return Collections.<ApiObject>singletonList(exceptionInMethodError(method, e)); return Collections.<ApiObject>singletonList(exceptionInMethodError(method, e));
} }
} }
private Map<ApiObject,ApiObject> errorMap(ApiObject.Error error) { private Map<ApiObject,ApiObject> errorMap(ApiObject.Error error) {
@ -130,7 +140,7 @@ public class ApiServerImplementation extends ApiInterface.Stub implements Api, A
} }
} catch (Throwable e) { } catch (Throwable e) {
return errorMap(exceptionInMethodError(method, e)); return errorMap(exceptionInMethodError(method, e));
} }
} }
// information about fbreader // information about fbreader