下面列出了android.os.Vibrator#vibrate ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
private void onPasscodeError(boolean clear)
{
if (getParentActivity() == null)
{
return;
}
Vibrator v = (Vibrator) getParentActivity().getSystemService(Context.VIBRATOR_SERVICE);
if (v != null)
{
v.vibrate(200);
}
if (clear)
{
codeField.setText("");
}
AndroidUtilities.shakeView(confirmTextView, 2, 0);
}
public void sendProfileOne(View view) {
Vibrator v = (Vibrator)getSystemService(VIBRATOR_SERVICE);
v.vibrate(400);
String videoResolutionOne = "";
String frameRateOne = "";
String fovOne = "";
String protuneOne = "";
String wbOne = "";
String colorOne = "";
String isoOne = "";
String sharpnessOne = "";
String evOne = "";
new HttpAsyncTask().execute("http://10.5.5.9/gp/gpControl/setting/2/" + videoResolutionOne);
new HttpAsyncTask().execute("http://10.5.5.9/gp/gpControl/setting/3/" + frameRateOne);
new HttpAsyncTask().execute("http://10.5.5.9/gp/gpControl/setting/4/" + fovOne);
new HttpAsyncTask().execute("http://10.5.5.9/gp/gpControl/setting/10/" + protuneOne);
new HttpAsyncTask().execute("http://10.5.5.9/gp/gpControl/setting/11/" + wbOne);
new HttpAsyncTask().execute("http://10.5.5.9/gp/gpControl/setting/12/" + colorOne);
new HttpAsyncTask().execute("http://10.5.5.9/gp/gpControl/setting/13/" + isoOne);
new HttpAsyncTask().execute("http://10.5.5.9/gp/gpControl/setting/14/" + sharpnessOne);
new HttpAsyncTask().execute("http://10.5.5.9/gp/gpControl/setting/15/" + evOne);
}
private void playBeepSoundAndVibrate() {
if (playBeep && mediaPlayer != null) {
mediaPlayer.start();
}
if (vibrate) {
Vibrator vibrator = (Vibrator) getSystemService(VIBRATOR_SERVICE);
vibrator.vibrate(VIBRATE_DURATION);
}
}
public void send60FPS(View view) {
Vibrator v = (Vibrator)getSystemService(VIBRATOR_SERVICE);
v.vibrate(400);
Toast.makeText(getApplicationContext(),
"60FPS", Toast.LENGTH_SHORT).show();
new HttpAsyncTask().execute("http://10.5.5.9/gp/gpControl/setting/3/5");
}
public synchronized void playBeepSoundAndVibrate() {
if (playBeep && mediaPlayer != null) {
mediaPlayer.start();
}
if (vibrate) {
Vibrator vibrator = (Vibrator) activity.getSystemService(Context.VIBRATOR_SERVICE);
vibrator.vibrate(VIBRATE_DURATION);
}
}
private void onPasscodeError()
{
if (getParentActivity() == null)
{
return;
}
Vibrator v = (Vibrator) getParentActivity().getSystemService(Context.VIBRATOR_SERVICE);
if (v != null)
{
v.vibrate(200);
}
AndroidUtilities.shakeView(titleTextView, 2, 0);
}
@Override
public void onReceive(Context context, Intent intent) {
Log.i(TAG, "INTENT RECEIVED");
Vibrator v = (Vibrator) context
.getSystemService(Context.VIBRATOR_SERVICE);
v.vibrate(500);
Toast.makeText(context, "INTENT RECEIVED by Receiver3",
Toast.LENGTH_LONG).show();
}
private void initiService(){
SettingUtility.setRunningType(SettingUtility.BREAK_FINISHED);
SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(this);
String strRingtonePreference = sp.getString("pref_notification_sound", "");
if(!strRingtonePreference.equals("")){
Uri ringtoneUri = Uri.parse(strRingtonePreference);
Ringtone ringtone = RingtoneManager.getRingtone(this, ringtoneUri);
ringtone.play();
// String name = ringtone.getTitle(context);
}
Boolean isVibrator = sp.getBoolean("pref_enable_vibrations", false);
if(isVibrator){
Vibrator mVibrator = (Vibrator) getSystemService(VIBRATOR_SERVICE);
mVibrator.vibrate(new long[]{50,100,50,100}, -1);
}
MyUtils.ScreenState screenState = MyUtils.getScreenState(this);
Intent intent = new Intent(BreakFinishService.this,BreakFinishActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
switch (screenState) {
case LOCK:
//prevent
//if BreakActivity behind the lockScreen, the screen will not be waked up
// Log.e("FinishService","LOCKing");
startActivity(intent);
break;
case MYAPP:
startActivity(intent);
break;
case OTHERAPP:
showAlertDialog();
break;
default:
break;
}
BreakFinishService.this.stopSelf();
}
public void sendMultishot(View view) {
Vibrator v = (Vibrator)getSystemService(VIBRATOR_SERVICE);
v.vibrate(600);
Toast.makeText(getApplicationContext(),
"Set to MultiShot mode!", Toast.LENGTH_SHORT).show();
new HttpAsyncTask().execute("http://10.5.5.9/gp/gpControl/command/mode?p=2");
}
@Override
public void onReceive(Context context, Intent intent) {
Log.i(TAG, "INTENT RECEIVED");
Vibrator v = (Vibrator) context
.getSystemService(Context.VIBRATOR_SERVICE);
v.vibrate(500);
Toast.makeText(context, "INTENT RECEIVED by Receiver3", Toast.LENGTH_LONG).show();
}
@SuppressWarnings("UnnecessaryReturnStatement")
@SuppressLint("MissingPermission")
public void vibrate(final int... ms) {
int ms_v = ms != null && ms.length > 0 ? ms[0] : 50;
Vibrator vibrator = ((Vibrator) _context.getSystemService(VIBRATOR_SERVICE));
if (vibrator == null) {
return;
} else if (Build.VERSION.SDK_INT >= 26) {
vibrator.vibrate(VibrationEffect.createOneShot(ms_v, VibrationEffect.DEFAULT_AMPLITUDE));
} else {
vibrator.vibrate(ms_v);
}
}
public void sendETNP15(View view) {
Vibrator v = (Vibrator)getSystemService(VIBRATOR_SERVICE);
v.vibrate(80);
Toast.makeText(getApplicationContext(),
"15sec", Toast.LENGTH_SHORT).show();
new HttpAsyncTask().execute("http://10.5.5.9/gp/gpControl/setting/19/4");
}
public void vibrateToUpdate() {
lastShakeTime = System.currentTimeMillis();
Vibrator vibrator = (Vibrator)context.getSystemService(Context.VIBRATOR_SERVICE);
//vibrator.vibrate(1000);
vibrator.vibrate(new long[]{50, 150}, -1);
Intent updateIntent = new Intent(Constants.ACTION_RECEIVER_AUTO_UPDATE);
context.sendBroadcast(updateIntent);
}
public void sendModePhotoSingle(View view) {
Vibrator v = (Vibrator)getSystemService(VIBRATOR_SERVICE);
v.vibrate(80);
Toast.makeText(getApplicationContext(),
"Photo mode!", Toast.LENGTH_SHORT).show();
new HttpAsyncTask().execute("http://10.5.5.9/gp/gpControl/setting/69/0");
}
private void handleLocation(int locationType, Location location) {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
// Filter nearby locations
int pref_nearby = Integer.parseInt(prefs.getString(SettingsFragment.PREF_NEARBY, SettingsFragment.DEFAULT_NEARBY));
Location lastLocation = LocationDeserializer.deserialize(prefs.getString(SettingsFragment.PREF_LAST_LOCATION, null));
if (locationType == LOCATION_TRACKPOINT || locationType == LOCATION_WAYPOINT || locationType == LOCATION_AUTO ||
lastLocation == null || Util.distance(lastLocation, location) >= pref_nearby ||
(lastLocation.hasAccuracy() ? lastLocation.getAccuracy() : Float.MAX_VALUE) >
(location.hasAccuracy() ? location.getAccuracy() : Float.MAX_VALUE)) {
// New location
Log.i(TAG, "New location=" + location + " type=" + locationType);
int altitude_type = (location.hasAltitude() ? ALTITUDE_GPS : ALTITUDE_NONE);
// Derive altitude from pressure
boolean pressure_enabled = prefs.getBoolean(SettingsFragment.PREF_PRESSURE_ENABLED, SettingsFragment.DEFAULT_PRESSURE_ENABLED);
if (pressure_enabled) {
float altitude = PressureService.getAltitude(location, this);
if (!Float.isNaN(altitude)) {
location.setAltitude(altitude);
altitude_type = ALTITUDE_PRESSURE;
}
}
// Add elevation data
try {
if (!location.hasAltitude() && Util.isConnected(this)) {
if (locationType == LOCATION_WAYPOINT || locationType == LOCATION_AUTO) {
if (prefs.getBoolean(SettingsFragment.PREF_ALTITUDE_WAYPOINT, SettingsFragment.DEFAULT_ALTITUDE_WAYPOINT)) {
GoogleElevationApi.getElevation(location, this);
altitude_type = ALTITUDE_LOOKUP;
}
} else {
if (prefs.getBoolean(SettingsFragment.PREF_ALTITUDE_TRACKPOINT, SettingsFragment.DEFAULT_ALTITUDE_TRACKPOINT)) {
GoogleElevationApi.getElevation(location, this);
altitude_type = ALTITUDE_LOOKUP;
}
}
}
} catch (Throwable ex) {
Log.e(TAG, ex.toString() + "\n" + Log.getStackTraceString(ex));
}
if (altitude_type != ALTITUDE_NONE && (locationType == LOCATION_WAYPOINT || locationType == LOCATION_AUTO))
altitude_type |= ALTITUDE_KEEP;
// Get waypoint name
String waypointName = null;
if (locationType == LOCATION_WAYPOINT || locationType == LOCATION_AUTO) {
waypointName = new GeocoderEx(this).reverseGeocode(location);
if (waypointName == null)
waypointName = SimpleDateFormat.getDateTimeInstance(SimpleDateFormat.MEDIUM, SimpleDateFormat.MEDIUM).format(new Date());
if (locationType == LOCATION_AUTO) {
long duration = new Date().getTime() - location.getTime();
long hours = TimeUnit.MILLISECONDS.toHours(duration);
long minutes = TimeUnit.MILLISECONDS.toMinutes(duration - hours * 3600 * 1000);
waypointName = hours + ":" + (minutes < 10 ? "0" : "") + minutes + " " + waypointName;
}
}
// Persist new location
prefs.edit().putString(SettingsFragment.PREF_LAST_LOCATION, LocationSerializer.serialize(location)).apply();
DatabaseHelper dh = null;
try {
dh = new DatabaseHelper(this);
dh.insertLocation(location, altitude_type, waypointName).close();
} finally {
if (dh != null)
dh.close();
}
// Feedback
showStateNotification(this);
if (locationType == LOCATION_TRACKPOINT || locationType == LOCATION_WAYPOINT) {
if (locationType == LOCATION_WAYPOINT)
Util.toast(waypointName, Toast.LENGTH_LONG, this);
Vibrator vibrator = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE);
vibrator.vibrate(locationType == LOCATION_TRACKPOINT ? VIBRATE_SHORT : VIBRATE_LONG);
} else if (Util.debugMode(this))
Util.toast(getString(R.string.title_trackpoint) + " " + getProviderName(location, this), Toast.LENGTH_SHORT, this);
if (locationType == LOCATION_TRACKPOINT || locationType == LOCATION_PERIODIC)
handleStationary(location);
} else
Log.i(TAG, "Filtered location=" + location);
}
/**
* 手机震动
* <p>
* duration:持续时间
*/
public static void vibrate(IQuickFragment webLoader, WebView wv, JSONObject param, Callback callback) {
long time = param.optLong("duration", 1000);
Vibrator vib = (Vibrator) webLoader.getPageControl().getActivity().getSystemService(Service.VIBRATOR_SERVICE);
vib.vibrate(time);
}
public static final void pulse(Context c) {
Vibrator v = (Vibrator) c.getSystemService(Context.VIBRATOR_SERVICE);
// Vibrate for 500 milliseconds
v.vibrate(500);
}
@Override
public void onConnectionStateChanged(int newState) {
if (newState == STATE_FAILED) {
callFailed();
return;
}
if (newState == STATE_ESTABLISHED) {
if(connectingSoundRunnable!=null){
AndroidUtilities.cancelRunOnUIThread(connectingSoundRunnable);
connectingSoundRunnable=null;
}
if (spPlayID != 0) {
soundPool.stop(spPlayID);
spPlayID = 0;
}
if(!wasEstablished){
wasEstablished=true;
if(!isProximityNear){
Vibrator vibrator=(Vibrator) getSystemService(VIBRATOR_SERVICE);
if(vibrator.hasVibrator())
vibrator.vibrate(100);
}
AndroidUtilities.runOnUIThread(new Runnable(){
@Override
public void run(){
if (tgVoip != null) {
StatsController.getInstance(currentAccount).incrementTotalCallsTime(getStatsNetworkType(), 5);
AndroidUtilities.runOnUIThread(this, 5000);
}
}
}, 5000);
if(isOutgoing)
StatsController.getInstance(currentAccount).incrementSentItemsCount(getStatsNetworkType(), StatsController.TYPE_CALLS, 1);
else
StatsController.getInstance(currentAccount).incrementReceivedItemsCount(getStatsNetworkType(), StatsController.TYPE_CALLS, 1);
}
}
if(newState==STATE_RECONNECTING){
if(spPlayID!=0)
soundPool.stop(spPlayID);
spPlayID=soundPool.play(spConnectingId, 1, 1, 0, -1, 1);
}
dispatchStateChanged(newState);
}
@Override
public void onReceive(Context context, Intent intent) {
Log.i(TAG, "Broadcast Received");
Vibrator v = (Vibrator) context
.getSystemService(Context.VIBRATOR_SERVICE);
v.vibrate(500);
Toast.makeText(context, "Broadcast Received by Receiver", Toast.LENGTH_LONG).show();
}
/**
* Vibrates the device with a given pattern.
*
* @param pattern Pattern with which to vibrate the device.
* Pass in an array of longs that
* are the durations for which to
* turn on or off the vibrator in
* milliseconds. The first value
* indicates the number of milliseconds
* to wait before turning the vibrator
* on. The next value indicates the
* number of milliseconds for which
* to keep the vibrator on before
* turning it off. Subsequent values
* alternate between durations in
* milliseconds to turn the vibrator
* off or to turn the vibrator on.
*
* @param repeat Optional index into the pattern array at which
* to start repeating, or -1 for no repetition (default).
*/
public void vibrateWithPattern(long[] pattern, int repeat) {
Vibrator vibrator = (Vibrator) this.cordova.getActivity().getSystemService(Context.VIBRATOR_SERVICE);
vibrator.vibrate(pattern, repeat);
}