├── .gitignore ├── .gitignore.bak ├── .gradle └── 3.3 │ ├── taskArtifacts │ ├── fileHashes.bin │ ├── fileSnapshots.bin │ ├── taskArtifacts.bin │ └── taskArtifacts.lock │ └── tasks │ ├── _advertlibrary_compileDebugJavaWithJavac │ ├── localClassSetAnalysis │ │ ├── localClassSetAnalysis.bin │ │ └── localClassSetAnalysis.lock │ └── localJarClasspathSnapshot │ │ ├── localJarClasspathSnapshot.bin │ │ └── localJarClasspathSnapshot.lock │ ├── _advertlibrary_compileReleaseJavaWithJavac │ ├── localClassSetAnalysis │ │ ├── localClassSetAnalysis.bin │ │ └── localClassSetAnalysis.lock │ └── localJarClasspathSnapshot │ │ ├── localJarClasspathSnapshot.bin │ │ └── localJarClasspathSnapshot.lock │ ├── _app_compileDebugJavaWithJavac │ ├── localClassSetAnalysis │ │ ├── localClassSetAnalysis.bin │ │ └── localClassSetAnalysis.lock │ └── localJarClasspathSnapshot │ │ ├── localJarClasspathSnapshot.bin │ │ └── localJarClasspathSnapshot.lock │ └── _app_compileReleaseJavaWithJavac │ ├── localClassSetAnalysis │ ├── localClassSetAnalysis.bin │ └── localClassSetAnalysis.lock │ └── localJarClasspathSnapshot │ ├── localJarClasspathSnapshot.bin │ └── localJarClasspathSnapshot.lock ├── .idea ├── compiler.xml ├── copyright │ └── profiles_settings.xml ├── gradle.xml ├── libraries │ ├── animated_vector_drawable_25_3_1.xml │ ├── appcompat_v7_25_3_1.xml │ ├── constraint_layout_1_0_2.xml │ ├── constraint_layout_solver_1_0_2.xml │ ├── espresso_core_2_2_2.xml │ ├── espresso_idling_resource_2_2_2.xml │ ├── exposed_instrumentation_api_publish_0_5.xml │ ├── hamcrest_core_1_3.xml │ ├── hamcrest_integration_1_3.xml │ ├── hamcrest_library_1_3.xml │ ├── javawriter_2_1_1.xml │ ├── javax_annotation_api_1_2.xml │ ├── javax_inject_1.xml │ ├── jsr305_2_0_1.xml │ ├── junit_4_12.xml │ ├── okhttp_2_4_0.xml │ ├── okio_1_8_0.xml │ ├── picasso_2_5_2.xml │ ├── rules_0_5.xml │ ├── runner_0_5.xml │ ├── support_annotations_25_3_1.xml │ ├── support_compat_25_3_1.xml │ ├── support_core_ui_25_3_1.xml │ ├── support_core_utils_25_3_1.xml │ ├── support_fragment_25_3_1.xml │ ├── support_media_compat_25_3_1.xml │ ├── support_v4_25_3_1.xml │ └── support_vector_drawable_25_3_1.xml ├── misc.xml ├── modules.xml ├── runConfigurations.xml ├── vcs.xml └── workspace.xml ├── AdvertSDK.iml ├── README.md ├── advertlibrary ├── .gitignore ├── advertlibrary.iml ├── build.gradle ├── proguard-rules.pro └── src │ ├── androidTest │ └── java │ │ └── advert │ │ └── sdk │ │ └── com │ │ └── advertlibrary │ │ └── ExampleInstrumentedTest.java │ └── main │ ├── AndroidManifest.xml │ ├── java │ └── advert │ │ └── sdk │ │ └── com │ │ └── advertlibrary │ │ ├── bean │ │ ├── AdvertBean.java │ │ └── ProgressModel.java │ │ ├── constant │ │ └── AdvertConstant.java │ │ ├── engine │ │ ├── AdvertEngine.java │ │ ├── AdvertManager.java │ │ ├── ProgressHelper.java │ │ └── ProgressResponseBody.java │ │ ├── intf │ │ ├── OnDownloadListener.java │ │ ├── OnGetBitmapByurlListener.java │ │ ├── ProgressResponseListener.java │ │ └── UIProgressResponseListener.java │ │ ├── receiver │ │ ├── AdvertReceiver.java │ │ ├── HomeWatcherReceiver.java │ │ └── NotificationAdvertReceiver.java │ │ ├── service │ │ └── AdvertService.java │ │ ├── utils │ │ ├── DownloadUtils.java │ │ ├── SPUtils.java │ │ └── ShowWindowAdvertUtils.java │ │ └── wiget │ │ ├── AdInsertLoad.java │ │ ├── BitmapUtils.java │ │ ├── CircleImageView.java │ │ ├── SizeUtils.java │ │ ├── SupportMultipleScreensUtil.java │ │ ├── TimeUtil.java │ │ ├── ToastUtil.java │ │ ├── XmlUtil.java │ │ └── animation │ │ ├── Animator.java │ │ ├── AnimatorListenerAdapter.java │ │ ├── AnimatorProxy.java │ │ ├── ArgbEvaluator.java │ │ ├── FloatEvaluator.java │ │ ├── IntEvaluator.java │ │ └── Keyframe.java │ └── res │ ├── anim │ ├── dialog_in_anim.xml │ └── dialog_out_anim.xml │ ├── drawable │ ├── close.png │ ├── closead.png │ └── ic_launcher.png │ ├── layout │ ├── dialog_advert_view.xml │ └── notification_advert_view.xml │ └── values │ ├── strings.xml │ └── styles.xml ├── app ├── .gitignore ├── app.iml ├── build.gradle ├── proguard-rules.pro └── src │ ├── androidTest │ └── java │ │ └── advert │ │ └── sdk │ │ └── com │ │ └── advertsdk │ │ └── ExampleInstrumentedTest.java │ ├── main │ ├── AndroidManifest.xml │ ├── java │ │ └── advert │ │ │ └── sdk │ │ │ └── com │ │ │ └── advertsdk │ │ │ ├── MainActivity.java │ │ │ └── MyApplication.java │ └── res │ │ ├── layout │ │ └── activity_main.xml │ │ ├── mipmap-hdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ ├── mipmap-mdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ ├── mipmap-xhdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ ├── mipmap-xxhdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ ├── mipmap-xxxhdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ └── values │ │ ├── colors.xml │ │ ├── strings.xml │ │ └── styles.xml │ └── test │ └── java │ └── advert │ └── sdk │ └── com │ └── advertsdk │ └── ExampleUnitTest.java ├── build.gradle ├── build ├── android-profile │ ├── profile-2017-06-20-14-03-13-285.rawproto │ ├── profile-2017-06-20-14-03-51-500.rawproto │ ├── profile-2017-06-20-14-10-25-038.rawproto │ ├── profile-2017-06-20-14-59-50-758.rawproto │ ├── profile-2017-06-20-15-10-10-730.rawproto │ ├── profile-2017-06-20-15-21-52-704.rawproto │ ├── profile-2017-06-20-17-31-03-957.rawproto │ ├── profile-2017-06-20-17-31-11-327.rawproto │ ├── profile-2017-06-20-17-31-41-376.rawproto │ ├── profile-2017-06-21-11-50-45-069.rawproto │ ├── profile-2017-06-21-11-50-52-037.rawproto │ ├── profile-2017-06-21-17-02-27-594.rawproto │ ├── profile-2017-06-21-17-02-33-939.rawproto │ ├── profile-2017-06-21-17-25-33-786.rawproto │ ├── profile-2017-06-21-17-27-36-179.rawproto │ ├── profile-2017-06-21-17-30-32-760.rawproto │ ├── profile-2017-06-21-17-32-23-270.rawproto │ ├── profile-2017-06-21-17-39-20-832.rawproto │ ├── profile-2017-06-21-17-39-27-940.rawproto │ ├── profile-2017-06-21-17-51-47-558.rawproto │ ├── profile-2017-06-21-17-52-15-072.rawproto │ ├── profile-2017-06-21-17-54-54-007.rawproto │ ├── profile-2017-06-21-18-01-15-894.rawproto │ ├── profile-2017-06-21-18-01-38-435.rawproto │ ├── profile-2017-06-22-09-16-07-058.rawproto │ ├── profile-2017-06-22-09-16-12-711.rawproto │ ├── profile-2017-06-22-10-21-08-419.rawproto │ ├── profile-2017-06-22-10-21-12-030.rawproto │ ├── profile-2017-06-22-10-25-58-365.rawproto │ ├── profile-2017-06-23-14-00-57-334.rawproto │ ├── profile-2017-06-23-14-00-59-865.rawproto │ ├── profile-2017-06-23-14-03-04-468.rawproto │ ├── profile-2017-06-23-14-33-23-503.rawproto │ └── profile-2017-06-23-14-33-25-351.rawproto ├── generated │ └── mockable-android-25.jar └── intermediates │ └── dex-cache │ └── cache.xml ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── local.properties └── settings.gradle /.gitignore: -------------------------------------------------------------------------------- 1 | .settings/ 2 | target/ 3 | .classpath 4 | .project 5 | .tern-project 6 | -------------------------------------------------------------------------------- /.gitignore.bak: -------------------------------------------------------------------------------- 1 | *.iml 2 | .gradle 3 | /local.properties 4 | /.idea/workspace.xml 5 | /.idea/libraries 6 | .DS_Store 7 | /build 8 | /captures 9 | .externalNativeBuild 10 | -------------------------------------------------------------------------------- /.gradle/3.3/taskArtifacts/fileHashes.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/15527621771/Android-Advert-SDK/c7e117e04d3a4de175ae35f7f65c785ccb305b67/.gradle/3.3/taskArtifacts/fileHashes.bin -------------------------------------------------------------------------------- /.gradle/3.3/taskArtifacts/fileSnapshots.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/15527621771/Android-Advert-SDK/c7e117e04d3a4de175ae35f7f65c785ccb305b67/.gradle/3.3/taskArtifacts/fileSnapshots.bin -------------------------------------------------------------------------------- /.gradle/3.3/taskArtifacts/taskArtifacts.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/15527621771/Android-Advert-SDK/c7e117e04d3a4de175ae35f7f65c785ccb305b67/.gradle/3.3/taskArtifacts/taskArtifacts.bin -------------------------------------------------------------------------------- /.gradle/3.3/taskArtifacts/taskArtifacts.lock: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/15527621771/Android-Advert-SDK/c7e117e04d3a4de175ae35f7f65c785ccb305b67/.gradle/3.3/taskArtifacts/taskArtifacts.lock -------------------------------------------------------------------------------- /.gradle/3.3/tasks/_advertlibrary_compileDebugJavaWithJavac/localClassSetAnalysis/localClassSetAnalysis.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/15527621771/Android-Advert-SDK/c7e117e04d3a4de175ae35f7f65c785ccb305b67/.gradle/3.3/tasks/_advertlibrary_compileDebugJavaWithJavac/localClassSetAnalysis/localClassSetAnalysis.bin -------------------------------------------------------------------------------- /.gradle/3.3/tasks/_advertlibrary_compileDebugJavaWithJavac/localClassSetAnalysis/localClassSetAnalysis.lock: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/15527621771/Android-Advert-SDK/c7e117e04d3a4de175ae35f7f65c785ccb305b67/.gradle/3.3/tasks/_advertlibrary_compileDebugJavaWithJavac/localClassSetAnalysis/localClassSetAnalysis.lock -------------------------------------------------------------------------------- /.gradle/3.3/tasks/_advertlibrary_compileDebugJavaWithJavac/localJarClasspathSnapshot/localJarClasspathSnapshot.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/15527621771/Android-Advert-SDK/c7e117e04d3a4de175ae35f7f65c785ccb305b67/.gradle/3.3/tasks/_advertlibrary_compileDebugJavaWithJavac/localJarClasspathSnapshot/localJarClasspathSnapshot.bin -------------------------------------------------------------------------------- /.gradle/3.3/tasks/_advertlibrary_compileDebugJavaWithJavac/localJarClasspathSnapshot/localJarClasspathSnapshot.lock: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/15527621771/Android-Advert-SDK/c7e117e04d3a4de175ae35f7f65c785ccb305b67/.gradle/3.3/tasks/_advertlibrary_compileDebugJavaWithJavac/localJarClasspathSnapshot/localJarClasspathSnapshot.lock -------------------------------------------------------------------------------- /.gradle/3.3/tasks/_advertlibrary_compileReleaseJavaWithJavac/localClassSetAnalysis/localClassSetAnalysis.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/15527621771/Android-Advert-SDK/c7e117e04d3a4de175ae35f7f65c785ccb305b67/.gradle/3.3/tasks/_advertlibrary_compileReleaseJavaWithJavac/localClassSetAnalysis/localClassSetAnalysis.bin -------------------------------------------------------------------------------- /.gradle/3.3/tasks/_advertlibrary_compileReleaseJavaWithJavac/localClassSetAnalysis/localClassSetAnalysis.lock: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/15527621771/Android-Advert-SDK/c7e117e04d3a4de175ae35f7f65c785ccb305b67/.gradle/3.3/tasks/_advertlibrary_compileReleaseJavaWithJavac/localClassSetAnalysis/localClassSetAnalysis.lock -------------------------------------------------------------------------------- /.gradle/3.3/tasks/_advertlibrary_compileReleaseJavaWithJavac/localJarClasspathSnapshot/localJarClasspathSnapshot.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/15527621771/Android-Advert-SDK/c7e117e04d3a4de175ae35f7f65c785ccb305b67/.gradle/3.3/tasks/_advertlibrary_compileReleaseJavaWithJavac/localJarClasspathSnapshot/localJarClasspathSnapshot.bin -------------------------------------------------------------------------------- /.gradle/3.3/tasks/_advertlibrary_compileReleaseJavaWithJavac/localJarClasspathSnapshot/localJarClasspathSnapshot.lock: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/15527621771/Android-Advert-SDK/c7e117e04d3a4de175ae35f7f65c785ccb305b67/.gradle/3.3/tasks/_advertlibrary_compileReleaseJavaWithJavac/localJarClasspathSnapshot/localJarClasspathSnapshot.lock -------------------------------------------------------------------------------- /.gradle/3.3/tasks/_app_compileDebugJavaWithJavac/localClassSetAnalysis/localClassSetAnalysis.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/15527621771/Android-Advert-SDK/c7e117e04d3a4de175ae35f7f65c785ccb305b67/.gradle/3.3/tasks/_app_compileDebugJavaWithJavac/localClassSetAnalysis/localClassSetAnalysis.bin -------------------------------------------------------------------------------- /.gradle/3.3/tasks/_app_compileDebugJavaWithJavac/localClassSetAnalysis/localClassSetAnalysis.lock: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/15527621771/Android-Advert-SDK/c7e117e04d3a4de175ae35f7f65c785ccb305b67/.gradle/3.3/tasks/_app_compileDebugJavaWithJavac/localClassSetAnalysis/localClassSetAnalysis.lock -------------------------------------------------------------------------------- /.gradle/3.3/tasks/_app_compileDebugJavaWithJavac/localJarClasspathSnapshot/localJarClasspathSnapshot.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/15527621771/Android-Advert-SDK/c7e117e04d3a4de175ae35f7f65c785ccb305b67/.gradle/3.3/tasks/_app_compileDebugJavaWithJavac/localJarClasspathSnapshot/localJarClasspathSnapshot.bin -------------------------------------------------------------------------------- /.gradle/3.3/tasks/_app_compileDebugJavaWithJavac/localJarClasspathSnapshot/localJarClasspathSnapshot.lock: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/15527621771/Android-Advert-SDK/c7e117e04d3a4de175ae35f7f65c785ccb305b67/.gradle/3.3/tasks/_app_compileDebugJavaWithJavac/localJarClasspathSnapshot/localJarClasspathSnapshot.lock -------------------------------------------------------------------------------- /.gradle/3.3/tasks/_app_compileReleaseJavaWithJavac/localClassSetAnalysis/localClassSetAnalysis.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/15527621771/Android-Advert-SDK/c7e117e04d3a4de175ae35f7f65c785ccb305b67/.gradle/3.3/tasks/_app_compileReleaseJavaWithJavac/localClassSetAnalysis/localClassSetAnalysis.bin -------------------------------------------------------------------------------- /.gradle/3.3/tasks/_app_compileReleaseJavaWithJavac/localClassSetAnalysis/localClassSetAnalysis.lock: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/15527621771/Android-Advert-SDK/c7e117e04d3a4de175ae35f7f65c785ccb305b67/.gradle/3.3/tasks/_app_compileReleaseJavaWithJavac/localClassSetAnalysis/localClassSetAnalysis.lock -------------------------------------------------------------------------------- /.gradle/3.3/tasks/_app_compileReleaseJavaWithJavac/localJarClasspathSnapshot/localJarClasspathSnapshot.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/15527621771/Android-Advert-SDK/c7e117e04d3a4de175ae35f7f65c785ccb305b67/.gradle/3.3/tasks/_app_compileReleaseJavaWithJavac/localJarClasspathSnapshot/localJarClasspathSnapshot.bin -------------------------------------------------------------------------------- /.gradle/3.3/tasks/_app_compileReleaseJavaWithJavac/localJarClasspathSnapshot/localJarClasspathSnapshot.lock: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/15527621771/Android-Advert-SDK/c7e117e04d3a4de175ae35f7f65c785ccb305b67/.gradle/3.3/tasks/_app_compileReleaseJavaWithJavac/localJarClasspathSnapshot/localJarClasspathSnapshot.lock -------------------------------------------------------------------------------- /.idea/compiler.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /.idea/copyright/profiles_settings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | -------------------------------------------------------------------------------- /.idea/gradle.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 18 | 19 | -------------------------------------------------------------------------------- /.idea/libraries/animated_vector_drawable_25_3_1.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/appcompat_v7_25_3_1.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /.idea/libraries/constraint_layout_1_0_2.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /.idea/libraries/constraint_layout_solver_1_0_2.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /.idea/libraries/espresso_core_2_2_2.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/espresso_idling_resource_2_2_2.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/exposed_instrumentation_api_publish_0_5.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/hamcrest_core_1_3.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /.idea/libraries/hamcrest_integration_1_3.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /.idea/libraries/hamcrest_library_1_3.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /.idea/libraries/javawriter_2_1_1.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /.idea/libraries/javax_annotation_api_1_2.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /.idea/libraries/javax_inject_1.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /.idea/libraries/jsr305_2_0_1.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /.idea/libraries/junit_4_12.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /.idea/libraries/okhttp_2_4_0.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /.idea/libraries/okio_1_8_0.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /.idea/libraries/picasso_2_5_2.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /.idea/libraries/rules_0_5.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /.idea/libraries/runner_0_5.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /.idea/libraries/support_annotations_25_3_1.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /.idea/libraries/support_compat_25_3_1.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /.idea/libraries/support_core_ui_25_3_1.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /.idea/libraries/support_core_utils_25_3_1.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /.idea/libraries/support_fragment_25_3_1.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /.idea/libraries/support_media_compat_25_3_1.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /.idea/libraries/support_v4_25_3_1.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /.idea/libraries/support_vector_drawable_25_3_1.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | Android 12 | 13 | 14 | Android Lint 15 | 16 | 17 | Java 18 | 19 | 20 | Java language level migration aidsJava 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 42 | 43 | 45 | 46 | 47 | 48 | 49 | 1.8 50 | 51 | 56 | 57 | 58 | 59 | 60 | 61 | -------------------------------------------------------------------------------- /.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /.idea/runConfigurations.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 11 | 12 | -------------------------------------------------------------------------------- /.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /AdvertSDK.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # 一套开源Android广告SDK(An open AndroidAdvert Channel SDK) 2 | 3 | 项目简介(Directions for use): 4 | ---- 5 | 大家好,我是想飞上天的PJJ~是一名普通的Android开发。 6 | 7 | 目前就职于一家游戏研发公司,公司部门目前的需要主要是针对一些SDK方面的业务开发和渠道的对接工作(对于只有App研发的我来说,感觉SDK开发涉及的知识更加底层,主要对业务的需要了解的更为透彻,其基本就是对代码的封装(后面实际研发中其实也只是应用到了android应用层的知识,并为涉及较深的内容,所以这个开源项目也是仅仅是作为SDK开发一些思维的参考,功能也比较简易,大家可以根据需要进行相关的业务拓展). 8 | 要命的是各大搜素引擎可查询SDK资料几乎就是打广告打广告,免费提供解决技术方案(也就是源代码)的参考实在太少,所以,本项目仅仅是针对未来有类似研发需求的朋友一些参考,节约时间少走弯路 9 | 10 | # 进一步的说明 11 | 一般来说,Android SDK主要就是对接口设计 (常用): (The Android SDK is a common design interface/function) 12 | 13 | * 其内部主要是对业务的封装,之后封装成接口,以jar,aar,库的形式被依赖后,调用SDK内容接口,实现对业务的需要. 14 | 15 | * 本套广告SDK的业务需求:(ndroid应用在依赖该SDK后,只需在应用的application进行初始化调用 AdvertEngine.init(this); 16 | 即可通过服务端对广告的弹出做出相应的处理(实际情况可更具业务调正) 17 | 18 | 项目需求 19 | 20 | * 1、广告SDK只暴露给应用APK一个初始化接口 21 | * 2、广告SDK里面到服务端获取数据,由服务端返回广告具体弹出时间,位置,内容,广告点击后的相应操作等, 22 | * 3、广告的显示不依赖应用APK的 开发者只需要初始化init方法所有内容由服务端控制 23 | * 4、能够监听系统广播(系统启动,返回Home,解锁,网络切换等),对SDK的唤醒(即服务的保活) 防止服务被杀死 24 | * 5、广告的弹出不影响第三方应用的体验效果 确保弹出的流畅. 不妨碍apk的正常使用 25 | 26 | 27 | 项目中用于悬浮方式展示广告的弹出,毕竟广告的业务不能对自身应用的使用产生影响,但是在由于国内的android系统较多,android的悬浮也需要动态的给出所以后面 28 | 在WindowManager悬浮窗TYPE_TOAST,像一个普通的Android Toast一样。这样就不需要申请悬浮窗权限了, 29 | 30 | 具体使用 31 | 需要将本项目中的libs引入或者打成需要的jar包使用 32 | 按照库中所需要的权限和四大组件的使用配置在你的项目中,在项目中application调用 AdvertEngine.init(this),即可完成对应的广告弹出. 33 | 34 | 35 | 36 | ### 最后:(该项目也只是笔者第一次了解SDK的时候对其简单的研究,有相同业务的同学也可以简单的参考) 37 | 38 | 路漫漫其修远兮,吾将上下而求索. 39 | 40 | 联系方式: 41 | 42 | 对本项目有任何问题,请直接联系笔者 43 | 44 | QQ:409752891(想飞上天的PJJ) 45 | 46 | email:409752891@qq.com 47 | 48 | 49 | -------------------------------------------------------------------------------- /advertlibrary/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /advertlibrary/advertlibrary.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 8 | 9 | 10 | 11 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | -------------------------------------------------------------------------------- /advertlibrary/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.library' 2 | 3 | android { 4 | compileSdkVersion 25 5 | buildToolsVersion "25.0.3" 6 | 7 | defaultConfig { 8 | minSdkVersion 19 9 | targetSdkVersion 25 10 | versionCode 1 11 | versionName "1.0" 12 | 13 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" 14 | 15 | } 16 | buildTypes { 17 | release { 18 | minifyEnabled false 19 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 20 | } 21 | } 22 | } 23 | 24 | dependencies { 25 | compile fileTree(dir: 'libs', include: ['*.jar']) 26 | androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', { 27 | exclude group: 'com.android.support', module: 'support-annotations' 28 | }) 29 | compile 'com.android.support:appcompat-v7:25.3.1' 30 | compile 'com.squareup.okio:okio:1.8.0' 31 | compile 'com.squareup.okhttp:okhttp:2.4.0' 32 | compile 'com.squareup.picasso:picasso:2.5.2' 33 | } 34 | -------------------------------------------------------------------------------- /advertlibrary/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # By default, the flags in this file are appended to flags specified 3 | # in G:\android\sdk/tools/proguard/proguard-android.txt 4 | # You can edit the include path and order by changing the proguardFiles 5 | # directive in build.gradle. 6 | # 7 | # For more details, see 8 | # http://developer.android.com/guide/developing/tools/proguard.html 9 | 10 | # Add any project specific keep options here: 11 | 12 | # If your project uses WebView with JS, uncomment the following 13 | # and specify the fully qualified class name to the JavaScript interface 14 | # class: 15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 16 | # public *; 17 | #} 18 | 19 | # Uncomment this to preserve the line number information for 20 | # debugging stack traces. 21 | #-keepattributes SourceFile,LineNumberTable 22 | 23 | # If you keep the line number information, uncomment this to 24 | # hide the original source file name. 25 | #-renamesourcefileattribute SourceFile 26 | -------------------------------------------------------------------------------- /advertlibrary/src/androidTest/java/advert/sdk/com/advertlibrary/ExampleInstrumentedTest.java: -------------------------------------------------------------------------------- 1 | package advert.sdk.com.advertlibrary; 2 | 3 | import android.content.Context; 4 | import android.support.test.InstrumentationRegistry; 5 | import android.support.test.runner.AndroidJUnit4; 6 | 7 | import org.junit.Test; 8 | import org.junit.runner.RunWith; 9 | 10 | import static org.junit.Assert.*; 11 | 12 | /** 13 | * Instrumentation test, which will execute on an Android device. 14 | * 15 | * @see Testing documentation 16 | */ 17 | @RunWith(AndroidJUnit4.class) 18 | public class ExampleInstrumentedTest { 19 | @Test 20 | public void useAppContext() throws Exception { 21 | // Context of the app under test. 22 | Context appContext = InstrumentationRegistry.getTargetContext(); 23 | 24 | assertEquals("advert.sdk.com.advertlibrary.test", appContext.getPackageName()); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /advertlibrary/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 3 | 4 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /advertlibrary/src/main/java/advert/sdk/com/advertlibrary/bean/AdvertBean.java: -------------------------------------------------------------------------------- 1 | package advert.sdk.com.advertlibrary.bean; 2 | 3 | import android.os.Parcel; 4 | import android.os.Parcelable; 5 | 6 | /** 7 | * 模拟数据javabean 8 | */ 9 | 10 | public class AdvertBean implements Parcelable { 11 | //广告显示时间,毫秒 12 | private int advertTime; 13 | //广告类型,0=插屏,1=横幅,2=通知栏 14 | private int advertType; 15 | //横幅广告位置,0=不是横幅,1=顶部,2=底部 16 | private int bannerLocation; 17 | //广告图片连接 18 | private String advertPicUrl; 19 | //广告apk下载连接 20 | private String advertApkDownloadUrl; 21 | 22 | public AdvertBean() { 23 | super(); 24 | } 25 | 26 | public AdvertBean(int advertTime, int advertType, int bannerLocation, String advertPicUrl, String advertApkDownloadUrl) { 27 | this.advertTime = advertTime; 28 | this.advertType = advertType; 29 | this.bannerLocation = bannerLocation; 30 | this.advertPicUrl = advertPicUrl; 31 | this.advertApkDownloadUrl = advertApkDownloadUrl; 32 | } 33 | 34 | public int getAdvertTime() { 35 | return advertTime; 36 | } 37 | 38 | public void setAdvertTime(int advertTime) { 39 | this.advertTime = advertTime; 40 | } 41 | 42 | public int getAdvertType() { 43 | return advertType; 44 | } 45 | 46 | public void setAdvertType(int advertType) { 47 | this.advertType = advertType; 48 | } 49 | 50 | public int getBannerLocation() { 51 | return bannerLocation; 52 | } 53 | 54 | public void setBannerLocation(int bannerLocation) { 55 | this.bannerLocation = bannerLocation; 56 | } 57 | 58 | public String getAdvertPicUrl() { 59 | return advertPicUrl; 60 | } 61 | 62 | public void setAdvertPicUrl(String advertPicUrl) { 63 | this.advertPicUrl = advertPicUrl; 64 | } 65 | 66 | public String getAdvertApkDownloadUrl() { 67 | return advertApkDownloadUrl; 68 | } 69 | 70 | public void setAdvertApkDownloadUrl(String advertApkDownloadUrl) { 71 | this.advertApkDownloadUrl = advertApkDownloadUrl; 72 | } 73 | 74 | @Override 75 | public int describeContents() { 76 | return 0; 77 | } 78 | 79 | @Override 80 | public void writeToParcel(Parcel dest, int flags) { 81 | dest.writeInt(this.advertTime); 82 | dest.writeInt(this.advertType); 83 | dest.writeInt(this.bannerLocation); 84 | dest.writeString(this.advertPicUrl); 85 | dest.writeString(this.advertApkDownloadUrl); 86 | } 87 | 88 | protected AdvertBean(Parcel in) { 89 | this.advertTime = in.readInt(); 90 | this.advertType = in.readInt(); 91 | this.bannerLocation = in.readInt(); 92 | this.advertPicUrl = in.readString(); 93 | this.advertApkDownloadUrl = in.readString(); 94 | } 95 | 96 | public static final Parcelable.Creator CREATOR = new Parcelable.Creator() { 97 | @Override 98 | public AdvertBean createFromParcel(Parcel source) { 99 | return new AdvertBean(source); 100 | } 101 | 102 | @Override 103 | public AdvertBean[] newArray(int size) { 104 | return new AdvertBean[size]; 105 | } 106 | }; 107 | 108 | @Override 109 | public String toString() { 110 | return "AdvertBean{" + 111 | "advertTime=" + advertTime + 112 | ", advertType=" + advertType + 113 | ", bannerLocation=" + bannerLocation + 114 | ", advertPicUrl='" + advertPicUrl + '\'' + 115 | ", advertApkDownloadUrl='" + advertApkDownloadUrl + '\'' + 116 | '}'; 117 | } 118 | } 119 | -------------------------------------------------------------------------------- /advertlibrary/src/main/java/advert/sdk/com/advertlibrary/bean/ProgressModel.java: -------------------------------------------------------------------------------- 1 | package advert.sdk.com.advertlibrary.bean; 2 | 3 | import java.io.Serializable; 4 | 5 | /** 6 | * UI进度回调实体类 7 | */ 8 | public class ProgressModel implements Serializable { 9 | //当前读取字节长度 10 | private long currentBytes; 11 | //总字节长度 12 | private long contentLength; 13 | //是否读取完成 14 | private boolean done; 15 | 16 | public ProgressModel(long currentBytes, long contentLength, boolean done) { 17 | this.currentBytes = currentBytes; 18 | this.contentLength = contentLength; 19 | this.done = done; 20 | } 21 | 22 | public long getCurrentBytes() { 23 | return currentBytes; 24 | } 25 | 26 | public void setCurrentBytes(long currentBytes) { 27 | this.currentBytes = currentBytes; 28 | } 29 | 30 | public long getContentLength() { 31 | return contentLength; 32 | } 33 | 34 | public void setContentLength(long contentLength) { 35 | this.contentLength = contentLength; 36 | } 37 | 38 | public boolean isDone() { 39 | return done; 40 | } 41 | 42 | public void setDone(boolean done) { 43 | this.done = done; 44 | } 45 | 46 | @Override 47 | public String toString() { 48 | return "ProgressModel{" + 49 | "currentBytes=" + currentBytes + 50 | ", contentLength=" + contentLength + 51 | ", done=" + done + 52 | '}'; 53 | } 54 | } -------------------------------------------------------------------------------- /advertlibrary/src/main/java/advert/sdk/com/advertlibrary/constant/AdvertConstant.java: -------------------------------------------------------------------------------- 1 | package advert.sdk.com.advertlibrary.constant; 2 | 3 | /** 4 | */ 5 | 6 | public interface AdvertConstant { 7 | //插屏广告 8 | int INSERT_ADVERT_TYPE = 0; 9 | //横幅广告 10 | int BANNER_ADVERT_TYPE = 1; 11 | //标题栏广告 12 | int BAR_ADVERT_TYPE = 2; 13 | //横幅广告顶部显示 14 | int BANNER_ADVERT_TOP = 1; 15 | //横幅广告低部显示 16 | int BANNER_ADVERT_BOTTOM = 2; 17 | } 18 | -------------------------------------------------------------------------------- /advertlibrary/src/main/java/advert/sdk/com/advertlibrary/engine/AdvertEngine.java: -------------------------------------------------------------------------------- 1 | package advert.sdk.com.advertlibrary.engine; 2 | 3 | import android.content.Context; 4 | import android.content.Intent; 5 | import android.content.IntentFilter; 6 | 7 | import advert.sdk.com.advertlibrary.receiver.AdvertReceiver; 8 | import advert.sdk.com.advertlibrary.receiver.HomeWatcherReceiver; 9 | import advert.sdk.com.advertlibrary.service.AdvertService; 10 | import advert.sdk.com.advertlibrary.utils.SPUtils; 11 | 12 | /** 13 | */ 14 | 15 | public class AdvertEngine { 16 | /** 17 | * 初始化广告程序,在程序启动时候调用 18 | * @param context 19 | */ 20 | public static void init(final Context context){ 21 | Intent service = new Intent(context,AdvertService.class); 22 | context.startService(service); 23 | //服务创建时,启动广播保活 24 | IntentFilter intentFilter = new IntentFilter(Intent.ACTION_TIME_TICK); 25 | AdvertReceiver adverBroadCast = new AdvertReceiver(); 26 | context.registerReceiver(adverBroadCast, intentFilter); 27 | //启动home键监听广播 28 | context.registerReceiver(new HomeWatcherReceiver(), new IntentFilter(Intent.ACTION_CLOSE_SYSTEM_DIALOGS)); 29 | //模拟服务被干死 30 | /*Handler handler=new Handler(); 31 | handler.postDelayed(new Runnable() { 32 | @Override 33 | public void run() { 34 | context.stopService( new Intent(context,AdvertService.class)); 35 | } 36 | }, 10000);*/ 37 | SPUtils.put(context,"HomeHitCount",0); 38 | } 39 | 40 | /** 41 | * 销毁服务和广播,在程序停止时候调用 42 | * @param context 43 | */ 44 | public static void burning(final Context context){ 45 | Intent service = new Intent(context,AdvertService.class); 46 | context.stopService(service); 47 | AdvertReceiver adverBroadCast = new AdvertReceiver(); 48 | context.unregisterReceiver(adverBroadCast); 49 | context.unregisterReceiver(new HomeWatcherReceiver()); 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /advertlibrary/src/main/java/advert/sdk/com/advertlibrary/engine/AdvertManager.java: -------------------------------------------------------------------------------- 1 | package advert.sdk.com.advertlibrary.engine; 2 | 3 | import android.annotation.TargetApi; 4 | import android.app.Notification; 5 | import android.app.NotificationManager; 6 | import android.app.PendingIntent; 7 | import android.content.Context; 8 | import android.content.Intent; 9 | import android.graphics.Bitmap; 10 | import android.os.Build; 11 | import android.os.Handler; 12 | import android.widget.RemoteViews; 13 | 14 | import java.util.List; 15 | 16 | import advert.sdk.com.advertlibrary.R; 17 | import advert.sdk.com.advertlibrary.bean.AdvertBean; 18 | import advert.sdk.com.advertlibrary.constant.AdvertConstant; 19 | import advert.sdk.com.advertlibrary.intf.OnGetBitmapByurlListener; 20 | import advert.sdk.com.advertlibrary.utils.DownloadUtils; 21 | import advert.sdk.com.advertlibrary.utils.ShowWindowAdvertUtils; 22 | 23 | /** 24 | */ 25 | 26 | public class AdvertManager { 27 | private final Context context; 28 | private final List advertBeanList; 29 | int index; 30 | int indexMax; 31 | 32 | public AdvertManager(List advertBeanList, Context context) { 33 | this.context = context; 34 | this.advertBeanList = advertBeanList; 35 | handler.postDelayed(runnable, TIME); 36 | index = 0; 37 | indexMax=advertBeanList==null?0:advertBeanList.size(); 38 | } 39 | 40 | //每隔两分钟显示一个 41 | private int TIME = 10000; 42 | Handler handler = new Handler(); 43 | Runnable runnable = new Runnable() { 44 | @Override 45 | public void run() { 46 | // handler自带方法实现定时器 47 | showAdvertManager(advertBeanList.get(index)); 48 | index++; 49 | if (index == indexMax) { 50 | index = 0; 51 | } 52 | handler.postDelayed(this, TIME); 53 | } 54 | }; 55 | 56 | 57 | private void showAdvertManager(final AdvertBean advertBean) { 58 | int advertType = advertBean.getAdvertType(); 59 | //根据广告类型来选择显示方式 60 | switch (advertType) { 61 | case AdvertConstant.INSERT_ADVERT_TYPE: 62 | //插入广告 63 | case AdvertConstant.BANNER_ADVERT_TYPE: 64 | //横幅广告 65 | //这两种广告都采用dialog方式 66 | //类型是TYPE_TOAST,像一个普通的Android Toast一样。这样就不需要申请悬浮窗权限了。 67 | //初始化后不首先获得窗口焦点。不妨碍设备上其他部件的点击、触摸事件。 68 | ShowWindowAdvertUtils.init(advertType, advertBean.getBannerLocation(), advertBean.getAdvertApkDownloadUrl(), advertBean.getAdvertPicUrl(), advertBean.getAdvertTime(), context); 69 | ShowWindowAdvertUtils.show(); 70 | //定时打开 71 | /* new Handler().postDelayed(new Runnable() { 72 | @Override 73 | public void run() { 74 | } 75 | }, advertBean.getAdvertTime());*/ 76 | break; 77 | case AdvertConstant.BAR_ADVERT_TYPE: 78 | //标题栏广告,采用notification 79 | new Handler().postDelayed(new Runnable() { 80 | @Override 81 | public void run() { 82 | showNotificationAlert(advertBean); 83 | } 84 | }, advertBean.getAdvertTime()); 85 | break; 86 | 87 | } 88 | } 89 | 90 | //弹出通知栏显示广告 91 | private void showNotificationAlert(final AdvertBean advertBean) { 92 | //将图片链接转换为bitmap对象 93 | DownloadUtils.getBitmapByPIcUrl(advertBean.getAdvertPicUrl(), new OnGetBitmapByurlListener() { 94 | @Override 95 | public void onGetBitmapSuccess(Bitmap bitmap) { 96 | initNotification("我是广告", "我是广告", bitmap, advertBean); 97 | } 98 | 99 | @Override 100 | public void onGetBitmapFailed() { 101 | } 102 | }); 103 | 104 | } 105 | 106 | @TargetApi(Build.VERSION_CODES.JELLY_BEAN) 107 | private void initNotification(String ticker, String title, Bitmap bitmap, AdvertBean advertBean) { 108 | Notification.Builder builder = new Notification.Builder(context); 109 | builder.setSmallIcon(R.drawable.close);//设置图标 110 | builder.setWhen(System.currentTimeMillis());//设置通知时间 111 | Intent intent = new Intent("NotificationAdvertReceiver"); 112 | intent.putExtra("apkUrl", advertBean.getAdvertApkDownloadUrl()); 113 | PendingIntent pendingIntent = PendingIntent.getBroadcast(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT); 114 | builder.setContentIntent(pendingIntent); 115 | 116 | NotificationManager manager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); 117 | builder.setDefaults(Notification.DEFAULT_LIGHTS);//设置指示灯 118 | builder.setDefaults(Notification.DEFAULT_SOUND);//设置提示声音 119 | builder.setDefaults(Notification.DEFAULT_VIBRATE);//设置震动 120 | Notification notification = builder.build(); 121 | notification.flags = Notification.FLAG_AUTO_CANCEL; 122 | 123 | RemoteViews remoteView = new RemoteViews(context.getPackageName(), R.layout.notification_advert_view); 124 | remoteView.setImageViewResource(R.id.image, R.drawable.close); 125 | remoteView.setImageViewBitmap(R.id.image, bitmap); 126 | remoteView.setTextViewText(R.id.title, ticker); 127 | remoteView.setTextViewText(R.id.text, title); 128 | notification.contentView = remoteView; 129 | manager.notify(2, notification); 130 | 131 | } 132 | } 133 | -------------------------------------------------------------------------------- /advertlibrary/src/main/java/advert/sdk/com/advertlibrary/engine/ProgressHelper.java: -------------------------------------------------------------------------------- 1 | package advert.sdk.com.advertlibrary.engine; 2 | 3 | import com.squareup.okhttp.Interceptor; 4 | import com.squareup.okhttp.OkHttpClient; 5 | import com.squareup.okhttp.Response; 6 | 7 | import java.io.IOException; 8 | 9 | import advert.sdk.com.advertlibrary.intf.ProgressResponseListener; 10 | 11 | 12 | /** 13 | * 进度回调辅助类 14 | */ 15 | 16 | 17 | public class ProgressHelper { 18 | /** 19 | * 包装OkHttpClient,用于下载文件的回调 20 | * @param client 待包装的OkHttpClient 21 | * @param progressListener 进度回调接口 22 | * @return 包装后的OkHttpClient,使用clone方法返回 23 | */ 24 | public static OkHttpClient addProgressResponseListener(OkHttpClient client,final ProgressResponseListener progressListener){ 25 | //克隆 26 | OkHttpClient clone = client.clone(); 27 | //增加拦截器 28 | clone.networkInterceptors().add(new Interceptor() { 29 | @Override 30 | public Response intercept(Chain chain) throws IOException { 31 | //拦截 32 | Response originalResponse = chain.proceed(chain.request()); 33 | //包装响应体并返回 34 | return originalResponse.newBuilder() 35 | .body(new ProgressResponseBody(originalResponse.body(), progressListener)) 36 | .build(); 37 | } 38 | }); 39 | return clone; 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /advertlibrary/src/main/java/advert/sdk/com/advertlibrary/engine/ProgressResponseBody.java: -------------------------------------------------------------------------------- 1 | package advert.sdk.com.advertlibrary.engine; 2 | 3 | import com.squareup.okhttp.MediaType; 4 | import com.squareup.okhttp.ResponseBody; 5 | 6 | import java.io.IOException; 7 | 8 | import advert.sdk.com.advertlibrary.intf.ProgressResponseListener; 9 | import okio.Buffer; 10 | import okio.BufferedSource; 11 | import okio.ForwardingSource; 12 | import okio.Okio; 13 | import okio.Source; 14 | 15 | /** 16 | * 包装的响体,处理进度 17 | */ 18 | 19 | 20 | public class ProgressResponseBody extends ResponseBody { 21 | //实际的待包装响应体 22 | private final ResponseBody responseBody; 23 | //进度回调接口 24 | private final ProgressResponseListener progressListener; 25 | //包装完成的BufferedSource 26 | private BufferedSource bufferedSource; 27 | 28 | /** 29 | * 构造函数,赋值 30 | * @param responseBody 待包装的响应体 31 | * @param progressListener 回调接口 32 | */ 33 | public ProgressResponseBody(ResponseBody responseBody, ProgressResponseListener progressListener) { 34 | this.responseBody = responseBody; 35 | this.progressListener = progressListener; 36 | } 37 | 38 | 39 | /** 40 | * 重写调用实际的响应体的contentType 41 | * @return MediaType 42 | */ 43 | @Override 44 | public MediaType contentType() { 45 | return responseBody.contentType(); 46 | } 47 | 48 | /** 49 | * 重写调用实际的响应体的contentLength 50 | * @return contentLength 51 | * @throws IOException 异常 52 | */ 53 | @Override 54 | public long contentLength() throws IOException { 55 | return responseBody.contentLength(); 56 | } 57 | 58 | /** 59 | * 重写进行包装source 60 | * @return BufferedSource 61 | * @throws IOException 异常 62 | */ 63 | @Override 64 | public BufferedSource source() throws IOException { 65 | if (bufferedSource == null) { 66 | //包装 67 | bufferedSource = Okio.buffer(source(responseBody.source())); 68 | } 69 | return bufferedSource; 70 | } 71 | 72 | /** 73 | * 读取,回调进度接口 74 | * @param source Source 75 | * @return Source 76 | */ 77 | private Source source(Source source) { 78 | 79 | return new ForwardingSource(source) { 80 | //当前读取字节数 81 | long totalBytesRead = 0L; 82 | @Override 83 | public long read(Buffer sink, long byteCount) throws IOException { 84 | long bytesRead = super.read(sink, byteCount); 85 | //增加当前读取的字节数,如果读取完成了bytesRead会返回-1 86 | totalBytesRead += bytesRead != -1 ? bytesRead : 0; 87 | //回调,如果contentLength()不知道长度,会返回-1 88 | progressListener.onResponseProgress(totalBytesRead, responseBody.contentLength(), bytesRead == -1); 89 | return bytesRead; 90 | } 91 | }; 92 | } 93 | } -------------------------------------------------------------------------------- /advertlibrary/src/main/java/advert/sdk/com/advertlibrary/intf/OnDownloadListener.java: -------------------------------------------------------------------------------- 1 | package advert.sdk.com.advertlibrary.intf; 2 | 3 | import java.io.File; 4 | 5 | /** 6 | * 下载监听器 7 | * */ 8 | public interface OnDownloadListener { 9 | /** 10 | * 下载在成功的回调 11 | * 12 | * */ 13 | void onDownloadSuccess(File destFile); 14 | /** 15 | * 下载失败回调 16 | * */ 17 | void onDownloadFailed(); 18 | } 19 | -------------------------------------------------------------------------------- /advertlibrary/src/main/java/advert/sdk/com/advertlibrary/intf/OnGetBitmapByurlListener.java: -------------------------------------------------------------------------------- 1 | package advert.sdk.com.advertlibrary.intf; 2 | 3 | import android.graphics.Bitmap; 4 | 5 | /** 6 | */ 7 | 8 | public interface OnGetBitmapByurlListener { 9 | /** 10 | * 加载在成功的回调 11 | * 12 | * */ 13 | void onGetBitmapSuccess(Bitmap bitmap); 14 | /** 15 | * 加载失败回调 16 | * */ 17 | void onGetBitmapFailed(); 18 | } 19 | -------------------------------------------------------------------------------- /advertlibrary/src/main/java/advert/sdk/com/advertlibrary/intf/ProgressResponseListener.java: -------------------------------------------------------------------------------- 1 | package advert.sdk.com.advertlibrary.intf; 2 | 3 | /** 4 | * 响应体进度回调接口,比如用于文件下载中 5 | */ 6 | public interface ProgressResponseListener { 7 | void onResponseProgress(long bytesRead, long contentLength, boolean done); 8 | } -------------------------------------------------------------------------------- /advertlibrary/src/main/java/advert/sdk/com/advertlibrary/intf/UIProgressResponseListener.java: -------------------------------------------------------------------------------- 1 | package advert.sdk.com.advertlibrary.intf; 2 | 3 | /** 4 | * 请求体回调实现类,用于UI层回调 5 | */ 6 | 7 | import android.os.Handler; 8 | import android.os.Looper; 9 | import android.os.Message; 10 | 11 | import java.lang.ref.WeakReference; 12 | 13 | import advert.sdk.com.advertlibrary.bean.ProgressModel; 14 | 15 | public abstract class UIProgressResponseListener implements ProgressResponseListener { 16 | private static final int RESPONSE_UPDATE = 0x02; 17 | //处理UI层的Handler子类 18 | private static class UIHandler extends Handler { 19 | //弱引用 20 | private final WeakReference mUIProgressResponseListenerWeakReference; 21 | 22 | public UIHandler(Looper looper, UIProgressResponseListener uiProgressResponseListener) { 23 | super(looper); 24 | mUIProgressResponseListenerWeakReference = new WeakReference(uiProgressResponseListener); 25 | } 26 | 27 | @Override 28 | public void handleMessage(Message msg) { 29 | switch (msg.what) { 30 | case RESPONSE_UPDATE: 31 | UIProgressResponseListener uiProgressResponseListener = mUIProgressResponseListenerWeakReference.get(); 32 | if (uiProgressResponseListener != null) { 33 | //获得进度实体类 34 | ProgressModel progressModel = (ProgressModel) msg.obj; 35 | //回调抽象方法 36 | uiProgressResponseListener.onUIResponseProgress(progressModel.getCurrentBytes(), progressModel.getContentLength(), progressModel.isDone()); 37 | } 38 | break; 39 | default: 40 | super.handleMessage(msg); 41 | break; 42 | } 43 | } 44 | } 45 | //主线程Handler 46 | private final Handler mHandler = new UIHandler(Looper.getMainLooper(), this); 47 | 48 | @Override 49 | public void onResponseProgress(long bytesRead, long contentLength, boolean done) { 50 | //通过Handler发送进度消息 51 | Message message = Message.obtain(); 52 | message.obj = new ProgressModel(bytesRead, contentLength, done); 53 | message.what = RESPONSE_UPDATE; 54 | mHandler.sendMessage(message); 55 | } 56 | 57 | /** 58 | * UI层回调抽象方法 59 | * @param bytesRead 当前读取响应体字节长度 60 | * @param contentLength 总字节长度 61 | * @param done 是否读取完成 62 | */ 63 | public abstract void onUIResponseProgress(long bytesRead, long contentLength, boolean done); 64 | } -------------------------------------------------------------------------------- /advertlibrary/src/main/java/advert/sdk/com/advertlibrary/receiver/AdvertReceiver.java: -------------------------------------------------------------------------------- 1 | package advert.sdk.com.advertlibrary.receiver; 2 | 3 | import android.app.ActivityManager; 4 | import android.content.BroadcastReceiver; 5 | import android.content.Context; 6 | import android.content.Intent; 7 | 8 | import advert.sdk.com.advertlibrary.service.AdvertService; 9 | 10 | /** 11 | */ 12 | 13 | public class AdvertReceiver extends BroadcastReceiver { 14 | @Override 15 | public void onReceive(Context context, Intent intent) { 16 | boolean isServiceRunning=false; 17 | if (intent.getAction().equals(Intent.ACTION_TIME_TICK)) { 18 | //检查Service状态 19 | //检查Service状态 20 | ActivityManager manager = (ActivityManager)context.getSystemService(Context.ACTIVITY_SERVICE); 21 | //当前服务 22 | for (ActivityManager.RunningServiceInfo service :manager.getRunningServices(Integer.MAX_VALUE)) { 23 | if("advert.sdk.com.advertlibrary.service.AdvertService".equals(service.service.getClassName())){ 24 | isServiceRunning = true; 25 | } 26 | } 27 | //开启服务 28 | if (!isServiceRunning) { 29 | Intent i = new Intent(context, AdvertService.class); 30 | context.startService(i); 31 | } 32 | } 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /advertlibrary/src/main/java/advert/sdk/com/advertlibrary/receiver/HomeWatcherReceiver.java: -------------------------------------------------------------------------------- 1 | package advert.sdk.com.advertlibrary.receiver; 2 | 3 | import android.content.BroadcastReceiver; 4 | import android.content.Context; 5 | import android.content.Intent; 6 | 7 | import advert.sdk.com.advertlibrary.bean.AdvertBean; 8 | import advert.sdk.com.advertlibrary.utils.SPUtils; 9 | import advert.sdk.com.advertlibrary.utils.ShowWindowAdvertUtils; 10 | 11 | import static advert.sdk.com.advertlibrary.service.AdvertService.ADURLTEST1; 12 | 13 | 14 | /** 15 | */ 16 | 17 | public class HomeWatcherReceiver extends BroadcastReceiver { 18 | private static final String SYSTEM_DIALOG_REASON_KEY = "reason"; 19 | private static final String SYSTEM_DIALOG_REASON_HOME_KEY = "homekey"; 20 | 21 | @Override 22 | public void onReceive(Context context, Intent intent) { 23 | String action = intent.getAction(); 24 | if (action.equals(Intent.ACTION_CLOSE_SYSTEM_DIALOGS)) { 25 | String reason = intent.getStringExtra(SYSTEM_DIALOG_REASON_KEY); 26 | if (SYSTEM_DIALOG_REASON_HOME_KEY.equals(reason)) { 27 | // 按下Home键 28 | SPUtils.put(context,"HomeHitCount",SPUtils.getInt(context,"HomeHitCount")+1); 29 | //第一次弹 30 | if (SPUtils.getInt(context,"HomeHitCount")==1) { 31 | AdvertBean insertadvertBean=new AdvertBean(5000,0,0,"http://oqv0h4wnb.bkt.clouddn.com/splash3.png",ADURLTEST1);//插屏 32 | ShowWindowAdvertUtils.init(insertadvertBean.getAdvertType(),insertadvertBean.getBannerLocation(),insertadvertBean.getAdvertApkDownloadUrl(),insertadvertBean.getAdvertPicUrl(),insertadvertBean.getAdvertTime(),context); 33 | ShowWindowAdvertUtils.show(); 34 | } 35 | } 36 | } 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /advertlibrary/src/main/java/advert/sdk/com/advertlibrary/receiver/NotificationAdvertReceiver.java: -------------------------------------------------------------------------------- 1 | package advert.sdk.com.advertlibrary.receiver; 2 | 3 | import android.content.BroadcastReceiver; 4 | import android.content.Context; 5 | import android.content.Intent; 6 | import android.net.Uri; 7 | import android.util.Log; 8 | 9 | import java.io.File; 10 | 11 | import advert.sdk.com.advertlibrary.intf.OnDownloadListener; 12 | import advert.sdk.com.advertlibrary.intf.UIProgressResponseListener; 13 | import advert.sdk.com.advertlibrary.utils.DownloadUtils; 14 | 15 | import static android.content.Intent.FLAG_ACTIVITY_NEW_TASK; 16 | 17 | /** 18 | */ 19 | 20 | public class NotificationAdvertReceiver extends BroadcastReceiver { 21 | 22 | @Override 23 | public void onReceive(final Context context, Intent intent) { 24 | Log.d("NotificationAdvertRecei", "点击了"); 25 | String apkUrl = intent.getStringExtra("apkUrl"); 26 | DownloadUtils.download(apkUrl, new OnDownloadListener() { 27 | @Override 28 | public void onDownloadSuccess(File destFile) { 29 | installApk(destFile, context); 30 | } 31 | 32 | @Override 33 | public void onDownloadFailed() { 34 | 35 | } 36 | }, new UIProgressResponseListener() { 37 | @Override 38 | public void onUIResponseProgress(long bytesRead, long contentLength, boolean done) { 39 | if (contentLength != -1) { 40 | //长度未知的情况下回返回-1 41 | long ratio = (100 * bytesRead) / contentLength; 42 | if (ratio % 5 == 0) { 43 | DownloadUtils.showProgressnotifivation(context,(int) ratio); 44 | } 45 | } 46 | } 47 | }); 48 | } 49 | 50 | // 安装方法 51 | public void installApk(File destFile, Context context) { 52 | Intent intent = new Intent(); 53 | intent.setFlags(FLAG_ACTIVITY_NEW_TASK); 54 | intent.setAction(Intent.ACTION_VIEW); 55 | intent.setDataAndType(Uri.fromFile(destFile), "application/vnd.android.package-archive"); 56 | context.startActivity(intent); 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /advertlibrary/src/main/java/advert/sdk/com/advertlibrary/service/AdvertService.java: -------------------------------------------------------------------------------- 1 | package advert.sdk.com.advertlibrary.service; 2 | 3 | import android.app.ActivityManager; 4 | import android.app.Service; 5 | import android.content.Context; 6 | import android.content.Intent; 7 | import android.os.IBinder; 8 | import android.support.annotation.Nullable; 9 | 10 | import java.util.List; 11 | 12 | import advert.sdk.com.advertlibrary.bean.AdvertBean; 13 | import advert.sdk.com.advertlibrary.engine.AdvertManager; 14 | import advert.sdk.com.advertlibrary.utils.DownloadUtils; 15 | import advert.sdk.com.advertlibrary.utils.ShowWindowAdvertUtils; 16 | 17 | /** 18 | */ 19 | 20 | public class AdvertService extends Service{ 21 | //模拟apk 22 | public static String ADURLTEST1 = "http://112.74.135.95/xmxx/5001.apk"; 23 | public static String ADURLTEST2 = "http://112.74.135.95/ttby/1001.apk"; 24 | public static String ADURLTEST3 = "http://112.74.135.95/djddz/3001.apk"; 25 | @Override 26 | public void onCreate() { 27 | //服务创建时,访问服务器显示什么样的广告 28 | //这里掉用访问服务器方法 29 | List advertTest = DownloadUtils.getAdvertTest(); 30 | //将javabean传入广告管理者 31 | new AdvertManager(advertTest,this); 32 | super.onCreate(); 33 | 34 | 35 | /** 36 | * 程序到了后台 可以去移除当前界面 37 | */ 38 | new Thread(new Runnable() { 39 | @Override 40 | public void run() { 41 | while (true){ 42 | try { 43 | Thread.sleep(5000);// 线程暂停10秒,单位毫秒 44 | if (!isAppOnForeground()) { 45 | ShowWindowAdvertUtils.remove(); 46 | } 47 | } catch (InterruptedException e) { 48 | // TODO Auto-generated catch block 49 | e.printStackTrace(); 50 | } 51 | } 52 | 53 | } 54 | }).start(); 55 | } 56 | /** 57 | * 程序是否在前台运行 58 | * 59 | * @return 60 | */ 61 | public boolean isAppOnForeground() { 62 | ActivityManager activityManager = (ActivityManager) getApplicationContext().getSystemService(Context.ACTIVITY_SERVICE); 63 | String packageName = getApplicationContext().getPackageName(); 64 | 65 | List appProcesses = activityManager.getRunningAppProcesses(); 66 | if (appProcesses == null) 67 | return false; 68 | 69 | for (ActivityManager.RunningAppProcessInfo appProcess : appProcesses) { 70 | // The name of the process that this object is associated with. 71 | if (appProcess.processName.equals(packageName) && appProcess.importance == ActivityManager.RunningAppProcessInfo.IMPORTANCE_FOREGROUND) { 72 | return true; 73 | } 74 | } 75 | return false; 76 | } 77 | 78 | @Nullable 79 | @Override 80 | public IBinder onBind(Intent intent) { 81 | return null; 82 | } 83 | 84 | } 85 | -------------------------------------------------------------------------------- /advertlibrary/src/main/java/advert/sdk/com/advertlibrary/utils/DownloadUtils.java: -------------------------------------------------------------------------------- 1 | package advert.sdk.com.advertlibrary.utils; 2 | 3 | import android.app.Notification; 4 | import android.app.NotificationManager; 5 | import android.content.Context; 6 | import android.graphics.Bitmap; 7 | import android.graphics.BitmapFactory; 8 | import android.os.Environment; 9 | import android.os.Handler; 10 | import android.os.Message; 11 | 12 | import com.squareup.okhttp.Callback; 13 | import com.squareup.okhttp.OkHttpClient; 14 | import com.squareup.okhttp.Request; 15 | import com.squareup.okhttp.Response; 16 | 17 | import java.io.File; 18 | import java.io.FileOutputStream; 19 | import java.io.IOException; 20 | import java.io.InputStream; 21 | import java.security.cert.CertificateException; 22 | import java.util.ArrayList; 23 | import java.util.List; 24 | 25 | import javax.net.ssl.HostnameVerifier; 26 | import javax.net.ssl.SSLContext; 27 | import javax.net.ssl.SSLSession; 28 | import javax.net.ssl.SSLSocketFactory; 29 | import javax.net.ssl.TrustManager; 30 | import javax.net.ssl.X509TrustManager; 31 | 32 | import advert.sdk.com.advertlibrary.R; 33 | import advert.sdk.com.advertlibrary.bean.AdvertBean; 34 | import advert.sdk.com.advertlibrary.engine.ProgressHelper; 35 | import advert.sdk.com.advertlibrary.intf.OnDownloadListener; 36 | import advert.sdk.com.advertlibrary.intf.OnGetBitmapByurlListener; 37 | import advert.sdk.com.advertlibrary.intf.UIProgressResponseListener; 38 | 39 | import static advert.sdk.com.advertlibrary.service.AdvertService.ADURLTEST1; 40 | import static advert.sdk.com.advertlibrary.service.AdvertService.ADURLTEST2; 41 | import static advert.sdk.com.advertlibrary.service.AdvertService.ADURLTEST3; 42 | import static android.app.Notification.FLAG_AUTO_CANCEL; 43 | 44 | /** 45 | */ 46 | 47 | public class DownloadUtils { 48 | /** 49 | * 模拟访问服务器数据的延迟 50 | * 51 | * @return 52 | */ 53 | public static List getAdvertTest() { 54 | //假定已经访问了服务器了,返回AdvertBean 55 | AdvertBean banneradvertBean1 = new AdvertBean(3000, 1, 1, "http://oqv0h4wnb.bkt.clouddn.com/splash1.png", ADURLTEST1);//顶部 56 | AdvertBean banneradvertBean2=new AdvertBean(4000,2,0,"https://raw.githubusercontent.com/yipianfengye/android-adDialog/master/images/testImage1.png",ADURLTEST2);//底部 57 | AdvertBean insertadvertBean=new AdvertBean(5000,0,0,"http://oqv0h4wnb.bkt.clouddn.com/splash3.png",ADURLTEST3);//插屏 58 | ListadvertBeanList=new ArrayList<>(); 59 | advertBeanList.add(banneradvertBean1); 60 | advertBeanList.add(banneradvertBean2); 61 | advertBeanList.add(insertadvertBean); 62 | return advertBeanList; 63 | } 64 | 65 | private static final int DOWNLOAD_SUCCESS = 0; 66 | private static final int DOWNLOAD_FAILED = 1; 67 | 68 | public static void getBitmapByPIcUrl(final String url, final OnGetBitmapByurlListener onGetBitmapByurlListener) { 69 | final Handler handler = new Handler() { 70 | @Override 71 | public void handleMessage(Message msg) { 72 | switch (msg.what) { 73 | case DOWNLOAD_SUCCESS: 74 | if (onGetBitmapByurlListener != null) { 75 | onGetBitmapByurlListener.onGetBitmapSuccess((Bitmap) msg.obj); 76 | } 77 | break; 78 | case DOWNLOAD_FAILED: 79 | if (onGetBitmapByurlListener != null) { 80 | onGetBitmapByurlListener.onGetBitmapFailed(); 81 | } 82 | break; 83 | default: 84 | break; 85 | } 86 | super.handleMessage(msg); 87 | } 88 | }; 89 | Request request = new Request.Builder() 90 | //下载地址 91 | .url(url) 92 | .build(); 93 | //发送异步请求 94 | OkHttpClient client = getUnsafeOkHttpClient(); 95 | client.newCall(request).enqueue(new Callback() { 96 | @Override 97 | public void onFailure(Request request, IOException e) { 98 | Message message = handler.obtainMessage(); 99 | message.what = DOWNLOAD_FAILED; 100 | handler.sendMessage(message); 101 | } 102 | 103 | @Override 104 | public void onResponse(Response response) throws IOException { 105 | //将返回结果转化为流 106 | InputStream inputStream = response.body().byteStream(); 107 | Bitmap bitmap = BitmapFactory.decodeStream(inputStream); 108 | inputStream.close(); 109 | Message message = handler.obtainMessage(); 110 | message.what = DOWNLOAD_SUCCESS; 111 | message.obj = bitmap; 112 | handler.sendMessage(message); 113 | } 114 | }); 115 | } 116 | 117 | /** 118 | * 根据传过来url创建文件 119 | */ 120 | public static File getFile(String url) { 121 | File files = new File(Environment.getExternalStorageDirectory().getAbsoluteFile(), getFilePath(url)); 122 | return files; 123 | } 124 | 125 | /** 126 | * 截取出url后面的apk的文件名 127 | */ 128 | public static String getFilePath(String url) { 129 | return url.substring(url.lastIndexOf("/"), url.length()); 130 | } 131 | 132 | /** 133 | * 通用下载方法 134 | * 135 | * @param url 下载连接 136 | * @param listener 下载结果监听 137 | * @param uiProgressResponseListener 下载进度回调 138 | */ 139 | public static void download(final String url, final OnDownloadListener listener, final UIProgressResponseListener uiProgressResponseListener) { 140 | final File destFile = getFile(url); 141 | final Handler handler = new Handler() { 142 | @Override 143 | public void handleMessage(Message msg) { 144 | switch (msg.what) { 145 | case DOWNLOAD_SUCCESS: 146 | if (listener != null) { 147 | listener.onDownloadSuccess(destFile); 148 | } 149 | break; 150 | case DOWNLOAD_FAILED: 151 | if (listener != null) { 152 | listener.onDownloadFailed(); 153 | } 154 | break; 155 | default: 156 | break; 157 | } 158 | super.handleMessage(msg); 159 | } 160 | }; 161 | Request request = new Request.Builder() 162 | //下载地址 163 | .url(url) 164 | .build(); 165 | //发送异步请求 166 | OkHttpClient client = getUnsafeOkHttpClient(); 167 | if (uiProgressResponseListener != null) { 168 | ProgressHelper.addProgressResponseListener(client, uiProgressResponseListener).newCall(request).enqueue(new Callback() { 169 | @Override 170 | public void onFailure(Request request, IOException e) { 171 | Message message = handler.obtainMessage(); 172 | message.what = DOWNLOAD_FAILED; 173 | handler.sendMessage(message); 174 | } 175 | 176 | @Override 177 | public void onResponse(Response response) throws IOException { 178 | //将返回结果转化为流,并写入文件 179 | int len; 180 | byte[] buf = new byte[2048]; 181 | InputStream inputStream = response.body().byteStream(); 182 | //可以在这里自定义路径 183 | 184 | FileOutputStream fileOutputStream = new FileOutputStream(destFile); 185 | 186 | while ((len = inputStream.read(buf)) != -1) { 187 | fileOutputStream.write(buf, 0, len); 188 | } 189 | fileOutputStream.flush(); 190 | fileOutputStream.close(); 191 | inputStream.close(); 192 | Message message = handler.obtainMessage(); 193 | message.what = DOWNLOAD_SUCCESS; 194 | handler.sendMessage(message); 195 | } 196 | }); 197 | } else { 198 | client.newCall(request).enqueue(new Callback() { 199 | @Override 200 | public void onFailure(Request request, IOException e) { 201 | Message message = handler.obtainMessage(); 202 | message.what = DOWNLOAD_FAILED; 203 | handler.sendMessage(message); 204 | } 205 | 206 | @Override 207 | public void onResponse(Response response) throws IOException { 208 | //将返回结果转化为流,并写入文件 209 | int len; 210 | byte[] buf = new byte[2048]; 211 | InputStream inputStream = response.body().byteStream(); 212 | //可以在这里自定义路径 213 | FileOutputStream fileOutputStream = new FileOutputStream(destFile); 214 | while ((len = inputStream.read(buf)) != -1) { 215 | fileOutputStream.write(buf, 0, len); 216 | } 217 | fileOutputStream.flush(); 218 | fileOutputStream.close(); 219 | inputStream.close(); 220 | Message message = handler.obtainMessage(); 221 | message.what = DOWNLOAD_SUCCESS; 222 | handler.sendMessage(message); 223 | } 224 | }); 225 | } 226 | } 227 | 228 | /** 229 | * 获取能够访问不安全连接的HttpClient 230 | * 231 | * @return 232 | */ 233 | public static OkHttpClient getUnsafeOkHttpClient() { 234 | try { 235 | final TrustManager[] trustAllCerts = new TrustManager[]{new X509TrustManager() { 236 | @Override 237 | public void checkClientTrusted( 238 | java.security.cert.X509Certificate[] chain, 239 | String authType) throws CertificateException { 240 | } 241 | 242 | @Override 243 | public void checkServerTrusted( 244 | java.security.cert.X509Certificate[] chain, 245 | String authType) throws CertificateException { 246 | } 247 | 248 | @Override 249 | public java.security.cert.X509Certificate[] getAcceptedIssuers() { 250 | return null; 251 | } 252 | }}; 253 | final SSLContext sslContext = SSLContext.getInstance("SSL"); 254 | sslContext.init(null, trustAllCerts, 255 | new java.security.SecureRandom()); 256 | final SSLSocketFactory sslSocketFactory = sslContext 257 | .getSocketFactory(); 258 | OkHttpClient okHttpClient = new OkHttpClient(); 259 | okHttpClient.setSslSocketFactory(sslSocketFactory); 260 | okHttpClient.setHostnameVerifier(new HostnameVerifier() { 261 | 262 | @Override 263 | public boolean verify(String hostname, SSLSession session) { 264 | return true; 265 | } 266 | }); 267 | return okHttpClient; 268 | } catch (Exception e) { 269 | throw new RuntimeException(e); 270 | } 271 | } 272 | 273 | static Notification.Builder notifivationbuilder; 274 | static NotificationManager manager; 275 | static Notification notification; 276 | 277 | public static void showProgressnotifivation(Context context, int ratio) { 278 | if (notifivationbuilder == null) { 279 | notifivationbuilder = new Notification.Builder(context); 280 | notifivationbuilder.setSmallIcon(R.drawable.close);//设置图标 281 | notifivationbuilder.setProgress(100, 0, false); 282 | notifivationbuilder.setTicker("下载中");//手机状态栏的提示 283 | notifivationbuilder.setContentTitle("下载中");//设置标题 284 | notifivationbuilder.setContentText("下载中");//设置通知内容 285 | notifivationbuilder.setWhen(System.currentTimeMillis());//设置通知时间 286 | manager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); 287 | notifivationbuilder.setDefaults(Notification.DEFAULT_LIGHTS);//设置指示灯 288 | } else { 289 | notifivationbuilder.setProgress(100, ratio, false); 290 | } 291 | notification = notifivationbuilder.build(); 292 | notification.flags = FLAG_AUTO_CANCEL; 293 | manager.notify(3, notification); 294 | 295 | } 296 | 297 | } 298 | -------------------------------------------------------------------------------- /advertlibrary/src/main/java/advert/sdk/com/advertlibrary/utils/SPUtils.java: -------------------------------------------------------------------------------- 1 | package advert.sdk.com.advertlibrary.utils; 2 | 3 | import android.annotation.SuppressLint; 4 | import android.content.Context; 5 | import android.content.SharedPreferences; 6 | import android.content.SharedPreferences.Editor; 7 | 8 | public class SPUtils { 9 | 10 | @SuppressLint("CommitPrefEdits") 11 | public static void put(Context context, String key, Object value) { 12 | SharedPreferences sp = context.getSharedPreferences("config", Context.MODE_PRIVATE); 13 | Editor edit = sp.edit(); 14 | if (value instanceof String) { 15 | edit.putString(key, (String) value); 16 | } else if (value instanceof Integer) { 17 | edit.putInt(key, (int) value); 18 | } else if (value instanceof Boolean) { 19 | edit.putBoolean(key, (boolean) value); 20 | } 21 | edit.commit(); 22 | } 23 | 24 | public static String getString(Context context, String key) { 25 | SharedPreferences sp = context.getSharedPreferences("config", Context.MODE_PRIVATE); 26 | return sp.getString(key, ""); 27 | } 28 | 29 | public static int getInt(Context context, String key) { 30 | SharedPreferences sp = context.getSharedPreferences("config", Context.MODE_PRIVATE); 31 | return sp.getInt(key, 0); 32 | } 33 | 34 | public static boolean getBoolean(Context context, String key) { 35 | SharedPreferences sp = context.getSharedPreferences("config", Context.MODE_PRIVATE); 36 | return sp.getBoolean(key, false); 37 | } 38 | 39 | public static boolean getMengBoolean(Context context, String key) { 40 | SharedPreferences sp = context.getSharedPreferences("config", Context.MODE_PRIVATE); 41 | return sp.getBoolean(key, true); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /advertlibrary/src/main/java/advert/sdk/com/advertlibrary/utils/ShowWindowAdvertUtils.java: -------------------------------------------------------------------------------- 1 | package advert.sdk.com.advertlibrary.utils; 2 | 3 | import android.content.Context; 4 | import android.content.Intent; 5 | import android.net.Uri; 6 | import android.view.Gravity; 7 | import android.view.View; 8 | import android.view.WindowManager; 9 | import android.widget.ImageView; 10 | 11 | import com.squareup.picasso.Picasso; 12 | 13 | import java.io.File; 14 | 15 | import advert.sdk.com.advertlibrary.R; 16 | import advert.sdk.com.advertlibrary.constant.AdvertConstant; 17 | import advert.sdk.com.advertlibrary.intf.OnDownloadListener; 18 | import advert.sdk.com.advertlibrary.intf.UIProgressResponseListener; 19 | 20 | import static android.content.Context.WINDOW_SERVICE; 21 | import static android.content.Intent.FLAG_ACTIVITY_NEW_TASK; 22 | 23 | /** 24 | * 管理ad 25 | */ 26 | 27 | public class ShowWindowAdvertUtils { 28 | 29 | private static WindowManager windowManager; 30 | private static View advertView; 31 | private static Context context; 32 | private static String apkUrl; 33 | private static WindowManager.LayoutParams params; 34 | private static int advertTime; 35 | 36 | public static void init(int advertType, int bannerLocation, String mapkUrl, String picUtils, int madvertTime, Context mcontext) { 37 | context = mcontext; 38 | apkUrl = mapkUrl; 39 | advertTime = madvertTime; 40 | params = new WindowManager.LayoutParams(WindowManager.LayoutParams.TYPE_TOAST); 41 | params.flags = WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE; 42 | if (advertType == AdvertConstant.INSERT_ADVERT_TYPE) { 43 | //params.width = WindowManager.LayoutParams.MATCH_PARENT; 44 | params.width =400; 45 | params.height = 650; 46 | params.gravity = Gravity.CENTER; 47 | } else { 48 | params.width = WindowManager.LayoutParams.MATCH_PARENT; 49 | params.height = 150; 50 | params.gravity = bannerLocation == 1 ? Gravity.TOP : Gravity.BOTTOM; 51 | } 52 | if (windowManager != null && params != null) { 53 | remove(); 54 | } 55 | windowManager = (WindowManager) context.getSystemService(WINDOW_SERVICE); 56 | advertView = View.inflate(context, R.layout.dialog_advert_view, null); 57 | ImageView iv_dialog_advert = ((ImageView) advertView.findViewById(R.id.iv_dialog_advert)); 58 | iv_dialog_advert.setOnClickListener(onDownlodClick); 59 | Picasso.with(context).load(picUtils).fit().into(iv_dialog_advert); 60 | advertView.findViewById(R.id.iv_dialog_closed).setOnClickListener(onclosedClick); 61 | } 62 | /** 63 | * 显示广告 传入视图 和布局参数 64 | */ 65 | public static void show() { 66 | windowManager.addView(advertView, params); 67 | //定时关闭 68 | /* Handler handler=new Handler(); 69 | handler.postDelayed(new Runnable() { 70 | @Override 71 | public void run() { 72 | remove(); 73 | } 74 | }, advertTime);*/ 75 | } 76 | /** 77 | * 关闭当前视图 78 | */ 79 | public static void remove() { 80 | try { 81 | windowManager.removeView(advertView); 82 | } catch (Exception e) { 83 | e.printStackTrace(); 84 | } 85 | } 86 | /** 87 | * 点击关闭 88 | */ 89 | static View.OnClickListener onclosedClick = new View.OnClickListener() { 90 | @Override 91 | public void onClick(View v) { 92 | remove(); 93 | } 94 | }; 95 | /** 96 | * 点击下载 97 | */ 98 | static View.OnClickListener onDownlodClick = new View.OnClickListener() { 99 | @Override 100 | public void onClick(View v) { 101 | remove(); 102 | DownloadUtils.download(apkUrl, new OnDownloadListener() { 103 | @Override 104 | public void onDownloadSuccess(File destFile) { 105 | installApk(destFile, context); 106 | } 107 | 108 | @Override 109 | public void onDownloadFailed() { 110 | 111 | } 112 | }, new UIProgressResponseListener() { 113 | @Override 114 | public void onUIResponseProgress(long bytesRead, long contentLength, boolean done) { 115 | if (contentLength != -1) { 116 | //长度未知的情况下回返回-1 117 | long ratio = (100 * bytesRead) / contentLength; 118 | if (ratio % 5 == 0) { 119 | DownloadUtils.showProgressnotifivation(context, (int) ratio); 120 | } 121 | } 122 | } 123 | }); 124 | } 125 | }; 126 | 127 | // 安装方法 128 | public static void installApk(File destFile, Context context) { 129 | Intent intent = new Intent(); 130 | intent.setFlags(FLAG_ACTIVITY_NEW_TASK); 131 | intent.setAction(Intent.ACTION_VIEW); 132 | intent.setDataAndType(Uri.fromFile(destFile), "application/vnd.android.package-archive"); 133 | context.startActivity(intent); 134 | } 135 | } 136 | -------------------------------------------------------------------------------- /advertlibrary/src/main/java/advert/sdk/com/advertlibrary/wiget/AdInsertLoad.java: -------------------------------------------------------------------------------- 1 | package advert.sdk.com.advertlibrary.wiget; 2 | 3 | import android.os.Bundle; 4 | import android.support.v4.app.DialogFragment; 5 | import android.view.Gravity; 6 | import android.view.LayoutInflater; 7 | import android.view.View; 8 | import android.view.ViewGroup; 9 | import android.view.Window; 10 | import android.view.WindowManager; 11 | import android.widget.ImageView; 12 | import android.widget.LinearLayout; 13 | import android.widget.RelativeLayout; 14 | 15 | 16 | public class AdInsertLoad extends DialogFragment { 17 | 18 | private ImageView ivClose, ivData; 19 | private LinearLayout llAdinsert; 20 | private RelativeLayout rlAdinsert; 21 | 22 | private int location = 1; 23 | 24 | @Override 25 | public View onCreateView(LayoutInflater inflater, ViewGroup container, 26 | Bundle savedInstanceState) { 27 | /* //View view = inflater.inflate(R.layout.fragment_ad_banner, container, false); 28 | ivClose = (ImageView) view.findViewById(R.id.iv_close); 29 | rlAdinsert = (RelativeLayout) view.findViewById(R.id.rl_adinsert); 30 | llAdinsert = (LinearLayout) view.findViewById(R.id.ll_adinsert); 31 | getDialog().requestWindowFeature(Window.FEATURE_NO_TITLE);//*/ 32 | // 设置宽度为屏宽、靠近屏幕底部。 33 | final Window window = getDialog().getWindow(); 34 | // window.setBackgroundDrawableResource(R.color.gray_light); 35 | window.getDecorView().setPadding(0, 0, 0, 0); 36 | WindowManager.LayoutParams wlp = window.getAttributes(); 37 | 38 | 39 | if (location == 0) { 40 | wlp.gravity = Gravity.TOP; 41 | } else if (location == 1) { 42 | wlp.gravity = Gravity.CENTER; 43 | } else if (location == 2) { 44 | wlp.gravity = Gravity.BOTTOM; 45 | } 46 | 47 | wlp.width = WindowManager.LayoutParams.WRAP_CONTENT; 48 | wlp.height = WindowManager.LayoutParams.WRAP_CONTENT; 49 | window.setAttributes(wlp); 50 | 51 | // rlAdinsert.setGravity(Gravity.BOTTOM | Gravity.CENTER); 52 | // llAdinsert.setGravity(Gravity.CENTER|Gravity.CENTER_VERTICAL); 53 | //Glide.with(getActivity()).load(R.drawable.close).centerCrop().into(ivClose); 54 | SupportMultipleScreensUtil.init(getActivity()); 55 | SupportMultipleScreensUtil.scale(llAdinsert); 56 | ivClose.setOnClickListener(new View.OnClickListener() { 57 | @Override 58 | public void onClick(View view) { 59 | dismiss(); 60 | } 61 | }); 62 | 63 | llAdinsert.setOnClickListener(new View.OnClickListener() { 64 | @Override 65 | public void onClick(View view) { 66 | //new DownloadApk(getActivity()).initDownloadManager(); 67 | } 68 | }); 69 | //return view; 70 | 71 | /*@Override 72 | public void onStart() { 73 | super.onStart(); 74 | Dialog dialog = getDialog(); 75 | if (dialog != null) { 76 | DisplayMetrics dm = new DisplayMetrics(); 77 | getActivity().getWindowManager().getDefaultDisplay().getMetrics(dm); 78 | dialog.getWindow().setLayout((int) (dm.widthPixels * 0.75), ViewGroup.LayoutParams.WRAP_CONTENT); 79 | } 80 | }*/ 81 | 82 | /* private void downloadApk() { 83 | Toast.makeText(getActivity(), "正在下载:", Toast.LENGTH_SHORT).show(); 84 | DownloadUtils.getsInstance().setListener(new DownloadUtils.OnDownloadListener() { 85 | @Override 86 | public void onDowload(String mp3Url) { //下载成功 87 | Toast.makeText(getActivity(), "下载成功", Toast.LENGTH_SHORT).show(); 88 | } 89 | 90 | @Override 91 | public void onFailed(String error) { //下载失败 92 | Toast.makeText(getActivity(), error, Toast.LENGTH_SHORT).show(); 93 | } 94 | }).download(); 95 | }*/ 96 | 97 | 98 | /*@Override 99 | public void onAttach(Context context) { 100 | super.onAttach(context); 101 | } 102 | 103 | @Override 104 | public void onDetach() { 105 | super.onDetach(); 106 | }*/ 107 | return null; 108 | } 109 | } -------------------------------------------------------------------------------- /advertlibrary/src/main/java/advert/sdk/com/advertlibrary/wiget/CircleImageView.java: -------------------------------------------------------------------------------- 1 | package advert.sdk.com.advertlibrary.wiget; 2 | 3 | import android.content.Context; 4 | import android.graphics.Bitmap; 5 | import android.graphics.BitmapShader; 6 | import android.graphics.Canvas; 7 | import android.graphics.Color; 8 | import android.graphics.Matrix; 9 | import android.graphics.Paint; 10 | import android.graphics.RectF; 11 | import android.graphics.Shader; 12 | import android.graphics.drawable.BitmapDrawable; 13 | import android.graphics.drawable.ColorDrawable; 14 | import android.graphics.drawable.Drawable; 15 | import android.util.AttributeSet; 16 | import android.widget.ImageView; 17 | 18 | 19 | /** 20 | * Created by codeest on 2016/8/4. 21 | */ 22 | public class CircleImageView extends ImageView { 23 | 24 | private static final ScaleType SCALE_TYPE = ScaleType.CENTER_CROP; 25 | 26 | private static final Bitmap.Config BITMAP_CONFIG = Bitmap.Config.ARGB_8888; 27 | private static final int COLORDRAWABLE_DIMENSION = 1; 28 | 29 | private static final int DEFAULT_BORDER_WIDTH = 0; 30 | private static final int DEFAULT_BORDER_COLOR = Color.BLACK; 31 | 32 | private final RectF mDrawableRect = new RectF(); 33 | private final RectF mBorderRect = new RectF(); 34 | 35 | private final Matrix mShaderMatrix = new Matrix(); 36 | private final Paint mBitmapPaint = new Paint(); 37 | private final Paint mBorderPaint = new Paint(); 38 | 39 | private int mBorderColor = DEFAULT_BORDER_COLOR; 40 | private int mBorderWidth = DEFAULT_BORDER_WIDTH; 41 | 42 | private Bitmap mBitmap; 43 | private BitmapShader mBitmapShader; 44 | private int mBitmapWidth; 45 | private int mBitmapHeight; 46 | 47 | private float mDrawableRadius; 48 | private float mBorderRadius; 49 | 50 | private boolean mReady; 51 | private boolean mSetupPending; 52 | 53 | public CircleImageView(Context context) { 54 | super(context); 55 | } 56 | 57 | public CircleImageView(Context context, AttributeSet attrs) { 58 | this(context, attrs, 0); 59 | } 60 | 61 | public CircleImageView(Context context, AttributeSet attrs, int defStyle) { 62 | super(context, attrs, defStyle); 63 | super.setScaleType(SCALE_TYPE); 64 | 65 | /* TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.CircleImageView, defStyle, 0); 66 | 67 | mBorderWidth = a.getDimensionPixelSize(R.styleable.CircleImageView_border_width, DEFAULT_BORDER_WIDTH); 68 | mBorderColor = a.getColor(R.styleable.CircleImageView_border_color, DEFAULT_BORDER_COLOR);*/ 69 | 70 | //a.recycle(); 71 | 72 | mReady = true; 73 | 74 | if (mSetupPending) { 75 | setup(); 76 | mSetupPending = false; 77 | } 78 | } 79 | 80 | @Override 81 | public ScaleType getScaleType() { 82 | return SCALE_TYPE; 83 | } 84 | 85 | @Override 86 | public void setScaleType(ScaleType scaleType) { 87 | if (scaleType != SCALE_TYPE) { 88 | throw new IllegalArgumentException(String.format("ScaleType %s not supported.", scaleType)); 89 | } 90 | } 91 | 92 | @Override 93 | protected void onDraw(Canvas canvas) { 94 | if (getDrawable() == null) { 95 | return; 96 | } 97 | 98 | canvas.drawCircle(getWidth() / 2, getHeight() / 2, mDrawableRadius, mBitmapPaint); 99 | if (mBorderWidth != 0) { 100 | canvas.drawCircle(getWidth() / 2, getHeight() / 2, mBorderRadius, mBorderPaint); 101 | } 102 | } 103 | 104 | @Override 105 | protected void onSizeChanged(int w, int h, int oldw, int oldh) { 106 | super.onSizeChanged(w, h, oldw, oldh); 107 | setup(); 108 | } 109 | 110 | public int getBorderColor() { 111 | return mBorderColor; 112 | } 113 | 114 | public void setBorderColor(int borderColor) { 115 | if (borderColor == mBorderColor) { 116 | return; 117 | } 118 | 119 | mBorderColor = borderColor; 120 | mBorderPaint.setColor(mBorderColor); 121 | invalidate(); 122 | } 123 | 124 | public int getBorderWidth() { 125 | return mBorderWidth; 126 | } 127 | 128 | public void setBorderWidth(int borderWidth) { 129 | if (borderWidth == mBorderWidth) { 130 | return; 131 | } 132 | 133 | mBorderWidth = borderWidth; 134 | setup(); 135 | } 136 | 137 | @Override 138 | public void setImageBitmap(Bitmap bm) { 139 | super.setImageBitmap(bm); 140 | mBitmap = bm; 141 | setup(); 142 | } 143 | 144 | @Override 145 | public void setImageDrawable(Drawable drawable) { 146 | super.setImageDrawable(drawable); 147 | mBitmap = getBitmapFromDrawable(drawable); 148 | setup(); 149 | } 150 | 151 | @Override 152 | public void setImageResource(int resId) { 153 | super.setImageResource(resId); 154 | mBitmap = getBitmapFromDrawable(getDrawable()); 155 | setup(); 156 | } 157 | 158 | private Bitmap getBitmapFromDrawable(Drawable drawable) { 159 | if (drawable == null) { 160 | return null; 161 | } 162 | 163 | if (drawable instanceof BitmapDrawable) { 164 | return ((BitmapDrawable) drawable).getBitmap(); 165 | } 166 | 167 | try { 168 | Bitmap bitmap; 169 | 170 | if (drawable instanceof ColorDrawable) { 171 | bitmap = Bitmap.createBitmap(COLORDRAWABLE_DIMENSION, COLORDRAWABLE_DIMENSION, BITMAP_CONFIG); 172 | } else { 173 | bitmap = Bitmap.createBitmap(drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight(), BITMAP_CONFIG); 174 | } 175 | 176 | Canvas canvas = new Canvas(bitmap); 177 | drawable.setBounds(0, 0, canvas.getWidth(), canvas.getHeight()); 178 | drawable.draw(canvas); 179 | return bitmap; 180 | } catch (OutOfMemoryError e) { 181 | return null; 182 | } 183 | } 184 | 185 | private void setup() { 186 | if (!mReady) { 187 | mSetupPending = true; 188 | return; 189 | } 190 | 191 | if (mBitmap == null) { 192 | return; 193 | } 194 | 195 | mBitmapShader = new BitmapShader(mBitmap, Shader.TileMode.CLAMP, Shader.TileMode.CLAMP); 196 | 197 | mBitmapPaint.setAntiAlias(true); 198 | mBitmapPaint.setShader(mBitmapShader); 199 | 200 | mBorderPaint.setStyle(Paint.Style.STROKE); 201 | mBorderPaint.setAntiAlias(true); 202 | mBorderPaint.setColor(mBorderColor); 203 | mBorderPaint.setStrokeWidth(mBorderWidth); 204 | 205 | mBitmapHeight = mBitmap.getHeight(); 206 | mBitmapWidth = mBitmap.getWidth(); 207 | 208 | mBorderRect.set(0, 0, getWidth(), getHeight()); 209 | mBorderRadius = Math.min((mBorderRect.height() - mBorderWidth) / 2, (mBorderRect.width() - mBorderWidth) / 2); 210 | 211 | mDrawableRect.set(mBorderWidth, mBorderWidth, mBorderRect.width() - mBorderWidth, mBorderRect.height() - mBorderWidth); 212 | mDrawableRadius = Math.min(mDrawableRect.height() / 2, mDrawableRect.width() / 2); 213 | 214 | updateShaderMatrix(); 215 | invalidate(); 216 | } 217 | 218 | private void updateShaderMatrix() { 219 | float scale; 220 | float dx = 0; 221 | float dy = 0; 222 | 223 | mShaderMatrix.set(null); 224 | 225 | if (mBitmapWidth * mDrawableRect.height() > mDrawableRect.width() * mBitmapHeight) { 226 | scale = mDrawableRect.height() / (float) mBitmapHeight; 227 | dx = (mDrawableRect.width() - mBitmapWidth * scale) * 0.5f; 228 | } else { 229 | scale = mDrawableRect.width() / (float) mBitmapWidth; 230 | dy = (mDrawableRect.height() - mBitmapHeight * scale) * 0.5f; 231 | } 232 | 233 | mShaderMatrix.setScale(scale, scale); 234 | mShaderMatrix.postTranslate((int) (dx + 0.5f) + mBorderWidth, (int) (dy + 0.5f) + mBorderWidth); 235 | 236 | mBitmapShader.setLocalMatrix(mShaderMatrix); 237 | } 238 | 239 | } -------------------------------------------------------------------------------- /advertlibrary/src/main/java/advert/sdk/com/advertlibrary/wiget/SizeUtils.java: -------------------------------------------------------------------------------- 1 | package advert.sdk.com.advertlibrary.wiget; 2 | 3 | import android.app.Activity; 4 | import android.content.Context; 5 | import android.util.DisplayMetrics; 6 | import android.view.Display; 7 | import android.view.WindowManager; 8 | 9 | 10 | /** 11 | * 像素转换 12 | * 屏幕尺寸相关工具类 13 | */ 14 | public class SizeUtils { 15 | 16 | /** 17 | * 获取手机屏幕分辨率, 18 | * 19 | * @param type 参数1表示获取屏幕宽像素值,2表示获取屏幕高像素值,3表示分辨率 20 | */ 21 | public static int getDisplay(Activity activity, int type) { 22 | DisplayMetrics localDisplayMetrics = new DisplayMetrics(); 23 | Display localDisplay = activity.getWindowManager().getDefaultDisplay(); 24 | localDisplay.getMetrics(localDisplayMetrics); 25 | int size = 0; 26 | switch (type) { 27 | case 1: 28 | size = localDisplayMetrics.widthPixels; 29 | break; 30 | case 2: 31 | size = localDisplayMetrics.heightPixels; 32 | break; 33 | case 3: 34 | size = localDisplayMetrics.densityDpi; 35 | break; 36 | } 37 | return size; 38 | } 39 | 40 | /** 41 | * 获取手机屏幕的宽度 42 | * 43 | */ 44 | public static int getScreenWidth(Activity activity) { 45 | // WindowManager wm = activity.getWindowManager(); 46 | // int width = wm.getDefaultDisplay().getWidth(); 47 | // int height = wm.getDefaultDisplay().getHeight(); 48 | DisplayMetrics localDisplayMetrics = new DisplayMetrics(); 49 | Display localDisplay = activity.getWindowManager().getDefaultDisplay(); 50 | localDisplay.getMetrics(localDisplayMetrics); 51 | return localDisplayMetrics.widthPixels; 52 | } 53 | 54 | /** 55 | * 获取手机屏幕的高度 56 | * 57 | */ 58 | public static int getScreenHeight(Activity activity) { 59 | DisplayMetrics localDisplayMetrics = new DisplayMetrics(); 60 | Display localDisplay = activity.getWindowManager().getDefaultDisplay(); 61 | localDisplay.getMetrics(localDisplayMetrics); 62 | return localDisplayMetrics.heightPixels; 63 | } 64 | 65 | /** 66 | * 获得屏幕的宽 67 | */ 68 | public static int getWidths(Activity activity){ 69 | int screenWidth;//宽度 70 | WindowManager windowManager = activity.getWindowManager(); 71 | Display display = windowManager.getDefaultDisplay(); 72 | screenWidth = display.getWidth(); 73 | return screenWidth; 74 | } 75 | 76 | /** 77 | * 获得屏幕的高 78 | */ 79 | public static int getHeights(Activity activity){ 80 | int screenHeight;//高度 81 | WindowManager windowManager = activity.getWindowManager(); 82 | Display display = windowManager.getDefaultDisplay(); 83 | screenHeight = display.getHeight(); 84 | return screenHeight; 85 | } 86 | 87 | /** 88 | * 将dip转换为px 89 | * 90 | */ 91 | public static int dip2px(Context context, float dipValue) { 92 | final float scale = context.getResources().getDisplayMetrics().density; 93 | return (int) (dipValue * scale + 0.5f); 94 | } 95 | 96 | /** 97 | * 将px转换为dip 98 | * 99 | */ 100 | public static int px2dip(Context context, float pxValue) { 101 | final float scale = context.getResources().getDisplayMetrics().density; 102 | return (int) (pxValue / scale + 0.5f) - 15; 103 | } 104 | 105 | /** 106 | * 将sp转换为px 107 | * 108 | */ 109 | public static int sp2px(Context context, float spValue) { 110 | final float fontScale = context.getResources().getDisplayMetrics().scaledDensity; 111 | return (int) (spValue * fontScale + 0.5f); 112 | } 113 | 114 | /** 115 | * 将px转换为sp 116 | * 117 | */ 118 | public static int px2sp(Context context, float pxValue) { 119 | final float fontScale = context.getResources().getDisplayMetrics().scaledDensity; 120 | return (int) (pxValue / fontScale + 0.5f); 121 | } 122 | 123 | } -------------------------------------------------------------------------------- /advertlibrary/src/main/java/advert/sdk/com/advertlibrary/wiget/SupportMultipleScreensUtil.java: -------------------------------------------------------------------------------- 1 | package advert.sdk.com.advertlibrary.wiget; 2 | 3 | import android.content.Context; 4 | import android.content.res.Resources; 5 | import android.graphics.drawable.Drawable; 6 | import android.util.DisplayMetrics; 7 | import android.view.View; 8 | import android.view.ViewGroup; 9 | import android.view.ViewGroup.LayoutParams; 10 | import android.view.ViewGroup.MarginLayoutParams; 11 | import android.widget.TextView; 12 | 13 | 14 | /** 15 | * Created by hzdykj on 2017/6/18. 16 | */ 17 | public class SupportMultipleScreensUtil { 18 | 19 | public static final int BASE_SCREEN_WIDTH = 1080; 20 | public static final int BASE_SCREEN_HEIGHT = 1920; 21 | public static final float BASE_SCREEN_WIDTH_FLOAT = 1080F; 22 | public static final float BASE_SCREEN_HEIGHT_FLOAT = 1920F; 23 | public static float scale = 1.0F; 24 | 25 | public SupportMultipleScreensUtil() { 26 | 27 | } 28 | 29 | public static void init(Context context) { 30 | Resources resources=context.getResources(); 31 | DisplayMetrics displayMetrics = resources.getDisplayMetrics(); 32 | int widthPixels = displayMetrics.widthPixels; 33 | scale = (float)widthPixels / BASE_SCREEN_WIDTH_FLOAT; 34 | } 35 | 36 | 37 | public static void scale(View view) { 38 | if(null != view) { 39 | if(view instanceof ViewGroup) { 40 | scaleViewGroup((ViewGroup)view); 41 | } else { 42 | scaleView(view); 43 | } 44 | } 45 | } 46 | 47 | private static void scaleView(View view) { 48 | //Object isScale = view.getTag(R.id.is_scale_size_tag); 49 | /* if (!(isScale instanceof Boolean) || !((Boolean) isScale).booleanValue()) { 50 | if (view instanceof TextView) { 51 | scaleTextView((TextView) view); 52 | } else { 53 | scaleViewSize(view); 54 | } 55 | // view.setTag(R.id.is_scale_size_tag, Boolean.valueOf(true)); 56 | }*/ 57 | } 58 | 59 | 60 | 61 | private static void scaleViewGroup(ViewGroup viewGroup) { 62 | for (int i = 0; i < viewGroup.getChildCount(); ++i) { 63 | View view = viewGroup.getChildAt(i); 64 | if (view instanceof ViewGroup) { 65 | scaleViewGroup((ViewGroup) view); 66 | } 67 | scaleView(view); 68 | } 69 | } 70 | 71 | 72 | 73 | 74 | public static void scaleViewSize(View view) { 75 | if (null != view) { 76 | int paddingLeft = getScaleValue(view.getPaddingLeft()); 77 | int paddingTop = getScaleValue(view.getPaddingTop()); 78 | int paddingRight = getScaleValue(view.getPaddingRight()); 79 | int paddingBottom = getScaleValue(view.getPaddingBottom()); 80 | view.setPadding(paddingLeft, paddingTop, paddingRight, paddingBottom); 81 | 82 | LayoutParams layoutParams = view.getLayoutParams(); 83 | 84 | if (null != layoutParams) { 85 | 86 | if (layoutParams.width > 0) { 87 | layoutParams.width = getScaleValue(layoutParams.width); 88 | } 89 | 90 | if (layoutParams.height > 0) { 91 | layoutParams.height = getScaleValue(layoutParams.height); 92 | } 93 | 94 | if (layoutParams instanceof MarginLayoutParams) { 95 | MarginLayoutParams marginLayoutParams = (MarginLayoutParams) layoutParams; 96 | int topMargin = getScaleValue(marginLayoutParams.topMargin); 97 | int leftMargin = getScaleValue(marginLayoutParams.leftMargin); 98 | int bottomMargin = getScaleValue(marginLayoutParams.bottomMargin); 99 | int rightMargin = getScaleValue(marginLayoutParams.rightMargin); 100 | marginLayoutParams.topMargin = topMargin; 101 | marginLayoutParams.leftMargin = leftMargin; 102 | marginLayoutParams.bottomMargin = bottomMargin; 103 | marginLayoutParams.rightMargin = rightMargin; 104 | } 105 | } 106 | view.setLayoutParams(layoutParams); 107 | } 108 | } 109 | 110 | private static void setTextViewCompoundDrawables(TextView textView, Drawable leftDrawable, Drawable topDrawable, Drawable rightDrawable, Drawable bottomDrawable) { 111 | if(null != leftDrawable) { 112 | scaleDrawableBounds(leftDrawable); 113 | } 114 | 115 | if(null != rightDrawable) { 116 | scaleDrawableBounds(rightDrawable); 117 | } 118 | 119 | if(null != topDrawable) { 120 | scaleDrawableBounds(topDrawable); 121 | } 122 | 123 | if(null != bottomDrawable) { 124 | scaleDrawableBounds(bottomDrawable); 125 | } 126 | 127 | textView.setCompoundDrawables(leftDrawable, topDrawable, rightDrawable, bottomDrawable); 128 | } 129 | 130 | public static Drawable scaleDrawableBounds(Drawable drawable) { 131 | int right=getScaleValue(drawable.getIntrinsicWidth()); 132 | int bottom=getScaleValue(drawable.getIntrinsicHeight()); 133 | drawable.setBounds(0, 0, right, bottom); 134 | return drawable; 135 | } 136 | 137 | public static void scaleTextView(TextView textView) { 138 | if (null != textView) { 139 | 140 | scaleViewSize(textView); 141 | 142 | /* Object isScale = textView.getTag(R.id.is_scale_font_tag); 143 | if (!(isScale instanceof Boolean) || !((Boolean) isScale).booleanValue()) { 144 | float size = textView.getTextSize(); 145 | size *= scale; 146 | textView.setTextSize(TypedValue.COMPLEX_UNIT_PX, size); 147 | }*/ 148 | 149 | Drawable[] drawables = textView.getCompoundDrawables(); 150 | Drawable leftDrawable = drawables[0]; 151 | Drawable topDrawable = drawables[1]; 152 | Drawable rightDrawable = drawables[2]; 153 | Drawable bottomDrawable = drawables[3]; 154 | setTextViewCompoundDrawables(textView, leftDrawable, topDrawable, rightDrawable, bottomDrawable); 155 | int compoundDrawablePadding = getScaleValue(textView.getCompoundDrawablePadding()); 156 | textView.setCompoundDrawablePadding(compoundDrawablePadding); 157 | } 158 | } 159 | 160 | public static int getScaleValue(int value) { 161 | return value <= 4?value:(int) Math.ceil((double)(scale * (float)value)); 162 | } 163 | 164 | } 165 | -------------------------------------------------------------------------------- /advertlibrary/src/main/java/advert/sdk/com/advertlibrary/wiget/ToastUtil.java: -------------------------------------------------------------------------------- 1 | package advert.sdk.com.advertlibrary.wiget; 2 | 3 | import android.content.Context; 4 | import android.view.Gravity; 5 | import android.widget.Toast; 6 | 7 | 8 | /** 9 | */ 10 | public class ToastUtil { 11 | 12 | static ToastUtil td; 13 | 14 | public static void show(int resId) { 15 | // show(App.getInstance().getString(resId)); 16 | } 17 | 18 | public static void show(String msg) { 19 | if (td == null) { 20 | // td = new ToastUtil(App.getInstance()); 21 | } 22 | td.setText(msg); 23 | td.create().show(); 24 | } 25 | 26 | public static void shortShow(String msg) { 27 | if (td == null) { 28 | // td = new ToastUtil(App.getInstance()); 29 | } 30 | td.setText(msg); 31 | td.createShort().show(); 32 | } 33 | 34 | 35 | Context context; 36 | Toast toast; 37 | String msg; 38 | 39 | public ToastUtil(Context context) { 40 | this.context = context; 41 | } 42 | 43 | public Toast create() { 44 | /* View contentView = View.inflate(context, R.layout.dialog_toast, null); 45 | TextView tvMsg = (TextView) contentView.findViewById(R.id.tv_toast_msg);*/ 46 | toast = new Toast(context); 47 | // toast.setView(contentView); 48 | toast.setGravity(Gravity.CENTER, 0, 0); 49 | toast.setDuration(Toast.LENGTH_LONG); 50 | //tvMsg.setText(msg); 51 | return toast; 52 | } 53 | 54 | public Toast createShort() { 55 | /* View contentView = View.inflate(context, R.layout.dialog_toast, null); 56 | TextView tvMsg = (TextView) contentView.findViewById(R.id.tv_toast_msg);*/ 57 | toast = new Toast(context); 58 | // toast.setView(contentView); 59 | toast.setGravity(Gravity.CENTER, 0, 0); 60 | toast.setDuration(Toast.LENGTH_SHORT); 61 | // tvMsg.setText(msg); 62 | return toast; 63 | } 64 | 65 | public void show() { 66 | if (toast != null) { 67 | toast.show(); 68 | } 69 | } 70 | 71 | public void setText(String text) { 72 | msg = text; 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /advertlibrary/src/main/java/advert/sdk/com/advertlibrary/wiget/XmlUtil.java: -------------------------------------------------------------------------------- 1 | package advert.sdk.com.advertlibrary.wiget; 2 | 3 | import android.content.res.XmlResourceParser; 4 | import android.support.v4.util.ArrayMap; 5 | 6 | /** 7 | * 8 | * 将一个xml解析为map集合类型数据模型 9 | */ 10 | 11 | public class XmlUtil { 12 | 13 | public static ArrayMap> parseNodes(XmlResourceParser xmlResourceParser) throws Exception{ 14 | if (xmlResourceParser==null) 15 | return null; 16 | ArrayMap> map = null; 17 | ArrayMap nodeMap = null; 18 | int root=xmlResourceParser.getEventType(); 19 | while (root!= XmlResourceParser.END_DOCUMENT){ 20 | switch (root){ 21 | case XmlResourceParser.START_DOCUMENT: 22 | map = new ArrayMap<>(); 23 | break; 24 | case XmlResourceParser.START_TAG: 25 | if("index".equals(xmlResourceParser.getName())){ 26 | String nodeName = xmlResourceParser.getAttributeValue(0); 27 | nodeMap = new ArrayMap<>(); 28 | if (map != null) { 29 | map.put(nodeName, nodeMap); 30 | } 31 | } 32 | else if ("node".equals(xmlResourceParser.getName())){ 33 | String node = xmlResourceParser.getAttributeValue(0); 34 | String nodeName = xmlResourceParser.nextText(); 35 | if (nodeMap != null) { 36 | nodeMap.put(node, nodeName); 37 | } 38 | } 39 | break; 40 | case XmlResourceParser.END_TAG: 41 | if("index".equals(xmlResourceParser.getName())){ 42 | nodeMap = null; 43 | } 44 | break; 45 | } 46 | root=xmlResourceParser.next(); 47 | } 48 | return map; 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /advertlibrary/src/main/java/advert/sdk/com/advertlibrary/wiget/animation/Animator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2010 The Android Open Source Project 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package advert.sdk.com.advertlibrary.wiget.animation; 18 | 19 | import android.view.animation.Interpolator; 20 | 21 | import java.util.ArrayList; 22 | 23 | /** 24 | * This is the superclass for classes which provide basic support for animations which can be 25 | * started, ended, and have AnimatorListeners added to them. 26 | */ 27 | public abstract class Animator implements Cloneable { 28 | 29 | 30 | /** 31 | * The set of listeners to be sent events through the life of an animation. 32 | */ 33 | ArrayList mListeners = null; 34 | 35 | /** 36 | * Starts this animation. If the animation has a nonzero startDelay, the animation will start 37 | * running after that delay elapses. A non-delayed animation will have its initial 38 | * value(s) set immediately, followed by calls to 39 | * {@link AnimatorListener#onAnimationStart(Animator)} for any listeners of this animator. 40 | * 41 | *

