Search in sources :

Example 1 with AbstractFlashcardViewer

use of com.ichi2.anki.AbstractFlashcardViewer in project AnkiChinaAndroid by ankichinateam.

the class AbstractFlashcardViewer method initLayout.

// Set the content view to the one provided and initialize accessors.
// Tracked separately as #5023 on github for clipboard
@SuppressWarnings("deprecation")
protected void initLayout() {
    FrameLayout mCardContainer = (FrameLayout) findViewById(R.id.flashcard_frame);
    mTopBarLayout = (RelativeLayout) findViewById(R.id.top_bar);
    ImageView mark = mTopBarLayout.findViewById(R.id.mark_icon);
    ImageView flag = mTopBarLayout.findViewById(R.id.flag_icon);
    mCardMarker = new CardMarker(mark, flag);
    mCardFrame = (FrameLayout) findViewById(R.id.flashcard);
    mCardFrameParent = (ViewGroup) mCardFrame.getParent();
    mTouchLayer = (FrameLayout) findViewById(R.id.touch_layer);
    mTouchLayer.setOnTouchListener(mGestureListener);
    if (!mDisableClipboard) {
        mClipboard = (android.text.ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE);
    }
    mCardFrame.removeAllViews();
    // Initialize swipe
    mGestureDetectorImpl = mLinkOverridesTouchGesture ? new LinkDetectingGestureDetector() : new MyGestureDetector();
    gestureDetector = new GestureDetectorCompat(this, mGestureDetectorImpl);
    mEaseButtonsLayout = findViewById(R.id.ease_buttons);
    mEase1 = findViewById(R.id.ease1);
    mEase1Layout = findViewById(R.id.flashcard_layout_ease1);
    mEase1Layout.setOnClickListener(mSelectEaseHandler);
    mEase2 = findViewById(R.id.ease2);
    mEase2Layout = findViewById(R.id.flashcard_layout_ease2);
    mEase2Layout.setOnClickListener(mSelectEaseHandler);
    mEase3 = findViewById(R.id.ease3);
    mEase3Layout = findViewById(R.id.flashcard_layout_ease3);
    mEase3Layout.setOnClickListener(mSelectEaseHandler);
    mEase4 = findViewById(R.id.ease4);
    mEase4Layout = findViewById(R.id.flashcard_layout_ease4);
    mEase4Layout.setOnClickListener(mSelectEaseHandler);
    mNext1 = findViewById(R.id.nextTime1);
    mNext2 = findViewById(R.id.nextTime2);
    mNext3 = findViewById(R.id.nextTime3);
    mNext4 = findViewById(R.id.nextTime4);
    if (!mShowNextReviewTime) {
        mNext1.setVisibility(View.GONE);
        mNext2.setVisibility(View.GONE);
        mNext3.setVisibility(View.GONE);
        mNext4.setVisibility(View.GONE);
    }
    Button mFlipCard = (Button) findViewById(R.id.flip_card);
    mFlipCardLayout = (LinearLayout) findViewById(R.id.flashcard_layout_flip);
    mFlipCardLayout.setOnClickListener(mFlipCardListener);
    if (!mButtonHeightSet && mRelativeButtonSize != 100) {
        ViewGroup.LayoutParams params = mFlipCardLayout.getLayoutParams();
        params.height = params.height * mRelativeButtonSize / 100;
        params = mEase1Layout.getLayoutParams();
        params.height = params.height * mRelativeButtonSize / 100;
        params = mEase2Layout.getLayoutParams();
        params.height = params.height * mRelativeButtonSize / 100;
        params = mEase3Layout.getLayoutParams();
        params.height = params.height * mRelativeButtonSize / 100;
        params = mEase4Layout.getLayoutParams();
        params.height = params.height * mRelativeButtonSize / 100;
        mButtonHeightSet = true;
    }
    mPreviewButtonsLayout = findViewById(R.id.preview_buttons_layout);
    mPreviewPrevCard = findViewById(R.id.preview_previous_flashcard);
    mPreviewNextCard = findViewById(R.id.preview_next_flashcard);
    mPreviewToggleAnswerText = findViewById(R.id.preview_flip_flashcard);
    mCardTimer = (Chronometer) findViewById(R.id.card_time);
    mChosenAnswer = (TextView) findViewById(R.id.choosen_answer);
    mAnswerField = (EditText) findViewById(R.id.answer_field);
    mLookUpIcon = findViewById(R.id.lookup_button);
    mLookUpIcon.setVisibility(View.GONE);
    mLookUpIcon.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View arg0) {
            Timber.i("AbstractFlashcardViewer:: Lookup button pressed");
            if (clipboardHasText()) {
                lookUp();
            }
        }
    });
    initControls();
    // Position answer buttons
    String answerButtonsPosition = AnkiDroidApp.getSharedPrefs(this).getString(getString(R.string.answer_buttons_position_preference), "bottom");
    LinearLayout answerArea = (LinearLayout) findViewById(R.id.bottom_area_layout);
    RelativeLayout.LayoutParams answerAreaParams = (RelativeLayout.LayoutParams) answerArea.getLayoutParams();
    RelativeLayout.LayoutParams cardContainerParams = (RelativeLayout.LayoutParams) mCardContainer.getLayoutParams();
    switch(answerButtonsPosition) {
        case "top":
            cardContainerParams.addRule(RelativeLayout.BELOW, R.id.bottom_area_layout);
            answerAreaParams.addRule(RelativeLayout.BELOW, R.id.mic_tool_bar_layer);
            answerArea.removeView(mAnswerField);
            answerArea.addView(mAnswerField, 1);
            break;
        case "bottom":
            cardContainerParams.addRule(RelativeLayout.ABOVE, R.id.bottom_area_layout);
            cardContainerParams.addRule(RelativeLayout.BELOW, R.id.mic_tool_bar_layer);
            answerAreaParams.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
            break;
        default:
            Timber.w("Unknown answerButtonsPosition: %s", answerButtonsPosition);
            break;
    }
    answerArea.setLayoutParams(answerAreaParams);
    mCardContainer.setLayoutParams(cardContainerParams);
}
Also used : ViewGroup(android.view.ViewGroup) CardMarker(com.ichi2.anki.reviewer.CardMarker) GestureDetectorCompat(androidx.core.view.GestureDetectorCompat) ImageView(android.widget.ImageView) View(android.view.View) WebView(android.webkit.WebView) TextView(android.widget.TextView) AudioView(com.ichi2.anki.multimediacard.AudioView) ImageButton(android.widget.ImageButton) Button(android.widget.Button) FrameLayout(android.widget.FrameLayout) RelativeLayout(android.widget.RelativeLayout) OnClickListener(android.view.View.OnClickListener) ImageView(android.widget.ImageView) Context(android.content.Context) LinearLayout(android.widget.LinearLayout)

