Esempio n. 1
0
 @Override
 public boolean onContextItemSelected(MenuItem item) {
   return super.onContextItemSelected(item) || mv.onContextItemSelected(item);
 }
Esempio n. 2
0
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    mv = new MapView(getApplicationContext(), 600, 600, 30, 30);
    registerForContextMenu(mv);
    NavigationalMap map = MapLoader.loadMap(getExternalFilesDir(null), "Lab-room-peninsula.svg");
    mv.setMap(map);

    // Implements a clear button that, when clicked, clears the graph and maximum values.
    final Button clearButton = new Button(getApplicationContext());
    clearButton.setOnClickListener(
        new View.OnClickListener() {
          public void onClick(View v) {
            // Performs action onClick
            // Erases data on graph
            graph.purge();
            graph2.purge();
          }
        });

    clearButton.setText("Clear Graph");
    final Button clearSteps = new Button(getApplicationContext());
    clearSteps.setOnClickListener(
        new View.OnClickListener() {

          @Override
          public void onClick(View v) {

            LinearAccelerometerSensorEventListener.stepsClearer();

            Context context = getApplicationContext();
            CharSequence text = "steps cleared";
            int duration = Toast.LENGTH_SHORT;

            Toast toast = Toast.makeText(context, text, duration);
            toast.show();
          }
        });
    clearSteps.setText("Clear Steps");
    LinearLayout layout = (LinearLayout) findViewById(R.id.main_activity);
    layout.setOrientation(LinearLayout.VERTICAL);

    LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(1000, 30);
    layoutParams.setMargins(0, 24, 0, 24);

    graph = new LineGraphView(getApplicationContext(), 100, Arrays.asList("x", "y", "z"));
    graph.setVisibility(View.VISIBLE);

    graph2 = new LineGraphView(getApplicationContext(), 100, Arrays.asList("x", "y", "z"));
    graph2.setVisibility(View.VISIBLE);

    layout.addView(graph);
    layout.addView(mv);
    layout.addView(graph2);

    TextView stepCounter = labelGen("#ff00cc", layout, layoutParams);
    TextView stepNorthSouthText = labelGen("#ff00cc", layout, layoutParams);
    TextView stepEastWestText = labelGen("#ff00cc", layout, layoutParams);
    TextView currentStateOutput = labelGen("#33cc00", layout, layoutParams);
    TextView accelText = labelGen("#33cc00", layout, layoutParams);
    TextView magneticText = labelGen("#33cc00", layout, layoutParams);
    TextView orientationText = labelGen("#33cc00", layout, layoutParams);

    layout.addView(clearButton);
    layout.addView(clearSteps);

    SensorEventListener linearAccelerometerListener =
        new LinearAccelerometerSensorEventListener(
            accelText,
            graph,
            stepCounter,
            currentStateOutput,
            gravity,
            stepNorthSouthText,
            stepEastWestText);
    SensorEventListener accelerometerListener = new AccelerometerSensorEventListener(gravity);
    SensorEventListener magneticfieldListener =
        new MagneticFieldSensorEventListener(magneticText, orientationText, gravity, graph2);

    SensorManager sensorManager = (SensorManager) getSystemService(SENSOR_SERVICE);

    Sensor magneticfieldSensor = sensorManager.getDefaultSensor(Sensor.TYPE_MAGNETIC_FIELD);
    sensorManager.registerListener(
        magneticfieldListener, magneticfieldSensor, SensorManager.SENSOR_DELAY_NORMAL);
    Sensor linearAccelerometerSensor =
        sensorManager.getDefaultSensor(Sensor.TYPE_LINEAR_ACCELERATION);
    sensorManager.registerListener(
        linearAccelerometerListener, linearAccelerometerSensor, SensorManager.SENSOR_DELAY_FASTEST);
    Sensor accelerometerSensor = sensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER);
    sensorManager.registerListener(
        accelerometerListener, accelerometerSensor, SensorManager.SENSOR_DELAY_FASTEST);
  }
Esempio n. 3
0
 @Override
 public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) {
   super.onCreateContextMenu(menu, v, menuInfo);
   mv.onCreateContextMenu(menu, v, menuInfo);
 }