Search in sources :

Example 1 with EaseButton

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

the class AbstractFlashcardViewer method initLayout.

// Set the content view to the one provided and initialize accessors.
protected void initLayout() {
    FrameLayout cardContainer = findViewById(R.id.flashcard_frame);
    mTopBarLayout = findViewById(R.id.top_bar);
    mCardFrame = findViewById(R.id.flashcard);
    mCardFrameParent = (ViewGroup) mCardFrame.getParent();
    mTouchLayer = findViewById(R.id.touch_layer);
    mTouchLayer.setOnTouchListener(mGestureListener);
    mCardFrame.removeAllViews();
    // Initialize swipe
    mGestureDetectorImpl = new LinkDetectingGestureDetector();
    mGestureDetector = new GestureDetector(this, mGestureDetectorImpl);
    mEaseButtonsLayout = findViewById(R.id.ease_buttons);
    mEaseButton1 = new EaseButton(EASE_1, findViewById(R.id.flashcard_layout_ease1), findViewById(R.id.ease1), findViewById(R.id.nextTime1));
    mEaseButton1.setListeners(mEaseHandler);
    mEaseButton2 = new EaseButton(EASE_2, findViewById(R.id.flashcard_layout_ease2), findViewById(R.id.ease2), findViewById(R.id.nextTime2));
    mEaseButton2.setListeners(mEaseHandler);
    mEaseButton3 = new EaseButton(EASE_3, findViewById(R.id.flashcard_layout_ease3), findViewById(R.id.ease3), findViewById(R.id.nextTime3));
    mEaseButton3.setListeners(mEaseHandler);
    mEaseButton4 = new EaseButton(EASE_4, findViewById(R.id.flashcard_layout_ease4), findViewById(R.id.ease4), findViewById(R.id.nextTime4));
    mEaseButton4.setListeners(mEaseHandler);
    if (!mShowNextReviewTime) {
        mEaseButton1.hideNextReviewTime();
        mEaseButton2.hideNextReviewTime();
        mEaseButton3.hideNextReviewTime();
        mEaseButton4.hideNextReviewTime();
    }
    Button flipCard = findViewById(R.id.flip_card);
    mFlipCardLayout = findViewById(R.id.flashcard_layout_flip);
    mFlipCardLayout.setOnClickListener(mFlipCardListener);
    if (animationEnabled()) {
        flipCard.setBackgroundResource(Themes.getResFromAttr(this, R.attr.hardButtonRippleRef));
    }
    if (!mButtonHeightSet && mRelativeButtonSize != 100) {
        ViewGroup.LayoutParams params = mFlipCardLayout.getLayoutParams();
        params.height = params.height * mRelativeButtonSize / 100;
        mEaseButton1.setButtonScale(mRelativeButtonSize);
        mEaseButton2.setButtonScale(mRelativeButtonSize);
        mEaseButton3.setButtonScale(mRelativeButtonSize);
        mEaseButton4.setButtonScale(mRelativeButtonSize);
        mButtonHeightSet = true;
    }
    mInitialFlipCardHeight = mFlipCardLayout.getLayoutParams().height;
    if (mLargeAnswerButtons) {
        ViewGroup.LayoutParams params = mFlipCardLayout.getLayoutParams();
        params.height = mInitialFlipCardHeight * 2;
    }
    mAnswerField = findViewById(R.id.answer_field);
    initControls();
    // Position answer buttons
    String answerButtonsPosition = AnkiDroidApp.getSharedPrefs(this).getString(getString(R.string.answer_buttons_position_preference), "bottom");
    LinearLayout answerArea = findViewById(R.id.bottom_area_layout);
    RelativeLayout.LayoutParams answerAreaParams = (RelativeLayout.LayoutParams) answerArea.getLayoutParams();
    RelativeLayout.LayoutParams cardContainerParams = (RelativeLayout.LayoutParams) cardContainer.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);
            answerArea.setVisibility(View.VISIBLE);
            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);
            answerArea.setVisibility(View.VISIBLE);
            break;
        case "none":
            answerArea.setVisibility(View.GONE);
            break;
        default:
            Timber.w("Unknown answerButtonsPosition: %s", answerButtonsPosition);
            break;
    }
    answerArea.setLayoutParams(answerAreaParams);
    cardContainer.setLayoutParams(cardContainerParams);
}
Also used : EaseButton(com.ichi2.anki.reviewer.EaseButton) Button(android.widget.Button) ViewGroup(android.view.ViewGroup) FrameLayout(android.widget.FrameLayout) RelativeLayout(android.widget.RelativeLayout) GestureDetector(android.view.GestureDetector) EaseButton(com.ichi2.anki.reviewer.EaseButton) LinearLayout(android.widget.LinearLayout)

Aggregations

GestureDetector (android.view.GestureDetector)1 ViewGroup (android.view.ViewGroup)1 Button (android.widget.Button)1 FrameLayout (android.widget.FrameLayout)1 LinearLayout (android.widget.LinearLayout)1 RelativeLayout (android.widget.RelativeLayout)1 EaseButton (com.ichi2.anki.reviewer.EaseButton)1