AccelerometerFragment extends Fragment implements
        View.OnClickListener, SensorEventListener { static List<Entry> smoothEntries(List<Entry> entries, int windowSize) { List<Entry> smoothEntries = new ArrayList<>(); for (int i = windowSize; i < entries.size() - windowSize; i++) { final float time = entries.get(i).getX(); float avg = 0; for (int j = i - windowSize; j <= i + windowSize; j++) { avg += entries.get(j).getY() / (2 * windowSize + 1); } smoothEntries.add(new Entry(time, avg)); } return smoothEntries; } AccelerometerFragment(); @Override View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState); @Override void onResume(); @Override void onPause(); void appendLogText(String msg); @Override void onClick(View v); @Override void onSensorChanged(SensorEvent event); @Override void onAccuracyChanged(Sensor sensor, int accuracy);  }
@Test public void testSmoothEntries() { Random rand = new Random(1234); List<Entry> entries = new ArrayList<>(); for (int i = 1; i <= 400; i++) { entries.add(new Entry(i, i + rand.nextFloat()*0.01f)); } final List<Entry> smoothEntries = AccelerometerFragment.smoothEntries(entries, 4); for (Entry e : smoothEntries) { assertEquals(e.getX(), e.getY(), 1e-2); } }