Search in sources :

Example 21 with OnEditorActionListener

use of android.widget.TextView.OnEditorActionListener in project androidannotations by androidannotations.

the class EditorActionsActivityTest method testActionHandled.

@Test
public void testActionHandled() {
    assertThat(activity.actionHandled).isFalse();
    EditText editText = (EditText) activity.findViewById(R.id.editText1);
    OnEditorActionListener listener = getOnEditorActionListener(editText);
    listener.onEditorAction(editText, 0, null);
    assertThat(activity.actionHandled).isTrue();
}
Also used : EditText(android.widget.EditText) OnEditorActionListener(android.widget.TextView.OnEditorActionListener) Test(org.junit.Test)

Example 22 with OnEditorActionListener

use of android.widget.TextView.OnEditorActionListener in project androidannotations by androidannotations.

the class EditorActionsActivityTest method testEditTextPassed.

@Test
public void testEditTextPassed() {
    assertThat(activity.passedEditText).isNull();
    EditText editText = (EditText) activity.findViewById(R.id.editText4);
    OnEditorActionListener listener = getOnEditorActionListener(editText);
    listener.onEditorAction(editText, 0, null);
    assertThat(activity.passedEditText).isSameAs(editText);
}
Also used : EditText(android.widget.EditText) OnEditorActionListener(android.widget.TextView.OnEditorActionListener) Test(org.junit.Test)

Example 23 with OnEditorActionListener

use of android.widget.TextView.OnEditorActionListener in project androidannotations by androidannotations.

the class EditorActionsActivityTest method testActionIdPassed.

@Test
public void testActionIdPassed() {
    assertThat(activity.actionId).isZero();
    EditText editText = (EditText) activity.findViewById(R.id.editText2);
    OnEditorActionListener listener = getOnEditorActionListener(editText);
    int actionId = 2;
    listener.onEditorAction(editText, actionId, null);
    assertThat(activity.actionId).isEqualTo(actionId);
}
Also used : EditText(android.widget.EditText) OnEditorActionListener(android.widget.TextView.OnEditorActionListener) Test(org.junit.Test)

Example 24 with OnEditorActionListener

use of android.widget.TextView.OnEditorActionListener in project storymaker by StoryMaker.

the class CacheWordActivity method requestPassphrase.

private void requestPassphrase() {
    mViewCreatePin.setVisibility(View.GONE);
    mViewEnterPin.setVisibility(View.VISIBLE);
    mButton = (Button) findViewById(R.id.btnOpen);
    mButton.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            if (mTextEnterPin.getText().toString().length() == 0)
                return;
            // Check passphrase
            try {
                if (mNotif == null) {
                    Timber.d("no handler notification");
                    // only display notification if the user has set a pin
                    SharedPreferences sp = getSharedPreferences("appPrefs", MODE_PRIVATE);
                    String cachewordStatus = sp.getString("cacheword_status", "default");
                    if (cachewordStatus.equals(BaseActivity.CACHEWORD_SET)) {
                        Timber.d("pin set, so display notification (cacheword)");
                        mNotif = buildNotification(CacheWordActivity.this);
                        mCacheWordHandler.setNotification(mNotif);
                    } else {
                        Timber.d("no pin set, so no notification (cacheword)");
                    }
                    Timber.d("set handler notification?");
                } else {
                    Timber.d("handler has a notification");
                }
                mCacheWordHandler.setPassphrase(mTextEnterPin.getText().toString().toCharArray());
                Timber.d("verified pin (request)");
            } catch (GeneralSecurityException gse) {
                mTextEnterPin.setText("");
                Log.e("CacheWordActivity", "failed to verify pin (request): " + gse.getMessage());
                return;
            }
        }
    });
    mTextEnterPin.setOnEditorActionListener(new OnEditorActionListener() {

        @Override
        public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
            if (actionId == EditorInfo.IME_NULL || actionId == EditorInfo.IME_ACTION_GO) {
                InputMethodManager imm = (InputMethodManager) getSystemService(INPUT_METHOD_SERVICE);
                Handler threadHandler = new Handler();
                imm.hideSoftInputFromWindow(v.getWindowToken(), 0, new ResultReceiver(threadHandler) {

                    @Override
                    protected void onReceiveResult(int resultCode, Bundle resultData) {
                        super.onReceiveResult(resultCode, resultData);
                        mButton.performClick();
                    }
                });
                return true;
            }
            return false;
        }
    });
}
Also used : SharedPreferences(android.content.SharedPreferences) Bundle(android.os.Bundle) GeneralSecurityException(java.security.GeneralSecurityException) Handler(android.os.Handler) CacheWordHandler(info.guardianproject.cacheword.CacheWordHandler) InputMethodManager(android.view.inputmethod.InputMethodManager) View(android.view.View) TextView(android.widget.TextView) KeyEvent(android.view.KeyEvent) OnClickListener(android.view.View.OnClickListener) OnEditorActionListener(android.widget.TextView.OnEditorActionListener) TextView(android.widget.TextView) ResultReceiver(android.os.ResultReceiver)

