Java Code Examples for com.taobao.weex.bridge.JSCallback#invoke()

The following examples show how to use com.taobao.weex.bridge.JSCallback#invoke() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: WXClipboardModule.java    From ucar-weex-core with Apache License 2.0 6 votes vote down vote up
@Override
@JSMethod
public void getString(@Nullable JSCallback callback) {
    Context context = mWXSDKInstance.getContext();
    ClipboardManager clipboard = (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE);

    Map<String, Object> map = new HashMap<>(2);
    ClipData clip = clipboard.getPrimaryClip();
    if (clip != null && clip.getItemCount() > 0) {
        ClipData.Item item = clip.getItemAt(0);
        CharSequence text = coerceToText(context, item);

        map.put(RESULT, text != null ? RESULT_OK : RESULT_FAILED);
        map.put(DATA, text != null ? text : "");
    } else {
        map.put(RESULT, RESULT_FAILED);
        map.put(DATA, "");
    }

    if (null != callback) {
        callback.invoke(map);
    }
}
 
Example 2
Source File: WXNavigatorModule.java    From ucar-weex-core with Apache License 2.0 6 votes vote down vote up
@JSMethod(uiThread = true)
public void close(JSONObject options, JSCallback success, JSCallback failure) {
    JSONObject result = new JSONObject();
    JSCallback callback = null;
    if (mWXSDKInstance.getContext() instanceof Activity) {
        callback = success;
        ((Activity) mWXSDKInstance.getContext()).finish();
    } else {
        result.put(CALLBACK_RESULT, MSG_FAILED);
        result.put(CALLBACK_MESSAGE, "Close page failed.");
        callback = failure;
    }
    if (callback != null) {
        callback.invoke(result);
    }
}
 
Example 3
Source File: UWXNavigatorModule2.java    From ucar-weex-core with Apache License 2.0 6 votes vote down vote up
@JSMethod(uiThread = true)
public void setNavBarTitle(String param, JSCallback callback) {
    if (!TextUtils.isEmpty(param)) {
        if (WXSDKEngine.getActivityNavBarSetter() != null) {
            if (WXSDKEngine.getActivityNavBarSetter().setNavBarTitle(param)) {
                if (callback != null) {
                    callback.invoke(MSG_SUCCESS);
                }
                return;
            }
        }
    }
    if (callback != null) {
        callback.invoke(MSG_FAILED);
    }
}
 
Example 4
Source File: WXNavigatorModule.java    From ucar-weex-core with Apache License 2.0 6 votes vote down vote up
@JSMethod(uiThread = true)
public void setNavBarTitle(String param, JSCallback callback) {
    if (!TextUtils.isEmpty(param)) {
        if (WXSDKEngine.getActivityNavBarSetter() != null) {
            if (WXSDKEngine.getActivityNavBarSetter().setNavBarTitle(param)) {
                if (callback != null) {
                    callback.invoke(MSG_SUCCESS);
                }
                return;
            }
        }
    }
    if (callback != null) {
        callback.invoke(MSG_FAILED);
    }
}
 
Example 5
Source File: UWXNavigatorModule2.java    From ucar-weex-core with Apache License 2.0 6 votes vote down vote up
@JSMethod(uiThread = true)
public void setNavBarMoreItem(String param, JSCallback callback) {
    if (!TextUtils.isEmpty(param)) {
        if (WXSDKEngine.getActivityNavBarSetter() != null) {
            if (WXSDKEngine.getActivityNavBarSetter().setNavBarMoreItem(param)) {
                if (callback != null) {
                    callback.invoke(MSG_SUCCESS);
                }
                return;
            }
        }
    }

    if (callback != null) {
        callback.invoke(MSG_FAILED);
    }
}
 
Example 6
Source File: UWXNavigatorModule2.java    From ucar-weex-core with Apache License 2.0 6 votes vote down vote up
@JSMethod(uiThread = true)
public void setNavBarLeftItem(String param, JSCallback callback) {
    if (!TextUtils.isEmpty(param)) {
        if (WXSDKEngine.getActivityNavBarSetter() != null) {
            if (WXSDKEngine.getActivityNavBarSetter().setNavBarLeftItem(param)) {
                if (callback != null) {
                    callback.invoke(MSG_SUCCESS);
                }
                return;
            }
        }
    }

    if (callback != null) {
        callback.invoke(MSG_FAILED);
    }

}
 
