diff --git a/README.md b/README.md index 0a339ad..f83c7b6 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,254 @@ # Rokid +## 准备工作 +### 配置文件 +配置文件 `init.json` 以 `JSON` 格式存储,通过 `Key-Value` 配置系统功能。 +> 示例: + ```json + { + "launchPackageName":"com.rokid.sample", + "wifiSsid":"", + "wifiPwd":"" + } + ``` +通过 `adb push` 至目录 `/sdcard/init.json` +### 调试连接 +```shell +adb shell setprop persist.vendor.adb 1 +``` +## Glasses行业版SDK + +### 0.背景 + +* 该插件仅适用于Glasses行业版OS。 + +### 1.开发接入 + +#### 1.1配置 + +1. 导入 sprite_dcg_sdk.aar + +### 1.系统服务 +行业版SDK提供服务列表: +* 语音指令服务 `IInstructService`,应用可监听系统固定语音指令 +* 离线TTS服务 `ITTSService` +* 系统功能服务 `ISystemFuncService`, 提供系统设置功能 +* 媒体服务 `ISpriteMediaService`,提供拍照、录像等功能 + +#### 1.1 异步获取服务 +* 异步获取语音指令服务:ServiceManager.getInstructService(Context context, IGetServiceCallback callback) +* 异步获取TTS服务:ServiceManager.getTTSService(Context context, IGetServiceCallback callback) +* 异步获取系统功能服务:ServiceManager.getSystemFuncService(Context context, IGetServiceCallback callback) +* 异步获取媒体服务:ServiceManager.getSpriteMediaService(Context context, IGetServiceCallback callback) + +> 调用异步接口时,如果服务没有bind,会自动bind +```java + ServiceManager.getTTSService(this) { + it.playTtsMsg("让每个人享受科技,Leave Nobody Behind!") + } +``` + +#### 1.1 同步获取服务 +* bind 服务:ServiceManager. +* 同步获取服务:ServiceManager.getService(Class serviceClass) + +> 调用同步接口时,必须提前bind,如果服务没有bind,或者bind还没完成时,将返回 `null` +```java + ServiceManager.getService(ITTSService::class.java)?.playTtsMsg("让每个人享受科技,Leave Nobody Behind!") +``` + +### 2. 语音指令服务 `IInstructService` + +#### 2.1 可用语音指令 +```java +const int INSTRUCT_WAKEUP = 1; // 若琪、乐琪 +const int INSTRUCT_VOLUME_UP = 2; // 声音大一点 +const int INSTRUCT_VOLUME_DOWN = 3; // 声音小一点 +const int INSTRUCT_LIGHT_UP = 4; // 亮一点 +const int INSTRUCT_LIGHT_DOWN = 5; // 暗一点 +const int INSTRUCT_TAKE_PHOTO = 6; // 拍照 +const int INSTRUCT_START_AUDIO_RECORD = 7; // 录音 +const int INSTRUCT_STOP_AUDIO_RECORD = 8; // 结束录音 +const int INSTRUCT_START_VIDEO_RECORD = 9; // 录像 +const int INSTRUCT_STOP_VIDEO_RECORD = 10; // 结束录像 +const int INSTRUCT_QUIT = 11; // 退出 +``` +#### 2.2 注册/反注册语音指令监听 +```java +interface IInstructListener { + void onInstructReceived(int instruct); +} + +void registerListener(IInstructListener listener); +void unregisterListener(IInstructListener listener); +``` + +例如: +```kotlin +private val mInstructListener = object : IInstructListener.Stub() { // 因为通过binder调用服务,这里必须是Stub对象 + override fun onInstructReceived(instruct: Int) { + Log.d("Instruct", "on receive instruct: $instruct") + // 注意: 服务的回调都不在主线程,如果要操作UI,请自己切换到主线程 + // textView.text = "收到语音指令: $instruct" + } +} + +override fun onResume() { + super.onResume() + ServiceManager.getInstructService(this) { it.registerListener(mInstructListener) } +} + +override fun onPause() { + super.onPause() + ServiceManager.getInstructService(this) { it.unregisterListener(mInstructListener) } +} +``` + +### 3. TTS服务 `ITTSService` + +#### 3.1 播放TTS +```java +void playTtsMsg(String ttsMsg); +``` + +### 4. 系统基础功能服务 `ISystemFuncService` + +#### 4.1 获取/设置系统音量,音量值范围 `[0, 15]` +```java +int getVolumeSpecified(); +void setVolumeSpecified(int value); +``` + +#### 4.2 获取/设置屏幕亮度,亮度值范围 `[0, 15]` +```java +int getBrightnessSpecified(); +void setBrightnessSpecified(int value); +``` + +#### 4.3 获取设备序列号 +```java +String getSn(); +``` + +#### 4.4 获取/设置自动休眠时间(单位:毫秒) +```java +long getScreenAutoSleepTime(); +void setScreenAutoSleepTime(long ms); +``` + +#### 4.5 唤醒设备 +```java +void wakeUp(); +``` + +#### 4.6 设备休眠 +```java +void goToSleep(); +``` + +#### 4.7 设备重启 +```java +void reboot(); +``` + + +#### 4.8 设备关机 +```java +void shutdown(); +``` + +### 5. 多媒体服务 `ISpriteMediaService` + +#### 5.1 多媒体Listener +```java +interface ISpriteMediaListener { + void onTakePicture(int errorCode, String path); // 拍照回调 + void onVideoRecord(int errorCode, String path); // 录像回调 + void onAudioRecord(int errorCode, String path); // 录音回调 +} + +// 错误码 +interface ISpriteMediaService { + const int ERROR_NONE = 0; + const int ERROR_CAMERA_EXCEPTION = 1; + const int ERROR_P_SENSOR_NEAR = 2; +} +``` + +#### 5.2 设置监听 +```java +void setMediaListener(ISpriteMediaListener listener); +``` + +#### 5.3 设置拍照分辨率 +```java +void setPictureSize(int width, int height); +/* 可用分辨率 +[4032x3024, 4000x3000, 4032x2268, 3264x2448, 3200x2400, 2268x3024, 2876x2156, 2688x2016, 2582x1936, 2400x1800, 1800x2400, 2560x1440, 2400x1350, 2048x1536, 2016x1512, 1920x1080, 1600x1200, 1440x1080, 1280x720, 720x1280, 1024x768, 800x600, 648x648, 854x480, 800x480, 640x480, 480x640, 352x288, 320x240, 320x180, 176x144] +*/ +``` + +#### 5.4 设置录像分辨率 +```java +void setVideoSize(int width, int height); +``` + +#### 5.5 拍照(结果通过Lisener获取) +```java +void takePicture(); +``` + +#### 5.6 录像(结果通过Lisener获取) +```java +void startVideoRecord(); // 开始录像 +void stopVideoRecord(); // 停止录像 +boolean isVideoRecording(); // 是否正在录像 +``` + +#### 5.7 录音(结果通过Lisener获取) +```java +void startAudioRecord(); +void stopAudioRecord(); +boolean isAudioRecording(); +``` + +### 6. 自定义按键 + +#### 6.1 触控板标准按键 +标准按键可通过onKeyDown、onKeyUp监听。可用键值如下: +* 点击:KeyEvent.KEYCODE_ENTER +* 前滑:KeyEvent.KEYCODE_DPAD_DOWN、KeyEvent.KEYCODE_DPAD_RIGHT +* 后滑:KeyEvent.KEYCODE_DPAD_UP、KeyEvent.KEYCODE_DPAD_LEFT +* 双击:KeyEvent.KEYCODE_BACK + +#### 6.2 特殊按键 +特殊按键需通过广播注册监听,可监听事件: +* 长按触摸板:SysKeyAction.TOUCH_BAR_LONG_PRESS +* 点击拍照键:SysKeyAction.SPRITE_BUTTON_CLICK +* 按下/弹起拍照键:SysKeyAction.SPRITE_BUTTON_DOWN、SysKeyAction.SPRITE_BUTTON_UP +* 长按拍照键:SysKeyAction.SPRITE_BUTTON_LONG_PRESS + +例如监听拍照键和触摸板长按事件: +```java +private final BroadcastReceiver mSysKeyReceiver = new BroadcastReceiver() { + @Override + public void onReceive(Context context, Intent intent) { + String action = intent.getAction(); + + if (SysKeyAction.SPRITE_BUTTON_CLICK.equals(action)) { + } else if (SysKeyAction.TOUCH_BAR_LONG_PRESS.equals(action)) { + } + } +}; + +private void registerSysKeyReceiver() { + try { + IntentFilter filter = new IntentFilter(); + filter.addAction(SysKeyAction.SPRITE_BUTTON_CLICK); + filter.addAction(SysKeyAction.TOUCH_BAR_LONG_PRESS); + registerReceiver(mSysKeyReceiver, filter) + } catch (Exception e) { + e.printStackTrace(); + } +} +``` 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.kts b/app/build.gradle.kts new file mode 100644 index 0000000..e1f0285 --- /dev/null +++ b/app/build.gradle.kts @@ -0,0 +1,53 @@ +plugins { + alias(libs.plugins.android.application) + alias(libs.plugins.kotlin.android) +} + +android { + namespace = "com.yuanxuan.rokid" + compileSdk { + version = release(36) + } + + defaultConfig { + applicationId = "com.yuanxuan.rokid" + minSdk = 29 + targetSdk = 36 + versionCode = 1 + versionName = "1.0" + + testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner" + } + + buildTypes { + release { + isMinifyEnabled = false + proguardFiles( + getDefaultProguardFile("proguard-android-optimize.txt"), + "proguard-rules.pro" + ) + } + } + compileOptions { + sourceCompatibility = JavaVersion.VERSION_11 + targetCompatibility = JavaVersion.VERSION_11 + } + kotlinOptions { + jvmTarget = "11" + } +} + +dependencies { + implementation(fileTree("libs") { include("*.aar", "*.jar") }) + implementation(libs.androidx.core.ktx) + implementation(libs.androidx.appcompat) + implementation(libs.material) + implementation(libs.androidx.activity) + implementation(libs.androidx.constraintlayout) + implementation(libs.logger.timber) + implementation(libs.okhttp) + implementation(libs.okhttp.logging.interceptor) + testImplementation(libs.junit) + androidTestImplementation(libs.androidx.junit) + androidTestImplementation(libs.androidx.espresso.core) +} \ 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/yuanxuan/rokid/ExampleInstrumentedTest.kt b/app/src/androidTest/java/com/yuanxuan/rokid/ExampleInstrumentedTest.kt new file mode 100644 index 0000000..0cae3a6 --- /dev/null +++ b/app/src/androidTest/java/com/yuanxuan/rokid/ExampleInstrumentedTest.kt @@ -0,0 +1,24 @@ +package com.yuanxuan.rokid + +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.yuanxuan.rokid", 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..f9cf2a1 --- /dev/null +++ b/app/src/main/AndroidManifest.xml @@ -0,0 +1,26 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/java/com/yuanxuan/rokid/MainActivity.kt b/app/src/main/java/com/yuanxuan/rokid/MainActivity.kt new file mode 100644 index 0000000..a0dc5db --- /dev/null +++ b/app/src/main/java/com/yuanxuan/rokid/MainActivity.kt @@ -0,0 +1,20 @@ +package com.yuanxuan.rokid + +import android.os.Bundle +import androidx.activity.enableEdgeToEdge +import androidx.appcompat.app.AppCompatActivity +import androidx.core.view.ViewCompat +import androidx.core.view.WindowInsetsCompat + +class MainActivity : AppCompatActivity() { + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + enableEdgeToEdge() + setContentView(R.layout.activity_main) + ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main)) { v, insets -> + val systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars()) + v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom) + insets + } + } +} \ No newline at end of file diff --git a/app/src/main/java/com/yuanxuan/rokid/app/RokidApplication.kt b/app/src/main/java/com/yuanxuan/rokid/app/RokidApplication.kt new file mode 100644 index 0000000..a511191 --- /dev/null +++ b/app/src/main/java/com/yuanxuan/rokid/app/RokidApplication.kt @@ -0,0 +1,11 @@ +package com.yuanxuan.rokid.app + +import android.app.Application + +class RokidApplication : Application() { + + override fun onCreate() { + super.onCreate() + } + +} \ No newline at end of file diff --git a/app/src/main/java/com/yuanxuan/rokid/keeplive/KeepLiveService.kt b/app/src/main/java/com/yuanxuan/rokid/keeplive/KeepLiveService.kt new file mode 100644 index 0000000..1e011ce --- /dev/null +++ b/app/src/main/java/com/yuanxuan/rokid/keeplive/KeepLiveService.kt @@ -0,0 +1,82 @@ +package com.yuanxuan.rokid.keeplive + +import android.app.Notification +import android.app.NotificationChannel +import android.app.NotificationManager +import android.app.Service +import android.content.Intent +import android.os.IBinder +import android.os.PowerManager +import androidx.core.app.NotificationCompat +import com.yuanxuan.rokid.R + +/** + * 提高APP进程优先级 保持长链接状态 + */ +class KeepLiveService : Service() { + + private lateinit var wakeLock: PowerManager.WakeLock + + companion object { + const val NOTIFICATION_CHANNEL_ID = "KeepLiveServiceChannel" + const val NOTIFICATION_CHANNEL_NAME = NOTIFICATION_CHANNEL_ID + const val NOTIFICATION_ID = 101 // 使用一个唯一的ID + const val WAKE_LOCK_TAG = "KeepLiveService:WakeLock" + } + + override fun onBind(intent: Intent?): IBinder? { + return null + } + + override fun onCreate() { + super.onCreate() + createNotificationChannel() + initWakeLock() + } + + override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int { + startForeground(NOTIFICATION_ID, createNotification()) + return START_STICKY + } + + override fun onDestroy() { + super.onDestroy() + if (::wakeLock.isInitialized && wakeLock.isHeld) { + wakeLock.release() + } + } + + private fun initWakeLock() { + wakeLock = + (getSystemService(POWER_SERVICE) as PowerManager) + .newWakeLock( + PowerManager.PARTIAL_WAKE_LOCK, + WAKE_LOCK_TAG + ) + .apply { + if (isHeld.not()) + acquire() + } + } + + private fun createNotificationChannel() { + // 最低支持Android 9 就不判断了 + val channel = NotificationChannel( + NOTIFICATION_CHANNEL_ID, + NOTIFICATION_CHANNEL_NAME, + NotificationManager.IMPORTANCE_LOW + ) + val manager = getSystemService(NotificationManager::class.java) + manager.createNotificationChannel(channel) + } + + private fun createNotification(): Notification { + return NotificationCompat.Builder(this, NOTIFICATION_CHANNEL_ID) + .setContentTitle(NOTIFICATION_CHANNEL_NAME) + .setContentText(NOTIFICATION_CHANNEL_NAME) + .setSmallIcon(R.mipmap.ic_launcher) + .setOngoing(true) + .build() + } + +} \ 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/drawable/ic_launcher_foreground.xml b/app/src/main/res/drawable/ic_launcher_foreground.xml new file mode 100644 index 0000000..2b068d1 --- /dev/null +++ b/app/src/main/res/drawable/ic_launcher_foreground.xml @@ -0,0 +1,30 @@ + + + + + + + + + + + \ No newline at end of file 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..86a5d97 --- /dev/null +++ b/app/src/main/res/layout/activity_main.xml @@ -0,0 +1,19 @@ + + + + + + \ No newline at end of file diff --git a/app/src/main/res/mipmap-anydpi/ic_launcher.xml b/app/src/main/res/mipmap-anydpi/ic_launcher.xml new file mode 100644 index 0000000..6f3b755 --- /dev/null +++ b/app/src/main/res/mipmap-anydpi/ic_launcher.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/app/src/main/res/mipmap-anydpi/ic_launcher_round.xml b/app/src/main/res/mipmap-anydpi/ic_launcher_round.xml new file mode 100644 index 0000000..6f3b755 --- /dev/null +++ b/app/src/main/res/mipmap-anydpi/ic_launcher_round.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/app/src/main/res/mipmap-hdpi/ic_launcher.webp b/app/src/main/res/mipmap-hdpi/ic_launcher.webp new file mode 100644 index 0000000..c209e78 Binary files /dev/null and b/app/src/main/res/mipmap-hdpi/ic_launcher.webp differ diff --git a/app/src/main/res/mipmap-hdpi/ic_launcher_round.webp b/app/src/main/res/mipmap-hdpi/ic_launcher_round.webp new file mode 100644 index 0000000..b2dfe3d Binary files /dev/null and b/app/src/main/res/mipmap-hdpi/ic_launcher_round.webp differ diff --git a/app/src/main/res/mipmap-mdpi/ic_launcher.webp b/app/src/main/res/mipmap-mdpi/ic_launcher.webp new file mode 100644 index 0000000..4f0f1d6 Binary files /dev/null and b/app/src/main/res/mipmap-mdpi/ic_launcher.webp differ diff --git a/app/src/main/res/mipmap-mdpi/ic_launcher_round.webp b/app/src/main/res/mipmap-mdpi/ic_launcher_round.webp new file mode 100644 index 0000000..62b611d Binary files /dev/null and b/app/src/main/res/mipmap-mdpi/ic_launcher_round.webp differ diff --git a/app/src/main/res/mipmap-xhdpi/ic_launcher.webp b/app/src/main/res/mipmap-xhdpi/ic_launcher.webp new file mode 100644 index 0000000..948a307 Binary files /dev/null and b/app/src/main/res/mipmap-xhdpi/ic_launcher.webp differ diff --git a/app/src/main/res/mipmap-xhdpi/ic_launcher_round.webp b/app/src/main/res/mipmap-xhdpi/ic_launcher_round.webp new file mode 100644 index 0000000..1b9a695 Binary files /dev/null and b/app/src/main/res/mipmap-xhdpi/ic_launcher_round.webp differ diff --git a/app/src/main/res/mipmap-xxhdpi/ic_launcher.webp b/app/src/main/res/mipmap-xxhdpi/ic_launcher.webp new file mode 100644 index 0000000..28d4b77 Binary files /dev/null and b/app/src/main/res/mipmap-xxhdpi/ic_launcher.webp differ diff --git a/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.webp b/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.webp new file mode 100644 index 0000000..9287f50 Binary files /dev/null and b/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.webp differ diff --git a/app/src/main/res/mipmap-xxxhdpi/ic_launcher.webp b/app/src/main/res/mipmap-xxxhdpi/ic_launcher.webp new file mode 100644 index 0000000..aa7d642 Binary files /dev/null and b/app/src/main/res/mipmap-xxxhdpi/ic_launcher.webp differ diff --git a/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.webp b/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.webp new file mode 100644 index 0000000..9126ae3 Binary files /dev/null and b/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.webp differ diff --git a/app/src/main/res/values-night/themes.xml b/app/src/main/res/values-night/themes.xml new file mode 100644 index 0000000..7fa1afc --- /dev/null +++ b/app/src/main/res/values-night/themes.xml @@ -0,0 +1,7 @@ + + + + \ No newline at end of file diff --git a/app/src/main/res/values/colors.xml b/app/src/main/res/values/colors.xml new file mode 100644 index 0000000..c8524cd --- /dev/null +++ b/app/src/main/res/values/colors.xml @@ -0,0 +1,5 @@ + + + #FF000000 + #FFFFFFFF + \ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml new file mode 100644 index 0000000..843c997 --- /dev/null +++ b/app/src/main/res/values/strings.xml @@ -0,0 +1,3 @@ + + Rokid + \ No newline at end of file diff --git a/app/src/main/res/values/themes.xml b/app/src/main/res/values/themes.xml new file mode 100644 index 0000000..300a2c6 --- /dev/null +++ b/app/src/main/res/values/themes.xml @@ -0,0 +1,10 @@ + + + + +