com.taobao.weex.annotation.JSMethod Java Examples

The following examples show how to use com.taobao.weex.annotation.JSMethod. 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: WXNavigatorModule.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 #2
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 #3
Source File: WXStorageModule.java    From weex-uikit with MIT License 6 votes vote down vote up
@Override
@JSMethod(uiThread = false)
public void setItem(String key, String value, @Nullable final JSCallback callback) {
    if (TextUtils.isEmpty(key) || value == null) {
        StorageResultHandler.handleInvalidParam(callback);
        return;
    }

    IWXStorageAdapter adapter = ability();
    if (adapter == null) {
        StorageResultHandler.handleNoHandlerError(callback);
        return;
    }
    adapter.setItem(key, value, new IWXStorageAdapter.OnResultReceivedListener() {
        @Override
        public void onReceived(Map<String, Object> data) {
            if(callback != null){
                callback.invoke(data);
            }
        }
    });


}
 
Example #4
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 #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: WXStorageModule.java    From ucar-weex-core with Apache License 2.0 6 votes vote down vote up
@Override
@JSMethod(uiThread = false)
public void setItem(String key, String value, @Nullable final JSCallback callback) {
    if (TextUtils.isEmpty(key) || value == null) {
        StorageResultHandler.handleInvalidParam(callback);
        return;
    }

    IWXStorageAdapter adapter = ability();
    if (adapter == null) {
        StorageResultHandler.handleNoHandlerError(callback);
        return;
    }
    adapter.setItem(key, value, new IWXStorageAdapter.OnResultReceivedListener() {
        @Override
        public void onReceived(Map<String, Object> data) {
            if(callback != null){
                callback.invoke(data);
            }
        }
    });


}
 
Example #7
Source File: WXStorageModule.java    From ucar-weex-core with Apache License 2.0 6 votes vote down vote up
@Override
@JSMethod(uiThread = false)
public void getItem(String key, @Nullable final JSCallback callback) {
    if (TextUtils.isEmpty(key)) {
        StorageResultHandler.handleInvalidParam(callback);
        return;
    }

    IWXStorageAdapter adapter = ability();
    if (adapter == null) {
        StorageResultHandler.handleNoHandlerError(callback);
        return;
    }
    adapter.getItem(key, new IWXStorageAdapter.OnResultReceivedListener() {
        @Override
        public void onReceived(Map<String, Object> data) {
            if(callback != null){
                callback.invoke(data);
            }
        }
    });
}
 
Example #8
Source File: WXStorageModule.java    From ucar-weex-core with Apache License 2.0 6 votes vote down vote up
@Override
@JSMethod(uiThread = false)
public void length(@Nullable final JSCallback callback) {
    IWXStorageAdapter adapter = ability();
    if (adapter == null) {
        StorageResultHandler.handleNoHandlerError(callback);
        return;
    }
    adapter.length(new IWXStorageAdapter.OnResultReceivedListener() {
        @Override
        public void onReceived(Map<String, Object> data) {
            if(callback != null){
                callback.invoke(data);
            }
        }
    });
}
 
Example #9
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 #10
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 #11
Source File: WXNavigatorModule.java    From ucar-weex-core with Apache License 2.0 6 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)) {
                if (callback != null) {
                    callback.invoke(MSG_SUCCESS);
                }
                return;
            }
        }
    }

    if (callback != null) {
        callback.invoke(MSG_FAILED);
    }
}
 
Example #12
Source File: WXNavigatorModule.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 #13
Source File: UWXNavigatorModule2.java    From ucar-weex-core with Apache License 2.0 6 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)) {
                if (callback != null) {
                    callback.invoke(MSG_SUCCESS);
                }
                return;
            }
        }
    }

    if (callback != null) {
        callback.invoke(MSG_FAILED);
    }
}
 