Example 7
Source File: WXNavigatorModule.java    From weex-uikit with MIT License 6 votes vote down vote up
@JSMethod(uiThread = true)
public void close(JSONObject options, JSCallback success, JSCallback failure) {
    JSONObject result = new JSONObject();
    JSCallback callback = null;
    if (mWXSDKInstance.getContext() instanceof Activity) {
        callback = success;
        ((Activity) mWXSDKInstance.getContext()).finish();
    } else {
        result.put(CALLBACK_RESULT, MSG_FAILED);
        result.put(CALLBACK_MESSAGE, "close page failed");
        callback = failure;
    }
    if (callback != null) {
        callback.invoke(result);
    }
}
 
Example 8
Source File: UWXNavigatorModule2.java    From ucar-weex-core with Apache License 2.0 6 votes vote down vote up
@JSMethod(uiThread = true)
public void pop(String param, JSCallback callback) {

    if (WXSDKEngine.getActivityNavBarSetter() != null) {
        if (WXSDKEngine.getActivityNavBarSetter().pop(param)) {
            if (callback != null) {
                callback.invoke(MSG_SUCCESS);
            }
            return;
        }
    }

    if (mWXSDKInstance.getContext() instanceof Activity) {
        if (callback != null) {
            callback.invoke(MSG_SUCCESS);
        }
        ((Activity) mWXSDKInstance.getContext()).finish();
    }
}
 
Example 9
Source File: WXWsonTestModule.java    From incubator-weex-playground with Apache License 2.0 5 votes vote down vote up
@JSMethod(uiThread = false)
public void  backAsync(JSONObject params, JSCallback callback) {
    JSONObject back = new JSONObject(params);
    back.put("longMax", Long.MAX_VALUE);
    back.put("longMin", Long.MIN_VALUE);
    back.put("javaJSON", back.toJSONString());
    callback.invoke(back);
}
 
Example 10
Source File: WXNavigatorModule.java    From weex-uikit with MIT License 5 votes vote down vote up
@JSMethod(uiThread = true)
public void clearNavBarLeftItem(String param, JSCallback callback) {
    if (WXSDKEngine.getActivityNavBarSetter() != null) {
        if (WXSDKEngine.getActivityNavBarSetter().clearNavBarLeftItem(param)) {
            callback.invoke(MSG_SUCCESS);
            return;
        }
    }

    callback.invoke(MSG_FAILED);
}
 
Example 11
Source File: WXNavigatorModule.java    From weex-uikit with MIT License 5 votes vote down vote up
@JSMethod(uiThread = true)
public void pop(String param, JSCallback callback) {

    if (WXSDKEngine.getActivityNavBarSetter() != null) {
        if (WXSDKEngine.getActivityNavBarSetter().pop(param)) {
            callback.invoke(MSG_SUCCESS);
            return;
        }
    }

    if (mWXSDKInstance.getContext() instanceof Activity) {
        callback.invoke(MSG_SUCCESS);
        ((Activity) mWXSDKInstance.getContext()).finish();
    }
}
 
Example 12
Source File: WXNavigatorModule.java    From weex-uikit with MIT License 5 votes vote down vote up
@JSMethod(uiThread = true)
public void setNavBarRightItem(String param, JSCallback callback) {
    if (!TextUtils.isEmpty(param)) {
        if (WXSDKEngine.getActivityNavBarSetter() != null) {
            if (WXSDKEngine.getActivityNavBarSetter().setNavBarRightItem(param)) {
                callback.invoke(MSG_SUCCESS);
                return;
            }
        }
    }

    callback.invoke(MSG_FAILED);
}
 
