Search in sources :

Example 6 with MaterialButton

use of com.google.android.material.button.MaterialButton in project Signal-Android by signalapp.

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;
        }
    });
}
Also used : AlertDialog(androidx.appcompat.app.AlertDialog) TransferStatus(org.signal.devicetransfer.TransferStatus) Bundle(android.os.Bundle) AlertDialog(androidx.appcompat.app.AlertDialog) NonNull(androidx.annotation.NonNull) Intent(android.content.Intent) ViewUtil(org.thoughtcrime.securesms.util.ViewUtil) LinkMovementMethod(android.text.method.LinkMovementMethod) R(org.thoughtcrime.securesms.R) Manifest(android.Manifest) OnBackPressedCallback(androidx.activity.OnBackPressedCallback) MaterialButton(com.google.android.material.button.MaterialButton) Locale(java.util.Locale) Toast(android.widget.Toast) EventBus(org.greenrobot.eventbus.EventBus) View(android.view.View) ViewModelProviders(androidx.lifecycle.ViewModelProviders) Settings(android.provider.Settings) ContextCompat(androidx.core.content.ContextCompat) WifiDirect(org.signal.devicetransfer.WifiDirect) NavHostFragment(androidx.navigation.fragment.NavHostFragment) DeviceToDeviceTransferService(org.signal.devicetransfer.DeviceToDeviceTransferService) Permissions(org.thoughtcrime.securesms.permissions.Permissions) SpanUtil(org.thoughtcrime.securesms.util.SpanUtil) CommunicationActions(org.thoughtcrime.securesms.util.CommunicationActions) ThreadMode(org.greenrobot.eventbus.ThreadMode) ThreadUtil(org.signal.core.util.ThreadUtil) TimeUnit(java.util.concurrent.TimeUnit) WifiManager(android.net.wifi.WifiManager) Log(org.signal.core.util.logging.Log) StringRes(androidx.annotation.StringRes) TextView(android.widget.TextView) Nullable(androidx.annotation.Nullable) Subscribe(org.greenrobot.eventbus.Subscribe) SubmitDebugLogActivity(org.thoughtcrime.securesms.logsubmit.SubmitDebugLogActivity) ActivityNotFoundException(android.content.ActivityNotFoundException) LoggingFragment(org.thoughtcrime.securesms.LoggingFragment) LocationManager(android.location.LocationManager) Group(androidx.constraintlayout.widget.Group) Group(androidx.constraintlayout.widget.Group) SubmitDebugLogActivity(org.thoughtcrime.securesms.logsubmit.SubmitDebugLogActivity) Intent(android.content.Intent) View(android.view.View) TextView(android.widget.TextView) MaterialButton(com.google.android.material.button.MaterialButton) TransferStatus(org.signal.devicetransfer.TransferStatus) TextView(android.widget.TextView)

Example 7 with MaterialButton

use of com.google.android.material.button.MaterialButton in project collect by opendatakit.

the class WidgetViewUtils method createSimpleButton.

public static Button createSimpleButton(Context context, @IdRes final int withId, boolean readOnly, String text, int answerFontSize, ButtonClickListener listener) {
    final MaterialButton button = (MaterialButton) LayoutInflater.from(context).inflate(R.layout.widget_answer_button, null, false);
    if (readOnly) {
        button.setVisibility(GONE);
    } else {
        button.setId(withId);
        button.setText(text);
        button.setTextSize(TypedValue.COMPLEX_UNIT_DIP, answerFontSize);
        TableLayout.LayoutParams params = new TableLayout.LayoutParams();
        params.setMargins(7, 5, 7, 5);
        button.setLayoutParams(params);
        button.setOnClickListener(v -> {
            if (MultiClickGuard.allowClick(QuestionWidget.class.getName())) {
                listener.onButtonClick(withId);
            }
        });
    }
    return button;
}
Also used : QuestionWidget(org.odk.collect.android.widgets.QuestionWidget) MaterialButton(com.google.android.material.button.MaterialButton) TableLayout(android.widget.TableLayout)

Example 8 with MaterialButton

use of com.google.android.material.button.MaterialButton in project android by nextcloud.

the class CommunityActivity method setupContent.

