feat(android): warm voice interface and custom sampling up to one day v0.1.51

This commit is contained in:
Codex
2026-10-19 01:19:28 +08:00
parent e3afb2e07f
commit 0a7c4d9b96
28 changed files with 401 additions and 107 deletions
@@ -17,6 +17,15 @@ public class LocationCadenceTest {
require(LocationCadence.custom(3,true)==259200);assertions++;
require(LocationCadence.custom(5,false)==18000);assertions++;
for(int invalid:new int[]{-1,0,721,Integer.MAX_VALUE}){try{LocationCadence.custom(invalid,false);throw new AssertionError();}catch(IllegalArgumentException expected){assertions++;}}
for(int seconds:new int[]{10,11,30,60,120,300,900,1800,3600,7200,10800,14400,18000,21600,43200,86399,86400}){
require(LocationCadence.sample(seconds)==seconds);assertions++;
require(LocationCadence.sampleDue(10000,0,seconds));assertions++;
require(!LocationCadence.sampleDue(1000+seconds*1000L-1,1000,seconds));assertions++;
require(LocationCadence.sampleDue(1000+seconds*1000L,1000,seconds));assertions++;
}
for(int invalid:new int[]{-1,0,9,86401,604800,Integer.MAX_VALUE}){require(!LocationCadence.sampleValid(invalid));assertions++;}
for(int[] period:new int[][]{{30,1,30},{7,60,420},{7,3600,25200},{24,3600,86400},{1,86400,86400}}){require(LocationCadence.customSample(period[0],period[1])==period[2]);assertions++;}
for(int[] period:new int[][]{{0,60},{9,1},{25,3600},{2,86400},{7,86400},{1,17},{Integer.MAX_VALUE,86400}}){try{LocationCadence.customSample(period[0],period[1]);throw new AssertionError();}catch(IllegalArgumentException expected){assertions++;}}
System.out.println("Location cadence: "+assertions+" assertions passed");
}
}
@@ -0,0 +1,11 @@
package cn.ucvl.zhaodisplay;
public class VoiceGestureTest {
static void check(boolean value){if(!value)throw new AssertionError();}
public static void main(String[] args){
check(!VoiceGesture.cancel(0,120,320,48));check(!VoiceGesture.cancel(-47,120,320,48));
check(VoiceGesture.cancel(-48,120,320,48));check(VoiceGesture.cancel(-100,120,320,48));
check(VoiceGesture.cancel(0,-1,320,48));check(VoiceGesture.cancel(0,321,320,48));
check(!VoiceGesture.cancel(-10,120,320,48));check(!VoiceGesture.sendAtLimit(true));check(VoiceGesture.sendAtLimit(false));
System.out.println("Voice gesture: 9 assertions passed");
}
}
@@ -0,0 +1,26 @@
package cn.ucvl.zhaodisplay;
import android.app.Activity;
import android.os.Bundle;
import android.view.*;
import android.widget.*;
import org.json.*;
/** Isolated visual fixture: no microphone/network/location permissions, no real identities. */
public class VoicePreviewActivity extends Activity {
VoiceSurface surface;JSONArray people;
protected void attachBaseContext(android.content.Context base){android.content.res.Configuration config=new android.content.res.Configuration(base.getResources().getConfiguration());config.densityDpi=420;super.attachBaseContext(base.createConfigurationContext(config));}
public void onCreate(Bundle state){super.onCreate(state);
getWindow().setStatusBarColor(0xfff8f5ed);getWindow().setNavigationBarColor(0xfff8f5ed);getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR|View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR);
ScrollView scroller=new ScrollView(this);scroller.setFillViewport(true);surface=new VoiceSurface(this,true);scroller.addView(surface);
FrameLayout frame=new FrameLayout(this);frame.setBackgroundColor(0xfff8f5ed);frame.addView(scroller,new FrameLayout.LayoutParams(surface.dp(390),surface.dp(844),Gravity.TOP|Gravity.CENTER_HORIZONTAL));setContentView(frame);
try{people=new JSONArray("[{\"id\":\"mom\",\"name\":\"妈妈\",\"online\":true},{\"id\":\"dad\",\"name\":\"爸爸\",\"online\":false},{\"id\":\"home\",\"name\":\"家庭屏\",\"online\":true}]");}catch(Exception e){throw new RuntimeException(e);}
surface.subtitle.setText("一句问候,家就在身边");surface.receive.setText("界面验收 · 模拟家人,不发送语音");surface.recipient.setText("对妈妈说句话");
surface.status.setText("只向已允许接收的家人发送");surface.stop.setVisibility(View.GONE);surface.expand.setOnClickListener(v->finish());
String mode=getIntent().getStringExtra("mode");boolean recording="recording".equals(mode)||"cancel".equals(mode),cancel="cancel".equals(mode);
surface.applyTheme("night".equals(mode));surface.targets(people,"mom",id->surface.targets(people,id,x->{}));
for(int i=0;i<31;i++)surface.recording(recording,cancel,8000,recording?(int)(4000+12000*Math.abs(Math.sin(i*.41))):0,false,true);
if(recording)surface.status.setText(cancel?"松开手指,这条语音不会发送":"正在对妈妈说话 · 演示波形");
scroller.postDelayed(()->{try{android.graphics.Bitmap bitmap=android.graphics.Bitmap.createBitmap(scroller.getWidth(),scroller.getHeight(),android.graphics.Bitmap.Config.ARGB_8888);scroller.draw(new android.graphics.Canvas(bitmap));try(java.io.FileOutputStream out=new java.io.FileOutputStream(new java.io.File(getExternalFilesDir(null),"preview.png"))){bitmap.compress(android.graphics.Bitmap.CompressFormat.PNG,100,out);}bitmap.recycle();}catch(Exception e){throw new RuntimeException(e);}},500);
}
}
@@ -0,0 +1,36 @@
param([string]$ToolRoot='C:\Users\Administrator\Documents\ChatGPT\优创未来\services\toplc-vpn-android\.tools')
$ErrorActionPreference='Stop'
$tests=Split-Path -Parent $MyInvocation.MyCommand.Path
$source=Split-Path -Parent $tests
$stage=Join-Path 'C:\CodexBuild' ('ZhaoVoiceCheck-'+[guid]::NewGuid().ToString('N'))
New-Item -ItemType Directory -Path $stage,"$stage\classes","$stage\dex" | Out-Null
$jdk=Join-Path $ToolRoot 'jdk-staging\jdk-21.0.12.1+1'
$sdk=Join-Path $ToolRoot 'android-sdk'
$bt=Join-Path $sdk 'build-tools\36.0.0'
$android=Join-Path $sdk 'platforms\android-37.0\android.jar'
$env:JAVA_HOME=$jdk
$env:Path="$jdk\bin;$env:Path"
@'
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="cn.ucvl.zhaodisplay.voicecheck" android:versionCode="1" android:versionName="1">
<uses-sdk android:minSdkVersion="26" android:targetSdkVersion="30"/>
<application android:label="喊话界面隔离测试" android:allowBackup="false" android:theme="@android:style/Theme.Material.Light.NoActionBar"><activity android:name="cn.ucvl.zhaodisplay.VoicePreviewActivity" android:exported="true" android:screenOrientation="portrait"/></application>
</manifest>
'@ | Set-Content -LiteralPath "$stage\AndroidManifest.xml" -Encoding utf8
& "$bt\aapt2.exe" link -o "$stage\unsigned.apk" -I $android --manifest "$stage\AndroidManifest.xml"
if($LASTEXITCODE){throw 'Test resource linking failed'}
& "$jdk\bin\javac.exe" -encoding UTF-8 -source 8 -target 8 -cp $android -d "$stage\classes" "$source\src\cn\ucvl\zhaodisplay\VoiceSurface.java" "$tests\VoicePreviewActivity.java"
if($LASTEXITCODE){throw 'Test Java compile failed'}
& "$jdk\bin\jar.exe" cf "$stage\classes.jar" -C "$stage\classes" .
& "$bt\d8.bat" --lib $android --min-api 26 --output "$stage\dex" "$stage\classes.jar"
if($LASTEXITCODE){throw 'Test Dex compile failed'}
Add-Type -AssemblyName System.IO.Compression.FileSystem
$zip=[IO.Compression.ZipFile]::Open("$stage\unsigned.apk",[IO.Compression.ZipArchiveMode]::Update)
try{[IO.Compression.ZipFileExtensions]::CreateEntryFromFile($zip,"$stage\dex\classes.dex",'classes.dex',[IO.Compression.CompressionLevel]::Optimal) | Out-Null}finally{$zip.Dispose()}
& "$bt\zipalign.exe" -f 4 "$stage\unsigned.apk" "$stage\aligned.apk"
$keystore=Join-Path $env:LOCALAPPDATA 'ZhaoDisplay\display-signing.jks'
& "$bt\apksigner.bat" sign --ks $keystore --ks-pass pass:android --key-pass pass:android --ks-key-alias zhaodisplay --out "$source\build\VoiceCheck.apk" "$stage\aligned.apk"
if($LASTEXITCODE){throw 'Test APK signing failed'}
& "$bt\apksigner.bat" verify "$source\build\VoiceCheck.apk"
if($LASTEXITCODE){throw 'Test APK verification failed'}
Write-Output "$source\build\VoiceCheck.apk"