Skip to content

Commit

Permalink
提交
Browse files Browse the repository at this point in the history
  • Loading branch information
gstory0404 committed Aug 6, 2021
1 parent 4f252b3 commit 4ba9efb
Show file tree
Hide file tree
Showing 86 changed files with 2,376 additions and 16 deletions.
82 changes: 66 additions & 16 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,21 +1,71 @@
# See https://www.dartlang.org/guides/libraries/private-files
# Miscellaneous
*.class
*.log
*.pyc
*.swp
.DS_Store
.atom/
.buildlog/
.history
.svn/

# Files and directories created by pub
# IntelliJ related
*.iml
*.ipr
*.iws
.idea/

# Visual Studio Code related
.vscode/

# Flutter/Dart/Pub related
**/doc/api/
.dart_tool/
.flutter-plugins
.flutter-plugins-dependencies
.packages
build/
# If you're building an application, you may want to check-in your pubspec.lock
pubspec.lock
.pub-cache/
.pub/
/build/

# Android related
**/android/**/gradle-wrapper.jar
**/android/.gradle
**/android/captures/
**/android/gradlew
**/android/gradlew.bat
**/android/local.properties
**/android/**/GeneratedPluginRegistrant.java

# Directory created by dartdoc
# If you don't generate documentation locally you can remove this line.
doc/api/
# iOS/XCode related
**/ios/**/*.mode1v3
**/ios/**/*.mode2v3
**/ios/**/*.moved-aside
**/ios/**/*.pbxuser
**/ios/**/*.perspectivev3
**/ios/**/*sync/
**/ios/**/.sconsign.dblite
**/ios/**/.tags*
**/ios/**/.vagrant/
**/ios/**/DerivedData/
**/ios/**/Icon?
**/ios/**/Pods/
**/ios/**/.symlinks/
**/ios/**/profile
**/ios/**/xcuserdata
**/ios/.generated/
**/ios/Flutter/App.framework
**/ios/Flutter/Flutter.framework
**/ios/Flutter/Generated.xcconfig
**/ios/Flutter/app.flx
**/ios/Flutter/app.zip
**/ios/Flutter/flutter_assets/
**/ios/ServiceDefinitions.json
**/ios/Runner/GeneratedPluginRegistrant.*

# Avoid committing generated Javascript files:
*.dart.js
*.info.json # Produced by the --dump-info flag.
*.js # When generated by dart2js. Don't specify *.js if your
# project includes source files written in JavaScript.
*.js_
*.js.deps
*.js.map
# Exceptions to above rules.
!**/ios/**/default.mode1v3
!**/ios/**/default.mode2v3
!**/ios/**/default.pbxuser
!**/ios/**/default.perspectivev3
!/packages/flutter_tools/test/data/dart_dependencies_test/**/.packages
10 changes: 10 additions & 0 deletions .metadata
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# This file tracks properties of this Flutter project.
# Used by Flutter tool to assess capabilities and perform upgrades etc.
#
# This file should be version controlled and should not be manually edited.

version:
revision: f4abaa0735eba4dfd8f33f73363911d63931fe03
channel: stable

project_type: plugin
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
## 0.0.1

* TODO: Describe initial release.
8 changes: 8 additions & 0 deletions android/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
*.iml
.gradle
/local.properties
/.idea/workspace.xml
/.idea/libraries
.DS_Store
/build
/captures
41 changes: 41 additions & 0 deletions android/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
group 'com.gstory.flutter_tencentad'
version '1.0-SNAPSHOT'

buildscript {
ext.kotlin_version = '1.3.50'
repositories {
google()
jcenter()
}

dependencies {
classpath 'com.android.tools.build:gradle:4.1.0'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}

rootProject.allprojects {
repositories {
google()
jcenter()
}
}

apply plugin: 'com.android.library'
apply plugin: 'kotlin-android'

android {
compileSdkVersion 30

sourceSets {
main.java.srcDirs += 'src/main/kotlin'
}
defaultConfig {
minSdkVersion 16
}
}

dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'com.qq.e.union:union:4.380.1250'
}
3 changes: 3 additions & 0 deletions android/gradle.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
org.gradle.jvmargs=-Xmx1536M
android.useAndroidX=true
android.enableJetifier=true
5 changes: 5 additions & 0 deletions android/gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-6.7-all.zip
1 change: 1 addition & 0 deletions android/settings.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
rootProject.name = 'flutter_tencentad'
31 changes: 31 additions & 0 deletions android/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="com.gstory.flutter_tencentad">

<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />

<application>
<provider
android:name="com.qq.e.comm.GDTFileProvider"
android:authorities="${applicationId}.gdt.fileprovider"
android:exported="false"
android:grantUriPermissions="true">
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/gdt_file_path" />
</provider>

<activity
android:name="com.qq.e.ads.PortraitADActivity"
android:screenOrientation="portrait"
android:configChanges="keyboard|keyboardHidden|orientation|screenSize"
tools:replace="android:screenOrientation"/>
<activity
android:name="com.qq.e.ads.LandscapeADActivity"
android:screenOrientation="landscape"
android:configChanges="keyboard|keyboardHidden|orientation|screenSize"
tools:replace="android:screenOrientation"/>
</application>
</manifest>
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package com.gstory.flutter_tencentad

import android.content.Context
import androidx.annotation.NonNull
import com.gstory.flutter_tencentad.rewardvideoad.RewardVideoAd
import com.qq.e.comm.managers.GDTADManager
import com.qq.e.comm.managers.status.SDKStatus
import io.flutter.embedding.engine.plugins.FlutterPlugin
import io.flutter.plugin.common.MethodCall
import io.flutter.plugin.common.MethodChannel
import io.flutter.plugin.common.MethodChannel.MethodCallHandler
import io.flutter.plugin.common.MethodChannel.Result