The animation started by calling this method will be run on the thread that called 42 | * this method. This thread should have a Looper on it (a runtime exception will be thrown if 43 | * this is not the case). Also, if the animation will animate 44 | * properties of objects in the view hierarchy, then the calling thread should be the UI 45 | * thread for that view hierarchy.

46 | * 47 | */ 48 | public void start() { 49 | } 50 | 51 | /** 52 | * Cancels the animation. Unlike {@link #end()}, cancel() causes the animation to 53 | * stop in its tracks, sending an 54 | * {@link android.animation.Animator.AnimatorListener#onAnimationCancel(Animator)} to 55 | * its listeners, followed by an 56 | * {@link android.animation.Animator.AnimatorListener#onAnimationEnd(Animator)} message. 57 | * 58 | *

This method must be called on the thread that is running the animation.

59 | */ 60 | public void cancel() { 61 | } 62 | 63 | /** 64 | * Ends the animation. This causes the animation to assign the end value of the property being 65 | * animated, then calling the 66 | * {@link android.animation.Animator.AnimatorListener#onAnimationEnd(Animator)} method on 67 | * its listeners. 68 | * 69 | *

This method must be called on the thread that is running the animation.

70 | */ 71 | public void end() { 72 | } 73 | 74 | /** 75 | * The amount of time, in milliseconds, to delay starting the animation after 76 | * {@link #start()} is called. 77 | * 78 | * @return the number of milliseconds to delay running the animation 79 | */ 80 | public abstract long getStartDelay(); 81 | 82 | /** 83 | * The amount of time, in milliseconds, to delay starting the animation after 84 | * {@link #start()} is called. 85 | 86 | * @param startDelay The amount of the delay, in milliseconds 87 | */ 88 | public abstract void setStartDelay(long startDelay); 89 | 90 | 91 | /** 92 | * Sets the length of the animation. 93 | * 94 | * @param duration The length of the animation, in milliseconds. 95 | */ 96 | public abstract Animator setDuration(long duration); 97 | 98 | /** 99 | * Gets the length of the animation. 100 | * 101 | * @return The length of the animation, in milliseconds. 102 | */ 103 | public abstract long getDuration(); 104 | 105 | /** 106 | * The time interpolator used in calculating the elapsed fraction of this animation. The 107 | * interpolator determines whether the animation runs with linear or non-linear motion, 108 | * such as acceleration and deceleration. The default value is 109 | * {@link android.view.animation.AccelerateDecelerateInterpolator} 110 | * 111 | * @param value the interpolator to be used by this animation 112 | */ 113 | public abstract void setInterpolator(/*Time*/Interpolator value); 114 | 115 | /** 116 | * Returns whether this Animator is currently running (having been started and gone past any 117 | * initial startDelay period and not yet ended). 118 | * 119 | * @return Whether the Animator is running. 120 | */ 121 | public abstract boolean isRunning(); 122 | 123 | /** 124 | * Returns whether this Animator has been started and not yet ended. This state is a superset 125 | * of the state of {@link #isRunning()}, because an Animator with a nonzero 126 | * {@link #getStartDelay() startDelay} will return true for {@link #isStarted()} during the 127 | * delay phase, whereas {@link #isRunning()} will return true only after the delay phase 128 | * is complete. 129 | * 130 | * @return Whether the Animator has been started and not yet ended. 131 | */ 132 | public boolean isStarted() { 133 | // Default method returns value for isRunning(). Subclasses should override to return a 134 | // real value. 135 | return isRunning(); 136 | } 137 | 138 | /** 139 | * Adds a listener to the set of listeners that are sent events through the life of an 140 | * animation, such as start, repeat, and end. 141 | * 142 | * @param listener the listener to be added to the current set of listeners for this animation. 143 | */ 144 | public void addListener(AnimatorListener listener) { 145 | if (mListeners == null) { 146 | mListeners = new ArrayList(); 147 | } 148 | mListeners.add(listener); 149 | } 150 | 151 | /** 152 | * Removes a listener from the set listening to this animation. 153 | * 154 | * @param listener the listener to be removed from the current set of listeners for this 155 | * animation. 156 | */ 157 | public void removeListener(AnimatorListener listener) { 158 | if (mListeners == null) { 159 | return; 160 | } 161 | mListeners.remove(listener); 162 | if (mListeners.size() == 0) { 163 | mListeners = null; 164 | } 165 | } 166 | 167 | /** 168 | * Gets the set of {@link android.animation.Animator.AnimatorListener} objects that are currently 169 | * listening for events on this Animator object. 170 | * 171 | * @return ArrayList The set of listeners. 172 | */ 173 | public ArrayList getListeners() { 174 | return mListeners; 175 | } 176 | 177 | /** 178 | * Removes all listeners from this object. This is equivalent to calling 179 | * getListeners() followed by calling clear() on the 180 | * returned list of listeners. 181 | */ 182 | public void removeAllListeners() { 183 | if (mListeners != null) { 184 | mListeners.clear(); 185 | mListeners = null; 186 | } 187 | } 188 | 189 | @Override 190 | public Animator clone() { 191 | try { 192 | final Animator anim = (Animator) super.clone(); 193 | if (mListeners != null) { 194 | ArrayList oldListeners = mListeners; 195 | anim.mListeners = new ArrayList(); 196 | int numListeners = oldListeners.size(); 197 | for (int i = 0; i < numListeners; ++i) { 198 | anim.mListeners.add(oldListeners.get(i)); 199 | } 200 | } 201 | return anim; 202 | } catch (CloneNotSupportedException e) { 203 | throw new AssertionError(); 204 | } 205 | } 206 | 207 | /** 208 | * This method tells the object to use appropriate information to extract 209 | * starting values for the animation. For example, a AnimatorSet object will pass 210 | * this call to its child objects to tell them to set up the values. A 211 | * ObjectAnimator object will use the information it has about its target object 212 | * and PropertyValuesHolder objects to get the start values for its properties. 213 | * An ValueAnimator object will ignore the request since it does not have enough 214 | * information (such as a target object) to gather these values. 215 | */ 216 | public void setupStartValues() { 217 | } 218 | 219 | /** 220 | * This method tells the object to use appropriate information to extract 221 | * ending values for the animation. For example, a AnimatorSet object will pass 222 | * this call to its child objects to tell them to set up the values. A 223 | * ObjectAnimator object will use the information it has about its target object 224 | * and PropertyValuesHolder objects to get the start values for its properties. 225 | * An ValueAnimator object will ignore the request since it does not have enough 226 | * information (such as a target object) to gather these values. 227 | */ 228 | public void setupEndValues() { 229 | } 230 | 231 | /** 232 | * Sets the target object whose property will be animated by this animation. Not all subclasses 233 | * operate on target objects (for example, {@link ValueAnimator}, but this method 234 | * is on the superclass for the convenience of dealing generically with those subclasses 235 | * that do handle targets. 236 | * 237 | * @param target The object being animated 238 | */ 239 | public void setTarget(Object target) { 240 | } 241 | 242 | /** 243 | *

An animation listener receives notifications from an animation. 244 | * Notifications indicate animation related events, such as the end or the 245 | * repetition of the animation.

246 | */ 247 | public static interface AnimatorListener { 248 | /** 249 | *

Notifies the start of the animation.

250 | * 251 | * @param animation The started animation. 252 | */ 253 | void onAnimationStart(Animator animation); 254 | 255 | /** 256 | *

Notifies the end of the animation. This callback is not invoked 257 | * for animations with repeat count set to INFINITE.

258 | * 259 | * @param animation The animation which reached its end. 260 | */ 261 | void onAnimationEnd(Animator animation); 262 | 263 | /** 264 | *

Notifies the cancellation of the animation. This callback is not invoked 265 | * for animations with repeat count set to INFINITE.

266 | * 267 | * @param animation The animation which was canceled. 268 | */ 269 | void onAnimationCancel(Animator animation); 270 | 271 | /** 272 | *

Notifies the repetition of the animation.

273 | * 274 | * @param animation The animation which was repeated. 275 | */ 276 | void onAnimationRepeat(Animator animation); 277 | } 278 | } 279 | -------------------------------------------------------------------------------- /advertlibrary/src/main/java/advert/sdk/com/advertlibrary/wiget/animation/AnimatorListenerAdapter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2010 The Android Open Source Project 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package advert.sdk.com.advertlibrary.wiget.animation; 18 | 19 | /** 20 | * This adapter class provides empty implementations of the methods from {@link android.animation.Animator.AnimatorListener}. 21 | * Any custom listener that cares only about a subset of the methods of this listener can 22 | * simply subclass this adapter class instead of implementing the interface directly. 23 | */ 24 | public abstract class AnimatorListenerAdapter implements Animator.AnimatorListener { 25 | 26 | /** 27 | * {@inheritDoc} 28 | */ 29 | @Override 30 | public void onAnimationCancel(Animator animation) { 31 | } 32 | 33 | /** 34 | * {@inheritDoc} 35 | */ 36 | @Override 37 | public void onAnimationEnd(Animator animation) { 38 | } 39 | 40 | /** 41 | * {@inheritDoc} 42 | */ 43 | @Override 44 | public void onAnimationRepeat(Animator animation) { 45 | } 46 | 47 | /** 48 | * {@inheritDoc} 49 | */ 50 | @Override 51 | public void onAnimationStart(Animator animation) { 52 | } 53 | 54 | } 55 | -------------------------------------------------------------------------------- /advertlibrary/src/main/java/advert/sdk/com/advertlibrary/wiget/animation/AnimatorProxy.java: -------------------------------------------------------------------------------- 1 | package advert.sdk.com.advertlibrary.wiget.animation; 2 | 3 | import android.graphics.Camera; 4 | import android.graphics.Matrix; 5 | import android.graphics.RectF; 6 | import android.os.Build; 7 | import android.view.View; 8 | import android.view.animation.Animation; 9 | import android.view.animation.Transformation; 10 | 11 | import java.lang.ref.WeakReference; 12 | import java.util.WeakHashMap; 13 | 14 | /** 15 | * A proxy class to allow for modifying post-3.0 view properties on all pre-3.0 16 | * platforms. DO NOT wrap your views with this class if you 17 | * are using {@code ObjectAnimator} as it will handle that itself. 18 | */ 19 | public final class AnimatorProxy extends Animation { 20 | /** Whether or not the current running platform needs to be proxied. */ 21 | public static final boolean NEEDS_PROXY = Integer.valueOf(Build.VERSION.SDK).intValue() < Build.VERSION_CODES.HONEYCOMB; 22 | 23 | private static final WeakHashMap PROXIES = 24 | new WeakHashMap(); 25 | 26 | /** 27 | * Create a proxy to allow for modifying post-3.0 view properties on all 28 | * pre-3.0 platforms. DO NOT wrap your views if you are 29 | * using {@code ObjectAnimator} as it will handle that itself. 30 | * 31 | * @param view View to wrap. 32 | * @return Proxy to post-3.0 properties. 33 | */ 34 | public static AnimatorProxy wrap(View view) { 35 | AnimatorProxy proxy = PROXIES.get(view); 36 | // This checks if the proxy already exists and whether it still is the animation of the given view 37 | if (proxy == null || proxy != view.getAnimation()) { 38 | proxy = new AnimatorProxy(view); 39 | PROXIES.put(view, proxy); 40 | } 41 | return proxy; 42 | } 43 | 44 | private final WeakReference mView; 45 | private final Camera mCamera = new Camera(); 46 | private boolean mHasPivot; 47 | 48 | private float mAlpha = 1; 49 | private float mPivotX; 50 | private float mPivotY; 51 | private float mRotationX; 52 | private float mRotationY; 53 | private float mRotationZ; 54 | private float mScaleX = 1; 55 | private float mScaleY = 1; 56 | private float mTranslationX; 57 | private float mTranslationY; 58 | 59 | private final RectF mBefore = new RectF(); 60 | private final RectF mAfter = new RectF(); 61 | private final Matrix mTempMatrix = new Matrix(); 62 | 63 | private AnimatorProxy(View view) { 64 | setDuration(0); //perform transformation immediately 65 | setFillAfter(true); //persist transformation beyond duration 66 | view.setAnimation(this); 67 | mView = new WeakReference(view); 68 | } 69 | 70 | public float getAlpha() { 71 | return mAlpha; 72 | } 73 | public void setAlpha(float alpha) { 74 | if (mAlpha != alpha) { 75 | mAlpha = alpha; 76 | View view = mView.get(); 77 | if (view != null) { 78 | view.invalidate(); 79 | } 80 | } 81 | } 82 | public float getPivotX() { 83 | return mPivotX; 84 | } 85 | public void setPivotX(float pivotX) { 86 | if (!mHasPivot || mPivotX != pivotX) { 87 | prepareForUpdate(); 88 | mHasPivot = true; 89 | mPivotX = pivotX; 90 | invalidateAfterUpdate(); 91 | } 92 | } 93 | public float getPivotY() { 94 | return mPivotY; 95 | } 96 | public void setPivotY(float pivotY) { 97 | if (!mHasPivot || mPivotY != pivotY) { 98 | prepareForUpdate(); 99 | mHasPivot = true; 100 | mPivotY = pivotY; 101 | invalidateAfterUpdate(); 102 | } 103 | } 104 | public float getRotation() { 105 | return mRotationZ; 106 | } 107 | public void setRotation(float rotation) { 108 | if (mRotationZ != rotation) { 109 | prepareForUpdate(); 110 | mRotationZ = rotation; 111 | invalidateAfterUpdate(); 112 | } 113 | } 114 | public float getRotationX() { 115 | return mRotationX; 116 | } 117 | public void setRotationX(float rotationX) { 118 | if (mRotationX != rotationX) { 119 | prepareForUpdate(); 120 | mRotationX = rotationX; 121 | invalidateAfterUpdate(); 122 | } 123 | } 124 | public float getRotationY() { 125 | return mRotationY; 126 | } 127 | 128 | public void setRotationY(float rotationY) { 129 | if (mRotationY != rotationY) { 130 | prepareForUpdate(); 131 | mRotationY = rotationY; 132 | invalidateAfterUpdate(); 133 | } 134 | } 135 | public float getScaleX() { 136 | return mScaleX; 137 | } 138 | public void setScaleX(float scaleX) { 139 | if (mScaleX != scaleX) { 140 | prepareForUpdate(); 141 | mScaleX = scaleX; 142 | invalidateAfterUpdate(); 143 | } 144 | } 145 | public float getScaleY() { 146 | return mScaleY; 147 | } 148 | public void setScaleY(float scaleY) { 149 | if (mScaleY != scaleY) { 150 | prepareForUpdate(); 151 | mScaleY = scaleY; 152 | invalidateAfterUpdate(); 153 | } 154 | } 155 | public int getScrollX() { 156 | View view = mView.get(); 157 | if (view == null) { 158 | return 0; 159 | } 160 | return view.getScrollX(); 161 | } 162 | public void setScrollX(int value) { 163 | View view = mView.get(); 164 | if (view != null) { 165 | view.scrollTo(value, view.getScrollY()); 166 | } 167 | } 168 | public int getScrollY() { 169 | View view = mView.get(); 170 | if (view == null) { 171 | return 0; 172 | } 173 | return view.getScrollY(); 174 | } 175 | public void setScrollY(int value) { 176 | View view = mView.get(); 177 | if (view != null) { 178 | view.scrollTo(view.getScrollX(), value); 179 | } 180 | } 181 | 182 | public float getTranslationX() { 183 | return mTranslationX; 184 | } 185 | public void setTranslationX(float translationX) { 186 | if (mTranslationX != translationX) { 187 | prepareForUpdate(); 188 | mTranslationX = translationX; 189 | invalidateAfterUpdate(); 190 | } 191 | } 192 | public float getTranslationY() { 193 | return mTranslationY; 194 | } 195 | public void setTranslationY(float translationY) { 196 | if (mTranslationY != translationY) { 197 | prepareForUpdate(); 198 | mTranslationY = translationY; 199 | invalidateAfterUpdate(); 200 | } 201 | } 202 | public float getX() { 203 | View view = mView.get(); 204 | if (view == null) { 205 | return 0; 206 | } 207 | return view.getLeft() + mTranslationX; 208 | } 209 | public void setX(float x) { 210 | View view = mView.get(); 211 | if (view != null) { 212 | setTranslationX(x - view.getLeft()); 213 | } 214 | } 215 | public float getY() { 216 | View view = mView.get(); 217 | if (view == null) { 218 | return 0; 219 | } 220 | return view.getTop() + mTranslationY; 221 | } 222 | public void setY(float y) { 223 | View view = mView.get(); 224 | if (view != null) { 225 | setTranslationY(y - view.getTop()); 226 | } 227 | } 228 | 229 | private void prepareForUpdate() { 230 | View view = mView.get(); 231 | if (view != null) { 232 | computeRect(mBefore, view); 233 | } 234 | } 235 | private void invalidateAfterUpdate() { 236 | View view = mView.get(); 237 | if (view == null || view.getParent() == null) { 238 | return; 239 | } 240 | 241 | final RectF after = mAfter; 242 | computeRect(after, view); 243 | after.union(mBefore); 244 | 245 | ((View)view.getParent()).invalidate( 246 | (int) Math.floor(after.left), 247 | (int) Math.floor(after.top), 248 | (int) Math.ceil(after.right), 249 | (int) Math.ceil(after.bottom)); 250 | } 251 | 252 | private void computeRect(final RectF r, View view) { 253 | // compute current rectangle according to matrix transformation 254 | final float w = view.getWidth(); 255 | final float h = view.getHeight(); 256 | 257 | // use a rectangle at 0,0 to make sure we don't run into issues with scaling 258 | r.set(0, 0, w, h); 259 | 260 | final Matrix m = mTempMatrix; 261 | m.reset(); 262 | transformMatrix(m, view); 263 | mTempMatrix.mapRect(r); 264 | 265 | r.offset(view.getLeft(), view.getTop()); 266 | 267 | // Straighten coords if rotations flipped them 268 | if (r.right < r.left) { 269 | final float f = r.right; 270 | r.right = r.left; 271 | r.left = f; 272 | } 273 | if (r.bottom < r.top) { 274 | final float f = r.top; 275 | r.top = r.bottom; 276 | r.bottom = f; 277 | } 278 | } 279 | 280 | private void transformMatrix(Matrix m, View view) { 281 | final float w = view.getWidth(); 282 | final float h = view.getHeight(); 283 | final boolean hasPivot = mHasPivot; 284 | final float pX = hasPivot ? mPivotX : w / 2f; 285 | final float pY = hasPivot ? mPivotY : h / 2f; 286 | 287 | final float rX = mRotationX; 288 | final float rY = mRotationY; 289 | final float rZ = mRotationZ; 290 | if ((rX != 0) || (rY != 0) || (rZ != 0)) { 291 | final Camera camera = mCamera; 292 | camera.save(); 293 | camera.rotateX(rX); 294 | camera.rotateY(rY); 295 | camera.rotateZ(-rZ); 296 | camera.getMatrix(m); 297 | camera.restore(); 298 | m.preTranslate(-pX, -pY); 299 | m.postTranslate(pX, pY); 300 | } 301 | 302 | final float sX = mScaleX; 303 | final float sY = mScaleY; 304 | if ((sX != 1.0f) || (sY != 1.0f)) { 305 | m.postScale(sX, sY); 306 | final float sPX = -(pX / w) * ((sX * w) - w); 307 | final float sPY = -(pY / h) * ((sY * h) - h); 308 | m.postTranslate(sPX, sPY); 309 | } 310 | 311 | m.postTranslate(mTranslationX, mTranslationY); 312 | } 313 | 314 | @Override 315 | protected void applyTransformation(float interpolatedTime, Transformation t) { 316 | View view = mView.get(); 317 | if (view != null) { 318 | t.setAlpha(mAlpha); 319 | transformMatrix(t.getMatrix(), view); 320 | } 321 | } 322 | } 323 | -------------------------------------------------------------------------------- /advertlibrary/src/main/java/advert/sdk/com/advertlibrary/wiget/animation/ArgbEvaluator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2010 The Android Open Source Project 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package advert.sdk.com.advertlibrary.wiget.animation; 18 | 19 | import android.animation.TypeEvaluator; 20 | 21 | /** 22 | * This evaluator can be used to perform type interpolation between integer 23 | * values that represent ARGB colors. 24 | */ 25 | public class ArgbEvaluator implements TypeEvaluator { 26 | 27 | /** 28 | * This function returns the calculated in-between value for a color 29 | * given integers that represent the start and end values in the four 30 | * bytes of the 32-bit int. Each channel is separately linearly interpolated 31 | * and the resulting calculated values are recombined into the return value. 32 | * 33 | * @param fraction The fraction from the starting to the ending values 34 | * @param startValue A 32-bit int value representing colors in the 35 | * separate bytes of the parameter 36 | * @param endValue A 32-bit int value representing colors in the 37 | * separate bytes of the parameter 38 | * @return A value that is calculated to be the linearly interpolated 39 | * result, derived by separating the start and end values into separate 40 | * color channels and interpolating each one separately, recombining the 41 | * resulting values in the same way. 42 | */ 43 | public Object evaluate(float fraction, Object startValue, Object endValue) { 44 | int startInt = (Integer) startValue; 45 | int startA = (startInt >> 24); 46 | int startR = (startInt >> 16) & 0xff; 47 | int startG = (startInt >> 8) & 0xff; 48 | int startB = startInt & 0xff; 49 | 50 | int endInt = (Integer) endValue; 51 | int endA = (endInt >> 24); 52 | int endR = (endInt >> 16) & 0xff; 53 | int endG = (endInt >> 8) & 0xff; 54 | int endB = endInt & 0xff; 55 | 56 | return (int)((startA + (int)(fraction * (endA - startA))) << 24) | 57 | (int)((startR + (int)(fraction * (endR - startR))) << 16) | 58 | (int)((startG + (int)(fraction * (endG - startG))) << 8) | 59 | (int)((startB + (int)(fraction * (endB - startB)))); 60 | } 61 | } -------------------------------------------------------------------------------- /advertlibrary/src/main/java/advert/sdk/com/advertlibrary/wiget/animation/FloatEvaluator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2010 The Android Open Source Project 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package advert.sdk.com.advertlibrary.wiget.animation; 18 | 19 | import android.animation.TypeEvaluator; 20 | 21 | /** 22 | * This evaluator can be used to perform type interpolation between float values. 23 | */ 24 | public class FloatEvaluator implements TypeEvaluator { 25 | 26 | /** 27 | * This function returns the result of linearly interpolating the start and end values, with 28 | * fraction representing the proportion between the start and end values. The 29 | * calculation is a simple parametric calculation: result = x0 + t * (v1 - v0), 30 | * where x0 is startValue, x1 is endValue, 31 | * and t is fraction. 32 | * 33 | * @param fraction The fraction from the starting to the ending values 34 | * @param startValue The start value; should be of type float or 35 | * Float 36 | * @param endValue The end value; should be of type float or Float 37 | * @return A linear interpolation between the start and end values, given the 38 | * fraction parameter. 39 | */ 40 | public Float evaluate(float fraction, Number startValue, Number endValue) { 41 | float startFloat = startValue.floatValue(); 42 | return startFloat + fraction * (endValue.floatValue() - startFloat); 43 | } 44 | } -------------------------------------------------------------------------------- /advertlibrary/src/main/java/advert/sdk/com/advertlibrary/wiget/animation/IntEvaluator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2010 The Android Open Source Project 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package advert.sdk.com.advertlibrary.wiget.animation; 18 | 19 | import android.animation.TypeEvaluator; 20 | 21 | /** 22 | * This evaluator can be used to perform type interpolation between int values. 23 | */ 24 | public class IntEvaluator implements TypeEvaluator { 25 | 26 | /** 27 | * This function returns the result of linearly interpolating the start and end values, with 28 | * fraction representing the proportion between the start and end values. The 29 | * calculation is a simple parametric calculation: result = x0 + t * (v1 - v0), 30 | * where x0 is startValue, x1 is endValue, 31 | * and t is fraction. 32 | * 33 | * @param fraction The fraction from the starting to the ending values 34 | * @param startValue The start value; should be of type int or 35 | * Integer 36 | * @param endValue The end value; should be of type int or Integer 37 | * @return A linear interpolation between the start and end values, given the 38 | * fraction parameter. 39 | */ 40 | public Integer evaluate(float fraction, Integer startValue, Integer endValue) { 41 | int startInt = startValue; 42 | return (int)(startInt + fraction * (endValue - startInt)); 43 | } 44 | } -------------------------------------------------------------------------------- /advertlibrary/src/main/res/anim/dialog_in_anim.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 10 | -------------------------------------------------------------------------------- /advertlibrary/src/main/res/anim/dialog_out_anim.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 10 | -------------------------------------------------------------------------------- /advertlibrary/src/main/res/drawable/close.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/15527621771/Android-Advert-SDK/c7e117e04d3a4de175ae35f7f65c785ccb305b67/advertlibrary/src/main/res/drawable/close.png -------------------------------------------------------------------------------- /advertlibrary/src/main/res/drawable/closead.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/15527621771/Android-Advert-SDK/c7e117e04d3a4de175ae35f7f65c785ccb305b67/advertlibrary/src/main/res/drawable/closead.png -------------------------------------------------------------------------------- /advertlibrary/src/main/res/drawable/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/15527621771/Android-Advert-SDK/c7e117e04d3a4de175ae35f7f65c785ccb305b67/advertlibrary/src/main/res/drawable/ic_launcher.png -------------------------------------------------------------------------------- /advertlibrary/src/main/res/layout/dialog_advert_view.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 12 | 20 | 21 | -------------------------------------------------------------------------------- /advertlibrary/src/main/res/layout/notification_advert_view.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 17 | 18 | 25 | 26 | 34 | 35 | -------------------------------------------------------------------------------- /advertlibrary/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | advertlibrary 3 | 4 | -------------------------------------------------------------------------------- /advertlibrary/src/main/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /app/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /app/app.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 8 | 9 | 10 | 11 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | 134 | 135 | 136 | 137 | 138 | 139 | 140 | 141 | 142 | -------------------------------------------------------------------------------- /app/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | 3 | android { 4 | compileSdkVersion 25 5 | buildToolsVersion "25.0.3" 6 | defaultConfig { 7 | applicationId "advert.sdk.com.advertsdk" 8 | minSdkVersion 19 9 | targetSdkVersion 25 10 | versionCode 1 11 | versionName "1.0" 12 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" 13 | } 14 | buildTypes { 15 | release { 16 | minifyEnabled false 17 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 18 | } 19 | } 20 | } 21 | 22 | dependencies { 23 | compile fileTree(include: ['*.jar'], dir: 'libs') 24 | androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', { 25 | exclude group: 'com.android.support', module: 'support-annotations' 26 | }) 27 | compile 'com.android.support:appcompat-v7:25.3.1' 28 | compile 'com.android.support.constraint:constraint-layout:1.0.2' 29 | testCompile 'junit:junit:4.12' 30 | compile project(':advertlibrary') 31 | } 32 | -------------------------------------------------------------------------------- /app/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # By default, the flags in this file are appended to flags specified 3 | # in G:\android\sdk/tools/proguard/proguard-android.txt 4 | # You can edit the include path and order by changing the proguardFiles 5 | # directive in build.gradle. 6 | # 7 | # For more details, see 8 | # http://developer.android.com/guide/developing/tools/proguard.html 9 | 10 | # Add any project specific keep options here: 11 | 12 | # If your project uses WebView with JS, uncomment the following 13 | # and specify the fully qualified class name to the JavaScript interface 14 | # class: 15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 16 | # public *; 17 | #} 18 | 19 | # Uncomment this to preserve the line number information for 20 | # debugging stack traces. 21 | #-keepattributes SourceFile,LineNumberTable 22 | 23 | # If you keep the line number information, uncomment this to 24 | # hide the original source file name. 25 | #-renamesourcefileattribute SourceFile 26 | -------------------------------------------------------------------------------- /app/src/androidTest/java/advert/sdk/com/advertsdk/ExampleInstrumentedTest.java: -------------------------------------------------------------------------------- 1 | package advert.sdk.com.advertsdk; 2 | 3 | import android.content.Context; 4 | import android.support.test.InstrumentationRegistry; 5 | import android.support.test.runner.AndroidJUnit4; 6 | 7 | import org.junit.Test; 8 | import org.junit.runner.RunWith; 9 | 10 | import static org.junit.Assert.*; 11 | 12 | /** 13 | * Instrumentation test, which will execute on an Android device. 14 | * 15 | * @see Testing documentation 16 | */ 17 | @RunWith(AndroidJUnit4.class) 18 | public class ExampleInstrumentedTest { 19 | @Test 20 | public void useAppContext() throws Exception { 21 | // Context of the app under test. 22 | Context appContext = InstrumentationRegistry.getTargetContext(); 23 | 24 | assertEquals("advert.sdk.com.advertsdk", appContext.getPackageName()); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | 8 | 9 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /app/src/main/java/advert/sdk/com/advertsdk/MainActivity.java: -------------------------------------------------------------------------------- 1 | package advert.sdk.com.advertsdk; 2 | 3 | import android.os.Bundle; 4 | import android.support.v7.app.AppCompatActivity; 5 | import android.view.View; 6 | import android.widget.Toast; 7 | 8 | public class MainActivity extends AppCompatActivity { 9 | 10 | @Override 11 | protected void onCreate(Bundle savedInstanceState) { 12 | super.onCreate(savedInstanceState); 13 | setContentView(R.layout.activity_main); 14 | findViewById(R.id.btn) 15 | .setOnClickListener(new View.OnClickListener() { 16 | @Override 17 | public void onClick(View v) { 18 | Toast.makeText(MainActivity.this, "不影响点击", Toast.LENGTH_SHORT).show(); 19 | } 20 | }); 21 | 22 | } 23 | 24 | } 25 | -------------------------------------------------------------------------------- /app/src/main/java/advert/sdk/com/advertsdk/MyApplication.java: -------------------------------------------------------------------------------- 1 | package advert.sdk.com.advertsdk; 2 | 3 | import android.app.Application; 4 | 5 | import advert.sdk.com.advertlibrary.engine.AdvertEngine; 6 | 7 | 8 | /** 9 | * Created by 18271 on 19/06/2017. 10 | */ 11 | 12 | public class MyApplication extends Application{ 13 | @Override 14 | public void onCreate() { 15 | super.onCreate(); 16 | AdvertEngine.init(this); 17 | } 18 | 19 | } 20 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 |