下面列出了android.view.animation.CycleInterpolator#android.os.Vibrator 实例代码,或者点击链接到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);
}
private void bindSystemServices(Application application) {
bindSystemService(application, LocationManager.class, LOCATION_SERVICE);
bindSystemService(application, WindowManager.class, WINDOW_SERVICE);
bindSystemService(application, ActivityManager.class, ACTIVITY_SERVICE);
bindSystemService(application, PowerManager.class, POWER_SERVICE);
bindSystemService(application, AlarmManager.class, ALARM_SERVICE);
bindSystemService(application, NotificationManager.class, NOTIFICATION_SERVICE);
bindSystemService(application, KeyguardManager.class, KEYGUARD_SERVICE);
bindSystemService(application, Vibrator.class, VIBRATOR_SERVICE);
bindSystemService(application, ConnectivityManager.class, CONNECTIVITY_SERVICE);
bindSystemService(application, WifiManager.class, WIFI_SERVICE);
bindSystemService(application, InputMethodManager.class, INPUT_METHOD_SERVICE);
bindSystemService(application, SearchManager.class, SEARCH_SERVICE);
bindSystemService(application, SensorManager.class, SENSOR_SERVICE);
bindSystemService(application, TelephonyManager.class, TELEPHONY_SERVICE);
bindSystemService(application, AudioManager.class, AUDIO_SERVICE);
bindSystemService(application, DownloadManager.class, DOWNLOAD_SERVICE);
bindSystemService(application, ClipboardManager.class, CLIPBOARD_SERVICE);
}
@Override
public void onReceive(Context context, Intent intent) {
Log.i(TAG, "INTENT RECEIVED");
if (isOrderedBroadcast()) {
Log.i(TAG, "Calling abortBroadcast()");
abortBroadcast();
}
Vibrator v = (Vibrator) context
.getSystemService(Context.VIBRATOR_SERVICE);
v.vibrate(500);
Toast.makeText(context, "INTENT RECEIVED by Receiver1",
Toast.LENGTH_LONG).show();
}
@Override
public void onReceive(Context context, Intent arg1) {
long[] pattern = {
0, // Start immediately
500, 500, 500, 500, 500};
Vibrator v = (Vibrator) context.getSystemService(Context.VIBRATOR_SERVICE);
// Vibrate for 500 milliseconds
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
v.vibrate(VibrationEffect.createWaveform(pattern, -1));
} else {
//deprecated in API 26
if (v != null) {
v.vibrate(pattern, -1);
}
}
}
@Override
public void onCreate() {
super.onCreate();
mInstance = this;
// 通过代码注册你的AppKey和AppSecret
MobSDK.init(this, "201f8a7a91c30", "c63ec5c1eeac1f873ec78c1365120431");
sContext = getApplicationContext();
initUser();
Utils.init(this);
locationService = new LocationService(getApplicationContext());
mVibrator = (Vibrator) getApplicationContext().getSystemService(Service.VIBRATOR_SERVICE);
setDatabase();
}
/**
* Handle progressive pressure on the screen
*/
private void progressiveForceTouch(){
runnable = new Runnable() {
@Override
public void run() {
if(getPressure() >= pressureLimit && !alreadyExecuted && isProgressive) {
if(isVibrate) {
Vibrator vibr = (Vibrator) context.getSystemService(Context.VIBRATOR_SERVICE);
vibr.vibrate(millisToVibrate);
}
forceTouchExecution.onForceTouch();
alreadyExecuted = true;
}
}
};
timer.scheduleAtFixedRate(runnable, 1);
}
@Override
public void onLongTokenClick(View view, Token token, List<BigInteger> tokenIds) {
//show radio buttons of all token groups
if (adapter != null) adapter.setRadioButtons(true);
selection = tokenIds;
Vibrator vb = (Vibrator) context.getSystemService(Context.VIBRATOR_SERVICE);
if (vb != null && vb.hasVibrator()) {
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) {
VibrationEffect vibe = VibrationEffect.createOneShot(200, DEFAULT_AMPLITUDE);
vb.vibrate(vibe);
} else {
//noinspection deprecation
vb.vibrate(200);
}
}
//Wait for availability to complete
waitForMapBuild();
populateButtons(token, getSelectedTokenId(tokenIds));
showButtons();
}
@SuppressLint("ClickableViewAccessibility")
public BaldConstraintLayoutButton(Context context) {
super(context);
this.sharedPreferences = context.getSharedPreferences(D.BALD_PREFS, Context.MODE_PRIVATE);
this.longPresses = sharedPreferences.getBoolean(BPrefs.LONG_PRESSES_KEY, BPrefs.LONG_PRESSES_DEFAULT_VALUE);
this.longPressesShorter = sharedPreferences.getBoolean(BPrefs.LONG_PRESSES_SHORTER_KEY, BPrefs.LONG_PRESSES_SHORTER_DEFAULT_VALUE);
this.vibrationFeedback = sharedPreferences.getBoolean(BPrefs.VIBRATION_FEEDBACK_KEY, BPrefs.VIBRATION_FEEDBACK_DEFAULT_VALUE);
this.vibrator = this.vibrationFeedback ? (Vibrator) context.getSystemService(Context.VIBRATOR_SERVICE) : null;
longer = longPresses ? BaldToast.from(context).setText(context.getText(R.string.press_longer)).setType(BaldToast.TYPE_DEFAULT).setLength(0).build() : null;
if (longPresses)
if (longPressesShorter) {
baldButtonTouchListener = new BaldButtonTouchListener(this);
super.setOnTouchListener(baldButtonTouchListener);
super.setOnClickListener(D.EMPTY_CLICK_LISTENER);
} else {
super.setOnLongClickListener(this);
super.setOnClickListener(this);
}
else
super.setOnClickListener(this);
}
public BaldLinearLayoutButton(Context context) {
super(context);
this.sharedPreferences = context.getSharedPreferences(D.BALD_PREFS, Context.MODE_PRIVATE);
this.longPresses = sharedPreferences.getBoolean(BPrefs.LONG_PRESSES_KEY, BPrefs.LONG_PRESSES_DEFAULT_VALUE);
this.longPressesShorter = sharedPreferences.getBoolean(BPrefs.LONG_PRESSES_SHORTER_KEY, BPrefs.LONG_PRESSES_SHORTER_DEFAULT_VALUE);
this.vibrationFeedback = sharedPreferences.getBoolean(BPrefs.VIBRATION_FEEDBACK_KEY, BPrefs.VIBRATION_FEEDBACK_DEFAULT_VALUE);
this.vibrator = this.vibrationFeedback ? (Vibrator) context.getSystemService(Context.VIBRATOR_SERVICE) : null;
longer = longPresses ? BaldToast.from(context).setText(context.getText(R.string.press_longer)).setType(BaldToast.TYPE_DEFAULT).setLength(0).build() : null;
if (longPresses)
if (longPressesShorter) {
baldButtonTouchListener = new BaldButtonTouchListener(this);
super.setOnTouchListener(baldButtonTouchListener);
super.setOnClickListener(D.EMPTY_CLICK_LISTENER);
} else {
super.setOnLongClickListener(this);
super.setOnClickListener(this);
}
else
super.setOnClickListener(this);
}
@PluginMethod()
@SuppressWarnings("MissingPermission")
public void vibrate(PluginCall call) {
Context c = this.getContext();
int duration = call.getInt("duration", 300);
if(!hasPermission(Manifest.permission.VIBRATE)) {
call.error("Can't vibrate: Missing VIBRATE permission in AndroidManifest.xml");
return;
}
if (Build.VERSION.SDK_INT >= 26) {
((Vibrator) c.getSystemService(Context.VIBRATOR_SERVICE)).vibrate(VibrationEffect.createOneShot(duration, VibrationEffect.DEFAULT_AMPLITUDE));
} else {
vibratePre26(duration);
}
call.success();
}
public BaldLinearLayoutButton(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
super(context, attrs, defStyleAttr, defStyleRes);
this.sharedPreferences = context.getSharedPreferences(D.BALD_PREFS, Context.MODE_PRIVATE);
this.longPresses = sharedPreferences.getBoolean(BPrefs.LONG_PRESSES_KEY, BPrefs.LONG_PRESSES_DEFAULT_VALUE);
this.longPressesShorter = sharedPreferences.getBoolean(BPrefs.LONG_PRESSES_SHORTER_KEY, BPrefs.LONG_PRESSES_SHORTER_DEFAULT_VALUE);
this.vibrationFeedback = sharedPreferences.getBoolean(BPrefs.VIBRATION_FEEDBACK_KEY, BPrefs.VIBRATION_FEEDBACK_DEFAULT_VALUE);
this.vibrator = this.vibrationFeedback ? (Vibrator) context.getSystemService(Context.VIBRATOR_SERVICE) : null;
longer = longPresses ? BaldToast.from(context).setText(context.getText(R.string.press_longer)).setType(BaldToast.TYPE_DEFAULT).setLength(0).build() : null;
if (longPresses)
if (longPressesShorter) {
baldButtonTouchListener = new BaldButtonTouchListener(this);
super.setOnTouchListener(baldButtonTouchListener);
super.setOnClickListener(D.EMPTY_CLICK_LISTENER);
} else {
super.setOnLongClickListener(this);
super.setOnClickListener(this);
}
else
super.setOnClickListener(this);
}
public BaldButton(Context context, @Nullable AttributeSet attrs) {
super(context, attrs);
this.sharedPreferences = context.getSharedPreferences(D.BALD_PREFS, Context.MODE_PRIVATE);
this.longPresses = sharedPreferences.getBoolean(BPrefs.LONG_PRESSES_KEY, BPrefs.LONG_PRESSES_DEFAULT_VALUE);
this.longPressesShorter = sharedPreferences.getBoolean(BPrefs.LONG_PRESSES_SHORTER_KEY, BPrefs.LONG_PRESSES_SHORTER_DEFAULT_VALUE);
this.vibrationFeedback = sharedPreferences.getBoolean(BPrefs.VIBRATION_FEEDBACK_KEY, BPrefs.VIBRATION_FEEDBACK_DEFAULT_VALUE);
this.vibrator = this.vibrationFeedback ? (Vibrator) context.getSystemService(Context.VIBRATOR_SERVICE) : null;
longer = longPresses ? BaldToast.from(context).setText(context.getText(R.string.press_longer)).setType(BaldToast.TYPE_DEFAULT).setLength(0).build() : null;
if (longPresses)
if (longPressesShorter) {
baldButtonTouchListener = new BaldButtonTouchListener(this);
super.setOnTouchListener(baldButtonTouchListener);
super.setOnClickListener(D.EMPTY_CLICK_LISTENER);
} else {
super.setOnLongClickListener(this);
super.setOnClickListener(this);
}
else
super.setOnClickListener(this);
}
@Override
public void onCreate() {
super.onCreate();
mApplicationContext = this;
/***
* 初始化版本升级模块
*/
UpdateConfig.initGet(this);
/***
* 初始化定位sdk,建议在Application中创建
*/
locationService = new LocationService(getApplicationContext());
mVibrator = (Vibrator) getApplicationContext().getSystemService(VIBRATOR_SERVICE);
SDKInitializer.initialize(getApplicationContext());
}
private void showToast(Activity activity, String message, boolean vibrateLong) {
LayoutInflater inflater = getLayoutInflater();
View layout = inflater.inflate(R.layout.custom_toast,
activity.findViewById(R.id.custom_toast_container));
TextView text = layout.findViewById(R.id.text);
text.setText(message);
Vibrator v = (Vibrator) activity.getSystemService(Context.VIBRATOR_SERVICE);
if (vibrateLong) {
v.vibrate(100);
v.vibrate(200);
} else {
v.vibrate(100);
}
Toast toast = new Toast(activity.getApplicationContext());
toast.setGravity(Gravity.BOTTOM, 0, convertDimensionToPx(this.getContext(), R.dimen.stdpadding));
toast.setDuration(Toast.LENGTH_LONG);
toast.setView(layout);
toast.show();
}
public MyGridView(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
mVibrator = (Vibrator) context.getSystemService(Context.VIBRATOR_SERVICE);
mWindowManager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
mStatusHeight = getStatusHeight(context);
background = BitmapFactory.decodeResource(getResources(),
R.drawable.bookshelf_layer_center1);
if(!mNumColumnsSet){
mNumColumns = AUTO_FIT;
}
mcontext = context;
setOnItemLongClickListener(this);
}
public void sendModeVideoVideoPhoto(View view) {
Vibrator v = (Vibrator)getSystemService(VIBRATOR_SERVICE);
v.vibrate(80);
Toast.makeText(getApplicationContext(),
"Video plus photo!", Toast.LENGTH_SHORT).show();
new HttpAsyncTask().execute("http://10.5.5.9/gp/gpControl/setting/68/2");
}
private boolean trySetUsername() {
if (getParentActivity() == null) {
return false;
}
if (!isPrivate && ((currentChat.username == null && usernameTextView.length() != 0) || (currentChat.username != null && !currentChat.username.equalsIgnoreCase(usernameTextView.getText().toString())))) {
if (usernameTextView.length() != 0 && !lastNameAvailable) {
Vibrator v = (Vibrator) getParentActivity().getSystemService(Context.VIBRATOR_SERVICE);
if (v != null) {
v.vibrate(200);
}
AndroidUtilities.shakeView(checkTextView, 2, 0);
return false;
}
}
String oldUserName = currentChat.username != null ? currentChat.username : "";
String newUserName = isPrivate ? "" : usernameTextView.getText().toString();
if (!oldUserName.equals(newUserName)) {
if (!ChatObject.isChannel(currentChat)) {
getMessagesController().convertToMegaGroup(getParentActivity(), chatId, this, param -> {
if (param != 0) {
chatId = param;
currentChat = getMessagesController().getChat(param);
processDone();
}
});
return false;
} else {
getMessagesController().updateChannelUserName(chatId, newUserName);
currentChat.username = newUserName;
}
}
return true;
}
@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 Receiver2", Toast.LENGTH_LONG).show();
}
public void sendIndoorProfile(View view) {
Vibrator v = (Vibrator)getSystemService(VIBRATOR_SERVICE);
v.vibrate(400);
Toast.makeText(getApplicationContext(),
"Be A HERO", Toast.LENGTH_SHORT).show();
new HttpAsyncTask().execute("http://10.5.5.9/gp/gpControl/setting/2/9");
new HttpAsyncTask().execute("http://10.5.5.9/gp/gpControl/setting/3/8");
new HttpAsyncTask().execute("http://10.5.5.9/gp/gpControl/setting/4/0");
new HttpAsyncTask().execute("http://10.5.5.9/gp/gpControl/setting/10/0");
}
public void sendVR27K(View view) {
Vibrator v = (Vibrator)getSystemService(VIBRATOR_SERVICE);
v.vibrate(80);
Toast.makeText(getApplicationContext(),
"2.7K!", Toast.LENGTH_SHORT).show();
new HttpAsyncTask().execute("http://10.5.5.9/gp/gpControl/setting/2/4");
}
private void showDialogInBroadcastReceiver(String message, final int flag) {
if (flag == 1 || flag == 2) {
mediaPlayer = MediaPlayer.create(this, R.raw.in_call_alarm);
mediaPlayer.setLooping(true);
mediaPlayer.start();
}
//数组参数意义:第一个参数为等待指定时间后开始震动,震动时间为第二个参数。后边的参数依次为等待震动和震动的时间
//第二个参数为重复次数,-1为不重复,0为一直震动
if (flag == 0 || flag == 2) {
vibrator = (Vibrator) this.getSystemService(Service.VIBRATOR_SERVICE);
vibrator.vibrate(new long[]{100, 10, 100, 600}, 0);
}
final SimpleDialog dialog = new SimpleDialog(this, R.style.Theme_dialog);
dialog.show();
dialog.setTitle("闹钟提醒");
dialog.setMessage(message);
dialog.setClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (dialog.bt_confirm == v || dialog.bt_cancel == v) {
if (flag == 1 || flag == 2) {
mediaPlayer.stop();
mediaPlayer.release();
}
if (flag == 0 || flag == 2) {
vibrator.cancel();
}
dialog.dismiss();
finish();
}
}
});
}
@Override
public void onCreate() {
super.onCreate();
mVibrator = (Vibrator) getApplicationContext().getSystemService(
VIBRATOR_SERVICE);
mAM = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
mMaxVolume = mAM.getStreamMaxVolume(AudioManager.STREAM_MUSIC);
}
public Controls(BlockDropWallpaper ga) {
super(ga);
lineThresholds = host.getResources().getIntArray(R.array.line_thresholds);
shortVibeTime = 0;
v = (Vibrator) host.getSystemService(Context.VIBRATOR_SERVICE);
buttonVibrationEnabled = PreferenceManager.getDefaultSharedPreferences(host).getBoolean("pref_vibration_button", false);
eventVibrationEnabled = PreferenceManager.getDefaultSharedPreferences(host).getBoolean("pref_vibration_events", false);
try {
vibrationOffset = Integer.parseInt(PreferenceManager.getDefaultSharedPreferences(host).getString("pref_vibDurOffset", "0"));
} catch(NumberFormatException e) {
vibrationOffset = 0;
}
if(PreferenceManager.getDefaultSharedPreferences(host).getBoolean("pref_accelerationH", true))
initialHIntervalFactor = 2;
else
initialHIntervalFactor = 1;
if(PreferenceManager.getDefaultSharedPreferences(host).getBoolean("pref_accelerationV", true))
initialVIntervalFactor = 2;
else
initialVIntervalFactor = 1;
playerSoftDrop = false;
leftMove = false;
rightMove = false;
leftRotation = false;
rightRotation = false;
clearLeftMove = false;
clearRightMove = false;
clearPlayerSoftDrop = false;
continuousSoftDrop = false;
continuousLeftMove = false;
continuousRightMove = false;
previewBox = null;
boardTouched = false;
}
protected void initView() {
//初始化SoundPool
mSoundPool = new SoundPool(1, AudioManager.STREAM_SYSTEM, 5);
mWeiChatAudio = mSoundPool.load(this, R.raw.shake_sound, 1);
//获取Vibrator震动服务
mVibrator = (Vibrator) getSystemService(VIBRATOR_SERVICE);
}
public void sendETNI2(View view) {
Vibrator v = (Vibrator)getSystemService(VIBRATOR_SERVICE);
v.vibrate(80);
Toast.makeText(getApplicationContext(),
"2sec", Toast.LENGTH_SHORT).show();
new HttpAsyncTask().execute("http://10.5.5.9/gp/gpControl/setting/31/1");
}
private int getCurrentIntensityLocked(Vibration vib) {
if (vib.isNotification() || vib.isRingtone()){
return mNotificationIntensity;
} else if (vib.isHapticFeedback()) {
return mHapticFeedbackIntensity;
} else {
return Vibrator.VIBRATION_INTENSITY_MEDIUM;
}
}
public void sendNarrowFOV(View view) {
Vibrator v = (Vibrator)getSystemService(VIBRATOR_SERVICE);
v.vibrate(80);
Toast.makeText(getApplicationContext(),
"Narrow", Toast.LENGTH_SHORT).show();
String yourFilePath = this.getFilesDir() + "/" + "camconfig.txt";
File yourFile = new File( yourFilePath );
try {
String password = getFileContents(yourFile);
new HttpAsyncTask ().execute("http://10.5.5.9/camera/FV?t=" + password + "&p=%02");
} catch (IOException e) {
e.printStackTrace();
}
}
private void onFieldError(TextView field, boolean clear) {
if (getParentActivity() == null) {
return;
}
Vibrator v = (Vibrator) getParentActivity().getSystemService(Context.VIBRATOR_SERVICE);
if (v != null) {
v.vibrate(200);
}
if (clear) {
field.setText("");
}
AndroidUtilities.shakeView(field, 2, 0);
}
public void sendETNP5(View view) {
Vibrator v = (Vibrator)getSystemService(VIBRATOR_SERVICE);
v.vibrate(80);
Toast.makeText(getApplicationContext(),
"5sec", Toast.LENGTH_SHORT).show();
new HttpAsyncTask().execute("http://10.5.5.9/gp/gpControl/setting/19/2");
}
/**
* Gets the vibrator service associated with the device, if there is one.
* Even if the device does not have a vibrator, the result is never null.
* Use {@link Vibrator#hasVibrator} to determine whether a vibrator is
* present.
*
* Note that the vibrator associated with the device may be different from
* the system vibrator. To obtain an instance of the system vibrator instead, call
* {@link Context#getSystemService} with {@link Context#VIBRATOR_SERVICE} as argument.
*
* @return The vibrator service associated with the device, never null.
*/
public Vibrator getVibrator() {
synchronized (mMotionRanges) {
if (mVibrator == null) {
if (mHasVibrator) {
mVibrator = InputManager.getInstance().getInputDeviceVibrator(mId);
} else {
mVibrator = NullVibrator.getInstance();
}
}
return mVibrator;
}
}