Java Code Examples for android.os.Vibrator#hasVibrator()

The following examples show how to use android.os.Vibrator#hasVibrator() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: FunctionButtonBar.java    From alpha-wallet-android with MIT License 6 votes vote down vote up
@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();
}
 
Example 2
Source File: HostVibrationProfile.java    From DeviceConnect-Android with MIT License 6 votes vote down vote up
@Override
public boolean onRequest(final Intent request, final Intent response) {
    Vibrator vibrator = (Vibrator) getContext().getSystemService(Context.VIBRATOR_SERVICE);

    if (vibrator == null || !vibrator.hasVibrator()) {
        setResult(response, IntentDConnectMessage.RESULT_ERROR);
    } else {
        vibrator.cancel();
    }

    // cancel()は現在されているの振調パターンの1節しかキャンセルしないので、
    // それ以降の振動パターンの節の再生を防ぐ為に、キャンセルされたことを示す
    // フラグをたてる。
    mIsCancelled = true;

    setResult(response, IntentDConnectMessage.RESULT_OK);
    return true;
}
 
Example 3
Source File: KeyService.java    From alpha-wallet-android with MIT License 6 votes vote down vote up
private void vibrate()
{
    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);
        }
    }
}
 
Example 4
Source File: TalkBackPreferencesActivity.java    From talkback with Apache License 2.0 6 votes vote down vote up
/** Ensure that the vibration setting does not appear on devices without a vibrator. */
private void checkVibrationSupport() {
  Activity activity = getActivity();
  if (activity == null) {
    return;
  }

  final Vibrator vibrator = (Vibrator) activity.getSystemService(VIBRATOR_SERVICE);

  if (vibrator != null && vibrator.hasVibrator()) {
    return;
  }

  final PreferenceGroup category =
      (PreferenceGroup) findPreferenceByResId(R.string.pref_category_feedback_key);
  final TwoStatePreference prefVibration =
      (TwoStatePreference) findPreferenceByResId(R.string.pref_vibration_key);

  if (prefVibration != null) {
    prefVibration.setChecked(false);
    category.removePreference(prefVibration);
  }
}
 
Example 5
Source File: IncomingRinger.java    From bcm-android with GNU General Public License v3.0 6 votes vote down vote up
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
private boolean shouldVibrateNew(Context context, int ringerMode) {
  Vibrator vibrator = (Vibrator) context.getSystemService(Context.VIBRATOR_SERVICE);

  if (vibrator == null || !vibrator.hasVibrator()) {
    return false;
  }

  boolean vibrateWhenRinging = Settings.System.getInt(context.getContentResolver(), "vibrate_when_ringing", 0) != 0;

  if (vibrateWhenRinging) {
    return ringerMode != AudioManager.RINGER_MODE_SILENT;
  } else {
    return ringerMode == AudioManager.RINGER_MODE_VIBRATE;
  }
}
 
Example 6
Source File: LegacyGlobalActions.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
/**
 * @param context everything needs a context :(
 */
