diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..26d3352 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,3 @@ +# Default ignored files +/shelf/ +/workspace.xml diff --git a/.idea/.name b/.idea/.name new file mode 100644 index 0000000..dcfce51 --- /dev/null +++ b/.idea/.name @@ -0,0 +1 @@ +magicPeach \ No newline at end of file diff --git a/.idea/compiler.xml b/.idea/compiler.xml new file mode 100644 index 0000000..fb7f4a8 --- /dev/null +++ b/.idea/compiler.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..f9b8e07 --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,17 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/app/.gitignore b/app/.gitignore new file mode 100644 index 0000000..42afabf --- /dev/null +++ b/app/.gitignore @@ -0,0 +1 @@ +/build \ No newline at end of file diff --git a/app/build.gradle b/app/build.gradle new file mode 100644 index 0000000..519b13b --- /dev/null +++ b/app/build.gradle @@ -0,0 +1,43 @@ +plugins { + id 'com.android.application' + id 'org.jetbrains.kotlin.android' + id 'kotlin-android-extensions' +} + +android { + compileSdk 31 + + defaultConfig { + applicationId "com.puy.magicpeach" + minSdk 21 + targetSdk 31 + versionCode 1 + versionName "1.0" + } + + buildTypes { + debug { + minifyEnabled true + proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' + } + release { + minifyEnabled false + proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' + } + } + compileOptions { + sourceCompatibility JavaVersion.VERSION_1_8 + targetCompatibility JavaVersion.VERSION_1_8 + } + kotlinOptions { + jvmTarget = '1.8' + } +} + +dependencies { + implementation fileTree(include: ['*.jar'], dir: 'libs') + implementation 'com.google.android.material:material:1.5.0' + implementation 'androidx.constraintlayout:constraintlayout:2.1.3' + implementation files('libs/PeachSdk.aar') + implementation 'androidx.work:work-runtime:2.7.1' +} \ No newline at end of file diff --git a/app/proguard-rules.pro b/app/proguard-rules.pro new file mode 100644 index 0000000..481bb43 --- /dev/null +++ b/app/proguard-rules.pro @@ -0,0 +1,21 @@ +# Add project specific ProGuard rules here. +# You can control the set of applied configuration files using the +# proguardFiles setting in build.gradle. +# +# For more details, see +# http://developer.android.com/guide/developing/tools/proguard.html + +# If your project uses WebView with JS, uncomment the following +# and specify the fully qualified class name to the JavaScript interface +# class: +#-keepclassmembers class fqcn.of.javascript.interface.for.webview { +# public *; +#} + +# Uncomment this to preserve the line number information for +# debugging stack traces. +#-keepattributes SourceFile,LineNumberTable + +# If you keep the line number information, uncomment this to +# hide the original source file name. +#-renamesourcefileattribute SourceFile \ No newline at end of file diff --git a/app/src/androidTest/java/com/puy/magicpeach/ExampleInstrumentedTest.kt b/app/src/androidTest/java/com/puy/magicpeach/ExampleInstrumentedTest.kt new file mode 100644 index 0000000..5fb3d81 --- /dev/null +++ b/app/src/androidTest/java/com/puy/magicpeach/ExampleInstrumentedTest.kt @@ -0,0 +1,24 @@ +package com.puy.magicpeach + +import androidx.test.platform.app.InstrumentationRegistry +import androidx.test.ext.junit.runners.AndroidJUnit4 + +import org.junit.Test +import org.junit.runner.RunWith + +import org.junit.Assert.* + +/** + * Instrumented test, which will execute on an Android device. + * + * See [testing documentation](http://d.android.com/tools/testing). + */ +@RunWith(AndroidJUnit4::class) +class ExampleInstrumentedTest { + @Test + fun useAppContext() { + // Context of the app under test. + val appContext = InstrumentationRegistry.getInstrumentation().targetContext + assertEquals("com.puy.magicpeach", appContext.packageName) + } +} \ No newline at end of file diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml new file mode 100644 index 0000000..e6ec99a --- /dev/null +++ b/app/src/main/AndroidManifest.xml @@ -0,0 +1,24 @@ + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/java/com/puy/magicpeach/App.kt b/app/src/main/java/com/puy/magicpeach/App.kt new file mode 100644 index 0000000..fb83671 --- /dev/null +++ b/app/src/main/java/com/puy/magicpeach/App.kt @@ -0,0 +1,63 @@ +package com.puy.magicpeach + +import android.app.Application +import android.app.PendingIntent +import android.content.Intent +import android.os.Build +import android.widget.Toast +import com.puy.peach.callback.PeachCallback +import com.puy.peach.configs.NotificationConfig +import com.puy.peach.ext.PeachInit + +/** + * author : puy + * date : 2022/2/24 13:57 + * desc : demo + */ +class App : Application() { + override fun onCreate() { + super.onCreate() + //可选,设置通知栏点击事件 建议设置 + val pendingIntent = + PendingIntent.getActivity(this, 0, Intent().apply { + setClass(this@App, MainActivity::class.java) + addFlags(Intent.FLAG_ACTIVITY_NEW_TASK) + }, if(Build.VERSION.SDK_INT >= 30) PendingIntent.FLAG_IMMUTABLE else PendingIntent.FLAG_UPDATE_CURRENT) + //初始化后默认直接启动 + PeachInit { + val notificationConfig = NotificationConfig() + //设置通知栏图标 + //notificationConfig.largeIcon = R.drawable.ic_launcher_foreground + //notificationConfig.smallIcon = R.drawable.ic_launcher_foreground + //设置通知栏名称 + notificationConfig.title = getString(R.string.app_name) + //设置通知栏内容 + notificationConfig.content = getString(R.string.app_name) + " is running" + //可选,设置通知栏配置 + setNotificationConfig(notificationConfig) + //可选,设置通知栏点击事件 + setPendingIntent(pendingIntent) + //可选,设置音乐 默认配置无声音乐 + //setMusicId(R.raw.main) + //可选,是否是debug模式 debug模式会输出日志 + isDebug(true) + //可选,运行时回调 + addCallback(object : PeachCallback { + override fun doWork(times: Int) { + } + + override fun onStop() { + } + }) + //可选,切后台切换回调 + addBackgroundCallback { + Toast.makeText(this@App, if (it) "退到后台啦" else "跑到前台啦", Toast.LENGTH_SHORT).show() + } + } + + //启动 + //PeachStart() + //停止 + //PeachStop() + } +} \ No newline at end of file diff --git a/app/src/main/java/com/puy/magicpeach/MainActivity.kt b/app/src/main/java/com/puy/magicpeach/MainActivity.kt new file mode 100644 index 0000000..eb686ae --- /dev/null +++ b/app/src/main/java/com/puy/magicpeach/MainActivity.kt @@ -0,0 +1,32 @@ +package com.puy.magicpeach + +import androidx.appcompat.app.AppCompatActivity +import android.os.Bundle +import com.puy.peach.configs.NotificationConfig +import com.puy.peach.ext.PeachStart +import com.puy.peach.ext.PeachStop +import com.puy.peach.ext.PeachUpdateNotification +import kotlinx.android.synthetic.main.activity_main.* + +class MainActivity : AppCompatActivity() { + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + setContentView(R.layout.activity_main) + + startPeach.setOnClickListener { + PeachStart() + } + stopPeach.setOnClickListener { + PeachStop() + } + updateNotification.setOnClickListener { + PeachUpdateNotification { + val notificationConfig = NotificationConfig() + //设置通知栏图标 + notificationConfig.largeIcon = R.drawable.ic_launcher_foreground + notificationConfig.smallIcon = R.drawable.ic_launcher_foreground + setNotificationConfig(notificationConfig) + } + } + } +} \ No newline at end of file diff --git a/app/src/main/res/drawable-v24/ic_launcher_foreground.xml b/app/src/main/res/drawable-v24/ic_launcher_foreground.xml new file mode 100644 index 0000000..2b068d1 --- /dev/null +++ b/app/src/main/res/drawable-v24/ic_launcher_foreground.xml @@ -0,0 +1,30 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/drawable/ic_launcher_background.xml b/app/src/main/res/drawable/ic_launcher_background.xml new file mode 100644 index 0000000..07d5da9 --- /dev/null +++ b/app/src/main/res/drawable/ic_launcher_background.xml @@ -0,0 +1,170 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml new file mode 100644 index 0000000..3463451 --- /dev/null +++ b/app/src/main/res/layout/activity_main.xml @@ -0,0 +1,41 @@ + + + +