diff --git a/README.md b/README.md index 2a6a2e6..fdb4d31 100755 --- a/README.md +++ b/README.md @@ -61,6 +61,13 @@ AnalysysAgent.setVisitorConfigURL(context, CONFIG_URL); ``` +3.可视化埋点功能 + +- 在项目根目录文件gradle.properties 设置 Build_Type=visual +- 运行apidemo项目,启动后进入可视化demo入口 +- 打开 https://growth.analysys.cn/project-management/visual-choice 左上角选中电商Demo,选Android平台 +- 在app打开的情况下摇一摇,设备连接成功后点击设备进入埋点界面 +- 点击View添加事件,点击右下方部署下发配置 diff --git a/ans-demo/apidemo/build.gradle b/ans-demo/apidemo/build.gradle index 505d1d7..feaac6b 100644 --- a/ans-demo/apidemo/build.gradle +++ b/ans-demo/apidemo/build.gradle @@ -48,6 +48,8 @@ android { signingConfig signingConfigs.release } } + //repositories { maven { url "https://maven.aliyun.com/repository/google" } } + } @@ -64,6 +66,12 @@ android { useNewCruncher = false } + repositories { + flatDir { + dirs 'libs' //this way we can find the .aar file in libs folder + } + } + lintOptions { checkReleaseBuilds false abortOnError false @@ -89,22 +97,23 @@ android { } dependencies { - + //implementation fileTree(include: ['*.aar'], dir: 'libs') if (apidemo_depend.toBoolean()) { api project(':analysys_arkanalysys') } else { api 'cn.com.analysys:analysys-arkanalysys:latest.release' } + //api project(':analysys-tools') -// api project(':analysys-tools') - - api project(':compatibilityDemo') - api project(':visualDemo') - + //api project(':compatibilityDemo') + //implementation(name: 'toolsLibrary', ext: 'aar') + //compile files('libs/toolsLibrary-debug.aar') implementation 'androidx.appcompat:appcompat:1.0.2' implementation 'com.google.android.material:material:1.0.0' + implementation 'androidx.fragment:fragment:1.0.0' + compileOnly 'androidx.recyclerview:recyclerview:1.0.0' } // 忽略文档编译错误. 设置编码 diff --git a/ans-demo/apidemo/libs/toolsLibrary.aar b/ans-demo/apidemo/libs/toolsLibrary.aar new file mode 100644 index 0000000..3f23867 Binary files /dev/null and b/ans-demo/apidemo/libs/toolsLibrary.aar differ diff --git a/ans-demo/apidemo/src/main/AndroidManifest.xml b/ans-demo/apidemo/src/main/AndroidManifest.xml index b76d4ac..c8123ba 100644 --- a/ans-demo/apidemo/src/main/AndroidManifest.xml +++ b/ans-demo/apidemo/src/main/AndroidManifest.xml @@ -6,53 +6,66 @@ android:versionName="1.0"> - - + - + - + - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + - - - + android:name="com.analysys.demo.Process2Activity" + android:process=":process2" /> + android:value="false" /> - - - - + android:value="false" /> \ No newline at end of file diff --git a/ans-demo/apidemo/src/main/assets/analysys.crt b/ans-demo/apidemo/src/main/assets/analysys.crt index 05eb1cb..379fe98 100644 --- a/ans-demo/apidemo/src/main/assets/analysys.crt +++ b/ans-demo/apidemo/src/main/assets/analysys.crt @@ -1,61 +1,60 @@ -----BEGIN CERTIFICATE----- -MIIGBTCCBO2gAwIBAgIMXR+tQNcr5HlTR/fLMA0GCSqGSIb3DQEBCwUAMGAxCzAJ -BgNVBAYTAkJFMRkwFwYDVQQKExBHbG9iYWxTaWduIG52LXNhMTYwNAYDVQQDEy1H -bG9iYWxTaWduIERvbWFpbiBWYWxpZGF0aW9uIENBIC0gU0hBMjU2IC0gRzIwHhcN -MTgwODMwMDgzNzI0WhcNMTkxMDE2MDkxNzA5WjA7MSEwHwYDVQQLExhEb21haW4g -Q29udHJvbCBWYWxpZGF0ZWQxFjAUBgNVBAMMDSouYW5hbHlzeXMuY24wggEiMA0G -CSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQDNd+iI8yTeRDlllxyr55Zphc0oWtmV -qiXjHfXr2a1C8Zh8JKSb6DI1CNLnlhTeNMjDQOHiy3CI1tExHK07ml04+nFo5Og8 -rv8kf2XbgR0tb5JYk8azuGTHTK3xU9uR1B0kQXJ+c9RJow2zaDmZU+hgO/+090RR -W34rlCvL8fOfUFxxUyetKwkwaqZPPXZWen3B6XqjBDzZR9W9IksO8F4pkz4StnCQ -77XnIkQ39SE8s/YtVrE4a67d/4c/V+EsecaFQw1A6Hpdx3NotWEHlXR8KelUzlnI -KRLDZAUtKvbzaoD/TN8T3fP2M38bcby9EIBw2nrC4Sy02fxX3qemz9FzAgMBAAGj -ggLiMIIC3jAOBgNVHQ8BAf8EBAMCBaAwgZQGCCsGAQUFBwEBBIGHMIGEMEcGCCsG -AQUFBzAChjtodHRwOi8vc2VjdXJlLmdsb2JhbHNpZ24uY29tL2NhY2VydC9nc2Rv -bWFpbnZhbHNoYTJnMnIxLmNydDA5BggrBgEFBQcwAYYtaHR0cDovL29jc3AyLmds -b2JhbHNpZ24uY29tL2dzZG9tYWludmFsc2hhMmcyMFYGA1UdIARPME0wQQYJKwYB -BAGgMgEKMDQwMgYIKwYBBQUHAgEWJmh0dHBzOi8vd3d3Lmdsb2JhbHNpZ24uY29t -L3JlcG9zaXRvcnkvMAgGBmeBDAECATAJBgNVHRMEAjAAMEMGA1UdHwQ8MDowOKA2 -oDSGMmh0dHA6Ly9jcmwuZ2xvYmFsc2lnbi5jb20vZ3MvZ3Nkb21haW52YWxzaGEy -ZzIuY3JsMCUGA1UdEQQeMByCDSouYW5hbHlzeXMuY26CC2FuYWx5c3lzLmNuMB0G -A1UdJQQWMBQGCCsGAQUFBwMBBggrBgEFBQcDAjAdBgNVHQ4EFgQUGUsML6T46hcT -5MQfz4jn03TsjiYwHwYDVR0jBBgwFoAU6k581IAt5RWBhiaMgm3AmKTPlw8wggEF -BgorBgEEAdZ5AgQCBIH2BIHzAPEAdwCkuQmQtBhYFIe7E6LMZ3AKPDWYBPkb37jj -d80OyA3cEAAAAWWJ+utGAAAEAwBIMEYCIQCe72SI8LiGAtUFe77tbMKJH+V2uTjl -ZZtkzXECFU7N8gIhAOB6atSPaPMgwoYT3nTfPMZbbibp9VpfqCM27w7kbhsQAHYA -b1N2rDHwMRnYmQCkURX/dxUcEdkCwQApBo2yCJo32RMAAAFlifrqJQAABAMARzBF -AiEAhTWQDAaTOseORIQylP8vxA7Kq7N2wydnGGR3YeEurmcCIETXRMDfIXvdx4rn -WWRbdtnJ2SomPbtBGSwDSKNS5xayMA0GCSqGSIb3DQEBCwUAA4IBAQAWwmnMzhp0 -HGsc5qSjAKgC/hhL0Sl0/87ZaLcu96y+NdMl2TZTQUUZA/sSMA65lnLu2/wW9Y+J -W1zVIcjW6uz2+Hs3Badid3+DeXOdCjpMjaW+PWhsvGwk3ubUs4j98myoCBHSES4f -FkOt1z5Cb6neMuR3OharpARxU4jN5wit7MZ6+cdNMD/qPkRkT+SPscfl0KobW7Ye -J35Z/XneS0wVUQ4rYW19wzb0FtBeQMWA+nM03u29C7gv4XOVPsINP6pz1n3Wr5l5 -wd76Xau1kmgCzJfsh++X39CwCFv/cVSPucTKFyGdqHQh16yjrCSCkaOutuQwjc93 -L6EhyjbVIou3 +MIIF6TCCBNGgAwIBAgIMJN2w0dtEGfsvA7gOMA0GCSqGSIb3DQEBCwUAMFAxCzAJ +BgNVBAYTAkJFMRkwFwYDVQQKExBHbG9iYWxTaWduIG52LXNhMSYwJAYDVQQDEx1H +bG9iYWxTaWduIFJTQSBEViBTU0wgQ0EgMjAxODAeFw0xOTA5MTkwNjQwMjNaFw0y +MDExMTUwOTE3MDlaMDsxITAfBgNVBAsTGERvbWFpbiBDb250cm9sIFZhbGlkYXRl +ZDEWMBQGA1UEAwwNKi5hbmFseXN5cy5jbjCCASIwDQYJKoZIhvcNAQEBBQADggEP +ADCCAQoCggEBAL6Gim7IHHe5GhPaSWOom2pWfnPSZiTiJPDNstYa5iwm2RkdbHRz +MYJJdPMS4IFkMls1wJ0rddUblIgdN7vizE5SwAtON7jnR1icbtiHeXqnDuHZqE5o +R+nnEMeDyBiwbhbakauLJ2DG1dv3dP/3NL/B8Cxy4EbeUWDdxqYfHfeNuAqRiKia +ZzmlQirMYx/2lZkkbOE0loTB/XqAVTPdM9pqyXVKz7iOtc8uAfA963wHjrRMIZe9 +rbLw2UfmRtu8jVL6wqzRH38E5Jf1QSd4wALvrhp0oF35GrNWa0urT2Ckbnw43Q4+ +DVNrRMIb2UJZGL+BapPn4TCfK10s8Uuhd/ECAwEAAaOCAtYwggLSMA4GA1UdDwEB +/wQEAwIFoDCBjgYIKwYBBQUHAQEEgYEwfzBEBggrBgEFBQcwAoY4aHR0cDovL3Nl +Y3VyZS5nbG9iYWxzaWduLmNvbS9jYWNlcnQvZ3Nyc2FkdnNzbGNhMjAxOC5jcnQw +NwYIKwYBBQUHMAGGK2h0dHA6Ly9vY3NwLmdsb2JhbHNpZ24uY29tL2dzcnNhZHZz +c2xjYTIwMTgwVgYDVR0gBE8wTTBBBgkrBgEEAaAyAQowNDAyBggrBgEFBQcCARYm +aHR0cHM6Ly93d3cuZ2xvYmFsc2lnbi5jb20vcmVwb3NpdG9yeS8wCAYGZ4EMAQIB +MAkGA1UdEwQCMAAwPwYDVR0fBDgwNjA0oDKgMIYuaHR0cDovL2NybC5nbG9iYWxz +aWduLmNvbS9nc3JzYWR2c3NsY2EyMDE4LmNybDAlBgNVHREEHjAcgg0qLmFuYWx5 +c3lzLmNuggthbmFseXN5cy5jbjAdBgNVHSUEFjAUBggrBgEFBQcDAQYIKwYBBQUH +AwIwHwYDVR0jBBgwFoAUgYDWKHk1Slt5NYk5jxIXbhF7LBEwHQYDVR0OBBYEFM6I +hDBl8JW7+YGejfMCiszDwNZzMIIBAwYKKwYBBAHWeQIEAgSB9ASB8QDvAHUAb1N2 +rDHwMRnYmQCkURX/dxUcEdkCwQApBo2yCJo32RMAAAFtSEAjVAAABAMARjBEAiBG +87jarY7Uh0zafJtHkCWyQ2lgsVoTsSTRJKAKkyvC6QIgNLRjE1qgEkO1X4FU64YC +Fn2JChoiUUUoyXW/EjqJBVUAdgDuS723dc5guuFCaR+r4Z5mow9+X7By2IMAxHuJ +eqj9ywAAAW1IQCMPAAAEAwBHMEUCIQCdJwY/P77fAMePc7eniG1xkAa9+Y5kpESp +tIvbTDdiEwIgVh9wXdKkZIPq4dpHyzkX4MwRj2IA32vvLLcJfin+QrAwDQYJKoZI +hvcNAQELBQADggEBADCx45t0g92GHZupXgNYx3slBy1i1PwsK5h3fcXkZk6Qm4TG +DRl7/uNUOeQ6kD9HY2tGa2R/TlT2gVHGGvGtDZPb5Pgf5JJ2KLRpdUarY0J2b2J+ +bZZ6X/faA1emSRg1jUV5GjTg/MAnSLubgUTdGUvXrsRTps5W0zFMUpXMVJfUh0OW +TAzV3S/uK4YymHiZnN16GS9Jqje0ZOyjfgD/N06NY8essCtk0Etfnz+wUiVDTyiy +v7AAQX8MeIJ/kTg0BmLnqFicP2AF1zmBNmVOHJnXGNteLNg+9hRoP+nf8OA9bv+m +lEuZNGC4gl26f1wFK2A9GFnCiQruM+ewWXNMVLg= -----END CERTIFICATE----- -----BEGIN CERTIFICATE----- -MIIEYzCCA0ugAwIBAgILBAAAAAABRE7wPiAwDQYJKoZIhvcNAQELBQAwVzELMAkG -A1UEBhMCQkUxGTAXBgNVBAoTEEdsb2JhbFNpZ24gbnYtc2ExEDAOBgNVBAsTB1Jv -b3QgQ0ExGzAZBgNVBAMTEkdsb2JhbFNpZ24gUm9vdCBDQTAeFw0xNDAyMjAxMDAw -MDBaFw0yNDAyMjAxMDAwMDBaMGAxCzAJBgNVBAYTAkJFMRkwFwYDVQQKExBHbG9i -YWxTaWduIG52LXNhMTYwNAYDVQQDEy1HbG9iYWxTaWduIERvbWFpbiBWYWxpZGF0 -aW9uIENBIC0gU0hBMjU2IC0gRzIwggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEK -AoIBAQCp3cwOs+IyOd1JIqgTaZOHiOEM7nF9vZCHll1Z8syz0lhXV/lG72wm2DZC -jn4wsy+aPlN7H262okxFHzzTFZMcie089Ffeyr3sBppqKqAZUn9R0XQ5CJ+r69eG -ExWXrjbDVGYOWvKgc4Ux47JkFGr/paKOJLu9hVIVonnu8LXuPbj0fYC82ZA1ZbgX -qa2zmJ+gfn1u+z+tfMIbWTaW2jcyS0tdNQJjjtunz2LuzC7Ujcm9PGqRcqIip3It -INH6yjfaGJjmFiRxJUvE5XuJUgkC/VkrBG7KB4HUs9ra2+PMgKhWBwZ8lgg3nds4 -tmI0kWIHdAE42HIw4uuQcSZiwFfzAgMBAAGjggElMIIBITAOBgNVHQ8BAf8EBAMC -AQYwEgYDVR0TAQH/BAgwBgEB/wIBADAdBgNVHQ4EFgQU6k581IAt5RWBhiaMgm3A -mKTPlw8wRwYDVR0gBEAwPjA8BgRVHSAAMDQwMgYIKwYBBQUHAgEWJmh0dHBzOi8v -d3d3Lmdsb2JhbHNpZ24uY29tL3JlcG9zaXRvcnkvMDMGA1UdHwQsMCowKKAmoCSG -Imh0dHA6Ly9jcmwuZ2xvYmFsc2lnbi5uZXQvcm9vdC5jcmwwPQYIKwYBBQUHAQEE -MTAvMC0GCCsGAQUFBzABhiFodHRwOi8vb2NzcC5nbG9iYWxzaWduLmNvbS9yb290 -cjEwHwYDVR0jBBgwFoAUYHtmGkUNl8qJUC99BM00qP/8/UswDQYJKoZIhvcNAQEL -BQADggEBANdFnqDc4ONhWgt9d4QXLWVagpqNoycqhffJ7+mG/dRHzQFSlsVDvTex -4bjyqdKKEYRxkRWJ3AKdC8tsM4U0KJ4gsrGX3G0LEME8zV/qXdeYMcU0mVwAYVXE -GwJbxeOJyLS4bx448lYm6UHvPc2smU9ZSlctS32ux4j71pg79eXw6ImJuYsDy1oj -H6T9uOr7Lp2uanMJvPzVoLVEgqtEkS5QLlfBQ9iRBIvpES5ftD953x77PzAAi1Pj -tywdO02L3ORkHQRYM68bVeerDL8wBHTk8w4vMDmNSwSMHnVmZkngvkA0x1xaUZK6 -EjxS1QSCVS1npd+3lXzuP8MIugS+wEY= ------END CERTIFICATE----- +MIIEdzCCA1+gAwIBAgINAe5fIi3nG0Ol1GafnjANBgkqhkiG9w0BAQsFADBMMSAw +HgYDVQQLExdHbG9iYWxTaWduIFJvb3QgQ0EgLSBSMzETMBEGA1UEChMKR2xvYmFs +U2lnbjETMBEGA1UEAxMKR2xvYmFsU2lnbjAeFw0xODExMjEwMDAwMDBaFw0yODEx +MjEwMDAwMDBaMFAxCzAJBgNVBAYTAkJFMRkwFwYDVQQKExBHbG9iYWxTaWduIG52 +LXNhMSYwJAYDVQQDEx1HbG9iYWxTaWduIFJTQSBEViBTU0wgQ0EgMjAxODCCASIw +DQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBAKj7VfX/8JCr/+fvQb1oMFLn/TLt +yfUV98C5rzFwmFJSFpjR4S1pgGfFbFt6LPlzuauahb2EM2vZg6+A+Z36UpAzj8CU +CgpDqjraJ6N1y9Atajog3Xef/EdgVDVuM/SzuoWp80Z+bFYW6KYeUwDGtPKGKfNb +ekAw2Ki3KWKreCHFGMTcYfnMGJY2N+pLm89uysRnqwNF11g0vbrjaDj8XcShkILV +HThoxdWgqXMsnIq33XDgSdcL8DTJ7D4/dUuCEEhpGv+LzpscwpTst91L1bTkWQ4Y +ghXxG/PYx3rayZY7V5NVOL6w/yDbr5UsCL2q41Q5RaMc8feC0stNYcIGhiUCAwEA +AaOCAVIwggFOMA4GA1UdDwEB/wQEAwIBhjAnBgNVHSUEIDAeBggrBgEFBQcDAQYI +KwYBBQUHAwIGCCsGAQUFBwMJMBIGA1UdEwEB/wQIMAYBAf8CAQAwHQYDVR0OBBYE +FIGA1ih5NUpbeTWJOY8SF24ReywRMB8GA1UdIwQYMBaAFI/wS3+oLkUkrk1Q+mOa +i97i3Ru8MD4GCCsGAQUFBwEBBDIwMDAuBggrBgEFBQcwAYYiaHR0cDovL29jc3Ay +Lmdsb2JhbHNpZ24uY29tL3Jvb3RyMzA2BgNVHR8ELzAtMCugKaAnhiVodHRwOi8v +Y3JsLmdsb2JhbHNpZ24uY29tL3Jvb3QtcjMuY3JsMEcGA1UdIARAMD4wPAYEVR0g +ADA0MDIGCCsGAQUFBwIBFiZodHRwczovL3d3dy5nbG9iYWxzaWduLmNvbS9yZXBv +c2l0b3J5LzANBgkqhkiG9w0BAQsFAAOCAQEAQgWFTN2WCOZP6FOnizgthtQ3PDrk +8Q4ueUBYp9H91Gf0hHucnY72cHtshG1iJKqOsLuQ+ewVFtXVEaK1GeJ15Ct9REvY +skxXwPgRLf/+4/mslqkJhm4jCGWdpuSDf0On0rmSq+N7/daOyaTXqckhd6r+Yx9k +rs0eI5tgc3p+KcpXhmrwtl5HKoXCkFAtYPIutVuLORlEiTD4mjV4kSeQlaQL/ZQD +GA9uXqsDj4J/okR7/ruByeEuh8aKWgBSmF7oFasKXPKdTbIS9D9FBPKbYvu1quvI +/AQsGpQZsvjRJbFu1gU20lhLYYC2PGK8owK23TZjOWglOnuii6MUGwkiMw== +-----END CERTIFICATE----- \ No newline at end of file diff --git a/ans-demo/apidemo/src/main/java/com/analysys/demo/AnsApplication.java b/ans-demo/apidemo/src/main/java/com/analysys/demo/AnsApplication.java index ab2c2a2..2ab6f61 100644 --- a/ans-demo/apidemo/src/main/java/com/analysys/demo/AnsApplication.java +++ b/ans-demo/apidemo/src/main/java/com/analysys/demo/AnsApplication.java @@ -2,14 +2,26 @@ import android.app.Application; import android.content.Context; +import android.content.SharedPreferences; import android.os.StrictMode; import com.analysys.AnalysysAgent; import com.analysys.AnalysysConfig; import com.analysys.EncryptEnum; import com.analysys.apidemo.BuildConfig; +import com.analysys.utils.AnalysysSSManager; import com.analysys.utils.AnsReflectUtils; +import static com.analysys.demo.ModifyConfigActivity.PREF_FILE; +import static com.analysys.demo.ModifyConfigActivity.PREF_KEY_APP_KEY; +import static com.analysys.demo.ModifyConfigActivity.PREF_KEY_CHANNEL_ID; +import static com.analysys.demo.ModifyConfigActivity.PREF_KEY_UPLOAD_URL; +import static com.analysys.demo.ModifyConfigActivity.PREF_KEY_VISUAL_CONFIG_URL; +import static com.analysys.demo.ModifyConfigActivity.PREF_KEY_VISUAL_DEBUG_URL; + +import java.util.HashMap; +import java.util.Map; + /** * @Copyright © 2019 EGuan Inc. All rights reserved. * @Description: TODO @@ -27,10 +39,15 @@ public class AnsApplication extends Application { // public static final String UPLOAD_URL = "https://172.81.254.172:4089"; // private static final String SOCKET_URL = "wss://172.81.254.172:4091"; // private static final String CONFIG_URL = "https://172.81.254.172:4089"; - public static final String APP_KEY = "2709692586aa3e42"; - public static final String UPLOAD_URL = "https://arkpaastest.analysys.cn:4089"; - private static final String SOCKET_URL = "wss://arkpaastest.analysys.cn:4091"; - private static final String CONFIG_URL = "https://arkpaastest.analysys.cn:4089"; +// public static final String APP_KEY = "2709692586aa3e42"; +// public static final String UPLOAD_URL = "https://arkpaastest.analysys.cn:4089"; +// private static final String SOCKET_URL = "wss://arkpaastest.analysys.cn:4091"; +// private static final String CONFIG_URL = "https://arkpaastest.analysys.cn:4089"; + + public static final String APP_KEY = "3dc2312475ba8f98"; + public static final String UPLOAD_URL = "https://uba-up.analysysdata.com"; + private static final String SOCKET_URL = "wss://uba.analysysdata.com:4091"; + private static final String CONFIG_URL = "https://uba-up.analysysdata.com"; private static AnsApplication instance; private boolean isDebug = true; @@ -44,34 +61,47 @@ public void onCreate() { super.onCreate(); instance = this; + AnalysysAgent.track(this,"test_before"); // 设置严苛模式 - strictMode(); + //strictMode(); // 初始化方舟SDK - initAnalsysy(); + initAnalysys(); + //AnalysysAgent.alias(); // 尝试初始化对应模块 - if ("compatibility".equals(BuildConfig.Build_Type)) { - AnsReflectUtils.invokeStaticMethod("com.analysys.compatibilitydemo.CompatibilityDemoInit", "init", Context.class, this); - } +// if ("compatibility".equals(BuildConfig.Build_Type)) { +// AnsReflectUtils.invokeStaticMethod("com.analysys.compatibilitydemo.CompatibilityDemoInit", "init", Context.class, this); +// } + + TrackEventObserver.getInstance().init(); + AnalysysAgent.registerSuperProperty(this,"testSuper","111111111"); + AnalysysAgent.setCacheDataLength(getApplicationContext(),20); + AnalysysAgent.setUseGravity(getApplicationContext(),true); + AnalysysAgent.setListenDuration(getApplicationContext(),10); + AnalysysAgent.startListen(getApplicationContext()); } @Override protected void attachBaseContext(Context base) { super.attachBaseContext(base); + } /** * 初始化方舟SDK相关API */ - private void initAnalsysy() { + private void initAnalysys() { + SharedPreferences sp = getSharedPreferences(PREF_FILE, Context.MODE_PRIVATE); + AnalysysAgent.setDebugMode(this, DEBUG_MODE); // 设置 debug 模式,值:0、1、2 AnalysysConfig config = new AnalysysConfig(); - // 设置key(目前使用电商demo的key) - config.setAppKey(APP_KEY); + // 设置key + config.setAppKey(sp.getString(PREF_KEY_APP_KEY, APP_KEY)); + //config.setAppKey("3dc2312475ba8f98"); // 设置渠道 - config.setChannel("AnalsysyDemo"); + config.setChannel(sp.getString(PREF_KEY_CHANNEL_ID, "AnalysysDemo")); // 设置追踪新用户的首次属性 config.setAutoProfile(true); // 设置使用AES加密 @@ -86,23 +116,39 @@ private void initAnalsysy() { config.setAutoHeatMap(true); // pageView自动上报总开关(默认开启) config.setAutoTrackPageView(true); + // pageClose自动上报开关(默认关闭) + config.setAutoPageViewDuration(true); // fragment-pageView自动上报开关(默认关闭) - config.setAutoTrackFragmentPageView(false); + config.setAutoTrackFragmentPageView(true); // 点击自动上报开关(默认关闭) config.setAutoTrackClick(false); config.setAutoTrackCrash(true); config.setAutoTrackDeviceId(true); + config.setNeedDeduplication(true); + // 初始化 AnalysysAgent.init(this, config); - AnalysysAgent.setUploadNetworkType(AnalysysAgent.AnalysysNetworkType.AnalysysNetworkWIFI); // 设置数据上传/更新地址 - AnalysysAgent.setUploadURL(this, UPLOAD_URL); - // 设置 WebSocket 连接 Url - AnalysysAgent.setVisitorDebugURL(this, SOCKET_URL); - // 设置配置下发 Url - AnalysysAgent.setVisitorConfigURL(this, CONFIG_URL); + //AnalysysAgent.setUploadURL(this,"https://uba-up.analysysdata.com"); + + //AnalysysAgent.setUploadURL(this,"https://uba-up.analysysdata.com"); + + AnalysysAgent.setUploadURL(this, sp.getString(PREF_KEY_UPLOAD_URL, UPLOAD_URL)); +// // 设置 WebSocket 连接 Url + AnalysysAgent.setVisitorDebugURL(this, sp.getString(PREF_KEY_VISUAL_DEBUG_URL, SOCKET_URL)); +// // 设置配置下发 Url + AnalysysAgent.setVisitorConfigURL(this, sp.getString(PREF_KEY_VISUAL_CONFIG_URL, CONFIG_URL)); + +// AnalysysAgent.getSSManager(this); +// Map propMap = new HashMap<>(); +// propMap.put("test00001","啦啦啦啦啦哦哦哦0001"); +// propMap.put("test00002","啦啦啦啦啦哦哦哦0002"); +// AnalysysAgent.registerPreEventUserProperties(this,propMap); +// AnalysysAgent.unRegisterPreEventUserProperties(this,"test00001");a + + } /** diff --git a/ans-demo/apidemo/src/main/java/com/analysys/demo/BaseActivity.java b/ans-demo/apidemo/src/main/java/com/analysys/demo/BaseActivity.java new file mode 100644 index 0000000..210c15e --- /dev/null +++ b/ans-demo/apidemo/src/main/java/com/analysys/demo/BaseActivity.java @@ -0,0 +1,103 @@ +package com.analysys.demo; + + +import android.content.Intent; +import android.os.Bundle; +import android.text.TextUtils; +import android.view.Menu; +import android.view.MenuItem; +import android.view.View; +import android.view.animation.AlphaAnimation; + + +import androidx.appcompat.app.AppCompatActivity; + +import com.analysys.apidemo.R; +import com.analysys.process.AgentProcess; + +import org.json.JSONObject; + +/** + * @Copyright © 2020 Analysys Inc. All rights reserved. + * @Description: + * @Create: 2020/7/22 11:06 AM + * @author: huchangqing + */ +public class BaseActivity extends AppCompatActivity implements AgentProcess.IEventObserver { + + + public static final String EXTRA_ACTIVITY_TITLE = "title"; + public static final String EXTRA_EVENT_NAME = "event_name"; + + private String mEventName; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + Intent intent = getIntent(); + String title = null; + if (intent != null) { + title = intent.getStringExtra(EXTRA_ACTIVITY_TITLE); + mEventName = intent.getStringExtra(EXTRA_EVENT_NAME); + } +// ActionBar actionBar = getSupportActionBar(); +// if (actionBar != null) { +// if (TextUtils.isEmpty(title)) { +// actionBar.setDisplayShowTitleEnabled(false); +// } else { +// actionBar.setTitle(title); +// } +// } + } + + @Override + protected void onResume() { + super.onResume(); + TrackEventObserver.getInstance().setObserver(mEventName, this); + } + + @Override + protected void onPause() { + super.onPause(); + TrackEventObserver.getInstance().setObserver(null, null); + } + + @Override + public boolean onCreateOptionsMenu(Menu menu) { + getMenuInflater().inflate(R.menu.base_menu, menu); + return super.onCreateOptionsMenu(menu); + } + + @Override + public boolean onOptionsItemSelected(MenuItem item) { + if (item.getItemId() == R.id.action_info) { + showMsgDialog(); + } + return super.onOptionsItemSelected(item); + } + + private void showMsgDialog() { + InfoDialog dialog = new InfoDialog(mEventName); + dialog.show(getSupportFragmentManager(), "info"); + } + + @Override + public void onEvent(String eventName, JSONObject sendData) { + runOnUiThread(new Runnable() { + @Override + public void run() { + hint(findViewById(R.id.action_info)); + } + }); + } + + public void hint(View view) { + if (view == null) { + return; + } + AlphaAnimation alphaAnimation = new AlphaAnimation(0, 1); + alphaAnimation.setDuration(300); + alphaAnimation.setRepeatCount(3); + view.startAnimation(alphaAnimation); + } +} diff --git a/ans-demo/apidemo/src/main/java/com/analysys/demo/EventActivity.java b/ans-demo/apidemo/src/main/java/com/analysys/demo/EventActivity.java deleted file mode 100644 index f388a2f..0000000 --- a/ans-demo/apidemo/src/main/java/com/analysys/demo/EventActivity.java +++ /dev/null @@ -1,60 +0,0 @@ -package com.analysys.demo; - -import android.content.Context; -import android.os.Bundle; -import android.view.View; - -import androidx.appcompat.app.AppCompatActivity; - -import com.analysys.ANSAutoPageTracker; -import com.analysys.AnalysysAgent; -import com.analysys.apidemo.R; - -import java.util.HashMap; -import java.util.Map; - -/** - * @Copyright © 2019 EGuan Inc. All rights reserved. - * @Description: TODO - * @Version: 1.0 - * @Create: 2019-07-01 00:48 - * @Author: Wang-X-C - */ -public class EventActivity extends AppCompatActivity implements ANSAutoPageTracker { - Context mContext = null; - - @Override - protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - setContentView(R.layout.activity_event); - mContext = this.getApplicationContext(); - } - - public void onClick(View view) { - int id = view.getId(); - if (id == R.id.singleTrack) {//统计用户确认订单的事件 - AnalysysAgent.track(mContext, "confirmOrder"); - } else if (id == R.id.multipleTrack) {//用户购买某一商品需支付2000元, - Map track = new HashMap<>(); - track.put("money", 2000); - AnalysysAgent.track(mContext.getApplicationContext(), "payment", track); - } else if (id == R.id.singlePage) {//服务正在开展某个活动,需要统计活动页面时 - AnalysysAgent.pageView(mContext, "活动页"); - } else if (id == R.id.multiplePage) {//购买一部iPhone手机,手机价格为8000元 - Map page = new HashMap<>(); - page.put("commodityName", "iPhone"); - page.put("commodityPrice", 8000); - AnalysysAgent.pageView(mContext, "商品页", page); - } - } - - @Override - public Map registerPageProperties() { - return null; - } - - @Override - public String registerPageUrl() { - return null; - } -} \ No newline at end of file diff --git a/ans-demo/apidemo/src/main/java/com/analysys/demo/FragmentEvent.java b/ans-demo/apidemo/src/main/java/com/analysys/demo/FragmentEvent.java new file mode 100644 index 0000000..d6fb504 --- /dev/null +++ b/ans-demo/apidemo/src/main/java/com/analysys/demo/FragmentEvent.java @@ -0,0 +1,121 @@ +package com.analysys.demo; + +import android.content.Context; +import android.os.Bundle; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.AdapterView; +import android.widget.BaseAdapter; +import android.widget.ListView; +import android.widget.TextView; + +import androidx.fragment.app.Fragment; + +import com.analysys.apidemo.R; + +import java.util.List; + +/** + * @Copyright © 2020 Analysys Inc. All rights reserved. + * @Description: + * @Create: 2020/7/21 5:22 PM + * @author: huchangqing + */ +public class FragmentEvent extends Fragment { + + private String mEventName; + + public FragmentEvent(String eventName) { + mEventName = eventName; + } + + @Override + public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { + return inflater.inflate(R.layout.fragment_event, null); + } + + @Override + public void onViewCreated(View view, Bundle savedInstanceState) { + super.onViewCreated(view, savedInstanceState); + ListView listView = view.findViewById(R.id.list_view); + List list = TrackEventObserver.getInstance().getData(mEventName); + MyAdapter adapter = new MyAdapter(getContext(), list); + listView.setAdapter(adapter); + listView.setOnItemClickListener(new AdapterView.OnItemClickListener() { + @Override + public void onItemClick(AdapterView parent, View view, int position, long id) { + adapter.setSelectedPosition(position); + } + }); + } + + public final class ViewHolder { + public TextView name; + public TextView time; + public TextView detail; + } + + public class MyAdapter extends BaseAdapter { + + private LayoutInflater mInflater; + private List mListData; + private int mSelectedPosition; + + public MyAdapter(Context context, List list) { + this.mInflater = LayoutInflater.from(context); + mListData = list; + } + + @Override + public int getCount() { + return mListData.size(); + } + + @Override + public Object getItem(int arg0) { + return null; + } + + @Override + public long getItemId(int arg0) { + return 0; + } + + @Override + public View getView(int position, View convertView, ViewGroup parent) { + ViewHolder holder; + if (convertView == null) { + holder = new ViewHolder(); + convertView = mInflater.inflate(R.layout.list_row_event, null); + holder.name = convertView.findViewById(R.id.tv_name); + holder.time = convertView.findViewById(R.id.tv_time); + holder.detail = convertView.findViewById(R.id.tv_detail); + convertView.setTag(holder); + } else { + holder = (ViewHolder) convertView.getTag(); + } + TrackEventObserver.EventData data = mListData.get(position); + holder.name.setText(data.eventName); + holder.time.setText(data.time); + if (position == mSelectedPosition) { + holder.detail.setText(data.getDetail()); + holder.detail.setVisibility(View.VISIBLE); + } else { + holder.detail.setText(""); + holder.detail.setVisibility(View.GONE); + } + + return convertView; + } + + public void setSelectedPosition(int position) { + if (mSelectedPosition == position) { + mSelectedPosition = -1; + } else { + mSelectedPosition = position; + } + notifyDataSetChanged(); + } + } +} diff --git a/ans-demo/apidemo/src/main/java/com/analysys/demo/FragmentFull.java b/ans-demo/apidemo/src/main/java/com/analysys/demo/FragmentFull.java new file mode 100644 index 0000000..87ba4ae --- /dev/null +++ b/ans-demo/apidemo/src/main/java/com/analysys/demo/FragmentFull.java @@ -0,0 +1,86 @@ +package com.analysys.demo; + +import android.app.Activity; +import android.content.Intent; +import android.os.Bundle; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.AdapterView; +import android.widget.ArrayAdapter; +import android.widget.ListView; + +import androidx.fragment.app.Fragment; + +import com.analysys.apidemo.R; +import com.analysys.utils.Constants; + +import java.util.ArrayList; +import java.util.List; + +/** + * @Copyright © 2020 Analysys Inc. All rights reserved. + * @Description: + * @Create: 2020/7/21 5:22 PM + * @author: huchangqing + */ +public class FragmentFull extends Fragment { + + class ClickAction { + Class activityClz; + String itemName; + String eventName; + + ClickAction(Class clz, String name, String eName) { + activityClz = clz; + itemName = name; + eventName = eName; + } + + void doAction() { + Activity activity = getActivity(); + if (activity == null) { + return; + } + Intent intent = new Intent(activity, activityClz); + intent.putExtra(BaseActivity.EXTRA_ACTIVITY_TITLE, itemName); + intent.putExtra(BaseActivity.EXTRA_EVENT_NAME, eventName); + activity.startActivity(intent); + } + } + + @Override + public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { + return inflater.inflate(R.layout.fragment_full, null); + } + + @Override + public void onViewCreated(View view, Bundle savedInstanceState) { + super.onViewCreated(view, savedInstanceState); + ListView listView = view.findViewById(R.id.list_view); + List list = new ArrayList<>(); + list.add(new ClickAction(PropertyActivity.class, "通用属性", null)); + list.add(new ClickAction(PageViewActivity.class, "页面采集", Constants.PAGE_VIEW)); + list.add(new ClickAction(ProbeActivity.class, "全埋点", Constants.USER_CLICK)); + list.add(new ClickAction(HeatMapActivity.class, "热图", Constants.APP_CLICK)); + list.add(new ClickAction(VisualActivity.class, "可视化", null)); + list.add(new ClickAction(TrackActivity.class, "统计事件", null)); + list.add(new ClickAction(UserInfoActivity.class, "用户ID 用户属性", null)); + list.add(new ClickAction(HybridActivity.class, "Hybrid", null)); + list.add(new ClickAction(OtherActivity.class, "其它", null)); + List listStr = new ArrayList<>(); + for (int i = 0; i < list.size(); i++) { + listStr.add(list.get(i).itemName); + } + listView.setAdapter(new ArrayAdapter<>(getActivity(), + android.R.layout.simple_list_item_1, + android.R.id.text1, + listStr)); + listView.setOnItemClickListener(new AdapterView.OnItemClickListener() { + @Override + public void onItemClick(AdapterView parent, View view, int position, long id) { + list.get(position).doAction(); + } + }); + } +} diff --git a/ans-demo/apidemo/src/main/java/com/analysys/demo/FragmentMini.java b/ans-demo/apidemo/src/main/java/com/analysys/demo/FragmentMini.java new file mode 100644 index 0000000..07b530e --- /dev/null +++ b/ans-demo/apidemo/src/main/java/com/analysys/demo/FragmentMini.java @@ -0,0 +1,89 @@ +package com.analysys.demo; + +import android.os.Bundle; +import android.text.TextUtils; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.Button; +import android.widget.EditText; +import android.widget.Toast; + +import androidx.fragment.app.Fragment; + +import com.analysys.ANSAutoPageTracker; +import com.analysys.AnalysysAgent; +import com.analysys.apidemo.R; + +import java.util.HashMap; +import java.util.Map; + +/** + * @Copyright © 2020 Analysys Inc. All rights reserved. + * @Description: + * @Create: 2020/7/21 5:22 PM + * @author: huchangqing + */ +public class FragmentMini extends Fragment implements View.OnClickListener { + + @Override + public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { + return inflater.inflate(R.layout.fragment_mini, null); + } + + @Override + public void onViewCreated(View view, Bundle savedInstanceState) { + super.onViewCreated(view, savedInstanceState); + Button btnNormal = view.findViewById(R.id.btn_track_normal); + btnNormal.setOnClickListener(this); + Button btnTrackName = view.findViewById(R.id.btn_track_name); + btnTrackName.setOnClickListener(this); + Button btnTrackProperty = view.findViewById(R.id.btn_track_property); + btnTrackProperty.setOnClickListener(this); + + edtName = view.findViewById(R.id.edt_event_name); + edtKey = view.findViewById(R.id.edt_key); + edtValue = view.findViewById(R.id.edt_value); + } + + private EditText edtName; + private EditText edtKey; + private EditText edtValue; + + @Override + public void onClick(View view) { + String eventName = null; + if (view.getId() == R.id.btn_track_normal) { + eventName = "track_test"; + AnalysysAgent.track(getContext(), eventName); + } else if (view.getId() == R.id.btn_track_name) { + eventName = edtName.getText().toString(); + if (TextUtils.isEmpty(eventName)) { + Toast.makeText(getContext(), "名称不能为空", Toast.LENGTH_SHORT).show(); + return; + } + AnalysysAgent.track(getContext(), eventName); + } else if (view.getId() == R.id.btn_track_property) { + String key = edtKey.getText().toString(); + if (TextUtils.isEmpty(key)) { + Toast.makeText(getContext(), "Key不能为空", Toast.LENGTH_SHORT).show(); + return; + } + String value = edtValue.getText().toString(); + if (TextUtils.isEmpty(value)) { + Toast.makeText(getContext(), "Value不能为空", Toast.LENGTH_SHORT).show(); + return; + } + Map data = new HashMap<>(); + data.put(key, value); + eventName = "track_property"; + AnalysysAgent.track(getContext(), eventName, data); + Toast.makeText(getContext(), "触发事件: " + eventName + "[" + key + "=" + value + "]", Toast.LENGTH_LONG).show(); + } + + Toast.makeText(getContext(), "触发事件: " + eventName, Toast.LENGTH_LONG).show(); + } + + + +} diff --git a/ans-demo/apidemo/src/main/java/com/analysys/demo/FragmentProbeOne.java b/ans-demo/apidemo/src/main/java/com/analysys/demo/FragmentProbeOne.java new file mode 100644 index 0000000..6dada7b --- /dev/null +++ b/ans-demo/apidemo/src/main/java/com/analysys/demo/FragmentProbeOne.java @@ -0,0 +1,48 @@ +package com.analysys.demo; + +import android.os.Bundle; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.CheckBox; +import android.widget.CompoundButton; +import android.widget.TextView; + +import androidx.fragment.app.Fragment; + +import com.analysys.AnalysysAgent; +import com.analysys.apidemo.R; +import com.analysys.process.AgentProcess; + +import java.util.ArrayList; +import java.util.List; + +public class FragmentProbeOne extends Fragment { + + @Override + public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { + return inflater.inflate(R.layout.fragment_probe_one, null); + } + + @Override + public void onViewCreated(View view, Bundle savedInstanceState) { + String pageName = this.getClass().getName(); + TextView tv = view.findViewById(R.id.tv_page_name); + tv.setText("页面名字:" + pageName); + CheckBox checkBox = view.findViewById(R.id.cb_ignore_page); + checkBox.setChecked(AgentProcess.getInstance().isThisPageInPageViewBlackList(pageName)); + checkBox.setText(checkBox.getText() + pageName); + checkBox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { + @Override + public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { + if (isChecked) { + List list = new ArrayList<>(); + list.add(pageName); + AnalysysAgent.setPageViewBlackListByPages(list); + } else { + AnalysysAgent.setPageViewBlackListByPages(null); + } + } + }); + } +} diff --git a/ans-demo/apidemo/src/main/java/com/analysys/demo/FragmentProbeTwo.java b/ans-demo/apidemo/src/main/java/com/analysys/demo/FragmentProbeTwo.java new file mode 100644 index 0000000..561eca2 --- /dev/null +++ b/ans-demo/apidemo/src/main/java/com/analysys/demo/FragmentProbeTwo.java @@ -0,0 +1,28 @@ +package com.analysys.demo; + +import android.os.Bundle; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.TextView; + +import androidx.fragment.app.Fragment; + +import com.analysys.allgro.annotations.AnalysysIgnorePage; +import com.analysys.apidemo.R; + +@AnalysysIgnorePage +public class FragmentProbeTwo extends Fragment { + + @Override + public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { + return inflater.inflate(R.layout.fragment_probe_two, null); + } + + @Override + public void onViewCreated(View view, Bundle savedInstanceState) { + String pageName = this.getClass().getName(); + TextView tv = view.findViewById(R.id.tv_page_name); + tv.setText("页面名字:" + pageName); + } +} diff --git a/ans-demo/apidemo/src/main/java/com/analysys/demo/HeatMapActivity.java b/ans-demo/apidemo/src/main/java/com/analysys/demo/HeatMapActivity.java new file mode 100644 index 0000000..3fb0edc --- /dev/null +++ b/ans-demo/apidemo/src/main/java/com/analysys/demo/HeatMapActivity.java @@ -0,0 +1,67 @@ +package com.analysys.demo; + +import android.content.Intent; +import android.os.Bundle; +import android.view.View; +import android.widget.Button; +import android.widget.CheckBox; +import android.widget.CompoundButton; +import android.widget.Switch; + +import com.analysys.AnalysysAgent; +import com.analysys.apidemo.R; +import com.analysys.process.AgentProcess; +import com.analysys.utils.Constants; + +import java.util.ArrayList; +import java.util.List; + +public class HeatMapActivity extends BaseActivity { + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_heatmap); + Switch autoTrack = findViewById(R.id.auto_track); + autoTrack.setChecked(AgentProcess.getInstance().getConfig().isAutoHeatMap()); + autoTrack.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { + @Override + public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { + AgentProcess.getInstance().getConfig().setAutoHeatMap(isChecked); + } + }); + + String testPageName = HeatMapTestActivity.class.getName(); + + Button btnOpenPage = findViewById(R.id.btn_open_page); + btnOpenPage.setText(btnOpenPage.getText() + testPageName); + + CheckBox cbIgnorePage = findViewById(R.id.cb_ignore_page); + cbIgnorePage.setText(cbIgnorePage.getText() + testPageName); + cbIgnorePage.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { + @Override + public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { + if (isChecked) { + List list = new ArrayList<>(); + list.add(testPageName); + AnalysysAgent.setHeatMapBlackListByPages(list); + } else { + AnalysysAgent.setHeatMapBlackListByPages(null); + } + } + }); + } + + public void onClick(View view) { + int id = view.getId(); + if (id == R.id.btn_open_page) { + Intent intent = new Intent(this, HeatMapTestActivity.class); + intent.putExtra(BaseActivity.EXTRA_ACTIVITY_TITLE, "热图页面测试"); + intent.putExtra(BaseActivity.EXTRA_EVENT_NAME, Constants.APP_CLICK); + startActivity(intent); + } + if (id == R.id.btn_open_fragment_page) { + + } + } +} \ No newline at end of file diff --git a/ans-demo/apidemo/src/main/java/com/analysys/demo/HeatMapTestActivity.java b/ans-demo/apidemo/src/main/java/com/analysys/demo/HeatMapTestActivity.java index aa01179..6332e6e 100644 --- a/ans-demo/apidemo/src/main/java/com/analysys/demo/HeatMapTestActivity.java +++ b/ans-demo/apidemo/src/main/java/com/analysys/demo/HeatMapTestActivity.java @@ -1,47 +1,17 @@ package com.analysys.demo; -import android.content.Intent; import android.os.Bundle; -import android.view.View; +import android.widget.TextView; -import com.analysys.AnalysysAgent; import com.analysys.apidemo.R; -import java.util.ArrayList; -import java.util.List; - -import androidx.appcompat.app.AppCompatActivity; - -/** - * Description: 热图黑白名单测试 - * Author: fengzeyuan - * Date: 2019-11-20 16:34 - * Version: 1.0 - */ -public class HeatMapTestActivity extends AppCompatActivity { - - private List mPages; +public class HeatMapTestActivity extends BaseActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_heatmap_test); - mPages = new ArrayList<>(); - mPages.add(MainActivity.class.getName()); - mPages.add(UserSettingActivity.class.getName()); - } - - public void onClick(View view) { - int id = view.getId(); - if (id == R.id.ignoreButton) { - // 设置热图黑名单 - AnalysysAgent.setHeatMapBlackListByPages(mPages); - } else if (id == R.id.clearButton) { - List pages = new ArrayList<>(); - AnalysysAgent.setHeatMapBlackListByPages(pages); - AnalysysAgent.setHeatMapWhiteListByPages(pages); - } else if (id == R.id.SingleProcessButton) { - startActivity(new Intent(HeatMapTestActivity.this, SingleProcessTestActivity.class)); - } + TextView tv = findViewById(R.id.tv_page_name); + tv.setText("页面名字:" + getClass().getName()); } } diff --git a/ans-demo/apidemo/src/main/java/com/analysys/demo/WebViewActivity.java b/ans-demo/apidemo/src/main/java/com/analysys/demo/HybridActivity.java similarity index 52% rename from ans-demo/apidemo/src/main/java/com/analysys/demo/WebViewActivity.java rename to ans-demo/apidemo/src/main/java/com/analysys/demo/HybridActivity.java index e0ce42b..c907725 100644 --- a/ans-demo/apidemo/src/main/java/com/analysys/demo/WebViewActivity.java +++ b/ans-demo/apidemo/src/main/java/com/analysys/demo/HybridActivity.java @@ -1,40 +1,44 @@ package com.analysys.demo; import android.annotation.SuppressLint; +import android.app.ProgressDialog; import android.content.Context; import android.os.Bundle; import android.util.Log; import android.view.ViewGroup; import android.view.ViewParent; +import android.webkit.WebChromeClient; +import android.webkit.WebSettings; import android.webkit.WebView; import android.webkit.WebViewClient; -import android.widget.LinearLayout; -import androidx.appcompat.app.AppCompatActivity; - -import com.analysys.ANSAutoPageTracker; import com.analysys.AnalysysAgent; import com.analysys.apidemo.R; -import java.util.Map; - -/** - * @Copyright © 2019 EGuan Inc. All rights reserved. - * @Description: TODO - * @Version: 1.0 - * @Create: 2019-07-01 00:48 - * @Author: Wang-X-C - */ -public class WebViewActivity extends AppCompatActivity implements ANSAutoPageTracker { +public class HybridActivity extends BaseActivity { private WebView mWebView; private Context mContext = null; + private ProgressDialog dialog; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); - setContentView(R.layout.activity_web_view); - initWebView(); + setContentView(getContentLayoutId()); mContext = this.getApplicationContext(); + initWebView(); + + dialog = new ProgressDialog(this); + dialog.setTitle("提示"); + dialog.setMessage("WebView加载中..."); + dialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL); + dialog.setCancelable(true); + dialog.setIndeterminate(true); + dialog.setMax(100); + dialog.show(); + } + + protected int getContentLayoutId() { + return R.layout.activity_hybrid; } @Override @@ -47,57 +51,50 @@ protected void onDestroy() { ((ViewGroup) parent).removeView(mWebView); } mWebView.stopLoading(); + + mWebView.clearCache(true); + // 退出时调用此方法,移除绑定的服务,否则某些特定系统会报错 mWebView.getSettings().setJavaScriptEnabled(false); mWebView.clearHistory(); mWebView.clearView(); mWebView.removeAllViews(); mWebView.destroy(); - +// AnalysysAgent.resetHybridModel(mContext, mWebView); + AnalysysAgent.resetAnalysysAgentHybrid(mWebView); + mWebView = null; } super.onDestroy(); - AnalysysAgent.resetHybridModel(mContext, mWebView); } @SuppressLint("SetJavaScriptEnabled") private void initWebView() { - mWebView = new WebView(getApplicationContext()); - LinearLayout linearLayout = findViewById(R.id.webViewLayout); - linearLayout.addView(mWebView); - mWebView.loadUrl("http://uc.analysys.cn/huaxiang/hybrid-4.3.0.10/"); + mWebView = findViewById(R.id.web_view); + mWebView.getSettings().setCacheMode(WebSettings.LOAD_NO_CACHE); + mWebView.clearCache(true); + mWebView.clearHistory(); mWebView.getSettings().setJavaScriptEnabled(true); mWebView.getSettings().setJavaScriptCanOpenWindowsAutomatically(true); -// mWebView.setWebViewClient(new OldWebviewClient()); - // 设置UserAgent - AnalysysAgent.setHybridModel(mContext, mWebView); - // 设置WebViewClient - mWebView.setWebViewClient(new MyWebviewClient()); - } - - @Override - public Map registerPageProperties() { - return null; - } - - @Override - public String registerPageUrl() { - return "WebView 页"; - } - - class OldWebviewClient extends WebViewClient { - @Override - public void onPageFinished(WebView view, String url) { - } - - @Override - public boolean shouldOverrideUrlLoading(WebView view, String url) { - Log.d("analysys.hybrid", "old: shouldOverrideUrlLoading url:" + url); -// AnalysysAgent.interceptUrl(mContext, url, view); - return false; - } + //mWebView.loadUrl("http://192.168.31.48:5173"); + mWebView.loadUrl("http://192.168.50.3:8080"); + //mWebView.loadUrl("http://10.9.24.114:9292?v=" + System.currentTimeMillis()); +// mWebView.setWebViewClient(new MyWebviewClient()); + mWebView.setWebChromeClient(new WebChromeClient() { + @Override + public void onProgressChanged(WebView view, int newProgress) { + super.onProgressChanged(view, newProgress); + dialog.setProgress(newProgress); + if (newProgress == 100) { + dialog.dismiss(); + } + } + }); +// AnalysysAgent.setHybridModel(mContext, mWebView); + AnalysysAgent.setAnalysysAgentHybrid(mWebView); } class MyWebviewClient extends WebViewClient { + @Override public void onPageFinished(WebView view, String url) { Log.d("analysys.hybrid", "onPageFinished url:" + url); @@ -105,8 +102,7 @@ public void onPageFinished(WebView view, String url) { @Override public boolean shouldOverrideUrlLoading(WebView view, String url) { - Log.d("analysys.hybrid", "new: shouldOverrideUrlLoading url:" + url); - // 设置URL拦截 + Log.d("analysys.hybrid", "shouldOverrideUrlLoading url:" + url); AnalysysAgent.interceptUrl(mContext, url, view); return false; } diff --git a/ans-demo/apidemo/src/main/java/com/analysys/demo/InfoDialog.java b/ans-demo/apidemo/src/main/java/com/analysys/demo/InfoDialog.java new file mode 100644 index 0000000..5984530 --- /dev/null +++ b/ans-demo/apidemo/src/main/java/com/analysys/demo/InfoDialog.java @@ -0,0 +1,101 @@ +package com.analysys.demo; + +import android.os.Bundle; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.TextView; + +import androidx.fragment.app.DialogFragment; +import androidx.fragment.app.Fragment; +import androidx.fragment.app.FragmentPagerAdapter; +import androidx.viewpager.widget.ViewPager; + +import com.analysys.apidemo.R; + +public class InfoDialog extends DialogFragment implements ViewPager.OnPageChangeListener, View.OnClickListener { + + private FragmentPagerAdapter adapter; + + private ViewPager mViewPager; + private TextView mTVEvent; + // private TextView mTVUser; +// private TextView mTVProperty; + private String mEventName; + + public InfoDialog(String eventName) { + mEventName = eventName; + } + + @Override + public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { + adapter = new FragmentPagerAdapter(getChildFragmentManager()) { + @Override + public Fragment getItem(int position) { + switch (position) { + case 0: + return new FragmentEvent(mEventName); +// case 1: +// return new FragmentUser(); +// case 2: +// return new FragmentProperty(); + default: + return null; + } + } + + @Override + public int getCount() { + return 1; + } + }; + + return inflater.inflate(R.layout.dialog_info, null); + } + + @Override + public void onViewCreated(View view, Bundle savedInstanceState) { + mTVEvent = view.findViewById(R.id.tv_event); + mTVEvent.setOnClickListener(this); +// mTVUser = view.findViewById(R.id.tv_user); +// mTVUser.setOnClickListener(this); +// mTVProperty = view.findViewById(R.id.tv_property); +// mTVProperty.setOnClickListener(this); + mViewPager = view.findViewById(R.id.view_pager); + mViewPager.setAdapter(adapter); + mViewPager.addOnPageChangeListener(this); + mTVEvent.setSelected(true); +// mTVUser.setSelected(false); +// mTVProperty.setSelected(false); + } + + @Override + public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) { + + } + + @Override + public void onPageSelected(int position) { + mTVEvent.setSelected(position == 0); +// mTVUser.setSelected(position == 1); +// mTVProperty.setSelected(position == 2); + } + + @Override + public void onPageScrollStateChanged(int state) { + + } + + @Override + public void onClick(View view) { + int id = view.getId(); + if (id == R.id.tv_event) { + mViewPager.setCurrentItem(0, true); + } +// else if (id == R.id.tv_user) { +// mViewPager.setCurrentItem(1, true); +// } else if (id == R.id.tv_property) { +// mViewPager.setCurrentItem(2, true); +// } + } +} \ No newline at end of file diff --git a/ans-demo/apidemo/src/main/java/com/analysys/demo/MainActivity.java b/ans-demo/apidemo/src/main/java/com/analysys/demo/MainActivity.java index e9af679..a53d21d 100644 --- a/ans-demo/apidemo/src/main/java/com/analysys/demo/MainActivity.java +++ b/ans-demo/apidemo/src/main/java/com/analysys/demo/MainActivity.java @@ -1,81 +1,127 @@ package com.analysys.demo; + + import android.content.Intent; import android.os.Bundle; +import android.text.SpannableString; +import android.text.style.ForegroundColorSpan; +import android.view.Menu; +import android.view.MenuItem; import android.view.View; +import android.widget.TextView; + +import androidx.appcompat.app.ActionBar; +import androidx.fragment.app.Fragment; +import androidx.fragment.app.FragmentPagerAdapter; +import androidx.viewpager.widget.ViewPager; -import androidx.appcompat.app.AppCompatActivity; import com.analysys.ANSAutoPageTracker; import com.analysys.AnalysysAgent; import com.analysys.apidemo.R; -import com.analysys.demo.allgroTest.AllgroTestActivity; import java.util.HashMap; import java.util.Map; /** - * @Copyright © 2019 EGuan Inc. All rights reserved. - * @Description: TODO - * @Version: 1.0 - * @Create: 2019-07-01 00:48 - * @Author: Wang-X-C + * @Copyright © 2020 Analysys Inc. All rights reserved. + * @Description: + * @Create: 2020/7/20 7:00 PM + * @author: huchangqing */ -public class MainActivity extends AppCompatActivity implements ANSAutoPageTracker { +public class MainActivity extends BaseActivity implements ViewPager.OnPageChangeListener { + + private FragmentMini mFragmentMini = new FragmentMini(); + private FragmentFull mFragmentFull = new FragmentFull(); + + + private FragmentPagerAdapter adapter = new FragmentPagerAdapter(getSupportFragmentManager()) { + @Override + public Fragment getItem(int position) { + switch (position) { + case 0: + return mFragmentMini; + case 1: + return mFragmentFull; + default: + return null; + } + } + + @Override + public int getCount() { + return 2; + } + }; + + private ViewPager mViewPager; + private TextView mTVMini; + private TextView mTVFull; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); - Intent intent = getIntent(); - if (intent != null && intent.getData() != null) { - // 判断如果是deepLink启动,设置启动来源为 3 - AnalysysAgent.launchSource(3); - } + mViewPager = findViewById(R.id.view_pager); + mTVMini = findViewById(R.id.tv_mini); + mTVFull = findViewById(R.id.tv_full); + mViewPager.setAdapter(adapter); + mViewPager.addOnPageChangeListener(this); + mTVMini.setSelected(true); + mTVFull.setSelected(false); +// ActionBar actionBar = getSupportActionBar(); +// if (actionBar != null) { +// actionBar.setDisplayShowTitleEnabled(true); +// actionBar.setTitle("易观方舟Demo"); +// } +// AnalysysAgent.track(this,"homepage"); + } + + @Override + public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) { + } - public void onClick(View view) { - int id = view.getId(); - if (id == R.id.profileButton) { - startActivity(new Intent(MainActivity.this, ProfileActivity.class)); - } else if (id == R.id.propertyButton) { - startActivity(new Intent(MainActivity.this, PropertyActivity.class)); - } else if (id == R.id.eventButton) { - startActivity(new Intent(MainActivity.this, EventActivity.class)); - } else if (id == R.id.userButton) { - startActivity(new Intent(MainActivity.this, UserSettingActivity.class)); - } else if (id == R.id.webViewButton) { - startActivity(new Intent(MainActivity.this, WebViewActivity.class)); - } else if (id == R.id.visualDemoButton) { - // 跳转可视化模块 - try { - Class clz = Class.forName("com.analysys.visualdemo.activity.TopVisualMainActivity"); - startActivity(new Intent(this, clz)); - } catch (ClassNotFoundException e) { - } - } else if (id == R.id.TestHeatMapButton) { - // 热图黑名单测试 - startActivity(new Intent(MainActivity.this, HeatMapTestActivity.class)); - } else if (id == R.id.TestAllgroButton) { - // 跳转全埋点模块 - startActivity(new Intent(MainActivity.this, AllgroTestActivity.class)); - } + @Override + public void onPageSelected(int position) { + mTVMini.setSelected(position == 0); + mTVFull.setSelected(position == 1); + } + + @Override + public void onPageScrollStateChanged(int state) { + } @Override - public Map registerPageProperties() { - // $title为自动采集使用key,用户可覆盖 - Map properties = new HashMap<>(); - properties.put("$title", "详情页"); - return properties; + public boolean onCreateOptionsMenu(Menu menu) { + getMenuInflater().inflate(R.menu.main_menu, menu); + MenuItem item = menu.findItem(R.id.action_modify); + SpannableString spannableString = new SpannableString(item.getTitle()); + spannableString.setSpan(new ForegroundColorSpan(0xff2222ee), 0, spannableString.length(), 0); + item.setTitle(spannableString); + return true; } @Override - public String registerPageUrl() { - // 页面$url字段,将覆盖SDK默认字段 - return "HomePage"; + public boolean onOptionsItemSelected(MenuItem item) { + if (item.getItemId() == R.id.action_modify) { + Intent intent = new Intent(this, ModifyConfigActivity.class); + intent.putExtra(BaseActivity.EXTRA_ACTIVITY_TITLE, "修改配置"); + startActivity(intent); + } + return super.onOptionsItemSelected(item); } + public void onTabClick(View view) { + int id = view.getId(); + if (id == R.id.tv_mini) { + mViewPager.setCurrentItem(0, true); + } else if (id == R.id.tv_full) { + mViewPager.setCurrentItem(1, true); + } + } } diff --git a/ans-demo/apidemo/src/main/java/com/analysys/demo/MainActivityTest.java b/ans-demo/apidemo/src/main/java/com/analysys/demo/MainActivityTest.java new file mode 100644 index 0000000..ae59af4 --- /dev/null +++ b/ans-demo/apidemo/src/main/java/com/analysys/demo/MainActivityTest.java @@ -0,0 +1,4 @@ +package com.analysys.demo; + +public class MainActivityTest extends BaseActivity{ +} diff --git a/ans-demo/apidemo/src/main/java/com/analysys/demo/ModifyConfigActivity.java b/ans-demo/apidemo/src/main/java/com/analysys/demo/ModifyConfigActivity.java new file mode 100644 index 0000000..15bb2d7 --- /dev/null +++ b/ans-demo/apidemo/src/main/java/com/analysys/demo/ModifyConfigActivity.java @@ -0,0 +1,115 @@ +package com.analysys.demo; + +import android.annotation.SuppressLint; +import android.app.AlertDialog; +import android.content.Context; +import android.content.DialogInterface; +import android.content.SharedPreferences; +import android.os.Bundle; +import android.view.View; +import android.widget.EditText; + +import com.analysys.apidemo.R; +import com.analysys.process.AgentProcess; + +import java.util.ArrayList; +import java.util.List; + +/** + * @Copyright © 2020 Analysys Inc. All rights reserved. + * @Description: + * @Create: 2020/7/22 11:04 AM + * @author: huchangqing + */ +public class ModifyConfigActivity extends BaseActivity { + + private EditText edtAppKey; + private EditText edtChannelId; + private EditText edtUploadUrl; + private EditText edtVisualDebugUrl; + private EditText edtVisualConfigUrl; + private SharedPreferences sp; + + public static final String PREF_FILE = "ans_demo_pref"; + public static final String PREF_KEY_APP_KEY = "app_key"; + public static final String PREF_KEY_CHANNEL_ID = "channel_id"; + public static final String PREF_KEY_UPLOAD_URL = "upload_url"; + public static final String PREF_KEY_VISUAL_DEBUG_URL = "visual_debug_url"; + public static final String PREF_KEY_VISUAL_CONFIG_URL = "visual_config_url"; + + class ConfigAction { + EditText view; + String prefKey; + + ConfigAction(EditText v, String key, String defaultValue) { + view = v; + prefKey = key; + String config = sp.getString(prefKey, defaultValue); + view.setText(config); + } + + @SuppressLint("ApplySharedPref") + void saveConfig() { + sp.edit().putString(prefKey, view.getText().toString()).commit(); + } + + public void clear() { + sp.edit().remove(prefKey).commit(); + } + } + + private List mConfigList = new ArrayList<>(); + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_modify_config); + sp = getSharedPreferences(PREF_FILE, Context.MODE_PRIVATE); + + edtAppKey = findViewById(R.id.edt_app_key); + ConfigAction configAction = new ConfigAction(edtAppKey, PREF_KEY_APP_KEY, AgentProcess.getInstance().getConfig().getAppKey()); + mConfigList.add(configAction); + + edtChannelId = findViewById(R.id.edt_channel_id); + configAction = new ConfigAction(edtChannelId, PREF_KEY_CHANNEL_ID, AgentProcess.getInstance().getConfig().getChannel()); + mConfigList.add(configAction); + + edtUploadUrl = findViewById(R.id.edt_upload_url); + configAction = new ConfigAction(edtUploadUrl, PREF_KEY_UPLOAD_URL, AgentProcess.getInstance().getUploadURL()); + mConfigList.add(configAction); + + edtVisualDebugUrl = findViewById(R.id.edt_visual_debug_url); + configAction = new ConfigAction(edtVisualDebugUrl, PREF_KEY_VISUAL_DEBUG_URL, AgentProcess.getInstance().getVisitorDebugURL()); + mConfigList.add(configAction); + + edtVisualConfigUrl = findViewById(R.id.edt_visual_config_url); + configAction = new ConfigAction(edtVisualConfigUrl, PREF_KEY_VISUAL_CONFIG_URL, AgentProcess.getInstance().getVisitorConfigURL()); + mConfigList.add(configAction); + } + + public void onClick(View view) { + boolean isSave = view.getId() == R.id.btn_save; + for (ConfigAction config : mConfigList) { + if (isSave) { + config.saveConfig(); + } else { + config.clear(); + } + } + AlertDialog.Builder builder = new AlertDialog.Builder(this); + StringBuilder sb = new StringBuilder(); + sb.append("AppKey: ").append(edtAppKey.getText().toString()).append("\n"); + sb.append("Channel ID: ").append(edtChannelId.getText().toString()).append("\n"); + sb.append("Upload Url: ").append(edtUploadUrl.getText().toString()).append("\n"); + sb.append("Visual Debug Url: ").append(edtVisualDebugUrl.getText().toString()).append("\n"); + sb.append("Visual Config Url: ").append(edtVisualConfigUrl.getText().toString()).append("\n"); + builder.setMessage(sb.toString()); + builder.setTitle("修改配置后需要重启才能生效"); + builder.setPositiveButton("确认", new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog, int which) { + System.exit(0); + } + }).setCancelable(false).create().show(); + } +} diff --git a/ans-demo/apidemo/src/main/java/com/analysys/demo/OtherActivity.java b/ans-demo/apidemo/src/main/java/com/analysys/demo/OtherActivity.java new file mode 100644 index 0000000..27c61ac --- /dev/null +++ b/ans-demo/apidemo/src/main/java/com/analysys/demo/OtherActivity.java @@ -0,0 +1,240 @@ +package com.analysys.demo; + +import android.os.Bundle; +import android.text.TextUtils; +import android.view.View; +import android.widget.AdapterView; +import android.widget.ArrayAdapter; +import android.widget.CompoundButton; +import android.widget.EditText; +import android.widget.Spinner; +import android.widget.Switch; +import android.widget.TextView; +import android.widget.Toast; + +import com.analysys.AnalysysAgent; +import com.analysys.AnsRamControl; +import com.analysys.EncryptEnum; +import com.analysys.apidemo.R; +import com.analysys.process.AgentProcess; +import com.analysys.strategy.PolicyManager; +import com.analysys.utils.CommonUtils; +import com.analysys.utils.Constants; + +import java.util.ArrayList; +import java.util.List; +import java.util.Map; + +public class OtherActivity extends BaseActivity { + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_other); + TextView tvVersion = findViewById(R.id.tv_version); + tvVersion.setText("App Version: " + CommonUtils.getVersionName(this) + "\nSDK Version: " + Constants.DEV_SDK_VERSION); + + Switch enableDataCollect = findViewById(R.id.enable_data_collect); + enableDataCollect.setChecked(AgentProcess.getInstance().isDataCollectEnable()); + enableDataCollect.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { + @Override + public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { + AnalysysAgent.setDataCollectEnable(isChecked); + } + }); + + Spinner spinner = findViewById(R.id.sp_network); + List listStr = new ArrayList<>(); + listStr.add("不允许上传"); + listStr.add("允许移动网络上传"); + listStr.add("允许wifi网络上传"); + listStr.add("允许所有网络上传"); + List listValues = new ArrayList<>(); + listValues.add(AnalysysAgent.AnalysysNetworkType.AnalysysNetworkNONE); + listValues.add(AnalysysAgent.AnalysysNetworkType.AnalysysNetworkWWAN); + listValues.add(AnalysysAgent.AnalysysNetworkType.AnalysysNetworkWIFI); + listValues.add(AnalysysAgent.AnalysysNetworkType.AnalysysNetworkALL); + initSpinner(spinner, listStr, new IOnItemSelected() { + @Override + public void onSelected(int pos) { + AnalysysAgent.setUploadNetworkType(listValues.get(pos)); + } + }, listValues.indexOf(AnsRamControl.getInstance().getUploadNetworkType())); + + spinner = findViewById(R.id.sp_encrypt); + listStr = new ArrayList<>(); + listStr.add("EMPTY"); + listStr.add("AES_ECB"); + listStr.add("AES_CBC"); + List listValuesEncrypt = new ArrayList<>(); + listValuesEncrypt.add(EncryptEnum.EMPTY); + listValuesEncrypt.add(EncryptEnum.AES); + listValuesEncrypt.add(EncryptEnum.AES_CBC); + initSpinner(spinner, listStr, new IOnItemSelected() { + @Override + public void onSelected(int pos) { + AgentProcess.getInstance().getConfig().setEncryptType((listValuesEncrypt.get(pos))); + } + }, listValuesEncrypt.indexOf(AgentProcess.getInstance().getConfig().getEncryptType())); + + spinner = findViewById(R.id.sp_debug_mode); + listStr = new ArrayList<>(); + listStr.add("关闭debug"); + listStr.add("打开Debug,不计统计"); + listStr.add("打开Debug,计入统计"); + List listValuesDebugMode = new ArrayList<>(); + listValuesDebugMode.add(0); + listValuesDebugMode.add(1); + listValuesDebugMode.add(2); + initSpinner(spinner, listStr, new IOnItemSelected() { + @Override + public void onSelected(int pos) { + AnalysysAgent.setDebugMode(OtherActivity.this, listValuesDebugMode.get(pos)); + } + }, listValuesDebugMode.indexOf(CommonUtils.getDebugMode(this))); + + EditText editText = findViewById(R.id.edt_interval); + editText.setText(PolicyManager.getIntervalTime(this) / 1000 + ""); + editText = findViewById(R.id.edt_max_event); + editText.setText(PolicyManager.getEventCount(this) + ""); + editText = findViewById(R.id.edt_max_cache); + editText.setText(AnalysysAgent.getMaxCacheSize(this) + ""); + + Switch autoTimeCheck = findViewById(R.id.time_check); + autoTimeCheck.setChecked(AgentProcess.getInstance().getConfig().isTimeCheck()); + autoTimeCheck.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { + @Override + public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { + AgentProcess.getInstance().getConfig().setAllowTimeCheck(isChecked); + } + }); + + editText = findViewById(R.id.edt_time_check); + editText.setText(AgentProcess.getInstance().getConfig().getMaxDiffTimeInterval() / 1000 + ""); + + Switch autoDeviceInfo = findViewById(R.id.device_info); + autoDeviceInfo.setChecked(AgentProcess.getInstance().getConfig().isAutoTrackDeviceId()); + autoDeviceInfo.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { + @Override + public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { + AgentProcess.getInstance().getConfig().setAutoTrackDeviceId(isChecked); + } + }); + + Switch autoTrackCrash = findViewById(R.id.auto_track_crash); + autoTrackCrash.setChecked(AgentProcess.getInstance().getConfig().isAutoTrackCrash()); + autoTrackCrash.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { + @Override + public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { + AgentProcess.getInstance().getConfig().setAutoTrackCrash(isChecked); + } + }); + + Switch autoTrack = findViewById(R.id.auto_track_page_view); + autoTrack.setChecked(AgentProcess.getInstance().getConfig().isAutoTrackPageView()); + autoTrack.setOnCheckedChangeListener((buttonView, isChecked) + -> AgentProcess.getInstance().getConfig().setAutoTrackPageView(isChecked)); + + autoTrack = findViewById(R.id.auto_track_probe_click); + autoTrack.setChecked(AgentProcess.getInstance().getConfig().isAutoTrackClick()); + autoTrack.setOnCheckedChangeListener((buttonView, isChecked) + -> AgentProcess.getInstance().getConfig().setAutoTrackClick(isChecked)); + + autoTrack = findViewById(R.id.auto_track_heat_map); + autoTrack.setChecked(AgentProcess.getInstance().getConfig().isAutoHeatMap()); + autoTrack.setOnCheckedChangeListener((buttonView, isChecked) + -> AgentProcess.getInstance().getConfig().setAutoHeatMap(isChecked)); + } + + private interface IOnItemSelected { + void onSelected(int pos); + } + + private void initSpinner(Spinner spinner, List listStr, IOnItemSelected onItemSelectedCallabck, int initPos) { + spinner.setAdapter(new ArrayAdapter<>(this, + android.R.layout.simple_list_item_1, + android.R.id.text1, + listStr)); + spinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { + @Override + public void onItemSelected(AdapterView parent, View view, int pos, long id) { + onItemSelectedCallabck.onSelected(pos); + Toast.makeText(OtherActivity.this, "设置成功", Toast.LENGTH_SHORT).show(); + } + + @Override + public void onNothingSelected(AdapterView parent) { + } + }); + spinner.setSelection(initPos); + } + + private long edt2Long(int resId, long min, long max) { + long value = -1; + try { + EditText editText = findViewById(resId); + value = Long.parseLong(editText.getText().toString()); + } catch (Exception e) { + } + if (value > max || value < min) { + value = -1; + } + return value; + } + + public void onClick(View view) { + int viewId = view.getId(); + if (viewId == R.id.btn_interval) { + long value = edt2Long(R.id.edt_interval, 1, Long.MAX_VALUE); + if (value == -1) { + Toast.makeText(this, "输入错误", Toast.LENGTH_SHORT).show(); + } else { + AnalysysAgent.setIntervalTime(this, value); + Toast.makeText(this, "操作成功", Toast.LENGTH_SHORT).show(); + } + } else if (viewId == R.id.btn_max_event) { + long value = edt2Long(R.id.edt_max_event, 1, Long.MAX_VALUE); + if (value == -1) { + Toast.makeText(this, "输入错误", Toast.LENGTH_SHORT).show(); + } else { + AnalysysAgent.setMaxEventSize(this, value); + Toast.makeText(this, "操作成功", Toast.LENGTH_SHORT).show(); + } + } else if (viewId == R.id.btn_max_cache) { + long value = edt2Long(R.id.edt_max_cache, 1, Long.MAX_VALUE); + if (value == -1) { + Toast.makeText(this, "输入错误", Toast.LENGTH_SHORT).show(); + } else { + AnalysysAgent.setMaxCacheSize(this, value); + Toast.makeText(this, "操作成功", Toast.LENGTH_SHORT).show(); + } + } else if (viewId == R.id.btn_time_check) { + long value = edt2Long(R.id.edt_time_check, 1, Long.MAX_VALUE); + if (value == -1) { + Toast.makeText(this, "输入错误", Toast.LENGTH_SHORT).show(); + } else { + AgentProcess.getInstance().getConfig().setMaxDiffTimeInterval(value); + Toast.makeText(this, "操作成功", Toast.LENGTH_SHORT).show(); + } + } else if (viewId == R.id.btn_crash) { + Toast.makeText(this, "操作成功,在logcat中查看xwhat为$app_crash的日志", Toast.LENGTH_LONG).show(); + int crash = 1 / 0; + } else if (viewId == R.id.btn_get_property) { + Map getProperty = AnalysysAgent.getPresetProperties(this); + StringBuilder properties = new StringBuilder(); + if (getProperty != null) { + for (Map.Entry entry : getProperty.entrySet()) { + properties.append("\n").append(entry.getKey()).append(" = " + entry.getValue()); + } + } + String props = properties.toString(); + Toast.makeText(this, "所有预置属性值为" + (TextUtils.isEmpty(props) ? "空" : props), Toast.LENGTH_LONG).show(); + } else if (viewId == R.id.btn_clean_db) { + AnalysysAgent.cleanDBCache(); + Toast.makeText(this, "操作成功", Toast.LENGTH_SHORT).show(); + } else if (viewId == R.id.btn_reset) { + AnalysysAgent.reset(this); + Toast.makeText(this, "操作成功", Toast.LENGTH_SHORT).show(); + } + } +} diff --git a/ans-demo/apidemo/src/main/java/com/analysys/demo/PageViewActivity.java b/ans-demo/apidemo/src/main/java/com/analysys/demo/PageViewActivity.java new file mode 100644 index 0000000..ca203f8 --- /dev/null +++ b/ans-demo/apidemo/src/main/java/com/analysys/demo/PageViewActivity.java @@ -0,0 +1,85 @@ +package com.analysys.demo; + +import android.content.Intent; +import android.os.Bundle; +import android.view.View; +import android.widget.Button; +import android.widget.CheckBox; +import android.widget.CompoundButton; +import android.widget.Switch; +import android.widget.Toast; + +import com.analysys.AnalysysAgent; +import com.analysys.apidemo.R; +import com.analysys.process.AgentProcess; +import com.analysys.utils.Constants; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +/** + * @Copyright © 2020 Analysys Inc. All rights reserved. + * @Description: + * @Create: 2020/7/22 11:37 AM + * @author: huchangqing + */ +public class PageViewActivity extends BaseActivity { + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_page_view); + Switch autoTrack = findViewById(R.id.auto_track); + autoTrack.setChecked(AgentProcess.getInstance().getConfig().isAutoTrackPageView()); + autoTrack.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { + @Override + public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { + AgentProcess.getInstance().getConfig().setAutoTrackPageView(isChecked); + } + }); + + String testPageName = PageViewTestActivity.class.getName(); + + Button btnOpenPage = findViewById(R.id.btn_open_page); + btnOpenPage.setText(btnOpenPage.getText() + testPageName); + + CheckBox checkBox = findViewById(R.id.cb_ignore_page); + checkBox.setChecked(AgentProcess.getInstance().isThisPageInPageViewBlackList(testPageName)); + checkBox.setText(checkBox.getText() + testPageName); + checkBox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { + @Override + public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { + if (isChecked) { + List list = new ArrayList<>(); + list.add(testPageName); + AnalysysAgent.setPageViewBlackListByPages(list); + } else { + AnalysysAgent.setPageViewBlackListByPages(null); + } + } + }); + } + + public void onClick(View view) { + int id = view.getId(); + if (id == R.id.btn_open_page) { + Intent intent = new Intent(this, PageViewTestActivity.class); + intent.putExtra(BaseActivity.EXTRA_ACTIVITY_TITLE, "页面采集测试"); + intent.putExtra(BaseActivity.EXTRA_EVENT_NAME, Constants.PAGE_VIEW); + startActivity(intent); + } else if (id == R.id.btn_manual_sigle) { + //服务正在开展某个活动,需要统计活动页面时 + AnalysysAgent.pageView(this, "活动页"); + Toast.makeText(this, "调用成功,统计【活动页】", Toast.LENGTH_LONG).show(); + } else if (id == R.id.btn_manual_multi) { + //购买一部iPhone手机,手机价格为8000元 + Map page = new HashMap<>(); + page.put("commodityName", "iPhone"); + page.put("commodityPrice", 8000); + AnalysysAgent.pageView(this, "商品页", page); + Toast.makeText(this, "调用成功,统计【商品页】,属性为[commodityName = iPhone, commodityPrice = 8000]", Toast.LENGTH_LONG).show(); + } + } +} diff --git a/ans-demo/apidemo/src/main/java/com/analysys/demo/PageViewTestActivity.java b/ans-demo/apidemo/src/main/java/com/analysys/demo/PageViewTestActivity.java new file mode 100644 index 0000000..85f3e1a --- /dev/null +++ b/ans-demo/apidemo/src/main/java/com/analysys/demo/PageViewTestActivity.java @@ -0,0 +1,36 @@ +package com.analysys.demo; + +import android.os.Bundle; +import android.widget.TextView; + +import com.analysys.ANSAutoPageTracker; +import com.analysys.apidemo.R; + +import java.util.HashMap; +import java.util.Map; + +public class PageViewTestActivity extends BaseActivity implements ANSAutoPageTracker { + + private Map pageProperties; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_page_view_test); + TextView tv = findViewById(R.id.tv_page_name); + pageProperties = new HashMap<>(); + pageProperties.put("name", "iphone"); + pageProperties.put("price", 4000); + tv.setText("页面名字:" + getClass().getName() + "\n\n\n自定义信息 " + pageProperties.toString()); + } + + @Override + public Map registerPageProperties() { + return pageProperties; + } + + @Override + public String registerPageUrl() { + return null; + } +} diff --git a/ans-demo/apidemo/src/main/java/com/analysys/demo/ProbeActivity.java b/ans-demo/apidemo/src/main/java/com/analysys/demo/ProbeActivity.java new file mode 100644 index 0000000..3a8ce15 --- /dev/null +++ b/ans-demo/apidemo/src/main/java/com/analysys/demo/ProbeActivity.java @@ -0,0 +1,94 @@ +package com.analysys.demo; + +import android.content.Intent; +import android.os.Bundle; +import android.view.View; +import android.widget.Button; +import android.widget.CheckBox; +import android.widget.CompoundButton; +import android.widget.Switch; + +import com.analysys.AnalysysAgent; +import com.analysys.apidemo.R; +import com.analysys.process.AgentProcess; +import com.analysys.utils.Constants; + +import java.util.ArrayList; +import java.util.List; + +public class ProbeActivity extends BaseActivity { + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_probe); + Switch switch0 = findViewById(R.id.auto_track_fragment); + switch0.setChecked(AgentProcess.getInstance().getConfig().isAutoTrackFragmentPageView()); + switch0.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { + @Override + public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { + AgentProcess.getInstance().getConfig().setAutoTrackFragmentPageView(isChecked); + } + }); + + switch0 = findViewById(R.id.auto_track_click); + switch0.setChecked(AgentProcess.getInstance().getConfig().isAutoTrackClick()); + switch0.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { + @Override + public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { + AgentProcess.getInstance().getConfig().setAutoTrackClick(isChecked); + } + }); + + String pageName = ProbeClickTestActivity.class.getName(); + + CheckBox checkBox = findViewById(R.id.auto_track_click_ignore); + checkBox.setText(checkBox.getText() + pageName); + checkBox.setChecked(AgentProcess.getInstance().isThisPageInAutoClickBlackList(pageName)); + checkBox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { + @Override + public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { + if (isChecked) { + List list = new ArrayList<>(); + list.add(pageName); + AnalysysAgent.setAutoClickBlackListByPages(list); + } else { + AnalysysAgent.setAutoClickBlackListByPages(null); + } + } + }); + + Button btn = findViewById(R.id.btn_open_fragment_page); + checkBox = findViewById(R.id.auto_track_click_ignore_button); + checkBox.setChecked(AgentProcess.getInstance().isThisViewTypeInAutoClickBlackList(btn.getClass())); + checkBox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { + @Override + public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { + if (isChecked) { + List list = new ArrayList<>(); + list.add(btn.getClass()); + AnalysysAgent.setAutoClickBlackListByViewTypes(list); + } else { + AnalysysAgent.setAutoClickBlackListByViewTypes(null); + } + } + }); + + Button btnOpenPage = findViewById(R.id.btn_open_click_page); + btnOpenPage.setText(btnOpenPage.getText() + pageName); + } + + public void onClick(View view) { + if (view.getId() == R.id.btn_open_fragment_page) { + Intent intent = new Intent(this, ProbeFragmentTestActivity.class); + intent.putExtra(EXTRA_ACTIVITY_TITLE, "Fragment PV测试页面"); + intent.putExtra(EXTRA_EVENT_NAME, Constants.PAGE_VIEW); + startActivity(intent); + } else if (view.getId() == R.id.btn_open_click_page) { + Intent intent = new Intent(this, ProbeClickTestActivity.class); + intent.putExtra(EXTRA_ACTIVITY_TITLE, "点击测试页面"); + intent.putExtra(EXTRA_EVENT_NAME, Constants.USER_CLICK); + startActivity(intent); + } + } +} diff --git a/ans-demo/apidemo/src/main/java/com/analysys/demo/ProbeClickTestActivity.java b/ans-demo/apidemo/src/main/java/com/analysys/demo/ProbeClickTestActivity.java new file mode 100644 index 0000000..a5a211f --- /dev/null +++ b/ans-demo/apidemo/src/main/java/com/analysys/demo/ProbeClickTestActivity.java @@ -0,0 +1,192 @@ +package com.analysys.demo; + +import android.app.AlertDialog; +import android.os.Bundle; +import android.view.View; +import android.widget.AdapterView; +import android.widget.ArrayAdapter; +import android.widget.Button; +import android.widget.CheckBox; +import android.widget.CompoundButton; +import android.widget.ExpandableListView; +import android.widget.ListView; +import android.widget.RadioGroup; +import android.widget.RatingBar; +import android.widget.SeekBar; +import android.widget.SimpleExpandableListAdapter; +import android.widget.TabHost; + +import com.analysys.AnalysysAgent; +import com.analysys.allgro.annotations.AnalysysIgnoreTrackClick; +import com.analysys.apidemo.R; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +public class ProbeClickTestActivity extends BaseActivity { + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_probe_click_test); + Button btnListener = findViewById(R.id.btn_listener); + btnListener.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + } + }); + + Button btnLambda = findViewById(R.id.btn_lambda); + btnLambda.setOnClickListener(v -> { + }); + + Button btnIgnore = findViewById(R.id.btn_ignore_annotation); + btnIgnore.setOnClickListener(new View.OnClickListener() { + @Override + @AnalysysIgnoreTrackClick + public void onClick(View v) { + } + }); + + btnIgnore = findViewById(R.id.btn_ignore_blacklist); + btnIgnore.setOnClickListener(v -> { + }); + AnalysysAgent.setAutoClickBlackListByView(btnIgnore); + + CheckBox checkBox = findViewById(R.id.checkbox); + checkBox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { + @Override + public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { + } + }); + + RatingBar ratingBar = findViewById(R.id.rating_bar); + ratingBar.setOnRatingBarChangeListener(new RatingBar.OnRatingBarChangeListener() { + @Override + public void onRatingChanged(RatingBar ratingBar, float rating, boolean fromUser) { + } + }); + + SeekBar seekBar = findViewById(R.id.seek_bar); + seekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() { + @Override + public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) { + } + + @Override + public void onStartTrackingTouch(SeekBar seekBar) { + } + + @Override + public void onStopTrackingTouch(SeekBar seekBar) { + } + }); + + RadioGroup radioGroup = findViewById(R.id.radio_group); + radioGroup.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() { + @Override + public void onCheckedChanged(RadioGroup group, int checkedId) { + } + }); + + ListView listView = findViewById(R.id.list_view); + List listStr = new ArrayList<>(); + for (int i = 0; i < 10; i++) { + listStr.add("list row " + i); + } + listView.setAdapter(new ArrayAdapter<>(this, + android.R.layout.simple_list_item_1, + android.R.id.text1, + listStr)); + listView.setOnItemClickListener(new AdapterView.OnItemClickListener() { + @Override + public void onItemClick(AdapterView parent, View view, int position, long id) { + } + }); + listView.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { + @Override + public void onItemSelected(AdapterView parent, View view, int position, long id) { + } + + @Override + public void onNothingSelected(AdapterView parent) { + } + }); + + ExpandableListView expandableListView = findViewById(R.id.ex_list_view); + List> groupData = new ArrayList>(); + List>> childData = new ArrayList>>(); + final String NAME = "NAME"; + final String IS_EVEN = "IS_EVEN"; + for (int i = 0; i < 3; i++) { + Map curGroupMap = new HashMap(); + groupData.add(curGroupMap); + curGroupMap.put(NAME, "Group " + i); + curGroupMap.put(IS_EVEN, (i % 2 == 0) ? "This group is even" : "This group is odd"); + + List> children = new ArrayList>(); + for (int j = 0; j < 5; j++) { + Map curChildMap = new HashMap(); + children.add(curChildMap); + curChildMap.put(NAME, "Child " + j); + curChildMap.put(IS_EVEN, (j % 2 == 0) ? "This child is even" : "This child is odd"); + } + childData.add(children); + } + expandableListView.setAdapter(new SimpleExpandableListAdapter( + this, + groupData, + android.R.layout.simple_expandable_list_item_2, + new String[]{NAME, IS_EVEN}, + new int[]{android.R.id.text1, android.R.id.text2}, + childData, + android.R.layout.simple_expandable_list_item_2, + new String[]{NAME, IS_EVEN}, + new int[]{android.R.id.text1, android.R.id.text2} + )); + expandableListView.expandGroup(groupData.size() - 1); + expandableListView.setOnGroupClickListener(new ExpandableListView.OnGroupClickListener() { + @Override + public boolean onGroupClick(ExpandableListView parent, View v, int groupPosition, long id) { + return false; + } + }); + expandableListView.setOnChildClickListener((parent, v, groupPosition, childPosition, id) -> false); + + TabHost tabHost = findViewById(R.id.tab_host); + tabHost.setup(); + tabHost.addTab(tabHost.newTabSpec("tab1").setIndicator("Tab1", null).setContent(R.id.tab1)); + tabHost.addTab(tabHost.newTabSpec("tab2").setIndicator("Tab2", null).setContent(R.id.tab2)); + tabHost.setOnTabChangedListener(new TabHost.OnTabChangeListener() { + @Override + public void onTabChanged(String tabId) { + } + }); + + Button btnDialog = findViewById(R.id.btn_dialog); + btnDialog.setOnClickListener(v -> { + AlertDialog.Builder builder = new AlertDialog.Builder(ProbeClickTestActivity.this); + builder.setMessage("对话框点击测试"); + builder.setTitle("提示"); + builder.setPositiveButton("确认", (dialog, which) -> dialog.dismiss()); + builder.show(); + }); + + Button btnDialogMultiChoice = findViewById(R.id.btn_dialog_multi_choice); + btnDialogMultiChoice.setOnClickListener(v -> { + AlertDialog.Builder builder = new AlertDialog.Builder(ProbeClickTestActivity.this); + builder.setTitle("提示"); + String[] items = {"item1", "item2", "item3"}; + boolean[] choices = {false, false, false}; + builder.setMultiChoiceItems(items, choices, (dialog, which, isChecked) -> { + }); + builder.setPositiveButton("确认", (dialog, which) -> dialog.dismiss()); + builder.show(); + }); + } + + public void onClick(View view) { + } +} diff --git a/ans-demo/apidemo/src/main/java/com/analysys/demo/ProbeFragmentTestActivity.java b/ans-demo/apidemo/src/main/java/com/analysys/demo/ProbeFragmentTestActivity.java new file mode 100644 index 0000000..2728372 --- /dev/null +++ b/ans-demo/apidemo/src/main/java/com/analysys/demo/ProbeFragmentTestActivity.java @@ -0,0 +1,85 @@ +package com.analysys.demo; + +import android.os.Bundle; +import android.view.View; + +import androidx.databinding.DataBindingUtil; +import androidx.fragment.app.Fragment; +import androidx.fragment.app.FragmentPagerAdapter; +import androidx.viewpager.widget.ViewPager; + +import com.analysys.apidemo.R; +import com.analysys.apidemo.databinding.ActivityProbeFragmentTestBinding; + +public class ProbeFragmentTestActivity extends BaseActivity implements ViewPager.OnPageChangeListener { + + private ActivityProbeFragmentTestBinding mDataBinding; + + private FragmentPagerAdapter adapter = new FragmentPagerAdapter(getSupportFragmentManager()) { + @Override + public Fragment getItem(int position) { + switch (position) { + case 0: + return new FragmentProbeOne(); + case 1: + return new FragmentProbeTwo(); + default: + throw new RuntimeException("数据异常"); + } + } + + @Override + public int getCount() { + return 2; + } + }; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + mDataBinding = DataBindingUtil.setContentView(this, R.layout.activity_probe_fragment_test); + if (mDataBinding == null) { + finish(); + return; + } + + mDataBinding.viewPager.setAdapter(adapter); + mDataBinding.viewPager.addOnPageChangeListener(this); + mDataBinding.btn1.setSelected(true); + mDataBinding.setPageInfo(this); + } + + + /** + * 页面滑动时的监听 + */ + @Override + public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) { + + } + + /** + * 页面选择时的监听 + */ + @Override + public void onPageSelected(int position) { + mDataBinding.btn1.setSelected(position == 0); + mDataBinding.btn2.setSelected(position == 1); + } + + /** + * 页面滑动状态变化时的监听 + */ + @Override + public void onPageScrollStateChanged(int state) { + } + + public void onViewClick(View view) { + int id = view.getId(); + if (id == R.id.btn1) { + mDataBinding.viewPager.setCurrentItem(0, true); + } else if (id == R.id.btn2) { + mDataBinding.viewPager.setCurrentItem(1, true); + } + } +} diff --git a/ans-demo/apidemo/src/main/java/com/analysys/demo/Process1Activity.java b/ans-demo/apidemo/src/main/java/com/analysys/demo/Process1Activity.java new file mode 100644 index 0000000..bf1ee1d --- /dev/null +++ b/ans-demo/apidemo/src/main/java/com/analysys/demo/Process1Activity.java @@ -0,0 +1,32 @@ +package com.analysys.demo; + +import android.content.Intent; +import android.os.Bundle; +import android.view.View; + +import androidx.appcompat.app.ActionBar; + +import com.analysys.apidemo.R; + +public class Process1Activity extends BaseActivity { + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_process1); + ActionBar actionBar = getSupportActionBar(); + if (actionBar != null) { + actionBar.setTitle("进程1"); + } + } + + public void onClick(View view) { + int id = view.getId(); + if (id == R.id.btn_ipc) { + } else if (id == R.id.btn_process2) { + Intent intent = new Intent(this, Process2Activity.class); + intent.putExtra(EXTRA_ACTIVITY_TITLE, "进程2"); + startActivity(intent); + } + } +} diff --git a/ans-demo/visualDemo/src/main/java/com/analysys/visualdemo/activity/DActivity.java b/ans-demo/apidemo/src/main/java/com/analysys/demo/Process2Activity.java similarity index 53% rename from ans-demo/visualDemo/src/main/java/com/analysys/visualdemo/activity/DActivity.java rename to ans-demo/apidemo/src/main/java/com/analysys/demo/Process2Activity.java index 476b9a4..70360cd 100644 --- a/ans-demo/visualDemo/src/main/java/com/analysys/visualdemo/activity/DActivity.java +++ b/ans-demo/apidemo/src/main/java/com/analysys/demo/Process2Activity.java @@ -1,19 +1,19 @@ -package com.analysys.visualdemo.activity; +package com.analysys.demo; -import android.app.Activity; import android.os.Bundle; import android.view.View; -import com.analysys.visualdemo.R; +import com.analysys.apidemo.R; -public class DActivity extends Activity { +public class Process2Activity extends BaseActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); - setContentView(R.layout.activity_d); + setContentView(R.layout.activity_process2); } public void onClick(View view) { + } } diff --git a/ans-demo/apidemo/src/main/java/com/analysys/demo/ProfileActivity.java b/ans-demo/apidemo/src/main/java/com/analysys/demo/ProfileActivity.java deleted file mode 100644 index 5032416..0000000 --- a/ans-demo/apidemo/src/main/java/com/analysys/demo/ProfileActivity.java +++ /dev/null @@ -1,92 +0,0 @@ -package com.analysys.demo; - -import android.content.Context; -import android.os.Bundle; -import android.view.View; - -import androidx.appcompat.app.AppCompatActivity; - -import com.analysys.ANSAutoPageTracker; -import com.analysys.AnalysysAgent; -import com.analysys.apidemo.R; - -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -/** - * @Copyright © 2019 EGuan Inc. All rights reserved. - * @Description: TODO - * @Version: 1.0 - * @Create: 2019-07-01 00:48 - * @Author: Wang-X-C - */ -public class ProfileActivity extends AppCompatActivity implements ANSAutoPageTracker { - Context mContext = null; - - @Override - protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - setContentView(R.layout.activity_profile); - mContext = this.getApplicationContext(); - } - - public void onClick(View view) { - int id = view.getId(); - if (id == R.id.singleProfile) {//要统计分析使用邮箱登录的用户 - AnalysysAgent.profileSet(mContext, "Email", "yonghu@163.com"); - } else if (id == R.id.multipleProfile) {//要统计用户的登录方式邮箱登录,微信登录 - Map profileSet = new HashMap<>(); - profileSet.put("Email", "yonghu@163.com"); - profileSet.put("WeChatID", "weixinhao"); - AnalysysAgent.profileSet(mContext, profileSet); - } else if (id == R.id.singleProfileSetOnce) {//要统计用户的激活时间 - AnalysysAgent.profileSetOnce(mContext, "activationTime", "1521594686781"); - } else if (id == R.id.multipleProfileSetOnce) {//要统计激活时间和首次登陆时间 - Map setOnceProfile = new HashMap<>(); - setOnceProfile.put("activationTime", "1521594686781"); - setOnceProfile.put("loginTime", "1521594726781"); - AnalysysAgent.profileSetOnce(mContext, setOnceProfile); - } else if (id == R.id.singleProfileIncrement) {//用户年龄增加了一岁 - AnalysysAgent.profileIncrement(mContext, "age", 1); - } else if (id == R.id.multipleProfileIncrement) {//用户年龄增加了一岁积分增加了200 - Map incrementProfile = new HashMap<>(); - incrementProfile.put("age", 1); - incrementProfile.put("integral", 200); - AnalysysAgent.profileIncrement(mContext, incrementProfile); - } else if (id == R.id.singleProfileUnset) {// 要删除已经设置的用户年龄这一属性, - AnalysysAgent.profileUnset(mContext, "age"); - } else if (id == R.id.multipleProfileDelete) {//清除用户的所有属性 - AnalysysAgent.profileDelete(mContext); - } else if (id == R.id.singleProfileAppend) {//添加用户爱好 - AnalysysAgent.profileAppend(mContext, "hobby", "Music"); - } else if (id == R.id.multipleProfileAppend) { - Map map = new HashMap<>(); - map.put("hobby", "PlayBasketball"); - map.put("sports", "Run"); - AnalysysAgent.profileAppend(mContext, map); - } else if (id == R.id.listProfileAppend) { - List list = new ArrayList<>(); - list.add("PlayBasketball"); - list.add("music"); - AnalysysAgent.profileAppend(mContext, "hobby", list); - } - - } - - @Override - public Map registerPageProperties() { - Map map = new HashMap<>(); - map.put("pageName", "用户属性页"); - map.put("pageDetails", "设置用户各个属性"); - return map; - } - - @Override - public String registerPageUrl() { - return "analysysapp://com.analysys.demo/second?" + - "utm_campaign_id=10000292&utm_campaign=AAA&" + - "utm_medium=1&utm_source=1&utm_content=1&utm_term=1"; - } -} diff --git a/ans-demo/apidemo/src/main/java/com/analysys/demo/PropertyActivity.java b/ans-demo/apidemo/src/main/java/com/analysys/demo/PropertyActivity.java index 0eb0403..d3b4637 100644 --- a/ans-demo/apidemo/src/main/java/com/analysys/demo/PropertyActivity.java +++ b/ans-demo/apidemo/src/main/java/com/analysys/demo/PropertyActivity.java @@ -1,71 +1,121 @@ package com.analysys.demo; -import android.content.Context; import android.os.Bundle; -import android.util.Log; +import android.text.TextUtils; import android.view.View; - -import androidx.appcompat.app.AppCompatActivity; +import android.widget.AdapterView; +import android.widget.ArrayAdapter; +import android.widget.ListView; +import android.widget.Toast; import com.analysys.AnalysysAgent; import com.analysys.apidemo.R; -import com.analysys.hybrid.HybridBridge; +import com.analysys.utils.Constants; +import java.util.ArrayList; import java.util.HashMap; +import java.util.List; import java.util.Map; -/** - * @Copyright © 2019 EGuan Inc. All rights reserved. - * @Description: TODO - * @Version: 1.0 - * @Create: 2019-07-01 00:48 - * @Author: Wang-X-C - */ -public class PropertyActivity extends AppCompatActivity { +public class PropertyActivity extends BaseActivity { + + class PropertyAction { + String name; + String eventName; + Runnable runnable; + + PropertyAction(String name, String eventName, Runnable runnable) { + this.name = name; + this.eventName = eventName; + this.runnable = runnable; + } + + public void doAction() { + runnable.run(); + } + } - Context mContext = null; - private static final String TAG = PropertyActivity.class.getSimpleName(); + public void onClick(View view) { + AnalysysAgent.track(this, "track_test"); + Toast.makeText(this, "触发成功", Toast.LENGTH_SHORT).show(); + } @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_property); - mContext = this.getApplicationContext(); - } - - public void onClick(View view) { - int id = view.getId(); - if (id == R.id.singleRegisterSuperProperty) {//购买一年腾讯会员,今年内只需设置一次即可 - AnalysysAgent.registerSuperProperty(mContext, "member", "VIP"); - Log.i(TAG, "不产生事件"); - } else if (id == R.id.multipleRegisterSuperProperty) {//购买了一年腾讯会员和设置了用户的年龄 - Map property = new HashMap<>(); - property.put("age", "20"); - property.put("member", "VIP"); - AnalysysAgent.registerSuperProperties(mContext, property); - Log.i(TAG, "不产生事件"); - } else if (id == R.id.singleUnregisterSuperProperty) {//删除设置的用户年龄属性 - AnalysysAgent.unRegisterSuperProperty(mContext, "age"); - Log.i(TAG, "不产生事件"); - } else if (id == R.id.multipleClearSuperProperty) {//清除所有已经设置的用户数属性 - AnalysysAgent.clearSuperProperties(mContext); - Log.i(TAG, "不产生事件"); - } else if (id == R.id.getSuperProperty) {//查看已经设置的“member”的通用属性 - Object singleSuperProperty = AnalysysAgent.getSuperProperty(mContext, "member"); - if (singleSuperProperty != null) { - Log.i(TAG, "属性:Value = " + singleSuperProperty.toString()); + ListView listView = findViewById(R.id.list_view); + List list = new ArrayList<>(); + list.add(new PropertyAction("注册单个通用属性", Constants.PROFILE_SET, new Runnable() { + @Override + public void run() { + //购买一年腾讯会员,今年内只需设置一次即可 + AnalysysAgent.registerSuperProperty(PropertyActivity.this, "member", "VIP"); + Toast.makeText(PropertyActivity.this, "注册[member = VIP],本操作不产生事件,请触发事件后查看结果", Toast.LENGTH_LONG).show(); + } + })); + list.add(new PropertyAction("注册多个通用属性", Constants.PROFILE_SET, new Runnable() { + @Override + public void run() { + //购买了一年腾讯会员和设置了用户的年龄 + Map property = new HashMap<>(); + property.put("age", "20"); + property.put("member", "VIP"); + AnalysysAgent.registerSuperProperties(PropertyActivity.this, property); + Toast.makeText(PropertyActivity.this, "注册[age = 20,member = VIP],本操作不产生事件,请触发事件后查看结果", Toast.LENGTH_LONG).show(); } - Log.i(TAG, "不产生事件"); - } else if (id == R.id.getSuperProperties) {//查看所有已经设置的通用属性 - Map getProperty = AnalysysAgent.getSuperProperties(mContext); - String properties = ""; - if (getProperty != null) { - for (Map.Entry entry : getProperty.entrySet()) { - Log.i(TAG, "属性:Key = " + entry.getKey() + ", Value = " + entry.getValue()); + })); + list.add(new PropertyAction("获取单个通用属性", Constants.PROFILE_INCREMENT, new Runnable() { + @Override + public void run() { + //查看已经设置的“member”的通用属性 + Object singleSuperProperty = AnalysysAgent.getSuperProperty(PropertyActivity.this, "member"); + Toast.makeText(PropertyActivity.this, "member属性值为" + (singleSuperProperty == null ? "空" : singleSuperProperty.toString()), Toast.LENGTH_LONG).show(); + } + })); + list.add(new PropertyAction("获取所有通用属性", Constants.PROFILE_INCREMENT, new Runnable() { + @Override + public void run() { + Map getProperty = AnalysysAgent.getSuperProperties(PropertyActivity.this); + StringBuilder properties = new StringBuilder(); + if (getProperty != null) { + for (Map.Entry entry : getProperty.entrySet()) { + properties.append("\n").append(entry.getKey()).append(" = " + entry.getValue()); + } } - Log.i(TAG, "不产生事件"); + String props = properties.toString(); + Toast.makeText(PropertyActivity.this, "所有通用属性值为" + (TextUtils.isEmpty(props) ? "空" : props), Toast.LENGTH_LONG).show(); + } + })); + list.add(new PropertyAction("删除单个通用属性", Constants.PROFILE_SET_ONCE, new Runnable() { + @Override + public void run() { + //删除设置的用户年龄属性 + AnalysysAgent.unRegisterSuperProperty(PropertyActivity.this, "age"); + Toast.makeText(PropertyActivity.this, "删除属性age,本操作不产生事件,请触发事件后查看结果", Toast.LENGTH_LONG).show(); } + })); + list.add(new PropertyAction("删除所有通用属性", Constants.PROFILE_SET_ONCE, new Runnable() { + @Override + public void run() { + AnalysysAgent.clearSuperProperties(PropertyActivity.this); + Toast.makeText(PropertyActivity.this, "操作成功,本操作不产生事件,请触发事件后查看结果", Toast.LENGTH_LONG).show(); + } + })); + + List listStr = new ArrayList<>(); + for (int i = 0; i < list.size(); i++) { + listStr.add(list.get(i).name); } + listView.setAdapter(new ArrayAdapter<>(this, + android.R.layout.simple_list_item_1, + android.R.id.text1, + listStr)); + listView.setOnItemClickListener(new AdapterView.OnItemClickListener() { + @Override + public void onItemClick(AdapterView parent, View view, int position, long id) { + list.get(position).doAction(); + } + }); } - } diff --git a/ans-demo/apidemo/src/main/java/com/analysys/demo/SingleProcessTestActivity.java b/ans-demo/apidemo/src/main/java/com/analysys/demo/SingleProcessTestActivity.java deleted file mode 100644 index b84b4a9..0000000 --- a/ans-demo/apidemo/src/main/java/com/analysys/demo/SingleProcessTestActivity.java +++ /dev/null @@ -1,28 +0,0 @@ -package com.analysys.demo; - -import android.os.Bundle; -import android.view.View; - -import androidx.appcompat.app.AppCompatActivity; - -import com.analysys.apidemo.R; - -/** - * Description: 测试独立进程 - * Author: fengzeyuan - * Date: 2019-11-20 16:34 - * Version: 1.0 - */ -public class SingleProcessTestActivity extends AppCompatActivity { - - - @Override - protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - setContentView(R.layout.activity_main); - } - - public void onClick(View view) { - - } -} diff --git a/ans-demo/apidemo/src/main/java/com/analysys/demo/TrackActivity.java b/ans-demo/apidemo/src/main/java/com/analysys/demo/TrackActivity.java new file mode 100644 index 0000000..7748ea5 --- /dev/null +++ b/ans-demo/apidemo/src/main/java/com/analysys/demo/TrackActivity.java @@ -0,0 +1,35 @@ +package com.analysys.demo; + +import android.os.Bundle; +import android.view.View; +import android.widget.Toast; + +import com.analysys.AnalysysAgent; +import com.analysys.apidemo.R; + +import java.util.HashMap; +import java.util.Map; + +public class TrackActivity extends BaseActivity { + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_track); + } + + public void onClick(View view) { + if (view.getId() == R.id.btn_track) { + //统计用户确认订单的事件 + AnalysysAgent.track(this, "confirmOrder"); + Toast.makeText(this, "触发事件:confirmOrder", Toast.LENGTH_SHORT).show(); + } else { + //用户购买某一商品需支付2000元 + Map eventInfo = new HashMap<>(); + eventInfo.put("name", "phone"); + eventInfo.put("money", 2000); + AnalysysAgent.track(this, "payment", eventInfo); + Toast.makeText(this, "触发事件:payment [name = phone, money = 2000]", Toast.LENGTH_SHORT).show(); + } + } +} diff --git a/ans-demo/apidemo/src/main/java/com/analysys/demo/TrackEventObserver.java b/ans-demo/apidemo/src/main/java/com/analysys/demo/TrackEventObserver.java new file mode 100644 index 0000000..14820ab --- /dev/null +++ b/ans-demo/apidemo/src/main/java/com/analysys/demo/TrackEventObserver.java @@ -0,0 +1,132 @@ +package com.analysys.demo; + +import android.text.TextUtils; + +import com.analysys.process.AgentProcess; + +import org.json.JSONException; +import org.json.JSONObject; + +import java.text.SimpleDateFormat; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Date; +import java.util.Iterator; +import java.util.List; + +/** + * @Copyright © 2020 Analysys Inc. All rights reserved. + * @Description: + * @Create: 2020/7/22 5:41 PM + * @author: huchangqing + */ +public class TrackEventObserver implements AgentProcess.IEventObserver { + + private static TrackEventObserver sInstance = new TrackEventObserver(); + + public static class EventData { + String eventName; + String time; + JSONObject sendData; + + public EventData(String eventName, String time, JSONObject sendData) { + this.eventName = eventName; + this.time = time; + this.sendData = sendData; + } + + public String getDetail() { + StringBuilder sb = new StringBuilder(); + sb.append("xwhat: ").append(sendData.optString("xwhat")); + sb.append("\nxwho: ").append(sendData.optString("xwho")); + sb.append("\nxwhen: ").append(sendData.optString("xwhen")); + sb.append("\nappid: ").append(sendData.optString("appid")); + JSONObject xcontext = sendData.optJSONObject("xcontext"); + sb.append("\nxcontext: "); + Iterator keys = xcontext.keys(); + try { + while (keys.hasNext()) { + String key = keys.next(); + Object value = xcontext.get(key); + sb.append("\n ").append(key).append(": ").append(value); + } + } catch (JSONException e) { + e.printStackTrace(); + } + return sb.toString(); + } + } + + public void init() { + AgentProcess.getInstance().setEventObserver(this); + } + + private List mListData = new ArrayList<>(); + + private TrackEventObserver() { + } + + public static TrackEventObserver getInstance() { + return sInstance; + } + + public synchronized List getData(String eventNameFilter) { + List listResult = new ArrayList<>(); + if (TextUtils.isEmpty(eventNameFilter)) { + listResult.addAll(mListData); + } else { + String[] names = eventNameFilter.split(" "); + for (int i = 0; i < mListData.size(); i++) { + EventData data = mListData.get(i); + for (int j = 0; j < names.length; j++) { + if (data.eventName.equals(names[j])) { + listResult.add(data); + break; + } + } + } + } + return listResult; + } + + private SimpleDateFormat mFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); + + private List mObseverEventName = new ArrayList<>(); + private AgentProcess.IEventObserver mObserver; + + public synchronized void setObserver(String eventName, AgentProcess.IEventObserver observer) { + mObseverEventName.clear(); + if (!TextUtils.isEmpty(eventName)) { + mObseverEventName.addAll(Arrays.asList(eventName.split(" "))); + } + mObserver = observer; + } + + @Override + public synchronized void onEvent(String eventName, JSONObject sendData) { + try { + long xwhen = sendData.getLong("xwhen"); + String xwhat = sendData.getString("xwhat"); + JSONObject xcontext = sendData.getJSONObject("xcontext"); + String url = xcontext.optString("$url", null); + if (!TextUtils.isEmpty(url) && (url.equals(FragmentEvent.class.getName()) +// || url.equals(FragmentUser.class.getName()) +// || url.equals(FragmentProperty.class.getName()) + || url.equals(InfoDialog.class.getName()))) { + return; + } + String elementType = xcontext.optString("$element_type", null); + if (!TextUtils.isEmpty(elementType) && elementType.equals("MenuItem")) { + return; + } + Date d1 = new Date(xwhen); + String time = mFormat.format(d1); + mListData.add(0, new EventData(eventName, time, sendData)); + if (mObserver != null && (mObseverEventName.isEmpty() || mObseverEventName.contains(xwhat))) { + mObserver.onEvent(eventName, sendData); + } + } catch (Exception e) { + e.printStackTrace(); + } + } +} diff --git a/ans-demo/apidemo/src/main/java/com/analysys/demo/UserInfoActivity.java b/ans-demo/apidemo/src/main/java/com/analysys/demo/UserInfoActivity.java new file mode 100644 index 0000000..c570dd8 --- /dev/null +++ b/ans-demo/apidemo/src/main/java/com/analysys/demo/UserInfoActivity.java @@ -0,0 +1,175 @@ +package com.analysys.demo; + +import android.os.Bundle; +import android.text.TextUtils; +import android.view.View; +import android.view.ViewGroup; +import android.widget.AdapterView; +import android.widget.ArrayAdapter; +import android.widget.ListView; +import android.widget.Toast; + +import com.analysys.AnalysysAgent; +import com.analysys.apidemo.R; +import com.analysys.utils.Constants; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +public class UserInfoActivity extends BaseActivity { + + class UserAction { + String name; + String eventName; + Runnable runnable; + String msg; + + UserAction(String name, String eventName, String msg, Runnable runnable) { + this.name = name; + this.eventName = eventName; + this.msg = msg; + this.runnable = runnable; + } + + public void doAction() { + if (runnable != null) { + runnable.run(); + } + if (!TextUtils.isEmpty(msg)) { + Toast.makeText(UserInfoActivity.this, msg, Toast.LENGTH_LONG).show(); + } + } + } + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_user_info); + ListView listView = findViewById(R.id.list_view); + List list = new ArrayList<>(); + list.add(new UserAction("设置匿名ID", Constants.PROFILE_SET, "匿名ID设置为 WechatID_1", new Runnable() { + @Override + public void run() { + //淘宝店铺使用该功能时,只关注访客用户或店铺会员,不关注设备信息 + AnalysysAgent.identify(UserInfoActivity.this, "WechatID_1"); + } + })); + list.add(new UserAction("匿名ID与用户关联", Constants.PROFILE_SET, "关联ID设置为 18688886666", new Runnable() { + @Override + public void run() { + AnalysysAgent.alias(UserInfoActivity.this, "18688886666"); + } + })); + list.add(new UserAction("获取匿名ID", null, null, new Runnable() { + @Override + public void run() { + Toast.makeText(UserInfoActivity.this, "匿名ID为 " + AnalysysAgent.getDistinctId(UserInfoActivity.this), Toast.LENGTH_LONG).show(); + } + })); + list.add(new UserAction("设置单个用户属性", Constants.PROFILE_SET, "用户属性[Email = yonghu@163.com]", new Runnable() { + @Override + public void run() { + //要统计分析使用邮箱登录的用户 + AnalysysAgent.profileSet(UserInfoActivity.this, "Email", "yonghu@163.com"); + } + })); + list.add(new UserAction("设置多个用户属性", Constants.PROFILE_SET, "用户属性[Email = yonghu@163.com, WeChatID = weixinhao]", new Runnable() { + @Override + public void run() { + //要统计用户的登录方式邮箱登录,微信登录 + Map profileSet = new HashMap<>(); + profileSet.put("Email", "yonghu@163.com"); + profileSet.put("WeChatID", "weixinhao"); + AnalysysAgent.profileSet(UserInfoActivity.this, profileSet); + } + })); + list.add(new UserAction("设置单个用户固有属性", Constants.PROFILE_SET_ONCE, "固有属性[activationTime = 1521594686781]", new Runnable() { + @Override + public void run() { + //要统计用户的激活时间 + AnalysysAgent.profileSetOnce(UserInfoActivity.this, "activationTime", "1521594686781"); + } + })); + list.add(new UserAction("设置多个用户固有属性", Constants.PROFILE_SET_ONCE, "固有属性[activationTime = 1521594686781, loginTime = 1521594726781]", new Runnable() { + @Override + public void run() { + //要统计激活时间和首次登陆时间 + Map setOnceProfile = new HashMap<>(); + setOnceProfile.put("activationTime", "1521594686781"); + setOnceProfile.put("loginTime", "1521594726781"); + AnalysysAgent.profileSetOnce(UserInfoActivity.this, setOnceProfile); + } + })); + list.add(new UserAction("设置单个用户属性相对变化值", Constants.PROFILE_INCREMENT, "用户属性 age 加1", new Runnable() { + @Override + public void run() { + //用户年龄增加了一岁 + AnalysysAgent.profileIncrement(UserInfoActivity.this, "age", 1); + } + })); + list.add(new UserAction("设置多个用户属性相对变化值", Constants.PROFILE_INCREMENT, "用户属性 age 加1,integral 加200", new Runnable() { + @Override + public void run() { + //用户年龄增加了一岁积分增加了200 + Map incrementProfile = new HashMap<>(); + incrementProfile.put("age", 1); + incrementProfile.put("integral", 200); + AnalysysAgent.profileIncrement(UserInfoActivity.this, incrementProfile); + } + })); + list.add(new UserAction("增加单个列表类型的属性", Constants.PROFILE_APPEND, "列表属性 hobby 加入 Music", new Runnable() { + @Override + public void run() { + //添加用户爱好 + AnalysysAgent.profileAppend(UserInfoActivity.this, "hobby", "Music"); + } + })); + list.add(new UserAction("增加多个列表类型的属性", Constants.PROFILE_APPEND, "列表属性 hobby 加入 PlayBasketball, Music", new Runnable() { + @Override + public void run() { + List list = new ArrayList<>(); + list.add("PlayBasketball"); + list.add("Music"); + AnalysysAgent.profileAppend(UserInfoActivity.this, "hobby", list); + } + })); + list.add(new UserAction("删除用户单个属性值", Constants.PROFILE_UNSET, "删除用户属性 age", new Runnable() { + @Override + public void run() { + // 删除用户年龄属性 + AnalysysAgent.profileUnset(UserInfoActivity.this, "age"); + } + })); + list.add(new UserAction("删除用户所有属性值", Constants.PROFILE_DELETE, "删除成功", new Runnable() { + @Override + public void run() { + AnalysysAgent.profileDelete(UserInfoActivity.this); + } + })); + + List listStr = new ArrayList<>(); + for (int i = 0; i < list.size(); i++) { + listStr.add(list.get(i).name); + } + listView.setAdapter(new ArrayAdapter(this, + android.R.layout.simple_list_item_1, + android.R.id.text1, + listStr) { + @Override + public View getView(int position, View convertView, ViewGroup parent) { + View view = super.getView(position, convertView, parent); + float scale = getResources().getDisplayMetrics().density; + view.getLayoutParams().height = (int) (40 * scale + 0.5f); + return view; + } + }); + listView.setOnItemClickListener(new AdapterView.OnItemClickListener() { + @Override + public void onItemClick(AdapterView parent, View view, int position, long id) { + list.get(position).doAction(); + } + }); + } +} diff --git a/ans-demo/apidemo/src/main/java/com/analysys/demo/UserSettingActivity.java b/ans-demo/apidemo/src/main/java/com/analysys/demo/UserSettingActivity.java deleted file mode 100644 index 94fc067..0000000 --- a/ans-demo/apidemo/src/main/java/com/analysys/demo/UserSettingActivity.java +++ /dev/null @@ -1,84 +0,0 @@ -package com.analysys.demo; - -import android.content.Context; -import android.os.Bundle; -import android.util.Log; -import android.view.View; - -import com.analysys.AnalysysAgent; -import com.analysys.apidemo.R; - -import java.util.ArrayList; -import java.util.List; -import java.util.Map; - -import androidx.appcompat.app.AppCompatActivity; - -/** - * @Copyright © 2019 EGuan Inc. All rights reserved. - * @Description: TODO - * @Version: 1.0 - * @Create: 2019-07-01 00:48 - * @Author: Wang-X-C - */ -public class UserSettingActivity extends AppCompatActivity { - Context mContext = null; - String tag = "analysys"; - - @Override - protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - setContentView(R.layout.activity_user_setting); - mContext = this.getApplicationContext(); - } - - public void onClick(View view) { - int viewId = view.getId(); - if (viewId == R.id.alias) {//设置aliasId, - AnalysysAgent.alias(mContext, "s4af4a7g90af5ad"); - } else if (viewId == R.id.identify) {//淘宝店铺使用该功能时,只关注访客用户或店铺会员,不关注设备信息 - AnalysysAgent.identify(mContext, "identifyId"); - Log.i(tag, "不产生事件"); - } else if (viewId == R.id.reset) {//清除本地现有的用户属性,包括通用属性 - AnalysysAgent.reset(mContext); - Log.i(tag, "不产生事件"); - } else if (viewId == R.id.getDistinctId) { - String id = AnalysysAgent.getDistinctId(mContext); - Log.i(tag, " Distinct id :" + id); - } else if (viewId == R.id.automaticCollection) {// 设置不做自动采集 - AnalysysAgent.setAutomaticCollection(mContext, false); - Log.i(tag, "不产生事件"); - } else if (viewId == R.id.moreIgnoredAutomaticCollection) {// 设置忽略页面 - List arrayList = new ArrayList<>(); - arrayList.add("com.analysys.compatibilitydemo.activity.MainActivity"); - AnalysysAgent.setIgnoredAutomaticCollectionActivities(mContext, arrayList); - Log.i(tag, "不产生事件"); - } else if (viewId == R.id.getIgnoredAutomaticCollection) { - List activityNames = - AnalysysAgent.getIgnoredAutomaticCollection(mContext); - if (activityNames != null) { - for (String name : activityNames) { - Log.i(tag, "忽略自动采集的页面名称:" + name); - } - } - Log.i(tag, "不产生事件"); - } else if (viewId == R.id.setURL) {//设置URL数据上传地址 - AnalysysAgent.setUploadURL(mContext, ""); - Log.i(tag, "不产生事件"); - } else if (viewId == R.id.setIntervalTime) {//上传的时间间隔定为20秒上传一次 - AnalysysAgent.setIntervalTime(mContext, 20); - Log.i(tag, "不产生事件"); - } else if (viewId == R.id.setEventCount) {//设置上传条数 - AnalysysAgent.setMaxEventSize(mContext, 20); - Log.i(tag, "不产生事件"); - } else if (viewId == R.id.flush) {//需要立刻将所有数据上传 - AnalysysAgent.flush(mContext); - } else if (viewId == R.id.setMaxCacheSize) {//设置本地数据缓存上限值为2000条 - AnalysysAgent.setMaxCacheSize(mContext, 2000); - Log.i(tag, "不产生事件"); - } else if (viewId == R.id.getPresetProperties) {//设置本地数据缓存上限值为2000条 - Map properties = AnalysysAgent.getPresetProperties(mContext); - Log.i(tag, "预置属性:\n" + properties); - } - } -} diff --git a/ans-demo/apidemo/src/main/java/com/analysys/demo/VisualActivity.java b/ans-demo/apidemo/src/main/java/com/analysys/demo/VisualActivity.java new file mode 100644 index 0000000..5c6570c --- /dev/null +++ b/ans-demo/apidemo/src/main/java/com/analysys/demo/VisualActivity.java @@ -0,0 +1,66 @@ +package com.analysys.demo; + +import android.content.Intent; +import android.os.Bundle; +import android.view.View; +import android.widget.AdapterView; +import android.widget.ArrayAdapter; +import android.widget.ListView; + +import com.analysys.apidemo.R; + +import java.util.ArrayList; +import java.util.List; + +public class VisualActivity extends BaseActivity { + + class ClickAction { + Class activityClz; + String itemName; + + ClickAction(Class clz, String name) { + activityClz = clz; + itemName = name; + } + + void doAction() { + Intent intent = new Intent(VisualActivity.this, activityClz); + intent.putExtra(BaseActivity.EXTRA_ACTIVITY_TITLE, itemName); + startActivity(intent); + } + } + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_visual); + ListView listView = findViewById(R.id.list_view); + List list = new ArrayList<>(); + list.add(new ClickAction(VisualBaseControlActivity.class, "基础控件")); + list.add(new ClickAction(VisualPositionBindActivity.class, "按位置定位")); + list.add(new ClickAction(VisualTextBindActivity.class, "按文字内容定位")); + list.add(new ClickAction(VisualClassBindActivity.class, "按类型定位")); + list.add(new ClickAction(VisualCrossPagesActivity.class, "跨页面定位")); + list.add(new ClickAction(VisualRelatedActivity.class, "上报关联属性")); + list.add(new ClickAction(VisualSibListViewActivity.class, "同级-ListView")); + list.add(new ClickAction(VisualSibRecyclerViewActivity.class, "同级-RecyclerView")); + list.add(new ClickAction(VisualSibViewPagerActivity.class, "同级-ViewPager")); + list.add(new ClickAction(VisualSibGridViewActivity.class, "同级-GridView")); + list.add(new ClickAction(VisualHybridActivity.class, "Hybrid可视化")); + list.add(new ClickAction(Process1Activity.class, "多进程支持")); + List listStr = new ArrayList<>(); + for (int i = 0; i < list.size(); i++) { + listStr.add(list.get(i).itemName); + } + listView.setAdapter(new ArrayAdapter<>(this, + android.R.layout.simple_list_item_1, + android.R.id.text1, + listStr)); + listView.setOnItemClickListener(new AdapterView.OnItemClickListener() { + @Override + public void onItemClick(AdapterView parent, View view, int position, long id) { + list.get(position).doAction(); + } + }); + } +} diff --git a/ans-demo/apidemo/src/main/java/com/analysys/demo/VisualBaseControlActivity.java b/ans-demo/apidemo/src/main/java/com/analysys/demo/VisualBaseControlActivity.java new file mode 100644 index 0000000..bec5072 --- /dev/null +++ b/ans-demo/apidemo/src/main/java/com/analysys/demo/VisualBaseControlActivity.java @@ -0,0 +1,64 @@ +package com.analysys.demo; + +import android.app.Dialog; +import android.os.Bundle; +import android.view.View; +import android.widget.AdapterView; +import android.widget.ArrayAdapter; +import android.widget.ListView; +import android.widget.PopupWindow; + +import com.analysys.apidemo.R; + +import java.util.ArrayList; +import java.util.List; + +public class VisualBaseControlActivity extends BaseActivity { + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_visual_base_control); + } + + public void onClick(View view) { + if (view.getId() == R.id.btn_dialog) { + showDialog(); + } else if (view.getId() == R.id.btn_pop) { + showPop(view); + } + } + + private void showPop(View view) { + ListView listView = new ListView(this); + listView.setBackgroundColor(0xffdddddd); + PopupWindow popupWindow = new PopupWindow(listView, 400, 600); + List listData = new ArrayList<>(); + listData.add("row 0"); + listData.add("row 1"); + listData.add("row 2"); + listData.add("row 3"); + ArrayAdapter adapter = new ArrayAdapter(this, android.R.layout.simple_list_item_1, listData); + listView.setAdapter(adapter); + listView.setOnItemClickListener(new AdapterView.OnItemClickListener() { + @Override + public void onItemClick(AdapterView parent, View view, int position, long id) { + popupWindow.dismiss(); + } + }); + popupWindow.setFocusable(true); + popupWindow.showAsDropDown(view); + } + + private void showDialog() { + Dialog dialog = new Dialog(this); + dialog.setContentView(R.layout.dialog_visual); + dialog.findViewById(R.id.btn_ok).setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + dialog.dismiss(); + } + }); + dialog.show(); + } +} diff --git a/ans-demo/apidemo/src/main/java/com/analysys/demo/VisualClassBindActivity.java b/ans-demo/apidemo/src/main/java/com/analysys/demo/VisualClassBindActivity.java new file mode 100644 index 0000000..d439394 --- /dev/null +++ b/ans-demo/apidemo/src/main/java/com/analysys/demo/VisualClassBindActivity.java @@ -0,0 +1,37 @@ +package com.analysys.demo; + +import android.content.Context; +import android.os.Bundle; +import android.view.View; +import android.view.ViewGroup; +import android.widget.Button; + +import com.analysys.apidemo.R; + +import java.lang.reflect.Constructor; + +public class VisualClassBindActivity extends BaseActivity { + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_visual_class_bind); + } + + private int buttonIdx; + + public void onClick(View view) { + try { + ViewGroup vg = (ViewGroup) view.getParent(); + Constructor constructor = view.getClass().getDeclaredConstructor(Context.class); + Button button = (Button) constructor.newInstance(this); + button.setText("Button " + (buttonIdx++)); + ViewGroup.MarginLayoutParams lp = new ViewGroup.MarginLayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT); + lp.topMargin = (int) (20 * getResources().getDisplayMetrics().density + 0.5f); + button.setLayoutParams(lp); + vg.addView(button); + } catch (Exception e) { + e.printStackTrace(); + } + } +} diff --git a/ans-demo/apidemo/src/main/java/com/analysys/demo/VisualCrossPagesActivity.java b/ans-demo/apidemo/src/main/java/com/analysys/demo/VisualCrossPagesActivity.java new file mode 100644 index 0000000..c4a0faa --- /dev/null +++ b/ans-demo/apidemo/src/main/java/com/analysys/demo/VisualCrossPagesActivity.java @@ -0,0 +1,59 @@ +package com.analysys.demo; + +import android.app.Dialog; +import android.content.Intent; +import android.os.Bundle; +import android.view.LayoutInflater; +import android.view.View; +import android.widget.PopupWindow; + +import com.analysys.apidemo.R; + +public class VisualCrossPagesActivity extends BaseActivity { + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_visual_cross_pages); + } + + public void onClick(View view) { + int id = view.getId(); + if (id == R.id.btn_open_page) { + Intent intent = new Intent(this, VisualTextBindActivity.class); + intent.putExtra(BaseActivity.EXTRA_ACTIVITY_TITLE, "按文字内容定位"); + startActivity(intent); + } else if (id == R.id.btn_open_dialog) { + showDialog(); + } else if (id == R.id.btn_open_pop) { + showPop(view); + } + } + + private void showPop(View view) { + View root = LayoutInflater.from(this).inflate(R.layout.pop_layout, null); + PopupWindow popupWindow = new PopupWindow(root, 400, 600); + popupWindow.setFocusable(true); + popupWindow.showAsDropDown(view); + View.OnClickListener listener = new View.OnClickListener() { + @Override + public void onClick(View v) { + popupWindow.dismiss(); + } + }; + root.findViewById(R.id.btn_ok).setOnClickListener(listener); + root.findViewById(R.id.btn_cancel).setOnClickListener(listener); + } + + private void showDialog() { + Dialog dialog = new Dialog(this); + dialog.setContentView(R.layout.dialog_visual); + dialog.findViewById(R.id.btn_ok).setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + dialog.dismiss(); + } + }); + dialog.show(); + } +} diff --git a/ans-demo/apidemo/src/main/java/com/analysys/demo/VisualHybridActivity.java b/ans-demo/apidemo/src/main/java/com/analysys/demo/VisualHybridActivity.java new file mode 100644 index 0000000..d051dde --- /dev/null +++ b/ans-demo/apidemo/src/main/java/com/analysys/demo/VisualHybridActivity.java @@ -0,0 +1,11 @@ +package com.analysys.demo; + +import com.analysys.apidemo.R; + +public class VisualHybridActivity extends HybridActivity { + + @Override + protected int getContentLayoutId() { + return R.layout.activity_visual_hybrid; + } +} diff --git a/ans-demo/apidemo/src/main/java/com/analysys/demo/VisualPositionBindActivity.java b/ans-demo/apidemo/src/main/java/com/analysys/demo/VisualPositionBindActivity.java new file mode 100644 index 0000000..4f0eec4 --- /dev/null +++ b/ans-demo/apidemo/src/main/java/com/analysys/demo/VisualPositionBindActivity.java @@ -0,0 +1,27 @@ +package com.analysys.demo; + +import android.os.Bundle; +import android.view.View; +import android.view.ViewGroup; + +import com.analysys.apidemo.R; + +public class VisualPositionBindActivity extends BaseActivity { + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_visual_position_bind); + } + + public void onClick(View view) { + ViewGroup ll1 = findViewById(R.id.ll1); + ViewGroup ll2 = findViewById(R.id.ll2); + View view1 = ll1.getChildAt(0); + View view2 = ll2.getChildAt(0); + ll1.removeView(view1); + ll2.removeView(view2); + ll1.addView(view2); + ll2.addView(view1); + } +} diff --git a/ans-demo/apidemo/src/main/java/com/analysys/demo/VisualRelatedActivity.java b/ans-demo/apidemo/src/main/java/com/analysys/demo/VisualRelatedActivity.java new file mode 100644 index 0000000..d299e9d --- /dev/null +++ b/ans-demo/apidemo/src/main/java/com/analysys/demo/VisualRelatedActivity.java @@ -0,0 +1,14 @@ +package com.analysys.demo; + +import android.os.Bundle; + +import com.analysys.apidemo.R; + +public class VisualRelatedActivity extends BaseActivity { + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_visual_related); + } +} diff --git a/ans-demo/apidemo/src/main/java/com/analysys/demo/VisualSibGridViewActivity.java b/ans-demo/apidemo/src/main/java/com/analysys/demo/VisualSibGridViewActivity.java new file mode 100644 index 0000000..0816cdb --- /dev/null +++ b/ans-demo/apidemo/src/main/java/com/analysys/demo/VisualSibGridViewActivity.java @@ -0,0 +1,49 @@ +package com.analysys.demo; + +import android.os.Bundle; +import android.view.View; +import android.widget.AdapterView; +import android.widget.GridView; +import android.widget.SimpleAdapter; + +import com.analysys.apidemo.R; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +public class VisualSibGridViewActivity extends BaseActivity { + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_visual_sib_grid_view); + GridView gridView = findViewById(R.id.grid_view); + List> dataList = new ArrayList<>(); + int[] icon = {R.drawable.icon, R.drawable.icon, + R.drawable.icon, R.drawable.icon, R.drawable.icon, + R.drawable.icon, R.drawable.icon, R.drawable.icon, + R.drawable.icon, R.drawable.icon, R.drawable.icon, + R.drawable.icon}; + String[] iconName = {"通讯录", "日历", "照相机", "时钟", "游戏", "短信", "铃声", + "设置", "语音", "天气", "浏览器", "视频"}; + for (int i = 0; i < icon.length; i++) { + Map map = new HashMap<>(); + map.put("image", icon[i]); + map.put("text", iconName[i]); + dataList.add(map); + } + + String[] from = {"image", "text"}; + int[] to = {R.id.image, R.id.text}; + SimpleAdapter adapter = new SimpleAdapter(this, dataList, R.layout.grid_view_item, from, to); + //配置适配器 + gridView.setAdapter(adapter); + gridView.setOnItemClickListener(new AdapterView.OnItemClickListener() { + @Override + public void onItemClick(AdapterView adapterView, View view, int i, long l) { + + } + }); + } +} diff --git a/ans-demo/apidemo/src/main/java/com/analysys/demo/VisualSibListViewActivity.java b/ans-demo/apidemo/src/main/java/com/analysys/demo/VisualSibListViewActivity.java new file mode 100644 index 0000000..50b916a --- /dev/null +++ b/ans-demo/apidemo/src/main/java/com/analysys/demo/VisualSibListViewActivity.java @@ -0,0 +1,115 @@ +package com.analysys.demo; + +import android.content.Context; +import android.os.Bundle; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.AdapterView; +import android.widget.BaseAdapter; +import android.widget.Button; +import android.widget.ImageView; +import android.widget.ListView; +import android.widget.TextView; + +import com.analysys.apidemo.R; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +public class VisualSibListViewActivity extends BaseActivity { + private List> mData; + + @Override + public void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + mData = getData(); + setContentView(R.layout.activity_visual_sib_list_view); + ListView listView = findViewById(R.id.list_view); + VisualSibListViewActivity.MyAdapter adapter = new VisualSibListViewActivity.MyAdapter(this); + listView.setAdapter(adapter); + listView.setOnItemClickListener(new AdapterView.OnItemClickListener() { + @Override + public void onItemClick(AdapterView adapterView, View view, int i, long l) { + + } + }); + } + + private List> getData() { + List> list = new ArrayList<>(); + + for (int i = 0; i < 100; i++) { + Map map = new HashMap<>(); + map.put("btn", "按钮 " + i); + map.put("title", "title " + i); + map.put("info", "detail " + i); + map.put("img", R.drawable.beauty); + list.add(map); + } + + return list; + } + + public final class ViewHolder { + public ImageView img; + public TextView title; + public TextView info; + public Button viewBtn; + } + + public class MyAdapter extends BaseAdapter { + + private LayoutInflater mInflater; + + public MyAdapter(Context context) { + this.mInflater = LayoutInflater.from(context); + } + + @Override + public int getCount() { + return mData.size(); + } + + @Override + public Object getItem(int arg0) { + return null; + } + + @Override + public long getItemId(int arg0) { + return 0; + } + + @Override + public int getItemViewType(int position) { + return position % 2; + } + + @Override + public View getView(int position, View convertView, ViewGroup parent) { + VisualSibListViewActivity.ViewHolder holder; + if (convertView == null) { + holder = new VisualSibListViewActivity.ViewHolder(); + convertView = mInflater.inflate(R.layout.list_row_visual, null); + holder.img = convertView.findViewById(R.id.img); + holder.title = convertView.findViewById(R.id.title); + holder.info = convertView.findViewById(R.id.info); + holder.viewBtn = convertView.findViewById(R.id.view_btn); + convertView.setTag(holder); + } else { + holder = (VisualSibListViewActivity.ViewHolder) convertView.getTag(); + } + + holder.viewBtn.setText((String) mData.get(position).get("btn")); + holder.img.setBackgroundResource((Integer) mData.get(position).get("img")); + holder.title.setText((String) mData.get(position).get("title")); + holder.info.setText((String) mData.get(position).get("info")); + + return convertView; + } + + } +} diff --git a/ans-demo/apidemo/src/main/java/com/analysys/demo/VisualSibRecyclerViewActivity.java b/ans-demo/apidemo/src/main/java/com/analysys/demo/VisualSibRecyclerViewActivity.java new file mode 100644 index 0000000..00dd619 --- /dev/null +++ b/ans-demo/apidemo/src/main/java/com/analysys/demo/VisualSibRecyclerViewActivity.java @@ -0,0 +1,193 @@ +package com.analysys.demo; + +import android.content.Context; +import android.content.res.TypedArray; +import android.graphics.Canvas; +import android.graphics.Rect; +import android.graphics.drawable.Drawable; +import android.os.Bundle; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.Button; +import android.widget.ImageView; +import android.widget.TextView; + +import androidx.recyclerview.widget.LinearLayoutManager; +import androidx.recyclerview.widget.RecyclerView; + +import com.analysys.apidemo.R; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +public class VisualSibRecyclerViewActivity extends BaseActivity { + + private RecyclerView mRecyclerView; + private List> mData; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_visual_sib_recycler_view); + mData = getData(); + mRecyclerView = findViewById(R.id.recycler_view); + mRecyclerView.addItemDecoration(new LinearItemDecoration(VisualSibRecyclerViewActivity.this, LinearLayoutManager.VERTICAL)); + initRecyclerView(); + } + + private List> getData() { + List> list = new ArrayList<>(); + + for (int i = 0; i < 100; i++) { + Map map = new HashMap<>(); + map.put("btn", "按钮 " + i); + map.put("title", "title " + i); + map.put("info", "detail " + i); + map.put("img", R.drawable.beauty); + list.add(map); + } + + return list; + } + + /** + * 初始化RecyclerView + */ + private void initRecyclerView() { + // 定义一个线性布局管理器 + LinearLayoutManager manager = new LinearLayoutManager(this); + // 设置布局管理器 + mRecyclerView.setLayoutManager(manager); + // 设置adapter + DemoAdapter adapter = new DemoAdapter(VisualSibRecyclerViewActivity.this); + mRecyclerView.setAdapter(adapter); + } + + class DemoAdapter extends RecyclerView.Adapter { + + private Context mContext; + + public DemoAdapter(Context context) { + this.mContext = context; + } + + @Override + public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { + View v = LayoutInflater.from(VisualSibRecyclerViewActivity.this).inflate(R.layout.list_row_visual, parent, false); + //返回MyViewHolder的对象 + return new DemoViewHolder(v); + } + + @Override + public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) { + DemoViewHolder demoViewHolder = (DemoViewHolder) holder; + demoViewHolder.viewBtn.setText((String) mData.get(position).get("btn")); + demoViewHolder.img.setBackgroundResource((Integer) mData.get(position).get("img")); + demoViewHolder.title.setText((String) mData.get(position).get("title")); + demoViewHolder.info.setText((String) mData.get(position).get("info")); + } + + @Override + public int getItemCount() { + return mData.size(); + } + + @Override + public int getItemViewType(int position) { + return position % 2; + } + + private class DemoViewHolder extends RecyclerView.ViewHolder { + + public ImageView img; + public TextView title; + public TextView info; + public Button viewBtn; + + public DemoViewHolder(View itemView) { + super(itemView); + itemView.setClickable(true); + img = itemView.findViewById(R.id.img); + title = itemView.findViewById(R.id.title); + info = itemView.findViewById(R.id.info); + viewBtn = itemView.findViewById(R.id.view_btn); + } + } + } + + static class LinearItemDecoration extends RecyclerView.ItemDecoration { + + private static final int[] ATTRS = new int[]{android.R.attr.listDivider}; + + public static final int ORIENTATION_HORIZONTAL = LinearLayoutManager.HORIZONTAL; + public static final int ORIENTATION_VERTICAL = LinearLayoutManager.VERTICAL; + + private Drawable mDrawable; + private int mOrientation; + + public LinearItemDecoration(Context context, int orientation) { + final TypedArray typedArray = context.obtainStyledAttributes(ATTRS); + mDrawable = typedArray.getDrawable(0); + typedArray.recycle(); + setOrientation(orientation); + } + + public void setOrientation(int orientation) { + if (orientation != ORIENTATION_HORIZONTAL && orientation != ORIENTATION_VERTICAL) { + this.mOrientation = ORIENTATION_VERTICAL; + } + this.mOrientation = orientation; + } + + @Override + public void onDraw(Canvas c, RecyclerView parent, RecyclerView.State state) { + if (mOrientation == ORIENTATION_HORIZONTAL) { + drawHorizontal(c, parent); + } else { + drawVertical(c, parent); + } + } + + private void drawHorizontal(Canvas c, RecyclerView parent) { + final int top = parent.getPaddingTop(); + final int bottom = parent.getHeight() - parent.getPaddingBottom(); + final int childCount = parent.getChildCount(); + + for (int i = 0; i < childCount; i++) { + final View child = parent.getChildAt(i); + final RecyclerView.LayoutParams layoutManager = (RecyclerView.LayoutParams) child.getLayoutParams(); + final int left = child.getRight() + layoutManager.rightMargin; + final int right = left + mDrawable.getIntrinsicHeight(); + mDrawable.setBounds(left, top, right, bottom); + mDrawable.draw(c); + } + } + + private void drawVertical(Canvas c, RecyclerView parent) { + final int left = parent.getPaddingLeft(); + final int right = parent.getWidth() - parent.getPaddingRight(); + final int childCount = parent.getChildCount(); + + for (int i = 0; i < childCount; i++) { + final View child = parent.getChildAt(i); + final RecyclerView.LayoutParams layoutParams = (RecyclerView.LayoutParams) child.getLayoutParams(); + final int top = child.getBottom() + layoutParams.bottomMargin; + final int bottom = top + mDrawable.getIntrinsicHeight(); + mDrawable.setBounds(left, top, right, bottom); + mDrawable.draw(c); + } + } + + @Override + public void getItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state) { + if (mOrientation == ORIENTATION_HORIZONTAL) { + outRect.set(0, 0, mDrawable.getIntrinsicWidth(), 0); + } else { + outRect.set(0, 0, 0, mDrawable.getIntrinsicHeight()); + } + } + } +} diff --git a/ans-demo/apidemo/src/main/java/com/analysys/demo/VisualSibViewPagerActivity.java b/ans-demo/apidemo/src/main/java/com/analysys/demo/VisualSibViewPagerActivity.java new file mode 100644 index 0000000..382e178 --- /dev/null +++ b/ans-demo/apidemo/src/main/java/com/analysys/demo/VisualSibViewPagerActivity.java @@ -0,0 +1,63 @@ +package com.analysys.demo; + +import android.os.Bundle; +import android.view.View; +import android.view.ViewGroup; +import android.widget.Button; + +import androidx.viewpager.widget.PagerAdapter; +import androidx.viewpager.widget.ViewPager; + +import com.analysys.apidemo.R; + +import java.util.HashMap; +import java.util.Map; + +public class VisualSibViewPagerActivity extends BaseActivity { + + class MyPagerAdapter extends PagerAdapter { + + Map views = new HashMap<>(); + + private final int[] BG_COLOR = {0xffaabbcc, 0xffbbaacc, 0xffccaabb, 0xffaaccbb, 0xffbbccaa}; + + @Override + public int getCount() { + return BG_COLOR.length; + } + + @Override + public boolean isViewFromObject(View view, Object object) { + return view == object; + } + + @Override + public Object instantiateItem(ViewGroup container, int position) { + View view = views.get(position); + if (view == null) { + view = getLayoutInflater().inflate(R.layout.view_pager_layout, null, false); + view.setBackgroundColor(BG_COLOR[position]); + Button btn = view.findViewById(R.id.btn_vp); + btn.setText("ViewPager Button " + position); + views.put(position, view); + } + container.addView(view); + return view; + } + + @Override + public void destroyItem(ViewGroup container, int position, Object object) { + View view = views.get(position); + views.remove(position); + container.removeView(view); + } + } + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_visual_sib_view_pager); + ViewPager viewPager = findViewById(R.id.view_pager); + viewPager.setAdapter(new MyPagerAdapter()); + } +} diff --git a/ans-demo/apidemo/src/main/java/com/analysys/demo/VisualTextBindActivity.java b/ans-demo/apidemo/src/main/java/com/analysys/demo/VisualTextBindActivity.java new file mode 100644 index 0000000..9f43e4c --- /dev/null +++ b/ans-demo/apidemo/src/main/java/com/analysys/demo/VisualTextBindActivity.java @@ -0,0 +1,14 @@ +package com.analysys.demo; + +import android.os.Bundle; + +import com.analysys.apidemo.R; + +public class VisualTextBindActivity extends BaseActivity { + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_visual_text_bind); + } +} diff --git a/ans-demo/apidemo/src/main/java/com/analysys/demo/allgroTest/AllgroMainActivity.java b/ans-demo/apidemo/src/main/java/com/analysys/demo/allgroTest/AllgroMainActivity.java deleted file mode 100644 index 16e6b20..0000000 --- a/ans-demo/apidemo/src/main/java/com/analysys/demo/allgroTest/AllgroMainActivity.java +++ /dev/null @@ -1,122 +0,0 @@ -package com.analysys.demo.allgroTest; - -import android.app.AlertDialog; -import android.content.DialogInterface; -import android.os.Bundle; -import android.view.View; -import android.view.ViewGroup; -import android.widget.AdapterView; -import android.widget.ArrayAdapter; -import android.widget.Button; -import android.widget.LinearLayout; -import android.widget.ListView; -import android.widget.TabHost; -import android.widget.Toast; - -import com.analysys.allgro.annotations.AnalysysIgnoreTrackClick; -import com.analysys.demo.AnsApplication; - -import androidx.appcompat.app.AppCompatActivity; - -/** - * @author fengzeyuan - */ -@AnalysysIgnoreTrackClick -public class AllgroMainActivity extends AppCompatActivity { - - - @Override - protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - - LinearLayout layout = new LinearLayout(this); - layout.setOrientation(LinearLayout.VERTICAL); - layout.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT)); - - - - - testbtn(layout); - - setContentView(layout); - - } - - private void testbtn(LinearLayout layout) { - Button view = new Button(AnsApplication.getInstance()); - view.setText("按钮"); - - view.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - Toast.makeText(AnsApplication.getInstance(), "按钮点击", Toast.LENGTH_LONG).show(); - showDialog(); - } - }); - - layout.addView(view); - } - - private void testListView(LinearLayout layout) { - final String[] COUNTRIES = new String[]{"中国", "俄罗斯", "英国", "法国"}; - - ArrayAdapter arrayAdapter = new ArrayAdapter(this, android.R.layout.simple_list_item_1, COUNTRIES); - ListView listView = new ListView(AnsApplication.getInstance()); - listView.setAdapter(arrayAdapter); - listView.setOnItemClickListener(new AdapterView.OnItemClickListener() { - @Override - public void onItemClick(AdapterView parent, View view, int position, long id) { - - } - }); - layout.addView(listView); - } - - private void showDialog(){ - AlertDialog.Builder builder = new AlertDialog.Builder(AllgroMainActivity.this); -// builder.setMultiChoiceItems(null, null, (dialog, which, isChecked) -> { -// -// }); - - builder.setMultiChoiceItems(null, null, new DialogInterface.OnMultiChoiceClickListener() { - @Override - public void onClick(DialogInterface dialog, int which, boolean isChecked) { - - } - }); - -// builder.setPositiveButton("确定", (dialog, which) -> { -// }); - - builder.setPositiveButton("确定", new DialogInterface.OnClickListener() { - @Override - public void onClick(DialogInterface dialog, int which) { - } - }); - - builder.setNegativeButton("取消", new DialogInterface.OnClickListener() { - @Override - public void onClick(DialogInterface dialog, int which) { - - } - }); - builder.setTitle("Test"); - builder.setMessage("你要点击哪一个按钮"); - builder.show(); - } - - private void test() { - TabHost tabHost = new TabHost(AllgroMainActivity.this); - - tabHost.setOnTabChangedListener(tabId -> { - - }); - - tabHost.setOnTabChangedListener(new TabHost.OnTabChangeListener() { - @Override - public void onTabChanged(String tabId) { - - } - }); - } -} diff --git a/ans-demo/apidemo/src/main/java/com/analysys/demo/allgroTest/AllgroTestActivity.java b/ans-demo/apidemo/src/main/java/com/analysys/demo/allgroTest/AllgroTestActivity.java deleted file mode 100644 index 9e57bff..0000000 --- a/ans-demo/apidemo/src/main/java/com/analysys/demo/allgroTest/AllgroTestActivity.java +++ /dev/null @@ -1,114 +0,0 @@ -package com.analysys.demo.allgroTest; - -import android.os.Bundle; -import android.view.View; - -import com.analysys.apidemo.R; -import com.analysys.apidemo.databinding.ActivityTestAllgroBinding; -import com.analysys.demo.allgroTest.fragment.FragmentOne; -import com.analysys.demo.allgroTest.fragment.FragmentThree; -import com.analysys.demo.allgroTest.fragment.FragmentTwo; - -import androidx.appcompat.app.AppCompatActivity; -import androidx.databinding.DataBindingUtil; -import androidx.fragment.app.Fragment; -import androidx.fragment.app.FragmentPagerAdapter; -import androidx.viewpager.widget.ViewPager; - -/** - * @author fengzeyuan - */ -public class AllgroTestActivity extends AppCompatActivity implements ViewPager.OnPageChangeListener, View.OnClickListener { - - private ActivityTestAllgroBinding mDataBinding; - - - //参数列表需要获取一个Fragment管理器 getSupportFragmentManager - private FragmentPagerAdapter adapter = new FragmentPagerAdapter(getSupportFragmentManager()) { - //通过当前的position初始化Fragment。将Fragment填充到ViewPager中 - @Override - public Fragment getItem(int position) { - switch (position) { - case 0: - return new FragmentOne(); - case 1: - return new FragmentTwo(); - case 2: - return new FragmentThree(); - default: - throw new RuntimeException("数据异常");//最后这里需要抛一个运行时异常runException - } - } - - @Override - public int getCount() { - return 3;//这里返回的值是我们已知的Fragment数量 - } - }; - - @Override - protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - mDataBinding = DataBindingUtil.setContentView(this, R.layout.activity_test_allgro); - - mDataBinding.viewPager.setAdapter(adapter);//viewPager设置上适配器 - mDataBinding.viewPager.addOnPageChangeListener(this);//给ViewPager设置滑动监听,目的是为了显示Fragment - mDataBinding.btn1.setSelected(true);//首次进入默认选中第一个 - //下方btn设置监听,点击时切换页面 - mDataBinding.btn0.setOnClickListener(this); - mDataBinding.btn1.setOnClickListener(this); - mDataBinding.btn2.setOnClickListener(this); - mDataBinding.btn3.setOnClickListener(this); - - mDataBinding.setPageInfo(this); - } - - - /** - * 页面滑动时的监听 - */ - @Override - public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) { - - } - - /** - * 页面选择时的监听 - */ - @Override - public void onPageSelected(int position) { - //当选择Fragment时,同步设置下方按钮的旋转状态 - mDataBinding.btn1.setSelected(position == 0); - mDataBinding.btn2.setSelected(position == 1); - mDataBinding.btn3.setSelected(position == 2); - } - - /** - * 页面滑动状态变化时的监听 - */ - @Override - public void onPageScrollStateChanged(int state) { - - } - - /** - * 点击btn设置ViewPager当前视图 - */ - @Override - public void onClick(View view) { - int id = view.getId(); - if(id == R.id.btn1) { - //参数一是ViewPager的position,参数二为是否有滑动效果 - mDataBinding.viewPager.setCurrentItem(0, true); - } else if (id == R.id.btn2){ - mDataBinding.viewPager.setCurrentItem(1, true); - } else if (id == R.id.btn3) { - mDataBinding.viewPager.setCurrentItem(2, true); - } - } - - public void onViewClick(View view) { - mDataBinding.viewPager.setCurrentItem(2, true); - } - -} diff --git a/ans-demo/apidemo/src/main/java/com/analysys/demo/allgroTest/TabTestActivity.java b/ans-demo/apidemo/src/main/java/com/analysys/demo/allgroTest/TabTestActivity.java deleted file mode 100644 index a30ffbe..0000000 --- a/ans-demo/apidemo/src/main/java/com/analysys/demo/allgroTest/TabTestActivity.java +++ /dev/null @@ -1,70 +0,0 @@ -package com.analysys.demo.allgroTest; - -import android.app.TabActivity; -import android.os.Bundle; -import android.view.Menu; -import android.view.MenuItem; -import android.widget.TabHost; - -import com.analysys.apidemo.R; - - -public class TabTestActivity extends TabActivity {//继承的是TabActivity - /*TabHost的基本用法: - * 1,在界面布局中定义TabHost组件,并未改组件定义该选项卡的内容 - * 2,继承TabActivity - * 3,调用TabActivity的getTabHost()方法获取TabHost对象 - * 4,TabHost对象的addTab方法创建,添加选项卡 - * */ - - @Override - protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - setContentView(R.layout.activity_tabhost); - //获取该activity里面的TabHost组件 - TabHost tabhost=getTabHost(); - - //创建第一个tab页对象,TabSpec代表一个选项卡页面,要设置标题和内容,内容是布局文件中FrameLayout中 - TabHost.TabSpec tab1=tabhost.newTabSpec("tab1"); - tab1.setIndicator("已接电话");//设置标题 - tab1.setContent(R.id.tab01);//设置内容 - //添加tab页 - tabhost.addTab(tab1); - - //创建第二个tab页对象 - TabHost.TabSpec tab2=tabhost.newTabSpec("tab1"); - tab2.setIndicator("已拨电话");//设置标题 - tab2.setContent(R.id.tab02);//设置内容 - //添加tab页 - tabhost.addTab(tab2); - - //创建第三个tab页对象 - TabHost.TabSpec tab3=tabhost.newTabSpec("tab1"); - tab3.setIndicator("未接电话");//设置标题 - tab3.setContent(R.id.tab03);//设置内容 - //添加tab页 - tabhost.addTab(tab3); - - - } - - @Override - public boolean onCreateOptionsMenu(Menu menu) { - // Inflate the menu; this adds items to the action bar if it is present. - getMenuInflater().inflate(R.menu.menu_main, menu); - return true; - } - - @Override - public boolean onOptionsItemSelected(MenuItem item) { - // Handle action bar item clicks here. The action bar will - // automatically handle clicks on the Home/Up button, so long - // as you specify a parent activity in AndroidManifest.xml. - int id = item.getItemId(); - if (id == R.id.menu_more) { - return true; - } - return super.onOptionsItemSelected(item); - } -} - diff --git a/ans-demo/apidemo/src/main/java/com/analysys/demo/allgroTest/TestCase.java b/ans-demo/apidemo/src/main/java/com/analysys/demo/allgroTest/TestCase.java deleted file mode 100644 index 763972d..0000000 --- a/ans-demo/apidemo/src/main/java/com/analysys/demo/allgroTest/TestCase.java +++ /dev/null @@ -1,237 +0,0 @@ -package com.analysys.demo.allgroTest; - -import android.app.AlertDialog; -import android.content.DialogInterface; -import android.view.MenuItem; -import android.view.View; -import android.widget.AdapterView; -import android.widget.CompoundButton; -import android.widget.ExpandableListView; -import android.widget.ListView; -import android.widget.RadioGroup; -import android.widget.RatingBar; -import android.widget.SeekBar; -import android.widget.TabHost; - -import com.analysys.demo.AnsApplication; -import com.google.android.material.bottomnavigation.BottomNavigationView; -import com.google.android.material.tabs.TabLayout; - -import androidx.annotation.NonNull; -import androidx.appcompat.widget.SwitchCompat; -import androidx.appcompat.widget.Toolbar; - -/** - * Description: - * Author: fengzeyuan - * Date: 2019-12-03 13:46 - * Version: 1.0 - */ -public class TestCase { - // 所有Hook代码,请移步:../build/intermediates/transforms/Analysys_ASMTransform - - public void testTrackViewClick() { - View view = new View(AnsApplication.getInstance()); - view.setOnClickListener(v -> { - - }); - - view.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - - } - }); - - SwitchCompat buttonCompat = new SwitchCompat(AnsApplication.getInstance()); - buttonCompat.setOnCheckedChangeListener((buttonView, isChecked) -> { - - }); - - buttonCompat.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { - @Override - public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { - - } - }); - - RatingBar bar = new RatingBar(AnsApplication.getInstance()); - bar.setOnRatingBarChangeListener((ratingBar, rating, fromUser) -> { - - }); - - bar.setOnRatingBarChangeListener(new RatingBar.OnRatingBarChangeListener() { - @Override - public void onRatingChanged(RatingBar ratingBar, float rating, boolean fromUser) { - - } - }); - SeekBar seekBar = new SeekBar(AnsApplication.getInstance()); - seekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() { - @Override - public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) { - - } - - @Override - public void onStartTrackingTouch(SeekBar seekBar) { - - } - - @Override - public void onStopTrackingTouch(SeekBar seekBar) { - - } - }); - - RadioGroup radioGroup =new RadioGroup(AnsApplication.getInstance()); - radioGroup.setOnCheckedChangeListener((group, checkedId) -> { - - }); - - radioGroup.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() { - @Override - public void onCheckedChanged(RadioGroup group, int checkedId) { - - } - }); - } - - /** - * ListView 系列 - */ - public void testTrackListView() { - ListView listView = new ListView(AnsApplication.getInstance()); - listView.setOnItemClickListener(new AdapterView.OnItemClickListener() { - @Override - public void onItemClick(AdapterView parent, View view, int position, long id) { - - } - }); - - ExpandableListView expListView = new ExpandableListView(AnsApplication.getInstance()); - expListView.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { - @Override - public void onItemSelected(AdapterView parent, View view, int position, long id) { - - } - - @Override - public void onNothingSelected(AdapterView parent) { - - } - }); - expListView.setOnChildClickListener((parent, v, groupPosition, childPosition, id) -> false); - - expListView.setOnChildClickListener(new ExpandableListView.OnChildClickListener() { - @Override - public boolean onChildClick(ExpandableListView parent, View v, int groupPosition, int childPosition, long id) { - return false; - } - }); - - expListView.setOnGroupClickListener((parent, v, groupPosition, id) -> false); - - expListView.setOnGroupClickListener(new ExpandableListView.OnGroupClickListener() { - @Override - public boolean onGroupClick(ExpandableListView parent, View v, int groupPosition, long id) { - return false; - } - }); - } - - /** - * dialog 上报 - */ - public void testTrackDialog() { - AlertDialog.Builder builder = new AlertDialog.Builder(AnsApplication.getInstance()); - builder.setMultiChoiceItems(null, null, (dialog, which, isChecked) -> { - - }); - - builder.setMultiChoiceItems(null, null, new DialogInterface.OnMultiChoiceClickListener() { - @Override - public void onClick(DialogInterface dialog, int which, boolean isChecked) { - - } - }); - - builder.setPositiveButton("确定", (dialog, which) -> { - }); - - builder.setPositiveButton("确定", new DialogInterface.OnClickListener() { - @Override - public void onClick(DialogInterface dialog, int which) { - } - }); - } - - /** - * TabLayout - */ - public void testTrackTabLayout() { - TabHost tabHost = new TabHost(AnsApplication.getInstance()); - - tabHost.setOnTabChangedListener(tabId -> { - - }); - - tabHost.setOnTabChangedListener(new TabHost.OnTabChangeListener() { - @Override - public void onTabChanged(String tabId) { - - } - }); - } - - /** - * TabHost - */ - public void testTrackTabHost() { - TabLayout tabLayout = new TabLayout(AnsApplication.getInstance()); - - tabLayout.addOnTabSelectedListener(new TabLayout.OnTabSelectedListener() { - @Override - public void onTabSelected(TabLayout.Tab tab) { - - } - - @Override - public void onTabUnselected(TabLayout.Tab tab) { - - } - - @Override - public void onTabReselected(TabLayout.Tab tab) { - - } - }); - } - - /** - * Menu - */ - public void testTrackMenu() { - Toolbar toolbar = new Toolbar(AnsApplication.getInstance()); - toolbar.setOnMenuItemClickListener(item -> false); - - toolbar.setOnMenuItemClickListener(new Toolbar.OnMenuItemClickListener() { - @Override - public boolean onMenuItemClick(MenuItem item) { - return false; - } - }); - - BottomNavigationView bottomNavView = new BottomNavigationView(AnsApplication.getInstance()); - bottomNavView.setOnNavigationItemSelectedListener(menuItem -> false); - - bottomNavView.setOnNavigationItemSelectedListener(new BottomNavigationView.OnNavigationItemSelectedListener() { - @Override - public boolean onNavigationItemSelected(@NonNull MenuItem menuItem) { - return false; - } - }); - } - - -} diff --git a/ans-demo/apidemo/src/main/java/com/analysys/demo/allgroTest/fragment/FragmentOne.java b/ans-demo/apidemo/src/main/java/com/analysys/demo/allgroTest/fragment/FragmentOne.java deleted file mode 100644 index 34be588..0000000 --- a/ans-demo/apidemo/src/main/java/com/analysys/demo/allgroTest/fragment/FragmentOne.java +++ /dev/null @@ -1,35 +0,0 @@ -package com.analysys.demo.allgroTest.fragment; - -import android.annotation.SuppressLint; -import android.os.Bundle; -import android.view.LayoutInflater; -import android.view.View; -import android.view.ViewGroup; - - -import androidx.annotation.NonNull; -import androidx.annotation.Nullable; -import androidx.fragment.app.Fragment; - -import com.analysys.apidemo.R; - -/** - * Created by lenovo on 2016/9/1. - */ -public class FragmentOne extends Fragment { - - @SuppressLint("InflateParams") - @Nullable - @Override - public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { - return inflater.inflate(R.layout.fragment_one, null); - } - - @Override - public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) { - view.findViewById(R.id.fraOne_btn1).setOnClickListener(v -> { - // 点击测试 - }); - super.onViewCreated(view, savedInstanceState); - } -} diff --git a/ans-demo/apidemo/src/main/java/com/analysys/demo/allgroTest/fragment/FragmentThree.java b/ans-demo/apidemo/src/main/java/com/analysys/demo/allgroTest/fragment/FragmentThree.java deleted file mode 100644 index 9b0929b..0000000 --- a/ans-demo/apidemo/src/main/java/com/analysys/demo/allgroTest/fragment/FragmentThree.java +++ /dev/null @@ -1,37 +0,0 @@ -package com.analysys.demo.allgroTest.fragment; - -import android.annotation.SuppressLint; -import android.os.Bundle; -import android.view.LayoutInflater; -import android.view.View; -import android.view.ViewGroup; - - -import androidx.annotation.NonNull; -import androidx.annotation.Nullable; -import androidx.fragment.app.Fragment; - -import com.analysys.apidemo.R; - -/** - * Created by lenovo on 2016/9/1. - */ -public class FragmentThree extends Fragment { - - @SuppressLint("InflateParams") - @Nullable - @Override - public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { - return inflater.inflate(R.layout.fragment_three, null); - } - - @Override - public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) { - super.onViewCreated(view, savedInstanceState); - } - - @Override - public void onResume() { - super.onResume(); - } -} diff --git a/ans-demo/apidemo/src/main/java/com/analysys/demo/allgroTest/fragment/FragmentTwo.java b/ans-demo/apidemo/src/main/java/com/analysys/demo/allgroTest/fragment/FragmentTwo.java deleted file mode 100644 index 3913e5d..0000000 --- a/ans-demo/apidemo/src/main/java/com/analysys/demo/allgroTest/fragment/FragmentTwo.java +++ /dev/null @@ -1,51 +0,0 @@ -package com.analysys.demo.allgroTest.fragment; - -import android.annotation.SuppressLint; -import android.os.Bundle; -import android.view.LayoutInflater; -import android.view.View; -import android.view.ViewGroup; - -import com.analysys.allgro.annotations.AnalysysIgnorePage; -import com.analysys.apidemo.R; - -import androidx.annotation.NonNull; -import androidx.annotation.Nullable; -import androidx.fragment.app.Fragment; - -/** - * Created by lenovo on 2016/9/1. - */ -@AnalysysIgnorePage -public class FragmentTwo extends Fragment { - - - @SuppressLint("InflateParams") - @Nullable - @Override - public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { - return inflater.inflate(R.layout.fragment_two, null); - } - - @Override - public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) { - view.findViewById(R.id.fraTwo_btn1).setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - // 白名单测试1:注解自动上报 - } - }); - - view.findViewById(R.id.fraTwo_btn2).setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - // 黑名单测试1:注解自动忽略 - } - }); - super.onViewCreated(view, savedInstanceState); - } - - public void onClick(View v) { - - } -} diff --git a/ans-demo/visualDemo/src/main/res/drawable/beauty.jpg b/ans-demo/apidemo/src/main/res/drawable/beauty.jpg similarity index 100% rename from ans-demo/visualDemo/src/main/res/drawable/beauty.jpg rename to ans-demo/apidemo/src/main/res/drawable/beauty.jpg diff --git a/ans-demo/apidemo/src/main/res/drawable/bg_dialog.xml b/ans-demo/apidemo/src/main/res/drawable/bg_dialog.xml new file mode 100644 index 0000000..b6c15e7 --- /dev/null +++ b/ans-demo/apidemo/src/main/res/drawable/bg_dialog.xml @@ -0,0 +1,9 @@ + + + + + + + \ No newline at end of file diff --git a/ans-demo/visualDemo/src/main/res/drawable/icon.png b/ans-demo/apidemo/src/main/res/drawable/icon.png similarity index 100% rename from ans-demo/visualDemo/src/main/res/drawable/icon.png rename to ans-demo/apidemo/src/main/res/drawable/icon.png diff --git a/ans-demo/apidemo/src/main/res/drawable/msg_icon.png b/ans-demo/apidemo/src/main/res/drawable/msg_icon.png new file mode 100644 index 0000000..35aa1f8 Binary files /dev/null and b/ans-demo/apidemo/src/main/res/drawable/msg_icon.png differ diff --git a/ans-demo/apidemo/src/main/res/drawable/tab_text.xml b/ans-demo/apidemo/src/main/res/drawable/tab_text.xml new file mode 100644 index 0000000..2e14a0c --- /dev/null +++ b/ans-demo/apidemo/src/main/res/drawable/tab_text.xml @@ -0,0 +1,7 @@ + + + + + + + \ No newline at end of file diff --git a/ans-demo/apidemo/src/main/res/drawable/tab_text_fragment.xml b/ans-demo/apidemo/src/main/res/drawable/tab_text_fragment.xml new file mode 100644 index 0000000..6db6e20 --- /dev/null +++ b/ans-demo/apidemo/src/main/res/drawable/tab_text_fragment.xml @@ -0,0 +1,7 @@ + + + + + + + \ No newline at end of file diff --git a/ans-demo/apidemo/src/main/res/layout/activity_allgro_mainactivity.xml b/ans-demo/apidemo/src/main/res/layout/activity_allgro_mainactivity.xml deleted file mode 100644 index ee24b8f..0000000 --- a/ans-demo/apidemo/src/main/res/layout/activity_allgro_mainactivity.xml +++ /dev/null @@ -1,146 +0,0 @@ - - - - - - - - - - -