public LegacyGlobalActions(Context context, WindowManagerFuncs windowManagerFuncs,
        Runnable onDismiss) {
    mContext = context;
    mWindowManagerFuncs = windowManagerFuncs;
    mOnDismiss = onDismiss;
    mAudioManager = (AudioManager) mContext.getSystemService(Context.AUDIO_SERVICE);
    mDreamManager = IDreamManager.Stub.asInterface(
            ServiceManager.getService(DreamService.DREAM_SERVICE));

    // receive broadcasts
    IntentFilter filter = new IntentFilter();
    filter.addAction(Intent.ACTION_CLOSE_SYSTEM_DIALOGS);
    filter.addAction(Intent.ACTION_SCREEN_OFF);
    filter.addAction(TelephonyIntents.ACTION_EMERGENCY_CALLBACK_MODE_CHANGED);
    context.registerReceiver(mBroadcastReceiver, filter);

    ConnectivityManager cm = (ConnectivityManager)
            context.getSystemService(Context.CONNECTIVITY_SERVICE);
    mHasTelephony = cm.isNetworkSupported(ConnectivityManager.TYPE_MOBILE);

    // get notified of phone state changes
    TelephonyManager telephonyManager =
            (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
    telephonyManager.listen(mPhoneStateListener, PhoneStateListener.LISTEN_SERVICE_STATE);
    mContext.getContentResolver().registerContentObserver(
            Settings.Global.getUriFor(Settings.Global.AIRPLANE_MODE_ON), true,
            mAirplaneModeObserver);
    Vibrator vibrator = (Vibrator) mContext.getSystemService(Context.VIBRATOR_SERVICE);
    mHasVibrator = vibrator != null && vibrator.hasVibrator();

    mShowSilentToggle = SHOW_SILENT_TOGGLE && !mContext.getResources().getBoolean(
            com.android.internal.R.bool.config_useFixedVolume);

    mEmergencyAffordanceManager = new EmergencyAffordanceManager(context);
}
 
Example 7
Source File: UIUtils.java    From Kore with Apache License 2.0 5 votes vote down vote up
public static void handleVibration(Context context) {
    if(context == null) return;

    Vibrator vibrator = (Vibrator) context.getSystemService(Context.VIBRATOR_SERVICE);
    if (!vibrator.hasVibrator()) return;

    //Check if we should vibrate
    boolean vibrateOnPress = PreferenceManager
            .getDefaultSharedPreferences(context)
            .getBoolean(Settings.KEY_PREF_VIBRATE_REMOTE_BUTTONS,
                        Settings.DEFAULT_PREF_VIBRATE_REMOTE_BUTTONS);
    if (vibrateOnPress) {
        vibrator.vibrate(UIUtils.buttonVibrationDuration);
    }
}
 
Example 8
Source File: ToggleVibratePhone.java    From itracing2 with GNU General Public License v2.0 5 votes vote down vote up
private void stopVibrate(Context context, Intent intent) {
    final Vibrator vibrator = (Vibrator) context.getSystemService(Context.VIBRATOR_SERVICE);

    if (!vibrator.hasVibrator()) {
        Toast.makeText(context, R.string.vibrator_not_found, Toast.LENGTH_LONG).show();
        return;
    }

    vibrator.cancel();

    NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
    notificationManager.cancel(ToggleVibratePhone.NOTIFICATION_ID);
    vibrating=false;
}
 
Example 9
Source File: Utils.java    From GravityBox with Apache License 2.0 5 votes vote down vote up
public static boolean hasVibrator(Context con) {
    if (mHasVibrator != null) return mHasVibrator;

    try {
        Vibrator v = (Vibrator) con.getSystemService(Context.VIBRATOR_SERVICE);
        mHasVibrator = v.hasVibrator();
        return mHasVibrator;
    } catch (Throwable t) {
        mHasVibrator = null;
        return false;
    }
}
 
Example 10
Source File: BasePasscodeView.java    From PasscodeView with Apache License 2.0 5 votes vote down vote up
/**
 * Run the vibrator to give tactile feedback for 50ms when any key is pressed.
 */
protected void giveTactileFeedbackForKeyPress() {
    if (!mIsTactileFeedbackEnabled) return;

    final Vibrator v = (Vibrator) getContext().getSystemService(Context.VIBRATOR_SERVICE);

    if (v == null) {
        Log.w("PasscodeView", "Vibrator service not found.");
        return;
    }

    if (v.hasVibrator()) v.vibrate(50);
}
 
Example 11
Source File: BasePasscodeView.java    From PasscodeView with Apache License 2.0 5 votes vote down vote up
/**
 * Run the vibrator to give tactile feedback for 100ms at difference of 50ms for two times when
 * user authentication is failed.
 */
private void giveTactileFeedbackForAuthSuccess() {
    if (!mIsTactileFeedbackEnabled) return;

    final Vibrator v = (Vibrator) getContext().getSystemService(Context.VIBRATOR_SERVICE);
    if (v == null) {
        Log.w("PasscodeView", "Vibrator service not found.");
        return;
    }

    if (v.hasVibrator()) v.vibrate(new long[]{50, 100, 50, 100}, -1);
}
 
Example 12
Source File: BasePasscodeView.java    From PasscodeView with Apache License 2.0 5 votes vote down vote up
/**
 * Run the vibrator to give tactile feedback for 350ms when user authentication is successful.
 */
private void giveTactileFeedbackForAuthFail() {
    if (!mIsTactileFeedbackEnabled) return;

    final Vibrator v = (Vibrator) getContext().getSystemService(Context.VIBRATOR_SERVICE);
    if (v == null) {
        Log.w("PasscodeView", "Vibrator service not found.");
        return;
    }

    if (v.hasVibrator()) v.vibrate(350);
}
 
Example 13
Source File: MainActivity.java    From connectivity-samples with Apache License 2.0 5 votes vote down vote up
/** Vibrates the phone. */
private void vibrate() {
  Vibrator vibrator = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE);
  if (hasPermissions(this, Manifest.permission.VIBRATE) && vibrator.hasVibrator()) {
    vibrator.vibrate(VIBRATION_STRENGTH);
  }
}
 