Example 13
Source File: UWXNavigatorModule2.java    From ucar-weex-core with Apache License 2.0 5 votes vote down vote up
@JSMethod(uiThread = true)
public void open(JSONObject options, JSCallback success, JSCallback failure) {
    if (options != null) {
        String url = options.getString(Constants.Value.URL);
        JSCallback callback = success;
        JSONObject result = new JSONObject();
        if (!TextUtils.isEmpty(url)) {
            Uri rawUri = Uri.parse(url);
            String scheme = rawUri.getScheme();
            if (TextUtils.isEmpty(scheme) || Constants.Scheme.HTTP.equalsIgnoreCase(scheme) || Constants.Scheme.HTTPS.equalsIgnoreCase(scheme)) {
                this.push(options.toJSONString(), success);
            } else {
                try {
                    Intent intent = new Intent(Intent.ACTION_VIEW, rawUri);
                    mWXSDKInstance.getContext().startActivity(intent);
                    result.put(CALLBACK_RESULT, MSG_SUCCESS);
                } catch (Throwable e) {
                    e.printStackTrace();
                    result.put(CALLBACK_RESULT, MSG_FAILED);
                    result.put(CALLBACK_MESSAGE, "Open page failed.");
                    callback = failure;
                }
            }
        } else {
            result.put(CALLBACK_RESULT, MSG_PARAM_ERR);
            result.put(CALLBACK_MESSAGE, "The URL parameter is empty.");
            callback = failure;
        }

        if(callback != null){
            callback.invoke(result);
        }
    }
}
 
Example 14
Source File: UWXNavigatorModule.java    From ucar-weex-core with Apache License 2.0 5 votes vote down vote up
@JSMethod
public void quit(JSCallback callback) {
    AppExitUtil.quitApp(mWXSDKInstance.getContext());
    if (callback != null) {
        callback.invoke(MSG_SUCCESS);
    }
}
 
Example 15
Source File: UWXNavigatorModule.java    From ucar-weex-core with Apache License 2.0 5 votes vote down vote up
@JSMethod
public void home(String params, JSCallback callback) {

    if (callback != null) {
        callback.invoke(MSG_SUCCESS);
    }
}
 
Example 16
Source File: WXDomManager.java    From weex-uikit with MIT License 5 votes vote down vote up
/**
 * Gets the coordinate information of the control
 * @param instanceId wxsdkinstance id
 * @param ref ref
 * @param callback callback
 */
public void getComponentSize(String instanceId, String ref, JSCallback callback) {
  if (!isDomThread()) {
    throw new WXRuntimeException("getComponentSize operation must be done in dom thread");
  }
  WXDomStatement statement = mDomRegistries.get(instanceId);
  if (statement == null) {
    Map<String, Object> options = new HashMap<>();
    options.put("result", false);
    options.put("errMsg", "Component does not exist");
    callback.invoke(options);
    return;
  }
  statement.getComponentSize(ref, callback);
}
 
Example 17
Source File: WXNavigatorModule.java    From ucar-weex-core with Apache License 2.0 5 votes vote down vote up
@JSMethod(uiThread = true)
public void open(JSONObject options, JSCallback success, JSCallback failure) {
    if (options != null) {
        String url = options.getString(Constants.Value.URL);
        JSCallback callback = success;
        JSONObject result = new JSONObject();
        if (!TextUtils.isEmpty(url)) {
            Uri rawUri = Uri.parse(url);
            String scheme = rawUri.getScheme();
            if (TextUtils.isEmpty(scheme) || Constants.Scheme.HTTP.equalsIgnoreCase(scheme) || Constants.Scheme.HTTPS.equalsIgnoreCase(scheme)) {
                this.push(options.toJSONString(), success);
            } else {
                try {
                    Intent intent = new Intent(Intent.ACTION_VIEW, rawUri);
                    mWXSDKInstance.getContext().startActivity(intent);
                    result.put(CALLBACK_RESULT, MSG_SUCCESS);
                } catch (Throwable e) {
                    e.printStackTrace();
                    result.put(CALLBACK_RESULT, MSG_FAILED);
                    result.put(CALLBACK_MESSAGE, "Open page failed.");
                    callback = failure;
                }
            }
        } else {
            result.put(CALLBACK_RESULT, MSG_PARAM_ERR);
            result.put(CALLBACK_MESSAGE, "The URL parameter is empty.");
            callback = failure;
        }

        if(callback != null){
            callback.invoke(result);
        }
    }
}
 
