Search in sources :

Example 1 with TextInputEditText

use of com.google.android.material.textfield.TextInputEditText in project android by owncloud.

the class ReceiveExternalFilesActivity method showUploadTextDialog.

/**
 * Show a dialog where the user can enter a filename for the file he wants to place the text in.
 */
private void showUploadTextDialog() {
    final AlertDialog.Builder builder = new Builder(this);
    final View dialogView = getLayoutInflater().inflate(R.layout.dialog_upload_text, null);
    builder.setView(dialogView);
    builder.setTitle(R.string.uploader_upload_text_dialog_title);
    builder.setCancelable(false);
    builder.setPositiveButton(R.string.uploader_btn_upload_text, null);
    builder.setNegativeButton(android.R.string.cancel, null);
    final TextInputEditText input = dialogView.findViewById(R.id.inputFileName);
    final TextInputLayout inputLayout = dialogView.findViewById(R.id.inputTextLayout);
    input.addTextChangedListener(new TextWatcher() {

        @Override
        public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {
        }

        @Override
        public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
        }

        @Override
        public void afterTextChanged(Editable editable) {
            inputLayout.setError(null);
            inputLayout.setErrorEnabled(false);
        }
    });
    final AlertDialog alertDialog = builder.create();
    setFileNameFromIntent(alertDialog, input);
    alertDialog.setOnShowListener(dialog -> {
        Button button = alertDialog.getButton(AlertDialog.BUTTON_POSITIVE);
        button.setOnClickListener(view -> {
            String fileName = input.getText().toString();
            String error = null;
            if (fileName.length() > MAX_FILENAME_LENGTH) {
                error = String.format(getString(R.string.uploader_upload_text_dialog_filename_error_length_max), MAX_FILENAME_LENGTH);
            } else if (fileName.length() == 0) {
                error = getString(R.string.uploader_upload_text_dialog_filename_error_empty);
            } else {
                fileName += ".txt";
                Uri fileUri = savePlainTextToFile(fileName);
                mStreamsToUpload.clear();
                mStreamsToUpload.add(fileUri);
                uploadFiles();
            }
            inputLayout.setErrorEnabled(error != null);
            inputLayout.setError(error);
        });
    });
    alertDialog.show();
}
Also used : AlertDialog(androidx.appcompat.app.AlertDialog) Builder(androidx.appcompat.app.AlertDialog.Builder) Builder(androidx.appcompat.app.AlertDialog.Builder) View(android.view.View) AdapterView(android.widget.AdapterView) SearchView(androidx.appcompat.widget.SearchView) TextView(android.widget.TextView) ListView(android.widget.ListView) SortOptionsView(com.owncloud.android.presentation.ui.files.SortOptionsView) Uri(android.net.Uri) Button(android.widget.Button) TextInputEditText(com.google.android.material.textfield.TextInputEditText) TextWatcher(android.text.TextWatcher) Editable(android.text.Editable) TextInputLayout(com.google.android.material.textfield.TextInputLayout)

Example 2 with TextInputEditText

use of com.google.android.material.textfield.TextInputEditText in project FirebaseUI-Android by firebase.

the class EmailActivityTest method testSetDefaultEmail_validField.

@Test
public void testSetDefaultEmail_validField() {
    EmailActivity emailActivity = createActivity(EmailAuthProvider.PROVIDER_ID, false, true);
    CheckEmailFragment fragment = (CheckEmailFragment) emailActivity.getSupportFragmentManager().findFragmentByTag(CheckEmailFragment.TAG);
    assertThat(fragment).isNotNull();
    TextInputEditText email = emailActivity.findViewById(R.id.email);
    assertEquals(TestConstants.EMAIL, email.getText().toString());
}
Also used : TextInputEditText(com.google.android.material.textfield.TextInputEditText) Test(org.junit.Test)

Aggregations

TextInputEditText (com.google.android.material.textfield.TextInputEditText)2 Uri (android.net.Uri)1 Editable (android.text.Editable)1 TextWatcher (android.text.TextWatcher)1 View (android.view.View)1 AdapterView (android.widget.AdapterView)1 Button (android.widget.Button)1 ListView (android.widget.ListView)1 TextView (android.widget.TextView)1 AlertDialog (androidx.appcompat.app.AlertDialog)1 Builder (androidx.appcompat.app.AlertDialog.Builder)1 SearchView (androidx.appcompat.widget.SearchView)1 TextInputLayout (com.google.android.material.textfield.TextInputLayout)1 SortOptionsView (com.owncloud.android.presentation.ui.files.SortOptionsView)1 Test (org.junit.Test)1