Search in sources :

Example 1 with ThemeUtils

use of org.odk.collect.android.utilities.ThemeUtils 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 2 with ThemeUtils

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

the class FixedDatePickerDialog method onResume.

@Override
public void onResume() {
    super.onResume();
    // Needed because the DatePickerDialog doesn't pick up theme colors properly for some reason
    DatePickerDialog dialog = (DatePickerDialog) getDialog();
    dialog.getButton(DialogInterface.BUTTON_POSITIVE).setTextColor(new ThemeUtils(getContext()).getColorPrimary());
    dialog.getButton(DialogInterface.BUTTON_NEGATIVE).setTextColor(new ThemeUtils(getContext()).getColorPrimary());
}
Also used : DatePickerDialog(android.app.DatePickerDialog) ThemeUtils(org.odk.collect.android.utilities.ThemeUtils)

Example 3 with ThemeUtils

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

the class FixedDatePickerDialog method onAttach.

@Override
public void onAttach(@NonNull Context context) {
    super.onAttach(context);
    themeUtils = new ThemeUtils(context);
    if (context instanceof CustomDatePickerDialog.DateChangeListener) {
        dateChangeListener = (CustomDatePickerDialog.DateChangeListener) context;
    }
    viewModel = new ViewModelProvider(this).get(DateTimeViewModel.class);
    viewModel.setDialogTheme(getArguments().getInt(DateTimeWidgetUtils.DIALOG_THEME));
    viewModel.setLocalDateTime((LocalDateTime) getArguments().getSerializable(DateTimeWidgetUtils.DATE));
    viewModel.setDatePickerDetails((DatePickerDetails) getArguments().getSerializable(DateTimeWidgetUtils.DATE_PICKER_DETAILS));
    viewModel.getSelectedDate().observe(this, localDateTime -> {
        if (localDateTime != null) {
            dateChangeListener.onDateChanged(localDateTime);
        }
    });
}
Also used : ThemeUtils(org.odk.collect.android.utilities.ThemeUtils) DateTimeViewModel(org.odk.collect.android.widgets.viewmodels.DateTimeViewModel) ViewModelProvider(androidx.lifecycle.ViewModelProvider)

Example 4 with ThemeUtils

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

the class DateTimeWidgetUtils method showTimePickerDialog.

public void showTimePickerDialog(Context context, LocalDateTime dateTime) {
    ThemeUtils themeUtils = new ThemeUtils(context);
    Bundle bundle = new Bundle();
    bundle.putInt(DIALOG_THEME, themeUtils.getSpinnerTimePickerDialogTheme());
    bundle.putSerializable(TIME, dateTime);
    DialogFragmentUtils.showIfNotShowing(CustomTimePickerDialog.class, bundle, ((FragmentActivity) context).getSupportFragmentManager());
}
Also used : Bundle(android.os.Bundle) ThemeUtils(org.odk.collect.android.utilities.ThemeUtils)

Example 5 with ThemeUtils

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

the class DateTimeWidgetUtils method showDatePickerDialog.

public void showDatePickerDialog(Context context, DatePickerDetails datePickerDetails, LocalDateTime date) {
    ThemeUtils themeUtils = new ThemeUtils(context);
    Bundle bundle = new Bundle();
    bundle.putInt(DIALOG_THEME, getDatePickerTheme(themeUtils, datePickerDetails));
    bundle.putSerializable(DATE, date);
    bundle.putSerializable(DATE_PICKER_DETAILS, datePickerDetails);
    DialogFragmentUtils.showIfNotShowing(getClass(datePickerDetails.getDatePickerType()), bundle, ((FragmentActivity) context).getSupportFragmentManager());
}
Also used : Bundle(android.os.Bundle) ThemeUtils(org.odk.collect.android.utilities.ThemeUtils)

Aggregations

ThemeUtils (org.odk.collect.android.utilities.ThemeUtils)12 TextView (android.widget.TextView)3 Bundle (android.os.Bundle)2 View (android.view.View)2 ViewModelProvider (androidx.lifecycle.ViewModelProvider)2 ArgbEvaluator (android.animation.ArgbEvaluator)1 ValueAnimator (android.animation.ValueAnimator)1 SuppressLint (android.annotation.SuppressLint)1 DatePickerDialog (android.app.DatePickerDialog)1 TimePickerDialog (android.app.TimePickerDialog)1 Intent (android.content.Intent)1 Drawable (android.graphics.drawable.Drawable)1 Handler (android.os.Handler)1 OnClickListener (android.view.View.OnClickListener)1 Button (android.widget.Button)1 DividerItemDecoration (androidx.recyclerview.widget.DividerItemDecoration)1 CircleOptions (com.google.android.gms.maps.model.CircleOptions)1 MarkerOptions (com.google.android.gms.maps.model.MarkerOptions)1 CurrentProjectViewModel (org.odk.collect.android.activities.viewmodels.CurrentProjectViewModel)1 MainMenuViewModel (org.odk.collect.android.activities.viewmodels.MainMenuViewModel)1