├── settings.gradle
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── app
├── src
│ └── main
│ │ ├── res
│ │ ├── mipmap-hdpi
│ │ │ ├── ic_launcher.png
│ │ │ └── ic_launcher_round.png
│ │ ├── mipmap-mdpi
│ │ │ ├── ic_launcher.png
│ │ │ └── ic_launcher_round.png
│ │ ├── mipmap-xhdpi
│ │ │ ├── ic_launcher.png
│ │ │ └── ic_launcher_round.png
│ │ ├── mipmap-xxhdpi
│ │ │ ├── ic_launcher.png
│ │ │ └── ic_launcher_round.png
│ │ ├── mipmap-xxxhdpi
│ │ │ ├── ic_launcher.png
│ │ │ └── ic_launcher_round.png
│ │ ├── values
│ │ │ ├── colors.xml
│ │ │ ├── styles.xml
│ │ │ └── strings.xml
│ │ ├── mipmap-anydpi-v26
│ │ │ ├── ic_launcher.xml
│ │ │ └── ic_launcher_round.xml
│ │ ├── layout
│ │ │ ├── app_loading_dialog.xml
│ │ │ ├── activity_main.xml
│ │ │ └── activity_registration.xml
│ │ ├── drawable-v24
│ │ │ └── ic_launcher_foreground.xml
│ │ └── drawable
│ │ │ └── ic_launcher_background.xml
│ │ ├── java
│ │ └── com
│ │ │ └── huawei
│ │ │ └── codelab
│ │ │ └── dcidemo
│ │ │ ├── push
│ │ │ ├── HwPushMsgService.java
│ │ │ └── HmsPushHelper.java
│ │ │ ├── dialog
│ │ │ └── AppLoadingDialog.java
│ │ │ ├── DciDemoApplication.java
│ │ │ ├── ErrorCode.java
│ │ │ ├── view
│ │ │ ├── BaseActivity.java
│ │ │ ├── MainActivity.java
│ │ │ └── RegistrationActivity.java
│ │ │ └── utils
│ │ │ ├── DataUtils.java
│ │ │ └── HmsLoginUtils.java
│ │ └── AndroidManifest.xml
├── .gitignore
├── proguard-rules.pro
└── build.gradle
├── .gitignore
├── gradle.properties
├── README_ZH.md
├── README.md
└── LICENSE
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':app'
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/HMS-Core/hms-DCI-demo/HEAD/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/HMS-Core/hms-DCI-demo/HEAD/app/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/HMS-Core/hms-DCI-demo/HEAD/app/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/HMS-Core/hms-DCI-demo/HEAD/app/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/HMS-Core/hms-DCI-demo/HEAD/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/HMS-Core/hms-DCI-demo/HEAD/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/HMS-Core/hms-DCI-demo/HEAD/app/src/main/res/mipmap-hdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/HMS-Core/hms-DCI-demo/HEAD/app/src/main/res/mipmap-mdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/HMS-Core/hms-DCI-demo/HEAD/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/HMS-Core/hms-DCI-demo/HEAD/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/HMS-Core/hms-DCI-demo/HEAD/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Tue Dec 01 17:31:35 CST 2020
2 | distributionBase=GRADLE_USER_HOME
3 | distributionPath=wrapper/dists
4 | zipStoreBase=GRADLE_USER_HOME
5 | zipStorePath=wrapper/dists
6 | distributionUrl=https\://services.gradle.org/distributions/gradle-6.1.1-all.zip
--------------------------------------------------------------------------------
/app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #007DFF
4 | #007DFF
5 | #007DFF
6 | #ffffff
7 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | *.iml
2 | .gradle
3 | /local.properties
4 | /.idea/caches
5 | /.idea/libraries
6 | /.idea/modules.xml
7 | /.idea/workspace.xml
8 | /.idea/navEditor.xml
9 | /.idea/assetWizardSettings.xml
10 | .DS_Store
11 | /build
12 | /captures
13 | .externalNativeBuild
14 | .cxx
15 | /.idea
16 | /.gradle
17 | /app/release
18 |
19 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/app_loading_dialog.xml:
--------------------------------------------------------------------------------
1 |
4 |
5 |
10 |
11 |
14 |
15 |
--------------------------------------------------------------------------------
/app/.gitignore:
--------------------------------------------------------------------------------
1 | #built application files
2 | *.apk
3 | *.ap_
4 |
5 | # files for the dex VM
6 | *.dex
7 |
8 | # Java class files
9 | *.class
10 |
11 | # generated files
12 | bin/
13 | gen/
14 | out/
15 | build/
16 | captures/
17 |
18 | # Local configuration file (sdk path, etc)
19 | local.properties
20 | develop.properties
21 |
22 | # Windows thumbnail db
23 | Thumbs.db
24 |
25 | # OSX files
26 | .DS_Store
27 |
28 | # Eclipse project files
29 | .classpath
30 | .project
31 |
32 | # Android Studio
33 | *.iml
34 | .idea
35 |
36 | #sign file
37 | *.jks
38 |
39 | # Local IDEA workspace
40 | .idea/workspace.xml
41 |
42 | # Gradle cache
43 | .gradle
44 | #NDK
45 | obj/
--------------------------------------------------------------------------------
/gradle.properties:
--------------------------------------------------------------------------------
1 | # Project-wide Gradle settings.
2 | # IDE (e.g. Android Studio) users:
3 | # Gradle settings configured through the IDE *will override*
4 | # any settings specified in this file.
5 | # For more details on how to configure your build environment visit
6 | # http://www.gradle.org/docs/current/userguide/build_environment.html
7 | # Specifies the JVM arguments used for the daemon process.
8 | # The setting is particularly useful for tweaking memory settings.
9 | org.gradle.jvmargs=-Xmx2048m
10 | # When configured, Gradle will run in incubating parallel mode.
11 | # This option should only be used with decoupled projects. More details, visit
12 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
13 | # org.gradle.parallel=true
14 | # AndroidX package structure to make it clearer which packages are bundled with the
15 | # Android operating system, and which are packaged with your app"s APK
16 | # https://developer.android.com/topic/libraries/support-library/androidx-rn
17 | android.useAndroidX=true
18 | # Automatically convert third-party libraries to use AndroidX
19 | android.enableJetifier=true
--------------------------------------------------------------------------------
/app/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # You can control the set of applied configuration files using the
3 | # proguardFiles setting in build.gradle.
4 | #
5 | # For more details, see
6 | # http://developer.android.com/guide/developing/tools/proguard.html
7 |
8 | # If your project uses WebView with JS, uncomment the following
9 | # and specify the fully qualified class name to the JavaScript interface
10 | # class:
11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
12 | # public *;
13 | #}
14 |
15 | # Uncomment this to preserve the line number information for
16 | # debugging stack traces.
17 | #-keepattributes SourceFile,LineNumberTable
18 |
19 | # If you keep the line number information, uncomment this to
20 | # hide the original source file name.
21 | #-renamesourcefileattribute SourceFile
22 | -ignorewarnings
23 | -keepattributes *Annotation*
24 | -keepattributes Exceptions
25 | -keepattributes InnerClasses
26 | -keepattributes Signature
27 | -keepattributes SourceFile,LineNumberTable
28 | -keep class com.huawei.hianalytics.**{*;}
29 | -keep class com.huawei.updatesdk.**{*;}
30 | -keep class com.huawei.hms.**{*;}
--------------------------------------------------------------------------------
/app/src/main/java/com/huawei/codelab/dcidemo/push/HwPushMsgService.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2021. Huawei Technologies Co., Ltd. All rights reserved.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.huawei.codelab.dcidemo.push;
18 |
19 | import android.os.Bundle;
20 | import android.text.TextUtils;
21 |
22 | import com.huawei.hms.push.HmsMessageService;
23 |
24 | /**
25 | * HMS Push Service class.
26 | *
27 | * @since 2021-06-02
28 | */
29 | public class HwPushMsgService extends HmsMessageService {
30 | @Override
31 | public void onNewToken(String token, Bundle bundle) {
32 | if (!TextUtils.isEmpty(token)) {
33 | HmsPushHelper.setPushToken(token);
34 | }
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/app/src/main/java/com/huawei/codelab/dcidemo/dialog/AppLoadingDialog.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2021. Huawei Technologies Co., Ltd. All rights reserved.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.huawei.codelab.dcidemo.dialog;
18 |
19 | import android.app.Dialog;
20 | import android.content.Context;
21 | import android.os.Bundle;
22 | import android.view.Window;
23 |
24 | import androidx.annotation.NonNull;
25 |
26 | import com.huawei.codelab.dcidemo.R;
27 |
28 | /**
29 | * Loading Dialog class.
30 | *
31 | * @since 2021-06-02
32 | */
33 | public class AppLoadingDialog extends Dialog {
34 | public AppLoadingDialog(@NonNull Context context) {
35 | super(context);
36 | }
37 |
38 | @Override
39 | protected void onCreate(Bundle savedInstanceState) {
40 | super.onCreate(savedInstanceState);
41 | Window window = getWindow();
42 | window.setBackgroundDrawableResource(android.R.color.transparent);
43 | setContentView(R.layout.app_loading_dialog);
44 | }
45 | }
46 |
--------------------------------------------------------------------------------
/app/src/main/java/com/huawei/codelab/dcidemo/DciDemoApplication.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2021. Huawei Technologies Co., Ltd. All rights reserved.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.huawei.codelab.dcidemo;
18 |
19 | import android.app.Application;
20 |
21 | import com.huawei.hms.dci.function.HwDciPublicClient;
22 |
23 |
24 | /**
25 | * DciDemoApplication class.
26 | *
27 | * @since 2021-06-02
28 | */
29 | public class DciDemoApplication extends Application {
30 | private static Application sApplication;
31 |
32 | @Override
33 | public void onCreate() {
34 | super.onCreate();
35 | setInstance(this);
36 | // Init DCI Kit
37 | HwDciPublicClient.initApplication(this);
38 | }
39 |
40 | private static void setInstance(DciDemoApplication application) {
41 | sApplication = application;
42 | }
43 |
44 | /**
45 | * Get application Instance.
46 | *
47 | * @return Application
48 | */
49 | public static Application getInstance() {
50 | return sApplication;
51 | }
52 | }
53 |
--------------------------------------------------------------------------------
/app/src/main/java/com/huawei/codelab/dcidemo/ErrorCode.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2021. Huawei Technologies Co., Ltd. All rights reserved.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.huawei.codelab.dcidemo;
18 |
19 | /**
20 | * DCI Kit Error code class.
21 | *
22 | * @since 2021-06-02
23 | */
24 | public class ErrorCode {
25 | /**
26 | * DCI copyRight account register failed.
27 | */
28 | public static final int NOT_REGISTER = 50000007;
29 |
30 | /**
31 | * Get DCI Account Information Success.
32 | */
33 | public static final int GET_DCI_ACCOUNT_SUCCESS_CODE = 200;
34 |
35 | /**
36 | * Real-Name Authentication Failure Caused by Forcible Exit.
37 | */
38 | public static final int REAL_NAME_FAIL_AS_FORCIBLE_EXIT = 10001001;
39 |
40 | /**
41 | * Hms token or openId is null.
42 | */
43 | public static final int REAL_NAME_FAIL_AS_TOKEN_OR_OPENID_NULL = 10001002;
44 |
45 | /**
46 | * Hms token or openId Unavailable.
47 | */
48 | public static final int HW_TOKEN_OR_UID_NOT_USED = 10001003;
49 | }
50 |
--------------------------------------------------------------------------------
/app/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 | apply plugin: 'com.huawei.agconnect'
3 | android {
4 | def APP_ID = "\"xxx\""
5 | compileSdkVersion 29
6 | buildToolsVersion "29.0.3"
7 |
8 | defaultConfig {
9 | applicationId "com.huawei.codelab.dcidemo"
10 | minSdkVersion 24
11 | targetSdkVersion 29
12 | versionCode 1
13 | versionName "1.0"
14 | buildConfigField("String", "APPID", "${APP_ID}")
15 | }
16 | signingConfigs {
17 | release {
18 | keyAlias "xxx"
19 | keyPassword "xxx"
20 | storePassword "xxx"
21 | storeFile file("xxx.xxx")
22 | }
23 | }
24 |
25 | buildTypes {
26 | release {
27 | minifyEnabled true
28 | proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
29 | signingConfig signingConfigs.release
30 | }
31 | debug {
32 | debuggable true
33 | minifyEnabled false
34 | zipAlignEnabled false
35 | shrinkResources false
36 | proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
37 | signingConfig signingConfigs.release
38 | }
39 | }
40 |
41 | compileOptions {
42 | sourceCompatibility JavaVersion.VERSION_1_8
43 | targetCompatibility JavaVersion.VERSION_1_8
44 | }
45 | }
46 |
47 | dependencies {
48 | implementation fileTree(dir: "libs", include: ["*.jar"])
49 | implementation 'androidx.appcompat:appcompat:1.2.0'
50 | implementation 'com.huawei.hms:dci:3.0.2.301'
51 | implementation 'com.huawei.hms:push:6.1.0.300'
52 | }
--------------------------------------------------------------------------------
/app/src/main/res/drawable-v24/ic_launcher_foreground.xml:
--------------------------------------------------------------------------------
1 |
7 |
8 |
9 |
15 |
18 |
21 |
22 |
23 |
24 |
30 |
--------------------------------------------------------------------------------
/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
6 |
7 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
25 |
26 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
17 |
18 |
26 |
27 |
35 |
36 |
44 |
45 |
53 |
54 |
55 |
--------------------------------------------------------------------------------
/app/src/main/java/com/huawei/codelab/dcidemo/view/BaseActivity.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2021. Huawei Technologies Co., Ltd. All rights reserved.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.huawei.codelab.dcidemo.view;
18 |
19 | import android.util.Log;
20 | import android.widget.Toast;
21 |
22 | import androidx.appcompat.app.AppCompatActivity;
23 |
24 | import com.huawei.codelab.dcidemo.dialog.AppLoadingDialog;
25 | import com.huawei.hms.dci.function.HwDciClientCallBack;
26 |
27 | /**
28 | * Base Activity class.
29 | *
30 | * @since 2021-06-02
31 | */
32 | public abstract class BaseActivity extends AppCompatActivity {
33 | private static final String TAG = BaseActivity.class.getName();
34 |
35 | private AppLoadingDialog mLoadingDialog;
36 |
37 | /**
38 | * Show loading.
39 | */
40 | protected void showLoading() {
41 | if (mLoadingDialog == null) {
42 | mLoadingDialog = new AppLoadingDialog(this);
43 | }
44 | if (!mLoadingDialog.isShowing()) {
45 | mLoadingDialog.show();
46 | }
47 | }
48 |
49 | /**
50 | * Hide loading.
51 | */
52 | protected void dismissDialog() {
53 | if (mLoadingDialog != null && mLoadingDialog.isShowing()) {
54 | mLoadingDialog.dismiss();
55 | }
56 | }
57 |
58 | /**
59 | * Deal Error logic
60 | *
61 | * @param T
62 | */
63 | protected abstract class CommonFailCallBack implements HwDciClientCallBack {
64 | @Override
65 | public void onFail(int code, String msg) {
66 | dismissDialog();
67 | disposeError(code, msg);
68 | }
69 | }
70 |
71 | private void disposeError(int code, String msg) {
72 | // deal error logic
73 | Log.e(TAG, "code = " + code + ",msg = " + msg);
74 | Toast.makeText(this, msg, Toast.LENGTH_SHORT).show();
75 | }
76 | }
77 |
--------------------------------------------------------------------------------
/README_ZH.md:
--------------------------------------------------------------------------------
1 | # 华为DCI版权服务安卓示例代码
2 |
3 | 中文 | [English](README.md)
4 |
5 | ## 目录
6 |
7 | * [简介](#简介)
8 | * [开发准备](#开发准备)
9 | * [环境要求](#环境要求)
10 | * [示例代码](#示例代码)
11 | * [运行结果](#运行结果)
12 | * [授权许可](#授权许可)
13 |
14 | 简介
15 | ------------
16 |
17 | DCI版权服务(Digital Copyright Identifier Kit,以下简称“DCI Kit”)是由华为和中国版权保护中心(即数字版权唯一标识符管理机构)合作,按照《中华人民共和国著作权法》、“数字版权唯一标识符”标准及相关规定,利用区块链和大数据、人工智能等技术,对数字作品版权进行保护,提供DCI版权服务用户注册、DCI登记服务、DCI授权服务和DCI维权服务等能力。DCI登记成功的作品信息和版权权属确认信息将会保存在区块链中,保证所有的版权信息可信、可回溯。
18 | ## 开发准备
19 |
20 | 我们提供一个示例展示如何使用DCI Kit安卓SDK。该示例使用Gradle编译系统。
21 |
22 | 1. 检查Android Studio开发环境。在Android Studio中打开示例项目,其中含有 "build.gradle" 文件。
23 |
24 | 2. 注册[华为帐号](https://developer.huawei.com/consumer/cn/),成为华为开发者。创建应用并在AppGallery Connect中配置相关信息,具体请参考[开发准备](https://developer.huawei.com/consumer/cn/doc/development/HMSCore-Guides/config-agc-0000001050196065),集成 [HUAWEI Account Kit](https://developer.huawei.com/consumer/cn/hms/huawei-accountkit),如果需要DCI登记发码有通知能力,集成 [Push Kit](https://developer.huawei.com/consumer/cn/hms/huawei-pushkit)。
25 |
26 | 3. 配置示例代码:
27 |
28 | (1)从AppGallery Connect下载您应用的agconnect-services.json文件,并添加到示例代码的app目录下(\app),替换app下build.gradle的APP_ID为您申请的。
29 |
30 | (2)将示例工程的应用级build.gradle文件中“applicationId”的值更改为您自己的应用包名。
31 |
32 | (3)需要生成签名证书指纹并将证书文件添加到项目中,并在app下的build.gradle文件中配置。
33 |
34 | ## 环境要求
35 |
36 | - Android Studio推荐3.X以上,Android SDK版本号为24或以上,JDK版本号为1.8或以上。
37 | - 支持的场景:华为手机、华为平板、非华为的安卓系统手机。
38 | - 支持的OS:EMUI 8.0+、Android 7.0+。
39 | - HMS Core(APK)版本:5.0.1.301及以上。
40 |
41 | ## 示例代码
42 |
43 | 该示例代码为您提供了DCI版权服务用户注册、获取DCI版权服务用户信息、注销DCI版权服务用户、摄影作品DCI登记、查询摄影作品DCI登记信息、撤销摄影作品的DCI登记、查询撤销摄影作品DCI登记的结果、对DCI登记成功的摄影作品添加DCI标。
44 |
45 | 1. MainActivity.java 提供DCI版权服务用户注册、获取DCI版权服务用户信息、注销DCI版权服务用户能力。代码位于app\src\main\java\com\huawei\codelab\dcidemo\MainActivity.java 中。
46 | 2. RegistrationActivity.java 提供摄影作品DCI登记、查询摄影作品DCI登记信息、撤销摄影作品的DCI登记、查询撤销摄影作品DCI登记的结果、对DCI登记成功的摄影作品添加DCI标能力。代码位于app\src\main\java\com\huawei\codelab\dcidemo\RegistrationActivity.java 中。
47 |
48 | ## 运行结果
49 |
50 | 该示例代码在日志中打印DCI版权服务用户信息,DCI摄影作品登记信息的内容,Toast弹窗提示注销DCI版权服务用户,撤销摄影作品的DCI登记的结果。
51 |
52 | ## 技术支持
53 |
54 | 如果您对HMS Core还处于评估阶段,可在[Reddit社区](https://www.reddit.com/r/HuaweiDevelopers/)获取关于HMS Core的最新讯息,并与其他开发者交流见解。
55 |
56 | 如果您对使用HMS示例代码有疑问,请尝试:
57 |
58 | - 开发过程遇到问题上[Stack Overflow](https://stackoverflow.com/questions/tagged/huawei-mobile-services?tab=Votes),在`huawei-mobile-services`标签下提问,有华为研发专家在线一对一解决您的问题。
59 | - 到[华为开发者论坛](https://developer.huawei.com/consumer/cn/forum/blockdisplay?fid=18) HMS Core板块与其他开发者进行交流。
60 |
61 | ## 授权许可
62 |
63 | 该示例代码经过[Apache 2.0授权许可](http://www.apache.org/licenses/LICENSE-2.0)。
--------------------------------------------------------------------------------
/app/src/main/java/com/huawei/codelab/dcidemo/push/HmsPushHelper.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2021. Huawei Technologies Co., Ltd. All rights reserved.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.huawei.codelab.dcidemo.push;
18 |
19 | import android.content.Context;
20 | import android.text.TextUtils;
21 | import android.util.Log;
22 |
23 | import androidx.annotation.NonNull;
24 |
25 | import com.huawei.agconnect.config.AGConnectServicesConfig;
26 | import com.huawei.hms.aaid.HmsInstanceId;
27 | import com.huawei.hms.common.ApiException;
28 |
29 | /**
30 | * HMS Push Helper class.
31 | *
32 | * @since 2021-06-02
33 | */
34 | public class HmsPushHelper {
35 | /**
36 | * HMS push token.
37 | */
38 | public volatile static String PUSH_TOKEN;
39 |
40 | private static final String TAG = "HmsPushHelper";
41 |
42 | private HmsPushHelper() {
43 | }
44 |
45 | /**
46 | * Get HMS pushToken.
47 | *
48 | * @param context Context
49 | */
50 | public static synchronized void getToken(@NonNull final Context context) {
51 | new Thread(new Runnable() {
52 | @Override
53 | public void run() {
54 | try {
55 | String appId = AGConnectServicesConfig.fromContext(context).getString("client/app_id");
56 | String token = HmsInstanceId.getInstance(context).getToken(appId, "HCM");
57 | if (TextUtils.isEmpty(token)) {
58 | Log.e(TAG, "token is empty.");
59 | return;
60 | }
61 | setPushToken(token);
62 | } catch (ApiException e) {
63 | Log.e(TAG, "get token failed,statusCode = " + e.getStatusCode());
64 | }
65 | }
66 | }).start();
67 | }
68 |
69 | /**
70 | * Setting HMS pushToken.
71 | *
72 | * @param pushToken pushToken
73 | */
74 | public static void setPushToken(String pushToken) {
75 | PUSH_TOKEN = pushToken;
76 | }
77 | }
--------------------------------------------------------------------------------
/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | DciKitDemo
3 | Sign in to your HUAWEI ID first.
4 | Sign-in successful.
5 | Sign in to HUAWEI ID
6 | Register as a DCI user.
7 | Sign-in expired. Please sign in again.
8 | Register as DCI user
9 |
10 | Deregister
11 | Deregistration successful.
12 | Deregistration failed.
13 |
14 | DCI Kit obtains user information
15 | DCI Kit needs to obtain user information first.
16 | Operation successful.
17 | Are you sure you want to deregister?
18 |
19 | Yes
20 | No
21 |
22 | Select a photographic work.
23 | Select photographic work
24 |
25 | Register copyright
26 | Register
27 | Registering…
28 | Registration failed
29 | Registration application sent successfully.
30 | View registration information
31 | DCI code issued.
32 | Revoke copyright registration
33 | Add DCI icon for registered photographic work
34 |
35 | Register your work first.
36 | Registration in progress or failed.
37 |
38 | Revoke copyright registration for the work first.
39 | Request to revoke copyright registration sent successfully.
40 | View revoking result
41 | Copyright registration revoked successfully.
42 | Request to revoke copyright registration is being processed.
43 | Failed to revoke copyright registration for the work
44 |
45 |
--------------------------------------------------------------------------------
/app/src/main/java/com/huawei/codelab/dcidemo/utils/DataUtils.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2021. Huawei Technologies Co., Ltd. All rights reserved.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.huawei.codelab.dcidemo.utils;
18 |
19 | import android.text.TextUtils;
20 | import android.widget.Toast;
21 |
22 | import com.huawei.codelab.dcidemo.BuildConfig;
23 | import com.huawei.codelab.dcidemo.DciDemoApplication;
24 | import com.huawei.codelab.dcidemo.R;
25 | import com.huawei.hms.dci.entity.ParamsInfoEntity;
26 |
27 | /**
28 | * Data Utils class.
29 | *
30 | * @since 2021-06-02
31 | */
32 | public class DataUtils {
33 | private static final String APP_ID = BuildConfig.APPID;
34 | private static String HMS_TOKEN;
35 | private static String HMS_OPEN_ID;
36 | private static String DCI_UID;
37 |
38 | public static String getHmsToken() {
39 | return HMS_TOKEN;
40 | }
41 |
42 | public static void setHmsToken(String hmsToken) {
43 | HMS_TOKEN = hmsToken;
44 | }
45 |
46 | public static String getHmsOpenId() {
47 | return HMS_OPEN_ID;
48 | }
49 |
50 | public static void setHmsOpenId(String hmsOpenId) {
51 | HMS_OPEN_ID = hmsOpenId;
52 | }
53 |
54 | public static String getDciUid() {
55 | return DCI_UID;
56 | }
57 |
58 | public static void setDciUid(String dciUid) {
59 | DCI_UID = dciUid;
60 | }
61 |
62 | /**
63 | * Check whether the hms parameter is empty.
64 | *
65 | * @return true if the parameter is empty.
66 | */
67 | public static boolean checkHms() {
68 | if (TextUtils.isEmpty(DataUtils.getHmsToken()) || TextUtils.isEmpty(DataUtils.getHmsOpenId())) {
69 | Toast.makeText(DciDemoApplication.getInstance(), DciDemoApplication.getInstance().getString(R.string.please_login_hms_first), Toast.LENGTH_SHORT).show();
70 | return true;
71 | }
72 | return false;
73 | }
74 |
75 | /**
76 | * Encapsulates DCI Kit general parameters.
77 | *
78 | * @return paramsInfoEntity
79 | */
80 | public static ParamsInfoEntity getCommonParamsInfoEntity() {
81 | ParamsInfoEntity paramsInfoEntity = new ParamsInfoEntity();
82 | paramsInfoEntity.setHmsToken(HMS_TOKEN);
83 | paramsInfoEntity.setHmsAppId(APP_ID);
84 | paramsInfoEntity.setHmsOpenId(HMS_OPEN_ID);
85 | return paramsInfoEntity;
86 | }
87 | }
88 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_registration.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
13 |
14 |
22 |
23 |
31 |
32 |
40 |
41 |
49 |
50 |
58 |
59 |
67 |
68 |
73 |
74 |
75 |
--------------------------------------------------------------------------------
/app/src/main/java/com/huawei/codelab/dcidemo/utils/HmsLoginUtils.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2021. Huawei Technologies Co., Ltd. All rights reserved.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.huawei.codelab.dcidemo.utils;
18 |
19 | import android.app.Activity;
20 | import android.content.Intent;
21 |
22 | import com.huawei.codelab.dcidemo.view.MainActivity;
23 | import com.huawei.hmf.tasks.OnFailureListener;
24 | import com.huawei.hmf.tasks.OnSuccessListener;
25 | import com.huawei.hmf.tasks.Task;
26 | import com.huawei.hms.common.ApiException;
27 | import com.huawei.hms.support.account.AccountAuthManager;
28 | import com.huawei.hms.support.account.request.AccountAuthParams;
29 | import com.huawei.hms.support.account.request.AccountAuthParamsHelper;
30 | import com.huawei.hms.support.account.result.AuthAccount;
31 | import com.huawei.hms.support.account.service.AccountAuthService;
32 |
33 | /**
34 | * HMS Account login Utils class.
35 | *
36 | * @since 2021-06-02
37 | */
38 | public class HmsLoginUtils {
39 | /**
40 | * HMS Account login.
41 | *
42 | * @param activity Activity
43 | * @param loginHmsAccountCallBack HmsLoginCallBack
44 | */
45 | public static void loginHmsAccount(final Activity activity, final LoginHmsAccountCallBack loginHmsAccountCallBack) {
46 | AccountAuthParams authParams =
47 | new AccountAuthParamsHelper(AccountAuthParams.DEFAULT_AUTH_REQUEST_PARAM)
48 | .setAccessToken()
49 | .setProfile()
50 | .createParams();
51 | final AccountAuthService service = AccountAuthManager.getService(activity, authParams);
52 | Task mTask = service.silentSignIn();
53 | mTask.addOnSuccessListener(
54 | new OnSuccessListener() {
55 | @Override
56 | public void onSuccess(AuthAccount authAccount) {
57 | if (loginHmsAccountCallBack != null && authAccount != null) {
58 | loginHmsAccountCallBack.hmsLoginSuccess(authAccount.getAccessToken(), authAccount.getOpenId());
59 | }
60 | }
61 | });
62 | mTask.addOnFailureListener(
63 | new OnFailureListener() {
64 | @Override
65 | public void onFailure(Exception ex) {
66 | if (ex instanceof ApiException) {
67 | Intent signInIntent = service.getSignInIntent();
68 | if (signInIntent != null) {
69 | activity.startActivityForResult(signInIntent, MainActivity.HMS_ACCOUNT_SUCCESS_CODE);
70 | }
71 | } else {
72 | if (loginHmsAccountCallBack != null) {
73 | loginHmsAccountCallBack.hmsLoginFail(ex.getMessage());
74 | }
75 | }
76 | }
77 | });
78 | }
79 |
80 | /**
81 | * HMS Account login callback.
82 | */
83 | public interface LoginHmsAccountCallBack {
84 | /**
85 | * HMS Account login success.
86 | *
87 | * @param hmsToken token
88 | * @param hmsOpenId openId
89 | */
90 | void hmsLoginSuccess(String hmsToken, String hmsOpenId);
91 |
92 | /**
93 | * HMS Account login failed.
94 | *
95 | * @param msg error message
96 | */
97 | void hmsLoginFail(String msg);
98 | }
99 | }
100 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # HMS Core DCI Kit Sample Code for Android
2 |
3 | English | [中文](README_ZH.md)
4 |
5 | ## Contents
6 |
7 | * [Introduction](#introduction)
8 | * [Development Preparations](#development-preparations)
9 | * [Environment Requirements](#environment-requirements)
10 | * [Sample Code](#sample-code)
11 | * [Running Result](#running-result)
12 | * [License](#license)
13 |
14 | Introduction
15 | ------------
16 |
17 | Digital Copyright Identifier Kit (DCI Kit), developed by Huawei and Copyright Protection Center of China (CPCC), protects copyright on digital works by leveraging technologies related to the blockchain, big data, and AI, in compliance with the Copyright Law of People's Republic of China and DCI specifications and regulations. Capabilities provided by this kit include DCI user registration, copyright registration, copyright licensing, and copyright safeguarding. Information about successfully registered works will be stored in the blockchain, ensuring that all copyright information is reliable and traceable.
18 | ## Development Preparations
19 |
20 | The sample code, which is compiled using Gradle, shows how to integrate the DCI SDK for Android into an app.
21 |
22 | 1. Install Android Studio on your computer. Open the demo project in Android Studio. You can find **build.gradle** files in the project.
23 |
24 | 2. Register as a Huawei developer on [HUAWEI Developers](https://developer.huawei.com/consumer/en/). Create an app and configure app information in AppGallery Connect. For details, please refer to [Preparations](https://developer.huawei.com/consumer/en/doc/development/HMSCore-Guides/config-agc-0000001050196065). Integrate [Account Kit](https://developer.huawei.com/consumer/en/hms/huawei-accountkit). If you want copyright owners to be notified when a DCI code is issued, also integrate [Push Kit](https://developer.huawei.com/consumer/en/hms/huawei-pushkit).
25 |
26 | 3. Configure the sample code.
27 |
28 | (1) Download the **agconnect-services.json** file from AppGallery Connect and add it to the **app** directory of the demo project.
29 |
30 | (2) Open the app-level **build.gradle** file. Replace **APP_ID** with the app ID obtained from AppGallery Connect and **applicationId** with your app package name.
31 |
32 | (3) Generate a signing certificate fingerprint. Copy the generated signing certificate to the project and configure the signing certificate in the app-level **build.gradle** file.
33 |
34 | ## Environment Requirements
35 |
36 | - It is recommended that the Android Studio version be 3.0 or later, the Android SDK version be 24 or later, and the JDK version be 1.8 or later.
37 | - Supported devices: Huawei phones and tablets, and non-Huawei Android phones
38 | - Supported operating systems: EMUI 8.0 or later and Android 7.0 or later
39 | - HMS Core (APK) version: 5.0.1.301 or later
40 |
41 | ## Sample Code
42 |
43 | The sample code shows how to use capabilities of DCI Kit, including registration and deregistration of DCI users, obtaining information about a DCI user, registration and deregistration of photographic work copyrights, obtaining work copyright registration and deregistration information, and adding a DCI icon to registered photographic works.
44 |
45 | 1. **MainActivity.java**, which is under the **app\src\main\java\com\huawei\codelab\dcidemo** directory, is used for registration and deregistration of DCI users and obtaining information about a DCI user.
46 | 2. **RegistrationActivity.java**, which is under the **app\src\main\java\com\huawei\codelab\dcidemo** directory, is used for registration and deregistration of photographic work copyrights, obtaining information about work copyright registration and deregistration, and adding a DCI icon to registered photographic works.
47 |
48 | ## Running Result
49 |
50 | Information about the registered DCI users and works is printed in the log. In addition, the user deregistration or work copyright deregistration result will be displayed in a toast window.
51 |
52 | ## Technical Support
53 |
54 | You can visit the [Reddit community](https://www.reddit.com/r/HuaweiDevelopers/) to obtain the latest information about HMS Core and communicate with other developers.
55 |
56 | If you have any questions about the sample code, try the following:
57 |
58 | - Visit [Stack Overflow](https://stackoverflow.com/questions/tagged/huawei-mobile-services?tab=Votes) and submit your questions under the `huawei-mobile-services` tag. Huawei experts will help you.
59 | - Visit the HMS Core section in the [Huawei Developer Forum](https://forums.developer.huawei.com/forumPortal/en/forum/hms-core) and communicate with other developers.
60 |
61 | ## License
62 |
63 | The sample code is licensed under [Apache 2.0](http://www.apache.org/licenses/LICENSE-2.0).
64 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_launcher_background.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
10 |
15 |
20 |
25 |
30 |
35 |
40 |
45 |
50 |
55 |
60 |
65 |
70 |
75 |
80 |
85 |
90 |
95 |
100 |
105 |
110 |
115 |
120 |
125 |
130 |
135 |
140 |
145 |
150 |
155 |
160 |
165 |
170 |
171 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | Apache License
2 | Version 2.0, January 2004
3 | http://www.apache.org/licenses/
4 |
5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6 |
7 | 1. Definitions.
8 |
9 | "License" shall mean the terms and conditions for use, reproduction,
10 | and distribution as defined by Sections 1 through 9 of this document.
11 |
12 | "Licensor" shall mean the copyright owner or entity authorized by
13 | the copyright owner that is granting the License.
14 |
15 | "Legal Entity" shall mean the union of the acting entity and all
16 | other entities that control, are controlled by, or are under common
17 | control with that entity. For the purposes of this definition,
18 | "control" means (i) the power, direct or indirect, to cause the
19 | direction or management of such entity, whether by contract or
20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the
21 | outstanding shares, or (iii) beneficial ownership of such entity.
22 |
23 | "You" (or "Your") shall mean an individual or Legal Entity
24 | exercising permissions granted by this License.
25 |
26 | "Source" form shall mean the preferred form for making modifications,
27 | including but not limited to software source code, documentation
28 | source, and configuration files.
29 |
30 | "Object" form shall mean any form resulting from mechanical
31 | transformation or translation of a Source form, including but
32 | not limited to compiled object code, generated documentation,
33 | and conversions to other media types.
34 |
35 | "Work" shall mean the work of authorship, whether in Source or
36 | Object form, made available under the License, as indicated by a
37 | copyright notice that is included in or attached to the work
38 | (an example is provided in the Appendix below).
39 |
40 | "Derivative Works" shall mean any work, whether in Source or Object
41 | form, that is based on (or derived from) the Work and for which the
42 | editorial revisions, annotations, elaborations, or other modifications
43 | represent, as a whole, an original work of authorship. For the purposes
44 | of this License, Derivative Works shall not include works that remain
45 | separable from, or merely link (or bind by name) to the interfaces of,
46 | the Work and Derivative Works thereof.
47 |
48 | "Contribution" shall mean any work of authorship, including
49 | the original version of the Work and any modifications or additions
50 | to that Work or Derivative Works thereof, that is intentionally
51 | submitted to Licensor for inclusion in the Work by the copyright owner
52 | or by an individual or Legal Entity authorized to submit on behalf of
53 | the copyright owner. For the purposes of this definition, "submitted"
54 | means any form of electronic, verbal, or written communication sent
55 | to the Licensor or its representatives, including but not limited to
56 | communication on electronic mailing lists, source code control systems,
57 | and issue tracking systems that are managed by, or on behalf of, the
58 | Licensor for the purpose of discussing and improving the Work, but
59 | excluding communication that is conspicuously marked or otherwise
60 | designated in writing by the copyright owner as "Not a Contribution."
61 |
62 | "Contributor" shall mean Licensor and any individual or Legal Entity
63 | on behalf of whom a Contribution has been received by Licensor and
64 | subsequently incorporated within the Work.
65 |
66 | 2. Grant of Copyright License. Subject to the terms and conditions of
67 | this License, each Contributor hereby grants to You a perpetual,
68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69 | copyright license to reproduce, prepare Derivative Works of,
70 | publicly display, publicly perform, sublicense, and distribute the
71 | Work and such Derivative Works in Source or Object form.
72 |
73 | 3. Grant of Patent License. Subject to the terms and conditions of
74 | this License, each Contributor hereby grants to You a perpetual,
75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76 | (except as stated in this section) patent license to make, have made,
77 | use, offer to sell, sell, import, and otherwise transfer the Work,
78 | where such license applies only to those patent claims licensable
79 | by such Contributor that are necessarily infringed by their
80 | Contribution(s) alone or by combination of their Contribution(s)
81 | with the Work to which such Contribution(s) was submitted. If You
82 | institute patent litigation against any entity (including a
83 | cross-claim or counterclaim in a lawsuit) alleging that the Work
84 | or a Contribution incorporated within the Work constitutes direct
85 | or contributory patent infringement, then any patent licenses
86 | granted to You under this License for that Work shall terminate
87 | as of the date such litigation is filed.
88 |
89 | 4. Redistribution. You may reproduce and distribute copies of the
90 | Work or Derivative Works thereof in any medium, with or without
91 | modifications, and in Source or Object form, provided that You
92 | meet the following conditions:
93 |
94 | (a) You must give any other recipients of the Work or
95 | Derivative Works a copy of this License; and
96 |
97 | (b) You must cause any modified files to carry prominent notices
98 | stating that You changed the files; and
99 |
100 | (c) You must retain, in the Source form of any Derivative Works
101 | that You distribute, all copyright, patent, trademark, and
102 | attribution notices from the Source form of the Work,
103 | excluding those notices that do not pertain to any part of
104 | the Derivative Works; and
105 |
106 | (d) If the Work includes a "NOTICE" text file as part of its
107 | distribution, then any Derivative Works that You distribute must
108 | include a readable copy of the attribution notices contained
109 | within such NOTICE file, excluding those notices that do not
110 | pertain to any part of the Derivative Works, in at least one
111 | of the following places: within a NOTICE text file distributed
112 | as part of the Derivative Works; within the Source form or
113 | documentation, if provided along with the Derivative Works; or,
114 | within a display generated by the Derivative Works, if and
115 | wherever such third-party notices normally appear. The contents
116 | of the NOTICE file are for informational purposes only and
117 | do not modify the License. You may add Your own attribution
118 | notices within Derivative Works that You distribute, alongside
119 | or as an addendum to the NOTICE text from the Work, provided
120 | that such additional attribution notices cannot be construed
121 | as modifying the License.
122 |
123 | You may add Your own copyright statement to Your modifications and
124 | may provide additional or different license terms and conditions
125 | for use, reproduction, or distribution of Your modifications, or
126 | for any such Derivative Works as a whole, provided Your use,
127 | reproduction, and distribution of the Work otherwise complies with
128 | the conditions stated in this License.
129 |
130 | 5. Submission of Contributions. Unless You explicitly state otherwise,
131 | any Contribution intentionally submitted for inclusion in the Work
132 | by You to the Licensor shall be under the terms and conditions of
133 | this License, without any additional terms or conditions.
134 | Notwithstanding the above, nothing herein shall supersede or modify
135 | the terms of any separate license agreement you may have executed
136 | with Licensor regarding such Contributions.
137 |
138 | 6. Trademarks. This License does not grant permission to use the trade
139 | names, trademarks, service marks, or product names of the Licensor,
140 | except as required for reasonable and customary use in describing the
141 | origin of the Work and reproducing the content of the NOTICE file.
142 |
143 | 7. Disclaimer of Warranty. Unless required by applicable law or
144 | agreed to in writing, Licensor provides the Work (and each
145 | Contributor provides its Contributions) on an "AS IS" BASIS,
146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147 | implied, including, without limitation, any warranties or conditions
148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149 | PARTICULAR PURPOSE. You are solely responsible for determining the
150 | appropriateness of using or redistributing the Work and assume any
151 | risks associated with Your exercise of permissions under this License.
152 |
153 | 8. Limitation of Liability. In no event and under no legal theory,
154 | whether in tort (including negligence), contract, or otherwise,
155 | unless required by applicable law (such as deliberate and grossly
156 | negligent acts) or agreed to in writing, shall any Contributor be
157 | liable to You for damages, including any direct, indirect, special,
158 | incidental, or consequential damages of any character arising as a
159 | result of this License or out of the use or inability to use the
160 | Work (including but not limited to damages for loss of goodwill,
161 | work stoppage, computer failure or malfunction, or any and all
162 | other commercial damages or losses), even if such Contributor
163 | has been advised of the possibility of such damages.
164 |
165 | 9. Accepting Warranty or Additional Liability. While redistributing
166 | the Work or Derivative Works thereof, You may choose to offer,
167 | and charge a fee for, acceptance of support, warranty, indemnity,
168 | or other liability obligations and/or rights consistent with this
169 | License. However, in accepting such obligations, You may act only
170 | on Your own behalf and on Your sole responsibility, not on behalf
171 | of any other Contributor, and only if You agree to indemnify,
172 | defend, and hold each Contributor harmless for any liability
173 | incurred by, or claims asserted against, such Contributor by reason
174 | of your accepting any such warranty or additional liability.
175 |
176 | END OF TERMS AND CONDITIONS
--------------------------------------------------------------------------------
/app/src/main/java/com/huawei/codelab/dcidemo/view/MainActivity.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2021. Huawei Technologies Co., Ltd. All rights reserved.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.huawei.codelab.dcidemo.view;
18 |
19 | import android.app.AlertDialog;
20 | import android.content.DialogInterface;
21 | import android.content.Intent;
22 | import android.os.Bundle;
23 | import android.text.TextUtils;
24 | import android.util.Log;
25 | import android.view.View;
26 | import android.widget.Toast;
27 |
28 | import androidx.annotation.Nullable;
29 |
30 | import com.huawei.codelab.dcidemo.ErrorCode;
31 | import com.huawei.codelab.dcidemo.R;
32 | import com.huawei.codelab.dcidemo.push.HmsPushHelper;
33 | import com.huawei.codelab.dcidemo.utils.DataUtils;
34 | import com.huawei.codelab.dcidemo.utils.HmsLoginUtils;
35 | import com.huawei.hmf.tasks.Task;
36 | import com.huawei.hms.dci.entity.AccountInfoEntity;
37 | import com.huawei.hms.dci.entity.ParamsInfoEntity;
38 | import com.huawei.hms.dci.function.HwDciClientCallBack;
39 | import com.huawei.hms.dci.function.HwDciConstant;
40 | import com.huawei.hms.dci.function.HwDciException;
41 | import com.huawei.hms.dci.function.HwDciPublicClient;
42 | import com.huawei.hms.support.account.AccountAuthManager;
43 | import com.huawei.hms.support.account.result.AuthAccount;
44 |
45 | /**
46 | * Main Activity class.
47 | *
48 | * @since 2021-06-02
49 | */
50 | public class MainActivity extends BaseActivity implements View.OnClickListener {
51 | /**
52 | * HMS Account login success code.
53 | */
54 | public static final int HMS_ACCOUNT_SUCCESS_CODE = 1000;
55 |
56 | private static final int CODE_GET_DCI_ACCOUNT = 1001;
57 |
58 | private static final String TAG = "MainActivity";
59 |
60 | @Override
61 | protected void onCreate(Bundle savedInstanceState) {
62 | super.onCreate(savedInstanceState);
63 | setContentView(R.layout.activity_main);
64 | initListener();
65 | HmsPushHelper.getToken(this);
66 | }
67 |
68 | private void initListener() {
69 | findViewById(R.id.btn_login_hms_account).setOnClickListener(this);
70 | findViewById(R.id.btn_get_dci_account).setOnClickListener(this);
71 | findViewById(R.id.btn_register_dci_account).setOnClickListener(this);
72 | findViewById(R.id.btn_registration).setOnClickListener(this);
73 | findViewById(R.id.btn_close_dci_account).setOnClickListener(this);
74 | }
75 |
76 | @Override
77 | public void onClick(View view) {
78 | switch (view.getId()) {
79 | case R.id.btn_login_hms_account:
80 | // hms account login
81 | loginHmsAccount();
82 | break;
83 | case R.id.btn_register_dci_account:
84 | // register as DCI user
85 | registerDciAccount();
86 | break;
87 | case R.id.btn_close_dci_account:
88 | // show deregister DCI user dialog
89 | showCloseDciAccountDialog();
90 | break;
91 | case R.id.btn_get_dci_account:
92 | // DCI Kit obtains user information
93 | getDciAccount();
94 | break;
95 | case R.id.btn_registration:
96 | if (checkHmsAndDciInActive()) {
97 | return;
98 | }
99 | // register copyright for photographic work
100 | RegistrationActivity.start(this);
101 | break;
102 | default:
103 | break;
104 | }
105 | }
106 |
107 | private void loginHmsAccount() {
108 | showLoading();
109 | HmsLoginUtils.loginHmsAccount(
110 | this,
111 | new HmsLoginUtils.LoginHmsAccountCallBack() {
112 | @Override
113 | public void hmsLoginSuccess(String hmsToken, String hmsOpenId) {
114 | DataUtils.setHmsToken(hmsToken);
115 | DataUtils.setHmsOpenId(hmsOpenId);
116 | Toast.makeText(MainActivity.this, getString(R.string.hms_login_success), Toast.LENGTH_SHORT).show();
117 | dismissDialog();
118 | }
119 |
120 | @Override
121 | public void hmsLoginFail(String msg) {
122 | dismissDialog();
123 | Toast.makeText(MainActivity.this, msg, Toast.LENGTH_SHORT).show();
124 | }
125 | });
126 | }
127 |
128 | private void getDciAccount() {
129 | if (DataUtils.checkHms()) {
130 | return;
131 | }
132 | showLoading();
133 | ParamsInfoEntity paramsInfoEntity = DataUtils.getCommonParamsInfoEntity();
134 | // If the DCI Kit needs to register result notifications, the app needs to integrate the HMS push function and transfer the pushToken.
135 | // If this parameter is not required, do not transfer this parameter.
136 | paramsInfoEntity.setHmsPushToken(HmsPushHelper.PUSH_TOKEN);
137 | try {
138 | HwDciPublicClient.getDciAccount(
139 | paramsInfoEntity,
140 | new HwDciClientCallBack() {
141 | @Override
142 | public void onSuccess(AccountInfoEntity accountInfoEntity) {
143 | dismissDialog();
144 | Log.e(TAG, "DCI copyRight user ID = " + accountInfoEntity.getUserId());
145 | // save DCI Uid
146 | DataUtils.setDciUid(accountInfoEntity.getUserId());
147 | Toast.makeText(MainActivity.this, getString(R.string.succeeded_get_dci_account), Toast.LENGTH_SHORT).show();
148 | }
149 |
150 | @Override
151 | public void onFail(int code, String s) {
152 | dismissDialog();
153 | Log.e(TAG, "code = " + code + " ,message = " + s);
154 | if (code == ErrorCode.NOT_REGISTER) {
155 | // The current hms account has not been registered as a DCI copyright user.
156 | Toast.makeText(MainActivity.this, getString(R.string.current_not_register_dci_account), Toast.LENGTH_SHORT).show();
157 | } else if (code == ErrorCode.HW_TOKEN_OR_UID_NOT_USED) {
158 | // hms token or openId unavailable
159 | Toast.makeText(MainActivity.this, getString(R.string.please_login_hms_again), Toast.LENGTH_SHORT).show();
160 | } else {
161 | // other error
162 | }
163 | }
164 | });
165 | } catch (HwDciException e) {
166 | dismissDialog();
167 | Log.e(TAG, e.getMessage());
168 | }
169 | }
170 |
171 | private void registerDciAccount() {
172 | if (DataUtils.checkHms()) {
173 | return;
174 | }
175 | ParamsInfoEntity paramsInfoEntity = DataUtils.getCommonParamsInfoEntity();
176 | paramsInfoEntity.setHmsPushToken(HmsPushHelper.PUSH_TOKEN);
177 | try {
178 | HwDciPublicClient.registerDciAccount(MainActivity.this, paramsInfoEntity, CODE_GET_DCI_ACCOUNT);
179 | } catch (HwDciException ex) {
180 | Log.e(TAG, ex.getMessage());
181 | }
182 | }
183 |
184 | private void showCloseDciAccountDialog() {
185 | if (checkHmsAndDciInActive()) {
186 | return;
187 | }
188 | AlertDialog.Builder builder = new AlertDialog.Builder(this);
189 | builder.setTitle(getString(R.string.deregister_dci_account_whether)).setPositiveButton(getString(R.string.yes), new DialogInterface.OnClickListener() {
190 | @Override
191 | public void onClick(DialogInterface dialog, int which) {
192 | closeAccount();
193 | }
194 | }).setNegativeButton(getString(R.string.no), (dialog, which) -> dialog.dismiss()).create().show();
195 | }
196 |
197 | private void closeAccount() {
198 | showLoading();
199 | ParamsInfoEntity paramsInfoEntity = DataUtils.getCommonParamsInfoEntity();
200 | paramsInfoEntity.setDciUid(DataUtils.getDciUid());
201 | try {
202 | HwDciPublicClient.closeDciAccount(
203 | paramsInfoEntity,
204 | new CommonFailCallBack() {
205 | @Override
206 | public void onSuccess(Boolean aBoolean) {
207 | dismissDialog();
208 | if (aBoolean == null) {
209 | return;
210 | }
211 | if (aBoolean) {
212 | Toast.makeText(MainActivity.this, getString(R.string.close_dci_account_success), Toast.LENGTH_SHORT).show();
213 | DataUtils.setDciUid(null);
214 | } else {
215 | Toast.makeText(MainActivity.this, getString(R.string.close_dci_account_failed), Toast.LENGTH_SHORT).show();
216 | }
217 | }
218 | });
219 | } catch (HwDciException ex) {
220 | dismissDialog();
221 | Log.e(TAG, ex.getMessage());
222 | }
223 | }
224 |
225 | @Override
226 | protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
227 | super.onActivityResult(requestCode, resultCode, data);
228 | dismissDialog();
229 | if (resultCode != RESULT_OK || data == null) {
230 | return;
231 | }
232 | if (requestCode == HMS_ACCOUNT_SUCCESS_CODE) {
233 | Task authAccountTask = AccountAuthManager.parseAuthResultFromIntent(data);
234 | if (authAccountTask == null) {
235 | Log.e(TAG, "onActivityResult authAccountTask is null");
236 | return;
237 | }
238 | if (authAccountTask.isSuccessful()) {
239 | AuthAccount authAccount = authAccountTask.getResult();
240 | if (authAccount != null) {
241 | DataUtils.setHmsToken(authAccount.getAccessToken());
242 | DataUtils.setHmsOpenId(authAccount.getOpenId());
243 | Toast.makeText(MainActivity.this, getString(R.string.hms_login_success), Toast.LENGTH_SHORT).show();
244 | }
245 | } else {
246 | Log.e(TAG, "onActivityResult authAccountTask exception");
247 | }
248 | } else if (requestCode == CODE_GET_DCI_ACCOUNT) {
249 | // DCI user is registered successfully
250 | if (!data.hasExtra(HwDciConstant.DCI_REGISTER_RESULT_CODE)) {
251 | return;
252 | }
253 | int code = data.getIntExtra(HwDciConstant.DCI_REGISTER_RESULT_CODE, 0);
254 | if (code == ErrorCode.GET_DCI_ACCOUNT_SUCCESS_CODE) {
255 | AccountInfoEntity accountInfoEntity = data.getParcelableExtra(HwDciConstant.DCI_ACCOUNT_INFO_KEY);
256 | if (accountInfoEntity != null) {
257 | Log.e(TAG, "DCI copyRight user ID = " + accountInfoEntity.getUserId());
258 | DataUtils.setDciUid(accountInfoEntity.getUserId());
259 | }
260 | Toast.makeText(MainActivity.this, getString(R.string.succeeded_get_dci_account), Toast.LENGTH_SHORT).show();
261 | } else {
262 | onActivityResultError(code);
263 | }
264 | }
265 | }
266 |
267 | private void onActivityResultError(int code) {
268 | switch (code) {
269 | case ErrorCode.REAL_NAME_FAIL_AS_FORCIBLE_EXIT:
270 | Log.e(TAG, "Real-Name Authentication Failure Caused by Forcible Exit");
271 | break;
272 | case ErrorCode.HW_TOKEN_OR_UID_NOT_USED:
273 | Log.e(TAG, "Hms token or openId unavailable");
274 | Toast.makeText(this, getString(R.string.please_login_hms_again), Toast.LENGTH_SHORT).show();
275 | break;
276 | case ErrorCode.REAL_NAME_FAIL_AS_TOKEN_OR_OPENID_NULL:
277 | Log.e(TAG, "Hms token or openId is null");
278 | break;
279 | default:
280 | break;
281 | }
282 | }
283 |
284 | private boolean checkHmsAndDciInActive() {
285 | if (DataUtils.checkHms()) {
286 | return true;
287 | }
288 | if (TextUtils.isEmpty(DataUtils.getDciUid())) {
289 | Toast.makeText(this, getString(R.string.please_get_dci_account), Toast.LENGTH_SHORT).show();
290 | return true;
291 | }
292 | return false;
293 | }
294 | }
295 |
--------------------------------------------------------------------------------
/app/src/main/java/com/huawei/codelab/dcidemo/view/RegistrationActivity.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2021. Huawei Technologies Co., Ltd. All rights reserved.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.huawei.codelab.dcidemo.view;
18 |
19 | import android.app.Activity;
20 | import android.content.Intent;
21 | import android.graphics.Bitmap;
22 | import android.graphics.BitmapFactory;
23 | import android.net.Uri;
24 | import android.os.Bundle;
25 | import android.os.Handler;
26 | import android.os.Message;
27 | import android.os.ParcelFileDescriptor;
28 | import android.text.TextUtils;
29 | import android.util.Base64;
30 | import android.util.Log;
31 | import android.view.MenuItem;
32 | import android.view.View;
33 | import android.widget.ImageView;
34 | import android.widget.Toast;
35 |
36 | import androidx.annotation.NonNull;
37 | import androidx.annotation.Nullable;
38 | import androidx.appcompat.app.ActionBar;
39 |
40 | import com.huawei.codelab.dcidemo.R;
41 | import com.huawei.codelab.dcidemo.utils.DataUtils;
42 | import com.huawei.hms.dci.entity.ParamsInfoEntity;
43 | import com.huawei.hms.dci.entity.QueryRevokeDciInfoEntity;
44 | import com.huawei.hms.dci.entity.WorkDciInfoEntity;
45 | import com.huawei.hms.dci.function.HwDciException;
46 | import com.huawei.hms.dci.function.HwDciPublicClient;
47 |
48 | import java.io.FileDescriptor;
49 | import java.io.FileNotFoundException;
50 | import java.io.IOException;
51 | import java.lang.ref.WeakReference;
52 |
53 | /**
54 | * Register copyright for photographic work class.
55 | *
56 | * @since 2021-06-02
57 | */
58 | public class RegistrationActivity extends BaseActivity implements View.OnClickListener {
59 | private static final String TAG = "RegistrationActivity";
60 |
61 | private static final int PICTURE_REQUEST_CODE = 1002;
62 |
63 | private String mWorkId;
64 |
65 | private DealImageHandler mDealImageHandler;
66 |
67 | private String mDciCode;
68 |
69 | private Uri selectUri;
70 |
71 | private ImageView mImageView;
72 |
73 | private boolean isRevokingWork;
74 |
75 | /**
76 | * Start DCI Work Registration Processing class.
77 | *
78 | * @param context Activity
79 | */
80 | public static void start(Activity context) {
81 | Intent intent = new Intent(context, RegistrationActivity.class);
82 | context.startActivity(intent);
83 | }
84 |
85 | @Override
86 | protected void onCreate(@Nullable Bundle savedInstanceState) {
87 | super.onCreate(savedInstanceState);
88 | setContentView(R.layout.activity_registration);
89 | mDealImageHandler = new DealImageHandler(this);
90 | ActionBar actionBar = getSupportActionBar();
91 | if (actionBar != null) {
92 | actionBar.setTitle(getString(R.string.about_registration));
93 | actionBar.setDisplayHomeAsUpEnabled(true);
94 | }
95 | initView();
96 | initData(getIntent());
97 | }
98 |
99 | private void initView() {
100 | mImageView = findViewById(R.id.iv_dci_logo);
101 | findViewById(R.id.btn_select_picture).setOnClickListener(this);
102 | findViewById(R.id.btn_dci_registration).setOnClickListener(this);
103 | findViewById(R.id.btn_query_result).setOnClickListener(this);
104 | findViewById(R.id.btn_add_dci_watermark).setOnClickListener(this);
105 | findViewById(R.id.btn_revoke_copyright).setOnClickListener(this);
106 | findViewById(R.id.btn_query_revoke_dci_info).setOnClickListener(this);
107 | }
108 |
109 | private void initData(Intent intent) {
110 | if (intent == null) {
111 | return;
112 | }
113 | // If you integrate the HMS Push capability and choose Obtaining DCI Copyright User Information or Registering a DCI Copyright User,the hmsPushToken parameter is transferred.
114 | // When there is a result notification for DCI registration, the notification bar will display the result notification of DCI registration.
115 | // Click DCI registration result notification. The activity for configuring the corresponding scheme protocol is displayed (for details, see AndroidManifest.xml).
116 | // You can obtain the URI from the intent and parse the DCI work ID, DCI registration status, and DCI code.
117 | Uri data = intent.getData();
118 | if (data != null) {
119 | try {
120 | // state DCI Registered Work Status:1:success 2:fail 3:revoked 4:manual review
121 | String workId = data.getQueryParameter("workId");
122 | String state = data.getQueryParameter("state");
123 | String dciCode = data.getQueryParameter("dciCode");
124 | Log.e(TAG, "DCI Registered Work ID = " + workId);
125 | Log.e(TAG, "The status of the work registered by DCI = " + state);
126 | Log.e(TAG, "DCI code = " + dciCode);
127 | } catch (RuntimeException ex) {
128 | Log.e(TAG, "uri getQueryParameter exception");
129 | }
130 | }
131 | }
132 |
133 | @Override
134 | public boolean onOptionsItemSelected(@NonNull MenuItem item) {
135 | if (item.getItemId() == android.R.id.home) {
136 | onBackPressed();
137 | return true;
138 | } else {
139 | return super.onOptionsItemSelected(item);
140 | }
141 | }
142 |
143 | @Override
144 | public void onClick(View view) {
145 | switch (view.getId()) {
146 | case R.id.btn_select_picture:
147 | // select photographic work
148 | selectWorkPic();
149 | break;
150 | case R.id.btn_dci_registration:
151 | // register
152 | applyDciCode();
153 | break;
154 | case R.id.btn_query_result:
155 | // view registration information
156 | queryDciResult();
157 | break;
158 | case R.id.btn_revoke_copyright:
159 | // deregister
160 | revokeDciCode();
161 | break;
162 | case R.id.btn_query_revoke_dci_info:
163 | // query revoke dci info
164 | queryRevokeDciInfo();
165 | break;
166 | case R.id.btn_add_dci_watermark:
167 | // add DCI icon for registered photographic work
168 | addDciWatermark();
169 | break;
170 | default:
171 | break;
172 | }
173 | }
174 |
175 | @Override
176 | protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
177 | super.onActivityResult(requestCode, resultCode, data);
178 | dismissDialog();
179 | if (resultCode != RESULT_OK || data == null) {
180 | return;
181 | }
182 | if (requestCode == PICTURE_REQUEST_CODE) {
183 | if (data.getData() == null) {
184 | return;
185 | }
186 | selectUri = data.getData();
187 | try {
188 | ParcelFileDescriptor fd = getContentResolver().openFileDescriptor(selectUri, "r");
189 | if (fd == null) {
190 | return;
191 | }
192 | showLoading();
193 | getBitmap(fd);
194 | } catch (FileNotFoundException e) {
195 | dismissDialog();
196 | Log.e(TAG, "openFileDescriptor FileNotFoundException");
197 | }
198 | }
199 | }
200 |
201 | private void getBitmap(ParcelFileDescriptor fd) {
202 | new Thread(new Runnable() {
203 | @Override
204 | public void run() {
205 | FileDescriptor fileDescriptor = fd.getFileDescriptor();
206 | BitmapFactory.Options options = new BitmapFactory.Options();
207 | options.inJustDecodeBounds = true;
208 | BitmapFactory.decodeFileDescriptor(fileDescriptor, null, options);
209 | options.inJustDecodeBounds = false;
210 | options.inSampleSize = calculateInSampleSize(options, 800, 800);
211 | Bitmap bitmap = BitmapFactory.decodeFileDescriptor(fileDescriptor, null, options);
212 | Message message = Message.obtain();
213 | message.obj = bitmap;
214 | mDealImageHandler.sendMessage(message);
215 | try {
216 | fd.close();
217 | } catch (IOException e) {
218 | Log.e(TAG, "ParcelFileDescriptor close IOException");
219 | }
220 | }
221 | }).start();
222 | }
223 |
224 | private static int calculateInSampleSize(BitmapFactory.Options options, int reqWidth, int reqHeight) {
225 | final int width = options.outWidth;
226 | final int height = options.outHeight;
227 | int inSampleSize = 1;
228 | if (width > reqWidth && height > reqHeight) {
229 | inSampleSize = Math.min(Math.round((float) width / (float) reqWidth), Math.round((float) height / (float) reqHeight));
230 | }
231 | return inSampleSize;
232 | }
233 |
234 | @Override
235 | protected void onNewIntent(Intent intent) {
236 | super.onNewIntent(intent);
237 | initData(intent);
238 | }
239 |
240 | private void selectWorkPic() {
241 | Intent intent = new Intent(Intent.ACTION_PICK);
242 | intent.setType("image/*");
243 | startActivityForResult(intent, PICTURE_REQUEST_CODE);
244 | }
245 |
246 | private void applyDciCode() {
247 | if (selectUri == null) {
248 | Toast.makeText(this, getString(R.string.please_select_picture_first), Toast.LENGTH_SHORT).show();
249 | return;
250 | }
251 | showLoading();
252 | ParamsInfoEntity paramsInfoEntity = DataUtils.getCommonParamsInfoEntity();
253 | paramsInfoEntity.setDciUid(DataUtils.getDciUid());
254 | try {
255 | // location address Fill in the actual information
256 | HwDciPublicClient.applyDciCode(
257 | paramsInfoEntity,
258 | selectUri,
259 | "北京市",
260 | System.currentTimeMillis(),
261 | new CommonFailCallBack() {
262 | @Override
263 | public void onSuccess(String workId) {
264 | Log.e(TAG, "DCI Registered Work ID = " + workId);
265 | isRevokingWork = false;
266 | mDciCode = null;
267 | mWorkId = workId;
268 | dismissDialog();
269 | Toast.makeText(RegistrationActivity.this, getString(R.string.uploading_registered_work_succeeded), Toast.LENGTH_SHORT).show();
270 | }
271 | });
272 | } catch (HwDciException e) {
273 | dismissDialog();
274 | Log.e(TAG, e.getMessage());
275 | }
276 | }
277 |
278 | private void queryDciResult() {
279 | if (TextUtils.isEmpty(mWorkId)) {
280 | Toast.makeText(this, getString(R.string.please_registration_work_first), Toast.LENGTH_SHORT).show();
281 | return;
282 | }
283 | showLoading();
284 | ParamsInfoEntity paramsInfoEntity = DataUtils.getCommonParamsInfoEntity();
285 | paramsInfoEntity.setDciUid(DataUtils.getDciUid());
286 | paramsInfoEntity.setWorkId(mWorkId);
287 | try {
288 | HwDciPublicClient.queryWorkDciInfo(paramsInfoEntity, new CommonFailCallBack() {
289 | @Override
290 | public void onSuccess(WorkDciInfoEntity result) {
291 | dismissDialog();
292 | if (result == null) {
293 | return;
294 | }
295 | // 0:dealing 1:success 2:fail
296 | if (result.getRegistrationStatus() == 1) {
297 | mDciCode = result.getDciCode();
298 | Log.e(TAG, "DCI code = " + mDciCode);
299 | Toast.makeText(RegistrationActivity.this, getString(R.string.registration_success), Toast.LENGTH_SHORT).show();
300 | } else if (result.getRegistrationStatus() == 0) {
301 | Toast.makeText(RegistrationActivity.this, getString(R.string.registration_processing), Toast.LENGTH_SHORT).show();
302 | } else {
303 | Toast.makeText(RegistrationActivity.this, getString(R.string.registration_failed) + ":" + result.getMessage(), Toast.LENGTH_SHORT).show();
304 | }
305 | }
306 | });
307 | } catch (HwDciException ex) {
308 | dismissDialog();
309 | Log.e(TAG, ex.getMessage());
310 | }
311 | }
312 |
313 | private void revokeDciCode() {
314 | if (TextUtils.isEmpty(mDciCode)) {
315 | Toast.makeText(this, getString(R.string.please_query_dci_registration_result), Toast.LENGTH_SHORT).show();
316 | return;
317 | }
318 | showLoading();
319 | ParamsInfoEntity paramsInfoEntity = DataUtils.getCommonParamsInfoEntity();
320 | paramsInfoEntity.setDciUid(DataUtils.getDciUid());
321 | try {
322 | HwDciPublicClient.revokeDciCode(paramsInfoEntity, mDciCode, new CommonFailCallBack() {
323 | @Override
324 | public void onSuccess(String workId) {
325 | dismissDialog();
326 | isRevokingWork = true;
327 | mWorkId = workId;
328 | Toast.makeText(RegistrationActivity.this, getString(R.string.apply_revoke_dci_success), Toast.LENGTH_SHORT).show();
329 | }
330 | });
331 | } catch (HwDciException e) {
332 | dismissDialog();
333 | Log.e(TAG, e.getMessage());
334 | }
335 | }
336 |
337 | private void queryRevokeDciInfo() {
338 | if (!isRevokingWork) {
339 | Toast.makeText(this, getString(R.string.please_revoke_dci_info_first), Toast.LENGTH_SHORT).show();
340 | return;
341 | }
342 | showLoading();
343 | ParamsInfoEntity paramsInfoEntity = DataUtils.getCommonParamsInfoEntity();
344 | paramsInfoEntity.setDciUid(DataUtils.getDciUid());
345 | paramsInfoEntity.setWorkId(mWorkId);
346 | try {
347 | HwDciPublicClient.queryRevokeDciCodeInfo(paramsInfoEntity, new CommonFailCallBack() {
348 | @Override
349 | public void onSuccess(QueryRevokeDciInfoEntity result) {
350 | dismissDialog();
351 | if (result == null) {
352 | return;
353 | }
354 | // 0:dealing 1:success 2:fail
355 | if (result.getCode() == 1) {
356 | mDciCode = null;
357 | isRevokingWork = false;
358 | mWorkId = null;
359 | Toast.makeText(RegistrationActivity.this, getString(R.string.revoke_dci_registration_success), Toast.LENGTH_SHORT).show();
360 | } else if (result.getCode() == 0) {
361 | Toast.makeText(RegistrationActivity.this, getString(R.string.revoke_dci_registration_processing), Toast.LENGTH_SHORT).show();
362 | } else {
363 | Toast.makeText(RegistrationActivity.this, getString(R.string.revoke_dci_registration_failed) + ":" + result.getMessage(), Toast.LENGTH_SHORT).show();
364 | }
365 | }
366 | });
367 | } catch (HwDciException ex) {
368 | dismissDialog();
369 | Log.e(TAG, ex.getMessage());
370 | }
371 | }
372 |
373 | private void addDciWatermark() {
374 | if (selectUri == null) {
375 | Toast.makeText(this, getString(R.string.please_select_picture_first), Toast.LENGTH_SHORT).show();
376 | return;
377 | }
378 | showLoading();
379 | try {
380 | HwDciPublicClient.addDciWatermark(selectUri, new CommonFailCallBack() {
381 | @Override
382 | public void onSuccess(String strBitmap) {
383 | dismissDialog();
384 | if (!TextUtils.isEmpty(strBitmap)) {
385 | stringToBitmap(strBitmap);
386 | }
387 | }
388 | });
389 | } catch (HwDciException ex) {
390 | dismissDialog();
391 | Log.e(TAG, ex.getMessage());
392 | }
393 | }
394 |
395 | private void stringToBitmap(String string) {
396 | new Thread(() -> {
397 | try {
398 | byte[] bitmapArray = Base64.decode(string, Base64.DEFAULT);
399 | if (bitmapArray != null) {
400 | Bitmap bitmap = BitmapFactory.decodeByteArray(bitmapArray, 0, bitmapArray.length);
401 | Message message = Message.obtain();
402 | message.obj = bitmap;
403 | mDealImageHandler.sendMessage(message);
404 | }
405 | } catch (IllegalArgumentException ex) {
406 | Log.e(TAG, "decode base64 exception");
407 | }
408 | }).start();
409 | }
410 |
411 | /**
412 | * Handler class.
413 | *
414 | * @since 2021-06-02
415 | */
416 | private static class DealImageHandler extends Handler {
417 | private WeakReference mReference;
418 |
419 | public DealImageHandler(RegistrationActivity activity) {
420 | mReference = new WeakReference<>(activity);
421 | }
422 |
423 | @Override
424 | public void handleMessage(@NonNull Message msg) {
425 | super.handleMessage(msg);
426 | if (mReference == null) {
427 | return;
428 | }
429 | RegistrationActivity preDealActivity = mReference.get();
430 | if (preDealActivity != null) {
431 | preDealActivity.dismissDialog();
432 | if (msg.obj instanceof Bitmap) {
433 | preDealActivity.mImageView.setImageBitmap((Bitmap) msg.obj);
434 | }
435 | }
436 | }
437 | }
438 | }
439 |
--------------------------------------------------------------------------------