fix display pairing and add scoped family voice announcements
This commit is contained in:
@@ -24,6 +24,7 @@ public class MainActivity extends Activity {
|
||||
static volatile MainActivity active;
|
||||
WebView web;
|
||||
CameraStrip cameras;
|
||||
VoicePanel voice;
|
||||
final Handler themeHandler=new Handler();
|
||||
final Runnable themeTick=new Runnable(){public void run(){applyTimeMode();themeHandler.postDelayed(this,60000);}};
|
||||
@Override public void onCreate(Bundle state) {
|
||||
@@ -47,6 +48,7 @@ public class MainActivity extends Activity {
|
||||
LinearLayout layout=new LinearLayout(this);layout.setOrientation(LinearLayout.VERTICAL);
|
||||
layout.addView(web,new LinearLayout.LayoutParams(-1,0,88));
|
||||
cameras=new CameraStrip(this);layout.addView(cameras,new LinearLayout.LayoutParams(-1,0,12));
|
||||
voice=new VoicePanel(this,"display",()->getSharedPreferences("display",0).getString("nativeToken",""));layout.addView(voice,new LinearLayout.LayoutParams(-1,-2));
|
||||
setContentView(layout);
|
||||
themeHandler.post(themeTick);
|
||||
configure(getIntent());
|
||||
@@ -55,14 +57,15 @@ public class MainActivity extends Activity {
|
||||
String code=intent.getStringExtra("pairing_code");
|
||||
if(code!=null&&code.matches("[0-9]{8}")){intent.removeExtra("pairing_code");pair(code);return;}
|
||||
String token=getSharedPreferences("display",MODE_PRIVATE).getString("token","");
|
||||
web.loadUrl("https://zhao.ucvl.cn/tv"+(token.isEmpty()?"":"#display="+token));
|
||||
// A changed fragment alone does not reload an existing WebView document.
|
||||
web.loadUrl("https://zhao.ucvl.cn/tv?client=android&load="+System.currentTimeMillis()+(token.isEmpty()?"":"#display="+token));
|
||||
if(!token.isEmpty())startForegroundService(new Intent(this,MonitorService.class));
|
||||
else pairDialog();
|
||||
}
|
||||
void pairDialog(){
|
||||
EditText code=new EditText(this);code.setInputType(InputType.TYPE_CLASS_NUMBER);code.setHint("8 位家庭屏配对码");
|
||||
code.setFilters(new android.text.InputFilter[]{new android.text.InputFilter.LengthFilter(8)});
|
||||
new AlertDialog.Builder(this).setTitle("绑定家庭中心").setMessage("在赵府智家中进入目标家庭 → 电视设备 → 电视管理 → 生成配对码。更换家庭前,请先由管理员移动这台设备的归属。")
|
||||
new AlertDialog.Builder(this).setTitle("绑定家庭显示终端").setMessage("在赵府智家中进入目标家庭 → 显示终端设备 → 显示终端管理 → 生成配对码。更换家庭前,请先由管理员移动这台设备的归属。")
|
||||
.setView(code).setNegativeButton("取消",null).setPositiveButton("绑定",(dialog,which)->pair(code.getText().toString().trim())).show();
|
||||
}
|
||||
void pair(String code){
|
||||
@@ -71,19 +74,20 @@ public class MainActivity extends Activity {
|
||||
try{
|
||||
JSONObject value=DisplayApi.call("/api/display/pair",null,new JSONObject().put("code",code));
|
||||
getSharedPreferences("display",MODE_PRIVATE).edit().putString("token",value.getString("token")).putString("nativeToken",value.getString("nativeToken")).apply();
|
||||
runOnUiThread(()->{configure(new Intent());cameras.refresh();Toast.makeText(this,"已绑定:"+value.optString("home"),Toast.LENGTH_LONG).show();});
|
||||
runOnUiThread(()->{configure(new Intent());cameras.refresh();voice.rebound();Toast.makeText(this,"已绑定:"+value.optString("home"),Toast.LENGTH_LONG).show();});
|
||||
}catch(Exception e){runOnUiThread(()->Toast.makeText(this,"绑定未成功,请检查网络或重新生成配对码",Toast.LENGTH_LONG).show());}
|
||||
},"display-pair").start();
|
||||
}
|
||||
@Override public void onNewIntent(Intent intent){super.onNewIntent(intent);setIntent(intent);configure(intent);}
|
||||
@Override public void onResume(){super.onResume();active=this;immersive();if(cameras!=null)cameras.foreground(true);}
|
||||
@Override public void onPause(){if(active==this)active=null;if(cameras!=null)cameras.foreground(false);super.onPause();}
|
||||
@Override public void onDestroy(){if(active==this)active=null;themeHandler.removeCallbacksAndMessages(null);if(cameras!=null)cameras.close();web.destroy();super.onDestroy();}
|
||||
@Override public void onResume(){super.onResume();active=this;immersive();if(cameras!=null)cameras.foreground(true);if(voice!=null)voice.active(true);}
|
||||
@Override public void onPause(){if(active==this)active=null;if(cameras!=null)cameras.foreground(false);if(voice!=null)voice.active(false);super.onPause();}
|
||||
@Override public void onDestroy(){if(active==this)active=null;themeHandler.removeCallbacksAndMessages(null);if(cameras!=null)cameras.close();if(voice!=null)voice.close();web.destroy();super.onDestroy();}
|
||||
void applyTimeMode(){
|
||||
java.util.Calendar cal=java.util.Calendar.getInstance(java.util.TimeZone.getTimeZone("Asia/Shanghai"));
|
||||
int hour=cal.get(java.util.Calendar.HOUR_OF_DAY);boolean night=hour>=20||hour<7;
|
||||
WindowManager.LayoutParams params=getWindow().getAttributes();params.screenBrightness=night?.12f:.75f;getWindow().setAttributes(params);
|
||||
if(cameras!=null){cameras.setBackgroundColor(night?0xff18221b:0xffe8e5db);cameras.title.setTextColor(night?0xff98a48c:0xff57634e);}
|
||||
if(voice!=null)voice.night(night);
|
||||
}
|
||||
@Override public void onWindowFocusChanged(boolean hasFocus){super.onWindowFocusChanged(hasFocus);if(hasFocus)immersive();}
|
||||
void immersive(){getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_FULLSCREEN|View.SYSTEM_UI_FLAG_HIDE_NAVIGATION|View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY|View.SYSTEM_UI_FLAG_LAYOUT_STABLE|View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN|View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION);}
|
||||
|
||||
Reference in New Issue
Block a user