UnifiedNlp/src/org/microg/nlp/AbstractBackendHelper.java
mar-v-in 8ff926120c Major cleanup, Add support for Geocoder
Using spaces for indentation from now on
Add support for forced locations (debug)
2014-12-25 12:49:33 +01:00

56 lines
1.4 KiB
Java

package org.microg.nlp;
import android.content.Context;
import android.content.Intent;
import android.content.ServiceConnection;
import android.os.RemoteException;
import android.util.Log;
public abstract class AbstractBackendHelper implements ServiceConnection {
protected final Context context;
protected final Intent serviceIntent;
protected boolean bound;
private final String TAG;
public AbstractBackendHelper(String tag, Context context, Intent serviceIntent) {
TAG = tag;
this.context = context;
this.serviceIntent = serviceIntent;
}
public abstract void close() throws RemoteException;
public abstract boolean hasBackend();
public void unbind() {
if (bound) {
if (hasBackend()) {
try {
close();
} catch (Exception e) {
Log.w(TAG, e);
}
}
try {
context.unbindService(this);
} catch (Exception e) {
Log.w(TAG, e);
}
bound = false;
}
}
public boolean bind() {
if (!bound) {
try {
context.bindService(serviceIntent, this, Context.BIND_AUTO_CREATE);
} catch (Exception e) {
Log.w(TAG, e);
return false;
}
}
return true;
}
}