feat(android): redesign family location into three native tabs
This commit is contained in:
@@ -0,0 +1,37 @@
|
||||
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' ('ZhaoPhoneCheck-'+[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.phonecheck" 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.PhonePreviewActivity" android:exported="true" android:screenOrientation="portrait"/><service android:name="cn.ucvl.zhaodisplay.LocationService" android:exported="false"/><service android:name="cn.ucvl.zhaodisplay.MonitorService" android:exported="false"/></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'}
|
||||
$sources=@("$source\src\cn\ucvl\zhaodisplay\LocationActivity.java","$source\src\cn\ucvl\zhaodisplay\PhoneLayout.java","$source\src\cn\ucvl\zhaodisplay\PhoneStyle.java","$source\src\cn\ucvl\zhaodisplay\VoicePanel.java","$source\src\cn\ucvl\zhaodisplay\VoiceSurface.java","$source\src\cn\ucvl\zhaodisplay\VoiceGesture.java","$source\src\cn\ucvl\zhaodisplay\LocationCadence.java") + @((Get-ChildItem "$tests\phone-preview" -Filter "*.java").FullName)
|
||||
& "$jdk\bin\javac.exe" -encoding UTF-8 -source 8 -target 8 -cp $android -d "$stage\classes" @sources
|
||||
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\PhoneCheck.apk" "$stage\aligned.apk"
|
||||
if($LASTEXITCODE){throw 'Test APK signing failed'}
|
||||
& "$bt\apksigner.bat" verify "$source\build\PhoneCheck.apk"
|
||||
if($LASTEXITCODE){throw 'Test APK verification failed'}
|
||||
Write-Output "$source\build\PhoneCheck.apk"
|
||||
@@ -19,7 +19,7 @@ $env:Path="$jdk\bin;$env:Path"
|
||||
'@ | 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"
|
||||
& "$jdk\bin\javac.exe" -encoding UTF-8 -source 8 -target 8 -cp $android -d "$stage\classes" "$source\src\cn\ucvl\zhaodisplay\VoiceSurface.java" "$source\src\cn\ucvl\zhaodisplay\PhoneStyle.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"
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
package cn.ucvl.zhaodisplay;
|
||||
import org.json.*;
|
||||
/** Test-only transport. The fixture has no Internet permission and never calls production. */
|
||||
final class DisplayApi {
|
||||
static volatile boolean offline=false,expired=false;
|
||||
static class ApiError extends Exception {final int status;ApiError(int status){this.status=status;}}
|
||||
static JSONObject call(String path,String token,JSONObject body)throws Exception{
|
||||
if(expired)throw new ApiError(401);if(offline)throw new ApiError(503);String action=body.optString("action");
|
||||
if(path.equals("/api/voice"))return new JSONObject("{\"enabled\":false,\"allowed\":[],\"candidates\":[{\"id\":\"phone:demo\",\"name\":\"示例家人的手机\"}],\"targets\":[{\"id\":\"display:demo\",\"name\":\"家庭显示终端\",\"kind\":\"display\",\"online\":true}],\"sent\":[],\"inbox\":[]}");
|
||||
if(action.equals("list")){JSONObject a=new JSONObject("{\"id\":\"a\",\"name\":\"家人甲(示例)\",\"status\":\"live\"}");a.put("position",new JSONObject().put("latitude",0).put("longitude",0).put("accuracy",25).put("at",System.currentTimeMillis()/1000));JSONObject b=new JSONObject("{\"id\":\"b\",\"name\":\"家人乙(示例)\",\"status\":\"scheduled\",\"scheduleReason\":\"sampling\"}");return new JSONObject().put("items",new JSONArray().put(a).put(b));}
|
||||
if(action.equals("settings"))return new JSONObject("{\"receipt\":\"fixture\",\"intervalSeconds\":7200,\"sampleIntervalSeconds\":300,\"historyEnabled\":true,\"historyDefault\":true,\"viewerIds\":[],\"phoneIds\":[\"demo\"],\"displayIds\":[],\"viewers\":[],\"phones\":[{\"id\":\"demo\",\"name\":\"示例家人的手机\"}],\"displays\":[],\"history\":{\"pending\":0,\"archived\":2,\"deleting\":0}}");
|
||||
throw new ApiError(403);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
package cn.ucvl.zhaodisplay;
|
||||
import android.graphics.*;
|
||||
import org.json.*;
|
||||
/** Clearly labelled placeholder: no map tiles or real coordinates in this offline fixture. */
|
||||
final class LocationMapView extends android.view.View {
|
||||
JSONArray items;Paint p=new Paint(3);
|
||||
LocationMapView(android.content.Context c){super(c);setContentDescription("地图占位,隔离验收不加载真实位置");}
|
||||
void setItems(JSONArray a){items=a;invalidate();}void setTrack(JSONArray a){}void reset(){}void focus(JSONObject p){}void resumeMap(){}void pauseMap(){setItems(new JSONArray());}void close(){}
|
||||
protected void onDraw(Canvas c){c.drawColor(0xffe7eee5);float d=getResources().getDisplayMetrics().density;p.setColor(0xffc9d9ce);p.setStrokeWidth(2*d);for(int x=0;x<getWidth();x+=60*d)c.drawLine(x,0,x,getHeight(),p);for(int y=0;y<getHeight();y+=60*d)c.drawLine(0,y,getWidth(),y,p);p.setColor(PhoneStyle.MUTED);p.setTextSize(15*d);p.setTextAlign(Paint.Align.CENTER);c.drawText("智家地图 · 隔离验收占位",getWidth()/2f,getHeight()/2f,p);p.setTextSize(12*d);c.drawText("正式版加载已授权家人位置",getWidth()/2f,getHeight()/2f+25*d,p);}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
package cn.ucvl.zhaodisplay;
|
||||
/** Test-only empty queue; never touches production storage. */
|
||||
final class LocationQueue {LocationQueue(android.content.Context c){}static String digest(String s){return "fixture";}long[] stats(String owner){return new long[]{0,0,0,0};}long total(){return 0;}void discard(String owner){}}
|
||||
@@ -0,0 +1,3 @@
|
||||
package cn.ucvl.zhaodisplay;
|
||||
/** Test-only noncollecting service. There are no location or foreground-service permissions. */
|
||||
public class LocationService extends android.app.Service {static boolean busy=false;static boolean locationEnabled(android.location.LocationManager m){return false;}public android.os.IBinder onBind(android.content.Intent i){return null;}}
|
||||
@@ -0,0 +1,2 @@
|
||||
package cn.ucvl.zhaodisplay;
|
||||
public class MonitorService extends android.app.Service {public android.os.IBinder onBind(android.content.Intent i){return null;}}
|
||||
@@ -0,0 +1,47 @@
|
||||
package cn.ucvl.zhaodisplay;
|
||||
|
||||
import android.os.*;
|
||||
import android.view.*;
|
||||
import android.widget.*;
|
||||
import org.json.*;
|
||||
|
||||
/** Runs the actual production LocationActivity with isolated transport, queue and map doubles. */
|
||||
public class PhonePreviewActivity extends LocationActivity {
|
||||
android.view.View previewRoot;String mode;
|
||||
protected void attachBaseContext(android.content.Context base){android.content.res.Configuration c=new android.content.res.Configuration(base.getResources().getConfiguration());c.densityDpi=420;super.attachBaseContext(base.createConfigurationContext(c));}
|
||||
public void onCreate(Bundle state){
|
||||
mode=getIntent().getStringExtra("mode");if(mode==null)mode="family";
|
||||
if(mode.equals("large")){android.content.res.Configuration cfg=new android.content.res.Configuration(getResources().getConfiguration());cfg.fontScale=1.35f;getResources().updateConfiguration(cfg,getResources().getDisplayMetrics());}
|
||||
DisplayApi.offline="offline".equals(mode);DisplayApi.expired="expired".equals(mode);
|
||||
getSharedPreferences("location",0).edit().clear().putString("token","unpaired".equals(mode)?"":"synthetic-token").putString("memberName","示例成员").putString("home","我的家 · 演示家庭").putLong("expires",System.currentTimeMillis()+86400000L).putString("status","共享关闭 · 可以查看已授权的家人").apply();
|
||||
super.onCreate(state);
|
||||
// Limit the actual Activity layout to a phone viewport without changing display configuration.
|
||||
((android.view.ViewGroup)phone.getParent()).removeView(phone);FrameLayout outer=new FrameLayout(this);outer.setBackgroundColor(PhoneStyle.PAPER);
|
||||
int width="narrow".equals(mode)||"large".equals(mode)?320:390;outer.addView(phone,new FrameLayout.LayoutParams(style.dp(width),style.dp("narrow".equals(mode)?640:844),Gravity.TOP|Gravity.CENTER_HORIZONTAL));previewRoot=phone;setContentView(outer);
|
||||
new Handler().postDelayed(()->{try{exercise();save();}catch(Exception e){throw new RuntimeException(e);}},1800);
|
||||
}
|
||||
void check(boolean condition,String message){if(!condition)throw new AssertionError(message);}
|
||||
void exercise()throws Exception{
|
||||
check(!prefs.getBoolean("active",false),"opening app must not share");
|
||||
if(!mode.equals("offline")&&!mode.equals("unpaired")&&!mode.equals("expired")){
|
||||
check(settingsReady,"settings loaded");check(samplePeriodSeconds()==300&&uploadPeriod()==7200,"independent cadence loaded");check(familyList.getChildCount()==2,"authorized family cards rendered");
|
||||
phone.nav.getChildAt(2).performClick();check(phone.tab==2,"mine tab click");phone.sampling.performClick();check(detailDialog!=null&&detailDialog.isShowing(),"sampling opens full screen");detailDialog.dismiss();
|
||||
check(sampleCadence.getParent()==sampleSection,"sample controls retain their owner");
|
||||
phone.upload.performClick();check(detailDialog!=null,"upload detail");detailDialog.dismiss();
|
||||
phone.nav.getChildAt(0).performClick();check(phone.tab==0,"family navigation");
|
||||
check(!prefs.getBoolean("active",false),"navigation never enables sharing");
|
||||
}
|
||||
if(mode.equals("mine")||mode.equals("large"))selectTab(2);
|
||||
else if(mode.equals("voice")||mode.equals("recording")||mode.equals("cancel")||mode.equals("narrow")){
|
||||
selectTab(1);voice.ui.removeCallbacks(voice.visual);VoiceSurface v=voice.page();v.expand.setVisibility(View.GONE);v.destination(new JSONObject("{\"name\":\"家庭显示终端\",\"kind\":\"display\",\"online\":true}"),true);v.recipient.setText("家庭显示终端");v.status.setText("界面验收 · 不录音、不发送语音");
|
||||
boolean recording=mode.equals("recording")||mode.equals("cancel");for(int i=0;i<31;i++)v.recording(recording,mode.equals("cancel"),8000,(int)(9000*Math.abs(Math.sin(i))),false,true);
|
||||
}
|
||||
else if(mode.equals("unpaired")){check(shareControls.getVisibility()==View.GONE,"unpaired share controls hidden");check(phone.tab==2,"unpaired starts on my page");}
|
||||
else selectTab(0);
|
||||
if(mode.equals("expired")){check(pairingRequired(),"expired requires re-pairing");check(!sharing.isEnabled(),"expired cannot start sharing");phone.check.performClick();check(detailDialog!=null&&pairSection.getParent()!=settings,"status routes to pairing instead of OS permission settings");detailDialog.dismiss();}
|
||||
if(mode.equals("offline")){check(familyList.getChildCount()==0,"offline stale positions removed");check(!sharing.isEnabled(),"offline cannot start sharing");}
|
||||
check(phone.nav.getChildCount()==3,"exactly three tabs");
|
||||
try(java.io.FileWriter f=new java.io.FileWriter(new java.io.File(getExternalFilesDir(null),"checks.txt"))){f.write("PASS "+mode+" production UI navigation, permission boundary and form ownership");}
|
||||
}
|
||||
void save(){previewRoot.postDelayed(()->{try{check(sampleSection.getParent()==settings&&uploadSection.getParent()==settings,"dismissed forms safely returned after queued dialog callbacks");android.graphics.Bitmap b=android.graphics.Bitmap.createBitmap(previewRoot.getWidth(),previewRoot.getHeight(),android.graphics.Bitmap.Config.ARGB_8888);previewRoot.draw(new android.graphics.Canvas(b));try(java.io.FileOutputStream f=new java.io.FileOutputStream(new java.io.File(getExternalFilesDir(null),"preview.png"))){b.compress(android.graphics.Bitmap.CompressFormat.PNG,100,f);}b.recycle();}catch(Exception e){throw new RuntimeException(e);}},300);}
|
||||
}
|
||||
Reference in New Issue
Block a user