If you think the Android project makler listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
Java Source Code
package pl.net.newton.Makler.history.service;
/*www.java2s.com*/import java.util.ArrayList;
import java.util.List;
import pl.net.newton.Makler.db.symbol.Symbol;
import pl.net.newton.Makler.history.EntryListWithIndexes;
import pl.net.newton.Makler.history.HistoryFilter;
import pl.net.newton.Makler.history.BossaProvider;
import android.app.Service;
import android.content.Intent;
import android.os.Binder;
import android.os.IBinder;
import android.util.Log;
publicclass HistoryService extends Service {
privatestaticfinal String TAG = "Makler";
privatefinal Binder binder = new LocalBinder();
privatefinal List<HistoryListener> listeners = new ArrayList<HistoryListener>();
private HistoryFilter filter;
@Override
publicvoid onCreate() {
super.onCreate();
filter = new HistoryFilter(new BossaProvider(this));
}
@Override
publicint onStartCommand(Intent intent, int flags, int startId) {
return START_NOT_STICKY;
}
@Override
public IBinder onBind(Intent intent) {
return binder;
}
publicsynchronizedvoid register(HistoryListener listener) {
listeners.add(listener);
}
publicsynchronizedvoid unregister(HistoryListener listener) {
listeners.remove(listener);
}
publicsynchronized List<HistoryListener> getListeners() {
returnnew ArrayList<HistoryListener>(listeners);
}
publicvoid historyByInt(finalint graphRange, final Symbol symbol, finalboolean force) {
new Thread(new Runnable() {
publicvoid run() {
EntryListWithIndexes entries = null;
try {
entries = filter.historyByInt(graphRange, symbol, force);
} catch (NullPointerException e) {
Log.e(TAG, "npe during history getting", e);
}
for (HistoryListener l : getListeners()) {
try {
l.gotEntries(entries);
} catch (Exception e) {
Log.e(TAG, "Can't inform about entries", e);
}
}
}
}).start();
}
publicboolean isRangeExist(final Symbol symbol, int graphRange) {
return filter.isRangeExist(symbol, graphRange);
}
publicclass LocalBinder extends Binder {
public HistoryService getService() {
return HistoryService.this;
}
}
}