|  | 
|  | 1 | +package com.symbol.enterprisebarcode; | 
|  | 2 | +import android.content.Context; | 
|  | 3 | +import android.util.Log; | 
|  | 4 | + | 
|  | 5 | +import org.apache.cordova.CallbackContext; | 
|  | 6 | +import org.json.JSONObject; | 
|  | 7 | + | 
|  | 8 | +import java.io.Serializable; | 
|  | 9 | + | 
|  | 10 | +/** | 
|  | 11 | + * The EMDK Proxy class is responsible for determining whether the EMDK is installed on the | 
|  | 12 | + * target device and failing gracefully if it is not installed. | 
|  | 13 | + */ | 
|  | 14 | +public class EMDKProxy implements Serializable { | 
|  | 15 | + | 
|  | 16 | +    private static EMDKScannerInterface emdk = null; | 
|  | 17 | +    private static Context context; | 
|  | 18 | +    private static final String LOG_TAG = "Symbol Barcode"; | 
|  | 19 | + | 
|  | 20 | +    public EMDKProxy(Context c, CallbackContext callbackContext) | 
|  | 21 | +    { | 
|  | 22 | +        if (isEMDKAvailable(c)) | 
|  | 23 | +        { | 
|  | 24 | +            //  Create the EMDK object | 
|  | 25 | +            emdk = new EMDKScannerInterface(c, true, callbackContext); | 
|  | 26 | +            this.context = c; | 
|  | 27 | +        } | 
|  | 28 | +        else | 
|  | 29 | +            EnterpriseBarcode.FailureCallback(callbackContext, "EMDK is not available"); | 
|  | 30 | +    } | 
|  | 31 | + | 
|  | 32 | +    //  Try to link to the EMDK on the device and if it is not there, fail gracefully | 
|  | 33 | +    public static boolean isEMDKAvailable(Context c) | 
|  | 34 | +    { | 
|  | 35 | +        try { | 
|  | 36 | + | 
|  | 37 | +            EMDKScannerInterface test = new EMDKScannerInterface(c, false, null); | 
|  | 38 | +            Log.i(LOG_TAG, "EMDK is available on this device"); | 
|  | 39 | +            return true; | 
|  | 40 | +        } | 
|  | 41 | +        catch (NoClassDefFoundError e) | 
|  | 42 | +        { | 
|  | 43 | +            Log.w(LOG_TAG, "EMDK is not available on this device"); | 
|  | 44 | +            return false; | 
|  | 45 | +        } | 
|  | 46 | +    } | 
|  | 47 | + | 
|  | 48 | +    //  Return the EMDK IsReady() method, true if the EMDK is reporting it is ready | 
|  | 49 | +    public boolean isReady() | 
|  | 50 | +    { | 
|  | 51 | +        if (emdk != null) | 
|  | 52 | +            return emdk.IsReady(); | 
|  | 53 | +        else | 
|  | 54 | +            return false; | 
|  | 55 | +    } | 
|  | 56 | + | 
|  | 57 | +    public static void destroy() | 
|  | 58 | +    { | 
|  | 59 | +        if (emdk != null) | 
|  | 60 | +        { | 
|  | 61 | +            emdk.disableScanner(false, null); | 
|  | 62 | +            emdk.Destroy(); | 
|  | 63 | +        } | 
|  | 64 | +    } | 
|  | 65 | + | 
|  | 66 | +    /** | 
|  | 67 | +     * Public API calls from Plugin interface, pass through to emdk object. | 
|  | 68 | +     */ | 
|  | 69 | +    public JSONObject enumerateScanners(CallbackContext callbackContext) | 
|  | 70 | +    { | 
|  | 71 | +        if (emdk != null) | 
|  | 72 | +            return emdk.enumerateScanners(callbackContext); | 
|  | 73 | +        else | 
|  | 74 | +            return null; | 
|  | 75 | +    } | 
|  | 76 | + | 
|  | 77 | +    /** | 
|  | 78 | +     * Public API calls from Plugin interface, pass through to emdk object. | 
|  | 79 | +     * @param callbackContext | 
|  | 80 | +     * @param userSpecifiedArgumentsToEnable | 
|  | 81 | +     * @return | 
|  | 82 | +     */ | 
|  | 83 | +    public JSONObject enableScanner(CallbackContext callbackContext, JSONObject userSpecifiedArgumentsToEnable) { | 
|  | 84 | +        if (emdk != null) | 
|  | 85 | +            return emdk.enableScanner(callbackContext, userSpecifiedArgumentsToEnable); | 
|  | 86 | +        else { | 
|  | 87 | +            EnterpriseBarcode.FailureCallback(callbackContext, "EMDK is not available"); | 
|  | 88 | +            return null; | 
|  | 89 | +        } | 
|  | 90 | +    } | 
|  | 91 | + | 
|  | 92 | +    /** | 
|  | 93 | +     * Public API calls from Plugin interface, pass through to emdk object. | 
|  | 94 | +     * @param callbackContext | 
|  | 95 | +     * @return | 
|  | 96 | +     */ | 
|  | 97 | +    public JSONObject disableScanner(CallbackContext callbackContext) { | 
|  | 98 | +        if (emdk != null) | 
|  | 99 | +        { | 
|  | 100 | +            emdk.disableScanner(true, callbackContext); | 
|  | 101 | +            return null; | 
|  | 102 | +        } | 
|  | 103 | +        else | 
|  | 104 | +        { | 
|  | 105 | +            EnterpriseBarcode.FailureCallback(callbackContext, "EMDK is not available"); | 
|  | 106 | +            return null; | 
|  | 107 | +        } | 
|  | 108 | +    } | 
|  | 109 | + | 
|  | 110 | +    /** | 
|  | 111 | +     * Public API calls from Plugin interface, pass through to emdk object. | 
|  | 112 | +     * @param callbackContext | 
|  | 113 | +     * @return | 
|  | 114 | +     */ | 
|  | 115 | +    public JSONObject getProperties(CallbackContext callbackContext) | 
|  | 116 | +    { | 
|  | 117 | +        if (emdk != null) | 
|  | 118 | +        { | 
|  | 119 | +            emdk.getProperties(callbackContext); | 
|  | 120 | +            return null; | 
|  | 121 | +        } | 
|  | 122 | +        else | 
|  | 123 | +        { | 
|  | 124 | +            EnterpriseBarcode.FailureCallback(callbackContext, "EMDK is not available"); | 
|  | 125 | +            return null; | 
|  | 126 | +        } | 
|  | 127 | +    } | 
|  | 128 | + | 
|  | 129 | +    /** | 
|  | 130 | +     * Public API calls from Plugin interface, pass through to emdk object. | 
|  | 131 | +     * @param callbackContext | 
|  | 132 | +     * @param arguments | 
|  | 133 | +     */ | 
|  | 134 | +    public void setProperties(CallbackContext callbackContext, JSONObject arguments) | 
|  | 135 | +    { | 
|  | 136 | +        if (emdk != null) | 
|  | 137 | +            emdk.setProperties(callbackContext, arguments); | 
|  | 138 | +        else { | 
|  | 139 | +            EnterpriseBarcode.FailureCallback(callbackContext, "EMDK is not available"); | 
|  | 140 | +            return; | 
|  | 141 | +        } | 
|  | 142 | +    } | 
|  | 143 | +} | 
|  | 144 | + | 
|  | 145 | + | 
0 commit comments