package com.kozen.printerlibrary;

import android.content.Context;
import android.content.Intent;

public class InnerPrinterManager {
    public static final String PRINTER_PACKAGE = "com.xcheng.printerservice";

    private InnerPrinterManager(){
    }
    private static class SingletonContainer{
        private static InnerPrinterManager instance = new InnerPrinterManager();
    }
    public static InnerPrinterManager getInstance(){
        return SingletonContainer.instance;
    }

    public boolean bindService(Context mContext, InnerPrinterCallback callback) throws InnerPrinterException {
        if(mContext == null || callback == null){
            throw new InnerPrinterException("parameter must be not null!");
        }
        Intent intent = new Intent();
        intent.setPackage(PRINTER_PACKAGE);
        intent.setAction(PRINTER_PACKAGE + ".IPrinterService");
        return mContext.getApplicationContext().bindService(intent, callback, Context.BIND_AUTO_CREATE);
    }

    public void unBindService(Context mContext, InnerPrinterCallback callback) throws InnerPrinterException {
        if(mContext == null || callback == null){
            throw new InnerPrinterException("parameter must be not null!");
        }
        mContext.getApplicationContext().unbindService(callback);
    }
}
