1
0
Fork 0
mirror of https://github.com/geometer/FBReaderJ.git synced 2025-10-05 10:49:24 +02:00

introduced SynchroniserService

This commit is contained in:
Nikolay Pultsin 2014-06-22 19:05:16 +01:00
parent 361c535c2c
commit 553b88dc70
4 changed files with 70 additions and 2 deletions

View file

@ -136,6 +136,7 @@
</intent-filter> </intent-filter>
</service> </service>
<service android:name="org.geometerplus.android.fbreader.config.ConfigService" android:launchMode="singleTask" android:process=":configService" android:exported="false"/> <service android:name="org.geometerplus.android.fbreader.config.ConfigService" android:launchMode="singleTask" android:process=":configService" android:exported="false"/>
<service android:name="org.geometerplus.android.fbreader.synchroniser.SynchroniserService" android:launchMode="singleTask" android:process=":synchroniser" android:exported="false"/>
<activity android:name="org.geometerplus.android.fbreader.library.BookInfoActivity" android:theme="@style/FBReader.Activity" android:process=":library" android:configChanges="orientation|keyboardHidden|screenSize"> <activity android:name="org.geometerplus.android.fbreader.library.BookInfoActivity" android:theme="@style/FBReader.Activity" android:process=":library" android:configChanges="orientation|keyboardHidden|screenSize">
<intent-filter> <intent-filter>
<action android:name="android.fbreader.action.BOOK_INFO"/> <action android:name="android.fbreader.action.BOOK_INFO"/>

View file

@ -136,6 +136,7 @@
</intent-filter> </intent-filter>
</service> </service>
<service android:name="org.geometerplus.android.fbreader.config.ConfigService" android:launchMode="singleTask" android:process=":configService" android:exported="false"/> <service android:name="org.geometerplus.android.fbreader.config.ConfigService" android:launchMode="singleTask" android:process=":configService" android:exported="false"/>
<service android:name="org.geometerplus.android.fbreader.synchroniser.SynchroniserService" android:launchMode="singleTask" android:process=":synchroniser" android:exported="false"/>
<activity android:name="org.geometerplus.android.fbreader.library.BookInfoActivity" android:theme="@style/FBReader.Activity" android:process=":library" android:configChanges="orientation|keyboardHidden|screenSize"> <activity android:name="org.geometerplus.android.fbreader.library.BookInfoActivity" android:theme="@style/FBReader.Activity" android:process=":library" android:configChanges="orientation|keyboardHidden|screenSize">
<intent-filter> <intent-filter>
<action android:name="android.fbreader.action.BOOK_INFO"/> <action android:name="android.fbreader.action.BOOK_INFO"/>

View file

@ -29,8 +29,7 @@ import android.app.SearchManager;
import android.content.*; import android.content.*;
import android.graphics.Color; import android.graphics.Color;
import android.net.Uri; import android.net.Uri;
import android.os.Bundle; import android.os.*;
import android.os.PowerManager;
import android.view.*; import android.view.*;
import android.widget.RelativeLayout; import android.widget.RelativeLayout;
@ -59,6 +58,7 @@ import org.geometerplus.android.fbreader.api.*;
import org.geometerplus.android.fbreader.httpd.DataService; import org.geometerplus.android.fbreader.httpd.DataService;
import org.geometerplus.android.fbreader.library.BookInfoActivity; import org.geometerplus.android.fbreader.library.BookInfoActivity;
import org.geometerplus.android.fbreader.libraryService.BookCollectionShadow; import org.geometerplus.android.fbreader.libraryService.BookCollectionShadow;
import org.geometerplus.android.fbreader.synchroniser.SynchroniserService;
import org.geometerplus.android.fbreader.tips.TipsActivity; import org.geometerplus.android.fbreader.tips.TipsActivity;
import org.geometerplus.android.util.*; import org.geometerplus.android.util.*;
@ -95,6 +95,17 @@ public final class FBReader extends Activity implements ZLApplicationWindow {
private String myMenuLanguage; private String myMenuLanguage;
final DataService.Connection DataConnection = new DataService.Connection(); final DataService.Connection DataConnection = new DataService.Connection();
private final ServiceConnection mySynchroniserConnection = new ServiceConnection() {
@Override
public void onServiceConnected(ComponentName componentName, IBinder binder) {
System.err.println("SynchroniserService CONNECTED");
}
@Override
public void onServiceDisconnected(ComponentName componentName) {
System.err.println("SynchroniserService DISCONNECTED");
}
};
private static final String PLUGIN_ACTION_PREFIX = "___"; private static final String PLUGIN_ACTION_PREFIX = "___";
private final List<PluginApi.ActionInfo> myPluginActions = private final List<PluginApi.ActionInfo> myPluginActions =
@ -450,6 +461,12 @@ public final class FBReader extends Activity implements ZLApplicationWindow {
protected void onResume() { protected void onResume() {
super.onResume(); super.onResume();
bindService(
new Intent(this, SynchroniserService.class),
mySynchroniserConnection,
SynchroniserService.BIND_AUTO_CREATE
);
myStartTimer = true; myStartTimer = true;
Config.Instance().runOnConnect(new Runnable() { Config.Instance().runOnConnect(new Runnable() {
public void run() { public void run() {
@ -494,6 +511,7 @@ public final class FBReader extends Activity implements ZLApplicationWindow {
setButtonLight(true); setButtonLight(true);
} }
myFBReaderApp.onWindowClosing(); myFBReaderApp.onWindowClosing();
unbindService(mySynchroniserConnection);
super.onPause(); super.onPause();
} }

View file

@ -0,0 +1,48 @@
/*
* Copyright (C) 2010-2014 Geometer Plus <contact@geometerplus.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
* 02110-1301, USA.
*/
package org.geometerplus.android.fbreader.synchroniser;
import android.app.Service;
import android.content.Intent;
import android.os.IBinder;
import org.geometerplus.android.fbreader.libraryService.BookCollectionShadow;
public class SynchroniserService extends Service implements Runnable {
private final BookCollectionShadow myCollection = new BookCollectionShadow();
@Override
public IBinder onBind(Intent intent) {
myCollection.bindToService(this, this);
return null;
}
@Override
public void run() {
System.err.println("SYNCHRONIZER BINDED TO LIBRARY");
}
@Override
public void onDestroy() {
myCollection.unbind();
System.err.println("SYNCHRONIZER UNBINDED FROM LIBRARY");
super.onDestroy();
}
}