use of com.google.android.material.button.MaterialButton in project AntennaPod by AntennaPod.
the class GpodderAuthenticationFragment method setupDeviceView.
private void setupDeviceView(View view) {
final EditText deviceName = view.findViewById(R.id.deviceName);
final LinearLayout devicesContainer = view.findViewById(R.id.devicesContainer);
deviceName.setText(generateDeviceName());
MaterialButton createDeviceButton = view.findViewById(R.id.createDeviceButton);
createDeviceButton.setOnClickListener(v -> createDevice(view));
for (GpodnetDevice device : devices) {
View row = View.inflate(getContext(), R.layout.gpodnetauth_device_row, null);
Button selectDeviceButton = row.findViewById(R.id.selectDeviceButton);
selectDeviceButton.setOnClickListener(v -> {
selectedDevice = device;
advance();
});
selectDeviceButton.setText(device.getCaption());
devicesContainer.addView(row);
}
}
use of com.google.android.material.button.MaterialButton in project Signal-Android by WhisperSystems.
the class DeviceTransferSetupFragment method onViewCreated.
@Override
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
Group progressGroup = view.findViewById(R.id.device_transfer_setup_fragment_progress_group);
Group errorGroup = view.findViewById(R.id.device_transfer_setup_fragment_error_group);
View verifyGroup = view.findViewById(R.id.device_transfer_setup_fragment_verify);
View waitingGroup = view.findViewById(R.id.device_transfer_setup_fragment_waiting);
View troubleshooting = view.findViewById(R.id.device_transfer_setup_fragment_troubleshooting);
TextView status = view.findViewById(R.id.device_transfer_setup_fragment_status);
TextView error = view.findViewById(R.id.device_transfer_setup_fragment_error);
MaterialButton errorResolve = view.findViewById(R.id.device_transfer_setup_fragment_error_resolve);
TextView sasNumber = view.findViewById(R.id.device_transfer_setup_fragment_sas_verify_code);
MaterialButton verifyNo = view.findViewById(R.id.device_transfer_setup_fragment_sas_verify_no);
MaterialButton verifyYes = view.findViewById(R.id.device_transfer_setup_fragment_sas_verify_yes);
viewModel = ViewModelProviders.of(this).get(DeviceTransferSetupViewModel.class);
viewModel.getState().observe(getViewLifecycleOwner(), state -> {
SetupStep step = state.getCurrentSetupStep();
progressGroup.setVisibility(step.isProgress() ? View.VISIBLE : View.GONE);
errorGroup.setVisibility(step.isError() ? View.VISIBLE : View.GONE);
verifyGroup.setVisibility(step == SetupStep.VERIFY ? View.VISIBLE : View.GONE);
waitingGroup.setVisibility(step == SetupStep.WAITING_FOR_OTHER_TO_VERIFY ? View.VISIBLE : View.GONE);
troubleshooting.setVisibility(step == SetupStep.TROUBLESHOOTING ? View.VISIBLE : View.GONE);
Log.i(TAG, "Handling step: " + step.name());
switch(step) {
case INITIAL:
status.setText("");
case PERMISSIONS_CHECK:
requestLocationPermission();
break;
case PERMISSIONS_DENIED:
error.setText(getErrorTextForStep(step));
errorResolve.setText(R.string.DeviceTransferSetup__grant_location_permission);
errorResolve.setOnClickListener(v -> viewModel.checkPermissions());
break;
case LOCATION_CHECK:
verifyLocationEnabled();
break;
case LOCATION_DISABLED:
error.setText(getErrorTextForStep(step));
errorResolve.setText(R.string.DeviceTransferSetup__turn_on_location_services);
errorResolve.setOnClickListener(v -> openLocationServices());
break;
case WIFI_CHECK:
verifyWifiEnabled();
break;
case WIFI_DISABLED:
error.setText(getErrorTextForStep(step));
errorResolve.setText(R.string.DeviceTransferSetup__turn_on_wifi);
errorResolve.setOnClickListener(v -> openWifiSettings());
break;
case WIFI_DIRECT_CHECK:
verifyWifiDirectAvailable();
break;
case WIFI_DIRECT_UNAVAILABLE:
error.setText(getErrorTextForStep(step));
errorResolve.setText(getErrorResolveButtonTextForStep(step));
errorResolve.setOnClickListener(v -> navigateWhenWifiDirectUnavailable());
break;
case START:
status.setText(getStatusTextForStep(SetupStep.SETTING_UP, false));
startTransfer();
break;
case SETTING_UP:
status.setText(getStatusTextForStep(step, false));
startTakingTooLong(() -> status.setText(getStatusTextForStep(step, true)), PREPARE_TAKING_TOO_LONG_TIME);
break;
case WAITING:
status.setText(getStatusTextForStep(step, false));
cancelTakingTooLong();
startTakingTooLong(() -> {
DeviceToDeviceTransferService.stop(requireContext());
viewModel.onWaitingTookTooLong();
}, WAITING_TAKING_TOO_LONG_TIME);
break;
case VERIFY:
cancelTakingTooLong();
sasNumber.setText(String.format(Locale.US, "%07d", state.getAuthenticationCode()));
// noinspection CodeBlock2Expr
verifyNo.setOnClickListener(v -> {
new AlertDialog.Builder(requireContext()).setTitle(R.string.DeviceTransferSetup__the_numbers_do_not_match).setMessage(R.string.DeviceTransferSetup__if_the_numbers_on_your_devices_do_not_match_its_possible_you_connected_to_the_wrong_device).setPositiveButton(R.string.DeviceTransferSetup__stop_transfer, (d, w) -> {
EventBus.getDefault().unregister(this);
DeviceToDeviceTransferService.setAuthenticationCodeVerified(requireContext(), false);
DeviceToDeviceTransferService.stop(requireContext());
EventBus.getDefault().removeStickyEvent(TransferStatus.class);
navigateAwayFromTransfer();
}).setNegativeButton(android.R.string.cancel, null).show();
});
verifyYes.setOnClickListener(v -> {
DeviceToDeviceTransferService.setAuthenticationCodeVerified(requireContext(), true);
viewModel.onVerified();
});
break;
case WAITING_FOR_OTHER_TO_VERIFY:
break;
case CONNECTED:
Log.d(TAG, "Connected! isNotShutdown: " + viewModel.isNotShutdown());
if (viewModel.isNotShutdown()) {
navigateToTransferConnected();
}
break;
case TROUBLESHOOTING:
TextView title = troubleshooting.findViewById(R.id.device_transfer_setup_fragment_troubleshooting_title);
title.setText(getStatusTextForStep(step, false));
int gapWidth = ViewUtil.dpToPx(12);
TextView step1 = troubleshooting.findViewById(R.id.device_transfer_setup_fragment_troubleshooting_step1);
step1.setText(SpanUtil.bullet(getString(R.string.DeviceTransferSetup__make_sure_the_following_permissions_are_enabled), gapWidth));
TextView step2 = troubleshooting.findViewById(R.id.device_transfer_setup_fragment_troubleshooting_step2);
step2.setMovementMethod(LinkMovementMethod.getInstance());
step2.setText(SpanUtil.clickSubstring(requireContext(), SpanUtil.bullet(getString(R.string.DeviceTransferSetup__on_the_wifi_direct_screen_remove_all_remembered_groups_and_unlink_any_invited_or_connected_devices), gapWidth), getString(R.string.DeviceTransferSetup__wifi_direct_screen), v -> openWifiDirectSettings()));
TextView step3 = troubleshooting.findViewById(R.id.device_transfer_setup_fragment_troubleshooting_step3);
step3.setText(SpanUtil.bullet(getString(R.string.DeviceTransferSetup__try_turning_wifi_off_and_on_on_both_devices), gapWidth));
TextView step4 = troubleshooting.findViewById(R.id.device_transfer_setup_fragment_troubleshooting_step4);
step4.setText(SpanUtil.bullet(getString(R.string.DeviceTransferSetup__make_sure_both_devices_are_in_transfer_mode), gapWidth));
troubleshooting.findViewById(R.id.device_transfer_setup_fragment_troubleshooting_location_permission).setOnClickListener(v -> openApplicationSystemSettings());
troubleshooting.findViewById(R.id.device_transfer_setup_fragment_troubleshooting_location_services).setOnClickListener(v -> openLocationServices());
troubleshooting.findViewById(R.id.device_transfer_setup_fragment_troubleshooting_wifi).setOnClickListener(v -> openWifiSettings());
troubleshooting.findViewById(R.id.device_transfer_setup_fragment_troubleshooting_go_to_support).setOnClickListener(v -> gotoSupport());
troubleshooting.findViewById(R.id.device_transfer_setup_fragment_troubleshooting_try_again).setOnClickListener(v -> viewModel.checkPermissions());
break;
case ERROR:
error.setText(getErrorTextForStep(step));
errorResolve.setText(R.string.DeviceTransferSetup__retry);
errorResolve.setOnClickListener(v -> viewModel.checkPermissions());
DeviceToDeviceTransferService.stop(requireContext());
cancelTakingTooLong();
new AlertDialog.Builder(requireContext()).setTitle(R.string.DeviceTransferSetup__error_connecting).setMessage(getStatusTextForStep(step, false)).setPositiveButton(R.string.DeviceTransferSetup__retry, (d, w) -> viewModel.checkPermissions()).setNegativeButton(android.R.string.cancel, (d, w) -> {
EventBus.getDefault().unregister(this);
EventBus.getDefault().removeStickyEvent(TransferStatus.class);
navigateAwayFromTransfer();
}).setNeutralButton(R.string.DeviceTransferSetup__submit_debug_logs, (d, w) -> {
EventBus.getDefault().unregister(this);
EventBus.getDefault().removeStickyEvent(TransferStatus.class);
navigateAwayFromTransfer();
startActivity(new Intent(requireContext(), SubmitDebugLogActivity.class));
}).setCancelable(false).show();
break;
}
});
}
use of com.google.android.material.button.MaterialButton in project collect by opendatakit.
the class ODKView method addIntentLaunchButton.
/**
* Adds a button to launch an intent if the group displayed by this view is an intent group.
* An intent group launches an intent and receives multiple values from the launched app.
*/
private void addIntentLaunchButton(Context context, FormEntryPrompt[] questionPrompts, FormEntryCaption c, String intentString) {
final String buttonText;
final String errorString;
String v = c.getSpecialFormQuestionText("buttonText");
buttonText = (v != null) ? v : context.getString(R.string.launch_app);
v = c.getSpecialFormQuestionText("noAppErrorString");
errorString = (v != null) ? v : context.getString(R.string.no_app);
// set button formatting
MaterialButton launchIntentButton = findViewById(R.id.launchIntentButton);
launchIntentButton.setText(buttonText);
launchIntentButton.setTextSize(TypedValue.COMPLEX_UNIT_DIP, QuestionFontSizeUtils.getQuestionFontSize() + 2);
launchIntentButton.setVisibility(VISIBLE);
launchIntentButton.setOnClickListener(view -> {
String intentName = ExternalAppsUtils.extractIntentName(intentString);
Map<String, String> parameters = ExternalAppsUtils.extractParameters(intentString);
Intent i = new Intent(intentName);
if (i.resolveActivity(Collect.getInstance().getPackageManager()) == null) {
Intent launchIntent = Collect.getInstance().getPackageManager().getLaunchIntentForPackage(intentName);
if (launchIntent != null) {
// Make sure FLAG_ACTIVITY_NEW_TASK is not set because it doesn't work with startActivityForResult
launchIntent.setFlags(0);
i = launchIntent;
}
}
try {
ExternalAppsUtils.populateParameters(i, parameters, c.getIndex().getReference());
for (FormEntryPrompt p : questionPrompts) {
IFormElement formElement = p.getFormElement();
if (formElement instanceof QuestionDef) {
TreeReference reference = (TreeReference) formElement.getBind().getReference();
IAnswerData answerValue = p.getAnswerValue();
Object value = answerValue == null ? null : answerValue.getValue();
switch(p.getDataType()) {
case Constants.DATATYPE_TEXT:
case Constants.DATATYPE_INTEGER:
case Constants.DATATYPE_DECIMAL:
case Constants.DATATYPE_BINARY:
i.putExtra(reference.getNameLast(), (Serializable) value);
break;
}
}
}
((Activity) getContext()).startActivityForResult(i, RequestCodes.EX_GROUP_CAPTURE);
} catch (ExternalParamsException e) {
Timber.e(e, "ExternalParamsException");
ToastUtils.showShortToast(getContext(), e.getMessage());
} catch (ActivityNotFoundException e) {
Timber.d(e, "ActivityNotFoundExcept");
ToastUtils.showShortToast(getContext(), errorString);
}
});
}
use of com.google.android.material.button.MaterialButton in project android by nextcloud.
the class ReceiveExternalFilesActivity method populateDirectoryList.
private void populateDirectoryList() {
setContentView(R.layout.receive_external_files);
setupEmptyList();
setupToolbar();
ActionBar actionBar = getSupportActionBar();
setupActionBarSubtitle();
ListView mListView = findViewById(android.R.id.list);
findViewById(R.id.sort_list_button_group).setVisibility(View.VISIBLE);
findViewById(R.id.switch_grid_view_button).setVisibility(View.GONE);
String current_dir = mParents.peek();
boolean notRoot = mParents.size() > 1;
if (actionBar != null) {
if (TextUtils.isEmpty(current_dir)) {
ThemeToolbarUtils.setColoredTitle(actionBar, R.string.uploader_top_message, this);
} else {
ThemeToolbarUtils.setColoredTitle(actionBar, current_dir, this);
}
actionBar.setDisplayHomeAsUpEnabled(notRoot);
actionBar.setHomeButtonEnabled(notRoot);
}
String full_path = generatePath(mParents);
Log_OC.d(TAG, "Populating view with content of : " + full_path);
mFile = getStorageManager().getFileByPath(full_path);
if (mFile != null) {
List<OCFile> files = getStorageManager().getFolderContent(mFile, false);
if (files.isEmpty()) {
setMessageForEmptyList(R.string.file_list_empty_headline, R.string.empty, R.drawable.uploads);
} else {
mEmptyListContainer.setVisibility(View.GONE);
files = sortFileList(files);
List<Map<String, Object>> data = new LinkedList<>();
for (OCFile f : files) {
Map<String, Object> h = new HashMap<>();
h.put("dirname", f);
data.add(h);
}
UploaderAdapter sa = new UploaderAdapter(this, data, R.layout.uploader_list_item_layout, new String[] { "dirname" }, new int[] { R.id.filename }, getStorageManager(), getUser().get());
mListView.setAdapter(sa);
}
MaterialButton btnChooseFolder = findViewById(R.id.uploader_choose_folder);
ThemeButtonUtils.colorPrimaryButton(btnChooseFolder, this);
btnChooseFolder.setOnClickListener(this);
if (mFile.canWrite()) {
btnChooseFolder.setEnabled(true);
ThemeButtonUtils.colorPrimaryButton(btnChooseFolder, this);
} else {
btnChooseFolder.setEnabled(false);
btnChooseFolder.setBackgroundColor(Color.GRAY);
}
ThemeToolbarUtils.colorStatusBar(this);
ThemeToolbarUtils.tintBackButton(actionBar, this);
Button btnNewFolder = findViewById(R.id.uploader_cancel);
btnNewFolder.setTextColor(ThemeColorUtils.primaryColor(this, true));
btnNewFolder.setOnClickListener(this);
mListView.setOnItemClickListener(this);
sortButton = findViewById(R.id.sort_button);
FileSortOrder sortOrder = preferences.getSortOrderByFolder(mFile);
sortButton.setText(DisplayUtils.getSortOrderStringId(sortOrder));
sortButton.setOnClickListener(l -> openSortingOrderDialogFragment(getSupportFragmentManager(), sortOrder));
}
}
use of com.google.android.material.button.MaterialButton in project fdroidclient by f-droid.
the class StartSwapView method uiInitButtons.
private void uiInitButtons() {
MaterialButton sendFDroidButton = findViewById(R.id.btn_send_fdroid);
sendFDroidButton.setEllipsize(TextUtils.TruncateAt.END);
findViewById(R.id.btn_send_fdroid).setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
getActivity().sendFDroid();
}
});
}
Aggregations