Example usage for android.webkit WebSettings setNeedInitialFocus

List of usage examples for android.webkit WebSettings setNeedInitialFocus

Introduction

In this page you can find the example usage for android.webkit WebSettings setNeedInitialFocus.

Prototype

public abstract void setNeedInitialFocus(boolean flag);

Source Link

Document

Tells the WebView whether it needs to set a node to have focus when WebView#requestFocus(int,android.graphics.Rect) is called.

Usage

From source file:org.microg.gms.auth.login.LoginActivity.java

@SuppressLint("SetJavaScriptEnabled")
private static void prepareWebViewSettings(WebSettings settings) {
    settings.setUserAgentString(settings.getUserAgentString() + MAGIC_USER_AGENT);
    settings.setJavaScriptEnabled(true);
    settings.setSupportMultipleWindows(false);
    settings.setSaveFormData(false);// w ww.  j a va  2  s  .  c o m
    settings.setAllowFileAccess(false);
    settings.setDatabaseEnabled(false);
    settings.setNeedInitialFocus(false);
    settings.setUseWideViewPort(false);
    settings.setSupportZoom(false);
    settings.setJavaScriptCanOpenWindowsAutomatically(false);
}

From source file:ch.gianulli.flashcards.ui.Flashcard.java

/**
 * @param view Instance of flashcard.xml
 *//*from w  w  w . j  a v a 2  s .  c  o  m*/
public Flashcard(View view, OnCardAnsweredListener listener) {
    mListener = listener;

    mView = view;
    mQuestion = (StyledMarkdownView) view.findViewById(R.id.question);
    mAnswer = (StyledMarkdownView) view.findViewById(R.id.answer);
    mCardView = (CardView) view.findViewById(R.id.card);
    mButtonBar = view.findViewById(R.id.button_bar);
    mCorrectButton = (Button) view.findViewById(R.id.correct_button);
    mWrongButton = (Button) view.findViewById(R.id.wrong_button);

    mContext = mView.getContext();

    // Load colors
    int[] attrs = { android.R.attr.textColorSecondary, android.R.attr.textColorPrimary };
    TypedArray ta = mView.getContext().obtainStyledAttributes(R.style.AppTheme, attrs);
    sDeactivatedTextColor = colorToCSSString(ta.getColor(0, 0));
    sDefaultTextColor = colorToCSSString(ta.getColor(1, 0));
    ta.recycle();

    sGreenTextColor = colorToCSSString(ContextCompat.getColor(mContext, R.color.green));

    mQuestionColor = sDefaultTextColor;
    mAnswerColor = sGreenTextColor;

    // Make question visible
    mQuestion.setAlpha(1.0f);
    mAnswer.setAlpha(0.0f);

    // Setup WebViews
    WebSettings settings = mQuestion.getSettings();
    settings.setDefaultFontSize(mFontSize);
    settings.setLoadsImagesAutomatically(true);
    settings.setGeolocationEnabled(false);
    settings.setAllowFileAccess(false);
    settings.setDisplayZoomControls(false);
    settings.setNeedInitialFocus(false);
    settings.setSupportZoom(false);
    settings.setSaveFormData(false);
    settings.setJavaScriptEnabled(true);
    mQuestion.setHorizontalScrollBarEnabled(false);
    mQuestion.setVerticalScrollBarEnabled(false);

    settings = mAnswer.getSettings();
    settings.setDefaultFontSize(mFontSize);
    settings.setLoadsImagesAutomatically(true);
    settings.setGeolocationEnabled(false);
    settings.setAllowFileAccess(false);
    settings.setDisplayZoomControls(false);
    settings.setNeedInitialFocus(false);
    settings.setSupportZoom(false);
    settings.setSaveFormData(false);
    settings.setJavaScriptEnabled(true);
    mAnswer.setHorizontalScrollBarEnabled(false);
    mAnswer.setVerticalScrollBarEnabled(false);

    // Hack to disable text selection in WebViews
    mQuestion.setOnLongClickListener(new View.OnLongClickListener() {

        public boolean onLongClick(View v) {
            return true;
        }
    });
    mAnswer.setOnLongClickListener(new View.OnLongClickListener() {

        public boolean onLongClick(View v) {
            return true;
        }
    });

    // Card should "turn" on click
    final FrameLayout questionLayout = (FrameLayout) view.findViewById(R.id.question_layout);
    questionLayout.setClickable(true);
    questionLayout.setOnTouchListener(mTurnCardListener);

    mQuestion.setOnTouchListener(mTurnCardListener);
    mAnswer.setOnTouchListener(mTurnCardListener);

    // Deactivate card when user answers it
    mCorrectButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            deactivateCard(true);
            mListener.onCardAnswered(mCard, true);
        }
    });
    mWrongButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            deactivateCard(false);
            mListener.onCardAnswered(mCard, false);
        }
    });

    // Limit card width to 400dp
    ViewTreeObserver observer = mCardView.getViewTreeObserver();
    final int width480dp = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 400,
            view.getContext().getResources().getDisplayMetrics());
    observer.addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener() {
        @Override
        public boolean onPreDraw() {
            if (mCardView.getWidth() > width480dp) {
                ViewGroup.LayoutParams layoutParams = mCardView.getLayoutParams();
                layoutParams.width = width480dp;
                mCardView.setLayoutParams(layoutParams);
                mCardView.requestLayout();

                return false;
            }
            return true;
        }
    });
}