Search in sources :

Example 1 with PlayServicesChecker

use of org.odk.collect.android.utilities.PlayServicesChecker in project collect by opendatakit.

the class ServerPreferencesFragment method initAccountPreferences.

public void initAccountPreferences() {
    selectedGoogleAccountPreference.setSummary(accountsManager.getLastSelectedAccountIfValid());
    selectedGoogleAccountPreference.setOnPreferenceClickListener(preference -> {
        if (allowClickSelectedGoogleAccountPreference) {
            if (new PlayServicesChecker().isGooglePlayServicesAvailable(getActivity())) {
                allowClickSelectedGoogleAccountPreference = false;
                requestAccountsPermission();
            } else {
                new PlayServicesChecker().showGooglePlayServicesAvailabilityErrorDialog(getActivity());
            }
        }
        return true;
    });
}
Also used : PlayServicesChecker(org.odk.collect.android.utilities.PlayServicesChecker)

Example 2 with PlayServicesChecker

use of org.odk.collect.android.utilities.PlayServicesChecker in project collect by opendatakit.

the class MainMenuActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    new ThemeUtils(this).setDarkModeForCurrentProject();
    super.onCreate(savedInstanceState);
    DaggerUtils.getComponent(this).inject(this);
    setContentView(R.layout.main_menu);
    settingsProvider.getMetaSettings().save(MetaKeys.FIRST_LAUNCH, false);
    mainMenuViewModel = new ViewModelProvider(this, viewModelFactory).get(MainMenuViewModel.class);
    currentProjectViewModel = new ViewModelProvider(this, currentProjectViewModelFactory).get(CurrentProjectViewModel.class);
    currentProjectViewModel.getCurrentProject().observe(this, project -> {
        invalidateOptionsMenu();
        setTitle(project.getName());
    });
    initToolbar();
    // enter data button. expects a result.
    Button enterDataButton = findViewById(R.id.enter_data);
    enterDataButton.setText(getString(R.string.enter_data_button));
    enterDataButton.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            Intent i = new Intent(getApplicationContext(), FillBlankFormActivity.class);
            startActivity(i);
        }
    });
    // review data button. expects a result.
    reviewDataButton = findViewById(R.id.review_data);
    reviewDataButton.setText(getString(R.string.review_data_button));
    reviewDataButton.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            Intent i = new Intent(getApplicationContext(), InstanceChooserList.class);
            i.putExtra(ApplicationConstants.BundleKeys.FORM_MODE, ApplicationConstants.FormModes.EDIT_SAVED);
            startActivity(i);
        }
    });
    // send data button. expects a result.
    sendDataButton = findViewById(R.id.send_data);
    sendDataButton.setText(getString(R.string.send_data_button));
    sendDataButton.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            Intent i = new Intent(getApplicationContext(), InstanceUploaderListActivity.class);
            startActivity(i);
        }
    });
    // View sent forms
    viewSentFormsButton = findViewById(R.id.view_sent_forms);
    viewSentFormsButton.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            Intent i = new Intent(getApplicationContext(), InstanceChooserList.class);
            i.putExtra(ApplicationConstants.BundleKeys.FORM_MODE, ApplicationConstants.FormModes.VIEW_SENT);
            startActivity(i);
        }
    });
    // manage forms button. no result expected.
    getFormsButton = findViewById(R.id.get_forms);
    getFormsButton.setText(getString(R.string.get_forms));
    getFormsButton.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            String protocol = settingsProvider.getUnprotectedSettings().getString(ProjectKeys.KEY_PROTOCOL);
            Intent i;
            if (protocol.equalsIgnoreCase(ProjectKeys.PROTOCOL_GOOGLE_SHEETS)) {
                if (new PlayServicesChecker().isGooglePlayServicesAvailable(MainMenuActivity.this)) {
                    i = new Intent(getApplicationContext(), GoogleDriveActivity.class);
                } else {
                    new PlayServicesChecker().showGooglePlayServicesAvailabilityErrorDialog(MainMenuActivity.this);
                    return;
                }
            } else {
                i = new Intent(getApplicationContext(), FormDownloadListActivity.class);
            }
            startActivity(i);
        }
    });
    // manage forms button. no result expected.
    manageFilesButton = findViewById(R.id.manage_forms);
    manageFilesButton.setText(getString(R.string.manage_files));
    manageFilesButton.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            Intent i = new Intent(getApplicationContext(), DeleteSavedFormActivity.class);
            startActivity(i);
        }
    });
    TextView appName = findViewById(R.id.app_name);
    appName.setText(String.format("%s %s", getString(R.string.collect_app_name), mainMenuViewModel.getVersion()));
    TextView versionSHAView = findViewById(R.id.version_sha);
    String versionSHA = mainMenuViewModel.getVersionCommitDescription();
    if (versionSHA != null) {
        versionSHAView.setText(versionSHA);
    } else {
        versionSHAView.setVisibility(View.GONE);
    }
    mainMenuViewModel.getSendableInstancesCount().observe(this, finalized -> {
        if (finalized > 0) {
            sendDataButton.setText(getString(R.string.send_data_button, String.valueOf(finalized)));
        } else {
            sendDataButton.setText(getString(R.string.send_data));
        }
    });
    mainMenuViewModel.getEditableInstancesCount().observe(this, unsent -> {
        if (unsent > 0) {
            reviewDataButton.setText(getString(R.string.review_data_button, String.valueOf(unsent)));
        } else {
            reviewDataButton.setText(getString(R.string.review_data));
        }
    });
    mainMenuViewModel.getSentInstancesCount().observe(this, sent -> {
        if (sent > 0) {
            viewSentFormsButton.setText(getString(R.string.view_sent_forms_button, String.valueOf(sent)));
        } else {
            viewSentFormsButton.setText(getString(R.string.view_sent_forms));
        }
    });
}
Also used : MainMenuViewModel(org.odk.collect.android.activities.viewmodels.MainMenuViewModel) ThemeUtils(org.odk.collect.android.utilities.ThemeUtils) PlayServicesChecker(org.odk.collect.android.utilities.PlayServicesChecker) Intent(android.content.Intent) View(android.view.View) ProjectIconView(org.odk.collect.android.projects.ProjectIconView) TextView(android.widget.TextView) Button(android.widget.Button) CurrentProjectViewModel(org.odk.collect.android.activities.viewmodels.CurrentProjectViewModel) OnClickListener(android.view.View.OnClickListener) TextView(android.widget.TextView) ViewModelProvider(androidx.lifecycle.ViewModelProvider)

