<commit_before>package nu.postnummeruppror.insamlingsappen;

import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.graphics.Color;
import android.graphics.PorterDuff;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.os.Bundle;
import android.os.StrictMode;
import android.provider.Settings;
import android.support.v7.app.ActionBarActivity;
import android.text.Editable;
import android.text.TextWatcher;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.EditText;
import android.widget.ProgressBar;
import android.widget.TextView;
import android.widget.Toast;

import insamlingsappen.postnummeruppror.nu.insamlingsappen.R;
import nu.postnummeruppror.insamlingsappen.commands.CreateLocationSample;


public class DataEntryActivity extends ActionBarActivity implements LocationListener {

  private static final int CREATE_ACCOUNT_REQUEST = 0;

  private CompoundLocationService locationService;
  private Location mostRecentLocation;
  private Location selectedLocation;

  private ProgressBar accuracyProgressBar;
  private TextView accuracyValue;
  private CheckBox accuracyIStandStill;

  private EditText postalCode;
  private EditText postalTown;
  private EditText streetName;
  private EditText houseNumber;
  private EditText houseName;

  private Button submit;

  private boolean ruleBasedPostalTown = false;

  private long maximumMillisecondsAgeOfLocationFix = 30 * 1000; // 30 seconds
  private AssertGoodLocationFixRunnable assertGoodLocationFixRunnable = new AssertGoodLocationFixRunnable();

  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    // Required to execute HTTP post from within the application thread on newer Android devices.
    if (android.os.Build.VERSION.SDK_INT > 8) {
      StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
      StrictMode.setThreadPolicy(policy);
    }


    setContentView(R.layout.activity_data_entry);

    /*
     *
     *
     *
     *
     *
     *
     */


    // Define views and widgets the application touch.

    accuracyProgressBar = (ProgressBar) findViewById(R.id.location_accuracy_progress_bar);
    accuracyValue = (TextView) findViewById(R.id.location_accuracy_value);
    accuracyIStandStill = (CheckBox) findViewById(R.id.location_accuracy_standing_still);

    accuracyIStandStill.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
      @Override
      public void onCheckedChanged(CompoundButton compoundButton, boolean checked) {
        if (!checked) {
          selectedLocation = null;
          onLocationChanged(mostRecentLocation);
        }
      }
    });

    postalCode = (EditText) findViewById(R.id.location_postal_code);
    postalTown = (EditText) findViewById(R.id.location_postal_town);
    streetName = (EditText) findViewById(R.id.location_street_name);
    houseNumber = (EditText) findViewById(R.id.location_house_number);
    houseName = (EditText) findViewById(R.id.location_house_name);

    submit = (Button) findViewById(R.id.submit_location_sample);

    submit.setOnClickListener(new View.OnClickListener() {
      @Override
      public void onClick(View view) {
        if (sendLocationSample()) {
          postalCode.setText(null);
          postalTown.setText(null);
          streetName.setText(null);
          houseNumber.setText(null);
          houseName.setText(null);

          accuracyIStandStill.setChecked(false);
          ruleBasedPostalTown = false;

          selectedLocation = null;

        }
      }
    });



    /*
     *
     *
     *
     *
     *
     *
     */


    locationService = new CompoundLocationService(this);
    locationService.setMaximumMillisecondsAgeOfGpsLocation(maximumMillisecondsAgeOfLocationFix);
    locationService.start();


    // make sure an account is created and registered.
    assertRegisteredAccount();


  }

  /**
   * onResume is executed after onCreate AND when returning to the application.
   */
  @Override
  protected void onResume() {
    super.onResume();

    LocationManager locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
    if (!locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER)) {
      showSettingsAlert();
    }

    locationService.requestLocationUpdates(this);

    Location mostRecentLocation = locationService.getMostRecentLocation();
    if (mostRecentLocation != null) {
      onLocationChanged(mostRecentLocation);
    }

//    accuracyProgressBar.getProgressDrawable().setColorFilter(Color.RED, PorterDuff.Mode.SRC_IN);
//    accuracyProgressBar.setProgress(0);

    new Thread(assertGoodLocationFixRunnable).start();

  }

  @Override
  protected void onDestroy() {
    super.onDestroy();
    locationService.stop();
  }

  @Override
  protected void onPause() {
    super.onPause();
    locationService.removeUpdates(this);
    assertGoodLocationFixRunnable.stop = true;
  }

  @Override
  public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.data_entry, menu);
    return true;
  }

  @Override
  public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
      case R.id.action_about:
        startActivity(new Intent(this, AboutActivity.class));<commit_msg>Minst ett fält ifyllt. Ingen maxålder på selected location<commit_after>package nu.postnummeruppror.insamlingsappen;

