feat: V0.1.53 location timeline and durable device conversations
This commit is contained in:
@@ -6,8 +6,11 @@ final class DisplayApi {
|
||||
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(path.equals("/api/voice")){
|
||||
if(action.equals("history")){boolean old=body.optLong("before")>0;JSONArray items=new JSONArray();for(int i=0;i<3;i++)items.put(new JSONObject().put("id","chat-"+i).put("seq",i+1).put("mine",i%2==0).put("senderName",i%2==0?"示例成员的手机":"家庭显示终端").put("at",1792387200+i*60-(old?86400:0)).put("seconds",i+3.6).put("delivery",i==2?"queued":"played").put("archive",i==2?"pending":"cloud"));return new JSONObject().put("items",items).put("before",old?0:12);}
|
||||
return new JSONObject("{\"enabled\":false,\"allowed\":[],\"candidates\":[{\"id\":\"phone:demo\",\"name\":\"示例家人的手机\"}],\"targets\":[{\"id\":\"display:demo\",\"archiveKey\":\"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\",\"name\":\"家庭显示终端\",\"kind\":\"display\",\"online\":true}],\"conversations\":[],\"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-120));JSONObject b=new JSONObject("{\"id\":\"b\",\"name\":\"家人乙(示例)\",\"status\":\"scheduled\",\"scheduleReason\":\"sampling\"}");JSONObject c=new JSONObject().put("id","c").put("name","家人丙(示例)").put("position",new JSONObject().put("latitude",0).put("longitude",0).put("accuracy",10).put("at",System.currentTimeMillis()/1000));return new JSONObject().put("items",new JSONArray().put(b).put(a).put(c));}
|
||||
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);
|
||||
}
|
||||
|
||||
@@ -3,8 +3,8 @@ 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);
|
||||
JSONArray items;JSONObject focused;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(){}
|
||||
void setItems(JSONArray a){items=a;invalidate();}void setTrack(JSONArray a){}void reset(){}void focus(JSONObject p){focused=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);}
|
||||
}
|
||||
|
||||
@@ -18,13 +18,16 @@ public class PhonePreviewActivity extends LocationActivity {
|
||||
// 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);
|
||||
new Handler().postDelayed(()->{try{exercise();if(mode.equals("history"))exerciseHistory();else 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");
|
||||
check(settingsReady,"settings loaded");check(samplePeriodSeconds()==300&&uploadPeriod()==7200,"independent cadence loaded");check(familyList.getChildCount()==3,"authorized family cards rendered");
|
||||
check(map.items.optJSONObject(0).optString("id").equals("c")&&map.items.optJSONObject(2).optString("id").equals("b"),"collection time descending, missing fixes last");
|
||||
((android.view.ViewGroup)familyList.getChildAt(0)).getChildAt(1).performClick();check(map.focused==map.items.optJSONObject(0).optJSONObject("position"),"row focuses the matching point");
|
||||
check(voice.getParent()==null,"no voice dock on the position page");check(voice.dock.receiverCard.getParent()==phone.voiceSettings,"receiver controls belong to my settings");
|
||||
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();
|
||||
@@ -32,7 +35,7 @@ public class PhonePreviewActivity extends LocationActivity {
|
||||
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")){
|
||||
else if(mode.equals("voice")||mode.equals("recording")||mode.equals("cancel")||mode.equals("narrow")||mode.equals("history")){
|
||||
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);
|
||||
}
|
||||
@@ -40,8 +43,11 @@ public class PhonePreviewActivity extends LocationActivity {
|
||||
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");}
|
||||
check(phone.nav.getChildCount()==3,"exactly three tabs");check(phone.navLabels[0].getText().toString().equals("位置")&&phone.navLabels[1].getText().toString().equals("沟通"),"requested navigation names");
|
||||
check(voice.page().receiverCard.getParent()==null,"communication page does not duplicate settings");
|
||||
}
|
||||
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);}
|
||||
void exerciseHistory(){
|
||||
new Handler().postDelayed(()->{check(voice.nextBefore==12,"history initial page");voice.page().chat.older.performClick();new Handler().postDelayed(()->{check(voice.historyBefore==12&&voice.nextBefore==0,"older page loaded");check(!voice.page().chat.older.isEnabled(),"end of history disables older");voice.page().chat.latest.performClick();new Handler().postDelayed(()->{check(voice.historyBefore==0&&voice.nextBefore==12,"return to latest page");check(!voice.enabled,"reading history does not enable reception");save();},250);},250);},250);
|
||||
}
|
||||
void save(){previewRoot.postDelayed(()->{try{check(sampleSection.getParent()==settings&&uploadSection.getParent()==settings,"dismissed forms safely returned after queued dialog callbacks");if(phone.tab==1){check(voice.page().chat.messages.getChildCount()==3,"real controller loads chat history");check(voice.nextBefore==12,"older history cursor available");check(voice.page().chat.scroll.getHeight()>=style.dp(90),"chat viewport="+voice.page().chat.scroll.getHeight()+", root="+voice.page().getHeight()+", chat="+voice.page().chat.getHeight()+", compose="+voice.page().compose.getHeight()+", compact="+voice.page().compact);check(voice.page().speak.getHeight()>=style.dp(110),"microphone remains a large target");}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();try(java.io.FileWriter f=new java.io.FileWriter(new java.io.File(getExternalFilesDir(null),"checks.txt"))){f.write("PASS "+mode+" production navigation, chronological list, focus, chat visibility and settings ownership");}}catch(Exception e){throw new RuntimeException(e);}},600);}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user