feat(android): redesign family location into three native tabs
This commit is contained in:
@@ -1,5 +1,9 @@
|
||||
# 赵府智家 · 视觉系统
|
||||
|
||||
## v0.1.52 · 家人位置手机端三页改版
|
||||
|
||||
按三屏参考图组织「家人 / 喊话 / 我的」:地图与最近位置、大号圆形喊话按钮、分组的共享与轨迹设置。采用暖白和青绿色,明细设置全屏打开;保留本人授权、离线加密暂存、补传校验和清理。手机端请从配套 App 下载页覆盖安装。[本版说明](RELEASE-v0.1.52.md)。
|
||||
|
||||
## v0.1.48 · 显示终端与家人喊话
|
||||
|
||||
修复重新配对后的旧授权残留;手机配对后直接进入家人位置,并提供按住说话、松开发送。接收方选择具体喊话人,默认关闭;显示终端可以先接收,装好话筒后再发送。手机与显示终端分别提供普通 APK。[本版说明](RELEASE-v0.1.48.md)。
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
# V0.1.52 — 家人位置手机端三页改版
|
||||
|
||||
## 界面与操作
|
||||
|
||||
- 采用用户提供的三屏参考图:暖白底、青绿色、大字号、圆角分组和本地矢量图标。底部固定「家人 / 喊话 / 我的」,保留各页滚动位置。
|
||||
- 「家人」展示家庭名称、自己的共享状态、智家地图及最近位置。点成员在地图上定位,点「轨迹」读取获授权的历史;底部固定喊话入口。地图仍加载智家第一方地图服务,原有缩放控件、比例尺和版权标识保留。
|
||||
- 「我的」按查看名单、有效期、采集频率、上传周期、历史轨迹、系统权限、配对设备分组。明细设置全屏打开;返回时保持控件与已填写内容,不重复生成授权对象。
|
||||
- 「喊话」使用明确的接收对象卡片、大号圆形话筒、录音计时、实际音量波形和上滑取消。接收开关先选择允许的家人;首页和喊话页都能停止正在播放的语音。
|
||||
- 姓名头像使用首字占位;成员、设备及在线状态来自实际授权接口,不写入设计图中的示例姓名、位置或照片。界面统一使用“显示终端”。
|
||||
|
||||
## 行为与数据
|
||||
|
||||
- 查看家人不要求共享本人位置。进入页面、切换标签、修改草稿均不会开启定位;开启共享前仍需本人核对名单并同意。轨迹保存保留独立的本人确认。
|
||||
- 修改查看名单和采集、上传频率前先关闭共享,新设置在再次开启时应用。配对有效期来自后台真实授权,不宣称已支持每个查看人单独设置有效期。
|
||||
- 采集间隔仍为 10 秒至 24 小时;上传周期仍独立支持小时、天和自定义。保留离线加密队列、恢复补传、网盘回读校验以及逐批确认后清理。
|
||||
- 切换标签、退出页面、手势中断和多指操作取消当前录音。网络不可用时不能开始喊话;页面不会自行打开麦克风或替家人开启接收。
|
||||
- 断网或配对失效后隐藏旧位置。配对更换前继续检查未同步轨迹,防止换身份后混用队列。
|
||||
|
||||
## 验证与安装
|
||||
|
||||
- Android 11 隔离包运行实际 `LocationActivity`、`PhoneLayout`、`VoicePanel` 和 `VoiceSurface`。验证首页、我的、喊话、录音、取消、320 dp 窄屏、135% 字体、未配对、断网、配对失效十种状态,以及页面切换、设置明细与控件归属。
|
||||
- 隔离包不申请网络、定位、麦克风权限;接口、地图、轨迹队列使用明确标注的测试替身。截图中的成员与地图占位仅用于验收。每轮结束卸载测试包并恢复原前台应用。
|
||||
- Python 回归 334 项、JavaScript 回归 191 项、原生周期边界 178 条断言、手势取消 9 条断言通过;Vue 静态资源构建、手机和显示终端 APK 的编译签名验证通过。
|
||||
- 真实双手机麦克风收发、不同厂商后台省电策略仍需在实际手机上复核。未连接的用户手机不会因服务器发布而自动安装。
|
||||
- 从系统的「配套 App 下载」页获取家人位置手机版并覆盖安装,保留原配对信息与本机待上传队列。显示终端 APK 仍单独提供。
|
||||
@@ -1,4 +1,4 @@
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="cn.ucvl.zhaodisplay" android:versionCode="7" android:versionName="0.1.51">
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="cn.ucvl.zhaodisplay" android:versionCode="8" android:versionName="0.1.52">
|
||||
<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="7" android:versionName="0.1.51">
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="cn.ucvl.zhaodisplay" android:versionCode="8" android:versionName="0.1.52">
|
||||
<uses-sdk android:minSdkVersion="26" android:targetSdkVersion="30"/>
|
||||
<uses-permission android:name="android.permission.INTERNET"/>
|
||||
<uses-permission android:name="android.permission.RECORD_AUDIO"/>
|
||||
|
||||
@@ -5,7 +5,7 @@ import android.os.*;
|
||||
import android.content.*;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.Manifest;
|
||||
import android.view.View;
|
||||
import android.view.*;
|
||||
import android.widget.*;
|
||||
import android.text.InputType;
|
||||
import org.json.*;
|
||||
@@ -21,15 +21,16 @@ public class LocationActivity extends Activity {
|
||||
final int[] sampleUnits={1,60,3600,86400};
|
||||
final int[] uploadIntervals={10,60,300,3600,7200,10800,14400,18000,86400,172800,259200,0};
|
||||
TextView historyStatus,historyNotice;Dialog historyDialog;LocationMapView historyMap;Button historyMore;JSONArray historyPoints=new JSONArray();int historyRequest=0;boolean historyAcknowledged=false;
|
||||
VoicePanel voice;Button settingsButton;
|
||||
LocationMapView map;boolean rendering=false,visible=false,loading=false,settingsReady=false,pendingStart=false;
|
||||
VoicePanel voice;Button settingsButton;PhoneLayout phone;PhoneStyle style;Dialog detailDialog;
|
||||
LinearLayout pairSection,recipientSection,sampleSection,uploadSection,historySection,permissionSection,consentSection;
|
||||
LocationMapView map;boolean rendering=false,visible=false,loading=false,settingsReady=false,pendingStart=false,bindingRejected=false;
|
||||
int generation=0,settingsRequest=0;long lastList=0;String settingsReceipt="",settingsError="";
|
||||
final Map<String,List<CheckBox>> choices=new HashMap<>();
|
||||
android.content.SharedPreferences prefs;
|
||||
final Handler ui=new Handler();
|
||||
final Runnable refresh=new Runnable(){public void run(){if(!visible)return;render();if(SystemClock.elapsedRealtime()-lastList>15000)loadFamily();ui.postDelayed(this,2000);}};
|
||||
TextView text(String value,int size,LinearLayout parent){TextView t=new TextView(this);t.setText(value);t.setTextSize(size);t.setTextColor(0xff263e35);t.setPadding(0,12,0,12);parent.addView(t);return t;}
|
||||
Button button(String label,LinearLayout parent){Button b=new Button(this);b.setText(label);parent.addView(b);return b;}
|
||||
TextView text(String value,int size,LinearLayout parent){TextView t=style.label(value,size,PhoneStyle.INK);t.setPadding(0,style.dp(10),0,style.dp(10));parent.addView(t);return t;}
|
||||
Button button(String label,LinearLayout parent){Button b=style.button(label,false);LinearLayout.LayoutParams lp=new LinearLayout.LayoutParams(-1,-2);lp.topMargin=style.dp(8);parent.addView(b,lp);return b;}
|
||||
public void onCreate(Bundle state){
|
||||
super.onCreate(state);prefs=getSharedPreferences("location",0);
|
||||
outbox=new LocationQueue(this);refreshQueueStats();
|
||||
@@ -40,64 +41,96 @@ public class LocationActivity extends Activity {
|
||||
prefs.edit().putBoolean("active",false).putString("status","共享已中断,请本人重新开启").apply();
|
||||
startService(new Intent(this,LocationService.class).setAction("STOP"));
|
||||
}
|
||||
LinearLayout layout=new LinearLayout(this);layout.setOrientation(1);int p=(int)(20*getResources().getDisplayMetrics().density);layout.setPadding(p,p,p,p);layout.setBackgroundColor(0xfff5f2e9);
|
||||
LinearLayout root=new LinearLayout(this);root.setOrientation(1);ScrollView scroll=new ScrollView(this);scroll.addView(layout);root.addView(scroll,new LinearLayout.LayoutParams(-1,0,1));setContentView(root);
|
||||
text("家人位置",30,layout);identity=text("",17,layout);
|
||||
text("只显示家人主动授权给这台手机的位置。查看家人不需要开启自己的定位。",16,layout);
|
||||
settingsButton=button("我的位置设置",layout);settingsButton.setOnClickListener(v->{settings.setVisibility(settings.getVisibility()==View.VISIBLE?View.GONE:View.VISIBLE);if(settings.getVisibility()==View.VISIBLE)loadSettings();});
|
||||
status=text("",16,layout);
|
||||
settings=new LinearLayout(this);settings.setOrientation(1);layout.addView(settings);
|
||||
text("配对本人 · 无需注册或登录",22,settings);
|
||||
text("请家人在平台进入家庭总览 → 为家庭成员配对手机,选择你的成员档案。这里使用手机配对码,不使用显示终端配对码。",16,settings);
|
||||
code=new EditText(this);code.setHint("八位手机配对码");code.setInputType(InputType.TYPE_CLASS_NUMBER);code.setFilters(new android.text.InputFilter[]{new android.text.InputFilter.LengthFilter(8)});settings.addView(code);
|
||||
pair=button("配对我的手机",settings);pair.setOnClickListener(v->pair());
|
||||
shareControls=new LinearLayout(this);shareControls.setOrientation(1);settings.addView(shareControls);
|
||||
text("我的位置共享",22,shareControls);text("选择谁能看我的位置",16,shareControls);
|
||||
recipients=new LinearLayout(this);recipients.setOrientation(1);shareControls.addView(recipients);
|
||||
text("定位采集频率",16,shareControls);sampleCadence=new Spinner(this);sampleCadence.setAdapter(new ArrayAdapter<String>(this,android.R.layout.simple_spinner_dropdown_item,new String[]{"每 10 秒(较耗电)","每 1 分钟(默认)","每 5 分钟","每 15 分钟","每 30 分钟","每 1 小时","每 2 小时","每 3 小时","每 4 小时","每 5 小时","每 6 小时","每 12 小时","每 1 天","自定义采集间隔"}));sampleCadence.setSelection(1);shareControls.addView(sampleCadence);
|
||||
samplePeriod=new LinearLayout(this);samplePeriod.setOrientation(LinearLayout.HORIZONTAL);sampleAmount=new EditText(this);sampleAmount.setInputType(InputType.TYPE_CLASS_NUMBER);sampleAmount.setHint("正整数");sampleAmount.setText("2");sampleAmount.setFilters(new android.text.InputFilter[]{new android.text.InputFilter.LengthFilter(5)});samplePeriod.addView(sampleAmount,new LinearLayout.LayoutParams(0,-2,1));sampleUnit=new Spinner(this);sampleUnit.setAdapter(new ArrayAdapter<String>(this,android.R.layout.simple_spinner_dropdown_item,new String[]{"秒","分钟","小时","天"}));sampleUnit.setSelection(2);samplePeriod.addView(sampleUnit);shareControls.addView(samplePeriod);samplePeriod.setVisibility(View.GONE);
|
||||
style=new PhoneStyle(this);phone=new PhoneLayout(this);setContentView(phone);
|
||||
getWindow().setStatusBarColor(PhoneStyle.PAPER);getWindow().setNavigationBarColor(PhoneStyle.CARD);
|
||||
getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR|View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR);
|
||||
identity=phone.identity;status=phone.myStatus;viewStatus=phone.viewStatus;settingsButton=phone.settingsButton;
|
||||
homeContent=phone.homeContent;familyList=phone.familyList;shareControls=phone.mineContent;sharing=phone.sharing;reload=phone.refresh;
|
||||
settings=style.column();pairSection=section();recipientSection=section();sampleSection=section();uploadSection=section();historySection=section();permissionSection=section();consentSection=section();
|
||||
text("配对本人 · 无需注册或登录",22,pairSection);
|
||||
text("请家人在平台进入家庭总览 → 为家庭成员配对手机,选择你的成员档案。这里使用手机配对码,不使用显示终端配对码。",16,pairSection);
|
||||
code=new EditText(this);code.setHint("八位手机配对码");code.setInputType(InputType.TYPE_CLASS_NUMBER);code.setFilters(new android.text.InputFilter[]{new android.text.InputFilter.LengthFilter(8)});pairSection.addView(code);
|
||||
pair=button("配对我的手机",pairSection);pair.setOnClickListener(v->pair());
|
||||
text("只允许勾选的对象查看我的位置",19,recipientSection);
|
||||
text("修改名单前先关闭共享。完成设置后,重新开启共享才会应用新的授权名单。",14,recipientSection);
|
||||
recipients=style.column();recipientSection.addView(recipients);
|
||||
text("定位采集频率",16,sampleSection);sampleCadence=new Spinner(this);sampleCadence.setAdapter(new ArrayAdapter<String>(this,android.R.layout.simple_spinner_dropdown_item,new String[]{"每 10 秒(较耗电)","每 1 分钟(默认)","每 5 分钟","每 15 分钟","每 30 分钟","每 1 小时","每 2 小时","每 3 小时","每 4 小时","每 5 小时","每 6 小时","每 12 小时","每 1 天","自定义采集间隔"}));sampleCadence.setSelection(1);sampleSection.addView(sampleCadence);
|
||||
samplePeriod=new LinearLayout(this);samplePeriod.setOrientation(LinearLayout.HORIZONTAL);sampleAmount=new EditText(this);sampleAmount.setInputType(InputType.TYPE_CLASS_NUMBER);sampleAmount.setHint("正整数");sampleAmount.setText("2");sampleAmount.setFilters(new android.text.InputFilter[]{new android.text.InputFilter.LengthFilter(5)});samplePeriod.addView(sampleAmount,new LinearLayout.LayoutParams(0,-2,1));sampleUnit=new Spinner(this);sampleUnit.setAdapter(new ArrayAdapter<String>(this,android.R.layout.simple_spinner_dropdown_item,new String[]{"秒","分钟","小时","天"}));sampleUnit.setSelection(2);samplePeriod.addView(sampleUnit);sampleSection.addView(samplePeriod);samplePeriod.setVisibility(View.GONE);
|
||||
sampleCadence.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener(){public void onItemSelected(AdapterView<?> p,View v,int position,long id){samplePeriod.setVisibility(position==sampleIntervals.length-1?View.VISIBLE:View.GONE);}public void onNothingSelected(AdapterView<?> p){}});
|
||||
text("每次采集留下一个定位点。可自定义 10 秒至 24 小时,最长每天一次,不设一周。采集越稀疏越省电,但无法还原期间的完整路线。",14,shareControls);
|
||||
text("集中上传周期",16,shareControls);cadence=new Spinner(this);cadence.setAdapter(new ArrayAdapter<String>(this,android.R.layout.simple_spinner_dropdown_item,new String[]{"实时(约 10 秒)","每 1 分钟","每 5 分钟(默认)","每 1 小时","每 2 小时","每 3 小时","每 4 小时","每 5 小时","每 1 天","每 2 天","每 3 天","自定义小时 / 天"}));cadence.setSelection(2);shareControls.addView(cadence);
|
||||
customPeriod=new LinearLayout(this);customPeriod.setOrientation(0);customAmount=new EditText(this);customAmount.setInputType(InputType.TYPE_CLASS_NUMBER);customAmount.setHint("正整数");customAmount.setText("6");customAmount.setFilters(new android.text.InputFilter[]{new android.text.InputFilter.LengthFilter(3)});customPeriod.addView(customAmount,new LinearLayout.LayoutParams(0,-2,1));customUnit=new Spinner(this);customUnit.setAdapter(new ArrayAdapter<String>(this,android.R.layout.simple_spinner_dropdown_item,new String[]{"小时","天"}));customPeriod.addView(customUnit);shareControls.addView(customPeriod);customPeriod.setVisibility(View.GONE);
|
||||
text("每次采集留下一个定位点。可自定义 10 秒至 24 小时,最长每天一次,不设一周。采集越稀疏越省电,但无法还原期间的完整路线。",14,sampleSection);
|
||||
text("集中上传周期",16,uploadSection);cadence=new Spinner(this);cadence.setAdapter(new ArrayAdapter<String>(this,android.R.layout.simple_spinner_dropdown_item,new String[]{"实时(约 10 秒)","每 1 分钟","每 5 分钟(默认)","每 1 小时","每 2 小时","每 3 小时","每 4 小时","每 5 小时","每 1 天","每 2 天","每 3 天","自定义小时 / 天"}));cadence.setSelection(2);uploadSection.addView(cadence);
|
||||
customPeriod=new LinearLayout(this);customPeriod.setOrientation(0);customAmount=new EditText(this);customAmount.setInputType(InputType.TYPE_CLASS_NUMBER);customAmount.setHint("正整数");customAmount.setText("6");customAmount.setFilters(new android.text.InputFilter[]{new android.text.InputFilter.LengthFilter(3)});customPeriod.addView(customAmount,new LinearLayout.LayoutParams(0,-2,1));customUnit=new Spinner(this);customUnit.setAdapter(new ArrayAdapter<String>(this,android.R.layout.simple_spinner_dropdown_item,new String[]{"小时","天"}));customPeriod.addView(customUnit);uploadSection.addView(customPeriod);customPeriod.setVisibility(View.GONE);
|
||||
cadence.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener(){public void onItemSelected(AdapterView<?> p,View v,int position,long id){customPeriod.setVisibility(position==uploadIntervals.length-1?View.VISIBLE:View.GONE);}public void onNothingSelected(AdapterView<?> p){}});
|
||||
text("采集与上传分开:例如每分钟采集、每天集中上传。自定义 1—720 小时或 1—30 天。断网时本地暂存,恢复后自动补传;长周期期间家人无法看到实时移动。调整名单或频率前,先关闭共享。",14,shareControls);
|
||||
historyConsent=new CheckBox(this);historyConsent.setText("另行同意保存我的历史轨迹到家庭网盘,长期保留至我手动删除;共享期间允许所选查看人读取其获授权期间的记录。");shareControls.addView(historyConsent);
|
||||
historyStatus=text("未开启时不保存历史轨迹。关闭共享只清除当前位置,已保存历史可在下方删除。",14,shareControls);
|
||||
button("查看我的历史轨迹",shareControls).setOnClickListener(v->history(""));
|
||||
queueStatus=text("",15,shareControls);
|
||||
button("立即同步待上传轨迹",shareControls).setOnClickListener(v->syncNow());
|
||||
text("本机待同步上限:50,000 个点或 12 MiB 密文,先到为准。达到上限暂停新增历史,保留未上传记录。只有网盘完整回读校验通过才自动清理对应批次;手机数据库文件最多 32 MiB,空页循环复用。",13,shareControls);
|
||||
button("放弃本机待同步记录",shareControls).setOnClickListener(v->new AlertDialog.Builder(this).setTitle("放弃尚未同步完的轨迹").setMessage("将停止本机共享并删除本机待同步副本,未上传内容无法恢复。已经被平台接收的记录不受此操作影响;如需彻底删除,请使用“删除我的全部历史轨迹”。").setNegativeButton("保留记录",null).setPositiveButton("确认放弃",(d,w)->discardLocal()).show());
|
||||
button("删除我的全部历史轨迹",shareControls).setOnClickListener(v->new AlertDialog.Builder(this).setTitle("删除自己的历史轨迹").setMessage("将暂停共享、清空本机待同步轨迹并隐藏平台历史,网盘文件随后删除;此操作不能撤销。以后可重新开启共享和记录。").setNegativeButton("取消",null).setPositiveButton("确认删除",(d,w)->deleteHistory()).show());
|
||||
consent=new CheckBox(this);consent.setText("我已核对本人身份、有效期和所选查看人,同意按上述周期采集和共享位置。启用历史保存后,断网会加密暂存并补传。关闭后停止新采集并清除当前位置,关闭前已采集轨迹仍会完成上传。");shareControls.addView(consent);
|
||||
sharing=new Switch(this);sharing.setText("共享我的位置");sharing.setTextSize(20);sharing.setPadding(0,20,0,20);shareControls.addView(sharing);
|
||||
sharing.setOnCheckedChangeListener((v,checked)->{if(rendering)return;if(checked)start();else{startService(new Intent(this,LocationService.class).setAction("STOP"));consent.setChecked(false);}render();});
|
||||
permissionStatus=text("",14,shareControls);
|
||||
Button backgroundButton=button("后台定位权限 · 始终允许",shareControls);backgroundButton.setOnClickListener(v->backgroundPermission());
|
||||
text("采集与上传分开:例如每分钟采集、每天集中上传。自定义 1—720 小时或 1—30 天。断网时本地暂存,恢复后自动补传;长周期期间家人无法看到实时移动。调整名单或频率前,先关闭共享。",14,uploadSection);
|
||||
historyConsent=new CheckBox(this);historyConsent.setText("另行同意保存我的历史轨迹到家庭网盘,长期保留至我手动删除;共享期间允许所选查看人读取其获授权期间的记录。");historySection.addView(historyConsent);
|
||||
historyStatus=text("未开启时不保存历史轨迹。关闭共享只清除当前位置,已保存历史可在下方删除。",14,historySection);
|
||||
button("查看我的历史轨迹",historySection).setOnClickListener(v->history(""));
|
||||
queueStatus=text("",15,historySection);
|
||||
button("立即同步待上传轨迹",historySection).setOnClickListener(v->syncNow());
|
||||
text("本机待同步上限:50,000 个点或 12 MiB 密文,先到为准。达到上限暂停新增历史,保留未上传记录。只有网盘完整回读校验通过才自动清理对应批次;手机数据库文件最多 32 MiB,空页循环复用。",13,historySection);
|
||||
button("放弃本机待同步记录",historySection).setOnClickListener(v->new AlertDialog.Builder(this).setTitle("放弃尚未同步完的轨迹").setMessage("将停止本机共享并删除本机待同步副本,未上传内容无法恢复。已经被平台接收的记录不受此操作影响;如需彻底删除,请使用“删除我的全部历史轨迹”。").setNegativeButton("保留记录",null).setPositiveButton("确认放弃",(d,w)->discardLocal()).show());
|
||||
button("删除我的全部历史轨迹",historySection).setOnClickListener(v->new AlertDialog.Builder(this).setTitle("删除自己的历史轨迹").setMessage("将暂停共享、清空本机待同步轨迹并隐藏平台历史,网盘文件随后删除;此操作不能撤销。以后可重新开启共享和记录。").setNegativeButton("取消",null).setPositiveButton("确认删除",(d,w)->deleteHistory()).show());
|
||||
consent=new CheckBox(this);consent.setText("我已核对本人身份、有效期和所选查看人,同意按上述周期采集和共享位置。启用历史保存后,断网会加密暂存并补传。关闭后停止新采集并清除当前位置,关闭前已采集轨迹仍会完成上传。");consentSection.addView(consent);
|
||||
permissionStatus=text("",14,permissionSection);
|
||||
Button backgroundButton=button("后台定位权限 · 始终允许",permissionSection);backgroundButton.setOnClickListener(v->backgroundPermission());
|
||||
try{if(!java.util.Arrays.asList(getPackageManager().getPackageInfo(getPackageName(),PackageManager.GET_PERMISSIONS).requestedPermissions).contains(Manifest.permission.ACCESS_BACKGROUND_LOCATION))backgroundButton.setVisibility(View.GONE);}catch(Exception ignored){}
|
||||
button("打开手机系统定位设置",shareControls).setOnClickListener(v->startActivity(new Intent(android.provider.Settings.ACTION_LOCATION_SOURCE_SETTINGS)));
|
||||
settings.setVisibility(prefs.getString("token","").isEmpty()?View.VISIBLE:View.GONE);
|
||||
homeContent=new LinearLayout(this);homeContent.setOrientation(1);layout.addView(homeContent);
|
||||
text("家人现在的位置",22,homeContent);viewStatus=text("",16,homeContent);
|
||||
map=new LocationMapView(this);homeContent.addView(map,new LinearLayout.LayoutParams(-1,(int)(360*getResources().getDisplayMetrics().density)));
|
||||
text("智家内置地图 · 可拖动、双指缩放;点家人卡片查看道路位置。圆圈表示定位精度范围。",13,homeContent);
|
||||
button("查看全部位置",homeContent).setOnClickListener(v->map.reset());
|
||||
reload=button("刷新家人位置",homeContent);reload.setOnClickListener(v->loadFamily());
|
||||
familyList=new LinearLayout(this);familyList.setOrientation(1);homeContent.addView(familyList);
|
||||
voice=new VoicePanel(this,"phone",()->prefs.getString("token",""));root.addView(voice,new LinearLayout.LayoutParams(-1,-2));render();
|
||||
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();};
|
||||
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));
|
||||
phone.myCheck.setOnClickListener(v->{if(pairingRequired())showDetail("配对我的手机",pairSection);else showDetail("定位权限",permissionSection);});phone.permissions.setOnClickListener(v->showDetail("定位权限与系统设置",permissionSection));
|
||||
phone.viewers.setOnClickListener(v->{if(!settingsReady)loadSettings();showDetail("允许谁查看",recipientSection);});
|
||||
phone.expiry.setOnClickListener(v->new AlertDialog.Builder(this).setTitle("共享有效期").setMessage(prefs.getLong("expires",0)>0?"本手机配对有效至 "+java.text.DateFormat.getDateTimeInstance().format(new Date(prefs.getLong("expires",0)))+"。到期后停止新位置共享;可随时手动关闭。续期或重新配对请联系家庭管理员。":"配对后显示有效期。").setPositiveButton("知道了",null).show());
|
||||
phone.sampling.setOnClickListener(v->showDetail("定位采集频率",sampleSection));phone.upload.setOnClickListener(v->showDetail("集中上传与离线暂存",uploadSection));phone.history.setOnClickListener(v->showDetail("我的历史轨迹",historySection));
|
||||
selectTab(paired()?0:2);render();
|
||||
}
|
||||
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 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);
|
||||
LinearLayout header=style.line();Button back=style.button("返回",false);header.addView(back);TextView heading=style.bold(title,22);heading.setPadding(style.dp(14),0,0,0);header.addView(heading,new LinearLayout.LayoutParams(0,-2,1));frame.addView(header);style.gap(frame,18);
|
||||
ScrollView scroll=new ScrollView(this);scroll.setFillViewport(true);scroll.addView(content);frame.addView(scroll,new LinearLayout.LayoutParams(-1,0,1));
|
||||
Button done=style.button("完成",true);frame.addView(done);Dialog shown=new Dialog(this,android.R.style.Theme_Material_Light_NoActionBar);detailDialog=shown;shown.setContentView(frame);
|
||||
Runnable close=()->{if(content==sampleSection||content==uploadSection){try{if(content==sampleSection)samplePeriodSeconds();else uploadPeriod();}catch(Exception e){Toast.makeText(this,"请填写有效的自定义间隔",1).show();return;}}shown.dismiss();};back.setOnClickListener(v->close.run());done.setOnClickListener(v->close.run());
|
||||
shown.setOnDismissListener(d->{if(content.getParent()==scroll)scroll.removeView(content);if(content.getParent()==null)settings.addView(content);if(detailDialog==shown)detailDialog=null;if(!isDestroyed())render();});shown.show();shown.getWindow().setLayout(-1,-1);shown.getWindow().setStatusBarColor(PhoneStyle.PAPER);shown.getWindow().setNavigationBarColor(PhoneStyle.PAPER);shown.getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR|View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR);render();
|
||||
}
|
||||
void confirmSharing(){
|
||||
if(!settingsReady)return;int total=0;for(List<CheckBox> list:choices.values())for(CheckBox c:list)if(c.isChecked())total++;
|
||||
if(total==0){showDetail("先选择查看人",recipientSection);Toast.makeText(this,"请先选择允许查看你位置的家人或显示终端",1).show();return;}
|
||||
try{samplePeriodSeconds();uploadPeriod();}catch(Exception e){Toast.makeText(this,"请先检查定位频率和上传周期",1).show();return;}
|
||||
if(consentSection.getParent()!=null)((android.view.ViewGroup)consentSection.getParent()).removeView(consentSection);consent.setChecked(false);
|
||||
new AlertDialog.Builder(this).setTitle("开启我的位置共享").setMessage("允许 "+total+" 个对象查看 · 采集"+periodLabel(samplePeriodSeconds())+" · 上传"+periodLabel(uploadPeriod())+"。\n可随时关闭。频率与名单将在此次开启时生效。").setView(consentSection).setNegativeButton("暂不开启",null).setPositiveButton("开启共享",(d,w)->start()).setOnDismissListener(d->{if(consentSection.getParent()!=null)((android.view.ViewGroup)consentSection.getParent()).removeView(consentSection);settings.addView(consentSection);render();}).show();
|
||||
}
|
||||
String periodLabel(int seconds){return "每 "+(seconds%86400==0?seconds/86400+" 天":seconds%3600==0?seconds/3600+" 小时":seconds%60==0?seconds/60+" 分钟":seconds+" 秒");}
|
||||
public void onBackPressed(){if(phone.tab!=0){selectTab(0);return;}super.onBackPressed();}
|
||||
|
||||
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);settingsButton.setVisibility(paired?View.VISIBLE:View.GONE);voice.setVisibility(paired?View.VISIBLE:View.GONE);
|
||||
if(!paired)settings.setVisibility(View.VISIBLE);
|
||||
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);
|
||||
long expires=prefs.getLong("expires",0);
|
||||
identity.setText(prefs.getString("memberName","尚未配对本人")+" · "+prefs.getString("home","请在我的位置设置中配对")+(expires>0?"\n配对有效至 "+java.text.DateFormat.getDateTimeInstance().format(new Date(expires)):""));
|
||||
status.setText(settingsError.isEmpty()?"我的位置:"+prefs.getString("status","共享关闭,不采集定位"):settingsError);
|
||||
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)));
|
||||
String current=settingsError.isEmpty()?prefs.getString("status","共享关闭,不采集定位"):settingsError;
|
||||
if(paired&&pairingRequired())current="手机配对已失效,请重新配对";
|
||||
VoiceSurface.text(status,current);VoiceSurface.text(phone.homeStatus,paired?current:"尚未配对 · 请关联本人档案");phone.homeStatus.setMaxLines(3);
|
||||
VoiceSurface.text(phone.check,pairingRequired()?"去配对":"检查");VoiceSurface.text(phone.myCheck,pairingRequired()?"重新配对":"检查权限");
|
||||
phone.expiry.value(expires>0?java.text.DateFormat.getDateInstance().format(new Date(expires))+" 到期":"尚未配对");
|
||||
int viewers=0;for(List<CheckBox> list:choices.values())for(CheckBox c:list)if(c.isChecked())viewers++;phone.viewers.value(settingsReady?viewers+" 个已选对象 · "+(active?"共享期间生效":"开启共享后生效"):"点击读取授权名单");
|
||||
try{phone.sampling.value(periodLabel(samplePeriodSeconds()));phone.upload.value(periodLabel(uploadPeriod())+" · 断网时加密暂存");}catch(Exception e){phone.sampling.value("请检查自定义间隔");}
|
||||
phone.history.value((historyConsent.isChecked()?"已选择保存轨迹":"未选择保存轨迹")+" · "+prefs.getLong("pendingPoints",0)+" 个点待同步");
|
||||
phone.permissions.value(locationPermissionText());
|
||||
queueStatus.setText(String.format(Locale.CHINA,"本机待同步:%d 个点 · %.1f KB\n累计校验清理:%d 个点 · %.1f KB\n%s%s",prefs.getLong("pendingPoints",0),prefs.getLong("pendingBytes",0)/1024d,prefs.getLong("uploadedPoints",0),prefs.getLong("freedBytes",0)/1024d,prefs.getBoolean("cacheFull",false)?"缓存已满,暂停新增历史。\n":"",prefs.getString("syncStatus","尚无待同步轨迹")));
|
||||
rendering=true;sharing.setChecked(active);rendering=false;
|
||||
sharing.setEnabled(paired&&!pairing&&(active||!busy&&settingsReady));
|
||||
sharing.setEnabled(paired&&!pairing&&(active||!pairingRequired()&&!busy&&settingsReady));
|
||||
pair.setEnabled(!active&&!busy);cadence.setEnabled(!active&&!busy);consent.setEnabled(!active&&!busy);historyConsent.setEnabled(!active&&!busy&&settingsReady);
|
||||
sampleCadence.setEnabled(!active&&!busy);sampleAmount.setEnabled(!active&&!busy);sampleUnit.setEnabled(!active&&!busy);customAmount.setEnabled(!active&&!busy);customUnit.setEnabled(!active&&!busy);
|
||||
for(List<CheckBox> list:choices.values())for(CheckBox c:list)c.setEnabled(!active&&!busy);
|
||||
@@ -115,7 +148,7 @@ public class LocationActivity extends Activity {
|
||||
new Thread(()->{try{
|
||||
JSONObject response=DisplayApi.call("/api/location/pair",null,new JSONObject().put("code",value).put("consentProtocol",3));remember(response);
|
||||
stopService(new Intent(this,LocationService.class));prefs.edit().putString("memberName",response.getString("memberName")).putString("token",response.getString("token")).putString("home",response.getString("home")).putLong("expires",(long)(response.getDouble("expires")*1000)).putBoolean("active",false).putString("status","已配对;共享关闭,可查看获授权家人").apply();refreshQueueStats();
|
||||
runOnUiThread(()->{if(isDestroyed())return;pairing=false;generation++;loading=false;familyList.removeAllViews();map.setItems(new JSONArray());code.setText("");consent.setChecked(false);settingsReady=false;settings.setVisibility(View.GONE);voice.rebound();loadSettings();loadFamily();});
|
||||
runOnUiThread(()->{if(isDestroyed())return;pairing=false;bindingRejected=false;generation++;loading=false;familyList.removeAllViews();map.setItems(new JSONArray());code.setText("");consent.setChecked(false);settingsReady=false;if(detailDialog!=null)detailDialog.dismiss();selectTab(0);voice.rebound();loadSettings();loadFamily();});
|
||||
}catch(Exception e){runOnUiThread(()->{if(!isDestroyed())Toast.makeText(this,"配对未成功,请检查手机配对码或安装新版 App",1).show();});}finally{pairing=false;runOnUiThread(()->{if(!isDestroyed())render();});}},"location-pair").start();
|
||||
}
|
||||
void loadFamily(){
|
||||
@@ -123,10 +156,11 @@ 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"))?"更新中断,旧坐标已隐藏":"等待定位")) : String.format(Locale.CHINA,"纬度 %.5f · 经度 %.5f\n精度约 %.0f 米 · %s",pos.optDouble("latitude"),pos.optDouble("longitude"),pos.optDouble("accuracy"),java.text.DateFormat.getTimeInstance().format(new Date((long)(pos.optDouble("at")*1000))));Button item=button(row.optString("name")+"\n"+detail,familyList);item.setAllCaps(false);item.setOnClickListener(v->{if(pos!=null)map.focus(pos);});button("查看 "+row.optString("name")+" 的已授权历史",familyList).setOnClickListener(v->history(row.optString("id")));}
|
||||
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")));}
|
||||
|
||||
});
|
||||
}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)){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();settings.setVisibility(View.VISIBLE);}viewStatus.setText(e instanceof DisplayApi.ApiError&&((DisplayApi.ApiError)e).status==401?"手机配对已过期或解除,请重新配对。":"位置未能刷新,已隐藏旧画面,请检查网络。");});}finally{runOnUiThread(()->{if(g==generation){loading=false;render();}});}},"family-positions").start();
|
||||
}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();
|
||||
}
|
||||
void loadSettings(){
|
||||
String token=prefs.getString("token","");if(token.isEmpty()||pairing)return;int g=generation,request=++settingsRequest;settingsReady=false;settingsError="";render();
|
||||
@@ -135,7 +169,7 @@ public class LocationActivity extends Activity {
|
||||
runOnUiThread(()->{if(!visible||g!=generation||request!=settingsRequest)return;settingsReceipt=result.optString("receipt");recipients.removeAllViews();choices.clear();
|
||||
for(String type:new String[]{"viewers","phones","displays"}){String key=type.equals("viewers")?"viewerIds":type.equals("phones")?"phoneIds":"displayIds";text(type.equals("viewers")?"平台查看账号":type.equals("phones")?"已配对的家人手机":"公共显示终端",16,recipients);JSONArray options=result.optJSONArray(type),selected=result.optJSONArray(key);Set<String> ids=new HashSet<>();if(selected!=null)for(int i=0;i<selected.length();i++)ids.add(selected.optString(i));List<CheckBox> list=new ArrayList<>();choices.put(key,list);if(options!=null)for(int i=0;i<options.length();i++){JSONObject item=options.optJSONObject(i);CheckBox c=new CheckBox(this);c.setText(item.optString("name"));c.setTag(item.optString("id"));c.setChecked(ids.contains(item.optString("id")));recipients.addView(c);list.add(c);}if(list.isEmpty())text("暂无可选对象",14,recipients);}
|
||||
int seconds=result.optInt("intervalSeconds",300);setUploadPeriod(seconds);setSamplePeriod(result.optInt("sampleIntervalSeconds",60));historyAcknowledged=result.optBoolean("historyEnabled",false);historyConsent.setChecked(historyAcknowledged||result.optBoolean("historyDefault",false));JSONObject h=result.optJSONObject("history");if(h!=null)historyStatus.setText("待归档 "+h.optInt("pending")+" 个定位点 · 已归档 "+h.optInt("archived")+" 段 · 待删除 "+h.optInt("deleting")+" 段\n"+h.optString("error")+"\n长期保留,由本人手动删除。修改设置前先关闭共享。");settingsReady=true;render();});
|
||||
}catch(Exception e){runOnUiThread(()->{if(visible&&g==generation&&request==settingsRequest){settingsReady=false;settingsError="无法读取我的位置设置,请检查网络或配对有效期,重新打开设置重试。";render();}});}},"location-settings").start();
|
||||
}catch(Exception e){runOnUiThread(()->{if(visible&&g==generation&&request==settingsRequest){settingsReady=false;if(e instanceof DisplayApi.ApiError&&(((DisplayApi.ApiError)e).status==401||((DisplayApi.ApiError)e).status==403))bindingRejected=true;settingsError="无法读取我的位置设置,请检查网络或配对有效期,重新打开设置重试。";render();}});}},"location-settings").start();
|
||||
}
|
||||
void start(){
|
||||
if(pairing||LocationService.busy||prefs.getBoolean("active",false)||!settingsReady)return;
|
||||
@@ -203,5 +237,5 @@ public class LocationActivity extends Activity {
|
||||
public void onRequestPermissionsResult(int request,String[] permissions,int[] results){super.onRequestPermissionsResult(request,permissions,results);if(request==47||request==48){render();return;}if(request==45){if(checkSelfPermission(Manifest.permission.ACCESS_FINE_LOCATION)==0||checkSelfPermission(Manifest.permission.ACCESS_COARSE_LOCATION)==0){if(visible)start();else pendingStart=true;}else Toast.makeText(this,"未授权定位,不采集自己的位置;仍可查看获授权家人",1).show();render();}}
|
||||
public void onResume(){super.onResume();visible=true;map.resumeMap();voice.active(true);lastList=0;refreshQueueStats();if(!LocationService.busy&&prefs.getLong("pendingPoints",0)>0)syncNow();if(!settingsReady)loadSettings();ui.post(refresh);if(pendingStart){pendingStart=false;start();}}
|
||||
public void onPause(){visible=false;if(historyDialog!=null)historyDialog.dismiss();voice.active(false);generation++;loading=false;ui.removeCallbacksAndMessages(null);if(map!=null)map.pauseMap();if(familyList!=null)familyList.removeAllViews();super.onPause();}
|
||||
public void onDestroy(){if(map!=null)map.close();if(voice!=null)voice.close();ui.removeCallbacksAndMessages(null);super.onDestroy();}
|
||||
public void onDestroy(){if(detailDialog!=null)detailDialog.dismiss();if(map!=null)map.close();if(voice!=null)voice.close();ui.removeCallbacksAndMessages(null);super.onDestroy();}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,52 @@
|
||||
package cn.ucvl.zhaodisplay;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.graphics.Typeface;
|
||||
import android.view.*;
|
||||
import android.widget.*;
|
||||
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 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;
|
||||
final TextView[] navLabels=new TextView[3];final ImageView[] navIcons=new ImageView[3];int tab=0;IntConsumer onTab;
|
||||
PhoneLayout(Activity app){
|
||||
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);
|
||||
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);
|
||||
homeContent=s.column();pages[0].addView(homeContent);
|
||||
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);
|
||||
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);
|
||||
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"};
|
||||
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 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,60 @@
|
||||
package cn.ucvl.zhaodisplay;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.res.ColorStateList;
|
||||
import android.graphics.*;
|
||||
import android.graphics.drawable.*;
|
||||
import android.view.*;
|
||||
import android.widget.*;
|
||||
|
||||
/** Small native design system. Icons are bundled vector paths; no remote fonts or artwork. */
|
||||
final class PhoneStyle {
|
||||
static final int PAPER=0xfff8f7ef,CARD=0xfffffefa,INK=0xff193d35,MUTED=0xff718078,GREEN=0xff177363,LINE=0xffe8ebe3,PALE=0xffe8f2e9;
|
||||
final Context context;
|
||||
PhoneStyle(Context context){this.context=context;}
|
||||
int dp(float value){return Math.round(value*context.getResources().getDisplayMetrics().density);}
|
||||
LinearLayout column(){LinearLayout v=new LinearLayout(context);v.setOrientation(LinearLayout.VERTICAL);return v;}
|
||||
LinearLayout line(){LinearLayout v=new LinearLayout(context);v.setGravity(Gravity.CENTER_VERTICAL);return v;}
|
||||
TextView label(String text,int size,int color){TextView v=new TextView(context);v.setText(text);v.setTextSize(size);v.setTextColor(color);v.setIncludeFontPadding(false);return v;}
|
||||
TextView bold(String text,int size){TextView v=label(text,size,INK);v.setTypeface(null,Typeface.BOLD);return v;}
|
||||
GradientDrawable shape(int color,int radius){GradientDrawable v=new GradientDrawable();v.setColor(color);v.setCornerRadius(dp(radius));return v;}
|
||||
void card(View v){v.setBackground(shape(CARD,20));v.setPadding(dp(16),dp(16),dp(16),dp(16));v.setClipToOutline(true);}
|
||||
void gap(LinearLayout parent,int height){parent.addView(new View(context),new LinearLayout.LayoutParams(1,dp(height)));}
|
||||
Button button(String text,boolean primary){Button b=new Button(context);b.setText(text);b.setTextSize(15);b.setAllCaps(false);b.setMinWidth(0);b.setMinimumWidth(0);b.setMinHeight(dp(48));b.setMinimumHeight(dp(48));b.setTextColor(primary?Color.WHITE:GREEN);b.setPadding(dp(14),dp(9),dp(14),dp(9));b.setStateListAnimator(null);b.setBackground(new RippleDrawable(ColorStateList.valueOf(0x1a177363),shape(primary?GREEN:PALE,14),null));return b;}
|
||||
Button iconButton(String icon,String description){Button b=button("",false);b.setBackground(new RippleDrawable(ColorStateList.valueOf(0x22177363),shape(CARD,14),null));Icon d=new Icon(icon,GREEN,dp(22));d.setBounds(0,0,dp(22),dp(22));b.setCompoundDrawables(d,null,null,null);b.setPadding(dp(13),dp(12),dp(13),dp(12));b.setContentDescription(description);return b;}
|
||||
TextView avatar(String name,int size){TextView v=bold(name.isEmpty()?"家":name.substring(0,name.offsetByCodePoints(0,1)),size/3);v.setGravity(Gravity.CENTER);v.setBackground(shape(PALE,size/2));v.setContentDescription(name);v.setLayoutParams(new LinearLayout.LayoutParams(dp(size),dp(size)));return v;}
|
||||
Row row(String icon,String title,String value){return new Row(icon,title,value);}
|
||||
final class Row extends LinearLayout {
|
||||
final TextView title,value;final LinearLayout words;
|
||||
Row(String icon,String name,String detail){
|
||||
super(context);setGravity(Gravity.CENTER_VERTICAL);setPadding(dp(4),dp(14),dp(4),dp(14));setMinimumHeight(dp(60));
|
||||
ImageView mark=new ImageView(context);mark.setImageDrawable(new Icon(icon,INK,dp(23)));LayoutParams ip=new LayoutParams(dp(24),dp(24));ip.rightMargin=dp(13);addView(mark,ip);
|
||||
words=column();title=label(name,16,INK);value=label(detail,13,MUTED);words.addView(title);gap(words,6);words.addView(value);addView(words,new LayoutParams(0,-2,1));
|
||||
TextView next=label("›",26,MUTED);next.setPadding(dp(12),0,dp(2),0);addView(next);setBackground(new RippleDrawable(ColorStateList.valueOf(0x14177363),null,shape(Color.WHITE,10)));setFocusable(true);setClickable(true);
|
||||
}
|
||||
void value(String text){VoiceSurface.text(value,text);value.setVisibility(text.isEmpty()?GONE:VISIBLE);}
|
||||
}
|
||||
static final class Icon extends Drawable {
|
||||
final String kind;final Paint p=new Paint(Paint.ANTI_ALIAS_FLAG);final int size;
|
||||
Icon(String kind,int color,int size){this.kind=kind;this.size=size;p.setColor(color);}
|
||||
public int getIntrinsicWidth(){return size;}public int getIntrinsicHeight(){return size;}
|
||||
public void draw(Canvas c){Rect b=getBounds();c.save();c.translate(b.left,b.top);c.scale(b.width()/24f,b.height()/24f);p.setStyle(Paint.Style.STROKE);p.setStrokeWidth(1.7f);p.setStrokeCap(Paint.Cap.ROUND);p.setStrokeJoin(Paint.Join.ROUND);
|
||||
switch(kind){
|
||||
case "mic":c.drawRoundRect(9,2,15,15,3,3,p);c.drawArc(5,5,19,20,0,180,false,p);c.drawLine(5,11,5,13,p);c.drawLine(19,11,19,13,p);c.drawLine(12,20,12,23,p);c.drawLine(8,23,16,23,p);break;
|
||||
case "family":c.drawCircle(9,6,3,p);c.drawArc(3,11,15,23,180,180,false,p);c.drawLine(3,17,3,20,p);c.drawLine(3,20,15,20,p);c.drawLine(15,17,15,20,p);c.drawArc(13,3,19,9,-90,180,false,p);c.drawArc(13,11,22,23,-90,90,false,p);c.drawLine(21,17,21,20,p);c.drawLine(18,20,21,20,p);break;
|
||||
case "person":c.drawCircle(12,7,4,p);c.drawArc(4,13,20,27,180,180,false,p);c.drawLine(4,20,20,20,p);break;
|
||||
case "display":c.drawRoundRect(2,3,22,17,2,2,p);c.drawLine(12,17,12,21,p);c.drawLine(7,21,17,21,p);break;
|
||||
case "phone":c.drawRoundRect(6,1,18,23,3,3,p);c.drawLine(10,4,14,4,p);c.drawLine(11,20,13,20,p);break;
|
||||
case "clock":c.drawCircle(12,12,9,p);c.drawLine(12,6,12,12,p);c.drawLine(12,12,16,14,p);break;
|
||||
case "pin":case "location":c.drawCircle(12,12,7,p);c.drawCircle(12,12,2.5f,p);c.drawLine(12,1,12,4,p);c.drawLine(12,20,12,23,p);c.drawLine(1,12,4,12,p);c.drawLine(20,12,23,12,p);break;
|
||||
case "cloud":Path cloud=new Path();cloud.moveTo(5,18);cloud.cubicTo(-1,18,0,9,6,9);cloud.cubicTo(7,1,19,2,19,10);cloud.cubicTo(25,11,23,18,19,18);c.drawPath(cloud,p);c.drawLine(12,21,12,11,p);c.drawLine(8,15,12,11,p);c.drawLine(16,15,12,11,p);break;
|
||||
case "track":c.drawCircle(5,18,3,p);c.drawCircle(18,5,3,p);Path path=new Path();path.moveTo(5,15);path.cubicTo(2,5,20,23,18,8);c.drawPath(path,p);break;
|
||||
case "shield":Path shield=new Path();shield.moveTo(12,2);shield.lineTo(21,6);shield.lineTo(20,15);shield.quadTo(18,20,12,23);shield.quadTo(6,20,4,15);shield.lineTo(3,6);shield.close();c.drawPath(shield,p);c.drawLine(8,12,11,15,p);c.drawLine(11,15,16,9,p);break;
|
||||
case "settings":c.drawCircle(12,12,6,p);c.drawCircle(12,12,2,p);for(int i=0;i<8;i++){double angle=i*Math.PI/4;c.drawLine(12+(float)Math.cos(angle)*7,12+(float)Math.sin(angle)*7,12+(float)Math.cos(angle)*10,12+(float)Math.sin(angle)*10,p);}break;
|
||||
case "refresh":c.drawArc(4,4,20,20,35,290,false,p);c.drawLine(19,3,19,9,p);c.drawLine(14,9,19,9,p);break;
|
||||
default:c.drawCircle(12,12,8,p);
|
||||
}c.restore();
|
||||
}
|
||||
public void setAlpha(int alpha){p.setAlpha(alpha);}public void setColorFilter(ColorFilter f){p.setColorFilter(f);}public int getOpacity(){return PixelFormat.TRANSLUCENT;}
|
||||
}
|
||||
}
|
||||
@@ -19,7 +19,7 @@ import java.util.function.Supplier;
|
||||
final class VoicePanel extends LinearLayout {
|
||||
final Activity app;final String kind;final Supplier<String> token;
|
||||
final Handler ui=new Handler();final ExecutorService worker=Executors.newSingleThreadExecutor();
|
||||
final TextView status;final Button speak,settings,stop;final VoiceSurface dock;VoiceSurface expanded;Dialog sheet;
|
||||
final TextView status;final Button speak,settings,stop;final VoiceSurface dock;VoiceSurface expanded,page;Dialog sheet;
|
||||
String selectedId="";boolean networkReady=false;long feedbackAt=0;
|
||||
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;
|
||||
@@ -35,9 +35,13 @@ final class VoicePanel extends LinearLayout {
|
||||
status=dock.status;speak=dock.speak;settings=dock.settings;stop=dock.stop;wire(dock);speak.setEnabled(false);stop.setEnabled(false);
|
||||
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);}
|
||||
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;}
|
||||
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.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();});
|
||||
view.expand.setOnClickListener(v->{if(view.full&&sheet!=null)sheet.dismiss();else openSheet();});view.recipient.setOnClickListener(v->{if(!view.full)openSheet();});
|
||||
final float[] down={0};view.speak.setOnTouchListener((v,event)->{
|
||||
switch(event.getActionMasked()){
|
||||
@@ -66,13 +70,13 @@ final class VoicePanel extends LinearLayout {
|
||||
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){}
|
||||
for(VoiceSurface view:new VoiceSurface[]{dock,expanded}){if(view==null)continue;
|
||||
view.targets(destinations,selectedId,this::choose);if(recorder==null||view.full)VoiceSurface.text(view.recipient,name.isEmpty()?"选择一位家人":view.full?"对"+name+"说句话":name+" · "+(available?"已打开 App":"未打开 App")+" ›");
|
||||
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?"● 接收已开启 · 仅限你允许的家人":"○ 接收已关闭 · 可在接收设置中开启");
|
||||
view.settings.setEnabled(networkReady&&recorder==null&&!sending);view.stop.setVisibility(player!=null?View.VISIBLE:View.GONE);view.stop.setEnabled(player!=null);
|
||||
view.recording(recorder!=null,cancelled,recorder==null?0:SystemClock.elapsedRealtime()-started,amplitude,sending,can);
|
||||
if(view!=dock)VoiceSurface.text(view.status,status.getText());
|
||||
if(!microphone()&&recorder==null&&!sending)view.speak.setText("待接入话筒");
|
||||
if(!microphone()&&recorder==null&&!sending){if(view.full)VoiceSurface.text(view.clock,"请先接入话筒");else view.speak.setText("待接入话筒");}
|
||||
}
|
||||
}
|
||||
JSONObject body(String action)throws Exception{return new JSONObject().put("kind",kind).put("action",action);}
|
||||
@@ -99,7 +103,7 @@ final class VoicePanel extends LinearLayout {
|
||||
}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);}});
|
||||
}
|
||||
String selectedTarget(){return destination()==null?"":selectedId;}
|
||||
void night(boolean value){night=value;dock.applyTheme(value);if(expanded!=null)expanded.applyTheme(value);renderSurfaces();}
|
||||
void night(boolean value){night=value;dock.applyTheme(value);if(expanded!=null)expanded.applyTheme(value);if(page!=null)page.applyTheme(value);renderSurfaces();}
|
||||
boolean microphone(){try{return audio.getDevices(AudioManager.GET_DEVICES_INPUTS).length>0;}catch(Exception e){return false;}}
|
||||
void configure(){
|
||||
if(choices==null)return;final JSONArray options=choices;String[] names=new String[options.length()];boolean[] checked=new boolean[names.length];
|
||||
@@ -114,7 +118,7 @@ final class VoicePanel extends LinearLayout {
|
||||
worker.execute(()->{try{DisplayApi.call("/api/voice",t,body("configure").put("enabled",receive).put("allowed",ids).put("consent",true));ui.post(()->{if(current(e,t)){lastMessage="";poll();}});}catch(Exception error){ui.post(()->{if(current(e,t))showStatus("接收设置保存失败,请检查网络后重试");});}});
|
||||
}
|
||||
void begin(){
|
||||
if(!visible||recorder!=null||sending||selectedTarget().isEmpty())return;
|
||||
if(!visible||!networkReady||recorder!=null||sending||selectedTarget().isEmpty())return;
|
||||
JSONObject target=destination();if(target==null||!target.optBoolean("online")){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;}
|
||||
|
||||
@@ -13,7 +13,8 @@ import java.util.function.Consumer;
|
||||
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;boolean night=false;String targetSignature="",controlSignature="";
|
||||
final VoiceArt art;final Switch receiver;final LinearLayout destinationCard,receiverCard,playbackCard;final TextView availability;final ImageView destinationIcon;
|
||||
boolean night=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,34 +23,53 @@ final class VoiceSurface extends LinearLayout {
|
||||
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));
|
||||
settings=button("接收设置",14);header.addView(settings);expand=button(full?"收起":"展开",14);header.addView(expand);
|
||||
subtitle=label("一句问候,家就在身边",17);if(full){addView(subtitle);space(16);}
|
||||
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);
|
||||
people=new LinearLayout(activity);people.setOrientation(HORIZONTAL);strip.addView(people);if(full)addView(strip,new LayoutParams(-1,-2));
|
||||
receive=label("",13);if(full){space(8);addView(receive);space(16);}
|
||||
recipient=label("选择一位家人",full?23:15);recipient.setTypeface(null,full?Typeface.BOLD:Typeface.NORMAL);recipient.setMaxLines(full?2:1);recipient.setEllipsize(android.text.TextUtils.TruncateAt.END);addView(recipient);if(full)space(14);
|
||||
compose=new LinearLayout(activity);compose.setOrientation(VERTICAL);compose.setGravity(Gravity.CENTER_HORIZONTAL);compose.setPadding(dp(full?20:0),dp(full?18:0),dp(full?20:0),dp(full?18:0));addView(compose,new LayoutParams(-1,-2));
|
||||
art=new VoiceArt(activity);art.setImportantForAccessibility(IMPORTANT_FOR_ACCESSIBILITY_NO);if(full)compose.addView(art,new LayoutParams(-1,dp(88)));
|
||||
clock=label("按住说话,松开发送",16);clock.setGravity(Gravity.CENTER);if(full)compose.addView(clock,new LayoutParams(-1,dp(56)));
|
||||
people=new LinearLayout(activity);people.setOrientation(HORIZONTAL);strip.addView(people);
|
||||
destinationCard=new LinearLayout(activity);destinationCard.setGravity(Gravity.CENTER_VERTICAL);destinationCard.setPadding(dp(16),dp(18),dp(12),dp(18));if(full)addView(destinationCard,new LayoutParams(-1,-2));
|
||||
destinationIcon=new ImageView(activity);destinationCard.addView(destinationIcon,new LayoutParams(dp(52),dp(52)));
|
||||
LinearLayout targetWords=new LinearLayout(activity);targetWords.setOrientation(VERTICAL);targetWords.setPadding(dp(14),0,0,0);destinationCard.addView(targetWords,new LayoutParams(0,-2,1));
|
||||
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);
|
||||
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);
|
||||
status=label("先配对,再选择家人",full?16:13);status.setGravity(Gravity.CENTER);status.setAccessibilityLiveRegion(ACCESSIBILITY_LIVE_REGION_POLITE);
|
||||
speak=button("按住说话",full?24:21);speak.setTypeface(null,Typeface.BOLD);speak.setCompoundDrawablePadding(dp(12));speak.setContentDescription("按住说话,松开发送,上滑取消");
|
||||
LayoutParams talkParams=new LayoutParams(-1,dp(full?80:64));talkParams.topMargin=dp(full?14:6);compose.addView(speak,talkParams);
|
||||
hint=label("上滑取消 · 最长 30 秒",13);hint.setGravity(Gravity.CENTER);if(full){spaceIn(compose,10);compose.addView(hint);spaceIn(compose,16);}else spaceIn(compose,4);
|
||||
compose.addView(status,new LayoutParams(-1,-2));
|
||||
stop=button("停止播放",16);stop.setVisibility(GONE);compose.addView(stop);
|
||||
LayoutParams talkParams=new LayoutParams(full?dp(228):-1,dp(full?228:60));talkParams.topMargin=dp(full?0:6);compose.addView(speak,talkParams);
|
||||
hint=label("松开发送 · 上滑取消 · 最长 30 秒",13);hint.setGravity(Gravity.CENTER);if(full){compose.addView(clock,new LayoutParams(-1,dp(56)));compose.addView(hint);compose.addView(art,new LayoutParams(-1,dp(28)));}else spaceIn(compose,4);
|
||||
receiverCard=new LinearLayout(activity);receiverCard.setOrientation(VERTICAL);receiverCard.setPadding(dp(16),dp(12),dp(16),dp(12));if(full)addView(receiverCard,new LayoutParams(-1,-2));
|
||||
receiver=new Switch(activity);receiver.setText("本机接收家人喊话");receiver.setTextSize(16);receiver.setMinHeight(dp(48));receiverCard.addView(receiver);
|
||||
LinearLayout receiveLine=new LinearLayout(activity);receiveLine.setGravity(Gravity.CENTER_VERTICAL);receiverCard.addView(receiveLine);receive=label("",12);receiveLine.addView(receive,new LayoutParams(0,-2,1));receiveLine.addView(settings);
|
||||
playbackCard=new LinearLayout(activity);playbackCard.setGravity(Gravity.CENTER_VERTICAL);playbackCard.setPadding(dp(full?14:0),dp(full?12:0),dp(full?14:0),dp(full?12:0));if(full){space(12);addView(playbackCard);}else compose.addView(playbackCard);
|
||||
playbackCard.addView(status,new LayoutParams(0,-2,1));stop=button("停止播放",14);stop.setVisibility(GONE);playbackCard.addView(stop);
|
||||
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 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);
|
||||
ImageView icon=new ImageView(getContext());icon.setImageDrawable(new PhoneStyle.Icon("mic",accent(),dp(26)));row.addView(icon,new LayoutParams(dp(30),dp(30)));recipient.setPadding(dp(10),0,dp(8),0);recipient.setTextSize(14);recipient.setMaxLines(2);row.addView(recipient,new LayoutParams(0,-2,1));speak.setTextSize(15);boolean large=getResources().getConfiguration().fontScale>1.2f;row.addView(speak,new LayoutParams(dp(large?146:118),dp(large?60:48)));addView(row);
|
||||
status.setTextSize(11);status.setMaxLines(2);status.setEllipsize(android.text.TextUtils.TruncateAt.END);LinearLayout feedback=new LinearLayout(getContext());feedback.setGravity(Gravity.CENTER_VERTICAL);feedback.addView(status,new LayoutParams(0,-2,1));feedback.addView(stop);addView(feedback);
|
||||
}
|
||||
static void text(TextView view,CharSequence value){if(!android.text.TextUtils.equals(view.getText(),value))view.setText(value);}
|
||||
Button button(String text,int size){Button b=new Button(getContext());b.setText(text);b.setTextSize(size);b.setAllCaps(false);b.setMinHeight(dp(44));b.setMinimumHeight(dp(44));b.setMinWidth(0);b.setMinimumWidth(0);b.setPadding(dp(12),dp(8),dp(12),dp(8));b.setStateListAnimator(null);return b;}
|
||||
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());
|
||||
compose.setBackground(full?shape(card(),night?0xff345043:0xffe4e8df,26):null);
|
||||
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="";
|
||||
}
|
||||
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());
|
||||
}
|
||||
void receiving(boolean enabled,boolean ready){receiver.setChecked(enabled);receiver.setEnabled(ready);}
|
||||
void targets(JSONArray values,String selected,Consumer<String> choose){
|
||||
String signature=String.valueOf(values)+selected+night;if(signature.equals(targetSignature))return;targetSignature=signature;people.removeAllViews();
|
||||
if(values==null||values.length()==0){TextView empty=label("暂无允许接收的家人\n请对方打开 App,在接收设置中允许你",16);empty.setTextColor(muted());people.addView(empty,new LayoutParams(dp(285),-2));return;}
|
||||
@@ -67,12 +87,18 @@ final class VoiceSurface extends LinearLayout {
|
||||
int color=cancel?(night?0xff69433b:0xffa84b37):accent();speak.setEnabled(canSpeak||recording);speak.setAlpha(canSpeak||recording?1f:.52f);
|
||||
String label=recording?(cancel?"松开取消":"松开发送"):uploading?"正在发送…":"按住说话";
|
||||
MicIcon inline=new MicIcon(night?0xffc8d5cd:Color.WHITE,dp(24));inline.setBounds(0,0,dp(24),dp(24));
|
||||
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(!android.text.TextUtils.equals(speak.getText(),text)||!controlSignature.equals(color+":"+night))speak.setText(text);speak.setTextColor(night?0xffd1dfd5:Color.WHITE);
|
||||
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),shape(color,0,32),null));}
|
||||
clock.setTextSize(recording?38:16);clock.setTypeface(null,recording?Typeface.BOLD:Typeface.NORMAL);text(clock,recording?String.format(java.util.Locale.ROOT,"00:%02d",Math.min(30,duration/1000)):"按住说话,松开发送");clock.setTextColor(cancel?color:ink());
|
||||
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());
|
||||
text(hint,recording?(cancel?"松开手指,取消这条语音":"上滑取消 · 松开发送 · 30 秒自动发送"):"上滑取消 · 最长 30 秒");hint.setTextColor(cancel?color:muted());
|
||||
art.level(recording,cancel,amplitude);if(!full&&recording)text(recipient,String.format(java.util.Locale.CHINA,"%s · %02d 秒",cancel?"松开即取消":"正在录音,上滑可取消",Math.min(30,duration/1000)));
|
||||
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)));
|
||||
}
|
||||
static final class VoiceCircle extends Drawable {
|
||||
final Paint p=new Paint(Paint.ANTI_ALIAS_FLAG);final int color;final boolean night;
|
||||
VoiceCircle(int color,boolean night){this.color=color;this.night=night;}
|
||||
public void draw(Canvas c){Rect b=getBounds();float x=b.exactCenterX(),y=b.exactCenterY(),r=Math.min(b.width(),b.height())/2f;p.setColor(night?0xff223c31:0xffe5f0e6);c.drawCircle(x,y,r,p);p.setColor(night?0xff2e4d40:0xffcfe5d8);c.drawCircle(x,y,r*.88f,p);p.setShader(new LinearGradient(x-r,y-r,x+r,y+r,new int[]{color,night?0xff355549:0xff095747},null,Shader.TileMode.CLAMP));c.drawCircle(x,y,r*.81f,p);p.setShader(null);MicIcon mic=new MicIcon(night?0xffcfdfd5:Color.WHITE,64);int half=Math.round(r*.27f);mic.setBounds(Math.round(x)-half,Math.round(y)-half,Math.round(x)+half,Math.round(y)+half);mic.draw(c);}
|
||||
public void setAlpha(int a){p.setAlpha(a);}public void setColorFilter(ColorFilter f){p.setColorFilter(f);}public int getOpacity(){return PixelFormat.TRANSLUCENT;}
|
||||
}
|
||||
static final class MicIcon extends Drawable {
|
||||
final Paint paint=new Paint(Paint.ANTI_ALIAS_FLAG);final int size;
|
||||
|
||||
@@ -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);}
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "zhao-steward-ui",
|
||||
"private": true,
|
||||
"version": "0.1.51",
|
||||
"version": "0.1.52",
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
"build": "vite build",
|
||||
|
||||
@@ -50,7 +50,8 @@ class AndroidLocationContractTests(unittest.TestCase):
|
||||
self.assertIn('phoneMode', boot)
|
||||
ui = (ANDROID/'src/cn/ucvl/zhaodisplay/LocationActivity.java').read_text(encoding='utf-8')
|
||||
self.assertNotIn('WebView', ui)
|
||||
self.assertIn('共享我的位置', ui)
|
||||
layout=(ANDROID/'src/cn/ucvl/zhaodisplay/PhoneLayout.java').read_text(encoding='utf-8')
|
||||
self.assertIn('共享我的位置', layout)
|
||||
self.assertIn('自定义采集间隔', ui)
|
||||
self.assertIn('LocationCadence.customSample', ui)
|
||||
self.assertIn('setSamplePeriod(result.optInt', ui)
|
||||
@@ -75,6 +76,34 @@ class AndroidLocationContractTests(unittest.TestCase):
|
||||
self.assertIn(text,source)
|
||||
self.assertNotIn('addJavascriptInterface',source)
|
||||
self.assertNotIn('getSharedPreferences',source)
|
||||
|
||||
def test_phone_three_tabs_use_native_cards_and_keep_sharing_explicit(self):
|
||||
source=(ANDROID/'src/cn/ucvl/zhaodisplay/LocationActivity.java').read_text(encoding='utf-8')
|
||||
layout=(ANDROID/'src/cn/ucvl/zhaodisplay/PhoneLayout.java').read_text(encoding='utf-8')
|
||||
for value in ('"家人","喊话","我的"','scrolls[i].setVisibility(i==next?VISIBLE:GONE)','setContentDescription','共享我的位置'):
|
||||
self.assertIn(value,layout)
|
||||
for value in ('voice.finish(false);phone.select(tab)','if(content.getParent()==scroll)','开启共享后生效','consent.setChecked(false)','showDetail("允许谁查看"','setLayout(-1,-1)'):
|
||||
self.assertIn(value,source)
|
||||
self.assertNotIn('startService',layout)
|
||||
self.assertNotIn('https://',layout)
|
||||
|
||||
def test_voice_page_uses_explicit_receiver_consent_and_cancels_on_navigation(self):
|
||||
source=(ANDROID/'src/cn/ucvl/zhaodisplay/VoicePanel.java').read_text(encoding='utf-8')
|
||||
surface=(ANDROID/'src/cn/ucvl/zhaodisplay/VoiceSurface.java').read_text(encoding='utf-8')
|
||||
for value in ('view.receiver.setChecked(enabled)','else configure()','VoiceSurface page()','new VoiceCircle(color,night)','setContentDescription'):
|
||||
self.assertIn(value,source+surface)
|
||||
self.assertIn('!visible||!networkReady||recorder!=null',source)
|
||||
self.assertIn('view.destination(selected,networkReady)',source)
|
||||
|
||||
def test_native_ui_fixture_cannot_access_real_data(self):
|
||||
build=(ANDROID/'tests/build-phone-check.ps1').read_text(encoding='utf-8')
|
||||
self.assertIn('cn.ucvl.zhaodisplay.phonecheck',build)
|
||||
self.assertNotIn('<uses-permission',build)
|
||||
production=(ANDROID/'build.ps1').read_text(encoding='utf-8')
|
||||
self.assertNotIn('phone-preview',production)
|
||||
transport=(ANDROID/'tests/phone-preview/DisplayApi.java').read_text(encoding='utf-8')
|
||||
self.assertNotIn('https://',transport)
|
||||
self.assertNotIn('HttpURLConnection',transport)
|
||||
def test_background_permission_only_in_phone_and_separately_requested(self):
|
||||
for name,expected in [('AndroidManifest.xml',True),('AndroidManifest-terminal.xml',False)]:
|
||||
manifest=ET.parse(ANDROID/name).getroot()
|
||||
|
||||
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
+2
-2
@@ -1,6 +1,6 @@
|
||||
<!doctype html><html lang="zh-CN"><head><meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1"><meta name="theme-color" content="#244d43"><link rel="icon" href="/zhao-icon.png"><link rel="apple-touch-icon" href="/zhao-icon.png"><title>赵府 · 智能数字管家</title> <script type="module" crossorigin src="/ui/assets/index-D1RrgHpo.js"></script>
|
||||
<!doctype html><html lang="zh-CN"><head><meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1"><meta name="theme-color" content="#244d43"><link rel="icon" href="/zhao-icon.png"><link rel="apple-touch-icon" href="/zhao-icon.png"><title>赵府 · 智能数字管家</title> <script type="module" crossorigin src="/ui/assets/index-DDMaGFMK.js"></script>
|
||||
<link rel="modulepreload" crossorigin href="/ui/assets/modulepreload-polyfill-B5Qt9EMX.js">
|
||||
<link rel="modulepreload" crossorigin href="/ui/assets/FamilyMap-CiWCoS6Z.js">
|
||||
<link rel="stylesheet" crossorigin href="/ui/assets/FamilyMap-DBkz-poX.css">
|
||||
<link rel="stylesheet" crossorigin href="/ui/assets/index-BlhoXB1K.css">
|
||||
<link rel="stylesheet" crossorigin href="/ui/assets/index-DLtOcw55.css">
|
||||
</head><body><div id="app"></div></body></html>
|
||||
|
||||
Reference in New Issue
Block a user