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:
parent
3098622b3e
commit
70afcac495
4 changed files with 31 additions and 5 deletions
|
@ -47,7 +47,7 @@ import org.geometerplus.fbreader.tips.TipsManager;
|
|||
|
||||
import org.geometerplus.android.fbreader.library.SQLiteBooksDatabase;
|
||||
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.util.UIUtil;
|
||||
|
@ -261,10 +261,12 @@ public final class FBReader extends ZLAndroidActivity {
|
|||
} catch (Throwable t) {
|
||||
}
|
||||
PopupPanel.restoreVisibilities(FBReaderApp.Instance());
|
||||
ApiServerImplementation.sendEvent(this, ApiListener.EVENT_READ_MODE_OPENED);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStop() {
|
||||
ApiServerImplementation.sendEvent(this, ApiListener.EVENT_READ_MODE_CLOSED);
|
||||
PopupPanel.removeAllWindows(FBReaderApp.Instance(), this);
|
||||
super.onStop();
|
||||
}
|
||||
|
|
|
@ -14,7 +14,9 @@ public class ApiClientImplementation implements ServiceConnection, Api, ApiMetho
|
|||
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 ConnectionListener myListener;
|
||||
|
|
12
src/org/geometerplus/android/fbreader/api/ApiListener.java
Normal file
12
src/org/geometerplus/android/fbreader/api/ApiListener.java
Normal 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);
|
||||
}
|
|
@ -21,6 +21,9 @@ package org.geometerplus.android.fbreader.api;
|
|||
|
||||
import java.util.*;
|
||||
|
||||
import android.content.ContextWrapper;
|
||||
import android.content.Intent;
|
||||
|
||||
import org.geometerplus.zlibrary.core.library.ZLibrary;
|
||||
import org.geometerplus.zlibrary.core.config.ZLConfig;
|
||||
|
||||
|
@ -29,6 +32,13 @@ import org.geometerplus.zlibrary.text.view.*;
|
|||
import org.geometerplus.fbreader.fbreader.FBReaderApp;
|
||||
|
||||
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 ApiObject.Error unsupportedMethodError(int method) {
|
||||
|
@ -96,7 +106,7 @@ public class ApiServerImplementation extends ApiInterface.Stub implements Api, A
|
|||
}
|
||||
} catch (Throwable e) {
|
||||
return new ApiObject.Error("Exception in method " + method + ": " + e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public List<ApiObject> requestList(int method, ApiObject[] parameters) {
|
||||
|
@ -115,7 +125,7 @@ public class ApiServerImplementation extends ApiInterface.Stub implements Api, A
|
|||
}
|
||||
} catch (Throwable e) {
|
||||
return Collections.<ApiObject>singletonList(exceptionInMethodError(method, e));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private Map<ApiObject,ApiObject> errorMap(ApiObject.Error error) {
|
||||
|
@ -130,7 +140,7 @@ public class ApiServerImplementation extends ApiInterface.Stub implements Api, A
|
|||
}
|
||||
} catch (Throwable e) {
|
||||
return errorMap(exceptionInMethodError(method, e));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// information about fbreader
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue