Package com.clover.sdk.v1
Class ServiceConnector<S extends IInterface>
- java.lang.Object
-
- com.clover.sdk.v1.ServiceConnector<S>
-
- Type Parameters:
S
- The service interface that is being encapsulated.
- All Implemented Interfaces:
ServiceConnection
- Direct Known Subclasses:
AppsConnector
,CustomerConnector
,EmployeeConnector
,InventoryConnector
,MerchantConnector
,OrderV31Connector
,OrderV3Connector
,PrinterConnector
,ReceiptRegistrationConnector
,ServiceFeeConnector
,TenderConnector
public abstract class ServiceConnector<S extends IInterface> extends Object implements ServiceConnection
Base class for implementing service connectors. A service connector is a class that encapsulates a bound AIDL service. Subclasses of this class implement methods that are specific to the service that they're interacting with.Connection with the service happens implicitly. However, the user of a
ServiceConnector
must calldisconnect()
when he or she is done with the instance. For example, when using aServiceConnector
in anActivity
, calldisconnect()
fromonPause()
oronDestroy()
.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interface
ServiceConnector.Callback<T>
Responds to the results of a call to aServiceConnector
method.static interface
ServiceConnector.OnServiceConnectedListener
protected static interface
ServiceConnector.ServiceCallable<S,T>
protected static interface
ServiceConnector.ServiceRunnable<S>
-
Constructor Summary
Constructors Constructor Description ServiceConnector(Context context, Account account, ServiceConnector.OnServiceConnectedListener client)
Constructs a new ServiceConnector object.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Deprecated Methods Modifier and Type Method Description boolean
connect()
void
disconnect()
protected <T> T
execute(ServiceConnector.ServiceCallable<S,T> callable)
protected <T> void
execute(ServiceConnector.ServiceCallable<S,T> callable, ServiceConnector.Callback<T> callback)
protected void
execute(ServiceConnector.ServiceRunnable<S> runnable)
protected void
execute(ServiceConnector.ServiceRunnable<S> runnable, ServiceConnector.Callback<Void> callback)
S
getService()
Returns the order service interfaceprotected abstract String
getServiceIntentAction()
protected String
getServiceIntentPackage()
The package which hosts the service to connect to.protected int
getServiceIntentVersion()
Deprecated.Include a version in the service connector action insteadprotected abstract S
getServiceInterface(IBinder iBinder)
protected Intent
getStartIntent()
boolean
isConnected()
Returns whether we are connected to the order serviceboolean
isInstalled()
protected void
notifyServiceConnected(ServiceConnector.OnServiceConnectedListener client)
protected void
notifyServiceDisconnected(ServiceConnector.OnServiceConnectedListener client)
void
onServiceConnected(ComponentName componentName, IBinder iBinder)
Part of the ServiceConnection interface.void
onServiceDisconnected(ComponentName componentName)
Part of the ServiceConnection interface.protected <T> void
postResults(T result, ResultStatus status, ServiceConnector.Callback<T> callback)
protected void
throwOnFailure(ResultStatus status)
protected S
waitForConnection()
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface android.content.ServiceConnection
onBindingDied, onNullBinding
-
-
-
-
Field Detail
-
mContext
protected final Context mContext
-
mAccount
protected final Account mAccount
-
mClient
protected final ServiceConnector.OnServiceConnectedListener mClient
-
mHandler
protected final Handler mHandler
-
mService
protected S extends IInterface mService
-
mConnected
protected boolean mConnected
-
-
Constructor Detail
-
ServiceConnector
public ServiceConnector(Context context, Account account, ServiceConnector.OnServiceConnectedListener client)
Constructs a new ServiceConnector object.- Parameters:
context
- the Context object, required for establishing a connection to the service.account
- the Account to use with the service.client
- an optional object implementing the OnServiceConnectedListener interface, for receiving connection notifications from the service.
-
-
Method Detail
-
getServiceIntentAction
protected abstract String getServiceIntentAction()
-
getServiceIntentPackage
protected String getServiceIntentPackage()
The package which hosts the service to connect to. Returning null is OK for api target < 21. Once you try to build with 21 or higher returning null will cause an illegal argument exception
-
getServiceIntentVersion
@Deprecated protected int getServiceIntentVersion()
Deprecated.Include a version in the service connector action insteadConnectors that are versioned include a version number in the action returned bygetServiceIntentAction()
instead of using this mechanism.
-
connect
public boolean connect()
-
isInstalled
public boolean isInstalled()
-
getStartIntent
protected Intent getStartIntent()
-
disconnect
public void disconnect()
-
waitForConnection
protected S waitForConnection() throws BindingException
- Throws:
BindingException
-
isConnected
public boolean isConnected()
Returns whether we are connected to the order service- Returns:
- true if we are connected, false otherwise
-
getService
public S getService()
Returns the order service interface- Returns:
- Service if we are connected, null otherwise
-
execute
protected void execute(ServiceConnector.ServiceRunnable<S> runnable) throws RemoteException, ClientException, ServiceException, BindingException
-
execute
protected <T> T execute(ServiceConnector.ServiceCallable<S,T> callable) throws RemoteException, ClientException, ServiceException, BindingException
-
execute
protected <T> void execute(ServiceConnector.ServiceCallable<S,T> callable, ServiceConnector.Callback<T> callback)
-
execute
protected void execute(ServiceConnector.ServiceRunnable<S> runnable, ServiceConnector.Callback<Void> callback)
-
throwOnFailure
protected void throwOnFailure(ResultStatus status) throws ClientException, ServiceException
- Throws:
ClientException
ServiceException
-
postResults
protected <T> void postResults(T result, ResultStatus status, ServiceConnector.Callback<T> callback)
-
notifyServiceConnected
protected void notifyServiceConnected(ServiceConnector.OnServiceConnectedListener client)
-
notifyServiceDisconnected
protected void notifyServiceDisconnected(ServiceConnector.OnServiceConnectedListener client)
-
onServiceConnected
public final void onServiceConnected(ComponentName componentName, IBinder iBinder)
Part of the ServiceConnection interface. Do not call.- Specified by:
onServiceConnected
in interfaceServiceConnection
-
onServiceDisconnected
public final void onServiceDisconnected(ComponentName componentName)
Part of the ServiceConnection interface. Do not call.- Specified by:
onServiceDisconnected
in interfaceServiceConnection
-
-