Example 14
Source File: IncomingCallFragment.java    From q-municate-android with Apache License 2.0 5 votes vote down vote up
public void startCallNotification() {
    ringtonePlayer.play(false);

    vibrator = (Vibrator) getActivity().getSystemService(Context.VIBRATOR_SERVICE);

    long[] vibrationCycle = {0, 1000, 1000};
    if (vibrator.hasVibrator()) {
        vibrator.vibrate(vibrationCycle, 1);
    }
}
 
Example 15
Source File: Utils.java    From ghwatch with Apache License 2.0 5 votes vote down vote up
/**
 * Get Vibrator if available in system.
 *
 * @param context to use for get
 * @return {@link Vibrator} instance or null if not available in system.
 */
public static Vibrator getVibrator(Context context) {
  Vibrator v = (Vibrator) context.getSystemService(Context.VIBRATOR_SERVICE);
  if (v.hasVibrator())
    return v;
  return null;
}
 
Example 16
Source File: FloatingView.java    From text_converter with GNU General Public License v3.0 4 votes vote down vote up
private void vibrate() {
    if (mDontVibrate) return;
    Vibrator vi = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE);
    if (!vi.hasVibrator()) return;
    vi.vibrate(VIBRATION);
}
 
Example 17
Source File: VoIPBaseService.java    From Telegram-FOSS with GNU General Public License v2.0 4 votes vote down vote up
@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);
}
 
Example 18
Source File: AlarmRingService.java    From Moring-Alarm with Apache License 2.0 4 votes vote down vote up
private void startVibrate() {
    mVibrator = (Vibrator)getSystemService(VIBRATOR_SERVICE);
    if(mVibrator.hasVibrator()){
        mVibrator.vibrate(new long[]{500, 1500, 500, 1500}, 0);//off on off on
    }
}
 
Example 19
Source File: VoIPBaseService.java    From Telegram with GNU General Public License v2.0 4 votes vote down vote up
@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);
}
 
Example 20
Source File: VoIPBaseService.java    From TelePlus-Android with GNU General Public License v2.0 4 votes vote down vote up
@Override
public void onConnectionStateChanged(int newState) {
	if (newState == STATE_FAILED) {
		callFailed();
		return;
	}
	if (newState == STATE_ESTABLISHED) {
		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(controller==null)
						return;
					int netType=getStatsNetworkType();
					StatsController.getInstance(currentAccount).incrementTotalCallsTime(netType, 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);
}