|
|
@@ -1,8 +1,31 @@
|
|
|
-package cordova-plugin-umeng;
|
|
|
+package com.umeng;
|
|
|
|
|
|
+import android.content.Context;
|
|
|
+import android.content.pm.ActivityInfo;
|
|
|
+import android.graphics.Color;
|
|
|
+import android.os.Build;
|
|
|
+import android.util.Log;
|
|
|
+import android.util.TypedValue;
|
|
|
+import android.view.View;
|
|
|
+import android.widget.RelativeLayout;
|
|
|
+import android.widget.TextView;
|
|
|
+
|
|
|
+import com.nirvana.tools.core.ExecutorManager;
|
|
|
+import com.umeng.commonsdk.UMConfigure;
|
|
|
+import com.umeng.umverify.UMResultCode;
|
|
|
+import com.umeng.umverify.UMVerifyHelper;
|
|
|
+import com.umeng.umverify.listener.UMCustomInterface;
|
|
|
+import com.umeng.umverify.listener.UMPreLoginResultListener;
|
|
|
+import com.umeng.umverify.listener.UMTokenResultListener;
|
|
|
+import com.umeng.umverify.model.UMTokenRet;
|
|
|
+import com.umeng.umverify.view.UMAuthRegisterViewConfig;
|
|
|
+import com.umeng.umverify.view.UMAuthUIConfig;
|
|
|
+
|
|
|
+import org.apache.cordova.CordovaInterface;
|
|
|
import org.apache.cordova.CordovaPlugin;
|
|
|
import org.apache.cordova.CallbackContext;
|
|
|
|
|
|
+import org.apache.cordova.CordovaWebView;
|
|
|
import org.json.JSONArray;
|
|
|
import org.json.JSONException;
|
|
|
import org.json.JSONObject;
|
|
|
@@ -11,6 +34,11 @@ import org.json.JSONObject;
|
|
|
* This class echoes a string called from JavaScript.
|
|
|
*/
|
|
|
public class UmengPlugin extends CordovaPlugin {
|
|
|
+ private final static String TAG = "CordovUmengPlugin";
|
|
|
+
|
|
|
+ private UMVerifyHelper mPhoneNumberAuthHelper;
|
|
|
+
|
|
|
+ private boolean sdkAvailable = true;
|
|
|
|
|
|
@Override
|
|
|
public boolean execute(String action, JSONArray args, CallbackContext callbackContext) throws JSONException {
|
|
|
@@ -22,6 +50,115 @@ public class UmengPlugin extends CordovaPlugin {
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ public void initialize(CordovaInterface cordova, CordovaWebView webView) {
|
|
|
+ super.initialize(cordova, webView);
|
|
|
+ UMConfigure.init(cordova.getContext(), "62b8106188ccdf4b7eaba3e8", "android", UMConfigure.DEVICE_TYPE_PHONE, "");
|
|
|
+ mPhoneNumberAuthHelper = UMVerifyHelper.getInstance(this.cordova.getContext(), new UMTokenResultListener() {
|
|
|
+ @Override
|
|
|
+ public void onTokenSuccess(String s) {
|
|
|
+ try {
|
|
|
+ Log.i(TAG, "checkEnvAvailable:" + s);
|
|
|
+ UMTokenRet tokenRet = UMTokenRet.fromJson(s);
|
|
|
+ if (UMResultCode.CODE_ERROR_ENV_CHECK_SUCCESS.equals(tokenRet.getCode())) {
|
|
|
+ accelerateLoginPage(5000);
|
|
|
+ }
|
|
|
+ if (UMResultCode.CODE_START_AUTHPAGE_SUCCESS.equals(tokenRet.getCode())) {
|
|
|
+ Log.i("TAG", "唤起授权页成功:" + s);
|
|
|
+ }
|
|
|
+
|
|
|
+ if (UMResultCode.CODE_SUCCESS.equals(tokenRet.getCode())) {
|
|
|
+ Log.i("TAG", "获取token成功:" + s);
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onTokenFailed(String s) {
|
|
|
+ sdkAvailable = false;
|
|
|
+ Log.e(TAG, "checkEnvAvailable:" + s);
|
|
|
+ //终端环境检查失败之后 跳转到其他号码校验方式
|
|
|
+ }
|
|
|
+ });
|
|
|
+ mPhoneNumberAuthHelper.setAuthSDKInfo("+oY1et2uQC/WwXWcPQqu+zRSrAxcdgTmyIiyWbtmhWoxYNMifV3qkKzpnEtiIQ+MQe/CqLFIvCdkqcO9CSkhWhQWx5DJT126HlDHzzK3b5UslXnS4LqopbJdEUjNmLCpM+khgkgzmVOnrqvlr3dIr2OPp1FgYEnj6P6pmMyLIisULU0madYyszsdFT1DQ1D5ogxTgeJnPgtmDq70vDg+INvObRDvzRZ3fGPDHKKwWCtwJA2VLeDh/fKkqVDThETyy5z8b3fD4igdO3iH41JnSlHlTWbA05yYtWs+ujETuyw=");
|
|
|
+ mPhoneNumberAuthHelper.checkEnvAvailable(UMVerifyHelper.SERVICE_TYPE_LOGIN);
|
|
|
+ }
|
|
|
+
|
|
|
+ public void login() {
|
|
|
+ mPhoneNumberAuthHelper.addAuthRegistViewConfig("switch_acc_tv", new UMAuthRegisterViewConfig.Builder()
|
|
|
+ .setView(initDynamicView())
|
|
|
+ .setRootViewId(UMAuthRegisterViewConfig.RootViewId.ROOT_VIEW_ID_BODY)
|
|
|
+ .setCustomInterface(new UMCustomInterface() {
|
|
|
+ @Override
|
|
|
+ public void onClick(Context context) {
|
|
|
+ mPhoneNumberAuthHelper.quitLoginPage();
|
|
|
+ }
|
|
|
+ }).build());
|
|
|
+ int authPageOrientation = ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT;
|
|
|
+ if (Build.VERSION.SDK_INT == 26) {
|
|
|
+ authPageOrientation = ActivityInfo.SCREEN_ORIENTATION_BEHIND;
|
|
|
+ }
|
|
|
+ mPhoneNumberAuthHelper.setAuthUIConfig(new UMAuthUIConfig.Builder()
|
|
|
+ .setAppPrivacyOne("《自定义隐私协议》", "https://www.baidu.com")
|
|
|
+ .setAppPrivacyColor(Color.GRAY, Color.parseColor("#002E00"))
|
|
|
+ .setPrivacyState(false)
|
|
|
+ .setCheckboxHidden(true)
|
|
|
+ .setStatusBarColor(Color.TRANSPARENT)
|
|
|
+ .setStatusBarUIFlag(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN)
|
|
|
+ .setLightColor(true)
|
|
|
+ .setVendorPrivacyPrefix("《")
|
|
|
+ .setVendorPrivacySuffix("》")
|
|
|
+ .setLogoImgPath("mytel_app_launcher")
|
|
|
+ .setScreenOrientation(authPageOrientation)
|
|
|
+ .create());
|
|
|
+ }
|
|
|
+
|
|
|
+ private View initDynamicView() {
|
|
|
+ TextView switchTV = new TextView(this.cordova.getContext());
|
|
|
+ RelativeLayout.LayoutParams mLayoutParams2 = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT, dp2px(this.cordova.getContext(), 50));
|
|
|
+ mLayoutParams2.addRule(RelativeLayout.CENTER_HORIZONTAL, RelativeLayout.TRUE);
|
|
|
+ mLayoutParams2.setMargins(0, dp2px(this.cordova.getContext(), 450), 0, 0);
|
|
|
+ switchTV.setText("----- 自定义view -----");
|
|
|
+ switchTV.setTextColor(0xff999999);
|
|
|
+ switchTV.setTextSize(TypedValue.COMPLEX_UNIT_SP, 13.0F);
|
|
|
+ switchTV.setLayoutParams(mLayoutParams2);
|
|
|
+ return switchTV;
|
|
|
+ }
|
|
|
+
|
|
|
+ public static int dp2px(Context context, float dipValue) {
|
|
|
+ try {
|
|
|
+ final float scale = context.getResources().getDisplayMetrics().density;
|
|
|
+ return (int) (dipValue * scale + 0.5f);
|
|
|
+ } catch (Exception e) {
|
|
|
+ return (int) dipValue;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public static int px2dp(Context context, float px) {
|
|
|
+ try {
|
|
|
+ final float scale = context.getResources().getDisplayMetrics().density;
|
|
|
+ return (int) (px / scale + 0.5f);
|
|
|
+ } catch (Exception e) {
|
|
|
+ return (int) px;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public void accelerateLoginPage(int timeout) {
|
|
|
+ mPhoneNumberAuthHelper.accelerateLoginPage(timeout, new UMPreLoginResultListener() {
|
|
|
+ @Override
|
|
|
+ public void onTokenSuccess(String s) {
|
|
|
+ Log.e(TAG, "预取号成功: " + s);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onTokenFailed(String s, String s1) {
|
|
|
+ Log.e(TAG, "预取号失败:" + ", " + s1);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
private void coolMethod(String message, CallbackContext callbackContext) {
|
|
|
if (message != null && message.length() > 0) {
|
|
|
callbackContext.success(message);
|