feat: V0.1.53 location timeline and durable device conversations
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="cn.ucvl.zhaodisplay" android:versionCode="8" android:versionName="0.1.52">
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="cn.ucvl.zhaodisplay" android:versionCode="9" android:versionName="0.1.53">
|
||||
<uses-sdk android:minSdkVersion="26" android:targetSdkVersion="30" />
|
||||
<uses-permission android:name="android.permission.INTERNET" />
|
||||
<uses-permission android:name="android.permission.RECORD_AUDIO" />
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="cn.ucvl.zhaodisplay" android:versionCode="8" android:versionName="0.1.52">
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="cn.ucvl.zhaodisplay" android:versionCode="9" android:versionName="0.1.53">
|
||||
<uses-sdk android:minSdkVersion="26" android:targetSdkVersion="30"/>
|
||||
<uses-permission android:name="android.permission.INTERNET"/>
|
||||
<uses-permission android:name="android.permission.RECORD_AUDIO"/>
|
||||
|
||||
@@ -77,9 +77,11 @@ public class LocationActivity extends Activity {
|
||||
button("打开手机系统定位设置",permissionSection).setOnClickListener(v->startActivity(new Intent(android.provider.Settings.ACTION_LOCATION_SOURCE_SETTINGS)));
|
||||
sharing.setOnCheckedChangeListener((v,checked)->{if(rendering)return;if(checked)confirmSharing();else{startService(new Intent(this,LocationService.class).setAction("STOP"));consent.setChecked(false);}render();});
|
||||
map=new LocationMapView(this);phone.mapSlot.addView(map,0,new FrameLayout.LayoutParams(-1,-1));phone.fit.setOnClickListener(v->map.reset());reload.setOnClickListener(v->loadFamily());
|
||||
voice=new VoicePanel(this,"phone",()->prefs.getString("token",""));voice.dock.compactHome();phone.dockSlot.addView(voice,new LinearLayout.LayoutParams(-1,-2));phone.pages[1].addView(voice.page());
|
||||
voice.dock.expand.setText("喊话");voice.dock.expand.setOnClickListener(v->selectTab(1));voice.dock.recipient.setOnClickListener(v->selectTab(1));
|
||||
phone.onTab=i->{voice.finish(false);if(i==2&&!settingsReady)loadSettings();};
|
||||
voice=new VoicePanel(this,"phone",()->prefs.getString("token",""));phone.pages[1].addView(voice.page(),new LinearLayout.LayoutParams(-1,0,1));phone.voiceSettings.addView(voice.dock.receiverCard);
|
||||
phone.voiceSettings.addView(style.label("仅接收你允许的家人或设备。聊天记录长期保存在家庭网盘,关闭接收不会删除历史。",12,PhoneStyle.MUTED));
|
||||
Button soundSettings=style.button("麦克风与声音权限",false);phone.voiceSettings.addView(soundSettings);soundSettings.setOnClickListener(v->startActivity(new Intent(android.provider.Settings.ACTION_APPLICATION_DETAILS_SETTINGS,android.net.Uri.parse("package:"+getPackageName()))));
|
||||
try{phone.pages[2].addView(style.label("赵府智家 · "+getPackageManager().getPackageInfo(getPackageName(),0).versionName,12,PhoneStyle.MUTED));}catch(Exception ignored){}
|
||||
phone.onTab=i->{voice.finish(false);voice.communication(i==1);if(i==2&&!settingsReady)loadSettings();};
|
||||
settingsButton.setOnClickListener(v->selectTab(2));phone.check.setOnClickListener(v->{selectTab(2);if(pairingRequired())showDetail("配对我的手机",pairSection);else showDetail("定位权限",permissionSection);});
|
||||
phone.pairNow.setOnClickListener(v->{selectTab(2);showDetail("配对我的手机",pairSection);});
|
||||
phone.profile.setOnClickListener(v->showDetail("配对与设备",pairSection));phone.pairing.setOnClickListener(v->showDetail("配对与设备",pairSection));
|
||||
@@ -92,7 +94,7 @@ public class LocationActivity extends Activity {
|
||||
boolean paired(){return !prefs.getString("token","").isEmpty();}
|
||||
boolean pairingRequired(){long expires=prefs.getLong("expires",0);return !paired()||bindingRejected||expires>0&&expires<=System.currentTimeMillis();}
|
||||
LinearLayout section(){LinearLayout v=style.column();settings.addView(v);return v;}
|
||||
void selectTab(int tab){voice.finish(false);phone.select(tab);if(tab==2&&!settingsReady)loadSettings();}
|
||||
void selectTab(int tab){voice.finish(false);phone.select(tab);voice.communication(tab==1);if(tab==2&&!settingsReady)loadSettings();}
|
||||
void showDetail(String title,LinearLayout content){
|
||||
if(detailDialog!=null)detailDialog.dismiss();voice.finish(false);if(content.getParent()!=null)((android.view.ViewGroup)content.getParent()).removeView(content);
|
||||
LinearLayout frame=style.column();frame.setPadding(style.dp(20),style.dp(16),style.dp(20),style.dp(16));frame.setBackgroundColor(PhoneStyle.PAPER);
|
||||
@@ -115,7 +117,7 @@ public class LocationActivity extends Activity {
|
||||
void render(){
|
||||
permissionStatus.setText(locationPermissionText());
|
||||
boolean paired=!prefs.getString("token","").isEmpty(),active=prefs.getBoolean("active",false),busy=pairing||LocationService.busy;
|
||||
homeContent.setVisibility(paired?View.VISIBLE:View.GONE);shareControls.setVisibility(paired?View.VISIBLE:View.GONE);voice.setVisibility(paired?View.VISIBLE:View.GONE);phone.pairIntro.setVisibility(paired?View.GONE:View.VISIBLE);phone.dockSlot.setVisibility(paired&&phone.tab==0?View.VISIBLE:View.GONE);
|
||||
homeContent.setVisibility(paired?View.VISIBLE:View.GONE);shareControls.setVisibility(paired?View.VISIBLE:View.GONE);voice.setVisibility(paired?View.VISIBLE:View.GONE);phone.pairIntro.setVisibility(paired?View.GONE:View.VISIBLE);
|
||||
long expires=prefs.getLong("expires",0);
|
||||
VoiceSurface.text(identity,prefs.getString("memberName","尚未配对本人"));VoiceSurface.text(phone.pairSummary,prefs.getString("home","无需注册 · 使用手机配对码"));VoiceSurface.text(phone.homeName,prefs.getString("home","配对后查看已授权的家人"));
|
||||
String member=prefs.getString("memberName","我");VoiceSurface.text(phone.avatar,member.isEmpty()?"我":member.substring(0,member.offsetByCodePoints(0,1)));
|
||||
@@ -156,12 +158,18 @@ public class LocationActivity extends Activity {
|
||||
int g=generation;loading=true;lastList=SystemClock.elapsedRealtime();render();
|
||||
new Thread(()->{try{
|
||||
JSONObject response=DisplayApi.call("/api/location/update",token,new JSONObject().put("action","list"));
|
||||
runOnUiThread(()->{if(!visible||g!=generation)return;JSONArray list=response.optJSONArray("items");map.setItems(list);familyList.removeAllViews();viewStatus.setText(list==null||list.length()==0?"尚无家人授权给这台手机的位置。请对方在自己的位置设置里勾选你的手机,并开启共享。":"点击家人查看位置,点「轨迹」回看已授权历史。");
|
||||
if(list!=null)for(int i=0;i<list.length();i++){JSONObject row=list.optJSONObject(i);if(row==null)continue;JSONObject pos=row.optJSONObject("position");String detail=pos==null?("scheduled".equals(row.optString("status"))?("sampling".equals(row.optString("scheduleReason"))?"等待下次采集":"等待下次上传"):("stale".equals(row.optString("status"))?"更新中断 · 已隐藏旧位置":"等待定位")):java.text.DateFormat.getTimeInstance(java.text.DateFormat.SHORT).format(new Date((long)(pos.optDouble("at")*1000)))+" 更新 · 约 "+Math.round(pos.optDouble("accuracy"))+" 米";phone.family(row.optString("name"),detail,pos!=null,()->{if(pos!=null)map.focus(pos);else Toast.makeText(this,"当前没有可显示的位置",0).show();},()->history(row.optString("id")));}
|
||||
runOnUiThread(()->{if(!visible||g!=generation)return;JSONArray list=sortPositions(response.optJSONArray("items"));map.setItems(list);familyList.removeAllViews();viewStatus.setText(list.length()==0?"尚无家人授权给这台手机的位置。请对方在自己的位置设置里勾选你的手机,并开启共享。":"按采集时间从新到旧 · 点击在地图上闪烁定位");
|
||||
for(int i=0;i<list.length();i++){JSONObject row=list.optJSONObject(i);if(row==null)continue;JSONObject pos=row.optJSONObject("position");String detail=pos==null?("scheduled".equals(row.optString("status"))?("sampling".equals(row.optString("scheduleReason"))?"等待下次采集":"等待下次上传"):("stale".equals(row.optString("status"))?"更新中断 · 已隐藏旧位置":"等待定位")):new java.text.SimpleDateFormat("yyyy-MM-dd HH:mm:ss",Locale.CHINA).format(new Date((long)(pos.optDouble("at")*1000)))+" 采集 · 约 "+Math.round(pos.optDouble("accuracy"))+" 米";phone.family(row.optString("name"),detail,pos!=null,()->{if(pos!=null){phone.scrolls[0].smoothScrollTo(0,0);map.focus(pos);}else Toast.makeText(this,"当前没有可显示的位置",0).show();},()->history(row.optString("id")));}
|
||||
|
||||
});
|
||||
}catch(Exception e){runOnUiThread(()->{if(!visible||g!=generation)return;familyList.removeAllViews();map.setItems(new JSONArray());if(e instanceof DisplayApi.ApiError&&(((DisplayApi.ApiError)e).status==401||((DisplayApi.ApiError)e).status==403)){bindingRejected=true;boolean wasSharing=prefs.getBoolean("active",false);prefs.edit().putBoolean("active",false).apply();if(wasSharing||LocationService.busy)startService(new Intent(this,LocationService.class).setAction("STOP"));voice.rebound();settingsReady=false;settingsError="手机配对已失效,请在「我的」重新配对";}viewStatus.setText(e instanceof DisplayApi.ApiError&&((DisplayApi.ApiError)e).status==401?"手机配对已过期或解除,请重新配对。":"位置未能刷新,已隐藏旧画面,请检查网络。");});}finally{runOnUiThread(()->{if(g==generation){loading=false;render();}});}},"family-positions").start();
|
||||
}
|
||||
static JSONArray sortPositions(JSONArray source){
|
||||
ArrayList<JSONObject> rows=new ArrayList<>();if(source!=null)for(int i=0;i<source.length();i++){JSONObject row=source.optJSONObject(i);if(row!=null)rows.add(row);}
|
||||
rows.sort((a,b)->{int time=Double.compare(positionTime(b),positionTime(a));return time!=0?time:a.optString("id").compareTo(b.optString("id"));});
|
||||
JSONArray sorted=new JSONArray();for(JSONObject row:rows)sorted.put(row);return sorted;
|
||||
}
|
||||
static double positionTime(JSONObject row){JSONObject p=row.optJSONObject("position");double at=p==null?0:p.optDouble("at",0);return Double.isFinite(at)&&at>0?at:0;}
|
||||
void loadSettings(){
|
||||
String token=prefs.getString("token","");if(token.isEmpty()||pairing)return;int g=generation,request=++settingsRequest;settingsReady=false;settingsError="";render();
|
||||
new Thread(()->{try{
|
||||
|
||||
@@ -9,7 +9,7 @@ import java.util.function.IntConsumer;
|
||||
/** Three persistent phone pages. All members, permissions and statuses are supplied by the controller. */
|
||||
final class PhoneLayout extends LinearLayout {
|
||||
final PhoneStyle s;final ScrollView[] scrolls=new ScrollView[3];final LinearLayout[] pages=new LinearLayout[3];
|
||||
final LinearLayout nav,homeContent,familyList,dockSlot,mineContent,pairIntro,shareCard,profile;
|
||||
final LinearLayout nav,homeContent,familyList,mineContent,pairIntro,shareCard,profile,voiceSettings;
|
||||
final FrameLayout mapSlot;final TextView homeName,identity,avatar,homeStatus,myStatus,viewStatus,pairSummary;
|
||||
final Button settingsButton,check,refresh,fit,pairNow,myCheck;final Switch sharing;
|
||||
final PhoneStyle.Row viewers,expiry,sampling,upload,history,pairing,permissions;
|
||||
@@ -18,7 +18,9 @@ final class PhoneLayout extends LinearLayout {
|
||||
super(app);s=new PhoneStyle(app);setOrientation(VERTICAL);setBackgroundColor(PhoneStyle.PAPER);
|
||||
FrameLayout content=new FrameLayout(app);addView(content,new LayoutParams(-1,0,1));
|
||||
for(int i=0;i<3;i++){scrolls[i]=new ScrollView(app);scrolls[i].setFillViewport(true);scrolls[i].setClipToPadding(false);pages[i]=s.column();pages[i].setPadding(s.dp(18),s.dp(18),s.dp(18),s.dp(16));scrolls[i].addView(pages[i]);content.addView(scrolls[i],new FrameLayout.LayoutParams(-1,-1));}
|
||||
LinearLayout heading=s.line();TextView title=s.bold("家人位置",28);heading.addView(title,new LayoutParams(0,-2,1));settingsButton=s.iconButton("settings","打开我的位置共享设置");heading.addView(settingsButton,new LayoutParams(s.dp(48),s.dp(48)));pages[0].addView(heading);
|
||||
// Keep recipient and microphone visible while only the conversation scrolls.
|
||||
scrolls[1].removeView(pages[1]);content.removeView(scrolls[1]);content.addView(pages[1],new FrameLayout.LayoutParams(-1,-1));
|
||||
LinearLayout heading=s.line();TextView title=s.bold("位置",28);heading.addView(title,new LayoutParams(0,-2,1));settingsButton=s.iconButton("settings","打开我的设置");heading.addView(settingsButton,new LayoutParams(s.dp(48),s.dp(48)));pages[0].addView(heading);
|
||||
homeName=s.label("配对后查看家人",16,PhoneStyle.MUTED);pages[0].addView(homeName);s.gap(pages[0],16);
|
||||
LinearLayout banner=s.line();banner.setPadding(s.dp(14),s.dp(8),s.dp(8),s.dp(8));banner.setBackground(s.shape(0xfffff1d6,16));
|
||||
homeStatus=s.label("尚未配对本人",14,0xff805c23);banner.addView(homeStatus,new LayoutParams(0,-2,1));check=s.button("检查",false);banner.addView(check);pages[0].addView(banner);s.gap(pages[0],12);
|
||||
@@ -26,26 +28,26 @@ final class PhoneLayout extends LinearLayout {
|
||||
mapSlot=new FrameLayout(app);mapSlot.setBackground(s.shape(0xffe5ede5,22));mapSlot.setClipToOutline(true);homeContent.addView(mapSlot,new LayoutParams(-1,s.dp(330)));
|
||||
fit=s.iconButton("location","在地图上查看全部家人");FrameLayout.LayoutParams fitParams=new FrameLayout.LayoutParams(s.dp(48),s.dp(48),Gravity.RIGHT|Gravity.CENTER_VERTICAL);fitParams.setMargins(0,0,s.dp(12),0);mapSlot.addView(fit,fitParams);
|
||||
TextView privacy=s.label("仅显示已授权的位置",11,PhoneStyle.GREEN);privacy.setPadding(s.dp(10),s.dp(7),s.dp(10),s.dp(7));privacy.setBackground(s.shape(PhoneStyle.CARD,20));FrameLayout.LayoutParams pp=new FrameLayout.LayoutParams(-2,-2,Gravity.LEFT|Gravity.TOP);pp.setMargins(s.dp(10),s.dp(12),s.dp(64),0);mapSlot.addView(privacy,pp);
|
||||
s.gap(homeContent,14);LinearLayout recent=s.column();s.card(recent);homeContent.addView(recent);LinearLayout recentHead=s.line();recentHead.addView(s.bold("最近位置",17),new LayoutParams(0,-2,1));refresh=s.iconButton("refresh","刷新家人位置");recentHead.addView(refresh,new LayoutParams(s.dp(48),s.dp(48)));recent.addView(recentHead);
|
||||
s.gap(homeContent,14);LinearLayout recent=s.column();s.card(recent);homeContent.addView(recent);LinearLayout recentHead=s.line();recentHead.addView(s.bold("位置列表",17),new LayoutParams(0,-2,1));refresh=s.iconButton("refresh","刷新家人位置");recentHead.addView(refresh,new LayoutParams(s.dp(48),s.dp(48)));recent.addView(recentHead);
|
||||
viewStatus=s.label("正在读取家人授权…",13,PhoneStyle.MUTED);viewStatus.setPadding(0,0,0,s.dp(8));recent.addView(viewStatus);familyList=s.column();recent.addView(familyList);s.gap(homeContent,10);
|
||||
dockSlot=s.column();dockSlot.setPadding(s.dp(12),s.dp(6),s.dp(12),s.dp(6));addView(dockSlot,new LayoutParams(-1,-2));
|
||||
pairIntro=s.column();s.card(pairIntro);pages[0].addView(pairIntro);pairIntro.addView(s.bold("与家人连接",23));s.gap(pairIntro,12);pairIntro.addView(s.label("使用手机配对码关联自己的成员档案,无需注册。配对后就能查看已授权给你的家人。",16,PhoneStyle.MUTED));s.gap(pairIntro,20);pairNow=s.button("去配对我的手机",true);pairIntro.addView(pairNow);
|
||||
// The voice page is populated with the same production VoiceSurface used by the controller.
|
||||
pages[1].setPadding(0,0,0,s.dp(8));
|
||||
pages[2].addView(s.bold("我的位置共享",27));s.gap(pages[2],20);
|
||||
pages[2].addView(s.bold("我的",27));s.gap(pages[2],20);
|
||||
profile=s.line();avatar=s.avatar("我",54);profile.addView(avatar);LinearLayout words=s.column();words.setPadding(s.dp(14),0,0,0);identity=s.bold("尚未配对本人",19);pairSummary=s.label("无需注册 · 使用手机配对码",13,PhoneStyle.MUTED);words.addView(identity);s.gap(words,5);words.addView(pairSummary);profile.addView(words,new LayoutParams(0,-2,1));TextView chevron=s.label("›",28,PhoneStyle.MUTED);profile.addView(chevron);profile.setMinimumHeight(s.dp(64));profile.setFocusable(true);profile.setClickable(true);pages[2].addView(profile);s.gap(pages[2],18);
|
||||
mineContent=s.column();pages[2].addView(mineContent);
|
||||
shareCard=s.column();s.card(shareCard);mineContent.addView(shareCard);sharing=new Switch(app);sharing.setText("共享我的位置");sharing.setTextSize(19);sharing.setTypeface(null,Typeface.BOLD);sharing.setTextColor(PhoneStyle.INK);sharing.setMinHeight(s.dp(50));sharing.setThumbTintList(new android.content.res.ColorStateList(new int[][]{new int[]{android.R.attr.state_checked},new int[]{}},new int[]{PhoneStyle.GREEN,0xffb5bcb6}));shareCard.addView(sharing);
|
||||
LinearLayout state=s.line();state.setPadding(s.dp(10),s.dp(6),s.dp(4),s.dp(6));state.setBackground(s.shape(0xfffff4de,12));myStatus=s.label("共享关闭",13,0xff805c23);state.addView(myStatus,new LayoutParams(0,-2,1));myCheck=s.button("检查权限",false);state.addView(myCheck);shareCard.addView(state);s.gap(shareCard,10);shareCard.addView(s.label("查看家人位置,无需开启自己的共享。",12,PhoneStyle.MUTED));
|
||||
section(mineContent,"允许谁查看");LinearLayout access=s.column();s.card(access);mineContent.addView(access);viewers=s.row("family","查看人名单","读取中");access.addView(viewers);expiry=s.row("clock","共享有效期","跟随本机配对有效期");access.addView(expiry);
|
||||
section(mineContent,"定位与轨迹");LinearLayout location=s.column();s.card(location);mineContent.addView(location);sampling=s.row("location","定位采集频率","每 1 分钟");upload=s.row("cloud","集中上传周期","每 5 分钟");history=s.row("track","我的历史轨迹","每天、每周、每月、每年、一生");permissions=s.row("shield","定位权限与系统设置","本人开启共享后才采集");for(View row:new View[]{sampling,upload,history,permissions})location.addView(row);
|
||||
s.gap(pages[2],12);LinearLayout device=s.column();s.card(device);pages[2].addView(device);pairing=s.row("phone","配对与设备","查看或更换手机配对");device.addView(pairing);
|
||||
nav=s.line();nav.setBackgroundColor(PhoneStyle.CARD);nav.setPadding(s.dp(8),s.dp(4),s.dp(8),s.dp(6));addView(nav,new LayoutParams(-1,-2));String[] names={"家人","喊话","我的"},icons={"family","mic","person"};
|
||||
section(mineContent,"沟通与声音");voiceSettings=s.column();s.card(voiceSettings);mineContent.addView(voiceSettings);
|
||||
section(pages[2],"设备与系统");LinearLayout device=s.column();s.card(device);pages[2].addView(device);pairing=s.row("phone","配对与设备","查看或更换手机配对");device.addView(pairing);
|
||||
nav=s.line();nav.setBackgroundColor(PhoneStyle.CARD);nav.setPadding(s.dp(8),s.dp(4),s.dp(8),s.dp(6));addView(nav,new LayoutParams(-1,-2));String[] names={"位置","沟通","我的"},icons={"location","mic","person"};
|
||||
for(int i=0;i<3;i++){final int index=i;LinearLayout item=s.column();item.setGravity(Gravity.CENTER);item.setMinimumHeight(s.dp(64));item.setPadding(0,s.dp(6),0,s.dp(6));navIcons[i]=new ImageView(app);item.addView(navIcons[i],new LayoutParams(s.dp(25),s.dp(25)));s.gap(item,5);navLabels[i]=s.label(names[i],12,PhoneStyle.MUTED);navLabels[i].setGravity(Gravity.CENTER);item.addView(navLabels[i]);item.setContentDescription(names[i]);item.setFocusable(true);item.setClickable(true);item.setOnClickListener(v->{select(index);if(onTab!=null)onTab.accept(index);});nav.addView(item,new LayoutParams(0,-2,1));}
|
||||
select(0);
|
||||
}
|
||||
void section(LinearLayout parent,String title){s.gap(parent,22);parent.addView(s.bold(title,17));s.gap(parent,10);}
|
||||
void select(int next){tab=next;dockSlot.setVisibility(next==0&&homeContent.getVisibility()==VISIBLE?VISIBLE:GONE);for(int i=0;i<3;i++){scrolls[i].setVisibility(i==next?VISIBLE:GONE);nav.getChildAt(i).setSelected(i==next);navLabels[i].setTextColor(i==next?PhoneStyle.GREEN:PhoneStyle.MUTED);navLabels[i].setTypeface(null,i==next?Typeface.BOLD:Typeface.NORMAL);navIcons[i].setImageDrawable(new PhoneStyle.Icon(new String[]{"family","mic","person"}[i],i==next?PhoneStyle.GREEN:PhoneStyle.MUTED,s.dp(25)));}}
|
||||
void select(int next){tab=next;pages[1].setVisibility(next==1?VISIBLE:GONE);for(int i=0;i<3;i++){scrolls[i].setVisibility(i==next?VISIBLE:GONE);nav.getChildAt(i).setSelected(i==next);navLabels[i].setTextColor(i==next?PhoneStyle.GREEN:PhoneStyle.MUTED);navLabels[i].setTypeface(null,i==next?Typeface.BOLD:Typeface.NORMAL);navIcons[i].setImageDrawable(new PhoneStyle.Icon(new String[]{"location","mic","person"}[i],i==next?PhoneStyle.GREEN:PhoneStyle.MUTED,s.dp(25)));}}
|
||||
void family(String name,String detail,boolean position,Runnable focus,Runnable history){
|
||||
LinearLayout row=s.line();row.setPadding(0,s.dp(10),0,s.dp(10));TextView avatar=s.avatar(name,42);row.addView(avatar);LinearLayout words=s.column();words.setPadding(s.dp(12),0,s.dp(6),0);TextView title=s.bold(name,17);words.addView(title);s.gap(words,5);words.addView(s.label(detail,12,PhoneStyle.MUTED));words.setMinimumHeight(s.dp(48));words.setFocusable(true);words.setClickable(true);words.setOnClickListener(v->focus.run());words.setContentDescription(name+","+detail+(position?",在地图上查看":""));row.addView(words,new LayoutParams(0,-2,1));Button more=s.button("轨迹",false);more.setContentDescription("查看 "+name+" 的已授权历史轨迹");more.setOnClickListener(v->history.run());row.addView(more);familyList.addView(row);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,42 @@
|
||||
package cn.ucvl.zhaodisplay;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.view.*;
|
||||
import android.widget.*;
|
||||
import org.json.*;
|
||||
import java.util.*;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
/** A bounded page of a permanent conversation; older pages are fetched on demand. */
|
||||
final class VoiceChat extends LinearLayout {
|
||||
final PhoneStyle s;final LinearLayout messages;final TextView notice,heading;final Button older,latest;final ScrollView scroll;
|
||||
boolean night=false,savedMore=false,savedPast=false;JSONArray saved=new JSONArray();
|
||||
String signature="";Consumer<String> replay=id->{};
|
||||
VoiceChat(Activity app){
|
||||
super(app);s=new PhoneStyle(app);setOrientation(VERTICAL);s.card(this);
|
||||
LinearLayout head=s.line();heading=s.bold("聊天记录",18);head.addView(heading,new LayoutParams(0,-2,1));older=s.button("更早",false);latest=s.button("最近",false);head.addView(older);head.addView(latest);addView(head);
|
||||
notice=s.label("选择沟通对象后查看记录",12,PhoneStyle.MUTED);addView(notice);
|
||||
scroll=new ScrollView(app);scroll.setFillViewport(true);messages=s.column();scroll.addView(messages);addView(scroll,new LayoutParams(-1,s.dp(218)));
|
||||
scroll.setOnTouchListener((v,e)->{if(e.getActionMasked()==MotionEvent.ACTION_DOWN)v.getParent().requestDisallowInterceptTouchEvent(true);if(e.getActionMasked()==MotionEvent.ACTION_UP||e.getActionMasked()==MotionEvent.ACTION_CANCEL)v.getParent().requestDisallowInterceptTouchEvent(false);return false;});
|
||||
older.setEnabled(false);
|
||||
}
|
||||
void clear(String text){signature="";saved=new JSONArray();messages.removeAllViews();notice.setText(text);older.setEnabled(false);}
|
||||
void theme(boolean value){if(night==value)return;night=value;setBackground(s.shape(night?0xff21372d:PhoneStyle.CARD,20));heading.setTextColor(night?0xffc8d5cd:PhoneStyle.INK);notice.setTextColor(night?0xff96aaa0:PhoneStyle.MUTED);for(Button b:new Button[]{older,latest}){b.setTextColor(night?0xffc8d5cd:PhoneStyle.GREEN);b.setBackground(s.shape(night?0xff2d4439:PhoneStyle.PALE,14));}if(saved.length()>0){signature="";show(saved,savedMore,savedPast,replay);}}
|
||||
void show(JSONArray items,boolean hasMore,boolean past,Consumer<String> play){
|
||||
replay=play;saved=items;savedMore=hasMore;savedPast=past;older.setEnabled(hasMore);notice.setText(past?"较早的记录 · 可继续向前翻阅":"长期保留 · 点击语音回听");
|
||||
String next=items.toString();if(next.equals(signature))return;boolean follow=signature.isEmpty()||scroll.getScrollY()+scroll.getHeight()>=messages.getHeight()-s.dp(32);int oldScroll=scroll.getScrollY();signature=next;messages.removeAllViews();
|
||||
if(items.length()==0){TextView empty=s.label("还没有聊天记录\n按住下方按钮,给家人说句话吧",15,PhoneStyle.MUTED);empty.setGravity(Gravity.CENTER);empty.setPadding(0,s.dp(42),0,s.dp(30));messages.addView(empty);return;}
|
||||
for(int i=0;i<items.length();i++){
|
||||
JSONObject item=items.optJSONObject(i);if(item==null)continue;boolean mine=item.optBoolean("mine");
|
||||
int ink=night?0xffc8d5cd:PhoneStyle.INK,muted=night?0xff96aaa0:PhoneStyle.MUTED;
|
||||
LinearLayout row=s.column();row.setPadding(s.dp(12),s.dp(10),s.dp(12),s.dp(10));row.setBackground(s.shape(night?(mine?0xff2e4d40:0xff2a3d33):mine?PhoneStyle.PALE:0xfff1f0e9,14));LayoutParams lp=new LayoutParams(-1,-2);lp.topMargin=s.dp(9);lp.leftMargin=s.dp(mine?22:0);lp.rightMargin=s.dp(mine?0:22);messages.addView(row,lp);
|
||||
String name=(mine?"我 · ":"")+item.optString("senderName","设备");TextView author=s.bold(name,14);author.setTextColor(ink);row.addView(author);
|
||||
row.addView(s.label(new java.text.SimpleDateFormat("yyyy-MM-dd HH:mm:ss",Locale.CHINA).format(new Date((long)(item.optDouble("at")*1000))),11,muted));
|
||||
Button voice=s.button("▶ 语音 · "+String.format(Locale.CHINA,"%.1f",item.optDouble("seconds"))+" 秒",mine);if(night){voice.setTextColor(ink);voice.setBackground(s.shape(0xff355549,14));}voice.setContentDescription("播放 "+name+" 的语音");voice.setOnClickListener(v->replay.accept(item.optString("id")));row.addView(voice,new LayoutParams(-1,-2));
|
||||
String delivery=item.optString("delivery"),archive=item.optString("archive");
|
||||
String state=delivery.equals("played")?"已播放":delivery.equals("received")?"已送达":delivery.equals("queued")?"等待播放":"未自动播放 · 可以回听";
|
||||
row.addView(s.label(state+" · "+(archive.equals("cloud")?"已存网盘":archive.equals("retry")?"网盘归档重试中":"网盘归档中"),11,muted));
|
||||
}
|
||||
if(!past&&follow)scroll.post(()->scroll.fullScroll(FOCUS_DOWN));else scroll.post(()->scroll.scrollTo(0,past?0:oldScroll));
|
||||
}
|
||||
}
|
||||
@@ -21,6 +21,7 @@ final class VoicePanel extends LinearLayout {
|
||||
final Handler ui=new Handler();final ExecutorService worker=Executors.newSingleThreadExecutor();
|
||||
final TextView status;final Button speak,settings,stop;final VoiceSurface dock;VoiceSurface expanded,page;Dialog sheet;
|
||||
String selectedId="";boolean networkReady=false;long feedbackAt=0;
|
||||
boolean communicationVisible=false,historyLoading=false,historyPlayback=false;long historyBefore=0,nextBefore=0;int historyEpoch=0,playbackRequest=0;String historyPeer="";
|
||||
final AudioManager audio;final AudioAttributes attributes=new AudioAttributes.Builder().setUsage(AudioAttributes.USAGE_MEDIA).setContentType(AudioAttributes.CONTENT_TYPE_SPEECH).build();
|
||||
AudioFocusRequest focus;MediaRecorder recorder;MediaPlayer player;File recording,playing;
|
||||
JSONArray choices=new JSONArray(),allowed=new JSONArray(),destinations=new JSONArray();
|
||||
@@ -36,9 +37,12 @@ final class VoicePanel extends LinearLayout {
|
||||
for(File file:Optional.ofNullable(app.getCacheDir().listFiles()).orElse(new File[0]))if(file.getName().startsWith("voice-"))file.delete();
|
||||
}
|
||||
void showStatus(String text){VoiceSurface.text(status,text);feedbackAt=SystemClock.elapsedRealtime();if(expanded!=null)VoiceSurface.text(expanded.status,text);if(page!=null)VoiceSurface.text(page.status,text);}
|
||||
VoiceSurface page(){if(page==null){page=new VoiceSurface(app,true);wire(page);page.expand.setVisibility(GONE);page.applyTheme(night);}renderSurfaces();return page;}
|
||||
VoiceSurface page(){if(page==null){page=new VoiceSurface(app,true);page.communicationPage();wire(page);page.expand.setVisibility(GONE);page.applyTheme(night);}renderSurfaces();return page;}
|
||||
void communication(boolean value){communicationVisible=value;if(value)loadConversation(false);}
|
||||
void chooseTarget(){if(recorder!=null||sending)return;if(destinations==null||destinations.length()==0){new AlertDialog.Builder(app).setTitle("暂无可接收的家人").setMessage("请对方打开 App,在接收设置中允许你向其喊话。显示终端也需要先授权。").setPositiveButton("知道了",null).show();return;}String[] names=new String[destinations.length()];int selected=-1;for(int i=0;i<names.length;i++){JSONObject d=destinations.optJSONObject(i);names[i]=d.optString("name")+" · "+(d.optBoolean("online")?"在线":"未打开 App");if(d.optString("id").equals(selectedId))selected=i;}final JSONArray snapshot=destinations;new AlertDialog.Builder(app).setTitle("发给谁").setSingleChoiceItems(names,selected,(d,i)->{choose(snapshot.optJSONObject(i).optString("id"));d.dismiss();}).setNegativeButton("取消",null).show();}
|
||||
void wire(VoiceSurface view){
|
||||
view.chat.older.setOnClickListener(v->{if(!historyLoading&&nextBefore>0){historyBefore=nextBefore;loadConversation(true);}});
|
||||
view.chat.latest.setOnClickListener(v->{if(!historyLoading){historyBefore=0;loadConversation(true);}});
|
||||
view.settings.setOnClickListener(v->configure());view.stop.setOnClickListener(v->stopPlayer("rejected"));
|
||||
view.destinationCard.setOnClickListener(v->chooseTarget());
|
||||
view.receiver.setOnClickListener(v->{view.receiver.setChecked(enabled);if(enabled)saveSettings(false,new JSONArray());else configure();});
|
||||
@@ -60,16 +64,16 @@ final class VoicePanel extends LinearLayout {
|
||||
expanded=new VoiceSurface(app,true);wire(expanded);expanded.applyTheme(night);
|
||||
ScrollView scroll=new ScrollView(app);scroll.setFillViewport(true);scroll.addView(expanded);
|
||||
sheet=new Dialog(app,android.R.style.Theme_Material_Light_NoActionBar);sheet.setContentView(scroll);
|
||||
sheet.setOnDismissListener(d->{finish(false);expanded=null;sheet=null;});sheet.show();
|
||||
sheet.setOnDismissListener(d->{finish(false);expanded=null;sheet=null;});sheet.show();loadConversation(false);
|
||||
sheet.getWindow().setLayout(-1,-1);sheet.getWindow().setStatusBarColor(night?0xff172820:0xfff8f5ed);sheet.getWindow().setNavigationBarColor(night?0xff172820:0xfff8f5ed);
|
||||
sheet.getWindow().getDecorView().setSystemUiVisibility(night?0:View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR|View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR);
|
||||
renderSurfaces();
|
||||
}
|
||||
JSONObject destination(){if(destinations!=null)for(int i=0;i<destinations.length();i++){JSONObject d=destinations.optJSONObject(i);if(d!=null&&d.optString("id").equals(selectedId))return d;}return null;}
|
||||
void choose(String id){if(recorder!=null||sending)return;selectedId=id;lastMessage="";JSONObject d=destination();showStatus(d!=null&&d.optBoolean("online")?"按住说话,松开发送给 "+d.optString("name"):"请先让对方打开 App,再向其喊话");renderSurfaces();}
|
||||
void choose(String id){if(recorder!=null||sending)return;stopPlayer("rejected");selectedId=id;lastMessage="";clearHistory("正在读取聊天记录…");JSONObject d=destination();showStatus(d!=null&&d.optBoolean("online")?"按住说话,松开发送给 "+d.optString("name"):"可以回听历史;发送需要对方授权并在线");renderSurfaces();loadConversation(true);}
|
||||
void renderSurfaces(){
|
||||
JSONObject selected=destination();String name=selected==null?"":selected.optString("name");boolean available=selected!=null&&selected.optBoolean("online");
|
||||
boolean can=networkReady&&available&&!sending&µphone();int amplitude=0;if(recorder!=null)try{amplitude=recorder.getMaxAmplitude();}catch(Exception ignored){}
|
||||
boolean can=networkReady&&available&&selected.optBoolean("canSend",true)&&!sending&µphone();int amplitude=0;if(recorder!=null)try{amplitude=recorder.getMaxAmplitude();}catch(Exception ignored){}
|
||||
for(VoiceSurface view:new VoiceSurface[]{dock,expanded,page}){if(view==null)continue;
|
||||
if(recorder==null||view.full)VoiceSurface.text(view.recipient,name.isEmpty()?"选择一位家人":view.full?name:name+" · "+(available?"已打开 App":"未打开 App")+" ›");view.destination(selected,networkReady);view.receiving(enabled,networkReady&&recorder==null&&!sending);
|
||||
VoiceSurface.text(view.receive,enabled?"● 接收已开启 · 仅限你允许的家人":"○ 接收已关闭 · 可在接收设置中开启");
|
||||
@@ -83,7 +87,7 @@ final class VoicePanel extends LinearLayout {
|
||||
boolean current(int e,String t){return visible&&!closed&&e==epoch&&t.equals(token.get());}
|
||||
void active(boolean value){
|
||||
if(closed)return;visible=value;epoch++;ui.removeCallbacks(refresh);ui.removeCallbacks(visual);
|
||||
if(value){ui.post(refresh);ui.post(visual);}else{if(sheet!=null)sheet.dismiss();finish(false);stopPlayer("rejected");String t=token.get();if(!t.isEmpty())worker.execute(()->{try{DisplayApi.call("/api/voice",t,body("offline"));}catch(Exception ignored){}});}
|
||||
if(value){ui.post(refresh);ui.post(visual);}else{clearHistory("打开沟通后读取记录");if(sheet!=null)sheet.dismiss();finish(false);stopPlayer("rejected");String t=token.get();if(!t.isEmpty())worker.execute(()->{try{DisplayApi.call("/api/voice",t,body("offline"));}catch(Exception ignored){}});}
|
||||
}
|
||||
void rebound(){active(false);choices=new JSONArray();allowed=new JSONArray();destinations=new JSONArray();enabled=false;networkReady=false;selectedId="";lastMessage="";active(true);}
|
||||
void close(){active(false);closed=true;ui.removeCallbacksAndMessages(null);worker.shutdown();}
|
||||
@@ -93,14 +97,41 @@ final class VoicePanel extends LinearLayout {
|
||||
worker.execute(()->{try{
|
||||
JSONObject value=DisplayApi.call("/api/voice",t,body("status"));
|
||||
ui.post(()->{if(!current(e,t))return;choices=value.optJSONArray("candidates");allowed=value.optJSONArray("allowed");enabled=value.optBoolean("enabled");networkReady=true;settings.setEnabled(true);
|
||||
if(!enabled&&player!=null)stopPlayer("rejected");
|
||||
if(recorder==null&&!sending){destinations=value.optJSONArray("targets");if(destination()==null){selectedId="";if(destinations!=null&&destinations.length()>0){selectedId=destinations.optJSONObject(0).optString("id");for(int i=0;i<destinations.length();i++){JSONObject d=destinations.optJSONObject(i);if(d.optBoolean("online")){selectedId=d.optString("id");break;}}}}}
|
||||
if(!enabled&&player!=null&&!historyPlayback)stopPlayer("rejected");
|
||||
if(recorder==null&&!sending){destinations=withConversations(value);if(destination()==null){selectedId="";if(destinations!=null&&destinations.length()>0){selectedId=destinations.optJSONObject(0).optString("id");for(int i=0;i<destinations.length();i++){JSONObject d=destinations.optJSONObject(i);if(d.optBoolean("online")){selectedId=d.optString("id");break;}}}}}
|
||||
JSONArray sent=value.optJSONArray("sent");if(sent!=null&&!lastMessage.isEmpty()&&recorder==null&&player==null&&!sending)for(int i=0;i<sent.length();i++){JSONObject r=sent.optJSONObject(i);if(lastMessage.equals(r.optString("id"))){String s=r.optString("status");showStatus(s.equals("played")?"对方已播放":s.equals("rejected")?"对方已停止或未播放":s.equals("expired")?"喊话已过期,未播放":s.equals("received")?"对方正在接收":"已发送,等待对方播放");}}
|
||||
if(lastMessage.isEmpty()&&player==null&&recorder==null&&!sending&&SystemClock.elapsedRealtime()-feedbackAt>12000)showStatus(destination()==null?"暂无允许接收的家人,请对方开启接收":!destination().optBoolean("online")?"请对方打开 App 后再说话":"按住说话,松开发送 · 上滑取消");
|
||||
renderSurfaces();
|
||||
loadConversation(false);
|
||||
JSONArray inbox=value.optJSONArray("inbox");if(enabled&&player==null&&recorder==null&&!sending&&inbox!=null&&inbox.length()>0)take(inbox.optJSONObject(0).optString("id"));
|
||||
});
|
||||
}catch(Exception error){ui.post(()->{if(current(e,t)){networkReady=false;speak.setEnabled(false);settings.setEnabled(false);if(error instanceof DisplayApi.ApiError&&(((DisplayApi.ApiError)error).status==401||((DisplayApi.ApiError)error).status==403)){finish(false);stopPlayer("rejected");enabled=false;destinations=new JSONArray();}showStatus("喊话连接暂不可用,请检查网络和配对");}});}finally{ui.post(()->polling=false);}});
|
||||
}catch(Exception error){ui.post(()->{if(current(e,t)){networkReady=false;speak.setEnabled(false);settings.setEnabled(false);if(error instanceof DisplayApi.ApiError&&(((DisplayApi.ApiError)error).status==401||((DisplayApi.ApiError)error).status==403)){finish(false);stopPlayer("rejected");enabled=false;destinations=new JSONArray();clearHistory("配对失效,请重新配对后查看");}showStatus("沟通连接暂不可用,请检查网络和配对");}});}finally{ui.post(()->polling=false);}});
|
||||
}
|
||||
JSONArray withConversations(JSONObject value){
|
||||
JSONArray result=new JSONArray(),targets=value.optJSONArray("targets"),saved=value.optJSONArray("conversations");HashSet<String> keys=new HashSet<>();
|
||||
if(targets!=null)for(int i=0;i<targets.length();i++){JSONObject item=targets.optJSONObject(i);if(item!=null){result.put(item);keys.add(item.optString("archiveKey"));}}
|
||||
if(saved!=null)for(int i=0;i<saved.length();i++){JSONObject item=saved.optJSONObject(i);if(item==null||keys.contains(item.optString("archiveKey")))continue;try{JSONObject copy=new JSONObject(item.toString());copy.put("id","archive:"+item.optString("archiveKey")).put("online",false).put("canSend",false);result.put(copy);}catch(Exception ignored){}}
|
||||
return result;
|
||||
}
|
||||
void clearHistory(String reason){historyEpoch++;historyLoading=false;historyPeer="";historyBefore=0;nextBefore=0;for(VoiceSurface v:new VoiceSurface[]{page,expanded})if(v!=null){v.chat.clear(reason);v.chat.latest.setEnabled(true);}}
|
||||
void loadConversation(boolean force){
|
||||
if(!visible||closed||!networkReady||(!communicationVisible&&expanded==null)||historyLoading)return;
|
||||
JSONObject d=destination();String peer=d==null?"":d.optString("archiveKey");
|
||||
if(peer.isEmpty()){clearHistory("选择允许沟通的家人或设备");return;}
|
||||
if(!peer.equals(historyPeer)){clearHistory("正在读取聊天记录…");historyPeer=peer;}
|
||||
if(!force&&historyBefore>0)return;
|
||||
final String t=token.get();final int e=epoch,request=++historyEpoch;final long before=historyBefore;historyLoading=true;
|
||||
for(VoiceSurface view:new VoiceSurface[]{page,expanded})if(view!=null){view.chat.older.setEnabled(false);view.chat.latest.setEnabled(false);}
|
||||
worker.execute(()->{try{
|
||||
JSONObject result=DisplayApi.call("/api/voice",t,body("history").put("peer",peer).put("before",before));
|
||||
ui.post(()->{if(!current(e,t)||request!=historyEpoch||!peer.equals(historyPeer))return;nextBefore=result.optLong("before");JSONArray items=result.optJSONArray("items");for(VoiceSurface view:new VoiceSurface[]{page,expanded})if(view!=null)view.chat.show(items==null?new JSONArray():items,nextBefore>0,before>0,this::replay);});
|
||||
}catch(Exception error){ui.post(()->{if(current(e,t)&&request==historyEpoch)for(VoiceSurface view:new VoiceSurface[]{page,expanded})if(view!=null)view.chat.notice.setText("聊天记录未能刷新,点“最近”重试");});}
|
||||
finally{ui.post(()->{if(request==historyEpoch){historyLoading=false;for(VoiceSurface view:new VoiceSurface[]{page,expanded})if(view!=null){view.chat.latest.setEnabled(true);view.chat.older.setEnabled(nextBefore>0);}}});}});
|
||||
}
|
||||
void replay(String id){
|
||||
if(!visible||!networkReady||recorder!=null||sending)return;stopPlayer("rejected");playingId=id;historyPlayback=true;String t=token.get();int e=epoch,request=++playbackRequest;showStatus("正在读取历史语音…");
|
||||
worker.execute(()->{try{JSONObject clip=DisplayApi.call("/api/voice",t,body("replay").put("id",id));byte[] bytes=Base64.decode(clip.getString("audio"),Base64.DEFAULT);ui.post(()->{if(current(e,t)&&request==playbackRequest&&historyPlayback&&playingId.equals(id)&&recorder==null)play(clip,t,bytes);});}
|
||||
catch(Exception error){ui.post(()->{if(current(e,t)&&request==playbackRequest&&playingId.equals(id)){stopPlayer("rejected");showStatus("未能回听,请检查网盘和网络后再点一次");}});}});
|
||||
}
|
||||
String selectedTarget(){return destination()==null?"":selectedId;}
|
||||
void night(boolean value){night=value;dock.applyTheme(value);if(expanded!=null)expanded.applyTheme(value);if(page!=null)page.applyTheme(value);renderSurfaces();}
|
||||
@@ -119,7 +150,7 @@ final class VoicePanel extends LinearLayout {
|
||||
}
|
||||
void begin(){
|
||||
if(!visible||!networkReady||recorder!=null||sending||selectedTarget().isEmpty())return;
|
||||
JSONObject target=destination();if(target==null||!target.optBoolean("online")){showStatus("请先让对方打开 App");return;}
|
||||
JSONObject target=destination();if(target==null||!target.optBoolean("online")||!target.optBoolean("canSend",true)){showStatus("请先让对方授权并打开 App");return;}
|
||||
if(!microphone()){showStatus("请先连接麦克风;仍可接收家人喊话");return;}
|
||||
if(app.checkSelfPermission(Manifest.permission.RECORD_AUDIO)!=0){app.requestPermissions(new String[]{Manifest.permission.RECORD_AUDIO},46);showStatus("授权麦克风后,再次按住说话");return;}
|
||||
stopPlayer("rejected");cancelled=false;recordTarget=selectedTarget();recordToken=token.get();lastMessage="";
|
||||
@@ -144,27 +175,28 @@ final class VoicePanel extends LinearLayout {
|
||||
}
|
||||
void take(String id){
|
||||
// Reserve the playback slot while the download is in flight.
|
||||
if(!playingId.isEmpty())return;playingId=id;String t=token.get();int e=epoch;
|
||||
if(!playingId.isEmpty())return;playingId=id;historyPlayback=false;String t=token.get();int e=epoch,request=++playbackRequest;
|
||||
worker.execute(()->{try{
|
||||
JSONObject clip=DisplayApi.call("/api/voice",t,body("take").put("id",id));byte[] bytes=Base64.decode(clip.getString("audio"),Base64.DEFAULT);
|
||||
ui.post(()->{if(!current(e,t)||!enabled||recorder!=null||!playingId.equals(id)){ack(t,id,"rejected");return;}play(clip,t,bytes);});
|
||||
}catch(Exception error){ui.post(()->{if(current(e,t)&&playingId.equals(id))playingId="";});}});
|
||||
ui.post(()->{if(!current(e,t)||request!=playbackRequest||!enabled||recorder!=null||!playingId.equals(id)){ack(t,id,"rejected");return;}play(clip,t,bytes);});
|
||||
}catch(Exception error){ui.post(()->{if(current(e,t)&&request==playbackRequest&&playingId.equals(id))playingId="";});}});
|
||||
}
|
||||
void play(JSONObject clip,String t,byte[] bytes){
|
||||
try{
|
||||
playingToken=t;focus=new AudioFocusRequest.Builder(AudioManager.AUDIOFOCUS_GAIN_TRANSIENT).setAudioAttributes(attributes).setOnAudioFocusChangeListener(change->{if(change<0)stopPlayer("rejected");}).build();
|
||||
if(audio.requestAudioFocus(focus)!=AudioManager.AUDIOFOCUS_REQUEST_GRANTED)throw new IOException("Audio busy");
|
||||
playing=File.createTempFile("voice-play-",".aac",app.getCacheDir());Files.write(playing.toPath(),bytes);player=new MediaPlayer();player.setAudioAttributes(attributes);player.setDataSource(playing.getAbsolutePath());
|
||||
player.setOnPreparedListener(p->{if(visible&&enabled&&p==player){p.start();stop.setEnabled(true);showStatus(clip.optString("senderName")+"正在喊话 · "+clip.optDouble("seconds")+" 秒");}else stopPlayer("rejected");});
|
||||
player.setOnPreparedListener(p->{if(visible&&(enabled||historyPlayback)&&p==player){p.start();stop.setEnabled(true);showStatus(clip.optString("senderName")+(historyPlayback?" · 历史语音 · ":"正在喊话 · ")+clip.optDouble("seconds")+" 秒");}else stopPlayer("rejected");});
|
||||
player.setOnCompletionListener(p->stopPlayer("played"));player.setOnErrorListener((p,what,extra)->{stopPlayer("rejected");return true;});player.prepareAsync();
|
||||
}catch(Exception error){stopPlayer("rejected");showStatus("语音未能播放,请检查扬声器");}
|
||||
}
|
||||
void stopPlayer(String outcome){
|
||||
playbackRequest++;
|
||||
if(player!=null){try{player.release();}catch(Exception ignored){}player=null;}
|
||||
if(focus!=null){audio.abandonAudioFocusRequest(focus);focus=null;}
|
||||
if(playing!=null){playing.delete();playing=null;}
|
||||
if(!playingId.isEmpty()&&!playingToken.isEmpty())ack(playingToken,playingId,outcome);
|
||||
playingId="";playingToken="";stop.setEnabled(false);renderSurfaces();
|
||||
if(!historyPlayback&&!playingId.isEmpty()&&!playingToken.isEmpty())ack(playingToken,playingId,outcome);
|
||||
playingId="";playingToken="";historyPlayback=false;stop.setEnabled(false);renderSurfaces();
|
||||
}
|
||||
void ack(String t,String id,String state){if(!worker.isShutdown())worker.execute(()->{try{DisplayApi.call("/api/voice",t,body("ack").put("id",id).put("status",state));}catch(Exception ignored){}});}
|
||||
}
|
||||
|
||||
@@ -14,7 +14,8 @@ final class VoiceSurface extends LinearLayout {
|
||||
final boolean full;final TextView title,subtitle,recipient,status,hint,clock,receive;
|
||||
final Button speak,settings,stop,expand;final LinearLayout people,compose;final HorizontalScrollView strip;
|
||||
final VoiceArt art;final Switch receiver;final LinearLayout destinationCard,receiverCard,playbackCard;final TextView availability;final ImageView destinationIcon;
|
||||
boolean night=false;String targetSignature="",controlSignature="";
|
||||
final VoiceChat chat;
|
||||
boolean night=false,communicationPage=false,compact=false;String targetSignature="",controlSignature="";
|
||||
int ink(){return night?0xffc8d5cd:0xff29443c;}int muted(){return night?0xff96aaa0:0xff65766d;}
|
||||
int accent(){return night?0xff456b5e:0xff17695e;}int paper(){return night?0xff172820:0xfff8f5ed;}
|
||||
int card(){return night?0xff21372d:0xfffffefa;}
|
||||
@@ -22,7 +23,7 @@ final class VoiceSurface extends LinearLayout {
|
||||
VoiceSurface(Activity activity,boolean expanded){
|
||||
super(activity);full=expanded;setOrientation(VERTICAL);setPadding(dp(full?20:12),dp(full?20:8),dp(full?20:12),dp(full?22:8));
|
||||
LinearLayout header=new LinearLayout(activity);header.setGravity(Gravity.CENTER_VERTICAL);addView(header);
|
||||
title=label(full?"家人喊话":"家人喊话",full?30:19);title.setTypeface(null,Typeface.BOLD);header.addView(title,new LayoutParams(0,-2,1));
|
||||
title=label("沟通",full?28:19);title.setTypeface(null,Typeface.BOLD);header.addView(title,new LayoutParams(0,-2,1));
|
||||
settings=button("管理",14);expand=button(full?"收起":"展开",14);if(!full)header.addView(expand);
|
||||
subtitle=label("一句问候,家就在身边",15);if(full){addView(subtitle);space(20);}
|
||||
strip=new HorizontalScrollView(activity);strip.setHorizontalScrollBarEnabled(false);strip.setClipToPadding(false);
|
||||
@@ -33,6 +34,7 @@ final class VoiceSurface extends LinearLayout {
|
||||
TextView sendLabel=label("发送到",12);sendLabel.setTextColor(0xff718078);targetWords.addView(sendLabel);
|
||||
recipient=label("选择一位家人",full?21:15);recipient.setTypeface(null,Typeface.BOLD);recipient.setMaxLines(2);recipient.setEllipsize(android.text.TextUtils.TruncateAt.END);if(full)targetWords.addView(recipient);else addView(recipient);
|
||||
availability=label("切换接收对象 ›",13);targetWords.addView(availability);destinationCard.setFocusable(true);destinationCard.setClickable(true);
|
||||
chat=new VoiceChat(activity);if(full){space(12);addView(chat,new LayoutParams(-1,-2));}
|
||||
compose=new LinearLayout(activity);compose.setOrientation(VERTICAL);compose.setGravity(Gravity.CENTER_HORIZONTAL);compose.setPadding(dp(full?4:0),dp(full?20:0),dp(full?4:0),dp(full?12:0));addView(compose,new LayoutParams(-1,-2));
|
||||
art=new VoiceArt(activity);art.setImportantForAccessibility(IMPORTANT_FOR_ACCESSIBILITY_NO);
|
||||
clock=label("按住说话",22);clock.setGravity(Gravity.CENTER);
|
||||
@@ -48,6 +50,24 @@ final class VoiceSurface extends LinearLayout {
|
||||
applyTheme(false);
|
||||
}
|
||||
TextView label(String text,int size){TextView v=new TextView(getContext());v.setText(text);v.setTextSize(size);v.setPadding(0,dp(3),0,dp(3));return v;}
|
||||
void communicationPage(){
|
||||
communicationPage=true;
|
||||
removeView(receiverCard);removeView(playbackCard);chat.addView(playbackCard,new LayoutParams(-1,-2));
|
||||
subtitle.setVisibility(GONE);compose.setPadding(0,dp(8),0,0);speak.setLayoutParams(new LayoutParams(dp(150),dp(150)));clock.setLayoutParams(new LayoutParams(-1,dp(42)));art.setLayoutParams(new LayoutParams(-1,dp(18)));
|
||||
destinationCard.setPadding(dp(12),dp(10),dp(12),dp(10));setPadding(dp(16),dp(10),dp(16),dp(6));
|
||||
chat.setLayoutParams(new LayoutParams(-1,0,1));chat.scroll.setLayoutParams(new LayoutParams(-1,0,1));
|
||||
status.setTextSize(12);playbackCard.setPadding(0,dp(4),0,dp(4));
|
||||
}
|
||||
protected void onMeasure(int width,int height){
|
||||
int available=View.MeasureSpec.getSize(height);boolean small=available>0&&available<dp(680);
|
||||
if(communicationPage&&available>0&&small!=compact){compact=small;
|
||||
title.setTextSize(small?23:28);recipient.setTextSize(small?18:21);speak.setLayoutParams(new LayoutParams(dp(small?120:150),dp(small?120:150)));clock.setLayoutParams(new LayoutParams(-1,dp(small?32:42)));art.setLayoutParams(new LayoutParams(-1,dp(small?12:18)));
|
||||
for(int i=0;i<getChildCount();i++){View child=getChildAt(i);if(child.getClass()==View.class)child.setLayoutParams(new LayoutParams(1,dp(small?4:12)));}
|
||||
destinationIcon.setLayoutParams(new LayoutParams(dp(small?38:52),dp(small?38:52)));destinationCard.setPadding(dp(12),dp(small?5:10),dp(12),dp(small?5:10));
|
||||
chat.setPadding(dp(small?12:16),dp(small?10:16),dp(small?12:16),dp(small?10:16));
|
||||
}
|
||||
super.onMeasure(width,height);
|
||||
}
|
||||
void compactHome(){
|
||||
if(full)return;removeAllViews();for(View v:new View[]{recipient,speak,status,stop})if(v.getParent()!=null)((ViewGroup)v.getParent()).removeView(v);
|
||||
setPadding(dp(12),dp(10),dp(12),dp(8));setBackground(shape(card(),0,18));LinearLayout row=new LinearLayout(getContext());row.setGravity(Gravity.CENTER_VERTICAL);
|
||||
@@ -59,7 +79,7 @@ final class VoiceSurface extends LinearLayout {
|
||||
void space(int amount){spaceIn(this,amount);}void spaceIn(LinearLayout parent,int amount){parent.addView(new View(getContext()),new LayoutParams(1,dp(amount)));}
|
||||
GradientDrawable shape(int color,int border,int radius){GradientDrawable d=new GradientDrawable();d.setColor(color);d.setCornerRadius(dp(radius));if(border!=0)d.setStroke(dp(1),border);return d;}
|
||||
void applyTheme(boolean value){
|
||||
night=value;setBackgroundColor(paper());for(TextView t:new TextView[]{title,recipient,clock})t.setTextColor(ink());for(TextView t:new TextView[]{subtitle,status,hint,receive})t.setTextColor(muted());
|
||||
night=value;chat.theme(value);setBackgroundColor(paper());for(TextView t:new TextView[]{title,recipient,clock})t.setTextColor(ink());for(TextView t:new TextView[]{subtitle,status,hint,receive})t.setTextColor(muted());
|
||||
compose.setBackground(null);for(View v:new View[]{destinationCard,receiverCard,playbackCard})v.setBackground(full?shape(card(),0,20):null);receiver.setTextColor(ink());availability.setTextColor(muted());
|
||||
for(Button b:new Button[]{settings,stop,expand}){b.setTextColor(ink());b.setBackground(shape(night?0xff2d4439:0xffefeee6,0,18));}
|
||||
art.night=value;art.invalidate();targetSignature="";controlSignature="";
|
||||
@@ -67,7 +87,7 @@ final class VoiceSurface extends LinearLayout {
|
||||
void destination(JSONObject selected,boolean ready){
|
||||
String name=selected==null?"选择一位家人":selected.optString("name","家人");boolean online=selected!=null&&selected.optBoolean("online");
|
||||
destinationIcon.setImageDrawable(new PhoneStyle.Icon(selected!=null&&"display".equals(selected.optString("kind"))?"display":"person",accent(),dp(48)));
|
||||
text(availability,selected==null?"点击选择接收对象 ›":(!ready?"连接待恢复":online?"● 在线":"○ 未打开 App")+" · 切换 ›");destinationCard.setContentDescription("发送到 "+name+","+availability.getText());
|
||||
text(availability,selected==null?"点击选择接收对象 ›":(!ready?"连接待恢复":!selected.optBoolean("canSend",true)?"历史会话 · 发送需重新授权":online?"● 在线":"○ 未打开 App")+" · 切换 ›");destinationCard.setContentDescription("发送到 "+name+","+availability.getText());
|
||||
}
|
||||
void receiving(boolean enabled,boolean ready){receiver.setChecked(enabled);receiver.setEnabled(ready);}
|
||||
void targets(JSONArray values,String selected,Consumer<String> choose){
|
||||
@@ -90,7 +110,7 @@ final class VoiceSurface extends LinearLayout {
|
||||
android.text.SpannableString text=new android.text.SpannableString(" "+label);text.setSpan(new android.text.style.ImageSpan(inline,android.text.style.ImageSpan.ALIGN_BOTTOM),0,1,android.text.Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);if(!full&&(!android.text.TextUtils.equals(speak.getText(),text)||!controlSignature.equals(color+":"+night)))speak.setText(text);if(full){text(speak,"");speak.setContentDescription(label+",上滑取消,最长 30 秒");}speak.setTextColor(night?0xffd1dfd5:Color.WHITE);
|
||||
String signature=color+":"+night;if(!signature.equals(controlSignature)){controlSignature=signature;
|
||||
speak.setBackground(new RippleDrawable(ColorStateList.valueOf(0x337fffff),full?new VoiceCircle(color,night):shape(color,0,32),null));}
|
||||
clock.setTextSize(recording?32:23);clock.setTypeface(null,Typeface.BOLD);text(clock,recording?String.format(java.util.Locale.ROOT,"00:%02d",Math.min(30,duration/1000)):uploading?"正在发送…":"按住说话");clock.setTextColor(cancel?color:ink());
|
||||
clock.setTextSize(recording?(compact?24:32):compact?19:23);clock.setTypeface(null,Typeface.BOLD);text(clock,recording?String.format(java.util.Locale.ROOT,"00:%02d",Math.min(30,duration/1000)):uploading?"正在发送…":"按住说话");clock.setTextColor(cancel?color:ink());
|
||||
text(hint,recording?(cancel?"松开手指,取消这条语音":"上滑取消 · 松开发送 · 30 秒自动发送"):"上滑取消 · 最长 30 秒");hint.setTextColor(cancel?color:muted());
|
||||
art.setVisibility(recording?VISIBLE:INVISIBLE);art.level(recording,cancel,amplitude);if(!full&&recording)text(recipient,String.format(java.util.Locale.CHINA,"%s · %02d 秒",cancel?"松开即取消":"正在录音,上滑可取消",Math.min(30,duration/1000)));
|
||||
}
|
||||
|
||||
@@ -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'}
|
||||
$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)
|
||||
$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\VoiceChat.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" .
|
||||
|
||||
@@ -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