Example #14
Source File: WXNavigatorModule.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 #15
Source File: WXStorageModule.java    From weex-uikit with MIT License 6 votes vote down vote up
@Override
@JSMethod(uiThread = false)
public void removeItem(String key, @Nullable final JSCallback callback) {
    if (TextUtils.isEmpty(key)) {
        StorageResultHandler.handleInvalidParam(callback);
        return;
    }

    IWXStorageAdapter adapter = ability();
    if (adapter == null) {
        StorageResultHandler.handleNoHandlerError(callback);
        return;
    }
    adapter.removeItem(key, new IWXStorageAdapter.OnResultReceivedListener() {
        @Override
        public void onReceived(Map<String, Object> data) {
            if(callback != null){
                callback.invoke(data);
            }
        }
    });
}
 
Example #16
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 #17
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 #18
Source File: WXTitleBar.java    From incubator-weex-playground with Apache License 2.0 5 votes vote down vote up
@JSMethod
public void setTitle(String title) {
  ActionBar actionBar = getActionBar();
  if (actionBar != null) {
    actionBar.setTitle(String.valueOf(title));
  }
}
 
Example #19
Source File: WXNavigatorModule.java    From ucar-weex-core with Apache License 2.0 5 votes vote down vote up
@JSMethod(uiThread = true)
public void clearNavBarMoreItem(String param, JSCallback callback) {
    if (WXSDKEngine.getActivityNavBarSetter() != null) {
        if (WXSDKEngine.getActivityNavBarSetter().clearNavBarMoreItem(param)) {
            if (callback != null) {
                callback.invoke(MSG_SUCCESS);
            }
            return;
        }
    }

    if (callback != null) {
        callback.invoke(MSG_FAILED);
    }
}
 
Example #20
Source File: WXNavigatorModule.java    From ucar-weex-core with Apache License 2.0 5 votes vote down vote up
@JSMethod
public void setNavBarHidden(String param, final String callback) {
    String message = MSG_FAILED;
    try {
        JSONObject jsObj = JSON.parseObject(param);
        int visibility = jsObj.getInteger(Constants.Name.NAV_BAR_VISIBILITY);
        boolean success = changeVisibilityOfActionBar(mWXSDKInstance.getContext(), visibility);
        if (success) {
            message = MSG_SUCCESS;
        }
    } catch (JSONException e) {
        WXLogUtils.e(TAG, WXLogUtils.getStackTrace(e));
    }
    WXBridgeManager.getInstance().callback(mWXSDKInstance.getInstanceId(), callback, message);
}
 
Example #21
Source File: WebSocketModule.java    From ucar-weex-core with Apache License 2.0 5 votes vote down vote up
@JSMethod
public void WebSocket(String url, String protocol) {
    if (webSocketAdapter != null) {
        webSocketAdapter.close(WebSocketCloseCodes.CLOSE_GOING_AWAY.getCode(), WebSocketCloseCodes.CLOSE_GOING_AWAY.name());
    }
    webSocketAdapter = mWXSDKInstance.getWXWebSocketAdapter();
    if (!reportErrorIfNoAdapter()) {
        webSocketAdapter.connect(url, protocol, eventListener);
    }
}
 
Example #22
Source File: WXNavigatorModule.java    From ucar-weex-core with Apache License 2.0 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)) {
            if (callback != null) {
                callback.invoke(MSG_SUCCESS);
            }
            return;
        }
    }

    if (callback != null) {
        callback.invoke(MSG_FAILED);
    }
}
 
Example #23
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 #24
Source File: WebSocketModule.java    From ucar-weex-core with Apache License 2.0 5 votes vote down vote up
@JSMethod
public void close(String code, String reason) {
    if (!reportErrorIfNoAdapter()) {
        int codeNumber = WebSocketCloseCodes.CLOSE_NORMAL.getCode();
        if (code != null) {
            try {
                codeNumber = Integer.parseInt(code);
            } catch (NumberFormatException e) {
                //ignore
            }
        }
        webSocketAdapter.close(codeNumber, reason);
    }
}
 