/** FlutterTencentadPlugin */
class FlutterTencentadPlugin : FlutterPlugin, MethodCallHandler {

private lateinit var channel: MethodChannel
private var applicationContext: Context? = null

override fun onAttachedToEngine(@NonNull flutterPluginBinding: FlutterPlugin.FlutterPluginBinding) {
channel = MethodChannel(flutterPluginBinding.binaryMessenger, "flutter_tencentad")
channel.setMethodCallHandler(this)
applicationContext = flutterPluginBinding.applicationContext
}

override fun onMethodCall(@NonNull call: MethodCall, @NonNull result: Result) {
//注册初始化
if (call.method == "register") {
val appId = call.argument<String>("appId")
val debug = call.argument<Boolean>("debug")
GDTADManager.getInstance().initWith(applicationContext, appId)
LogUtil.setAppName("flutter_tencentad")
LogUtil.setShow(debug!!)
result.success(GDTADManager.getInstance().isInitialized)
//获取sdk版本
} else if (call.method == "getSDKVersion") {
result.success("${SDKStatus.getSDKVersion()}.${GDTADManager.getInstance().pm.pluginVersion}")
} else if (call.method == "loadRewardVideoAd") {
RewardVideoAd.init(applicationContext!!,call.arguments as Map<*, *>)
result.success(true)
} else if (call.method == "showRewardVideoAd") {
RewardVideoAd.showAd()
} else {
result.notImplemented()
}
}

override fun onDetachedFromEngine(@NonNull binding: FlutterPlugin.FlutterPluginBinding) {
channel.setMethodCallHandler(null)
}
}
143 changes: 143 additions & 0 deletions android/src/main/kotlin/com/gstory/flutter_tencentad/LogUtil.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,143 @@
package com.gstory.flutter_tencentad

import android.text.TextUtils
import android.util.Log


/**
* @Description: 打印工具类
* @Author: gstory
* @CreateDate: 2021/8/6 17:51
**/

/**
*
* 可自动把调用位置所在的类名和方法名作为tag,并可设置打印级别
* dway
*/
object LogUtil {
//以下为打印级别,级别从低到高
const val LOG_LEVEL_VERBOSE = 1
const val LOG_LEVEL_DEBUG = 2
const val LOG_LEVEL_INFO = 3
const val LOG_LEVEL_WARN = 4
const val LOG_LEVEL_ERROR = 5
const val LOG_LEVEL_NOLOG = 6
private var AppName = ""
private var PrintLine = false
private var LogLevel = LOG_LEVEL_VERBOSE
private var isShow = false

/**
* 可在打印的TAG前添加应用名标识,不设置则不输出
*/
fun setAppName(appName: String) {
AppName = appName
}

/**
* 是否输出打印所在的行数,默认不输出
*/
fun setPrintLine(enable: Boolean) {
PrintLine = enable
}

/**
* 可在打印的TAG前添加应用名标识,不设置则不输出
*/
fun setShow(show: Boolean) {
isShow = show
}


/**
* 设置打印级别,且只有等于或高于该级别的打印才会输出
*/
fun setLogLevel(logLevel: Int) {
LogLevel = logLevel
}

fun v() {
log(LOG_LEVEL_VERBOSE, "")
}

fun d() {
log(LOG_LEVEL_DEBUG, "")
}

fun i() {
log(LOG_LEVEL_INFO, "")
}

fun w() {
log(LOG_LEVEL_WARN, "")
}

fun e() {
log(LOG_LEVEL_ERROR, "")
}

fun v(msg: String) {
if (LogLevel <= LOG_LEVEL_VERBOSE) {
log(LOG_LEVEL_VERBOSE, msg)
}
}

fun d(msg: String) {
if (LogLevel <= LOG_LEVEL_DEBUG) {
log(LOG_LEVEL_DEBUG, msg)
}
}

fun i(msg: String) {
if (LogLevel <= LOG_LEVEL_INFO) {
log(LOG_LEVEL_INFO, msg)
}
}

fun w(msg: String) {
if (LogLevel <= LOG_LEVEL_WARN) {
log(LOG_LEVEL_WARN, msg)
}
}

fun e(msg: String) {
if (LogLevel <= LOG_LEVEL_ERROR) {
log(LOG_LEVEL_ERROR, msg)
}
}

private fun log(logLevel: Int, msg: String) {
if(!isShow){
return
}
val caller = Thread.currentThread().stackTrace[4]
var callerClazzName = caller.className
if (callerClazzName.contains(".")) {
callerClazzName = callerClazzName.substring(callerClazzName.lastIndexOf(".") + 1)
}
if (callerClazzName.contains("$")) {
callerClazzName = callerClazzName.substring(0, callerClazzName.indexOf("$"))
}
var tag = callerClazzName
if (!TextUtils.isEmpty(AppName)) {
tag = AppName + "_" + tag
}
if (PrintLine) {
tag += "(Line:%d)"
tag = String.format(tag, caller.lineNumber)
}
tag = String.format(tag, callerClazzName)
val message = "---" + caller.methodName + "---" + msg
when (logLevel) {
LOG_LEVEL_VERBOSE -> Log.v(tag, message)
LOG_LEVEL_DEBUG -> Log.d(tag, message)
LOG_LEVEL_INFO -> Log.i(tag, message)
LOG_LEVEL_WARN -> Log.w(tag, message)
LOG_LEVEL_ERROR -> Log.e(tag, message)
LOG_LEVEL_NOLOG -> {
}
}
}
}

Loading

0 comments on commit 4ba9efb

Please sign in to comment.