use of com.google.android.material.textfield.TextInputLayout 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();
}
use of com.google.android.material.textfield.TextInputLayout in project OneSignal-Android-SDK by OneSignal.
the class Dialog method createSendOutcomeAlertDialog.
public void createSendOutcomeAlertDialog(final String content) {
final View sendOutcomeAlertDialogView = layoutInflater.inflate(R.layout.send_outcome_alert_dialog_layout, null, false);
final CardView sendOutcomeDialogTitleCardView = sendOutcomeAlertDialogView.findViewById(R.id.send_outcome_alert_dialog_selection_card_view);
final RelativeLayout sendOutcomeDialogTitleRelativeLayout = sendOutcomeAlertDialogView.findViewById(R.id.send_outcome_alert_dialog_selection_relative_layout);
final TextView sendOutcomeDialogTitleTextView = sendOutcomeAlertDialogView.findViewById(R.id.send_outcome_alert_dialog_selection_text_view);
final ImageView sendOutcomeDialogTitleArrowImageView = sendOutcomeAlertDialogView.findViewById(R.id.send_outcome_alert_dialog_selection_arrow_image_view);
final RecyclerView sendOutcomeDialogSelectionRecyclerView = sendOutcomeAlertDialogView.findViewById(R.id.send_outcome_alert_dialog_selection_recycler_view);
final LinearLayout sendOutcomeDialogSelectionContentLinearLayout = sendOutcomeAlertDialogView.findViewById(R.id.send_outcome_alert_dialog_content_linear_layout);
final TextInputLayout sendOutcomeDialogNameTextInputLayout = sendOutcomeAlertDialogView.findViewById(R.id.send_outcome_alert_dialog_name_text_input_layout);
final EditText sendOutcomeDialogNameEditText = sendOutcomeAlertDialogView.findViewById(R.id.send_outcome_alert_dialog_name_edit_text);
final TextInputLayout sendOutcomeDialogValueTextInputLayout = sendOutcomeAlertDialogView.findViewById(R.id.send_outcome_alert_dialog_value_text_input_layout);
final EditText sendOutcomeDialogValueEditText = sendOutcomeAlertDialogView.findViewById(R.id.send_outcome_alert_dialog_value_edit_text);
final ProgressBar sendOutcomeDialogProgressBar = sendOutcomeAlertDialogView.findViewById(R.id.send_outcome_alert_dialog_progress_bar);
sendOutcomeDialogNameTextInputLayout.setHint("Name");
sendOutcomeDialogValueTextInputLayout.setHint("Value");
sendOutcomeDialogTitleTextView.setText(content);
font.applyFont(sendOutcomeDialogTitleTextView, font.saralaBold);
font.applyFont(sendOutcomeDialogNameTextInputLayout, font.saralaBold);
font.applyFont(sendOutcomeDialogValueTextInputLayout, font.saralaBold);
sendOutcomeDialogTitleCardView.setCardElevation(8f);
recyclerViewBuilder.setupRecyclerView(sendOutcomeDialogSelectionRecyclerView, 3, false, true);
LinearLayoutManager linearLayoutManager = new LinearLayoutManager(context);
sendOutcomeDialogSelectionRecyclerView.setLayoutManager(linearLayoutManager);
EnumSelectionRecyclerViewAdapter enumSelectionRecyclerViewAdapter = new EnumSelectionRecyclerViewAdapter(context, OutcomeEvent.values(), new EnumSelectionCallback() {
@Override
public void onSelection(String title) {
int nameVisibility = View.GONE;
int valueVisibility = View.GONE;
OutcomeEvent outcomeEvent = OutcomeEvent.enumFromTitleString(title);
if (outcomeEvent == null) {
Drawable arrow = context.getResources().getDrawable(R.drawable.ic_chevron_down_white_48dp);
sendOutcomeDialogTitleArrowImageView.setImageDrawable(arrow);
sendOutcomeDialogTitleCardView.setCardElevation(0f);
sendOutcomeDialogSelectionRecyclerView.setVisibility(View.GONE);
sendOutcomeDialogSelectionContentLinearLayout.setVisibility(View.GONE);
sendOutcomeDialogNameEditText.setVisibility(nameVisibility);
sendOutcomeDialogValueTextInputLayout.setVisibility(valueVisibility);
return;
}
switch(outcomeEvent) {
case OUTCOME:
case UNIQUE_OUTCOME:
nameVisibility = View.VISIBLE;
break;
case OUTCOME_WITH_VALUE:
nameVisibility = View.VISIBLE;
valueVisibility = View.VISIBLE;
break;
}
sendOutcomeDialogTitleTextView.setText(outcomeEvent.getTitle());
Drawable arrow = context.getResources().getDrawable(R.drawable.ic_chevron_down_white_48dp);
sendOutcomeDialogTitleArrowImageView.setImageDrawable(arrow);
sendOutcomeDialogTitleCardView.setCardElevation(0f);
sendOutcomeDialogSelectionRecyclerView.setVisibility(View.GONE);
sendOutcomeDialogSelectionContentLinearLayout.setVisibility(View.VISIBLE);
sendOutcomeDialogNameTextInputLayout.setVisibility(nameVisibility);
sendOutcomeDialogNameEditText.setVisibility(nameVisibility);
sendOutcomeDialogValueTextInputLayout.setVisibility(valueVisibility);
sendOutcomeDialogValueEditText.setVisibility(valueVisibility);
}
});
sendOutcomeDialogSelectionRecyclerView.setAdapter(enumSelectionRecyclerViewAdapter);
sendOutcomeDialogTitleRelativeLayout.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
boolean showMenu = sendOutcomeDialogSelectionRecyclerView.getVisibility() == View.GONE;
Drawable arrow = context.getResources().getDrawable(showMenu ? R.drawable.ic_chevron_up_white_48dp : R.drawable.ic_chevron_down_white_48dp);
int menuVisibility = showMenu ? View.VISIBLE : View.GONE;
int contentVisibility = showMenu ? View.GONE : View.VISIBLE;
float shadow = showMenu ? 8f : 0f;
sendOutcomeDialogTitleArrowImageView.setImageDrawable(arrow);
sendOutcomeDialogTitleCardView.setCardElevation(shadow);
sendOutcomeDialogSelectionRecyclerView.setVisibility(menuVisibility);
sendOutcomeDialogSelectionContentLinearLayout.setVisibility(contentVisibility);
int nameVisibility = View.GONE;
int valueVisibility = View.GONE;
String selectedTitle = sendOutcomeDialogTitleTextView.getText().toString();
OutcomeEvent outcomeEvent = OutcomeEvent.enumFromTitleString(selectedTitle);
if (outcomeEvent == null) {
sendOutcomeDialogSelectionContentLinearLayout.setVisibility(View.GONE);
return;
}
if (!showMenu) {
switch(outcomeEvent) {
case OUTCOME:
case UNIQUE_OUTCOME:
nameVisibility = View.VISIBLE;
break;
case OUTCOME_WITH_VALUE:
nameVisibility = View.VISIBLE;
valueVisibility = View.VISIBLE;
break;
}
}
sendOutcomeDialogSelectionContentLinearLayout.setVisibility(nameVisibility);
sendOutcomeDialogNameEditText.setVisibility(nameVisibility);
sendOutcomeDialogValueTextInputLayout.setVisibility(valueVisibility);
sendOutcomeDialogValueEditText.setVisibility(valueVisibility);
}
});
final CustomAlertDialogBuilder sendOutcomeAlertDialog = new CustomAlertDialogBuilder(context, sendOutcomeAlertDialogView);
sendOutcomeAlertDialog.setView(sendOutcomeAlertDialogView);
sendOutcomeAlertDialog.setIsCancelable(true);
sendOutcomeAlertDialog.setCanceledOnTouchOutside(false);
sendOutcomeAlertDialog.setPositiveButton(Text.BUTTON_SEND, new DialogInterface.OnClickListener() {
@Override
public void onClick(final DialogInterface dialog, int which) {
toggleUpdateAlertDialogAttributes(true);
String selectedTitle = sendOutcomeDialogTitleTextView.getText().toString();
OutcomeEvent outcomeEvent = OutcomeEvent.enumFromTitleString(selectedTitle);
if (outcomeEvent == null) {
toaster.makeCustomViewToast("Please select an outcome type!", ToastType.ERROR);
toggleUpdateAlertDialogAttributes(false);
return;
}
String name = sendOutcomeDialogNameEditText.getText().toString().trim();
String value = sendOutcomeDialogValueEditText.getText().toString().trim();
if (name.isEmpty()) {
toaster.makeCustomViewToast("Please enter an outcome name!", ToastType.ERROR);
toggleUpdateAlertDialogAttributes(false);
return;
}
switch(outcomeEvent) {
case OUTCOME:
OneSignal.sendOutcome(name, new OneSignal.OutcomeCallback() {
@Override
public void onSuccess(@Nullable OSOutcomeEvent outcomeEvent) {
((Activity) context).runOnUiThread(new Runnable() {
@Override
public void run() {
toggleUpdateAlertDialogAttributes(false);
dialog.dismiss();
}
});
}
});
break;
case UNIQUE_OUTCOME:
OneSignal.sendUniqueOutcome(name, new OneSignal.OutcomeCallback() {
@Override
public void onSuccess(@Nullable OSOutcomeEvent outcomeEvent) {
((Activity) context).runOnUiThread(new Runnable() {
@Override
public void run() {
toggleUpdateAlertDialogAttributes(false);
dialog.dismiss();
}
});
}
});
break;
case OUTCOME_WITH_VALUE:
if (value.isEmpty()) {
toaster.makeCustomViewToast("Please enter an outcome value!", ToastType.ERROR);
toggleUpdateAlertDialogAttributes(false);
return;
}
OneSignal.sendOutcomeWithValue(name, Float.parseFloat(value), new OneSignal.OutcomeCallback() {
@Override
public void onSuccess(@Nullable OSOutcomeEvent outcomeEvent) {
((Activity) context).runOnUiThread(new Runnable() {
@Override
public void run() {
toggleUpdateAlertDialogAttributes(false);
dialog.dismiss();
}
});
}
});
break;
}
InterfaceUtil.hideKeyboardFrom(context, sendOutcomeAlertDialogView);
}
private void toggleUpdateAlertDialogAttributes(boolean disableAttributes) {
int progressVisibility = disableAttributes ? View.VISIBLE : View.GONE;
sendOutcomeDialogProgressBar.setVisibility(progressVisibility);
int buttonVisibility = disableAttributes ? View.GONE : View.VISIBLE;
sendOutcomeAlertDialog.getPositiveButtonElement().setVisibility(buttonVisibility);
sendOutcomeAlertDialog.getNegativeButtonElement().setVisibility(buttonVisibility);
sendOutcomeAlertDialog.getPositiveButtonElement().setEnabled(!disableAttributes);
sendOutcomeAlertDialog.getNegativeButtonElement().setEnabled(!disableAttributes);
sendOutcomeAlertDialog.setIsCancelable(!disableAttributes);
}
}).setNegativeButton(Text.BUTTON_CANCEL, null);
sendOutcomeAlertDialog.show();
}
use of com.google.android.material.textfield.TextInputLayout in project ETSMobile-Android2 by ApplETS.
the class BandwidthFragment method onCreateView.
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
final View v = inflater.inflate(R.layout.fragment_bandwith, container, false);
textInputLayoutPhase = v.findViewById(R.id.text_input_layout_phase);
editTextPhase = v.findViewById(R.id.bandwidth_editText_phase);
phaseSpinner = v.findViewById(R.id.bandwidth_phase_spinner);
textInputLayoutApp = v.findViewById(R.id.text_input_layout_app);
editTextApp = v.findViewById(R.id.bandwidth_editText_app);
textInputLayoutChambre = v.findViewById(R.id.text_input_layout_chambre);
editTextChambre = v.findViewById(R.id.bandwidth_editText_chambre);
// grid = v.findViewById(R.id.bandwith_grid);
progressBar = v.findViewById(R.id.bandwidth_progress);
progressBarTv = v.findViewById(R.id.bandwidth_progress_tv);
loadProgressBar = v.findViewById(R.id.progressBarLoad);
progressLayout = v.findViewById(R.id.bandwidth_progress_layout);
chart = v.findViewById(R.id.chart);
chart.setVisibility(View.INVISIBLE);
progressLayout.setVisibility(View.GONE);
SharedPreferences defaultSharedPreferences = PreferenceManager.getDefaultSharedPreferences(getActivity());
phase = defaultSharedPreferences.getString(PHASE_PREF_KEY, "");
app = defaultSharedPreferences.getString(APP_PREF_KEY, "");
chambre = defaultSharedPreferences.getString(CHAMBRE_PREF_KEY, "");
if (chambre.length() > 0)
editTextChambre.setText(chambre);
else
editTextChambre.setText(UNE_SEULE_CHAMBRE);
if (phase.length() > 0 && app.length() > 0) {
editTextApp.setText(app);
phaseSpinner.setSelection(Integer.parseInt(phase) - 1);
getBandwidth(phase, app, chambre);
}
editTextPhase.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
phaseSpinner.performClick();
}
});
phaseSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
int phase = position + 1;
editTextPhase.setText(String.valueOf(phase));
if (phase == 3) {
displayPhase3Dialog();
}
verifyInputsAndGetBandwidth();
}
@Override
public void onNothingSelected(AdapterView<?> parent) {
}
});
TextWatcher textWatcher = new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence cS, int start, int before, int count) {
}
@Override
public void onTextChanged(CharSequence cS, int start, int before, int count) {
verifyInputsAndGetBandwidth();
}
@Override
public void afterTextChanged(Editable editable) {
}
};
editTextApp.addTextChangedListener(textWatcher);
editTextChambre.addTextChangedListener(textWatcher);
OnFocusChangeListener editTextFocusChangeListener = new OnFocusChangeListener() {
@Override
public void onFocusChange(View view, boolean hasFocus) {
EditText editText = (EditText) view;
TextInputLayout textInputLayout = null;
switch(view.getId()) {
case R.id.bandwidth_editText_phase:
textInputLayout = textInputLayoutPhase;
break;
case R.id.bandwidth_editText_app:
textInputLayout = textInputLayoutApp;
break;
}
if (textInputLayout != null) {
if (!hasFocus && editText.getText().toString().length() == 0)
textInputLayout.setError(getString(R.string.error_field_required));
else
textInputLayout.setError(null);
}
}
};
editTextPhase.setOnFocusChangeListener(editTextFocusChangeListener);
editTextApp.setOnFocusChangeListener(editTextFocusChangeListener);
return v;
}
use of com.google.android.material.textfield.TextInputLayout in project AntennaPod by AntennaPod.
the class GpodderAuthenticationFragment method setupHostView.
private void setupHostView(View view) {
final Button selectHost = view.findViewById(R.id.chooseHostButton);
final RadioGroup serverRadioGroup = view.findViewById(R.id.serverRadioGroup);
final EditText serverUrlText = view.findViewById(R.id.serverUrlText);
if (!GpodnetService.DEFAULT_BASE_HOST.equals(SynchronizationCredentials.getHosturl())) {
serverUrlText.setText(SynchronizationCredentials.getHosturl());
}
final TextInputLayout serverUrlTextInput = view.findViewById(R.id.serverUrlTextInput);
serverRadioGroup.setOnCheckedChangeListener((group, checkedId) -> {
serverUrlTextInput.setVisibility(checkedId == R.id.customServerRadio ? View.VISIBLE : View.GONE);
});
selectHost.setOnClickListener(v -> {
SynchronizationCredentials.clear(getContext());
if (serverRadioGroup.getCheckedRadioButtonId() == R.id.customServerRadio) {
SynchronizationCredentials.setHosturl(serverUrlText.getText().toString());
} else {
SynchronizationCredentials.setHosturl(GpodnetService.DEFAULT_BASE_HOST);
}
service = new GpodnetService(AntennapodHttpClient.getHttpClient(), SynchronizationCredentials.getHosturl(), SynchronizationCredentials.getDeviceID(), SynchronizationCredentials.getUsername(), SynchronizationCredentials.getPassword());
getDialog().setTitle(SynchronizationCredentials.getHosturl());
advance();
});
}
use of com.google.android.material.textfield.TextInputLayout in project Signal-Android by WhisperSystems.
the class PaymentsRecoveryPhraseConfirmFragment method onViewCreated.
@Override
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
Toolbar toolbar = view.findViewById(R.id.payments_recovery_phrase_confirm_fragment_toolbar);
EditText word1 = view.findViewById(R.id.payments_recovery_phrase_confirm_fragment_word_1);
EditText word2 = view.findViewById(R.id.payments_recovery_phrase_confirm_fragment_word_2);
View seePhraseAgain = view.findViewById(R.id.payments_recovery_phrase_confirm_fragment_see_again);
View done = view.findViewById(R.id.payments_recovery_phrase_confirm_fragment_done);
TextInputLayout wordWrapper1 = view.findViewById(R.id.payments_recovery_phrase_confirm_fragment_word1_wrapper);
TextInputLayout wordWrapper2 = view.findViewById(R.id.payments_recovery_phrase_confirm_fragment_word2_wrapper);
PaymentsRecoveryPhraseConfirmFragmentArgs args = PaymentsRecoveryPhraseConfirmFragmentArgs.fromBundle(requireArguments());
validWordCheckMark = AppCompatResources.getDrawable(requireContext(), R.drawable.ic_check_circle_24);
invalidWordX = AppCompatResources.getDrawable(requireContext(), R.drawable.ic_circle_x_24);
DrawableCompat.setTint(validWordCheckMark, ContextCompat.getColor(requireContext(), R.color.signal_accent_green));
DrawableCompat.setTint(invalidWordX, ContextCompat.getColor(requireContext(), R.color.signal_alert_primary));
PaymentsRecoveryPhraseConfirmViewModel viewModel = ViewModelProviders.of(requireActivity()).get(PaymentsRecoveryPhraseConfirmViewModel.class);
toolbar.setNavigationOnClickListener(v -> Navigation.findNavController(requireView()).popBackStack());
word1.addTextChangedListener(new AfterTextChanged(e -> viewModel.validateWord1(e.toString())));
word2.addTextChangedListener(new AfterTextChanged(e -> viewModel.validateWord2(e.toString())));
seePhraseAgain.setOnClickListener(v -> Navigation.findNavController(requireView()).popBackStack());
done.setOnClickListener(v -> {
SignalStore.paymentsValues().setUserConfirmedMnemonic(true);
ViewUtil.hideKeyboard(requireContext(), view);
Toast.makeText(requireContext(), R.string.PaymentRecoveryPhraseConfirmFragment__recovery_phrase_confirmed, Toast.LENGTH_SHORT).show();
if (args.getFinishOnConfirm()) {
requireActivity().setResult(Activity.RESULT_OK);
requireActivity().finish();
} else {
Navigation.findNavController(view).popBackStack(R.id.paymentsHome, false);
}
});
viewModel.getViewState().observe(getViewLifecycleOwner(), viewState -> {
updateValidity(word1, viewState.isWord1Valid());
updateValidity(word2, viewState.isWord2Valid());
done.setEnabled(viewState.areAllWordsValid());
String hint1 = getString(R.string.PaymentRecoveryPhraseConfirmFragment__word_d, viewState.getWord1Index() + 1);
String hint2 = getString(R.string.PaymentRecoveryPhraseConfirmFragment__word_d, viewState.getWord2Index() + 1);
wordWrapper1.setHint(hint1);
wordWrapper2.setHint(hint2);
});
viewModel.updateRandomIndices();
}
Aggregations