Example 18
Source File: WXWsonTestModule.java    From incubator-weex-playground with Apache License 2.0 5 votes vote down vote up
@JSMethod(uiThread = false)
public void switchTrans(JSCallback callback) {
    if(WXWsonJSONSwitch.USE_WSON){
        WXBridgeManager.updateGlobalConfig("wson_off");
        callback.invoke("wson off, use json");
    }else{
        WXBridgeManager.updateGlobalConfig("wson_on");
        callback.invoke("wson on, use wson");
    }
}
 
Example 19
Source File: UWXNavigatorModule2.java    From ucar-weex-core with Apache License 2.0 4 votes vote down vote up
@JSMethod(uiThread = true)
public void push(String param, JSCallback callback) {

    if (!TextUtils.isEmpty(param)) {
        if (WXSDKEngine.getActivityNavBarSetter() != null) {
            if (WXSDKEngine.getActivityNavBarSetter().push(param)) {
                if (callback != null) {
                    callback.invoke(MSG_SUCCESS);
                }
                return;
            }
        }

        try {
            JSONObject jsonObject = JSON.parseObject(param);
            String url = jsonObject.getString(URL);
            if (!TextUtils.isEmpty(url)) {
                Uri rawUri = Uri.parse(url);
                String scheme = rawUri.getScheme();
                Uri.Builder builder = rawUri.buildUpon();
                if (TextUtils.isEmpty(scheme)) {
                    builder.scheme(Constants.Scheme.HTTP);
                }
                Intent intent = new Intent(Intent.ACTION_VIEW, builder.build());
                intent.addCategory(WEEX);
                intent.putExtra(INSTANCE_ID, mWXSDKInstance.getInstanceId());
                mWXSDKInstance.getContext().startActivity(intent);
                if (callback != null) {
                    callback.invoke(MSG_SUCCESS);
                }
            }
        } catch (Exception e) {
            WXLogUtils.eTag(TAG, e);
            if (callback != null) {
                callback.invoke(MSG_FAILED);
            }
        }
    } else if (callback != null) {
        callback.invoke(MSG_FAILED);
    }
}
 
Example 20
Source File: UWXNavigatorModule.java    From ucar-weex-core with Apache License 2.0 4 votes vote down vote up
@JSMethod
public void pushNative(String encodeParam, JSCallback callback) {
    if (TextUtils.isEmpty(encodeParam)) {
        return;
    }
    try {
        JSONObject options = JSON.parseObject(encodeParam);
        String url = "";
        UWXTheme.NavBar navBar = null;
        JSONObject param = null;
        if (options.containsKey(UWXBundleInfo.KEY_URL)) {
            url = options.getString(UWXBundleInfo.KEY_URL);
        }
        if (options.containsKey(UWXBundleInfo.KEY_NAV_BAR)) {
            String _navBar = options.getString(UWXBundleInfo.KEY_NAV_BAR);
            if (!TextUtils.isEmpty(_navBar)) {
                navBar = JSON.parseObject(_navBar, UWXTheme.NavBar.class);
            }
        }
        if (options.containsKey(UWXBundleInfo.KEY_PARAM)) {
            param = options.getJSONObject(UWXBundleInfo.KEY_PARAM);
        }
        UWLog.v("params=" + encodeParam);
        if (!TextUtils.isEmpty(url)) {
            UWXNavigatorAdapter navigatorAdapter = UWXSDKManager.getInstance().getNavigatorAdapter();
            if (navigatorAdapter != null) {
                navigatorAdapter.pushNative((Activity) mWXSDKInstance.getContext(),url ,param);
                if (callback != null) {
                    callback.invoke(MSG_SUCCESS);
                }
            }
        } else {
            callback.invoke(MSG_FAILED);
        }
    } catch (Exception e) {
        WXLogUtils.eTag(TAG, e);
        if (callback != null) {
            callback.invoke(MSG_FAILED);
        }
    }
}