@Override protected void onDestroy() { super.onDestroy(); // asr.cancel(); // asr.destroy(); ASRModule.destory(); TTSModule.destory(); }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); SdkData.turingApiManager.setRequestWatcher(new HHttpRequestWatcher(this)); findViewById(R.id.btn_send).setOnClickListener(this); findViewById(R.id.image_voice).setOnClickListener(this); ((EditText) findViewById(R.id.type_blank)).addTextChangedListener(new HTextWatcher()); ((RoundButton) findViewById(R.id.btn_voice)) .setOnTouchListener( new RoundButton.OnTouchListener() { @Override public void onTouchDown() { ASRModule.start( new Runnable() { @Override public void run() { sendMsg(ASRModule.output); } }); } @Override public void onTouchUp() { ASRModule.stop(); } }); ViewTreeObserver vto = findViewById(R.id.scroll_chatbox).getViewTreeObserver(); vto.addOnGlobalLayoutListener( new ViewTreeObserver.OnGlobalLayoutListener() { @Override public void onGlobalLayout() { View scrollView = MainActivity.this.findViewById(R.id.scroll_chatbox); int height = scrollView.getHeight(); int scrollValue = lastScrollHeight - height; if (scrollValue > 0 || scrollView.getScrollY() + scrollView.getHeight() != MainActivity.this.findViewById(R.id.layout_chatbox).getHeight()) scrollView.scrollBy(0, scrollValue); else scrollView.scrollBy( 0, -MainActivity.this.findViewById(R.id.layout_chatbox).getHeight() + scrollY + lastScrollHeight); lastScrollHeight = height; } }); vto.addOnScrollChangedListener( new ViewTreeObserver.OnScrollChangedListener() { @Override public void onScrollChanged() { View scrollView = MainActivity.this.findViewById(R.id.scroll_chatbox); scrollY = scrollView.getScrollY(); } }); findViewById(R.id.scroll_chatbox) .setOnTouchListener( new View.OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { v.requestFocus(); return false; } }); findViewById(R.id.btn_voice) .setOnFocusChangeListener( new View.OnFocusChangeListener() { @Override public void onFocusChange(View v, boolean hasFocus) { if (hasFocus && !isBtmBarShowing) showBtmBar(); if (isBtmBarShowing && !hasFocus && !isSendingMsg) hideBtmBar(); } }); ASRModule.init(this); TTSModule.init(this); }