예제 #1
0
  @Override
  public void onClick(View v) {
    // TODO Auto-generated method stub
    switch (v.getId()) {
      case R.id.detect_start_localize_button:
        ConnectivityManager cm =
            (ConnectivityManager)
                this.getApplicationContext().getSystemService(CONNECTIVITY_SERVICE);
        NetworkInfo networkInfo = cm.getActiveNetworkInfo();
        if (networkInfo == null || !networkInfo.isConnected()) {
          myHandler.post(new FailConnectInternet());
          return;
        }

        if (((String) listTypeSpinner.getSelectedItem()).equals("GPS")) {
          LocationManager locationManager =
              (LocationManager) getSystemService(Context.LOCATION_SERVICE);
          if (!locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER)) {
            Toast.makeText(getApplicationContext(), "Gps Disabled", Toast.LENGTH_SHORT).show();

            return;
          }
        }

        startLocalizeButton.setEnabled(false);
        startLocalizeButton.setFocusable(false);
        stopLocalizeButton.setEnabled(true);
        stopLocalizeButton.setFocusable(true);
        listTypeSpinner.setEnabled(false);
        listTypeSpinner.setFocusable(false);

        countInt = 0;

        if (((String) listTypeSpinner.getSelectedItem()).equals("WIFI")) {
          wifiDetector.setConvert(convertCheckbox.isChecked());
          wifiDetector.startDetectLocation();
        } else {
          gpsDetector.startDetectLocation();
        }
        break;

      case R.id.detect_stop_localize_button:
        startLocalizeButton.setEnabled(true);
        startLocalizeButton.setFocusable(true);
        stopLocalizeButton.setEnabled(false);
        stopLocalizeButton.setFocusable(false);
        listTypeSpinner.setEnabled(true);
        listTypeSpinner.setFocusable(true);

        if (((String) listTypeSpinner.getSelectedItem()).equals("WIFI")) {
          wifiDetector.stopDectectLocation();
        } else {
          gpsDetector.stopDectectLocation();
        }
        break;

      default:
        break;
    }
  }
예제 #2
0
  @Override
  public void onCreate(android.os.Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.detect);

    listTypeSpinner = (Spinner) findViewById(R.id.detect_list_types);

    ArrayList<String> listType = new ArrayList<String>();
    listType.add("GPS");
    listType.add("WIFI");

    ArrayAdapter<String> spinnerAdapter =
        new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, listType);
    listTypeSpinner.setAdapter(spinnerAdapter);

    convertCheckbox = (CheckBox) findViewById(R.id.detect_convert);

    startLocalizeButton = (Button) findViewById(R.id.detect_start_localize_button);
    startLocalizeButton.setOnClickListener(this);

    stopLocalizeButton = (Button) findViewById(R.id.detect_stop_localize_button);
    stopLocalizeButton.setOnClickListener(this);

    locationNameText = (TextView) findViewById(R.id.detect_locationname);
    rootLocationText = (TextView) findViewById(R.id.detect_rootlocation);
    userNameText = (TextView) findViewById(R.id.detect_userName);
    calibrateText = (TextView) findViewById(R.id.detect_calibrateStatus);
    resultTimeText = (TextView) findViewById(R.id.detect_result_time);

    wifiDetector.setFrequency(1.0);
    wifiDetector.setServerHost(Prefs.getServerHost(getApplicationContext()));
    wifiDetector.setPort(Prefs.getDetectWifiPort(getApplicationContext()));
    wifiDetector.setDetectAtClient(false);
    wifiDetector.setConvert(false);
    wifiDetector.setConfidence(90);
    wifiDetector.addNewResultComingEventListener(
        new NewResultComingEventListener() {

          public void handleEvent(NewResultComingEvent nrce) {
            myHandler.post(updateUI);
            countInt += 1;
            lastGetResultTime = Calendar.getInstance().getTimeInMillis();
          }
        });

    gpsDetector.setServerHost(Prefs.getServerHost(getApplicationContext()));
    gpsDetector.setPort(Prefs.getDetectWifiPort(getApplicationContext()));
    gpsDetector.setConfidence(90);
    gpsDetector.addNewResultComingEventListener(
        new NewResultComingEventListener() {

          public void handleEvent(NewResultComingEvent nrce) {
            myHandler.post(updateUI);
            countInt += 1;
            lastGetResultTime = Calendar.getInstance().getTimeInMillis();
          }
        });
  };