diff --git a/Account Kit/README.md b/Account Kit/README.md index 3223ddd..406f92c 100644 --- a/Account Kit/README.md +++ b/Account Kit/README.md @@ -1,21 +1,27 @@ # Accountkit-Android-sample +English | [中文](https://github.com/HMS-Core/huawei-account-demo/blob/master/Account-Client-Java-Demo/Account_Demo_AndroidStudio/README_ZH.md) + ## Table of Contents * [Introduction](#introduction) - * [Getting Started](#getting-started) * [Supported Environments](#supported-environments) + * [Getting Started](#getting-started) * [Result](#result) * [License](#license) ## Introduction - Android sample code encapsulates APIs of the HUAWEI Account Kit server. It provides sample program for your reference or usage. - The following describes of Android sample code. - - hmssample: Sample code packages. This package contains code that implements Sign, SignInCode and SignOut. - logger: This packages contains code that implements logger View. +Android sample code encapsulates APIs of the HUAWEI Account Kit server. It provides sample program for your reference or usage. +The following describes of Android sample code. + +hmssample: Sample code packages. This package contains code that implements Sign, SignInCode, SilentSignIn, SignOut and CancelAuthorization. +logger: This packages contains code that implements logger View. + + +## Supported Environments +Android SDK Version >= 23 and JDK version >= 1.8 is recommended. ## Getting Started @@ -30,16 +36,17 @@ (2) Change the value of applicationid in the app-level build.gradle file of the sample project to the package name of your app. 6. Run the sample on your Android device or emulator. - -## Supported Environments - Android SDK Version >= 23 and JDK version >= 1.8 is recommended. -## Result - This demo provides demonstration for following scenarios: - 1. ID-Token Mode Sign In. Sign in and Id-Token verification are both included. - 2. Authorization Code Mode Sign In. - 3. Sign out. +## Result +This demo provides demonstration for following scenarios: +1. ID-Token Mode Sign In. +2. Authorization Code Mode Sign In. +3. Silent Sign In. +4. Sign out. +5. Cancel Authorization. + ![account sample result](images/account_sample_result.jpg) -## License - Account-kit Android sample is licensed under the [Apache License, version 2.0](http://www.apache.org/licenses/LICENSE-2.0). + +## License +Account-kit Android sample is licensed under the [Apache License, version 2.0](http://www.apache.org/licenses/LICENSE-2.0). diff --git a/Account Kit/README_ZH.md b/Account Kit/README_ZH.md new file mode 100644 index 0000000..feb3a58 --- /dev/null +++ b/Account Kit/README_ZH.md @@ -0,0 +1,42 @@ +# »ªÎªÕʺŷþÎñ¿Í»§¶ËJavaʾÀý´úÂë + +ÖÐÎÄ | [English](https://github.com/HMS-Core/huawei-account-demo/blob/master/Account-Client-Java-Demo/Account_Demo_AndroidStudio/README.md) + +## Ŀ¼ +* [¼ò½é](#¼ò½é) +* [»·¾³ÒªÇó](#»·¾³ÒªÇó) +* [¿ª·¢×¼±¸](#¿ª·¢×¼±¸) +* [ÔËÐнá¹û](#ÔËÐнá¹û) +* [ÊÚȨÐí¿É](#ÊÚȨÐí¿É) + +## ¼ò½é +AndroidʾÀý´úÂë¶Ô»ªÎªÕʺŷþÎñ£¨HUAWEI Account Kit£©µÄ¿Í»§¶Ë½Ó¿Ú½øÐзâ×°£¬°üº¬·á¸»µÄʾÀý³ÌÐò£¬·½±ãÄú²Î¿¼»òÖ±½ÓʹÓá£ÏêÇéÈçÏ£º + +hmssample£ºÊ¾Àý´úÂë°ü£¬¿ÉʵÏֵǼ¡¢ÊÚȨµÇ¼¡¢¾²Ä¬µÇ¼¡¢Í˳öÕʺźÍÕʺÅÈ¡ÏûÊÚȨ¹¦ÄÜ¡£ +logger£º¿ÉʵÏÖÈÕÖ¾¼Ç¼¡£ + +## »·¾³ÒªÇó +ÍÆ¼öʹÓÃAndroid SDK 23¼°ÒÔÉϰ汾¡¢JDK 1.8¼°ÒÔÉϰ汾¡£ + +## ¿ª·¢×¼±¸ +1. ¼ì²éAndroid Studio¿ª·¢»·¾³ÊÇ·ñ¾ÍÐ÷¡£ÔÚAndroid StudioÖдò¿ª¡°build.gradle¡±ÎļþËùÔÚµÄʾÀý´úÂ빤³ÌĿ¼£¬²¢ÔÚÄúÒѰ²×°×îÐÂ°æ»ªÎªÒÆ¶¯·þÎñ£¨HMS Core£©µÄÉ豸»òÄ£ÄâÆ÷ÉÏÔËÐвâÊÔÓ¦Óᣠ+2. ×¢²á[»ªÎªÕʺÅ](https://developer.huawei.com/consumer/cn/)¡£ +3. ´´½¨Ó¦Óò¢ÔÚAppGallery ConnectÖÐÅäÖÃÏà¹ØÐÅÏ¢¡£¾ßÌåÇë²Î¿¼[¿ª·¢×¼±¸](https://developer.huawei.com/consumer/cn/doc/development/HMSCore-Guides/config-agc-0000001050196065)¡£ +4. ¹¹½¨´ËʾÀýdemoǰ£¬ÇëÏȽ«demoµ¼ÈëAndroid Studio£¨3.0¼°ÒÔÉϰ汾£©¡£ +5. ÅäÖÃʾÀý´úÂ룺 + £¨1£©ÔÚAppGallery ConnectÏÂÔØÄúÓ¦Óõġ°agconnect-services.json¡±Îļþ£¬½«¸ÃÎļþ¿½±´µ½Ó¦Óü¶¸ùĿ¼Ï¡£ + £¨2£©ÐÞ¸ÄʾÀý¹¤³ÌÖÐÓ¦Óü¶¡°build.gradle¡±ÎļþÖеġ°applicationid¡±ÎªÄú×Ô¼ºµÄÓ¦ÓðüÃû¡£ +6. ÔÚAndroidÉ豸»òÄ£ÄâÆ÷ÉÏÔËÐÐÄúµÄÓ¦Óᣠ+ +## ÔËÐнá¹û +±¾Ê¾Àý´úÂëÌṩÁËÒÔÏÂʹÓó¡¾°£º +1. ID TokenģʽµÇ¼¡£ +2. Authorization CodeģʽµÇ¼¡£ +3. ¾²Ä¬µÇ¼¡£ +4. Í˳öÕʺš£ +5. ÕʺÅÈ¡ÏûÊÚȨ¡£ + +![image.png](http://image.huawei.com/tiny-lts/v1/images/1159b3ee2b0003e52e27e0d41c0fe0d2_400x866.png@900-0-90-f.png) + +## ÊÚȨÐí¿É +»ªÎªÕʺŷþÎñAndroidʾÀý´úÂë¾­¹ý[Apache License 2.0](http://www.apache.org/licenses/LICENSE-2.0)ÊÚȨÐí¿É¡£ \ No newline at end of file diff --git a/Account Kit/Third Party Open Source Software Notice.docx b/Account Kit/Third Party Open Source Software Notice.docx deleted file mode 100644 index 172a7bd..0000000 Binary files a/Account Kit/Third Party Open Source Software Notice.docx and /dev/null differ diff --git a/Account Kit/Third Party Open Source Software Notice.pdf b/Account Kit/Third Party Open Source Software Notice.pdf new file mode 100644 index 0000000..8b7ffc7 Binary files /dev/null and b/Account Kit/Third Party Open Source Software Notice.pdf differ diff --git a/Account Kit/images/account_sample_result.jpg b/Account Kit/images/account_sample_result.jpg index 7172e4b..1aefb3a 100644 Binary files a/Account Kit/images/account_sample_result.jpg and b/Account Kit/images/account_sample_result.jpg differ diff --git a/Account Kit/java/.gitignore b/Account Kit/java/.gitignore index 39fb081..a9dbb41 100644 --- a/Account Kit/java/.gitignore +++ b/Account Kit/java/.gitignore @@ -3,6 +3,7 @@ /local.properties /.idea/workspace.xml /.idea/libraries +.idea .DS_Store /build /captures diff --git a/Account Kit/java/README.md b/Account Kit/java/README.md index a8d6183..406f92c 100644 --- a/Account Kit/java/README.md +++ b/Account Kit/java/README.md @@ -1,21 +1,27 @@ # Accountkit-Android-sample +English | [中文](https://github.com/HMS-Core/huawei-account-demo/blob/master/Account-Client-Java-Demo/Account_Demo_AndroidStudio/README_ZH.md) + ## Table of Contents * [Introduction](#introduction) - * [Getting Started](#getting-started) * [Supported Environments](#supported-environments) + * [Getting Started](#getting-started) * [Result](#result) * [License](#license) ## Introduction - Android sample code encapsulates APIs of the HUAWEI Account Kit server. It provides sample program for your reference or usage. - The following describes of Android sample code. +Android sample code encapsulates APIs of the HUAWEI Account Kit server. It provides sample program for your reference or usage. +The following describes of Android sample code. - hmssample: Sample code packages. This package contains code that implements Sign, SignInCode and SignOut. - logger: This packages contains code that implements logger View. +hmssample: Sample code packages. This package contains code that implements Sign, SignInCode, SilentSignIn, SignOut and CancelAuthorization. +logger: This packages contains code that implements logger View. + + +## Supported Environments +Android SDK Version >= 23 and JDK version >= 1.8 is recommended. ## Getting Started @@ -30,16 +36,17 @@ (2) Change the value of applicationid in the app-level build.gradle file of the sample project to the package name of your app. 6. Run the sample on your Android device or emulator. - -## Supported Environments - Android SDK Version >= 23 and JDK version >= 1.8 is recommended. -## Result - This demo provides demonstration for following scenarios: - 1. ID-Token Mode Sign In. Sign in and Id-Token verification are both included. - 2. Authorization Code Mode Sign In. - 3. Sign out. -![account sample result](../images/account_sample_result.jpg) - -## License - Account-kit Android sample is licensed under the [Apache License, version 2.0](http://www.apache.org/licenses/LICENSE-2.0). +## Result +This demo provides demonstration for following scenarios: +1. ID-Token Mode Sign In. +2. Authorization Code Mode Sign In. +3. Silent Sign In. +4. Sign out. +5. Cancel Authorization. + +![account sample result](images/account_sample_result.jpg) + + +## License +Account-kit Android sample is licensed under the [Apache License, version 2.0](http://www.apache.org/licenses/LICENSE-2.0). diff --git a/Account Kit/java/README_ZH.md b/Account Kit/java/README_ZH.md new file mode 100644 index 0000000..feb3a58 --- /dev/null +++ b/Account Kit/java/README_ZH.md @@ -0,0 +1,42 @@ +# »ªÎªÕʺŷþÎñ¿Í»§¶ËJavaʾÀý´úÂë + +ÖÐÎÄ | [English](https://github.com/HMS-Core/huawei-account-demo/blob/master/Account-Client-Java-Demo/Account_Demo_AndroidStudio/README.md) + +## Ŀ¼ +* [¼ò½é](#¼ò½é) +* [»·¾³ÒªÇó](#»·¾³ÒªÇó) +* [¿ª·¢×¼±¸](#¿ª·¢×¼±¸) +* [ÔËÐнá¹û](#ÔËÐнá¹û) +* [ÊÚȨÐí¿É](#ÊÚȨÐí¿É) + +## ¼ò½é +AndroidʾÀý´úÂë¶Ô»ªÎªÕʺŷþÎñ£¨HUAWEI Account Kit£©µÄ¿Í»§¶Ë½Ó¿Ú½øÐзâ×°£¬°üº¬·á¸»µÄʾÀý³ÌÐò£¬·½±ãÄú²Î¿¼»òÖ±½ÓʹÓá£ÏêÇéÈçÏ£º + +hmssample£ºÊ¾Àý´úÂë°ü£¬¿ÉʵÏֵǼ¡¢ÊÚȨµÇ¼¡¢¾²Ä¬µÇ¼¡¢Í˳öÕʺźÍÕʺÅÈ¡ÏûÊÚȨ¹¦ÄÜ¡£ +logger£º¿ÉʵÏÖÈÕÖ¾¼Ç¼¡£ + +## »·¾³ÒªÇó +ÍÆ¼öʹÓÃAndroid SDK 23¼°ÒÔÉϰ汾¡¢JDK 1.8¼°ÒÔÉϰ汾¡£ + +## ¿ª·¢×¼±¸ +1. ¼ì²éAndroid Studio¿ª·¢»·¾³ÊÇ·ñ¾ÍÐ÷¡£ÔÚAndroid StudioÖдò¿ª¡°build.gradle¡±ÎļþËùÔÚµÄʾÀý´úÂ빤³ÌĿ¼£¬²¢ÔÚÄúÒѰ²×°×îÐÂ°æ»ªÎªÒÆ¶¯·þÎñ£¨HMS Core£©µÄÉ豸»òÄ£ÄâÆ÷ÉÏÔËÐвâÊÔÓ¦Óᣠ+2. ×¢²á[»ªÎªÕʺÅ](https://developer.huawei.com/consumer/cn/)¡£ +3. ´´½¨Ó¦Óò¢ÔÚAppGallery ConnectÖÐÅäÖÃÏà¹ØÐÅÏ¢¡£¾ßÌåÇë²Î¿¼[¿ª·¢×¼±¸](https://developer.huawei.com/consumer/cn/doc/development/HMSCore-Guides/config-agc-0000001050196065)¡£ +4. ¹¹½¨´ËʾÀýdemoǰ£¬ÇëÏȽ«demoµ¼ÈëAndroid Studio£¨3.0¼°ÒÔÉϰ汾£©¡£ +5. ÅäÖÃʾÀý´úÂ룺 + £¨1£©ÔÚAppGallery ConnectÏÂÔØÄúÓ¦Óõġ°agconnect-services.json¡±Îļþ£¬½«¸ÃÎļþ¿½±´µ½Ó¦Óü¶¸ùĿ¼Ï¡£ + £¨2£©ÐÞ¸ÄʾÀý¹¤³ÌÖÐÓ¦Óü¶¡°build.gradle¡±ÎļþÖеġ°applicationid¡±ÎªÄú×Ô¼ºµÄÓ¦ÓðüÃû¡£ +6. ÔÚAndroidÉ豸»òÄ£ÄâÆ÷ÉÏÔËÐÐÄúµÄÓ¦Óᣠ+ +## ÔËÐнá¹û +±¾Ê¾Àý´úÂëÌṩÁËÒÔÏÂʹÓó¡¾°£º +1. ID TokenģʽµÇ¼¡£ +2. Authorization CodeģʽµÇ¼¡£ +3. ¾²Ä¬µÇ¼¡£ +4. Í˳öÕʺš£ +5. ÕʺÅÈ¡ÏûÊÚȨ¡£ + +![image.png](http://image.huawei.com/tiny-lts/v1/images/1159b3ee2b0003e52e27e0d41c0fe0d2_400x866.png@900-0-90-f.png) + +## ÊÚȨÐí¿É +»ªÎªÕʺŷþÎñAndroidʾÀý´úÂë¾­¹ý[Apache License 2.0](http://www.apache.org/licenses/LICENSE-2.0)ÊÚȨÐí¿É¡£ \ No newline at end of file diff --git a/Account Kit/java/app/Third Party Open Source Software Notice.docx b/Account Kit/java/app/Third Party Open Source Software Notice.docx deleted file mode 100644 index c0def5a..0000000 Binary files a/Account Kit/java/app/Third Party Open Source Software Notice.docx and /dev/null differ diff --git a/Account Kit/java/app/Third Party Open Source Software Notice.pdf b/Account Kit/java/app/Third Party Open Source Software Notice.pdf new file mode 100644 index 0000000..8b7ffc7 Binary files /dev/null and b/Account Kit/java/app/Third Party Open Source Software Notice.pdf differ diff --git a/Account Kit/java/app/app.iml b/Account Kit/java/app/app.iml index 1851702..f51c452 100644 --- a/Account Kit/java/app/app.iml +++ b/Account Kit/java/app/app.iml @@ -4,8 +4,6 @@ @@ -19,8 +17,8 @@ @@ -34,15 +32,15 @@ - - - + + + - - + + @@ -51,13 +49,6 @@ - - - - - - - @@ -65,6 +56,13 @@ + + + + + + + @@ -72,13 +70,6 @@ - - - - - - - @@ -86,40 +77,69 @@ - + + + + + + + + + + + + + + + + + + + + + - + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Account Kit/java/app/build.gradle b/Account Kit/java/app/build.gradle index 069b76f..feb28ac 100644 --- a/Account Kit/java/app/build.gradle +++ b/Account Kit/java/app/build.gradle @@ -24,10 +24,11 @@ android { } } - compileSdkVersion 28 + compileSdkVersion 29 + buildToolsVersion "29.0.3" defaultConfig { applicationId "com.huawei.codelab.hwid" - minSdkVersion 17 + minSdkVersion 19 targetSdkVersion 28 versionCode 1 versionName "1.0" @@ -48,11 +49,9 @@ dependencies { ext.ESPRESSO_VERSION = '2.2.2' implementation fileTree(include: ['*.jar',], dir: 'libs') - implementation 'com.android.support:support-compat:28.0.0' - implementation 'com.google.code.gson:gson:2.8.5' - implementation 'com.huawei.hms:hwid:5.0.3.301' - implementation "com.squareup.okhttp3:okhttp:3.14.2" - implementation 'com.squareup.okio:okio:1.14.1' + implementation 'androidx.appcompat:appcompat:1.2.0' + implementation "com.google.code.gson:gson:2.8.5" + implementation 'com.huawei.hms:hwid:5.2.0.300' } repositories { flatDir { dirs '../aars' } } diff --git a/Account Kit/java/app/src/main/AndroidManifest.xml b/Account Kit/java/app/src/main/AndroidManifest.xml index 33ca520..f8fb9bd 100644 --- a/Account Kit/java/app/src/main/AndroidManifest.xml +++ b/Account Kit/java/app/src/main/AndroidManifest.xml @@ -3,8 +3,6 @@ package="com.huawei.hmssample"> - - @@ -13,13 +11,6 @@ - - - - - - - - - - - - - - - - diff --git a/Account Kit/java/app/src/main/assets/hmssdksample.jpg b/Account Kit/java/app/src/main/assets/hmssdksample.jpg deleted file mode 100644 index bb1e543..0000000 Binary files a/Account Kit/java/app/src/main/assets/hmssdksample.jpg and /dev/null differ diff --git a/Account Kit/java/app/src/main/java/com/huawei/hmssample/HuaweiIdActivity.java b/Account Kit/java/app/src/main/java/com/huawei/hmssample/AccountActivity.java similarity index 52% rename from Account Kit/java/app/src/main/java/com/huawei/hmssample/HuaweiIdActivity.java rename to Account Kit/java/app/src/main/java/com/huawei/hmssample/AccountActivity.java index 47ce042..7ffcf10 100644 --- a/Account Kit/java/app/src/main/java/com/huawei/hmssample/HuaweiIdActivity.java +++ b/Account Kit/java/app/src/main/java/com/huawei/hmssample/AccountActivity.java @@ -17,7 +17,9 @@ import android.app.FragmentTransaction; import android.content.Intent; +import android.os.Build; import android.os.Bundle; +import android.text.TextUtils; import android.view.View; import android.view.View.OnClickListener; @@ -25,33 +27,34 @@ import com.huawei.hmf.tasks.OnSuccessListener; import com.huawei.hmf.tasks.Task; import com.huawei.hms.common.ApiException; -import com.huawei.hms.support.hwid.HuaweiIdAuthManager; -import com.huawei.hms.support.hwid.request.HuaweiIdAuthParams; -import com.huawei.hms.support.hwid.request.HuaweiIdAuthParamsHelper; -import com.huawei.hms.support.hwid.result.AuthHuaweiId; -import com.huawei.hms.support.hwid.service.HuaweiIdAuthService; +import com.huawei.hms.support.account.AccountAuthManager; +import com.huawei.hms.support.account.request.AccountAuthParams; +import com.huawei.hms.support.account.request.AccountAuthParamsHelper; +import com.huawei.hms.support.account.result.AuthAccount; +import com.huawei.hms.support.account.service.AccountAuthService; import com.huawei.logger.Log; import com.huawei.logger.LoggerActivity; /** - * Codelab - * Demonstration of HuaweiId + * Codelab + * Demonstration of HuaweiId */ -public class HuaweiIdActivity extends LoggerActivity implements OnClickListener { +public class AccountActivity extends LoggerActivity implements OnClickListener { //Log tag public static final String TAG = "HuaweiIdActivity"; - private HuaweiIdAuthService mAuthManager; - private HuaweiIdAuthParams mAuthParam; + private AccountAuthService mAuthManager; + private AccountAuthParams mAuthParam; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); - setContentView(R.layout.activity_huaweiid); - findViewById(R.id.hwid_signin).setOnClickListener(this); - findViewById(R.id.hwid_signout).setOnClickListener(this); - findViewById(R.id.hwid_signInCode).setOnClickListener(this); - + setContentView(R.layout.activity_account); + findViewById(R.id.account_signin).setOnClickListener(this); + findViewById(R.id.account_signout).setOnClickListener(this); + findViewById(R.id.account_signInCode).setOnClickListener(this); + findViewById(R.id.account_silent_signin).setOnClickListener(this); + findViewById(R.id.cancel_authorization).setOnClickListener(this); //sample log Please ignore addLogFragment(); } @@ -76,20 +79,20 @@ protected void onDestroy() { * Pull up the authorization interface by getSignInIntent */ private void signIn() { - mAuthParam = new HuaweiIdAuthParamsHelper(HuaweiIdAuthParams.DEFAULT_AUTH_REQUEST_PARAM) + mAuthParam = new AccountAuthParamsHelper(AccountAuthParams.DEFAULT_AUTH_REQUEST_PARAM) .setIdToken() .setAccessToken() .createParams(); - mAuthManager = HuaweiIdAuthManager.getService(HuaweiIdActivity.this, mAuthParam); + mAuthManager = AccountAuthManager.getService(AccountActivity.this, mAuthParam); startActivityForResult(mAuthManager.getSignInIntent(), Constant.REQUEST_SIGN_IN_LOGIN); } private void signInCode() { - mAuthParam = new HuaweiIdAuthParamsHelper(HuaweiIdAuthParams.DEFAULT_AUTH_REQUEST_PARAM) + mAuthParam = new AccountAuthParamsHelper(AccountAuthParams.DEFAULT_AUTH_REQUEST_PARAM) .setProfile() .setAuthorizationCode() .createParams(); - mAuthManager = HuaweiIdAuthManager.getService(HuaweiIdActivity.this, mAuthParam); + mAuthManager = AccountAuthManager.getService(AccountActivity.this, mAuthParam); startActivityForResult(mAuthManager.getSignInIntent(), Constant.REQUEST_SIGN_IN_LOGIN_CODE); } @@ -98,32 +101,29 @@ private void signInCode() { * sign Out by signOut */ private void signOut() { - if (null != mAuthManager) { - Task signOutTask = mAuthManager.signOut(); - signOutTask.addOnSuccessListener(new OnSuccessListener() { - @Override - public void onSuccess(Void aVoid) { - Log.i(TAG, "signOut Success"); - } - }).addOnFailureListener(new OnFailureListener() { - @Override - public void onFailure(Exception e) { - Log.i(TAG, "signOut fail"); - } - }); - } + Task signOutTask = mAuthManager.signOut(); + signOutTask.addOnSuccessListener(new OnSuccessListener() { + @Override + public void onSuccess(Void aVoid) { + Log.i(TAG, "signOut Success"); + } + }).addOnFailureListener(new OnFailureListener() { + @Override + public void onFailure(Exception e) { + Log.i(TAG, "signOut fail"); + } + }); } - /** * Codelab Code * Silent SignIn by silentSignIn */ private void silentSignIn() { - Task task = mAuthManager.silentSignIn(); - task.addOnSuccessListener(new OnSuccessListener() { + Task task = mAuthManager.silentSignIn(); + task.addOnSuccessListener(new OnSuccessListener() { @Override - public void onSuccess(AuthHuaweiId authHuaweiId) { + public void onSuccess(AuthAccount authAccount) { Log.i(TAG, "silentSignIn success"); } }); @@ -142,47 +142,74 @@ public void onFailure(Exception e) { @Override public void onClick(View v) { switch (v.getId()) { - case R.id.hwid_signin: + case R.id.account_signin: signIn(); break; - case R.id.hwid_signout: + case R.id.account_signout: signOut(); break; - case R.id.hwid_signInCode: + case R.id.account_signInCode: signInCode(); break; + case R.id.account_silent_signin: + silentSignIn(); + break; + case R.id.cancel_authorization: + cancelAuthorization(); + break; default: break; } } + private void cancelAuthorization() { + mAuthParam = new AccountAuthParamsHelper(AccountAuthParams.DEFAULT_AUTH_REQUEST_PARAM) + .setProfile() + .setAuthorizationCode() + .createParams(); + mAuthManager = AccountAuthManager.getService(AccountActivity.this, mAuthParam); + Task task = mAuthManager.cancelAuthorization(); + task.addOnSuccessListener(new OnSuccessListener() { + @Override + public void onSuccess(Void aVoid) { + Log.i(TAG, "cancelAuthorization success"); + } + }); + task.addOnFailureListener(new OnFailureListener() { + @Override + public void onFailure(Exception e) { + Log.i(TAG, "cancelAuthorization failure:" + e.getClass().getSimpleName()); + } + }); + } + @Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); if (requestCode == Constant.REQUEST_SIGN_IN_LOGIN) { //login success //get user message by parseAuthResultFromIntent - Task authHuaweiIdTask = HuaweiIdAuthManager.parseAuthResultFromIntent(data); - if (authHuaweiIdTask.isSuccessful()) { - AuthHuaweiId huaweiAccount = authHuaweiIdTask.getResult(); - Log.i(TAG, huaweiAccount.getDisplayName() + " signIn success "); - Log.i(TAG,"AccessToken: " + huaweiAccount.getAccessToken()); + Task authAccountTask = AccountAuthManager.parseAuthResultFromIntent(data); + if (authAccountTask.isSuccessful()) { + AuthAccount authAccount = authAccountTask.getResult(); + Log.i(TAG, authAccount.getDisplayName() + " signIn success "); + Log.i(TAG, "AccessToken: " + authAccount.getAccessToken()); } else { - Log.i(TAG, "signIn failed: " + ((ApiException) authHuaweiIdTask.getException()).getStatusCode()); + Log.i(TAG, "signIn failed: " + ((ApiException) authAccountTask.getException()).getStatusCode()); } } if (requestCode == Constant.REQUEST_SIGN_IN_LOGIN_CODE) { //login success - Task authHuaweiIdTask = HuaweiIdAuthManager.parseAuthResultFromIntent(data); - if (authHuaweiIdTask.isSuccessful()) { - AuthHuaweiId huaweiAccount = authHuaweiIdTask.getResult(); + Task authAccountTask = AccountAuthManager.parseAuthResultFromIntent(data); + if (authAccountTask.isSuccessful()) { + AuthAccount authAccount = authAccountTask.getResult(); Log.i(TAG, "signIn get code success."); - Log.i(TAG,"ServerAuthCode: " + huaweiAccount.getAuthorizationCode()); + Log.i(TAG, "ServerAuthCode: " + authAccount.getAuthorizationCode()); /**** english doc:For security reasons, the operation of changing the code to an AT must be performed on your server. The code is only an example and cannot be run. ****/ /**********************************************************************************************/ } else { - Log.i(TAG, "signIn get code failed: " + ((ApiException) authHuaweiIdTask.getException()).getStatusCode()); + Log.i(TAG, "signIn get code failed: " + ((ApiException) authAccountTask.getException()).getStatusCode()); } } } diff --git a/Account Kit/java/app/src/main/java/com/huawei/hmssample/Constant.java b/Account Kit/java/app/src/main/java/com/huawei/hmssample/Constant.java index 934a7a1..df17931 100644 --- a/Account Kit/java/app/src/main/java/com/huawei/hmssample/Constant.java +++ b/Account Kit/java/app/src/main/java/com/huawei/hmssample/Constant.java @@ -24,9 +24,4 @@ public class Constant { public static final int REQUEST_SIGN_IN_LOGIN = 1002; //login by code public static final int REQUEST_SIGN_IN_LOGIN_CODE = 1003; - - /** - * your app’s client ID,please replace it of yours - */ - public static final String CLIENT_ID = "your app's client ID"; } diff --git a/Account Kit/java/app/src/main/java/com/huawei/logger/LogView.java b/Account Kit/java/app/src/main/java/com/huawei/logger/LogView.java index 8acbcd4..1cf7afd 100644 --- a/Account Kit/java/app/src/main/java/com/huawei/logger/LogView.java +++ b/Account Kit/java/app/src/main/java/com/huawei/logger/LogView.java @@ -18,6 +18,7 @@ import java.text.SimpleDateFormat; import java.util.Date; +import android.annotation.SuppressLint; import android.app.Activity; import android.content.Context; import android.util.AttributeSet; @@ -25,6 +26,7 @@ import com.huawei.logger.Log.LogNode; +@SuppressLint("AppCompatCustomView") public class LogView extends TextView implements LogNode { private LogNode mNext; diff --git a/Account Kit/kotlin/app/src/main/res/layout/activity_huaweiid.xml b/Account Kit/java/app/src/main/res/layout/activity_account.xml similarity index 58% rename from Account Kit/kotlin/app/src/main/res/layout/activity_huaweiid.xml rename to Account Kit/java/app/src/main/res/layout/activity_account.xml index a7c413c..fd54f0b 100644 --- a/Account Kit/kotlin/app/src/main/res/layout/activity_huaweiid.xml +++ b/Account Kit/java/app/src/main/res/layout/activity_account.xml @@ -10,29 +10,39 @@ android:paddingLeft="@dimen/activity_title_margin" android:paddingTop="@dimen/activity_title_margin" android:paddingRight="@dimen/activity_title_margin" - tools:context="com.huawei.hmssample.HuaweiIdActivity"> + tools:context="com.huawei.hmssample.AccountActivity">