Example #25
Source File: WXModalUIModule.java    From weex-uikit with MIT License 5 votes vote down vote up
@JSMethod(uiThread = true)
public void toast(String param) {

  String message = "";
  int duration = Toast.LENGTH_SHORT;
  if (!TextUtils.isEmpty(param)) {
    try {
      param = URLDecoder.decode(param, "utf-8");
      JSONObject jsObj = JSON.parseObject(param);
      message = jsObj.getString(MESSAGE);
      duration = jsObj.getInteger(DURATION);
    } catch (Exception e) {
      WXLogUtils.e("[WXModalUIModule] alert param parse error ", e);
    }
  }
  if (TextUtils.isEmpty(message)) {
    WXLogUtils.e("[WXModalUIModule] toast param parse is null ");
    return;
  }

  if (duration > 3) {
    duration = Toast.LENGTH_LONG;
  } else {
    duration = Toast.LENGTH_SHORT;
  }
  if (toast == null) {
    toast = Toast.makeText(mWXSDKInstance.getContext(), message, duration);
  } else {
    toast.setDuration(duration);
    toast.setText(message);
  }
  toast.setGravity(Gravity.CENTER, 0, 0);
  toast.show();
}
 
Example #26
Source File: UWXGlobalEventModule.java    From ucar-weex-core with Apache License 2.0 5 votes vote down vote up
@JSMethod
public void postGlobalEvent(String eventName, String params) {
    Intent intent = new Intent(WXGlobalEventReceiver.EVENT_ACTION);
    intent.putExtra(WXGlobalEventReceiver.EVENT_NAME, eventName);
    intent.putExtra(WXGlobalEventReceiver.EVENT_PARAMS, params);
    mWXSDKInstance.getContext().sendBroadcast(intent);
}
 
Example #27
Source File: AbstractEditComponent.java    From ucar-weex-core with Apache License 2.0 5 votes vote down vote up
@JSMethod
public void focus() {
  WXEditText host = getHostView();
  if (host != null && !host.hasFocus()) {
    if (getParent() != null) {
      getParent().ignoreFocus();
    }
    host.requestFocus();
    host.setFocusable(true);
    host.setFocusableInTouchMode(true);
    showSoftKeyboard();
  }
}
 
Example #28
Source File: WXModalUIModule.java    From ucar-weex-core with Apache License 2.0 5 votes vote down vote up
@JSMethod(uiThread = true)
public void alert(String param, final JSCallback callback) {

  if (mWXSDKInstance.getContext() instanceof Activity) {

    String message = "";
    String okTitle = OK;
    if (!TextUtils.isEmpty(param)) {
      try {
        param = URLDecoder.decode(param, "utf-8");
        JSONObject jsObj = JSON.parseObject(param);
        message = jsObj.getString(MESSAGE);
        okTitle = jsObj.getString(OK_TITLE);
      } catch (Exception e) {
        WXLogUtils.e("[WXModalUIModule] alert param parse error ", e);
      }
    }
    if (TextUtils.isEmpty(message)) {
      message = "";
    }
    AlertDialog.Builder builder = new AlertDialog.Builder(mWXSDKInstance.getContext());
    builder.setMessage(message);

    final String okTitle_f = TextUtils.isEmpty(okTitle) ? OK : okTitle;
    builder.setPositiveButton(okTitle_f, new OnClickListener() {
      @Override
      public void onClick(DialogInterface dialog, int which) {
        if (callback != null) {
          callback.invoke(okTitle_f);
        }
      }
    });
    AlertDialog alertDialog = builder.create();
    alertDialog.setCanceledOnTouchOutside(false);
    alertDialog.show();
    tracking(alertDialog);
  } else {
    WXLogUtils.e("[WXModalUIModule] when call alert mWXSDKInstance.getContext() must instanceof Activity");
  }
}
 
Example #29
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 #30
Source File: WXNavigatorModule.java    From weex-uikit with MIT License 5 votes vote down vote up
@JSMethod
public void setNavBarHidden(String param, final String callback) {
    String message = MSG_FAILED;
    try {
        JSONObject jsObj = JSON.parseObject(param);
        int visibility = jsObj.getInteger(Constants.Name.NAV_BAR_VISIBILITY);
        boolean success = changeVisibilityOfActionBar(mWXSDKInstance.getContext(), visibility);
        if (success) {
            message = MSG_SUCCESS;
        }
    } catch (JSONException e) {
        WXLogUtils.e(TAG, WXLogUtils.getStackTrace(e));
    }
    WXBridgeManager.getInstance().callback(mWXSDKInstance.getInstanceId(), callback, message);
}