Example 2 with AbstractFlashcardViewer

use of com.ichi2.anki.AbstractFlashcardViewer in project AnkiChinaAndroid by ankichinateam.

the class Previewer2 method showDeleteNoteDialog.

@Override
protected void showDeleteNoteDialog() {
    Resources res = getResources();
    new MaterialDialog.Builder(this).title(res.getString(R.string.delete_card_title)).iconAttr(R.attr.dialogErrorIcon).content(res.getString(R.string.delete_note_message, Utils.stripHTML(mCurrentCard.q(true)))).positiveText(res.getString(R.string.dialog_positive_delete)).negativeText(res.getString(R.string.dialog_cancel)).onPositive((dialog, which) -> {
        Timber.i("AbstractFlashcardViewer:: OK button pressed to delete note %d", mCurrentCard.getNid());
        mSoundPlayer.stopSounds();
        blockControls(false);
        CollectionTask.launchCollectionTask(DISMISS, mDismissCardHandler, new TaskData(new Object[] { mCurrentCard, Collection.DismissType.DELETE_NOTE }));
        mCardList[mIndex] = mCardList[mCardList.length - 1];
        // 数组缩容
        mCardList = Arrays.copyOf(mCardList, mCardList.length - 1);
        mIndex--;
        mNextCardLayout.performClick();
        // updateScreenCounts();
        Toast.makeText(Previewer2.this, "成功删除卡牌", Toast.LENGTH_SHORT).show();
    }).build().show();
}
Also used : Resources(android.content.res.Resources) TaskData(com.ichi2.async.TaskData)

Example 3 with AbstractFlashcardViewer

use of com.ichi2.anki.AbstractFlashcardViewer in project Anki-Android by ankidroid.

the class AbstractFlashcardViewer method showDeleteNoteDialog.

protected void showDeleteNoteDialog() {
    Resources res = getResources();
    new MaterialDialog.Builder(this).title(res.getString(R.string.delete_card_title)).iconAttr(R.attr.dialogErrorIcon).content(res.getString(R.string.delete_note_message, Utils.stripHTML(mCurrentCard.q(true)))).positiveText(R.string.dialog_positive_delete).negativeText(R.string.dialog_cancel).onPositive((dialog, which) -> {
        Timber.i("AbstractFlashcardViewer:: OK button pressed to delete note %d", mCurrentCard.getNid());
        mSoundPlayer.stopSounds();
        deleteNoteWithoutConfirmation();
    }).build().show();
}
Also used : TaskListenerBuilder(com.ichi2.anki.servicelayer.TaskListenerBuilder) Resources(android.content.res.Resources)

Example 4 with AbstractFlashcardViewer

use of com.ichi2.anki.AbstractFlashcardViewer in project Anki-Android by ankidroid.

the class AbstractFlashcardViewer method displayCardQuestion.