Example 3 with PlayServicesChecker

use of org.odk.collect.android.utilities.PlayServicesChecker in project collect by opendatakit.

the class InstanceUploaderListActivity method uploadSelectedFiles.

private void uploadSelectedFiles() {
    long[] instanceIds = listView.getCheckedItemIds();
    String server = settingsProvider.getUnprotectedSettings().getString(KEY_PROTOCOL);
    if (server.equalsIgnoreCase(ProjectKeys.PROTOCOL_GOOGLE_SHEETS)) {
        // first make sure we have a google account selected
        if (new PlayServicesChecker().isGooglePlayServicesAvailable(this)) {
            Intent i = new Intent(this, GoogleSheetsUploaderActivity.class);
            i.putExtra(FormEntryActivity.KEY_INSTANCES, instanceIds);
            startActivityForResult(i, INSTANCE_UPLOADER);
        } else {
            new PlayServicesChecker().showGooglePlayServicesAvailabilityErrorDialog(this);
        }
    } else {
        // otherwise, do the normal aggregate/other thing.
        Intent i = new Intent(this, InstanceUploaderActivity.class);
        i.putExtra(FormEntryActivity.KEY_INSTANCES, instanceIds);
        startActivityForResult(i, INSTANCE_UPLOADER);
    }
}
Also used : PlayServicesChecker(org.odk.collect.android.utilities.PlayServicesChecker) Intent(android.content.Intent)

Example 4 with PlayServicesChecker

use of org.odk.collect.android.utilities.PlayServicesChecker in project collect by opendatakit.

the class FormEntryActivity method startFormEntry.

private void startFormEntry(FormController formController, String warningMsg) {
    // log. onStart has already run but the formController was null so try again.
    if (formController.currentFormAuditsLocation() && new PlayServicesChecker().isGooglePlayServicesAvailable(this)) {
        registerReceiver(locationProvidersReceiver, new IntentFilter(LocationManager.PROVIDERS_CHANGED_ACTION));
    }
    // onResume ran before the form was loaded. Let the viewModel know that the activity
    // is about to be displayed and configured. Do this before the refresh actually
    // happens because if audit logging is enabled, the refresh logs a question event
    // and we want that to show up after initialization events.
    activityDisplayed();
    onScreenRefresh();
    if (warningMsg != null) {
        showLongToast(this, warningMsg);
        Timber.w(warningMsg);
    }
}
Also used : IntentFilter(android.content.IntentFilter) PlayServicesChecker(org.odk.collect.android.utilities.PlayServicesChecker)

Example 5 with PlayServicesChecker

use of org.odk.collect.android.utilities.PlayServicesChecker in project collect by opendatakit.

the class FormEntryActivity method onStart.

@Override
protected void onStart() {
    super.onStart();
    FormController formController = getFormController();
    // Register to receive location provider change updates and write them to the audit log
    if (formController != null && formController.currentFormAuditsLocation() && new PlayServicesChecker().isGooglePlayServicesAvailable(this)) {
        registerReceiver(locationProvidersReceiver, new IntentFilter(LocationManager.PROVIDERS_CHANGED_ACTION));
    }
    // User may have changed location permissions in Android settings
    if (permissionsProvider.areLocationPermissionsGranted() != locationPermissionsPreviouslyGranted) {
        backgroundLocationViewModel.locationPermissionChanged();
        locationPermissionsPreviouslyGranted = !locationPermissionsPreviouslyGranted;
    }
}
Also used : FormController(org.odk.collect.android.javarosawrapper.FormController) IntentFilter(android.content.IntentFilter) PlayServicesChecker(org.odk.collect.android.utilities.PlayServicesChecker)

Aggregations

PlayServicesChecker (org.odk.collect.android.utilities.PlayServicesChecker)6 Intent (android.content.Intent)2 IntentFilter (android.content.IntentFilter)2 MenuItem (android.view.MenuItem)1 View (android.view.View)1 OnClickListener (android.view.View.OnClickListener)1 Button (android.widget.Button)1 TextView (android.widget.TextView)1 ViewModelProvider (androidx.lifecycle.ViewModelProvider)1 CurrentProjectViewModel (org.odk.collect.android.activities.viewmodels.CurrentProjectViewModel)1 MainMenuViewModel (org.odk.collect.android.activities.viewmodels.MainMenuViewModel)1 FormController (org.odk.collect.android.javarosawrapper.FormController)1 ProjectIconView (org.odk.collect.android.projects.ProjectIconView)1 ThemeUtils (org.odk.collect.android.utilities.ThemeUtils)1