use of android.os.Vibrator in project LuaViewSDK by alibaba.
the class UDVibrator method vibrate.
/**
* 震动
*
* @param patternTable
* @param repeat
* @return
*/
public UDVibrator vibrate(final LuaTable patternTable, final Integer repeat) {
if (patternTable != null) {
final Vibrator vibrator = getVibrator();
if (vibrator != null) {
if (patternTable.length() > 1) {
long[] pattern = new long[patternTable.length()];
for (int i = 0; i < patternTable.length(); i++) {
pattern[i] = (long) (patternTable.get((i + 1)).optdouble(1) * 1000);
}
vibrator.vibrate(pattern, repeat);
} else {
vibrator.vibrate((long) (patternTable.get(1).optdouble(1) * 1000));
}
}
}
return this;
}
use of android.os.Vibrator in project Signal-Android by WhisperSystems.
the class ConversationActivity method onRecorderFinished.
@Override
public void onRecorderFinished() {
Vibrator vibrator = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE);
vibrator.vibrate(20);
getWindow().clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
ListenableFuture<Pair<Uri, Long>> future = audioRecorder.stopRecording();
future.addListener(new ListenableFuture.Listener<Pair<Uri, Long>>() {
@Override
public void onSuccess(@NonNull final Pair<Uri, Long> result) {
try {
boolean forceSms = sendButton.isManualSelection() && sendButton.getSelectedTransport().isSms();
int subscriptionId = sendButton.getSelectedTransport().getSimSubscriptionId().or(-1);
long expiresIn = recipients.getExpireMessages() * 1000;
AudioSlide audioSlide = new AudioSlide(ConversationActivity.this, result.first, result.second, ContentType.AUDIO_AAC);
SlideDeck slideDeck = new SlideDeck();
slideDeck.addSlide(audioSlide);
sendMediaMessage(forceSms, "", slideDeck, expiresIn, subscriptionId).addListener(new AssertedSuccessListener<Void>() {
@Override
public void onSuccess(Void nothing) {
new AsyncTask<Void, Void, Void>() {
@Override
protected Void doInBackground(Void... params) {
PersistentBlobProvider.getInstance(ConversationActivity.this).delete(result.first);
return null;
}
}.execute();
}
});
} catch (InvalidMessageException e) {
Log.w(TAG, e);
Toast.makeText(ConversationActivity.this, R.string.ConversationActivity_error_sending_voice_message, Toast.LENGTH_LONG).show();
}
}
@Override
public void onFailure(ExecutionException e) {
Toast.makeText(ConversationActivity.this, R.string.ConversationActivity_unable_to_record_audio, Toast.LENGTH_LONG).show();
}
});
}
use of android.os.Vibrator in project Signal-Android by WhisperSystems.
the class ConversationActivity method onRecorderStarted.
@Override
public void onRecorderStarted() {
Vibrator vibrator = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE);
vibrator.vibrate(20);
getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
audioRecorder.startRecording();
}
use of android.os.Vibrator in project Carbon by ZieIony.
the class PowerMenuActivity method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_powermenu);
powerMenu = findViewById(R.id.powerMenu);
final FrameLayout transitionLayout = (FrameLayout) findViewById(R.id.transition);
findViewById(R.id.button).setOnClickListener(view -> {
if (powerMenu.getVisibility() == View.VISIBLE)
return;
for (int i = 0; i < transitionLayout.getChildCount(); i++) transitionLayout.getChildAt(i).setVisibility(i == 0 ? View.VISIBLE : View.GONE);
final List<View> viewsWithTag = ((LinearLayout) transitionLayout.getChildAt(0)).findViewsWithTag("animate");
Stream.of(viewsWithTag).forEach(v -> v.setVisibility(View.INVISIBLE));
powerMenu.setVisibility(View.VISIBLE);
view.getHandler().postDelayed(() -> {
Stream.of(viewsWithTag).forEach(v -> {
v.getHandler().postDelayed(() -> {
v.setVisibility(View.VISIBLE);
}, viewsWithTag.indexOf(v) * 40);
});
}, 200);
});
findViewById(R.id.powerOff).setOnClickListener(view -> {
final List<View> viewsWithTag = ((FrameLayout) transitionLayout.getChildAt(1)).findViewsWithTag("animate");
for (int i = 0; i < viewsWithTag.size(); i++) viewsWithTag.get(i).setVisibility(View.INVISIBLE);
view.getHandler().postDelayed(() -> {
for (int i = 0; i < viewsWithTag.size(); i++) {
final int finalI = i;
view.getHandler().postDelayed(() -> viewsWithTag.get(finalI).setVisibility(View.VISIBLE), i * 20);
}
}, 400);
view.getHandler().postDelayed(() -> powerMenu.setVisibility(View.INVISIBLE), 3000);
});
findViewById(R.id.reboot).setOnClickListener(view -> {
final List<View> viewsWithTag = ((FrameLayout) transitionLayout.getChildAt(2)).findViewsWithTag("animate");
for (int i = 0; i < viewsWithTag.size(); i++) viewsWithTag.get(i).setVisibility(View.INVISIBLE);
view.getHandler().postDelayed(() -> {
for (int i = 0; i < viewsWithTag.size(); i++) {
final int finalI = i;
view.getHandler().postDelayed(() -> viewsWithTag.get(finalI).setVisibility(View.VISIBLE), i * 20);
}
}, 400);
view.getHandler().postDelayed(() -> powerMenu.setVisibility(View.INVISIBLE), 3000);
});
findViewById(R.id.airplaneMode).setOnClickListener(view -> {
final List<View> viewsWithTag = ((FrameLayout) transitionLayout.getChildAt(3)).findViewsWithTag("animate");
for (int i = 0; i < viewsWithTag.size(); i++) viewsWithTag.get(i).setVisibility(View.INVISIBLE);
view.getHandler().postDelayed(() -> {
for (int i = 0; i < viewsWithTag.size(); i++) {
final int finalI = i;
view.getHandler().postDelayed(() -> viewsWithTag.get(finalI).setVisibility(View.VISIBLE), i * 20);
}
}, 400);
view.getHandler().postDelayed(() -> {
airplaneMode = !airplaneMode;
TextView amStatus = (TextView) findViewById(R.id.airplaneModeStatus);
amStatus.setText("Airplane Mode is " + (airplaneMode ? "on" : "off"));
ImageView airplaneModeIcon = (ImageView) view.findViewById(R.id.airplaneModeIcon);
airplaneModeIcon.setImageResource(airplaneMode ? R.raw.ic_airplanemode_on_24px : R.raw.ic_airplanemode_off_24px);
}, 3000);
});
findViewById(R.id.vibration).setOnClickListener(view -> {
if (vibration) {
vibration = false;
view.setBackgroundColor(0xffffffff);
((ImageView) view).setTint(getResources().getColor(R.color.carbon_black_54));
} else {
vibration = true;
view.setBackgroundColor(0xff00695D);
((ImageView) view).setTint(0xffffffff);
Vibrator vibrator = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE);
vibrator.vibrate(500);
}
powerMenu.postInvalidate();
});
findViewById(R.id.volume).setOnClickListener(view -> {
if (volume) {
volume = false;
view.setBackgroundColor(0xffffffff);
((ImageView) view).setTint(getResources().getColor(R.color.carbon_black_54));
} else {
volume = true;
view.setBackgroundColor(0xff00695D);
((ImageView) view).setTint(0xffffffff);
view.playSoundEffect(SoundEffectConstants.CLICK);
}
powerMenu.postInvalidate();
});
}
use of android.os.Vibrator in project jpHolo by teusink.
the class Vibration method vibrate.
//--------------------------------------------------------------------------
// LOCAL METHODS
//--------------------------------------------------------------------------
/**
* Vibrates the device for a given amount of time.
*
* @param time Time to vibrate in ms.
*/
public void vibrate(long time) {
// Start the vibration, 0 defaults to half a second.
if (time == 0) {
time = 500;
}
Vibrator vibrator = (Vibrator) this.cordova.getActivity().getSystemService(Context.VIBRATOR_SERVICE);
vibrator.vibrate(time);
}
Aggregations