import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.graphics.Color;
import android.graphics.PorterDuff;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.os.Bundle;
import android.os.StrictMode;
import android.provider.Settings;
import android.support.v7.app.ActionBarActivity;
import android.text.Editable;
import android.text.TextWatcher;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.EditText;
import android.widget.ProgressBar;
import android.widget.TextView;
import android.widget.Toast;

import insamlingsappen.postnummeruppror.nu.insamlingsappen.R;
import nu.postnummeruppror.insamlingsappen.commands.CreateLocationSample;


public class DataEntryActivity extends ActionBarActivity implements LocationListener {

  private static final int CREATE_ACCOUNT_REQUEST = 0;

  private CompoundLocationService locationService;
  private Location mostRecentLocation;
  private Location selectedLocation;

  private ProgressBar accuracyProgressBar;
  private TextView accuracyValue;
  private CheckBox accuracyIStandStill;

  private EditText postalCode;
  private EditText postalTown;
  private EditText streetName;
  private EditText houseNumber;
  private EditText houseName;

  private Button submit;

  private boolean ruleBasedPostalTown = false;

  private long maximumMillisecondsAgeOfLocationFix = 30 * 1000; // 30 seconds
  private AssertGoodLocationFixRunnable assertGoodLocationFixRunnable = new AssertGoodLocationFixRunnable();

  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    // Required to execute HTTP post from within the application thread on newer Android devices.
    if (android.os.Build.VERSION.SDK_INT > 8) {
      StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
      StrictMode.setThreadPolicy(policy);
    }


    setContentView(R.layout.activity_data_entry);

    /*
     *
     *
     *
     *
     *
     *
     */


    // Define views and widgets the application touch.

    accuracyProgressBar = (ProgressBar) findViewById(R.id.location_accuracy_progress_bar);
    accuracyValue = (TextView) findViewById(R.id.location_accuracy_value);
    accuracyIStandStill = (CheckBox) findViewById(R.id.location_accuracy_standing_still);

    accuracyIStandStill.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
      @Override
      public void onCheckedChanged(CompoundButton compoundButton, boolean checked) {
        if (!checked) {
          selectedLocation = null;
          onLocationChanged(mostRecentLocation);
        }
      }
    });

    postalCode = (EditText) findViewById(R.id.location_postal_code);
    postalTown = (EditText) findViewById(R.id.location_postal_town);
    streetName = (EditText) findViewById(R.id.location_street_name);
    houseNumber = (EditText) findViewById(R.id.location_house_number);
    houseName = (EditText) findViewById(R.id.location_house_name);

    submit = (Button) findViewById(R.id.submit_location_sample);

    submit.setOnClickListener(new View.OnClickListener() {
      @Override
      public void onClick(View view) {
        if (sendLocationSample()) {
          postalCode.setText(null);
          postalTown.setText(null);
          streetName.setText(null);
          houseNumber.setText(null);
          houseName.setText(null);

          accuracyIStandStill.setChecked(false);
          ruleBasedPostalTown = false;

          selectedLocation = null;

        }
      }
    });



    /*
     *
     *
     *
     *
     *
     *
     */


    locationService = new CompoundLocationService(this);
    locationService.setMaximumMillisecondsAgeOfGpsLocation(maximumMillisecondsAgeOfLocationFix);
    locationService.start();


    // make sure an account is created and registered.
    assertRegisteredAccount();


  }

  /**
   * onResume is executed after onCreate AND when returning to the application.
   */
  @Override
  protected void onResume() {
    super.onResume();

    accuracyIStandStill.setChecked(false);

    LocationManager locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
    if (!locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER)) {
      showSettingsAlert();
    }

    locationService.requestLocationUpdates(this);

    Location mostRecentLocation = locationService.getMostRecentLocation();
    if (mostRecentLocation != null) {
      onLocationChanged(mostRecentLocation);
    }

//    accuracyProgressBar.getProgressDrawable().setColorFilter(Color.RED, PorterDuff.Mode.SRC_IN);
//    accuracyProgressBar.setProgress(0);

    new Thread(assertGoodLocationFixRunnable).start();

  }

  @Override
  protected void onDestroy() {
    super.onDestroy();
    locationService.stop();
  }

  @Override
  protected void onPause() {
    super.onPause();

    accuracyIStandStill.setChecked(false);

    locationService.removeUpdates(this);
    assertGoodLocationFixRunnable.stop = true;
  }

  @Override
  public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.data_entry, menu);
    return true;
  }

  @Override
  public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
      case R.id.action_about:
        startActivity(new Intent(this, AboutActivity.class));
{'fraction_non_alphanumeric': 0.08670470262793914, 'fraction_numerical': 0.002074688796680498, 'mean_word_length': 4.0497599301615015, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3438973', 'n_tokens_mistral': 3309, 'n_tokens_neox': 3121, 'n_words': 645}