Files

27 lines
2.9 KiB
Java

package cn.ucvl.zhaodisplay;
import android.app.Activity;
import android.os.Bundle;
import android.view.*;
import android.widget.*;
import org.json.*;
/** Isolated visual fixture: no microphone/network/location permissions, no real identities. */
public class VoicePreviewActivity extends Activity {
VoiceSurface surface;JSONArray people;
protected void attachBaseContext(android.content.Context base){android.content.res.Configuration config=new android.content.res.Configuration(base.getResources().getConfiguration());config.densityDpi=420;super.attachBaseContext(base.createConfigurationContext(config));}
public void onCreate(Bundle state){super.onCreate(state);
getWindow().setStatusBarColor(0xfff8f5ed);getWindow().setNavigationBarColor(0xfff8f5ed);getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR|View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR);
ScrollView scroller=new ScrollView(this);scroller.setFillViewport(true);surface=new VoiceSurface(this,true);scroller.addView(surface);
FrameLayout frame=new FrameLayout(this);frame.setBackgroundColor(0xfff8f5ed);frame.addView(scroller,new FrameLayout.LayoutParams(surface.dp(390),surface.dp(844),Gravity.TOP|Gravity.CENTER_HORIZONTAL));setContentView(frame);
try{people=new JSONArray("[{\"id\":\"mom\",\"name\":\"妈妈\",\"online\":true},{\"id\":\"dad\",\"name\":\"爸爸\",\"online\":false},{\"id\":\"home\",\"name\":\"家庭屏\",\"online\":true}]");}catch(Exception e){throw new RuntimeException(e);}
surface.subtitle.setText("一句问候,家就在身边");surface.receive.setText("界面验收 · 模拟家人,不发送语音");surface.recipient.setText("对妈妈说句话");
surface.status.setText("只向已允许接收的家人发送");surface.stop.setVisibility(View.GONE);surface.expand.setOnClickListener(v->finish());
String mode=getIntent().getStringExtra("mode");boolean recording="recording".equals(mode)||"cancel".equals(mode),cancel="cancel".equals(mode);
surface.applyTheme("night".equals(mode));surface.targets(people,"mom",id->surface.targets(people,id,x->{}));
for(int i=0;i<31;i++)surface.recording(recording,cancel,8000,recording?(int)(4000+12000*Math.abs(Math.sin(i*.41))):0,false,true);
if(recording)surface.status.setText(cancel?"松开手指,这条语音不会发送":"正在对妈妈说话 · 演示波形");
scroller.postDelayed(()->{try{android.graphics.Bitmap bitmap=android.graphics.Bitmap.createBitmap(scroller.getWidth(),scroller.getHeight(),android.graphics.Bitmap.Config.ARGB_8888);scroller.draw(new android.graphics.Canvas(bitmap));try(java.io.FileOutputStream out=new java.io.FileOutputStream(new java.io.File(getExternalFilesDir(null),"preview.png"))){bitmap.compress(android.graphics.Bitmap.CompressFormat.PNG,100,out);}bitmap.recycle();}catch(Exception e){throw new RuntimeException(e);}},500);
}
}