android.os.Vibrator#hasVibrator ( )源码实例Demo

下面列出了android.os.Vibrator#hasVibrator ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: bcm-android   文件: IncomingRinger.java
@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;
  }
}
 
源代码2 项目: talkback   文件: TalkBackPreferencesActivity.java
/** 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);
  }
}
 
源代码3 项目: alpha-wallet-android   文件: KeyService.java
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);
        }
    }
}
 
源代码4 项目: alpha-wallet-android   文件: FunctionButtonBar.java
@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();
}
 
@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;
}
 
源代码6 项目: connectivity-samples   文件: MainActivity.java
/** 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);
  }
}
 
源代码7 项目: Kore   文件: UIUtils.java
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);
    }
}
 
源代码8 项目: android_9.0.0_r45   文件: LegacyGlobalActions.java
/**
 * @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);
}
 
源代码9 项目: ghwatch   文件: Utils.java
/**
 * 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;
}
 
源代码10 项目: q-municate-android   文件: IncomingCallFragment.java
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);
    }
}
 
源代码11 项目: PasscodeView   文件: BasePasscodeView.java
/**
 * 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);
}
 
源代码12 项目: PasscodeView   文件: BasePasscodeView.java
/**
 * 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);
}
 
源代码13 项目: PasscodeView   文件: BasePasscodeView.java
/**
 * 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);
}
 
源代码14 项目: GravityBox   文件: Utils.java
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;
    }
}
 
源代码15 项目: itracing2   文件: ToggleVibratePhone.java
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;
}
 
源代码16 项目: TelePlus-Android   文件: VoIPBaseService.java
@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);
}
 
源代码17 项目: Telegram   文件: VoIPBaseService.java
@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);
}
 
源代码18 项目: Telegram-FOSS   文件: VoIPBaseService.java
@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);
}
 
源代码19 项目: text_converter   文件: FloatingView.java
private void vibrate() {
    if (mDontVibrate) return;
    Vibrator vi = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE);
    if (!vi.hasVibrator()) return;
    vi.vibrate(VIBRATION);
}
 
源代码20 项目: Moring-Alarm   文件: AlarmRingService.java
private void startVibrate() {
    mVibrator = (Vibrator)getSystemService(VIBRATOR_SERVICE);
    if(mVibrator.hasVibrator()){
        mVibrator.vibrate(new long[]{500, 1500, 500, 1500}, 0);//off on off on
    }
}