Search in sources :

Example 1 with ContextMenuEditText

use of org.wordpress.android.widgets.ContextMenuEditText in project WordPress-Android by wordpress-mobile.

the class SignInFragment method onCreateView.

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    ViewGroup rootView = (ViewGroup) inflater.inflate(R.layout.signin_fragment, container, false);
    mIconSwitcher = (ViewSwitcher) rootView.findViewById(R.id.icon_switcher);
    mWpcomLogotype = rootView.findViewById(R.id.nux_wordpress_logotype);
    mUrlButtonLayout = (RelativeLayout) rootView.findViewById(R.id.url_button_layout);
    mTwoStepLayout = (RelativeLayout) rootView.findViewById(R.id.two_factor_layout);
    mTwoStepFooter = (LinearLayout) rootView.findViewById(R.id.two_step_footer);
    mUsernameLayout = (RelativeLayout) rootView.findViewById(R.id.nux_username_layout);
    mUsernameLayout.setOnClickListener(mOnLoginFormClickListener);
    mPasswordLayout = (RelativeLayout) rootView.findViewById(R.id.nux_password_layout);
    mPasswordLayout.setOnClickListener(mOnLoginFormClickListener);
    mUsernameEditText = (EditText) rootView.findViewById(R.id.nux_username);
    mUsernameEditText.addTextChangedListener(this);
    mUsernameEditText.setOnClickListener(mOnLoginFormClickListener);
    mPasswordEditText = (EditText) rootView.findViewById(R.id.nux_password);
    mPasswordEditText.addTextChangedListener(this);
    mPasswordEditText.setOnClickListener(mOnLoginFormClickListener);
    mJetpackAuthLabel = (WPTextView) rootView.findViewById(R.id.nux_jetpack_auth_label);
    mUrlEditText = (EditText) rootView.findViewById(R.id.nux_url);
    mSignInButton = (WPTextView) rootView.findViewById(R.id.nux_sign_in_button);
    mSignInButton.setOnClickListener(mSignInClickListener);
    mProgressBarSignIn = (RelativeLayout) rootView.findViewById(R.id.nux_sign_in_progress_bar);
    mProgressTextSignIn = (WPTextView) rootView.findViewById(R.id.nux_sign_in_progress_text);
    mCreateAccountButton = (WPTextView) rootView.findViewById(R.id.nux_create_account_button);
    mCreateAccountButton.setOnClickListener(mCreateAccountListener);
    mAddSelfHostedButton = (WPTextView) rootView.findViewById(R.id.nux_add_selfhosted_button);
    mAddSelfHostedButton.setText(getString(R.string.nux_add_selfhosted_blog));
    mAddSelfHostedButton.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            toggleSignInMode();
        }
    });
    mForgotPassword = (WPTextView) rootView.findViewById(R.id.forgot_password);
    mForgotPassword.setOnClickListener(mForgotPasswordListener);
    mUsernameEditText.setOnFocusChangeListener(new View.OnFocusChangeListener() {

        public void onFocusChange(View v, boolean hasFocus) {
            if (!hasFocus) {
                autocorrectUsername();
                // Show the self-hosted sign-in form if the user entered a username that can't be for WordPress.com
                if (!mSelfHosted) {
                    mReservedNameMatcher.reset(mUsernameEditText.getText().toString());
                    if (mReservedNameMatcher.matches()) {
                        showSelfHostedSignInForm();
                    }
                }
            }
        }
    });
    mPasswordEditText.setOnEditorActionListener(mEditorAction);
    mUrlEditText.setOnEditorActionListener(mEditorAction);
    mTwoStepEditText = (ContextMenuEditText) rootView.findViewById(R.id.nux_two_step);
    mTwoStepEditText.addTextChangedListener(this);
    mTwoStepEditText.setOnKeyListener(new View.OnKeyListener() {

        @Override
        public boolean onKey(View v, int keyCode, KeyEvent event) {
            if ((event != null && (event.getKeyCode() == KeyEvent.KEYCODE_ENTER)) || (keyCode == EditorInfo.IME_ACTION_DONE)) {
                if (fieldsFilled()) {
                    signIn();
                }
            }
            return false;
        }
    });
    mTwoStepEditText.setOnContextMenuListener(new ContextMenuEditText.OnContextMenuListener() {

        @Override
        public void onCut() {
        }

        @Override
        public void onCopy() {
        }

        @Override
        public void onPaste() {
            mTwoStepEditText.setText(getAuthCodeFromClipboard());
            if (TextUtils.isEmpty(mTwoStepEditText.getText().toString())) {
                showTwoStepCodeError(R.string.invalid_verification_code_format);
            }
        }
    });
    WPTextView twoStepFooterButton = (WPTextView) rootView.findViewById(R.id.two_step_footer_button);
    twoStepFooterButton.setText(Html.fromHtml("<u>" + getString(R.string.two_step_footer_button) + "</u>"));
    twoStepFooterButton.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            requestSMSTwoStepCode();
        }
    });
    mBottomButtonsLayout = (LinearLayout) rootView.findViewById(R.id.nux_bottom_buttons);
    initPasswordVisibilityButton(rootView, mPasswordEditText);
    initInfoButtons(rootView);
    moveBottomButtons();
    if (mSelfHosted) {
        showSelfHostedSignInForm();
    }
    autofillFromBuildConfig();
    if (savedInstanceState == null) {
        configureMagicLinkUI();
    }
    mUsernameEditText.setOnEditorActionListener(new TextView.OnEditorActionListener() {

        @Override
        public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
            if ((didPressNextKey(actionId, event) || didPressEnterKey(actionId, event)) && mIsMagicLinksEnabled) {
                signIn();
                return true;
            } else {
                return false;
            }
        }
    });
    return rootView;
}
Also used : ViewGroup(android.view.ViewGroup) WPTextView(org.wordpress.android.widgets.WPTextView) ImageView(android.widget.ImageView) View(android.view.View) TextView(android.widget.TextView) WPTextView(org.wordpress.android.widgets.WPTextView) ContextMenuEditText(org.wordpress.android.widgets.ContextMenuEditText) KeyEvent(android.view.KeyEvent) OnClickListener(android.view.View.OnClickListener) TextView(android.widget.TextView) WPTextView(org.wordpress.android.widgets.WPTextView)

Aggregations

KeyEvent (android.view.KeyEvent)1 View (android.view.View)1 OnClickListener (android.view.View.OnClickListener)1 ViewGroup (android.view.ViewGroup)1 ImageView (android.widget.ImageView)1 TextView (android.widget.TextView)1 ContextMenuEditText (org.wordpress.android.widgets.ContextMenuEditText)1 WPTextView (org.wordpress.android.widgets.WPTextView)1