11package cn .jpush .reactnativejvrification ;
22
33import android .Manifest ;
4- import android .util .Log ;
54
65import com .facebook .react .bridge .Arguments ;
76import com .facebook .react .bridge .Callback ;
1312import com .facebook .react .bridge .WritableMap ;
1413
1514import cn .jiguang .verifysdk .api .JVerificationInterface ;
15+ import cn .jiguang .verifysdk .api .JVerifyUIConfig ;
1616import cn .jiguang .verifysdk .api .VerifyListener ;
1717import cn .jpush .reactnativejvrification .utils .AndroidUtils ;
1818
@@ -51,19 +51,13 @@ public void initialize() {
5151 super .initialize ();
5252 }
5353
54- @ ReactMethod
55- public void setup (ReadableMap map ) {
56- JVerificationInterface .init (getCurrentActivity ());
57- }
58-
5954 @ ReactMethod
6055 public void requestPermission (Callback permissionCallback ) {
6156 if (AndroidUtils .checkPermission (getCurrentActivity (), REQUIRED_PERMISSIONS )) {
62- doCallback (permissionCallback ,CODE_PERMISSION_GRANTED ,MSG_PERMISSION_GRANTED );
57+ doCallback (permissionCallback , CODE_PERMISSION_GRANTED , MSG_PERMISSION_GRANTED );
6358 return ;
6459 }
6560 this .permissionCallback = permissionCallback ;
66- Log .i (TAG ,"requestPermission" );
6761 try {
6862 AndroidUtils .requestPermission (getCurrentActivity (), REQUIRED_PERMISSIONS );
6963 requestPermissionSended = true ;
@@ -72,46 +66,128 @@ public void requestPermission(Callback permissionCallback) {
7266 }
7367 }
7468
75-
7669 @ ReactMethod
77- public void setDebug (boolean enable ) {
70+ public void setDebugMode (boolean enable ) {
7871 JVerificationInterface .setDebugMode (enable );
7972 }
8073
74+ @ ReactMethod
75+ public void init () {
76+ JVerificationInterface .init (getCurrentActivity ());
77+ }
78+
79+ @ ReactMethod
80+ public void checkVerifyEnable (Callback callback ) {
81+ boolean isVerifyEnable = JVerificationInterface .checkVerifyEnable (getCurrentActivity ());
82+ WritableMap map = Arguments .createMap ();
83+ map .putBoolean ("enable" , isVerifyEnable );
84+ callback .invoke (map );
85+ }
86+
8187 @ ReactMethod
8288 public void getToken (final Callback callback ) {
8389 JVerificationInterface .getToken (getCurrentActivity (), new VerifyListener () {
8490 @ Override
85- public void onResult (int code , String content , String operato ) {
86- doCallback (callback ,code ,content );
91+ public void onResult (int code , String content , String operator ) {
92+ doCallback (callback , code , content , operator );
8793 }
8894 });
8995 }
9096
9197 @ ReactMethod
92- public void verifyNumber (ReadableMap map ,final Callback callback ) {
98+ public void verifyNumber (ReadableMap map , final Callback callback ) {
9399 String number = map .getString ("number" );
94100 String token = map .getString ("token" );
95101
96102 JVerificationInterface .verifyNumber (getCurrentActivity (), token , number , new VerifyListener () {
97103 @ Override
98104 public void onResult (int code , String content , String operator ) {
99- doCallback (callback ,code ,content );
105+ doCallback (callback , code , content , operator );
100106 }
101107 });
102108 }
103109
110+ @ ReactMethod
111+ public void loginAuth (final Callback callback ) {
112+ JVerificationInterface .loginAuth (getCurrentActivity (), new VerifyListener () {
113+ @ Override
114+ public void onResult (int code , String token , String operator ) {
115+ doCallback (callback , code , token , operator );
116+ }
117+ });
118+ }
119+
120+ @ ReactMethod
121+ public void setCustomUIWithConfig (ReadableMap map ) {
122+ JVerifyUIConfig uiConfig = convertMapToConfig (map );
123+ JVerificationInterface .setCustomUIWithConfig (uiConfig );
124+ }
125+
126+ private JVerifyUIConfig convertMapToConfig (ReadableMap map ) {
127+ int navColor = map .hasKey (JVerificationConstant .NAV_COLOR ) ? map .getInt (JVerificationConstant .NAV_COLOR ) : -16742704 ;
128+ String navText = map .hasKey (JVerificationConstant .NAV_TEXT ) ? map .getString (JVerificationConstant .NAV_TEXT ) : "登录" ;
129+ int navTextColor = map .hasKey (JVerificationConstant .NAV_TEXT_COLOR ) ? map .getInt (JVerificationConstant .NAV_TEXT_COLOR ) : -1 ;
130+ String navReturnImage = map .hasKey (JVerificationConstant .NAV_RETURN_IMAGE ) ? map .getString (JVerificationConstant .NAV_RETURN_IMAGE ) : "umcsdk_return_bg" ;
131+ boolean isLogoHidden = map .hasKey (JVerificationConstant .LOGO_HIDDEN ) && map .getBoolean (JVerificationConstant .LOGO_HIDDEN );
132+ String logoImage = map .hasKey (JVerificationConstant .LOGO_Image ) ? map .getString (JVerificationConstant .LOGO_Image ) : null ;
133+ int logoWidth = map .hasKey (JVerificationConstant .LOGO_Width ) ? map .getInt (JVerificationConstant .LOGO_Width ) : 70 ;
134+ int logoHeight = map .hasKey (JVerificationConstant .LOGO_Height ) ? map .getInt (JVerificationConstant .LOGO_Height ) : 70 ;
135+ int logoOffsetY = map .hasKey (JVerificationConstant .LOGO_OFFSET_Y ) ? map .getInt (JVerificationConstant .LOGO_OFFSET_Y ) : 50 ;
136+ int numColor = map .hasKey (JVerificationConstant .NUM_COLOR ) ? map .getInt (JVerificationConstant .NUM_COLOR ) : -16742704 ;
137+ int numOffsetY = map .hasKey (JVerificationConstant .NUM_OFFSET_Y ) ? map .getInt (JVerificationConstant .NUM_OFFSET_Y ) : 184 ;
138+ int sloganTextColor = map .hasKey (JVerificationConstant .SLOGAN_TEXT_COLOR ) ? map .getInt (JVerificationConstant .SLOGAN_TEXT_COLOR ) : -1 ;
139+ int sloganOffsetY = map .hasKey (JVerificationConstant .SLOGAN_OFFSET_Y ) ? map .getInt (JVerificationConstant .SLOGAN_OFFSET_Y ) : 224 ;
140+ String loginBtnText = map .hasKey (JVerificationConstant .LOGIN_BTN_TEXT ) ? map .getString (JVerificationConstant .LOGIN_BTN_TEXT ) : "本机号码一键登录" ;
141+ int loginBtnTextColor = map .hasKey (JVerificationConstant .LOGIN_BTN_TEXT_COLOR ) ? map .getInt (JVerificationConstant .LOGIN_BTN_TEXT_COLOR ) : -1 ;
142+ String loginBtnImage = map .hasKey (JVerificationConstant .LOGIN_BTN_IMAGE ) ? map .getString (JVerificationConstant .LOGIN_BTN_IMAGE ) : "umcsdk_login_btn_bg" ;
143+ int loginBtnOffsetY = map .hasKey (JVerificationConstant .LOGIN_BTN_OFFSET_Y ) ? map .getInt (JVerificationConstant .LOGIN_BTN_OFFSET_Y ) : 254 ;
144+ String privacyOneName = map .hasKey (JVerificationConstant .PRIVACY_ONE_NAME ) ? map .getString (JVerificationConstant .PRIVACY_ONE_NAME ) : null ;
145+ String privacyOneUrl = map .hasKey (JVerificationConstant .PRIVACY_ONE_URL ) ? map .getString (JVerificationConstant .PRIVACY_ONE_URL ) : null ;
146+ String privacyTwoName = map .hasKey (JVerificationConstant .PRIVACY_TWO_NAME ) ? map .getString (JVerificationConstant .PRIVACY_TWO_NAME ) : null ;
147+ String privacyTwoUrl = map .hasKey (JVerificationConstant .PRIVACY_TWO_URL ) ? map .getString (JVerificationConstant .PRIVACY_TWO_URL ) : null ;
148+ int privacyBasicColor = map .hasKey (JVerificationConstant .PRIVACY_BASIC_COLOR ) ? map .getInt (JVerificationConstant .PRIVACY_BASIC_COLOR ) : -10066330 ;
149+ int privacyProtocolColor = map .hasKey (JVerificationConstant .PRIVACY_PROTOCOL_COLOR ) ? map .getInt (JVerificationConstant .PRIVACY_PROTOCOL_COLOR ) : -16007674 ;
150+ int privacyOffsetY = map .hasKey (JVerificationConstant .PRIVACY_OFFSET_Y ) ? map .getInt (JVerificationConstant .PRIVACY_OFFSET_Y ) : 30 ;
151+ String checkImage = map .hasKey (JVerificationConstant .PRIVACY_CHECK_IMAGE ) ? map .getString (JVerificationConstant .PRIVACY_CHECK_IMAGE ) : "umcsdk_check_image" ;
152+ String unCheckImage = map .hasKey (JVerificationConstant .PRIVACY_UNCHECK_IMAGE ) ? map .getString (JVerificationConstant .PRIVACY_UNCHECK_IMAGE ) : "umcsdk_uncheck_image" ;
153+
154+ return new JVerifyUIConfig .Builder ()
155+ .setNavColor (navColor )
156+ .setNavText (navText )
157+ .setNavTextColor (navTextColor )
158+ .setNavReturnImgPath (navReturnImage )
159+ .setLogoHidden (isLogoHidden )
160+ .setLogoImgPath (logoImage )
161+ .setLogoWidth (logoWidth )
162+ .setLogoHeight (logoHeight )
163+ .setLogoOffsetY (logoOffsetY )
164+ .setNumberColor (numColor )
165+ .setNumFieldOffsetY (numOffsetY )
166+ .setSloganTextColor (sloganTextColor )
167+ .setSloganOffsetY (sloganOffsetY )
168+ .setLogBtnText (loginBtnText )
169+ .setLogBtnTextColor (loginBtnTextColor )
170+ .setLogBtnImgPath (loginBtnImage )
171+ .setLogBtnOffsetY (loginBtnOffsetY )
172+ .setAppPrivacyOne (privacyOneName , privacyOneUrl )
173+ .setAppPrivacyTwo (privacyTwoName , privacyTwoUrl )
174+ .setAppPrivacyColor (privacyBasicColor , privacyProtocolColor )
175+ .setPrivacyOffsetY (privacyOffsetY )
176+ .setCheckedImgPath (checkImage )
177+ .setUncheckedImgPath (unCheckImage )
178+ .build ();
179+ }
180+
104181 @ Override
105182 public void onHostResume () {
106183 if (requestPermissionSended ) {
107184 if (AndroidUtils .checkPermission (getCurrentActivity (), REQUIRED_PERMISSIONS )) {
108- doCallback (permissionCallback ,CODE_PERMISSION_GRANTED ,MSG_PERMISSION_GRANTED );
185+ doCallback (permissionCallback , CODE_PERMISSION_GRANTED , MSG_PERMISSION_GRANTED );
109186 } else {
110- doCallback (permissionCallback ,ERR_CODE_PERMISSION ,ERR_MSG_PERMISSION );
187+ doCallback (permissionCallback , ERR_CODE_PERMISSION , ERR_MSG_PERMISSION );
111188 }
112189 }
113190 requestPermissionSended = false ;
114-
115191 }
116192
117193 @ Override
@@ -124,10 +200,18 @@ public void onHostDestroy() {
124200
125201 }
126202
127- private void doCallback (Callback callback , int code , String content ){
203+ private void doCallback (Callback callback , int code , String content ) {
204+ WritableMap map = Arguments .createMap ();
205+ map .putInt ("code" , code );
206+ map .putString ("content" , content );
207+ callback .invoke (map );
208+ }
209+
210+ private void doCallback (Callback callback , int code , String content , String operator ) {
128211 WritableMap map = Arguments .createMap ();
129- map .putInt ("code" ,code );
130- map .putString ("content" ,content );
212+ map .putInt ("code" , code );
213+ map .putString ("content" , content );
214+ map .putString ("operator" , operator );
131215 callback .invoke (map );
132216 }
133217}
0 commit comments