protected void setupContent() {
    binding.communityReleaseCandidateText.setMovementMethod(LinkMovementMethod.getInstance());
    TextView contributeForumView = binding.communityContributeForumText;
    contributeForumView.setMovementMethod(LinkMovementMethod.getInstance());
    contributeForumView.setText(Html.fromHtml(getString(R.string.community_contribute_forum_text) + " " + getString(R.string.community_contribute_forum_text_link, ThemeColorUtils.primaryColorToHexString(this), getString(R.string.help_link), getString(R.string.community_contribute_forum_forum))));
    TextView contributeTranslationView = binding.communityContributeTranslateText;
    contributeTranslationView.setMovementMethod(LinkMovementMethod.getInstance());
    contributeTranslationView.setText(Html.fromHtml(getString(R.string.community_contribute_translate_link, ThemeColorUtils.primaryColorToHexString(this), getString(R.string.translation_link), getString(R.string.community_contribute_translate_translate)) + " " + getString(R.string.community_contribute_translate_text)));
    TextView contributeGithubView = binding.communityContributeGithubText;
    contributeGithubView.setMovementMethod(LinkMovementMethod.getInstance());
    contributeGithubView.setText(Html.fromHtml(getString(R.string.community_contribute_github_text, getString(R.string.community_contribute_github_text_link, ThemeColorUtils.primaryColorToHexString(this), getString(R.string.contributing_link)))));
    MaterialButton reportButton = binding.communityTestingReport;
    ThemeButtonUtils.colorPrimaryButton(reportButton, this);
    reportButton.setOnClickListener(v -> DisplayUtils.startLinkIntent(this, R.string.report_issue_link));
    binding.communityBetaFdroid.setOnClickListener(l -> DisplayUtils.startLinkIntent(this, R.string.fdroid_beta_link));
    binding.communityReleaseCandidateFdroid.setOnClickListener(l -> DisplayUtils.startLinkIntent(this, R.string.fdroid_link));
    binding.communityReleaseCandidatePlaystore.setOnClickListener(l -> DisplayUtils.startLinkIntent(this, R.string.play_store_register_beta));
    binding.communityBetaApk.setOnClickListener(l -> DisplayUtils.startLinkIntent(this, R.string.beta_apk_link));
}
Also used : TextView(android.widget.TextView) MaterialButton(com.google.android.material.button.MaterialButton)

Example 9 with MaterialButton

use of com.google.android.material.button.MaterialButton in project android by nextcloud.

the class DrawerActivity method avatarGenerated.

@Override
public void avatarGenerated(Drawable avatarDrawable, Object callContext) {
    if (callContext instanceof MenuItem) {
        MenuItem menuItem = (MenuItem) callContext;
        menuItem.setIcon(avatarDrawable);
    } else if (callContext instanceof ImageView) {
        ImageView imageView = (ImageView) callContext;
        imageView.setImageDrawable(avatarDrawable);
    } else if (callContext instanceof MaterialButton) {
        MaterialButton materialButton = (MaterialButton) callContext;
        materialButton.setIcon(avatarDrawable);
    }
}
Also used : MenuItem(android.view.MenuItem) ImageView(android.widget.ImageView) MaterialButton(com.google.android.material.button.MaterialButton)

Example 10 with MaterialButton

use of com.google.android.material.button.MaterialButton in project android by nextcloud.

the class UploadFilesActivity method onCreate.

