Search in sources :

Example 1 with DevOptionHandler

use of com.alibaba.weex.commons.util.DevOptionHandler in project weex-example by KalicyZhou.

the class WXPageActivity method showDevOptionsDialog.

public void showDevOptionsDialog() {
    if (mDevOptionsDialog != null || !mIsDevSupportEnabled || ActivityManager.isUserAMonkey()) {
        return;
    }
    LinkedHashMap<String, DevOptionHandler> options = new LinkedHashMap<>();
    /* register standard options */
    options.put(getString(R.string.scan_qr_code), new DevOptionHandler() {

        @Override
        public void onOptionSelected() {
            IntentIntegrator integrator = new IntentIntegrator(WXPageActivity.this);
            integrator.setDesiredBarcodeFormats(IntentIntegrator.QR_CODE_TYPES);
            integrator.setPrompt("Scan a barcode");
            //integrator.setCameraId(0);  // Use a specific camera of the device
            integrator.setBeepEnabled(true);
            integrator.setOrientationLocked(false);
            integrator.setBarcodeImageEnabled(true);
            integrator.setPrompt(getString(R.string.capture_qrcode_prompt));
            integrator.initiateScan();
        }
    });
    options.put(getString(R.string.page_refresh), new DevOptionHandler() {

        @Override
        public void onOptionSelected() {
            createWeexInstance();
            renderPage();
        }
    });
    if (mCustomDevOptions.size() > 0) {
        options.putAll(mCustomDevOptions);
    }
    final DevOptionHandler[] optionHandlers = options.values().toArray(new DevOptionHandler[0]);
    mDevOptionsDialog = new AlertDialog.Builder(WXPageActivity.this).setItems(options.keySet().toArray(new String[0]), new DialogInterface.OnClickListener() {

        @Override
        public void onClick(DialogInterface dialog, int which) {
            optionHandlers[which].onOptionSelected();
            mDevOptionsDialog = null;
        }
    }).setOnCancelListener(new DialogInterface.OnCancelListener() {

        @Override
        public void onCancel(DialogInterface dialog) {
            mDevOptionsDialog = null;
        }
    }).create();
    mDevOptionsDialog.getWindow().setType(WindowManager.LayoutParams.TYPE_SYSTEM_ALERT);
    mDevOptionsDialog.show();
}
Also used : DevOptionHandler(com.alibaba.weex.commons.util.DevOptionHandler) DialogInterface(android.content.DialogInterface) IntentIntegrator(com.google.zxing.integration.android.IntentIntegrator) LinkedHashMap(java.util.LinkedHashMap)

Aggregations

DialogInterface (android.content.DialogInterface)1 DevOptionHandler (com.alibaba.weex.commons.util.DevOptionHandler)1 IntentIntegrator (com.google.zxing.integration.android.IntentIntegrator)1 LinkedHashMap (java.util.LinkedHashMap)1