Beispiel #1
0
  // Helper function to start a new day
  private void startNewDay() {
    // Add the pilot so we can autocomplete it later
    contactlistmanager.saveContact(towPilotNameIn.getText().toString().trim());

    // Add tow info to the bundle
    String action = "new";
    Intent intent = new Intent(MainActivity.this, DayOverviewActivity.class);
    Bundle bundle = bundleDayInfo();
    bundle.putSerializable("action", action);

    // Start next activity, DayOverview
    intent.putExtras(bundle);
    startActivity(intent);
  }
Beispiel #2
0
  // Refresh the view when going back
  protected void onResume() {
    super.onResume();
    Log.e("MAIN", "onResume() called");

    today = Calendar.getInstance();

    // Day log loader, check if we already have a log for the current date
    dayLogFileNameSuffix =
        String.valueOf(datepicker.getYear())
            + "_"
            + String.valueOf(datepicker.getMonth() + 1)
            + "_"
            + String.valueOf(datepicker.getDayOfMonth());
    if (loadDayLog()) {
      found_daylog = true;
      resumeDayButton.setVisibility(View.VISIBLE);

      // Jump straight to daylog if we are currently on the shown date from a clean startup
      int day = datepicker.getDayOfMonth();
      int month = datepicker.getMonth();
      int year = datepicker.getYear();
      Calendar date_picked = Calendar.getInstance();
      date_picked.set(year, month, day);

      if (autoLoadLog
          && date_picked.get(Calendar.YEAR) == today.get(Calendar.YEAR)
          && date_picked.get(Calendar.DAY_OF_YEAR) == today.get(Calendar.DAY_OF_YEAR)) {
        resumeDayButton.callOnClick();
      }
    } else {
      found_daylog = false;
      resumeDayButton.setVisibility(View.INVISIBLE);
    }

    // Subsequent resumes will autoload logs again
    autoLoadLog = true;

    // Reload the contact list
    contactlistmanager = new ContactListManager(this);
    towPilotNameIn.setAdapter(contactlistmanager.getContactNameListAdapter());

    // Set the daylog dialog
    daylogdialog = getPrevLogsAlertDialog();

    // To avoid focus going to the text fields
    datepicker.requestFocus();
  }
Beispiel #3
0
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    toolbar = (Toolbar) findViewById(R.id.toolbarmain);
    toolbar.setTitle("Prepare Towing");
    setSupportActionBar(toolbar);

    settings = PreferenceManager.getDefaultSharedPreferences(this);

    // Set up the tow pilot name input, including autocomplete and hasAccount check
    contactlistmanager = new ContactListManager(this);

    towPilotCheckmark = (ImageView) findViewById(R.id.towPilotCheckmark);

    towPilotNameIn = (AutoCompleteTextView) findViewById(R.id.towPilotNameIn);
    towPilotNameIn.setAdapter(contactlistmanager.getContactNameListAdapter());
    towPilotNameIn.addTextChangedListener(
        new TextWatcher() {
          public void onTextChanged(CharSequence s, int start, int before, int count) {
            Contact selected = contactlistmanager.findContactFromName(String.valueOf(s));
            selectedTowPilot = selected;
            if (selected == null) {
              towPilotCheckmark.setBackgroundResource(0);
            } else {
              if (selected.hasAccount) {
                towPilotCheckmark.setBackgroundResource(R.mipmap.green_checkmark);
              } else {
                towPilotCheckmark.setBackgroundResource(R.mipmap.new_icon_blue);
              }
            }
          }

          public void beforeTextChanged(CharSequence s, int start, int count, int after) {}

          public void afterTextChanged(Editable s) {}
        });

    // Set up towplane input
    towPlaneIn = (EditText) findViewById(R.id.towPlaneIn);
    towPlaneIn.setText(
        settings.getString("lasttowplane", settings.getString("towplane_default_reg", "")));

    // Set up Datepicker
    datepicker = (DatePicker) findViewById(R.id.datePicker);
    today = Calendar.getInstance();
    datepicker.init(
        today.get(Calendar.YEAR),
        today.get(Calendar.MONTH),
        today.get(Calendar.DAY_OF_MONTH),
        new DatePicker.OnDateChangedListener() {
          @Override
          public void onDateChanged(DatePicker view, int year, int monthOfYear, int dayOfMonth) {
            Calendar c = Calendar.getInstance();
            c.set(year, monthOfYear, dayOfMonth);
            selecteddate = c.getTime();

            dayLogFileNameSuffix =
                String.valueOf(year)
                    + "_"
                    + String.valueOf(monthOfYear + 1)
                    + "_"
                    + String.valueOf(dayOfMonth);

            Log.e("DATEPICKER", dayLogFileNameSuffix);

            if (loadDayLog()) {
              found_daylog = true;
              resumeDayButton.setVisibility(View.VISIBLE);
            } else {
              found_daylog = false;
              resumeDayButton.setVisibility(View.INVISIBLE);
            }
          }
        });

    Log.e("DATEPICKER", "Inited object, " + datepicker);

    // Start new day button
    startDayButton = (Button) findViewById(R.id.startDayButton);
    ColoringUtil.colorMe(startDayButton, getResources().getColor(R.color.colorPrimary));
    startDayButton.setTextColor(getResources().getColor(R.color.white));
    startDayButton.setOnClickListener(
        new View.OnClickListener() {
          public void onClick(View v) {
            if (found_daylog) {
              new AlertDialog.Builder(MainActivity.this)
                  .setMessage(
                      "There is already a log for this date. "
                          + "Are you sure you want to overwrite it?")
                  .setCancelable(false)
                  .setPositiveButton(
                      "Yes",
                      new DialogInterface.OnClickListener() {
                        public void onClick(DialogInterface dialog, int id) {
                          startNewDay();
                        }
                      })
                  .setNegativeButton("No", null)
                  .show();

            } else {
              startNewDay();
            }
          }
        });

    // Resume day button
    resumeDayButton = (Button) findViewById(R.id.resumeDayButton);
    ColoringUtil.colorMe(resumeDayButton, getResources().getColor(R.color.resumeday_button));
    resumeDayButton.setTextColor(getResources().getColor(R.color.white));
    resumeDayButton.setVisibility(View.INVISIBLE);
    resumeDayButton.setOnClickListener(
        new View.OnClickListener() {
          public void onClick(View v) {
            String action = "resume";
            Intent intent = new Intent(MainActivity.this, DayOverviewActivity.class);
            Bundle bundle = bundleDayInfo();
            bundle.putSerializable("action", action);
            bundle.putSerializable("reason", "Resuming day");
            intent.putExtras(bundle);
            startActivityForResult(intent, 0);
          }
        });

    // Various dialogs for the menus
    daylogdialog = getPrevLogsAlertDialog();
    loadfikencontactsdialog = getLoadFikenContactsAlertDialog();
  }