@Override
// wrong error on finding local_files_list
@SuppressLint("WrongViewCast")
public void onCreate(Bundle savedInstanceState) {
    Log_OC.d(TAG, "onCreate() start");
    super.onCreate(savedInstanceState);
    Bundle extras = getIntent().getExtras();
    if (extras != null) {
        mLocalFolderPickerMode = extras.getBoolean(KEY_LOCAL_FOLDER_PICKER_MODE, false);
        requestCode = (int) extras.get(REQUEST_CODE_KEY);
    }
    if (savedInstanceState != null) {
        mCurrentDir = new File(savedInstanceState.getString(UploadFilesActivity.KEY_DIRECTORY_PATH, Environment.getExternalStorageDirectory().getAbsolutePath()));
        mSelectAll = savedInstanceState.getBoolean(UploadFilesActivity.KEY_ALL_SELECTED, false);
    } else {
        String lastUploadFrom = preferences.getUploadFromLocalLastPath();
        if (!lastUploadFrom.isEmpty()) {
            mCurrentDir = new File(lastUploadFrom);
            while (!mCurrentDir.exists()) {
                mCurrentDir = mCurrentDir.getParentFile();
            }
        } else {
            mCurrentDir = Environment.getExternalStorageDirectory();
        }
    }
    mAccountOnCreation = getAccount();
    // / USER INTERFACE
    // Drop-down navigation
    mDirectories = new ArrayAdapter<>(this, android.R.layout.simple_spinner_item);
    mDirectories.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    fillDirectoryDropdown();
    // Inflate and set the layout view
    setContentView(R.layout.upload_files_layout);
    if (mLocalFolderPickerMode) {
        findViewById(R.id.upload_options).setVisibility(View.GONE);
        ((MaterialButton) findViewById(R.id.upload_files_btn_upload)).setText(R.string.uploader_btn_alternative_text);
    }
    mFileListFragment = (LocalFileListFragment) getSupportFragmentManager().findFragmentByTag("local_files_list");
    // Set input controllers
    MaterialButton cancelButton = findViewById(R.id.upload_files_btn_cancel);
    cancelButton.setTextColor(ThemeColorUtils.primaryColor(this, true));
    cancelButton.setOnClickListener(this);
    uploadButton = findViewById(R.id.upload_files_btn_upload);
    ThemeButtonUtils.colorPrimaryButton(uploadButton, this);
    uploadButton.setOnClickListener(this);
    uploadButton.setEnabled(false);
    int localBehaviour = preferences.getUploaderBehaviour();
    // file upload spinner
    mBehaviourSpinner = findViewById(R.id.upload_files_spinner_behaviour);
    List<String> behaviours = new ArrayList<>();
    behaviours.add(getString(R.string.uploader_upload_files_behaviour_move_to_nextcloud_folder, ThemeUtils.getDefaultDisplayNameForRootFolder(this)));
    behaviours.add(getString(R.string.uploader_upload_files_behaviour_only_upload));
    behaviours.add(getString(R.string.uploader_upload_files_behaviour_upload_and_delete_from_source));
    ArrayAdapter<String> behaviourAdapter = new ArrayAdapter<>(this, android.R.layout.simple_spinner_item, behaviours);
    behaviourAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    mBehaviourSpinner.setAdapter(behaviourAdapter);
    mBehaviourSpinner.setSelection(localBehaviour);
    // setup the toolbar
    setupToolbar();
    findViewById(R.id.sort_list_button_group).setVisibility(View.VISIBLE);
    findViewById(R.id.switch_grid_view_button).setVisibility(View.GONE);
    // Action bar setup
    ActionBar actionBar = getSupportActionBar();
    if (actionBar != null) {
        // mandatory since Android ICS, according to the official documentation
        actionBar.setHomeButtonEnabled(true);
        actionBar.setDisplayHomeAsUpEnabled(mCurrentDir != null);
        actionBar.setDisplayShowTitleEnabled(false);
        ThemeToolbarUtils.tintBackButton(actionBar, this);
    }
    showToolbarSpinner();
    mToolbarSpinner.setAdapter(mDirectories);
    mToolbarSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {

        @Override
        public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
            int i = position;
            while (i-- != 0) {
                onBackPressed();
            }
            // user selected it in the navigation list
            if (position != 0) {
                mToolbarSpinner.setSelection(0);
            }
        }

        @Override
        public void onNothingSelected(AdapterView<?> parent) {
        // no action
        }
    });
    // wait dialog
    if (mCurrentDialog != null) {
        mCurrentDialog.dismiss();
        mCurrentDialog = null;
    }
    checkWritableFolder(mCurrentDir);
    Log_OC.d(TAG, "onCreate() end");
}
Also used : Bundle(android.os.Bundle) ArrayList(java.util.ArrayList) MaterialButton(com.google.android.material.button.MaterialButton) View(android.view.View) AdapterView(android.widget.AdapterView) SearchView(androidx.appcompat.widget.SearchView) TextView(android.widget.TextView) SuppressLint(android.annotation.SuppressLint) AdapterView(android.widget.AdapterView) File(java.io.File) ArrayAdapter(android.widget.ArrayAdapter) ActionBar(androidx.appcompat.app.ActionBar) SuppressLint(android.annotation.SuppressLint)

Aggregations

MaterialButton (com.google.android.material.button.MaterialButton)12 TextView (android.widget.TextView)7 Intent (android.content.Intent)5 View (android.view.View)5 ActivityNotFoundException (android.content.ActivityNotFoundException)3 Bundle (android.os.Bundle)3 Manifest (android.Manifest)2 LocationManager (android.location.LocationManager)2 WifiManager (android.net.wifi.WifiManager)2 Settings (android.provider.Settings)2 LinkMovementMethod (android.text.method.LinkMovementMethod)2 Button (android.widget.Button)2 ListView (android.widget.ListView)2 Toast (android.widget.Toast)2 OnBackPressedCallback (androidx.activity.OnBackPressedCallback)2 NonNull (androidx.annotation.NonNull)2 Nullable (androidx.annotation.Nullable)2 StringRes (androidx.annotation.StringRes)2 AlertDialog (androidx.appcompat.app.AlertDialog)2 Group (androidx.constraintlayout.widget.Group)2