Search in sources :

Example 1 with KEY_SHOW_TTS_ICON

use of com.ichi2.libanki.Consts.KEY_SHOW_TTS_ICON in project AnkiChinaAndroid by ankichinateam.

the class AbstractFlashcardViewer method onCreateOptionsMenu.

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    MenuItem speak = menu.findItem(R.id.action_speak);
    if (speak != null) {
        speakingHandler = new Handler() {

            @Override
            public void handleMessage(Message msg) {
                super.handleMessage(msg);
                if (msg.what == 10086) {
                    speakingHandler.removeCallbacksAndMessages(null);
                    ((ImageButton) speak.getActionView()).setImageResource(R.mipmap.nav_bar_aloud_normal);
                }
            }
        };
        speak.setVisible(AnkiDroidApp.getSharedPrefs(this).getBoolean(KEY_SHOW_TTS_ICON, true));
        if (mVipSpeakMenuItem == null) {
            mVipSpeakMenuItem = new ImageButton(this);
        }
        mVipSpeakMenuItem.setBackground(null);
        speak.setActionView(mVipSpeakMenuItem);
        mVipSpeakMenuItem.setImageResource(R.mipmap.nav_bar_aloud_normal);
        speak.getActionView().setOnLongClickListener(v -> {
            SpeakSettingActivity.OpenSpeakSetting(mCurrentCard.getId(), mCurrentCard.getDid(), AbstractFlashcardViewer.this);
            return false;
        });
        speak.getActionView().setOnClickListener(v -> {
            Timber.i("speak icon pressed,ins speaking:" + mOnlineSpeaking + ",object:" + synthesizer);
            if (ReadText.isSpeaking()) /*||(synthesizer!=null&&synthesizer.isInitied()&&synthesizer.)*/
            {
                ReadText.stopTts();
            } else if (mOnlineSpeaking) /* && synthesizer != null*/
            {
                stopOnlineSpeaking();
                mSoundPlayer.stopSounds();
                mOnlineSpeaking = false;
            } else {
                playSoundsVIP(true);
            }
        });
        speakingRunnable = new Runnable() {

            @Override
            public void run() {
                speakingIndex++;
                // Timber.i("running speaking!:"+speakingIndex );
                if (isSpeaking()) {
                    // Timber.i("running is speaking! " );
                    ((ImageButton) speak.getActionView()).setImageResource(speakingIndex % 2 == 0 ? R.mipmap.nav_bar_aloud_one : R.mipmap.nav_bar_aloud_two);
                    speakingHandler.postDelayed(this, 200);
                } else {
                    // Timber.i("running is speaking end! " );
                    speakingHandler.removeCallbacksAndMessages(null);
                    ((ImageButton) speak.getActionView()).setImageResource(R.mipmap.nav_bar_aloud_normal);
                }
            }
        };
    }
    return super.onCreateOptionsMenu(menu);
}
Also used : ImageButton(android.widget.ImageButton) Message(android.os.Message) Handler(android.os.Handler) MissingImageHandler(com.ichi2.anki.cardviewer.MissingImageHandler) MenuItem(android.view.MenuItem)

Aggregations

Handler (android.os.Handler)1 Message (android.os.Message)1 MenuItem (android.view.MenuItem)1 ImageButton (android.widget.ImageButton)1 MissingImageHandler (com.ichi2.anki.cardviewer.MissingImageHandler)1