Android Open Source - EnergyWastingApp Vibration






From Project

Back to project page EnergyWastingApp.

License

The source code is released under:

Copyright ? 2013-2014 Pekka Ekman <pekka.ekman@aalto.fi> 2013 Babujee Jerome Robin <robin.babujeejerome@aalto.fi> Permission is hereby granted, free of charge, to any person obtaining a ...

If you think the Android project EnergyWastingApp listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package fi.aalto.pekman.energywastingapp.components;
//  ww w. j  av  a2  s .  c o m
import android.annotation.TargetApi;
import android.content.Context;
import android.os.Build;
import android.os.Vibrator;

public class Vibration extends Component {

  private static final int PERIOD = 20;  // in ms
  
  private static final Vibrator vibrator = (Vibrator)
      context.getSystemService(Context.VIBRATOR_SERVICE);
  
  private int dutyCycle = getAdjustmentMax();
  
  @Override
  public String getName() { return "Vibration"; }
  
  @TargetApi(11)
  @Override
  public boolean isSupported() {
    if (Build.VERSION.SDK_INT >= 11)
      return vibrator.hasVibrator();
    else
      return true;
  }
  
  @Override
  public void start() {
    long[] pattern = new long[] { PERIOD - dutyCycle, dutyCycle };
    vibrator.vibrate(pattern, 0);
  }
  
  @Override
  public void stop() {
    vibrator.cancel();
  }
  
  @Override public boolean isAdjustable() { return true; }
  @Override public int getAdjustmentMax() { return PERIOD; }
  
  @Override
  protected void onAdjustmentChange(int value) {
    dutyCycle = value;
    if (running) {
      stop();
      start();
    }
  }

}




Java Source Code List

fi.aalto.pekman.energywastingapp.MainActivity.java
fi.aalto.pekman.energywastingapp.components.AbstractCamera.java
fi.aalto.pekman.energywastingapp.components.AbstractFileWriter.java
fi.aalto.pekman.energywastingapp.components.AppDirFileWriter.java
fi.aalto.pekman.energywastingapp.components.BlueToothBurn.java
fi.aalto.pekman.energywastingapp.components.CPUBurn.java
fi.aalto.pekman.energywastingapp.components.Component.java
fi.aalto.pekman.energywastingapp.components.Display.java
fi.aalto.pekman.energywastingapp.components.ExtStorageFileWriter.java
fi.aalto.pekman.energywastingapp.components.GPSCoordSearch.java
fi.aalto.pekman.energywastingapp.components.RecordAudio.java
fi.aalto.pekman.energywastingapp.components.StillCamera.java
fi.aalto.pekman.energywastingapp.components.TonePlay.java
fi.aalto.pekman.energywastingapp.components.Vibration.java
fi.aalto.pekman.energywastingapp.components.VideoCamera.java
fi.aalto.pekman.energywastingapp.components.WiFiDataTransfer.java