Example 25 with OnEditorActionListener

use of android.widget.TextView.OnEditorActionListener in project storymaker by StoryMaker.

the class CacheWordActivity method createPassphrase.

private void createPassphrase() {
    mViewCreatePin.setVisibility(View.VISIBLE);
    mViewEnterPin.setVisibility(View.GONE);
    mTextCreatePin.setOnEditorActionListener(new OnEditorActionListener() {

        @Override
        public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
            if (actionId == EditorInfo.IME_NULL || actionId == EditorInfo.IME_ACTION_DONE) {
                if (!isPasswordValid())
                    showValidationError();
                else
                    mSlider.showConfirmationField();
            }
            return false;
        }
    });
    mTextConfirmPin.setOnEditorActionListener(new OnEditorActionListener() {

        @Override
        public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
            if (actionId == EditorInfo.IME_NULL || actionId == EditorInfo.IME_ACTION_DONE) {
                if (!newEqualsConfirmation()) {
                    showInequalityError();
                    mSlider.showNewPasswordField();
                }
            }
            return false;
        }
    });
    Button btnCreate = (Button) findViewById(R.id.btnCreate);
    btnCreate.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            // validate pin
            if (!isPasswordValid()) {
                showValidationError();
                mSlider.showNewPasswordField();
            } else if (isConfirmationFieldEmpty()) {
                mSlider.showConfirmationField();
            } else if (!newEqualsConfirmation()) {
                showInequalityError();
                mSlider.showNewPasswordField();
            } else {
                try {
                    CharSequence defaultPinSequence = getText(R.string.cacheword_default_pin);
                    char[] defaultPin = defaultPinSequence.toString().toCharArray();
                    PassphraseSecrets secrets = PassphraseSecrets.fetchSecrets(CacheWordActivity.this, defaultPin);
                    mCacheWordHandler.changePassphrase(secrets, mTextCreatePin.getText().toString().toCharArray());
                    Timber.d("replaced default pin");
                    // moving this code here to prevent accidental locks
                    // set status to prevent use of default pin
                    SharedPreferences sp = getSharedPreferences("appPrefs", Context.MODE_PRIVATE);
                    SharedPreferences.Editor e = sp.edit();
                    e.putString("cacheword_status", BaseActivity.CACHEWORD_SET);
                    e.commit();
                    // changePassphrase does not seem to trigger this so it is called manually
                    onCacheWordOpened();
                } catch (GeneralSecurityException gse1) {
                    Log.e("CacheWordActivity", "failed to replace default pin: " + gse1.getMessage());
                    try {
                        mCacheWordHandler.setPassphrase(mTextCreatePin.getText().toString().toCharArray());
                        Timber.d("created new pin (create)");
                    } catch (GeneralSecurityException gse2) {
                        Log.e("CacheWordActivity", "failed to create new pin (create): " + gse2.getMessage());
                    }
                } catch (IOException ioe) {
                    Log.e("CacheWordActivity", "unexpected exception: " + ioe.getMessage());
                }
            }
        }
    });
}
Also used : SharedPreferences(android.content.SharedPreferences) GeneralSecurityException(java.security.GeneralSecurityException) PassphraseSecrets(info.guardianproject.cacheword.PassphraseSecrets) IOException(java.io.IOException) View(android.view.View) TextView(android.widget.TextView) KeyEvent(android.view.KeyEvent) Button(android.widget.Button) OnClickListener(android.view.View.OnClickListener) OnEditorActionListener(android.widget.TextView.OnEditorActionListener) TextView(android.widget.TextView)

Aggregations

OnEditorActionListener (android.widget.TextView.OnEditorActionListener)37 KeyEvent (android.view.KeyEvent)32 TextView (android.widget.TextView)32 View (android.view.View)28 DialogInterface (android.content.DialogInterface)13 LayoutInflater (android.view.LayoutInflater)13 EditText (android.widget.EditText)13 OnClickListener (android.view.View.OnClickListener)12 AlertDialog (android.app.AlertDialog)11 Context (android.content.Context)11 OnClickListener (android.content.DialogInterface.OnClickListener)11 Intent (android.content.Intent)9 Test (org.junit.Test)6 ContentResolver (android.content.ContentResolver)5 Button (android.widget.Button)4 InjectView (roboguice.inject.InjectView)4 Handler (android.os.Handler)3 AlertDialog (android.support.v7.app.AlertDialog)3 InputMethodManager (android.view.inputmethod.InputMethodManager)3 AutoCompleteTextView (android.widget.AutoCompleteTextView)3