protected void displayCardQuestion(boolean reload) {
    Timber.d("displayCardQuestion()");
    sDisplayAnswer = false;
    mBackButtonPressedToReturn = false;
    setInterface();
    mTypeAnswer.setInput("");
    mTypeAnswer.updateInfo(mCurrentCard, getResources());
    if (!mCurrentCard.isEmpty() && mTypeAnswer.validForEditText()) {
        // Show text entry based on if the user wants to write the answer
        mAnswerField.setVisibility(View.VISIBLE);
        LanguageHintService.applyLanguageHint(mAnswerField, mTypeAnswer.getLanguageHint());
    } else {
        mAnswerField.setVisibility(View.GONE);
    }
    CardHtml content = mHtmlGenerator.generateHtml(mCurrentCard, reload, Side.FRONT);
    updateCard(content);
    hideEaseButtons();
    mAutomaticAnswer.onDisplayQuestion();
    // If Card-based TTS is enabled, we "automatic display" after the TTS has finished as we don't know the duration
    if (!mTTS.isEnabled()) {
        mAutomaticAnswer.scheduleAutomaticDisplayAnswer(mUseTimerDynamicMS);
    }
    Timber.i("AbstractFlashcardViewer:: Question successfully shown for card id %d", mCurrentCard.getId());
}
Also used : CardHtml(com.ichi2.anki.cardviewer.CardHtml)

Example 5 with AbstractFlashcardViewer

use of com.ichi2.anki.AbstractFlashcardViewer in project Anki-Android by ankidroid.

the class Reviewer method setFullScreen.

// #9332: UI Visibility -> Insets
@SuppressWarnings("deprecation")
private void setFullScreen(final AbstractFlashcardViewer a) {
    // Set appropriate flags to enable Sticky Immersive mode.
    a.getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_STABLE | // | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION // temporarily disabled due to #5245
    View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_FULLSCREEN | View.SYSTEM_UI_FLAG_LOW_PROFILE | View.SYSTEM_UI_FLAG_IMMERSIVE);
    // Show / hide the Action bar together with the status bar
    SharedPreferences prefs = AnkiDroidApp.getSharedPrefs(a);
    FullScreenMode fullscreenMode = FullScreenMode.fromPreference(prefs);
    a.getWindow().setStatusBarColor(Themes.getColorFromAttr(a, R.attr.colorPrimaryDark));
    View decorView = a.getWindow().getDecorView();
    decorView.setOnSystemUiVisibilityChangeListener(flags -> {
        final View toolbar = a.findViewById(R.id.toolbar);
        final View answerButtons = a.findViewById(R.id.answer_options_layout);
        final View topbar = a.findViewById(R.id.top_bar);
        if (toolbar == null || topbar == null || answerButtons == null) {
            return;
        }
        // Note that system bars will only be "visible" if none of the
        // LOW_PROFILE, HIDE_NAVIGATION, or FULLSCREEN flags are set.
        boolean visible = (flags & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) == 0;
        Timber.d("System UI visibility change. Visible: %b", visible);
        if (visible) {
            showViewWithAnimation(toolbar);
            if (fullscreenMode.equals(FullScreenMode.FULLSCREEN_ALL_GONE)) {
                showViewWithAnimation(topbar);
                showViewWithAnimation(answerButtons);
            }
        } else {
            hideViewWithAnimation(toolbar);
            if (fullscreenMode.equals(FullScreenMode.FULLSCREEN_ALL_GONE)) {
                hideViewWithAnimation(topbar);
                hideViewWithAnimation(answerButtons);
            }
        }
    });
}
Also used : SharedPreferences(android.content.SharedPreferences) FullScreenMode(com.ichi2.anki.reviewer.FullScreenMode) ImageView(android.widget.ImageView) View(android.view.View) WebView(android.webkit.WebView) TextView(android.widget.TextView) AudioView(com.ichi2.anki.multimediacard.AudioView)

Aggregations

AbstractFlashcardViewer (com.ichi2.anki.AbstractFlashcardViewer)9 Test (org.junit.Test)6 Resources (android.content.res.Resources)4 WebView (android.webkit.WebView)4 Uri (android.net.Uri)3 View (android.view.View)3 Context (android.content.Context)2 MediaPlayer (android.media.MediaPlayer)2 ImageView (android.widget.ImageView)2 TextView (android.widget.TextView)2 AudioView (com.ichi2.anki.multimediacard.AudioView)2 TaskData (com.ichi2.async.TaskData)2 SharedPreferences (android.content.SharedPreferences)1 AudioAttributes (android.media.AudioAttributes)1 AudioFocusRequest (android.media.AudioFocusRequest)1 Handler (android.os.Handler)1 TextToSpeech (android.speech.tts.TextToSpeech)1 UtteranceProgressListener (android.speech.tts.UtteranceProgressListener)1 OnClickListener (android.view.View.OnClickListener)1 ViewGroup (android.view.ViewGroup)1